You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

intel.h 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #ifndef _INTEL_H
  2. #define _INTEL_H
  3. /** @file
  4. *
  5. * Intel 10/100/1000 network card driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <ipxe/if_ether.h>
  11. #include <ipxe/nvs.h>
  12. /** Intel BAR size */
  13. #define INTEL_BAR_SIZE ( 128 * 1024 )
  14. /** A packet descriptor */
  15. struct intel_descriptor {
  16. /** Buffer address */
  17. uint64_t address;
  18. /** Length */
  19. uint16_t length;
  20. /** Reserved */
  21. uint8_t reserved_a;
  22. /** Command */
  23. uint8_t command;
  24. /** Status */
  25. uint8_t status;
  26. /** Errors */
  27. uint8_t errors;
  28. /** Reserved */
  29. uint16_t reserved_b;
  30. } __attribute__ (( packed ));
  31. /** Packet descriptor command bits */
  32. enum intel_descriptor_command {
  33. /** Report status */
  34. INTEL_DESC_CMD_RS = 0x08,
  35. /** Insert frame checksum (CRC) */
  36. INTEL_DESC_CMD_IFCS = 0x02,
  37. /** End of packet */
  38. INTEL_DESC_CMD_EOP = 0x01,
  39. };
  40. /** Packet descriptor status bits */
  41. enum intel_descriptor_status {
  42. /** Descriptor done */
  43. INTEL_DESC_STATUS_DD = 0x01,
  44. };
  45. /** Device Control Register */
  46. #define INTEL_CTRL 0x00000UL
  47. #define INTEL_CTRL_LRST 0x00000008UL /**< Link reset */
  48. #define INTEL_CTRL_ASDE 0x00000020UL /**< Auto-speed detection */
  49. #define INTEL_CTRL_SLU 0x00000040UL /**< Set link up */
  50. #define INTEL_CTRL_FRCSPD 0x00000800UL /**< Force speed */
  51. #define INTEL_CTRL_FRCDPLX 0x00001000UL /**< Force duplex */
  52. #define INTEL_CTRL_RST 0x04000000UL /**< Device reset */
  53. #define INTEL_CTRL_PHY_RST 0x80000000UL /**< PHY reset */
  54. /** Time to delay for device reset, in milliseconds */
  55. #define INTEL_RESET_DELAY_MS 20
  56. /** Device Status Register */
  57. #define INTEL_STATUS 0x00008UL
  58. #define INTEL_STATUS_LU 0x00000002UL /**< Link up */
  59. /** EEPROM Read Register */
  60. #define INTEL_EERD 0x00014UL
  61. #define INTEL_EERD_START 0x00000001UL /**< Start read */
  62. #define INTEL_EERD_DONE_SMALL 0x00000010UL /**< Read done (small EERD) */
  63. #define INTEL_EERD_DONE_LARGE 0x00000002UL /**< Read done (large EERD) */
  64. #define INTEL_EERD_ADDR_SHIFT_SMALL 8 /**< Address shift (small) */
  65. #define INTEL_EERD_ADDR_SHIFT_LARGE 2 /**< Address shift (large) */
  66. #define INTEL_EERD_DATA(value) ( (value) >> 16 ) /**< Read data */
  67. /** Maximum time to wait for EEPROM read, in milliseconds */
  68. #define INTEL_EEPROM_MAX_WAIT_MS 100
  69. /** EEPROM word length */
  70. #define INTEL_EEPROM_WORD_LEN_LOG2 1
  71. /** Minimum EEPROM size, in words */
  72. #define INTEL_EEPROM_MIN_SIZE_WORDS 64
  73. /** Offset of MAC address within EEPROM */
  74. #define INTEL_EEPROM_MAC 0x00
  75. /** Interrupt Cause Read Register */
  76. #define INTEL_ICR 0x000c0UL
  77. #define INTEL_IRQ_TXDW 0x00000001UL /**< Transmit descriptor done */
  78. #define INTEL_IRQ_LSC 0x00000004UL /**< Link status change */
  79. #define INTEL_IRQ_RXT0 0x00000080UL /**< Receive timer */
  80. /** Interrupt Mask Set/Read Register */
  81. #define INTEL_IMS 0x000d0UL
  82. /** Interrupt Mask Clear Register */
  83. #define INTEL_IMC 0x000d8UL
  84. /** Receive Control Register */
  85. #define INTEL_RCTL 0x00100UL
  86. #define INTEL_RCTL_EN 0x00000002UL /**< Receive enable */
  87. #define INTEL_RCTL_UPE 0x00000008UL /**< Unicast promiscuous mode */
  88. #define INTEL_RCTL_MPE 0x00000010UL /**< Multicast promiscuous */
  89. #define INTEL_RCTL_BAM 0x00008000UL /**< Broadcast accept mode */
  90. #define INTEL_RCTL_BSIZE_BSEX(bsex,bsize) \
  91. ( ( (bsize) << 16 ) | ( (bsex) << 25 ) ) /**< Buffer size */
  92. #define INTEL_RCTL_BSIZE_2048 INTEL_RCTL_BSIZE_BSEX ( 0, 0 )
  93. #define INTEL_RCTL_BSIZE_BSEX_MASK INTEL_RCTL_BSIZE_BSEX ( 1, 3 )
  94. #define INTEL_RCTL_SECRC 0x04000000UL /**< Strip CRC */
  95. /** Transmit Control Register */
  96. #define INTEL_TCTL 0x00400UL
  97. #define INTEL_TCTL_EN 0x00000002UL /**< Transmit enable */
  98. #define INTEL_TCTL_PSP 0x00000008UL /**< Pad short packets */
  99. #define INTEL_TCTL_CT(x) ( (x) << 4 ) /**< Collision threshold */
  100. #define INTEL_TCTL_CT_DEFAULT INTEL_TCTL_CT ( 0x0f )
  101. #define INTEL_TCTL_CT_MASK INTEL_TCTL_CT ( 0xff )
  102. #define INTEL_TCTL_COLD(x) ( (x) << 12 ) /**< Collision distance */
  103. #define INTEL_TCTL_COLD_DEFAULT INTEL_TCTL_COLD ( 0x040 )
  104. #define INTEL_TCTL_COLD_MASK INTEL_TCTL_COLD ( 0x3ff )
  105. /** Packet Buffer Allocation */
  106. #define INTEL_PBA 0x01000UL
  107. /** Packet Buffer Size */
  108. #define INTEL_PBS 0x01008UL
  109. /** Receive Descriptor register block */
  110. #define INTEL_RD 0x02800UL
  111. /** Number of receive descriptors
  112. *
  113. * Minimum value is 8, since the descriptor ring length must be a
  114. * multiple of 128.
  115. */
  116. #define INTEL_NUM_RX_DESC 8
  117. /** Receive descriptor ring fill level */
  118. #define INTEL_RX_FILL 4
  119. /** Receive buffer length */
  120. #define INTEL_RX_MAX_LEN 2048
  121. /** Transmit Descriptor register block */
  122. #define INTEL_TD 0x03800UL
  123. /** Number of transmit descriptors
  124. *
  125. * Descriptor ring length must be a multiple of 16. ICH8/9/10
  126. * requires a minimum of 16 TX descriptors.
  127. */
  128. #define INTEL_NUM_TX_DESC 16
  129. /** Receive/Transmit Descriptor Base Address Low (offset) */
  130. #define INTEL_xDBAL 0x00
  131. /** Receive/Transmit Descriptor Base Address High (offset) */
  132. #define INTEL_xDBAH 0x04
  133. /** Receive/Transmit Descriptor Length (offset) */
  134. #define INTEL_xDLEN 0x08
  135. /** Receive/Transmit Descriptor Head (offset) */
  136. #define INTEL_xDH 0x10
  137. /** Receive/Transmit Descriptor Tail (offset) */
  138. #define INTEL_xDT 0x18
  139. /** Receive Descriptor Head */
  140. #define INTEL_RDH ( INTEL_RD + INTEL_xDH )
  141. /** Receive Descriptor Tail */
  142. #define INTEL_RDT ( INTEL_RD + INTEL_xDT )
  143. /** Transmit Descriptor Head */
  144. #define INTEL_TDH ( INTEL_TD + INTEL_xDH )
  145. /** Transmit Descriptor Tail */
  146. #define INTEL_TDT ( INTEL_TD + INTEL_xDT )
  147. /** Receive Address Low */
  148. #define INTEL_RAL0 0x05400UL
  149. /** Receive Address High */
  150. #define INTEL_RAH0 0x05404UL
  151. #define INTEL_RAH0_AV 0x80000000UL /**< Address valid */
  152. /** Receive address */
  153. union intel_receive_address {
  154. struct {
  155. uint32_t low;
  156. uint32_t high;
  157. } __attribute__ (( packed )) reg;
  158. uint8_t raw[ETH_ALEN];
  159. };
  160. /** An Intel descriptor ring */
  161. struct intel_ring {
  162. /** Descriptors */
  163. struct intel_descriptor *desc;
  164. /** Producer index */
  165. unsigned int prod;
  166. /** Consumer index */
  167. unsigned int cons;
  168. /** Register block */
  169. unsigned int reg;
  170. /** Length (in bytes) */
  171. size_t len;
  172. };
  173. /**
  174. * Initialise descriptor ring
  175. *
  176. * @v ring Descriptor ring
  177. * @v count Number of descriptors
  178. * @v reg Descriptor register block
  179. */
  180. static inline __attribute__ (( always_inline)) void
  181. intel_init_ring ( struct intel_ring *ring, unsigned int count,
  182. unsigned int reg ) {
  183. ring->len = ( count * sizeof ( ring->desc[0] ) );
  184. ring->reg = reg;
  185. }
  186. /** An Intel network card */
  187. struct intel_nic {
  188. /** Registers */
  189. void *regs;
  190. /** Port number (for multi-port devices) */
  191. unsigned int port;
  192. /** EEPROM */
  193. struct nvs_device eeprom;
  194. /** EEPROM done flag */
  195. uint32_t eerd_done;
  196. /** EEPROM address shift */
  197. unsigned int eerd_addr_shift;
  198. /** Transmit descriptor ring */
  199. struct intel_ring tx;
  200. /** Receive descriptor ring */
  201. struct intel_ring rx;
  202. /** Receive I/O buffers */
  203. struct io_buffer *rx_iobuf[INTEL_NUM_RX_DESC];
  204. };
  205. #endif /* _INTEL_H */