dwceth.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. dwceth.h
  5. Abstract:
  6. This header contains definitions for the DesignWare Ethernet controller.
  7. Author:
  8. Evan Green 5-Dec-2014
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // --------------------------------------------------------------------- Macros
  15. //
  16. //
  17. // These macros read and write registers in the controller.
  18. //
  19. #define DWE_READ(_Controller, _Register) \
  20. HlReadRegister32((PUCHAR)(_Controller)->ControllerBase + (_Register))
  21. #define DWE_WRITE(_Controller, _Register, _Value) \
  22. HlWriteRegister32((PUCHAR)(_Controller)->ControllerBase + (_Register), \
  23. (_Value))
  24. //
  25. // This macro creates a descriptor value given the two buffer sizes.
  26. //
  27. #define DWE_BUFFER_SIZE(_Size1, _Size2) \
  28. (((_Size1) & DWE_BUFFER_SIZE_MASK) | \
  29. (((_Size2) & DWE_BUFFER_SIZE_MASK) << DWE_BUFFER2_SHIFT))
  30. //
  31. // These macros return the register numbers for one of the programmable MAC
  32. // addresses.
  33. //
  34. #define DWE_MAC_ADDRESS_HIGH(_Index) \
  35. (DweRegisterMacAddress0High + ((_Index) * 8))
  36. #define DWE_MAC_ADDRESS_LOW(_Index) \
  37. (DweRegisterMacAddress0Low + ((_Index) * 8))
  38. //
  39. // ---------------------------------------------------------------- Definitions
  40. //
  41. //
  42. // Define the DesignWare Ethernet controller allocation tag: DwEt
  43. //
  44. #define DWE_ALLOCATION_TAG 0x74457744
  45. //
  46. // Define the size of receive frame data.
  47. //
  48. #define DWE_RECEIVE_FRAME_DATA_SIZE 1520
  49. //
  50. // Define the number of receive buffers that will be allocated for the
  51. // controller.
  52. //
  53. #define DWE_RECEIVE_FRAME_COUNT 32
  54. //
  55. // Define the number of transmit descriptors to allocate for the controller.
  56. //
  57. #define DWE_TRANSMIT_DESCRIPTOR_COUNT 32
  58. //
  59. // Define how often to poll the link state, in seconds.
  60. //
  61. #define DWE_LINK_CHECK_INTERVAL 5
  62. //
  63. // Define the number of seconds to wait for the MII to respond.
  64. //
  65. #define DWE_MII_TIMEOUT 5
  66. #define DWE_MII_CLOCK_VALUE 2
  67. //
  68. // Define receive descriptor status bits. Some bits have double (or triple)
  69. // meanings depending on what features are enabled.
  70. //
  71. //
  72. // If timestamping or checksum offloading is enabled, bit 0 describes whether
  73. // or not the extended status word is valid. If neither of these features are
  74. // available, the bit describes whether MAC Address 0 matched the packet
  75. // destination (1) or MAC Address 1-15 matched (0).
  76. //
  77. #define DWE_RX_STATUS_EXTENDED_STATUS (1 << 0)
  78. #define DWE_RX_STATUS_MAC0_MATCH (1 << 0)
  79. #define DWE_RX_STATUS_CRC_ERROR (1 << 1)
  80. #define DWE_RX_STATUS_DRIBBLE_BIT_ERROR (1 << 2)
  81. #define DWE_RX_STATUS_RECEIVE_ERROR (1 << 3)
  82. #define DWE_RX_STATUS_WATCHDOG_TIMEOUT (1 << 4)
  83. #define DWE_RX_STATUS_ETHERTYPE (1 << 5)
  84. #define DWE_RX_STATUS_LATE_COLLISION (1 << 6)
  85. //
  86. // If timestamping is enabled, this bit indicates the timestamp fields are
  87. // valid. If IP checksumming is enabled, this bit indicates that the IPv4
  88. // header checksum failed. Otherwise, this bit indicates the giant frame status.
  89. //
  90. #define DWE_RX_STATUS_TIMESTAMP_AVAILABLE (1 << 7)
  91. #define DWE_RX_STATUS_IP_CHECKSUM_ERROR (1 << 7)
  92. #define DWE_RX_STATUS_GIANT_FRAME (1 << 7)
  93. #define DWE_RX_STATUS_LAST_DESCRIPTOR (1 << 8)
  94. #define DWE_RX_STATUS_FIRST_DESCRIPTOR (1 << 9)
  95. #define DWE_RX_STATUS_VLAN (1 << 10)
  96. #define DWE_RX_STATUS_LENGTH_ERROR (1 << 11)
  97. #define DWE_RX_STATUS_SOURCE_FILTER_FAIL (1 << 13)
  98. #define DWE_RX_STATUS_DESCRIPTOR_ERROR (1 << 14)
  99. #define DWE_RX_STATUS_ERROR_SUMMARY (1 << 15)
  100. #define DWE_RX_STATUS_FRAME_LENGTH_SHIFT 16
  101. #define DWE_RX_STATUS_FRAME_LENGTH_MASK 0x3FFF
  102. #define DWE_RX_STATUS_DESTINATION_FILTER_FAIL (1 << 30)
  103. #define DWE_RX_STATUS_DMA_OWNED (1 << 31)
  104. #define DWE_RX_STATUS_ERROR_MASK \
  105. (DWE_RX_STATUS_LENGTH_ERROR | DWE_RX_STATUS_SOURCE_FILTER_FAIL | \
  106. DWE_RX_STATUS_DESCRIPTOR_ERROR | DWE_RX_STATUS_ERROR_SUMMARY | \
  107. DWE_RX_STATUS_DESTINATION_FILTER_FAIL)
  108. //
  109. // Define the generic descriptor buffer size bits.
  110. //
  111. #define DWE_BUFFER_SIZE_MASK 0x00000FFF
  112. #define DWE_BUFFER2_SHIFT 16
  113. //
  114. // Define the receive descriptor buffer size bits.
  115. //
  116. #define DWE_RX_SIZE_CHAINED (1 << 14)
  117. #define DWE_RX_SIZE_END_OF_RING (1 << 15)
  118. #define DWE_RX_SIZE_DISABLE_INTERRUPT (1 << 31)
  119. //
  120. // Define receive descriptor extended status bits.
  121. //
  122. #define DWE_RX_STATUS2_IP_PAYLOAD_TYPE_MASK 0x00000007
  123. #define DWE_RX_STATUS2_IP_PAYLOAD_NONE 0
  124. #define DWE_RX_STATUS2_IP_PAYLOAD_UDP 1
  125. #define DWE_RX_STATUS2_IP_PAYLOAD_TCP 2
  126. #define DWE_RX_STATUS2_IP_PAYLOAD_ICMP 3
  127. #define DWE_RX_STATUS2_IP_HEADER_ERROR (1 << 3)
  128. #define DWE_RX_STATUS2_IP_PAYLOAD_ERROR (1 << 4)
  129. #define DWE_RX_STATUS2_IP_CHECKSUM_BYPASSED (1 << 5)
  130. #define DWE_RX_STATUS2_IP4_PACKET_RECEIVED (1 << 6)
  131. #define DWE_RX_STATUS2_IP6_PACKET_RECEIVED (1 << 7)
  132. #define DWE_RX_STATUS2_MESSAGE_TYPE_MASK 0x00000F00
  133. #define DWE_RX_STATUS2_MESAGE_TYPE_SHIFT 8
  134. #define DWE_RX_STATUS2_MESSAGE_NONE 0
  135. #define DWE_RX_STATUS2_MESSAGE_SYNC 1
  136. #define DWE_RX_STATUS2_MESSAGE_FOLLOW_UP 2
  137. #define DWE_RX_STATUS2_MESSAGE_DELAY_REQUEST 3
  138. #define DWE_RX_STATUS2_MESSAGE_DELAY_RESPONSE 4
  139. #define DWE_RX_STATUS2_MESSAGE_PEER_DELAY_REQUEST 5
  140. #define DWE_RX_STATUS2_MESSAGE_PEER_DELAY_RESPONSE 6
  141. #define DWE_RX_STATUS2_MESSAGE_PEER_DELAY_FOLLOW_UP 7
  142. #define DWE_RX_STATUS2_MESSAGE_ANNOUNCE 8
  143. #define DWE_RX_STATUS2_MESSAGE_MANAGEMENT 9
  144. #define DWE_RX_STATUS2_MESSAGE_SIGNALING 10
  145. #define DWE_RX_STATUS2_MESSAGE_RESERVED 15
  146. #define DWE_RX_STATUS2_PTP_FRAME_TYPE (1 << 12)
  147. #define DWE_RX_STATUS2_PTP_VERSION (1 << 13)
  148. #define DWE_RX_STATUS2_TIMESTAMP_DROPPED (1 << 14)
  149. #define DWE_RX_STATUS2_LAYER_3_FILTER_MATCH (1 << 24)
  150. #define DWE_RX_STATUS2_LAYER_4_FILTER_MATCH (1 << 25)
  151. #define DWE_RX_STATUS2_LAYER_FILTER_MASK 0x00000003
  152. #define DWE_RX_STATUS2_LAYER_FILTER_SHIFT 26
  153. //
  154. // Define transmit descriptor control/status bits.
  155. //
  156. #define DWE_TX_CONTROL_DEFERRED (1 << 0)
  157. #define DWE_TX_CONTROL_UNDERFLOW_ERROR (1 << 1)
  158. #define DWE_TX_CONTROL_EXCESSIVE_DEFERRAL (1 << 2)
  159. #define DWE_TX_CONTROL_COLLISION_COUNT_MASK 0x0000000F
  160. #define DWE_TX_CONTROL_COLLISION_COUNT_SHIFT 3
  161. #define DWE_TX_CONTROL_VLAN (1 << 7)
  162. #define DWE_TX_CONTROL_EXCESSIVE_COLLISION (1 << 8)
  163. #define DWE_TX_CONTROL_NO_CARRIER (1 << 10)
  164. #define DWE_TX_CONTROL_LOST_CARRIER (1 << 11)
  165. #define DWE_TX_CONTROL_IP_PAYLOAD_ERROR (1 << 12)
  166. #define DWE_TX_CONTROL_FRAME_FLUSHED (1 << 13)
  167. #define DWE_TX_CONTROL_JABBER_TIMEOUT (1 << 14)
  168. #define DWE_TX_CONTROL_ERROR_SUMMARY (1 << 15)
  169. #define DWE_TX_CONTROL_IP_HEADER_ERROR (1 << 16)
  170. #define DWE_TX_CONTROL_TRANSMIT_TIMESTAMP_STATUS (1 << 17)
  171. #define DWE_TX_CONTROL_CHAINED (1 << 20)
  172. #define DWE_TX_CONTROL_END_OF_RING (1 << 21)
  173. #define DWE_TX_CONTROL_CHECKSUM_NONE (0x0 << 22)
  174. #define DWE_TX_CONTROL_CHECKSUM_IP_HEADER (0x1 << 22)
  175. #define DWE_TX_CONTROL_CHECKSUM_IP (0x2 << 22)
  176. #define DWE_TX_CONTROL_CHECKSUM_PSEUDOHEADER (0x3 << 22)
  177. #define DWE_TX_CONTROL_TRANSMIT_TIMESTAMP (1 << 25)
  178. #define DWE_TX_CONTROL_DISABLE_PAD (1 << 26)
  179. #define DWE_TX_CONTROL_DISABLE_CRC (1 << 27)
  180. #define DWE_TX_CONTROL_FIRST_SEGMENT (1 << 28)
  181. #define DWE_TX_CONTROL_LAST_SEGMENT (1 << 29)
  182. #define DWE_TX_CONTROL_INTERRUPT_ON_COMPLETE (1 << 30)
  183. #define DWE_TX_CONTROL_DMA_OWNED (1 << 31)
  184. #define DWE_TX_CONTROL_ERROR_MASK \
  185. (DWE_TX_CONTROL_UNDERFLOW_ERROR | DWE_TX_CONTROL_EXCESSIVE_DEFERRAL | \
  186. DWE_TX_CONTROL_EXCESSIVE_COLLISION | DWE_TX_CONTROL_NO_CARRIER | \
  187. DWE_TX_CONTROL_LOST_CARRIER | DWE_TX_CONTROL_IP_PAYLOAD_ERROR | \
  188. DWE_TX_CONTROL_JABBER_TIMEOUT | DWE_TX_CONTROL_ERROR_SUMMARY | \
  189. DWE_TX_CONTROL_IP_HEADER_ERROR)
  190. //
  191. // Define MAC configuration register bit definitions.
  192. //
  193. #define DWE_MAC_CONFIGURATION_7_BYTE_PREAMBLE (0x0 << 0)
  194. #define DWE_MAC_CONFIGURATION_5_BYTE_PREAMBLE (0x1 << 0)
  195. #define DWE_MAC_CONFIGURATION_3_BYTE_PREAMBLE (0x2 << 0)
  196. #define DWE_MAC_CONFIGURATION_RECEIVER_ENABLE (1 << 2)
  197. #define DWE_MAC_CONFIGURATION_TRANSMITTER_ENABLE (1 << 3)
  198. #define DWE_MAC_CONFIGURATION_DEFERRAL_CHECK (1 << 4)
  199. #define DWE_MAC_CONFIGURATION_BACKOFF_LIMIT_10 (0x0 << 5)
  200. #define DWE_MAC_CONFIGURATION_BACKOFF_LIMIT_8 (0x1 << 5)
  201. #define DWE_MAC_CONFIGURATION_BACKOFF_LIMIT_4 (0x2 << 5)
  202. #define DWE_MAC_CONFIGURATION_BACKOFF_LIMIT_1 (0x3 << 5)
  203. #define DWE_MAC_CONFIGURATION_AUTO_PAD_CRC_STRIPPING (1 << 7)
  204. #define DWE_MAC_CONFIGURATION_DISABLE_RETRY (1 << 9)
  205. #define DWE_MAC_CONFIGURATION_CHECKSUM_OFFLOAD (1 << 10)
  206. #define DWE_MAC_CONFIGURATION_DUPLEX_MODE (1 << 11)
  207. #define DWE_MAC_CONFIGURATION_LOOPBACK_MODE (1 << 12)
  208. #define DWE_MAC_CONFIGURATION_DISABLE_RECEIVE_OWN (1 << 13)
  209. #define DWE_MAC_CONFIGURATION_RMII_SPEED_100 (1 << 14)
  210. #define DWE_MAC_CONFIGURATION_RMII_NOT_GIGABIT (1 << 15)
  211. #define DWE_MAC_CONFIGURATION_DISABLE_CARRIER_SENSE_DURING_TX (1 << 16)
  212. #define DWE_MAC_CONFIGURATION_FRAME_GAP_96 (0x0 << 17)
  213. #define DWE_MAC_CONFIGURATION_FRAME_GAP_88 (0x1 << 17)
  214. #define DWE_MAC_CONFIGURATION_FRAME_GAP_80 (0x2 << 17)
  215. #define DWE_MAC_CONFIGURATION_FRAME_GAP_40 (0x7 << 17)
  216. #define DWE_MAC_CONFIGURATION_JUMBO_FRAME_ENABLE (1 << 20)
  217. #define DWE_MAC_CONFIGURATION_BURST_ENABLE (1 << 21)
  218. #define DWE_MAC_CONFIGURATION_JABBER_DISABLE (1 << 22)
  219. #define DWE_MAC_CONFIGURATION_WATCHDOG_DISABLE (1 << 23)
  220. #define DWE_MAC_CONFIGURATION_2K_FRAMES (1 << 27)
  221. #define DWE_MAC_CONFIGURATION_SOURCE_ADDRESS_REPLACE (0x3 << 28)
  222. //
  223. // Define MAC frame filter register bit definitions.
  224. //
  225. #define DWE_MAC_FRAME_FILTER_PROMISCUOUS (1 << 0)
  226. #define DWE_MAC_FRAME_FILTER_HASH_UNICAST (1 << 1)
  227. #define DWE_MAC_FRAME_FILTER_HASH_MULTICAST (1 << 2)
  228. #define DWE_MAC_FRAME_FILTER_DESTINATION_INVERSE_FILTERING (1 << 3)
  229. #define DWE_MAC_FRAME_FILTER_PASS_ALL_MULTICAST (1 << 4)
  230. #define DWE_MAC_FRAME_FILTER_DISABLE_BROADCAST_FRAMES (1 << 5)
  231. #define DWE_MAC_FRAME_FILTER_NO_CONTROL (0x0 << 6)
  232. #define DWE_MAC_FRAME_FILTER_ALL_CONTROL_NOT_PAUSE (0x1 << 6)
  233. #define DWE_MAC_FRAME_FILTER_ALL_CONTROL (0x2 << 6)
  234. #define DWE_MAC_FRAME_FILTER_PASS_CONTROL (0x3 << 6)
  235. #define DWE_MAC_FRAME_FILTER_SOURCE_INVERSE (1 << 8)
  236. #define DWE_MAC_FRAME_FILTER_SOURCE_ENABLE (1 << 9)
  237. #define DWE_MAC_FRAME_FILTER_HASH_OR_PERFECT (1 << 10)
  238. #define DWE_MAC_FRAME_FILTER_VLAN (1 << 16)
  239. #define DWE_MAC_FRAME_FILTER_PASS_ALL (1 << 31)
  240. //
  241. // Define GMII address register bit definitions.
  242. //
  243. #define DWE_GMII_ADDRESS_DEVICE_MASK 0x1F
  244. #define DWE_GMII_ADDRESS_DEVICE_SHIFT 11
  245. #define DWE_GMII_ADDRESS_REGISTER_MASK 0x1F
  246. #define DWE_GMII_ADDRESS_REGISTER_SHIFT 6
  247. #define DWE_GMII_ADDRESS_CLOCK_RANGE_MASK 0xF
  248. #define DWE_GMII_ADDRESS_CLOCK_RANGE_SHIFT 2
  249. #define DWE_GMII_ADDRESS_WRITE (1 << 1)
  250. #define DWE_GMII_ADDRESS_BUSY (1 << 0)
  251. //
  252. // Define bus mode register bit definitions.
  253. //
  254. #define DWE_BUS_MODE_SOFTWARE_RESET (1 << 0)
  255. #define DWE_BUS_MODE_DMA_ARBITRATION_FIXED (1 << 1)
  256. #define DWE_BUS_MODE_DESCRIPTOR_SKIP_LENGTH_MASK 0x0000001F
  257. #define DWE_BUS_MODE_DESCRIPTOR_SKIP_LENGTH_SHIFT 2
  258. #define DWE_BUS_MODE_LARGE_DESCRIPTORS (1 << 7)
  259. #define DWE_BUS_MODE_TX_BURST_LENGTH_MASK 0x0000001F
  260. #define DWE_BUS_MODE_TX_BURST_LENGTH_SHIFT 8
  261. #define DWE_BUS_MODE_PRIORITY_RATIO_MASK 0x00000003
  262. #define DWE_BUS_MODE_PRIORITY_RATIO_SHIFT 14
  263. #define DWE_BUS_MODE_FIXED_BURST (1 << 16)
  264. #define DWE_BUS_MODE_RX_BURST_LENGTH_MASK 0x0000001F
  265. #define DWE_BUS_MODE_RX_BURST_LENGTH_SHIFT 17
  266. #define DWE_BUS_MODE_USE_SEPARATE_BURST_LENGTHS (1 << 23)
  267. #define DWE_BUS_MODE_8X_BURST_LENGTHS (1 << 24)
  268. #define DWE_BUS_MODE_ADDRESS_ALIGNED_BEATS (1 << 25)
  269. #define DWE_BUS_MODE_MIXED_BURST (1 << 26)
  270. #define DWE_BUS_MODE_TRANSMIT_PRIORITY (1 << 27)
  271. #define DWE_BUS_MODE_CHANNEL_PRIORITY_WEIGHT_MASK 0x00000003
  272. #define DWE_BUS_MODE_CHANNEL_PRIORITY_WEIGHT_SHIFT 28
  273. #define DWE_BUS_MODE_REBUILD_REBUILD_INCR_BURST (1 << 31)
  274. //
  275. // Define default values used for the bus mode register.
  276. //
  277. #define DWE_BUS_MODE_TX_BURST_LENGTH 8
  278. //
  279. // Define operation mode register bit definitions.
  280. //
  281. #define DWE_OPERATION_MODE_START_RECEIVE (1 << 1)
  282. #define DWE_OPERATION_MODE_OPERATE_ON_SECOND_FRAME (1 << 2)
  283. #define DWE_OPERATION_MODE_RX_THRESHOLD_64 (0x0 << 3)
  284. #define DWE_OPERATION_MODE_RX_THRESHOLD_32 (0x1 << 3)
  285. #define DWE_OPERATION_MODE_RX_THRESHOLD_96 (0x2 << 3)
  286. #define DWE_OPERATION_MODE_RX_THRESHOLD_128 (0x3 << 3)
  287. #define DWE_OPERATION_MODE_FORWARD_UNDERSIZED_GOOD_FRAMES (1 << 6)
  288. #define DWE_OPERATION_MODE_FORWARD_ERROR_FRAMES (1 << 7)
  289. #define DWE_OPERATION_MODE_ENABLE_HW_FLOW_CONTROL (1 << 8)
  290. #define DWE_OPERATION_MODE_ACTIVATE_FLOW_CONTROL_SHIFT 9
  291. #define DWE_OPERATION_MODE_DEACTIVATE_FLOW_CONTROL_SHIFT 11
  292. #define DWE_OPERATION_MODE_FLOW_FULL_MINUS_1KB 0
  293. #define DWE_OPERATION_MODE_FLOW_FULL_MINUS_2KB 1
  294. #define DWE_OPERATION_MODE_FLOW_FULL_MINUS_3KB 2
  295. #define DWE_OPERATION_MODE_FLOW_FULL_MINUS_4KB 3
  296. #define DWE_OPERATION_MODE_START_TRANSMIT (1 << 13)
  297. #define DWE_OPERATION_MODE_TX_THRESHOLD_64 (0x0 << 14)
  298. #define DWE_OPERATION_MODE_TX_THRESHOLD_128 (0x1 << 14)
  299. #define DWE_OPERATION_MODE_TX_THRESHOLD_192 (0x2 << 14)
  300. #define DWE_OPERATION_MODE_TX_THRESHOLD_256 (0x3 << 14)
  301. #define DWE_OPERATION_MODE_TX_THRESHOLD_40 (0x4 << 14)
  302. #define DWE_OPERATION_MODE_TX_THRESHOLD_32 (0x5 << 14)
  303. #define DWE_OPERATION_MODE_TX_THRESHOLD_24 (0x6 << 14)
  304. #define DWE_OPERATION_MODE_TX_THRESHOLD_16 (0x7 << 14)
  305. #define DWE_OPERATION_MODE_FLUSH_TX_FIFO (1 << 20)
  306. #define DWE_OPERATION_MODE_TX_STORE_AND_FORWARD (1 << 21)
  307. #define DWE_OPERATION_MODE_DEACTIVATE_FLOW_CONTROL_HIGH (1 << 22)
  308. #define DWE_OPERATION_MODE_ACTIVATE_FLOW_CONTROL_HIGH (1 << 23)
  309. #define DWE_OPERATION_MODE_DISABLE_FLUSHING_RECEIVED_FRAMES (1 << 24)
  310. #define DWE_OPERATION_MODE_RX_STORE_AND_FORWARD (1 << 25)
  311. #define DWE_OPERATION_MODE_DISABLE_DROPPING_CHECKSUM_FAILURES (1 << 26)
  312. //
  313. // Define interrupt enable register bit definitions.
  314. //
  315. #define DWE_INTERRUPT_ENABLE_TX (1 << 0)
  316. #define DWE_INTERRUPT_ENABLE_TX_STOPPED (1 << 1)
  317. #define DWE_INTERRUPT_ENABLE_TX_BUFFER_UNAVAILABLE (1 << 2)
  318. #define DWE_INTERRUPT_ENABLE_TX_JABBER_TIMEOUT (1 << 3)
  319. #define DWE_INTERRUPT_ENABLE_OVERFLOW (1 << 4)
  320. #define DWE_INTERRUPT_ENABLE_UNDERFLOW (1 << 5)
  321. #define DWE_INTERRUPT_ENABLE_RX (1 << 6)
  322. #define DWE_INTERRUPT_ENABLE_RX_BUFFER_UNAVAILABLE (1 << 7)
  323. #define DWE_INTERRUPT_ENABLE_RX_STOPPED (1 << 8)
  324. #define DWE_INTERRUPT_ENABLE_RX_WATCHDOG_TIMEOUT (1 << 9)
  325. #define DWE_INTERRUPT_ENABLE_EARLY_TX (1 << 10)
  326. #define DWE_INTERRUPT_ENABLE_FATAL_BUS_ERROR (1 << 13)
  327. #define DWE_INTERRUPT_ENABLE_EARLY_RX (1 << 14)
  328. #define DWE_INTERRUPT_ENABLE_ABNORMAL_SUMMARY (1 << 15)
  329. #define DWE_INTERRUPT_ENABLE_NORMAL_SUMMARY (1 << 16)
  330. #define DWE_INTERRUPT_ENABLE_DEFAULT \
  331. (DWE_INTERRUPT_ENABLE_TX | DWE_INTERRUPT_ENABLE_RX | \
  332. DWE_INTERRUPT_ENABLE_ABNORMAL_SUMMARY | \
  333. DWE_INTERRUPT_ENABLE_NORMAL_SUMMARY | \
  334. DWE_INTERRUPT_ENABLE_FATAL_BUS_ERROR | \
  335. DWE_INTERRUPT_ENABLE_UNDERFLOW)
  336. //
  337. // Define DMA status register bit definitions.
  338. //
  339. #define DWE_STATUS_TRANSMIT_INTERRUPT (1 << 0)
  340. #define DWE_STATUS_TRANSMIT_STOPPED (1 << 1)
  341. #define DWE_STATUS_TRANSMIT_BUFFER_UNAVAILABLE (1 << 2)
  342. #define DWE_STATUS_TRANSMIT_JABBER_TIMEOUT (1 << 3)
  343. #define DWE_STATUS_RECEIVE_OVERFLOW (1 << 4)
  344. #define DWE_STATUS_TRANSMIT_UNDERFLOW (1 << 5)
  345. #define DWE_STATUS_RECEIVE_INTERRUPT (1 << 6)
  346. #define DWE_STATUS_RECEIVE_BUFFER_UNAVAILABLE (1 << 7)
  347. #define DWE_STATUS_RECEIVE_STOPPED (1 << 8)
  348. #define DWE_STATUS_RECEIVE_WATCHDOG_TIMEOUT (1 << 9)
  349. #define DWE_STATUS_EARLY_TRANSMIT_INTERRUPT (1 << 10)
  350. #define DWE_STATUS_FATAL_BUS_ERROR_INTERRUPT (1 << 13)
  351. #define DWE_STATUS_EARLY_RECEIVE_INTERRUPT (1 << 14)
  352. #define DWE_STATUS_ABNORMAL_INTERRUPT_SUMMARY (1 << 15)
  353. #define DWE_STATUS_NORMAL_INTERRUPT_SUMMARY (1 << 16)
  354. #define DWE_STATUS_RECEIVE_STATE_MASK 0x0000007
  355. #define DWE_STATUS_RECEIVE_STATE_SHIFT 17
  356. #define DWE_STATUS_TRANSMIT_STATE_MASK 0x0000007
  357. #define DWE_STATUS_TRANSMIT_STATE_SHIFT 20
  358. #define DWE_STATUS_ERROR_BITS_MASK 0x0000007
  359. #define DWE_STATUS_ERROR_BITS_SHIFT 23
  360. #define DWE_STATUS_MAC_MMC_INTERRUPT (1 << 27)
  361. #define DWE_STATUS_TIMESTAMP_TRIGGER_INTERRUPT (1 << 28)
  362. #define DWE_STATUS_ERROR_MASK \
  363. (DWE_STATUS_TRANSMIT_JABBER_TIMEOUT | DWE_STATUS_RECEIVE_OVERFLOW | \
  364. DWE_STATUS_TRANSMIT_UNDERFLOW | DWE_STATUS_RECEIVE_WATCHDOG_TIMEOUT | \
  365. DWE_STATUS_FATAL_BUS_ERROR_INTERRUPT | \
  366. DWE_STATUS_ABNORMAL_INTERRUPT_SUMMARY)
  367. //
  368. // Define receive interrupt mask register bit definitions.
  369. //
  370. #define DWE_RECEIVE_INTERRUPT_MASK 0x03FFFFFF
  371. //
  372. // Define transmit interrupt mask register bit definitions.
  373. //
  374. #define DWE_TRANSMIT_INTERRUPT_MASK 0x03FFFFFF
  375. //
  376. // Define receive checksum offload interrupt register bit definitions.
  377. //
  378. #define DWE_RECEIVE_CHECKSUM_INTERRUPT_MASK 0x3FFF3FFF
  379. //
  380. // ------------------------------------------------------ Data Type Definitions
  381. //
  382. typedef enum _DWE_REGISTER {
  383. DweRegisterMacConfiguration = 0x0000,
  384. DweRegisterMacFrameFilter = 0x0004,
  385. DweRegisterHashTableHigh = 0x0008,
  386. DweRegisterHashTableLow = 0x000C,
  387. DweRegisterGmiiAddress = 0x0010,
  388. DweRegisterGmiiData = 0x0014,
  389. DweRegisterFlowControl = 0x0018,
  390. DweRegisterVlanTag = 0x001C,
  391. DweRegisterVersion = 0x0020,
  392. DweRegisterDebug = 0x0024,
  393. DweRegisterInterrupt = 0x0038,
  394. DweRegisterInterruptMask = 0x003C,
  395. DweRegisterMacAddress0High = 0x0040,
  396. DweRegisterMacAddress0Low = 0x0044,
  397. DweRegisterMmcControl = 0x0100,
  398. DweRegisterMmcReceiveInterrupt = 0x0104,
  399. DweRegisterMmcTransmitInterrupt = 0x0108,
  400. DweRegisterMmcReceiveInterruptMask = 0x010C,
  401. DweRegisterMmcTransmitInterruptMask = 0x0110,
  402. DweRegisterReceiveChecksumOffloadInterruptMask = 0x0200,
  403. DweRegisterReceiveChecksumOffloadInterrupt = 0x0208,
  404. DweRegisterVlanTagInclusionReplacement = 0x584,
  405. DweRegisterVlanHashTable = 0x588,
  406. DweRegisterTimestampControl = 0x0700,
  407. DweRegisterSubSecondIncrement = 0x0704,
  408. DweRegisterSystemTimeSeconds = 0x0708,
  409. DweRegisterSystemTimeNanoseconds = 0x070C,
  410. DweRegisterSystemTimeSecondsUpdate = 0x0710,
  411. DweRegisterSystemTimeNanosecondsUpdate = 0x714,
  412. DweRegisterTimestampAddend = 0x0718,
  413. DweRegisterTargetTimeSeconds = 0x071C,
  414. DweRegisterTargetTimeNanoseconds = 0x0720,
  415. DweRegisterSystemTimeHigherWordSeconds = 0x0724,
  416. DweRegisterTimestampStatus = 0x0728,
  417. DweRegisterBusMode = 0x1000,
  418. DweRegisterTransmitPollDemand = 0x1004,
  419. DweRegisterReceivePollDemand = 0x1008,
  420. DweRegisterReceiveDescriptorListAddress = 0x100C,
  421. DweRegisterTransmitDescriptorListAddress = 0x1010,
  422. DweRegisterStatus = 0x1014,
  423. DweRegisterOperationMode = 0x1018,
  424. DweRegisterInterruptEnable = 0x101C,
  425. DweRegisterMissedFrameAndBufferOverflowCount = 0x1020,
  426. DweRegisterReceiveInterruptWatchdogTimer = 0x1024,
  427. DweRegisterAhbStatus = 0x102C,
  428. DweRegisterCurrentHostTransmitDescriptor = 0x1048,
  429. DweRegisterCurrentHostReceiveDescriptor = 0x104C,
  430. DweRegisterCurrentHostTransmitBufferAddress = 0x1050,
  431. DweRegisterCurrentHostReceiveBufferAddress = 0x1054,
  432. DweRegisterHardwareFeature = 0x1058
  433. } DWE_REGISTER, *PDWE_REGISTER;
  434. /*++
  435. Structure Description:
  436. This structure defines the DesignWare Ethernet controller transmit and
  437. receive descriptor format, as defined by the hardware.
  438. Members:
  439. Control - Stores control and/or status bits.
  440. BufferSize - Stores the sizes of one (or both) buffers the descriptor is
  441. describing.
  442. Address1 - Stores the physical address of the first buffer.
  443. Address2OrNextDescriptor - Stores either the physical address of the second
  444. buffer in "ring mode" or the physical address of the next transmit
  445. descriptor in "chain mode".
  446. ExtendedStatus - Stores extended status bits for receive descriptors. For
  447. transmit descriptors, this field is reserved.
  448. Reserved - Stores reserved regions.
  449. Timestamp - Stores the hardware timestamp when the packet was sent or
  450. received if timestamping is enabled.
  451. --*/
  452. typedef struct _DWE_DESCRIPTOR {
  453. ULONG Control;
  454. ULONG BufferSize;
  455. ULONG Address1;
  456. ULONG Address2OrNextDescriptor;
  457. ULONG ExtendedStatus;
  458. ULONG Reserved;
  459. ULONGLONG Timestamp;
  460. } PACKED DWE_DESCRIPTOR, *PDWE_DESCRIPTOR;
  461. /*++
  462. Structure Description:
  463. This structure defines an DesignWare Ethernet controller device.
  464. Members:
  465. OsDevice - Stores a pointer to the OS device object.
  466. InterruptLine - Stores the interrupt line that this controller's interrupt
  467. comes in on.
  468. InterruptVector - Stores the interrupt vector that this controller's
  469. interrupt comes in on.
  470. InterruptResourcesFound - Stores a boolean indicating whether or not the
  471. interrupt line and interrupt vector fields are valid.
  472. InterruptHandle - Stores a pointer to the handle received when the
  473. interrupt was connected.
  474. ControllerBase - Stores the virtual address of the memory mapping to the
  475. controller's registers.
  476. NetworkLink - Stores a pointer to the core networking link.
  477. ReceiveDataIoBuffer - Stores a pointer to the I/O buffer associated with
  478. the receive frames.
  479. ReceiveData - Stores the pointer to the array of receive frames.
  480. ReceiveBegin - Stores the index of the beginning of the list, which is
  481. the oldest received frame and the first one to dispatch.
  482. ReceiveLock - Stores a pointer to a queued lock that protects the
  483. received list.
  484. CommandPhysicalAddress - Stores the physical address of the base of the
  485. command list (called a list but is really an array).
  486. DescriptorIoBuffer - Stores a pointer to the I/O buffer associated with
  487. the command block list.
  488. TransmitDescriptors - Stores the virtual address of the array of transmit
  489. descriptors.
  490. ReceiveDescriptors - Stores the virtual address of the array of receive
  491. descriptors.
  492. TransmitPacket - Stores a pointer to the array of net packet buffers that
  493. go with each command.
  494. TransmitPacketList - Stores a list of network packets waiting to be sent.
  495. TransmitBegin - Stores the index of the least recent command, the first
  496. one to reap.
  497. TransmitEnd - Stores the index where the next command should be placed.
  498. TransmitLock - Stores the lock protecting software access to the transmit
  499. descriptors.
  500. CommandEntryFreeEvent - Stores the event to wait on in the event that no
  501. command entries are free.
  502. LinkActive - Stores a boolean indicating if there is an active network link.
  503. LinkSpeed - Stores the current link speed, if active.
  504. FullDuplex - Stores the duplex status of the link, TRUE for full duplex and
  505. FALSE for half duplex.
  506. LinkCheckTimer - Stores a pointer to the timer that fires periodically to
  507. see if the link is active.
  508. LinkCheckDpc - Stores a pointer to the DPC associated with the link check
  509. timer.
  510. NextLinkCheck - Stores the time counter value when the next link check
  511. should be performed.
  512. LinkCheckInterval - Stores the interval in time counter ticks that the
  513. link state should be polled.
  514. WorkItem - Stores a pointer to the work item queued from the DPC.
  515. PendingStatusBits - Stores the bitfield of status bits that have yet to be
  516. dealt with by software.
  517. MacAddressAssigned - Stores a boolean indicating if the MAC address matter
  518. has been settled.
  519. MacAddress - Stores the default MAC address of the device.
  520. PhyId - Stores the address of the PHY.
  521. DroppedTxPackets - Stores the number of packets that were dropped from
  522. being transmitted because there were no descriptors available. This is
  523. a sign that more descriptors should be allocated.
  524. ChecksumFlags - Stores the current checksum offloading options.
  525. --*/
  526. typedef struct _DWE_DEVICE {
  527. PDEVICE OsDevice;
  528. ULONGLONG InterruptLine;
  529. ULONGLONG InterruptVector;
  530. BOOL InterruptResourcesFound;
  531. HANDLE InterruptHandle;
  532. PVOID ControllerBase;
  533. PNET_LINK NetworkLink;
  534. PIO_BUFFER ReceiveDataIoBuffer;
  535. PVOID ReceiveData;
  536. ULONG ReceiveBegin;
  537. PQUEUED_LOCK ReceiveLock;
  538. PIO_BUFFER DescriptorIoBuffer;
  539. PDWE_DESCRIPTOR TransmitDescriptors;
  540. PDWE_DESCRIPTOR ReceiveDescriptors;
  541. PNET_PACKET_BUFFER *TransmitPacket;
  542. NET_PACKET_LIST TransmitPacketList;
  543. ULONG TransmitBegin;
  544. ULONG TransmitEnd;
  545. PQUEUED_LOCK TransmitLock;
  546. BOOL LinkActive;
  547. ULONGLONG LinkSpeed;
  548. BOOL FullDuplex;
  549. PKTIMER LinkCheckTimer;
  550. PDPC LinkCheckDpc;
  551. ULONGLONG NextLinkCheck;
  552. ULONGLONG LinkCheckInterval;
  553. PWORK_ITEM WorkItem;
  554. volatile ULONG PendingStatusBits;
  555. BOOL MacAddressAssigned;
  556. BYTE MacAddress[ETHERNET_ADDRESS_SIZE];
  557. ULONG PhyId;
  558. UINTN DroppedTxPackets;
  559. ULONG ChecksumFlags;
  560. } DWE_DEVICE, *PDWE_DEVICE;
  561. //
  562. // -------------------------------------------------------------------- Globals
  563. //
  564. //
  565. // -------------------------------------------------------- Function Prototypes
  566. //
  567. KSTATUS
  568. DweSend (
  569. PVOID DeviceContext,
  570. PNET_PACKET_LIST PacketList
  571. );
  572. /*++
  573. Routine Description:
  574. This routine sends data through the network.
  575. Arguments:
  576. DeviceContext - Supplies a pointer to the device context associated with
  577. the link down which this data is to be sent.
  578. PacketList - Supplies a pointer to a list of network packets to send. Data
  579. in these packets may be modified by this routine, but must not be used
  580. once this routine returns.
  581. Return Value:
  582. STATUS_SUCCESS if all packets were sent.
  583. STATUS_RESOURCE_IN_USE if some or all of the packets were dropped due to
  584. the hardware being backed up with too many packets to send.
  585. Other failure codes indicate that none of the packets were sent.
  586. --*/
  587. KSTATUS
  588. DweGetSetInformation (
  589. PVOID DeviceContext,
  590. NET_LINK_INFORMATION_TYPE InformationType,
  591. PVOID Data,
  592. PUINTN DataSize,
  593. BOOL Set
  594. );
  595. /*++
  596. Routine Description:
  597. This routine gets or sets the network device layer's link information.
  598. Arguments:
  599. DeviceContext - Supplies a pointer to the device context associated with
  600. the link for which information is being set or queried.
  601. InformationType - Supplies the type of information being queried or set.
  602. Data - Supplies a pointer to the data buffer where the data is either
  603. returned for a get operation or given for a set operation.
  604. DataSize - Supplies a pointer that on input contains the size of the data
  605. buffer. On output, contains the required size of the data buffer.
  606. Set - Supplies a boolean indicating if this is a get operation (FALSE) or a
  607. set operation (TRUE).
  608. Return Value:
  609. Status code.
  610. --*/
  611. KSTATUS
  612. DwepInitializeDeviceStructures (
  613. PDWE_DEVICE Device
  614. );
  615. /*++
  616. Routine Description:
  617. This routine creates the data structures needed for a DesignWare Ethernet
  618. controller.
  619. Arguments:
  620. Device - Supplies a pointer to the device.
  621. Return Value:
  622. Status code.
  623. --*/
  624. KSTATUS
  625. DwepResetDevice (
  626. PDWE_DEVICE Device
  627. );
  628. /*++
  629. Routine Description:
  630. This routine resets the DesignWare Ethernet device.
  631. Arguments:
  632. Device - Supplies a pointer to the device.
  633. Return Value:
  634. Status code.
  635. --*/
  636. INTERRUPT_STATUS
  637. DwepInterruptService (
  638. PVOID Context
  639. );
  640. /*++
  641. Routine Description:
  642. This routine implements the DesignWare Ethernet interrupt service routine.
  643. Arguments:
  644. Context - Supplies the context pointer given to the system when the
  645. interrupt was connected. In this case, this points to the e100 device
  646. structure.
  647. Return Value:
  648. Interrupt status.
  649. --*/
  650. INTERRUPT_STATUS
  651. DwepInterruptServiceWorker (
  652. PVOID Parameter
  653. );
  654. /*++
  655. Routine Description:
  656. This routine processes interrupts for the DesignWare Ethernet controller at
  657. low level.
  658. Arguments:
  659. Parameter - Supplies an optional parameter passed in by the creator of the
  660. work item.
  661. Return Value:
  662. Interrupt status.
  663. --*/
  664. KSTATUS
  665. DwepAddNetworkDevice (
  666. PDWE_DEVICE Device
  667. );
  668. /*++
  669. Routine Description:
  670. This routine adds the device to core networking's available links.
  671. Arguments:
  672. Device - Supplies a pointer to the device to add.
  673. Return Value:
  674. Status code.
  675. --*/