ndis.h revision 307516
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: stable/11/sys/dev/hyperv/netvsc/ndis.h 307516 2016-10-17 09:31:49Z sephe $
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
63struct ndis_object_hdr {
64	uint8_t			ndis_type;	/* NDIS_OBJTYPE_ */
65	uint8_t			ndis_rev;	/* type specific */
66	uint16_t		ndis_size;	/* incl. this hdr */
67};
68
69/*
70 * OID_TCP_OFFLOAD_PARAMETERS
71 * ndis_type: NDIS_OBJTYPE_DEFAULT
72 */
73struct ndis_offload_params {
74	struct ndis_object_hdr	ndis_hdr;
75	uint8_t			ndis_ip4csum;	/* NDIS_OFFLOAD_PARAM_ */
76	uint8_t			ndis_tcp4csum;	/* NDIS_OFFLOAD_PARAM_ */
77	uint8_t			ndis_udp4csum;	/* NDIS_OFFLOAD_PARAM_ */
78	uint8_t			ndis_tcp6csum;	/* NDIS_OFFLOAD_PARAM_ */
79	uint8_t			ndis_udp6csum;	/* NDIS_OFFLOAD_PARAM_ */
80	uint8_t			ndis_lsov1;	/* NDIS_OFFLOAD_PARAM_ */
81	uint8_t			ndis_ipsecv1;	/* NDIS_OFFLOAD_IPSECV1_ */
82	uint8_t			ndis_lsov2_ip4;	/* NDIS_OFFLOAD_LSOV2_ */
83	uint8_t			ndis_lsov2_ip6;	/* NDIS_OFFLOAD_LSOV2_ */
84	uint8_t			ndis_tcp4conn;	/* 0 */
85	uint8_t			ndis_tcp6conn;	/* 0 */
86	uint32_t		ndis_flags;	/* 0 */
87	/* NDIS >= 6.1 */
88	uint8_t			ndis_ipsecv2;	/* NDIS_OFFLOAD_IPSECV2_ */
89	uint8_t			ndis_ipsecv2_ip4;/* NDIS_OFFLOAD_IPSECV2_ */
90	/* NDIS >= 6.30 */
91	uint8_t			ndis_rsc_ip4;	/* NDIS_OFFLOAD_RSC_ */
92	uint8_t			ndis_rsc_ip6;	/* NDIS_OFFLOAD_RSC_ */
93	uint8_t			ndis_encap;	/* NDIS_OFFLOAD_SET_ */
94	uint8_t			ndis_encap_types;/* NDIS_ENCAP_TYPE_ */
95};
96
97#define	NDIS_OFFLOAD_PARAMS_SIZE	sizeof(struct ndis_offload_params)
98#define	NDIS_OFFLOAD_PARAMS_SIZE_6_1	\
99	__offsetof(struct ndis_offload_params, ndis_rsc_ip4)
100
101#define	NDIS_OFFLOAD_PARAMS_REV_2	2	/* NDIS 6.1 */
102#define	NDIS_OFFLOAD_PARAMS_REV_3	3	/* NDIS 6.30 */
103
104#define	NDIS_OFFLOAD_PARAM_NOCHG	0	/* common */
105#define	NDIS_OFFLOAD_PARAM_OFF		1
106#define	NDIS_OFFLOAD_PARAM_TX		2
107#define	NDIS_OFFLOAD_PARAM_RX		3
108#define	NDIS_OFFLOAD_PARAM_TXRX		4
109
110/* NDIS_OFFLOAD_PARAM_NOCHG */
111#define	NDIS_OFFLOAD_LSOV1_OFF		1
112#define	NDIS_OFFLOAD_LSOV1_ON		2
113
114/* NDIS_OFFLOAD_PARAM_NOCHG */
115#define	NDIS_OFFLOAD_IPSECV1_OFF	1
116#define	NDIS_OFFLOAD_IPSECV1_AH		2
117#define	NDIS_OFFLOAD_IPSECV1_ESP	3
118#define	NDIS_OFFLOAD_IPSECV1_AH_ESP	4
119
120/* NDIS_OFFLOAD_PARAM_NOCHG */
121#define	NDIS_OFFLOAD_LSOV2_OFF		1
122#define	NDIS_OFFLOAD_LSOV2_ON		2
123
124/* NDIS_OFFLOAD_PARAM_NOCHG */
125#define	NDIS_OFFLOAD_IPSECV2_OFF	1
126#define	NDIS_OFFLOAD_IPSECV2_AH		2
127#define	NDIS_OFFLOAD_IPSECV2_ESP	3
128#define	NDIS_OFFLOAD_IPSECV2_AH_ESP	4
129
130/* NDIS_OFFLOAD_PARAM_NOCHG */
131#define	NDIS_OFFLOAD_RSC_OFF		1
132#define	NDIS_OFFLOAD_RSC_ON		2
133
134/*
135 * OID_GEN_RECEIVE_SCALE_CAPABILITIES
136 * ndis_type: NDIS_OBJTYPE_RSS_CAPS
137 */
138struct ndis_rss_caps {
139	struct ndis_object_hdr		ndis_hdr;
140	uint32_t			ndis_flags;	/* NDIS_RSS_CAP_ */
141	uint32_t			ndis_nmsi;	/* # of MSIs */
142	uint32_t			ndis_nrxr;	/* # of RX rings */
143	/* NDIS >= 6.30 */
144	uint16_t			ndis_nind;	/* # of indtbl ent. */
145	uint16_t			ndis_pad;
146};
147
148#define	NDIS_RSS_CAPS_SIZE		\
149	__offsetof(struct ndis_rss_caps, ndis_pad)
150#define	NDIS_RSS_CAPS_SIZE_6_0		\
151	__offsetof(struct ndis_rss_caps, ndis_nind)
152
153#define	NDIS_RSS_CAPS_REV_1		1	/* NDIS 6.{0,1,20} */
154#define	NDIS_RSS_CAPS_REV_2		2	/* NDIS 6.30 */
155
156#define	NDIS_RSS_CAP_MSI		0x01000000
157#define	NDIS_RSS_CAP_CLASSIFY_ISR	0x02000000
158#define	NDIS_RSS_CAP_CLASSIFY_DPC	0x04000000
159#define	NDIS_RSS_CAP_MSIX		0x08000000
160#define	NDIS_RSS_CAP_IPV4		0x00000100
161#define	NDIS_RSS_CAP_IPV6		0x00000200
162#define	NDIS_RSS_CAP_IPV6_EX		0x00000400
163#define	NDIS_RSS_CAP_HASH_TOEPLITZ	0x00000001
164
165/*
166 * OID_GEN_RECEIVE_SCALE_PARAMETERS
167 * ndis_type: NDIS_OBJTYPE_RSS_PARAMS
168 */
169struct ndis_rss_params {
170	struct ndis_object_hdr		ndis_hdr;
171	uint16_t			ndis_flags;	/* NDIS_RSS_FLAG_ */
172	uint16_t			ndis_bcpu;	/* base cpu 0 */
173	uint32_t			ndis_hash;	/* NDIS_HASH_ */
174	uint16_t			ndis_indsize;	/* indirect table */
175	uint32_t			ndis_indoffset;
176	uint16_t			ndis_keysize;	/* hash key */
177	uint32_t			ndis_keyoffset;
178	/* NDIS >= 6.20 */
179	uint32_t			ndis_cpumaskoffset;
180	uint32_t			ndis_cpumaskcnt;
181	uint32_t			ndis_cpumaskentsz;
182};
183
184#define	NDIS_RSS_PARAMS_SIZE		sizeof(struct ndis_rss_params)
185#define	NDIS_RSS_PARAMS_SIZE_6_0	\
186	__offsetof(struct ndis_rss_params, ndis_cpumaskoffset)
187
188#define	NDIS_RSS_PARAMS_REV_1		1	/* NDIS 6.0 */
189#define	NDIS_RSS_PARAMS_REV_2		2	/* NDIS 6.20 */
190
191#define	NDIS_RSS_FLAG_NONE		0x0000
192#define	NDIS_RSS_FLAG_BCPU_UNCHG	0x0001
193#define	NDIS_RSS_FLAG_HASH_UNCHG	0x0002
194#define	NDIS_RSS_FLAG_IND_UNCHG		0x0004
195#define	NDIS_RSS_FLAG_KEY_UNCHG		0x0008
196#define	NDIS_RSS_FLAG_DISABLE		0x0010
197
198/* non-standard convenient struct */
199struct ndis_rssprm_toeplitz {
200	struct ndis_rss_params		rss_params;
201	/* Toeplitz hash key */
202	uint8_t				rss_key[NDIS_HASH_KEYSIZE_TOEPLITZ];
203	/* Indirect table */
204	uint32_t			rss_ind[NDIS_HASH_INDCNT];
205};
206
207/*
208 * Per-packet-info
209 */
210
211/* VLAN */
212#define	NDIS_VLAN_INFO_SIZE		sizeof(uint32_t)
213#define	NDIS_VLAN_INFO_PRI_MASK		0x0007
214#define	NDIS_VLAN_INFO_CFI_MASK		0x0008
215#define	NDIS_VLAN_INFO_ID_MASK		0xfff0
216#define	NDIS_VLAN_INFO_MAKE(id, pri, cfi)	\
217        (((pri) & NDIS_VLAN_INFO_PRI_MASK) |	\
218	 (((cfi) & 0x1) << 3) | (((id) & 0xfff) << 4))
219#define	NDIS_VLAN_INFO_ID(inf)		(((inf) & NDIS_VLAN_INFO_ID_MASK) >> 4)
220#define	NDIS_VLAN_INFO_CFI(inf)		(((inf) & NDIS_VLAN_INFO_CFI_MASK) >> 3)
221#define	NDIS_VLAN_INFO_PRI(inf)		((inf) & NDIS_VLAN_INFO_PRI_MASK)
222
223/* Reception checksum */
224#define	NDIS_RXCSUM_INFO_SIZE		sizeof(uint32_t)
225#define	NDIS_RXCSUM_INFO_TCPCS_FAILED	0x0001
226#define	NDIS_RXCSUM_INFO_UDPCS_FAILED	0x0002
227#define	NDIS_RXCSUM_INFO_IPCS_FAILED	0x0004
228#define	NDIS_RXCSUM_INFO_TCPCS_OK	0x0008
229#define	NDIS_RXCSUM_INFO_UDPCS_OK	0x0010
230#define	NDIS_RXCSUM_INFO_IPCS_OK	0x0020
231#define	NDIS_RXCSUM_INFO_LOOPBACK	0x0040
232#define	NDIS_RXCSUM_INFO_TCPCS_INVAL	0x0080
233#define	NDIS_RXCSUM_INFO_IPCS_INVAL	0x0100
234
235/* LSOv2 */
236#define	NDIS_LSO2_INFO_SIZE		sizeof(uint32_t)
237#define	NDIS_LSO2_INFO_MSS_MASK		0x000fffff
238#define	NDIS_LSO2_INFO_THOFF_MASK	0x3ff00000
239#define	NDIS_LSO2_INFO_ISLSO2		0x40000000
240#define	NDIS_LSO2_INFO_ISIPV6		0x80000000
241
242#define	NDIS_LSO2_INFO_MAKE(thoff, mss)				\
243	((((uint32_t)(mss)) & NDIS_LSO2_INFO_MSS_MASK) |	\
244	 ((((uint32_t)(thoff)) & 0x3ff) << 20) |		\
245	 NDIS_LSO2_INFO_ISLSO2)
246
247#define	NDIS_LSO2_INFO_MAKEIPV4(thoff, mss)			\
248	NDIS_LSO2_INFO_MAKE((thoff), (mss))
249
250#define	NDIS_LSO2_INFO_MAKEIPV6(thoff, mss)			\
251	(NDIS_LSO2_INFO_MAKE((thoff), (mss)) | NDIS_LSO2_INFO_ISIPV6)
252
253/* Transmission checksum */
254#define	NDIS_TXCSUM_INFO_SIZE		sizeof(uint32_t)
255#define	NDIS_TXCSUM_INFO_IPV4		0x00000001
256#define	NDIS_TXCSUM_INFO_IPV6		0x00000002
257#define	NDIS_TXCSUM_INFO_TCPCS		0x00000004
258#define	NDIS_TXCSUM_INFO_UDPCS		0x00000008
259#define	NDIS_TXCSUM_INFO_IPCS		0x00000010
260#define	NDIS_TXCSUM_INFO_THOFF		0x03ff0000
261
262#endif	/* !_NET_NDIS_H_ */
263