xref: /titanic_50/usr/src/uts/common/xen/io/xnb.h (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
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		*x_devinfo;	/* System per-device info. */
98 
99 	xnb_flavour_t		*x_flavour;
100 	void			*x_flavour_data;
101 
102 	boolean_t		x_irq;
103 	unsigned char		x_mac_addr[ETHERADDRL];
104 
105 	uint64_t		x_stat_ipackets;
106 	uint64_t		x_stat_opackets;
107 	uint64_t		x_stat_rbytes;
108 	uint64_t		x_stat_obytes;
109 
110 	uint64_t		x_stat_intr;
111 	uint64_t		x_stat_xmit_defer;
112 
113 	uint64_t		x_stat_tx_cksum_deferred;
114 	uint64_t		x_stat_rx_cksum_no_need;
115 
116 	uint64_t		x_stat_tx_notify_sent;
117 	uint64_t		x_stat_tx_notify_deferred;
118 
119 	uint64_t		x_stat_rx_notify_sent;
120 	uint64_t		x_stat_rx_notify_deferred;
121 
122 	uint64_t		x_stat_tx_too_early;
123 	uint64_t		x_stat_rx_too_early;
124 	uint64_t		x_stat_rx_allocb_failed;
125 	uint64_t		x_stat_mac_full;
126 	uint64_t		x_stat_spurious_intr;
127 	uint64_t		x_stat_allocation_success;
128 	uint64_t		x_stat_allocation_failure;
129 	uint64_t		x_stat_small_allocation_success;
130 	uint64_t		x_stat_small_allocation_failure;
131 
132 	uint64_t		x_stat_csum_hardware;
133 	uint64_t		x_stat_csum_software;
134 
135 	kstat_t			*x_kstat_aux;
136 
137 	boolean_t		x_cksum_offload;
138 
139 	ddi_iblock_cookie_t	x_icookie;
140 
141 	kmutex_t		x_rx_lock;
142 	kmutex_t		x_tx_lock;
143 
144 	int			x_rx_unmop_count;
145 	int			x_rx_buf_count;
146 	boolean_t		x_rx_pages_writable;
147 
148 	netif_rx_back_ring_t	x_rx_ring;	/* rx interface struct ptr */
149 	void			*x_rx_ring_addr;
150 	grant_ref_t		x_rx_ring_ref;
151 	grant_handle_t		x_rx_ring_handle;
152 
153 	netif_tx_back_ring_t	x_tx_ring;	/* tx interface struct ptr */
154 	void			*x_tx_ring_addr;
155 	grant_ref_t		x_tx_ring_ref;
156 	grant_handle_t		x_tx_ring_handle;
157 
158 	boolean_t		x_connected;
159 	boolean_t		x_hotplugged;
160 	boolean_t		x_detachable;
161 	int			x_evtchn;	/* channel to front end */
162 	domid_t			x_peer;
163 
164 	xnb_rxbuf_t			*x_rx_bufp[NET_TX_RING_SIZE];
165 	gnttab_map_grant_ref_t		x_rx_mop[NET_TX_RING_SIZE];
166 	gnttab_unmap_grant_ref_t	x_rx_unmop[NET_TX_RING_SIZE];
167 
168 	caddr_t			x_tx_va;
169 	gnttab_transfer_t	x_tx_top[NET_RX_RING_SIZE];
170 };
171 
172 extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
173 extern void xnb_detach(dev_info_t *);
174 extern mblk_t *xnb_to_peer(xnb_t *, mblk_t *);
175 extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif	/* _SYS_XNB_H */
182