vmxnet3.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * QEMU VMWARE VMXNET3 paravirtual NIC interface definitions
  3. *
  4. * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
  5. *
  6. * Developed by Daynix Computing LTD (http://www.daynix.com)
  7. *
  8. * Authors:
  9. * Dmitry Fleytman <dmitry@daynix.com>
  10. * Tamir Shomer <tamirs@daynix.com>
  11. * Yan Vugenfirer <yan@daynix.com>
  12. *
  13. * This work is licensed under the terms of the GNU GPL, version 2.
  14. * See the COPYING file in the top-level directory.
  15. *
  16. */
  17. #ifndef QEMU_VMXNET3_H
  18. #define QEMU_VMXNET3_H
  19. #define VMXNET3_DEVICE_MAX_TX_QUEUES 8
  20. #define VMXNET3_DEVICE_MAX_RX_QUEUES 8 /* Keep this value as a power of 2 */
  21. /*
  22. * VMWARE headers we got from Linux kernel do not fully comply QEMU coding
  23. * standards in sense of types and defines used.
  24. * Since we didn't want to change VMWARE code, following set of typedefs
  25. * and defines needed to compile these headers with QEMU introduced.
  26. */
  27. #define u64 uint64_t
  28. #define u32 uint32_t
  29. #define u16 uint16_t
  30. #define u8 uint8_t
  31. #define __le16 uint16_t
  32. #define __le32 uint32_t
  33. #define __le64 uint64_t
  34. #if HOST_BIG_ENDIAN
  35. #define __BIG_ENDIAN_BITFIELD
  36. #else
  37. #endif
  38. /*
  39. * Following is an interface definition for
  40. * VMXNET3 device as provided by VMWARE
  41. * See original copyright from Linux kernel v3.2.8
  42. * header file drivers/net/vmxnet3/vmxnet3_defs.h below.
  43. */
  44. /*
  45. * Linux driver for VMware's vmxnet3 ethernet NIC.
  46. *
  47. * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
  48. *
  49. * This program is free software; you can redistribute it and/or modify it
  50. * under the terms of the GNU General Public License as published by the
  51. * Free Software Foundation; version 2 of the License and no later version.
  52. *
  53. * This program is distributed in the hope that it will be useful, but
  54. * WITHOUT ANY WARRANTY; without even the implied warranty of
  55. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  56. * NON INFRINGEMENT. See the GNU General Public License for more
  57. * details.
  58. *
  59. * You should have received a copy of the GNU General Public License
  60. * along with this program; if not, write to the Free Software
  61. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  62. *
  63. * The full GNU General Public License is included in this distribution in
  64. * the file called "COPYING".
  65. *
  66. * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
  67. *
  68. */
  69. struct UPT1_TxStats {
  70. u64 TSOPktsTxOK; /* TSO pkts post-segmentation */
  71. u64 TSOBytesTxOK;
  72. u64 ucastPktsTxOK;
  73. u64 ucastBytesTxOK;
  74. u64 mcastPktsTxOK;
  75. u64 mcastBytesTxOK;
  76. u64 bcastPktsTxOK;
  77. u64 bcastBytesTxOK;
  78. u64 pktsTxError;
  79. u64 pktsTxDiscard;
  80. };
  81. struct UPT1_RxStats {
  82. u64 LROPktsRxOK; /* LRO pkts */
  83. u64 LROBytesRxOK; /* bytes from LRO pkts */
  84. /* the following counters are for pkts from the wire, i.e., pre-LRO */
  85. u64 ucastPktsRxOK;
  86. u64 ucastBytesRxOK;
  87. u64 mcastPktsRxOK;
  88. u64 mcastBytesRxOK;
  89. u64 bcastPktsRxOK;
  90. u64 bcastBytesRxOK;
  91. u64 pktsRxOutOfBuf;
  92. u64 pktsRxError;
  93. };
  94. /* interrupt moderation level */
  95. enum {
  96. UPT1_IML_NONE = 0, /* no interrupt moderation */
  97. UPT1_IML_HIGHEST = 7, /* least intr generated */
  98. UPT1_IML_ADAPTIVE = 8, /* adpative intr moderation */
  99. };
  100. /* values for UPT1_RSSConf.hashFunc */
  101. enum {
  102. UPT1_RSS_HASH_TYPE_NONE = 0x0,
  103. UPT1_RSS_HASH_TYPE_IPV4 = 0x01,
  104. UPT1_RSS_HASH_TYPE_TCP_IPV4 = 0x02,
  105. UPT1_RSS_HASH_TYPE_IPV6 = 0x04,
  106. UPT1_RSS_HASH_TYPE_TCP_IPV6 = 0x08,
  107. };
  108. enum {
  109. UPT1_RSS_HASH_FUNC_NONE = 0x0,
  110. UPT1_RSS_HASH_FUNC_TOEPLITZ = 0x01,
  111. };
  112. #define UPT1_RSS_MAX_KEY_SIZE 40
  113. #define UPT1_RSS_MAX_IND_TABLE_SIZE 128
  114. struct UPT1_RSSConf {
  115. u16 hashType;
  116. u16 hashFunc;
  117. u16 hashKeySize;
  118. u16 indTableSize;
  119. u8 hashKey[UPT1_RSS_MAX_KEY_SIZE];
  120. u8 indTable[UPT1_RSS_MAX_IND_TABLE_SIZE];
  121. };
  122. /* features */
  123. enum {
  124. UPT1_F_RXCSUM = 0x0001, /* rx csum verification */
  125. UPT1_F_RSS = 0x0002,
  126. UPT1_F_RXVLAN = 0x0004, /* VLAN tag stripping */
  127. UPT1_F_LRO = 0x0008,
  128. };
  129. /* all registers are 32 bit wide */
  130. /* BAR 1 */
  131. enum {
  132. VMXNET3_REG_VRRS = 0x0, /* Vmxnet3 Revision Report Selection */
  133. VMXNET3_REG_UVRS = 0x8, /* UPT Version Report Selection */
  134. VMXNET3_REG_DSAL = 0x10, /* Driver Shared Address Low */
  135. VMXNET3_REG_DSAH = 0x18, /* Driver Shared Address High */
  136. VMXNET3_REG_CMD = 0x20, /* Command */
  137. VMXNET3_REG_MACL = 0x28, /* MAC Address Low */
  138. VMXNET3_REG_MACH = 0x30, /* MAC Address High */
  139. VMXNET3_REG_ICR = 0x38, /* Interrupt Cause Register */
  140. VMXNET3_REG_ECR = 0x40 /* Event Cause Register */
  141. };
  142. /* BAR 0 */
  143. enum {
  144. VMXNET3_REG_IMR = 0x0, /* Interrupt Mask Register */
  145. VMXNET3_REG_TXPROD = 0x600, /* Tx Producer Index */
  146. VMXNET3_REG_RXPROD = 0x800, /* Rx Producer Index for ring 1 */
  147. VMXNET3_REG_RXPROD2 = 0xA00 /* Rx Producer Index for ring 2 */
  148. };
  149. #define VMXNET3_PT_REG_SIZE 4096 /* BAR 0 */
  150. #define VMXNET3_VD_REG_SIZE 4096 /* BAR 1 */
  151. #define VMXNET3_REG_ALIGN 8 /* All registers are 8-byte aligned. */
  152. #define VMXNET3_REG_ALIGN_MASK 0x7
  153. /* I/O Mapped access to registers */
  154. #define VMXNET3_IO_TYPE_PT 0
  155. #define VMXNET3_IO_TYPE_VD 1
  156. #define VMXNET3_IO_ADDR(type, reg) (((type) << 24) | ((reg) & 0xFFFFFF))
  157. #define VMXNET3_IO_TYPE(addr) ((addr) >> 24)
  158. #define VMXNET3_IO_REG(addr) ((addr) & 0xFFFFFF)
  159. enum {
  160. VMXNET3_CMD_FIRST_SET = 0xCAFE0000,
  161. VMXNET3_CMD_ACTIVATE_DEV = VMXNET3_CMD_FIRST_SET, /* 0xCAFE0000 */
  162. VMXNET3_CMD_QUIESCE_DEV, /* 0xCAFE0001 */
  163. VMXNET3_CMD_RESET_DEV, /* 0xCAFE0002 */
  164. VMXNET3_CMD_UPDATE_RX_MODE, /* 0xCAFE0003 */
  165. VMXNET3_CMD_UPDATE_MAC_FILTERS, /* 0xCAFE0004 */
  166. VMXNET3_CMD_UPDATE_VLAN_FILTERS, /* 0xCAFE0005 */
  167. VMXNET3_CMD_UPDATE_RSSIDT, /* 0xCAFE0006 */
  168. VMXNET3_CMD_UPDATE_IML, /* 0xCAFE0007 */
  169. VMXNET3_CMD_UPDATE_PMCFG, /* 0xCAFE0008 */
  170. VMXNET3_CMD_UPDATE_FEATURE, /* 0xCAFE0009 */
  171. VMXNET3_CMD_LOAD_PLUGIN, /* 0xCAFE000A */
  172. VMXNET3_CMD_FIRST_GET = 0xF00D0000,
  173. VMXNET3_CMD_GET_QUEUE_STATUS = VMXNET3_CMD_FIRST_GET, /* 0xF00D0000 */
  174. VMXNET3_CMD_GET_STATS, /* 0xF00D0001 */
  175. VMXNET3_CMD_GET_LINK, /* 0xF00D0002 */
  176. VMXNET3_CMD_GET_PERM_MAC_LO, /* 0xF00D0003 */
  177. VMXNET3_CMD_GET_PERM_MAC_HI, /* 0xF00D0004 */
  178. VMXNET3_CMD_GET_DID_LO, /* 0xF00D0005 */
  179. VMXNET3_CMD_GET_DID_HI, /* 0xF00D0006 */
  180. VMXNET3_CMD_GET_DEV_EXTRA_INFO, /* 0xF00D0007 */
  181. VMXNET3_CMD_GET_CONF_INTR, /* 0xF00D0008 */
  182. VMXNET3_CMD_GET_ADAPTIVE_RING_INFO /* 0xF00D0009 */
  183. };
  184. /* Adaptive Ring Info Flags */
  185. #define VMXNET3_DISABLE_ADAPTIVE_RING 1
  186. /*
  187. * Little Endian layout of bitfields -
  188. * Byte 0 : 7.....len.....0
  189. * Byte 1 : rsvd gen 13.len.8
  190. * Byte 2 : 5.msscof.0 ext1 dtype
  191. * Byte 3 : 13...msscof...6
  192. *
  193. * Big Endian layout of bitfields -
  194. * Byte 0: 13...msscof...6
  195. * Byte 1 : 5.msscof.0 ext1 dtype
  196. * Byte 2 : rsvd gen 13.len.8
  197. * Byte 3 : 7.....len.....0
  198. *
  199. * Thus, le32_to_cpu on the dword will allow the big endian driver to read
  200. * the bit fields correctly. And cpu_to_le32 will convert bitfields
  201. * bit fields written by big endian driver to format required by device.
  202. */
  203. struct Vmxnet3_TxDesc {
  204. __le64 addr;
  205. union {
  206. struct {
  207. #ifdef __BIG_ENDIAN_BITFIELD
  208. u32 msscof:14; /* MSS, checksum offset, flags */
  209. u32 ext1:1;
  210. u32 dtype:1; /* descriptor type */
  211. u32 rsvd:1;
  212. u32 gen:1; /* generation bit */
  213. u32 len:14;
  214. #else
  215. u32 len:14;
  216. u32 gen:1; /* generation bit */
  217. u32 rsvd:1;
  218. u32 dtype:1; /* descriptor type */
  219. u32 ext1:1;
  220. u32 msscof:14; /* MSS, checksum offset, flags */
  221. #endif /* __BIG_ENDIAN_BITFIELD */
  222. };
  223. u32 val1;
  224. };
  225. union {
  226. struct {
  227. #ifdef __BIG_ENDIAN_BITFIELD
  228. u32 tci:16; /* Tag to Insert */
  229. u32 ti:1; /* VLAN Tag Insertion */
  230. u32 ext2:1;
  231. u32 cq:1; /* completion request */
  232. u32 eop:1; /* End Of Packet */
  233. u32 om:2; /* offload mode */
  234. u32 hlen:10; /* header len */
  235. #else
  236. u32 hlen:10; /* header len */
  237. u32 om:2; /* offload mode */
  238. u32 eop:1; /* End Of Packet */
  239. u32 cq:1; /* completion request */
  240. u32 ext2:1;
  241. u32 ti:1; /* VLAN Tag Insertion */
  242. u32 tci:16; /* Tag to Insert */
  243. #endif /* __BIG_ENDIAN_BITFIELD */
  244. };
  245. u32 val2;
  246. };
  247. };
  248. /* TxDesc.OM values */
  249. #define VMXNET3_OM_NONE 0
  250. #define VMXNET3_OM_CSUM 2
  251. #define VMXNET3_OM_TSO 3
  252. /* fields in TxDesc we access w/o using bit fields */
  253. #define VMXNET3_TXD_EOP_SHIFT 12
  254. #define VMXNET3_TXD_CQ_SHIFT 13
  255. #define VMXNET3_TXD_GEN_SHIFT 14
  256. #define VMXNET3_TXD_EOP_DWORD_SHIFT 3
  257. #define VMXNET3_TXD_GEN_DWORD_SHIFT 2
  258. #define VMXNET3_TXD_CQ (1 << VMXNET3_TXD_CQ_SHIFT)
  259. #define VMXNET3_TXD_EOP (1 << VMXNET3_TXD_EOP_SHIFT)
  260. #define VMXNET3_TXD_GEN (1 << VMXNET3_TXD_GEN_SHIFT)
  261. #define VMXNET3_HDR_COPY_SIZE 128
  262. struct Vmxnet3_TxDataDesc {
  263. u8 data[VMXNET3_HDR_COPY_SIZE];
  264. };
  265. #define VMXNET3_TCD_GEN_SHIFT 31
  266. #define VMXNET3_TCD_GEN_SIZE 1
  267. #define VMXNET3_TCD_TXIDX_SHIFT 0
  268. #define VMXNET3_TCD_TXIDX_SIZE 12
  269. #define VMXNET3_TCD_GEN_DWORD_SHIFT 3
  270. struct Vmxnet3_TxCompDesc {
  271. union {
  272. struct {
  273. #ifdef __BIG_ENDIAN_BITFIELD
  274. u32 ext1:20;
  275. u32 txdIdx:12; /* Index of the EOP TxDesc */
  276. #else
  277. u32 txdIdx:12; /* Index of the EOP TxDesc */
  278. u32 ext1:20;
  279. #endif
  280. };
  281. u32 val1;
  282. };
  283. __le32 ext2;
  284. __le32 ext3;
  285. union {
  286. struct {
  287. #ifdef __BIG_ENDIAN_BITFIELD
  288. u32 gen:1; /* generation bit */
  289. u32 type:7; /* completion type */
  290. u32 rsvd:24;
  291. #else
  292. u32 rsvd:24;
  293. u32 type:7; /* completion type */
  294. u32 gen:1; /* generation bit */
  295. #endif
  296. };
  297. u32 val2;
  298. };
  299. };
  300. struct Vmxnet3_RxDesc {
  301. __le64 addr;
  302. union {
  303. struct {
  304. #ifdef __BIG_ENDIAN_BITFIELD
  305. u32 gen:1; /* Generation bit */
  306. u32 rsvd:15;
  307. u32 dtype:1; /* Descriptor type */
  308. u32 btype:1; /* Buffer Type */
  309. u32 len:14;
  310. #else
  311. u32 len:14;
  312. u32 btype:1; /* Buffer Type */
  313. u32 dtype:1; /* Descriptor type */
  314. u32 rsvd:15;
  315. u32 gen:1; /* Generation bit */
  316. #endif
  317. };
  318. u32 val1;
  319. };
  320. u32 ext1;
  321. };
  322. /* values of RXD.BTYPE */
  323. #define VMXNET3_RXD_BTYPE_HEAD 0 /* head only */
  324. #define VMXNET3_RXD_BTYPE_BODY 1 /* body only */
  325. /* fields in RxDesc we access w/o using bit fields */
  326. #define VMXNET3_RXD_BTYPE_SHIFT 14
  327. #define VMXNET3_RXD_GEN_SHIFT 31
  328. struct Vmxnet3_RxCompDesc {
  329. union {
  330. struct {
  331. #ifdef __BIG_ENDIAN_BITFIELD
  332. u32 ext2:1;
  333. u32 cnc:1; /* Checksum Not Calculated */
  334. u32 rssType:4; /* RSS hash type used */
  335. u32 rqID:10; /* rx queue/ring ID */
  336. u32 sop:1; /* Start of Packet */
  337. u32 eop:1; /* End of Packet */
  338. u32 ext1:2;
  339. u32 rxdIdx:12; /* Index of the RxDesc */
  340. #else
  341. u32 rxdIdx:12; /* Index of the RxDesc */
  342. u32 ext1:2;
  343. u32 eop:1; /* End of Packet */
  344. u32 sop:1; /* Start of Packet */
  345. u32 rqID:10; /* rx queue/ring ID */
  346. u32 rssType:4; /* RSS hash type used */
  347. u32 cnc:1; /* Checksum Not Calculated */
  348. u32 ext2:1;
  349. #endif /* __BIG_ENDIAN_BITFIELD */
  350. };
  351. u32 val1;
  352. };
  353. __le32 rssHash; /* RSS hash value */
  354. union {
  355. struct {
  356. #ifdef __BIG_ENDIAN_BITFIELD
  357. u32 tci:16; /* Tag stripped */
  358. u32 ts:1; /* Tag is stripped */
  359. u32 err:1; /* Error */
  360. u32 len:14; /* data length */
  361. #else
  362. u32 len:14; /* data length */
  363. u32 err:1; /* Error */
  364. u32 ts:1; /* Tag is stripped */
  365. u32 tci:16; /* Tag stripped */
  366. #endif /* __BIG_ENDIAN_BITFIELD */
  367. };
  368. u32 val2;
  369. };
  370. union {
  371. struct {
  372. #ifdef __BIG_ENDIAN_BITFIELD
  373. u32 gen:1; /* generation bit */
  374. u32 type:7; /* completion type */
  375. u32 fcs:1; /* Frame CRC correct */
  376. u32 frg:1; /* IP Fragment */
  377. u32 v4:1; /* IPv4 */
  378. u32 v6:1; /* IPv6 */
  379. u32 ipc:1; /* IP Checksum Correct */
  380. u32 tcp:1; /* TCP packet */
  381. u32 udp:1; /* UDP packet */
  382. u32 tuc:1; /* TCP/UDP Checksum Correct */
  383. u32 csum:16;
  384. #else
  385. u32 csum:16;
  386. u32 tuc:1; /* TCP/UDP Checksum Correct */
  387. u32 udp:1; /* UDP packet */
  388. u32 tcp:1; /* TCP packet */
  389. u32 ipc:1; /* IP Checksum Correct */
  390. u32 v6:1; /* IPv6 */
  391. u32 v4:1; /* IPv4 */
  392. u32 frg:1; /* IP Fragment */
  393. u32 fcs:1; /* Frame CRC correct */
  394. u32 type:7; /* completion type */
  395. u32 gen:1; /* generation bit */
  396. #endif /* __BIG_ENDIAN_BITFIELD */
  397. };
  398. u32 val3;
  399. };
  400. };
  401. /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.dword[3] */
  402. #define VMXNET3_RCD_TUC_SHIFT 16
  403. #define VMXNET3_RCD_IPC_SHIFT 19
  404. /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.qword[1] */
  405. #define VMXNET3_RCD_TYPE_SHIFT 56
  406. #define VMXNET3_RCD_GEN_SHIFT 63
  407. /* csum OK for TCP/UDP pkts over IP */
  408. #define VMXNET3_RCD_CSUM_OK (1 << VMXNET3_RCD_TUC_SHIFT | \
  409. 1 << VMXNET3_RCD_IPC_SHIFT)
  410. #define VMXNET3_TXD_GEN_SIZE 1
  411. #define VMXNET3_TXD_EOP_SIZE 1
  412. /* value of RxCompDesc.rssType */
  413. enum {
  414. VMXNET3_RCD_RSS_TYPE_NONE = 0,
  415. VMXNET3_RCD_RSS_TYPE_IPV4 = 1,
  416. VMXNET3_RCD_RSS_TYPE_TCPIPV4 = 2,
  417. VMXNET3_RCD_RSS_TYPE_IPV6 = 3,
  418. VMXNET3_RCD_RSS_TYPE_TCPIPV6 = 4,
  419. };
  420. /* a union for accessing all cmd/completion descriptors */
  421. union Vmxnet3_GenericDesc {
  422. __le64 qword[2];
  423. __le32 dword[4];
  424. __le16 word[8];
  425. struct Vmxnet3_TxDesc txd;
  426. struct Vmxnet3_RxDesc rxd;
  427. struct Vmxnet3_TxCompDesc tcd;
  428. struct Vmxnet3_RxCompDesc rcd;
  429. };
  430. #define VMXNET3_INIT_GEN 1
  431. /* Max size of a single tx buffer */
  432. #define VMXNET3_MAX_TX_BUF_SIZE (1 << 14)
  433. /* # of tx desc needed for a tx buffer size */
  434. #define VMXNET3_TXD_NEEDED(size) (((size) + VMXNET3_MAX_TX_BUF_SIZE - 1) / \
  435. VMXNET3_MAX_TX_BUF_SIZE)
  436. /* max # of tx descs for a non-tso pkt */
  437. #define VMXNET3_MAX_TXD_PER_PKT 16
  438. /* Max size of a single rx buffer */
  439. #define VMXNET3_MAX_RX_BUF_SIZE ((1 << 14) - 1)
  440. /* Minimum size of a type 0 buffer */
  441. #define VMXNET3_MIN_T0_BUF_SIZE 128
  442. #define VMXNET3_MAX_CSUM_OFFSET 1024
  443. /* Ring base address alignment */
  444. #define VMXNET3_RING_BA_ALIGN 512
  445. #define VMXNET3_RING_BA_MASK (VMXNET3_RING_BA_ALIGN - 1)
  446. /* Ring size must be a multiple of 32 */
  447. #define VMXNET3_RING_SIZE_ALIGN 32
  448. #define VMXNET3_RING_SIZE_MASK (VMXNET3_RING_SIZE_ALIGN - 1)
  449. /* Max ring size */
  450. #define VMXNET3_TX_RING_MAX_SIZE 4096
  451. #define VMXNET3_TC_RING_MAX_SIZE 4096
  452. #define VMXNET3_RX_RING_MAX_SIZE 4096
  453. #define VMXNET3_RC_RING_MAX_SIZE 8192
  454. /* a list of reasons for queue stop */
  455. enum {
  456. VMXNET3_ERR_NOEOP = 0x80000000, /* cannot find the EOP desc of a pkt */
  457. VMXNET3_ERR_TXD_REUSE = 0x80000001, /* reuse TxDesc before tx completion */
  458. VMXNET3_ERR_BIG_PKT = 0x80000002, /* too many TxDesc for a pkt */
  459. VMXNET3_ERR_DESC_NOT_SPT = 0x80000003, /* descriptor type not supported */
  460. VMXNET3_ERR_SMALL_BUF = 0x80000004, /* type 0 buffer too small */
  461. VMXNET3_ERR_STRESS = 0x80000005, /* stress option firing in vmkernel */
  462. VMXNET3_ERR_SWITCH = 0x80000006, /* mode switch failure */
  463. VMXNET3_ERR_TXD_INVALID = 0x80000007, /* invalid TxDesc */
  464. };
  465. /* completion descriptor types */
  466. #define VMXNET3_CDTYPE_TXCOMP 0 /* Tx Completion Descriptor */
  467. #define VMXNET3_CDTYPE_RXCOMP 3 /* Rx Completion Descriptor */
  468. enum {
  469. VMXNET3_GOS_BITS_UNK = 0, /* unknown */
  470. VMXNET3_GOS_BITS_32 = 1,
  471. VMXNET3_GOS_BITS_64 = 2,
  472. };
  473. #define VMXNET3_GOS_TYPE_UNK 0 /* unknown */
  474. #define VMXNET3_GOS_TYPE_LINUX 1
  475. #define VMXNET3_GOS_TYPE_WIN 2
  476. #define VMXNET3_GOS_TYPE_SOLARIS 3
  477. #define VMXNET3_GOS_TYPE_FREEBSD 4
  478. #define VMXNET3_GOS_TYPE_PXE 5
  479. struct Vmxnet3_GOSInfo {
  480. #ifdef __BIG_ENDIAN_BITFIELD
  481. u32 gosMisc:10; /* other info about gos */
  482. u32 gosVer:16; /* gos version */
  483. u32 gosType:4; /* which guest */
  484. u32 gosBits:2; /* 32-bit or 64-bit? */
  485. #else
  486. u32 gosBits:2; /* 32-bit or 64-bit? */
  487. u32 gosType:4; /* which guest */
  488. u32 gosVer:16; /* gos version */
  489. u32 gosMisc:10; /* other info about gos */
  490. #endif /* __BIG_ENDIAN_BITFIELD */
  491. };
  492. struct Vmxnet3_DriverInfo {
  493. __le32 version;
  494. struct Vmxnet3_GOSInfo gos;
  495. __le32 vmxnet3RevSpt;
  496. __le32 uptVerSpt;
  497. };
  498. #define VMXNET3_REV1_MAGIC 0xbabefee1
  499. /*
  500. * QueueDescPA must be 128 bytes aligned. It points to an array of
  501. * Vmxnet3_TxQueueDesc followed by an array of Vmxnet3_RxQueueDesc.
  502. * The number of Vmxnet3_TxQueueDesc/Vmxnet3_RxQueueDesc are specified by
  503. * Vmxnet3_MiscConf.numTxQueues/numRxQueues, respectively.
  504. */
  505. #define VMXNET3_QUEUE_DESC_ALIGN 128
  506. struct Vmxnet3_MiscConf {
  507. struct Vmxnet3_DriverInfo driverInfo;
  508. __le64 uptFeatures;
  509. __le64 ddPA; /* driver data PA */
  510. __le64 queueDescPA; /* queue descriptor table PA */
  511. __le32 ddLen; /* driver data len */
  512. __le32 queueDescLen; /* queue desc. table len in bytes */
  513. __le32 mtu;
  514. __le16 maxNumRxSG;
  515. u8 numTxQueues;
  516. u8 numRxQueues;
  517. __le32 reserved[4];
  518. };
  519. struct Vmxnet3_TxQueueConf {
  520. __le64 txRingBasePA;
  521. __le64 dataRingBasePA;
  522. __le64 compRingBasePA;
  523. __le64 ddPA; /* driver data */
  524. __le64 reserved;
  525. __le32 txRingSize; /* # of tx desc */
  526. __le32 dataRingSize; /* # of data desc */
  527. __le32 compRingSize; /* # of comp desc */
  528. __le32 ddLen; /* size of driver data */
  529. u8 intrIdx;
  530. u8 _pad[7];
  531. };
  532. struct Vmxnet3_RxQueueConf {
  533. __le64 rxRingBasePA[2];
  534. __le64 compRingBasePA;
  535. __le64 ddPA; /* driver data */
  536. __le64 reserved;
  537. __le32 rxRingSize[2]; /* # of rx desc */
  538. __le32 compRingSize; /* # of rx comp desc */
  539. __le32 ddLen; /* size of driver data */
  540. u8 intrIdx;
  541. u8 _pad[7];
  542. };
  543. enum vmxnet3_intr_mask_mode {
  544. VMXNET3_IMM_AUTO = 0,
  545. VMXNET3_IMM_ACTIVE = 1,
  546. VMXNET3_IMM_LAZY = 2
  547. };
  548. enum vmxnet3_intr_type {
  549. VMXNET3_IT_AUTO = 0,
  550. VMXNET3_IT_INTX = 1,
  551. VMXNET3_IT_MSI = 2,
  552. VMXNET3_IT_MSIX = 3
  553. };
  554. #define VMXNET3_MAX_TX_QUEUES 8
  555. #define VMXNET3_MAX_RX_QUEUES 16
  556. /* addition 1 for events */
  557. #define VMXNET3_MAX_INTRS 25
  558. /* value of intrCtrl */
  559. #define VMXNET3_IC_DISABLE_ALL 0x1 /* bit 0 */
  560. struct Vmxnet3_IntrConf {
  561. bool autoMask;
  562. u8 numIntrs; /* # of interrupts */
  563. u8 eventIntrIdx;
  564. u8 modLevels[VMXNET3_MAX_INTRS]; /* moderation level for
  565. * each intr */
  566. __le32 intrCtrl;
  567. __le32 reserved[2];
  568. };
  569. /* one bit per VLAN ID, the size is in the units of u32 */
  570. #define VMXNET3_VFT_SIZE (4096/(sizeof(uint32_t)*8))
  571. struct Vmxnet3_QueueStatus {
  572. bool stopped;
  573. u8 _pad[3];
  574. __le32 error;
  575. };
  576. struct Vmxnet3_TxQueueCtrl {
  577. __le32 txNumDeferred;
  578. __le32 txThreshold;
  579. __le64 reserved;
  580. };
  581. struct Vmxnet3_RxQueueCtrl {
  582. bool updateRxProd;
  583. u8 _pad[7];
  584. __le64 reserved;
  585. };
  586. enum {
  587. VMXNET3_RXM_UCAST = 0x01, /* unicast only */
  588. VMXNET3_RXM_MCAST = 0x02, /* multicast passing the filters */
  589. VMXNET3_RXM_BCAST = 0x04, /* broadcast only */
  590. VMXNET3_RXM_ALL_MULTI = 0x08, /* all multicast */
  591. VMXNET3_RXM_PROMISC = 0x10 /* promiscuous */
  592. };
  593. struct Vmxnet3_RxFilterConf {
  594. __le32 rxMode; /* VMXNET3_RXM_xxx */
  595. __le16 mfTableLen; /* size of the multicast filter table */
  596. __le16 _pad1;
  597. __le64 mfTablePA; /* PA of the multicast filters table */
  598. __le32 vfTable[VMXNET3_VFT_SIZE]; /* vlan filter */
  599. };
  600. #define VMXNET3_PM_MAX_FILTERS 6
  601. #define VMXNET3_PM_MAX_PATTERN_SIZE 128
  602. #define VMXNET3_PM_MAX_MASK_SIZE (VMXNET3_PM_MAX_PATTERN_SIZE / 8)
  603. #define VMXNET3_PM_WAKEUP_MAGIC cpu_to_le16(0x01) /* wake up on magic pkts */
  604. #define VMXNET3_PM_WAKEUP_FILTER cpu_to_le16(0x02) /* wake up on pkts matching
  605. * filters */
  606. struct Vmxnet3_PM_PktFilter {
  607. u8 maskSize;
  608. u8 patternSize;
  609. u8 mask[VMXNET3_PM_MAX_MASK_SIZE];
  610. u8 pattern[VMXNET3_PM_MAX_PATTERN_SIZE];
  611. u8 pad[6];
  612. };
  613. struct Vmxnet3_PMConf {
  614. __le16 wakeUpEvents; /* VMXNET3_PM_WAKEUP_xxx */
  615. u8 numFilters;
  616. u8 pad[5];
  617. struct Vmxnet3_PM_PktFilter filters[VMXNET3_PM_MAX_FILTERS];
  618. };
  619. struct Vmxnet3_VariableLenConfDesc {
  620. __le32 confVer;
  621. __le32 confLen;
  622. __le64 confPA;
  623. };
  624. struct Vmxnet3_TxQueueDesc {
  625. struct Vmxnet3_TxQueueCtrl ctrl;
  626. struct Vmxnet3_TxQueueConf conf;
  627. /* Driver read after a GET command */
  628. struct Vmxnet3_QueueStatus status;
  629. struct UPT1_TxStats stats;
  630. u8 _pad[88]; /* 128 aligned */
  631. };
  632. struct Vmxnet3_RxQueueDesc {
  633. struct Vmxnet3_RxQueueCtrl ctrl;
  634. struct Vmxnet3_RxQueueConf conf;
  635. /* Driver read after a GET command */
  636. struct Vmxnet3_QueueStatus status;
  637. struct UPT1_RxStats stats;
  638. u8 __pad[88]; /* 128 aligned */
  639. };
  640. struct Vmxnet3_DSDevRead {
  641. /* read-only region for device, read by dev in response to a SET cmd */
  642. struct Vmxnet3_MiscConf misc;
  643. struct Vmxnet3_IntrConf intrConf;
  644. struct Vmxnet3_RxFilterConf rxFilterConf;
  645. struct Vmxnet3_VariableLenConfDesc rssConfDesc;
  646. struct Vmxnet3_VariableLenConfDesc pmConfDesc;
  647. struct Vmxnet3_VariableLenConfDesc pluginConfDesc;
  648. };
  649. /* All structures in DriverShared are padded to multiples of 8 bytes */
  650. struct Vmxnet3_DriverShared {
  651. __le32 magic;
  652. /* make devRead start at 64bit boundaries */
  653. __le32 pad;
  654. struct Vmxnet3_DSDevRead devRead;
  655. __le32 ecr;
  656. __le32 reserved[5];
  657. };
  658. #define VMXNET3_ECR_RQERR (1 << 0)
  659. #define VMXNET3_ECR_TQERR (1 << 1)
  660. #define VMXNET3_ECR_LINK (1 << 2)
  661. #define VMXNET3_ECR_DIC (1 << 3)
  662. #define VMXNET3_ECR_DEBUG (1 << 4)
  663. /* flip the gen bit of a ring */
  664. #define VMXNET3_FLIP_RING_GEN(gen) ((gen) = (gen) ^ 0x1)
  665. /* only use this if moving the idx won't affect the gen bit */
  666. #define VMXNET3_INC_RING_IDX_ONLY(idx, ring_size) \
  667. do {\
  668. (idx)++;\
  669. if (unlikely((idx) == (ring_size))) {\
  670. (idx) = 0;\
  671. } \
  672. } while (0)
  673. #define VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid) \
  674. (vfTable[vid >> 5] |= (1 << (vid & 31)))
  675. #define VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid) \
  676. (vfTable[vid >> 5] &= ~(1 << (vid & 31)))
  677. #define VMXNET3_VFTABLE_ENTRY_IS_SET(vfTable, vid) \
  678. ((vfTable[vid >> 5] & (1 << (vid & 31))) != 0)
  679. #define VMXNET3_MAX_MTU 9000
  680. #define VMXNET3_MIN_MTU 60
  681. #define VMXNET3_LINK_UP (10000 << 16 | 1) /* 10 Gbps, up */
  682. #define VMXNET3_LINK_DOWN 0
  683. #undef u64
  684. #undef u32
  685. #undef u16
  686. #undef u8
  687. #undef __le16
  688. #undef __le32
  689. #undef __le64
  690. #if HOST_BIG_ENDIAN
  691. #undef __BIG_ENDIAN_BITFIELD
  692. #endif
  693. #endif