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