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>
43 #include <sys/malloc.h>
44 #include <sys/queue.h>
47 #include <machine/bus.h>
49 #include <sys/bus_dma.h>
51 #include <netinet/in.h>
52 #include <netinet/tcp_lro.h>
55 #include <net/if_media.h>
57 #include <dev/hyperv/include/hyperv.h>
59 MALLOC_DECLARE(M_NETVSC);
61 #define NVSP_INVALID_PROTOCOL_VERSION (0xFFFFFFFF)
63 #define NVSP_PROTOCOL_VERSION_1 2
64 #define NVSP_PROTOCOL_VERSION_2 0x30002
65 #define NVSP_PROTOCOL_VERSION_4 0x40000
66 #define NVSP_PROTOCOL_VERSION_5 0x50000
67 #define NVSP_MIN_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_1)
68 #define NVSP_MAX_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_2)
70 #define NVSP_PROTOCOL_VERSION_CURRENT NVSP_PROTOCOL_VERSION_2
72 #define VERSION_4_OFFLOAD_SIZE 22
74 #define NVSP_OPERATIONAL_STATUS_OK (0x00000000)
75 #define NVSP_OPERATIONAL_STATUS_DEGRADED (0x00000001)
76 #define NVSP_OPERATIONAL_STATUS_NONRECOVERABLE (0x00000002)
77 #define NVSP_OPERATIONAL_STATUS_NO_CONTACT (0x00000003)
78 #define NVSP_OPERATIONAL_STATUS_LOST_COMMUNICATION (0x00000004)
81 * Maximun number of transfer pages (packets) the VSP will use on a receive
83 #define NVSP_MAX_PACKETS_PER_RECEIVE 375
86 typedef enum nvsp_msg_type_ {
87 nvsp_msg_type_none = 0,
92 nvsp_msg_type_init = 1,
93 nvsp_msg_type_init_complete = 2,
95 nvsp_version_msg_start = 100,
100 nvsp_msg_1_type_send_ndis_vers = nvsp_version_msg_start,
102 nvsp_msg_1_type_send_rx_buf,
103 nvsp_msg_1_type_send_rx_buf_complete,
104 nvsp_msg_1_type_revoke_rx_buf,
106 nvsp_msg_1_type_send_send_buf,
107 nvsp_msg_1_type_send_send_buf_complete,
108 nvsp_msg_1_type_revoke_send_buf,
110 nvsp_msg_1_type_send_rndis_pkt,
111 nvsp_msg_1_type_send_rndis_pkt_complete,
116 nvsp_msg_2_type_send_chimney_delegated_buf,
117 nvsp_msg_2_type_send_chimney_delegated_buf_complete,
118 nvsp_msg_2_type_revoke_chimney_delegated_buf,
120 nvsp_msg_2_type_resume_chimney_rx_indication,
122 nvsp_msg_2_type_terminate_chimney,
123 nvsp_msg_2_type_terminate_chimney_complete,
125 nvsp_msg_2_type_indicate_chimney_event,
127 nvsp_msg_2_type_send_chimney_packet,
128 nvsp_msg_2_type_send_chimney_packet_complete,
130 nvsp_msg_2_type_post_chimney_rx_request,
131 nvsp_msg_2_type_post_chimney_rx_request_complete,
133 nvsp_msg_2_type_alloc_rx_buf,
134 nvsp_msg_2_type_alloc_rx_buf_complete,
136 nvsp_msg_2_type_free_rx_buf,
138 nvsp_msg_2_send_vmq_rndis_pkt,
139 nvsp_msg_2_send_vmq_rndis_pkt_complete,
141 nvsp_msg_2_type_send_ndis_config,
143 nvsp_msg_2_type_alloc_chimney_handle,
144 nvsp_msg_2_type_alloc_chimney_handle_complete,
147 typedef enum nvsp_status_ {
148 nvsp_status_none = 0,
152 nvsp_status_prot_vers_range_too_new,
154 nvsp_status_prot_vers_range_too_old,
155 nvsp_status_invalid_rndis_pkt,
160 typedef struct nvsp_msg_hdr_ {
162 } __packed nvsp_msg_hdr;
169 * This message is used by the VSC to initialize the channel
170 * after the channels has been opened. This message should
171 * never include anything other then versioning (i.e. this
172 * message will be the same for ever).
174 * Forever is a long time. The values have been redefined
175 * in Win7 to indicate major and minor protocol version
178 typedef struct nvsp_msg_init_ {
181 uint16_t minor_protocol_version;
182 uint16_t major_protocol_version;
184 /* Formerly min_protocol_version */
185 uint32_t protocol_version;
187 /* Formerly max_protocol_version */
188 uint32_t protocol_version_2;
189 } __packed nvsp_msg_init;
192 * This message is used by the VSP to complete the initialization
193 * of the channel. This message should never include anything other
194 * then versioning (i.e. this message will be the same forever).
196 typedef struct nvsp_msg_init_complete_ {
198 uint32_t negotiated_prot_vers;
199 uint32_t max_mdl_chain_len;
201 } __packed nvsp_msg_init_complete;
203 typedef union nvsp_msg_init_uber_ {
205 nvsp_msg_init_complete init_compl;
206 } __packed nvsp_msg_init_uber;
213 * This message is used by the VSC to send the NDIS version
214 * to the VSP. The VSP can use this information when handling
215 * OIDs sent by the VSC.
217 typedef struct nvsp_1_msg_send_ndis_version_ {
218 uint32_t ndis_major_vers;
220 uint32_t ndis_minor_vers;
221 } __packed nvsp_1_msg_send_ndis_version;
224 * This message is used by the VSC to send a receive buffer
225 * to the VSP. The VSP can then use the receive buffer to
226 * send data to the VSC.
228 typedef struct nvsp_1_msg_send_rx_buf_ {
229 uint32_t gpadl_handle;
231 } __packed nvsp_1_msg_send_rx_buf;
233 typedef struct nvsp_1_rx_buf_section_ {
235 uint32_t sub_allocation_size;
236 uint32_t num_sub_allocations;
238 } __packed nvsp_1_rx_buf_section;
241 * This message is used by the VSP to acknowledge a receive
242 * buffer send by the VSC. This message must be sent by the
243 * VSP before the VSP uses the receive buffer.
245 typedef struct nvsp_1_msg_send_rx_buf_complete_ {
247 uint32_t num_sections;
250 * The receive buffer is split into two parts, a large
251 * suballocation section and a small suballocation
252 * section. These sections are then suballocated by a
255 * For example, the following break up of the receive
256 * buffer has 6 large suballocations and 10 small
259 * | Large Section | | Small Section |
260 * ------------------------------------------------------------
261 * | | | | | | | | | | | | | | | | | |
263 * LargeOffset SmallOffset
265 nvsp_1_rx_buf_section sections[1];
267 } __packed nvsp_1_msg_send_rx_buf_complete;
270 * This message is sent by the VSC to revoke the receive buffer.
271 * After the VSP completes this transaction, the VSP should never
272 * use the receive buffer again.
274 typedef struct nvsp_1_msg_revoke_rx_buf_ {
276 } __packed nvsp_1_msg_revoke_rx_buf;
279 * This message is used by the VSC to send a send buffer
280 * to the VSP. The VSC can then use the send buffer to
281 * send data to the VSP.
283 typedef struct nvsp_1_msg_send_send_buf_ {
284 uint32_t gpadl_handle;
286 } __packed nvsp_1_msg_send_send_buf;
289 * This message is used by the VSP to acknowledge a send
290 * buffer sent by the VSC. This message must be sent by the
291 * VSP before the VSP uses the sent buffer.
293 typedef struct nvsp_1_msg_send_send_buf_complete_ {
297 * The VSC gets to choose the size of the send buffer and
298 * the VSP gets to choose the sections size of the buffer.
299 * This was done to enable dynamic reconfigurations when
300 * the cost of GPA-direct buffers decreases.
302 uint32_t section_size;
303 } __packed nvsp_1_msg_send_send_buf_complete;
306 * This message is sent by the VSC to revoke the send buffer.
307 * After the VSP completes this transaction, the vsp should never
308 * use the send buffer again.
310 typedef struct nvsp_1_msg_revoke_send_buf_ {
312 } __packed nvsp_1_msg_revoke_send_buf;
315 * This message is used by both the VSP and the VSC to send
316 * an RNDIS message to the opposite channel endpoint.
318 typedef struct nvsp_1_msg_send_rndis_pkt_ {
320 * This field is specified by RNIDS. They assume there's
321 * two different channels of communication. However,
322 * the Network VSP only has one. Therefore, the channel
323 * travels with the RNDIS packet.
328 * This field is used to send part or all of the data
329 * through a send buffer. This values specifies an
330 * index into the send buffer. If the index is
331 * 0xFFFFFFFF, then the send buffer is not being used
332 * and all of the data was sent through other VMBus
335 uint32_t send_buf_section_idx;
336 uint32_t send_buf_section_size;
337 } __packed nvsp_1_msg_send_rndis_pkt;
340 * This message is used by both the VSP and the VSC to complete
341 * a RNDIS message to the opposite channel endpoint. At this
342 * point, the initiator of this message cannot use any resources
343 * associated with the original RNDIS packet.
345 typedef struct nvsp_1_msg_send_rndis_pkt_complete_ {
347 } __packed nvsp_1_msg_send_rndis_pkt_complete;
355 * This message is used by the VSC to send the NDIS version
356 * to the VSP. The VSP can use this information when handling
357 * OIDs sent by the VSC.
359 typedef struct nvsp_2_netvsc_capabilities_ {
364 uint64_t chimney : 1;
366 uint64_t ieee8021q : 1;
367 uint64_t correlationid : 1;
368 uint64_t teaming : 1;
371 } __packed nvsp_2_netvsc_capabilities;
373 typedef struct nvsp_2_msg_send_ndis_config_ {
376 nvsp_2_netvsc_capabilities capabilities;
377 } __packed nvsp_2_msg_send_ndis_config;
380 * NvspMessage2TypeSendChimneyDelegatedBuffer
382 typedef struct nvsp_2_msg_send_chimney_buf_
385 * On WIN7 beta, delegated_obj_max_size is defined as a uint32_t
386 * Since WIN7 RC, it was split into two uint16_t. To have the same
387 * struct layout, delegated_obj_max_size shall be the first field.
389 uint16_t delegated_obj_max_size;
392 * The revision # of chimney protocol used between NVSC and NVSP.
394 * This revision is NOT related to the chimney revision between
395 * NDIS protocol and miniport drivers.
399 uint32_t gpadl_handle;
400 } __packed nvsp_2_msg_send_chimney_buf;
403 /* Unsupported chimney revision 0 (only present in WIN7 beta) */
404 #define NVSP_CHIMNEY_REVISION_0 0
406 /* WIN7 Beta Chimney QFE */
407 #define NVSP_CHIMNEY_REVISION_1 1
409 /* The chimney revision since WIN7 RC */
410 #define NVSP_CHIMNEY_REVISION_2 2
414 * NvspMessage2TypeSendChimneyDelegatedBufferComplete
416 typedef struct nvsp_2_msg_send_chimney_buf_complete_ {
420 * Maximum number outstanding sends and pre-posted receives.
422 * NVSC should not post more than SendQuota/ReceiveQuota packets.
423 * Otherwise, it can block the non-chimney path for an indefinite
425 * (since chimney sends/receives are affected by the remote peer).
427 * Note: NVSP enforces the quota restrictions on a per-VMBCHANNEL
428 * basis. It doesn't enforce the restriction separately for chimney
429 * send/receive. If NVSC doesn't voluntarily enforce "SendQuota",
430 * it may kill its own network connectivity.
434 } __packed nvsp_2_msg_send_chimney_buf_complete;
437 * NvspMessage2TypeRevokeChimneyDelegatedBuffer
439 typedef struct nvsp_2_msg_revoke_chimney_buf_ {
440 uint32_t gpadl_handle;
441 } __packed nvsp_2_msg_revoke_chimney_buf;
444 #define NVSP_CHIMNEY_OBJECT_TYPE_NEIGHBOR 0
445 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH4 1
446 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH6 2
447 #define NVSP_CHIMNEY_OBJECT_TYPE_TCP 3
450 * NvspMessage2TypeAllocateChimneyHandle
452 typedef struct nvsp_2_msg_alloc_chimney_handle_ {
453 uint64_t vsc_context;
454 uint32_t object_type;
455 } __packed nvsp_2_msg_alloc_chimney_handle;
458 * NvspMessage2TypeAllocateChimneyHandleComplete
460 typedef struct nvsp_2_msg_alloc_chimney_handle_complete_ {
462 } __packed nvsp_2_msg_alloc_chimney_handle_complete;
466 * NvspMessage2TypeResumeChimneyRXIndication
468 typedef struct nvsp_2_msg_resume_chimney_rx_indication {
470 * Handle identifying the offloaded connection
472 uint32_t vsp_tcp_handle;
473 } __packed nvsp_2_msg_resume_chimney_rx_indication;
476 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_FIRST_STAGE (0x01u)
477 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_RESERVED (~(0x01u))
480 * NvspMessage2TypeTerminateChimney
482 typedef struct nvsp_2_msg_terminate_chimney_ {
484 * Handle identifying the offloaded object
489 * Terminate Offload Flags
491 * When set to 0, terminate the offload at the destination NIC
492 * Bit 1-31: Reserved, shall be zero
498 * This field is valid only when bit 0 of flags is clear.
499 * It specifies the index into the premapped delegated
500 * object buffer. The buffer was sent through the
501 * NvspMessage2TypeSendChimneyDelegatedBuffer
502 * message at initialization time.
504 * NVSP will write the delegated state into the delegated
505 * buffer upon upload completion.
510 * This field is valid only when bit 0 of flags is set.
512 * The seqence number of the most recently accepted RX
513 * indication when VSC sets its TCP context into
514 * "terminating" state.
516 * This allows NVSP to determines if there are any in-flight
517 * RX indications for which the acceptance state is still
520 uint64_t last_accepted_rx_seq_no;
522 } __packed nvsp_2_msg_terminate_chimney;
525 #define NVSP_TERMINATE_CHIMNEY_COMPLETE_FLAG_DATA_CORRUPTED 0x0000001u
528 * NvspMessage2TypeTerminateChimneyComplete
530 typedef struct nvsp_2_msg_terminate_chimney_complete_ {
531 uint64_t vsc_context;
533 } __packed nvsp_2_msg_terminate_chimney_complete;
536 * NvspMessage2TypeIndicateChimneyEvent
538 typedef struct nvsp_2_msg_indicate_chimney_event_ {
540 * When VscTcpContext is 0, event_type is an NDIS_STATUS event code
541 * Otherwise, EventType is an TCP connection event (defined in
542 * NdisTcpOffloadEventHandler chimney DDK document).
547 * When VscTcpContext is 0, EventType is an NDIS_STATUS event code
548 * Otherwise, EventType is an TCP connection event specific information
549 * (defined in NdisTcpOffloadEventHandler chimney DDK document).
551 uint32_t event_specific_info;
554 * If not 0, the event is per-TCP connection event. This field
555 * contains the VSC's TCP context.
556 * If 0, the event indication is global.
558 uint64_t vsc_tcp_context;
559 } __packed nvsp_2_msg_indicate_chimney_event;
562 #define NVSP_1_CHIMNEY_SEND_INVALID_OOB_INDEX 0xffffu
563 #define NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX 0xffffffff
566 * NvspMessage2TypeSendChimneyPacket
568 typedef struct nvsp_2_msg_send_chimney_pkt_ {
570 * Identify the TCP connection for which this chimney send is
572 uint32_t vsp_tcp_handle;
575 * This field is used to send part or all of the data
576 * through a send buffer. This values specifies an
577 * index into the send buffer. If the index is
578 * 0xFFFF, then the send buffer is not being used
579 * and all of the data was sent through other VMBus
582 uint16_t send_buf_section_index;
583 uint16_t send_buf_section_size;
587 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
588 * then there is no OOB data.
590 * This field shall be always 0xFFFFFFFF for now. It is reserved for
593 uint16_t oob_data_index;
596 * DisconnectFlags = 0
597 * Normal chimney send. See MiniportTcpOffloadSend for details.
599 * DisconnectFlags = TCP_DISCONNECT_GRACEFUL_CLOSE (0x01)
600 * Graceful disconnect. See MiniportTcpOffloadDisconnect for details.
602 * DisconnectFlags = TCP_DISCONNECT_ABORTIVE_CLOSE (0x02)
603 * Abortive disconnect. See MiniportTcpOffloadDisconnect for details.
605 uint16_t disconnect_flags;
608 } __packed nvsp_2_msg_send_chimney_pkt;
611 * NvspMessage2TypeSendChimneyPacketComplete
613 typedef struct nvsp_2_msg_send_chimney_pkt_complete_ {
615 * The NDIS_STATUS for the chimney send
620 * Number of bytes that have been sent to the peer (and ACKed by the peer).
622 uint32_t bytes_transferred;
623 } __packed nvsp_2_msg_send_chimney_pkt_complete;
626 #define NVSP_1_CHIMNEY_RECV_FLAG_NO_PUSH 0x0001u
627 #define NVSP_1_CHIMNEY_RECV_INVALID_OOB_INDEX 0xffffu
630 * NvspMessage2TypePostChimneyRecvRequest
632 typedef struct nvsp_2_msg_post_chimney_rx_request_ {
634 * Identify the TCP connection which this chimney receive request
637 uint32_t vsp_tcp_handle;
641 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
642 * then there is no OOB data.
644 * This field shall be always 0xFFFFFFFF for now. It is reserved for
647 uint32_t oob_data_index;
651 * When it is set, this is a "no-push" receive.
652 * When it is clear, this is a "push" receive.
654 * Bit 1-15: Reserved and shall be zero
659 * For debugging and diagnoses purpose.
660 * The SeqNo is per TCP connection and starts from 0.
663 } __packed nvsp_2_msg_post_chimney_rx_request;
666 * NvspMessage2TypePostChimneyRecvRequestComplete
668 typedef struct nvsp_2_msg_post_chimney_rx_request_complete_ {
670 * The NDIS_STATUS for the chimney send
675 * Number of bytes that have been sent to the peer (and ACKed by
678 uint32_t bytes_xferred;
679 } __packed nvsp_2_msg_post_chimney_rx_request_complete;
682 * NvspMessage2TypeAllocateReceiveBuffer
684 typedef struct nvsp_2_msg_alloc_rx_buf_ {
686 * Allocation ID to match the allocation request and response
688 uint32_t allocation_id;
691 * Length of the VM shared memory receive buffer that needs to
695 } __packed nvsp_2_msg_alloc_rx_buf;
698 * NvspMessage2TypeAllocateReceiveBufferComplete
700 typedef struct nvsp_2_msg_alloc_rx_buf_complete_ {
702 * The NDIS_STATUS code for buffer allocation
707 * Allocation ID from NVSP_2_MESSAGE_ALLOCATE_RECEIVE_BUFFER
709 uint32_t allocation_id;
712 * GPADL handle for the allocated receive buffer
714 uint32_t gpadl_handle;
717 * Receive buffer ID that is further used in
718 * NvspMessage2SendVmqRndisPacket
721 } __packed nvsp_2_msg_alloc_rx_buf_complete;
724 * NvspMessage2TypeFreeReceiveBuffer
726 typedef struct nvsp_2_msg_free_rx_buf_ {
728 * Receive buffer ID previous returned in
729 * NvspMessage2TypeAllocateReceiveBufferComplete message
732 } __packed nvsp_2_msg_free_rx_buf;
735 * This structure is used in defining the buffers in
736 * NVSP_2_MESSAGE_SEND_VMQ_RNDIS_PACKET structure
738 typedef struct nvsp_xfer_page_range_ {
740 * Specifies the ID of the receive buffer that has the buffer. This
741 * ID can be the general receive buffer ID specified in
742 * NvspMessage1TypeSendReceiveBuffer or it can be the shared memory
743 * receive buffer ID allocated by the VSC and specified in
744 * NvspMessage2TypeAllocateReceiveBufferComplete message
746 uint64_t xfer_page_set_id;
754 * Offset in bytes from the beginning of the buffer
756 uint32_t byte_offset;
757 } __packed nvsp_xfer_page_range;
760 * NvspMessage2SendVmqRndisPacket
762 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_ {
764 * This field is specified by RNIDS. They assume there's
765 * two different channels of communication. However,
766 * the Network VSP only has one. Therefore, the channel
767 * travels with the RNDIS packet. It must be RMC_DATA
769 uint32_t channel_type;
772 * Only the Range element corresponding to the RNDIS header of
773 * the first RNDIS message in the multiple RNDIS messages sent
774 * in one NVSP message. Information about the data portions as well
775 * as the subsequent RNDIS messages in the same NVSP message are
776 * embedded in the RNDIS header itself
778 nvsp_xfer_page_range range;
779 } __packed nvsp_2_msg_send_vmq_rndis_pkt;
782 * This message is used by the VSC to complete
783 * a RNDIS VMQ message to the VSP. At this point,
784 * the initiator of this message can use any resources
785 * associated with the original RNDIS VMQ packet.
787 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_complete_
790 } __packed nvsp_2_msg_send_vmq_rndis_pkt_complete;
793 typedef union nvsp_1_msg_uber_ {
794 nvsp_1_msg_send_ndis_version send_ndis_vers;
796 nvsp_1_msg_send_rx_buf send_rx_buf;
797 nvsp_1_msg_send_rx_buf_complete send_rx_buf_complete;
798 nvsp_1_msg_revoke_rx_buf revoke_rx_buf;
800 nvsp_1_msg_send_send_buf send_send_buf;
801 nvsp_1_msg_send_send_buf_complete send_send_buf_complete;
802 nvsp_1_msg_revoke_send_buf revoke_send_buf;
804 nvsp_1_msg_send_rndis_pkt send_rndis_pkt;
805 nvsp_1_msg_send_rndis_pkt_complete send_rndis_pkt_complete;
806 } __packed nvsp_1_msg_uber;
809 typedef union nvsp_2_msg_uber_ {
810 nvsp_2_msg_send_ndis_config send_ndis_config;
812 nvsp_2_msg_send_chimney_buf send_chimney_buf;
813 nvsp_2_msg_send_chimney_buf_complete send_chimney_buf_complete;
814 nvsp_2_msg_revoke_chimney_buf revoke_chimney_buf;
816 nvsp_2_msg_resume_chimney_rx_indication resume_chimney_rx_indication;
817 nvsp_2_msg_terminate_chimney terminate_chimney;
818 nvsp_2_msg_terminate_chimney_complete terminate_chimney_complete;
819 nvsp_2_msg_indicate_chimney_event indicate_chimney_event;
821 nvsp_2_msg_send_chimney_pkt send_chimney_packet;
822 nvsp_2_msg_send_chimney_pkt_complete send_chimney_packet_complete;
823 nvsp_2_msg_post_chimney_rx_request post_chimney_rx_request;
824 nvsp_2_msg_post_chimney_rx_request_complete
825 post_chimney_rx_request_complete;
827 nvsp_2_msg_alloc_rx_buf alloc_rx_buffer;
828 nvsp_2_msg_alloc_rx_buf_complete alloc_rx_buffer_complete;
829 nvsp_2_msg_free_rx_buf free_rx_buffer;
831 nvsp_2_msg_send_vmq_rndis_pkt send_vmq_rndis_pkt;
832 nvsp_2_msg_send_vmq_rndis_pkt_complete send_vmq_rndis_pkt_complete;
833 nvsp_2_msg_alloc_chimney_handle alloc_chimney_handle;
834 nvsp_2_msg_alloc_chimney_handle_complete alloc_chimney_handle_complete;
835 } __packed nvsp_2_msg_uber;
838 typedef union nvsp_all_msgs_ {
839 nvsp_msg_init_uber init_msgs;
840 nvsp_1_msg_uber vers_1_msgs;
841 nvsp_2_msg_uber vers_2_msgs;
842 } __packed nvsp_all_msgs;
847 typedef struct nvsp_msg_ {
854 * The following arguably belongs in a separate header file
861 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
862 #define NETVSC_SEND_BUFFER_ID 0xface
864 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
865 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
867 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
869 #define NETVSC_RECEIVE_SG_COUNT 1
871 /* Preallocated receive packets */
872 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
875 * Maximum MTU we permit to be configured for a netvsc interface.
876 * When the code was developed, a max MTU of 12232 was tested and
877 * proven to work. 9K is a reasonable maximum for an Ethernet.
879 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
881 #define NETVSC_PACKET_SIZE PAGE_SIZE
888 * Per netvsc channel-specific
890 typedef struct netvsc_dev_ {
891 struct hv_device *dev;
892 int num_outstanding_sends;
894 /* Send buffer allocated by us but manages by NetVSP */
896 uint32_t send_buf_size;
897 uint32_t send_buf_gpadl_handle;
898 uint32_t send_section_size;
899 uint32_t send_section_count;
900 unsigned long bitsmap_words;
901 unsigned long *send_section_bitsmap;
903 /* Receive buffer allocated by us but managed by NetVSP */
905 uint32_t rx_buf_size;
906 uint32_t rx_buf_gpadl_handle;
907 uint32_t rx_section_count;
908 nvsp_1_rx_buf_section *rx_sections;
910 /* Used for NetVSP initialization protocol */
911 struct sema channel_init_sema;
912 nvsp_msg channel_init_packet;
914 nvsp_msg revoke_packet;
915 /*uint8_t hw_mac_addr[HW_MACADDR_LEN];*/
917 /* Holds rndis device info */
920 hv_bool_uint8_t destroy;
921 /* Negotiated NVSP version */
922 uint32_t nvsp_version;
924 uint8_t callback_buf[NETVSC_PACKET_SIZE];
928 typedef void (*pfn_on_send_rx_completion)(void *);
930 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
931 #define NETVSC_PACKET_MAXPAGE 32
934 #define NETVSC_VLAN_PRIO_MASK 0xe000
935 #define NETVSC_VLAN_PRIO_SHIFT 13
936 #define NETVSC_VLAN_VID_MASK 0x0fff
943 #define TRANSPORT_TYPE_NOT_IP 0
944 #define TRANSPORT_TYPE_IPV4_TCP ((TYPE_IPV4 << 16) | TYPE_TCP)
945 #define TRANSPORT_TYPE_IPV4_UDP ((TYPE_IPV4 << 16) | TYPE_UDP)
946 #define TRANSPORT_TYPE_IPV6_TCP ((TYPE_IPV6 << 16) | TYPE_TCP)
947 #define TRANSPORT_TYPE_IPV6_UDP ((TYPE_IPV6 << 16) | TYPE_UDP)
950 #define BITS_PER_LONG 64
952 #define BITS_PER_LONG 32
955 typedef struct netvsc_packet_ {
956 struct hv_device *device;
957 hv_bool_uint8_t is_data_pkt; /* One byte */
964 uint64_t rx_completion_tid;
965 void *rx_completion_context;
966 /* This is no longer used */
967 pfn_on_send_rx_completion on_rx_completion;
970 uint64_t send_completion_tid;
971 void *send_completion_context;
972 /* Still used in netvsc and filter code */
973 pfn_on_send_rx_completion on_send_completion;
976 uint32_t send_buf_section_idx;
977 uint32_t send_buf_section_size;
980 uint32_t tot_data_buf_len;
982 uint32_t page_buf_count;
983 hv_vmbus_page_buffer page_buffers[NETVSC_PACKET_MAXPAGE];
987 uint8_t mac_addr[6]; /* Assumption unsigned long */
988 hv_bool_uint8_t link_state;
989 } netvsc_device_info;
992 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
995 * Device-specific softc structure
997 typedef struct hn_softc {
998 struct ifnet *hn_ifp;
999 struct arpcom arpcom;
1000 struct ifmedia hn_media;
1007 /* See hv_netvsc_drv_freebsd.c for rules on how to use */
1009 struct hv_device *hn_dev_obj;
1010 netvsc_dev *net_dev;
1013 struct hn_txdesc *hn_txdesc;
1014 bus_dma_tag_t hn_tx_data_dtag;
1015 bus_dma_tag_t hn_tx_rndis_dtag;
1016 int hn_tx_chimney_size;
1017 int hn_tx_chimney_max;
1019 struct mtx hn_txlist_spin;
1020 struct hn_txdesc_list hn_txlist;
1021 int hn_txdesc_avail;
1024 struct lro_ctrl hn_lro;
1027 /* Trust tcp segments verification on host side */
1028 int hn_trust_hosttcp;
1032 u_long hn_csum_trusted;
1033 u_long hn_lro_tried;
1034 u_long hn_small_pkts;
1035 u_long hn_no_txdescs;
1036 u_long hn_send_failed;
1037 u_long hn_txdma_failed;
1038 u_long hn_tx_collapsed;
1039 u_long hn_tx_chimney;
1046 extern int hv_promisc_mode;
1048 void netvsc_linkstatus_callback(struct hv_device *device_obj, uint32_t status);
1049 void netvsc_xmit_completion(void *context);
1050 void hv_nv_on_receive_completion(struct hv_device *device,
1051 uint64_t tid, uint32_t status);
1052 netvsc_dev *hv_nv_on_device_add(struct hv_device *device,
1053 void *additional_info);
1054 int hv_nv_on_device_remove(struct hv_device *device,
1055 boolean_t destroy_channel);
1056 int hv_nv_on_send(struct hv_device *device, netvsc_packet *pkt);
1057 int hv_nv_get_next_send_section(netvsc_dev *net_dev);
1059 #endif /* __HV_NET_VSC_H__ */