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