Home | History | Annotate | Download | only in Ax88772
      1 /** @file
      2   Definitions for ASIX AX88772 Ethernet adapter.
      3 
      4   Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
      5   This program and the accompanying materials
      6   are licensed and made available under the terms and conditions of the BSD License
      7   which accompanies this distribution.  The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 #ifndef _AX88772_H_
     16 #define _AX88772_H_
     17 
     18 #include <Uefi.h>
     19 
     20 #include <Guid/EventGroup.h>
     21 
     22 #include <IndustryStandard/Pci.h>
     23 
     24 #include <Library/BaseMemoryLib.h>
     25 #include <Library/DebugLib.h>
     26 #include <Library/DevicePathLib.h>
     27 #include <Library/UefiBootServicesTableLib.h>
     28 #include <Library/UefiDriverEntryPoint.h>
     29 #include <Library/UefiLib.h>
     30 #include <Library/UefiRuntimeLib.h>
     31 
     32 #include <Protocol/DevicePath.h>
     33 #include <Protocol/LoadedImage.h>
     34 #include <Protocol/NetworkInterfaceIdentifier.h>
     35 #include <Protocol/SimpleNetwork.h>
     36 #include <Protocol/UsbIo.h>
     37 
     38 //------------------------------------------------------------------------------
     39 //  Macros
     40 //------------------------------------------------------------------------------
     41 //
     42 //Too many output debug info hangs system in Debug tip
     43 //
     44 //#if defined(_MSC_VER)           /* Handle Microsoft VC++ compiler specifics. */
     45 //#define DBG_ENTER()             DEBUG (( DEBUG_INFO, "Entering " __FUNCTION__ "\n" )) ///<  Display routine entry
     46 //#define DBG_EXIT()              DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ "\n" ))  ///<  Display routine exit
     47 //#define DBG_EXIT_DEC(Status)    DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %d\n", Status ))      ///<  Display routine exit with decimal value
     48 //#define DBG_EXIT_HEX(Status)    DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: 0x%08x\n", Status ))  ///<  Display routine exit with hex value
     49 //#define DBG_EXIT_STATUS(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %r\n", Status ))      ///<  Display routine exit with status value
     50 //#define DBG_EXIT_TF(Status)     DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", returning %s\n", (FALSE == Status) ? L"FALSE" : L"TRUE" ))  ///<  Display routine with TRUE/FALSE value
     51 //#else   //  _MSC_VER
     52 #define DBG_ENTER()               ///<  Display routine entry
     53 #define DBG_EXIT()                ///<  Display routine exit
     54 #define DBG_EXIT_DEC(Status)      ///<  Display routine exit with decimal value
     55 #define DBG_EXIT_HEX(Status)      ///<  Display routine exit with hex value
     56 #define DBG_EXIT_STATUS(Status)   ///<  Display routine exit with status value
     57 #define DBG_EXIT_TF(Status)       ///<  Display routine with TRUE/FALSE value
     58 //#endif  //  _MSC_VER
     59 
     60 #define USB_IS_IN_ENDPOINT(EndPointAddr)      (((EndPointAddr) & BIT7) != 0)  ///<  Return TRUE/FALSE for IN direction
     61 #define USB_IS_OUT_ENDPOINT(EndPointAddr)     (((EndPointAddr) & BIT7) == 0)  ///<  Return TRUE/FALSE for OUT direction
     62 #define USB_IS_BULK_ENDPOINT(Attribute)       (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_BULK)      ///<  Return TRUE/FALSE for BULK type
     63 #define USB_IS_INTERRUPT_ENDPOINT(Attribute)  (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) ///<  Return TRUE/FALSE for INTERRUPT type
     64 
     65 //------------------------------------------------------------------------------
     66 //  Constants
     67 //------------------------------------------------------------------------------
     68 
     69 #define DEBUG_RX_BROADCAST  0x40000000  ///<  Display RX broadcast messages
     70 #define DEBUG_RX_MULTICAST  0x20000000  ///<  Display RX multicast messages
     71 #define DEBUG_RX_UNICAST    0x10000000  ///<  Display RX unicast messages
     72 #define DEBUG_MAC_ADDRESS   0x08000000  ///<  Display the MAC address
     73 #define DEBUG_LINK          0x04000000  ///<  Display the link status
     74 #define DEBUG_TX            0x02000000  ///<  Display the TX messages
     75 #define DEBUG_PHY           0x01000000  ///<  Display the PHY register values
     76 #define DEBUG_SROM          0x00800000  ///<  Display the SROM contents
     77 #define DEBUG_TIMER         0x00400000  ///<  Display the timer routine entry/exit
     78 #define DEBUG_TPL           0x00200000  ///<  Display the timer routine entry/exit
     79 
     80 #define AX88772_MAX_PKT_SIZE  ( 2048 - 4 )  ///< Maximum packet size
     81 #define ETHERNET_HEADER_SIZE  sizeof ( ETHERNET_HEADER )  ///<  Size in bytes of the Ethernet header
     82 #define MIN_ETHERNET_PKT_SIZE 60    ///<  Minimum packet size including Ethernet header
     83 #define MAX_ETHERNET_PKT_SIZE 1500  ///<  Ethernet spec 3.1.1: Minimum packet size
     84 #define MAX_BULKIN_SIZE       2048  ///<  Maximum size of one UsbBulk
     85 
     86 
     87 #define USB_NETWORK_CLASS   0x09    ///<  USB Network class code
     88 #define USB_BUS_TIMEOUT     1000    ///<  USB timeout in milliseconds
     89 
     90 #define TIMER_MSEC          20              ///<  Polling interval for the NIC
     91 #define TPL_AX88772         TPL_CALLBACK    ///<  TPL for routine synchronization
     92 
     93 /**
     94   Verify new TPL value
     95 
     96   This macro which is enabled when debug is enabled verifies that
     97   the new TPL value is >= the current TPL value.
     98 **/
     99 #ifdef VERIFY_TPL
    100 #undef VERIFY_TPL
    101 #endif  //  VERIFY_TPL
    102 
    103 #if !defined(MDEPKG_NDEBUG)
    104 
    105 #define VERIFY_TPL(tpl)                           \
    106 {                                                 \
    107   EFI_TPL PreviousTpl;                            \
    108                                                   \
    109   PreviousTpl = gBS->RaiseTPL ( TPL_HIGH_LEVEL ); \
    110   gBS->RestoreTPL ( PreviousTpl );                \
    111   if ( PreviousTpl > tpl ) {                      \
    112     DEBUG (( DEBUG_ERROR, "Current TPL: %d, New TPL: %d\r\n", PreviousTpl, tpl ));  \
    113     ASSERT ( PreviousTpl <= tpl );                \
    114   }                                               \
    115 }
    116 
    117 #else   //  MDEPKG_NDEBUG
    118 
    119 #define VERIFY_TPL(tpl)
    120 
    121 #endif  //  MDEPKG_NDEBUG
    122 
    123 //------------------------------------------------------------------------------
    124 //  Hardware Definition
    125 //------------------------------------------------------------------------------
    126 
    127 #define DEV_SIGNATURE     SIGNATURE_32 ('A','X','8','8')  ///<  Signature of data structures in memory
    128 
    129 #define VENDOR_ID         0x0b95  ///<  Vendor ID for Asix
    130 #define PRODUCT_ID        0x7720  ///<  Product ID for the AX88772 USB 10/100 Ethernet controller
    131 
    132 #define RESET_MSEC        1000    ///<  Reset duration
    133 #define PHY_RESET_MSEC     500    ///<  PHY reset duration
    134 
    135 //
    136 //  RX Control register
    137 //
    138 
    139 #define RXC_PRO           0x0001  ///<  Receive all packets
    140 #define RXC_AMALL         0x0002  ///<  Receive all multicast packets
    141 #define RXC_SEP           0x0004  ///<  Save error packets
    142 #define RXC_AB            0x0008  ///<  Receive broadcast packets
    143 #define RXC_AM            0x0010  ///<  Use multicast destination address hash table
    144 #define RXC_AP            0x0020  ///<  Accept physical address from Multicast Filter
    145 #define RXC_SO            0x0080  ///<  Start operation
    146 #define RXC_MFB           0x0300  ///<  Maximum frame burst
    147 #define RXC_MFB_2048      0       ///<  Maximum frame size:  2048 bytes
    148 #define RXC_MFB_4096      0x0100  ///<  Maximum frame size:  4096 bytes
    149 #define RXC_MFB_8192      0x0200  ///<  Maximum frame size:  8192 bytes
    150 #define RXC_MFB_16384     0x0300  ///<  Maximum frame size: 16384 bytes
    151 
    152 //
    153 //  Medium Status register
    154 //
    155 
    156 #define MS_FD             0x0002  ///<  Full duplex
    157 #define MS_ONE            0x0004  ///<  Must be one
    158 #define MS_RFC            0x0010  ///<  RX flow control enable
    159 #define MS_TFC            0x0020  ///<  TX flow control enable
    160 #define MS_PF             0x0080  ///<  Pause frame enable
    161 #define MS_RE             0x0100  ///<  Receive enable
    162 #define MS_PS             0x0200  ///<  Port speed 1=100, 0=10 Mbps
    163 #define MS_SBP            0x0800  ///<  Stop back pressure
    164 #define MS_SM             0x1000  ///<  Super MAC support
    165 
    166 //
    167 //  Software PHY Select register
    168 //
    169 
    170 #define SPHY_PSEL         0x01    ///<  Select internal PHY
    171 #define SPHY_ASEL         0x02    ///<  1=Auto select, 0=Manual select
    172 
    173 //
    174 //  Software Reset register
    175 //
    176 
    177 #define SRR_RR            0x01    ///<  Clear receive frame length error
    178 #define SRR_RT            0x02    ///<  Clear transmit frame length error
    179 #define SRR_PRTE          0x04    ///<  External PHY reset pin tri-state enable
    180 #define SRR_PRL           0x08    ///<  External PHY reset pin level
    181 #define SRR_BZ            0x10    ///<  Force Bulk to return zero length packet
    182 #define SRR_IPRL          0x20    ///<  Internal PHY reset control
    183 #define SRR_IPPD          0x40    ///<  Internal PHY power down
    184 
    185 //
    186 //  PHY ID values
    187 //
    188 
    189 #define PHY_ID_INTERNAL   0x0010  ///<  Internal PHY
    190 
    191 //
    192 //  USB Commands
    193 //
    194 
    195 #define CMD_PHY_ACCESS_SOFTWARE   0x06  ///<  Software in control of PHY
    196 #define CMD_PHY_REG_READ          0x07  ///<  Read PHY register, Value: PHY, Index: Register, Data: Register value
    197 #define CMD_PHY_REG_WRITE         0x08  ///<  Write PHY register, Value: PHY, Index: Register, Data: New 16-bit value
    198 #define CMD_PHY_ACCESS_HARDWARE   0x0a  ///<  Hardware in control of PHY
    199 #define CMD_SROM_READ             0x0b  ///<  Read SROM register: Value: Address, Data: Value
    200 #define CMD_RX_CONTROL_WRITE      0x10  ///<  Set the RX control register, Value: New value
    201 #define CMD_GAPS_WRITE            0x12  ///<  Write the gaps register, Value: New value
    202 #define CMD_MAC_ADDRESS_READ      0x13  ///<  Read the MAC address, Data: 6 byte MAC address
    203 #define CMD_MAC_ADDRESS_WRITE     0x14  ///<  Set the MAC address, Data: New 6 byte MAC address
    204 #define CMD_MULTICAST_HASH_WRITE  0x16  ///<  Write the multicast hash table, Data: New 8 byte value
    205 #define CMD_MEDIUM_STATUS_READ    0x1a  ///<  Read medium status register, Data: Register value
    206 #define CMD_MEDIUM_STATUS_WRITE   0x1b  ///<  Write medium status register, Value: New value
    207 #define CMD_RESET                 0x20  ///<  Reset register, Value: New value
    208 #define CMD_PHY_SELECT            0x22  ///<  PHY select register, Value: New value
    209 
    210 //------------------------------
    211 //  USB Endpoints
    212 //------------------------------
    213 
    214 #define CONTROL_ENDPOINT                0       ///<  Control endpoint
    215 #define INTERRUPT_ENDPOINT              1       ///<  Interrupt endpoint
    216 #define BULK_IN_ENDPOINT                2       ///<  Receive endpoint
    217 #define BULK_OUT_ENDPOINT               3       ///<  Transmit endpoint
    218 
    219 //------------------------------
    220 //  PHY Registers
    221 //------------------------------
    222 
    223 #define PHY_BMCR                        0       ///<  Control register
    224 #define PHY_BMSR                        1       ///<  Status register
    225 #define PHY_ANAR                        4       ///<  Autonegotiation advertisement register
    226 #define PHY_ANLPAR                      5       ///<  Autonegotiation link parter ability register
    227 #define PHY_ANER                        6       ///<  Autonegotiation expansion register
    228 
    229 //  BMCR - Register 0
    230 
    231 #define BMCR_RESET                      0x8000  ///<  1 = Reset the PHY, bit clears after reset
    232 #define BMCR_LOOPBACK                   0x4000  ///<  1 = Loopback enabled
    233 #define BMCR_100MBPS                    0x2000  ///<  100 Mbits/Sec
    234 #define BMCR_10MBPS                     0       ///<  10 Mbits/Sec
    235 #define BMCR_AUTONEGOTIATION_ENABLE     0x1000  ///<  1 = Enable autonegotiation
    236 #define BMCR_POWER_DOWN                 0x0800  ///<  1 = Power down
    237 #define BMCR_ISOLATE                    0x0400  ///<  0 = Isolate PHY
    238 #define BMCR_RESTART_AUTONEGOTIATION    0x0200  ///<  1 = Restart autonegotiation
    239 #define BMCR_FULL_DUPLEX                0x0100  ///<  Full duplex operation
    240 #define BMCR_HALF_DUPLEX                0       ///<  Half duplex operation
    241 #define BMCR_COLLISION_TEST             0x0080  ///<  1 = Collision test enabled
    242 
    243 //  BSMR - Register 1
    244 
    245 #define BMSR_100BASET4                  0x8000  ///<  1 = 100BASE-T4 mode
    246 #define BMSR_100BASETX_FDX              0x4000  ///<  1 = 100BASE-TX full duplex
    247 #define BMSR_100BASETX_HDX              0x2000  ///<  1 = 100BASE-TX half duplex
    248 #define BMSR_10BASET_FDX                0x1000  ///<  1 = 10BASE-T full duplex
    249 #define BMSR_10BASET_HDX                0x0800  ///<  1 = 10BASE-T half duplex
    250 #define BMSR_MF                         0x0040  ///<  1 = PHY accepts frames with preamble suppressed
    251 #define BMSR_AUTONEG_CMPLT              0x0020  ///<  1 = Autonegotiation complete
    252 #define BMSR_RF                         0x0010  ///<  1 = Remote fault
    253 #define BMSR_AUTONEG                    0x0008  ///<  1 = Able to perform autonegotiation
    254 #define BMSR_LINKST                     0x0004  ///<  1 = Link up
    255 #define BMSR_JABBER_DETECT              0x0002  ///<  1 = jabber condition detected
    256 #define BMSR_EXTENDED_CAPABILITY        0x0001  ///<  1 = Extended register capable
    257 
    258 //  ANAR and ANLPAR Registers 4, 5
    259 
    260 #define AN_NP                           0x8000  ///<  1 = Next page available
    261 #define AN_ACK                          0x4000  ///<  1 = Link partner acknowledged
    262 #define AN_RF                           0x2000  ///<  1 = Remote fault indicated by link partner
    263 #define AN_FCS                          0x0400  ///<  1 = Flow control ability
    264 #define AN_T4                           0x0200  ///<  1 = 100BASE-T4 support
    265 #define AN_TX_FDX                       0x0100  ///<  1 = 100BASE-TX Full duplex
    266 #define AN_TX_HDX                       0x0080  ///<  1 = 100BASE-TX support
    267 #define AN_10_FDX                       0x0040  ///<  1 = 10BASE-T Full duplex
    268 #define AN_10_HDX                       0x0020  ///<  1 = 10BASE-T support
    269 #define AN_CSMA_CD                      0x0001  ///<  1 = IEEE 802.3 CSMA/CD support
    270 
    271 //------------------------------------------------------------------------------
    272 //  Data Types
    273 //------------------------------------------------------------------------------
    274 
    275 /**
    276   Ethernet header layout
    277 
    278   IEEE 802.3-2002 Part 3 specification, section 3.1.1.
    279 **/
    280 #pragma pack(1)
    281 typedef struct {
    282   UINT8 dest_addr[PXE_HWADDR_LEN_ETHER];  ///<  Destination LAN address
    283   UINT8 src_addr[PXE_HWADDR_LEN_ETHER];   ///<  Source LAN address
    284   UINT16 type;                            ///<  Protocol or length
    285 } ETHERNET_HEADER;
    286 #pragma pack()
    287 
    288 /**
    289   Receive and Transmit packet structure
    290 **/
    291 #pragma pack(1)
    292 typedef struct _RX_TX_PACKET {
    293   struct _RX_TX_PACKET * pNext;       ///<  Next receive packet
    294   UINT16 Length;                      ///<  Packet length
    295   UINT16 LengthBar;                   ///<  Complement of the length
    296   UINT8 Data[ AX88772_MAX_PKT_SIZE ]; ///<  Received packet data
    297 } RX_TX_PACKET;
    298 #pragma pack()
    299 
    300 /**
    301   AX88772 control structure
    302 
    303   The driver uses this structure to manage the Asix AX88772 10/100
    304   Ethernet controller.
    305 **/
    306 typedef struct {
    307   UINTN Signature;          ///<  Structure identification
    308 
    309   //
    310   //  USB data
    311   //
    312   EFI_HANDLE Controller;        ///<  Controller handle
    313   EFI_USB_IO_PROTOCOL * pUsbIo; ///<  USB driver interface
    314 
    315   //
    316   //  Simple network protocol data
    317   //
    318   EFI_SIMPLE_NETWORK_PROTOCOL SimpleNetwork;  ///<  Driver's network stack interface
    319   EFI_SIMPLE_NETWORK_MODE SimpleNetworkData;  ///<  Data for simple network
    320 
    321   //
    322   // Ethernet controller data
    323   //
    324   BOOLEAN bInitialized;     ///<  Controller initialized
    325   VOID * pTxBuffer;         ///<  Last transmit buffer
    326   UINT16 PhyId;             ///<  PHY ID
    327 
    328   //
    329   //  Link state
    330   //
    331   BOOLEAN b100Mbps;         ///<  Current link speed, FALSE = 10 Mbps
    332   BOOLEAN bComplete;        ///<  Current state of auto-negotiation
    333   BOOLEAN bFullDuplex;      ///<  Current duplex
    334   BOOLEAN bLinkUp;          ///<  Current link state
    335   BOOLEAN bLinkIdle;        ///<  TRUE = No received traffic
    336   EFI_EVENT Timer;          ///<  Timer to monitor link state and receive packets
    337   UINTN PollCount;          ///<  Number of times the autonegotiation status was polled
    338 
    339   //
    340   //  Receive buffer list
    341   //
    342   RX_TX_PACKET * pRxHead;   ///<  Head of receive packet list
    343   RX_TX_PACKET * pRxTail;   ///<  Tail of receive packet list
    344   RX_TX_PACKET * pRxFree;   ///<  Free packet list
    345   INT32 MulticastHash[2];   ///<  Hash table for multicast destination addresses
    346   UINT8 * pBulkInBuff;      ///<  Buffer for Usb Bulk
    347 } NIC_DEVICE;
    348 
    349 #define DEV_FROM_SIMPLE_NETWORK(a)  CR (a, NIC_DEVICE, SimpleNetwork, DEV_SIGNATURE)  ///< Locate NIC_DEVICE from Simple Network Protocol
    350 
    351 //------------------------------------------------------------------------------
    352 // Simple Network Protocol
    353 //------------------------------------------------------------------------------
    354 
    355 /**
    356   Reset the network adapter.
    357 
    358   Resets a network adapter and reinitializes it with the parameters that
    359   were provided in the previous call to Initialize ().  The transmit and
    360   receive queues are cleared.  Receive filters, the station address, the
    361   statistics, and the multicast-IP-to-HW MAC addresses are not reset by
    362   this call.
    363 
    364   This routine calls ::Ax88772Reset to perform the adapter specific
    365   reset operation.  This routine also starts the link negotiation
    366   by calling ::Ax88772NegotiateLinkStart.
    367 
    368   @param [in] pSimpleNetwork    Protocol instance pointer
    369   @param [in] bExtendedVerification  Indicates that the driver may perform a more
    370                                 exhaustive verification operation of the device
    371                                 during reset.
    372 
    373   @retval EFI_SUCCESS           This operation was successful.
    374   @retval EFI_NOT_STARTED       The network interface was not started.
    375   @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
    376                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
    377   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
    378   @retval EFI_UNSUPPORTED       The increased buffer size feature is not supported.
    379 
    380 **/
    381 EFI_STATUS
    382 EFIAPI
    383 SN_Reset (
    384   IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
    385   IN BOOLEAN bExtendedVerification
    386   );
    387 
    388 /**
    389   Initialize the simple network protocol.
    390 
    391   This routine calls ::Ax88772MacAddressGet to obtain the
    392   MAC address.
    393 
    394   @param [in] pNicDevice       NIC_DEVICE_INSTANCE pointer
    395 
    396   @retval EFI_SUCCESS     Setup was successful
    397 
    398 **/
    399 EFI_STATUS
    400 SN_Setup (
    401   IN NIC_DEVICE * pNicDevice
    402   );
    403 
    404 /**
    405   This routine starts the network interface.
    406 
    407   @param [in] pSimpleNetwork    Protocol instance pointer
    408 
    409   @retval EFI_SUCCESS           This operation was successful.
    410   @retval EFI_ALREADY_STARTED   The network interface was already started.
    411   @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
    412                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
    413   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
    414   @retval EFI_UNSUPPORTED       The increased buffer size feature is not supported.
    415 
    416 **/
    417 EFI_STATUS
    418 EFIAPI
    419 SN_Start (
    420   IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork
    421   );
    422 
    423 /**
    424   Set the MAC address.
    425 
    426   This function modifies or resets the current station address of a
    427   network interface.  If Reset is TRUE, then the current station address
    428   is set ot the network interface's permanent address.  If Reset if FALSE
    429   then the current station address is changed to the address specified by
    430   pNew.
    431 
    432   This routine calls ::Ax88772MacAddressSet to update the MAC address
    433   in the network adapter.
    434 
    435   @param [in] pSimpleNetwork    Protocol instance pointer
    436   @param [in] bReset            Flag used to reset the station address to the
    437                                 network interface's permanent address.
    438   @param [in] pNew              New station address to be used for the network
    439                                 interface.
    440 
    441   @retval EFI_SUCCESS           This operation was successful.
    442   @retval EFI_NOT_STARTED       The network interface was not started.
    443   @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
    444                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
    445   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
    446   @retval EFI_UNSUPPORTED       The increased buffer size feature is not supported.
    447 
    448 **/
    449 EFI_STATUS
    450 EFIAPI
    451 SN_StationAddress (
    452   IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
    453   IN BOOLEAN bReset,
    454   IN EFI_MAC_ADDRESS * pNew
    455   );
    456 
    457 /**
    458   This function resets or collects the statistics on a network interface.
    459   If the size of the statistics table specified by StatisticsSize is not
    460   big enough for all of the statistics that are collected by the network
    461   interface, then a partial buffer of statistics is returned in
    462   StatisticsTable.
    463 
    464   @param [in] pSimpleNetwork    Protocol instance pointer
    465   @param [in] bReset            Set to TRUE to reset the statistics for the network interface.
    466   @param [in, out] pStatisticsSize  On input the size, in bytes, of StatisticsTable.  On output
    467                                 the size, in bytes, of the resulting table of statistics.
    468   @param [out] pStatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
    469                                 conains the statistics.
    470 
    471   @retval EFI_SUCCESS           This operation was successful.
    472   @retval EFI_NOT_STARTED       The network interface was not started.
    473   @retval EFI_BUFFER_TOO_SMALL  The pStatisticsTable is NULL or the buffer is too small.
    474   @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
    475                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
    476   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
    477   @retval EFI_UNSUPPORTED       The increased buffer size feature is not supported.
    478 
    479 **/
    480 EFI_STATUS
    481 EFIAPI
    482 SN_Statistics (
    483   IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
    484   IN BOOLEAN bReset,
    485   IN OUT UINTN * pStatisticsSize,
    486   OUT EFI_NETWORK_STATISTICS * pStatisticsTable
    487   );
    488 
    489 /**
    490   This function stops a network interface.  This call is only valid
    491   if the network interface is in the started state.
    492 
    493   @param [in] pSimpleNetwork    Protocol instance pointer
    494 
    495   @retval EFI_SUCCESS           This operation was successful.
    496   @retval EFI_NOT_STARTED       The network interface was not started.
    497   @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
    498                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
    499   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
    500   @retval EFI_UNSUPPORTED       The increased buffer size feature is not supported.
    501 
    502 **/
    503 EFI_STATUS
    504 EFIAPI
    505 SN_Stop (
    506   IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork
    507   );
    508 
    509 /**
    510   This function releases the memory buffers assigned in the Initialize() call.
    511   Pending transmits and receives are lost, and interrupts are cleared and disabled.
    512   After this call, only Initialize() and Stop() calls may be used.
    513 
    514   @param [in] pSimpleNetwork    Protocol instance pointer
    515 
    516   @retval EFI_SUCCESS           This operation was successful.
    517   @retval EFI_NOT_STARTED       The network interface was not started.
    518   @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
    519                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
    520   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
    521   @retval EFI_UNSUPPORTED       The increased buffer size feature is not supported.
    522 
    523 **/
    524 EFI_STATUS
    525 EFIAPI
    526 SN_Shutdown (
    527   IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork
    528   );
    529 
    530 /**
    531   Send a packet over the network.
    532 
    533   This function places the packet specified by Header and Buffer on
    534   the transmit queue.  This function performs a non-blocking transmit
    535   operation.  When the transmit is complete, the buffer is returned
    536   via the GetStatus() call.
    537 
    538   This routine calls ::Ax88772Rx to empty the network adapter of
    539   receive packets.  The routine then passes the transmit packet
    540   to the network adapter.
    541 
    542   @param [in] pSimpleNetwork    Protocol instance pointer
    543   @param [in] HeaderSize        The size, in bytes, of the media header to be filled in by
    544                                 the Transmit() function.  If HeaderSize is non-zero, then
    545                                 it must be equal to SimpleNetwork->Mode->MediaHeaderSize
    546                                 and DestAddr and Protocol parameters must not be NULL.
    547   @param [in] BufferSize        The size, in bytes, of the entire packet (media header and
    548                                 data) to be transmitted through the network interface.
    549   @param [in] pBuffer           A pointer to the packet (media header followed by data) to
    550                                 to be transmitted.  This parameter can not be NULL.  If
    551                                 HeaderSize is zero, then the media header is Buffer must
    552                                 already be filled in by the caller.  If HeaderSize is nonzero,
    553                                 then the media header will be filled in by the Transmit()
    554                                 function.
    555   @param [in] pSrcAddr          The source HW MAC address.  If HeaderSize is zero, then
    556                                 this parameter is ignored.  If HeaderSize is nonzero and
    557                                 SrcAddr is NULL, then SimpleNetwork->Mode->CurrentAddress
    558                                 is used for the source HW MAC address.
    559   @param [in] pDestAddr         The destination HW MAC address.  If HeaderSize is zero, then
    560                                 this parameter is ignored.
    561   @param [in] pProtocol         The type of header to build.  If HeaderSize is zero, then
    562                                 this parameter is ignored.
    563 
    564   @retval EFI_SUCCESS           This operation was successful.
    565   @retval EFI_NOT_STARTED       The network interface was not started.
    566   @retval EFI_NOT_READY         The network interface is too busy to accept this transmit request.
    567   @retval EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.
    568   @retval EFI_INVALID_PARAMETER pSimpleNetwork parameter was NULL or did not point to a valid
    569                                 EFI_SIMPLE_NETWORK_PROTOCOL structure.
    570   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
    571 
    572 **/
    573 EFI_STATUS
    574 EFIAPI
    575 SN_Transmit (
    576   IN EFI_SIMPLE_NETWORK_PROTOCOL * pSimpleNetwork,
    577   IN UINTN HeaderSize,
    578   IN UINTN BufferSize,
    579   IN VOID * pBuffer,
    580   IN EFI_MAC_ADDRESS * pSrcAddr,
    581   IN EFI_MAC_ADDRESS * pDestAddr,
    582   IN UINT16 * pProtocol
    583   );
    584 
    585 //------------------------------------------------------------------------------
    586 // Support Routines
    587 //------------------------------------------------------------------------------
    588 
    589 /**
    590   Get the MAC address
    591 
    592   This routine calls ::Ax88772UsbCommand to request the MAC
    593   address from the network adapter.
    594 
    595   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    596   @param [out] pMacAddress      Address of a six byte buffer to receive the MAC address.
    597 
    598   @retval EFI_SUCCESS          The MAC address is available.
    599   @retval other                The MAC address is not valid.
    600 
    601 **/
    602 EFI_STATUS
    603 Ax88772MacAddressGet (
    604   IN NIC_DEVICE * pNicDevice,
    605   OUT UINT8 * pMacAddress
    606   );
    607 
    608 /**
    609   Set the MAC address
    610 
    611   This routine calls ::Ax88772UsbCommand to set the MAC address
    612   in the network adapter.
    613 
    614   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    615   @param [in] pMacAddress      Address of a six byte buffer to containing the new MAC address.
    616 
    617   @retval EFI_SUCCESS          The MAC address was set.
    618   @retval other                The MAC address was not set.
    619 
    620 **/
    621 EFI_STATUS
    622 Ax88772MacAddressSet (
    623   IN NIC_DEVICE * pNicDevice,
    624   IN UINT8 * pMacAddress
    625   );
    626 
    627 /**
    628   Clear the multicast hash table
    629 
    630   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    631 
    632 **/
    633 VOID
    634 Ax88772MulticastClear (
    635   IN NIC_DEVICE * pNicDevice
    636   );
    637 
    638 /**
    639   Enable a multicast address in the multicast hash table
    640 
    641   This routine calls ::Ax88772Crc to compute the hash bit for
    642   this MAC address.
    643 
    644   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    645   @param [in] pMacAddress      Address of a six byte buffer to containing the MAC address.
    646 
    647 **/
    648 VOID
    649 Ax88772MulticastSet (
    650   IN NIC_DEVICE * pNicDevice,
    651   IN UINT8 * pMacAddress
    652   );
    653 
    654 /**
    655   Start the link negotiation
    656 
    657   This routine calls ::Ax88772PhyWrite to start the PHY's link
    658   negotiation.
    659 
    660   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    661 
    662   @retval EFI_SUCCESS          The link negotiation was started.
    663   @retval other                Failed to start the link negotiation.
    664 
    665 **/
    666 EFI_STATUS
    667 Ax88772NegotiateLinkStart (
    668   IN NIC_DEVICE * pNicDevice
    669   );
    670 
    671 /**
    672   Complete the negotiation of the PHY link
    673 
    674   This routine calls ::Ax88772PhyRead to determine if the
    675   link negotiation is complete.
    676 
    677   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    678   @param [in, out] pPollCount  Address of number of times this routine was polled
    679   @param [out] pbComplete      Address of boolean to receive complate status.
    680   @param [out] pbLinkUp        Address of boolean to receive link status, TRUE=up.
    681   @param [out] pbHiSpeed       Address of boolean to receive link speed, TRUE=100Mbps.
    682   @param [out] pbFullDuplex    Address of boolean to receive link duplex, TRUE=full.
    683 
    684   @retval EFI_SUCCESS          The MAC address is available.
    685   @retval other                The MAC address is not valid.
    686 
    687 **/
    688 EFI_STATUS
    689 Ax88772NegotiateLinkComplete (
    690   IN NIC_DEVICE * pNicDevice,
    691   IN OUT UINTN * pPollCount,
    692   OUT BOOLEAN * pbComplete,
    693   OUT BOOLEAN * pbLinkUp,
    694   OUT BOOLEAN * pbHiSpeed,
    695   OUT BOOLEAN * pbFullDuplex
    696   );
    697 
    698 /**
    699   Read a register from the PHY
    700 
    701   This routine calls ::Ax88772UsbCommand to read a PHY register.
    702 
    703   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    704   @param [in] RegisterAddress  Number of the register to read.
    705   @param [in, out] pPhyData    Address of a buffer to receive the PHY register value
    706 
    707   @retval EFI_SUCCESS          The PHY data is available.
    708   @retval other                The PHY data is not valid.
    709 
    710 **/
    711 EFI_STATUS
    712 Ax88772PhyRead (
    713   IN NIC_DEVICE * pNicDevice,
    714   IN UINT8 RegisterAddress,
    715   IN OUT UINT16 * pPhyData
    716   );
    717 
    718 /**
    719   Write to a PHY register
    720 
    721   This routine calls ::Ax88772UsbCommand to write a PHY register.
    722 
    723   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    724   @param [in] RegisterAddress  Number of the register to read.
    725   @param [in] PhyData          Address of a buffer to receive the PHY register value
    726 
    727   @retval EFI_SUCCESS          The PHY data was written.
    728   @retval other                Failed to wwrite the PHY register.
    729 
    730 **/
    731 EFI_STATUS
    732 Ax88772PhyWrite (
    733   IN NIC_DEVICE * pNicDevice,
    734   IN UINT8 RegisterAddress,
    735   IN UINT16 PhyData
    736   );
    737 
    738 /**
    739   Reset the AX88772
    740 
    741   This routine uses ::Ax88772UsbCommand to reset the network
    742   adapter.  This routine also uses ::Ax88772PhyWrite to reset
    743   the PHY.
    744 
    745   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    746 
    747   @retval EFI_SUCCESS          The MAC address is available.
    748   @retval other                The MAC address is not valid.
    749 
    750 **/
    751 EFI_STATUS
    752 Ax88772Reset (
    753   IN NIC_DEVICE * pNicDevice
    754   );
    755 
    756 /**
    757   Receive a frame from the network.
    758 
    759   This routine polls the USB receive interface for a packet.  If a packet
    760   is available, this routine adds the receive packet to the list of
    761   pending receive packets.
    762 
    763   This routine calls ::Ax88772NegotiateLinkComplete to verify
    764   that the link is up.  This routine also calls ::SN_Reset to
    765   reset the network adapter when necessary.  Finally this
    766   routine attempts to receive one or more packets from the
    767   network adapter.
    768 
    769   @param [in] pNicDevice  Pointer to the NIC_DEVICE structure
    770   @param [in] bUpdateLink TRUE = Update link status
    771 
    772 **/
    773 VOID
    774 Ax88772Rx (
    775   IN NIC_DEVICE * pNicDevice,
    776   IN BOOLEAN bUpdateLink
    777   );
    778 
    779 /**
    780   Enable or disable the receiver
    781 
    782   This routine calls ::Ax88772UsbCommand to update the
    783   receiver state.  This routine also calls ::Ax88772MacAddressSet
    784   to establish the MAC address for the network adapter.
    785 
    786   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    787   @param [in] RxFilter         Simple network RX filter mask value
    788 
    789   @retval EFI_SUCCESS          The MAC address was set.
    790   @retval other                The MAC address was not set.
    791 
    792 **/
    793 EFI_STATUS
    794 Ax88772RxControl (
    795   IN NIC_DEVICE * pNicDevice,
    796   IN UINT32 RxFilter
    797   );
    798 
    799 /**
    800   Read an SROM location
    801 
    802   This routine calls ::Ax88772UsbCommand to read data from the
    803   SROM.
    804 
    805   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    806   @param [in] Address          SROM address
    807   @param [out] pData           Buffer to receive the data
    808 
    809   @retval EFI_SUCCESS          The read was successful
    810   @retval other                The read failed
    811 
    812 **/
    813 EFI_STATUS
    814 Ax88772SromRead (
    815   IN NIC_DEVICE * pNicDevice,
    816   IN UINT32 Address,
    817   OUT UINT16 * pData
    818   );
    819 
    820 /**
    821   This routine is called at a regular interval to poll for
    822   receive packets.
    823 
    824   This routine polls the link state and gets any receive packets
    825   by calling ::Ax88772Rx.
    826 
    827   @param [in] Event            Timer event
    828   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    829 
    830 **/
    831 VOID
    832 Ax88772Timer (
    833   IN EFI_EVENT Event,
    834   IN NIC_DEVICE * pNicDevice
    835   );
    836 
    837 /**
    838   Send a command to the USB device.
    839 
    840   @param [in] pNicDevice       Pointer to the NIC_DEVICE structure
    841   @param [in] pRequest         Pointer to the request structure
    842   @param [in, out] pBuffer     Data buffer address
    843 
    844   @retval EFI_SUCCESS          The USB transfer was successful
    845   @retval other                The USB transfer failed
    846 
    847 **/
    848 EFI_STATUS
    849 Ax88772UsbCommand (
    850   IN NIC_DEVICE * pNicDevice,
    851   IN USB_DEVICE_REQUEST * pRequest,
    852   IN OUT VOID * pBuffer
    853   );
    854 
    855 //------------------------------------------------------------------------------
    856 // EFI Component Name Protocol Support
    857 //------------------------------------------------------------------------------
    858 
    859 extern EFI_COMPONENT_NAME_PROTOCOL   gComponentName;  ///<  Component name protocol declaration
    860 extern EFI_COMPONENT_NAME2_PROTOCOL  gComponentName2; ///<  Component name 2 protocol declaration
    861 
    862 /**
    863   Retrieves a Unicode string that is the user readable name of the driver.
    864 
    865   This function retrieves the user readable name of a driver in the form of a
    866   Unicode string. If the driver specified by This has a user readable name in
    867   the language specified by Language, then a pointer to the driver name is
    868   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
    869   by This does not support the language specified by Language,
    870   then EFI_UNSUPPORTED is returned.
    871 
    872   @param [in] pThis             A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    873                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    874   @param [in] pLanguage         A pointer to a Null-terminated ASCII string
    875                                 array indicating the language. This is the
    876                                 language of the driver name that the caller is
    877                                 requesting, and it must match one of the
    878                                 languages specified in SupportedLanguages. The
    879                                 number of languages supported by a driver is up
    880                                 to the driver writer. Language is specified
    881                                 in RFC 3066 or ISO 639-2 language code format.
    882   @param [out] ppDriverName     A pointer to the Unicode string to return.
    883                                 This Unicode string is the name of the
    884                                 driver specified by This in the language
    885                                 specified by Language.
    886 
    887   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
    888                                 This and the language specified by Language was
    889                                 returned in DriverName.
    890   @retval EFI_INVALID_PARAMETER Language is NULL.
    891   @retval EFI_INVALID_PARAMETER DriverName is NULL.
    892   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    893                                 the language specified by Language.
    894 
    895 **/
    896 EFI_STATUS
    897 EFIAPI
    898 GetDriverName (
    899   IN  EFI_COMPONENT_NAME_PROTOCOL * pThis,
    900   IN  CHAR8 * pLanguage,
    901   OUT CHAR16 ** ppDriverName
    902   );
    903 
    904 
    905 /**
    906   Retrieves a Unicode string that is the user readable name of the controller
    907   that is being managed by a driver.
    908 
    909   This function retrieves the user readable name of the controller specified by
    910   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    911   driver specified by This has a user readable name in the language specified by
    912   Language, then a pointer to the controller name is returned in ControllerName,
    913   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    914   managing the controller specified by ControllerHandle and ChildHandle,
    915   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    916   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    917 
    918   @param [in] pThis             A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    919                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    920   @param [in] ControllerHandle  The handle of a controller that the driver
    921                                 specified by This is managing.  This handle
    922                                 specifies the controller whose name is to be
    923                                 returned.
    924   @param [in] ChildHandle       The handle of the child controller to retrieve
    925                                 the name of.  This is an optional parameter that
    926                                 may be NULL.  It will be NULL for device
    927                                 drivers.  It will also be NULL for a bus drivers
    928                                 that wish to retrieve the name of the bus
    929                                 controller.  It will not be NULL for a bus
    930                                 driver that wishes to retrieve the name of a
    931                                 child controller.
    932   @param [in] pLanguage         A pointer to a Null-terminated ASCII string
    933                                 array indicating the language.  This is the
    934                                 language of the driver name that the caller is
    935                                 requesting, and it must match one of the
    936                                 languages specified in SupportedLanguages. The
    937                                 number of languages supported by a driver is up
    938                                 to the driver writer. Language is specified in
    939                                 RFC 3066 or ISO 639-2 language code format.
    940   @param [out] ppControllerName A pointer to the Unicode string to return.
    941                                 This Unicode string is the name of the
    942                                 controller specified by ControllerHandle and
    943                                 ChildHandle in the language specified by
    944                                 Language from the point of view of the driver
    945                                 specified by This.
    946 
    947   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    948                                 the language specified by Language for the
    949                                 driver specified by This was returned in
    950                                 DriverName.
    951   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
    952   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    953                                 EFI_HANDLE.
    954   @retval EFI_INVALID_PARAMETER Language is NULL.
    955   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    956   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    957                                 managing the controller specified by
    958                                 ControllerHandle and ChildHandle.
    959   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    960                                 the language specified by Language.
    961 
    962 **/
    963 EFI_STATUS
    964 EFIAPI
    965 GetControllerName (
    966   IN  EFI_COMPONENT_NAME_PROTOCOL * pThis,
    967   IN  EFI_HANDLE ControllerHandle,
    968   IN OPTIONAL EFI_HANDLE ChildHandle,
    969   IN  CHAR8 * pLanguage,
    970   OUT CHAR16 ** ppControllerName
    971   );
    972 
    973 //------------------------------------------------------------------------------
    974 
    975 #endif  //  _AX88772_H_
    976