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