2 * Copyright (c) 2009-2012 Microsoft Corp.
3 * Copyright (c) 2010-2012 Citrix Inc.
4 * Copyright (c) 2012 NetApp Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
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.
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.
32 * HyperV vmbus (virtual machine bus) network VSC (virtual services client)
35 * (Updated from unencumbered NvspProtocol.h)
38 #ifndef __HV_NET_VSC_H__
39 #define __HV_NET_VSC_H__
41 #include <sys/param.h>
42 #include <sys/kernel.h>
44 #include <sys/malloc.h>
45 #include <sys/queue.h>
46 #include <sys/taskqueue.h>
49 #include <machine/bus.h>
51 #include <sys/bus_dma.h>
53 #include <netinet/in.h>
54 #include <netinet/tcp_lro.h>
57 #include <net/if_media.h>
59 #include <dev/hyperv/include/hyperv.h>
61 #define HN_USE_TXDESC_BUFRING
63 MALLOC_DECLARE(M_NETVSC);
65 #define NVSP_INVALID_PROTOCOL_VERSION (0xFFFFFFFF)
67 #define NVSP_PROTOCOL_VERSION_1 2
68 #define NVSP_PROTOCOL_VERSION_2 0x30002
69 #define NVSP_PROTOCOL_VERSION_4 0x40000
70 #define NVSP_PROTOCOL_VERSION_5 0x50000
71 #define NVSP_MIN_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_1)
72 #define NVSP_MAX_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_2)
74 #define NVSP_PROTOCOL_VERSION_CURRENT NVSP_PROTOCOL_VERSION_2
76 #define VERSION_4_OFFLOAD_SIZE 22
78 #define NVSP_OPERATIONAL_STATUS_OK (0x00000000)
79 #define NVSP_OPERATIONAL_STATUS_DEGRADED (0x00000001)
80 #define NVSP_OPERATIONAL_STATUS_NONRECOVERABLE (0x00000002)
81 #define NVSP_OPERATIONAL_STATUS_NO_CONTACT (0x00000003)
82 #define NVSP_OPERATIONAL_STATUS_LOST_COMMUNICATION (0x00000004)
85 * Maximun number of transfer pages (packets) the VSP will use on a receive
87 #define NVSP_MAX_PACKETS_PER_RECEIVE 375
90 typedef enum nvsp_msg_type_ {
91 nvsp_msg_type_none = 0,
96 nvsp_msg_type_init = 1,
97 nvsp_msg_type_init_complete = 2,
99 nvsp_version_msg_start = 100,
104 nvsp_msg_1_type_send_ndis_vers = nvsp_version_msg_start,
106 nvsp_msg_1_type_send_rx_buf,
107 nvsp_msg_1_type_send_rx_buf_complete,
108 nvsp_msg_1_type_revoke_rx_buf,
110 nvsp_msg_1_type_send_send_buf,
111 nvsp_msg_1_type_send_send_buf_complete,
112 nvsp_msg_1_type_revoke_send_buf,
114 nvsp_msg_1_type_send_rndis_pkt,
115 nvsp_msg_1_type_send_rndis_pkt_complete,
120 nvsp_msg_2_type_send_chimney_delegated_buf,
121 nvsp_msg_2_type_send_chimney_delegated_buf_complete,
122 nvsp_msg_2_type_revoke_chimney_delegated_buf,
124 nvsp_msg_2_type_resume_chimney_rx_indication,
126 nvsp_msg_2_type_terminate_chimney,
127 nvsp_msg_2_type_terminate_chimney_complete,
129 nvsp_msg_2_type_indicate_chimney_event,
131 nvsp_msg_2_type_send_chimney_packet,
132 nvsp_msg_2_type_send_chimney_packet_complete,
134 nvsp_msg_2_type_post_chimney_rx_request,
135 nvsp_msg_2_type_post_chimney_rx_request_complete,
137 nvsp_msg_2_type_alloc_rx_buf,
138 nvsp_msg_2_type_alloc_rx_buf_complete,
140 nvsp_msg_2_type_free_rx_buf,
142 nvsp_msg_2_send_vmq_rndis_pkt,
143 nvsp_msg_2_send_vmq_rndis_pkt_complete,
145 nvsp_msg_2_type_send_ndis_config,
147 nvsp_msg_2_type_alloc_chimney_handle,
148 nvsp_msg_2_type_alloc_chimney_handle_complete,
151 typedef enum nvsp_status_ {
152 nvsp_status_none = 0,
156 nvsp_status_prot_vers_range_too_new,
158 nvsp_status_prot_vers_range_too_old,
159 nvsp_status_invalid_rndis_pkt,
164 typedef struct nvsp_msg_hdr_ {
166 } __packed nvsp_msg_hdr;
173 * This message is used by the VSC to initialize the channel
174 * after the channels has been opened. This message should
175 * never include anything other then versioning (i.e. this
176 * message will be the same for ever).
178 * Forever is a long time. The values have been redefined
179 * in Win7 to indicate major and minor protocol version
182 typedef struct nvsp_msg_init_ {
185 uint16_t minor_protocol_version;
186 uint16_t major_protocol_version;
188 /* Formerly min_protocol_version */
189 uint32_t protocol_version;
191 /* Formerly max_protocol_version */
192 uint32_t protocol_version_2;
193 } __packed nvsp_msg_init;
196 * This message is used by the VSP to complete the initialization
197 * of the channel. This message should never include anything other
198 * then versioning (i.e. this message will be the same forever).
200 typedef struct nvsp_msg_init_complete_ {
202 uint32_t negotiated_prot_vers;
203 uint32_t max_mdl_chain_len;
205 } __packed nvsp_msg_init_complete;
207 typedef union nvsp_msg_init_uber_ {
209 nvsp_msg_init_complete init_compl;
210 } __packed nvsp_msg_init_uber;
217 * This message is used by the VSC to send the NDIS version
218 * to the VSP. The VSP can use this information when handling
219 * OIDs sent by the VSC.
221 typedef struct nvsp_1_msg_send_ndis_version_ {
222 uint32_t ndis_major_vers;
224 uint32_t ndis_minor_vers;
225 } __packed nvsp_1_msg_send_ndis_version;
228 * This message is used by the VSC to send a receive buffer
229 * to the VSP. The VSP can then use the receive buffer to
230 * send data to the VSC.
232 typedef struct nvsp_1_msg_send_rx_buf_ {
233 uint32_t gpadl_handle;
235 } __packed nvsp_1_msg_send_rx_buf;
237 typedef struct nvsp_1_rx_buf_section_ {
239 uint32_t sub_allocation_size;
240 uint32_t num_sub_allocations;
242 } __packed nvsp_1_rx_buf_section;
245 * This message is used by the VSP to acknowledge a receive
246 * buffer send by the VSC. This message must be sent by the
247 * VSP before the VSP uses the receive buffer.
249 typedef struct nvsp_1_msg_send_rx_buf_complete_ {
251 uint32_t num_sections;
254 * The receive buffer is split into two parts, a large
255 * suballocation section and a small suballocation
256 * section. These sections are then suballocated by a
259 * For example, the following break up of the receive
260 * buffer has 6 large suballocations and 10 small
263 * | Large Section | | Small Section |
264 * ------------------------------------------------------------
265 * | | | | | | | | | | | | | | | | | |
267 * LargeOffset SmallOffset
269 nvsp_1_rx_buf_section sections[1];
271 } __packed nvsp_1_msg_send_rx_buf_complete;
274 * This message is sent by the VSC to revoke the receive buffer.
275 * After the VSP completes this transaction, the VSP should never
276 * use the receive buffer again.
278 typedef struct nvsp_1_msg_revoke_rx_buf_ {
280 } __packed nvsp_1_msg_revoke_rx_buf;
283 * This message is used by the VSC to send a send buffer
284 * to the VSP. The VSC can then use the send buffer to
285 * send data to the VSP.
287 typedef struct nvsp_1_msg_send_send_buf_ {
288 uint32_t gpadl_handle;
290 } __packed nvsp_1_msg_send_send_buf;
293 * This message is used by the VSP to acknowledge a send
294 * buffer sent by the VSC. This message must be sent by the
295 * VSP before the VSP uses the sent buffer.
297 typedef struct nvsp_1_msg_send_send_buf_complete_ {
301 * The VSC gets to choose the size of the send buffer and
302 * the VSP gets to choose the sections size of the buffer.
303 * This was done to enable dynamic reconfigurations when
304 * the cost of GPA-direct buffers decreases.
306 uint32_t section_size;
307 } __packed nvsp_1_msg_send_send_buf_complete;
310 * This message is sent by the VSC to revoke the send buffer.
311 * After the VSP completes this transaction, the vsp should never
312 * use the send buffer again.
314 typedef struct nvsp_1_msg_revoke_send_buf_ {
316 } __packed nvsp_1_msg_revoke_send_buf;
319 * This message is used by both the VSP and the VSC to send
320 * an RNDIS message to the opposite channel endpoint.
322 typedef struct nvsp_1_msg_send_rndis_pkt_ {
324 * This field is specified by RNIDS. They assume there's
325 * two different channels of communication. However,
326 * the Network VSP only has one. Therefore, the channel
327 * travels with the RNDIS packet.
332 * This field is used to send part or all of the data
333 * through a send buffer. This values specifies an
334 * index into the send buffer. If the index is
335 * 0xFFFFFFFF, then the send buffer is not being used
336 * and all of the data was sent through other VMBus
339 uint32_t send_buf_section_idx;
340 uint32_t send_buf_section_size;
341 } __packed nvsp_1_msg_send_rndis_pkt;
344 * This message is used by both the VSP and the VSC to complete
345 * a RNDIS message to the opposite channel endpoint. At this
346 * point, the initiator of this message cannot use any resources
347 * associated with the original RNDIS packet.
349 typedef struct nvsp_1_msg_send_rndis_pkt_complete_ {
351 } __packed nvsp_1_msg_send_rndis_pkt_complete;
359 * This message is used by the VSC to send the NDIS version
360 * to the VSP. The VSP can use this information when handling
361 * OIDs sent by the VSC.
363 typedef struct nvsp_2_netvsc_capabilities_ {
368 uint64_t chimney : 1;
370 uint64_t ieee8021q : 1;
371 uint64_t correlationid : 1;
372 uint64_t teaming : 1;
375 } __packed nvsp_2_netvsc_capabilities;
377 typedef struct nvsp_2_msg_send_ndis_config_ {
380 nvsp_2_netvsc_capabilities capabilities;
381 } __packed nvsp_2_msg_send_ndis_config;
384 * NvspMessage2TypeSendChimneyDelegatedBuffer
386 typedef struct nvsp_2_msg_send_chimney_buf_
389 * On WIN7 beta, delegated_obj_max_size is defined as a uint32_t
390 * Since WIN7 RC, it was split into two uint16_t. To have the same
391 * struct layout, delegated_obj_max_size shall be the first field.
393 uint16_t delegated_obj_max_size;
396 * The revision # of chimney protocol used between NVSC and NVSP.
398 * This revision is NOT related to the chimney revision between
399 * NDIS protocol and miniport drivers.
403 uint32_t gpadl_handle;
404 } __packed nvsp_2_msg_send_chimney_buf;
407 /* Unsupported chimney revision 0 (only present in WIN7 beta) */
408 #define NVSP_CHIMNEY_REVISION_0 0
410 /* WIN7 Beta Chimney QFE */
411 #define NVSP_CHIMNEY_REVISION_1 1
413 /* The chimney revision since WIN7 RC */
414 #define NVSP_CHIMNEY_REVISION_2 2
418 * NvspMessage2TypeSendChimneyDelegatedBufferComplete
420 typedef struct nvsp_2_msg_send_chimney_buf_complete_ {
424 * Maximum number outstanding sends and pre-posted receives.
426 * NVSC should not post more than SendQuota/ReceiveQuota packets.
427 * Otherwise, it can block the non-chimney path for an indefinite
429 * (since chimney sends/receives are affected by the remote peer).
431 * Note: NVSP enforces the quota restrictions on a per-VMBCHANNEL
432 * basis. It doesn't enforce the restriction separately for chimney
433 * send/receive. If NVSC doesn't voluntarily enforce "SendQuota",
434 * it may kill its own network connectivity.
438 } __packed nvsp_2_msg_send_chimney_buf_complete;
441 * NvspMessage2TypeRevokeChimneyDelegatedBuffer
443 typedef struct nvsp_2_msg_revoke_chimney_buf_ {
444 uint32_t gpadl_handle;
445 } __packed nvsp_2_msg_revoke_chimney_buf;
448 #define NVSP_CHIMNEY_OBJECT_TYPE_NEIGHBOR 0
449 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH4 1
450 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH6 2
451 #define NVSP_CHIMNEY_OBJECT_TYPE_TCP 3
454 * NvspMessage2TypeAllocateChimneyHandle
456 typedef struct nvsp_2_msg_alloc_chimney_handle_ {
457 uint64_t vsc_context;
458 uint32_t object_type;
459 } __packed nvsp_2_msg_alloc_chimney_handle;
462 * NvspMessage2TypeAllocateChimneyHandleComplete
464 typedef struct nvsp_2_msg_alloc_chimney_handle_complete_ {
466 } __packed nvsp_2_msg_alloc_chimney_handle_complete;
470 * NvspMessage2TypeResumeChimneyRXIndication
472 typedef struct nvsp_2_msg_resume_chimney_rx_indication {
474 * Handle identifying the offloaded connection
476 uint32_t vsp_tcp_handle;
477 } __packed nvsp_2_msg_resume_chimney_rx_indication;
480 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_FIRST_STAGE (0x01u)
481 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_RESERVED (~(0x01u))
484 * NvspMessage2TypeTerminateChimney
486 typedef struct nvsp_2_msg_terminate_chimney_ {
488 * Handle identifying the offloaded object
493 * Terminate Offload Flags
495 * When set to 0, terminate the offload at the destination NIC
496 * Bit 1-31: Reserved, shall be zero
502 * This field is valid only when bit 0 of flags is clear.
503 * It specifies the index into the premapped delegated
504 * object buffer. The buffer was sent through the
505 * NvspMessage2TypeSendChimneyDelegatedBuffer
506 * message at initialization time.
508 * NVSP will write the delegated state into the delegated
509 * buffer upon upload completion.
514 * This field is valid only when bit 0 of flags is set.
516 * The seqence number of the most recently accepted RX
517 * indication when VSC sets its TCP context into
518 * "terminating" state.
520 * This allows NVSP to determines if there are any in-flight
521 * RX indications for which the acceptance state is still
524 uint64_t last_accepted_rx_seq_no;
526 } __packed nvsp_2_msg_terminate_chimney;
529 #define NVSP_TERMINATE_CHIMNEY_COMPLETE_FLAG_DATA_CORRUPTED 0x0000001u
532 * NvspMessage2TypeTerminateChimneyComplete
534 typedef struct nvsp_2_msg_terminate_chimney_complete_ {
535 uint64_t vsc_context;
537 } __packed nvsp_2_msg_terminate_chimney_complete;
540 * NvspMessage2TypeIndicateChimneyEvent
542 typedef struct nvsp_2_msg_indicate_chimney_event_ {
544 * When VscTcpContext is 0, event_type is an NDIS_STATUS event code
545 * Otherwise, EventType is an TCP connection event (defined in
546 * NdisTcpOffloadEventHandler chimney DDK document).
551 * When VscTcpContext is 0, EventType is an NDIS_STATUS event code
552 * Otherwise, EventType is an TCP connection event specific information
553 * (defined in NdisTcpOffloadEventHandler chimney DDK document).
555 uint32_t event_specific_info;
558 * If not 0, the event is per-TCP connection event. This field
559 * contains the VSC's TCP context.
560 * If 0, the event indication is global.
562 uint64_t vsc_tcp_context;
563 } __packed nvsp_2_msg_indicate_chimney_event;
566 #define NVSP_1_CHIMNEY_SEND_INVALID_OOB_INDEX 0xffffu
567 #define NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX 0xffffffff
570 * NvspMessage2TypeSendChimneyPacket
572 typedef struct nvsp_2_msg_send_chimney_pkt_ {
574 * Identify the TCP connection for which this chimney send is
576 uint32_t vsp_tcp_handle;
579 * This field is used to send part or all of the data
580 * through a send buffer. This values specifies an
581 * index into the send buffer. If the index is
582 * 0xFFFF, then the send buffer is not being used
583 * and all of the data was sent through other VMBus
586 uint16_t send_buf_section_index;
587 uint16_t send_buf_section_size;
591 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
592 * then there is no OOB data.
594 * This field shall be always 0xFFFFFFFF for now. It is reserved for
597 uint16_t oob_data_index;
600 * DisconnectFlags = 0
601 * Normal chimney send. See MiniportTcpOffloadSend for details.
603 * DisconnectFlags = TCP_DISCONNECT_GRACEFUL_CLOSE (0x01)
604 * Graceful disconnect. See MiniportTcpOffloadDisconnect for details.
606 * DisconnectFlags = TCP_DISCONNECT_ABORTIVE_CLOSE (0x02)
607 * Abortive disconnect. See MiniportTcpOffloadDisconnect for details.
609 uint16_t disconnect_flags;
612 } __packed nvsp_2_msg_send_chimney_pkt;
615 * NvspMessage2TypeSendChimneyPacketComplete
617 typedef struct nvsp_2_msg_send_chimney_pkt_complete_ {
619 * The NDIS_STATUS for the chimney send
624 * Number of bytes that have been sent to the peer (and ACKed by the peer).
626 uint32_t bytes_transferred;
627 } __packed nvsp_2_msg_send_chimney_pkt_complete;
630 #define NVSP_1_CHIMNEY_RECV_FLAG_NO_PUSH 0x0001u
631 #define NVSP_1_CHIMNEY_RECV_INVALID_OOB_INDEX 0xffffu
634 * NvspMessage2TypePostChimneyRecvRequest
636 typedef struct nvsp_2_msg_post_chimney_rx_request_ {
638 * Identify the TCP connection which this chimney receive request
641 uint32_t vsp_tcp_handle;
645 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
646 * then there is no OOB data.
648 * This field shall be always 0xFFFFFFFF for now. It is reserved for
651 uint32_t oob_data_index;
655 * When it is set, this is a "no-push" receive.
656 * When it is clear, this is a "push" receive.
658 * Bit 1-15: Reserved and shall be zero
663 * For debugging and diagnoses purpose.
664 * The SeqNo is per TCP connection and starts from 0.
667 } __packed nvsp_2_msg_post_chimney_rx_request;
670 * NvspMessage2TypePostChimneyRecvRequestComplete
672 typedef struct nvsp_2_msg_post_chimney_rx_request_complete_ {
674 * The NDIS_STATUS for the chimney send
679 * Number of bytes that have been sent to the peer (and ACKed by
682 uint32_t bytes_xferred;
683 } __packed nvsp_2_msg_post_chimney_rx_request_complete;
686 * NvspMessage2TypeAllocateReceiveBuffer
688 typedef struct nvsp_2_msg_alloc_rx_buf_ {
690 * Allocation ID to match the allocation request and response
692 uint32_t allocation_id;
695 * Length of the VM shared memory receive buffer that needs to
699 } __packed nvsp_2_msg_alloc_rx_buf;
702 * NvspMessage2TypeAllocateReceiveBufferComplete
704 typedef struct nvsp_2_msg_alloc_rx_buf_complete_ {
706 * The NDIS_STATUS code for buffer allocation
711 * Allocation ID from NVSP_2_MESSAGE_ALLOCATE_RECEIVE_BUFFER
713 uint32_t allocation_id;
716 * GPADL handle for the allocated receive buffer
718 uint32_t gpadl_handle;
721 * Receive buffer ID that is further used in
722 * NvspMessage2SendVmqRndisPacket
725 } __packed nvsp_2_msg_alloc_rx_buf_complete;
728 * NvspMessage2TypeFreeReceiveBuffer
730 typedef struct nvsp_2_msg_free_rx_buf_ {
732 * Receive buffer ID previous returned in
733 * NvspMessage2TypeAllocateReceiveBufferComplete message
736 } __packed nvsp_2_msg_free_rx_buf;
739 * This structure is used in defining the buffers in
740 * NVSP_2_MESSAGE_SEND_VMQ_RNDIS_PACKET structure
742 typedef struct nvsp_xfer_page_range_ {
744 * Specifies the ID of the receive buffer that has the buffer. This
745 * ID can be the general receive buffer ID specified in
746 * NvspMessage1TypeSendReceiveBuffer or it can be the shared memory
747 * receive buffer ID allocated by the VSC and specified in
748 * NvspMessage2TypeAllocateReceiveBufferComplete message
750 uint64_t xfer_page_set_id;
758 * Offset in bytes from the beginning of the buffer
760 uint32_t byte_offset;
761 } __packed nvsp_xfer_page_range;
764 * NvspMessage2SendVmqRndisPacket
766 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_ {
768 * This field is specified by RNIDS. They assume there's
769 * two different channels of communication. However,
770 * the Network VSP only has one. Therefore, the channel
771 * travels with the RNDIS packet. It must be RMC_DATA
773 uint32_t channel_type;
776 * Only the Range element corresponding to the RNDIS header of
777 * the first RNDIS message in the multiple RNDIS messages sent
778 * in one NVSP message. Information about the data portions as well
779 * as the subsequent RNDIS messages in the same NVSP message are
780 * embedded in the RNDIS header itself
782 nvsp_xfer_page_range range;
783 } __packed nvsp_2_msg_send_vmq_rndis_pkt;
786 * This message is used by the VSC to complete
787 * a RNDIS VMQ message to the VSP. At this point,
788 * the initiator of this message can use any resources
789 * associated with the original RNDIS VMQ packet.
791 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_complete_
794 } __packed nvsp_2_msg_send_vmq_rndis_pkt_complete;
797 typedef union nvsp_1_msg_uber_ {
798 nvsp_1_msg_send_ndis_version send_ndis_vers;
800 nvsp_1_msg_send_rx_buf send_rx_buf;
801 nvsp_1_msg_send_rx_buf_complete send_rx_buf_complete;
802 nvsp_1_msg_revoke_rx_buf revoke_rx_buf;
804 nvsp_1_msg_send_send_buf send_send_buf;
805 nvsp_1_msg_send_send_buf_complete send_send_buf_complete;
806 nvsp_1_msg_revoke_send_buf revoke_send_buf;
808 nvsp_1_msg_send_rndis_pkt send_rndis_pkt;
809 nvsp_1_msg_send_rndis_pkt_complete send_rndis_pkt_complete;
810 } __packed nvsp_1_msg_uber;
813 typedef union nvsp_2_msg_uber_ {
814 nvsp_2_msg_send_ndis_config send_ndis_config;
816 nvsp_2_msg_send_chimney_buf send_chimney_buf;
817 nvsp_2_msg_send_chimney_buf_complete send_chimney_buf_complete;
818 nvsp_2_msg_revoke_chimney_buf revoke_chimney_buf;
820 nvsp_2_msg_resume_chimney_rx_indication resume_chimney_rx_indication;
821 nvsp_2_msg_terminate_chimney terminate_chimney;
822 nvsp_2_msg_terminate_chimney_complete terminate_chimney_complete;
823 nvsp_2_msg_indicate_chimney_event indicate_chimney_event;
825 nvsp_2_msg_send_chimney_pkt send_chimney_packet;
826 nvsp_2_msg_send_chimney_pkt_complete send_chimney_packet_complete;
827 nvsp_2_msg_post_chimney_rx_request post_chimney_rx_request;
828 nvsp_2_msg_post_chimney_rx_request_complete
829 post_chimney_rx_request_complete;
831 nvsp_2_msg_alloc_rx_buf alloc_rx_buffer;
832 nvsp_2_msg_alloc_rx_buf_complete alloc_rx_buffer_complete;
833 nvsp_2_msg_free_rx_buf free_rx_buffer;
835 nvsp_2_msg_send_vmq_rndis_pkt send_vmq_rndis_pkt;
836 nvsp_2_msg_send_vmq_rndis_pkt_complete send_vmq_rndis_pkt_complete;
837 nvsp_2_msg_alloc_chimney_handle alloc_chimney_handle;
838 nvsp_2_msg_alloc_chimney_handle_complete alloc_chimney_handle_complete;
839 } __packed nvsp_2_msg_uber;
842 typedef union nvsp_all_msgs_ {
843 nvsp_msg_init_uber init_msgs;
844 nvsp_1_msg_uber vers_1_msgs;
845 nvsp_2_msg_uber vers_2_msgs;
846 } __packed nvsp_all_msgs;
851 typedef struct nvsp_msg_ {
858 * The following arguably belongs in a separate header file
865 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
866 #define NETVSC_SEND_BUFFER_ID 0xface
868 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
869 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
871 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
873 #define NETVSC_RECEIVE_SG_COUNT 1
875 /* Preallocated receive packets */
876 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
879 * Maximum MTU we permit to be configured for a netvsc interface.
880 * When the code was developed, a max MTU of 12232 was tested and
881 * proven to work. 9K is a reasonable maximum for an Ethernet.
883 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
885 #define NETVSC_PACKET_SIZE PAGE_SIZE
892 * Per netvsc channel-specific
894 typedef struct netvsc_dev_ {
895 struct hv_device *dev;
896 int num_outstanding_sends;
898 /* Send buffer allocated by us but manages by NetVSP */
900 uint32_t send_buf_size;
901 uint32_t send_buf_gpadl_handle;
902 uint32_t send_section_size;
903 uint32_t send_section_count;
904 unsigned long bitsmap_words;
905 unsigned long *send_section_bitsmap;
907 /* Receive buffer allocated by us but managed by NetVSP */
909 uint32_t rx_buf_size;
910 uint32_t rx_buf_gpadl_handle;
911 uint32_t rx_section_count;
912 nvsp_1_rx_buf_section *rx_sections;
914 /* Used for NetVSP initialization protocol */
915 struct sema channel_init_sema;
916 nvsp_msg channel_init_packet;
918 nvsp_msg revoke_packet;
919 /*uint8_t hw_mac_addr[HW_MACADDR_LEN];*/
921 /* Holds rndis device info */
924 hv_bool_uint8_t destroy;
925 /* Negotiated NVSP version */
926 uint32_t nvsp_version;
928 uint8_t callback_buf[NETVSC_PACKET_SIZE];
932 typedef void (*pfn_on_send_rx_completion)(void *);
934 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
935 #define NETVSC_PACKET_MAXPAGE 32
938 #define NETVSC_VLAN_PRIO_MASK 0xe000
939 #define NETVSC_VLAN_PRIO_SHIFT 13
940 #define NETVSC_VLAN_VID_MASK 0x0fff
947 #define TRANSPORT_TYPE_NOT_IP 0
948 #define TRANSPORT_TYPE_IPV4_TCP ((TYPE_IPV4 << 16) | TYPE_TCP)
949 #define TRANSPORT_TYPE_IPV4_UDP ((TYPE_IPV4 << 16) | TYPE_UDP)
950 #define TRANSPORT_TYPE_IPV6_TCP ((TYPE_IPV6 << 16) | TYPE_TCP)
951 #define TRANSPORT_TYPE_IPV6_UDP ((TYPE_IPV6 << 16) | TYPE_UDP)
954 #define BITS_PER_LONG 64
956 #define BITS_PER_LONG 32
959 typedef struct netvsc_packet_ {
960 struct hv_device *device;
961 hv_bool_uint8_t is_data_pkt; /* One byte */
968 uint64_t rx_completion_tid;
969 void *rx_completion_context;
970 /* This is no longer used */
971 pfn_on_send_rx_completion on_rx_completion;
974 uint64_t send_completion_tid;
975 void *send_completion_context;
976 /* Still used in netvsc and filter code */
977 pfn_on_send_rx_completion on_send_completion;
980 uint32_t send_buf_section_idx;
981 uint32_t send_buf_section_size;
984 uint32_t tot_data_buf_len;
986 uint32_t page_buf_count;
987 hv_vmbus_page_buffer page_buffers[NETVSC_PACKET_MAXPAGE];
991 uint8_t mac_addr[6]; /* Assumption unsigned long */
992 hv_bool_uint8_t link_state;
993 } netvsc_device_info;
995 #ifndef HN_USE_TXDESC_BUFRING
997 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
1003 struct lro_ctrl hn_lro;
1005 /* Trust csum verification on host side */
1006 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
1011 u_long hn_csum_trusted;
1012 u_long hn_lro_tried;
1013 u_long hn_small_pkts;
1014 } __aligned(CACHE_LINE_SIZE);
1016 #define HN_TRUST_HCSUM_IP 0x0001
1017 #define HN_TRUST_HCSUM_TCP 0x0002
1018 #define HN_TRUST_HCSUM_UDP 0x0004
1021 #ifndef HN_USE_TXDESC_BUFRING
1022 struct mtx hn_txlist_spin;
1023 struct hn_txdesc_list hn_txlist;
1025 struct buf_ring *hn_txdesc_br;
1028 int hn_txdesc_avail;
1032 void (*hn_txeof)(struct hn_tx_ring *);
1033 struct taskqueue *hn_tx_taskq;
1034 struct task hn_tx_task;
1035 struct task hn_txeof_task;
1037 struct buf_ring *hn_mbuf_br;
1040 struct mtx hn_tx_lock;
1041 struct hn_softc *hn_sc;
1043 int hn_direct_tx_size;
1044 int hn_tx_chimney_size;
1045 bus_dma_tag_t hn_tx_data_dtag;
1046 uint64_t hn_csum_assist;
1048 u_long hn_no_txdescs;
1049 u_long hn_send_failed;
1050 u_long hn_txdma_failed;
1051 u_long hn_tx_collapsed;
1052 u_long hn_tx_chimney;
1054 /* Rarely used stuffs */
1055 struct hn_txdesc *hn_txdesc;
1056 bus_dma_tag_t hn_tx_rndis_dtag;
1057 struct sysctl_oid *hn_tx_sysctl_tree;
1058 } __aligned(CACHE_LINE_SIZE);
1061 * Device-specific softc structure
1063 typedef struct hn_softc {
1064 struct ifnet *hn_ifp;
1065 struct arpcom arpcom;
1066 struct ifmedia hn_media;
1073 /* See hv_netvsc_drv_freebsd.c for rules on how to use */
1075 struct hv_device *hn_dev_obj;
1076 netvsc_dev *net_dev;
1079 struct hn_rx_ring *hn_rx_ring;
1082 struct hn_tx_ring *hn_tx_ring;
1083 int hn_tx_chimney_max;
1084 struct taskqueue *hn_tx_taskq;
1085 struct sysctl_oid *hn_tx_sysctl_tree;
1091 extern int hv_promisc_mode;
1093 void netvsc_linkstatus_callback(struct hv_device *device_obj, uint32_t status);
1094 void hv_nv_on_receive_completion(struct hv_device *device,
1095 uint64_t tid, uint32_t status);
1096 netvsc_dev *hv_nv_on_device_add(struct hv_device *device,
1097 void *additional_info);
1098 int hv_nv_on_device_remove(struct hv_device *device,
1099 boolean_t destroy_channel);
1100 int hv_nv_on_send(struct hv_device *device, netvsc_packet *pkt);
1101 int hv_nv_get_next_send_section(netvsc_dev *net_dev);
1103 #endif /* __HV_NET_VSC_H__ */