xref: /titanic_50/usr/src/uts/common/xen/io/xnf.h (revision 582271e8d649568c83e9a016cc0d54265389c5d9)
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 #include <sys/types.h>
33 #include <sys/kstat.h>
34 #include <sys/hypervisor.h>
35 #include <xen/public/io/netif.h>
36 #include <xen/sys/xenbus_impl.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
43 #define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
44 
45 #define	XNF_MAXPKT	1500		/* MTU size */
46 #define	XNF_FRAMESIZE	1514		/* frame size including MAC header */
47 
48 #define	XNF_MAX_RXDESCS	256
49 
50 /* Watermark for causing "interrupt on completion" for outgoing packets */
51 #define	XNF_TX_FREE_THRESH	(NET_TX_RING_SIZE / 10)
52 
53 #define	MCAST_HASHBITS		256
54 
55 extern int	xnf_diagnose;	/* Available for use any time. */
56 
57 /* Flags to set in the global xnf_diagnose */
58 #define	XNF_DIAG_RX		0x01
59 #define	XNF_DIAG_TX		0x02
60 #define	XNF_DIAG_STATS		0x04
61 #define	XNF_DIAG_RX_BUFS	0x08
62 
63 /* DEBUG flags */
64 #define	XNF_DEBUG_DDI		0x01
65 #define	XNF_DEBUG_TRACE		0x02
66 #define	XNF_DEBUG_SEND		0x04
67 #define	XNF_DEBUG_INT		0x08
68 
69 #define	XNF_DESC_ALIGN		8
70 
71 
72 /* Info pertaining to each xmit/receive buffer */
73 struct xnf_buffer_desc {
74 	frtn_t			free_rtn;	/* desballoc() structure */
75 	struct xnf		*xnfp;
76 	ddi_dma_handle_t	dma_handle;
77 	caddr_t			buf;		/* DMA-able data buffer */
78 	paddr_t			buf_phys;
79 	struct xnf_buffer_desc	*next;	/* For linking into free list */
80 	ddi_acc_handle_t	acc_handle;
81 	grant_ref_t		grant_ref;	/* grant table reference */
82 	uint16_t		id;		/* buffer id */
83 };
84 
85 /* Various information about each transmit packet */
86 struct tx_pktinfo {
87 	mblk_t			*mp;	/* mblk associated with packet */
88 	ddi_dma_handle_t	dma_handle;
89 	struct xnf_buffer_desc	*bdesc; /* pointer to buffer descriptor */
90 	grant_ref_t		grant_ref;	/* grant table reference */
91 	uint16_t		id;	/* tx pkt id/free list next pointer */
92 };
93 
94 /* Per network-interface-controller driver private structure */
95 typedef struct xnf {
96 	/* most interesting stuff first to assist debugging */
97 	dev_info_t		*devinfo;	/* System per-device info. */
98 	mac_handle_t		mh;		/* Nemo per-device info. */
99 	int			rx_bufs_outstanding;
100 	int			tx_descs_free;
101 	int			rx_descs_free;	/* count of free rx bufs */
102 	int			n_xmits;	/* No. xmit descriptors */
103 	int			n_recvs;	/* No. recv descriptors */
104 	int			n_recv_bufs;	/* No. recv DMA buffers */
105 	int			tx_start_thresh_regval;
106 	unsigned char		mac_addr[ETHERADDRL];
107 	int			max_recv_bufs;
108 	int			recv_buffer_count;
109 	int			xmit_buffer_count;
110 
111 	boolean_t		connected;
112 	boolean_t		running;
113 
114 	boolean_t		cksum_offload;
115 
116 	uint64_t		stat_intr;
117 	uint64_t		stat_norcvbuf;
118 	uint64_t		stat_errrcv;
119 
120 	uint64_t		stat_xmit_attempt;
121 	uint64_t		stat_xmit_pullup;
122 	uint64_t		stat_xmit_pagebndry;
123 	uint64_t		stat_xmit_defer;
124 	uint64_t		stat_rx_no_ringbuf;
125 	uint64_t		stat_mac_rcv_error;
126 	uint64_t		stat_runt;
127 
128 	uint64_t		stat_ipackets;
129 	uint64_t		stat_opackets;
130 	uint64_t		stat_rbytes;
131 	uint64_t		stat_obytes;
132 
133 	uint64_t		stat_tx_cksum_deferred;
134 	uint64_t		stat_rx_cksum_no_need;
135 
136 	kstat_t			*kstat_aux;
137 
138 	struct xnf_buffer_desc	*free_list;
139 	struct xnf_buffer_desc	*xmit_free_list;
140 	int			tx_pkt_id_list; /* free list of avail pkt ids */
141 	struct tx_pktinfo	tx_pkt_info[NET_TX_RING_SIZE];
142 	struct xnf_buffer_desc	*rxpkt_bufptr[XNF_MAX_RXDESCS];
143 
144 	mac_resource_handle_t	rx_handle;
145 	ddi_iblock_cookie_t	icookie;
146 	kmutex_t		tx_buf_mutex;
147 	kmutex_t		rx_buf_mutex;
148 	kmutex_t		txlock;
149 	kmutex_t		intrlock;
150 	boolean_t		tx_pages_readonly;
151 
152 	netif_tx_front_ring_t	tx_ring;	/* tx interface struct ptr */
153 	ddi_dma_handle_t	tx_ring_dma_handle;
154 	ddi_acc_handle_t	tx_ring_dma_acchandle;
155 	paddr_t			tx_ring_phys_addr;
156 	grant_ref_t		tx_ring_ref;
157 
158 	netif_rx_front_ring_t	rx_ring;	/* rx interface struct ptr */
159 	ddi_dma_handle_t	rx_ring_dma_handle;
160 	ddi_acc_handle_t	rx_ring_dma_acchandle;
161 	paddr_t			rx_ring_phys_addr;
162 	grant_ref_t		rx_ring_ref;
163 
164 	uint16_t		evtchn;		/* channel to back end ctlr */
165 	grant_ref_t		gref_tx_head;	/* tx grant free list */
166 	grant_ref_t		gref_rx_head;	/* rx grant free list */
167 	kcondvar_t		cv;
168 } xnf_t;
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif	/* _SYS_XNF_H */
175