xref: /titanic_50/usr/src/uts/common/xen/io/xnb.h (revision d62bc4badc1c1f1549c961cfb8b420e650e1272b)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include <sys/types.h>
35 #include <sys/kstat.h>
36 #include <sys/stream.h>
37 #include <sys/ethernet.h>
38 #include <sys/hypervisor.h>
39 #include <xen/public/io/netif.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
46 #define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
47 
48 #define	XNBMAXPKT	1500		/* MTU size */
49 
50 /* DEBUG flags */
51 #define	XNBDDI		0x01
52 #define	XNBTRACE	0x02
53 #define	XNBSEND		0x04
54 #define	XNBRECV		0x08
55 #define	XNBINTR		0x10
56 #define	XNBRING		0x20
57 #define	XNBCKSUM	0x40
58 
59 typedef struct xnb xnb_t;
60 
61 /*
62  * The xnb module provides core inter-domain network protocol functionality.
63  * It is connected to the rest of Solaris in two ways:
64  * - as a GLDv3 driver (with xnbu),
65  * - as a GLDv3 consumer (with xnbo).
66  *
67  * The different modes of operation are termed "flavours" and each
68  * instance of an xnb based driver operates in one and only one mode.
69  * The common xnb driver exports a set of functions to these drivers
70  * (declarations at the foot of this file) and calls back into the
71  * drivers via the xnb_flavour_t structure.
72  */
73 typedef struct xnb_flavour {
74 	void		(*xf_recv)(xnb_t *, mblk_t *);
75 	void		(*xf_peer_connected)(xnb_t *);
76 	void		(*xf_peer_disconnected)(xnb_t *);
77 	boolean_t	(*xf_hotplug_connected)(xnb_t *);
78 	mblk_t		*(*xf_cksum_from_peer)(xnb_t *, mblk_t *, uint16_t);
79 	uint16_t	(*xf_cksum_to_peer)(xnb_t *, mblk_t *);
80 } xnb_flavour_t;
81 
82 typedef struct xnb_rxbuf {
83 	frtn_t			xr_free_rtn;
84 	xnb_t			*xr_xnbp;
85 	gnttab_map_grant_ref_t	xr_mop;
86 	RING_IDX		xr_id;
87 	uint16_t		xr_status;
88 	unsigned int		xr_flags;
89 
90 #define	XNB_RXBUF_INUSE	0x01
91 
92 } xnb_rxbuf_t;
93 
94 /* Per network-interface-controller driver private structure */
95 struct xnb {
96 	/* most interesting stuff first to assist debugging */
97 	dev_info_t		*xnb_devinfo;	/* System per-device info. */
98 
99 	xnb_flavour_t		*xnb_flavour;
100 	void			*xnb_flavour_data;
101 
102 	boolean_t		xnb_irq;
103 	unsigned char		xnb_mac_addr[ETHERADDRL];
104 
105 	uint64_t		xnb_stat_ipackets;
106 	uint64_t		xnb_stat_opackets;
107 	uint64_t		xnb_stat_rbytes;
108 	uint64_t		xnb_stat_obytes;
109 
110 	uint64_t		xnb_stat_intr;
111 	uint64_t		xnb_stat_xmit_defer;
112 
113 	uint64_t		xnb_stat_tx_cksum_deferred;
114 	uint64_t		xnb_stat_rx_cksum_no_need;
115 
116 	uint64_t		xnb_stat_tx_notify_sent;
117 	uint64_t		xnb_stat_tx_notify_deferred;
118 
119 	uint64_t		xnb_stat_rx_notify_sent;
120 	uint64_t		xnb_stat_rx_notify_deferred;
121 
122 	uint64_t		xnb_stat_tx_too_early;
123 	uint64_t		xnb_stat_rx_too_early;
124 	uint64_t		xnb_stat_rx_allocb_failed;
125 	uint64_t		xnb_stat_tx_allocb_failed;
126 	uint64_t		xnb_stat_tx_foreign_page;
127 	uint64_t		xnb_stat_mac_full;
128 	uint64_t		xnb_stat_spurious_intr;
129 	uint64_t		xnb_stat_allocation_success;
130 	uint64_t		xnb_stat_allocation_failure;
131 	uint64_t		xnb_stat_small_allocation_success;
132 	uint64_t		xnb_stat_small_allocation_failure;
133 	uint64_t		xnb_stat_other_allocation_failure;
134 
135 	uint64_t		xnb_stat_tx_pagebndry_crossed;
136 	uint64_t		xnb_stat_tx_cpoparea_grown;
137 
138 	uint64_t		xnb_stat_csum_hardware;
139 	uint64_t		xnb_stat_csum_software;
140 
141 	kstat_t			*xnb_kstat_aux;
142 
143 	boolean_t		xnb_cksum_offload;
144 
145 	ddi_iblock_cookie_t	xnb_icookie;
146 
147 	kmutex_t		xnb_rx_lock;
148 	kmutex_t		xnb_tx_lock;
149 
150 	int			xnb_rx_unmop_count;
151 	int			xnb_rx_buf_count;
152 	boolean_t		xnb_rx_pages_writable;
153 
154 	netif_rx_back_ring_t	xnb_rx_ring;	/* rx interface struct ptr */
155 	void			*xnb_rx_ring_addr;
156 	grant_ref_t		xnb_rx_ring_ref;
157 	grant_handle_t		xnb_rx_ring_handle;
158 
159 	netif_tx_back_ring_t	xnb_tx_ring;	/* tx interface struct ptr */
160 	void			*xnb_tx_ring_addr;
161 	grant_ref_t		xnb_tx_ring_ref;
162 	grant_handle_t		xnb_tx_ring_handle;
163 
164 	boolean_t		xnb_connected;
165 	boolean_t		xnb_hotplugged;
166 	boolean_t		xnb_detachable;
167 	int			xnb_evtchn;	/* channel to front end */
168 	domid_t			xnb_peer;
169 
170 	xnb_rxbuf_t			*xnb_rx_bufp[NET_TX_RING_SIZE];
171 	gnttab_map_grant_ref_t		xnb_rx_mop[NET_TX_RING_SIZE];
172 	gnttab_unmap_grant_ref_t	xnb_rx_unmop[NET_TX_RING_SIZE];
173 
174 	/* store information for unmop */
175 	xnb_rxbuf_t		*xnb_rx_unmop_rxp[NET_TX_RING_SIZE];
176 
177 	caddr_t			xnb_tx_va;
178 	gnttab_transfer_t	xnb_tx_top[NET_RX_RING_SIZE];
179 
180 	boolean_t		xnb_hv_copy;	/* do we do hypervisor copy? */
181 	gnttab_copy_t		*xnb_tx_cpop;
182 #define	CPOP_DEFCNT 	8
183 	size_t			xnb_cpop_sz; 	/* in elements, not bytes */
184 };
185 
186 extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
187 extern void xnb_detach(dev_info_t *);
188 extern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *);
189 extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif	/* _SYS_XNB_H */
196