xref: /illumos-gate/usr/src/uts/common/xen/io/xnf.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright (c) 2014, 2017 by Delphix. All rights reserved.
29  */
30 
31 #ifndef _SYS_XNF_H
32 #define	_SYS_XNF_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * As of April 2017, TX and RX ring sizes are fixed to 1 page in
40  * size and Xen doesn't support changing it.
41  * This represents 256 entries.
42  */
43 #define	NET_TX_RING_SIZE  __CONST_RING_SIZE(netif_tx, PAGESIZE)
44 #define	NET_RX_RING_SIZE  __CONST_RING_SIZE(netif_rx, PAGESIZE)
45 
46 /*
47  * There is no MTU limit, however for all practical purposes hardware won't
48  * support anything much larger than 9k. We put an arbitrary 16k limit.
49  */
50 #define	XNF_MAXPKT	16384
51 #define	XNF_FRAMESIZE	1514		/* frame size including MAC header */
52 
53 /*
54  * Based on XEN_NETIF_NR_SLOTS_MIN in Linux. Packets that span more pages
55  * than this must be defragmented or dropped.
56  */
57 #define	XEN_MAX_TX_DATA_PAGES	18
58 /*
59  * We keep one extra slot for LSO
60  */
61 #define	XEN_MAX_SLOTS_PER_TX	(XEN_MAX_TX_DATA_PAGES + 1)
62 
63 #define	XEN_DATA_BOUNDARY	0x1000
64 
65 /*
66  * Information about each receive buffer and any transmit look-aside
67  * buffers.
68  */
69 typedef struct xnf_buf {
70 	frtn_t			free_rtn;
71 	struct xnf		*xnfp;
72 	ddi_dma_handle_t	dma_handle;
73 	caddr_t			buf;		/* DMA-able data buffer */
74 	paddr_t			buf_phys;
75 	mfn_t			buf_mfn;
76 	size_t			len;
77 	struct xnf_buf		*next;	/* For linking into free list */
78 	ddi_acc_handle_t	acc_handle;
79 	grant_ref_t		grant_ref;	/* grant table reference */
80 	uint16_t		id;		/* buffer id */
81 	unsigned int		gen;
82 } xnf_buf_t;
83 
84 /*
85  * Information about each transmit buffer.
86  */
87 typedef enum xnf_txbuf_type {
88 	TX_DATA = 1,
89 	TX_MCAST_REQ,
90 	TX_MCAST_RSP
91 } xnf_txbuf_type_t;
92 
93 /*
94  * A xnf_txbuf is used to store ancillary data for a netif_tx_request_t.
95  * A tx packet can span multiple xnf_txbuf's, linked together through tx_next
96  * and tx_prev; tx_head points to the head of the chain.
97  */
98 typedef struct xnf_txbuf {
99 	struct xnf_txbuf	*tx_next;
100 	struct xnf_txbuf	*tx_prev;
101 	struct xnf_txbuf	*tx_head;
102 	xnf_txbuf_type_t	tx_type;
103 	netif_tx_request_t	tx_txreq;
104 	netif_extra_info_t	tx_extra;
105 	/* Used for TX_DATA types */
106 	ddi_dma_handle_t	tx_dma_handle;
107 	boolean_t		tx_handle_bound;
108 	mblk_t			*tx_mp;
109 	xnf_buf_t		*tx_bdesc; /* Look-aside buffer, if used. */
110 	int			tx_frags_to_ack;
111 	/* Used for TX_MCAST types */
112 	int16_t			tx_status;
113 	/* Used for debugging */
114 	mfn_t			tx_mfn;
115 	RING_IDX		tx_slot;
116 } xnf_txbuf_t;
117 
118 #define	TXBUF_SETNEXT(head, next)	\
119 	head->tx_next = next;		\
120 	next->tx_prev = head;
121 
122 /*
123  * Information about each outstanding transmit operation.
124  */
125 typedef struct xnf_txid {
126 	uint16_t	id;	/* Id of this transmit buffer. */
127 	uint16_t	next;	/* Freelist of ids. */
128 	xnf_txbuf_t	*txbuf;	/* Buffer details. */
129 } xnf_txid_t;
130 
131 /*
132  * Per-instance data.
133  */
134 typedef struct xnf {
135 	/* most interesting stuff first to assist debugging */
136 	dev_info_t		*xnf_devinfo;
137 	mac_handle_t		xnf_mh;
138 	unsigned char		xnf_mac_addr[ETHERADDRL];
139 	uint32_t		xnf_mtu;
140 
141 	unsigned int		xnf_gen;	/* Increments on resume. */
142 
143 	boolean_t		xnf_connected;
144 	boolean_t		xnf_running;
145 
146 	boolean_t		xnf_be_rx_copy;
147 	boolean_t		xnf_be_mcast_control;
148 	boolean_t		xnf_be_tx_sg;
149 	boolean_t		xnf_be_lso;
150 
151 	uint64_t		xnf_stat_interrupts;
152 	uint64_t		xnf_stat_unclaimed_interrupts;
153 	uint64_t		xnf_stat_norxbuf;
154 	uint64_t		xnf_stat_rx_drop;
155 	uint64_t		xnf_stat_errrx;
156 
157 	uint64_t		xnf_stat_tx_pullup;
158 	uint64_t		xnf_stat_tx_lookaside;
159 	uint64_t		xnf_stat_tx_defer;
160 	uint64_t		xnf_stat_tx_drop;
161 	uint64_t		xnf_stat_tx_eth_hdr_split;
162 	uint64_t		xnf_stat_mac_rcv_error;
163 	uint64_t		xnf_stat_runt;
164 
165 	uint64_t		xnf_stat_ipackets;
166 	uint64_t		xnf_stat_opackets;
167 	uint64_t		xnf_stat_rbytes;
168 	uint64_t		xnf_stat_obytes;
169 
170 	uint64_t		xnf_stat_tx_cksum_deferred;
171 	uint64_t		xnf_stat_rx_cksum_no_need;
172 
173 	uint64_t		xnf_stat_buf_allocated;
174 	uint64_t		xnf_stat_buf_outstanding;
175 	uint64_t		xnf_stat_gref_outstanding;
176 	uint64_t		xnf_stat_gref_failure;
177 	uint64_t		xnf_stat_gref_peak;
178 	uint64_t		xnf_stat_rx_allocb_fail;
179 	uint64_t		xnf_stat_rx_desballoc_fail;
180 
181 	kstat_t			*xnf_kstat_aux;
182 
183 	ddi_iblock_cookie_t	xnf_icookie;
184 
185 	netif_tx_front_ring_t	xnf_tx_ring;
186 	ddi_dma_handle_t	xnf_tx_ring_dma_handle;
187 	ddi_acc_handle_t	xnf_tx_ring_dma_acchandle;
188 	paddr_t			xnf_tx_ring_phys_addr;
189 	grant_ref_t		xnf_tx_ring_ref;
190 
191 	xnf_txid_t		*xnf_tx_pkt_id;
192 	uint16_t		xnf_tx_pkt_id_head;
193 	kmutex_t		xnf_txlock;
194 	kmutex_t		xnf_schedlock;
195 	boolean_t		xnf_need_sched;
196 	kcondvar_t		xnf_cv_tx_slots;
197 	kmem_cache_t		*xnf_tx_buf_cache;
198 
199 	netif_rx_front_ring_t	xnf_rx_ring;
200 	ddi_dma_handle_t	xnf_rx_ring_dma_handle;
201 	ddi_acc_handle_t	xnf_rx_ring_dma_acchandle;
202 	paddr_t			xnf_rx_ring_phys_addr;
203 	grant_ref_t		xnf_rx_ring_ref;
204 
205 	xnf_buf_t		**xnf_rx_pkt_info;
206 	kmutex_t		xnf_rxlock;
207 	mblk_t			*xnf_rx_head;
208 	mblk_t			*xnf_rx_tail;
209 	boolean_t		xnf_rx_new_buffers_posted;
210 	kmem_cache_t		*xnf_buf_cache;
211 
212 	uint16_t		xnf_evtchn;
213 
214 	kmutex_t		xnf_gref_lock;
215 	grant_ref_t		xnf_gref_head;
216 
217 	kcondvar_t		xnf_cv_state;
218 	kcondvar_t		xnf_cv_multicast;
219 	uint_t			xnf_pending_multicast;
220 } xnf_t;
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif	/* _SYS_XNF_H */
227