xref: /titanic_51/usr/src/uts/common/xen/io/xnf.h (revision a3c4695861e3f0a8d3706f77ccd53683cca48d67)
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 
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_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_rx_no_ringbuf;
120 	uint64_t		xnf_stat_mac_rcv_error;
121 	uint64_t		xnf_stat_runt;
122 
123 	uint64_t		xnf_stat_ipackets;
124 	uint64_t		xnf_stat_opackets;
125 	uint64_t		xnf_stat_rbytes;
126 	uint64_t		xnf_stat_obytes;
127 
128 	uint64_t		xnf_stat_tx_cksum_deferred;
129 	uint64_t		xnf_stat_rx_cksum_no_need;
130 	uint64_t		xnf_stat_hvcopy_enabled; /* on/off */
131 	uint64_t		xnf_stat_hvcopy_packet_processed;
132 
133 	kstat_t			*xnf_kstat_aux;
134 
135 	struct xnf_buffer_desc	*xnf_free_list;
136 	struct xnf_buffer_desc	*xnf_tx_free_list;
137 	int			xnf_tx_pkt_id_list;
138 				/* free list of avail pkt ids */
139 	struct tx_pktinfo	xnf_tx_pkt_info[NET_TX_RING_SIZE];
140 	struct xnf_buffer_desc	*xnf_rxpkt_bufptr[XNF_MAX_RXDESCS];
141 
142 	mac_resource_handle_t	xnf_rx_handle;
143 	ddi_iblock_cookie_t	xnf_icookie;
144 	kmutex_t		xnf_tx_buf_mutex;
145 	kmutex_t		xnf_rx_buf_mutex;
146 	kmutex_t		xnf_txlock;
147 	kmutex_t		xnf_intrlock;
148 	boolean_t		xnf_tx_pages_readonly;
149 
150 	netif_tx_front_ring_t	xnf_tx_ring;	/* tx interface struct ptr */
151 	ddi_dma_handle_t	xnf_tx_ring_dma_handle;
152 	ddi_acc_handle_t	xnf_tx_ring_dma_acchandle;
153 	paddr_t			xnf_tx_ring_phys_addr;
154 	grant_ref_t		xnf_tx_ring_ref;
155 
156 	netif_rx_front_ring_t	xnf_rx_ring;	/* rx interface struct ptr */
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 	uint16_t		xnf_evtchn;	/* channel to back end ctlr */
163 	grant_ref_t		xnf_gref_tx_head;	/* tx grant free list */
164 	grant_ref_t		xnf_gref_rx_head;	/* rx grant free list */
165 	kcondvar_t		xnf_cv;
166 
167 	boolean_t		xnf_rx_hvcopy;	/* do we do HV copy? */
168 } xnf_t;
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif	/* _SYS_XNF_H */
175