3 * Copyright (c) 2011, Microsoft Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
21 * K. Y. Srinivasan <kys@microsoft.com>
28 #include <linux/list.h>
29 #include <linux/hyperv.h>
30 #include <linux/rndis.h>
33 struct hv_netvsc_packet
;
35 /* Represent the xfer page packet which contains 1 or more netvsc packet */
36 struct xferpage_packet
{
37 struct list_head list_ent
;
39 /* # of netvsc packets this xfer packet contains */
44 * Represent netvsc packet which contains 1 RNDIS and 1 ethernet frame
47 struct hv_netvsc_packet
{
48 /* Bookkeeping stuff */
49 struct list_head list_ent
;
51 struct hv_device
*device
;
56 * Valid only for receives when we break a xfer page packet
57 * into multiple netvsc packets
59 struct xferpage_packet
*xfer_page_pkt
;
63 u64 recv_completion_tid
;
64 void *recv_completion_ctx
;
65 void (*recv_completion
)(void *context
);
68 u64 send_completion_tid
;
69 void *send_completion_ctx
;
70 void (*send_completion
)(void *context
);
74 /* This points to the memory after page_buf */
77 u32 total_data_buflen
;
78 /* Points to the send/receive buffer where the ethernet frame is */
81 struct hv_page_buffer page_buf
[0];
84 struct netvsc_device_info
{
85 unsigned char mac_adr
[6];
86 bool link_state
; /* 0 - link up, 1 - link down */
90 enum rndis_device_state
{
91 RNDIS_DEV_UNINITIALIZED
= 0,
92 RNDIS_DEV_INITIALIZING
,
93 RNDIS_DEV_INITIALIZED
,
94 RNDIS_DEV_DATAINITIALIZED
,
98 struct netvsc_device
*net_dev
;
100 enum rndis_device_state state
;
104 spinlock_t request_lock
;
105 struct list_head req_list
;
107 unsigned char hw_mac_adr
[ETH_ALEN
];
112 int netvsc_device_add(struct hv_device
*device
, void *additional_info
);
113 int netvsc_device_remove(struct hv_device
*device
);
114 int netvsc_send(struct hv_device
*device
,
115 struct hv_netvsc_packet
*packet
);
116 void netvsc_linkstatus_callback(struct hv_device
*device_obj
,
117 unsigned int status
);
118 int netvsc_recv_callback(struct hv_device
*device_obj
,
119 struct hv_netvsc_packet
*packet
);
120 int rndis_filter_open(struct hv_device
*dev
);
121 int rndis_filter_close(struct hv_device
*dev
);
122 int rndis_filter_device_add(struct hv_device
*dev
,
123 void *additional_info
);
124 void rndis_filter_device_remove(struct hv_device
*dev
);
125 int rndis_filter_receive(struct hv_device
*dev
,
126 struct hv_netvsc_packet
*pkt
);
130 int rndis_filter_send(struct hv_device
*dev
,
131 struct hv_netvsc_packet
*pkt
);
133 int rndis_filter_set_packet_filter(struct rndis_device
*dev
, u32 new_filter
);
134 int rndis_filter_set_device_mac(struct hv_device
*hdev
, char *mac
);
137 #define NVSP_INVALID_PROTOCOL_VERSION ((u32)0xFFFFFFFF)
139 #define NVSP_PROTOCOL_VERSION_1 2
140 #define NVSP_PROTOCOL_VERSION_2 0x30002
143 NVSP_MSG_TYPE_NONE
= 0,
146 NVSP_MSG_TYPE_INIT
= 1,
147 NVSP_MSG_TYPE_INIT_COMPLETE
= 2,
149 NVSP_VERSION_MSG_START
= 100,
151 /* Version 1 Messages */
152 NVSP_MSG1_TYPE_SEND_NDIS_VER
= NVSP_VERSION_MSG_START
,
154 NVSP_MSG1_TYPE_SEND_RECV_BUF
,
155 NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE
,
156 NVSP_MSG1_TYPE_REVOKE_RECV_BUF
,
158 NVSP_MSG1_TYPE_SEND_SEND_BUF
,
159 NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE
,
160 NVSP_MSG1_TYPE_REVOKE_SEND_BUF
,
162 NVSP_MSG1_TYPE_SEND_RNDIS_PKT
,
163 NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE
,
165 /* Version 2 messages */
166 NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF
,
167 NVSP_MSG2_TYPE_SEND_CHIMNEY_DELEGATED_BUF_COMP
,
168 NVSP_MSG2_TYPE_REVOKE_CHIMNEY_DELEGATED_BUF
,
170 NVSP_MSG2_TYPE_RESUME_CHIMNEY_RX_INDICATION
,
172 NVSP_MSG2_TYPE_TERMINATE_CHIMNEY
,
173 NVSP_MSG2_TYPE_TERMINATE_CHIMNEY_COMP
,
175 NVSP_MSG2_TYPE_INDICATE_CHIMNEY_EVENT
,
177 NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT
,
178 NVSP_MSG2_TYPE_SEND_CHIMNEY_PKT_COMP
,
180 NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ
,
181 NVSP_MSG2_TYPE_POST_CHIMNEY_RECV_REQ_COMP
,
183 NVSP_MSG2_TYPE_ALLOC_RXBUF
,
184 NVSP_MSG2_TYPE_ALLOC_RXBUF_COMP
,
186 NVSP_MSG2_TYPE_FREE_RXBUF
,
188 NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT
,
189 NVSP_MSG2_TYPE_SEND_VMQ_RNDIS_PKT_COMP
,
191 NVSP_MSG2_TYPE_SEND_NDIS_CONFIG
,
193 NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE
,
194 NVSP_MSG2_TYPE_ALLOC_CHIMNEY_HANDLE_COMP
,
201 NVSP_STAT_PROTOCOL_TOO_NEW
,
202 NVSP_STAT_PROTOCOL_TOO_OLD
,
203 NVSP_STAT_INVALID_RNDIS_PKT
,
205 NVSP_STAT_PROTOCOL_UNSUPPORTED
,
209 struct nvsp_message_header
{
216 * This message is used by the VSC to initialize the channel after the channels
217 * has been opened. This message should never include anything other then
218 * versioning (i.e. this message will be the same for ever).
220 struct nvsp_message_init
{
221 u32 min_protocol_ver
;
222 u32 max_protocol_ver
;
226 * This message is used by the VSP to complete the initialization of the
227 * channel. This message should never include anything other then versioning
228 * (i.e. this message will be the same for ever).
230 struct nvsp_message_init_complete
{
231 u32 negotiated_protocol_ver
;
232 u32 max_mdl_chain_len
;
236 union nvsp_message_init_uber
{
237 struct nvsp_message_init init
;
238 struct nvsp_message_init_complete init_complete
;
241 /* Version 1 Messages */
244 * This message is used by the VSC to send the NDIS version to the VSP. The VSP
245 * can use this information when handling OIDs sent by the VSC.
247 struct nvsp_1_message_send_ndis_version
{
253 * This message is used by the VSC to send a receive buffer to the VSP. The VSP
254 * can then use the receive buffer to send data to the VSC.
256 struct nvsp_1_message_send_receive_buffer
{
261 struct nvsp_1_receive_buffer_section
{
269 * This message is used by the VSP to acknowledge a receive buffer send by the
270 * VSC. This message must be sent by the VSP before the VSP uses the receive
273 struct nvsp_1_message_send_receive_buffer_complete
{
278 * The receive buffer is split into two parts, a large suballocation
279 * section and a small suballocation section. These sections are then
280 * suballocated by a certain size.
284 * For example, the following break up of the receive buffer has 6
285 * large suballocations and 10 small suballocations.
289 * | Large Section | | Small Section |
290 * ------------------------------------------------------------
291 * | | | | | | | | | | | | | | | | | |
293 * LargeOffset SmallOffset
296 struct nvsp_1_receive_buffer_section sections
[1];
300 * This message is sent by the VSC to revoke the receive buffer. After the VSP
301 * completes this transaction, the vsp should never use the receive buffer
304 struct nvsp_1_message_revoke_receive_buffer
{
309 * This message is used by the VSC to send a send buffer to the VSP. The VSC
310 * can then use the send buffer to send data to the VSP.
312 struct nvsp_1_message_send_send_buffer
{
318 * This message is used by the VSP to acknowledge a send buffer sent by the
319 * VSC. This message must be sent by the VSP before the VSP uses the sent
322 struct nvsp_1_message_send_send_buffer_complete
{
326 * The VSC gets to choose the size of the send buffer and the VSP gets
327 * to choose the sections size of the buffer. This was done to enable
328 * dynamic reconfigurations when the cost of GPA-direct buffers
335 * This message is sent by the VSC to revoke the send buffer. After the VSP
336 * completes this transaction, the vsp should never use the send buffer again.
338 struct nvsp_1_message_revoke_send_buffer
{
343 * This message is used by both the VSP and the VSC to send a RNDIS message to
344 * the opposite channel endpoint.
346 struct nvsp_1_message_send_rndis_packet
{
348 * This field is specified by RNIDS. They assume there's two different
349 * channels of communication. However, the Network VSP only has one.
350 * Therefore, the channel travels with the RNDIS packet.
355 * This field is used to send part or all of the data through a send
356 * buffer. This values specifies an index into the send buffer. If the
357 * index is 0xFFFFFFFF, then the send buffer is not being used and all
358 * of the data was sent through other VMBus mechanisms.
360 u32 send_buf_section_index
;
361 u32 send_buf_section_size
;
365 * This message is used by both the VSP and the VSC to complete a RNDIS message
366 * to the opposite channel endpoint. At this point, the initiator of this
367 * message cannot use any resources associated with the original RNDIS packet.
369 struct nvsp_1_message_send_rndis_packet_complete
{
373 union nvsp_1_message_uber
{
374 struct nvsp_1_message_send_ndis_version send_ndis_ver
;
376 struct nvsp_1_message_send_receive_buffer send_recv_buf
;
377 struct nvsp_1_message_send_receive_buffer_complete
378 send_recv_buf_complete
;
379 struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf
;
381 struct nvsp_1_message_send_send_buffer send_send_buf
;
382 struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete
;
383 struct nvsp_1_message_revoke_send_buffer revoke_send_buf
;
385 struct nvsp_1_message_send_rndis_packet send_rndis_pkt
;
386 struct nvsp_1_message_send_rndis_packet_complete
387 send_rndis_pkt_complete
;
392 * Network VSP protocol version 2 messages:
394 struct nvsp_2_vsc_capability
{
402 u64 correlation_id
:1;
407 struct nvsp_2_send_ndis_config
{
410 struct nvsp_2_vsc_capability capability
;
413 /* Allocate receive buffer */
414 struct nvsp_2_alloc_rxbuf
{
415 /* Allocation ID to match the allocation request and response */
418 /* Length of the VM shared memory receive buffer that needs to
424 /* Allocate receive buffer complete */
425 struct nvsp_2_alloc_rxbuf_comp
{
426 /* The NDIS_STATUS code for buffer allocation */
431 /* GPADL handle for the allocated receive buffer */
434 /* Receive buffer ID */
438 struct nvsp_2_free_rxbuf
{
442 union nvsp_2_message_uber
{
443 struct nvsp_2_send_ndis_config send_ndis_config
;
444 struct nvsp_2_alloc_rxbuf alloc_rxbuf
;
445 struct nvsp_2_alloc_rxbuf_comp alloc_rxbuf_comp
;
446 struct nvsp_2_free_rxbuf free_rxbuf
;
449 union nvsp_all_messages
{
450 union nvsp_message_init_uber init_msg
;
451 union nvsp_1_message_uber v1_msg
;
452 union nvsp_2_message_uber v2_msg
;
456 struct nvsp_message
{
457 struct nvsp_message_header hdr
;
458 union nvsp_all_messages msg
;
462 #define NETVSC_MTU 65536
464 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*2) /* 2MB */
466 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
468 #define NETVSC_RECEIVE_SG_COUNT 1
470 /* Preallocated receive packets */
471 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
473 #define NETVSC_PACKET_SIZE 2048
475 /* Per netvsc channel-specific */
476 struct netvsc_device
{
477 struct hv_device
*dev
;
481 atomic_t num_outstanding_sends
;
482 wait_queue_head_t wait_drain
;
486 * List of free preallocated hv_netvsc_packet to represent receive
489 struct list_head recv_pkt_list
;
490 spinlock_t recv_pkt_list_lock
;
492 /* Receive buffer allocated by us but manages by NetVSP */
495 u32 recv_buf_gpadl_handle
;
496 u32 recv_section_cnt
;
497 struct nvsp_1_receive_buffer_section
*recv_section
;
499 /* Used for NetVSP initialization protocol */
500 struct completion channel_init_wait
;
501 struct nvsp_message channel_init_pkt
;
503 struct nvsp_message revoke_packet
;
504 /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
506 struct net_device
*ndev
;
508 /* Holds rndis device info */
512 /* NdisInitialize message */
513 struct rndis_initialize_request
{
520 /* Response to NdisInitialize */
521 struct rndis_initialize_complete
{
530 u32 pkt_alignment_factor
;
535 /* Call manager devices only: Information about an address family */
536 /* supported by the device is appended to the response to NdisInitialize. */
537 struct rndis_co_address_family
{
543 /* NdisHalt message */
544 struct rndis_halt_request
{
548 /* NdisQueryRequest message */
549 struct rndis_query_request
{
557 /* Response to NdisQueryRequest */
558 struct rndis_query_complete
{
565 /* NdisSetRequest message */
566 struct rndis_set_request
{
574 /* Response to NdisSetRequest */
575 struct rndis_set_complete
{
580 /* NdisReset message */
581 struct rndis_reset_request
{
585 /* Response to NdisReset */
586 struct rndis_reset_complete
{
588 u32 addressing_reset
;
591 /* NdisMIndicateStatus message */
592 struct rndis_indicate_status
{
595 u32 status_buf_offset
;
598 /* Diagnostic information passed as the status buffer in */
599 /* struct rndis_indicate_status messages signifying error conditions. */
600 struct rndis_diagnostic_info
{
605 /* NdisKeepAlive message */
606 struct rndis_keepalive_request
{
610 /* Response to NdisKeepAlive */
611 struct rndis_keepalive_complete
{
617 * Data message. All Offset fields contain byte offsets from the beginning of
618 * struct rndis_packet. All Length fields are in bytes. VcHandle is set
619 * to 0 for connectionless data, otherwise it contains the VC handle.
621 struct rndis_packet
{
626 u32 num_oob_data_elements
;
627 u32 per_pkt_info_offset
;
628 u32 per_pkt_info_len
;
633 /* Optional Out of Band data associated with a Data message. */
637 u32 class_info_offset
;
640 /* Packet extension field contents associated with a Data message. */
641 struct rndis_per_packet_info
{
647 enum ndis_per_pkt_info_type
{
648 TCPIP_CHKSUM_PKTINFO
,
650 TCP_LARGESEND_PKTINFO
,
651 CLASSIFICATION_HANDLE_PKTINFO
,
657 ORIGINAL_NET_BUFLIST
,
663 struct ndis_pkt_8021q_info
{
666 u32 pri
:3; /* User Priority */
667 u32 cfi
:1; /* Canonical Format ID */
668 u32 vlanid
:12; /* VLAN ID */
675 #define NDIS_VLAN_PPI_SIZE (sizeof(struct rndis_per_packet_info) + \
676 sizeof(struct ndis_pkt_8021q_info))
678 /* Format of Information buffer passed in a SetRequest for the OID */
679 /* OID_GEN_RNDIS_CONFIG_PARAMETER. */
680 struct rndis_config_parameter_info
{
681 u32 parameter_name_offset
;
682 u32 parameter_name_length
;
684 u32 parameter_value_offset
;
685 u32 parameter_value_length
;
688 /* Values for ParameterType in struct rndis_config_parameter_info */
689 #define RNDIS_CONFIG_PARAM_TYPE_INTEGER 0
690 #define RNDIS_CONFIG_PARAM_TYPE_STRING 2
692 /* CONDIS Miniport messages for connection oriented devices */
693 /* that do not implement a call manager. */
695 /* CoNdisMiniportCreateVc message */
696 struct rcondis_mp_create_vc
{
701 /* Response to CoNdisMiniportCreateVc */
702 struct rcondis_mp_create_vc_complete
{
708 /* CoNdisMiniportDeleteVc message */
709 struct rcondis_mp_delete_vc
{
714 /* Response to CoNdisMiniportDeleteVc */
715 struct rcondis_mp_delete_vc_complete
{
720 /* CoNdisMiniportQueryRequest message */
721 struct rcondis_mp_query_request
{
730 /* CoNdisMiniportSetRequest message */
731 struct rcondis_mp_set_request
{
740 /* CoNdisIndicateStatus message */
741 struct rcondis_indicate_status
{
745 u32 status_buf_offset
;
748 /* CONDIS Call/VC parameters */
749 struct rcondis_specific_parameters
{
751 u32 parameter_length
;
752 u32 parameter_lffset
;
755 struct rcondis_media_parameters
{
759 struct rcondis_specific_parameters media_specific
;
762 struct rndis_flowspec
{
764 u32 token_bucket_size
;
770 u32 minimum_policed_size
;
773 struct rcondis_call_manager_parameters
{
774 struct rndis_flowspec transmit
;
775 struct rndis_flowspec receive
;
776 struct rcondis_specific_parameters call_mgr_specific
;
779 /* CoNdisMiniportActivateVc message */
780 struct rcondis_mp_activate_vc_request
{
784 u32 media_params_offset
;
785 u32 media_params_length
;
786 u32 call_mgr_params_offset
;
787 u32 call_mgr_params_length
;
790 /* Response to CoNdisMiniportActivateVc */
791 struct rcondis_mp_activate_vc_complete
{
796 /* CoNdisMiniportDeactivateVc message */
797 struct rcondis_mp_deactivate_vc_request
{
803 /* Response to CoNdisMiniportDeactivateVc */
804 struct rcondis_mp_deactivate_vc_complete
{
810 /* union with all of the RNDIS messages */
811 union rndis_message_container
{
812 struct rndis_packet pkt
;
813 struct rndis_initialize_request init_req
;
814 struct rndis_halt_request halt_req
;
815 struct rndis_query_request query_req
;
816 struct rndis_set_request set_req
;
817 struct rndis_reset_request reset_req
;
818 struct rndis_keepalive_request keep_alive_req
;
819 struct rndis_indicate_status indicate_status
;
820 struct rndis_initialize_complete init_complete
;
821 struct rndis_query_complete query_complete
;
822 struct rndis_set_complete set_complete
;
823 struct rndis_reset_complete reset_complete
;
824 struct rndis_keepalive_complete keep_alive_complete
;
825 struct rcondis_mp_create_vc co_miniport_create_vc
;
826 struct rcondis_mp_delete_vc co_miniport_delete_vc
;
827 struct rcondis_indicate_status co_indicate_status
;
828 struct rcondis_mp_activate_vc_request co_miniport_activate_vc
;
829 struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc
;
830 struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete
;
831 struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete
;
832 struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete
;
833 struct rcondis_mp_deactivate_vc_complete
834 co_miniport_deactivate_vc_complete
;
837 /* Remote NDIS message format */
838 struct rndis_message
{
841 /* Total length of this message, from the beginning */
842 /* of the sruct rndis_message, in bytes. */
846 union rndis_message_container msg
;
850 struct rndis_filter_packet
{
851 void *completion_ctx
;
852 void (*completion
)(void *context
);
853 struct rndis_message msg
;
858 /* get the size of an RNDIS message. Pass in the message type, */
859 /* struct rndis_set_request, struct rndis_packet for example */
860 #define RNDIS_MESSAGE_SIZE(msg) \
861 (sizeof(msg) + (sizeof(struct rndis_message) - \
862 sizeof(union rndis_message_container)))
864 /* get pointer to info buffer with message pointer */
865 #define MESSAGE_TO_INFO_BUFFER(msg) \
866 (((unsigned char *)(msg)) + msg->info_buf_offset)
868 /* get pointer to status buffer with message pointer */
869 #define MESSAGE_TO_STATUS_BUFFER(msg) \
870 (((unsigned char *)(msg)) + msg->status_buf_offset)
872 /* get pointer to OOBD buffer with message pointer */
873 #define MESSAGE_TO_OOBD_BUFFER(msg) \
874 (((unsigned char *)(msg)) + msg->oob_data_offset)
876 /* get pointer to data buffer with message pointer */
877 #define MESSAGE_TO_DATA_BUFFER(msg) \
878 (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
880 /* get pointer to contained message from NDIS_MESSAGE pointer */
881 #define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \
882 ((void *) &rndis_msg->msg)
884 /* get pointer to contained message from NDIS_MESSAGE pointer */
885 #define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
889 #define __struct_bcount(x)
893 #define RNDIS_HEADER_SIZE (sizeof(struct rndis_message) - \
894 sizeof(union rndis_message_container))
896 #define NDIS_PACKET_TYPE_DIRECTED 0x00000001
897 #define NDIS_PACKET_TYPE_MULTICAST 0x00000002
898 #define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
899 #define NDIS_PACKET_TYPE_BROADCAST 0x00000008
900 #define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
901 #define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
902 #define NDIS_PACKET_TYPE_SMT 0x00000040
903 #define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
904 #define NDIS_PACKET_TYPE_GROUP 0x00000100
905 #define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
906 #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
907 #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
911 #endif /* _HYPERV_NET_H */