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