967ef2818fa617d4fa5ea43aed91a64e4a514672
[pandora-kernel.git] / drivers / staging / hv / hyperv_net.h
1 /*
2  *
3  * Copyright (c) 2011, Microsoft Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * Authors:
19  *   Haiyang Zhang <haiyangz@microsoft.com>
20  *   Hank Janssen  <hjanssen@microsoft.com>
21  *   K. Y. Srinivasan <kys@microsoft.com>
22  *
23  */
24
25 #ifndef _HYPERV_NET_H
26 #define _HYPERV_NET_H
27
28 #include <linux/list.h>
29 #include "hyperv.h"
30
31 /* Fwd declaration */
32 struct hv_netvsc_packet;
33
34 /* Represent the xfer page packet which contains 1 or more netvsc packet */
35 struct xferpage_packet {
36         struct list_head list_ent;
37
38         /* # of netvsc packets this xfer packet contains */
39         u32 count;
40 };
41
42 /* The number of pages which are enough to cover jumbo frame buffer. */
43 #define NETVSC_PACKET_MAXPAGE           4
44
45 /*
46  * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
47  * within the RNDIS
48  */
49 struct hv_netvsc_packet {
50         /* Bookkeeping stuff */
51         struct list_head list_ent;
52
53         struct hv_device *device;
54         bool is_data_pkt;
55
56         /*
57          * Valid only for receives when we break a xfer page packet
58          * into multiple netvsc packets
59          */
60         struct xferpage_packet *xfer_page_pkt;
61
62         union {
63                 struct {
64                         u64 recv_completion_tid;
65                         void *recv_completion_ctx;
66                         void (*recv_completion)(void *context);
67                 } recv;
68                 struct {
69                         u64 send_completion_tid;
70                         void *send_completion_ctx;
71                         void (*send_completion)(void *context);
72                 } send;
73         } completion;
74
75         /* This points to the memory after page_buf */
76         void *extension;
77
78         u32 total_data_buflen;
79         /* Points to the send/receive buffer where the ethernet frame is */
80         u32 page_buf_cnt;
81         struct hv_page_buffer page_buf[NETVSC_PACKET_MAXPAGE];
82 };
83
84 /* Represents the net vsc driver */
85 struct netvsc_driver {
86         /* Must be the first field */
87         /* Which is a bug FIXME! */
88         struct hv_driver base;
89
90         u32 ring_buf_size;
91         u32 req_ext_size;
92
93         /*
94          * This is set by the caller to allow us to callback when we
95          * receive a packet from the "wire"
96          */
97         int (*recv_cb)(struct hv_device *dev,
98                                  struct hv_netvsc_packet *packet);
99         void (*link_status_change)(struct hv_device *dev, u32 status);
100
101         /* Specific to this driver */
102         int (*send)(struct hv_device *dev, struct hv_netvsc_packet *packet);
103
104 };
105
106 static inline
107 struct netvsc_driver *drv_to_netvscdrv(struct device_driver *d)
108 {
109         struct hv_driver *hvdrv = drv_to_hv_drv(d);
110         return container_of(hvdrv, struct netvsc_driver, base);
111 }
112
113 struct netvsc_device_info {
114         unsigned char mac_adr[6];
115         bool link_state;        /* 0 - link up, 1 - link down */
116 };
117
118 /* Interface */
119 int netvsc_device_add(struct hv_device *device, void *additional_info);
120 int netvsc_device_remove(struct hv_device *device);
121 int netvsc_send(struct hv_device *device,
122                 struct hv_netvsc_packet *packet);
123 void netvsc_linkstatus_callback(struct hv_device *device_obj,
124                                 unsigned int status);
125 int netvsc_initialize(struct hv_driver *drv);
126 int rndis_filter_open(struct hv_device *dev);
127 int rndis_filter_close(struct hv_device *dev);
128 int rndis_filte_device_add(struct hv_device *dev,
129                         void *additional_info);
130 int rndis_filter_device_remove(struct hv_device *dev);
131
132
133
134
135 #define NVSP_INVALID_PROTOCOL_VERSION   ((u32)0xFFFFFFFF)
136
137 #define NVSP_PROTOCOL_VERSION_1         2
138 #define NVSP_MIN_PROTOCOL_VERSION       NVSP_PROTOCOL_VERSION_1
139 #define NVSP_MAX_PROTOCOL_VERSION       NVSP_PROTOCOL_VERSION_1
140
141 enum {
142         NVSP_MSG_TYPE_NONE = 0,
143
144         /* Init Messages */
145         NVSP_MSG_TYPE_INIT                      = 1,
146         NVSP_MSG_TYPE_INIT_COMPLETE             = 2,
147
148         NVSP_VERSION_MSG_START                  = 100,
149
150         /* Version 1 Messages */
151         NVSP_MSG1_TYPE_SEND_NDIS_VER            = NVSP_VERSION_MSG_START,
152
153         NVSP_MSG1_TYPE_SEND_RECV_BUF,
154         NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
155         NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
156
157         NVSP_MSG1_TYPE_SEND_SEND_BUF,
158         NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
159         NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
160
161         NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
162         NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
163
164         /*
165          * This should be set to the number of messages for the version with
166          * the maximum number of messages.
167          */
168         NVSP_NUM_MSG_PER_VERSION                = 9,
169 };
170
171 enum {
172         NVSP_STAT_NONE = 0,
173         NVSP_STAT_SUCCESS,
174         NVSP_STAT_FAIL,
175         NVSP_STAT_PROTOCOL_TOO_NEW,
176         NVSP_STAT_PROTOCOL_TOO_OLD,
177         NVSP_STAT_INVALID_RNDIS_PKT,
178         NVSP_STAT_BUSY,
179         NVSP_STAT_MAX,
180 };
181
182 struct nvsp_message_header {
183         u32 msg_type;
184 };
185
186 /* Init Messages */
187
188 /*
189  * This message is used by the VSC to initialize the channel after the channels
190  * has been opened. This message should never include anything other then
191  * versioning (i.e. this message will be the same for ever).
192  */
193 struct nvsp_message_init {
194         u32 min_protocol_ver;
195         u32 max_protocol_ver;
196 } __packed;
197
198 /*
199  * This message is used by the VSP to complete the initialization of the
200  * channel. This message should never include anything other then versioning
201  * (i.e. this message will be the same for ever).
202  */
203 struct nvsp_message_init_complete {
204         u32 negotiated_protocol_ver;
205         u32 max_mdl_chain_len;
206         u32 status;
207 } __packed;
208
209 union nvsp_message_init_uber {
210         struct nvsp_message_init init;
211         struct nvsp_message_init_complete init_complete;
212 } __packed;
213
214 /* Version 1 Messages */
215
216 /*
217  * This message is used by the VSC to send the NDIS version to the VSP. The VSP
218  * can use this information when handling OIDs sent by the VSC.
219  */
220 struct nvsp_1_message_send_ndis_version {
221         u32 ndis_major_ver;
222         u32 ndis_minor_ver;
223 } __packed;
224
225 /*
226  * This message is used by the VSC to send a receive buffer to the VSP. The VSP
227  * can then use the receive buffer to send data to the VSC.
228  */
229 struct nvsp_1_message_send_receive_buffer {
230         u32 gpadl_handle;
231         u16 id;
232 } __packed;
233
234 struct nvsp_1_receive_buffer_section {
235         u32 offset;
236         u32 sub_alloc_size;
237         u32 num_sub_allocs;
238         u32 end_offset;
239 } __packed;
240
241 /*
242  * This message is used by the VSP to acknowledge a receive buffer send by the
243  * VSC. This message must be sent by the VSP before the VSP uses the receive
244  * buffer.
245  */
246 struct nvsp_1_message_send_receive_buffer_complete {
247         u32 status;
248         u32 num_sections;
249
250         /*
251          * The receive buffer is split into two parts, a large suballocation
252          * section and a small suballocation section. These sections are then
253          * suballocated by a certain size.
254          */
255
256         /*
257          * For example, the following break up of the receive buffer has 6
258          * large suballocations and 10 small suballocations.
259          */
260
261         /*
262          * |            Large Section          |  |   Small Section   |
263          * ------------------------------------------------------------
264          * |     |     |     |     |     |     |  | | | | | | | | | | |
265          * |                                      |
266          *  LargeOffset                            SmallOffset
267          */
268
269         struct nvsp_1_receive_buffer_section sections[1];
270 } __packed;
271
272 /*
273  * This message is sent by the VSC to revoke the receive buffer.  After the VSP
274  * completes this transaction, the vsp should never use the receive buffer
275  * again.
276  */
277 struct nvsp_1_message_revoke_receive_buffer {
278         u16 id;
279 };
280
281 /*
282  * This message is used by the VSC to send a send buffer to the VSP. The VSC
283  * can then use the send buffer to send data to the VSP.
284  */
285 struct nvsp_1_message_send_send_buffer {
286         u32 gpadl_handle;
287         u16 id;
288 } __packed;
289
290 /*
291  * This message is used by the VSP to acknowledge a send buffer sent by the
292  * VSC. This message must be sent by the VSP before the VSP uses the sent
293  * buffer.
294  */
295 struct nvsp_1_message_send_send_buffer_complete {
296         u32 status;
297
298         /*
299          * The VSC gets to choose the size of the send buffer and the VSP gets
300          * to choose the sections size of the buffer.  This was done to enable
301          * dynamic reconfigurations when the cost of GPA-direct buffers
302          * decreases.
303          */
304         u32 section_size;
305 } __packed;
306
307 /*
308  * This message is sent by the VSC to revoke the send buffer.  After the VSP
309  * completes this transaction, the vsp should never use the send buffer again.
310  */
311 struct nvsp_1_message_revoke_send_buffer {
312         u16 id;
313 };
314
315 /*
316  * This message is used by both the VSP and the VSC to send a RNDIS message to
317  * the opposite channel endpoint.
318  */
319 struct nvsp_1_message_send_rndis_packet {
320         /*
321          * This field is specified by RNIDS. They assume there's two different
322          * channels of communication. However, the Network VSP only has one.
323          * Therefore, the channel travels with the RNDIS packet.
324          */
325         u32 channel_type;
326
327         /*
328          * This field is used to send part or all of the data through a send
329          * buffer. This values specifies an index into the send buffer. If the
330          * index is 0xFFFFFFFF, then the send buffer is not being used and all
331          * of the data was sent through other VMBus mechanisms.
332          */
333         u32 send_buf_section_index;
334         u32 send_buf_section_size;
335 } __packed;
336
337 /*
338  * This message is used by both the VSP and the VSC to complete a RNDIS message
339  * to the opposite channel endpoint. At this point, the initiator of this
340  * message cannot use any resources associated with the original RNDIS packet.
341  */
342 struct nvsp_1_message_send_rndis_packet_complete {
343         u32 status;
344 };
345
346 union nvsp_1_message_uber {
347         struct nvsp_1_message_send_ndis_version send_ndis_ver;
348
349         struct nvsp_1_message_send_receive_buffer send_recv_buf;
350         struct nvsp_1_message_send_receive_buffer_complete
351                                                 send_recv_buf_complete;
352         struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
353
354         struct nvsp_1_message_send_send_buffer send_send_buf;
355         struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
356         struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
357
358         struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
359         struct nvsp_1_message_send_rndis_packet_complete
360                                                 send_rndis_pkt_complete;
361 } __packed;
362
363 union nvsp_all_messages {
364         union nvsp_message_init_uber init_msg;
365         union nvsp_1_message_uber v1_msg;
366 } __packed;
367
368 /* ALL Messages */
369 struct nvsp_message {
370         struct nvsp_message_header hdr;
371         union nvsp_all_messages msg;
372 } __packed;
373
374
375
376
377 /* #define NVSC_MIN_PROTOCOL_VERSION            1 */
378 /* #define NVSC_MAX_PROTOCOL_VERSION            1 */
379
380 #define NETVSC_SEND_BUFFER_SIZE                 (64*1024)       /* 64K */
381 #define NETVSC_SEND_BUFFER_ID                   0xface
382
383
384 #define NETVSC_RECEIVE_BUFFER_SIZE              (1024*1024)     /* 1MB */
385
386 #define NETVSC_RECEIVE_BUFFER_ID                0xcafe
387
388 #define NETVSC_RECEIVE_SG_COUNT                 1
389
390 /* Preallocated receive packets */
391 #define NETVSC_RECEIVE_PACKETLIST_COUNT         256
392
393 #define NETVSC_PACKET_SIZE                      2048
394
395 /* Per netvsc channel-specific */
396 struct netvsc_device {
397         struct hv_device *dev;
398
399         atomic_t refcnt;
400         atomic_t num_outstanding_sends;
401         /*
402          * List of free preallocated hv_netvsc_packet to represent receive
403          * packet
404          */
405         struct list_head recv_pkt_list;
406         spinlock_t recv_pkt_list_lock;
407
408         /* Send buffer allocated by us but manages by NetVSP */
409         void *send_buf;
410         u32 send_buf_size;
411         u32 send_buf_gpadl_handle;
412         u32 send_section_size;
413
414         /* Receive buffer allocated by us but manages by NetVSP */
415         void *recv_buf;
416         u32 recv_buf_size;
417         u32 recv_buf_gpadl_handle;
418         u32 recv_section_cnt;
419         struct nvsp_1_receive_buffer_section *recv_section;
420
421         /* Used for NetVSP initialization protocol */
422         struct completion channel_init_wait;
423         struct nvsp_message channel_init_pkt;
424
425         struct nvsp_message revoke_packet;
426         /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
427
428         /* Holds rndis device info */
429         void *extension;
430 };
431
432
433 /*  Status codes */
434
435
436 #ifndef STATUS_SUCCESS
437 #define STATUS_SUCCESS                          (0x00000000L)
438 #endif
439
440 #ifndef STATUS_UNSUCCESSFUL
441 #define STATUS_UNSUCCESSFUL                     (0xC0000001L)
442 #endif
443
444 #ifndef STATUS_PENDING
445 #define STATUS_PENDING                          (0x00000103L)
446 #endif
447
448 #ifndef STATUS_INSUFFICIENT_RESOURCES
449 #define STATUS_INSUFFICIENT_RESOURCES           (0xC000009AL)
450 #endif
451
452 #ifndef STATUS_BUFFER_OVERFLOW
453 #define STATUS_BUFFER_OVERFLOW                  (0x80000005L)
454 #endif
455
456 #ifndef STATUS_NOT_SUPPORTED
457 #define STATUS_NOT_SUPPORTED                    (0xC00000BBL)
458 #endif
459
460 #define RNDIS_STATUS_SUCCESS                    (STATUS_SUCCESS)
461 #define RNDIS_STATUS_PENDING                    (STATUS_PENDING)
462 #define RNDIS_STATUS_NOT_RECOGNIZED             (0x00010001L)
463 #define RNDIS_STATUS_NOT_COPIED                 (0x00010002L)
464 #define RNDIS_STATUS_NOT_ACCEPTED               (0x00010003L)
465 #define RNDIS_STATUS_CALL_ACTIVE                (0x00010007L)
466
467 #define RNDIS_STATUS_ONLINE                     (0x40010003L)
468 #define RNDIS_STATUS_RESET_START                (0x40010004L)
469 #define RNDIS_STATUS_RESET_END                  (0x40010005L)
470 #define RNDIS_STATUS_RING_STATUS                (0x40010006L)
471 #define RNDIS_STATUS_CLOSED                     (0x40010007L)
472 #define RNDIS_STATUS_WAN_LINE_UP                (0x40010008L)
473 #define RNDIS_STATUS_WAN_LINE_DOWN              (0x40010009L)
474 #define RNDIS_STATUS_WAN_FRAGMENT               (0x4001000AL)
475 #define RNDIS_STATUS_MEDIA_CONNECT              (0x4001000BL)
476 #define RNDIS_STATUS_MEDIA_DISCONNECT           (0x4001000CL)
477 #define RNDIS_STATUS_HARDWARE_LINE_UP           (0x4001000DL)
478 #define RNDIS_STATUS_HARDWARE_LINE_DOWN         (0x4001000EL)
479 #define RNDIS_STATUS_INTERFACE_UP               (0x4001000FL)
480 #define RNDIS_STATUS_INTERFACE_DOWN             (0x40010010L)
481 #define RNDIS_STATUS_MEDIA_BUSY                 (0x40010011L)
482 #define RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION  (0x40010012L)
483 #define RNDIS_STATUS_WW_INDICATION              RDIA_SPECIFIC_INDICATION
484 #define RNDIS_STATUS_LINK_SPEED_CHANGE          (0x40010013L)
485
486 #define RNDIS_STATUS_NOT_RESETTABLE             (0x80010001L)
487 #define RNDIS_STATUS_SOFT_ERRORS                (0x80010003L)
488 #define RNDIS_STATUS_HARD_ERRORS                (0x80010004L)
489 #define RNDIS_STATUS_BUFFER_OVERFLOW            (STATUS_BUFFER_OVERFLOW)
490
491 #define RNDIS_STATUS_FAILURE                    (STATUS_UNSUCCESSFUL)
492 #define RNDIS_STATUS_RESOURCES                  (STATUS_INSUFFICIENT_RESOURCES)
493 #define RNDIS_STATUS_CLOSING                    (0xC0010002L)
494 #define RNDIS_STATUS_BAD_VERSION                (0xC0010004L)
495 #define RNDIS_STATUS_BAD_CHARACTERISTICS        (0xC0010005L)
496 #define RNDIS_STATUS_ADAPTER_NOT_FOUND          (0xC0010006L)
497 #define RNDIS_STATUS_OPEN_FAILED                (0xC0010007L)
498 #define RNDIS_STATUS_DEVICE_FAILED              (0xC0010008L)
499 #define RNDIS_STATUS_MULTICAST_FULL             (0xC0010009L)
500 #define RNDIS_STATUS_MULTICAST_EXISTS           (0xC001000AL)
501 #define RNDIS_STATUS_MULTICAST_NOT_FOUND        (0xC001000BL)
502 #define RNDIS_STATUS_REQUEST_ABORTED            (0xC001000CL)
503 #define RNDIS_STATUS_RESET_IN_PROGRESS          (0xC001000DL)
504 #define RNDIS_STATUS_CLOSING_INDICATING         (0xC001000EL)
505 #define RNDIS_STATUS_NOT_SUPPORTED              (STATUS_NOT_SUPPORTED)
506 #define RNDIS_STATUS_INVALID_PACKET             (0xC001000FL)
507 #define RNDIS_STATUS_OPEN_LIST_FULL             (0xC0010010L)
508 #define RNDIS_STATUS_ADAPTER_NOT_READY          (0xC0010011L)
509 #define RNDIS_STATUS_ADAPTER_NOT_OPEN           (0xC0010012L)
510 #define RNDIS_STATUS_NOT_INDICATING             (0xC0010013L)
511 #define RNDIS_STATUS_INVALID_LENGTH             (0xC0010014L)
512 #define RNDIS_STATUS_INVALID_DATA               (0xC0010015L)
513 #define RNDIS_STATUS_BUFFER_TOO_SHORT           (0xC0010016L)
514 #define RNDIS_STATUS_INVALID_OID                (0xC0010017L)
515 #define RNDIS_STATUS_ADAPTER_REMOVED            (0xC0010018L)
516 #define RNDIS_STATUS_UNSUPPORTED_MEDIA          (0xC0010019L)
517 #define RNDIS_STATUS_GROUP_ADDRESS_IN_USE       (0xC001001AL)
518 #define RNDIS_STATUS_FILE_NOT_FOUND             (0xC001001BL)
519 #define RNDIS_STATUS_ERROR_READING_FILE         (0xC001001CL)
520 #define RNDIS_STATUS_ALREADY_MAPPED             (0xC001001DL)
521 #define RNDIS_STATUS_RESOURCE_CONFLICT          (0xC001001EL)
522 #define RNDIS_STATUS_NO_CABLE                   (0xC001001FL)
523
524 #define RNDIS_STATUS_INVALID_SAP                (0xC0010020L)
525 #define RNDIS_STATUS_SAP_IN_USE                 (0xC0010021L)
526 #define RNDIS_STATUS_INVALID_ADDRESS            (0xC0010022L)
527 #define RNDIS_STATUS_VC_NOT_ACTIVATED           (0xC0010023L)
528 #define RNDIS_STATUS_DEST_OUT_OF_ORDER          (0xC0010024L)
529 #define RNDIS_STATUS_VC_NOT_AVAILABLE           (0xC0010025L)
530 #define RNDIS_STATUS_CELLRATE_NOT_AVAILABLE     (0xC0010026L)
531 #define RNDIS_STATUS_INCOMPATABLE_QOS           (0xC0010027L)
532 #define RNDIS_STATUS_AAL_PARAMS_UNSUPPORTED     (0xC0010028L)
533 #define RNDIS_STATUS_NO_ROUTE_TO_DESTINATION    (0xC0010029L)
534
535 #define RNDIS_STATUS_TOKEN_RING_OPEN_ERROR      (0xC0011000L)
536
537 /* Object Identifiers used by NdisRequest Query/Set Information */
538 /* General Objects */
539 #define RNDIS_OID_GEN_SUPPORTED_LIST            0x00010101
540 #define RNDIS_OID_GEN_HARDWARE_STATUS           0x00010102
541 #define RNDIS_OID_GEN_MEDIA_SUPPORTED           0x00010103
542 #define RNDIS_OID_GEN_MEDIA_IN_USE              0x00010104
543 #define RNDIS_OID_GEN_MAXIMUM_LOOKAHEAD         0x00010105
544 #define RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE        0x00010106
545 #define RNDIS_OID_GEN_LINK_SPEED                0x00010107
546 #define RNDIS_OID_GEN_TRANSMIT_BUFFER_SPACE     0x00010108
547 #define RNDIS_OID_GEN_RECEIVE_BUFFER_SPACE      0x00010109
548 #define RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE       0x0001010A
549 #define RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE        0x0001010B
550 #define RNDIS_OID_GEN_VENDOR_ID                 0x0001010C
551 #define RNDIS_OID_GEN_VENDOR_DESCRIPTION        0x0001010D
552 #define RNDIS_OID_GEN_CURRENT_PACKET_FILTER     0x0001010E
553 #define RNDIS_OID_GEN_CURRENT_LOOKAHEAD         0x0001010F
554 #define RNDIS_OID_GEN_DRIVER_VERSION            0x00010110
555 #define RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE        0x00010111
556 #define RNDIS_OID_GEN_PROTOCOL_OPTIONS          0x00010112
557 #define RNDIS_OID_GEN_MAC_OPTIONS               0x00010113
558 #define RNDIS_OID_GEN_MEDIA_CONNECT_STATUS      0x00010114
559 #define RNDIS_OID_GEN_MAXIMUM_SEND_PACKETS      0x00010115
560 #define RNDIS_OID_GEN_VENDOR_DRIVER_VERSION     0x00010116
561 #define RNDIS_OID_GEN_NETWORK_LAYER_ADDRESSES   0x00010118
562 #define RNDIS_OID_GEN_TRANSPORT_HEADER_OFFSET   0x00010119
563 #define RNDIS_OID_GEN_MACHINE_NAME              0x0001021A
564 #define RNDIS_OID_GEN_RNDIS_CONFIG_PARAMETER    0x0001021B
565
566 #define RNDIS_OID_GEN_XMIT_OK                   0x00020101
567 #define RNDIS_OID_GEN_RCV_OK                    0x00020102
568 #define RNDIS_OID_GEN_XMIT_ERROR                0x00020103
569 #define RNDIS_OID_GEN_RCV_ERROR                 0x00020104
570 #define RNDIS_OID_GEN_RCV_NO_BUFFER             0x00020105
571
572 #define RNDIS_OID_GEN_DIRECTED_BYTES_XMIT       0x00020201
573 #define RNDIS_OID_GEN_DIRECTED_FRAMES_XMIT      0x00020202
574 #define RNDIS_OID_GEN_MULTICAST_BYTES_XMIT      0x00020203
575 #define RNDIS_OID_GEN_MULTICAST_FRAMES_XMIT     0x00020204
576 #define RNDIS_OID_GEN_BROADCAST_BYTES_XMIT      0x00020205
577 #define RNDIS_OID_GEN_BROADCAST_FRAMES_XMIT     0x00020206
578 #define RNDIS_OID_GEN_DIRECTED_BYTES_RCV        0x00020207
579 #define RNDIS_OID_GEN_DIRECTED_FRAMES_RCV       0x00020208
580 #define RNDIS_OID_GEN_MULTICAST_BYTES_RCV       0x00020209
581 #define RNDIS_OID_GEN_MULTICAST_FRAMES_RCV      0x0002020A
582 #define RNDIS_OID_GEN_BROADCAST_BYTES_RCV       0x0002020B
583 #define RNDIS_OID_GEN_BROADCAST_FRAMES_RCV      0x0002020C
584
585 #define RNDIS_OID_GEN_RCV_CRC_ERROR             0x0002020D
586 #define RNDIS_OID_GEN_TRANSMIT_QUEUE_LENGTH     0x0002020E
587
588 #define RNDIS_OID_GEN_GET_TIME_CAPS             0x0002020F
589 #define RNDIS_OID_GEN_GET_NETCARD_TIME          0x00020210
590
591 /* These are connection-oriented general OIDs. */
592 /* These replace the above OIDs for connection-oriented media. */
593 #define RNDIS_OID_GEN_CO_SUPPORTED_LIST         0x00010101
594 #define RNDIS_OID_GEN_CO_HARDWARE_STATUS        0x00010102
595 #define RNDIS_OID_GEN_CO_MEDIA_SUPPORTED        0x00010103
596 #define RNDIS_OID_GEN_CO_MEDIA_IN_USE           0x00010104
597 #define RNDIS_OID_GEN_CO_LINK_SPEED             0x00010105
598 #define RNDIS_OID_GEN_CO_VENDOR_ID              0x00010106
599 #define RNDIS_OID_GEN_CO_VENDOR_DESCRIPTION     0x00010107
600 #define RNDIS_OID_GEN_CO_DRIVER_VERSION         0x00010108
601 #define RNDIS_OID_GEN_CO_PROTOCOL_OPTIONS       0x00010109
602 #define RNDIS_OID_GEN_CO_MAC_OPTIONS            0x0001010A
603 #define RNDIS_OID_GEN_CO_MEDIA_CONNECT_STATUS   0x0001010B
604 #define RNDIS_OID_GEN_CO_VENDOR_DRIVER_VERSION  0x0001010C
605 #define RNDIS_OID_GEN_CO_MINIMUM_LINK_SPEED     0x0001010D
606
607 #define RNDIS_OID_GEN_CO_GET_TIME_CAPS          0x00010201
608 #define RNDIS_OID_GEN_CO_GET_NETCARD_TIME       0x00010202
609
610 /* These are connection-oriented statistics OIDs. */
611 #define RNDIS_OID_GEN_CO_XMIT_PDUS_OK           0x00020101
612 #define RNDIS_OID_GEN_CO_RCV_PDUS_OK            0x00020102
613 #define RNDIS_OID_GEN_CO_XMIT_PDUS_ERROR        0x00020103
614 #define RNDIS_OID_GEN_CO_RCV_PDUS_ERROR         0x00020104
615 #define RNDIS_OID_GEN_CO_RCV_PDUS_NO_BUFFER     0x00020105
616
617
618 #define RNDIS_OID_GEN_CO_RCV_CRC_ERROR          0x00020201
619 #define RNDIS_OID_GEN_CO_TRANSMIT_QUEUE_LENGTH  0x00020202
620 #define RNDIS_OID_GEN_CO_BYTES_XMIT             0x00020203
621 #define RNDIS_OID_GEN_CO_BYTES_RCV              0x00020204
622 #define RNDIS_OID_GEN_CO_BYTES_XMIT_OUTSTANDING 0x00020205
623 #define RNDIS_OID_GEN_CO_NETCARD_LOAD           0x00020206
624
625 /* These are objects for Connection-oriented media call-managers. */
626 #define RNDIS_OID_CO_ADD_PVC                    0xFF000001
627 #define RNDIS_OID_CO_DELETE_PVC                 0xFF000002
628 #define RNDIS_OID_CO_GET_CALL_INFORMATION       0xFF000003
629 #define RNDIS_OID_CO_ADD_ADDRESS                0xFF000004
630 #define RNDIS_OID_CO_DELETE_ADDRESS             0xFF000005
631 #define RNDIS_OID_CO_GET_ADDRESSES              0xFF000006
632 #define RNDIS_OID_CO_ADDRESS_CHANGE             0xFF000007
633 #define RNDIS_OID_CO_SIGNALING_ENABLED          0xFF000008
634 #define RNDIS_OID_CO_SIGNALING_DISABLED         0xFF000009
635
636 /* 802.3 Objects (Ethernet) */
637 #define RNDIS_OID_802_3_PERMANENT_ADDRESS       0x01010101
638 #define RNDIS_OID_802_3_CURRENT_ADDRESS         0x01010102
639 #define RNDIS_OID_802_3_MULTICAST_LIST          0x01010103
640 #define RNDIS_OID_802_3_MAXIMUM_LIST_SIZE       0x01010104
641 #define RNDIS_OID_802_3_MAC_OPTIONS             0x01010105
642
643 #define NDIS_802_3_MAC_OPTION_PRIORITY          0x00000001
644
645 #define RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT     0x01020101
646 #define RNDIS_OID_802_3_XMIT_ONE_COLLISION      0x01020102
647 #define RNDIS_OID_802_3_XMIT_MORE_COLLISIONS    0x01020103
648
649 #define RNDIS_OID_802_3_XMIT_DEFERRED           0x01020201
650 #define RNDIS_OID_802_3_XMIT_MAX_COLLISIONS     0x01020202
651 #define RNDIS_OID_802_3_RCV_OVERRUN             0x01020203
652 #define RNDIS_OID_802_3_XMIT_UNDERRUN           0x01020204
653 #define RNDIS_OID_802_3_XMIT_HEARTBEAT_FAILURE  0x01020205
654 #define RNDIS_OID_802_3_XMIT_TIMES_CRS_LOST     0x01020206
655 #define RNDIS_OID_802_3_XMIT_LATE_COLLISIONS    0x01020207
656
657 /* Remote NDIS message types */
658 #define REMOTE_NDIS_PACKET_MSG                  0x00000001
659 #define REMOTE_NDIS_INITIALIZE_MSG              0x00000002
660 #define REMOTE_NDIS_HALT_MSG                    0x00000003
661 #define REMOTE_NDIS_QUERY_MSG                   0x00000004
662 #define REMOTE_NDIS_SET_MSG                     0x00000005
663 #define REMOTE_NDIS_RESET_MSG                   0x00000006
664 #define REMOTE_NDIS_INDICATE_STATUS_MSG         0x00000007
665 #define REMOTE_NDIS_KEEPALIVE_MSG               0x00000008
666
667 #define REMOTE_CONDIS_MP_CREATE_VC_MSG          0x00008001
668 #define REMOTE_CONDIS_MP_DELETE_VC_MSG          0x00008002
669 #define REMOTE_CONDIS_MP_ACTIVATE_VC_MSG        0x00008005
670 #define REMOTE_CONDIS_MP_DEACTIVATE_VC_MSG      0x00008006
671 #define REMOTE_CONDIS_INDICATE_STATUS_MSG       0x00008007
672
673 /* Remote NDIS message completion types */
674 #define REMOTE_NDIS_INITIALIZE_CMPLT            0x80000002
675 #define REMOTE_NDIS_QUERY_CMPLT                 0x80000004
676 #define REMOTE_NDIS_SET_CMPLT                   0x80000005
677 #define REMOTE_NDIS_RESET_CMPLT                 0x80000006
678 #define REMOTE_NDIS_KEEPALIVE_CMPLT             0x80000008
679
680 #define REMOTE_CONDIS_MP_CREATE_VC_CMPLT        0x80008001
681 #define REMOTE_CONDIS_MP_DELETE_VC_CMPLT        0x80008002
682 #define REMOTE_CONDIS_MP_ACTIVATE_VC_CMPLT      0x80008005
683 #define REMOTE_CONDIS_MP_DEACTIVATE_VC_CMPLT    0x80008006
684
685 /*
686  * Reserved message type for private communication between lower-layer host
687  * driver and remote device, if necessary.
688  */
689 #define REMOTE_NDIS_BUS_MSG                     0xff000001
690
691 /*  Defines for DeviceFlags in struct rndis_initialize_complete */
692 #define RNDIS_DF_CONNECTIONLESS                 0x00000001
693 #define RNDIS_DF_CONNECTION_ORIENTED            0x00000002
694 #define RNDIS_DF_RAW_DATA                       0x00000004
695
696 /*  Remote NDIS medium types. */
697 #define RNDIS_MEDIUM_802_3                      0x00000000
698 #define RNDIS_MEDIUM_802_5                      0x00000001
699 #define RNDIS_MEDIUM_FDDI                               0x00000002
700 #define RNDIS_MEDIUM_WAN                                0x00000003
701 #define RNDIS_MEDIUM_LOCAL_TALK                 0x00000004
702 #define RNDIS_MEDIUM_ARCNET_RAW                 0x00000006
703 #define RNDIS_MEDIUM_ARCNET_878_2                       0x00000007
704 #define RNDIS_MEDIUM_ATM                                0x00000008
705 #define RNDIS_MEDIUM_WIRELESS_WAN                       0x00000009
706 #define RNDIS_MEDIUM_IRDA                               0x0000000a
707 #define RNDIS_MEDIUM_CO_WAN                     0x0000000b
708 /* Not a real medium, defined as an upper-bound */
709 #define RNDIS_MEDIUM_MAX                                0x0000000d
710
711
712 /* Remote NDIS medium connection states. */
713 #define RNDIS_MEDIA_STATE_CONNECTED             0x00000000
714 #define RNDIS_MEDIA_STATE_DISCONNECTED          0x00000001
715
716 /*  Remote NDIS version numbers */
717 #define RNDIS_MAJOR_VERSION                     0x00000001
718 #define RNDIS_MINOR_VERSION                     0x00000000
719
720
721 /* NdisInitialize message */
722 struct rndis_initialize_request {
723         u32 req_id;
724         u32 major_ver;
725         u32 minor_ver;
726         u32 max_xfer_size;
727 };
728
729 /* Response to NdisInitialize */
730 struct rndis_initialize_complete {
731         u32 req_id;
732         u32 status;
733         u32 major_ver;
734         u32 minor_ver;
735         u32 dev_flags;
736         u32 medium;
737         u32 max_pkt_per_msg;
738         u32 max_xfer_size;
739         u32 pkt_alignment_factor;
740         u32 af_list_offset;
741         u32 af_list_size;
742 };
743
744 /* Call manager devices only: Information about an address family */
745 /* supported by the device is appended to the response to NdisInitialize. */
746 struct rndis_co_address_family {
747         u32 address_family;
748         u32 major_ver;
749         u32 minor_ver;
750 };
751
752 /* NdisHalt message */
753 struct rndis_halt_request {
754         u32 req_id;
755 };
756
757 /* NdisQueryRequest message */
758 struct rndis_query_request {
759         u32 req_id;
760         u32 oid;
761         u32 info_buflen;
762         u32 info_buf_offset;
763         u32 dev_vc_handle;
764 };
765
766 /* Response to NdisQueryRequest */
767 struct rndis_query_complete {
768         u32 req_id;
769         u32 status;
770         u32 info_buflen;
771         u32 info_buf_offset;
772 };
773
774 /* NdisSetRequest message */
775 struct rndis_set_request {
776         u32 req_id;
777         u32 oid;
778         u32 info_buflen;
779         u32 info_buf_offset;
780         u32 dev_vc_handle;
781 };
782
783 /* Response to NdisSetRequest */
784 struct rndis_set_complete {
785         u32 req_id;
786         u32 status;
787 };
788
789 /* NdisReset message */
790 struct rndis_reset_request {
791         u32 reserved;
792 };
793
794 /* Response to NdisReset */
795 struct rndis_reset_complete {
796         u32 status;
797         u32 addressing_reset;
798 };
799
800 /* NdisMIndicateStatus message */
801 struct rndis_indicate_status {
802         u32 status;
803         u32 status_buflen;
804         u32 status_buf_offset;
805 };
806
807 /* Diagnostic information passed as the status buffer in */
808 /* struct rndis_indicate_status messages signifying error conditions. */
809 struct rndis_diagnostic_info {
810         u32 diag_status;
811         u32 error_offset;
812 };
813
814 /* NdisKeepAlive message */
815 struct rndis_keepalive_request {
816         u32 req_id;
817 };
818
819 /* Response to NdisKeepAlive */
820 struct rndis_keepalive_complete {
821         u32 req_id;
822         u32 status;
823 };
824
825 /*
826  * Data message. All Offset fields contain byte offsets from the beginning of
827  * struct rndis_packet. All Length fields are in bytes.  VcHandle is set
828  * to 0 for connectionless data, otherwise it contains the VC handle.
829  */
830 struct rndis_packet {
831         u32 data_offset;
832         u32 data_len;
833         u32 oob_data_offset;
834         u32 oob_data_len;
835         u32 num_oob_data_elements;
836         u32 per_pkt_info_offset;
837         u32 per_pkt_info_len;
838         u32 vc_handle;
839         u32 reserved;
840 };
841
842 /* Optional Out of Band data associated with a Data message. */
843 struct rndis_oobd {
844         u32 size;
845         u32 type;
846         u32 class_info_offset;
847 };
848
849 /* Packet extension field contents associated with a Data message. */
850 struct rndis_per_packet_info {
851         u32 size;
852         u32 type;
853         u32 per_pkt_info_offset;
854 };
855
856 /* Format of Information buffer passed in a SetRequest for the OID */
857 /* OID_GEN_RNDIS_CONFIG_PARAMETER. */
858 struct rndis_config_parameter_info {
859         u32 parameter_name_offset;
860         u32 parameter_name_length;
861         u32 parameter_type;
862         u32 parameter_value_offset;
863         u32 parameter_value_length;
864 };
865
866 /* Values for ParameterType in struct rndis_config_parameter_info */
867 #define RNDIS_CONFIG_PARAM_TYPE_INTEGER     0
868 #define RNDIS_CONFIG_PARAM_TYPE_STRING      2
869
870 /* CONDIS Miniport messages for connection oriented devices */
871 /* that do not implement a call manager. */
872
873 /* CoNdisMiniportCreateVc message */
874 struct rcondis_mp_create_vc {
875         u32 req_id;
876         u32 ndis_vc_handle;
877 };
878
879 /* Response to CoNdisMiniportCreateVc */
880 struct rcondis_mp_create_vc_complete {
881         u32 req_id;
882         u32 dev_vc_handle;
883         u32 status;
884 };
885
886 /* CoNdisMiniportDeleteVc message */
887 struct rcondis_mp_delete_vc {
888         u32 req_id;
889         u32 dev_vc_handle;
890 };
891
892 /* Response to CoNdisMiniportDeleteVc */
893 struct rcondis_mp_delete_vc_complete {
894         u32 req_id;
895         u32 status;
896 };
897
898 /* CoNdisMiniportQueryRequest message */
899 struct rcondis_mp_query_request {
900         u32 req_id;
901         u32 request_type;
902         u32 oid;
903         u32 dev_vc_handle;
904         u32 info_buflen;
905         u32 info_buf_offset;
906 };
907
908 /* CoNdisMiniportSetRequest message */
909 struct rcondis_mp_set_request {
910         u32 req_id;
911         u32 request_type;
912         u32 oid;
913         u32 dev_vc_handle;
914         u32 info_buflen;
915         u32 info_buf_offset;
916 };
917
918 /* CoNdisIndicateStatus message */
919 struct rcondis_indicate_status {
920         u32 ndis_vc_handle;
921         u32 status;
922         u32 status_buflen;
923         u32 status_buf_offset;
924 };
925
926 /* CONDIS Call/VC parameters */
927 struct rcondis_specific_parameters {
928         u32 parameter_type;
929         u32 parameter_length;
930         u32 parameter_lffset;
931 };
932
933 struct rcondis_media_parameters {
934         u32 flags;
935         u32 reserved1;
936         u32 reserved2;
937         struct rcondis_specific_parameters media_specific;
938 };
939
940 struct rndis_flowspec {
941         u32 token_rate;
942         u32 token_bucket_size;
943         u32 peak_bandwidth;
944         u32 latency;
945         u32 delay_variation;
946         u32 service_type;
947         u32 max_sdu_size;
948         u32 minimum_policed_size;
949 };
950
951 struct rcondis_call_manager_parameters {
952         struct rndis_flowspec transmit;
953         struct rndis_flowspec receive;
954         struct rcondis_specific_parameters call_mgr_specific;
955 };
956
957 /* CoNdisMiniportActivateVc message */
958 struct rcondis_mp_activate_vc_request {
959         u32 req_id;
960         u32 flags;
961         u32 dev_vc_handle;
962         u32 media_params_offset;
963         u32 media_params_length;
964         u32 call_mgr_params_offset;
965         u32 call_mgr_params_length;
966 };
967
968 /* Response to CoNdisMiniportActivateVc */
969 struct rcondis_mp_activate_vc_complete {
970         u32 req_id;
971         u32 status;
972 };
973
974 /* CoNdisMiniportDeactivateVc message */
975 struct rcondis_mp_deactivate_vc_request {
976         u32 req_id;
977         u32 flags;
978         u32 dev_vc_handle;
979 };
980
981 /* Response to CoNdisMiniportDeactivateVc */
982 struct rcondis_mp_deactivate_vc_complete {
983         u32 req_id;
984         u32 status;
985 };
986
987
988 /* union with all of the RNDIS messages */
989 union rndis_message_container {
990         struct rndis_packet pkt;
991         struct rndis_initialize_request init_req;
992         struct rndis_halt_request halt_req;
993         struct rndis_query_request query_req;
994         struct rndis_set_request set_req;
995         struct rndis_reset_request reset_req;
996         struct rndis_keepalive_request keep_alive_req;
997         struct rndis_indicate_status indicate_status;
998         struct rndis_initialize_complete init_complete;
999         struct rndis_query_complete query_complete;
1000         struct rndis_set_complete set_complete;
1001         struct rndis_reset_complete reset_complete;
1002         struct rndis_keepalive_complete keep_alive_complete;
1003         struct rcondis_mp_create_vc co_miniport_create_vc;
1004         struct rcondis_mp_delete_vc co_miniport_delete_vc;
1005         struct rcondis_indicate_status co_indicate_status;
1006         struct rcondis_mp_activate_vc_request co_miniport_activate_vc;
1007         struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc;
1008         struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete;
1009         struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete;
1010         struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete;
1011         struct rcondis_mp_deactivate_vc_complete
1012                 co_miniport_deactivate_vc_complete;
1013 };
1014
1015 /* Remote NDIS message format */
1016 struct rndis_message {
1017         u32 ndis_msg_type;
1018
1019         /* Total length of this message, from the beginning */
1020         /* of the sruct rndis_message, in bytes. */
1021         u32 msg_len;
1022
1023         /* Actual message */
1024         union rndis_message_container msg;
1025 };
1026
1027 /* Handy macros */
1028
1029 /* get the size of an RNDIS message. Pass in the message type, */
1030 /* struct rndis_set_request, struct rndis_packet for example */
1031 #define RNDIS_MESSAGE_SIZE(msg)                         \
1032         (sizeof(msg) + (sizeof(struct rndis_message) -  \
1033          sizeof(union rndis_message_container)))
1034
1035 /* get pointer to info buffer with message pointer */
1036 #define MESSAGE_TO_INFO_BUFFER(msg)                             \
1037         (((unsigned char *)(msg)) + msg->info_buf_offset)
1038
1039 /* get pointer to status buffer with message pointer */
1040 #define MESSAGE_TO_STATUS_BUFFER(msg)                   \
1041         (((unsigned char *)(msg)) + msg->status_buf_offset)
1042
1043 /* get pointer to OOBD buffer with message pointer */
1044 #define MESSAGE_TO_OOBD_BUFFER(msg)                             \
1045         (((unsigned char *)(msg)) + msg->oob_data_offset)
1046
1047 /* get pointer to data buffer with message pointer */
1048 #define MESSAGE_TO_DATA_BUFFER(msg)                             \
1049         (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
1050
1051 /* get pointer to contained message from NDIS_MESSAGE pointer */
1052 #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg)             \
1053         ((void *) &rndis_msg->msg)
1054
1055 /* get pointer to contained message from NDIS_MESSAGE pointer */
1056 #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
1057         ((void *) rndis_msg)
1058
1059
1060 #define __struct_bcount(x)
1061
1062
1063
1064 #define RNDIS_HEADER_SIZE       (sizeof(struct rndis_message) - \
1065                                  sizeof(union rndis_message_container))
1066
1067 #define NDIS_PACKET_TYPE_DIRECTED       0x00000001
1068 #define NDIS_PACKET_TYPE_MULTICAST      0x00000002
1069 #define NDIS_PACKET_TYPE_ALL_MULTICAST  0x00000004
1070 #define NDIS_PACKET_TYPE_BROADCAST      0x00000008
1071 #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
1072 #define NDIS_PACKET_TYPE_PROMISCUOUS    0x00000020
1073 #define NDIS_PACKET_TYPE_SMT            0x00000040
1074 #define NDIS_PACKET_TYPE_ALL_LOCAL      0x00000080
1075 #define NDIS_PACKET_TYPE_GROUP          0x00000100
1076 #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
1077 #define NDIS_PACKET_TYPE_FUNCTIONAL     0x00000400
1078 #define NDIS_PACKET_TYPE_MAC_FRAME      0x00000800
1079
1080
1081 /* Interface */
1082
1083 extern int rndis_filter_init(struct netvsc_driver *driver);
1084
1085 #endif /* _HYPERV_NET_H */