e1000e.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #include <defs.hpp>
  2. namespace hw::e1000e {
  3. // Register names
  4. // Control register
  5. constexpr u32 REG_CTRL = 0x00000;
  6. // Status register
  7. constexpr u32 REG_STATUS = 0x00008;
  8. // Interrupt cause register
  9. constexpr u32 REG_ICR = 0x000C0;
  10. // Interrupt mask set/clear register
  11. constexpr u32 REG_IMS = 0x000D0;
  12. // Interrupt mask clear register
  13. constexpr u32 REG_IMC = 0x000D8;
  14. // Receive control
  15. constexpr u32 REG_RCTL = 0x00100;
  16. // These registers are per-queue
  17. // Receive descriptor base address low
  18. constexpr u32 REG_RDBAL = 0x02800;
  19. // Receive descriptor base address high
  20. constexpr u32 REG_RDBAH = 0x02804;
  21. // Receive descriptor length
  22. constexpr u32 REG_RDLEN = 0x02808;
  23. // Receive descriptor head
  24. constexpr u32 REG_RDH = 0x02810;
  25. // Receive descriptor tail
  26. constexpr u32 REG_RDT = 0x02818;
  27. // Receive descriptor control
  28. constexpr u32 REG_RXDCTL = 0x02828;
  29. // Transmit control
  30. constexpr u32 REG_TCTL = 0x00400;
  31. // These registers are per-queue
  32. // Transmit descriptor base address low
  33. constexpr u32 REG_TDBAL = 0x03800;
  34. // Transmit descriptor base address high
  35. constexpr u32 REG_TDBAH = 0x03804;
  36. // Transmit descriptor length
  37. constexpr u32 REG_TDLEN = 0x03808;
  38. // Transmit descriptor head
  39. constexpr u32 REG_TDH = 0x03810;
  40. // Transmit descriptor tail
  41. constexpr u32 REG_TDT = 0x03818;
  42. // Transmit descriptor control
  43. constexpr u32 REG_TXDCTL = 0x03828;
  44. // Collision counter
  45. constexpr u32 REG_COLC = 0x04028;
  46. // Good packets received counter
  47. constexpr u32 REG_GPRC = 0x04074;
  48. // Multicast packets received counter
  49. constexpr u32 REG_MPRC = 0x0407C;
  50. // Good packets transmitted counter
  51. constexpr u32 REG_GPTC = 0x04080;
  52. // Good octets received counter low
  53. constexpr u32 REG_GORCL = 0x04088;
  54. // Good octets received counter high
  55. constexpr u32 REG_GORCH = 0x0408C;
  56. // Good octets transmitted counter low
  57. constexpr u32 REG_GOTCL = 0x04090;
  58. // Good octets transmitted counter high
  59. constexpr u32 REG_GOTCH = 0x04094;
  60. // Full-duplex
  61. constexpr u32 CTRL_FD = 0x00000001;
  62. // GIO master disable
  63. constexpr u32 CTRL_GIOD = 0x00000004;
  64. // Set link up
  65. constexpr u32 CTRL_SLU = 0x00000040;
  66. // Software reset
  67. constexpr u32 CTRL_RST = 0x04000000;
  68. // Receive flow control enable
  69. constexpr u32 CTRL_RFCE = 0x08000000;
  70. // Transmit flow control enable
  71. constexpr u32 CTRL_TFCE = 0x10000000;
  72. // Full-duplex
  73. constexpr u32 STATUS_FD = 0x00000001;
  74. // Link up
  75. constexpr u32 STATUS_LU = 0x00000002;
  76. // Transmit paused
  77. constexpr u32 STATUS_TXOFF = 0x00000010;
  78. // Link speed settings
  79. constexpr u32 STATUS_SPEED_MASK = 0x000000C0;
  80. constexpr u32 STATUS_SPEED_10M = 0x00000000;
  81. constexpr u32 STATUS_SPEED_100M = 0x00000040;
  82. constexpr u32 STATUS_SPEED_1000M = 0x00000080;
  83. // GIO master enable
  84. constexpr u32 STATUS_GIOE = 0x00080000;
  85. // Receive control enable
  86. constexpr u32 RCTL_EN = 0x00000002;
  87. // Store bad packets
  88. constexpr u32 RCTL_SBP = 0x00000004;
  89. // Unicast promiscuous mode
  90. constexpr u32 RCTL_UPE = 0x00000008;
  91. // Multicast promiscuous mode
  92. constexpr u32 RCTL_MPE = 0x00000010;
  93. // Long packet enable
  94. constexpr u32 RCTL_LPE = 0x00000020;
  95. // Loopback mode
  96. constexpr u32 RCTL_LBM_MASK = 0x000000C0;
  97. constexpr u32 RCTL_LBM_NO = 0x00000000;
  98. constexpr u32 RCTL_LBM_MAC = 0x00000040;
  99. // Receive descriptor minimum threshold size
  100. constexpr u32 RCTL_RDMTS_MASK = 0x00000300;
  101. constexpr u32 RCTL_RDMTS_HALF = 0x00000000;
  102. constexpr u32 RCTL_RDMTS_QUARTER = 0x00000100;
  103. constexpr u32 RCTL_RDMTS_EIGHTH = 0x00000200;
  104. // Receive descriptor type
  105. constexpr u32 RCTL_DTYP_MASK = 0x00000C00;
  106. constexpr u32 RCTL_DTYP_LEGACY = 0x00000000;
  107. constexpr u32 RCTL_DTYP_SPLIT = 0x00000400;
  108. // Multicast offset
  109. constexpr u32 RCTL_MO_MASK = 0x00003000;
  110. // Broadcast accept mode
  111. constexpr u32 RCTL_BAM = 0x00008000;
  112. // Receive buffer size
  113. constexpr u32 RCTL_BSIZE_MASK = 0x00030000;
  114. constexpr u32 RCTL_BSIZE_2048 = 0x00000000;
  115. constexpr u32 RCTL_BSIZE_1024 = 0x00010000;
  116. constexpr u32 RCTL_BSIZE_512 = 0x00020000;
  117. constexpr u32 RCTL_BSIZE_256 = 0x00030000;
  118. // VLAN filter enable
  119. constexpr u32 RCTL_VFE = 0x00040000;
  120. // Canonical form indicator enable
  121. constexpr u32 RCTL_CFIEN = 0x00080000;
  122. // Canonical form indicator bit value
  123. constexpr u32 RCTL_CFI = 0x00100000;
  124. // Discard pause frames
  125. constexpr u32 RCTL_DPF = 0x00400000;
  126. // Pass MAC control frames
  127. constexpr u32 RCTL_PMCF = 0x00800000;
  128. // Buffer size extension
  129. constexpr u32 RCTL_BSEX = 0x02000000;
  130. // Strip Ethernet CRC
  131. constexpr u32 RCTL_SECRC = 0x04000000;
  132. // Flexible buffer size
  133. constexpr u32 RCTL_FLXBUF_MASK = 0x78000000;
  134. constexpr u32 RCTL_BSIZE_16384 = (RCTL_BSIZE_1024 | RCTL_BSEX);
  135. constexpr u32 RCTL_BSIZE_8192 = (RCTL_BSIZE_512 | RCTL_BSEX);
  136. constexpr u32 RCTL_BSIZE_4096 = (RCTL_BSIZE_256 | RCTL_BSEX);
  137. // Transmit control enable
  138. constexpr u32 TCTL_EN = 0x00000002;
  139. // Pad short packets
  140. constexpr u32 TCTL_PSP = 0x00000008;
  141. // Collision threshold
  142. constexpr u32 TCTL_CT_MASK = 0x00000ff0;
  143. constexpr u32 TCTL_CT_SHIFT = 4;
  144. // Collision distance
  145. constexpr u32 TCTL_COLD_MASK = 0x003ff000;
  146. constexpr u32 TCTL_COLD_SHIFT = 12;
  147. // Software XOFF transmission
  148. constexpr u32 TCTL_SWXOFF = 0x00400000;
  149. // Packet burst enable
  150. constexpr u32 TCTL_PBE = 0x00800000;
  151. // Re-transmit on late collision
  152. constexpr u32 TCTL_RTLC = 0x01000000;
  153. // Transmit descriptor written back
  154. constexpr u32 ICR_TXDW = 0x00000001;
  155. // Link status change
  156. constexpr u32 ICR_LSC = 0x00000004;
  157. // Receive sequence error
  158. constexpr u32 ICR_RXSEQ = 0x00000008;
  159. // Receive descriptor minimum threshold
  160. constexpr u32 ICR_RXDMT0 = 0x00000010;
  161. // Receive overrun
  162. constexpr u32 ICR_RXO = 0x00000040;
  163. // Receive timer expired
  164. constexpr u32 ICR_RXT0 = 0x00000080;
  165. // MDIO access complete
  166. constexpr u32 ICR_MDAC = 0x00000200;
  167. // Transmit descriptor low minimum threshold
  168. constexpr u32 ICR_TXD_LOW = 0x00008000;
  169. // Small packet received
  170. constexpr u32 ICR_SRPD = 0x00010000;
  171. // ACK frame received
  172. constexpr u32 ICR_ACK = 0x0020000;
  173. // Management frame received
  174. constexpr u32 ICR_MNG = 0x0040000;
  175. // Other interrupt
  176. constexpr u32 ICR_OTHER = 0x01000000;
  177. // Interrupt asserted
  178. constexpr u32 ICR_INT = 0x80000000;
  179. constexpr u32 ICR_NORMAL =
  180. (ICR_LSC | ICR_RXO | ICR_MDAC | ICR_SRPD | ICR_ACK | ICR_MNG);
  181. constexpr u32 ICR_UP = (ICR_TXDW | ICR_RXSEQ | ICR_RXDMT0 | ICR_RXT0);
  182. struct RxDescriptor {
  183. u64 bufferAddress;
  184. u16 length;
  185. u16 volatile csum; // Checksum
  186. u8 volatile status;
  187. u8 volatile errors;
  188. u16 vlan;
  189. };
  190. // Descriptor done
  191. constexpr u8 RXD_STAT_DD = 0x01;
  192. struct TxDescriptor {
  193. u64 bufferAddress;
  194. u16 length;
  195. u8 cso; // Checksum offset
  196. u8 cmd;
  197. u8 volatile status;
  198. u8 css; // Checksum start
  199. u16 vlan;
  200. };
  201. // Descriptor done
  202. constexpr u8 TXD_STAT_DD = 0x01;
  203. // End of packet
  204. constexpr u8 TXD_CMD_EOP = 0x01;
  205. // Insert FCS
  206. constexpr u8 TXD_CMD_IFCS = 0x02;
  207. // Report status
  208. constexpr u8 TXD_CMD_RS = 0x08;
  209. } // namespace hw::e1000e