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.

vmxnet3.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. #ifndef _VMXNET3_H
  2. #define _VMXNET3_H
  3. /*
  4. * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. */
  21. FILE_LICENCE ( GPL2_OR_LATER );
  22. /**
  23. * @file
  24. *
  25. * VMware vmxnet3 virtual NIC driver
  26. *
  27. */
  28. #include <ipxe/pci.h>
  29. /** Maximum number of TX queues */
  30. #define VMXNET3_MAX_TX_QUEUES 8
  31. /** Maximum number of RX queues */
  32. #define VMXNET3_MAX_RX_QUEUES 16
  33. /** Maximum number of interrupts */
  34. #define VMXNET3_MAX_INTRS 25
  35. /** Maximum packet size */
  36. #define VMXNET3_MAX_PACKET_LEN 0x4000
  37. /** "PT" PCI BAR address */
  38. #define VMXNET3_PT_BAR PCI_BASE_ADDRESS_0
  39. /** "PT" PCI BAR size */
  40. #define VMXNET3_PT_LEN 0x1000
  41. /** Interrupt Mask Register */
  42. #define VMXNET3_PT_IMR 0x0
  43. /** Transmit producer index */
  44. #define VMXNET3_PT_TXPROD 0x600
  45. /** Rx producer index for ring 1 */
  46. #define VMXNET3_PT_RXPROD 0x800
  47. /** Rx producer index for ring 2 */
  48. #define VMXNET3_PT_RXPROD2 0xa00
  49. /** "VD" PCI BAR address */
  50. #define VMXNET3_VD_BAR PCI_BASE_ADDRESS_1
  51. /** "VD" PCI BAR size */
  52. #define VMXNET3_VD_LEN 0x1000
  53. /** vmxnet3 Revision Report Selection */
  54. #define VMXNET3_VD_VRRS 0x0
  55. /** UPT Version Report Selection */
  56. #define VMXNET3_VD_UVRS 0x8
  57. /** Driver Shared Address Low */
  58. #define VMXNET3_VD_DSAL 0x10
  59. /** Driver Shared Address High */
  60. #define VMXNET3_VD_DSAH 0x18
  61. /** Command */
  62. #define VMXNET3_VD_CMD 0x20
  63. /** MAC Address Low */
  64. #define VMXNET3_VD_MACL 0x28
  65. /** MAC Address High */
  66. #define VMXNET3_VD_MACH 0x30
  67. /** Interrupt Cause Register */
  68. #define VMXNET3_VD_ICR 0x38
  69. /** Event Cause Register */
  70. #define VMXNET3_VD_ECR 0x40
  71. /** Commands */
  72. enum vmxnet3_command {
  73. VMXNET3_CMD_FIRST_SET = 0xcafe0000,
  74. VMXNET3_CMD_ACTIVATE_DEV = VMXNET3_CMD_FIRST_SET,
  75. VMXNET3_CMD_QUIESCE_DEV,
  76. VMXNET3_CMD_RESET_DEV,
  77. VMXNET3_CMD_UPDATE_RX_MODE,
  78. VMXNET3_CMD_UPDATE_MAC_FILTERS,
  79. VMXNET3_CMD_UPDATE_VLAN_FILTERS,
  80. VMXNET3_CMD_UPDATE_RSSIDT,
  81. VMXNET3_CMD_UPDATE_IML,
  82. VMXNET3_CMD_UPDATE_PMCFG,
  83. VMXNET3_CMD_UPDATE_FEATURE,
  84. VMXNET3_CMD_LOAD_PLUGIN,
  85. VMXNET3_CMD_FIRST_GET = 0xf00d0000,
  86. VMXNET3_CMD_GET_QUEUE_STATUS = VMXNET3_CMD_FIRST_GET,
  87. VMXNET3_CMD_GET_STATS,
  88. VMXNET3_CMD_GET_LINK,
  89. VMXNET3_CMD_GET_PERM_MAC_LO,
  90. VMXNET3_CMD_GET_PERM_MAC_HI,
  91. VMXNET3_CMD_GET_DID_LO,
  92. VMXNET3_CMD_GET_DID_HI,
  93. VMXNET3_CMD_GET_DEV_EXTRA_INFO,
  94. VMXNET3_CMD_GET_CONF_INTR
  95. };
  96. /** Events */
  97. enum vmxnet3_event {
  98. VMXNET3_ECR_RQERR = 0x00000001,
  99. VMXNET3_ECR_TQERR = 0x00000002,
  100. VMXNET3_ECR_LINK = 0x00000004,
  101. VMXNET3_ECR_DIC = 0x00000008,
  102. VMXNET3_ECR_DEBUG = 0x00000010,
  103. };
  104. /** Miscellaneous configuration descriptor */
  105. struct vmxnet3_misc_config {
  106. /** Driver version */
  107. uint32_t version;
  108. /** Guest information */
  109. uint32_t guest_info;
  110. /** Version supported */
  111. uint32_t version_support;
  112. /** UPT version supported */
  113. uint32_t upt_version_support;
  114. /** UPT features supported */
  115. uint64_t upt_features;
  116. /** Driver-private data address */
  117. uint64_t driver_data_address;
  118. /** Queue descriptors data address */
  119. uint64_t queue_desc_address;
  120. /** Driver-private data length */
  121. uint32_t driver_data_len;
  122. /** Queue descriptors data length */
  123. uint32_t queue_desc_len;
  124. /** Maximum transmission unit */
  125. uint32_t mtu;
  126. /** Maximum number of RX scatter-gather */
  127. uint16_t max_num_rx_sg;
  128. /** Number of TX queues */
  129. uint8_t num_tx_queues;
  130. /** Number of RX queues */
  131. uint8_t num_rx_queues;
  132. /** Reserved */
  133. uint32_t reserved0[4];
  134. } __attribute__ (( packed ));
  135. /** Driver version magic */
  136. #define VMXNET3_VERSION_MAGIC 0x69505845
  137. /** Interrupt configuration */
  138. struct vmxnet3_interrupt_config {
  139. uint8_t mask_mode;
  140. uint8_t num_intrs;
  141. uint8_t event_intr_index;
  142. uint8_t moderation_level[VMXNET3_MAX_INTRS];
  143. uint32_t control;
  144. uint32_t reserved0[2];
  145. } __attribute__ (( packed ));
  146. /** Interrupt control - disable all interrupts */
  147. #define VMXNET3_IC_DISABLE_ALL 0x1
  148. /** Receive filter configuration */
  149. struct vmxnet3_rx_filter_config {
  150. /** Receive filter mode */
  151. uint32_t mode;
  152. /** Multicast filter table length */
  153. uint16_t multicast_len;
  154. /** Reserved */
  155. uint16_t reserved0;
  156. /** Multicast filter table address */
  157. uint64_t multicast_address;
  158. /** VLAN filter table (one bit per possible VLAN) */
  159. uint8_t vlan_filter[512];
  160. } __attribute__ (( packed ));
  161. /** Receive filter mode */
  162. enum vmxnet3_rx_filter_mode {
  163. VMXNET3_RXM_UCAST = 0x01, /**< Unicast only */
  164. VMXNET3_RXM_MCAST = 0x02, /**< Multicast passing the filters */
  165. VMXNET3_RXM_BCAST = 0x04, /**< Broadcast only */
  166. VMXNET3_RXM_ALL_MULTI = 0x08, /**< All multicast */
  167. VMXNET3_RXM_PROMISC = 0x10, /**< Promiscuous */
  168. };
  169. /** Variable-length configuration descriptor */
  170. struct vmxnet3_variable_config {
  171. uint32_t version;
  172. uint32_t length;
  173. uint64_t address;
  174. } __attribute__ (( packed ));
  175. /** Driver shared area */
  176. struct vmxnet3_shared {
  177. /** Magic signature */
  178. uint32_t magic;
  179. /** Reserved */
  180. uint32_t reserved0;
  181. /** Miscellaneous configuration */
  182. struct vmxnet3_misc_config misc;
  183. /** Interrupt configuration */
  184. struct vmxnet3_interrupt_config interrupt;
  185. /** Receive filter configuration */
  186. struct vmxnet3_rx_filter_config rx_filter;
  187. /** RSS configuration */
  188. struct vmxnet3_variable_config rss;
  189. /** Pattern-matching configuration */
  190. struct vmxnet3_variable_config pattern;
  191. /** Plugin configuration */
  192. struct vmxnet3_variable_config plugin;
  193. /** Event notifications */
  194. uint32_t ecr;
  195. /** Reserved */
  196. uint32_t reserved1[5];
  197. } __attribute__ (( packed ));
  198. /** Alignment of driver shared area */
  199. #define VMXNET3_SHARED_ALIGN 8
  200. /** Driver shared area magic */
  201. #define VMXNET3_SHARED_MAGIC 0xbabefee1
  202. /** Transmit descriptor */
  203. struct vmxnet3_tx_desc {
  204. /** Address */
  205. uint64_t address;
  206. /** Flags */
  207. uint32_t flags[2];
  208. } __attribute__ (( packed ));
  209. /** Transmit generation flag */
  210. #define VMXNET3_TXF_GEN 0x00004000UL
  211. /** Transmit end-of-packet flag */
  212. #define VMXNET3_TXF_EOP 0x000001000UL
  213. /** Transmit completion request flag */
  214. #define VMXNET3_TXF_CQ 0x000002000UL
  215. /** Transmit completion descriptor */
  216. struct vmxnet3_tx_comp {
  217. /** Index of the end-of-packet descriptor */
  218. uint32_t index;
  219. /** Reserved */
  220. uint32_t reserved0[2];
  221. /** Flags */
  222. uint32_t flags;
  223. } __attribute__ (( packed ));
  224. /** Transmit completion generation flag */
  225. #define VMXNET3_TXCF_GEN 0x80000000UL
  226. /** Transmit queue control */
  227. struct vmxnet3_tx_queue_control {
  228. uint32_t num_deferred;
  229. uint32_t threshold;
  230. uint64_t reserved0;
  231. } __attribute__ (( packed ));
  232. /** Transmit queue configuration */
  233. struct vmxnet3_tx_queue_config {
  234. /** Descriptor ring address */
  235. uint64_t desc_address;
  236. /** Data ring address */
  237. uint64_t immediate_address;
  238. /** Completion ring address */
  239. uint64_t comp_address;
  240. /** Driver-private data address */
  241. uint64_t driver_data_address;
  242. /** Reserved */
  243. uint64_t reserved0;
  244. /** Number of descriptors */
  245. uint32_t num_desc;
  246. /** Number of data descriptors */
  247. uint32_t num_immediate;
  248. /** Number of completion descriptors */
  249. uint32_t num_comp;
  250. /** Driver-private data length */
  251. uint32_t driver_data_len;
  252. /** Interrupt index */
  253. uint8_t intr_index;
  254. /** Reserved */
  255. uint8_t reserved[7];
  256. } __attribute__ (( packed ));
  257. /** Transmit queue statistics */
  258. struct vmxnet3_tx_stats {
  259. /** Reserved */
  260. uint64_t reserved[10];
  261. } __attribute__ (( packed ));
  262. /** Receive descriptor */
  263. struct vmxnet3_rx_desc {
  264. /** Address */
  265. uint64_t address;
  266. /** Flags */
  267. uint32_t flags;
  268. /** Reserved */
  269. uint32_t reserved0;
  270. } __attribute__ (( packed ));
  271. /** Receive generation flag */
  272. #define VMXNET3_RXF_GEN 0x80000000UL
  273. /** Receive completion descriptor */
  274. struct vmxnet3_rx_comp {
  275. /** Descriptor index */
  276. uint32_t index;
  277. /** RSS hash value */
  278. uint32_t rss;
  279. /** Length */
  280. uint32_t len;
  281. /** Flags */
  282. uint32_t flags;
  283. } __attribute__ (( packed ));
  284. /** Receive completion generation flag */
  285. #define VMXNET3_RXCF_GEN 0x80000000UL
  286. /** Receive queue control */
  287. struct vmxnet3_rx_queue_control {
  288. uint8_t update_prod;
  289. uint8_t reserved0[7];
  290. uint64_t reserved1;
  291. } __attribute__ (( packed ));
  292. /** Receive queue configuration */
  293. struct vmxnet3_rx_queue_config {
  294. /** Descriptor ring addresses */
  295. uint64_t desc_address[2];
  296. /** Completion ring address */
  297. uint64_t comp_address;
  298. /** Driver-private data address */
  299. uint64_t driver_data_address;
  300. /** Reserved */
  301. uint64_t reserved0;
  302. /** Number of descriptors */
  303. uint32_t num_desc[2];
  304. /** Number of completion descriptors */
  305. uint32_t num_comp;
  306. /** Driver-private data length */
  307. uint32_t driver_data_len;
  308. /** Interrupt index */
  309. uint8_t intr_index;
  310. /** Reserved */
  311. uint8_t reserved[7];
  312. } __attribute__ (( packed ));
  313. /** Receive queue statistics */
  314. struct vmxnet3_rx_stats {
  315. /** Reserved */
  316. uint64_t reserved[10];
  317. } __attribute__ (( packed ));
  318. /** Queue status */
  319. struct vmxnet3_queue_status {
  320. uint8_t stopped;
  321. uint8_t reserved0[3];
  322. uint32_t error;
  323. } __attribute__ (( packed ));
  324. /** Transmit queue descriptor */
  325. struct vmxnet3_tx_queue {
  326. struct vmxnet3_tx_queue_control ctrl;
  327. struct vmxnet3_tx_queue_config cfg;
  328. struct vmxnet3_queue_status status;
  329. struct vmxnet3_tx_stats state;
  330. uint8_t reserved[88];
  331. } __attribute__ (( packed ));
  332. /** Receive queue descriptor */
  333. struct vmxnet3_rx_queue {
  334. struct vmxnet3_rx_queue_control ctrl;
  335. struct vmxnet3_rx_queue_config cfg;
  336. struct vmxnet3_queue_status status;
  337. struct vmxnet3_rx_stats stats;
  338. uint8_t reserved[88];
  339. } __attribute__ (( packed ));
  340. /**
  341. * Queue descriptor set
  342. *
  343. * We use only a single TX and RX queue
  344. */
  345. struct vmxnet3_queues {
  346. /** Transmit queue descriptor(s) */
  347. struct vmxnet3_tx_queue tx;
  348. /** Receive queue descriptor(s) */
  349. struct vmxnet3_rx_queue rx;
  350. } __attribute__ (( packed ));
  351. /** Alignment of queue descriptor set */
  352. #define VMXNET3_QUEUES_ALIGN 128
  353. /** Alignment of rings */
  354. #define VMXNET3_RING_ALIGN 512
  355. /** Number of TX descriptors */
  356. #define VMXNET3_NUM_TX_DESC 32
  357. /** Number of TX completion descriptors */
  358. #define VMXNET3_NUM_TX_COMP 32
  359. /** Number of RX descriptors */
  360. #define VMXNET3_NUM_RX_DESC 32
  361. /** Number of RX completion descriptors */
  362. #define VMXNET3_NUM_RX_COMP 32
  363. /**
  364. * DMA areas
  365. *
  366. * These are arranged in order of decreasing alignment, to allow for a
  367. * single allocation
  368. */
  369. struct vmxnet3_dma {
  370. /** TX descriptor ring */
  371. struct vmxnet3_tx_desc tx_desc[VMXNET3_NUM_TX_DESC];
  372. /** TX completion ring */
  373. struct vmxnet3_tx_comp tx_comp[VMXNET3_NUM_TX_COMP];
  374. /** RX descriptor ring */
  375. struct vmxnet3_rx_desc rx_desc[VMXNET3_NUM_RX_DESC];
  376. /** RX completion ring */
  377. struct vmxnet3_rx_comp rx_comp[VMXNET3_NUM_RX_COMP];
  378. /** Queue descriptors */
  379. struct vmxnet3_queues queues;
  380. /** Shared area */
  381. struct vmxnet3_shared shared;
  382. } __attribute__ (( packed ));
  383. /** DMA area alignment */
  384. #define VMXNET3_DMA_ALIGN 512
  385. /** Producer and consumer counters */
  386. struct vmxnet3_counters {
  387. /** Transmit producer counter */
  388. unsigned int tx_prod;
  389. /** Transmit completion consumer counter */
  390. unsigned int tx_cons;
  391. /** Receive producer counter */
  392. unsigned int rx_prod;
  393. /** Receive fill level */
  394. unsigned int rx_fill;
  395. /** Receive consumer counter */
  396. unsigned int rx_cons;
  397. };
  398. /** A vmxnet3 NIC */
  399. struct vmxnet3_nic {
  400. /** "PT" register base address */
  401. void *pt;
  402. /** "VD" register base address */
  403. void *vd;
  404. /** DMA area */
  405. struct vmxnet3_dma *dma;
  406. /** Producer and consumer counters */
  407. struct vmxnet3_counters count;
  408. /** Transmit I/O buffers */
  409. struct io_buffer *tx_iobuf[VMXNET3_NUM_TX_DESC];
  410. /** Receive I/O buffers */
  411. struct io_buffer *rx_iobuf[VMXNET3_NUM_RX_DESC];
  412. };
  413. /** vmxnet3 version that we support */
  414. #define VMXNET3_VERSION_SELECT 1
  415. /** UPT version that we support */
  416. #define VMXNET3_UPT_VERSION_SELECT 1
  417. /** MTU size */
  418. #define VMXNET3_MTU ( ETH_FRAME_LEN + 4 /* VLAN */ + 4 /* FCS */ )
  419. /** Receive ring maximum fill level */
  420. #define VMXNET3_RX_FILL 8
  421. /** Received packet alignment padding */
  422. #define NET_IP_ALIGN 2
  423. #endif /* _VMXNET3_H */