vmxnet3_defs.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /*
  2. * Linux driver for VMware's vmxnet3 ethernet NIC.
  3. *
  4. * Copyright (C) 2008-2016, VMware, Inc. All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; version 2 of the License and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  13. * NON INFRINGEMENT. See the GNU General Public License for more
  14. * 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 St, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * The full GNU General Public License is included in this distribution in
  21. * the file called "COPYING".
  22. *
  23. * Maintained by: pv-drivers@vmware.com
  24. *
  25. */
  26. #ifndef _VMXNET3_DEFS_H_
  27. #define _VMXNET3_DEFS_H_
  28. #include "upt1_defs.h"
  29. /* all registers are 32 bit wide */
  30. /* BAR 1 */
  31. enum {
  32. VMXNET3_REG_VRRS = 0x0, /* Vmxnet3 Revision Report Selection */
  33. VMXNET3_REG_UVRS = 0x8, /* UPT Version Report Selection */
  34. VMXNET3_REG_DSAL = 0x10, /* Driver Shared Address Low */
  35. VMXNET3_REG_DSAH = 0x18, /* Driver Shared Address High */
  36. VMXNET3_REG_CMD = 0x20, /* Command */
  37. VMXNET3_REG_MACL = 0x28, /* MAC Address Low */
  38. VMXNET3_REG_MACH = 0x30, /* MAC Address High */
  39. VMXNET3_REG_ICR = 0x38, /* Interrupt Cause Register */
  40. VMXNET3_REG_ECR = 0x40 /* Event Cause Register */
  41. };
  42. /* BAR 0 */
  43. enum {
  44. VMXNET3_REG_IMR = 0x0, /* Interrupt Mask Register */
  45. VMXNET3_REG_TXPROD = 0x600, /* Tx Producer Index */
  46. VMXNET3_REG_RXPROD = 0x800, /* Rx Producer Index for ring 1 */
  47. VMXNET3_REG_RXPROD2 = 0xA00 /* Rx Producer Index for ring 2 */
  48. };
  49. #define VMXNET3_PT_REG_SIZE 4096 /* BAR 0 */
  50. #define VMXNET3_VD_REG_SIZE 4096 /* BAR 1 */
  51. #define VMXNET3_REG_ALIGN 8 /* All registers are 8-byte aligned. */
  52. #define VMXNET3_REG_ALIGN_MASK 0x7
  53. /* I/O Mapped access to registers */
  54. #define VMXNET3_IO_TYPE_PT 0
  55. #define VMXNET3_IO_TYPE_VD 1
  56. #define VMXNET3_IO_ADDR(type, reg) (((type) << 24) | ((reg) & 0xFFFFFF))
  57. #define VMXNET3_IO_TYPE(addr) ((addr) >> 24)
  58. #define VMXNET3_IO_REG(addr) ((addr) & 0xFFFFFF)
  59. enum {
  60. VMXNET3_CMD_FIRST_SET = 0xCAFE0000,
  61. VMXNET3_CMD_ACTIVATE_DEV = VMXNET3_CMD_FIRST_SET,
  62. VMXNET3_CMD_QUIESCE_DEV,
  63. VMXNET3_CMD_RESET_DEV,
  64. VMXNET3_CMD_UPDATE_RX_MODE,
  65. VMXNET3_CMD_UPDATE_MAC_FILTERS,
  66. VMXNET3_CMD_UPDATE_VLAN_FILTERS,
  67. VMXNET3_CMD_UPDATE_RSSIDT,
  68. VMXNET3_CMD_UPDATE_IML,
  69. VMXNET3_CMD_UPDATE_PMCFG,
  70. VMXNET3_CMD_UPDATE_FEATURE,
  71. VMXNET3_CMD_RESERVED1,
  72. VMXNET3_CMD_LOAD_PLUGIN,
  73. VMXNET3_CMD_RESERVED2,
  74. VMXNET3_CMD_RESERVED3,
  75. VMXNET3_CMD_SET_COALESCE,
  76. VMXNET3_CMD_REGISTER_MEMREGS,
  77. VMXNET3_CMD_FIRST_GET = 0xF00D0000,
  78. VMXNET3_CMD_GET_QUEUE_STATUS = VMXNET3_CMD_FIRST_GET,
  79. VMXNET3_CMD_GET_STATS,
  80. VMXNET3_CMD_GET_LINK,
  81. VMXNET3_CMD_GET_PERM_MAC_LO,
  82. VMXNET3_CMD_GET_PERM_MAC_HI,
  83. VMXNET3_CMD_GET_DID_LO,
  84. VMXNET3_CMD_GET_DID_HI,
  85. VMXNET3_CMD_GET_DEV_EXTRA_INFO,
  86. VMXNET3_CMD_GET_CONF_INTR,
  87. VMXNET3_CMD_GET_RESERVED1,
  88. VMXNET3_CMD_GET_TXDATA_DESC_SIZE,
  89. VMXNET3_CMD_GET_COALESCE,
  90. };
  91. /*
  92. * Little Endian layout of bitfields -
  93. * Byte 0 : 7.....len.....0
  94. * Byte 1 : rsvd gen 13.len.8
  95. * Byte 2 : 5.msscof.0 ext1 dtype
  96. * Byte 3 : 13...msscof...6
  97. *
  98. * Big Endian layout of bitfields -
  99. * Byte 0: 13...msscof...6
  100. * Byte 1 : 5.msscof.0 ext1 dtype
  101. * Byte 2 : rsvd gen 13.len.8
  102. * Byte 3 : 7.....len.....0
  103. *
  104. * Thus, le32_to_cpu on the dword will allow the big endian driver to read
  105. * the bit fields correctly. And cpu_to_le32 will convert bitfields
  106. * bit fields written by big endian driver to format required by device.
  107. */
  108. struct Vmxnet3_TxDesc {
  109. __le64 addr;
  110. #ifdef __BIG_ENDIAN_BITFIELD
  111. u32 msscof:14; /* MSS, checksum offset, flags */
  112. u32 ext1:1;
  113. u32 dtype:1; /* descriptor type */
  114. u32 rsvd:1;
  115. u32 gen:1; /* generation bit */
  116. u32 len:14;
  117. #else
  118. u32 len:14;
  119. u32 gen:1; /* generation bit */
  120. u32 rsvd:1;
  121. u32 dtype:1; /* descriptor type */
  122. u32 ext1:1;
  123. u32 msscof:14; /* MSS, checksum offset, flags */
  124. #endif /* __BIG_ENDIAN_BITFIELD */
  125. #ifdef __BIG_ENDIAN_BITFIELD
  126. u32 tci:16; /* Tag to Insert */
  127. u32 ti:1; /* VLAN Tag Insertion */
  128. u32 ext2:1;
  129. u32 cq:1; /* completion request */
  130. u32 eop:1; /* End Of Packet */
  131. u32 om:2; /* offload mode */
  132. u32 hlen:10; /* header len */
  133. #else
  134. u32 hlen:10; /* header len */
  135. u32 om:2; /* offload mode */
  136. u32 eop:1; /* End Of Packet */
  137. u32 cq:1; /* completion request */
  138. u32 ext2:1;
  139. u32 ti:1; /* VLAN Tag Insertion */
  140. u32 tci:16; /* Tag to Insert */
  141. #endif /* __BIG_ENDIAN_BITFIELD */
  142. };
  143. /* TxDesc.OM values */
  144. #define VMXNET3_OM_NONE 0
  145. #define VMXNET3_OM_CSUM 2
  146. #define VMXNET3_OM_TSO 3
  147. /* fields in TxDesc we access w/o using bit fields */
  148. #define VMXNET3_TXD_EOP_SHIFT 12
  149. #define VMXNET3_TXD_CQ_SHIFT 13
  150. #define VMXNET3_TXD_GEN_SHIFT 14
  151. #define VMXNET3_TXD_EOP_DWORD_SHIFT 3
  152. #define VMXNET3_TXD_GEN_DWORD_SHIFT 2
  153. #define VMXNET3_TXD_CQ (1 << VMXNET3_TXD_CQ_SHIFT)
  154. #define VMXNET3_TXD_EOP (1 << VMXNET3_TXD_EOP_SHIFT)
  155. #define VMXNET3_TXD_GEN (1 << VMXNET3_TXD_GEN_SHIFT)
  156. #define VMXNET3_HDR_COPY_SIZE 128
  157. struct Vmxnet3_TxDataDesc {
  158. u8 data[VMXNET3_HDR_COPY_SIZE];
  159. };
  160. typedef u8 Vmxnet3_RxDataDesc;
  161. #define VMXNET3_TCD_GEN_SHIFT 31
  162. #define VMXNET3_TCD_GEN_SIZE 1
  163. #define VMXNET3_TCD_TXIDX_SHIFT 0
  164. #define VMXNET3_TCD_TXIDX_SIZE 12
  165. #define VMXNET3_TCD_GEN_DWORD_SHIFT 3
  166. struct Vmxnet3_TxCompDesc {
  167. u32 txdIdx:12; /* Index of the EOP TxDesc */
  168. u32 ext1:20;
  169. __le32 ext2;
  170. __le32 ext3;
  171. u32 rsvd:24;
  172. u32 type:7; /* completion type */
  173. u32 gen:1; /* generation bit */
  174. };
  175. struct Vmxnet3_RxDesc {
  176. __le64 addr;
  177. #ifdef __BIG_ENDIAN_BITFIELD
  178. u32 gen:1; /* Generation bit */
  179. u32 rsvd:15;
  180. u32 dtype:1; /* Descriptor type */
  181. u32 btype:1; /* Buffer Type */
  182. u32 len:14;
  183. #else
  184. u32 len:14;
  185. u32 btype:1; /* Buffer Type */
  186. u32 dtype:1; /* Descriptor type */
  187. u32 rsvd:15;
  188. u32 gen:1; /* Generation bit */
  189. #endif
  190. u32 ext1;
  191. };
  192. /* values of RXD.BTYPE */
  193. #define VMXNET3_RXD_BTYPE_HEAD 0 /* head only */
  194. #define VMXNET3_RXD_BTYPE_BODY 1 /* body only */
  195. /* fields in RxDesc we access w/o using bit fields */
  196. #define VMXNET3_RXD_BTYPE_SHIFT 14
  197. #define VMXNET3_RXD_GEN_SHIFT 31
  198. struct Vmxnet3_RxCompDesc {
  199. #ifdef __BIG_ENDIAN_BITFIELD
  200. u32 ext2:1;
  201. u32 cnc:1; /* Checksum Not Calculated */
  202. u32 rssType:4; /* RSS hash type used */
  203. u32 rqID:10; /* rx queue/ring ID */
  204. u32 sop:1; /* Start of Packet */
  205. u32 eop:1; /* End of Packet */
  206. u32 ext1:2;
  207. u32 rxdIdx:12; /* Index of the RxDesc */
  208. #else
  209. u32 rxdIdx:12; /* Index of the RxDesc */
  210. u32 ext1:2;
  211. u32 eop:1; /* End of Packet */
  212. u32 sop:1; /* Start of Packet */
  213. u32 rqID:10; /* rx queue/ring ID */
  214. u32 rssType:4; /* RSS hash type used */
  215. u32 cnc:1; /* Checksum Not Calculated */
  216. u32 ext2:1;
  217. #endif /* __BIG_ENDIAN_BITFIELD */
  218. __le32 rssHash; /* RSS hash value */
  219. #ifdef __BIG_ENDIAN_BITFIELD
  220. u32 tci:16; /* Tag stripped */
  221. u32 ts:1; /* Tag is stripped */
  222. u32 err:1; /* Error */
  223. u32 len:14; /* data length */
  224. #else
  225. u32 len:14; /* data length */
  226. u32 err:1; /* Error */
  227. u32 ts:1; /* Tag is stripped */
  228. u32 tci:16; /* Tag stripped */
  229. #endif /* __BIG_ENDIAN_BITFIELD */
  230. #ifdef __BIG_ENDIAN_BITFIELD
  231. u32 gen:1; /* generation bit */
  232. u32 type:7; /* completion type */
  233. u32 fcs:1; /* Frame CRC correct */
  234. u32 frg:1; /* IP Fragment */
  235. u32 v4:1; /* IPv4 */
  236. u32 v6:1; /* IPv6 */
  237. u32 ipc:1; /* IP Checksum Correct */
  238. u32 tcp:1; /* TCP packet */
  239. u32 udp:1; /* UDP packet */
  240. u32 tuc:1; /* TCP/UDP Checksum Correct */
  241. u32 csum:16;
  242. #else
  243. u32 csum:16;
  244. u32 tuc:1; /* TCP/UDP Checksum Correct */
  245. u32 udp:1; /* UDP packet */
  246. u32 tcp:1; /* TCP packet */
  247. u32 ipc:1; /* IP Checksum Correct */
  248. u32 v6:1; /* IPv6 */
  249. u32 v4:1; /* IPv4 */
  250. u32 frg:1; /* IP Fragment */
  251. u32 fcs:1; /* Frame CRC correct */
  252. u32 type:7; /* completion type */
  253. u32 gen:1; /* generation bit */
  254. #endif /* __BIG_ENDIAN_BITFIELD */
  255. };
  256. struct Vmxnet3_RxCompDescExt {
  257. __le32 dword1;
  258. u8 segCnt; /* Number of aggregated packets */
  259. u8 dupAckCnt; /* Number of duplicate Acks */
  260. __le16 tsDelta; /* TCP timestamp difference */
  261. __le32 dword2;
  262. #ifdef __BIG_ENDIAN_BITFIELD
  263. u32 gen:1; /* generation bit */
  264. u32 type:7; /* completion type */
  265. u32 fcs:1; /* Frame CRC correct */
  266. u32 frg:1; /* IP Fragment */
  267. u32 v4:1; /* IPv4 */
  268. u32 v6:1; /* IPv6 */
  269. u32 ipc:1; /* IP Checksum Correct */
  270. u32 tcp:1; /* TCP packet */
  271. u32 udp:1; /* UDP packet */
  272. u32 tuc:1; /* TCP/UDP Checksum Correct */
  273. u32 mss:16;
  274. #else
  275. u32 mss:16;
  276. u32 tuc:1; /* TCP/UDP Checksum Correct */
  277. u32 udp:1; /* UDP packet */
  278. u32 tcp:1; /* TCP packet */
  279. u32 ipc:1; /* IP Checksum Correct */
  280. u32 v6:1; /* IPv6 */
  281. u32 v4:1; /* IPv4 */
  282. u32 frg:1; /* IP Fragment */
  283. u32 fcs:1; /* Frame CRC correct */
  284. u32 type:7; /* completion type */
  285. u32 gen:1; /* generation bit */
  286. #endif /* __BIG_ENDIAN_BITFIELD */
  287. };
  288. /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.dword[3] */
  289. #define VMXNET3_RCD_TUC_SHIFT 16
  290. #define VMXNET3_RCD_IPC_SHIFT 19
  291. /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.qword[1] */
  292. #define VMXNET3_RCD_TYPE_SHIFT 56
  293. #define VMXNET3_RCD_GEN_SHIFT 63
  294. /* csum OK for TCP/UDP pkts over IP */
  295. #define VMXNET3_RCD_CSUM_OK (1 << VMXNET3_RCD_TUC_SHIFT | \
  296. 1 << VMXNET3_RCD_IPC_SHIFT)
  297. #define VMXNET3_TXD_GEN_SIZE 1
  298. #define VMXNET3_TXD_EOP_SIZE 1
  299. /* value of RxCompDesc.rssType */
  300. enum {
  301. VMXNET3_RCD_RSS_TYPE_NONE = 0,
  302. VMXNET3_RCD_RSS_TYPE_IPV4 = 1,
  303. VMXNET3_RCD_RSS_TYPE_TCPIPV4 = 2,
  304. VMXNET3_RCD_RSS_TYPE_IPV6 = 3,
  305. VMXNET3_RCD_RSS_TYPE_TCPIPV6 = 4,
  306. };
  307. /* a union for accessing all cmd/completion descriptors */
  308. union Vmxnet3_GenericDesc {
  309. __le64 qword[2];
  310. __le32 dword[4];
  311. __le16 word[8];
  312. struct Vmxnet3_TxDesc txd;
  313. struct Vmxnet3_RxDesc rxd;
  314. struct Vmxnet3_TxCompDesc tcd;
  315. struct Vmxnet3_RxCompDesc rcd;
  316. struct Vmxnet3_RxCompDescExt rcdExt;
  317. };
  318. #define VMXNET3_INIT_GEN 1
  319. /* Max size of a single tx buffer */
  320. #define VMXNET3_MAX_TX_BUF_SIZE (1 << 14)
  321. /* # of tx desc needed for a tx buffer size */
  322. #define VMXNET3_TXD_NEEDED(size) (((size) + VMXNET3_MAX_TX_BUF_SIZE - 1) / \
  323. VMXNET3_MAX_TX_BUF_SIZE)
  324. /* max # of tx descs for a non-tso pkt */
  325. #define VMXNET3_MAX_TXD_PER_PKT 16
  326. /* Max size of a single rx buffer */
  327. #define VMXNET3_MAX_RX_BUF_SIZE ((1 << 14) - 1)
  328. /* Minimum size of a type 0 buffer */
  329. #define VMXNET3_MIN_T0_BUF_SIZE 128
  330. #define VMXNET3_MAX_CSUM_OFFSET 1024
  331. /* Ring base address alignment */
  332. #define VMXNET3_RING_BA_ALIGN 512
  333. #define VMXNET3_RING_BA_MASK (VMXNET3_RING_BA_ALIGN - 1)
  334. /* Ring size must be a multiple of 32 */
  335. #define VMXNET3_RING_SIZE_ALIGN 32
  336. #define VMXNET3_RING_SIZE_MASK (VMXNET3_RING_SIZE_ALIGN - 1)
  337. /* Tx Data Ring buffer size must be a multiple of 64 */
  338. #define VMXNET3_TXDATA_DESC_SIZE_ALIGN 64
  339. #define VMXNET3_TXDATA_DESC_SIZE_MASK (VMXNET3_TXDATA_DESC_SIZE_ALIGN - 1)
  340. /* Rx Data Ring buffer size must be a multiple of 64 */
  341. #define VMXNET3_RXDATA_DESC_SIZE_ALIGN 64
  342. #define VMXNET3_RXDATA_DESC_SIZE_MASK (VMXNET3_RXDATA_DESC_SIZE_ALIGN - 1)
  343. /* Max ring size */
  344. #define VMXNET3_TX_RING_MAX_SIZE 4096
  345. #define VMXNET3_TC_RING_MAX_SIZE 4096
  346. #define VMXNET3_RX_RING_MAX_SIZE 4096
  347. #define VMXNET3_RX_RING2_MAX_SIZE 4096
  348. #define VMXNET3_RC_RING_MAX_SIZE 8192
  349. #define VMXNET3_TXDATA_DESC_MIN_SIZE 128
  350. #define VMXNET3_TXDATA_DESC_MAX_SIZE 2048
  351. #define VMXNET3_RXDATA_DESC_MAX_SIZE 2048
  352. /* a list of reasons for queue stop */
  353. enum {
  354. VMXNET3_ERR_NOEOP = 0x80000000, /* cannot find the EOP desc of a pkt */
  355. VMXNET3_ERR_TXD_REUSE = 0x80000001, /* reuse TxDesc before tx completion */
  356. VMXNET3_ERR_BIG_PKT = 0x80000002, /* too many TxDesc for a pkt */
  357. VMXNET3_ERR_DESC_NOT_SPT = 0x80000003, /* descriptor type not supported */
  358. VMXNET3_ERR_SMALL_BUF = 0x80000004, /* type 0 buffer too small */
  359. VMXNET3_ERR_STRESS = 0x80000005, /* stress option firing in vmkernel */
  360. VMXNET3_ERR_SWITCH = 0x80000006, /* mode switch failure */
  361. VMXNET3_ERR_TXD_INVALID = 0x80000007, /* invalid TxDesc */
  362. };
  363. /* completion descriptor types */
  364. #define VMXNET3_CDTYPE_TXCOMP 0 /* Tx Completion Descriptor */
  365. #define VMXNET3_CDTYPE_RXCOMP 3 /* Rx Completion Descriptor */
  366. #define VMXNET3_CDTYPE_RXCOMP_LRO 4 /* Rx Completion Descriptor for LRO */
  367. enum {
  368. VMXNET3_GOS_BITS_UNK = 0, /* unknown */
  369. VMXNET3_GOS_BITS_32 = 1,
  370. VMXNET3_GOS_BITS_64 = 2,
  371. };
  372. #define VMXNET3_GOS_TYPE_LINUX 1
  373. struct Vmxnet3_GOSInfo {
  374. #ifdef __BIG_ENDIAN_BITFIELD
  375. u32 gosMisc:10; /* other info about gos */
  376. u32 gosVer:16; /* gos version */
  377. u32 gosType:4; /* which guest */
  378. u32 gosBits:2; /* 32-bit or 64-bit? */
  379. #else
  380. u32 gosBits:2; /* 32-bit or 64-bit? */
  381. u32 gosType:4; /* which guest */
  382. u32 gosVer:16; /* gos version */
  383. u32 gosMisc:10; /* other info about gos */
  384. #endif /* __BIG_ENDIAN_BITFIELD */
  385. };
  386. struct Vmxnet3_DriverInfo {
  387. __le32 version;
  388. struct Vmxnet3_GOSInfo gos;
  389. __le32 vmxnet3RevSpt;
  390. __le32 uptVerSpt;
  391. };
  392. #define VMXNET3_REV1_MAGIC 3133079265u
  393. /*
  394. * QueueDescPA must be 128 bytes aligned. It points to an array of
  395. * Vmxnet3_TxQueueDesc followed by an array of Vmxnet3_RxQueueDesc.
  396. * The number of Vmxnet3_TxQueueDesc/Vmxnet3_RxQueueDesc are specified by
  397. * Vmxnet3_MiscConf.numTxQueues/numRxQueues, respectively.
  398. */
  399. #define VMXNET3_QUEUE_DESC_ALIGN 128
  400. struct Vmxnet3_MiscConf {
  401. struct Vmxnet3_DriverInfo driverInfo;
  402. __le64 uptFeatures;
  403. __le64 ddPA; /* driver data PA */
  404. __le64 queueDescPA; /* queue descriptor table PA */
  405. __le32 ddLen; /* driver data len */
  406. __le32 queueDescLen; /* queue desc. table len in bytes */
  407. __le32 mtu;
  408. __le16 maxNumRxSG;
  409. u8 numTxQueues;
  410. u8 numRxQueues;
  411. __le32 reserved[4];
  412. };
  413. struct Vmxnet3_TxQueueConf {
  414. __le64 txRingBasePA;
  415. __le64 dataRingBasePA;
  416. __le64 compRingBasePA;
  417. __le64 ddPA; /* driver data */
  418. __le64 reserved;
  419. __le32 txRingSize; /* # of tx desc */
  420. __le32 dataRingSize; /* # of data desc */
  421. __le32 compRingSize; /* # of comp desc */
  422. __le32 ddLen; /* size of driver data */
  423. u8 intrIdx;
  424. u8 _pad1[1];
  425. __le16 txDataRingDescSize;
  426. u8 _pad2[4];
  427. };
  428. struct Vmxnet3_RxQueueConf {
  429. __le64 rxRingBasePA[2];
  430. __le64 compRingBasePA;
  431. __le64 ddPA; /* driver data */
  432. __le64 rxDataRingBasePA;
  433. __le32 rxRingSize[2]; /* # of rx desc */
  434. __le32 compRingSize; /* # of rx comp desc */
  435. __le32 ddLen; /* size of driver data */
  436. u8 intrIdx;
  437. u8 _pad1[1];
  438. __le16 rxDataRingDescSize; /* size of rx data ring buffer */
  439. u8 _pad2[4];
  440. };
  441. enum vmxnet3_intr_mask_mode {
  442. VMXNET3_IMM_AUTO = 0,
  443. VMXNET3_IMM_ACTIVE = 1,
  444. VMXNET3_IMM_LAZY = 2
  445. };
  446. enum vmxnet3_intr_type {
  447. VMXNET3_IT_AUTO = 0,
  448. VMXNET3_IT_INTX = 1,
  449. VMXNET3_IT_MSI = 2,
  450. VMXNET3_IT_MSIX = 3
  451. };
  452. #define VMXNET3_MAX_TX_QUEUES 8
  453. #define VMXNET3_MAX_RX_QUEUES 16
  454. /* addition 1 for events */
  455. #define VMXNET3_MAX_INTRS 25
  456. /* value of intrCtrl */
  457. #define VMXNET3_IC_DISABLE_ALL 0x1 /* bit 0 */
  458. struct Vmxnet3_IntrConf {
  459. bool autoMask;
  460. u8 numIntrs; /* # of interrupts */
  461. u8 eventIntrIdx;
  462. u8 modLevels[VMXNET3_MAX_INTRS]; /* moderation level for
  463. * each intr */
  464. __le32 intrCtrl;
  465. __le32 reserved[2];
  466. };
  467. /* one bit per VLAN ID, the size is in the units of u32 */
  468. #define VMXNET3_VFT_SIZE (4096 / (sizeof(u32) * 8))
  469. struct Vmxnet3_QueueStatus {
  470. bool stopped;
  471. u8 _pad[3];
  472. __le32 error;
  473. };
  474. struct Vmxnet3_TxQueueCtrl {
  475. __le32 txNumDeferred;
  476. __le32 txThreshold;
  477. __le64 reserved;
  478. };
  479. struct Vmxnet3_RxQueueCtrl {
  480. bool updateRxProd;
  481. u8 _pad[7];
  482. __le64 reserved;
  483. };
  484. enum {
  485. VMXNET3_RXM_UCAST = 0x01, /* unicast only */
  486. VMXNET3_RXM_MCAST = 0x02, /* multicast passing the filters */
  487. VMXNET3_RXM_BCAST = 0x04, /* broadcast only */
  488. VMXNET3_RXM_ALL_MULTI = 0x08, /* all multicast */
  489. VMXNET3_RXM_PROMISC = 0x10 /* promiscuous */
  490. };
  491. struct Vmxnet3_RxFilterConf {
  492. __le32 rxMode; /* VMXNET3_RXM_xxx */
  493. __le16 mfTableLen; /* size of the multicast filter table */
  494. __le16 _pad1;
  495. __le64 mfTablePA; /* PA of the multicast filters table */
  496. __le32 vfTable[VMXNET3_VFT_SIZE]; /* vlan filter */
  497. };
  498. #define VMXNET3_PM_MAX_FILTERS 6
  499. #define VMXNET3_PM_MAX_PATTERN_SIZE 128
  500. #define VMXNET3_PM_MAX_MASK_SIZE (VMXNET3_PM_MAX_PATTERN_SIZE / 8)
  501. #define VMXNET3_PM_WAKEUP_MAGIC cpu_to_le16(0x01) /* wake up on magic pkts */
  502. #define VMXNET3_PM_WAKEUP_FILTER cpu_to_le16(0x02) /* wake up on pkts matching
  503. * filters */
  504. struct Vmxnet3_PM_PktFilter {
  505. u8 maskSize;
  506. u8 patternSize;
  507. u8 mask[VMXNET3_PM_MAX_MASK_SIZE];
  508. u8 pattern[VMXNET3_PM_MAX_PATTERN_SIZE];
  509. u8 pad[6];
  510. };
  511. struct Vmxnet3_PMConf {
  512. __le16 wakeUpEvents; /* VMXNET3_PM_WAKEUP_xxx */
  513. u8 numFilters;
  514. u8 pad[5];
  515. struct Vmxnet3_PM_PktFilter filters[VMXNET3_PM_MAX_FILTERS];
  516. };
  517. struct Vmxnet3_VariableLenConfDesc {
  518. __le32 confVer;
  519. __le32 confLen;
  520. __le64 confPA;
  521. };
  522. struct Vmxnet3_TxQueueDesc {
  523. struct Vmxnet3_TxQueueCtrl ctrl;
  524. struct Vmxnet3_TxQueueConf conf;
  525. /* Driver read after a GET command */
  526. struct Vmxnet3_QueueStatus status;
  527. struct UPT1_TxStats stats;
  528. u8 _pad[88]; /* 128 aligned */
  529. };
  530. struct Vmxnet3_RxQueueDesc {
  531. struct Vmxnet3_RxQueueCtrl ctrl;
  532. struct Vmxnet3_RxQueueConf conf;
  533. /* Driver read after a GET commad */
  534. struct Vmxnet3_QueueStatus status;
  535. struct UPT1_RxStats stats;
  536. u8 __pad[88]; /* 128 aligned */
  537. };
  538. struct Vmxnet3_SetPolling {
  539. u8 enablePolling;
  540. };
  541. #define VMXNET3_COAL_STATIC_MAX_DEPTH 128
  542. #define VMXNET3_COAL_RBC_MIN_RATE 100
  543. #define VMXNET3_COAL_RBC_MAX_RATE 100000
  544. enum Vmxnet3_CoalesceMode {
  545. VMXNET3_COALESCE_DISABLED = 0,
  546. VMXNET3_COALESCE_ADAPT = 1,
  547. VMXNET3_COALESCE_STATIC = 2,
  548. VMXNET3_COALESCE_RBC = 3
  549. };
  550. struct Vmxnet3_CoalesceRbc {
  551. u32 rbc_rate;
  552. };
  553. struct Vmxnet3_CoalesceStatic {
  554. u32 tx_depth;
  555. u32 tx_comp_depth;
  556. u32 rx_depth;
  557. };
  558. struct Vmxnet3_CoalesceScheme {
  559. enum Vmxnet3_CoalesceMode coalMode;
  560. union {
  561. struct Vmxnet3_CoalesceRbc coalRbc;
  562. struct Vmxnet3_CoalesceStatic coalStatic;
  563. } coalPara;
  564. };
  565. struct Vmxnet3_MemoryRegion {
  566. __le64 startPA;
  567. __le32 length;
  568. __le16 txQueueBits;
  569. __le16 rxQueueBits;
  570. };
  571. #define MAX_MEMORY_REGION_PER_QUEUE 16
  572. #define MAX_MEMORY_REGION_PER_DEVICE 256
  573. struct Vmxnet3_MemRegs {
  574. __le16 numRegs;
  575. __le16 pad[3];
  576. struct Vmxnet3_MemoryRegion memRegs[1];
  577. };
  578. /* If the command data <= 16 bytes, use the shared memory directly.
  579. * otherwise, use variable length configuration descriptor.
  580. */
  581. union Vmxnet3_CmdInfo {
  582. struct Vmxnet3_VariableLenConfDesc varConf;
  583. struct Vmxnet3_SetPolling setPolling;
  584. __le64 data[2];
  585. };
  586. struct Vmxnet3_DSDevRead {
  587. /* read-only region for device, read by dev in response to a SET cmd */
  588. struct Vmxnet3_MiscConf misc;
  589. struct Vmxnet3_IntrConf intrConf;
  590. struct Vmxnet3_RxFilterConf rxFilterConf;
  591. struct Vmxnet3_VariableLenConfDesc rssConfDesc;
  592. struct Vmxnet3_VariableLenConfDesc pmConfDesc;
  593. struct Vmxnet3_VariableLenConfDesc pluginConfDesc;
  594. };
  595. /* All structures in DriverShared are padded to multiples of 8 bytes */
  596. struct Vmxnet3_DriverShared {
  597. __le32 magic;
  598. /* make devRead start at 64bit boundaries */
  599. __le32 pad;
  600. struct Vmxnet3_DSDevRead devRead;
  601. __le32 ecr;
  602. __le32 reserved;
  603. union {
  604. __le32 reserved1[4];
  605. union Vmxnet3_CmdInfo cmdInfo; /* only valid in the context of
  606. * executing the relevant
  607. * command
  608. */
  609. } cu;
  610. };
  611. #define VMXNET3_ECR_RQERR (1 << 0)
  612. #define VMXNET3_ECR_TQERR (1 << 1)
  613. #define VMXNET3_ECR_LINK (1 << 2)
  614. #define VMXNET3_ECR_DIC (1 << 3)
  615. #define VMXNET3_ECR_DEBUG (1 << 4)
  616. /* flip the gen bit of a ring */
  617. #define VMXNET3_FLIP_RING_GEN(gen) ((gen) = (gen) ^ 0x1)
  618. /* only use this if moving the idx won't affect the gen bit */
  619. #define VMXNET3_INC_RING_IDX_ONLY(idx, ring_size) \
  620. do {\
  621. (idx)++;\
  622. if (unlikely((idx) == (ring_size))) {\
  623. (idx) = 0;\
  624. } \
  625. } while (0)
  626. #define VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid) \
  627. (vfTable[vid >> 5] |= (1 << (vid & 31)))
  628. #define VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid) \
  629. (vfTable[vid >> 5] &= ~(1 << (vid & 31)))
  630. #define VMXNET3_VFTABLE_ENTRY_IS_SET(vfTable, vid) \
  631. ((vfTable[vid >> 5] & (1 << (vid & 31))) != 0)
  632. #define VMXNET3_MAX_MTU 9000
  633. #define VMXNET3_MIN_MTU 60
  634. #define VMXNET3_LINK_UP (10000 << 16 | 1) /* 10 Gbps, up */
  635. #define VMXNET3_LINK_DOWN 0
  636. #endif /* _VMXNET3_DEFS_H_ */