New upstream version 18.08
[deb_dpdk.git] / drivers / net / netvsc / ndis.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2018 Microsoft Corp.
3  * All rights reserved.
4  */
5
6 #ifndef _NET_NDIS_H_
7 #define _NET_NDIS_H_
8
9 #define NDIS_MEDIA_STATE_CONNECTED      0
10 #define NDIS_MEDIA_STATE_DISCONNECTED   1
11
12 #define NDIS_NETCHANGE_TYPE_POSSIBLE    1
13 #define NDIS_NETCHANGE_TYPE_DEFINITE    2
14 #define NDIS_NETCHANGE_TYPE_FROMMEDIA   3
15
16 #define NDIS_OFFLOAD_SET_NOCHG          0
17 #define NDIS_OFFLOAD_SET_ON             1
18 #define NDIS_OFFLOAD_SET_OFF            2
19
20 /* a.k.a GRE MAC */
21 #define NDIS_ENCAP_TYPE_NVGRE           0x00000001
22
23 #define NDIS_HASH_FUNCTION_MASK         0x000000FF      /* see hash function */
24 #define NDIS_HASH_TYPE_MASK             0x00FFFF00      /* see hash type */
25
26 /* hash function */
27 #define NDIS_HASH_FUNCTION_TOEPLITZ     0x00000001
28
29 /* hash type */
30 #define NDIS_HASH_IPV4                  0x00000100
31 #define NDIS_HASH_TCP_IPV4              0x00000200
32 #define NDIS_HASH_IPV6                  0x00000400
33 #define NDIS_HASH_IPV6_EX               0x00000800
34 #define NDIS_HASH_TCP_IPV6              0x00001000
35 #define NDIS_HASH_TCP_IPV6_EX           0x00002000
36
37 #define NDIS_HASH_KEYSIZE_TOEPLITZ      40
38 #define NDIS_HASH_INDCNT                128
39
40 #define NDIS_OBJTYPE_DEFAULT            0x80
41 #define NDIS_OBJTYPE_RSS_CAPS           0x88
42 #define NDIS_OBJTYPE_RSS_PARAMS         0x89
43 #define NDIS_OBJTYPE_OFFLOAD            0xa7
44
45 struct ndis_object_hdr {
46         uint8_t                 ndis_type;      /* NDIS_OBJTYPE_ */
47         uint8_t                 ndis_rev;       /* type specific */
48         uint16_t                ndis_size;      /* incl. this hdr */
49 } __rte_packed;
50
51 /*
52  * OID_TCP_OFFLOAD_PARAMETERS
53  * ndis_type: NDIS_OBJTYPE_DEFAULT
54  */
55 struct ndis_offload_params {
56         struct ndis_object_hdr  ndis_hdr;
57         uint8_t                 ndis_ip4csum;   /* NDIS_OFFLOAD_PARAM_ */
58         uint8_t                 ndis_tcp4csum;  /* NDIS_OFFLOAD_PARAM_ */
59         uint8_t                 ndis_udp4csum;  /* NDIS_OFFLOAD_PARAM_ */
60         uint8_t                 ndis_tcp6csum;  /* NDIS_OFFLOAD_PARAM_ */
61         uint8_t                 ndis_udp6csum;  /* NDIS_OFFLOAD_PARAM_ */
62         uint8_t                 ndis_lsov1;     /* NDIS_OFFLOAD_PARAM_ */
63         uint8_t                 ndis_ipsecv1;   /* NDIS_OFFLOAD_IPSECV1_ */
64         uint8_t                 ndis_lsov2_ip4; /* NDIS_OFFLOAD_LSOV2_ */
65         uint8_t                 ndis_lsov2_ip6; /* NDIS_OFFLOAD_LSOV2_ */
66         uint8_t                 ndis_tcp4conn;  /* 0 */
67         uint8_t                 ndis_tcp6conn;  /* 0 */
68         uint32_t                ndis_flags;     /* 0 */
69         /* NDIS >= 6.1 */
70         uint8_t                 ndis_ipsecv2;   /* NDIS_OFFLOAD_IPSECV2_ */
71         uint8_t                 ndis_ipsecv2_ip4;/* NDIS_OFFLOAD_IPSECV2_ */
72         /* NDIS >= 6.30 */
73         uint8_t                 ndis_rsc_ip4;   /* NDIS_OFFLOAD_RSC_ */
74         uint8_t                 ndis_rsc_ip6;   /* NDIS_OFFLOAD_RSC_ */
75         uint8_t                 ndis_encap;     /* NDIS_OFFLOAD_SET_ */
76         uint8_t                 ndis_encap_types;/* NDIS_ENCAP_TYPE_ */
77 };
78
79 #define NDIS_OFFLOAD_PARAMS_SIZE        sizeof(struct ndis_offload_params)
80 #define NDIS_OFFLOAD_PARAMS_SIZE_6_1    \
81         offsetof(struct ndis_offload_params, ndis_rsc_ip4)
82
83 #define NDIS_OFFLOAD_PARAMS_REV_2       2       /* NDIS 6.1 */
84 #define NDIS_OFFLOAD_PARAMS_REV_3       3       /* NDIS 6.30 */
85
86 #define NDIS_OFFLOAD_PARAM_NOCHG        0       /* common */
87 #define NDIS_OFFLOAD_PARAM_OFF          1
88 #define NDIS_OFFLOAD_PARAM_TX           2
89 #define NDIS_OFFLOAD_PARAM_RX           3
90 #define NDIS_OFFLOAD_PARAM_TXRX         4
91
92 /* NDIS_OFFLOAD_PARAM_NOCHG */
93 #define NDIS_OFFLOAD_LSOV1_OFF          1
94 #define NDIS_OFFLOAD_LSOV1_ON           2
95
96 /* NDIS_OFFLOAD_PARAM_NOCHG */
97 #define NDIS_OFFLOAD_IPSECV1_OFF        1
98 #define NDIS_OFFLOAD_IPSECV1_AH         2
99 #define NDIS_OFFLOAD_IPSECV1_ESP        3
100 #define NDIS_OFFLOAD_IPSECV1_AH_ESP     4
101
102 /* NDIS_OFFLOAD_PARAM_NOCHG */
103 #define NDIS_OFFLOAD_LSOV2_OFF          1
104 #define NDIS_OFFLOAD_LSOV2_ON           2
105
106 /* NDIS_OFFLOAD_PARAM_NOCHG */
107 #define NDIS_OFFLOAD_IPSECV2_OFF        1
108 #define NDIS_OFFLOAD_IPSECV2_AH         2
109 #define NDIS_OFFLOAD_IPSECV2_ESP        3
110 #define NDIS_OFFLOAD_IPSECV2_AH_ESP     4
111
112 /* NDIS_OFFLOAD_PARAM_NOCHG */
113 #define NDIS_OFFLOAD_RSC_OFF            1
114 #define NDIS_OFFLOAD_RSC_ON             2
115
116 /*
117  * OID_GEN_RECEIVE_SCALE_CAPABILITIES
118  * ndis_type: NDIS_OBJTYPE_RSS_CAPS
119  */
120 struct ndis_rss_caps {
121         struct ndis_object_hdr          ndis_hdr;
122         uint32_t                        ndis_caps;      /* NDIS_RSS_CAP_ */
123         uint32_t                        ndis_nmsi;      /* # of MSIs */
124         uint32_t                        ndis_nrxr;      /* # of RX rings */
125         /* NDIS >= 6.30 */
126         uint16_t                        ndis_nind;      /* # of indtbl ent. */
127         uint16_t                        ndis_pad;
128 } __rte_packed;
129
130 #define NDIS_RSS_CAPS_SIZE              \
131         offsetof(struct ndis_rss_caps, ndis_pad)
132 #define NDIS_RSS_CAPS_SIZE_6_0          \
133         offsetof(struct ndis_rss_caps, ndis_nind)
134
135 #define NDIS_RSS_CAPS_REV_1             1       /* NDIS 6.{0,1,20} */
136 #define NDIS_RSS_CAPS_REV_2             2       /* NDIS 6.30 */
137
138 #define NDIS_RSS_CAP_MSI                0x01000000
139 #define NDIS_RSS_CAP_CLASSIFY_ISR       0x02000000
140 #define NDIS_RSS_CAP_CLASSIFY_DPC       0x04000000
141 #define NDIS_RSS_CAP_MSIX               0x08000000
142 #define NDIS_RSS_CAP_IPV4               0x00000100
143 #define NDIS_RSS_CAP_IPV6               0x00000200
144 #define NDIS_RSS_CAP_IPV6_EX            0x00000400
145 #define NDIS_RSS_CAP_HASH_TOEPLITZ      NDIS_HASH_FUNCTION_TOEPLITZ
146 #define NDIS_RSS_CAP_HASHFUNC_MASK      NDIS_HASH_FUNCTION_MASK
147
148 /*
149  * OID_GEN_RECEIVE_SCALE_PARAMETERS
150  * ndis_type: NDIS_OBJTYPE_RSS_PARAMS
151  */
152 struct ndis_rss_params {
153         struct ndis_object_hdr          ndis_hdr;
154         uint16_t                        ndis_flags;     /* NDIS_RSS_FLAG_ */
155         uint16_t                        ndis_bcpu;      /* base cpu 0 */
156         uint32_t                        ndis_hash;      /* NDIS_HASH_ */
157         uint16_t                        ndis_indsize;   /* indirect table */
158         uint32_t                        ndis_indoffset;
159         uint16_t                        ndis_keysize;   /* hash key */
160         uint32_t                        ndis_keyoffset;
161         /* NDIS >= 6.20 */
162         uint32_t                        ndis_cpumaskoffset;
163         uint32_t                        ndis_cpumaskcnt;
164         uint32_t                        ndis_cpumaskentsz;
165 };
166
167 #define NDIS_RSS_PARAMS_SIZE            sizeof(struct ndis_rss_params)
168 #define NDIS_RSS_PARAMS_SIZE_6_0        \
169         offsetof(struct ndis_rss_params, ndis_cpumaskoffset)
170
171 #define NDIS_RSS_PARAMS_REV_1           1       /* NDIS 6.0 */
172 #define NDIS_RSS_PARAMS_REV_2           2       /* NDIS 6.20 */
173
174 #define NDIS_RSS_FLAG_NONE              0x0000
175 #define NDIS_RSS_FLAG_BCPU_UNCHG        0x0001
176 #define NDIS_RSS_FLAG_HASH_UNCHG        0x0002
177 #define NDIS_RSS_FLAG_IND_UNCHG         0x0004
178 #define NDIS_RSS_FLAG_KEY_UNCHG         0x0008
179 #define NDIS_RSS_FLAG_DISABLE           0x0010
180
181 /* non-standard convenient struct */
182 struct ndis_rssprm_toeplitz {
183         struct ndis_rss_params          rss_params;
184         /* Indirect table */
185         uint32_t                        rss_ind[NDIS_HASH_INDCNT];
186         /* Toeplitz hash key */
187         uint8_t                         rss_key[NDIS_HASH_KEYSIZE_TOEPLITZ];
188 };
189
190 #define NDIS_RSSPRM_TOEPLITZ_SIZE(nind) \
191         offsetof(struct ndis_rssprm_toeplitz, rss_ind[nind])
192
193 /*
194  * OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES
195  * ndis_type: NDIS_OBJTYPE_OFFLOAD
196  */
197
198 #define NDIS_OFFLOAD_ENCAP_NONE         0x0000
199 #define NDIS_OFFLOAD_ENCAP_NULL         0x0001
200 #define NDIS_OFFLOAD_ENCAP_8023         0x0002
201 #define NDIS_OFFLOAD_ENCAP_8023PQ       0x0004
202 #define NDIS_OFFLOAD_ENCAP_8023PQ_OOB   0x0008
203 #define NDIS_OFFLOAD_ENCAP_RFC1483      0x0010
204
205 struct ndis_csum_offload {
206         uint32_t                        ndis_ip4_txenc; /*NDIS_OFFLOAD_ENCAP_*/
207         uint32_t                        ndis_ip4_txcsum;
208 #define NDIS_TXCSUM_CAP_IP4OPT          0x001
209 #define NDIS_TXCSUM_CAP_TCP4OPT         0x004
210 #define NDIS_TXCSUM_CAP_TCP4            0x010
211 #define NDIS_TXCSUM_CAP_UDP4            0x040
212 #define NDIS_TXCSUM_CAP_IP4             0x100
213         uint32_t                        ndis_ip4_rxenc; /*NDIS_OFFLOAD_ENCAP_*/
214         uint32_t                        ndis_ip4_rxcsum;
215 #define NDIS_RXCSUM_CAP_IP4OPT          0x001
216 #define NDIS_RXCSUM_CAP_TCP4OPT         0x004
217 #define NDIS_RXCSUM_CAP_TCP4            0x010
218 #define NDIS_RXCSUM_CAP_UDP4            0x040
219 #define NDIS_RXCSUM_CAP_IP4             0x100
220         uint32_t                        ndis_ip6_txenc; /*NDIS_OFFLOAD_ENCAP_*/
221         uint32_t                        ndis_ip6_txcsum;
222 #define NDIS_TXCSUM_CAP_IP6EXT          0x001
223 #define NDIS_TXCSUM_CAP_TCP6OPT         0x004
224 #define NDIS_TXCSUM_CAP_TCP6            0x010
225 #define NDIS_TXCSUM_CAP_UDP6            0x040
226         uint32_t                        ndis_ip6_rxenc; /*NDIS_OFFLOAD_ENCAP_*/
227         uint32_t                        ndis_ip6_rxcsum;
228 #define NDIS_RXCSUM_CAP_IP6EXT          0x001
229 #define NDIS_RXCSUM_CAP_TCP6OPT         0x004
230 #define NDIS_RXCSUM_CAP_TCP6            0x010
231 #define NDIS_RXCSUM_CAP_UDP6            0x040
232 };
233
234 struct ndis_lsov1_offload {
235         uint32_t                        ndis_encap;     /*NDIS_OFFLOAD_ENCAP_*/
236         uint32_t                        ndis_maxsize;
237         uint32_t                        ndis_minsegs;
238         uint32_t                        ndis_opts;
239 };
240
241 struct ndis_ipsecv1_offload {
242         uint32_t                        ndis_encap;     /*NDIS_OFFLOAD_ENCAP_*/
243         uint32_t                        ndis_ah_esp;
244         uint32_t                        ndis_xport_tun;
245         uint32_t                        ndis_ip4_opts;
246         uint32_t                        ndis_flags;
247         uint32_t                        ndis_ip4_ah;
248         uint32_t                        ndis_ip4_esp;
249 };
250
251 struct ndis_lsov2_offload {
252         uint32_t                        ndis_ip4_encap; /*NDIS_OFFLOAD_ENCAP_*/
253         uint32_t                        ndis_ip4_maxsz;
254         uint32_t                        ndis_ip4_minsg;
255         uint32_t                        ndis_ip6_encap; /*NDIS_OFFLOAD_ENCAP_*/
256         uint32_t                        ndis_ip6_maxsz;
257         uint32_t                        ndis_ip6_minsg;
258         uint32_t                        ndis_ip6_opts;
259 #define NDIS_LSOV2_CAP_IP6EXT           0x001
260 #define NDIS_LSOV2_CAP_TCP6OPT          0x004
261 };
262
263 struct ndis_ipsecv2_offload {
264         uint32_t                        ndis_encap;     /*NDIS_OFFLOAD_ENCAP_*/
265         uint16_t                        ndis_ip6;
266         uint16_t                        ndis_ip4opt;
267         uint16_t                        ndis_ip6ext;
268         uint16_t                        ndis_ah;
269         uint16_t                        ndis_esp;
270         uint16_t                        ndis_ah_esp;
271         uint16_t                        ndis_xport;
272         uint16_t                        ndis_tun;
273         uint16_t                        ndis_xport_tun;
274         uint16_t                        ndis_lso;
275         uint16_t                        ndis_extseq;
276         uint32_t                        ndis_udp_esp;
277         uint32_t                        ndis_auth;
278         uint32_t                        ndis_crypto;
279         uint32_t                        ndis_sa_caps;
280 };
281
282 struct ndis_rsc_offload {
283         uint16_t                        ndis_ip4;
284         uint16_t                        ndis_ip6;
285 };
286
287 struct ndis_encap_offload {
288         uint32_t                        ndis_flags;
289         uint32_t                        ndis_maxhdr;
290 };
291
292 struct ndis_offload {
293         struct ndis_object_hdr          ndis_hdr;
294         struct ndis_csum_offload        ndis_csum;
295         struct ndis_lsov1_offload       ndis_lsov1;
296         struct ndis_ipsecv1_offload     ndis_ipsecv1;
297         struct ndis_lsov2_offload       ndis_lsov2;
298         uint32_t                        ndis_flags;
299         /* NDIS >= 6.1 */
300         struct ndis_ipsecv2_offload     ndis_ipsecv2;
301         /* NDIS >= 6.30 */
302         struct ndis_rsc_offload         ndis_rsc;
303         struct ndis_encap_offload       ndis_encap_gre;
304 };
305
306 #define NDIS_OFFLOAD_SIZE               sizeof(struct ndis_offload)
307 #define NDIS_OFFLOAD_SIZE_6_0           offsetof(struct ndis_offload, ndis_ipsecv2)
308 #define NDIS_OFFLOAD_SIZE_6_1           offsetof(struct ndis_offload, ndis_rsc)
309
310 #define NDIS_OFFLOAD_REV_1              1       /* NDIS 6.0 */
311 #define NDIS_OFFLOAD_REV_2              2       /* NDIS 6.1 */
312 #define NDIS_OFFLOAD_REV_3              3       /* NDIS 6.30 */
313
314 /*
315  * Per-packet-info
316  */
317
318 /* VLAN */
319 #define NDIS_VLAN_INFO_SIZE             sizeof(uint32_t)
320 #define NDIS_VLAN_INFO_PRI_MASK         0x0007
321 #define NDIS_VLAN_INFO_CFI_MASK         0x0008
322 #define NDIS_VLAN_INFO_ID_MASK          0xfff0
323 #define NDIS_VLAN_INFO_MAKE(id, pri, cfi)       \
324         (((pri) & NDIS_VLAN_INFO_PRI_MASK) |    \
325          (((cfi) & 0x1) << 3) | (((id) & 0xfff) << 4))
326 #define NDIS_VLAN_INFO_ID(inf)          (((inf) & NDIS_VLAN_INFO_ID_MASK) >> 4)
327 #define NDIS_VLAN_INFO_CFI(inf)         (((inf) & NDIS_VLAN_INFO_CFI_MASK) >> 3)
328 #define NDIS_VLAN_INFO_PRI(inf)         ((inf) & NDIS_VLAN_INFO_PRI_MASK)
329
330 /* Reception checksum */
331 #define NDIS_RXCSUM_INFO_SIZE           sizeof(uint32_t)
332 #define NDIS_RXCSUM_INFO_TCPCS_FAILED   0x0001
333 #define NDIS_RXCSUM_INFO_UDPCS_FAILED   0x0002
334 #define NDIS_RXCSUM_INFO_IPCS_FAILED    0x0004
335 #define NDIS_RXCSUM_INFO_TCPCS_OK       0x0008
336 #define NDIS_RXCSUM_INFO_UDPCS_OK       0x0010
337 #define NDIS_RXCSUM_INFO_IPCS_OK        0x0020
338 #define NDIS_RXCSUM_INFO_LOOPBACK       0x0040
339 #define NDIS_RXCSUM_INFO_TCPCS_INVAL    0x0080
340 #define NDIS_RXCSUM_INFO_IPCS_INVAL     0x0100
341
342 /* LSOv2 */
343 #define NDIS_LSO2_INFO_SIZE             sizeof(uint32_t)
344 #define NDIS_LSO2_INFO_MSS_MASK         0x000fffff
345 #define NDIS_LSO2_INFO_THOFF_MASK       0x3ff00000
346 #define NDIS_LSO2_INFO_ISLSO2           0x40000000
347 #define NDIS_LSO2_INFO_ISIPV6           0x80000000
348
349 #define NDIS_LSO2_INFO_MAKE(thoff, mss)                         \
350         ((((uint32_t)(mss)) & NDIS_LSO2_INFO_MSS_MASK) |        \
351          ((((uint32_t)(thoff)) & 0x3ff) << 20) |                \
352          NDIS_LSO2_INFO_ISLSO2)
353
354 #define NDIS_LSO2_INFO_MAKEIPV4(thoff, mss)                     \
355         NDIS_LSO2_INFO_MAKE((thoff), (mss))
356
357 #define NDIS_LSO2_INFO_MAKEIPV6(thoff, mss)                     \
358         (NDIS_LSO2_INFO_MAKE((thoff), (mss)) | NDIS_LSO2_INFO_ISIPV6)
359
360 /* Transmission checksum */
361 #define NDIS_TXCSUM_INFO_SIZE           sizeof(uint32_t)
362 #define NDIS_TXCSUM_INFO_IPV4           0x00000001
363 #define NDIS_TXCSUM_INFO_IPV6           0x00000002
364 #define NDIS_TXCSUM_INFO_TCPCS          0x00000004
365 #define NDIS_TXCSUM_INFO_UDPCS          0x00000008
366 #define NDIS_TXCSUM_INFO_IPCS           0x00000010
367 #define NDIS_TXCSUM_INFO_THOFF          0x03ff0000
368
369 #define NDIS_TXCSUM_INFO_MKL4CS(thoff, flag)                    \
370         ((((uint32_t)(thoff)) << 16) | (flag))
371
372 #define NDIS_TXCSUM_INFO_MKTCPCS(thoff)                         \
373         NDIS_TXCSUM_INFO_MKL4CS((thoff), NDIS_TXCSUM_INFO_TCPCS)
374
375 #define NDIS_TXCSUM_INFO_MKUDPCS(thoff)                         \
376         NDIS_TXCSUM_INFO_MKL4CS((thoff), NDIS_TXCSUM_INFO_UDPCS)
377
378 #endif  /* !_NET_NDIS_H_ */