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);
72 * The following arguably belongs in a separate header file
79 #define NETVSC_SEND_BUFFER_SIZE (1024*1024*15) /* 15M */
81 #define NETVSC_RECEIVE_BUFFER_SIZE_LEGACY (1024*1024*15) /* 15MB */
82 #define NETVSC_RECEIVE_BUFFER_SIZE (1024*1024*16) /* 16MB */
85 * Maximum MTU we permit to be configured for a netvsc interface.
86 * When the code was developed, a max MTU of 12232 was tested and
87 * proven to work. 9K is a reasonable maximum for an Ethernet.
89 #define NETVSC_MAX_CONFIGURABLE_MTU (9 * 1024)
91 #define NETVSC_PACKET_SIZE PAGE_SIZE
99 #define NETVSC_DEVICE_RING_BUFFER_SIZE (128 * PAGE_SIZE)
100 #define NETVSC_PACKET_MAXPAGE 32
102 #define HN_XACT_REQ_PGCNT 2
103 #define HN_XACT_RESP_PGCNT 2
104 #define HN_XACT_REQ_SIZE (HN_XACT_REQ_PGCNT * PAGE_SIZE)
105 #define HN_XACT_RESP_SIZE (HN_XACT_RESP_PGCNT * PAGE_SIZE)
107 #ifndef HN_USE_TXDESC_BUFRING
109 SLIST_HEAD(hn_txdesc_list, hn_txdesc);
117 struct ifnet *hn_ifp;
118 struct hn_tx_ring *hn_txr;
120 uint8_t *hn_rxbuf; /* shadow sc->hn_rxbuf */
123 /* Trust csum verification on host side */
124 int hn_trust_hcsum; /* HN_TRUST_HCSUM_ */
125 struct lro_ctrl hn_lro;
130 u_long hn_csum_trusted;
132 u_long hn_small_pkts;
136 /* Rarely used stuffs */
137 struct sysctl_oid *hn_rx_sysctl_tree;
140 void *hn_br; /* TX/RX bufring */
141 struct hyperv_dma hn_br_dma;
142 } __aligned(CACHE_LINE_SIZE);
144 #define HN_TRUST_HCSUM_IP 0x0001
145 #define HN_TRUST_HCSUM_TCP 0x0002
146 #define HN_TRUST_HCSUM_UDP 0x0004
148 #define HN_RX_FLAG_ATTACHED 0x1
151 #ifndef HN_USE_TXDESC_BUFRING
152 struct mtx hn_txlist_spin;
153 struct hn_txdesc_list hn_txlist;
155 struct buf_ring *hn_txdesc_br;
159 u_short hn_has_txeof;
160 u_short hn_txdone_cnt;
163 void (*hn_txeof)(struct hn_tx_ring *);
164 struct taskqueue *hn_tx_taskq;
165 struct task hn_tx_task;
166 struct task hn_txeof_task;
168 struct buf_ring *hn_mbuf_br;
173 struct mtx hn_tx_lock;
174 struct hn_softc *hn_sc;
175 struct vmbus_channel *hn_chan;
177 int hn_direct_tx_size;
179 bus_dma_tag_t hn_tx_data_dtag;
180 uint64_t hn_csum_assist;
184 struct vmbus_gpa hn_gpa[NETVSC_PACKET_MAXPAGE];
186 u_long hn_no_txdescs;
187 u_long hn_send_failed;
188 u_long hn_txdma_failed;
189 u_long hn_tx_collapsed;
190 u_long hn_tx_chimney_tried;
191 u_long hn_tx_chimney;
194 /* Rarely used stuffs */
195 struct hn_txdesc *hn_txdesc;
196 bus_dma_tag_t hn_tx_rndis_dtag;
197 struct sysctl_oid *hn_tx_sysctl_tree;
198 } __aligned(CACHE_LINE_SIZE);
200 #define HN_TX_FLAG_ATTACHED 0x1
201 #define HN_TX_FLAG_HASHVAL 0x2 /* support HASHVAL pktinfo */
204 * Device-specific softc structure
207 struct ifnet *hn_ifp;
208 struct arpcom arpcom;
209 struct ifmedia hn_media;
214 struct vmbus_channel *hn_prichan;
217 int hn_rx_ring_inuse;
218 struct hn_rx_ring *hn_rx_ring;
221 int hn_tx_ring_inuse;
222 struct hn_tx_ring *hn_tx_ring;
225 u_long *hn_chim_bmap;
226 int hn_chim_bmap_cnt;
231 struct taskqueue *hn_tx_taskq;
232 struct sysctl_oid *hn_tx_sysctl_tree;
233 struct sysctl_oid *hn_rx_sysctl_tree;
234 struct vmbus_xact_ctx *hn_xact;
237 struct taskqueue *hn_mgmt_taskq;
238 struct taskqueue *hn_mgmt_taskq0;
239 struct task hn_link_task;
241 uint32_t hn_caps; /* HN_CAP_ */
242 uint32_t hn_flags; /* HN_FLAG_ */
244 uint32_t hn_rxbuf_gpadl;
245 struct hyperv_dma hn_rxbuf_dma;
247 uint32_t hn_chim_gpadl;
248 struct hyperv_dma hn_chim_dma;
250 uint32_t hn_rndis_rid;
251 uint32_t hn_ndis_ver;
252 int hn_ndis_tso_szmax;
253 int hn_ndis_tso_sgmin;
255 struct ndis_rssprm_toeplitz hn_rss;
258 #define HN_FLAG_RXBUF_CONNECTED 0x0001
259 #define HN_FLAG_CHIM_CONNECTED 0x0002
260 #define HN_FLAG_HAS_RSSKEY 0x0004
261 #define HN_FLAG_HAS_RSSIND 0x0008
262 #define HN_FLAG_SYNTH_ATTACHED 0x0010
264 #define HN_CAP_VLAN 0x0001
265 #define HN_CAP_MTU 0x0002
266 #define HN_CAP_IPCS 0x0004
267 #define HN_CAP_TCP4CS 0x0008
268 #define HN_CAP_TCP6CS 0x0010
269 #define HN_CAP_UDP4CS 0x0020
270 #define HN_CAP_UDP6CS 0x0040
271 #define HN_CAP_TSO4 0x0080
272 #define HN_CAP_TSO6 0x0100
279 int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
280 struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
282 #endif /* __HV_NET_VSC_H__ */