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 #include <dev/hyperv/netvsc/ndis.h>
67 #define HN_USE_TXDESC_BUFRING
69 MALLOC_DECLARE(M_NETVSC);
71 #define NVSP_INVALID_PROTOCOL_VERSION (0xFFFFFFFF)
73 #define NVSP_PROTOCOL_VERSION_1 2
74 #define NVSP_PROTOCOL_VERSION_2 0x30002
75 #define NVSP_PROTOCOL_VERSION_4 0x40000
76 #define NVSP_PROTOCOL_VERSION_5 0x50000
79 * The following arguably belongs in a separate header file
86 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
88 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
89 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
92 * Maximum MTU we permit to be configured for a netvsc interface.
93 * When the code was developed, a max MTU of 12232 was tested and
94 * proven to work. 9K is a reasonable maximum for an Ethernet.
96 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
98 #define NETVSC_PACKET_SIZE PAGE_SIZE
104 struct vmbus_channel;
106 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
107 #define NETVSC_PACKET_MAXPAGE 32
110 uint8_t mac_addr[ETHER_ADDR_LEN];
112 } netvsc_device_info;
114 #define HN_XACT_REQ_PGCNT 2
115 #define HN_XACT_RESP_PGCNT 2
116 #define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE)
117 #define HN_XACT_RESP_SIZE (HN_XACT_RESP_PGCNT * PAGE_SIZE)
119 #ifndef HN_USE_TXDESC_BUFRING
121 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
129 struct ifnet *hn_ifp;
130 struct hn_tx_ring *hn_txr;
132 uint8_t *hn_rxbuf; /* shadow sc->hn_rxbuf */
135 /* Trust csum verification on host side */
136 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
137 struct lro_ctrl hn_lro;
142 u_long hn_csum_trusted;
144 u_long hn_small_pkts;
148 /* Rarely used stuffs */
149 struct sysctl_oid *hn_rx_sysctl_tree;
151 } __aligned(CACHE_LINE_SIZE);
153 #define HN_TRUST_HCSUM_IP 0x0001
154 #define HN_TRUST_HCSUM_TCP 0x0002
155 #define HN_TRUST_HCSUM_UDP 0x0004
157 #define HN_RX_FLAG_ATTACHED 0x1
160 #ifndef HN_USE_TXDESC_BUFRING
161 struct mtx hn_txlist_spin;
162 struct hn_txdesc_list hn_txlist;
164 struct buf_ring *hn_txdesc_br;
168 u_short hn_has_txeof;
169 u_short hn_txdone_cnt;
172 void (*hn_txeof)(struct hn_tx_ring *);
173 struct taskqueue *hn_tx_taskq;
174 struct task hn_tx_task;
175 struct task hn_txeof_task;
177 struct buf_ring *hn_mbuf_br;
181 struct mtx hn_tx_lock;
182 struct hn_softc *hn_sc;
183 struct vmbus_channel *hn_chan;
185 int hn_direct_tx_size;
187 bus_dma_tag_t hn_tx_data_dtag;
188 uint64_t hn_csum_assist;
191 struct vmbus_gpa hn_gpa[NETVSC_PACKET_MAXPAGE];
193 u_long hn_no_txdescs;
194 u_long hn_send_failed;
195 u_long hn_txdma_failed;
196 u_long hn_tx_collapsed;
197 u_long hn_tx_chimney_tried;
198 u_long hn_tx_chimney;
201 /* Rarely used stuffs */
202 struct hn_txdesc *hn_txdesc;
203 bus_dma_tag_t hn_tx_rndis_dtag;
204 struct sysctl_oid *hn_tx_sysctl_tree;
206 } __aligned(CACHE_LINE_SIZE);
208 #define HN_TX_FLAG_ATTACHED 0x1
211 * Device-specific softc structure
213 typedef struct hn_softc {
214 struct ifnet *hn_ifp;
215 struct arpcom arpcom;
216 struct ifmedia hn_media;
223 /* See hv_netvsc_drv_freebsd.c for rules on how to use */
225 struct vmbus_channel *hn_prichan;
228 int hn_rx_ring_inuse;
229 struct hn_rx_ring *hn_rx_ring;
232 int hn_tx_ring_inuse;
233 struct hn_tx_ring *hn_tx_ring;
236 u_long *hn_chim_bmap;
237 int hn_chim_bmap_cnt;
242 struct taskqueue *hn_tx_taskq;
243 struct sysctl_oid *hn_tx_sysctl_tree;
244 struct sysctl_oid *hn_rx_sysctl_tree;
245 struct vmbus_xact_ctx *hn_xact;
250 uint32_t hn_rxbuf_gpadl;
251 struct hyperv_dma hn_rxbuf_dma;
253 uint32_t hn_chim_gpadl;
254 struct hyperv_dma hn_chim_dma;
256 uint32_t hn_rndis_rid;
257 uint32_t hn_ndis_ver;
259 struct ndis_rssprm_toeplitz hn_rss;
262 #define HN_FLAG_RXBUF_CONNECTED 0x0001
263 #define HN_FLAG_CHIM_CONNECTED 0x0002
268 extern int hv_promisc_mode;
271 void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
272 int hv_nv_on_device_add(struct hn_softc *sc, struct hn_rx_ring *rxr);
273 int hv_nv_on_device_remove(struct hn_softc *sc);
274 int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
275 struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
276 void hv_nv_subchan_attach(struct vmbus_channel *chan,
277 struct hn_rx_ring *rxr);
279 #endif /* __HV_NET_VSC_H__ */