7484b84e4e14fd3f493b9f5991549faf0dae8b14
[dpdk.git] / drivers / net / vmxnet3 / base / vmxnet3_defs.h
1 /*********************************************************
2  * Copyright (C) 2007 VMware, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *********************************************************/
27
28 /*
29  * vmxnet3_defs.h --
30  *
31  *      Definitions shared by device emulation and guest drivers for
32  *      VMXNET3 NIC
33  */
34
35 #ifndef _VMXNET3_DEFS_H_
36 #define _VMXNET3_DEFS_H_
37
38 #include "vmxnet3_osdep.h"
39 #include "upt1_defs.h"
40
41 /* all registers are 32 bit wide */
42 /* BAR 1 */
43 #define VMXNET3_REG_VRRS  0x0    /* Vmxnet3 Revision Report Selection */
44 #define VMXNET3_REG_UVRS  0x8    /* UPT Version Report Selection */
45 #define VMXNET3_REG_DSAL  0x10   /* Driver Shared Address Low */
46 #define VMXNET3_REG_DSAH  0x18   /* Driver Shared Address High */
47 #define VMXNET3_REG_CMD   0x20   /* Command */
48 #define VMXNET3_REG_MACL  0x28   /* MAC Address Low */
49 #define VMXNET3_REG_MACH  0x30   /* MAC Address High */
50 #define VMXNET3_REG_ICR   0x38   /* Interrupt Cause Register */
51 #define VMXNET3_REG_ECR   0x40   /* Event Cause Register */
52
53 #define VMXNET3_REG_WSAL  0xF00  /* Wireless Shared Address Lo  */
54 #define VMXNET3_REG_WSAH  0xF08  /* Wireless Shared Address Hi  */
55 #define VMXNET3_REG_WCMD  0xF18  /* Wireless Command */
56
57 /* BAR 0 */
58 #define VMXNET3_REG_IMR      0x0   /* Interrupt Mask Register */
59 #define VMXNET3_REG_TXPROD   0x600 /* Tx Producer Index */
60 #define VMXNET3_REG_RXPROD   0x800 /* Rx Producer Index for ring 1 */
61 #define VMXNET3_REG_RXPROD2  0xA00 /* Rx Producer Index for ring 2 */
62
63 #define VMXNET3_PT_REG_SIZE     4096    /* BAR 0 */
64 #define VMXNET3_VD_REG_SIZE     4096    /* BAR 1 */
65
66 /*
67  * The two Vmxnet3 MMIO Register PCI BARs (BAR 0 at offset 10h and BAR 1 at
68  * offset 14h)  as well as the MSI-X BAR are combined into one PhysMem region:
69  * <-VMXNET3_PT_REG_SIZE-><-VMXNET3_VD_REG_SIZE-><-VMXNET3_MSIX_BAR_SIZE-->
70  * -------------------------------------------------------------------------
71  * |Pass Thru Registers  | Virtual Dev Registers | MSI-X Vector/PBA Table  |
72  * -------------------------------------------------------------------------
73  * VMXNET3_MSIX_BAR_SIZE is defined in "vmxnet3Int.h"
74  */
75 #define VMXNET3_PHYSMEM_PAGES   4
76
77 #define VMXNET3_REG_ALIGN       8  /* All registers are 8-byte aligned. */
78 #define VMXNET3_REG_ALIGN_MASK  0x7
79
80 /* I/O Mapped access to registers */
81 #define VMXNET3_IO_TYPE_PT              0
82 #define VMXNET3_IO_TYPE_VD              1
83 #define VMXNET3_IO_ADDR(type, reg)      (((type) << 24) | ((reg) & 0xFFFFFF))
84 #define VMXNET3_IO_TYPE(addr)           ((addr) >> 24)
85 #define VMXNET3_IO_REG(addr)            ((addr) & 0xFFFFFF)
86
87 #ifndef __le16
88 #define __le16 uint16
89 #endif
90 #ifndef __le32
91 #define __le32 uint32
92 #endif
93 #ifndef __le64
94 #define __le64 uint64
95 #endif
96
97 typedef enum {
98    VMXNET3_CMD_FIRST_SET = 0xCAFE0000,
99    VMXNET3_CMD_ACTIVATE_DEV = VMXNET3_CMD_FIRST_SET,
100    VMXNET3_CMD_QUIESCE_DEV,
101    VMXNET3_CMD_RESET_DEV,
102    VMXNET3_CMD_UPDATE_RX_MODE,
103    VMXNET3_CMD_UPDATE_MAC_FILTERS,
104    VMXNET3_CMD_UPDATE_VLAN_FILTERS,
105    VMXNET3_CMD_UPDATE_RSSIDT,
106    VMXNET3_CMD_UPDATE_IML,
107    VMXNET3_CMD_UPDATE_PMCFG,
108    VMXNET3_CMD_UPDATE_FEATURE,
109    VMXNET3_CMD_STOP_EMULATION,
110    VMXNET3_CMD_LOAD_PLUGIN,
111    VMXNET3_CMD_ACTIVATE_VF,
112    VMXNET3_CMD_RESERVED3,
113
114    VMXNET3_CMD_FIRST_GET = 0xF00D0000,
115    VMXNET3_CMD_GET_QUEUE_STATUS = VMXNET3_CMD_FIRST_GET,
116    VMXNET3_CMD_GET_STATS,
117    VMXNET3_CMD_GET_LINK,
118    VMXNET3_CMD_GET_PERM_MAC_LO,
119    VMXNET3_CMD_GET_PERM_MAC_HI,
120    VMXNET3_CMD_GET_DID_LO,
121    VMXNET3_CMD_GET_DID_HI,
122    VMXNET3_CMD_GET_DEV_EXTRA_INFO,
123    VMXNET3_CMD_GET_CONF_INTR,
124    VMXNET3_CMD_GET_ADAPTIVE_RING_INFO
125 } Vmxnet3_Cmd;
126
127 /* Adaptive Ring Info Flags */
128 #define VMXNET3_DISABLE_ADAPTIVE_RING 1
129
130 /*
131  *      Little Endian layout of bitfields -
132  *      Byte 0 :        7.....len.....0
133  *      Byte 1 :        rsvd gen 13.len.8
134  *      Byte 2 :        5.msscof.0 ext1  dtype
135  *      Byte 3 :        13...msscof...6
136  *
137  *      Big Endian layout of bitfields -
138  *      Byte 0:         13...msscof...6
139  *      Byte 1 :        5.msscof.0 ext1  dtype
140  *      Byte 2 :        rsvd gen 13.len.8
141  *      Byte 3 :        7.....len.....0
142  *
143  *      Thus, le32_to_cpu on the dword will allow the big endian driver to read
144  *      the bit fields correctly. And cpu_to_le32 will convert bitfields
145  *      bit fields written by big endian driver to format required by device.
146  */
147
148 typedef
149 #include "vmware_pack_begin.h"
150 struct Vmxnet3_TxDesc {
151    __le64 addr;
152
153 #ifdef __BIG_ENDIAN_BITFIELD
154    uint32 msscof:14;  /* MSS, checksum offset, flags */
155    uint32 ext1:1;
156    uint32 dtype:1;    /* descriptor type */
157    uint32 rsvd:1;
158    uint32 gen:1;      /* generation bit */
159    uint32 len:14;
160 #else
161    uint32 len:14;
162    uint32 gen:1;      /* generation bit */
163    uint32 rsvd:1;
164    uint32 dtype:1;    /* descriptor type */
165    uint32 ext1:1;
166    uint32 msscof:14;  /* MSS, checksum offset, flags */
167 #endif  /* __BIG_ENDIAN_BITFIELD */
168
169 #ifdef __BIG_ENDIAN_BITFIELD
170    uint32 tci:16;     /* Tag to Insert */
171    uint32 ti:1;       /* VLAN Tag Insertion */
172    uint32 ext2:1;
173    uint32 cq:1;       /* completion request */
174    uint32 eop:1;      /* End Of Packet */
175    uint32 om:2;       /* offload mode */
176    uint32 hlen:10;    /* header len */
177 #else
178    uint32 hlen:10;    /* header len */
179    uint32 om:2;       /* offload mode */
180    uint32 eop:1;      /* End Of Packet */
181    uint32 cq:1;       /* completion request */
182    uint32 ext2:1;
183    uint32 ti:1;       /* VLAN Tag Insertion */
184    uint32 tci:16;     /* Tag to Insert */
185 #endif  /* __BIG_ENDIAN_BITFIELD */
186 }
187 #include "vmware_pack_end.h"
188 Vmxnet3_TxDesc;
189
190 /* TxDesc.OM values */
191 #define VMXNET3_OM_NONE  0
192 #define VMXNET3_OM_CSUM  2
193 #define VMXNET3_OM_TSO   3
194
195 /* fields in TxDesc we access w/o using bit fields */
196 #define VMXNET3_TXD_EOP_SHIFT 12
197 #define VMXNET3_TXD_CQ_SHIFT  13
198 #define VMXNET3_TXD_GEN_SHIFT 14
199 #define VMXNET3_TXD_EOP_DWORD_SHIFT 3
200 #define VMXNET3_TXD_GEN_DWORD_SHIFT 2
201
202 #define VMXNET3_TXD_CQ  (1 << VMXNET3_TXD_CQ_SHIFT)
203 #define VMXNET3_TXD_EOP (1 << VMXNET3_TXD_EOP_SHIFT)
204 #define VMXNET3_TXD_GEN (1 << VMXNET3_TXD_GEN_SHIFT)
205
206 #define VMXNET3_TXD_GEN_SIZE 1
207 #define VMXNET3_TXD_EOP_SIZE 1
208
209 #define VMXNET3_HDR_COPY_SIZE   128
210
211 typedef
212 #include "vmware_pack_begin.h"
213 struct Vmxnet3_TxDataDesc {
214    uint8 data[VMXNET3_HDR_COPY_SIZE];
215 }
216 #include "vmware_pack_end.h"
217 Vmxnet3_TxDataDesc;
218
219 #define VMXNET3_TCD_GEN_SHIFT   31
220 #define VMXNET3_TCD_GEN_SIZE    1
221 #define VMXNET3_TCD_TXIDX_SHIFT 0
222 #define VMXNET3_TCD_TXIDX_SIZE  12
223 #define VMXNET3_TCD_GEN_DWORD_SHIFT     3
224
225 typedef
226 #include "vmware_pack_begin.h"
227 struct Vmxnet3_TxCompDesc {
228    uint32 txdIdx:12;    /* Index of the EOP TxDesc */
229    uint32 ext1:20;
230
231    __le32 ext2;
232    __le32 ext3;
233
234    uint32 rsvd:24;
235    uint32 type:7;       /* completion type */
236    uint32 gen:1;        /* generation bit */
237 }
238 #include "vmware_pack_end.h"
239 Vmxnet3_TxCompDesc;
240
241 typedef
242 #include "vmware_pack_begin.h"
243 struct Vmxnet3_RxDesc {
244    __le64 addr;
245
246 #ifdef __BIG_ENDIAN_BITFIELD
247    uint32 gen:1;        /* Generation bit */
248    uint32 rsvd:15;
249    uint32 dtype:1;      /* Descriptor type */
250    uint32 btype:1;      /* Buffer Type */
251    uint32 len:14;
252 #else
253    uint32 len:14;
254    uint32 btype:1;      /* Buffer Type */
255    uint32 dtype:1;      /* Descriptor type */
256    uint32 rsvd:15;
257    uint32 gen:1;        /* Generation bit */
258 #endif
259    __le32 ext1;
260 }
261 #include "vmware_pack_end.h"
262 Vmxnet3_RxDesc;
263
264 /* values of RXD.BTYPE */
265 #define VMXNET3_RXD_BTYPE_HEAD   0    /* head only */
266 #define VMXNET3_RXD_BTYPE_BODY   1    /* body only */
267
268 /* fields in RxDesc we access w/o using bit fields */
269 #define VMXNET3_RXD_BTYPE_SHIFT  14
270 #define VMXNET3_RXD_GEN_SHIFT    31
271
272 typedef
273 #include "vmware_pack_begin.h"
274 struct Vmxnet3_RxCompDesc {
275 #ifdef __BIG_ENDIAN_BITFIELD
276    uint32 ext2:1;
277    uint32 cnc:1;        /* Checksum Not Calculated */
278    uint32 rssType:4;    /* RSS hash type used */
279    uint32 rqID:10;      /* rx queue/ring ID */
280    uint32 sop:1;        /* Start of Packet */
281    uint32 eop:1;        /* End of Packet */
282    uint32 ext1:2;
283    uint32 rxdIdx:12;    /* Index of the RxDesc */
284 #else
285    uint32 rxdIdx:12;    /* Index of the RxDesc */
286    uint32 ext1:2;
287    uint32 eop:1;        /* End of Packet */
288    uint32 sop:1;        /* Start of Packet */
289    uint32 rqID:10;      /* rx queue/ring ID */
290    uint32 rssType:4;    /* RSS hash type used */
291    uint32 cnc:1;        /* Checksum Not Calculated */
292    uint32 ext2:1;
293 #endif  /* __BIG_ENDIAN_BITFIELD */
294
295    __le32 rssHash;      /* RSS hash value */
296
297 #ifdef __BIG_ENDIAN_BITFIELD
298    uint32 tci:16;       /* Tag stripped */
299    uint32 ts:1;         /* Tag is stripped */
300    uint32 err:1;        /* Error */
301    uint32 len:14;       /* data length */
302 #else
303    uint32 len:14;       /* data length */
304    uint32 err:1;        /* Error */
305    uint32 ts:1;         /* Tag is stripped */
306    uint32 tci:16;       /* Tag stripped */
307 #endif  /* __BIG_ENDIAN_BITFIELD */
308
309
310 #ifdef __BIG_ENDIAN_BITFIELD
311    uint32 gen:1;        /* generation bit */
312    uint32 type:7;       /* completion type */
313    uint32 fcs:1;        /* Frame CRC correct */
314    uint32 frg:1;        /* IP Fragment */
315    uint32 v4:1;         /* IPv4 */
316    uint32 v6:1;         /* IPv6 */
317    uint32 ipc:1;        /* IP Checksum Correct */
318    uint32 tcp:1;        /* TCP packet */
319    uint32 udp:1;        /* UDP packet */
320    uint32 tuc:1;        /* TCP/UDP Checksum Correct */
321    uint32 csum:16;
322 #else
323    uint32 csum:16;
324    uint32 tuc:1;        /* TCP/UDP Checksum Correct */
325    uint32 udp:1;        /* UDP packet */
326    uint32 tcp:1;        /* TCP packet */
327    uint32 ipc:1;        /* IP Checksum Correct */
328    uint32 v6:1;         /* IPv6 */
329    uint32 v4:1;         /* IPv4 */
330    uint32 frg:1;        /* IP Fragment */
331    uint32 fcs:1;        /* Frame CRC correct */
332    uint32 type:7;       /* completion type */
333    uint32 gen:1;        /* generation bit */
334 #endif  /* __BIG_ENDIAN_BITFIELD */
335 }
336 #include "vmware_pack_end.h"
337 Vmxnet3_RxCompDesc;
338
339 typedef
340 #include "vmware_pack_begin.h"
341 struct Vmxnet3_RxCompDescExt {
342    __le32 dword1;
343    uint8  segCnt;       /* Number of aggregated packets */
344    uint8  dupAckCnt;    /* Number of duplicate Acks */
345    __le16 tsDelta;      /* TCP timestamp difference */
346    __le32 dword2[2];
347 }
348 #include "vmware_pack_end.h"
349 Vmxnet3_RxCompDescExt;
350
351 /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.dword[3] */
352 #define VMXNET3_RCD_TUC_SHIFT  16
353 #define VMXNET3_RCD_IPC_SHIFT  19
354
355 /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.qword[1] */
356 #define VMXNET3_RCD_TYPE_SHIFT 56
357 #define VMXNET3_RCD_GEN_SHIFT  63
358
359 /* csum OK for TCP/UDP pkts over IP */
360 #define VMXNET3_RCD_CSUM_OK (1 << VMXNET3_RCD_TUC_SHIFT | 1 << VMXNET3_RCD_IPC_SHIFT)
361
362 /* value of RxCompDesc.rssType */
363 #define VMXNET3_RCD_RSS_TYPE_NONE     0
364 #define VMXNET3_RCD_RSS_TYPE_IPV4     1
365 #define VMXNET3_RCD_RSS_TYPE_TCPIPV4  2
366 #define VMXNET3_RCD_RSS_TYPE_IPV6     3
367 #define VMXNET3_RCD_RSS_TYPE_TCPIPV6  4
368
369 /* a union for accessing all cmd/completion descriptors */
370 typedef union Vmxnet3_GenericDesc {
371    __le64                qword[2];
372    __le32                dword[4];
373    __le16                word[8];
374    Vmxnet3_TxDesc        txd;
375    Vmxnet3_RxDesc        rxd;
376    Vmxnet3_TxCompDesc    tcd;
377    Vmxnet3_RxCompDesc    rcd;
378    Vmxnet3_RxCompDescExt rcdExt;
379 } Vmxnet3_GenericDesc;
380
381 #define VMXNET3_INIT_GEN       1
382
383 /* Max size of a single tx buffer */
384 #define VMXNET3_MAX_TX_BUF_SIZE  (1 << 14)
385
386 /* # of tx desc needed for a tx buffer size */
387 #define VMXNET3_TXD_NEEDED(size) (((size) + VMXNET3_MAX_TX_BUF_SIZE - 1) / VMXNET3_MAX_TX_BUF_SIZE)
388
389 /* max # of tx descs for a non-tso pkt */
390 #define VMXNET3_MAX_TXD_PER_PKT 16
391
392 /* Max size of a single rx buffer */
393 #define VMXNET3_MAX_RX_BUF_SIZE  ((1 << 14) - 1)
394 /* Minimum size of a type 0 buffer */
395 #define VMXNET3_MIN_T0_BUF_SIZE  128
396 #define VMXNET3_MAX_CSUM_OFFSET  1024
397
398 /* Ring base address alignment */
399 #define VMXNET3_RING_BA_ALIGN   512
400 #define VMXNET3_RING_BA_MASK    (VMXNET3_RING_BA_ALIGN - 1)
401
402 /* Ring size must be a multiple of 32 */
403 #define VMXNET3_RING_SIZE_ALIGN 32
404 #define VMXNET3_RING_SIZE_MASK  (VMXNET3_RING_SIZE_ALIGN - 1)
405
406 /* Max ring size */
407 #define VMXNET3_TX_RING_MAX_SIZE   4096
408 #define VMXNET3_TC_RING_MAX_SIZE   4096
409 #define VMXNET3_RX_RING_MAX_SIZE   4096
410 #define VMXNET3_RC_RING_MAX_SIZE   8192
411
412 /* a list of reasons for queue stop */
413
414 #define VMXNET3_ERR_NOEOP        0x80000000  /* cannot find the EOP desc of a pkt */
415 #define VMXNET3_ERR_TXD_REUSE    0x80000001  /* reuse a TxDesc before tx completion */
416 #define VMXNET3_ERR_BIG_PKT      0x80000002  /* too many TxDesc for a pkt */
417 #define VMXNET3_ERR_DESC_NOT_SPT 0x80000003  /* descriptor type not supported */
418 #define VMXNET3_ERR_SMALL_BUF    0x80000004  /* type 0 buffer too small */
419 #define VMXNET3_ERR_STRESS       0x80000005  /* stress option firing in vmkernel */
420 #define VMXNET3_ERR_SWITCH       0x80000006  /* mode switch failure */
421 #define VMXNET3_ERR_TXD_INVALID  0x80000007  /* invalid TxDesc */
422
423 /* completion descriptor types */
424 #define VMXNET3_CDTYPE_TXCOMP      0    /* Tx Completion Descriptor */
425 #define VMXNET3_CDTYPE_RXCOMP      3    /* Rx Completion Descriptor */
426 #define VMXNET3_CDTYPE_RXCOMP_LRO  4    /* Rx Completion Descriptor for LRO */
427
428 #define VMXNET3_GOS_BITS_UNK    0   /* unknown */
429 #define VMXNET3_GOS_BITS_32     1
430 #define VMXNET3_GOS_BITS_64     2
431
432 #define VMXNET3_GOS_TYPE_UNK        0 /* unknown */
433 #define VMXNET3_GOS_TYPE_LINUX      1
434 #define VMXNET3_GOS_TYPE_WIN        2
435 #define VMXNET3_GOS_TYPE_SOLARIS    3
436 #define VMXNET3_GOS_TYPE_FREEBSD    4
437 #define VMXNET3_GOS_TYPE_PXE        5
438
439 /* All structures in DriverShared are padded to multiples of 8 bytes */
440
441 typedef
442 #include "vmware_pack_begin.h"
443 struct Vmxnet3_GOSInfo {
444 #ifdef __BIG_ENDIAN_BITFIELD
445    uint32   gosMisc: 10;    /* other info about gos */
446    uint32   gosVer:  16;    /* gos version */
447    uint32   gosType: 4;     /* which guest */
448    uint32   gosBits: 2;     /* 32-bit or 64-bit? */
449 #else
450    uint32   gosBits: 2;     /* 32-bit or 64-bit? */
451    uint32   gosType: 4;     /* which guest */
452    uint32   gosVer:  16;    /* gos version */
453    uint32   gosMisc: 10;    /* other info about gos */
454 #endif  /* __BIG_ENDIAN_BITFIELD */
455 }
456 #include "vmware_pack_end.h"
457 Vmxnet3_GOSInfo;
458
459 typedef
460 #include "vmware_pack_begin.h"
461 struct Vmxnet3_DriverInfo {
462    __le32          version;        /* driver version */
463    Vmxnet3_GOSInfo gos;
464    __le32          vmxnet3RevSpt;  /* vmxnet3 revision supported */
465    __le32          uptVerSpt;      /* upt version supported */
466 }
467 #include "vmware_pack_end.h"
468 Vmxnet3_DriverInfo;
469
470 #define VMXNET3_REV1_MAGIC  0xbabefee1
471
472 /*
473  * QueueDescPA must be 128 bytes aligned. It points to an array of
474  * Vmxnet3_TxQueueDesc followed by an array of Vmxnet3_RxQueueDesc.
475  * The number of Vmxnet3_TxQueueDesc/Vmxnet3_RxQueueDesc are specified by
476  * Vmxnet3_MiscConf.numTxQueues/numRxQueues, respectively.
477  */
478 #define VMXNET3_QUEUE_DESC_ALIGN  128
479
480 typedef
481 #include "vmware_pack_begin.h"
482 struct Vmxnet3_MiscConf {
483    Vmxnet3_DriverInfo driverInfo;
484    __le64             uptFeatures;
485    __le64             ddPA;         /* driver data PA */
486    __le64             queueDescPA;  /* queue descriptor table PA */
487    __le32             ddLen;        /* driver data len */
488    __le32             queueDescLen; /* queue descriptor table len, in bytes */
489    __le32             mtu;
490    __le16             maxNumRxSG;
491    uint8              numTxQueues;
492    uint8              numRxQueues;
493    __le32             reserved[4];
494 }
495 #include "vmware_pack_end.h"
496 Vmxnet3_MiscConf;
497
498 typedef
499 #include "vmware_pack_begin.h"
500 struct Vmxnet3_TxQueueConf {
501    __le64    txRingBasePA;
502    __le64    dataRingBasePA;
503    __le64    compRingBasePA;
504    __le64    ddPA;         /* driver data */
505    __le64    reserved;
506    __le32    txRingSize;   /* # of tx desc */
507    __le32    dataRingSize; /* # of data desc */
508    __le32    compRingSize; /* # of comp desc */
509    __le32    ddLen;        /* size of driver data */
510    uint8     intrIdx;
511    uint8     _pad[7];
512 }
513 #include "vmware_pack_end.h"
514 Vmxnet3_TxQueueConf;
515
516 typedef
517 #include "vmware_pack_begin.h"
518 struct Vmxnet3_RxQueueConf {
519    __le64    rxRingBasePA[2];
520    __le64    compRingBasePA;
521    __le64    ddPA;            /* driver data */
522    __le64    reserved;
523    __le32    rxRingSize[2];   /* # of rx desc */
524    __le32    compRingSize;    /* # of rx comp desc */
525    __le32    ddLen;           /* size of driver data */
526    uint8     intrIdx;
527    uint8     _pad[7];
528 }
529 #include "vmware_pack_end.h"
530 Vmxnet3_RxQueueConf;
531
532 enum vmxnet3_intr_mask_mode {
533    VMXNET3_IMM_AUTO   = 0,
534    VMXNET3_IMM_ACTIVE = 1,
535    VMXNET3_IMM_LAZY   = 2
536 };
537
538 enum vmxnet3_intr_type {
539    VMXNET3_IT_AUTO = 0,
540    VMXNET3_IT_INTX = 1,
541    VMXNET3_IT_MSI  = 2,
542    VMXNET3_IT_MSIX = 3
543 };
544
545 #define VMXNET3_MAX_TX_QUEUES  8
546 #define VMXNET3_MAX_RX_QUEUES  16
547 /* addition 1 for events */
548 #define VMXNET3_MAX_INTRS      25
549
550 /* value of intrCtrl */
551 #define VMXNET3_IC_DISABLE_ALL  0x1   /* bit 0 */
552
553 typedef
554 #include "vmware_pack_begin.h"
555 struct Vmxnet3_IntrConf {
556    Bool   autoMask;
557    uint8  numIntrs;      /* # of interrupts */
558    uint8  eventIntrIdx;
559    uint8  modLevels[VMXNET3_MAX_INTRS]; /* moderation level for each intr */
560    __le32 intrCtrl;
561    __le32 reserved[2];
562 }
563 #include "vmware_pack_end.h"
564 Vmxnet3_IntrConf;
565
566 /* one bit per VLAN ID, the size is in the units of uint32 */
567 #define VMXNET3_VFT_SIZE  (4096 / (sizeof(uint32) * 8))
568
569 typedef
570 #include "vmware_pack_begin.h"
571 struct Vmxnet3_QueueStatus {
572    Bool    stopped;
573    uint8   _pad[3];
574    __le32  error;
575 }
576 #include "vmware_pack_end.h"
577 Vmxnet3_QueueStatus;
578
579 typedef
580 #include "vmware_pack_begin.h"
581 struct Vmxnet3_TxQueueCtrl {
582    __le32  txNumDeferred;
583    __le32  txThreshold;
584    __le64  reserved;
585 }
586 #include "vmware_pack_end.h"
587 Vmxnet3_TxQueueCtrl;
588
589 typedef
590 #include "vmware_pack_begin.h"
591 struct Vmxnet3_RxQueueCtrl {
592    Bool    updateRxProd;
593    uint8   _pad[7];
594    __le64  reserved;
595 }
596 #include "vmware_pack_end.h"
597 Vmxnet3_RxQueueCtrl;
598
599 #define VMXNET3_RXM_UCAST     0x01  /* unicast only */
600 #define VMXNET3_RXM_MCAST     0x02  /* multicast passing the filters */
601 #define VMXNET3_RXM_BCAST     0x04  /* broadcast only */
602 #define VMXNET3_RXM_ALL_MULTI 0x08  /* all multicast */
603 #define VMXNET3_RXM_PROMISC   0x10  /* promiscuous */
604
605 typedef
606 #include "vmware_pack_begin.h"
607 struct Vmxnet3_RxFilterConf {
608    __le32   rxMode;       /* VMXNET3_RXM_xxx */
609    __le16   mfTableLen;   /* size of the multicast filter table */
610    __le16   _pad1;
611    __le64   mfTablePA;    /* PA of the multicast filters table */
612    __le32   vfTable[VMXNET3_VFT_SIZE]; /* vlan filter */
613 }
614 #include "vmware_pack_end.h"
615 Vmxnet3_RxFilterConf;
616
617 #define VMXNET3_PM_MAX_FILTERS        6
618 #define VMXNET3_PM_MAX_PATTERN_SIZE   128
619 #define VMXNET3_PM_MAX_MASK_SIZE      (VMXNET3_PM_MAX_PATTERN_SIZE / 8)
620
621 #define VMXNET3_PM_WAKEUP_MAGIC       0x01  /* wake up on magic pkts */
622 #define VMXNET3_PM_WAKEUP_FILTER      0x02  /* wake up on pkts matching filters */
623
624 typedef
625 #include "vmware_pack_begin.h"
626 struct Vmxnet3_PM_PktFilter {
627    uint8 maskSize;
628    uint8 patternSize;
629    uint8 mask[VMXNET3_PM_MAX_MASK_SIZE];
630    uint8 pattern[VMXNET3_PM_MAX_PATTERN_SIZE];
631    uint8 pad[6];
632 }
633 #include "vmware_pack_end.h"
634 Vmxnet3_PM_PktFilter;
635
636 typedef
637 #include "vmware_pack_begin.h"
638 struct Vmxnet3_PMConf {
639    __le16               wakeUpEvents;  /* VMXNET3_PM_WAKEUP_xxx */
640    uint8                numFilters;
641    uint8                pad[5];
642    Vmxnet3_PM_PktFilter filters[VMXNET3_PM_MAX_FILTERS];
643 }
644 #include "vmware_pack_end.h"
645 Vmxnet3_PMConf;
646
647 typedef
648 #include "vmware_pack_begin.h"
649 struct Vmxnet3_VariableLenConfDesc {
650    __le32              confVer;
651    __le32              confLen;
652    __le64              confPA;
653 }
654 #include "vmware_pack_end.h"
655 Vmxnet3_VariableLenConfDesc;
656
657 typedef
658 #include "vmware_pack_begin.h"
659 struct Vmxnet3_DSDevRead {
660    /* read-only region for device, read by dev in response to a SET cmd */
661    Vmxnet3_MiscConf     misc;
662    Vmxnet3_IntrConf     intrConf;
663    Vmxnet3_RxFilterConf rxFilterConf;
664    Vmxnet3_VariableLenConfDesc  rssConfDesc;
665    Vmxnet3_VariableLenConfDesc  pmConfDesc;
666    Vmxnet3_VariableLenConfDesc  pluginConfDesc;
667 }
668 #include "vmware_pack_end.h"
669 Vmxnet3_DSDevRead;
670
671 typedef
672 #include "vmware_pack_begin.h"
673 struct Vmxnet3_TxQueueDesc {
674    Vmxnet3_TxQueueCtrl ctrl;
675    Vmxnet3_TxQueueConf conf;
676    /* Driver read after a GET command */
677    Vmxnet3_QueueStatus status;
678    UPT1_TxStats        stats;
679    uint8               _pad[88]; /* 128 aligned */
680 }
681 #include "vmware_pack_end.h"
682 Vmxnet3_TxQueueDesc;
683
684 typedef
685 #include "vmware_pack_begin.h"
686 struct Vmxnet3_RxQueueDesc {
687    Vmxnet3_RxQueueCtrl ctrl;
688    Vmxnet3_RxQueueConf conf;
689    /* Driver read after a GET command */
690    Vmxnet3_QueueStatus status;
691    UPT1_RxStats        stats;
692    uint8               _pad[88]; /* 128 aligned */
693 }
694 #include "vmware_pack_end.h"
695 Vmxnet3_RxQueueDesc;
696
697 typedef
698 #include "vmware_pack_begin.h"
699 struct Vmxnet3_SetPolling {
700    uint8 enablePolling;
701 }
702 #include "vmware_pack_end.h"
703 Vmxnet3_SetPolling;
704
705 /*
706  * If the command data <= 16 bytes, use the shared memory direcly.
707  * Otherwise, use the variable length configuration descriptor.
708  */
709 typedef
710 #include "vmware_pack_begin.h"
711 union Vmxnet3_CmdInfo {
712    Vmxnet3_VariableLenConfDesc varConf;
713    Vmxnet3_SetPolling          setPolling;
714    __le64                      data[2];
715 }
716 #include "vmware_pack_end.h"
717 Vmxnet3_CmdInfo;
718
719 typedef
720 #include "vmware_pack_begin.h"
721 struct Vmxnet3_DriverShared {
722    __le32               magic;
723    __le32               pad; /* make devRead start at 64-bit boundaries */
724    Vmxnet3_DSDevRead    devRead;
725    __le32               ecr;
726    __le32               reserved;
727
728    union {
729       __le32            reserved1[4];
730       Vmxnet3_CmdInfo   cmdInfo; /* only valid in the context of executing the
731                                   * relevant command
732                                   */
733    } cu;
734 }
735 #include "vmware_pack_end.h"
736 Vmxnet3_DriverShared;
737
738 #define VMXNET3_ECR_RQERR       (1 << 0)
739 #define VMXNET3_ECR_TQERR       (1 << 1)
740 #define VMXNET3_ECR_LINK        (1 << 2)
741 #define VMXNET3_ECR_DIC         (1 << 3)
742 #define VMXNET3_ECR_DEBUG       (1 << 4)
743
744 /* flip the gen bit of a ring */
745 #define VMXNET3_FLIP_RING_GEN(gen) ((gen) = (gen) ^ 0x1)
746
747 /* only use this if moving the idx won't affect the gen bit */
748 #define VMXNET3_INC_RING_IDX_ONLY(idx, ring_size) \
749 do {\
750    (idx)++;\
751    if (UNLIKELY((idx) == (ring_size))) {\
752       (idx) = 0;\
753    }\
754 } while (0)
755
756 #define VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid) \
757    vfTable[vid >> 5] |= (1 << (vid & 31))
758 #define VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid) \
759    vfTable[vid >> 5] &= ~(1 << (vid & 31))
760
761 #define VMXNET3_VFTABLE_ENTRY_IS_SET(vfTable, vid) \
762    ((vfTable[vid >> 5] & (1 << (vid & 31))) != 0)
763
764 #define VMXNET3_MAX_MTU     9000
765 #define VMXNET3_MIN_MTU     60
766
767 #define VMXNET3_LINK_UP         (10000 << 16 | 1)    // 10 Gbps, up
768 #define VMXNET3_LINK_DOWN       0
769
770 #define VMXWIFI_DRIVER_SHARED_LEN 8192
771
772 #define VMXNET3_DID_PASSTHRU    0xFFFF
773
774 #endif /* _VMXNET3_DEFS_H_ */