if_hnvar.h revision 311375
1/*-
2 * Copyright (c) 2016 Microsoft Corp.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice unmodified, this list of conditions, and the following
10 *    disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: stable/11/sys/dev/hyperv/netvsc/if_hnvar.h 311375 2017-01-05 06:25:16Z sephe $
27 */
28
29#ifndef _IF_HNVAR_H_
30#define _IF_HNVAR_H_
31
32#define HN_USE_TXDESC_BUFRING
33
34#define HN_CHIM_SIZE			(15 * 1024 * 1024)
35
36#define HN_RXBUF_SIZE			(16 * 1024 * 1024)
37#define HN_RXBUF_SIZE_COMPAT		(15 * 1024 * 1024)
38
39/* Claimed to be 12232B */
40#define HN_MTU_MAX			(9 * 1024)
41
42#define HN_TXBR_SIZE			(128 * PAGE_SIZE)
43#define HN_RXBR_SIZE			(128 * PAGE_SIZE)
44
45#define HN_XACT_REQ_PGCNT		2
46#define HN_XACT_RESP_PGCNT		2
47#define HN_XACT_REQ_SIZE		(HN_XACT_REQ_PGCNT * PAGE_SIZE)
48#define HN_XACT_RESP_SIZE		(HN_XACT_RESP_PGCNT * PAGE_SIZE)
49
50#define HN_GPACNT_MAX			32
51
52struct hn_txdesc;
53#ifndef HN_USE_TXDESC_BUFRING
54SLIST_HEAD(hn_txdesc_list, hn_txdesc);
55#else
56struct buf_ring;
57#endif
58struct hn_tx_ring;
59
60struct hn_rx_ring {
61	struct ifnet	*hn_ifp;
62	struct hn_tx_ring *hn_txr;
63	void		*hn_pktbuf;
64	int		hn_pktbuf_len;
65	uint8_t		*hn_rxbuf;	/* shadow sc->hn_rxbuf */
66	int		hn_rx_idx;
67
68	/* Trust csum verification on host side */
69	int		hn_trust_hcsum;	/* HN_TRUST_HCSUM_ */
70	struct lro_ctrl	hn_lro;
71
72	u_long		hn_csum_ip;
73	u_long		hn_csum_tcp;
74	u_long		hn_csum_udp;
75	u_long		hn_csum_trusted;
76	u_long		hn_lro_tried;
77	u_long		hn_small_pkts;
78	u_long		hn_pkts;
79	u_long		hn_rss_pkts;
80	u_long		hn_ack_failed;
81
82	/* Rarely used stuffs */
83	struct sysctl_oid *hn_rx_sysctl_tree;
84	int		hn_rx_flags;
85
86	void		*hn_br;		/* TX/RX bufring */
87	struct hyperv_dma hn_br_dma;
88} __aligned(CACHE_LINE_SIZE);
89
90#define HN_TRUST_HCSUM_IP	0x0001
91#define HN_TRUST_HCSUM_TCP	0x0002
92#define HN_TRUST_HCSUM_UDP	0x0004
93
94#define HN_RX_FLAG_ATTACHED	0x0001
95#define HN_RX_FLAG_BR_REF	0x0002
96
97struct hn_tx_ring {
98#ifndef HN_USE_TXDESC_BUFRING
99	struct mtx	hn_txlist_spin;
100	struct hn_txdesc_list hn_txlist;
101#else
102	struct buf_ring	*hn_txdesc_br;
103#endif
104	int		hn_txdesc_cnt;
105	int		hn_txdesc_avail;
106	u_short		hn_has_txeof;
107	u_short		hn_txdone_cnt;
108
109	int		hn_sched_tx;
110	void		(*hn_txeof)(struct hn_tx_ring *);
111	struct taskqueue *hn_tx_taskq;
112	struct task	hn_tx_task;
113	struct task	hn_txeof_task;
114
115	struct buf_ring	*hn_mbuf_br;
116	int		hn_oactive;
117	int		hn_tx_idx;
118	int		hn_tx_flags;
119
120	struct mtx	hn_tx_lock;
121	struct hn_softc	*hn_sc;
122	struct vmbus_channel *hn_chan;
123
124	int		hn_direct_tx_size;
125	int		hn_chim_size;
126	bus_dma_tag_t	hn_tx_data_dtag;
127	uint64_t	hn_csum_assist;
128
129	/* Applied packet transmission aggregation limits. */
130	int		hn_agg_szmax;
131	short		hn_agg_pktmax;
132	short		hn_agg_align;
133
134	/* Packet transmission aggregation states. */
135	struct hn_txdesc *hn_agg_txd;
136	int		hn_agg_szleft;
137	short		hn_agg_pktleft;
138	struct rndis_packet_msg *hn_agg_prevpkt;
139
140	/* Temporary stats for each sends. */
141	int		hn_stat_size;
142	short		hn_stat_pkts;
143	short		hn_stat_mcasts;
144
145	int		(*hn_sendpkt)(struct hn_tx_ring *, struct hn_txdesc *);
146	int		hn_suspended;
147	int		hn_gpa_cnt;
148	struct vmbus_gpa hn_gpa[HN_GPACNT_MAX];
149
150	u_long		hn_no_txdescs;
151	u_long		hn_send_failed;
152	u_long		hn_txdma_failed;
153	u_long		hn_tx_collapsed;
154	u_long		hn_tx_chimney_tried;
155	u_long		hn_tx_chimney;
156	u_long		hn_pkts;
157	u_long		hn_sends;
158	u_long		hn_flush_failed;
159
160	/* Rarely used stuffs */
161	struct hn_txdesc *hn_txdesc;
162	bus_dma_tag_t	hn_tx_rndis_dtag;
163	struct sysctl_oid *hn_tx_sysctl_tree;
164} __aligned(CACHE_LINE_SIZE);
165
166#define HN_TX_FLAG_ATTACHED	0x0001
167#define HN_TX_FLAG_HASHVAL	0x0002	/* support HASHVAL pktinfo */
168
169/*
170 * Device-specific softc structure
171 */
172struct hn_softc {
173	struct ifnet    *hn_ifp;
174	struct ifmedia	hn_media;
175	device_t        hn_dev;
176	int             hn_if_flags;
177	struct sx	hn_lock;
178	struct vmbus_channel *hn_prichan;
179
180	int		hn_rx_ring_cnt;
181	int		hn_rx_ring_inuse;
182	struct hn_rx_ring *hn_rx_ring;
183
184	int		hn_tx_ring_cnt;
185	int		hn_tx_ring_inuse;
186	struct hn_tx_ring *hn_tx_ring;
187
188	uint8_t		*hn_chim;
189	u_long		*hn_chim_bmap;
190	int		hn_chim_bmap_cnt;
191	int		hn_chim_cnt;
192	int		hn_chim_szmax;
193
194	int		hn_cpu;
195	struct taskqueue **hn_tx_taskqs;
196	struct sysctl_oid *hn_tx_sysctl_tree;
197	struct sysctl_oid *hn_rx_sysctl_tree;
198	struct vmbus_xact_ctx *hn_xact;
199	uint32_t	hn_nvs_ver;
200	uint32_t	hn_rx_filter;
201
202	/* Packet transmission aggregation user settings. */
203	int			hn_agg_size;
204	int			hn_agg_pkts;
205
206	struct taskqueue	*hn_mgmt_taskq;
207	struct taskqueue	*hn_mgmt_taskq0;
208	struct task		hn_link_task;
209	struct task		hn_netchg_init;
210	struct timeout_task	hn_netchg_status;
211	uint32_t		hn_link_flags;	/* HN_LINK_FLAG_ */
212
213	uint32_t		hn_caps;	/* HN_CAP_ */
214	uint32_t		hn_flags;	/* HN_FLAG_ */
215	u_int			hn_pollhz;
216
217	void			*hn_rxbuf;
218	uint32_t		hn_rxbuf_gpadl;
219	struct hyperv_dma	hn_rxbuf_dma;
220
221	uint32_t		hn_chim_gpadl;
222	struct hyperv_dma	hn_chim_dma;
223
224	uint32_t		hn_rndis_rid;
225	uint32_t		hn_ndis_ver;
226	int			hn_ndis_tso_szmax;
227	int			hn_ndis_tso_sgmin;
228	uint32_t		hn_rndis_agg_size;
229	uint32_t		hn_rndis_agg_pkts;
230	uint32_t		hn_rndis_agg_align;
231
232	int			hn_rss_ind_size;
233	uint32_t		hn_rss_hash;	/* NDIS_HASH_ */
234	struct ndis_rssprm_toeplitz hn_rss;
235};
236
237#define HN_FLAG_RXBUF_CONNECTED		0x0001
238#define HN_FLAG_CHIM_CONNECTED		0x0002
239#define HN_FLAG_HAS_RSSKEY		0x0004
240#define HN_FLAG_HAS_RSSIND		0x0008
241#define HN_FLAG_SYNTH_ATTACHED		0x0010
242#define HN_FLAG_NO_SLEEPING		0x0020
243#define HN_FLAG_RXBUF_REF		0x0040
244#define HN_FLAG_CHIM_REF		0x0080
245
246#define HN_FLAG_ERRORS			(HN_FLAG_RXBUF_REF | HN_FLAG_CHIM_REF)
247
248#define HN_NO_SLEEPING(sc)			\
249do {						\
250	(sc)->hn_flags |= HN_FLAG_NO_SLEEPING;	\
251} while (0)
252
253#define HN_SLEEPING_OK(sc)			\
254do {						\
255	(sc)->hn_flags &= ~HN_FLAG_NO_SLEEPING;	\
256} while (0)
257
258#define HN_CAN_SLEEP(sc)		\
259	(((sc)->hn_flags & HN_FLAG_NO_SLEEPING) == 0)
260
261#define HN_CAP_VLAN			0x0001
262#define HN_CAP_MTU			0x0002
263#define HN_CAP_IPCS			0x0004
264#define HN_CAP_TCP4CS			0x0008
265#define HN_CAP_TCP6CS			0x0010
266#define HN_CAP_UDP4CS			0x0020
267#define HN_CAP_UDP6CS			0x0040
268#define HN_CAP_TSO4			0x0080
269#define HN_CAP_TSO6			0x0100
270#define HN_CAP_HASHVAL			0x0200
271
272/* Capability description for use with printf(9) %b identifier. */
273#define HN_CAP_BITS				\
274	"\020\1VLAN\2MTU\3IPCS\4TCP4CS\5TCP6CS"	\
275	"\6UDP4CS\7UDP6CS\10TSO4\11TSO6\12HASHVAL"
276
277#define HN_LINK_FLAG_LINKUP		0x0001
278#define HN_LINK_FLAG_NETCHG		0x0002
279
280#endif	/* !_IF_HNVAR_H_ */
281