xref: /illumos-gate/usr/src/uts/common/xen/io/xnf.h (revision 03270635d68df6a0392fb8f4b7c04acad764648b)
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 /* DEBUG flags */
54 #define	XNF_DEBUG_DDI		0x01
55 #define	XNF_DEBUG_TRACE		0x02
56 
57 /*
58  * Based on XEN_NETIF_NR_SLOTS_MIN in Linux. Packets that span more pages
59  * than this must be defragmented or dropped.
60  */
61 #define	XEN_MAX_TX_DATA_PAGES	18
62 /*
63  * We keep one extra slot for LSO
64  */
65 #define	XEN_MAX_SLOTS_PER_TX	(XEN_MAX_TX_DATA_PAGES + 1)
66 
67 #define	XEN_DATA_BOUNDARY	0x1000
68 
69 /*
70  * Information about each receive buffer and any transmit look-aside
71  * buffers.
72  */
73 typedef struct xnf_buf {
74 	frtn_t			free_rtn;
75 	struct xnf		*xnfp;
76 	ddi_dma_handle_t	dma_handle;
77 	caddr_t			buf;		/* DMA-able data buffer */
78 	paddr_t			buf_phys;
79 	mfn_t			buf_mfn;
80 	size_t			len;
81 	struct xnf_buf		*next;	/* For linking into free list */
82 	ddi_acc_handle_t	acc_handle;
83 	grant_ref_t		grant_ref;	/* grant table reference */
84 	uint16_t		id;		/* buffer id */
85 	unsigned int		gen;
86 } xnf_buf_t;
87 
88 /*
89  * Information about each transmit buffer.
90  */
91 typedef enum xnf_txbuf_type {
92 	TX_DATA = 1,
93 	TX_MCAST_REQ,
94 	TX_MCAST_RSP
95 } xnf_txbuf_type_t;
96 
97 /*
98  * A xnf_txbuf is used to store ancillary data for a netif_tx_request_t.
99  * A tx packet can span multiple xnf_txbuf's, linked together through tx_next
100  * and tx_prev; tx_head points to the head of the chain.
101  */
102 typedef struct xnf_txbuf {
103 	struct xnf_txbuf	*tx_next;
104 	struct xnf_txbuf	*tx_prev;
105 	struct xnf_txbuf	*tx_head;
106 	xnf_txbuf_type_t	tx_type;
107 	netif_tx_request_t	tx_txreq;
108 	netif_extra_info_t	tx_extra;
109 	/* Used for TX_DATA types */
110 	ddi_dma_handle_t	tx_dma_handle;
111 	boolean_t		tx_handle_bound;
112 	mblk_t			*tx_mp;
113 	xnf_buf_t		*tx_bdesc; /* Look-aside buffer, if used. */
114 	int			tx_frags_to_ack;
115 	/* Used for TX_MCAST types */
116 	int16_t			tx_status;
117 	/* Used for debugging */
118 	mfn_t			tx_mfn;
119 	RING_IDX		tx_slot;
120 } xnf_txbuf_t;
121 
122 #define	TXBUF_SETNEXT(head, next)	\
123 	head->tx_next = next;		\
124 	next->tx_prev = head;
125 
126 /*
127  * Information about each outstanding transmit operation.
128  */
129 typedef struct xnf_txid {
130 	uint16_t	id;	/* Id of this transmit buffer. */
131 	uint16_t	next;	/* Freelist of ids. */
132 	xnf_txbuf_t	*txbuf;	/* Buffer details. */
133 } xnf_txid_t;
134 
135 /*
136  * Per-instance data.
137  */
138 typedef struct xnf {
139 	/* most interesting stuff first to assist debugging */
140 	dev_info_t		*xnf_devinfo;
141 	mac_handle_t		xnf_mh;
142 	unsigned char		xnf_mac_addr[ETHERADDRL];
143 	uint32_t		xnf_mtu;
144 
145 	unsigned int		xnf_gen;	/* Increments on resume. */
146 
147 	boolean_t		xnf_connected;
148 	boolean_t		xnf_running;
149 
150 	boolean_t		xnf_be_rx_copy;
151 	boolean_t		xnf_be_mcast_control;
152 	boolean_t		xnf_be_tx_sg;
153 	boolean_t		xnf_be_lso;
154 
155 	uint64_t		xnf_stat_interrupts;
156 	uint64_t		xnf_stat_unclaimed_interrupts;
157 	uint64_t		xnf_stat_norxbuf;
158 	uint64_t		xnf_stat_rx_drop;
159 	uint64_t		xnf_stat_errrx;
160 
161 	uint64_t		xnf_stat_tx_pullup;
162 	uint64_t		xnf_stat_tx_lookaside;
163 	uint64_t		xnf_stat_tx_defer;
164 	uint64_t		xnf_stat_tx_drop;
165 	uint64_t		xnf_stat_tx_eth_hdr_split;
166 	uint64_t		xnf_stat_mac_rcv_error;
167 	uint64_t		xnf_stat_runt;
168 
169 	uint64_t		xnf_stat_ipackets;
170 	uint64_t		xnf_stat_opackets;
171 	uint64_t		xnf_stat_rbytes;
172 	uint64_t		xnf_stat_obytes;
173 
174 	uint64_t		xnf_stat_tx_cksum_deferred;
175 	uint64_t		xnf_stat_rx_cksum_no_need;
176 
177 	uint64_t		xnf_stat_buf_allocated;
178 	uint64_t		xnf_stat_buf_outstanding;
179 	uint64_t		xnf_stat_gref_outstanding;
180 	uint64_t		xnf_stat_gref_failure;
181 	uint64_t		xnf_stat_gref_peak;
182 	uint64_t		xnf_stat_rx_allocb_fail;
183 	uint64_t		xnf_stat_rx_desballoc_fail;
184 
185 	kstat_t			*xnf_kstat_aux;
186 
187 	ddi_iblock_cookie_t	xnf_icookie;
188 
189 	netif_tx_front_ring_t	xnf_tx_ring;
190 	ddi_dma_handle_t	xnf_tx_ring_dma_handle;
191 	ddi_acc_handle_t	xnf_tx_ring_dma_acchandle;
192 	paddr_t			xnf_tx_ring_phys_addr;
193 	grant_ref_t		xnf_tx_ring_ref;
194 
195 	xnf_txid_t		*xnf_tx_pkt_id;
196 	uint16_t		xnf_tx_pkt_id_head;
197 	kmutex_t		xnf_txlock;
198 	kmutex_t		xnf_schedlock;
199 	boolean_t		xnf_need_sched;
200 	kcondvar_t		xnf_cv_tx_slots;
201 	kmem_cache_t		*xnf_tx_buf_cache;
202 
203 	netif_rx_front_ring_t	xnf_rx_ring;
204 	ddi_dma_handle_t	xnf_rx_ring_dma_handle;
205 	ddi_acc_handle_t	xnf_rx_ring_dma_acchandle;
206 	paddr_t			xnf_rx_ring_phys_addr;
207 	grant_ref_t		xnf_rx_ring_ref;
208 
209 	xnf_buf_t		**xnf_rx_pkt_info;
210 	kmutex_t		xnf_rxlock;
211 	mblk_t			*xnf_rx_head;
212 	mblk_t			*xnf_rx_tail;
213 	boolean_t		xnf_rx_new_buffers_posted;
214 	kmem_cache_t		*xnf_buf_cache;
215 
216 	uint16_t		xnf_evtchn;
217 
218 	kmutex_t		xnf_gref_lock;
219 	grant_ref_t		xnf_gref_head;
220 
221 	kcondvar_t		xnf_cv_state;
222 	kcondvar_t		xnf_cv_multicast;
223 	uint_t			xnf_pending_multicast;
224 } xnf_t;
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 #endif	/* _SYS_XNF_H */
231