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