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 MALLOC_DECLARE(M_NETVSC);
63 #define NVSP_INVALID_PROTOCOL_VERSION (0xFFFFFFFF)
65 #define NVSP_PROTOCOL_VERSION_1 2
66 #define NVSP_PROTOCOL_VERSION_2 0x30002
67 #define NVSP_PROTOCOL_VERSION_4 0x40000
68 #define NVSP_PROTOCOL_VERSION_5 0x50000
69 #define NVSP_MIN_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_1)
70 #define NVSP_MAX_PROTOCOL_VERSION (NVSP_PROTOCOL_VERSION_2)
72 #define NVSP_PROTOCOL_VERSION_CURRENT NVSP_PROTOCOL_VERSION_2
74 #define VERSION_4_OFFLOAD_SIZE 22
76 #define NVSP_OPERATIONAL_STATUS_OK (0x00000000)
77 #define NVSP_OPERATIONAL_STATUS_DEGRADED (0x00000001)
78 #define NVSP_OPERATIONAL_STATUS_NONRECOVERABLE (0x00000002)
79 #define NVSP_OPERATIONAL_STATUS_NO_CONTACT (0x00000003)
80 #define NVSP_OPERATIONAL_STATUS_LOST_COMMUNICATION (0x00000004)
83 * Maximun number of transfer pages (packets) the VSP will use on a receive
85 #define NVSP_MAX_PACKETS_PER_RECEIVE 375
88 typedef enum nvsp_msg_type_ {
89 nvsp_msg_type_none = 0,
94 nvsp_msg_type_init = 1,
95 nvsp_msg_type_init_complete = 2,
97 nvsp_version_msg_start = 100,
102 nvsp_msg_1_type_send_ndis_vers = nvsp_version_msg_start,
104 nvsp_msg_1_type_send_rx_buf,
105 nvsp_msg_1_type_send_rx_buf_complete,
106 nvsp_msg_1_type_revoke_rx_buf,
108 nvsp_msg_1_type_send_send_buf,
109 nvsp_msg_1_type_send_send_buf_complete,
110 nvsp_msg_1_type_revoke_send_buf,
112 nvsp_msg_1_type_send_rndis_pkt,
113 nvsp_msg_1_type_send_rndis_pkt_complete,
118 nvsp_msg_2_type_send_chimney_delegated_buf,
119 nvsp_msg_2_type_send_chimney_delegated_buf_complete,
120 nvsp_msg_2_type_revoke_chimney_delegated_buf,
122 nvsp_msg_2_type_resume_chimney_rx_indication,
124 nvsp_msg_2_type_terminate_chimney,
125 nvsp_msg_2_type_terminate_chimney_complete,
127 nvsp_msg_2_type_indicate_chimney_event,
129 nvsp_msg_2_type_send_chimney_packet,
130 nvsp_msg_2_type_send_chimney_packet_complete,
132 nvsp_msg_2_type_post_chimney_rx_request,
133 nvsp_msg_2_type_post_chimney_rx_request_complete,
135 nvsp_msg_2_type_alloc_rx_buf,
136 nvsp_msg_2_type_alloc_rx_buf_complete,
138 nvsp_msg_2_type_free_rx_buf,
140 nvsp_msg_2_send_vmq_rndis_pkt,
141 nvsp_msg_2_send_vmq_rndis_pkt_complete,
143 nvsp_msg_2_type_send_ndis_config,
145 nvsp_msg_2_type_alloc_chimney_handle,
146 nvsp_msg_2_type_alloc_chimney_handle_complete,
149 typedef enum nvsp_status_ {
150 nvsp_status_none = 0,
154 nvsp_status_prot_vers_range_too_new,
156 nvsp_status_prot_vers_range_too_old,
157 nvsp_status_invalid_rndis_pkt,
162 typedef struct nvsp_msg_hdr_ {
164 } __packed nvsp_msg_hdr;
171 * This message is used by the VSC to initialize the channel
172 * after the channels has been opened. This message should
173 * never include anything other then versioning (i.e. this
174 * message will be the same for ever).
176 * Forever is a long time. The values have been redefined
177 * in Win7 to indicate major and minor protocol version
180 typedef struct nvsp_msg_init_ {
183 uint16_t minor_protocol_version;
184 uint16_t major_protocol_version;
186 /* Formerly min_protocol_version */
187 uint32_t protocol_version;
189 /* Formerly max_protocol_version */
190 uint32_t protocol_version_2;
191 } __packed nvsp_msg_init;
194 * This message is used by the VSP to complete the initialization
195 * of the channel. This message should never include anything other
196 * then versioning (i.e. this message will be the same forever).
198 typedef struct nvsp_msg_init_complete_ {
200 uint32_t negotiated_prot_vers;
201 uint32_t max_mdl_chain_len;
203 } __packed nvsp_msg_init_complete;
205 typedef union nvsp_msg_init_uber_ {
207 nvsp_msg_init_complete init_compl;
208 } __packed nvsp_msg_init_uber;
215 * This message is used by the VSC to send the NDIS version
216 * to the VSP. The VSP can use this information when handling
217 * OIDs sent by the VSC.
219 typedef struct nvsp_1_msg_send_ndis_version_ {
220 uint32_t ndis_major_vers;
222 uint32_t ndis_minor_vers;
223 } __packed nvsp_1_msg_send_ndis_version;
226 * This message is used by the VSC to send a receive buffer
227 * to the VSP. The VSP can then use the receive buffer to
228 * send data to the VSC.
230 typedef struct nvsp_1_msg_send_rx_buf_ {
231 uint32_t gpadl_handle;
233 } __packed nvsp_1_msg_send_rx_buf;
235 typedef struct nvsp_1_rx_buf_section_ {
237 uint32_t sub_allocation_size;
238 uint32_t num_sub_allocations;
240 } __packed nvsp_1_rx_buf_section;
243 * This message is used by the VSP to acknowledge a receive
244 * buffer send by the VSC. This message must be sent by the
245 * VSP before the VSP uses the receive buffer.
247 typedef struct nvsp_1_msg_send_rx_buf_complete_ {
249 uint32_t num_sections;
252 * The receive buffer is split into two parts, a large
253 * suballocation section and a small suballocation
254 * section. These sections are then suballocated by a
257 * For example, the following break up of the receive
258 * buffer has 6 large suballocations and 10 small
261 * | Large Section | | Small Section |
262 * ------------------------------------------------------------
263 * | | | | | | | | | | | | | | | | | |
265 * LargeOffset SmallOffset
267 nvsp_1_rx_buf_section sections[1];
269 } __packed nvsp_1_msg_send_rx_buf_complete;
272 * This message is sent by the VSC to revoke the receive buffer.
273 * After the VSP completes this transaction, the VSP should never
274 * use the receive buffer again.
276 typedef struct nvsp_1_msg_revoke_rx_buf_ {
278 } __packed nvsp_1_msg_revoke_rx_buf;
281 * This message is used by the VSC to send a send buffer
282 * to the VSP. The VSC can then use the send buffer to
283 * send data to the VSP.
285 typedef struct nvsp_1_msg_send_send_buf_ {
286 uint32_t gpadl_handle;
288 } __packed nvsp_1_msg_send_send_buf;
291 * This message is used by the VSP to acknowledge a send
292 * buffer sent by the VSC. This message must be sent by the
293 * VSP before the VSP uses the sent buffer.
295 typedef struct nvsp_1_msg_send_send_buf_complete_ {
299 * The VSC gets to choose the size of the send buffer and
300 * the VSP gets to choose the sections size of the buffer.
301 * This was done to enable dynamic reconfigurations when
302 * the cost of GPA-direct buffers decreases.
304 uint32_t section_size;
305 } __packed nvsp_1_msg_send_send_buf_complete;
308 * This message is sent by the VSC to revoke the send buffer.
309 * After the VSP completes this transaction, the vsp should never
310 * use the send buffer again.
312 typedef struct nvsp_1_msg_revoke_send_buf_ {
314 } __packed nvsp_1_msg_revoke_send_buf;
317 * This message is used by both the VSP and the VSC to send
318 * an RNDIS message to the opposite channel endpoint.
320 typedef struct nvsp_1_msg_send_rndis_pkt_ {
322 * This field is specified by RNIDS. They assume there's
323 * two different channels of communication. However,
324 * the Network VSP only has one. Therefore, the channel
325 * travels with the RNDIS packet.
330 * This field is used to send part or all of the data
331 * through a send buffer. This values specifies an
332 * index into the send buffer. If the index is
333 * 0xFFFFFFFF, then the send buffer is not being used
334 * and all of the data was sent through other VMBus
337 uint32_t send_buf_section_idx;
338 uint32_t send_buf_section_size;
339 } __packed nvsp_1_msg_send_rndis_pkt;
342 * This message is used by both the VSP and the VSC to complete
343 * a RNDIS message to the opposite channel endpoint. At this
344 * point, the initiator of this message cannot use any resources
345 * associated with the original RNDIS packet.
347 typedef struct nvsp_1_msg_send_rndis_pkt_complete_ {
349 } __packed nvsp_1_msg_send_rndis_pkt_complete;
357 * This message is used by the VSC to send the NDIS version
358 * to the VSP. The VSP can use this information when handling
359 * OIDs sent by the VSC.
361 typedef struct nvsp_2_netvsc_capabilities_ {
366 uint64_t chimney : 1;
368 uint64_t ieee8021q : 1;
369 uint64_t correlationid : 1;
370 uint64_t teaming : 1;
373 } __packed nvsp_2_netvsc_capabilities;
375 typedef struct nvsp_2_msg_send_ndis_config_ {
378 nvsp_2_netvsc_capabilities capabilities;
379 } __packed nvsp_2_msg_send_ndis_config;
382 * NvspMessage2TypeSendChimneyDelegatedBuffer
384 typedef struct nvsp_2_msg_send_chimney_buf_
387 * On WIN7 beta, delegated_obj_max_size is defined as a uint32_t
388 * Since WIN7 RC, it was split into two uint16_t. To have the same
389 * struct layout, delegated_obj_max_size shall be the first field.
391 uint16_t delegated_obj_max_size;
394 * The revision # of chimney protocol used between NVSC and NVSP.
396 * This revision is NOT related to the chimney revision between
397 * NDIS protocol and miniport drivers.
401 uint32_t gpadl_handle;
402 } __packed nvsp_2_msg_send_chimney_buf;
405 /* Unsupported chimney revision 0 (only present in WIN7 beta) */
406 #define NVSP_CHIMNEY_REVISION_0 0
408 /* WIN7 Beta Chimney QFE */
409 #define NVSP_CHIMNEY_REVISION_1 1
411 /* The chimney revision since WIN7 RC */
412 #define NVSP_CHIMNEY_REVISION_2 2
416 * NvspMessage2TypeSendChimneyDelegatedBufferComplete
418 typedef struct nvsp_2_msg_send_chimney_buf_complete_ {
422 * Maximum number outstanding sends and pre-posted receives.
424 * NVSC should not post more than SendQuota/ReceiveQuota packets.
425 * Otherwise, it can block the non-chimney path for an indefinite
427 * (since chimney sends/receives are affected by the remote peer).
429 * Note: NVSP enforces the quota restrictions on a per-VMBCHANNEL
430 * basis. It doesn't enforce the restriction separately for chimney
431 * send/receive. If NVSC doesn't voluntarily enforce "SendQuota",
432 * it may kill its own network connectivity.
436 } __packed nvsp_2_msg_send_chimney_buf_complete;
439 * NvspMessage2TypeRevokeChimneyDelegatedBuffer
441 typedef struct nvsp_2_msg_revoke_chimney_buf_ {
442 uint32_t gpadl_handle;
443 } __packed nvsp_2_msg_revoke_chimney_buf;
446 #define NVSP_CHIMNEY_OBJECT_TYPE_NEIGHBOR 0
447 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH4 1
448 #define NVSP_CHIMNEY_OBJECT_TYPE_PATH6 2
449 #define NVSP_CHIMNEY_OBJECT_TYPE_TCP 3
452 * NvspMessage2TypeAllocateChimneyHandle
454 typedef struct nvsp_2_msg_alloc_chimney_handle_ {
455 uint64_t vsc_context;
456 uint32_t object_type;
457 } __packed nvsp_2_msg_alloc_chimney_handle;
460 * NvspMessage2TypeAllocateChimneyHandleComplete
462 typedef struct nvsp_2_msg_alloc_chimney_handle_complete_ {
464 } __packed nvsp_2_msg_alloc_chimney_handle_complete;
468 * NvspMessage2TypeResumeChimneyRXIndication
470 typedef struct nvsp_2_msg_resume_chimney_rx_indication {
472 * Handle identifying the offloaded connection
474 uint32_t vsp_tcp_handle;
475 } __packed nvsp_2_msg_resume_chimney_rx_indication;
478 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_FIRST_STAGE (0x01u)
479 #define NVSP_2_MSG_TERMINATE_CHIMNEY_FLAGS_RESERVED (~(0x01u))
482 * NvspMessage2TypeTerminateChimney
484 typedef struct nvsp_2_msg_terminate_chimney_ {
486 * Handle identifying the offloaded object
491 * Terminate Offload Flags
493 * When set to 0, terminate the offload at the destination NIC
494 * Bit 1-31: Reserved, shall be zero
500 * This field is valid only when bit 0 of flags is clear.
501 * It specifies the index into the premapped delegated
502 * object buffer. The buffer was sent through the
503 * NvspMessage2TypeSendChimneyDelegatedBuffer
504 * message at initialization time.
506 * NVSP will write the delegated state into the delegated
507 * buffer upon upload completion.
512 * This field is valid only when bit 0 of flags is set.
514 * The seqence number of the most recently accepted RX
515 * indication when VSC sets its TCP context into
516 * "terminating" state.
518 * This allows NVSP to determines if there are any in-flight
519 * RX indications for which the acceptance state is still
522 uint64_t last_accepted_rx_seq_no;
524 } __packed nvsp_2_msg_terminate_chimney;
527 #define NVSP_TERMINATE_CHIMNEY_COMPLETE_FLAG_DATA_CORRUPTED 0x0000001u
530 * NvspMessage2TypeTerminateChimneyComplete
532 typedef struct nvsp_2_msg_terminate_chimney_complete_ {
533 uint64_t vsc_context;
535 } __packed nvsp_2_msg_terminate_chimney_complete;
538 * NvspMessage2TypeIndicateChimneyEvent
540 typedef struct nvsp_2_msg_indicate_chimney_event_ {
542 * When VscTcpContext is 0, event_type is an NDIS_STATUS event code
543 * Otherwise, EventType is an TCP connection event (defined in
544 * NdisTcpOffloadEventHandler chimney DDK document).
549 * When VscTcpContext is 0, EventType is an NDIS_STATUS event code
550 * Otherwise, EventType is an TCP connection event specific information
551 * (defined in NdisTcpOffloadEventHandler chimney DDK document).
553 uint32_t event_specific_info;
556 * If not 0, the event is per-TCP connection event. This field
557 * contains the VSC's TCP context.
558 * If 0, the event indication is global.
560 uint64_t vsc_tcp_context;
561 } __packed nvsp_2_msg_indicate_chimney_event;
564 #define NVSP_1_CHIMNEY_SEND_INVALID_OOB_INDEX 0xffffu
565 #define NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX 0xffffffff
568 * NvspMessage2TypeSendChimneyPacket
570 typedef struct nvsp_2_msg_send_chimney_pkt_ {
572 * Identify the TCP connection for which this chimney send is
574 uint32_t vsp_tcp_handle;
577 * This field is used to send part or all of the data
578 * through a send buffer. This values specifies an
579 * index into the send buffer. If the index is
580 * 0xFFFF, then the send buffer is not being used
581 * and all of the data was sent through other VMBus
584 uint16_t send_buf_section_index;
585 uint16_t send_buf_section_size;
589 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
590 * then there is no OOB data.
592 * This field shall be always 0xFFFFFFFF for now. It is reserved for
595 uint16_t oob_data_index;
598 * DisconnectFlags = 0
599 * Normal chimney send. See MiniportTcpOffloadSend for details.
601 * DisconnectFlags = TCP_DISCONNECT_GRACEFUL_CLOSE (0x01)
602 * Graceful disconnect. See MiniportTcpOffloadDisconnect for details.
604 * DisconnectFlags = TCP_DISCONNECT_ABORTIVE_CLOSE (0x02)
605 * Abortive disconnect. See MiniportTcpOffloadDisconnect for details.
607 uint16_t disconnect_flags;
610 } __packed nvsp_2_msg_send_chimney_pkt;
613 * NvspMessage2TypeSendChimneyPacketComplete
615 typedef struct nvsp_2_msg_send_chimney_pkt_complete_ {
617 * The NDIS_STATUS for the chimney send
622 * Number of bytes that have been sent to the peer (and ACKed by the peer).
624 uint32_t bytes_transferred;
625 } __packed nvsp_2_msg_send_chimney_pkt_complete;
628 #define NVSP_1_CHIMNEY_RECV_FLAG_NO_PUSH 0x0001u
629 #define NVSP_1_CHIMNEY_RECV_INVALID_OOB_INDEX 0xffffu
632 * NvspMessage2TypePostChimneyRecvRequest
634 typedef struct nvsp_2_msg_post_chimney_rx_request_ {
636 * Identify the TCP connection which this chimney receive request
639 uint32_t vsp_tcp_handle;
643 * This an index to the OOB data buffer. If the index is 0xFFFFFFFF,
644 * then there is no OOB data.
646 * This field shall be always 0xFFFFFFFF for now. It is reserved for
649 uint32_t oob_data_index;
653 * When it is set, this is a "no-push" receive.
654 * When it is clear, this is a "push" receive.
656 * Bit 1-15: Reserved and shall be zero
661 * For debugging and diagnoses purpose.
662 * The SeqNo is per TCP connection and starts from 0.
665 } __packed nvsp_2_msg_post_chimney_rx_request;
668 * NvspMessage2TypePostChimneyRecvRequestComplete
670 typedef struct nvsp_2_msg_post_chimney_rx_request_complete_ {
672 * The NDIS_STATUS for the chimney send
677 * Number of bytes that have been sent to the peer (and ACKed by
680 uint32_t bytes_xferred;
681 } __packed nvsp_2_msg_post_chimney_rx_request_complete;
684 * NvspMessage2TypeAllocateReceiveBuffer
686 typedef struct nvsp_2_msg_alloc_rx_buf_ {
688 * Allocation ID to match the allocation request and response
690 uint32_t allocation_id;
693 * Length of the VM shared memory receive buffer that needs to
697 } __packed nvsp_2_msg_alloc_rx_buf;
700 * NvspMessage2TypeAllocateReceiveBufferComplete
702 typedef struct nvsp_2_msg_alloc_rx_buf_complete_ {
704 * The NDIS_STATUS code for buffer allocation
709 * Allocation ID from NVSP_2_MESSAGE_ALLOCATE_RECEIVE_BUFFER
711 uint32_t allocation_id;
714 * GPADL handle for the allocated receive buffer
716 uint32_t gpadl_handle;
719 * Receive buffer ID that is further used in
720 * NvspMessage2SendVmqRndisPacket
723 } __packed nvsp_2_msg_alloc_rx_buf_complete;
726 * NvspMessage2TypeFreeReceiveBuffer
728 typedef struct nvsp_2_msg_free_rx_buf_ {
730 * Receive buffer ID previous returned in
731 * NvspMessage2TypeAllocateReceiveBufferComplete message
734 } __packed nvsp_2_msg_free_rx_buf;
737 * This structure is used in defining the buffers in
738 * NVSP_2_MESSAGE_SEND_VMQ_RNDIS_PACKET structure
740 typedef struct nvsp_xfer_page_range_ {
742 * Specifies the ID of the receive buffer that has the buffer. This
743 * ID can be the general receive buffer ID specified in
744 * NvspMessage1TypeSendReceiveBuffer or it can be the shared memory
745 * receive buffer ID allocated by the VSC and specified in
746 * NvspMessage2TypeAllocateReceiveBufferComplete message
748 uint64_t xfer_page_set_id;
756 * Offset in bytes from the beginning of the buffer
758 uint32_t byte_offset;
759 } __packed nvsp_xfer_page_range;
762 * NvspMessage2SendVmqRndisPacket
764 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_ {
766 * This field is specified by RNIDS. They assume there's
767 * two different channels of communication. However,
768 * the Network VSP only has one. Therefore, the channel
769 * travels with the RNDIS packet. It must be RMC_DATA
771 uint32_t channel_type;
774 * Only the Range element corresponding to the RNDIS header of
775 * the first RNDIS message in the multiple RNDIS messages sent
776 * in one NVSP message. Information about the data portions as well
777 * as the subsequent RNDIS messages in the same NVSP message are
778 * embedded in the RNDIS header itself
780 nvsp_xfer_page_range range;
781 } __packed nvsp_2_msg_send_vmq_rndis_pkt;
784 * This message is used by the VSC to complete
785 * a RNDIS VMQ message to the VSP. At this point,
786 * the initiator of this message can use any resources
787 * associated with the original RNDIS VMQ packet.
789 typedef struct nvsp_2_msg_send_vmq_rndis_pkt_complete_
792 } __packed nvsp_2_msg_send_vmq_rndis_pkt_complete;
795 typedef union nvsp_1_msg_uber_ {
796 nvsp_1_msg_send_ndis_version send_ndis_vers;
798 nvsp_1_msg_send_rx_buf send_rx_buf;
799 nvsp_1_msg_send_rx_buf_complete send_rx_buf_complete;
800 nvsp_1_msg_revoke_rx_buf revoke_rx_buf;
802 nvsp_1_msg_send_send_buf send_send_buf;
803 nvsp_1_msg_send_send_buf_complete send_send_buf_complete;
804 nvsp_1_msg_revoke_send_buf revoke_send_buf;
806 nvsp_1_msg_send_rndis_pkt send_rndis_pkt;
807 nvsp_1_msg_send_rndis_pkt_complete send_rndis_pkt_complete;
808 } __packed nvsp_1_msg_uber;
811 typedef union nvsp_2_msg_uber_ {
812 nvsp_2_msg_send_ndis_config send_ndis_config;
814 nvsp_2_msg_send_chimney_buf send_chimney_buf;
815 nvsp_2_msg_send_chimney_buf_complete send_chimney_buf_complete;
816 nvsp_2_msg_revoke_chimney_buf revoke_chimney_buf;
818 nvsp_2_msg_resume_chimney_rx_indication resume_chimney_rx_indication;
819 nvsp_2_msg_terminate_chimney terminate_chimney;
820 nvsp_2_msg_terminate_chimney_complete terminate_chimney_complete;
821 nvsp_2_msg_indicate_chimney_event indicate_chimney_event;
823 nvsp_2_msg_send_chimney_pkt send_chimney_packet;
824 nvsp_2_msg_send_chimney_pkt_complete send_chimney_packet_complete;
825 nvsp_2_msg_post_chimney_rx_request post_chimney_rx_request;
826 nvsp_2_msg_post_chimney_rx_request_complete
827 post_chimney_rx_request_complete;
829 nvsp_2_msg_alloc_rx_buf alloc_rx_buffer;
830 nvsp_2_msg_alloc_rx_buf_complete alloc_rx_buffer_complete;
831 nvsp_2_msg_free_rx_buf free_rx_buffer;
833 nvsp_2_msg_send_vmq_rndis_pkt send_vmq_rndis_pkt;
834 nvsp_2_msg_send_vmq_rndis_pkt_complete send_vmq_rndis_pkt_complete;
835 nvsp_2_msg_alloc_chimney_handle alloc_chimney_handle;
836 nvsp_2_msg_alloc_chimney_handle_complete alloc_chimney_handle_complete;
837 } __packed nvsp_2_msg_uber;
840 typedef union nvsp_all_msgs_ {
841 nvsp_msg_init_uber init_msgs;
842 nvsp_1_msg_uber vers_1_msgs;
843 nvsp_2_msg_uber vers_2_msgs;
844 } __packed nvsp_all_msgs;
849 typedef struct nvsp_msg_ {
856 * The following arguably belongs in a separate header file
863 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
864 #define NETVSC_SEND_BUFFER_ID 0xface
866 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
867 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
869 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
871 #define NETVSC_RECEIVE_SG_COUNT 1
873 /* Preallocated receive packets */
874 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
877 * Maximum MTU we permit to be configured for a netvsc interface.
878 * When the code was developed, a max MTU of 12232 was tested and
879 * proven to work. 9K is a reasonable maximum for an Ethernet.
881 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
883 #define NETVSC_PACKET_SIZE PAGE_SIZE
890 * Per netvsc channel-specific
892 typedef struct netvsc_dev_ {
893 struct hv_device *dev;
894 int num_outstanding_sends;
896 /* Send buffer allocated by us but manages by NetVSP */
898 uint32_t send_buf_size;
899 uint32_t send_buf_gpadl_handle;
900 uint32_t send_section_size;
901 uint32_t send_section_count;
902 unsigned long bitsmap_words;
903 unsigned long *send_section_bitsmap;
905 /* Receive buffer allocated by us but managed by NetVSP */
907 uint32_t rx_buf_size;
908 uint32_t rx_buf_gpadl_handle;
909 uint32_t rx_section_count;
910 nvsp_1_rx_buf_section *rx_sections;
912 /* Used for NetVSP initialization protocol */
913 struct sema channel_init_sema;
914 nvsp_msg channel_init_packet;
916 nvsp_msg revoke_packet;
917 /*uint8_t hw_mac_addr[HW_MACADDR_LEN];*/
919 /* Holds rndis device info */
922 hv_bool_uint8_t destroy;
923 /* Negotiated NVSP version */
924 uint32_t nvsp_version;
926 uint8_t callback_buf[NETVSC_PACKET_SIZE];
930 typedef void (*pfn_on_send_rx_completion)(void *);
932 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
933 #define NETVSC_PACKET_MAXPAGE 32
936 #define NETVSC_VLAN_PRIO_MASK 0xe000
937 #define NETVSC_VLAN_PRIO_SHIFT 13
938 #define NETVSC_VLAN_VID_MASK 0x0fff
945 #define TRANSPORT_TYPE_NOT_IP 0
946 #define TRANSPORT_TYPE_IPV4_TCP ((TYPE_IPV4 << 16) | TYPE_TCP)
947 #define TRANSPORT_TYPE_IPV4_UDP ((TYPE_IPV4 << 16) | TYPE_UDP)
948 #define TRANSPORT_TYPE_IPV6_TCP ((TYPE_IPV6 << 16) | TYPE_TCP)
949 #define TRANSPORT_TYPE_IPV6_UDP ((TYPE_IPV6 << 16) | TYPE_UDP)
952 #define BITS_PER_LONG 64
954 #define BITS_PER_LONG 32
957 typedef struct netvsc_packet_ {
958 struct hv_device *device;
959 hv_bool_uint8_t is_data_pkt; /* One byte */
966 uint64_t rx_completion_tid;
967 void *rx_completion_context;
968 /* This is no longer used */
969 pfn_on_send_rx_completion on_rx_completion;
972 uint64_t send_completion_tid;
973 void *send_completion_context;
974 /* Still used in netvsc and filter code */
975 pfn_on_send_rx_completion on_send_completion;
978 uint32_t send_buf_section_idx;
979 uint32_t send_buf_section_size;
982 uint32_t tot_data_buf_len;
984 uint32_t page_buf_count;
985 hv_vmbus_page_buffer page_buffers[NETVSC_PACKET_MAXPAGE];
989 uint8_t mac_addr[6]; /* Assumption unsigned long */
990 hv_bool_uint8_t link_state;
991 } netvsc_device_info;
994 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
997 struct lro_ctrl hn_lro;
999 /* Trust csum verification on host side */
1000 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
1005 u_long hn_csum_trusted;
1006 u_long hn_lro_tried;
1007 u_long hn_small_pkts;
1008 } __aligned(CACHE_LINE_SIZE);
1010 #define HN_TRUST_HCSUM_IP 0x0001
1011 #define HN_TRUST_HCSUM_TCP 0x0002
1012 #define HN_TRUST_HCSUM_UDP 0x0004
1015 struct mtx hn_txlist_spin;
1016 struct hn_txdesc_list hn_txlist;
1018 int hn_txdesc_avail;
1022 struct taskqueue *hn_tx_taskq;
1023 struct task hn_start_task;
1024 struct task hn_txeof_task;
1026 struct mtx hn_tx_lock;
1027 struct hn_softc *hn_sc;
1029 int hn_direct_tx_size;
1030 int hn_tx_chimney_size;
1031 bus_dma_tag_t hn_tx_data_dtag;
1032 uint64_t hn_csum_assist;
1034 u_long hn_no_txdescs;
1035 u_long hn_send_failed;
1036 u_long hn_txdma_failed;
1037 u_long hn_tx_collapsed;
1038 u_long hn_tx_chimney;
1040 /* Rarely used stuffs */
1041 struct hn_txdesc *hn_txdesc;
1042 bus_dma_tag_t hn_tx_rndis_dtag;
1043 struct sysctl_oid *hn_tx_sysctl_tree;
1044 } __aligned(CACHE_LINE_SIZE);
1047 * Device-specific softc structure
1049 typedef struct hn_softc {
1050 struct ifnet *hn_ifp;
1051 struct arpcom arpcom;
1052 struct ifmedia hn_media;
1059 /* See hv_netvsc_drv_freebsd.c for rules on how to use */
1061 struct hv_device *hn_dev_obj;
1062 netvsc_dev *net_dev;
1065 struct hn_rx_ring *hn_rx_ring;
1068 struct hn_tx_ring *hn_tx_ring;
1069 int hn_tx_chimney_max;
1070 struct taskqueue *hn_tx_taskq;
1071 struct sysctl_oid *hn_tx_sysctl_tree;
1077 extern int hv_promisc_mode;
1079 void netvsc_linkstatus_callback(struct hv_device *device_obj, uint32_t status);
1080 void netvsc_xmit_completion(void *context);
1081 void hv_nv_on_receive_completion(struct hv_device *device,
1082 uint64_t tid, uint32_t status);
1083 netvsc_dev *hv_nv_on_device_add(struct hv_device *device,
1084 void *additional_info);
1085 int hv_nv_on_device_remove(struct hv_device *device,
1086 boolean_t destroy_channel);
1087 int hv_nv_on_send(struct hv_device *device, netvsc_packet *pkt);
1088 int hv_nv_get_next_send_section(netvsc_dev *net_dev);
1090 #endif /* __HV_NET_VSC_H__ */