Ax88772.h 41 KB

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