vmxnet3_defs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. * Linux driver for VMware's vmxnet3 ethernet NIC.
  3. *
  4. * Copyright (C) 2008-2009, 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: Shreyas Bhatewara <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_LOAD_PLUGIN,
  72. VMXNET3_CMD_FIRST_GET = 0xF00D0000,
  73. VMXNET3_CMD_GET_QUEUE_STATUS = VMXNET3_CMD_FIRST_GET,
  74. VMXNET3_CMD_GET_STATS,
  75. VMXNET3_CMD_GET_LINK,
  76. VMXNET3_CMD_GET_PERM_MAC_LO,
  77. VMXNET3_CMD_GET_PERM_MAC_HI,
  78. VMXNET3_CMD_GET_DID_LO,
  79. VMXNET3_CMD_GET_DID_HI,
  80. VMXNET3_CMD_GET_DEV_EXTRA_INFO,
  81. VMXNET3_CMD_GET_CONF_INTR
  82. };
  83. struct Vmxnet3_TxDesc {
  84. u64 addr;
  85. u32 len:14;
  86. u32 gen:1; /* generation bit */
  87. u32 rsvd:1;
  88. u32 dtype:1; /* descriptor type */
  89. u32 ext1:1;
  90. u32 msscof:14; /* MSS, checksum offset, flags */
  91. u32 hlen:10; /* header len */
  92. u32 om:2; /* offload mode */
  93. u32 eop:1; /* End Of Packet */
  94. u32 cq:1; /* completion request */
  95. u32 ext2:1;
  96. u32 ti:1; /* VLAN Tag Insertion */
  97. u32 tci:16; /* Tag to Insert */
  98. };
  99. /* TxDesc.OM values */
  100. #define VMXNET3_OM_NONE 0
  101. #define VMXNET3_OM_CSUM 2
  102. #define VMXNET3_OM_TSO 3
  103. /* fields in TxDesc we access w/o using bit fields */
  104. #define VMXNET3_TXD_EOP_SHIFT 12
  105. #define VMXNET3_TXD_CQ_SHIFT 13
  106. #define VMXNET3_TXD_GEN_SHIFT 14
  107. #define VMXNET3_TXD_CQ (1 << VMXNET3_TXD_CQ_SHIFT)
  108. #define VMXNET3_TXD_EOP (1 << VMXNET3_TXD_EOP_SHIFT)
  109. #define VMXNET3_TXD_GEN (1 << VMXNET3_TXD_GEN_SHIFT)
  110. #define VMXNET3_HDR_COPY_SIZE 128
  111. struct Vmxnet3_TxDataDesc {
  112. u8 data[VMXNET3_HDR_COPY_SIZE];
  113. };
  114. struct Vmxnet3_TxCompDesc {
  115. u32 txdIdx:12; /* Index of the EOP TxDesc */
  116. u32 ext1:20;
  117. u32 ext2;
  118. u32 ext3;
  119. u32 rsvd:24;
  120. u32 type:7; /* completion type */
  121. u32 gen:1; /* generation bit */
  122. };
  123. struct Vmxnet3_RxDesc {
  124. u64 addr;
  125. u32 len:14;
  126. u32 btype:1; /* Buffer Type */
  127. u32 dtype:1; /* Descriptor type */
  128. u32 rsvd:15;
  129. u32 gen:1; /* Generation bit */
  130. u32 ext1;
  131. };
  132. /* values of RXD.BTYPE */
  133. #define VMXNET3_RXD_BTYPE_HEAD 0 /* head only */
  134. #define VMXNET3_RXD_BTYPE_BODY 1 /* body only */
  135. /* fields in RxDesc we access w/o using bit fields */
  136. #define VMXNET3_RXD_BTYPE_SHIFT 14
  137. #define VMXNET3_RXD_GEN_SHIFT 31
  138. struct Vmxnet3_RxCompDesc {
  139. u32 rxdIdx:12; /* Index of the RxDesc */
  140. u32 ext1:2;
  141. u32 eop:1; /* End of Packet */
  142. u32 sop:1; /* Start of Packet */
  143. u32 rqID:10; /* rx queue/ring ID */
  144. u32 rssType:4; /* RSS hash type used */
  145. u32 cnc:1; /* Checksum Not Calculated */
  146. u32 ext2:1;
  147. u32 rssHash; /* RSS hash value */
  148. u32 len:14; /* data length */
  149. u32 err:1; /* Error */
  150. u32 ts:1; /* Tag is stripped */
  151. u32 tci:16; /* Tag stripped */
  152. u32 csum:16;
  153. u32 tuc:1; /* TCP/UDP Checksum Correct */
  154. u32 udp:1; /* UDP packet */
  155. u32 tcp:1; /* TCP packet */
  156. u32 ipc:1; /* IP Checksum Correct */
  157. u32 v6:1; /* IPv6 */
  158. u32 v4:1; /* IPv4 */
  159. u32 frg:1; /* IP Fragment */
  160. u32 fcs:1; /* Frame CRC correct */
  161. u32 type:7; /* completion type */
  162. u32 gen:1; /* generation bit */
  163. };
  164. /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.dword[3] */
  165. #define VMXNET3_RCD_TUC_SHIFT 16
  166. #define VMXNET3_RCD_IPC_SHIFT 19
  167. /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.qword[1] */
  168. #define VMXNET3_RCD_TYPE_SHIFT 56
  169. #define VMXNET3_RCD_GEN_SHIFT 63
  170. /* csum OK for TCP/UDP pkts over IP */
  171. #define VMXNET3_RCD_CSUM_OK (1 << VMXNET3_RCD_TUC_SHIFT | \
  172. 1 << VMXNET3_RCD_IPC_SHIFT)
  173. /* value of RxCompDesc.rssType */
  174. enum {
  175. VMXNET3_RCD_RSS_TYPE_NONE = 0,
  176. VMXNET3_RCD_RSS_TYPE_IPV4 = 1,
  177. VMXNET3_RCD_RSS_TYPE_TCPIPV4 = 2,
  178. VMXNET3_RCD_RSS_TYPE_IPV6 = 3,
  179. VMXNET3_RCD_RSS_TYPE_TCPIPV6 = 4,
  180. };
  181. /* a union for accessing all cmd/completion descriptors */
  182. union Vmxnet3_GenericDesc {
  183. u64 qword[2];
  184. u32 dword[4];
  185. u16 word[8];
  186. struct Vmxnet3_TxDesc txd;
  187. struct Vmxnet3_RxDesc rxd;
  188. struct Vmxnet3_TxCompDesc tcd;
  189. struct Vmxnet3_RxCompDesc rcd;
  190. };
  191. #define VMXNET3_INIT_GEN 1
  192. /* Max size of a single tx buffer */
  193. #define VMXNET3_MAX_TX_BUF_SIZE (1 << 14)
  194. /* # of tx desc needed for a tx buffer size */
  195. #define VMXNET3_TXD_NEEDED(size) (((size) + VMXNET3_MAX_TX_BUF_SIZE - 1) / \
  196. VMXNET3_MAX_TX_BUF_SIZE)
  197. /* max # of tx descs for a non-tso pkt */
  198. #define VMXNET3_MAX_TXD_PER_PKT 16
  199. /* Max size of a single rx buffer */
  200. #define VMXNET3_MAX_RX_BUF_SIZE ((1 << 14) - 1)
  201. /* Minimum size of a type 0 buffer */
  202. #define VMXNET3_MIN_T0_BUF_SIZE 128
  203. #define VMXNET3_MAX_CSUM_OFFSET 1024
  204. /* Ring base address alignment */
  205. #define VMXNET3_RING_BA_ALIGN 512
  206. #define VMXNET3_RING_BA_MASK (VMXNET3_RING_BA_ALIGN - 1)
  207. /* Ring size must be a multiple of 32 */
  208. #define VMXNET3_RING_SIZE_ALIGN 32
  209. #define VMXNET3_RING_SIZE_MASK (VMXNET3_RING_SIZE_ALIGN - 1)
  210. /* Max ring size */
  211. #define VMXNET3_TX_RING_MAX_SIZE 4096
  212. #define VMXNET3_TC_RING_MAX_SIZE 4096
  213. #define VMXNET3_RX_RING_MAX_SIZE 4096
  214. #define VMXNET3_RC_RING_MAX_SIZE 8192
  215. /* a list of reasons for queue stop */
  216. enum {
  217. VMXNET3_ERR_NOEOP = 0x80000000, /* cannot find the EOP desc of a pkt */
  218. VMXNET3_ERR_TXD_REUSE = 0x80000001, /* reuse TxDesc before tx completion */
  219. VMXNET3_ERR_BIG_PKT = 0x80000002, /* too many TxDesc for a pkt */
  220. VMXNET3_ERR_DESC_NOT_SPT = 0x80000003, /* descriptor type not supported */
  221. VMXNET3_ERR_SMALL_BUF = 0x80000004, /* type 0 buffer too small */
  222. VMXNET3_ERR_STRESS = 0x80000005, /* stress option firing in vmkernel */
  223. VMXNET3_ERR_SWITCH = 0x80000006, /* mode switch failure */
  224. VMXNET3_ERR_TXD_INVALID = 0x80000007, /* invalid TxDesc */
  225. };
  226. /* completion descriptor types */
  227. #define VMXNET3_CDTYPE_TXCOMP 0 /* Tx Completion Descriptor */
  228. #define VMXNET3_CDTYPE_RXCOMP 3 /* Rx Completion Descriptor */
  229. enum {
  230. VMXNET3_GOS_BITS_UNK = 0, /* unknown */
  231. VMXNET3_GOS_BITS_32 = 1,
  232. VMXNET3_GOS_BITS_64 = 2,
  233. };
  234. #define VMXNET3_GOS_TYPE_LINUX 1
  235. struct Vmxnet3_GOSInfo {
  236. u32 gosBits:2; /* 32-bit or 64-bit? */
  237. u32 gosType:4; /* which guest */
  238. u32 gosVer:16; /* gos version */
  239. u32 gosMisc:10; /* other info about gos */
  240. };
  241. struct Vmxnet3_DriverInfo {
  242. u32 version;
  243. struct Vmxnet3_GOSInfo gos;
  244. u32 vmxnet3RevSpt;
  245. u32 uptVerSpt;
  246. };
  247. #define VMXNET3_REV1_MAGIC 0xbabefee1
  248. /*
  249. * QueueDescPA must be 128 bytes aligned. It points to an array of
  250. * Vmxnet3_TxQueueDesc followed by an array of Vmxnet3_RxQueueDesc.
  251. * The number of Vmxnet3_TxQueueDesc/Vmxnet3_RxQueueDesc are specified by
  252. * Vmxnet3_MiscConf.numTxQueues/numRxQueues, respectively.
  253. */
  254. #define VMXNET3_QUEUE_DESC_ALIGN 128
  255. struct Vmxnet3_MiscConf {
  256. struct Vmxnet3_DriverInfo driverInfo;
  257. u64 uptFeatures;
  258. u64 ddPA; /* driver data PA */
  259. u64 queueDescPA; /* queue descriptor table PA */
  260. u32 ddLen; /* driver data len */
  261. u32 queueDescLen; /* queue desc. table len in bytes */
  262. u32 mtu;
  263. u16 maxNumRxSG;
  264. u8 numTxQueues;
  265. u8 numRxQueues;
  266. u32 reserved[4];
  267. };
  268. struct Vmxnet3_TxQueueConf {
  269. u64 txRingBasePA;
  270. u64 dataRingBasePA;
  271. u64 compRingBasePA;
  272. u64 ddPA; /* driver data */
  273. u64 reserved;
  274. u32 txRingSize; /* # of tx desc */
  275. u32 dataRingSize; /* # of data desc */
  276. u32 compRingSize; /* # of comp desc */
  277. u32 ddLen; /* size of driver data */
  278. u8 intrIdx;
  279. u8 _pad[7];
  280. };
  281. struct Vmxnet3_RxQueueConf {
  282. u64 rxRingBasePA[2];
  283. u64 compRingBasePA;
  284. u64 ddPA; /* driver data */
  285. u64 reserved;
  286. u32 rxRingSize[2]; /* # of rx desc */
  287. u32 compRingSize; /* # of rx comp desc */
  288. u32 ddLen; /* size of driver data */
  289. u8 intrIdx;
  290. u8 _pad[7];
  291. };
  292. enum vmxnet3_intr_mask_mode {
  293. VMXNET3_IMM_AUTO = 0,
  294. VMXNET3_IMM_ACTIVE = 1,
  295. VMXNET3_IMM_LAZY = 2
  296. };
  297. enum vmxnet3_intr_type {
  298. VMXNET3_IT_AUTO = 0,
  299. VMXNET3_IT_INTX = 1,
  300. VMXNET3_IT_MSI = 2,
  301. VMXNET3_IT_MSIX = 3
  302. };
  303. #define VMXNET3_MAX_TX_QUEUES 8
  304. #define VMXNET3_MAX_RX_QUEUES 16
  305. /* addition 1 for events */
  306. #define VMXNET3_MAX_INTRS 25
  307. struct Vmxnet3_IntrConf {
  308. bool autoMask;
  309. u8 numIntrs; /* # of interrupts */
  310. u8 eventIntrIdx;
  311. u8 modLevels[VMXNET3_MAX_INTRS]; /* moderation level for
  312. * each intr */
  313. u32 reserved[3];
  314. };
  315. /* one bit per VLAN ID, the size is in the units of u32 */
  316. #define VMXNET3_VFT_SIZE (4096 / (sizeof(u32) * 8))
  317. struct Vmxnet3_QueueStatus {
  318. bool stopped;
  319. u8 _pad[3];
  320. u32 error;
  321. };
  322. struct Vmxnet3_TxQueueCtrl {
  323. u32 txNumDeferred;
  324. u32 txThreshold;
  325. u64 reserved;
  326. };
  327. struct Vmxnet3_RxQueueCtrl {
  328. bool updateRxProd;
  329. u8 _pad[7];
  330. u64 reserved;
  331. };
  332. enum {
  333. VMXNET3_RXM_UCAST = 0x01, /* unicast only */
  334. VMXNET3_RXM_MCAST = 0x02, /* multicast passing the filters */
  335. VMXNET3_RXM_BCAST = 0x04, /* broadcast only */
  336. VMXNET3_RXM_ALL_MULTI = 0x08, /* all multicast */
  337. VMXNET3_RXM_PROMISC = 0x10 /* promiscuous */
  338. };
  339. struct Vmxnet3_RxFilterConf {
  340. u32 rxMode; /* VMXNET3_RXM_xxx */
  341. u16 mfTableLen; /* size of the multicast filter table */
  342. u16 _pad1;
  343. u64 mfTablePA; /* PA of the multicast filters table */
  344. u32 vfTable[VMXNET3_VFT_SIZE]; /* vlan filter */
  345. };
  346. #define VMXNET3_PM_MAX_FILTERS 6
  347. #define VMXNET3_PM_MAX_PATTERN_SIZE 128
  348. #define VMXNET3_PM_MAX_MASK_SIZE (VMXNET3_PM_MAX_PATTERN_SIZE / 8)
  349. #define VMXNET3_PM_WAKEUP_MAGIC 0x01 /* wake up on magic pkts */
  350. #define VMXNET3_PM_WAKEUP_FILTER 0x02 /* wake up on pkts matching
  351. * filters */
  352. struct Vmxnet3_PM_PktFilter {
  353. u8 maskSize;
  354. u8 patternSize;
  355. u8 mask[VMXNET3_PM_MAX_MASK_SIZE];
  356. u8 pattern[VMXNET3_PM_MAX_PATTERN_SIZE];
  357. u8 pad[6];
  358. };
  359. struct Vmxnet3_PMConf {
  360. u16 wakeUpEvents; /* VMXNET3_PM_WAKEUP_xxx */
  361. u8 numFilters;
  362. u8 pad[5];
  363. struct Vmxnet3_PM_PktFilter filters[VMXNET3_PM_MAX_FILTERS];
  364. };
  365. struct Vmxnet3_VariableLenConfDesc {
  366. u32 confVer;
  367. u32 confLen;
  368. u64 confPA;
  369. };
  370. struct Vmxnet3_TxQueueDesc {
  371. struct Vmxnet3_TxQueueCtrl ctrl;
  372. struct Vmxnet3_TxQueueConf conf;
  373. /* Driver read after a GET command */
  374. struct Vmxnet3_QueueStatus status;
  375. struct UPT1_TxStats stats;
  376. u8 _pad[88]; /* 128 aligned */
  377. };
  378. struct Vmxnet3_RxQueueDesc {
  379. struct Vmxnet3_RxQueueCtrl ctrl;
  380. struct Vmxnet3_RxQueueConf conf;
  381. /* Driver read after a GET commad */
  382. struct Vmxnet3_QueueStatus status;
  383. struct UPT1_RxStats stats;
  384. u8 __pad[88]; /* 128 aligned */
  385. };
  386. struct Vmxnet3_DSDevRead {
  387. /* read-only region for device, read by dev in response to a SET cmd */
  388. struct Vmxnet3_MiscConf misc;
  389. struct Vmxnet3_IntrConf intrConf;
  390. struct Vmxnet3_RxFilterConf rxFilterConf;
  391. struct Vmxnet3_VariableLenConfDesc rssConfDesc;
  392. struct Vmxnet3_VariableLenConfDesc pmConfDesc;
  393. struct Vmxnet3_VariableLenConfDesc pluginConfDesc;
  394. };
  395. /* All structures in DriverShared are padded to multiples of 8 bytes */
  396. struct Vmxnet3_DriverShared {
  397. u32 magic;
  398. /* make devRead start at 64bit boundaries */
  399. u32 pad;
  400. struct Vmxnet3_DSDevRead devRead;
  401. u32 ecr;
  402. u32 reserved[5];
  403. };
  404. #define VMXNET3_ECR_RQERR (1 << 0)
  405. #define VMXNET3_ECR_TQERR (1 << 1)
  406. #define VMXNET3_ECR_LINK (1 << 2)
  407. #define VMXNET3_ECR_DIC (1 << 3)
  408. #define VMXNET3_ECR_DEBUG (1 << 4)
  409. /* flip the gen bit of a ring */
  410. #define VMXNET3_FLIP_RING_GEN(gen) ((gen) = (gen) ^ 0x1)
  411. /* only use this if moving the idx won't affect the gen bit */
  412. #define VMXNET3_INC_RING_IDX_ONLY(idx, ring_size) \
  413. do {\
  414. (idx)++;\
  415. if (unlikely((idx) == (ring_size))) {\
  416. (idx) = 0;\
  417. } \
  418. } while (0)
  419. #define VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid) \
  420. (vfTable[vid >> 5] |= (1 << (vid & 31)))
  421. #define VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid) \
  422. (vfTable[vid >> 5] &= ~(1 << (vid & 31)))
  423. #define VMXNET3_VFTABLE_ENTRY_IS_SET(vfTable, vid) \
  424. ((vfTable[vid >> 5] & (1 << (vid & 31))) != 0)
  425. #define VMXNET3_MAX_MTU 9000
  426. #define VMXNET3_MIN_MTU 60
  427. #define VMXNET3_LINK_UP (10000 << 16 | 1) /* 10 Gbps, up */
  428. #define VMXNET3_LINK_DOWN 0
  429. #endif /* _VMXNET3_DEFS_H_ */