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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. /** Port register offset */
  50. #define EXANIC_PORT_REGS( index ) ( 0x0200 + ( 0x40 * (index) ) )
  51. /** Port enable register */
  52. #define EXANIC_PORT_ENABLE 0x0000
  53. #define EXANIC_PORT_ENABLE_ENABLED 0x00000001UL /**< Port is enabled */
  54. /** Port speed register */
  55. #define EXANIC_PORT_SPEED 0x0004
  56. /** Port status register */
  57. #define EXANIC_PORT_STATUS 0x0008
  58. #define EXANIC_PORT_STATUS_LINK 0x00000008UL /**< Link is up */
  59. #define EXANIC_PORT_STATUS_ABSENT 0x80000000UL /**< Port is not present */
  60. /** Port MAC address (second half) register */
  61. #define EXANIC_PORT_MAC 0x000c
  62. /** Port flags register */
  63. #define EXANIC_PORT_FLAGS 0x0010
  64. #define EXANIC_PORT_FLAGS_PROMISC 0x00000001UL /**< Promiscuous mode */
  65. /** Port receive chunk base address register */
  66. #define EXANIC_PORT_RX_BASE 0x0014
  67. /** Port transmit command register */
  68. #define EXANIC_PORT_TX_COMMAND 0x0020
  69. /** Port transmit region offset register */
  70. #define EXANIC_PORT_TX_OFFSET 0x0024
  71. /** Port transmit region length register */
  72. #define EXANIC_PORT_TX_LEN 0x0028
  73. /** Port MAC address (first half) register */
  74. #define EXANIC_PORT_OUI 0x0030
  75. /** Port interrupt configuration register */
  76. #define EXANIC_PORT_IRQ 0x0034
  77. /** An ExaNIC transmit chunk descriptor */
  78. struct exanic_tx_descriptor {
  79. /** Feedback ID */
  80. uint16_t txf_id;
  81. /** Feedback slot */
  82. uint16_t txf_slot;
  83. /** Payload length (including padding */
  84. uint16_t len;
  85. /** Payload type */
  86. uint8_t type;
  87. /** Flags */
  88. uint8_t flags;
  89. } __attribute__ (( packed ));
  90. /** An ExaNIC transmit chunk */
  91. struct exanic_tx_chunk {
  92. /** Descriptor */
  93. struct exanic_tx_descriptor desc;
  94. /** Padding */
  95. uint8_t pad[2];
  96. /** Payload data */
  97. uint8_t data[2038];
  98. } __attribute__ (( packed ));
  99. /** Raw Ethernet frame type */
  100. #define EXANIC_TYPE_RAW 0x01
  101. /** An ExaNIC receive chunk descriptor */
  102. struct exanic_rx_descriptor {
  103. /** Timestamp */
  104. uint32_t timestamp;
  105. /** Status (valid only on final chunk) */
  106. uint8_t status;
  107. /** Length (zero except on the final chunk) */
  108. uint8_t len;
  109. /** Filter number */
  110. uint8_t filter;
  111. /** Generation */
  112. uint8_t generation;
  113. } __attribute__ (( packed ));
  114. /** An ExaNIC receive chunk */
  115. struct exanic_rx_chunk {
  116. /** Payload data */
  117. uint8_t data[120];
  118. /** Descriptor */
  119. struct exanic_rx_descriptor desc;
  120. } __attribute__ (( packed ));
  121. /** Receive status error mask */
  122. #define EXANIC_STATUS_ERROR_MASK 0x0f
  123. /** An ExaNIC I2C bus configuration */
  124. struct exanic_i2c_config {
  125. /** GPIO bit for pulling SCL low */
  126. uint8_t setscl;
  127. /** GPIO bit for pulling SDA low */
  128. uint8_t setsda;
  129. /** GPIO bit for reading SDA */
  130. uint8_t getsda;
  131. };
  132. /** EEPROM address */
  133. #define EXANIC_EEPROM_ADDRESS 0x50
  134. /** An ExaNIC port */
  135. struct exanic_port {
  136. /** Network device */
  137. struct net_device *netdev;
  138. /** Port registers */
  139. void *regs;
  140. /** Transmit region offset */
  141. size_t tx_offset;
  142. /** Transmit region */
  143. void *tx;
  144. /** Number of transmit descriptors */
  145. uint16_t tx_count;
  146. /** Transmit producer counter */
  147. uint16_t tx_prod;
  148. /** Transmit consumer counter */
  149. uint16_t tx_cons;
  150. /** Transmit feedback slot */
  151. uint16_t txf_slot;
  152. /** Transmit feedback region */
  153. uint16_t *txf;
  154. /** Receive region */
  155. userptr_t rx;
  156. /** Receive consumer counter */
  157. unsigned int rx_cons;
  158. /** Receive I/O buffer (if any) */
  159. struct io_buffer *rx_iobuf;
  160. /** Receive status */
  161. int rx_rc;
  162. /** Port status */
  163. uint32_t status;
  164. /** Default link speed (as raw register value) */
  165. uint32_t default_speed;
  166. /** Speed capability bitmask */
  167. uint32_t speeds;
  168. /** Current attempted link speed (as a capability bit index) */
  169. unsigned int speed;
  170. /** Port status check timer */
  171. struct retry_timer timer;
  172. };
  173. /** An ExaNIC */
  174. struct exanic {
  175. /** Registers */
  176. void *regs;
  177. /** Transmit region */
  178. void *tx;
  179. /** Transmit feedback region */
  180. void *txf;
  181. /** I2C bus configuration */
  182. struct exanic_i2c_config i2cfg;
  183. /** I2C bit-bashing interface */
  184. struct i2c_bit_basher basher;
  185. /** I2C serial EEPROM */
  186. struct i2c_device eeprom;
  187. /** Capabilities */
  188. uint32_t caps;
  189. /** Base MAC address */
  190. uint8_t mac[ETH_ALEN];
  191. /** Ports */
  192. struct exanic_port *port[EXANIC_MAX_PORTS];
  193. };
  194. /** Maximum used length of transmit region
  195. *
  196. * This is a policy decision to avoid overflowing the 16-bit transmit
  197. * producer and consumer counters.
  198. */
  199. #define EXANIC_MAX_TX_LEN ( 256 * sizeof ( struct exanic_tx_chunk ) )
  200. /** Maximum length of received packet
  201. *
  202. * This is a policy decision.
  203. */
  204. #define EXANIC_MAX_RX_LEN ( ETH_FRAME_LEN + 4 /* VLAN */ + 4 /* CRC */ )
  205. /** Interval between link state checks
  206. *
  207. * This is a policy decision.
  208. */
  209. #define EXANIC_LINK_INTERVAL ( 1 * TICKS_PER_SEC )
  210. #endif /* _EXANIC_H */