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