xref: /titanic_41/usr/src/uts/common/xen/io/xnf.h (revision ff3124eff995e6cd8ebd8c6543648e0670920034)
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 
27 #ifndef _SYS_XNF_H
28 #define	_SYS_XNF_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
37 #define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
38 
39 #define	XNF_MAXPKT	1500		/* MTU size */
40 #define	XNF_FRAMESIZE	1514		/* frame size including MAC header */
41 
42 #define	XNF_MAX_RXDESCS	256
43 
44 /* Watermark for causing "interrupt on completion" for outgoing packets */
45 #define	XNF_TX_FREE_THRESH	(NET_TX_RING_SIZE / 10)
46 
47 #define	MCAST_HASHBITS		256
48 
49 extern int	xnf_diagnose;	/* Available for use any time. */
50 
51 /* Flags to set in the global xnf_diagnose */
52 #define	XNF_DIAG_RX		0x01
53 #define	XNF_DIAG_TX		0x02
54 #define	XNF_DIAG_STATS		0x04
55 #define	XNF_DIAG_RX_BUFS	0x08
56 
57 /* DEBUG flags */
58 #define	XNF_DEBUG_DDI		0x01
59 #define	XNF_DEBUG_TRACE		0x02
60 #define	XNF_DEBUG_SEND		0x04
61 #define	XNF_DEBUG_INT		0x08
62 
63 #define	XNF_DESC_ALIGN		8
64 
65 
66 /* Info pertaining to each xmit/receive buffer */
67 struct xnf_buffer_desc {
68 	frtn_t			free_rtn;	/* desballoc() structure */
69 	struct xnf		*xnfp;
70 	ddi_dma_handle_t	dma_handle;
71 	caddr_t			buf;		/* DMA-able data buffer */
72 	paddr_t			buf_phys;
73 	struct xnf_buffer_desc	*next;	/* For linking into free list */
74 	ddi_acc_handle_t	acc_handle;
75 	grant_ref_t		grant_ref;	/* grant table reference */
76 	uint16_t		id;		/* buffer id */
77 };
78 
79 /* Various information about each transmit packet */
80 struct tx_pktinfo {
81 	mblk_t			*mp;	/* mblk associated with packet */
82 	ddi_dma_handle_t	dma_handle;
83 	struct xnf_buffer_desc	*bdesc; /* pointer to buffer descriptor */
84 	grant_ref_t		grant_ref;	/* grant table reference */
85 	uint16_t		id;	/* tx pkt id/free list next pointer */
86 };
87 
88 /* Per network-interface-controller driver private structure */
89 typedef struct xnf {
90 	/* most interesting stuff first to assist debugging */
91 	dev_info_t		*xnf_devinfo;	/* System per-device info. */
92 	mac_handle_t		xnf_mh;		/* Nemo per-device info. */
93 	int			xnf_rx_bufs_outstanding;
94 	int			xnf_tx_descs_free;
95 	int			xnf_rx_descs_free; /* count of free rx bufs */
96 	int			xnf_n_tx;	/* No. xmit descriptors */
97 	int			xnf_n_rx;	/* No. recv descriptors */
98 	int			xnf_n_rx_bufs;	/* No. recv DMA buffers */
99 	int			xnf_tx_start_thresh_regval;
100 	unsigned char		xnf_mac_addr[ETHERADDRL];
101 	int			xnf_max_rx_bufs;
102 	int			xnf_rx_buffer_count;
103 	int			xnf_tx_buffer_count;
104 
105 	boolean_t		xnf_connected;
106 	boolean_t		xnf_running;
107 
108 	boolean_t		xnf_cksum_offload;
109 
110 	uint64_t		xnf_stat_interrupts;
111 	uint64_t		xnf_stat_unclaimed_interrupts;
112 	uint64_t		xnf_stat_norxbuf;
113 	uint64_t		xnf_stat_drop;
114 	uint64_t		xnf_stat_errrx;
115 
116 	uint64_t		xnf_stat_tx_attempt;
117 	uint64_t		xnf_stat_tx_pullup;
118 	uint64_t		xnf_stat_tx_pagebndry;
119 	uint64_t		xnf_stat_tx_defer;
120 	uint64_t		xnf_stat_rx_no_ringbuf;
121 	uint64_t		xnf_stat_mac_rcv_error;
122 	uint64_t		xnf_stat_runt;
123 
124 	uint64_t		xnf_stat_ipackets;
125 	uint64_t		xnf_stat_opackets;
126 	uint64_t		xnf_stat_rbytes;
127 	uint64_t		xnf_stat_obytes;
128 
129 	uint64_t		xnf_stat_tx_cksum_deferred;
130 	uint64_t		xnf_stat_rx_cksum_no_need;
131 	uint64_t		xnf_stat_hvcopy_enabled; /* on/off */
132 	uint64_t		xnf_stat_hvcopy_packet_processed;
133 
134 	kstat_t			*xnf_kstat_aux;
135 
136 	struct xnf_buffer_desc	*xnf_free_list;
137 	struct xnf_buffer_desc	*xnf_tx_free_list;
138 	int			xnf_tx_pkt_id_list;
139 				/* free list of avail pkt ids */
140 	struct tx_pktinfo	xnf_tx_pkt_info[NET_TX_RING_SIZE];
141 	struct xnf_buffer_desc	*xnf_rxpkt_bufptr[XNF_MAX_RXDESCS];
142 
143 	mac_resource_handle_t	xnf_rx_handle;
144 	ddi_iblock_cookie_t	xnf_icookie;
145 	kmutex_t		xnf_tx_buf_mutex;
146 	kmutex_t		xnf_rx_buf_mutex;
147 	kmutex_t		xnf_txlock;
148 	kmutex_t		xnf_intrlock;
149 	boolean_t		xnf_tx_pages_readonly;
150 
151 	netif_tx_front_ring_t	xnf_tx_ring;	/* tx interface struct ptr */
152 	ddi_dma_handle_t	xnf_tx_ring_dma_handle;
153 	ddi_acc_handle_t	xnf_tx_ring_dma_acchandle;
154 	paddr_t			xnf_tx_ring_phys_addr;
155 	grant_ref_t		xnf_tx_ring_ref;
156 
157 	netif_rx_front_ring_t	xnf_rx_ring;	/* rx interface struct ptr */
158 	ddi_dma_handle_t	xnf_rx_ring_dma_handle;
159 	ddi_acc_handle_t	xnf_rx_ring_dma_acchandle;
160 	paddr_t			xnf_rx_ring_phys_addr;
161 	grant_ref_t		xnf_rx_ring_ref;
162 
163 	uint16_t		xnf_evtchn;	/* channel to back end ctlr */
164 	grant_ref_t		xnf_gref_tx_head;	/* tx grant free list */
165 	grant_ref_t		xnf_gref_rx_head;	/* rx grant free list */
166 	kcondvar_t		xnf_cv;
167 
168 	boolean_t		xnf_rx_hvcopy;	/* do we do HV copy? */
169 } xnf_t;
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif	/* _SYS_XNF_H */
176