]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/hyperv/netvsc/hv_net_vsc.h
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / sys / dev / hyperv / netvsc / hv_net_vsc.h
1 /*-
2  * Copyright (c) 2009-2012 Microsoft Corp.
3  * Copyright (c) 2010-2012 Citrix Inc.
4  * Copyright (c) 2012 NetApp Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 /*
30  * HyperV vmbus (virtual machine bus) network VSC (virtual services client)
31  * header file
32  *
33  * (Updated from unencumbered NvspProtocol.h)
34  */
35
36 #ifndef __HV_NET_VSC_H__
37 #define __HV_NET_VSC_H__
38
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/lock.h>
42 #include <sys/sx.h>
43
44 #include <dev/hyperv/include/hyperv.h>
45
46
47 #define NVSP_INVALID_PROTOCOL_VERSION           (0xFFFFFFFF)
48
49 #define NVSP_PROTOCOL_VERSION_1                 2
50 #define NVSP_PROTOCOL_VERSION_2                 0x30002
51 #define NVSP_MIN_PROTOCOL_VERSION               (NVSP_PROTOCOL_VERSION_1)
52 #define NVSP_MAX_PROTOCOL_VERSION               (NVSP_PROTOCOL_VERSION_2)
53
54 #define NVSP_PROTOCOL_VERSION_CURRENT           NVSP_PROTOCOL_VERSION_2
55
56 #define NVSP_OPERATIONAL_STATUS_OK              (0x00000000)
57 #define NVSP_OPERATIONAL_STATUS_DEGRADED        (0x00000001)
58 #define NVSP_OPERATIONAL_STATUS_NONRECOVERABLE  (0x00000002)
59 #define NVSP_OPERATIONAL_STATUS_NO_CONTACT      (0x00000003)
60 #define NVSP_OPERATIONAL_STATUS_LOST_COMMUNICATION (0x00000004)
61
62 /*
63  * Maximun number of transfer pages (packets) the VSP will use on a receive
64  */
65 #define NVSP_MAX_PACKETS_PER_RECEIVE            375
66
67
68 typedef enum nvsp_msg_type_ {
69         nvsp_msg_type_none                      = 0,
70
71         /*
72          * Init Messages
73          */
74         nvsp_msg_type_init                      = 1,
75         nvsp_msg_type_init_complete             = 2,
76
77         nvsp_version_msg_start                  = 100,
78
79         /*
80          * Version 1 Messages
81          */
82         nvsp_msg_1_type_send_ndis_vers          = nvsp_version_msg_start,
83
84         nvsp_msg_1_type_send_rx_buf,
85         nvsp_msg_1_type_send_rx_buf_complete,
86         nvsp_msg_1_type_revoke_rx_buf,
87
88         nvsp_msg_1_type_send_send_buf,
89         nvsp_msg_1_type_send_send_buf_complete,
90         nvsp_msg_1_type_revoke_send_buf,
91
92         nvsp_msg_1_type_send_rndis_pkt,
93         nvsp_msg_1_type_send_rndis_pkt_complete,
94     
95         /*
96          * Version 2 Messages
97          */
98         nvsp_msg_2_type_send_chimney_delegated_buf,
99         nvsp_msg_2_type_send_chimney_delegated_buf_complete,
100         nvsp_msg_2_type_revoke_chimney_delegated_buf,
101
102         nvsp_msg_2_type_resume_chimney_rx_indication,
103
104         nvsp_msg_2_type_terminate_chimney,
105         nvsp_msg_2_type_terminate_chimney_complete,
106
107         nvsp_msg_2_type_indicate_chimney_event,
108
109         nvsp_msg_2_type_send_chimney_packet,
110         nvsp_msg_2_type_send_chimney_packet_complete,
111
112         nvsp_msg_2_type_post_chimney_rx_request,
113         nvsp_msg_2_type_post_chimney_rx_request_complete,
114
115         nvsp_msg_2_type_alloc_rx_buf,
116         nvsp_msg_2_type_alloc_rx_buf_complete,
117
118         nvsp_msg_2_type_free_rx_buf,
119
120         nvsp_msg_2_send_vmq_rndis_pkt,
121         nvsp_msg_2_send_vmq_rndis_pkt_complete,
122
123         nvsp_msg_2_type_send_ndis_config,
124
125         nvsp_msg_2_type_alloc_chimney_handle,
126         nvsp_msg_2_type_alloc_chimney_handle_complete,
127 } nvsp_msg_type;
128
129 typedef enum nvsp_status_ {
130         nvsp_status_none = 0,
131         nvsp_status_success,
132         nvsp_status_failure,
133         /* Deprecated */
134         nvsp_status_prot_vers_range_too_new,
135         /* Deprecated */
136         nvsp_status_prot_vers_range_too_old,
137         nvsp_status_invalid_rndis_pkt,
138         nvsp_status_busy,
139         nvsp_status_max,
140 } nvsp_status;
141
142 typedef struct nvsp_msg_hdr_ {
143         uint32_t                                msg_type;
144 } __packed nvsp_msg_hdr;
145
146 /*
147  * Init Messages
148  */
149
150 /*
151  * This message is used by the VSC to initialize the channel
152  * after the channels has been opened. This message should 
153  * never include anything other then versioning (i.e. this
154  * message will be the same for ever).
155  *
156  * Forever is a long time.  The values have been redefined
157  * in Win7 to indicate major and minor protocol version
158  * number.
159  */
160 typedef struct nvsp_msg_init_ {
161         union {
162                 struct {
163                         uint16_t                minor_protocol_version;
164                         uint16_t                major_protocol_version;
165                 } s;
166                 /* Formerly min_protocol_version */
167                 uint32_t                        protocol_version;
168         } p1;
169         /* Formerly max_protocol_version */
170         uint32_t                                protocol_version_2;
171 } __packed nvsp_msg_init;
172
173 /*
174  * This message is used by the VSP to complete the initialization
175  * of the channel. This message should never include anything other 
176  * then versioning (i.e. this message will be the same forever).
177  */
178 typedef struct nvsp_msg_init_complete_ {
179         /* Deprecated */
180         uint32_t                                negotiated_prot_vers;
181         uint32_t                                max_mdl_chain_len;
182         uint32_t                                status;
183 } __packed nvsp_msg_init_complete;
184
185 typedef union nvsp_msg_init_uber_ {
186         nvsp_msg_init                           init;
187         nvsp_msg_init_complete                  init_compl;
188 } __packed nvsp_msg_init_uber;
189
190 /*
191  * Version 1 Messages
192  */
193
194 /*
195  * This message is used by the VSC to send the NDIS version
196  * to the VSP.  The VSP can use this information when handling
197  * OIDs sent by the VSC.
198  */
199 typedef struct nvsp_1_msg_send_ndis_version_ {
200         uint32_t                                ndis_major_vers;
201         /* Deprecated */
202         uint32_t                                ndis_minor_vers;
203 } __packed nvsp_1_msg_send_ndis_version;
204
205 /*
206  * This message is used by the VSC to send a receive buffer
207  * to the VSP. The VSP can then use the receive buffer to
208  * send data to the VSC.
209  */
210 typedef struct nvsp_1_msg_send_rx_buf_ {
211         uint32_t                                gpadl_handle;
212         uint16_t                                id;
213 } __packed nvsp_1_msg_send_rx_buf;
214
215 typedef struct nvsp_1_rx_buf_section_ {
216         uint32_t                                offset;
217         uint32_t                                sub_allocation_size;
218         uint32_t                                num_sub_allocations;
219         uint32_t                                end_offset;
220 } __packed nvsp_1_rx_buf_section;
221
222 /*
223  * This message is used by the VSP to acknowledge a receive 
224  * buffer send by the VSC.  This message must be sent by the 
225  * VSP before the VSP uses the receive buffer.
226  */
227 typedef struct nvsp_1_msg_send_rx_buf_complete_ {
228         uint32_t                                status;
229         uint32_t                                num_sections;
230
231         /*
232          * The receive buffer is split into two parts, a large
233          * suballocation section and a small suballocation
234          * section. These sections are then suballocated by a 
235          * certain size.
236          *
237          * For example, the following break up of the receive
238          * buffer has 6 large suballocations and 10 small
239          * suballocations.
240          *
241          * |            Large Section          |  |   Small Section   |
242          * ------------------------------------------------------------
243          * |     |     |     |     |     |     |  | | | | | | | | | | |
244          * |                                      |  
245          * LargeOffset                            SmallOffset
246          */
247         nvsp_1_rx_buf_section                   sections[1];
248
249 } __packed nvsp_1_msg_send_rx_buf_complete;
250
251 /*
252  * This message is sent by the VSC to revoke the receive buffer.
253  * After the VSP completes this transaction, the VSP should never
254  * use the receive buffer again.
255  */
256 typedef struct nvsp_1_msg_revoke_rx_buf_ {
257         uint16_t                                id;
258 } __packed nvsp_1_msg_revoke_rx_buf;
259
260 /*
261  * This message is used by the VSC to send a send buffer
262  * to the VSP. The VSC can then use the send buffer to
263  * send data to the VSP.
264  */
265 typedef struct nvsp_1_msg_send_send_buf_ {
266         uint32_t                                gpadl_handle;
267         uint16_t                                id;
268 } __packed nvsp_1_msg_send_send_buf;
269
270 /*
271  * This message is used by the VSP to acknowledge a send 
272  * buffer sent by the VSC. This message must be sent by the 
273  * VSP before the VSP uses the sent buffer.
274  */
275 typedef struct nvsp_1_msg_send_send_buf_complete_ {
276         uint32_t                                status;
277
278         /*
279          * The VSC gets to choose the size of the send buffer and
280          * the VSP gets to choose the sections size of the buffer.
281          * This was done to enable dynamic reconfigurations when
282          * the cost of GPA-direct buffers decreases.
283          */
284         uint32_t                                section_size;
285 } __packed nvsp_1_msg_send_send_buf_complete;
286
287 /*
288  * This message is sent by the VSC to revoke the send buffer.
289  * After the VSP completes this transaction, the vsp should never
290  * use the send buffer again.
291  */
292 typedef struct nvsp_1_msg_revoke_send_buf_ {
293         uint16_t                                id;
294 } __packed nvsp_1_msg_revoke_send_buf;
295
296 /*
297  * This message is used by both the VSP and the VSC to send
298  * an RNDIS message to the opposite channel endpoint.
299  */
300 typedef struct nvsp_1_msg_send_rndis_pkt_ {
301         /*
302          * This field is specified by RNIDS.  They assume there's
303          * two different channels of communication. However, 
304          * the Network VSP only has one.  Therefore, the channel
305          * travels with the RNDIS packet.
306          */
307         uint32_t                                chan_type;
308
309         /*
310          * This field is used to send part or all of the data
311          * through a send buffer. This values specifies an 
312          * index into the send buffer.  If the index is 
313          * 0xFFFFFFFF, then the send buffer is not being used
314          * and all of the data was sent through other VMBus
315          * mechanisms.
316          */
317         uint32_t                                send_buf_section_idx;
318         uint32_t                                send_buf_section_size;
319 } __packed nvsp_1_msg_send_rndis_pkt;
320
321 /*
322  * This message is used by both the VSP and the VSC to complete
323  * a RNDIS message to the opposite channel endpoint.  At this
324  * point, the initiator of this message cannot use any resources
325  * associated with the original RNDIS packet.
326  */
327 typedef struct nvsp_1_msg_send_rndis_pkt_complete_ {
328         uint32_t                                status;
329 } __packed nvsp_1_msg_send_rndis_pkt_complete;
330
331
332 /*
333  * Version 2 Messages
334  */
335
336 /*
337  * This message is used by the VSC to send the NDIS version
338  * to the VSP.  The VSP can use this information when handling
339  * OIDs sent by the VSC.
340  */
341 typedef struct nvsp_2_netvsc_capabilities_ {
342         union {
343                 uint64_t                        as_uint64;
344                 struct {
345                         uint64_t                vmq           : 1;
346                         uint64_t                chimney       : 1;
347                         uint64_t                sriov         : 1;
348                         uint64_t                ieee8021q     : 1;
349                         uint64_t                correlationid : 1;
350                         uint64_t                teaming       : 1;
351                 } u2;
352         } u1;
353 } __packed nvsp_2_netvsc_capabilities;
354
355 typedef struct nvsp_2_msg_send_ndis_config_ {
356         uint32_t                                mtu;
357         uint32_t                                reserved;
358         nvsp_2_netvsc_capabilities              capabilities;
359 } __packed nvsp_2_msg_send_ndis_config;
360
361 /*
362  * NvspMessage2TypeSendChimneyDelegatedBuffer
363  */
364 typedef struct nvsp_2_msg_send_chimney_buf_
365 {
366         /*
367          * On WIN7 beta, delegated_obj_max_size is defined as a uint32_t
368          * Since WIN7 RC, it was split into two uint16_t.  To have the same
369          * struct layout, delegated_obj_max_size shall be the first field.
370          */
371         uint16_t                                delegated_obj_max_size;
372
373         /*
374          * The revision # of chimney protocol used between NVSC and NVSP.
375          *
376          * This revision is NOT related to the chimney revision between
377          * NDIS protocol and miniport drivers.
378          */
379         uint16_t                                revision;
380
381         uint32_t                                gpadl_handle;
382 } __packed nvsp_2_msg_send_chimney_buf;
383
384
385 /* Unsupported chimney revision 0 (only present in WIN7 beta) */
386 #define NVSP_CHIMNEY_REVISION_0                 0
387
388 /* WIN7 Beta Chimney QFE */
389 #define NVSP_CHIMNEY_REVISION_1                 1
390
391 /* The chimney revision since WIN7 RC */
392 #define NVSP_CHIMNEY_REVISION_2                 2
393
394
395 /*
396  * NvspMessage2TypeSendChimneyDelegatedBufferComplete
397  */
398 typedef struct nvsp_2_msg_send_chimney_buf_complete_ {
399         uint32_t                                status;
400
401         /*
402          * Maximum number outstanding sends and pre-posted receives.
403          *
404          * NVSC should not post more than SendQuota/ReceiveQuota packets.
405          * Otherwise, it can block the non-chimney path for an indefinite
406          * amount of time.
407          * (since chimney sends/receives are affected by the remote peer).
408          *
409          * Note: NVSP enforces the quota restrictions on a per-VMBCHANNEL
410          * basis.  It doesn't enforce the restriction separately for chimney
411          * send/receive.  If NVSC doesn't voluntarily enforce "SendQuota",
412          * it may kill its own network connectivity.
413          */
414         uint32_t                                send_quota;
415         uint32_t                                rx_quota;
416 } __packed nvsp_2_msg_send_chimney_buf_complete;
417
418 /*
419  * NvspMessage2TypeRevokeChimneyDelegatedBuffer
420  */
421 typedef struct nvsp_2_msg_revoke_chimney_buf_ {
422         uint32_t                                gpadl_handle;
423 } __packed nvsp_2_msg_revoke_chimney_buf;
424
425
426 #define NVSP_CHIMNEY_OBJECT_TYPE_NEIGHBOR       0
427 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH4          1
428 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH6          2
429 #define NVSP_CHIMNEY_OBJECT_TYPE_TCP            3
430
431 /*
432  * NvspMessage2TypeAllocateChimneyHandle
433  */
434 typedef struct nvsp_2_msg_alloc_chimney_handle_ {
435         uint64_t                                vsc_context;
436         uint32_t                                object_type;
437 } __packed nvsp_2_msg_alloc_chimney_handle;
438
439 /*
440  * NvspMessage2TypeAllocateChimneyHandleComplete
441  */
442 typedef struct nvsp_2_msg_alloc_chimney_handle_complete_ {
443         uint32_t                                vsp_handle;
444 } __packed nvsp_2_msg_alloc_chimney_handle_complete;
445
446
447 /*
448  * NvspMessage2TypeResumeChimneyRXIndication
449  */
450 typedef struct nvsp_2_msg_resume_chimney_rx_indication {
451         /*
452          * Handle identifying the offloaded connection
453          */
454         uint32_t                                vsp_tcp_handle;
455 } __packed nvsp_2_msg_resume_chimney_rx_indication;
456
457
458 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_FIRST_STAGE      (0x01u)
459 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_RESERVED         (~(0x01u))
460
461 /*
462  * NvspMessage2TypeTerminateChimney
463  */
464 typedef struct nvsp_2_msg_terminate_chimney_ {
465         /*
466         * Handle identifying the offloaded object
467         */
468         uint32_t                                vsp_handle;
469
470         /*
471          * Terminate Offload Flags
472          *     Bit 0:
473          *         When set to 0, terminate the offload at the destination NIC
474          *     Bit 1-31:  Reserved, shall be zero
475          */
476         uint32_t                                flags;
477
478         union {
479                 /*
480                  * This field is valid only when bit 0 of flags is clear.
481                  * It specifies the index into the premapped delegated
482                  * object buffer.  The buffer was sent through the
483                  * NvspMessage2TypeSendChimneyDelegatedBuffer
484                  * message at initialization time.
485                  *
486                  * NVSP will write the delegated state into the delegated
487                  * buffer upon upload completion.
488                  */
489                 uint32_t                        index;
490
491                 /*
492                  * This field is valid only when bit 0 of flags is set.
493                  *
494                  * The seqence number of the most recently accepted RX
495                  * indication when VSC sets its TCP context into
496                  * "terminating" state.
497                  *
498                  * This allows NVSP to determines if there are any in-flight
499                  * RX indications for which the acceptance state is still
500                  * undefined.
501                  */
502                 uint64_t                        last_accepted_rx_seq_no;
503         } f0;
504 } __packed nvsp_2_msg_terminate_chimney;
505
506
507 #define NVSP_TERMINATE_CHIMNEY_COMPLETE_FLAG_DATA_CORRUPTED     0x0000001u
508
509 /*
510  * NvspMessage2TypeTerminateChimneyComplete
511  */
512 typedef struct nvsp_2_msg_terminate_chimney_complete_ {
513         uint64_t                                vsc_context;
514         uint32_t                                flags;
515 } __packed nvsp_2_msg_terminate_chimney_complete;
516
517 /*
518  * NvspMessage2TypeIndicateChimneyEvent
519  */
520 typedef struct nvsp_2_msg_indicate_chimney_event_ {
521         /*
522          * When VscTcpContext is 0, event_type is an NDIS_STATUS event code
523          * Otherwise, EventType is an TCP connection event (defined in
524          * NdisTcpOffloadEventHandler chimney DDK document).
525          */
526         uint32_t                                event_type;
527
528         /*
529          * When VscTcpContext is 0, EventType is an NDIS_STATUS event code
530          * Otherwise, EventType is an TCP connection event specific information
531          * (defined in NdisTcpOffloadEventHandler chimney DDK document).
532          */
533         uint32_t                                event_specific_info;
534
535         /*
536          * If not 0, the event is per-TCP connection event.  This field
537          * contains the VSC's TCP context.
538          * If 0, the event indication is global.
539          */
540         uint64_t                                vsc_tcp_context;
541 } __packed nvsp_2_msg_indicate_chimney_event;
542
543
544 #define NVSP_1_CHIMNEY_SEND_INVALID_OOB_INDEX       0xffffu
545 #define NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX   0xffffu
546
547 /*
548  * NvspMessage2TypeSendChimneyPacket
549  */
550 typedef struct nvsp_2_msg_send_chimney_pkt_ {
551     /*
552      * Identify the TCP connection for which this chimney send is
553      */
554     uint32_t                                    vsp_tcp_handle;
555
556     /*
557      * This field is used to send part or all of the data
558      * through a send buffer. This values specifies an
559      * index into the send buffer. If the index is
560      * 0xFFFF, then the send buffer is not being used
561      * and all of the data was sent through other VMBus
562      * mechanisms.
563      */
564     uint16_t                                    send_buf_section_index;
565     uint16_t                                    send_buf_section_size;
566
567     /*
568      * OOB Data Index
569      * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
570      * then there is no OOB data.
571      *
572      * This field shall be always 0xFFFFFFFF for now. It is reserved for
573      * the future.
574      */
575     uint16_t                                    oob_data_index;
576
577     /*
578      * DisconnectFlags = 0
579      *      Normal chimney send. See MiniportTcpOffloadSend for details.
580      *
581      * DisconnectFlags = TCP_DISCONNECT_GRACEFUL_CLOSE (0x01)
582      *      Graceful disconnect. See MiniportTcpOffloadDisconnect for details.
583      *
584      * DisconnectFlags = TCP_DISCONNECT_ABORTIVE_CLOSE (0x02)
585      *      Abortive disconnect. See MiniportTcpOffloadDisconnect for details.
586      */
587     uint16_t                                    disconnect_flags;
588
589     uint32_t                                    seq_no;
590 } __packed nvsp_2_msg_send_chimney_pkt;
591
592 /*
593  * NvspMessage2TypeSendChimneyPacketComplete
594  */
595 typedef struct nvsp_2_msg_send_chimney_pkt_complete_ {
596     /*
597      * The NDIS_STATUS for the chimney send
598      */
599     uint32_t                                    status;
600
601     /*
602      * Number of bytes that have been sent to the peer (and ACKed by the peer).
603      */
604     uint32_t                                    bytes_transferred;
605 } __packed nvsp_2_msg_send_chimney_pkt_complete;
606
607
608 #define NVSP_1_CHIMNEY_RECV_FLAG_NO_PUSH        0x0001u
609 #define NVSP_1_CHIMNEY_RECV_INVALID_OOB_INDEX   0xffffu
610
611 /*
612  * NvspMessage2TypePostChimneyRecvRequest
613  */
614 typedef struct nvsp_2_msg_post_chimney_rx_request_ {
615         /*
616          * Identify the TCP connection which this chimney receive request
617          * is for.
618          */
619         uint32_t                                vsp_tcp_handle;
620
621         /*
622          * OOB Data Index
623          * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
624          * then there is no OOB data.
625          *
626          * This field shall be always 0xFFFFFFFF for now. It is reserved for
627          * the future.
628          */
629         uint32_t                                oob_data_index;
630
631         /*
632          * Bit 0
633          *      When it is set, this is a "no-push" receive.
634          *      When it is clear, this is a "push" receive.
635          *
636          * Bit 1-15:  Reserved and shall be zero
637          */
638         uint16_t                                flags;
639
640         /*
641          * For debugging and diagnoses purpose.
642          * The SeqNo is per TCP connection and starts from 0.
643          */
644         uint32_t                                seq_no;
645 } __packed nvsp_2_msg_post_chimney_rx_request;
646
647 /*
648  * NvspMessage2TypePostChimneyRecvRequestComplete
649  */
650 typedef struct nvsp_2_msg_post_chimney_rx_request_complete_ {
651         /*
652          * The NDIS_STATUS for the chimney send
653          */
654         uint32_t                                status;
655
656         /*
657          * Number of bytes that have been sent to the peer (and ACKed by
658          * the peer).
659          */
660         uint32_t                                bytes_xferred;
661 } __packed nvsp_2_msg_post_chimney_rx_request_complete;
662
663 /*
664  * NvspMessage2TypeAllocateReceiveBuffer
665  */
666 typedef struct nvsp_2_msg_alloc_rx_buf_ {
667         /*
668          * Allocation ID to match the allocation request and response
669          */
670         uint32_t                                allocation_id;
671
672         /*
673          * Length of the VM shared memory receive buffer that needs to
674          * be allocated
675          */
676         uint32_t                                length;
677 } __packed nvsp_2_msg_alloc_rx_buf;
678
679 /*
680  * NvspMessage2TypeAllocateReceiveBufferComplete
681  */
682 typedef struct nvsp_2_msg_alloc_rx_buf_complete_ {
683         /*
684          * The NDIS_STATUS code for buffer allocation
685          */
686         uint32_t                                status;
687
688         /*
689          * Allocation ID from NVSP_2_MESSAGE_ALLOCATE_RECEIVE_BUFFER
690          */
691         uint32_t                                allocation_id;
692
693         /*
694          * GPADL handle for the allocated receive buffer
695          */
696         uint32_t                                gpadl_handle;
697
698         /*
699          * Receive buffer ID that is further used in
700          * NvspMessage2SendVmqRndisPacket
701          */
702         uint64_t                                rx_buf_id;
703 } __packed nvsp_2_msg_alloc_rx_buf_complete;
704
705 /*
706  * NvspMessage2TypeFreeReceiveBuffer
707  */
708 typedef struct nvsp_2_msg_free_rx_buf_ {
709         /*
710          * Receive buffer ID previous returned in
711          * NvspMessage2TypeAllocateReceiveBufferComplete message
712          */
713         uint64_t                                rx_buf_id;
714 } __packed nvsp_2_msg_free_rx_buf;
715
716 /*
717  * This structure is used in defining the buffers in
718  * NVSP_2_MESSAGE_SEND_VMQ_RNDIS_PACKET structure
719  */
720 typedef struct nvsp_xfer_page_range_ {
721         /*
722          * Specifies the ID of the receive buffer that has the buffer. This
723          * ID can be the general receive buffer ID specified in
724          * NvspMessage1TypeSendReceiveBuffer or it can be the shared memory
725          * receive buffer ID allocated by the VSC and specified in
726          * NvspMessage2TypeAllocateReceiveBufferComplete message
727          */
728         uint64_t                                xfer_page_set_id;
729
730         /*
731          * Number of bytes
732          */
733         uint32_t                                byte_count;
734
735         /*
736          * Offset in bytes from the beginning of the buffer
737          */
738         uint32_t                                byte_offset;
739 } __packed nvsp_xfer_page_range;
740
741 /*
742  * NvspMessage2SendVmqRndisPacket
743  */
744 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_ {
745         /*
746          * This field is specified by RNIDS. They assume there's
747          * two different channels of communication. However,
748          * the Network VSP only has one. Therefore, the channel
749          * travels with the RNDIS packet. It must be RMC_DATA
750          */
751         uint32_t                                channel_type;
752
753         /*
754          * Only the Range element corresponding to the RNDIS header of
755          * the first RNDIS message in the multiple RNDIS messages sent
756          * in one NVSP message.  Information about the data portions as well
757          * as the subsequent RNDIS messages in the same NVSP message are
758          * embedded in the RNDIS header itself
759          */
760         nvsp_xfer_page_range                    range;
761 } __packed nvsp_2_msg_send_vmq_rndis_pkt;
762
763 /*
764  * This message is used by the VSC to complete
765  * a RNDIS VMQ message to the VSP.  At this point,
766  * the initiator of this message can use any resources
767  * associated with the original RNDIS VMQ packet.
768  */
769 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_complete_
770 {
771         uint32_t                                status;
772 } __packed nvsp_2_msg_send_vmq_rndis_pkt_complete;
773
774
775 typedef union nvsp_1_msg_uber_ {
776         nvsp_1_msg_send_ndis_version            send_ndis_vers;
777
778         nvsp_1_msg_send_rx_buf                  send_rx_buf;
779         nvsp_1_msg_send_rx_buf_complete         send_rx_buf_complete;
780         nvsp_1_msg_revoke_rx_buf                revoke_rx_buf;
781
782         nvsp_1_msg_send_send_buf                send_send_buf;
783         nvsp_1_msg_send_send_buf_complete       send_send_buf_complete;
784         nvsp_1_msg_revoke_send_buf              revoke_send_buf;
785
786         nvsp_1_msg_send_rndis_pkt               send_rndis_pkt;
787         nvsp_1_msg_send_rndis_pkt_complete      send_rndis_pkt_complete;
788 } __packed nvsp_1_msg_uber;
789
790
791 typedef union nvsp_2_msg_uber_ {
792         nvsp_2_msg_send_ndis_config             send_ndis_config;
793
794         nvsp_2_msg_send_chimney_buf             send_chimney_buf;
795         nvsp_2_msg_send_chimney_buf_complete    send_chimney_buf_complete;
796         nvsp_2_msg_revoke_chimney_buf           revoke_chimney_buf;
797
798         nvsp_2_msg_resume_chimney_rx_indication resume_chimney_rx_indication;
799         nvsp_2_msg_terminate_chimney            terminate_chimney;
800         nvsp_2_msg_terminate_chimney_complete   terminate_chimney_complete;
801         nvsp_2_msg_indicate_chimney_event       indicate_chimney_event;
802
803         nvsp_2_msg_send_chimney_pkt             send_chimney_packet;
804         nvsp_2_msg_send_chimney_pkt_complete    send_chimney_packet_complete;
805         nvsp_2_msg_post_chimney_rx_request      post_chimney_rx_request;
806         nvsp_2_msg_post_chimney_rx_request_complete
807                                                post_chimney_rx_request_complete;
808
809         nvsp_2_msg_alloc_rx_buf                 alloc_rx_buffer;
810         nvsp_2_msg_alloc_rx_buf_complete        alloc_rx_buffer_complete;
811         nvsp_2_msg_free_rx_buf                  free_rx_buffer;
812
813         nvsp_2_msg_send_vmq_rndis_pkt           send_vmq_rndis_pkt;
814         nvsp_2_msg_send_vmq_rndis_pkt_complete  send_vmq_rndis_pkt_complete;
815         nvsp_2_msg_alloc_chimney_handle         alloc_chimney_handle;
816         nvsp_2_msg_alloc_chimney_handle_complete alloc_chimney_handle_complete;
817 } __packed nvsp_2_msg_uber;
818
819
820 typedef union nvsp_all_msgs_ {
821         nvsp_msg_init_uber                      init_msgs;
822         nvsp_1_msg_uber                         vers_1_msgs;
823         nvsp_2_msg_uber                         vers_2_msgs;
824 } __packed nvsp_all_msgs;
825
826 /*
827  * ALL Messages
828  */
829 typedef struct nvsp_msg_ {
830         nvsp_msg_hdr                            hdr; 
831         nvsp_all_msgs                           msgs;
832 } __packed nvsp_msg;
833
834
835 /*
836  * The following arguably belongs in a separate header file
837  */
838
839 /*
840  * Defines
841  */
842
843 #define NETVSC_SEND_BUFFER_SIZE                 (64*1024)   /* 64K */
844 #define NETVSC_SEND_BUFFER_ID                   0xface
845
846
847 #define NETVSC_RECEIVE_BUFFER_SIZE              (1024*1024) /* 1MB */
848
849 #define NETVSC_RECEIVE_BUFFER_ID                0xcafe
850
851 #define NETVSC_RECEIVE_SG_COUNT                 1
852
853 /* Preallocated receive packets */
854 #define NETVSC_RECEIVE_PACKETLIST_COUNT         256
855
856 /*
857  * Maximum MTU we permit to be configured for a netvsc interface.
858  * When the code was developed, a max MTU of 12232 was tested and
859  * proven to work.  9K is a reasonable maximum for an Ethernet.
860  */
861 #define NETVSC_MAX_CONFIGURABLE_MTU             (9 * 1024)
862
863 /*
864  * Data types
865  */
866
867 /*
868  * Per netvsc channel-specific
869  */
870 typedef struct netvsc_dev_ {
871         struct hv_device                        *dev;
872         int                                     num_outstanding_sends;
873
874         /* List of free preallocated NETVSC_PACKET to represent RX packet */
875         STAILQ_HEAD(PQ, netvsc_packet_)         myrx_packet_list;
876         struct mtx                              rx_pkt_list_lock;
877
878         /* Send buffer allocated by us but manages by NetVSP */
879         void                                    *send_buf;
880         uint32_t                                send_buf_size;
881         uint32_t                                send_buf_gpadl_handle;
882         uint32_t                                send_section_size;
883
884         /* Receive buffer allocated by us but managed by NetVSP */
885         void                                    *rx_buf;
886         uint32_t                                rx_buf_size;
887         uint32_t                                rx_buf_gpadl_handle;
888         uint32_t                                rx_section_count;
889         nvsp_1_rx_buf_section                   *rx_sections;
890
891         /* Used for NetVSP initialization protocol */
892         struct sema                             channel_init_sema;
893         nvsp_msg                                channel_init_packet;
894
895         nvsp_msg                                revoke_packet;
896         /*uint8_t                               hw_mac_addr[HW_MACADDR_LEN];*/
897
898         /* Holds rndis device info */
899         void                                    *extension;
900
901         hv_bool_uint8_t                         destroy;
902         /* Negotiated NVSP version */
903         uint32_t                                nvsp_version;
904 } netvsc_dev;
905
906
907 typedef void (*pfn_on_send_rx_completion)(void *);
908
909 #define NETVSC_DEVICE_RING_BUFFER_SIZE   (64 * PAGE_SIZE)
910 #define NETVSC_PACKET_MAXPAGE            16
911
912
913 typedef struct xfer_page_packet_ {
914         /*
915          * This needs to be here because the network RX code casts
916          * an instantiation of this structure to a netvsc_packet.
917          */
918         STAILQ_ENTRY(netvsc_packet_) mylist_entry;
919
920         uint32_t count;
921 } xfer_page_packet;
922
923 typedef struct netvsc_packet_ {
924         /*
925          * List used when enqueued on &net_dev->rx_packet_list,
926          * and when enqueued within the netvsc code
927          */
928         STAILQ_ENTRY(netvsc_packet_) mylist_entry;
929         struct hv_device           *device;
930         hv_bool_uint8_t            is_data_pkt;      /* One byte */
931         uint16_t                   vlan_tci;
932         xfer_page_packet           *xfer_page_pkt;
933
934         /* Completion */
935         union {
936                 struct {
937                         uint64_t   rx_completion_tid;
938                         void       *rx_completion_context;
939                         /* This is no longer used */
940                         pfn_on_send_rx_completion   on_rx_completion;
941                 } rx;
942                 struct {
943                         uint64_t    send_completion_tid;
944                         void        *send_completion_context;
945                         /* Still used in netvsc and filter code */
946                         pfn_on_send_rx_completion   on_send_completion;
947                 } send;
948         } compl;
949
950         void            *extension;
951         uint32_t        tot_data_buf_len;
952         uint32_t        page_buf_count;
953         hv_vmbus_page_buffer    page_buffers[NETVSC_PACKET_MAXPAGE];
954 } netvsc_packet;
955
956 typedef struct {
957         uint8_t         mac_addr[6];  /* Assumption unsigned long */
958         hv_bool_uint8_t link_state;
959 } netvsc_device_info;
960
961 /*
962  * Device-specific softc structure
963  */
964 typedef struct hn_softc {
965         struct ifnet    *hn_ifp;
966         struct arpcom   arpcom;
967         device_t        hn_dev;
968         uint8_t         hn_unit;
969         int             hn_carrier;
970         int             hn_if_flags;
971         struct mtx      hn_lock;
972         int             hn_initdone;
973         struct hv_device  *hn_dev_obj;
974         netvsc_dev      *net_dev;
975 } hn_softc_t;
976
977
978 /*
979  * Externs
980  */
981 extern int hv_promisc_mode;
982
983 extern void netvsc_linkstatus_callback(struct hv_device *device_obj,
984                                        uint32_t status);
985 extern int  netvsc_recv(struct hv_device *device_obj, netvsc_packet *packet);
986 extern void netvsc_xmit_completion(void *context);
987
988 extern void hv_nv_on_receive_completion(void *context);
989 extern netvsc_dev *hv_nv_on_device_add(struct hv_device *device, void *additional_info);
990 extern int  hv_nv_on_device_remove(struct hv_device *device,
991                                    boolean_t destroy_channel);
992 extern int  hv_nv_on_send(struct hv_device *device, netvsc_packet *pkt);
993
994 #endif  /* __HV_NET_VSC_H__ */
995