xref: /titanic_51/usr/src/uts/common/xen/io/xnf.h (revision 0db3240d392634cfff2f95fb6da34b56b8dc574f)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_XNF_H
28 #define	_SYS_XNF_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
35 #define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
36 
37 #define	XNF_MAXPKT	1500		/* MTU size */
38 #define	XNF_FRAMESIZE	1514		/* frame size including MAC header */
39 
40 /* DEBUG flags */
41 #define	XNF_DEBUG_DDI		0x01
42 #define	XNF_DEBUG_TRACE		0x02
43 
44 /*
45  * Information about each receive buffer and any transmit look-aside
46  * buffers.
47  */
48 typedef struct xnf_buf {
49 	frtn_t			free_rtn;
50 	struct xnf		*xnfp;
51 	ddi_dma_handle_t	dma_handle;
52 	caddr_t			buf;		/* DMA-able data buffer */
53 	paddr_t			buf_phys;
54 	mfn_t			buf_mfn;
55 	size_t			len;
56 	struct xnf_buf		*next;	/* For linking into free list */
57 	ddi_acc_handle_t	acc_handle;
58 	grant_ref_t		grant_ref;	/* grant table reference */
59 	uint16_t		id;		/* buffer id */
60 	unsigned int		gen;
61 } xnf_buf_t;
62 
63 /*
64  * Information about each transmit buffer.
65  */
66 typedef struct xnf_txbuf {
67 	struct xnf_txbuf	*tx_next;
68 	mblk_t			*tx_mp;	/* mblk associated with packet */
69 	netif_tx_request_t	tx_txreq;
70 	caddr_t			tx_bufp;
71 	ddi_dma_handle_t	tx_dma_handle;
72 	mfn_t			tx_mfn;
73 	xnf_buf_t		*tx_bdesc; /* Look-aside buffer, if used. */
74 	unsigned char		tx_type;
75 	int16_t			tx_status;
76 	RING_IDX		tx_slot;
77 
78 #define	TX_DATA		1
79 #define	TX_MCAST_REQ	2
80 #define	TX_MCAST_RSP	3
81 } xnf_txbuf_t;
82 
83 /*
84  * Information about each outstanding transmit operation.
85  */
86 typedef struct xnf_txid {
87 	uint16_t	id;	/* Id of this transmit buffer. */
88 	uint16_t	next;	/* Freelist of ids. */
89 	xnf_txbuf_t	*txbuf;	/* Buffer details. */
90 } xnf_txid_t;
91 
92 /*
93  * Per-instance data.
94  */
95 typedef struct xnf {
96 	/* most interesting stuff first to assist debugging */
97 	dev_info_t		*xnf_devinfo;
98 	mac_handle_t		xnf_mh;
99 	unsigned char		xnf_mac_addr[ETHERADDRL];
100 
101 	unsigned int		xnf_gen;	/* Increments on resume. */
102 
103 	boolean_t		xnf_connected;
104 	boolean_t		xnf_running;
105 
106 	boolean_t		xnf_be_rx_copy;
107 	boolean_t		xnf_be_mcast_control;
108 
109 	uint64_t		xnf_stat_interrupts;
110 	uint64_t		xnf_stat_unclaimed_interrupts;
111 	uint64_t		xnf_stat_norxbuf;
112 	uint64_t		xnf_stat_drop;
113 	uint64_t		xnf_stat_errrx;
114 
115 	uint64_t		xnf_stat_tx_attempt;
116 	uint64_t		xnf_stat_tx_pullup;
117 	uint64_t		xnf_stat_tx_pagebndry;
118 	uint64_t		xnf_stat_tx_defer;
119 	uint64_t		xnf_stat_mac_rcv_error;
120 	uint64_t		xnf_stat_runt;
121 
122 	uint64_t		xnf_stat_ipackets;
123 	uint64_t		xnf_stat_opackets;
124 	uint64_t		xnf_stat_rbytes;
125 	uint64_t		xnf_stat_obytes;
126 
127 	uint64_t		xnf_stat_tx_cksum_deferred;
128 	uint64_t		xnf_stat_rx_cksum_no_need;
129 
130 	uint64_t		xnf_stat_buf_allocated;
131 	uint64_t		xnf_stat_buf_outstanding;
132 	uint64_t		xnf_stat_gref_outstanding;
133 	uint64_t		xnf_stat_gref_failure;
134 	uint64_t		xnf_stat_gref_peak;
135 	uint64_t		xnf_stat_rx_allocb_fail;
136 	uint64_t		xnf_stat_rx_desballoc_fail;
137 
138 	kstat_t			*xnf_kstat_aux;
139 
140 	ddi_iblock_cookie_t	xnf_icookie;
141 
142 	netif_tx_front_ring_t	xnf_tx_ring;
143 	ddi_dma_handle_t	xnf_tx_ring_dma_handle;
144 	ddi_acc_handle_t	xnf_tx_ring_dma_acchandle;
145 	paddr_t			xnf_tx_ring_phys_addr;
146 	grant_ref_t		xnf_tx_ring_ref;
147 
148 	xnf_txid_t		xnf_tx_pkt_id[NET_TX_RING_SIZE];
149 	uint16_t		xnf_tx_pkt_id_head;
150 	kmutex_t		xnf_txlock;
151 	kmutex_t		xnf_schedlock;
152 	boolean_t		xnf_need_sched;
153 	kcondvar_t		xnf_cv_tx_slots;
154 	kmem_cache_t		*xnf_tx_buf_cache;
155 
156 	netif_rx_front_ring_t	xnf_rx_ring;
157 	ddi_dma_handle_t	xnf_rx_ring_dma_handle;
158 	ddi_acc_handle_t	xnf_rx_ring_dma_acchandle;
159 	paddr_t			xnf_rx_ring_phys_addr;
160 	grant_ref_t		xnf_rx_ring_ref;
161 
162 	xnf_buf_t		*xnf_rx_pkt_info[NET_RX_RING_SIZE];
163 	kmutex_t		xnf_rxlock;
164 	mblk_t			*xnf_rx_head;
165 	mblk_t			*xnf_rx_tail;
166 	boolean_t		xnf_rx_new_buffers_posted;
167 	kmem_cache_t		*xnf_buf_cache;
168 
169 	uint16_t		xnf_evtchn;
170 
171 	kmutex_t		xnf_gref_lock;
172 	grant_ref_t		xnf_gref_head;
173 
174 	kcondvar_t		xnf_cv_state;
175 	kcondvar_t		xnf_cv_multicast;
176 	uint_t			xnf_pending_multicast;
177 } xnf_t;
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif	/* _SYS_XNF_H */
184