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 #define RNDIS_OBJECT_TYPE_RSS_CAPABILITIES 0x88
91 #define RNDIS_OBJECT_TYPE_RSS_PARAMETERS 0x89
93 #define RNDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2
94 #define RNDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2
96 struct rndis_obj_header {
102 /* rndis_recv_scale_cap/cap_flag */
103 #define RNDIS_RSS_CAPS_MESSAGE_SIGNALED_INTERRUPTS 0x01000000
104 #define RNDIS_RSS_CAPS_CLASSIFICATION_AT_ISR 0x02000000
105 #define RNDIS_RSS_CAPS_CLASSIFICATION_AT_DPC 0x04000000
106 #define RNDIS_RSS_CAPS_USING_MSI_X 0x08000000
107 #define RNDIS_RSS_CAPS_RSS_AVAILABLE_ON_PORTS 0x10000000
108 #define RNDIS_RSS_CAPS_SUPPORTS_MSI_X 0x20000000
109 #define RNDIS_RSS_CAPS_HASH_TYPE_TCP_IPV4 0x00000100
110 #define RNDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6 0x00000200
111 #define RNDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6_EX 0x00000400
113 /* RNDIS_RECEIVE_SCALE_CAPABILITIES */
114 struct rndis_recv_scale_cap {
115 struct rndis_obj_header hdr;
117 uint32_t num_int_msg;
118 uint32_t num_recv_que;
119 uint16_t num_indirect_tabent;
122 /* rndis_recv_scale_param flags */
123 #define RNDIS_RSS_PARAM_FLAG_BASE_CPU_UNCHANGED 0x0001
124 #define RNDIS_RSS_PARAM_FLAG_HASH_INFO_UNCHANGED 0x0002
125 #define RNDIS_RSS_PARAM_FLAG_ITABLE_UNCHANGED 0x0004
126 #define RNDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED 0x0008
127 #define RNDIS_RSS_PARAM_FLAG_DISABLE_RSS 0x0010
130 #define RNDIS_HASH_FUNC_TOEPLITZ 0x00000001
131 #define RNDIS_HASH_IPV4 0x00000100
132 #define RNDIS_HASH_TCP_IPV4 0x00000200
133 #define RNDIS_HASH_IPV6 0x00000400
134 #define RNDIS_HASH_IPV6_EX 0x00000800
135 #define RNDIS_HASH_TCP_IPV6 0x00001000
136 #define RNDIS_HASH_TCP_IPV6_EX 0x00002000
138 #define RNDIS_RSS_INDIRECTION_TABLE_MAX_SIZE_REVISION_2 (128 * 4)
139 #define RNDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2 40
142 #define HASH_KEYLEN RNDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2
144 /* RNDIS_RECEIVE_SCALE_PARAMETERS */
145 typedef struct rndis_recv_scale_param_ {
146 struct rndis_obj_header hdr;
148 /* Qualifies the rest of the information */
151 /* The base CPU number to do receive processing. not used */
152 uint16_t base_cpu_number;
154 /* This describes the hash function and type being enabled */
157 /* The size of indirection table array */
158 uint16_t indirect_tabsize;
160 /* The offset of the indirection table from the beginning of this
163 uint32_t indirect_taboffset;
165 /* The size of the hash secret key */
166 uint16_t hashkey_size;
168 /* The offset of the secret key from the beginning of this structure */
169 uint32_t hashkey_offset;
171 uint32_t processor_masks_offset;
172 uint32_t num_processor_masks;
173 uint32_t processor_masks_entry_size;
174 } rndis_recv_scale_param;
176 typedef enum nvsp_msg_type_ {
177 nvsp_msg_type_none = 0,
182 nvsp_msg_type_init = 1,
183 nvsp_msg_type_init_complete = 2,
185 nvsp_version_msg_start = 100,
190 nvsp_msg_1_type_send_ndis_vers = nvsp_version_msg_start,
192 nvsp_msg_1_type_send_rx_buf,
193 nvsp_msg_1_type_send_rx_buf_complete,
194 nvsp_msg_1_type_revoke_rx_buf,
196 nvsp_msg_1_type_send_send_buf,
197 nvsp_msg_1_type_send_send_buf_complete,
198 nvsp_msg_1_type_revoke_send_buf,
200 nvsp_msg_1_type_send_rndis_pkt,
201 nvsp_msg_1_type_send_rndis_pkt_complete,
206 nvsp_msg_2_type_send_chimney_delegated_buf,
207 nvsp_msg_2_type_send_chimney_delegated_buf_complete,
208 nvsp_msg_2_type_revoke_chimney_delegated_buf,
210 nvsp_msg_2_type_resume_chimney_rx_indication,
212 nvsp_msg_2_type_terminate_chimney,
213 nvsp_msg_2_type_terminate_chimney_complete,
215 nvsp_msg_2_type_indicate_chimney_event,
217 nvsp_msg_2_type_send_chimney_packet,
218 nvsp_msg_2_type_send_chimney_packet_complete,
220 nvsp_msg_2_type_post_chimney_rx_request,
221 nvsp_msg_2_type_post_chimney_rx_request_complete,
223 nvsp_msg_2_type_alloc_rx_buf,
224 nvsp_msg_2_type_alloc_rx_buf_complete,
226 nvsp_msg_2_type_free_rx_buf,
228 nvsp_msg_2_send_vmq_rndis_pkt,
229 nvsp_msg_2_send_vmq_rndis_pkt_complete,
231 nvsp_msg_2_type_send_ndis_config,
233 nvsp_msg_2_type_alloc_chimney_handle,
234 nvsp_msg_2_type_alloc_chimney_handle_complete,
236 nvsp_msg2_max = nvsp_msg_2_type_alloc_chimney_handle_complete,
241 nvsp_msg4_type_send_vf_association,
242 nvsp_msg4_type_switch_data_path,
243 nvsp_msg4_type_uplink_connect_state_deprecated,
245 nvsp_msg4_max = nvsp_msg4_type_uplink_connect_state_deprecated,
250 nvsp_msg5_type_oid_query_ex,
251 nvsp_msg5_type_oid_query_ex_comp,
252 nvsp_msg5_type_subchannel,
253 nvsp_msg5_type_send_indirection_table,
255 nvsp_msg5_max = nvsp_msg5_type_send_indirection_table,
258 typedef enum nvsp_status_ {
259 nvsp_status_none = 0,
263 nvsp_status_prot_vers_range_too_new,
265 nvsp_status_prot_vers_range_too_old,
266 nvsp_status_invalid_rndis_pkt,
271 typedef struct nvsp_msg_hdr_ {
273 } __packed nvsp_msg_hdr;
280 * This message is used by the VSC to initialize the channel
281 * after the channels has been opened. This message should
282 * never include anything other then versioning (i.e. this
283 * message will be the same for ever).
285 * Forever is a long time. The values have been redefined
286 * in Win7 to indicate major and minor protocol version
289 typedef struct nvsp_msg_init_ {
292 uint16_t minor_protocol_version;
293 uint16_t major_protocol_version;
295 /* Formerly min_protocol_version */
296 uint32_t protocol_version;
298 /* Formerly max_protocol_version */
299 uint32_t protocol_version_2;
300 } __packed nvsp_msg_init;
303 * This message is used by the VSP to complete the initialization
304 * of the channel. This message should never include anything other
305 * then versioning (i.e. this message will be the same forever).
307 typedef struct nvsp_msg_init_complete_ {
309 uint32_t negotiated_prot_vers;
310 uint32_t max_mdl_chain_len;
312 } __packed nvsp_msg_init_complete;
314 typedef union nvsp_msg_init_uber_ {
316 nvsp_msg_init_complete init_compl;
317 } __packed nvsp_msg_init_uber;
324 * This message is used by the VSC to send the NDIS version
325 * to the VSP. The VSP can use this information when handling
326 * OIDs sent by the VSC.
328 typedef struct nvsp_1_msg_send_ndis_version_ {
329 uint32_t ndis_major_vers;
331 uint32_t ndis_minor_vers;
332 } __packed nvsp_1_msg_send_ndis_version;
335 * This message is used by the VSC to send a receive buffer
336 * to the VSP. The VSP can then use the receive buffer to
337 * send data to the VSC.
339 typedef struct nvsp_1_msg_send_rx_buf_ {
340 uint32_t gpadl_handle;
342 } __packed nvsp_1_msg_send_rx_buf;
344 typedef struct nvsp_1_rx_buf_section_ {
346 uint32_t sub_allocation_size;
347 uint32_t num_sub_allocations;
349 } __packed nvsp_1_rx_buf_section;
352 * This message is used by the VSP to acknowledge a receive
353 * buffer send by the VSC. This message must be sent by the
354 * VSP before the VSP uses the receive buffer.
356 typedef struct nvsp_1_msg_send_rx_buf_complete_ {
358 uint32_t num_sections;
361 * The receive buffer is split into two parts, a large
362 * suballocation section and a small suballocation
363 * section. These sections are then suballocated by a
366 * For example, the following break up of the receive
367 * buffer has 6 large suballocations and 10 small
370 * | Large Section | | Small Section |
371 * ------------------------------------------------------------
372 * | | | | | | | | | | | | | | | | | |
374 * LargeOffset SmallOffset
376 nvsp_1_rx_buf_section sections[1];
378 } __packed nvsp_1_msg_send_rx_buf_complete;
381 * This message is sent by the VSC to revoke the receive buffer.
382 * After the VSP completes this transaction, the VSP should never
383 * use the receive buffer again.
385 typedef struct nvsp_1_msg_revoke_rx_buf_ {
387 } __packed nvsp_1_msg_revoke_rx_buf;
390 * This message is used by the VSC to send a send buffer
391 * to the VSP. The VSC can then use the send buffer to
392 * send data to the VSP.
394 typedef struct nvsp_1_msg_send_send_buf_ {
395 uint32_t gpadl_handle;
397 } __packed nvsp_1_msg_send_send_buf;
400 * This message is used by the VSP to acknowledge a send
401 * buffer sent by the VSC. This message must be sent by the
402 * VSP before the VSP uses the sent buffer.
404 typedef struct nvsp_1_msg_send_send_buf_complete_ {
408 * The VSC gets to choose the size of the send buffer and
409 * the VSP gets to choose the sections size of the buffer.
410 * This was done to enable dynamic reconfigurations when
411 * the cost of GPA-direct buffers decreases.
413 uint32_t section_size;
414 } __packed nvsp_1_msg_send_send_buf_complete;
417 * This message is sent by the VSC to revoke the send buffer.
418 * After the VSP completes this transaction, the vsp should never
419 * use the send buffer again.
421 typedef struct nvsp_1_msg_revoke_send_buf_ {
423 } __packed nvsp_1_msg_revoke_send_buf;
426 * This message is used by both the VSP and the VSC to send
427 * an RNDIS message to the opposite channel endpoint.
429 typedef struct nvsp_1_msg_send_rndis_pkt_ {
431 * This field is specified by RNIDS. They assume there's
432 * two different channels of communication. However,
433 * the Network VSP only has one. Therefore, the channel
434 * travels with the RNDIS packet.
439 * This field is used to send part or all of the data
440 * through a send buffer. This values specifies an
441 * index into the send buffer. If the index is
442 * 0xFFFFFFFF, then the send buffer is not being used
443 * and all of the data was sent through other VMBus
446 uint32_t send_buf_section_idx;
447 uint32_t send_buf_section_size;
448 } __packed nvsp_1_msg_send_rndis_pkt;
451 * This message is used by both the VSP and the VSC to complete
452 * a RNDIS message to the opposite channel endpoint. At this
453 * point, the initiator of this message cannot use any resources
454 * associated with the original RNDIS packet.
456 typedef struct nvsp_1_msg_send_rndis_pkt_complete_ {
458 } __packed nvsp_1_msg_send_rndis_pkt_complete;
466 * This message is used by the VSC to send the NDIS version
467 * to the VSP. The VSP can use this information when handling
468 * OIDs sent by the VSC.
470 typedef struct nvsp_2_netvsc_capabilities_ {
475 uint64_t chimney : 1;
477 uint64_t ieee8021q : 1;
478 uint64_t correlationid : 1;
479 uint64_t teaming : 1;
482 } __packed nvsp_2_netvsc_capabilities;
484 typedef struct nvsp_2_msg_send_ndis_config_ {
487 nvsp_2_netvsc_capabilities capabilities;
488 } __packed nvsp_2_msg_send_ndis_config;
491 * NvspMessage2TypeSendChimneyDelegatedBuffer
493 typedef struct nvsp_2_msg_send_chimney_buf_
496 * On WIN7 beta, delegated_obj_max_size is defined as a uint32_t
497 * Since WIN7 RC, it was split into two uint16_t. To have the same
498 * struct layout, delegated_obj_max_size shall be the first field.
500 uint16_t delegated_obj_max_size;
503 * The revision # of chimney protocol used between NVSC and NVSP.
505 * This revision is NOT related to the chimney revision between
506 * NDIS protocol and miniport drivers.
510 uint32_t gpadl_handle;
511 } __packed nvsp_2_msg_send_chimney_buf;
514 /* Unsupported chimney revision 0 (only present in WIN7 beta) */
515 #define NVSP_CHIMNEY_REVISION_0 0
517 /* WIN7 Beta Chimney QFE */
518 #define NVSP_CHIMNEY_REVISION_1 1
520 /* The chimney revision since WIN7 RC */
521 #define NVSP_CHIMNEY_REVISION_2 2
525 * NvspMessage2TypeSendChimneyDelegatedBufferComplete
527 typedef struct nvsp_2_msg_send_chimney_buf_complete_ {
531 * Maximum number outstanding sends and pre-posted receives.
533 * NVSC should not post more than SendQuota/ReceiveQuota packets.
534 * Otherwise, it can block the non-chimney path for an indefinite
536 * (since chimney sends/receives are affected by the remote peer).
538 * Note: NVSP enforces the quota restrictions on a per-VMBCHANNEL
539 * basis. It doesn't enforce the restriction separately for chimney
540 * send/receive. If NVSC doesn't voluntarily enforce "SendQuota",
541 * it may kill its own network connectivity.
545 } __packed nvsp_2_msg_send_chimney_buf_complete;
548 * NvspMessage2TypeRevokeChimneyDelegatedBuffer
550 typedef struct nvsp_2_msg_revoke_chimney_buf_ {
551 uint32_t gpadl_handle;
552 } __packed nvsp_2_msg_revoke_chimney_buf;
555 #define NVSP_CHIMNEY_OBJECT_TYPE_NEIGHBOR 0
556 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH4 1
557 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH6 2
558 #define NVSP_CHIMNEY_OBJECT_TYPE_TCP 3
561 * NvspMessage2TypeAllocateChimneyHandle
563 typedef struct nvsp_2_msg_alloc_chimney_handle_ {
564 uint64_t vsc_context;
565 uint32_t object_type;
566 } __packed nvsp_2_msg_alloc_chimney_handle;
569 * NvspMessage2TypeAllocateChimneyHandleComplete
571 typedef struct nvsp_2_msg_alloc_chimney_handle_complete_ {
573 } __packed nvsp_2_msg_alloc_chimney_handle_complete;
577 * NvspMessage2TypeResumeChimneyRXIndication
579 typedef struct nvsp_2_msg_resume_chimney_rx_indication {
581 * Handle identifying the offloaded connection
583 uint32_t vsp_tcp_handle;
584 } __packed nvsp_2_msg_resume_chimney_rx_indication;
587 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_FIRST_STAGE (0x01u)
588 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_RESERVED (~(0x01u))
591 * NvspMessage2TypeTerminateChimney
593 typedef struct nvsp_2_msg_terminate_chimney_ {
595 * Handle identifying the offloaded object
600 * Terminate Offload Flags
602 * When set to 0, terminate the offload at the destination NIC
603 * Bit 1-31: Reserved, shall be zero
609 * This field is valid only when bit 0 of flags is clear.
610 * It specifies the index into the premapped delegated
611 * object buffer. The buffer was sent through the
612 * NvspMessage2TypeSendChimneyDelegatedBuffer
613 * message at initialization time.
615 * NVSP will write the delegated state into the delegated
616 * buffer upon upload completion.
621 * This field is valid only when bit 0 of flags is set.
623 * The seqence number of the most recently accepted RX
624 * indication when VSC sets its TCP context into
625 * "terminating" state.
627 * This allows NVSP to determines if there are any in-flight
628 * RX indications for which the acceptance state is still
631 uint64_t last_accepted_rx_seq_no;
633 } __packed nvsp_2_msg_terminate_chimney;
636 #define NVSP_TERMINATE_CHIMNEY_COMPLETE_FLAG_DATA_CORRUPTED 0x0000001u
639 * NvspMessage2TypeTerminateChimneyComplete
641 typedef struct nvsp_2_msg_terminate_chimney_complete_ {
642 uint64_t vsc_context;
644 } __packed nvsp_2_msg_terminate_chimney_complete;
647 * NvspMessage2TypeIndicateChimneyEvent
649 typedef struct nvsp_2_msg_indicate_chimney_event_ {
651 * When VscTcpContext is 0, event_type is an NDIS_STATUS event code
652 * Otherwise, EventType is an TCP connection event (defined in
653 * NdisTcpOffloadEventHandler chimney DDK document).
658 * When VscTcpContext is 0, EventType is an NDIS_STATUS event code
659 * Otherwise, EventType is an TCP connection event specific information
660 * (defined in NdisTcpOffloadEventHandler chimney DDK document).
662 uint32_t event_specific_info;
665 * If not 0, the event is per-TCP connection event. This field
666 * contains the VSC's TCP context.
667 * If 0, the event indication is global.
669 uint64_t vsc_tcp_context;
670 } __packed nvsp_2_msg_indicate_chimney_event;
673 #define NVSP_1_CHIMNEY_SEND_INVALID_OOB_INDEX 0xffffu
674 #define NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX 0xffffffff
677 * NvspMessage2TypeSendChimneyPacket
679 typedef struct nvsp_2_msg_send_chimney_pkt_ {
681 * Identify the TCP connection for which this chimney send is
683 uint32_t vsp_tcp_handle;
686 * This field is used to send part or all of the data
687 * through a send buffer. This values specifies an
688 * index into the send buffer. If the index is
689 * 0xFFFF, then the send buffer is not being used
690 * and all of the data was sent through other VMBus
693 uint16_t send_buf_section_index;
694 uint16_t send_buf_section_size;
698 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
699 * then there is no OOB data.
701 * This field shall be always 0xFFFFFFFF for now. It is reserved for
704 uint16_t oob_data_index;
707 * DisconnectFlags = 0
708 * Normal chimney send. See MiniportTcpOffloadSend for details.
710 * DisconnectFlags = TCP_DISCONNECT_GRACEFUL_CLOSE (0x01)
711 * Graceful disconnect. See MiniportTcpOffloadDisconnect for details.
713 * DisconnectFlags = TCP_DISCONNECT_ABORTIVE_CLOSE (0x02)
714 * Abortive disconnect. See MiniportTcpOffloadDisconnect for details.
716 uint16_t disconnect_flags;
719 } __packed nvsp_2_msg_send_chimney_pkt;
722 * NvspMessage2TypeSendChimneyPacketComplete
724 typedef struct nvsp_2_msg_send_chimney_pkt_complete_ {
726 * The NDIS_STATUS for the chimney send
731 * Number of bytes that have been sent to the peer (and ACKed by the peer).
733 uint32_t bytes_transferred;
734 } __packed nvsp_2_msg_send_chimney_pkt_complete;
737 #define NVSP_1_CHIMNEY_RECV_FLAG_NO_PUSH 0x0001u
738 #define NVSP_1_CHIMNEY_RECV_INVALID_OOB_INDEX 0xffffu
741 * NvspMessage2TypePostChimneyRecvRequest
743 typedef struct nvsp_2_msg_post_chimney_rx_request_ {
745 * Identify the TCP connection which this chimney receive request
748 uint32_t vsp_tcp_handle;
752 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
753 * then there is no OOB data.
755 * This field shall be always 0xFFFFFFFF for now. It is reserved for
758 uint32_t oob_data_index;
762 * When it is set, this is a "no-push" receive.
763 * When it is clear, this is a "push" receive.
765 * Bit 1-15: Reserved and shall be zero
770 * For debugging and diagnoses purpose.
771 * The SeqNo is per TCP connection and starts from 0.
774 } __packed nvsp_2_msg_post_chimney_rx_request;
777 * NvspMessage2TypePostChimneyRecvRequestComplete
779 typedef struct nvsp_2_msg_post_chimney_rx_request_complete_ {
781 * The NDIS_STATUS for the chimney send
786 * Number of bytes that have been sent to the peer (and ACKed by
789 uint32_t bytes_xferred;
790 } __packed nvsp_2_msg_post_chimney_rx_request_complete;
793 * NvspMessage2TypeAllocateReceiveBuffer
795 typedef struct nvsp_2_msg_alloc_rx_buf_ {
797 * Allocation ID to match the allocation request and response
799 uint32_t allocation_id;
802 * Length of the VM shared memory receive buffer that needs to
806 } __packed nvsp_2_msg_alloc_rx_buf;
809 * NvspMessage2TypeAllocateReceiveBufferComplete
811 typedef struct nvsp_2_msg_alloc_rx_buf_complete_ {
813 * The NDIS_STATUS code for buffer allocation
818 * Allocation ID from NVSP_2_MESSAGE_ALLOCATE_RECEIVE_BUFFER
820 uint32_t allocation_id;
823 * GPADL handle for the allocated receive buffer
825 uint32_t gpadl_handle;
828 * Receive buffer ID that is further used in
829 * NvspMessage2SendVmqRndisPacket
832 } __packed nvsp_2_msg_alloc_rx_buf_complete;
835 * NvspMessage2TypeFreeReceiveBuffer
837 typedef struct nvsp_2_msg_free_rx_buf_ {
839 * Receive buffer ID previous returned in
840 * NvspMessage2TypeAllocateReceiveBufferComplete message
843 } __packed nvsp_2_msg_free_rx_buf;
846 * This structure is used in defining the buffers in
847 * NVSP_2_MESSAGE_SEND_VMQ_RNDIS_PACKET structure
849 typedef struct nvsp_xfer_page_range_ {
851 * Specifies the ID of the receive buffer that has the buffer. This
852 * ID can be the general receive buffer ID specified in
853 * NvspMessage1TypeSendReceiveBuffer or it can be the shared memory
854 * receive buffer ID allocated by the VSC and specified in
855 * NvspMessage2TypeAllocateReceiveBufferComplete message
857 uint64_t xfer_page_set_id;
865 * Offset in bytes from the beginning of the buffer
867 uint32_t byte_offset;
868 } __packed nvsp_xfer_page_range;
871 * NvspMessage2SendVmqRndisPacket
873 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_ {
875 * This field is specified by RNIDS. They assume there's
876 * two different channels of communication. However,
877 * the Network VSP only has one. Therefore, the channel
878 * travels with the RNDIS packet. It must be RMC_DATA
880 uint32_t channel_type;
883 * Only the Range element corresponding to the RNDIS header of
884 * the first RNDIS message in the multiple RNDIS messages sent
885 * in one NVSP message. Information about the data portions as well
886 * as the subsequent RNDIS messages in the same NVSP message are
887 * embedded in the RNDIS header itself
889 nvsp_xfer_page_range range;
890 } __packed nvsp_2_msg_send_vmq_rndis_pkt;
893 * This message is used by the VSC to complete
894 * a RNDIS VMQ message to the VSP. At this point,
895 * the initiator of this message can use any resources
896 * associated with the original RNDIS VMQ packet.
898 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_complete_
901 } __packed nvsp_2_msg_send_vmq_rndis_pkt_complete;
906 enum nvsp_subchannel_operation {
907 NVSP_SUBCHANNEL_NONE = 0,
908 NVSP_SUBCHANNE_ALLOCATE,
912 typedef struct nvsp_5_subchannel_request_
915 uint32_t num_subchannels;
916 } __packed nvsp_5_subchannel_request;
918 typedef struct nvsp_5_subchannel_complete_
921 /* Actual number of subchannels allocated */
922 uint32_t num_subchannels;
923 } __packed nvsp_5_subchannel_complete;
925 typedef struct nvsp_5_send_indirect_table_
927 /* The number of entries in the send indirection table */
930 * The offset of the send indireciton table from top of
931 * this struct. The send indirection table tells which channel
932 * to put the send traffic on. Each entry is a channel number.
935 } __packed nvsp_5_send_indirect_table;
937 typedef union nvsp_1_msg_uber_ {
938 nvsp_1_msg_send_ndis_version send_ndis_vers;
940 nvsp_1_msg_send_rx_buf send_rx_buf;
941 nvsp_1_msg_send_rx_buf_complete send_rx_buf_complete;
942 nvsp_1_msg_revoke_rx_buf revoke_rx_buf;
944 nvsp_1_msg_send_send_buf send_send_buf;
945 nvsp_1_msg_send_send_buf_complete send_send_buf_complete;
946 nvsp_1_msg_revoke_send_buf revoke_send_buf;
948 nvsp_1_msg_send_rndis_pkt send_rndis_pkt;
949 nvsp_1_msg_send_rndis_pkt_complete send_rndis_pkt_complete;
950 } __packed nvsp_1_msg_uber;
953 typedef union nvsp_2_msg_uber_ {
954 nvsp_2_msg_send_ndis_config send_ndis_config;
956 nvsp_2_msg_send_chimney_buf send_chimney_buf;
957 nvsp_2_msg_send_chimney_buf_complete send_chimney_buf_complete;
958 nvsp_2_msg_revoke_chimney_buf revoke_chimney_buf;
960 nvsp_2_msg_resume_chimney_rx_indication resume_chimney_rx_indication;
961 nvsp_2_msg_terminate_chimney terminate_chimney;
962 nvsp_2_msg_terminate_chimney_complete terminate_chimney_complete;
963 nvsp_2_msg_indicate_chimney_event indicate_chimney_event;
965 nvsp_2_msg_send_chimney_pkt send_chimney_packet;
966 nvsp_2_msg_send_chimney_pkt_complete send_chimney_packet_complete;
967 nvsp_2_msg_post_chimney_rx_request post_chimney_rx_request;
968 nvsp_2_msg_post_chimney_rx_request_complete
969 post_chimney_rx_request_complete;
971 nvsp_2_msg_alloc_rx_buf alloc_rx_buffer;
972 nvsp_2_msg_alloc_rx_buf_complete alloc_rx_buffer_complete;
973 nvsp_2_msg_free_rx_buf free_rx_buffer;
975 nvsp_2_msg_send_vmq_rndis_pkt send_vmq_rndis_pkt;
976 nvsp_2_msg_send_vmq_rndis_pkt_complete send_vmq_rndis_pkt_complete;
977 nvsp_2_msg_alloc_chimney_handle alloc_chimney_handle;
978 nvsp_2_msg_alloc_chimney_handle_complete alloc_chimney_handle_complete;
979 } __packed nvsp_2_msg_uber;
981 typedef union nvsp_5_msg_uber_
983 nvsp_5_subchannel_request subchannel_request;
984 nvsp_5_subchannel_complete subchn_complete;
985 nvsp_5_send_indirect_table send_table;
986 } __packed nvsp_5_msg_uber;
988 typedef union nvsp_all_msgs_ {
989 nvsp_msg_init_uber init_msgs;
990 nvsp_1_msg_uber vers_1_msgs;
991 nvsp_2_msg_uber vers_2_msgs;
992 nvsp_5_msg_uber vers_5_msgs;
993 } __packed nvsp_all_msgs;
998 typedef struct nvsp_msg_ {
1001 } __packed nvsp_msg;
1005 * The following arguably belongs in a separate header file
1012 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
1013 #define NETVSC_SEND_BUFFER_ID 0xface
1015 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
1016 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
1018 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
1020 #define NETVSC_RECEIVE_SG_COUNT 1
1022 /* Preallocated receive packets */
1023 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
1026 * Maximum MTU we permit to be configured for a netvsc interface.
1027 * When the code was developed, a max MTU of 12232 was tested and
1028 * proven to work. 9K is a reasonable maximum for an Ethernet.
1030 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
1032 #define NETVSC_PACKET_SIZE PAGE_SIZE
1033 #define VRSS_SEND_TABLE_SIZE 16
1040 * Per netvsc channel-specific
1042 typedef struct netvsc_dev_ {
1043 struct hv_device *dev;
1045 /* Send buffer allocated by us but manages by NetVSP */
1047 uint32_t send_buf_size;
1048 uint32_t send_buf_gpadl_handle;
1049 uint32_t send_section_size;
1050 uint32_t send_section_count;
1051 unsigned long bitsmap_words;
1052 unsigned long *send_section_bitsmap;
1054 /* Receive buffer allocated by us but managed by NetVSP */
1056 uint32_t rx_buf_size;
1057 uint32_t rx_buf_gpadl_handle;
1058 uint32_t rx_section_count;
1059 nvsp_1_rx_buf_section *rx_sections;
1061 /* Used for NetVSP initialization protocol */
1062 struct sema channel_init_sema;
1063 nvsp_msg channel_init_packet;
1065 nvsp_msg revoke_packet;
1066 /*uint8_t hw_mac_addr[HW_MACADDR_LEN];*/
1068 /* Holds rndis device info */
1071 hv_bool_uint8_t destroy;
1072 /* Negotiated NVSP version */
1073 uint32_t nvsp_version;
1075 uint32_t num_channel;
1077 uint32_t vrss_send_table[VRSS_SEND_TABLE_SIZE];
1080 struct hv_vmbus_channel;
1082 typedef void (*pfn_on_send_rx_completion)(struct hv_vmbus_channel *, void *);
1084 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
1085 #define NETVSC_PACKET_MAXPAGE 32
1088 #define NETVSC_VLAN_PRIO_MASK 0xe000
1089 #define NETVSC_VLAN_PRIO_SHIFT 13
1090 #define NETVSC_VLAN_VID_MASK 0x0fff
1097 #define TRANSPORT_TYPE_NOT_IP 0
1098 #define TRANSPORT_TYPE_IPV4_TCP ((TYPE_IPV4 << 16) | TYPE_TCP)
1099 #define TRANSPORT_TYPE_IPV4_UDP ((TYPE_IPV4 << 16) | TYPE_UDP)
1100 #define TRANSPORT_TYPE_IPV6_TCP ((TYPE_IPV6 << 16) | TYPE_TCP)
1101 #define TRANSPORT_TYPE_IPV6_UDP ((TYPE_IPV6 << 16) | TYPE_UDP)
1104 #define BITS_PER_LONG 64
1106 #define BITS_PER_LONG 32
1109 typedef struct netvsc_packet_ {
1110 struct hv_device *device;
1111 hv_bool_uint8_t is_data_pkt; /* One byte */
1118 uint64_t rx_completion_tid;
1119 void *rx_completion_context;
1120 /* This is no longer used */
1121 pfn_on_send_rx_completion on_rx_completion;
1124 uint64_t send_completion_tid;
1125 void *send_completion_context;
1126 /* Still used in netvsc and filter code */
1127 pfn_on_send_rx_completion on_send_completion;
1130 uint32_t send_buf_section_idx;
1131 uint32_t send_buf_section_size;
1134 uint32_t tot_data_buf_len;
1136 uint32_t page_buf_count;
1137 hv_vmbus_page_buffer page_buffers[NETVSC_PACKET_MAXPAGE];
1141 uint8_t mac_addr[6]; /* Assumption unsigned long */
1142 hv_bool_uint8_t link_state;
1143 } netvsc_device_info;
1145 #ifndef HN_USE_TXDESC_BUFRING
1147 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
1153 struct ifnet *hn_ifp;
1156 /* Trust csum verification on host side */
1157 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
1158 struct lro_ctrl hn_lro;
1163 u_long hn_csum_trusted;
1164 u_long hn_lro_tried;
1165 u_long hn_small_pkts;
1168 /* Rarely used stuffs */
1169 struct sysctl_oid *hn_rx_sysctl_tree;
1171 } __aligned(CACHE_LINE_SIZE);
1173 #define HN_TRUST_HCSUM_IP 0x0001
1174 #define HN_TRUST_HCSUM_TCP 0x0002
1175 #define HN_TRUST_HCSUM_UDP 0x0004
1177 #define HN_RX_FLAG_ATTACHED 0x1
1180 #ifndef HN_USE_TXDESC_BUFRING
1181 struct mtx hn_txlist_spin;
1182 struct hn_txdesc_list hn_txlist;
1184 struct buf_ring *hn_txdesc_br;
1187 int hn_txdesc_avail;
1191 void (*hn_txeof)(struct hn_tx_ring *);
1192 struct taskqueue *hn_tx_taskq;
1193 struct task hn_tx_task;
1194 struct task hn_txeof_task;
1196 struct buf_ring *hn_mbuf_br;
1200 struct mtx hn_tx_lock;
1201 struct hn_softc *hn_sc;
1202 struct hv_vmbus_channel *hn_chan;
1204 int hn_direct_tx_size;
1205 int hn_tx_chimney_size;
1206 bus_dma_tag_t hn_tx_data_dtag;
1207 uint64_t hn_csum_assist;
1209 u_long hn_no_txdescs;
1210 u_long hn_send_failed;
1211 u_long hn_txdma_failed;
1212 u_long hn_tx_collapsed;
1213 u_long hn_tx_chimney;
1216 /* Rarely used stuffs */
1217 struct hn_txdesc *hn_txdesc;
1218 bus_dma_tag_t hn_tx_rndis_dtag;
1219 struct sysctl_oid *hn_tx_sysctl_tree;
1221 } __aligned(CACHE_LINE_SIZE);
1223 #define HN_TX_FLAG_ATTACHED 0x1
1226 * Device-specific softc structure
1228 typedef struct hn_softc {
1229 struct ifnet *hn_ifp;
1230 struct arpcom arpcom;
1231 struct ifmedia hn_media;
1238 /* See hv_netvsc_drv_freebsd.c for rules on how to use */
1240 struct hv_device *hn_dev_obj;
1241 netvsc_dev *net_dev;
1244 int hn_rx_ring_inuse;
1245 struct hn_rx_ring *hn_rx_ring;
1248 int hn_tx_ring_inuse;
1249 struct hn_tx_ring *hn_tx_ring;
1252 int hn_tx_chimney_max;
1253 struct taskqueue *hn_tx_taskq;
1254 struct sysctl_oid *hn_tx_sysctl_tree;
1255 struct sysctl_oid *hn_rx_sysctl_tree;
1261 extern int hv_promisc_mode;
1263 void netvsc_linkstatus_callback(struct hv_device *device_obj, uint32_t status);
1264 netvsc_dev *hv_nv_on_device_add(struct hv_device *device,
1265 void *additional_info);
1266 int hv_nv_on_device_remove(struct hv_device *device,
1267 boolean_t destroy_channel);
1268 int hv_nv_on_send(struct hv_vmbus_channel *chan, netvsc_packet *pkt);
1269 int hv_nv_get_next_send_section(netvsc_dev *net_dev);
1271 #endif /* __HV_NET_VSC_H__ */