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;
181 * The following arguably belongs in a separate header file
188 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
189 #define NETVSC_SEND_BUFFER_ID 0xface
191 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
192 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
194 #define NETVSC_RECEIVE_BUFFER_ID 0xcafe
196 #define NETVSC_RECEIVE_SG_COUNT 1
198 /* Preallocated receive packets */
199 #define NETVSC_RECEIVE_PACKETLIST_COUNT 256
202 * Maximum MTU we permit to be configured for a netvsc interface.
203 * When the code was developed, a max MTU of 12232 was tested and
204 * proven to work. 9K is a reasonable maximum for an Ethernet.
206 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
208 #define NETVSC_PACKET_SIZE PAGE_SIZE
209 #define VRSS_SEND_TABLE_SIZE 16
216 * Per netvsc channel-specific
218 typedef struct netvsc_dev_ {
221 /* Send buffer allocated by us but manages by NetVSP */
223 uint32_t send_buf_size;
224 uint32_t send_buf_gpadl_handle;
225 uint32_t send_section_size;
226 uint32_t send_section_count;
227 unsigned long bitsmap_words;
228 unsigned long *send_section_bitsmap;
230 /* Receive buffer allocated by us but managed by NetVSP */
232 uint32_t rx_buf_size;
233 uint32_t rx_buf_gpadl_handle;
234 uint32_t rx_section_count;
236 /* Holds rndis device info */
240 /* Negotiated NVSP version */
241 uint32_t nvsp_version;
243 uint32_t num_channel;
245 struct hyperv_dma rxbuf_dma;
246 struct hyperv_dma txbuf_dma;
249 struct vmbus_channel;
251 typedef void (*pfn_on_send_rx_completion)(struct vmbus_channel *, void *);
253 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
254 #define NETVSC_PACKET_MAXPAGE 32
256 #define NETVSC_VLAN_PRIO_MASK 0xe000
257 #define NETVSC_VLAN_PRIO_SHIFT 13
258 #define NETVSC_VLAN_VID_MASK 0x0fff
265 #define TRANSPORT_TYPE_NOT_IP 0
266 #define TRANSPORT_TYPE_IPV4_TCP ((TYPE_IPV4 << 16) | TYPE_TCP)
267 #define TRANSPORT_TYPE_IPV4_UDP ((TYPE_IPV4 << 16) | TYPE_UDP)
268 #define TRANSPORT_TYPE_IPV6_TCP ((TYPE_IPV6 << 16) | TYPE_TCP)
269 #define TRANSPORT_TYPE_IPV6_UDP ((TYPE_IPV6 << 16) | TYPE_UDP)
272 #define BITS_PER_LONG 64
274 #define BITS_PER_LONG 32
277 typedef struct netvsc_packet_ {
280 uint32_t tot_data_buf_len;
285 uint8_t mac_addr[6]; /* Assumption unsigned long */
287 } netvsc_device_info;
289 #ifndef HN_USE_TXDESC_BUFRING
291 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
299 struct ifnet *hn_ifp;
300 struct hn_tx_ring *hn_txr;
304 /* Trust csum verification on host side */
305 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
306 struct lro_ctrl hn_lro;
311 u_long hn_csum_trusted;
313 u_long hn_small_pkts;
317 /* Rarely used stuffs */
318 struct sysctl_oid *hn_rx_sysctl_tree;
320 } __aligned(CACHE_LINE_SIZE);
322 #define HN_TRUST_HCSUM_IP 0x0001
323 #define HN_TRUST_HCSUM_TCP 0x0002
324 #define HN_TRUST_HCSUM_UDP 0x0004
326 #define HN_RX_FLAG_ATTACHED 0x1
329 #ifndef HN_USE_TXDESC_BUFRING
330 struct mtx hn_txlist_spin;
331 struct hn_txdesc_list hn_txlist;
333 struct buf_ring *hn_txdesc_br;
337 u_short hn_has_txeof;
338 u_short hn_txdone_cnt;
341 void (*hn_txeof)(struct hn_tx_ring *);
342 struct taskqueue *hn_tx_taskq;
343 struct task hn_tx_task;
344 struct task hn_txeof_task;
346 struct buf_ring *hn_mbuf_br;
350 struct mtx hn_tx_lock;
351 struct hn_softc *hn_sc;
352 struct vmbus_channel *hn_chan;
354 int hn_direct_tx_size;
355 int hn_tx_chimney_size;
356 bus_dma_tag_t hn_tx_data_dtag;
357 uint64_t hn_csum_assist;
360 struct vmbus_gpa hn_gpa[NETVSC_PACKET_MAXPAGE];
362 u_long hn_no_txdescs;
363 u_long hn_send_failed;
364 u_long hn_txdma_failed;
365 u_long hn_tx_collapsed;
366 u_long hn_tx_chimney_tried;
367 u_long hn_tx_chimney;
370 /* Rarely used stuffs */
371 struct hn_txdesc *hn_txdesc;
372 bus_dma_tag_t hn_tx_rndis_dtag;
373 struct sysctl_oid *hn_tx_sysctl_tree;
375 } __aligned(CACHE_LINE_SIZE);
377 #define HN_TX_FLAG_ATTACHED 0x1
380 * Device-specific softc structure
382 typedef struct hn_softc {
383 struct ifnet *hn_ifp;
384 struct arpcom arpcom;
385 struct ifmedia hn_media;
392 /* See hv_netvsc_drv_freebsd.c for rules on how to use */
395 struct vmbus_channel *hn_prichan;
398 int hn_rx_ring_inuse;
399 struct hn_rx_ring *hn_rx_ring;
402 int hn_tx_ring_inuse;
403 struct hn_tx_ring *hn_tx_ring;
406 int hn_tx_chimney_max;
407 struct taskqueue *hn_tx_taskq;
408 struct sysctl_oid *hn_tx_sysctl_tree;
409 struct sysctl_oid *hn_rx_sysctl_tree;
410 struct vmbus_xact_ctx *hn_xact;
416 extern int hv_promisc_mode;
419 void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
420 netvsc_dev *hv_nv_on_device_add(struct hn_softc *sc,
421 void *additional_info, struct hn_rx_ring *rxr);
422 int hv_nv_on_device_remove(struct hn_softc *sc,
423 boolean_t destroy_channel);
424 int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
425 struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
426 int hv_nv_get_next_send_section(netvsc_dev *net_dev);
427 void hv_nv_subchan_attach(struct vmbus_channel *chan,
428 struct hn_rx_ring *rxr);
430 #endif /* __HV_NET_VSC_H__ */