e2018089974330dc661a55c797c4b881a1d8c87c
[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_GET_TXDATA_DESC_SIZE
126 } Vmxnet3_Cmd;
127
128 /* Adaptive Ring Info Flags */
129 #define VMXNET3_DISABLE_ADAPTIVE_RING 1
130
131 /*
132  *      Little Endian layout of bitfields -
133  *      Byte 0 :        7.....len.....0
134  *      Byte 1 :        rsvd gen 13.len.8
135  *      Byte 2 :        5.msscof.0 ext1  dtype
136  *      Byte 3 :        13...msscof...6
137  *
138  *      Big Endian layout of bitfields -
139  *      Byte 0:         13...msscof...6
140  *      Byte 1 :        5.msscof.0 ext1  dtype
141  *      Byte 2 :        rsvd gen 13.len.8
142  *      Byte 3 :        7.....len.....0
143  *
144  *      Thus, le32_to_cpu on the dword will allow the big endian driver to read
145  *      the bit fields correctly. And cpu_to_le32 will convert bitfields
146  *      bit fields written by big endian driver to format required by device.
147  */
148
149 typedef
150 #include "vmware_pack_begin.h"
151 struct Vmxnet3_TxDesc {
152    __le64 addr;
153
154 #ifdef __BIG_ENDIAN_BITFIELD
155    uint32 msscof:14;  /* MSS, checksum offset, flags */
156    uint32 ext1:1;
157    uint32 dtype:1;    /* descriptor type */
158    uint32 rsvd:1;
159    uint32 gen:1;      /* generation bit */
160    uint32 len:14;
161 #else
162    uint32 len:14;
163    uint32 gen:1;      /* generation bit */
164    uint32 rsvd:1;
165    uint32 dtype:1;    /* descriptor type */
166    uint32 ext1:1;
167    uint32 msscof:14;  /* MSS, checksum offset, flags */
168 #endif  /* __BIG_ENDIAN_BITFIELD */
169
170 #ifdef __BIG_ENDIAN_BITFIELD
171    uint32 tci:16;     /* Tag to Insert */
172    uint32 ti:1;       /* VLAN Tag Insertion */
173    uint32 ext2:1;
174    uint32 cq:1;       /* completion request */
175    uint32 eop:1;      /* End Of Packet */
176    uint32 om:2;       /* offload mode */
177    uint32 hlen:10;    /* header len */
178 #else
179    uint32 hlen:10;    /* header len */
180    uint32 om:2;       /* offload mode */
181    uint32 eop:1;      /* End Of Packet */
182    uint32 cq:1;       /* completion request */
183    uint32 ext2:1;
184    uint32 ti:1;       /* VLAN Tag Insertion */
185    uint32 tci:16;     /* Tag to Insert */
186 #endif  /* __BIG_ENDIAN_BITFIELD */
187 }
188 #include "vmware_pack_end.h"
189 Vmxnet3_TxDesc;
190
191 /* TxDesc.OM values */
192 #define VMXNET3_OM_NONE  0
193 #define VMXNET3_OM_CSUM  2
194 #define VMXNET3_OM_TSO   3
195
196 /* fields in TxDesc we access w/o using bit fields */
197 #define VMXNET3_TXD_EOP_SHIFT 12
198 #define VMXNET3_TXD_CQ_SHIFT  13
199 #define VMXNET3_TXD_GEN_SHIFT 14
200 #define VMXNET3_TXD_EOP_DWORD_SHIFT 3
201 #define VMXNET3_TXD_GEN_DWORD_SHIFT 2
202
203 #define VMXNET3_TXD_CQ  (1 << VMXNET3_TXD_CQ_SHIFT)
204 #define VMXNET3_TXD_EOP (1 << VMXNET3_TXD_EOP_SHIFT)
205 #define VMXNET3_TXD_GEN (1 << VMXNET3_TXD_GEN_SHIFT)
206
207 #define VMXNET3_TXD_GEN_SIZE 1
208 #define VMXNET3_TXD_EOP_SIZE 1
209
210 #define VMXNET3_HDR_COPY_SIZE   128
211
212 typedef
213 #include "vmware_pack_begin.h"
214 struct Vmxnet3_TxDataDesc {
215    uint8 data[VMXNET3_HDR_COPY_SIZE];
216 }
217 #include "vmware_pack_end.h"
218 Vmxnet3_TxDataDesc;
219
220 #define VMXNET3_TCD_GEN_SHIFT   31
221 #define VMXNET3_TCD_GEN_SIZE    1
222 #define VMXNET3_TCD_TXIDX_SHIFT 0
223 #define VMXNET3_TCD_TXIDX_SIZE  12
224 #define VMXNET3_TCD_GEN_DWORD_SHIFT     3
225
226 typedef
227 #include "vmware_pack_begin.h"
228 struct Vmxnet3_TxCompDesc {
229    uint32 txdIdx:12;    /* Index of the EOP TxDesc */
230    uint32 ext1:20;
231
232    __le32 ext2;
233    __le32 ext3;
234
235    uint32 rsvd:24;
236    uint32 type:7;       /* completion type */
237    uint32 gen:1;        /* generation bit */
238 }
239 #include "vmware_pack_end.h"
240 Vmxnet3_TxCompDesc;
241
242 typedef
243 #include "vmware_pack_begin.h"
244 struct Vmxnet3_RxDesc {
245    __le64 addr;
246
247 #ifdef __BIG_ENDIAN_BITFIELD
248    uint32 gen:1;        /* Generation bit */
249    uint32 rsvd:15;
250    uint32 dtype:1;      /* Descriptor type */
251    uint32 btype:1;      /* Buffer Type */
252    uint32 len:14;
253 #else
254    uint32 len:14;
255    uint32 btype:1;      /* Buffer Type */
256    uint32 dtype:1;      /* Descriptor type */
257    uint32 rsvd:15;
258    uint32 gen:1;        /* Generation bit */
259 #endif
260    __le32 ext1;
261 }
262 #include "vmware_pack_end.h"
263 Vmxnet3_RxDesc;
264
265 /* values of RXD.BTYPE */
266 #define VMXNET3_RXD_BTYPE_HEAD   0    /* head only */
267 #define VMXNET3_RXD_BTYPE_BODY   1    /* body only */
268
269 /* fields in RxDesc we access w/o using bit fields */
270 #define VMXNET3_RXD_BTYPE_SHIFT  14
271 #define VMXNET3_RXD_GEN_SHIFT    31
272
273 typedef
274 #include "vmware_pack_begin.h"
275 struct Vmxnet3_RxCompDesc {
276 #ifdef __BIG_ENDIAN_BITFIELD
277    uint32 ext2:1;
278    uint32 cnc:1;        /* Checksum Not Calculated */
279    uint32 rssType:4;    /* RSS hash type used */
280    uint32 rqID:10;      /* rx queue/ring ID */
281    uint32 sop:1;        /* Start of Packet */
282    uint32 eop:1;        /* End of Packet */
283    uint32 ext1:2;
284    uint32 rxdIdx:12;    /* Index of the RxDesc */
285 #else
286    uint32 rxdIdx:12;    /* Index of the RxDesc */
287    uint32 ext1:2;
288    uint32 eop:1;        /* End of Packet */
289    uint32 sop:1;        /* Start of Packet */
290    uint32 rqID:10;      /* rx queue/ring ID */
291    uint32 rssType:4;    /* RSS hash type used */
292    uint32 cnc:1;        /* Checksum Not Calculated */
293    uint32 ext2:1;
294 #endif  /* __BIG_ENDIAN_BITFIELD */
295
296    __le32 rssHash;      /* RSS hash value */
297
298 #ifdef __BIG_ENDIAN_BITFIELD
299    uint32 tci:16;       /* Tag stripped */
300    uint32 ts:1;         /* Tag is stripped */
301    uint32 err:1;        /* Error */
302    uint32 len:14;       /* data length */
303 #else
304    uint32 len:14;       /* data length */
305    uint32 err:1;        /* Error */
306    uint32 ts:1;         /* Tag is stripped */
307    uint32 tci:16;       /* Tag stripped */
308 #endif  /* __BIG_ENDIAN_BITFIELD */
309
310
311 #ifdef __BIG_ENDIAN_BITFIELD
312    uint32 gen:1;        /* generation bit */
313    uint32 type:7;       /* completion type */
314    uint32 fcs:1;        /* Frame CRC correct */
315    uint32 frg:1;        /* IP Fragment */
316    uint32 v4:1;         /* IPv4 */
317    uint32 v6:1;         /* IPv6 */
318    uint32 ipc:1;        /* IP Checksum Correct */
319    uint32 tcp:1;        /* TCP packet */
320    uint32 udp:1;        /* UDP packet */
321    uint32 tuc:1;        /* TCP/UDP Checksum Correct */
322    uint32 csum:16;
323 #else
324    uint32 csum:16;
325    uint32 tuc:1;        /* TCP/UDP Checksum Correct */
326    uint32 udp:1;        /* UDP packet */
327    uint32 tcp:1;        /* TCP packet */
328    uint32 ipc:1;        /* IP Checksum Correct */
329    uint32 v6:1;         /* IPv6 */
330    uint32 v4:1;         /* IPv4 */
331    uint32 frg:1;        /* IP Fragment */
332    uint32 fcs:1;        /* Frame CRC correct */
333    uint32 type:7;       /* completion type */
334    uint32 gen:1;        /* generation bit */
335 #endif  /* __BIG_ENDIAN_BITFIELD */
336 }
337 #include "vmware_pack_end.h"
338 Vmxnet3_RxCompDesc;
339
340 typedef
341 #include "vmware_pack_begin.h"
342 struct Vmxnet3_RxCompDescExt {
343    __le32 dword1;
344    uint8  segCnt;       /* Number of aggregated packets */
345    uint8  dupAckCnt;    /* Number of duplicate Acks */
346    __le16 tsDelta;      /* TCP timestamp difference */
347    __le32 dword2[2];
348 }
349 #include "vmware_pack_end.h"
350 Vmxnet3_RxCompDescExt;
351
352 /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.dword[3] */
353 #define VMXNET3_RCD_TUC_SHIFT  16
354 #define VMXNET3_RCD_IPC_SHIFT  19
355
356 /* fields in RxCompDesc we access via Vmxnet3_GenericDesc.qword[1] */
357 #define VMXNET3_RCD_TYPE_SHIFT 56
358 #define VMXNET3_RCD_GEN_SHIFT  63
359
360 /* csum OK for TCP/UDP pkts over IP */
361 #define VMXNET3_RCD_CSUM_OK (1 << VMXNET3_RCD_TUC_SHIFT | 1 << VMXNET3_RCD_IPC_SHIFT)
362
363 /* value of RxCompDesc.rssType */
364 #define VMXNET3_RCD_RSS_TYPE_NONE     0
365 #define VMXNET3_RCD_RSS_TYPE_IPV4     1
366 #define VMXNET3_RCD_RSS_TYPE_TCPIPV4  2
367 #define VMXNET3_RCD_RSS_TYPE_IPV6     3
368 #define VMXNET3_RCD_RSS_TYPE_TCPIPV6  4
369
370 /* a union for accessing all cmd/completion descriptors */
371 typedef union Vmxnet3_GenericDesc {
372    __le64                qword[2];
373    __le32                dword[4];
374    __le16                word[8];
375    Vmxnet3_TxDesc        txd;
376    Vmxnet3_RxDesc        rxd;
377    Vmxnet3_TxCompDesc    tcd;
378    Vmxnet3_RxCompDesc    rcd;
379    Vmxnet3_RxCompDescExt rcdExt;
380 } Vmxnet3_GenericDesc;
381
382 #define VMXNET3_INIT_GEN       1
383
384 /* Max size of a single tx buffer */
385 #define VMXNET3_MAX_TX_BUF_SIZE  (1 << 14)
386
387 /* # of tx desc needed for a tx buffer size */
388 #define VMXNET3_TXD_NEEDED(size) (((size) + VMXNET3_MAX_TX_BUF_SIZE - 1) / VMXNET3_MAX_TX_BUF_SIZE)
389
390 /* max # of tx descs for a non-tso pkt */
391 #define VMXNET3_MAX_TXD_PER_PKT 16
392
393 /* Max size of a single rx buffer */
394 #define VMXNET3_MAX_RX_BUF_SIZE  ((1 << 14) - 1)
395 /* Minimum size of a type 0 buffer */
396 #define VMXNET3_MIN_T0_BUF_SIZE  128
397 #define VMXNET3_MAX_CSUM_OFFSET  1024
398
399 /* Ring base address alignment */
400 #define VMXNET3_RING_BA_ALIGN   512
401 #define VMXNET3_RING_BA_MASK    (VMXNET3_RING_BA_ALIGN - 1)
402
403 /* Ring size must be a multiple of 32 */
404 #define VMXNET3_RING_SIZE_ALIGN 32
405 #define VMXNET3_RING_SIZE_MASK  (VMXNET3_RING_SIZE_ALIGN - 1)
406
407 /* Tx Data Ring buffer size must be a multiple of 64 */
408 #define VMXNET3_TXDATA_DESC_SIZE_ALIGN 64
409 #define VMXNET3_TXDATA_DESC_SIZE_MASK  (VMXNET3_TXDATA_DESC_SIZE_ALIGN - 1)
410
411 /* Max ring size */
412 #define VMXNET3_TX_RING_MAX_SIZE   4096
413 #define VMXNET3_TC_RING_MAX_SIZE   4096
414 #define VMXNET3_RX_RING_MAX_SIZE   4096
415 #define VMXNET3_RC_RING_MAX_SIZE   8192
416
417 #define VMXNET3_TXDATA_DESC_MIN_SIZE 128
418 #define VMXNET3_TXDATA_DESC_MAX_SIZE 2048
419
420 /* a list of reasons for queue stop */
421
422 #define VMXNET3_ERR_NOEOP        0x80000000  /* cannot find the EOP desc of a pkt */
423 #define VMXNET3_ERR_TXD_REUSE    0x80000001  /* reuse a TxDesc before tx completion */
424 #define VMXNET3_ERR_BIG_PKT      0x80000002  /* too many TxDesc for a pkt */
425 #define VMXNET3_ERR_DESC_NOT_SPT 0x80000003  /* descriptor type not supported */
426 #define VMXNET3_ERR_SMALL_BUF    0x80000004  /* type 0 buffer too small */
427 #define VMXNET3_ERR_STRESS       0x80000005  /* stress option firing in vmkernel */
428 #define VMXNET3_ERR_SWITCH       0x80000006  /* mode switch failure */
429 #define VMXNET3_ERR_TXD_INVALID  0x80000007  /* invalid TxDesc */
430
431 /* completion descriptor types */
432 #define VMXNET3_CDTYPE_TXCOMP      0    /* Tx Completion Descriptor */
433 #define VMXNET3_CDTYPE_RXCOMP      3    /* Rx Completion Descriptor */
434 #define VMXNET3_CDTYPE_RXCOMP_LRO  4    /* Rx Completion Descriptor for LRO */
435
436 #define VMXNET3_GOS_BITS_UNK    0   /* unknown */
437 #define VMXNET3_GOS_BITS_32     1
438 #define VMXNET3_GOS_BITS_64     2
439
440 #define VMXNET3_GOS_TYPE_UNK        0 /* unknown */
441 #define VMXNET3_GOS_TYPE_LINUX      1
442 #define VMXNET3_GOS_TYPE_WIN        2
443 #define VMXNET3_GOS_TYPE_SOLARIS    3
444 #define VMXNET3_GOS_TYPE_FREEBSD    4
445 #define VMXNET3_GOS_TYPE_PXE        5
446
447 /* All structures in DriverShared are padded to multiples of 8 bytes */
448
449 typedef
450 #include "vmware_pack_begin.h"
451 struct Vmxnet3_GOSInfo {
452 #ifdef __BIG_ENDIAN_BITFIELD
453    uint32   gosMisc: 10;    /* other info about gos */
454    uint32   gosVer:  16;    /* gos version */
455    uint32   gosType: 4;     /* which guest */
456    uint32   gosBits: 2;     /* 32-bit or 64-bit? */
457 #else
458    uint32   gosBits: 2;     /* 32-bit or 64-bit? */
459    uint32   gosType: 4;     /* which guest */
460    uint32   gosVer:  16;    /* gos version */
461    uint32   gosMisc: 10;    /* other info about gos */
462 #endif  /* __BIG_ENDIAN_BITFIELD */
463 }
464 #include "vmware_pack_end.h"
465 Vmxnet3_GOSInfo;
466
467 typedef
468 #include "vmware_pack_begin.h"
469 struct Vmxnet3_DriverInfo {
470    __le32          version;        /* driver version */
471    Vmxnet3_GOSInfo gos;
472    __le32          vmxnet3RevSpt;  /* vmxnet3 revision supported */
473    __le32          uptVerSpt;      /* upt version supported */
474 }
475 #include "vmware_pack_end.h"
476 Vmxnet3_DriverInfo;
477
478 #define VMXNET3_REV1_MAGIC  0xbabefee1
479
480 /*
481  * QueueDescPA must be 128 bytes aligned. It points to an array of
482  * Vmxnet3_TxQueueDesc followed by an array of Vmxnet3_RxQueueDesc.
483  * The number of Vmxnet3_TxQueueDesc/Vmxnet3_RxQueueDesc are specified by
484  * Vmxnet3_MiscConf.numTxQueues/numRxQueues, respectively.
485  */
486 #define VMXNET3_QUEUE_DESC_ALIGN  128
487
488 typedef
489 #include "vmware_pack_begin.h"
490 struct Vmxnet3_MiscConf {
491    Vmxnet3_DriverInfo driverInfo;
492    __le64             uptFeatures;
493    __le64             ddPA;         /* driver data PA */
494    __le64             queueDescPA;  /* queue descriptor table PA */
495    __le32             ddLen;        /* driver data len */
496    __le32             queueDescLen; /* queue descriptor table len, in bytes */
497    __le32             mtu;
498    __le16             maxNumRxSG;
499    uint8              numTxQueues;
500    uint8              numRxQueues;
501    __le32             reserved[4];
502 }
503 #include "vmware_pack_end.h"
504 Vmxnet3_MiscConf;
505
506 typedef
507 #include "vmware_pack_begin.h"
508 struct Vmxnet3_TxQueueConf {
509    __le64    txRingBasePA;
510    __le64    dataRingBasePA;
511    __le64    compRingBasePA;
512    __le64    ddPA;         /* driver data */
513    __le64    reserved;
514    __le32    txRingSize;   /* # of tx desc */
515    __le32    dataRingSize; /* # of data desc */
516    __le32    compRingSize; /* # of comp desc */
517    __le32    ddLen;        /* size of driver data */
518    uint8     intrIdx;
519    uint8     _pad[1];
520    __le16    txDataRingDescSize;
521    uint8     _pad2[4];
522 }
523 #include "vmware_pack_end.h"
524 Vmxnet3_TxQueueConf;
525
526 typedef
527 #include "vmware_pack_begin.h"
528 struct Vmxnet3_RxQueueConf {
529    __le64    rxRingBasePA[2];
530    __le64    compRingBasePA;
531    __le64    ddPA;            /* driver data */
532    __le64    reserved;
533    __le32    rxRingSize[2];   /* # of rx desc */
534    __le32    compRingSize;    /* # of rx comp desc */
535    __le32    ddLen;           /* size of driver data */
536    uint8     intrIdx;
537    uint8     _pad[7];
538 }
539 #include "vmware_pack_end.h"
540 Vmxnet3_RxQueueConf;
541
542 enum vmxnet3_intr_mask_mode {
543    VMXNET3_IMM_AUTO   = 0,
544    VMXNET3_IMM_ACTIVE = 1,
545    VMXNET3_IMM_LAZY   = 2
546 };
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
555 #define VMXNET3_MAX_TX_QUEUES  8
556 #define VMXNET3_MAX_RX_QUEUES  16
557 /* addition 1 for events */
558 #define VMXNET3_MAX_INTRS      25
559
560 /* value of intrCtrl */
561 #define VMXNET3_IC_DISABLE_ALL  0x1   /* bit 0 */
562
563 typedef
564 #include "vmware_pack_begin.h"
565 struct Vmxnet3_IntrConf {
566    Bool   autoMask;
567    uint8  numIntrs;      /* # of interrupts */
568    uint8  eventIntrIdx;
569    uint8  modLevels[VMXNET3_MAX_INTRS]; /* moderation level for each intr */
570    __le32 intrCtrl;
571    __le32 reserved[2];
572 }
573 #include "vmware_pack_end.h"
574 Vmxnet3_IntrConf;
575
576 /* one bit per VLAN ID, the size is in the units of uint32 */
577 #define VMXNET3_VFT_SIZE  (4096 / (sizeof(uint32) * 8))
578
579 typedef
580 #include "vmware_pack_begin.h"
581 struct Vmxnet3_QueueStatus {
582    Bool    stopped;
583    uint8   _pad[3];
584    __le32  error;
585 }
586 #include "vmware_pack_end.h"
587 Vmxnet3_QueueStatus;
588
589 typedef
590 #include "vmware_pack_begin.h"
591 struct Vmxnet3_TxQueueCtrl {
592    __le32  txNumDeferred;
593    __le32  txThreshold;
594    __le64  reserved;
595 }
596 #include "vmware_pack_end.h"
597 Vmxnet3_TxQueueCtrl;
598
599 typedef
600 #include "vmware_pack_begin.h"
601 struct Vmxnet3_RxQueueCtrl {
602    Bool    updateRxProd;
603    uint8   _pad[7];
604    __le64  reserved;
605 }
606 #include "vmware_pack_end.h"
607 Vmxnet3_RxQueueCtrl;
608
609 #define VMXNET3_RXM_UCAST     0x01  /* unicast only */
610 #define VMXNET3_RXM_MCAST     0x02  /* multicast passing the filters */
611 #define VMXNET3_RXM_BCAST     0x04  /* broadcast only */
612 #define VMXNET3_RXM_ALL_MULTI 0x08  /* all multicast */
613 #define VMXNET3_RXM_PROMISC   0x10  /* promiscuous */
614
615 typedef
616 #include "vmware_pack_begin.h"
617 struct Vmxnet3_RxFilterConf {
618    __le32   rxMode;       /* VMXNET3_RXM_xxx */
619    __le16   mfTableLen;   /* size of the multicast filter table */
620    __le16   _pad1;
621    __le64   mfTablePA;    /* PA of the multicast filters table */
622    __le32   vfTable[VMXNET3_VFT_SIZE]; /* vlan filter */
623 }
624 #include "vmware_pack_end.h"
625 Vmxnet3_RxFilterConf;
626
627 #define VMXNET3_PM_MAX_FILTERS        6
628 #define VMXNET3_PM_MAX_PATTERN_SIZE   128
629 #define VMXNET3_PM_MAX_MASK_SIZE      (VMXNET3_PM_MAX_PATTERN_SIZE / 8)
630
631 #define VMXNET3_PM_WAKEUP_MAGIC       0x01  /* wake up on magic pkts */
632 #define VMXNET3_PM_WAKEUP_FILTER      0x02  /* wake up on pkts matching filters */
633
634 typedef
635 #include "vmware_pack_begin.h"
636 struct Vmxnet3_PM_PktFilter {
637    uint8 maskSize;
638    uint8 patternSize;
639    uint8 mask[VMXNET3_PM_MAX_MASK_SIZE];
640    uint8 pattern[VMXNET3_PM_MAX_PATTERN_SIZE];
641    uint8 pad[6];
642 }
643 #include "vmware_pack_end.h"
644 Vmxnet3_PM_PktFilter;
645
646 typedef
647 #include "vmware_pack_begin.h"
648 struct Vmxnet3_PMConf {
649    __le16               wakeUpEvents;  /* VMXNET3_PM_WAKEUP_xxx */
650    uint8                numFilters;
651    uint8                pad[5];
652    Vmxnet3_PM_PktFilter filters[VMXNET3_PM_MAX_FILTERS];
653 }
654 #include "vmware_pack_end.h"
655 Vmxnet3_PMConf;
656
657 typedef
658 #include "vmware_pack_begin.h"
659 struct Vmxnet3_VariableLenConfDesc {
660    __le32              confVer;
661    __le32              confLen;
662    __le64              confPA;
663 }
664 #include "vmware_pack_end.h"
665 Vmxnet3_VariableLenConfDesc;
666
667 typedef
668 #include "vmware_pack_begin.h"
669 struct Vmxnet3_DSDevRead {
670    /* read-only region for device, read by dev in response to a SET cmd */
671    Vmxnet3_MiscConf     misc;
672    Vmxnet3_IntrConf     intrConf;
673    Vmxnet3_RxFilterConf rxFilterConf;
674    Vmxnet3_VariableLenConfDesc  rssConfDesc;
675    Vmxnet3_VariableLenConfDesc  pmConfDesc;
676    Vmxnet3_VariableLenConfDesc  pluginConfDesc;
677 }
678 #include "vmware_pack_end.h"
679 Vmxnet3_DSDevRead;
680
681 typedef
682 #include "vmware_pack_begin.h"
683 struct Vmxnet3_TxQueueDesc {
684    Vmxnet3_TxQueueCtrl ctrl;
685    Vmxnet3_TxQueueConf conf;
686    /* Driver read after a GET command */
687    Vmxnet3_QueueStatus status;
688    UPT1_TxStats        stats;
689    uint8               _pad[88]; /* 128 aligned */
690 }
691 #include "vmware_pack_end.h"
692 Vmxnet3_TxQueueDesc;
693
694 typedef
695 #include "vmware_pack_begin.h"
696 struct Vmxnet3_RxQueueDesc {
697    Vmxnet3_RxQueueCtrl ctrl;
698    Vmxnet3_RxQueueConf conf;
699    /* Driver read after a GET command */
700    Vmxnet3_QueueStatus status;
701    UPT1_RxStats        stats;
702    uint8               _pad[88]; /* 128 aligned */
703 }
704 #include "vmware_pack_end.h"
705 Vmxnet3_RxQueueDesc;
706
707 typedef
708 #include "vmware_pack_begin.h"
709 struct Vmxnet3_SetPolling {
710    uint8 enablePolling;
711 }
712 #include "vmware_pack_end.h"
713 Vmxnet3_SetPolling;
714
715 /*
716  * If the command data <= 16 bytes, use the shared memory direcly.
717  * Otherwise, use the variable length configuration descriptor.
718  */
719 typedef
720 #include "vmware_pack_begin.h"
721 union Vmxnet3_CmdInfo {
722    Vmxnet3_VariableLenConfDesc varConf;
723    Vmxnet3_SetPolling          setPolling;
724    __le64                      data[2];
725 }
726 #include "vmware_pack_end.h"
727 Vmxnet3_CmdInfo;
728
729 typedef
730 #include "vmware_pack_begin.h"
731 struct Vmxnet3_DriverShared {
732    __le32               magic;
733    __le32               pad; /* make devRead start at 64-bit boundaries */
734    Vmxnet3_DSDevRead    devRead;
735    __le32               ecr;
736    __le32               reserved;
737
738    union {
739       __le32            reserved1[4];
740       Vmxnet3_CmdInfo   cmdInfo; /* only valid in the context of executing the
741                                   * relevant command
742                                   */
743    } cu;
744 }
745 #include "vmware_pack_end.h"
746 Vmxnet3_DriverShared;
747
748 #define VMXNET3_ECR_RQERR       (1 << 0)
749 #define VMXNET3_ECR_TQERR       (1 << 1)
750 #define VMXNET3_ECR_LINK        (1 << 2)
751 #define VMXNET3_ECR_DIC         (1 << 3)
752 #define VMXNET3_ECR_DEBUG       (1 << 4)
753
754 /* flip the gen bit of a ring */
755 #define VMXNET3_FLIP_RING_GEN(gen) ((gen) = (gen) ^ 0x1)
756
757 /* only use this if moving the idx won't affect the gen bit */
758 #define VMXNET3_INC_RING_IDX_ONLY(idx, ring_size) \
759 do {\
760    (idx)++;\
761    if (UNLIKELY((idx) == (ring_size))) {\
762       (idx) = 0;\
763    }\
764 } while (0)
765
766 #define VMXNET3_SET_VFTABLE_ENTRY(vfTable, vid) \
767    vfTable[vid >> 5] |= (1 << (vid & 31))
768 #define VMXNET3_CLEAR_VFTABLE_ENTRY(vfTable, vid) \
769    vfTable[vid >> 5] &= ~(1 << (vid & 31))
770
771 #define VMXNET3_VFTABLE_ENTRY_IS_SET(vfTable, vid) \
772    ((vfTable[vid >> 5] & (1 << (vid & 31))) != 0)
773
774 #define VMXNET3_MAX_MTU     9000
775 #define VMXNET3_MIN_MTU     60
776
777 #define VMXNET3_LINK_UP         (10000 << 16 | 1)    // 10 Gbps, up
778 #define VMXNET3_LINK_DOWN       0
779
780 #define VMXWIFI_DRIVER_SHARED_LEN 8192
781
782 #define VMXNET3_DID_PASSTHRU    0xFFFF
783
784 #endif /* _VMXNET3_DEFS_H_ */