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