xref: /titanic_44/usr/src/uts/common/xen/io/xnb.h (revision 98157a7002f4f2cf7978f3084ca5577f0a1d72b2)
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 2008 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_rsp_notok;
117 
118 	uint64_t		xnb_stat_tx_notify_sent;
119 	uint64_t		xnb_stat_tx_notify_deferred;
120 
121 	uint64_t		xnb_stat_rx_notify_sent;
122 	uint64_t		xnb_stat_rx_notify_deferred;
123 
124 	uint64_t		xnb_stat_tx_too_early;
125 	uint64_t		xnb_stat_rx_too_early;
126 	uint64_t		xnb_stat_rx_allocb_failed;
127 	uint64_t		xnb_stat_tx_allocb_failed;
128 	uint64_t		xnb_stat_tx_foreign_page;
129 	uint64_t		xnb_stat_mac_full;
130 	uint64_t		xnb_stat_spurious_intr;
131 	uint64_t		xnb_stat_allocation_success;
132 	uint64_t		xnb_stat_allocation_failure;
133 	uint64_t		xnb_stat_small_allocation_success;
134 	uint64_t		xnb_stat_small_allocation_failure;
135 	uint64_t		xnb_stat_other_allocation_failure;
136 
137 	uint64_t		xnb_stat_tx_pagebndry_crossed;
138 	uint64_t		xnb_stat_tx_cpoparea_grown;
139 
140 	uint64_t		xnb_stat_csum_hardware;
141 	uint64_t		xnb_stat_csum_software;
142 
143 	kstat_t			*xnb_kstat_aux;
144 
145 	boolean_t		xnb_cksum_offload;
146 
147 	ddi_iblock_cookie_t	xnb_icookie;
148 
149 	kmutex_t		xnb_rx_lock;
150 	kmutex_t		xnb_tx_lock;
151 
152 	int			xnb_rx_unmop_count;
153 	int			xnb_rx_buf_count;
154 	boolean_t		xnb_rx_pages_writable;
155 
156 	netif_rx_back_ring_t	xnb_rx_ring;	/* rx interface struct ptr */
157 	void			*xnb_rx_ring_addr;
158 	grant_ref_t		xnb_rx_ring_ref;
159 	grant_handle_t		xnb_rx_ring_handle;
160 
161 	netif_tx_back_ring_t	xnb_tx_ring;	/* tx interface struct ptr */
162 	void			*xnb_tx_ring_addr;
163 	grant_ref_t		xnb_tx_ring_ref;
164 	grant_handle_t		xnb_tx_ring_handle;
165 
166 	boolean_t		xnb_connected;
167 	boolean_t		xnb_hotplugged;
168 	boolean_t		xnb_detachable;
169 	int			xnb_evtchn;	/* channel to front end */
170 	domid_t			xnb_peer;
171 
172 	xnb_rxbuf_t			*xnb_rx_bufp[NET_TX_RING_SIZE];
173 	gnttab_map_grant_ref_t		xnb_rx_mop[NET_TX_RING_SIZE];
174 	gnttab_unmap_grant_ref_t	xnb_rx_unmop[NET_TX_RING_SIZE];
175 
176 	/* store information for unmop */
177 	xnb_rxbuf_t		*xnb_rx_unmop_rxp[NET_TX_RING_SIZE];
178 
179 	caddr_t			xnb_tx_va;
180 	gnttab_transfer_t	xnb_tx_top[NET_RX_RING_SIZE];
181 
182 	boolean_t		xnb_hv_copy;	/* do we do hypervisor copy? */
183 	gnttab_copy_t		*xnb_tx_cpop;
184 #define	CPOP_DEFCNT 	8
185 	size_t			xnb_cpop_sz; 	/* in elements, not bytes */
186 };
187 
188 extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
189 extern void xnb_detach(dev_info_t *);
190 extern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *);
191 extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif	/* _SYS_XNB_H */
198