xref: /illumos-gate/usr/src/uts/common/xen/io/xnb.h (revision 66582b606a8194f7f3ba5b3a3a6dca5b0d346361)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * xnb.h - definitions for Xen dom0 network driver
27  */
28 
29 #ifndef _SYS_XNB_H
30 #define	_SYS_XNB_H
31 
32 #include <sys/types.h>
33 #include <sys/kstat.h>
34 #include <sys/stream.h>
35 #include <sys/ethernet.h>
36 #include <sys/hypervisor.h>
37 #include <sys/sysmacros.h>
38 #include <xen/public/io/netif.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #define	NET_TX_RING_SIZE  __CONST_RING_SIZE(netif_tx, PAGESIZE)
45 #define	NET_RX_RING_SIZE  __CONST_RING_SIZE(netif_rx, PAGESIZE)
46 
47 #define	XNBMAXPKT	1500		/* MTU size */
48 
49 /* DEBUG flags */
50 #define	XNBDDI		0x01
51 #define	XNBTRACE	0x02
52 #define	XNBSEND		0x04
53 #define	XNBRECV		0x08
54 #define	XNBINTR		0x10
55 #define	XNBRING		0x20
56 #define	XNBCKSUM	0x40
57 
58 #define	XNB_STATE_INIT	0x01
59 #define	XNB_STATE_READY	0x02
60 
61 typedef struct xnb xnb_t;
62 
63 /*
64  * The xnb module provides core inter-domain network protocol functionality.
65  * It is connected to the rest of Solaris in two ways:
66  * - as a GLDv3 driver (with xnbu),
67  * - as a GLDv3 consumer (with xnbo).
68  *
69  * The different modes of operation are termed "flavours" and each
70  * instance of an xnb based driver operates in one and only one mode.
71  * The common xnb driver exports a set of functions to these drivers
72  * (declarations at the foot of this file) and calls back into the
73  * drivers via the xnb_flavour_t structure.
74  */
75 typedef struct xnb_flavour {
76 	void		(*xf_from_peer)(xnb_t *, mblk_t *);
77 	boolean_t	(*xf_peer_connected)(xnb_t *);
78 	void		(*xf_peer_disconnected)(xnb_t *);
79 	boolean_t	(*xf_hotplug_connected)(xnb_t *);
80 	boolean_t	(*xf_start_connect)(xnb_t *);
81 	mblk_t		*(*xf_cksum_from_peer)(xnb_t *, mblk_t *, uint16_t);
82 	uint16_t	(*xf_cksum_to_peer)(xnb_t *, mblk_t *);
83 	boolean_t	(*xf_mcast_add)(xnb_t *, ether_addr_t *);
84 	boolean_t	(*xf_mcast_del)(xnb_t *, ether_addr_t *);
85 } xnb_flavour_t;
86 
87 typedef struct xnb_txbuf {
88 	frtn_t			xt_free_rtn;
89 	xnb_t			*xt_xnbp;
90 	struct xnb_txbuf	*xt_next;
91 	RING_IDX		xt_id;
92 	RING_IDX		xt_idx;
93 	uint16_t		xt_status;
94 
95 	ddi_dma_handle_t	xt_dma_handle;
96 	ddi_acc_handle_t	xt_acc_handle;
97 	caddr_t			xt_buf;
98 	size_t			xt_buflen;
99 	mfn_t			xt_mfn;
100 
101 	mblk_t			*xt_mblk;
102 
103 	unsigned int		xt_flags;
104 
105 #define	XNB_TXBUF_INUSE	0x01
106 
107 } xnb_txbuf_t;
108 
109 /* Per network-interface-controller driver private structure */
110 struct xnb {
111 	/* most interesting stuff first to assist debugging */
112 	dev_info_t		*xnb_devinfo;	/* System per-device info. */
113 
114 	xnb_flavour_t		*xnb_flavour;
115 	void			*xnb_flavour_data;
116 
117 	boolean_t		xnb_irq;
118 	unsigned char		xnb_mac_addr[ETHERADDRL];
119 
120 	uint64_t		xnb_stat_ipackets;
121 	uint64_t		xnb_stat_opackets;
122 	uint64_t		xnb_stat_rbytes;
123 	uint64_t		xnb_stat_obytes;
124 
125 	uint64_t		xnb_stat_intr;
126 	uint64_t		xnb_stat_rx_defer;
127 
128 	uint64_t		xnb_stat_rx_cksum_deferred;
129 	uint64_t		xnb_stat_tx_cksum_no_need;
130 
131 	uint64_t		xnb_stat_rx_rsp_notok;
132 
133 	uint64_t		xnb_stat_tx_notify_sent;
134 	uint64_t		xnb_stat_tx_notify_deferred;
135 
136 	uint64_t		xnb_stat_rx_notify_sent;
137 	uint64_t		xnb_stat_rx_notify_deferred;
138 
139 	uint64_t		xnb_stat_tx_too_early;
140 	uint64_t		xnb_stat_rx_too_early;
141 	uint64_t		xnb_stat_rx_allocb_failed;
142 	uint64_t		xnb_stat_tx_allocb_failed;
143 	uint64_t		xnb_stat_rx_foreign_page;
144 	uint64_t		xnb_stat_tx_overflow_page;
145 	uint64_t		xnb_stat_tx_unexpected_flags;
146 	uint64_t		xnb_stat_mac_full;
147 	uint64_t		xnb_stat_spurious_intr;
148 	uint64_t		xnb_stat_allocation_success;
149 	uint64_t		xnb_stat_allocation_failure;
150 	uint64_t		xnb_stat_small_allocation_success;
151 	uint64_t		xnb_stat_small_allocation_failure;
152 	uint64_t		xnb_stat_other_allocation_failure;
153 
154 	uint64_t		xnb_stat_rx_pagebndry_crossed;
155 	uint64_t		xnb_stat_rx_cpoparea_grown;
156 
157 	uint64_t		xnb_stat_csum_hardware;
158 	uint64_t		xnb_stat_csum_software;
159 
160 	kstat_t			*xnb_kstat_aux;
161 
162 	ddi_iblock_cookie_t	xnb_icookie;
163 
164 	kmutex_t		xnb_rx_lock;
165 	kmutex_t		xnb_tx_lock;
166 	kmutex_t		xnb_state_lock;
167 
168 	int			xnb_be_status;
169 	int			xnb_fe_status;
170 
171 	kmem_cache_t		*xnb_tx_buf_cache;
172 	uint32_t		xnb_tx_buf_count;
173 	int			xnb_tx_buf_outstanding;
174 
175 	netif_rx_back_ring_t	xnb_rx_ring;	/* rx interface struct ptr */
176 	void			*xnb_rx_ring_addr;
177 	grant_ref_t		xnb_rx_ring_ref;
178 	grant_handle_t		xnb_rx_ring_handle;
179 
180 	netif_tx_back_ring_t	xnb_tx_ring;	/* tx interface struct ptr */
181 	void			*xnb_tx_ring_addr;
182 	grant_ref_t		xnb_tx_ring_ref;
183 	grant_handle_t		xnb_tx_ring_handle;
184 
185 	boolean_t		xnb_connected;
186 	boolean_t		xnb_hotplugged;
187 	boolean_t		xnb_detachable;
188 	int			xnb_evtchn;	/* channel to front end */
189 	evtchn_port_t		xnb_fe_evtchn;
190 	domid_t			xnb_peer;
191 
192 	xnb_txbuf_t		*xnb_tx_bufp[NET_TX_RING_SIZE];
193 	gnttab_copy_t		xnb_tx_cop[NET_TX_RING_SIZE];
194 
195 	caddr_t			xnb_rx_va;
196 	gnttab_transfer_t	xnb_rx_top[NET_RX_RING_SIZE];
197 
198 	boolean_t		xnb_rx_hv_copy;
199 	boolean_t		xnb_multicast_control;
200 	boolean_t		xnb_no_csum_offload;
201 
202 	gnttab_copy_t		*xnb_rx_cpop;
203 #define	CPOP_DEFCNT 	8
204 	size_t			xnb_rx_cpop_count; 	/* in elements */
205 };
206 
207 extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
208 extern void xnb_detach(dev_info_t *);
209 extern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *);
210 extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif	/* _SYS_XNB_H */
217