xref: /titanic_41/usr/src/uts/common/xen/io/xnb.h (revision 95c2d3023b88b9097d9822eb47ace5466e6d1cf4)
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 #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 typedef struct xnb xnb_t;
58 
59 /*
60  * The xnb module provides core inter-domain network protocol functionality.
61  * It is connected to the rest of Solaris in two ways:
62  * - as a GLDv3 driver (with xnbu),
63  * - as a GLDv3 consumer (with xnbo).
64  *
65  * The different modes of operation are termed "flavours" and each
66  * instance of an xnb based driver operates in one and only one mode.
67  * The common xnb driver exports a set of functions to these drivers
68  * (declarations at the foot of this file) and calls back into the
69  * drivers via the xnb_flavour_t structure.
70  */
71 typedef struct xnb_flavour {
72 	void		(*xf_from_peer)(xnb_t *, mblk_t *);
73 	void		(*xf_peer_connected)(xnb_t *);
74 	void		(*xf_peer_disconnected)(xnb_t *);
75 	boolean_t	(*xf_hotplug_connected)(xnb_t *);
76 	mblk_t		*(*xf_cksum_from_peer)(xnb_t *, mblk_t *, uint16_t);
77 	uint16_t	(*xf_cksum_to_peer)(xnb_t *, mblk_t *);
78 } xnb_flavour_t;
79 
80 typedef struct xnb_txbuf {
81 	frtn_t			xt_free_rtn;
82 	xnb_t			*xt_xnbp;
83 	gnttab_map_grant_ref_t	xt_mop;
84 	RING_IDX		xt_id;
85 	uint16_t		xt_status;
86 	unsigned int		xt_flags;
87 
88 #define	XNB_TXBUF_INUSE	0x01
89 
90 } xnb_txbuf_t;
91 
92 /* Per network-interface-controller driver private structure */
93 struct xnb {
94 	/* most interesting stuff first to assist debugging */
95 	dev_info_t		*xnb_devinfo;	/* System per-device info. */
96 
97 	xnb_flavour_t		*xnb_flavour;
98 	void			*xnb_flavour_data;
99 
100 	boolean_t		xnb_irq;
101 	unsigned char		xnb_mac_addr[ETHERADDRL];
102 
103 	uint64_t		xnb_stat_ipackets;
104 	uint64_t		xnb_stat_opackets;
105 	uint64_t		xnb_stat_rbytes;
106 	uint64_t		xnb_stat_obytes;
107 
108 	uint64_t		xnb_stat_intr;
109 	uint64_t		xnb_stat_rx_defer;
110 
111 	uint64_t		xnb_stat_rx_cksum_deferred;
112 	uint64_t		xnb_stat_tx_cksum_no_need;
113 
114 	uint64_t		xnb_stat_rx_rsp_notok;
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_rx_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_rx_pagebndry_crossed;
136 	uint64_t		xnb_stat_rx_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_tx_unmop_count;
151 	int			xnb_tx_buf_count;
152 	boolean_t		xnb_tx_pages_writable;
153 	boolean_t		xnb_tx_always_copy;
154 
155 	netif_rx_back_ring_t	xnb_rx_ring;	/* rx interface struct ptr */
156 	void			*xnb_rx_ring_addr;
157 	grant_ref_t		xnb_rx_ring_ref;
158 	grant_handle_t		xnb_rx_ring_handle;
159 
160 	netif_tx_back_ring_t	xnb_tx_ring;	/* tx interface struct ptr */
161 	void			*xnb_tx_ring_addr;
162 	grant_ref_t		xnb_tx_ring_ref;
163 	grant_handle_t		xnb_tx_ring_handle;
164 
165 	boolean_t		xnb_connected;
166 	boolean_t		xnb_hotplugged;
167 	boolean_t		xnb_detachable;
168 	int			xnb_evtchn;	/* channel to front end */
169 	domid_t			xnb_peer;
170 
171 	xnb_txbuf_t			*xnb_tx_bufp[NET_TX_RING_SIZE];
172 	gnttab_map_grant_ref_t		xnb_tx_mop[NET_TX_RING_SIZE];
173 	gnttab_unmap_grant_ref_t	xnb_tx_unmop[NET_TX_RING_SIZE];
174 
175 	/* store information for unmop */
176 	xnb_txbuf_t		*xnb_tx_unmop_txp[NET_TX_RING_SIZE];
177 
178 	caddr_t			xnb_rx_va;
179 	gnttab_transfer_t	xnb_rx_top[NET_RX_RING_SIZE];
180 
181 	boolean_t		xnb_hv_copy;	/* do we do hypervisor copy? */
182 	gnttab_copy_t		*xnb_rx_cpop;
183 #define	CPOP_DEFCNT 	8
184 	size_t			xnb_cpop_sz; 	/* in elements, not bytes */
185 };
186 
187 extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
188 extern void xnb_detach(dev_info_t *);
189 extern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *);
190 extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
191 
192 #ifdef __cplusplus
193 }
194 #endif
195 
196 #endif	/* _SYS_XNB_H */
197