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.

exanic.h 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #ifndef _EXANIC_H
  2. #define _EXANIC_H
  3. /** @file
  4. *
  5. * Exablaze ExaNIC driver
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/pci.h>
  11. #include <ipxe/ethernet.h>
  12. #include <ipxe/uaccess.h>
  13. #include <ipxe/retry.h>
  14. #include <ipxe/i2c.h>
  15. #include <ipxe/bitbash.h>
  16. /** Maximum number of ports */
  17. #define EXANIC_MAX_PORTS 8
  18. /** Register BAR */
  19. #define EXANIC_REGS_BAR PCI_BASE_ADDRESS_0
  20. /** Transmit region BAR */
  21. #define EXANIC_TX_BAR PCI_BASE_ADDRESS_2
  22. /** Alignment for DMA regions */
  23. #define EXANIC_ALIGN 0x1000
  24. /** Flag for 32-bit DMA addresses */
  25. #define EXANIC_DMA_32_BIT 0x00000001UL
  26. /** Register set length */
  27. #define EXANIC_REGS_LEN 0x2000
  28. /** Transmit feedback region length */
  29. #define EXANIC_TXF_LEN 0x1000
  30. /** Transmit feedback slot
  31. *
  32. * This is a policy decision.
  33. */
  34. #define EXANIC_TXF_SLOT( index ) ( 0x40 * (index) )
  35. /** Receive region length */
  36. #define EXANIC_RX_LEN 0x200000
  37. /** Transmit feedback base address register */
  38. #define EXANIC_TXF_BASE 0x0014
  39. /** Capabilities register */
  40. #define EXANIC_CAPS 0x0038
  41. #define EXANIC_CAPS_100M 0x01000000UL /**< 100Mbps supported */
  42. #define EXANIC_CAPS_1G 0x02000000UL /**< 1Gbps supported */
  43. #define EXANIC_CAPS_10G 0x04000000UL /**< 10Gbps supported */
  44. #define EXANIC_CAPS_40G 0x08000000UL /**< 40Gbps supported */
  45. #define EXANIC_CAPS_100G 0x10000000UL /**< 100Gbps supported */
  46. #define EXANIC_CAPS_SPEED_MASK 0x1f000000UL /**< Supported speeds mask */
  47. /** I2C GPIO register */
  48. #define EXANIC_I2C 0x012c
  49. /** Power control register */
  50. #define EXANIC_POWER 0x0138
  51. #define EXANIC_POWER_ON 0x000000f0UL /**< Power on PHYs */
  52. /** Port register offset */
  53. #define EXANIC_PORT_REGS( index ) ( 0x0200 + ( 0x40 * (index) ) )
  54. /** Port enable register */
  55. #define EXANIC_PORT_ENABLE 0x0000
  56. #define EXANIC_PORT_ENABLE_ENABLED 0x00000001UL /**< Port is enabled */
  57. /** Port speed register */
  58. #define EXANIC_PORT_SPEED 0x0004
  59. /** Port status register */
  60. #define EXANIC_PORT_STATUS 0x0008
  61. #define EXANIC_PORT_STATUS_LINK 0x00000008UL /**< Link is up */
  62. #define EXANIC_PORT_STATUS_ABSENT 0x80000000UL /**< Port is not present */
  63. /** Port MAC address (second half) register */
  64. #define EXANIC_PORT_MAC 0x000c
  65. /** Port flags register */
  66. #define EXANIC_PORT_FLAGS 0x0010
  67. #define EXANIC_PORT_FLAGS_PROMISC 0x00000001UL /**< Promiscuous mode */
  68. /** Port receive chunk base address register */
  69. #define EXANIC_PORT_RX_BASE 0x0014
  70. /** Port transmit command register */
  71. #define EXANIC_PORT_TX_COMMAND 0x0020
  72. /** Port transmit region offset register */
  73. #define EXANIC_PORT_TX_OFFSET 0x0024
  74. /** Port transmit region length register */
  75. #define EXANIC_PORT_TX_LEN 0x0028
  76. /** Port MAC address (first half) register */
  77. #define EXANIC_PORT_OUI 0x0030
  78. /** Port interrupt configuration register */
  79. #define EXANIC_PORT_IRQ 0x0034
  80. /** An ExaNIC transmit chunk descriptor */
  81. struct exanic_tx_descriptor {
  82. /** Feedback ID */
  83. uint16_t txf_id;
  84. /** Feedback slot */
  85. uint16_t txf_slot;
  86. /** Payload length (including padding */
  87. uint16_t len;
  88. /** Payload type */
  89. uint8_t type;
  90. /** Flags */
  91. uint8_t flags;
  92. } __attribute__ (( packed ));
  93. /** An ExaNIC transmit chunk */
  94. struct exanic_tx_chunk {
  95. /** Descriptor */
  96. struct exanic_tx_descriptor desc;
  97. /** Padding */
  98. uint8_t pad[2];
  99. /** Payload data */
  100. uint8_t data[2038];
  101. } __attribute__ (( packed ));
  102. /** Raw Ethernet frame type */
  103. #define EXANIC_TYPE_RAW 0x01
  104. /** An ExaNIC receive chunk descriptor */
  105. struct exanic_rx_descriptor {
  106. /** Timestamp */
  107. uint32_t timestamp;
  108. /** Status (valid only on final chunk) */
  109. uint8_t status;
  110. /** Length (zero except on the final chunk) */
  111. uint8_t len;
  112. /** Filter number */
  113. uint8_t filter;
  114. /** Generation */
  115. uint8_t generation;
  116. } __attribute__ (( packed ));
  117. /** An ExaNIC receive chunk */
  118. struct exanic_rx_chunk {
  119. /** Payload data */
  120. uint8_t data[120];
  121. /** Descriptor */
  122. struct exanic_rx_descriptor desc;
  123. } __attribute__ (( packed ));
  124. /** Receive status error mask */
  125. #define EXANIC_STATUS_ERROR_MASK 0x0f
  126. /** An ExaNIC I2C bus configuration */
  127. struct exanic_i2c_config {
  128. /** GPIO bit for pulling SCL low */
  129. uint8_t setscl;
  130. /** GPIO bit for pulling SDA low */
  131. uint8_t setsda;
  132. /** GPIO bit for reading SDA */
  133. uint8_t getsda;
  134. };
  135. /** EEPROM address */
  136. #define EXANIC_EEPROM_ADDRESS 0x50
  137. /** An ExaNIC port */
  138. struct exanic_port {
  139. /** Network device */
  140. struct net_device *netdev;
  141. /** Port registers */
  142. void *regs;
  143. /** Transmit region offset */
  144. size_t tx_offset;
  145. /** Transmit region */
  146. void *tx;
  147. /** Number of transmit descriptors */
  148. uint16_t tx_count;
  149. /** Transmit producer counter */
  150. uint16_t tx_prod;
  151. /** Transmit consumer counter */
  152. uint16_t tx_cons;
  153. /** Transmit feedback slot */
  154. uint16_t txf_slot;
  155. /** Transmit feedback region */
  156. uint16_t *txf;
  157. /** Receive region */
  158. userptr_t rx;
  159. /** Receive consumer counter */
  160. unsigned int rx_cons;
  161. /** Receive I/O buffer (if any) */
  162. struct io_buffer *rx_iobuf;
  163. /** Receive status */
  164. int rx_rc;
  165. /** Port status */
  166. uint32_t status;
  167. /** Default link speed (as raw register value) */
  168. uint32_t default_speed;
  169. /** Speed capability bitmask */
  170. uint32_t speeds;
  171. /** Current attempted link speed (as a capability bit index) */
  172. unsigned int speed;
  173. /** Port status check timer */
  174. struct retry_timer timer;
  175. };
  176. /** An ExaNIC */
  177. struct exanic {
  178. /** Registers */
  179. void *regs;
  180. /** Transmit region */
  181. void *tx;
  182. /** Transmit feedback region */
  183. void *txf;
  184. /** I2C bus configuration */
  185. struct exanic_i2c_config i2cfg;
  186. /** I2C bit-bashing interface */
  187. struct i2c_bit_basher basher;
  188. /** I2C serial EEPROM */
  189. struct i2c_device eeprom;
  190. /** Capabilities */
  191. uint32_t caps;
  192. /** Base MAC address */
  193. uint8_t mac[ETH_ALEN];
  194. /** Ports */
  195. struct exanic_port *port[EXANIC_MAX_PORTS];
  196. };
  197. /** Maximum used length of transmit region
  198. *
  199. * This is a policy decision to avoid overflowing the 16-bit transmit
  200. * producer and consumer counters.
  201. */
  202. #define EXANIC_MAX_TX_LEN ( 256 * sizeof ( struct exanic_tx_chunk ) )
  203. /** Maximum length of received packet
  204. *
  205. * This is a policy decision.
  206. */
  207. #define EXANIC_MAX_RX_LEN ( ETH_FRAME_LEN + 4 /* VLAN */ + 4 /* CRC */ )
  208. /** Interval between link state checks
  209. *
  210. * This is a policy decision.
  211. */
  212. #define EXANIC_LINK_INTERVAL ( 1 * TICKS_PER_SEC )
  213. #endif /* _EXANIC_H */