xref: /freebsd/sys/dev/hyperv/netvsc/if_hnreg.h (revision 273c26a3c3bea87a241d6879abd4f991db180bf0)
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 _IF_HNREG_H_
30 #define _IF_HNREG_H_
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 
35 /*
36  * NDIS protocol version numbers
37  */
38 #define HN_NDIS_VERSION_6_1		0x00060001
39 #define HN_NDIS_VERSION_6_30		0x0006001e
40 #define HN_NDIS_VERSION_MAJOR(ver)	(((ver) & 0xffff0000) >> 16)
41 #define HN_NDIS_VERSION_MINOR(ver)	((ver) & 0xffff)
42 
43 /*
44  * NVS versions.
45  */
46 #define HN_NVS_VERSION_1		0x00002
47 #define HN_NVS_VERSION_2		0x30002
48 #define HN_NVS_VERSION_4		0x40000
49 #define HN_NVS_VERSION_5		0x50000
50 
51 #define HN_NVS_RXBUF_SIG		0xcafe
52 #define HN_NVS_CHIM_SIG			0xface
53 
54 #define HN_NVS_CHIM_IDX_INVALID		0xffffffff
55 
56 #define HN_NVS_RNDIS_MTYPE_DATA		0
57 #define HN_NVS_RNDIS_MTYPE_CTRL		1
58 
59 /*
60  * NVS message transacion status codes.
61  */
62 #define HN_NVS_STATUS_OK		1
63 #define HN_NVS_STATUS_FAILED		2
64 
65 /*
66  * NVS request/response message types.
67  */
68 #define HN_NVS_TYPE_INIT		1
69 #define HN_NVS_TYPE_INIT_RESP		2
70 #define HN_NVS_TYPE_NDIS_INIT		100
71 #define HN_NVS_TYPE_RXBUF_CONN		101
72 #define HN_NVS_TYPE_RXBUF_CONNRESP	102
73 #define HN_NVS_TYPE_RXBUF_DISCONN	103
74 #define HN_NVS_TYPE_CHIM_CONN		104
75 #define HN_NVS_TYPE_CHIM_CONNRESP	105
76 #define HN_NVS_TYPE_CHIM_DISCONN	106
77 #define HN_NVS_TYPE_RNDIS		107
78 #define HN_NVS_TYPE_RNDIS_ACK		108
79 #define HN_NVS_TYPE_NDIS_CONF		125
80 #define HN_NVS_TYPE_VFASSOC_NOTE	128	/* notification */
81 #define HN_NVS_TYPE_SET_DATAPATH	129
82 #define HN_NVS_TYPE_SUBCH_REQ		133
83 #define HN_NVS_TYPE_SUBCH_RESP		133	/* same as SUBCH_REQ */
84 #define HN_NVS_TYPE_TXTBL_NOTE		134	/* notification */
85 
86 /*
87  * Any size less than this one will _not_ work, e.g. hn_nvs_init
88  * only has 12B valid data, however, if only 12B data were sent,
89  * Hypervisor would never reply.
90  */
91 #define HN_NVS_REQSIZE_MIN		32
92 
93 /* NVS message common header */
94 struct hn_nvs_hdr {
95 	uint32_t	nvs_type;
96 } __packed;
97 
98 struct hn_nvs_init {
99 	uint32_t	nvs_type;	/* HN_NVS_TYPE_INIT */
100 	uint32_t	nvs_ver_min;
101 	uint32_t	nvs_ver_max;
102 	uint8_t		nvs_rsvd[20];
103 } __packed;
104 CTASSERT(sizeof(struct hn_nvs_init) >= HN_NVS_REQSIZE_MIN);
105 
106 struct hn_nvs_init_resp {
107 	uint32_t	nvs_type;	/* HN_NVS_TYPE_INIT_RESP */
108 	uint32_t	nvs_ver;	/* deprecated */
109 	uint32_t	nvs_rsvd;
110 	uint32_t	nvs_status;	/* HN_NVS_STATUS_ */
111 } __packed;
112 
113 /* No reponse */
114 struct hn_nvs_ndis_conf {
115 	uint32_t	nvs_type;	/* HN_NVS_TYPE_NDIS_CONF */
116 	uint32_t	nvs_mtu;
117 	uint32_t	nvs_rsvd;
118 	uint64_t	nvs_caps;	/* HN_NVS_NDIS_CONF_ */
119 	uint8_t		nvs_rsvd1[12];
120 } __packed;
121 CTASSERT(sizeof(struct hn_nvs_ndis_conf) >= HN_NVS_REQSIZE_MIN);
122 
123 #define HN_NVS_NDIS_CONF_SRIOV		0x0004
124 #define HN_NVS_NDIS_CONF_VLAN		0x0008
125 
126 /* No response */
127 struct hn_nvs_ndis_init {
128 	uint32_t	nvs_type;	/* HN_NVS_TYPE_NDIS_INIT */
129 	uint32_t	nvs_ndis_major;	/* NDIS_VERSION_MAJOR_ */
130 	uint32_t	nvs_ndis_minor;	/* NDIS_VERSION_MINOR_ */
131 	uint8_t		nvs_rsvd[20];
132 } __packed;
133 CTASSERT(sizeof(struct hn_nvs_ndis_init) >= HN_NVS_REQSIZE_MIN);
134 
135 struct hn_nvs_rxbuf_conn {
136 	uint32_t	nvs_type;	/* HN_NVS_TYPE_RXBUF_CONN */
137 	uint32_t	nvs_gpadl;	/* RXBUF vmbus GPADL */
138 	uint16_t	nvs_sig;	/* HN_NVS_RXBUF_SIG */
139 	uint8_t		nvs_rsvd[22];
140 } __packed;
141 CTASSERT(sizeof(struct hn_nvs_rxbuf_conn) >= HN_NVS_REQSIZE_MIN);
142 
143 struct hn_nvs_rxbuf_sect {
144 	uint32_t	nvs_start;
145 	uint32_t	nvs_slotsz;
146 	uint32_t	nvs_slotcnt;
147 	uint32_t	nvs_end;
148 } __packed;
149 
150 struct hn_nvs_rxbuf_connresp {
151 	uint32_t	nvs_type;	/* HN_NVS_TYPE_RXBUF_CONNRESP */
152 	uint32_t	nvs_status;	/* HN_NVS_STATUS_ */
153 	uint32_t	nvs_nsect;	/* # of elem in nvs_sect */
154 	struct hn_nvs_rxbuf_sect nvs_sect[];
155 } __packed;
156 
157 /* No response */
158 struct hn_nvs_rxbuf_disconn {
159 	uint32_t	nvs_type;	/* HN_NVS_TYPE_RXBUF_DISCONN */
160 	uint16_t	nvs_sig;	/* HN_NVS_RXBUF_SIG */
161 	uint8_t		nvs_rsvd[26];
162 } __packed;
163 CTASSERT(sizeof(struct hn_nvs_rxbuf_disconn) >= HN_NVS_REQSIZE_MIN);
164 
165 struct hn_nvs_chim_conn {
166 	uint32_t	nvs_type;	/* HN_NVS_TYPE_CHIM_CONN */
167 	uint32_t	nvs_gpadl;	/* chimney buf vmbus GPADL */
168 	uint16_t	nvs_sig;	/* NDIS_NVS_CHIM_SIG */
169 	uint8_t		nvs_rsvd[22];
170 } __packed;
171 CTASSERT(sizeof(struct hn_nvs_chim_conn) >= HN_NVS_REQSIZE_MIN);
172 
173 struct hn_nvs_chim_connresp {
174 	uint32_t	nvs_type;	/* HN_NVS_TYPE_CHIM_CONNRESP */
175 	uint32_t	nvs_status;	/* HN_NVS_STATUS_ */
176 	uint32_t	nvs_sectsz;	/* section size */
177 } __packed;
178 
179 /* No response */
180 struct hn_nvs_chim_disconn {
181 	uint32_t	nvs_type;	/* HN_NVS_TYPE_CHIM_DISCONN */
182 	uint16_t	nvs_sig;	/* HN_NVS_CHIM_SIG */
183 	uint8_t		nvs_rsvd[26];
184 } __packed;
185 CTASSERT(sizeof(struct hn_nvs_chim_disconn) >= HN_NVS_REQSIZE_MIN);
186 
187 #define HN_NVS_SUBCH_OP_ALLOC		1
188 
189 struct hn_nvs_subch_req {
190 	uint32_t	nvs_type;	/* HN_NVS_TYPE_SUBCH_REQ */
191 	uint32_t	nvs_op;		/* HN_NVS_SUBCH_OP_ */
192 	uint32_t	nvs_nsubch;
193 	uint8_t		nvs_rsvd[20];
194 } __packed;
195 CTASSERT(sizeof(struct hn_nvs_subch_req) >= HN_NVS_REQSIZE_MIN);
196 
197 struct hn_nvs_subch_resp {
198 	uint32_t	nvs_type;	/* HN_NVS_TYPE_SUBCH_RESP */
199 	uint32_t	nvs_status;	/* HN_NVS_STATUS_ */
200 	uint32_t	nvs_nsubch;
201 } __packed;
202 
203 struct hn_nvs_rndis {
204 	uint32_t	nvs_type;	/* HN_NVS_TYPE_RNDIS */
205 	uint32_t	nvs_rndis_mtype;/* HN_NVS_RNDIS_MTYPE_ */
206 	/*
207 	 * Chimney sending buffer index and size.
208 	 *
209 	 * NOTE:
210 	 * If nvs_chim_idx is set to HN_NVS_CHIM_IDX_INVALID
211 	 * and nvs_chim_sz is set to 0, then chimney sending
212 	 * buffer is _not_ used by this RNDIS message.
213 	 */
214 	uint32_t	nvs_chim_idx;
215 	uint32_t	nvs_chim_sz;
216 	uint8_t		nvs_rsvd[16];
217 } __packed;
218 CTASSERT(sizeof(struct hn_nvs_rndis) >= HN_NVS_REQSIZE_MIN);
219 
220 struct hn_nvs_rndis_ack {
221 	uint32_t	nvs_type;	/* HN_NVS_TYPE_RNDIS_ACK */
222 	uint32_t	nvs_status;	/* HN_NVS_STATUS_ */
223 	uint8_t		nvs_rsvd[24];
224 } __packed;
225 CTASSERT(sizeof(struct hn_nvs_rndis_ack) >= HN_NVS_REQSIZE_MIN);
226 
227 /*
228  * RNDIS extension
229  */
230 
231 /* Per-packet hash info */
232 #define HN_NDIS_HASH_INFO_SIZE		sizeof(uint32_t)
233 #define HN_NDIS_PKTINFO_TYPE_HASHINF	NDIS_PKTINFO_TYPE_ORIG_NBLIST
234 /* NDIS_HASH_ */
235 
236 /* Per-packet hash value */
237 #define HN_NDIS_HASH_VALUE_SIZE		sizeof(uint32_t)
238 #define HN_NDIS_PKTINFO_TYPE_HASHVAL	NDIS_PKTINFO_TYPE_PKT_CANCELID
239 
240 /* Per-packet-info size */
241 #define HN_RNDIS_PKTINFO_SIZE(dlen)	\
242 	__offsetof(struct rndis_pktinfo, rm_data[dlen])
243 
244 #endif	/* !_IF_HNREG_H_ */
245