2 * Copyright (c) 2009-2012,2016 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>
50 #include <machine/bus.h>
52 #include <sys/bus_dma.h>
54 #include <netinet/in.h>
55 #include <netinet/tcp_lro.h>
57 #include <net/ethernet.h>
59 #include <net/if_media.h>
61 #include <dev/hyperv/include/hyperv.h>
62 #include <dev/hyperv/include/hyperv_busdma.h>
63 #include <dev/hyperv/include/vmbus.h>
65 #define HN_USE_TXDESC_BUFRING
67 MALLOC_DECLARE(M_NETVSC);
69 #define NVSP_INVALID_PROTOCOL_VERSION (0xFFFFFFFF)
71 #define NVSP_PROTOCOL_VERSION_1 2
72 #define NVSP_PROTOCOL_VERSION_2 0x30002
73 #define NVSP_PROTOCOL_VERSION_4 0x40000
74 #define NVSP_PROTOCOL_VERSION_5 0x50000
75 #define NVSP_MIN_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_1)
76 #define NVSP_MAX_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_2)
78 #define NVSP_PROTOCOL_VERSION_CURRENT NVSP_PROTOCOL_VERSION_2
80 #define VERSION_4_OFFLOAD_SIZE 22
82 #define NVSP_OPERATIONAL_STATUS_OK (0x00000000)
83 #define NVSP_OPERATIONAL_STATUS_DEGRADED (0x00000001)
84 #define NVSP_OPERATIONAL_STATUS_NONRECOVERABLE (0x00000002)
85 #define NVSP_OPERATIONAL_STATUS_NO_CONTACT (0x00000003)
86 #define NVSP_OPERATIONAL_STATUS_LOST_COMMUNICATION (0x00000004)
89 * Maximun number of transfer pages (packets) the VSP will use on a receive
91 #define NVSP_MAX_PACKETS_PER_RECEIVE 375
94 #define RNDIS_OBJECT_TYPE_RSS_CAPABILITIES 0x88
95 #define RNDIS_OBJECT_TYPE_RSS_PARAMETERS 0x89
97 #define RNDIS_RECEIVE_SCALE_CAPABILITIES_REVISION_2 2
98 #define RNDIS_RECEIVE_SCALE_PARAMETERS_REVISION_2 2
100 struct rndis_obj_header {
106 /* rndis_recv_scale_cap/cap_flag */
107 #define RNDIS_RSS_CAPS_MESSAGE_SIGNALED_INTERRUPTS 0x01000000
108 #define RNDIS_RSS_CAPS_CLASSIFICATION_AT_ISR 0x02000000
109 #define RNDIS_RSS_CAPS_CLASSIFICATION_AT_DPC 0x04000000
110 #define RNDIS_RSS_CAPS_USING_MSI_X 0x08000000
111 #define RNDIS_RSS_CAPS_RSS_AVAILABLE_ON_PORTS 0x10000000
112 #define RNDIS_RSS_CAPS_SUPPORTS_MSI_X 0x20000000
113 #define RNDIS_RSS_CAPS_HASH_TYPE_TCP_IPV4 0x00000100
114 #define RNDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6 0x00000200
115 #define RNDIS_RSS_CAPS_HASH_TYPE_TCP_IPV6_EX 0x00000400
117 /* RNDIS_RECEIVE_SCALE_CAPABILITIES */
118 struct rndis_recv_scale_cap {
119 struct rndis_obj_header hdr;
121 uint32_t num_int_msg;
122 uint32_t num_recv_que;
123 uint16_t num_indirect_tabent;
126 /* rndis_recv_scale_param flags */
127 #define RNDIS_RSS_PARAM_FLAG_BASE_CPU_UNCHANGED 0x0001
128 #define RNDIS_RSS_PARAM_FLAG_HASH_INFO_UNCHANGED 0x0002
129 #define RNDIS_RSS_PARAM_FLAG_ITABLE_UNCHANGED 0x0004
130 #define RNDIS_RSS_PARAM_FLAG_HASH_KEY_UNCHANGED 0x0008
131 #define RNDIS_RSS_PARAM_FLAG_DISABLE_RSS 0x0010
134 #define RNDIS_HASH_FUNC_TOEPLITZ 0x00000001
135 #define RNDIS_HASH_IPV4 0x00000100
136 #define RNDIS_HASH_TCP_IPV4 0x00000200
137 #define RNDIS_HASH_IPV6 0x00000400
138 #define RNDIS_HASH_IPV6_EX 0x00000800
139 #define RNDIS_HASH_TCP_IPV6 0x00001000
140 #define RNDIS_HASH_TCP_IPV6_EX 0x00002000
142 #define RNDIS_RSS_INDIRECTION_TABLE_MAX_SIZE_REVISION_2 (128 * 4)
143 #define RNDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2 40
146 #define HASH_KEYLEN RNDIS_RSS_HASH_SECRET_KEY_MAX_SIZE_REVISION_2
148 /* RNDIS_RECEIVE_SCALE_PARAMETERS */
149 typedef struct rndis_recv_scale_param_ {
150 struct rndis_obj_header hdr;
152 /* Qualifies the rest of the information */
155 /* The base CPU number to do receive processing. not used */
156 uint16_t base_cpu_number;
158 /* This describes the hash function and type being enabled */
161 /* The size of indirection table array */
162 uint16_t indirect_tabsize;
164 /* The offset of the indirection table from the beginning of this
167 uint32_t indirect_taboffset;
169 /* The size of the hash secret key */
170 uint16_t hashkey_size;
172 /* The offset of the secret key from the beginning of this structure */
173 uint32_t hashkey_offset;
175 uint32_t processor_masks_offset;
176 uint32_t num_processor_masks;
177 uint32_t processor_masks_entry_size;
178 } rndis_recv_scale_param;
180 typedef enum nvsp_msg_type_ {
181 nvsp_msg_type_none = 0,
186 nvsp_msg_type_init = 1,
187 nvsp_msg_type_init_complete = 2,
189 nvsp_version_msg_start = 100,
194 nvsp_msg_1_type_send_ndis_vers = nvsp_version_msg_start,
196 nvsp_msg_1_type_send_rx_buf,
197 nvsp_msg_1_type_send_rx_buf_complete,
198 nvsp_msg_1_type_revoke_rx_buf,
200 nvsp_msg_1_type_send_send_buf,
201 nvsp_msg_1_type_send_send_buf_complete,
202 nvsp_msg_1_type_revoke_send_buf,
204 nvsp_msg_1_type_send_rndis_pkt,
205 nvsp_msg_1_type_send_rndis_pkt_complete,
210 nvsp_msg_2_type_send_chimney_delegated_buf,
211 nvsp_msg_2_type_send_chimney_delegated_buf_complete,
212 nvsp_msg_2_type_revoke_chimney_delegated_buf,
214 nvsp_msg_2_type_resume_chimney_rx_indication,
216 nvsp_msg_2_type_terminate_chimney,
217 nvsp_msg_2_type_terminate_chimney_complete,
219 nvsp_msg_2_type_indicate_chimney_event,
221 nvsp_msg_2_type_send_chimney_packet,
222 nvsp_msg_2_type_send_chimney_packet_complete,
224 nvsp_msg_2_type_post_chimney_rx_request,
225 nvsp_msg_2_type_post_chimney_rx_request_complete,
227 nvsp_msg_2_type_alloc_rx_buf,
228 nvsp_msg_2_type_alloc_rx_buf_complete,
230 nvsp_msg_2_type_free_rx_buf,
232 nvsp_msg_2_send_vmq_rndis_pkt,
233 nvsp_msg_2_send_vmq_rndis_pkt_complete,
235 nvsp_msg_2_type_send_ndis_config,
237 nvsp_msg_2_type_alloc_chimney_handle,
238 nvsp_msg_2_type_alloc_chimney_handle_complete,
240 nvsp_msg2_max = nvsp_msg_2_type_alloc_chimney_handle_complete,
245 nvsp_msg4_type_send_vf_association,
246 nvsp_msg4_type_switch_data_path,
247 nvsp_msg4_type_uplink_connect_state_deprecated,
249 nvsp_msg4_max = nvsp_msg4_type_uplink_connect_state_deprecated,
254 nvsp_msg5_type_oid_query_ex,
255 nvsp_msg5_type_oid_query_ex_comp,
256 nvsp_msg5_type_subchannel,
257 nvsp_msg5_type_send_indirection_table,
259 nvsp_msg5_max = nvsp_msg5_type_send_indirection_table,
262 typedef enum nvsp_status_ {
263 nvsp_status_none = 0,
267 nvsp_status_prot_vers_range_too_new,
269 nvsp_status_prot_vers_range_too_old,
270 nvsp_status_invalid_rndis_pkt,
275 typedef struct nvsp_msg_hdr_ {
277 } __packed nvsp_msg_hdr;
284 * This message is used by the VSC to initialize the channel
285 * after the channels has been opened. This message should
286 * never include anything other then versioning (i.e. this
287 * message will be the same for ever).
289 * Forever is a long time. The values have been redefined
290 * in Win7 to indicate major and minor protocol version
293 typedef struct nvsp_msg_init_ {
296 uint16_t minor_protocol_version;
297 uint16_t major_protocol_version;
299 /* Formerly min_protocol_version */
300 uint32_t protocol_version;
302 /* Formerly max_protocol_version */
303 uint32_t protocol_version_2;
304 } __packed nvsp_msg_init;
307 * This message is used by the VSP to complete the initialization
308 * of the channel. This message should never include anything other
309 * then versioning (i.e. this message will be the same forever).
311 typedef struct nvsp_msg_init_complete_ {
313 uint32_t negotiated_prot_vers;
314 uint32_t max_mdl_chain_len;
316 } __packed nvsp_msg_init_complete;
318 typedef union nvsp_msg_init_uber_ {
320 nvsp_msg_init_complete init_compl;
321 } __packed nvsp_msg_init_uber;
328 * This message is used by the VSC to send the NDIS version
329 * to the VSP. The VSP can use this information when handling
330 * OIDs sent by the VSC.
332 typedef struct nvsp_1_msg_send_ndis_version_ {
333 uint32_t ndis_major_vers;
335 uint32_t ndis_minor_vers;
336 } __packed nvsp_1_msg_send_ndis_version;
339 * This message is used by the VSC to send a receive buffer
340 * to the VSP. The VSP can then use the receive buffer to
341 * send data to the VSC.
343 typedef struct nvsp_1_msg_send_rx_buf_ {
344 uint32_t gpadl_handle;
346 } __packed nvsp_1_msg_send_rx_buf;
348 typedef struct nvsp_1_rx_buf_section_ {
350 uint32_t sub_allocation_size;
351 uint32_t num_sub_allocations;
353 } __packed nvsp_1_rx_buf_section;
356 * This message is used by the VSP to acknowledge a receive
357 * buffer send by the VSC. This message must be sent by the
358 * VSP before the VSP uses the receive buffer.
360 typedef struct nvsp_1_msg_send_rx_buf_complete_ {
362 uint32_t num_sections;
365 * The receive buffer is split into two parts, a large
366 * suballocation section and a small suballocation
367 * section. These sections are then suballocated by a
370 * For example, the following break up of the receive
371 * buffer has 6 large suballocations and 10 small
374 * | Large Section | | Small Section |
375 * ------------------------------------------------------------
376 * | | | | | | | | | | | | | | | | | |
378 * LargeOffset SmallOffset
380 nvsp_1_rx_buf_section sections[1];
382 } __packed nvsp_1_msg_send_rx_buf_complete;
385 * This message is sent by the VSC to revoke the receive buffer.
386 * After the VSP completes this transaction, the VSP should never
387 * use the receive buffer again.
389 typedef struct nvsp_1_msg_revoke_rx_buf_ {
391 } __packed nvsp_1_msg_revoke_rx_buf;
394 * This message is used by the VSC to send a send buffer
395 * to the VSP. The VSC can then use the send buffer to
396 * send data to the VSP.
398 typedef struct nvsp_1_msg_send_send_buf_ {
399 uint32_t gpadl_handle;
401 } __packed nvsp_1_msg_send_send_buf;
404 * This message is used by the VSP to acknowledge a send
405 * buffer sent by the VSC. This message must be sent by the
406 * VSP before the VSP uses the sent buffer.
408 typedef struct nvsp_1_msg_send_send_buf_complete_ {
412 * The VSC gets to choose the size of the send buffer and
413 * the VSP gets to choose the sections size of the buffer.
414 * This was done to enable dynamic reconfigurations when
415 * the cost of GPA-direct buffers decreases.
417 uint32_t section_size;
418 } __packed nvsp_1_msg_send_send_buf_complete;
421 * This message is sent by the VSC to revoke the send buffer.
422 * After the VSP completes this transaction, the vsp should never
423 * use the send buffer again.
425 typedef struct nvsp_1_msg_revoke_send_buf_ {
427 } __packed nvsp_1_msg_revoke_send_buf;
430 * This message is used by both the VSP and the VSC to send
431 * an RNDIS message to the opposite channel endpoint.
433 typedef struct nvsp_1_msg_send_rndis_pkt_ {
435 * This field is specified by RNIDS. They assume there's
436 * two different channels of communication. However,
437 * the Network VSP only has one. Therefore, the channel
438 * travels with the RNDIS packet.
443 * This field is used to send part or all of the data
444 * through a send buffer. This values specifies an
445 * index into the send buffer. If the index is
446 * 0xFFFFFFFF, then the send buffer is not being used
447 * and all of the data was sent through other VMBus
450 uint32_t send_buf_section_idx;
451 uint32_t send_buf_section_size;
452 } __packed nvsp_1_msg_send_rndis_pkt;
455 * This message is used by both the VSP and the VSC to complete
456 * a RNDIS message to the opposite channel endpoint. At this
457 * point, the initiator of this message cannot use any resources
458 * associated with the original RNDIS packet.
460 typedef struct nvsp_1_msg_send_rndis_pkt_complete_ {
462 } __packed nvsp_1_msg_send_rndis_pkt_complete;
470 * This message is used by the VSC to send the NDIS version
471 * to the VSP. The VSP can use this information when handling
472 * OIDs sent by the VSC.
474 typedef struct nvsp_2_netvsc_capabilities_ {
479 uint64_t chimney : 1;
481 uint64_t ieee8021q : 1;
482 uint64_t correlationid : 1;
483 uint64_t teaming : 1;
486 } __packed nvsp_2_netvsc_capabilities;
488 typedef struct nvsp_2_msg_send_ndis_config_ {
491 nvsp_2_netvsc_capabilities capabilities;
492 } __packed nvsp_2_msg_send_ndis_config;
495 * NvspMessage2TypeSendChimneyDelegatedBuffer
497 typedef struct nvsp_2_msg_send_chimney_buf_
500 * On WIN7 beta, delegated_obj_max_size is defined as a uint32_t
501 * Since WIN7 RC, it was split into two uint16_t. To have the same
502 * struct layout, delegated_obj_max_size shall be the first field.
504 uint16_t delegated_obj_max_size;
507 * The revision # of chimney protocol used between NVSC and NVSP.
509 * This revision is NOT related to the chimney revision between
510 * NDIS protocol and miniport drivers.
514 uint32_t gpadl_handle;
515 } __packed nvsp_2_msg_send_chimney_buf;
518 /* Unsupported chimney revision 0 (only present in WIN7 beta) */
519 #define NVSP_CHIMNEY_REVISION_0 0
521 /* WIN7 Beta Chimney QFE */
522 #define NVSP_CHIMNEY_REVISION_1 1
524 /* The chimney revision since WIN7 RC */
525 #define NVSP_CHIMNEY_REVISION_2 2
529 * NvspMessage2TypeSendChimneyDelegatedBufferComplete
531 typedef struct nvsp_2_msg_send_chimney_buf_complete_ {
535 * Maximum number outstanding sends and pre-posted receives.
537 * NVSC should not post more than SendQuota/ReceiveQuota packets.
538 * Otherwise, it can block the non-chimney path for an indefinite
540 * (since chimney sends/receives are affected by the remote peer).
542 * Note: NVSP enforces the quota restrictions on a per-VMBCHANNEL
543 * basis. It doesn't enforce the restriction separately for chimney
544 * send/receive. If NVSC doesn't voluntarily enforce "SendQuota",
545 * it may kill its own network connectivity.
549 } __packed nvsp_2_msg_send_chimney_buf_complete;
552 * NvspMessage2TypeRevokeChimneyDelegatedBuffer
554 typedef struct nvsp_2_msg_revoke_chimney_buf_ {
555 uint32_t gpadl_handle;
556 } __packed nvsp_2_msg_revoke_chimney_buf;
559 #define NVSP_CHIMNEY_OBJECT_TYPE_NEIGHBOR 0
560 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH4 1
561 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH6 2
562 #define NVSP_CHIMNEY_OBJECT_TYPE_TCP 3
565 * NvspMessage2TypeAllocateChimneyHandle
567 typedef struct nvsp_2_msg_alloc_chimney_handle_ {
568 uint64_t vsc_context;
569 uint32_t object_type;
570 } __packed nvsp_2_msg_alloc_chimney_handle;
573 * NvspMessage2TypeAllocateChimneyHandleComplete
575 typedef struct nvsp_2_msg_alloc_chimney_handle_complete_ {
577 } __packed nvsp_2_msg_alloc_chimney_handle_complete;
581 * NvspMessage2TypeResumeChimneyRXIndication
583 typedef struct nvsp_2_msg_resume_chimney_rx_indication {
585 * Handle identifying the offloaded connection
587 uint32_t vsp_tcp_handle;
588 } __packed nvsp_2_msg_resume_chimney_rx_indication;
591 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_FIRST_STAGE (0x01u)
592 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_RESERVED (~(0x01u))
595 * NvspMessage2TypeTerminateChimney
597 typedef struct nvsp_2_msg_terminate_chimney_ {
599 * Handle identifying the offloaded object
604 * Terminate Offload Flags
606 * When set to 0, terminate the offload at the destination NIC
607 * Bit 1-31: Reserved, shall be zero
613 * This field is valid only when bit 0 of flags is clear.
614 * It specifies the index into the premapped delegated
615 * object buffer. The buffer was sent through the
616 * NvspMessage2TypeSendChimneyDelegatedBuffer
617 * message at initialization time.
619 * NVSP will write the delegated state into the delegated
620 * buffer upon upload completion.
625 * This field is valid only when bit 0 of flags is set.
627 * The seqence number of the most recently accepted RX
628 * indication when VSC sets its TCP context into
629 * "terminating" state.
631 * This allows NVSP to determines if there are any in-flight
632 * RX indications for which the acceptance state is still
635 uint64_t last_accepted_rx_seq_no;
637 } __packed nvsp_2_msg_terminate_chimney;
640 #define NVSP_TERMINATE_CHIMNEY_COMPLETE_FLAG_DATA_CORRUPTED 0x0000001u
643 * NvspMessage2TypeTerminateChimneyComplete
645 typedef struct nvsp_2_msg_terminate_chimney_complete_ {
646 uint64_t vsc_context;
648 } __packed nvsp_2_msg_terminate_chimney_complete;
651 * NvspMessage2TypeIndicateChimneyEvent
653 typedef struct nvsp_2_msg_indicate_chimney_event_ {
655 * When VscTcpContext is 0, event_type is an NDIS_STATUS event code
656 * Otherwise, EventType is an TCP connection event (defined in
657 * NdisTcpOffloadEventHandler chimney DDK document).
662 * When VscTcpContext is 0, EventType is an NDIS_STATUS event code
663 * Otherwise, EventType is an TCP connection event specific information
664 * (defined in NdisTcpOffloadEventHandler chimney DDK document).
666 uint32_t event_specific_info;
669 * If not 0, the event is per-TCP connection event. This field
670 * contains the VSC's TCP context.
671 * If 0, the event indication is global.
673 uint64_t vsc_tcp_context;
674 } __packed nvsp_2_msg_indicate_chimney_event;
677 #define NVSP_1_CHIMNEY_SEND_INVALID_OOB_INDEX 0xffffu
678 #define NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX 0xffffffff
681 * NvspMessage2TypeSendChimneyPacket
683 typedef struct nvsp_2_msg_send_chimney_pkt_ {
685 * Identify the TCP connection for which this chimney send is
687 uint32_t vsp_tcp_handle;
690 * This field is used to send part or all of the data
691 * through a send buffer. This values specifies an
692 * index into the send buffer. If the index is
693 * 0xFFFF, then the send buffer is not being used
694 * and all of the data was sent through other VMBus
697 uint16_t send_buf_section_index;
698 uint16_t send_buf_section_size;
702 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
703 * then there is no OOB data.
705 * This field shall be always 0xFFFFFFFF for now. It is reserved for
708 uint16_t oob_data_index;
711 * DisconnectFlags = 0
712 * Normal chimney send. See MiniportTcpOffloadSend for details.
714 * DisconnectFlags = TCP_DISCONNECT_GRACEFUL_CLOSE (0x01)
715 * Graceful disconnect. See MiniportTcpOffloadDisconnect for details.
717 * DisconnectFlags = TCP_DISCONNECT_ABORTIVE_CLOSE (0x02)
718 * Abortive disconnect. See MiniportTcpOffloadDisconnect for details.
720 uint16_t disconnect_flags;
723 } __packed nvsp_2_msg_send_chimney_pkt;
726 * NvspMessage2TypeSendChimneyPacketComplete
728 typedef struct nvsp_2_msg_send_chimney_pkt_complete_ {
730 * The NDIS_STATUS for the chimney send
735 * Number of bytes that have been sent to the peer (and ACKed by the peer).
737 uint32_t bytes_transferred;
738 } __packed nvsp_2_msg_send_chimney_pkt_complete;
741 #define NVSP_1_CHIMNEY_RECV_FLAG_NO_PUSH 0x0001u
742 #define NVSP_1_CHIMNEY_RECV_INVALID_OOB_INDEX 0xffffu
745 * NvspMessage2TypePostChimneyRecvRequest
747 typedef struct nvsp_2_msg_post_chimney_rx_request_ {
749 * Identify the TCP connection which this chimney receive request
752 uint32_t vsp_tcp_handle;
756 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
757 * then there is no OOB data.
759 * This field shall be always 0xFFFFFFFF for now. It is reserved for
762 uint32_t oob_data_index;
766 * When it is set, this is a "no-push" receive.
767 * When it is clear, this is a "push" receive.
769 * Bit 1-15: Reserved and shall be zero
774 * For debugging and diagnoses purpose.
775 * The SeqNo is per TCP connection and starts from 0.
778 } __packed nvsp_2_msg_post_chimney_rx_request;
781 * NvspMessage2TypePostChimneyRecvRequestComplete
783 typedef struct nvsp_2_msg_post_chimney_rx_request_complete_ {
785 * The NDIS_STATUS for the chimney send
790 * Number of bytes that have been sent to the peer (and ACKed by
793 uint32_t bytes_xferred;
794 } __packed nvsp_2_msg_post_chimney_rx_request_complete;
797 * NvspMessage2TypeAllocateReceiveBuffer
799 typedef struct nvsp_2_msg_alloc_rx_buf_ {
801 * Allocation ID to match the allocation request and response
803 uint32_t allocation_id;
806 * Length of the VM shared memory receive buffer that needs to
810 } __packed nvsp_2_msg_alloc_rx_buf;
813 * NvspMessage2TypeAllocateReceiveBufferComplete
815 typedef struct nvsp_2_msg_alloc_rx_buf_complete_ {
817 * The NDIS_STATUS code for buffer allocation
822 * Allocation ID from NVSP_2_MESSAGE_ALLOCATE_RECEIVE_BUFFER
824 uint32_t allocation_id;
827 * GPADL handle for the allocated receive buffer
829 uint32_t gpadl_handle;
832 * Receive buffer ID that is further used in
833 * NvspMessage2SendVmqRndisPacket
836 } __packed nvsp_2_msg_alloc_rx_buf_complete;
839 * NvspMessage2TypeFreeReceiveBuffer
841 typedef struct nvsp_2_msg_free_rx_buf_ {
843 * Receive buffer ID previous returned in
844 * NvspMessage2TypeAllocateReceiveBufferComplete message
847 } __packed nvsp_2_msg_free_rx_buf;
850 * This structure is used in defining the buffers in
851 * NVSP_2_MESSAGE_SEND_VMQ_RNDIS_PACKET structure
853 typedef struct nvsp_xfer_page_range_ {
855 * Specifies the ID of the receive buffer that has the buffer. This
856 * ID can be the general receive buffer ID specified in
857 * NvspMessage1TypeSendReceiveBuffer or it can be the shared memory
858 * receive buffer ID allocated by the VSC and specified in
859 * NvspMessage2TypeAllocateReceiveBufferComplete message
861 uint64_t xfer_page_set_id;
869 * Offset in bytes from the beginning of the buffer
871 uint32_t byte_offset;
872 } __packed nvsp_xfer_page_range;
875 * NvspMessage2SendVmqRndisPacket
877 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_ {
879 * This field is specified by RNIDS. They assume there's
880 * two different channels of communication. However,
881 * the Network VSP only has one. Therefore, the channel
882 * travels with the RNDIS packet. It must be RMC_DATA
884 uint32_t channel_type;
887 * Only the Range element corresponding to the RNDIS header of
888 * the first RNDIS message in the multiple RNDIS messages sent
889 * in one NVSP message. Information about the data portions as well
890 * as the subsequent RNDIS messages in the same NVSP message are
891 * embedded in the RNDIS header itself
893 nvsp_xfer_page_range range;
894 } __packed nvsp_2_msg_send_vmq_rndis_pkt;
897 * This message is used by the VSC to complete
898 * a RNDIS VMQ message to the VSP. At this point,
899 * the initiator of this message can use any resources
900 * associated with the original RNDIS VMQ packet.
902 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_complete_
905 } __packed nvsp_2_msg_send_vmq_rndis_pkt_complete;
910 enum nvsp_subchannel_operation {
911 NVSP_SUBCHANNEL_NONE = 0,
912 NVSP_SUBCHANNE_ALLOCATE,
916 typedef struct nvsp_5_subchannel_request_
919 uint32_t num_subchannels;
920 } __packed nvsp_5_subchannel_request;
922 typedef struct nvsp_5_subchannel_complete_
925 /* Actual number of subchannels allocated */
926 uint32_t num_subchannels;
927 } __packed nvsp_5_subchannel_complete;
929 typedef struct nvsp_5_send_indirect_table_
931 /* The number of entries in the send indirection table */
934 * The offset of the send indireciton table from top of
935 * this struct. The send indirection table tells which channel
936 * to put the send traffic on. Each entry is a channel number.
939 } __packed nvsp_5_send_indirect_table;
941 typedef union nvsp_1_msg_uber_ {
942 nvsp_1_msg_send_ndis_version send_ndis_vers;
944 nvsp_1_msg_send_rx_buf send_rx_buf;
945 nvsp_1_msg_send_rx_buf_complete send_rx_buf_complete;
946 nvsp_1_msg_revoke_rx_buf revoke_rx_buf;
948 nvsp_1_msg_send_send_buf send_send_buf;
949 nvsp_1_msg_send_send_buf_complete send_send_buf_complete;
950 nvsp_1_msg_revoke_send_buf revoke_send_buf;
952 nvsp_1_msg_send_rndis_pkt send_rndis_pkt;
953 nvsp_1_msg_send_rndis_pkt_complete send_rndis_pkt_complete;
954 } __packed nvsp_1_msg_uber;
957 typedef union nvsp_2_msg_uber_ {
958 nvsp_2_msg_send_ndis_config send_ndis_config;
960 nvsp_2_msg_send_chimney_buf send_chimney_buf;
961 nvsp_2_msg_send_chimney_buf_complete send_chimney_buf_complete;
962 nvsp_2_msg_revoke_chimney_buf revoke_chimney_buf;
964 nvsp_2_msg_resume_chimney_rx_indication resume_chimney_rx_indication;
965 nvsp_2_msg_terminate_chimney terminate_chimney;
966 nvsp_2_msg_terminate_chimney_complete terminate_chimney_complete;
967 nvsp_2_msg_indicate_chimney_event indicate_chimney_event;
969 nvsp_2_msg_send_chimney_pkt send_chimney_packet;
970 nvsp_2_msg_send_chimney_pkt_complete send_chimney_packet_complete;
971 nvsp_2_msg_post_chimney_rx_request post_chimney_rx_request;
972 nvsp_2_msg_post_chimney_rx_request_complete
973 post_chimney_rx_request_complete;
975 nvsp_2_msg_alloc_rx_buf alloc_rx_buffer;
976 nvsp_2_msg_alloc_rx_buf_complete alloc_rx_buffer_complete;
977 nvsp_2_msg_free_rx_buf free_rx_buffer;
979 nvsp_2_msg_send_vmq_rndis_pkt send_vmq_rndis_pkt;
980 nvsp_2_msg_send_vmq_rndis_pkt_complete send_vmq_rndis_pkt_complete;
981 nvsp_2_msg_alloc_chimney_handle alloc_chimney_handle;
982 nvsp_2_msg_alloc_chimney_handle_complete alloc_chimney_handle_complete;
983 } __packed nvsp_2_msg_uber;
985 typedef union nvsp_5_msg_uber_
987 nvsp_5_subchannel_request subchannel_request;
988 nvsp_5_subchannel_complete subchn_complete;
989 nvsp_5_send_indirect_table send_table;
990 } __packed nvsp_5_msg_uber;
992 typedef union nvsp_all_msgs_ {
993 nvsp_msg_init_uber init_msgs;
994 nvsp_1_msg_uber vers_1_msgs;
995 nvsp_2_msg_uber vers_2_msgs;
996 nvsp_5_msg_uber vers_5_msgs;
997 } __packed nvsp_all_msgs;
1002 typedef struct nvsp_msg_ {
1005 } __packed nvsp_msg;
1009 * The following arguably belongs in a separate header file
1016 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
1017 #define NETVSC_SEND_BUFFER_ID 0xface
1019 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
1020 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
1022 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
1024 #define NETVSC_RECEIVE_SG_COUNT 1
1026 /* Preallocated receive packets */
1027 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
1030 * Maximum MTU we permit to be configured for a netvsc interface.
1031 * When the code was developed, a max MTU of 12232 was tested and
1032 * proven to work. 9K is a reasonable maximum for an Ethernet.
1034 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
1036 #define NETVSC_PACKET_SIZE PAGE_SIZE
1037 #define VRSS_SEND_TABLE_SIZE 16
1044 * Per netvsc channel-specific
1046 typedef struct netvsc_dev_ {
1047 struct hn_softc *sc;
1049 /* Send buffer allocated by us but manages by NetVSP */
1051 uint32_t send_buf_size;
1052 uint32_t send_buf_gpadl_handle;
1053 uint32_t send_section_size;
1054 uint32_t send_section_count;
1055 unsigned long bitsmap_words;
1056 unsigned long *send_section_bitsmap;
1058 /* Receive buffer allocated by us but managed by NetVSP */
1060 uint32_t rx_buf_size;
1061 uint32_t rx_buf_gpadl_handle;
1062 uint32_t rx_section_count;
1063 nvsp_1_rx_buf_section *rx_sections;
1065 /* Used for NetVSP initialization protocol */
1066 struct sema channel_init_sema;
1067 nvsp_msg channel_init_packet;
1069 nvsp_msg revoke_packet;
1070 /*uint8_t hw_mac_addr[ETHER_ADDR_LEN];*/
1072 /* Holds rndis device info */
1076 /* Negotiated NVSP version */
1077 uint32_t nvsp_version;
1079 uint32_t num_channel;
1081 struct hyperv_dma rxbuf_dma;
1082 struct hyperv_dma txbuf_dma;
1083 uint32_t vrss_send_table[VRSS_SEND_TABLE_SIZE];
1086 struct vmbus_channel;
1088 typedef void (*pfn_on_send_rx_completion)(struct vmbus_channel *, void *);
1090 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
1091 #define NETVSC_PACKET_MAXPAGE 32
1093 #define NETVSC_VLAN_PRIO_MASK 0xe000
1094 #define NETVSC_VLAN_PRIO_SHIFT 13
1095 #define NETVSC_VLAN_VID_MASK 0x0fff
1102 #define TRANSPORT_TYPE_NOT_IP 0
1103 #define TRANSPORT_TYPE_IPV4_TCP ((TYPE_IPV4 << 16) | TYPE_TCP)
1104 #define TRANSPORT_TYPE_IPV4_UDP ((TYPE_IPV4 << 16) | TYPE_UDP)
1105 #define TRANSPORT_TYPE_IPV6_TCP ((TYPE_IPV6 << 16) | TYPE_TCP)
1106 #define TRANSPORT_TYPE_IPV6_UDP ((TYPE_IPV6 << 16) | TYPE_UDP)
1109 #define BITS_PER_LONG 64
1111 #define BITS_PER_LONG 32
1114 typedef struct netvsc_packet_ {
1115 uint8_t is_data_pkt; /* One byte */
1122 uint64_t rx_completion_tid;
1123 void *rx_completion_context;
1124 /* This is no longer used */
1125 pfn_on_send_rx_completion on_rx_completion;
1128 uint64_t send_completion_tid;
1129 void *send_completion_context;
1130 /* Still used in netvsc and filter code */
1131 pfn_on_send_rx_completion on_send_completion;
1134 uint32_t send_buf_section_idx;
1135 uint32_t send_buf_section_size;
1138 uint32_t tot_data_buf_len;
1141 struct vmbus_gpa gpa[NETVSC_PACKET_MAXPAGE];
1145 uint8_t mac_addr[6]; /* Assumption unsigned long */
1147 } netvsc_device_info;
1149 #ifndef HN_USE_TXDESC_BUFRING
1151 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
1159 struct ifnet *hn_ifp;
1160 struct hn_tx_ring *hn_txr;
1164 /* Trust csum verification on host side */
1165 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
1166 struct lro_ctrl hn_lro;
1171 u_long hn_csum_trusted;
1172 u_long hn_lro_tried;
1173 u_long hn_small_pkts;
1177 /* Rarely used stuffs */
1178 struct sysctl_oid *hn_rx_sysctl_tree;
1180 } __aligned(CACHE_LINE_SIZE);
1182 #define HN_TRUST_HCSUM_IP 0x0001
1183 #define HN_TRUST_HCSUM_TCP 0x0002
1184 #define HN_TRUST_HCSUM_UDP 0x0004
1186 #define HN_RX_FLAG_ATTACHED 0x1
1189 #ifndef HN_USE_TXDESC_BUFRING
1190 struct mtx hn_txlist_spin;
1191 struct hn_txdesc_list hn_txlist;
1193 struct buf_ring *hn_txdesc_br;
1196 int hn_txdesc_avail;
1197 u_short hn_has_txeof;
1198 u_short hn_txdone_cnt;
1201 void (*hn_txeof)(struct hn_tx_ring *);
1202 struct taskqueue *hn_tx_taskq;
1203 struct task hn_tx_task;
1204 struct task hn_txeof_task;
1206 struct buf_ring *hn_mbuf_br;
1210 struct mtx hn_tx_lock;
1211 struct hn_softc *hn_sc;
1212 struct vmbus_channel *hn_chan;
1214 int hn_direct_tx_size;
1215 int hn_tx_chimney_size;
1216 bus_dma_tag_t hn_tx_data_dtag;
1217 uint64_t hn_csum_assist;
1219 u_long hn_no_txdescs;
1220 u_long hn_send_failed;
1221 u_long hn_txdma_failed;
1222 u_long hn_tx_collapsed;
1223 u_long hn_tx_chimney_tried;
1224 u_long hn_tx_chimney;
1227 /* Rarely used stuffs */
1228 struct hn_txdesc *hn_txdesc;
1229 bus_dma_tag_t hn_tx_rndis_dtag;
1230 struct sysctl_oid *hn_tx_sysctl_tree;
1232 } __aligned(CACHE_LINE_SIZE);
1234 #define HN_TX_FLAG_ATTACHED 0x1
1237 * Device-specific softc structure
1239 typedef struct hn_softc {
1240 struct ifnet *hn_ifp;
1241 struct arpcom arpcom;
1242 struct ifmedia hn_media;
1249 /* See hv_netvsc_drv_freebsd.c for rules on how to use */
1251 netvsc_dev *net_dev;
1252 struct vmbus_channel *hn_prichan;
1255 int hn_rx_ring_inuse;
1256 struct hn_rx_ring *hn_rx_ring;
1259 int hn_tx_ring_inuse;
1260 struct hn_tx_ring *hn_tx_ring;
1263 int hn_tx_chimney_max;
1264 struct taskqueue *hn_tx_taskq;
1265 struct sysctl_oid *hn_tx_sysctl_tree;
1266 struct sysctl_oid *hn_rx_sysctl_tree;
1272 extern int hv_promisc_mode;
1274 void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
1275 netvsc_dev *hv_nv_on_device_add(struct hn_softc *sc,
1276 void *additional_info, struct hn_rx_ring *rxr);
1277 int hv_nv_on_device_remove(struct hn_softc *sc,
1278 boolean_t destroy_channel);
1279 int hv_nv_on_send(struct vmbus_channel *chan, netvsc_packet *pkt);
1280 int hv_nv_get_next_send_section(netvsc_dev *net_dev);
1281 void hv_nv_subchan_attach(struct vmbus_channel *chan,
1282 struct hn_rx_ring *rxr);
1284 #endif /* __HV_NET_VSC_H__ */