zfs: merge openzfs/zfs@a382e2119
[freebsd.git] / sys / net / rndis.h
1 /*      $OpenBSD: if_urndisreg.h,v 1.19 2013/11/21 14:08:05 mpi Exp $ */
2
3 /*
4  * Copyright (c) 2010 Jonathan Armani <armani@openbsd.org>
5  * Copyright (c) 2010 Fabien Romano <fabien@openbsd.org>
6  * Copyright (c) 2010 Michael Knudsen <mk@openbsd.org>
7  * All rights reserved.
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21
22 #ifndef _NET_RNDIS_H_
23 #define _NET_RNDIS_H_
24
25 /* Canonical major/minor version as of 22th Aug. 2016. */
26 #define RNDIS_VERSION_MAJOR             0x00000001
27 #define RNDIS_VERSION_MINOR             0x00000000
28
29 #define RNDIS_STATUS_SUCCESS            0x00000000L
30 #define RNDIS_STATUS_PENDING            0x00000103L
31 #define RNDIS_STATUS_MEDIA_CONNECT      0x4001000BL
32 #define RNDIS_STATUS_MEDIA_DISCONNECT   0x4001000CL
33 #define RNDIS_STATUS_LINK_SPEED_CHANGE  0x40010013L
34 #define RNDIS_STATUS_NETWORK_CHANGE     0x40010018L
35 #define RNDIS_STATUS_TASK_OFFLOAD_CURRENT_CONFIG        0x40020006L
36 #define RNDIS_STATUS_BUFFER_OVERFLOW    0x80000005L
37 #define RNDIS_STATUS_FAILURE            0xC0000001L
38 #define RNDIS_STATUS_NOT_SUPPORTED      0xC00000BBL
39 #define RNDIS_STATUS_RESOURCES          0xC000009AL
40 #define RNDIS_STATUS_INVALID_DATA       0xC0010015L
41
42 #define OID_GEN_SUPPORTED_LIST          0x00010101
43 #define OID_GEN_HARDWARE_STATUS         0x00010102
44 #define OID_GEN_MEDIA_SUPPORTED         0x00010103
45 #define OID_GEN_MEDIA_IN_USE            0x00010104
46 #define OID_GEN_MAXIMUM_LOOKAHEAD       0x00010105
47 #define OID_GEN_MAXIMUM_FRAME_SIZE      0x00010106
48 #define OID_GEN_LINK_SPEED              0x00010107
49 #define OID_GEN_TRANSMIT_BUFFER_SPACE   0x00010108
50 #define OID_GEN_RECEIVE_BUFFER_SPACE    0x00010109
51 #define OID_GEN_TRANSMIT_BLOCK_SIZE     0x0001010A
52 #define OID_GEN_RECEIVE_BLOCK_SIZE      0x0001010B
53 #define OID_GEN_VENDOR_ID               0x0001010C
54 #define OID_GEN_VENDOR_DESCRIPTION      0x0001010D
55 #define OID_GEN_CURRENT_PACKET_FILTER   0x0001010E
56 #define OID_GEN_CURRENT_LOOKAHEAD       0x0001010F
57 #define OID_GEN_DRIVER_VERSION          0x00010110
58 #define OID_GEN_MAXIMUM_TOTAL_SIZE      0x00010111
59 #define OID_GEN_PROTOCOL_OPTIONS        0x00010112
60 #define OID_GEN_MAC_OPTIONS             0x00010113
61 #define OID_GEN_MEDIA_CONNECT_STATUS    0x00010114
62 #define OID_GEN_MAXIMUM_SEND_PACKETS    0x00010115
63 #define OID_GEN_VENDOR_DRIVER_VERSION   0x00010116
64 #define OID_GEN_SUPPORTED_GUIDS         0x00010117
65 #define OID_GEN_NETWORK_LAYER_ADDRESSES 0x00010118
66 #define OID_GEN_TRANSPORT_HEADER_OFFSET 0x00010119
67 #define OID_GEN_RECEIVE_SCALE_CAPABILITIES      0x00010203
68 #define OID_GEN_RECEIVE_SCALE_PARAMETERS        0x00010204
69 #define OID_GEN_MACHINE_NAME            0x0001021A
70 #define OID_GEN_RNDIS_CONFIG_PARAMETER  0x0001021B
71 #define OID_GEN_VLAN_ID                 0x0001021C
72
73 #define OID_802_3_PERMANENT_ADDRESS     0x01010101
74 #define OID_802_3_CURRENT_ADDRESS       0x01010102
75 #define OID_802_3_MULTICAST_LIST        0x01010103
76 #define OID_802_3_MAXIMUM_LIST_SIZE     0x01010104
77 #define OID_802_3_MAC_OPTIONS           0x01010105
78 #define OID_802_3_RCV_ERROR_ALIGNMENT   0x01020101
79 #define OID_802_3_XMIT_ONE_COLLISION    0x01020102
80 #define OID_802_3_XMIT_MORE_COLLISIONS  0x01020103
81 #define OID_802_3_XMIT_DEFERRED         0x01020201
82 #define OID_802_3_XMIT_MAX_COLLISIONS   0x01020202
83 #define OID_802_3_RCV_OVERRUN           0x01020203
84 #define OID_802_3_XMIT_UNDERRUN         0x01020204
85 #define OID_802_3_XMIT_HEARTBEAT_FAILURE        0x01020205
86 #define OID_802_3_XMIT_TIMES_CRS_LOST   0x01020206
87 #define OID_802_3_XMIT_LATE_COLLISIONS  0x01020207
88
89 #define OID_TCP_OFFLOAD_PARAMETERS      0xFC01020C
90 #define OID_TCP_OFFLOAD_HARDWARE_CAPABILITIES   0xFC01020D
91
92 #define RNDIS_MEDIUM_802_3              0x00000000
93
94 /* Device flags */
95 #define RNDIS_DF_CONNECTIONLESS         0x00000001
96 #define RNDIS_DF_CONNECTION_ORIENTED    0x00000002
97
98 /*
99  * Common RNDIS message header.
100  */
101 struct rndis_msghdr {
102         uint32_t rm_type;
103         uint32_t rm_len;
104 };
105
106 /*
107  * RNDIS data message
108  */
109 #define REMOTE_NDIS_PACKET_MSG          0x00000001
110
111 struct rndis_packet_msg {
112         uint32_t rm_type;
113         uint32_t rm_len;
114         uint32_t rm_dataoffset;
115         uint32_t rm_datalen;
116         uint32_t rm_oobdataoffset;
117         uint32_t rm_oobdatalen;
118         uint32_t rm_oobdataelements;
119         uint32_t rm_pktinfooffset;
120         uint32_t rm_pktinfolen;
121         uint32_t rm_vchandle;
122         uint32_t rm_reserved;
123 };
124
125 /*
126  * Minimum value for rm_dataoffset, rm_oobdataoffset, and
127  * rm_pktinfooffset.
128  */
129 #define RNDIS_PACKET_MSG_OFFSET_MIN             \
130         (sizeof(struct rndis_packet_msg) -      \
131          __offsetof(struct rndis_packet_msg, rm_dataoffset))
132
133 /* Offset from the beginning of rndis_packet_msg. */
134 #define RNDIS_PACKET_MSG_OFFSET_ABS(ofs)        \
135         ((ofs) + __offsetof(struct rndis_packet_msg, rm_dataoffset))
136
137 #define RNDIS_PACKET_MSG_OFFSET_ALIGN           4
138 #define RNDIS_PACKET_MSG_OFFSET_ALIGNMASK       \
139         (RNDIS_PACKET_MSG_OFFSET_ALIGN - 1)
140
141 /* Per-packet-info for RNDIS data message */
142 struct rndis_pktinfo {
143         uint32_t rm_size;
144         uint32_t rm_type:31;            /* NDIS_PKTINFO_TYPE_ */
145         uint32_t rm_internal:1;         /* Indicate if internal type */
146         uint32_t rm_pktinfooffset;
147         uint8_t rm_data[];
148 };
149
150 #define RNDIS_PKTINFO_OFFSET            \
151         __offsetof(struct rndis_pktinfo, rm_data[0])
152 #define RNDIS_PKTINFO_SIZE_ALIGN        4
153 #define RNDIS_PKTINFO_SIZE_ALIGNMASK    (RNDIS_PKTINFO_SIZE_ALIGN - 1)
154
155 #define NDIS_PKTINFO_TYPE_CSUM          0
156 #define NDIS_PKTINFO_TYPE_IPSEC         1
157 #define NDIS_PKTINFO_TYPE_LSO           2
158 #define NDIS_PKTINFO_TYPE_CLASSIFY      3
159 /* reserved 4 */
160 #define NDIS_PKTINFO_TYPE_SGLIST        5
161 #define NDIS_PKTINFO_TYPE_VLAN          6
162 #define NDIS_PKTINFO_TYPE_ORIG          7
163 #define NDIS_PKTINFO_TYPE_PKT_CANCELID  8
164 #define NDIS_PKTINFO_TYPE_ORIG_NBLIST   9
165 #define NDIS_PKTINFO_TYPE_CACHE_NBLIST  10
166 #define NDIS_PKTINFO_TYPE_PKT_PAD       11
167
168 /* Per-packet-info internal type */
169 #define NDIS_PKTINFO_IT_PKTINFO_ID      1
170 /* Add more internal type here */
171
172 /*
173  * RNDIS control messages
174  */
175
176 /*
177  * Common header for RNDIS completion messages.
178  *
179  * NOTE: It does not apply to REMOTE_NDIS_RESET_CMPLT.
180  */
181 struct rndis_comp_hdr {
182         uint32_t rm_type;
183         uint32_t rm_len;
184         uint32_t rm_rid;
185         uint32_t rm_status;
186 };
187
188 /* Initialize the device. */
189 #define REMOTE_NDIS_INITIALIZE_MSG      0x00000002
190 #define REMOTE_NDIS_INITIALIZE_CMPLT    0x80000002
191
192 struct rndis_init_req {
193         uint32_t rm_type;
194         uint32_t rm_len;
195         uint32_t rm_rid;
196         uint32_t rm_ver_major;
197         uint32_t rm_ver_minor;
198         uint32_t rm_max_xfersz;
199 };
200
201 struct rndis_init_comp {
202         uint32_t rm_type;
203         uint32_t rm_len;
204         uint32_t rm_rid;
205         uint32_t rm_status;
206         uint32_t rm_ver_major;
207         uint32_t rm_ver_minor;
208         uint32_t rm_devflags;
209         uint32_t rm_medium;
210         uint32_t rm_pktmaxcnt;
211         uint32_t rm_pktmaxsz;
212         uint32_t rm_align;
213         uint32_t rm_aflistoffset;
214         uint32_t rm_aflistsz;
215 };
216
217 #define RNDIS_INIT_COMP_SIZE_MIN        \
218         __offsetof(struct rndis_init_comp, rm_aflistsz)
219
220 /* Halt the device.  No response sent. */
221 #define REMOTE_NDIS_HALT_MSG            0x00000003
222
223 struct rndis_halt_req {
224         uint32_t rm_type;
225         uint32_t rm_len;
226         uint32_t rm_rid;
227 };
228
229 /* Send a query object. */
230 #define REMOTE_NDIS_QUERY_MSG           0x00000004
231 #define REMOTE_NDIS_QUERY_CMPLT         0x80000004
232
233 struct rndis_query_req {
234         uint32_t rm_type;
235         uint32_t rm_len;
236         uint32_t rm_rid;
237         uint32_t rm_oid;
238         uint32_t rm_infobuflen;
239         uint32_t rm_infobufoffset;
240         uint32_t rm_devicevchdl;
241 };
242
243 #define RNDIS_QUERY_REQ_INFOBUFOFFSET           \
244         (sizeof(struct rndis_query_req) -       \
245          __offsetof(struct rndis_query_req, rm_rid))
246
247 struct rndis_query_comp {
248         uint32_t rm_type;
249         uint32_t rm_len;
250         uint32_t rm_rid;
251         uint32_t rm_status;
252         uint32_t rm_infobuflen;
253         uint32_t rm_infobufoffset;
254 };
255
256 /* infobuf offset from the beginning of rndis_query_comp. */
257 #define RNDIS_QUERY_COMP_INFOBUFOFFSET_ABS(ofs) \
258         ((ofs) + __offsetof(struct rndis_query_req, rm_rid))
259
260 /* Send a set object request. */
261 #define REMOTE_NDIS_SET_MSG             0x00000005
262 #define REMOTE_NDIS_SET_CMPLT           0x80000005
263
264 struct rndis_set_req {
265         uint32_t rm_type;
266         uint32_t rm_len;
267         uint32_t rm_rid;
268         uint32_t rm_oid;
269         uint32_t rm_infobuflen;
270         uint32_t rm_infobufoffset;
271         uint32_t rm_devicevchdl;
272 };
273
274 #define RNDIS_SET_REQ_INFOBUFOFFSET             \
275         (sizeof(struct rndis_set_req) -         \
276          __offsetof(struct rndis_set_req, rm_rid))
277
278 struct rndis_set_comp {
279         uint32_t rm_type;
280         uint32_t rm_len;
281         uint32_t rm_rid;
282         uint32_t rm_status;
283 };
284
285 /*
286  * Parameter used by OID_GEN_RNDIS_CONFIG_PARAMETER.
287  */
288 #define REMOTE_NDIS_SET_PARAM_NUMERIC   0x00000000
289 #define REMOTE_NDIS_SET_PARAM_STRING    0x00000002
290
291 struct rndis_set_parameter {
292         uint32_t rm_nameoffset;
293         uint32_t rm_namelen;
294         uint32_t rm_type;
295         uint32_t rm_valueoffset;
296         uint32_t rm_valuelen;
297 };
298
299 /* Perform a soft reset on the device. */
300 #define REMOTE_NDIS_RESET_MSG           0x00000006
301 #define REMOTE_NDIS_RESET_CMPLT         0x80000006
302
303 struct rndis_reset_req {
304         uint32_t rm_type;
305         uint32_t rm_len;
306         uint32_t rm_rid;
307 };
308
309 struct rndis_reset_comp {
310         uint32_t rm_type;
311         uint32_t rm_len;
312         uint32_t rm_status;
313         uint32_t rm_adrreset;
314 };
315
316 /* 802.3 link-state or undefined message error.  Sent by device. */
317 #define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007
318
319 struct rndis_status_msg {
320         uint32_t rm_type;
321         uint32_t rm_len;
322         uint32_t rm_status;
323         uint32_t rm_stbuflen;
324         uint32_t rm_stbufoffset;
325         /* rndis_diag_info */
326 };
327
328 /* stbuf offset from the beginning of rndis_status_msg. */
329 #define RNDIS_STBUFOFFSET_ABS(ofs)      \
330         ((ofs) + __offsetof(struct rndis_status_msg, rm_status))
331
332 /*
333  * Immediately after rndis_status_msg.rm_stbufoffset, if a control
334  * message is malformatted, or a packet message contains inappropriate
335  * content.
336  */
337 struct rndis_diag_info {
338         uint32_t rm_diagstatus;
339         uint32_t rm_erroffset;
340 };
341
342 /* Keepalive message.  May be sent by device. */
343 #define REMOTE_NDIS_KEEPALIVE_MSG       0x00000008
344 #define REMOTE_NDIS_KEEPALIVE_CMPLT     0x80000008
345
346 struct rndis_keepalive_req {
347         uint32_t rm_type;
348         uint32_t rm_len;
349         uint32_t rm_rid;
350 };
351
352 struct rndis_keepalive_comp {
353         uint32_t rm_type;
354         uint32_t rm_len;
355         uint32_t rm_rid;
356         uint32_t rm_status;
357 };
358
359 /* Packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */
360 #define NDIS_PACKET_TYPE_NONE                   0x00000000
361 #define NDIS_PACKET_TYPE_DIRECTED               0x00000001
362 #define NDIS_PACKET_TYPE_MULTICAST              0x00000002
363 #define NDIS_PACKET_TYPE_ALL_MULTICAST          0x00000004
364 #define NDIS_PACKET_TYPE_BROADCAST              0x00000008
365 #define NDIS_PACKET_TYPE_SOURCE_ROUTING         0x00000010
366 #define NDIS_PACKET_TYPE_PROMISCUOUS            0x00000020
367 #define NDIS_PACKET_TYPE_SMT                    0x00000040
368 #define NDIS_PACKET_TYPE_ALL_LOCAL              0x00000080
369 #define NDIS_PACKET_TYPE_GROUP                  0x00001000
370 #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL         0x00002000
371 #define NDIS_PACKET_TYPE_FUNCTIONAL             0x00004000
372 #define NDIS_PACKET_TYPE_MAC_FRAME              0x00008000
373
374 /*
375  * Packet filter description for use with printf(9) %b identifier.
376  */
377 #define NDIS_PACKET_TYPES                               \
378         "\20\1DIRECT\2MULTICAST\3ALLMULTI\4BROADCAST"   \
379         "\5SRCROUTE\6PROMISC\7SMT\10ALLLOCAL"           \
380         "\11GROUP\12ALLFUNC\13FUNC\14MACFRAME"
381
382 /* RNDIS offsets */
383 #define RNDIS_HEADER_OFFSET     ((uint32_t)sizeof(struct rndis_msghdr))
384 #define RNDIS_DATA_OFFSET       \
385     ((uint32_t)(sizeof(struct rndis_packet_msg) - RNDIS_HEADER_OFFSET))
386
387 #endif  /* !_NET_RNDIS_H_ */