xref: /illumos-gate/usr/src/uts/common/io/sfe/sfe_util.h (revision 915ebf8da9f4ef3e7b2e34dd367f64d358a628d9)
1f8919bdaSduboff /*
2f8919bdaSduboff  *  sfe_util.h: header to support the gem layer used by Masa Murayama
3f8919bdaSduboff  *
423d366e3Sduboff  * Copyright (c) 2002-2008 Masayuki Murayama.  All rights reserved.
5f8919bdaSduboff  *
6f8919bdaSduboff  * Redistribution and use in source and binary forms, with or without
7f8919bdaSduboff  * modification, are permitted provided that the following conditions are met:
8f8919bdaSduboff  *
9f8919bdaSduboff  * 1. Redistributions of source code must retain the above copyright notice,
10f8919bdaSduboff  *    this list of conditions and the following disclaimer.
11f8919bdaSduboff  *
12f8919bdaSduboff  * 2. Redistributions in binary form must reproduce the above copyright notice,
13f8919bdaSduboff  *    this list of conditions and the following disclaimer in the documentation
14f8919bdaSduboff  *    and/or other materials provided with the distribution.
15f8919bdaSduboff  *
16f8919bdaSduboff  * 3. Neither the name of the author nor the names of its contributors may be
17f8919bdaSduboff  *    used to endorse or promote products derived from this software without
18f8919bdaSduboff  *    specific prior written permission.
19f8919bdaSduboff  *
20f8919bdaSduboff  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21f8919bdaSduboff  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22f8919bdaSduboff  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23f8919bdaSduboff  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24f8919bdaSduboff  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25f8919bdaSduboff  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26f8919bdaSduboff  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27f8919bdaSduboff  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28f8919bdaSduboff  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29f8919bdaSduboff  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30f8919bdaSduboff  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31f8919bdaSduboff  * DAMAGE.
32f8919bdaSduboff  */
3323d366e3Sduboff 
34f8919bdaSduboff #ifndef _SFE_UTIL_H_
35f8919bdaSduboff #define	_SFE_UTIL_H_
36f8919bdaSduboff #include <sys/mac.h>
37f8919bdaSduboff #include <sys/mac_ether.h>
38f8919bdaSduboff 
39f8919bdaSduboff /*
40f8919bdaSduboff  * Useful macros and typedefs
41f8919bdaSduboff  */
42f8919bdaSduboff 
43f8919bdaSduboff #define	GEM_NAME_LEN	32
44f8919bdaSduboff 
45f8919bdaSduboff #define	GEM_TX_TIMEOUT		(drv_usectohz(5*1000000))
46f8919bdaSduboff #define	GEM_TX_TIMEOUT_INTERVAL	(drv_usectohz(1*1000000))
47f8919bdaSduboff #define	GEM_LINK_WATCH_INTERVAL	(drv_usectohz(1*1000000))	/* 1 sec */
48f8919bdaSduboff 
49f8919bdaSduboff /* general return code */
50f8919bdaSduboff #define	GEM_SUCCESS	0
51f8919bdaSduboff #define	GEM_FAILURE	(-1)
52f8919bdaSduboff 
53f8919bdaSduboff /* return code of gem_tx_done */
54f8919bdaSduboff #define	INTR_RESTART_TX	0x80000000
55f8919bdaSduboff 
56f8919bdaSduboff typedef	int32_t		seqnum_t;
57f8919bdaSduboff 
58f8919bdaSduboff /*
59f8919bdaSduboff  * I/O instructions
60f8919bdaSduboff  */
61f8919bdaSduboff #define	OUTB(dp, p, v)	\
62f8919bdaSduboff 	ddi_put8((dp)->regs_handle, \
63f8919bdaSduboff 		(void *)((caddr_t)((dp)->base_addr) + (p)), v)
64f8919bdaSduboff #define	OUTW(dp, p, v)	\
65f8919bdaSduboff 	ddi_put16((dp)->regs_handle, \
66f8919bdaSduboff 		(void *)((caddr_t)((dp)->base_addr) + (p)), v)
67f8919bdaSduboff #define	OUTL(dp, p, v)  \
68f8919bdaSduboff 	ddi_put32((dp)->regs_handle, \
69f8919bdaSduboff 	    (void *)((caddr_t)((dp)->base_addr) + (p)), v)
70*915ebf8dSAlan Duboff #define	OUTLINL(dp, p, v) \
71*915ebf8dSAlan Duboff 	ddi_put32((dp)->regs_handle, \
72*915ebf8dSAlan Duboff 	    (void *)((caddr_t)((dp)->base_addr) + (p)), v); \
73*915ebf8dSAlan Duboff 	(void) INL((dp), (p))
74f8919bdaSduboff #define	INB(dp, p)	\
75f8919bdaSduboff 	ddi_get8((dp)->regs_handle, \
76f8919bdaSduboff 		(void *)(((caddr_t)(dp)->base_addr) + (p)))
77f8919bdaSduboff #define	INW(dp, p)	\
78f8919bdaSduboff 	ddi_get16((dp)->regs_handle, \
79f8919bdaSduboff 		(void *)(((caddr_t)(dp)->base_addr) + (p)))
80f8919bdaSduboff #define	INL(dp, p)	\
81f8919bdaSduboff 	ddi_get32((dp)->regs_handle, \
82f8919bdaSduboff 		(void *)(((caddr_t)(dp)->base_addr) + (p)))
83f8919bdaSduboff 
84f8919bdaSduboff struct gem_stats {
85f8919bdaSduboff 	uint32_t	intr;
86f8919bdaSduboff 
87f8919bdaSduboff 	uint32_t	crc;
88f8919bdaSduboff 	uint32_t	errrcv;
89f8919bdaSduboff 	uint32_t	overflow;
90f8919bdaSduboff 	uint32_t	frame;
91f8919bdaSduboff 	uint32_t	missed;
92f8919bdaSduboff 	uint32_t	runt;
93f8919bdaSduboff 	uint32_t	frame_too_long;
94f8919bdaSduboff 	uint32_t	norcvbuf;
95f8919bdaSduboff 	uint32_t	sqe;
96f8919bdaSduboff 
97f8919bdaSduboff 	uint32_t	collisions;
98f8919bdaSduboff 	uint32_t	first_coll;
99f8919bdaSduboff 	uint32_t	multi_coll;
100f8919bdaSduboff 	uint32_t	excoll;
101f8919bdaSduboff 	uint32_t	xmit_internal_err;
102f8919bdaSduboff 	uint32_t	nocarrier;
103f8919bdaSduboff 	uint32_t	defer;
104f8919bdaSduboff 	uint32_t	errxmt;
105f8919bdaSduboff 	uint32_t	underflow;
106f8919bdaSduboff 	uint32_t	xmtlatecoll;
107f8919bdaSduboff 	uint32_t	noxmtbuf;
108f8919bdaSduboff 	uint32_t	jabber;
109f8919bdaSduboff 
110f8919bdaSduboff 	uint64_t	rbytes;
111f8919bdaSduboff 	uint64_t	obytes;
112f8919bdaSduboff 	uint64_t	rpackets;
113f8919bdaSduboff 	uint64_t	opackets;
114f8919bdaSduboff 	uint32_t	rbcast;
115f8919bdaSduboff 	uint32_t	obcast;
116f8919bdaSduboff 	uint32_t	rmcast;
117f8919bdaSduboff 	uint32_t	omcast;
118f8919bdaSduboff 	uint32_t	rcv_internal_err;
119f8919bdaSduboff };
120f8919bdaSduboff #define	GEM_MAXTXSEGS		4
121f8919bdaSduboff #define	GEM_MAXRXSEGS		1
122f8919bdaSduboff 
123f8919bdaSduboff #define	GEM_MAXTXFRAGS		8
124f8919bdaSduboff #define	GEM_MAXRXFRAGS		4
125f8919bdaSduboff /* TX buffer management */
126f8919bdaSduboff struct txbuf {
127f8919bdaSduboff 	struct txbuf		*txb_next;
128f8919bdaSduboff 
129f8919bdaSduboff 	/* pointer to original mblk */
130f8919bdaSduboff 	mblk_t			*txb_mp;
131f8919bdaSduboff 
132f8919bdaSduboff 	/* dma mapping for current packet */
133f8919bdaSduboff 	ddi_dma_cookie_t	txb_dmacookie[GEM_MAXTXFRAGS];
134f8919bdaSduboff 	uint_t			txb_nfrags;
135f8919bdaSduboff 
136f8919bdaSduboff 	/* bounce buffer management */
137f8919bdaSduboff 	ddi_dma_handle_t	txb_bdh;
138f8919bdaSduboff 	ddi_acc_handle_t	txb_bah;
139f8919bdaSduboff 	caddr_t			txb_buf;	/* vaddr of bounce buffer */
140f8919bdaSduboff 	uint64_t		txb_buf_dma;	/* paddr of bounce buffer */
141f8919bdaSduboff 
142f8919bdaSduboff 	/* timeout management */
143f8919bdaSduboff 	clock_t			txb_stime;
144f8919bdaSduboff 
145f8919bdaSduboff 	/* Hardware descriptor info */
146f8919bdaSduboff 	seqnum_t		txb_desc;
147f8919bdaSduboff 	int			txb_ndescs;
148f8919bdaSduboff 	uint64_t		txb_flag;
149f8919bdaSduboff };
150f8919bdaSduboff 
151f8919bdaSduboff 
152f8919bdaSduboff /* RX buffer management */
153f8919bdaSduboff struct rxbuf {
15423d366e3Sduboff 	/* Hardware independent section */
155f8919bdaSduboff 	struct rxbuf		*rxb_next;
156f8919bdaSduboff 	struct gem_dev		*rxb_devp;
157f8919bdaSduboff 
158f8919bdaSduboff 	/* dma mapping management */
159f8919bdaSduboff 	ddi_dma_handle_t	rxb_dh;
160f8919bdaSduboff 	caddr_t			rxb_buf;
161f8919bdaSduboff 	size_t			rxb_buf_len;
162f8919bdaSduboff 	ddi_dma_cookie_t	rxb_dmacookie[GEM_MAXRXFRAGS];
163f8919bdaSduboff 	uint_t			rxb_nfrags;
164f8919bdaSduboff 
165f8919bdaSduboff 	/* bounce buffer management */
166f8919bdaSduboff 	ddi_acc_handle_t	rxb_bah;
167f8919bdaSduboff };
168f8919bdaSduboff 
169f8919bdaSduboff struct mcast_addr {
170f8919bdaSduboff 	struct ether_addr	addr;
171f8919bdaSduboff 	uint32_t		hash;
172f8919bdaSduboff };
173f8919bdaSduboff 
174f8919bdaSduboff #define	GEM_MAXMC		64
175f8919bdaSduboff #define	GEM_MCALLOC		(sizeof (struct mcast_addr) * GEM_MAXMC)
176f8919bdaSduboff 
177f8919bdaSduboff #define	SUB(x, y)		((seqnum_t)((x) - (y)))
178f8919bdaSduboff #define	SLOT(seqnum, size)	(((unsigned int)(seqnum)) & ((size)-1))
179f8919bdaSduboff 
180f8919bdaSduboff /*
181f8919bdaSduboff  * mac soft state
182f8919bdaSduboff  */
183f8919bdaSduboff struct gem_dev {
184f8919bdaSduboff 	dev_info_t		*dip;
185f8919bdaSduboff 	mac_handle_t		mh;
186f8919bdaSduboff 	char			name[GEM_NAME_LEN];
187f8919bdaSduboff 	void			*base_addr;
188f8919bdaSduboff 	ddi_acc_handle_t	regs_handle;
189f8919bdaSduboff 	ddi_iblock_cookie_t	iblock_cookie;
190f8919bdaSduboff 
191f8919bdaSduboff 	/* MAC address information */
192f8919bdaSduboff 	struct ether_addr	cur_addr;
193f8919bdaSduboff 	struct ether_addr	dev_addr;
194f8919bdaSduboff 
195f8919bdaSduboff 	/* Descriptor rings, io area */
196f8919bdaSduboff 	ddi_dma_handle_t	desc_dma_handle;
197f8919bdaSduboff 	ddi_acc_handle_t	desc_acc_handle;
198f8919bdaSduboff 	caddr_t			rx_ring;
199f8919bdaSduboff 	caddr_t			tx_ring;
200f8919bdaSduboff 	caddr_t			io_area;
201f8919bdaSduboff 	/* caddr_t			rx_buf; */
202f8919bdaSduboff 
203f8919bdaSduboff 	uint64_t		rx_ring_dma;
204f8919bdaSduboff 	uint64_t		tx_ring_dma;
205f8919bdaSduboff 	uint64_t		io_area_dma;
206f8919bdaSduboff 
207f8919bdaSduboff 	/* RX slot ring management */
208f8919bdaSduboff 	kmutex_t		intrlock;
209f8919bdaSduboff 	boolean_t		intr_busy;
210f8919bdaSduboff 	seqnum_t		rx_active_head;
211f8919bdaSduboff 	seqnum_t		rx_active_tail;
212f8919bdaSduboff 	mac_resource_handle_t	mac_rx_ring_ha;
213f8919bdaSduboff 	/* Rx buffer management */
214f8919bdaSduboff 	struct rxbuf		*rx_buf_head;
215f8919bdaSduboff 	struct rxbuf		*rx_buf_tail;
216f8919bdaSduboff 	struct rxbuf		*rx_buf_freelist;
217f8919bdaSduboff 	int			rx_buf_allocated;
218f8919bdaSduboff 	int			rx_buf_freecnt;
219f8919bdaSduboff 	int			rx_buf_len;
220f8919bdaSduboff 
221f8919bdaSduboff 	/* TX descriptor ring management */
222f8919bdaSduboff 	seqnum_t		tx_desc_head;
223f8919bdaSduboff 	seqnum_t		tx_desc_tail;
224f8919bdaSduboff 	seqnum_t		tx_desc_intr;
225f8919bdaSduboff 
226f8919bdaSduboff 	/* TX buffur ring management */
227f8919bdaSduboff 	kmutex_t		xmitlock;
228f8919bdaSduboff 	kcondvar_t		tx_drain_cv;
229f8919bdaSduboff 	seqnum_t		tx_active_head;
230f8919bdaSduboff 	seqnum_t		tx_active_tail;
231f8919bdaSduboff 	seqnum_t		tx_softq_head;
232f8919bdaSduboff 	seqnum_t		tx_softq_tail;
233f8919bdaSduboff 	seqnum_t		tx_free_head;
234f8919bdaSduboff 	seqnum_t		tx_free_tail;
23523d366e3Sduboff 	int			tx_max_packets;
236f8919bdaSduboff 
237f8919bdaSduboff 	/* TX buffer resource management */
238f8919bdaSduboff 	struct txbuf		*tx_buf;
239f8919bdaSduboff 	seqnum_t		tx_slots_base;
240f8919bdaSduboff 
241f8919bdaSduboff 	/* TX state management */
242f8919bdaSduboff 	int			tx_busy;
243f8919bdaSduboff 	int			tx_reclaim_busy;
24423d366e3Sduboff 	clock_t			tx_blocked;
245f8919bdaSduboff 
246f8919bdaSduboff 	/* NIC state */
247f8919bdaSduboff 	volatile boolean_t	mac_active;	/* tx and rx are running */
248f8919bdaSduboff 	volatile int		nic_state;	/* logical driver state */
249f8919bdaSduboff #define	NIC_STATE_STOPPED	0
250f8919bdaSduboff #define	NIC_STATE_INITIALIZED	1
251f8919bdaSduboff #define	NIC_STATE_ONLINE	2
252f8919bdaSduboff 	volatile boolean_t	mac_suspended;
253f8919bdaSduboff 
254f8919bdaSduboff 	/* robustness: timer and watchdog */
255f8919bdaSduboff 	volatile timeout_id_t	timeout_id;
256f8919bdaSduboff 
257f8919bdaSduboff 
258f8919bdaSduboff 	/* MII management */
259f8919bdaSduboff 	boolean_t		anadv_autoneg:1;
260f8919bdaSduboff 	boolean_t		anadv_1000fdx:1;
261f8919bdaSduboff 	boolean_t		anadv_1000hdx:1;
262f8919bdaSduboff 	boolean_t		anadv_100t4:1;
263f8919bdaSduboff 	boolean_t		anadv_100fdx:1;
264f8919bdaSduboff 	boolean_t		anadv_100hdx:1;
265f8919bdaSduboff 	boolean_t		anadv_10fdx:1;
266f8919bdaSduboff 	boolean_t		anadv_10hdx:1;
267f8919bdaSduboff 	boolean_t		anadv_flow_control:2;
268f8919bdaSduboff 	boolean_t		mii_advert_ro:1;
269f8919bdaSduboff 
270f8919bdaSduboff 	boolean_t		full_duplex:1;
271f8919bdaSduboff 	int			speed:3;
272f8919bdaSduboff #define		GEM_SPD_10	0
273f8919bdaSduboff #define		GEM_SPD_100	1
274f8919bdaSduboff #define		GEM_SPD_1000	2
27523d366e3Sduboff #define		GEM_SPD_NUM	3
276f8919bdaSduboff 	unsigned int		flow_control:2;
277f8919bdaSduboff #define		FLOW_CONTROL_NONE	0
278f8919bdaSduboff #define		FLOW_CONTROL_SYMMETRIC	1
279f8919bdaSduboff #define		FLOW_CONTROL_TX_PAUSE	2
280f8919bdaSduboff #define		FLOW_CONTROL_RX_PAUSE	3
281f8919bdaSduboff 
282f8919bdaSduboff 	boolean_t		mii_supress_msg:1;
283f8919bdaSduboff 
284f8919bdaSduboff 	uint32_t		mii_phy_id;
285f8919bdaSduboff 	uint16_t		mii_status;
286f8919bdaSduboff 	uint16_t		mii_advert;
287f8919bdaSduboff 	uint16_t		mii_lpable;
288f8919bdaSduboff 	uint16_t		mii_exp;
289f8919bdaSduboff 	uint16_t		mii_ctl1000;
290f8919bdaSduboff 	uint16_t		mii_stat1000;
291f8919bdaSduboff 	uint16_t		mii_xstatus;
292f8919bdaSduboff 	int8_t			mii_phy_addr;	/* must be signed */
293f8919bdaSduboff 
294f8919bdaSduboff 	uint8_t			mii_state;
295f8919bdaSduboff #define		MII_STATE_UNKNOWN		0
296f8919bdaSduboff #define		MII_STATE_RESETTING		1
297f8919bdaSduboff #define		MII_STATE_AUTONEGOTIATING	2
298f8919bdaSduboff #define		MII_STATE_AN_DONE		3
299f8919bdaSduboff #define		MII_STATE_MEDIA_SETUP		4
300f8919bdaSduboff #define		MII_STATE_LINKUP		5
301f8919bdaSduboff #define		MII_STATE_LINKDOWN		6
302f8919bdaSduboff 
303f8919bdaSduboff 	clock_t			mii_last_check;	/* in tick */
304f8919bdaSduboff 	clock_t			mii_timer;	/* in tick */
305f8919bdaSduboff #define		MII_RESET_TIMEOUT	drv_usectohz(1000*1000)
306f8919bdaSduboff #define		MII_AN_TIMEOUT		drv_usectohz(5000*1000)
307f8919bdaSduboff #define		MII_LINKDOWN_TIMEOUT	drv_usectohz(10000*1000)
308f8919bdaSduboff 	clock_t			mii_interval;	/* in tick */
30923d366e3Sduboff 	clock_t			linkup_delay;	/* in tick */
310f8919bdaSduboff 
311f8919bdaSduboff 	volatile timeout_id_t	link_watcher_id;
312f8919bdaSduboff 
313f8919bdaSduboff 	ddi_softintr_t		soft_id;
314f8919bdaSduboff 
315f8919bdaSduboff 	/* multcast list management */
316f8919bdaSduboff 	int16_t			mc_count;
317f8919bdaSduboff 	int16_t			mc_count_req;
318f8919bdaSduboff 	struct mcast_addr	*mc_list;
319f8919bdaSduboff 	uint32_t		rxmode;
320f8919bdaSduboff #define		RXMODE_PROMISC		0x01
321f8919bdaSduboff #define		RXMODE_ALLMULTI_REQ	0x02
322f8919bdaSduboff #define		RXMODE_MULTI_OVF	0x04
323f8919bdaSduboff #define		RXMODE_ENABLE		0x08
324f8919bdaSduboff #define		RXMODE_ALLMULTI		(RXMODE_ALLMULTI_REQ | RXMODE_MULTI_OVF)
325f8919bdaSduboff #define		RXMODE_BITS	\
326f8919bdaSduboff 			"\020"	\
327f8919bdaSduboff 			"\004ENABLE"	\
328f8919bdaSduboff 			"\003MULTI_OVF"	\
329f8919bdaSduboff 			"\002ALLMULTI_REQ"	\
330f8919bdaSduboff 			"\001PROMISC"
331f8919bdaSduboff 
332f8919bdaSduboff 	/* statistcs */
333f8919bdaSduboff 	struct gem_stats		stats;
334f8919bdaSduboff 
335f8919bdaSduboff 	/* pointer to local structure */
336f8919bdaSduboff 	void			*private;
337f8919bdaSduboff 	int			priv_size;
338f8919bdaSduboff 
339f8919bdaSduboff 	/* polling mode */
340f8919bdaSduboff 	int			poll_pkt_delay;	/* in number of packets */
341f8919bdaSduboff 
342f8919bdaSduboff 	/* descriptor area */
343f8919bdaSduboff 	int			tx_desc_size;
344f8919bdaSduboff 	int			rx_desc_size;
345f8919bdaSduboff 
346f8919bdaSduboff 	/* configuration */
347f8919bdaSduboff 	struct gem_conf {
348f8919bdaSduboff 		/* name */
349f8919bdaSduboff 		char	gc_name[GEM_NAME_LEN];
350f8919bdaSduboff 
351f8919bdaSduboff 		/* specification on tx and rx dma engine */
352f8919bdaSduboff 		long	gc_tx_buf_align;
353f8919bdaSduboff 		int	gc_tx_max_frags;
354f8919bdaSduboff 		int	gc_tx_max_descs_per_pkt;
355f8919bdaSduboff 		int	gc_tx_buf_size;
356f8919bdaSduboff 		int	gc_tx_buf_limit;
357f8919bdaSduboff 		int	gc_tx_desc_unit_shift;
358f8919bdaSduboff 		int	gc_tx_ring_size;
359f8919bdaSduboff 		int	gc_tx_ring_limit;
360f8919bdaSduboff 		int	gc_tx_copy_thresh;
361f8919bdaSduboff 		boolean_t gc_tx_auto_pad;
362f8919bdaSduboff 		boolean_t gc_tx_desc_write_oo;
363f8919bdaSduboff 
364f8919bdaSduboff 		long	gc_rx_buf_align;
365f8919bdaSduboff 		int	gc_rx_max_frags;
366f8919bdaSduboff 		int	gc_rx_desc_unit_shift;
367f8919bdaSduboff 		int	gc_rx_ring_size;
368f8919bdaSduboff 		int	gc_rx_copy_thresh;
369f8919bdaSduboff 		int	gc_rx_buf_max;
370f8919bdaSduboff 		int	gc_rx_header_len;
371f8919bdaSduboff 
372f8919bdaSduboff 		int	gc_io_area_size;
373f8919bdaSduboff 
374f8919bdaSduboff 		/* memory mapping attributes */
375f8919bdaSduboff 		struct ddi_device_acc_attr	gc_dev_attr;
376f8919bdaSduboff 		struct ddi_device_acc_attr	gc_buf_attr;
377f8919bdaSduboff 		struct ddi_device_acc_attr	gc_desc_attr;
378f8919bdaSduboff 
379f8919bdaSduboff 		/* dma attributes */
380f8919bdaSduboff 		ddi_dma_attr_t		gc_dma_attr_desc;
381f8919bdaSduboff 		ddi_dma_attr_t		gc_dma_attr_txbuf;
382f8919bdaSduboff 		ddi_dma_attr_t		gc_dma_attr_rxbuf;
383f8919bdaSduboff 
384f8919bdaSduboff 		/* tx time out parameters */
385f8919bdaSduboff 		clock_t	gc_tx_timeout;
386f8919bdaSduboff 		clock_t	gc_tx_timeout_interval;
387f8919bdaSduboff 
388f8919bdaSduboff 		/* auto negotiation capability */
389f8919bdaSduboff 		int		gc_flow_control;
390f8919bdaSduboff 
391f8919bdaSduboff 		/* MII mode */
392f8919bdaSduboff 		int	gc_mii_mode;
393f8919bdaSduboff #define		GEM_MODE_100BASETX	0
394f8919bdaSduboff #define		GEM_MODE_1000BASET	1
395f8919bdaSduboff #define		GEM_MODE_1000BASETX	2
396f8919bdaSduboff 
397f8919bdaSduboff 		/* MII link state watch parameters */
398f8919bdaSduboff 		clock_t	gc_mii_linkdown_timeout;
399f8919bdaSduboff 		clock_t	gc_mii_link_watch_interval;
400f8919bdaSduboff 		clock_t	gc_mii_reset_timeout;
401f8919bdaSduboff 
402f8919bdaSduboff 		clock_t	gc_mii_an_watch_interval;
403f8919bdaSduboff 		clock_t	gc_mii_an_timeout;
404f8919bdaSduboff 		clock_t	gc_mii_an_wait;
405f8919bdaSduboff 		clock_t	gc_mii_an_delay;
406f8919bdaSduboff 
407f8919bdaSduboff 		/* MII configuration */
408f8919bdaSduboff 		int	gc_mii_addr_min;
409f8919bdaSduboff 		int	gc_mii_linkdown_action;
410f8919bdaSduboff 		int	gc_mii_linkdown_timeout_action;
411f8919bdaSduboff #define		MII_ACTION_NONE		0
412f8919bdaSduboff #define		MII_ACTION_RESET	1
413f8919bdaSduboff #define		MII_ACTION_RSA		2
414f8919bdaSduboff 		boolean_t	gc_mii_dont_reset;
415f8919bdaSduboff 		boolean_t	gc_mii_an_oneshot;
416f8919bdaSduboff 		boolean_t	gc_mii_hw_link_detection;
417f8919bdaSduboff 		boolean_t	gc_mii_stop_mac_on_linkdown;
418f8919bdaSduboff 
419f8919bdaSduboff 		/* I/O methods */
420f8919bdaSduboff 
421f8919bdaSduboff 		/* mac operation */
422f8919bdaSduboff 		int	(*gc_attach_chip)(struct gem_dev *dp);
423f8919bdaSduboff 		int	(*gc_reset_chip)(struct gem_dev *dp);
424f8919bdaSduboff 		int	(*gc_init_chip)(struct gem_dev *dp);
425f8919bdaSduboff 		int	(*gc_start_chip)(struct gem_dev *dp);
426f8919bdaSduboff 		int	(*gc_stop_chip)(struct gem_dev *dp);
427f8919bdaSduboff 		uint32_t (*gc_multicast_hash)(struct gem_dev *dp, uint8_t *);
428f8919bdaSduboff 		int	(*gc_set_rx_filter)(struct gem_dev *dp);
429f8919bdaSduboff 		int	(*gc_set_media)(struct gem_dev *dp);
430f8919bdaSduboff 		int	(*gc_get_stats)(struct gem_dev *dp);
431f8919bdaSduboff 		uint_t	(*gc_interrupt)(struct gem_dev *dp);
432f8919bdaSduboff 
433f8919bdaSduboff 		/* descriptor operation */
434f8919bdaSduboff 		int	(*gc_tx_desc_write)(struct gem_dev *dp, int slot,
435f8919bdaSduboff 				ddi_dma_cookie_t *dmacookie,
436f8919bdaSduboff 				int frags, uint64_t flag);
437f8919bdaSduboff #define			GEM_TXFLAG_INTR		0x00000001ull
438f8919bdaSduboff #define			GEM_TXFLAG_TCP		0x00000002ull
439f8919bdaSduboff #define				GEM_TXFLAG_TCP_SHIFT		1ull
440f8919bdaSduboff #define			GEM_TXFLAG_UDP		0x00000004ull
441f8919bdaSduboff #define				GEM_TXFLAG_UDP_SHIFT		2ull
442f8919bdaSduboff #define			GEM_TXFLAG_IPv4		0x00000008ull
443f8919bdaSduboff #define				GEM_TXFLAG_IPv4_SHIFT		3ull
444f8919bdaSduboff #define			GEM_TXFLAG_IPv6		0x00000010ull
445f8919bdaSduboff #define				GEM_TXFLAG_IPv6_SHIFT		4ull
446f8919bdaSduboff #define			GEM_TXFLAG_HEAD		0x00000020ull
447f8919bdaSduboff #define			GEM_TXFLAG_TAIL		0x00000040ull
448f8919bdaSduboff #define			GEM_TXFLAG_SWVTAG	0x00000080ull
449f8919bdaSduboff #define			GEM_TXFLAG_PRIVATE	0x0000ff00ull
450f8919bdaSduboff #define				GEM_TXFLAG_PRIVATE_SHIFT	8ull
451f8919bdaSduboff #define				GEM_TXFLAG_PRIVATE_MASK	0xffull
452f8919bdaSduboff #define			GEM_TXFLAG_VID		0x0fff0000ull
453f8919bdaSduboff #define				GEM_TXFLAG_VID_SHIFT		16ull
454f8919bdaSduboff #define				GEM_TXFLAG_VID_MASK		0xfffull
455f8919bdaSduboff #define			GEM_TXFLAG_CFI		0x10000000ull
456f8919bdaSduboff #define			GEM_TXFLAG_PRI		0xe0000000ull
457f8919bdaSduboff #define				GEM_TXFLAG_PRI_SHIFT		29ull
458f8919bdaSduboff #define				GEM_TXFLAG_PRI_MASK		0x7ull
459f8919bdaSduboff #define			GEM_TXFLAG_VTAG		0xffff0000ull
460f8919bdaSduboff #define				GEM_TXFLAG_VTAG_SHIFT		16ull
461f8919bdaSduboff #define			GEM_TXFLAG_HCKSTART	0x000000ff00000000ull
462f8919bdaSduboff #define				GEM_TXFLAG_HCKSTART_SHIFT	32ull
463f8919bdaSduboff #define			GEM_TXFLAG_HCKSTUFF	0x0000ff0000000000ull
464f8919bdaSduboff #define				GEM_TXFLAG_HCKSTUFF_SHIFT	40ull
46523d366e3Sduboff #define			GEM_TXFLAG_TCPHLEN	0x0000ff0000000000ull
46623d366e3Sduboff #define				GEM_TXFLAG_TCPHLEN_SHIFT	40ull
46723d366e3Sduboff #define			GEM_TXFLAG_MSS		0xffff000000000000ull
46823d366e3Sduboff #define				GEM_TXFLAG_MSS_SHIFT	48ull
469f8919bdaSduboff 
470f8919bdaSduboff 		void (*gc_tx_start) (struct gem_dev *dp, int slot, int frags);
471f8919bdaSduboff 		void	(*gc_rx_desc_write)(struct gem_dev *dp, int slot,
472f8919bdaSduboff 			    ddi_dma_cookie_t *dmacookie, int frags);
473f8919bdaSduboff 		void	(*gc_rx_start)(struct gem_dev *dp, int slot, int frags);
474f8919bdaSduboff 
475f8919bdaSduboff 		uint_t	(*gc_tx_desc_stat)
476f8919bdaSduboff 			(struct gem_dev *dp, int slot, int descs);
477f8919bdaSduboff #define			GEM_TX_DONE	0x00010000
478f8919bdaSduboff #define			GEM_TX_ERR	0x00020000
479f8919bdaSduboff 
480f8919bdaSduboff 
481f8919bdaSduboff 		uint64_t (*gc_rx_desc_stat)
482f8919bdaSduboff 				(struct gem_dev *dp, int slot, int frags);
483f8919bdaSduboff 
484f8919bdaSduboff #define			GEM_RX_CKSUM		0xffff000000000000ull
485f8919bdaSduboff #define			GEM_RX_CKSUM_SHIFT	48
486f8919bdaSduboff #define			GEM_RX_PRI		0x0000e00000000000ull
487f8919bdaSduboff #define			GEM_RX_PRI_SHIFT	45
488f8919bdaSduboff #define			GEM_RX_CFI		0x0000100000000000ull
489f8919bdaSduboff #define			GEM_RX_VID		0x00000fff00000000ull
490f8919bdaSduboff #define			GEM_RX_VID_SHIFT	32
491f8919bdaSduboff #define			GEM_RX_VTAG		0x0000ffff00000000ull
492f8919bdaSduboff #define			GEM_RX_VTAG_SHIFT	32
493f8919bdaSduboff 
494f8919bdaSduboff #define			GEM_RX_CKSUM_IPv6	0x00080000ul
495f8919bdaSduboff #define			GEM_RX_CKSUM_IPv6_SHIFT	19
496f8919bdaSduboff #define			GEM_RX_CKSUM_IPv4	0x00040000ul
497f8919bdaSduboff #define			GEM_RX_CKSUM_IPv4_SHIFT	18
498f8919bdaSduboff #define			GEM_RX_CKSUM_UDP	0x00020000ul
499f8919bdaSduboff #define			GEM_RX_CKSUM_UDP_SHIFT	17
500f8919bdaSduboff #define			GEM_RX_CKSUM_TCP	0x00010000ul
501f8919bdaSduboff #define			GEM_RX_CKSUM_TCP_SHIFT	16
502f8919bdaSduboff #define			GEM_RX_ERR		0x00008000ul
503f8919bdaSduboff #define			GEM_RX_DONE		0x00004000ul
504f8919bdaSduboff #define			GEM_RX_LEN		0x00003ffful	/* 16KB - 1 */
505f8919bdaSduboff 
506f8919bdaSduboff 		void	(*gc_tx_desc_init)(struct gem_dev *dp, int slot);
507f8919bdaSduboff 		void	(*gc_rx_desc_init)(struct gem_dev *dp, int slot);
508f8919bdaSduboff 		void	(*gc_tx_desc_clean)(struct gem_dev *dp, int slot);
509f8919bdaSduboff 		void	(*gc_rx_desc_clean)(struct gem_dev *dp, int slot);
510f8919bdaSduboff 
511f8919bdaSduboff 		/* mii operations */
512f8919bdaSduboff 		int	(*gc_mii_probe)(struct gem_dev *dp);
513f8919bdaSduboff 		int	(*gc_mii_init)(struct gem_dev *dp);
514f8919bdaSduboff 		int	(*gc_mii_config)(struct gem_dev *dp);
515f8919bdaSduboff 		void	(*gc_mii_sync)(struct gem_dev *dp);
516f8919bdaSduboff 		uint16_t (*gc_mii_read)(struct gem_dev *dp, uint_t reg);
517f8919bdaSduboff 		void (*gc_mii_write)(struct gem_dev *dp,
518f8919bdaSduboff 			uint_t reg, uint16_t val);
519f8919bdaSduboff 		void (*gc_mii_tune_phy)(struct gem_dev *dp);
520f8919bdaSduboff 
521f8919bdaSduboff 		/* packet in/out operation for copy-style  */
522f8919bdaSduboff 		void (*gc_put_packet)(struct gem_dev *dp,
523f8919bdaSduboff 			mblk_t *, void *, size_t);
524f8919bdaSduboff 		mblk_t	*(*gc_get_packet)(struct gem_dev *dp,
525f8919bdaSduboff 			struct rxbuf *, size_t);
526f8919bdaSduboff 		int	gc_nports;
527f8919bdaSduboff 
528f8919bdaSduboff 		/* hw checksum */
529f8919bdaSduboff 		uint32_t	gc_hck_rx_start;
530f8919bdaSduboff 	} gc;
531f8919bdaSduboff 
532f8919bdaSduboff 	uint32_t	misc_flag;
53323d366e3Sduboff #define		GEM_LSO			0x00000400
534f8919bdaSduboff #define		GEM_CTRL_PKT		0x00000200
535f8919bdaSduboff #define		GEM_SOFTINTR		0x00000100
536f8919bdaSduboff #define		GEM_POLL_RXONLY		0x00000080
537f8919bdaSduboff #define		GEM_VLAN_HARD		0x00000040
538f8919bdaSduboff #define		GEM_VLAN_SOFT		0x00000020
539f8919bdaSduboff #define		GEM_VLAN		(GEM_VLAN_HARD | GEM_VLAN_SOFT)
540f8919bdaSduboff #define		GEM_CKSUM_HEADER_IPv4	0x00000010
541f8919bdaSduboff #define		GEM_CKSUM_PARTIAL	0x00000008
542f8919bdaSduboff #define		GEM_CKSUM_FULL_IPv6	0x00000004
543f8919bdaSduboff #define		GEM_CKSUM_FULL_IPv4	0x00000002
544f8919bdaSduboff #define		GEM_NOINTR		0x00000001
545f8919bdaSduboff 
546f8919bdaSduboff 	volatile timeout_id_t	intr_watcher_id;
547f8919bdaSduboff 
548f8919bdaSduboff 	uint_t	mtu;
549f8919bdaSduboff 
550f8919bdaSduboff 	/* performance tuning parameters */
551f8919bdaSduboff 	uint_t	txthr;		/* tx fifo threshoold */
552f8919bdaSduboff 	uint_t	txmaxdma;	/* tx max dma burst size */
553f8919bdaSduboff 	uint_t	rxthr;		/* rx fifo threshoold */
554f8919bdaSduboff 	uint_t	rxmaxdma;	/* tx max dma burst size */
555f8919bdaSduboff 
556f8919bdaSduboff 	/* kstat stuff */
557f8919bdaSduboff 	kstat_t	*ksp;
558f8919bdaSduboff 
55923d366e3Sduboff 	/* multiple port device support */
560f8919bdaSduboff 	struct	gem_dev	*next;	/* pointer to next port on the same device */
56123d366e3Sduboff 	int		port;
562f8919bdaSduboff 
563f8919bdaSduboff 	/* ndd stuff */
564f8919bdaSduboff 	caddr_t	nd_data_p;
565f8919bdaSduboff 	caddr_t	nd_arg_p;
566f8919bdaSduboff 
567f8919bdaSduboff #ifdef GEM_DEBUG_LEVEL
568f8919bdaSduboff 	int	tx_cnt;
569f8919bdaSduboff #endif
570f8919bdaSduboff };
571f8919bdaSduboff 
572f8919bdaSduboff /*
573f8919bdaSduboff  * Exported functions
574f8919bdaSduboff  */
575f8919bdaSduboff boolean_t gem_get_mac_addr_conf(struct gem_dev *);
576f8919bdaSduboff int gem_mii_probe_default(struct gem_dev *);
577f8919bdaSduboff int gem_mii_config_default(struct gem_dev *);
578f8919bdaSduboff boolean_t gem_mii_link_check(struct gem_dev *dp);
579f8919bdaSduboff uint16_t gem_mii_read(struct gem_dev *, uint_t);
580f8919bdaSduboff void gem_mii_write(struct gem_dev *, uint_t, uint16_t);
581f8919bdaSduboff int gem_reclaim_txbuf(struct gem_dev *dp);
582f8919bdaSduboff int gem_restart_nic(struct gem_dev *dp, uint_t flags);
583f8919bdaSduboff #define	GEM_RESTART_NOWAIT	0x00000002
584f8919bdaSduboff #define	GEM_RESTART_KEEP_BUF	0x00000001
585f8919bdaSduboff boolean_t gem_tx_done(struct gem_dev *);
586f8919bdaSduboff int gem_receive(struct gem_dev *);
587f8919bdaSduboff int gem_receive_copy(struct gem_dev *);
588f8919bdaSduboff struct gem_dev *gem_do_attach(dev_info_t *, int,
589f8919bdaSduboff 		struct gem_conf *, void *, ddi_acc_handle_t *, void *, int);
590f8919bdaSduboff 
591f8919bdaSduboff mblk_t *gem_send_common(struct gem_dev *, mblk_t *, uint32_t);
592f8919bdaSduboff #define	GEM_SEND_COPY	0x00008000
593f8919bdaSduboff #define	GEM_SEND_CTRL	0x000000ff	/* private flags for control packets */
594f8919bdaSduboff #define	GEM_SEND_VTAG	0xffff0000
595f8919bdaSduboff #define	GEM_SEND_VTAG_SHIFT	16
596f8919bdaSduboff 
597f8919bdaSduboff mblk_t *gem_get_packet_default(struct gem_dev *, struct rxbuf *, size_t);
598f8919bdaSduboff 
599f8919bdaSduboff uint32_t gem_ether_crc_le(const uint8_t *addr, int len);
600f8919bdaSduboff uint32_t gem_ether_crc_be(const uint8_t *addr, int len);
601f8919bdaSduboff int gem_do_detach(dev_info_t *);
602f8919bdaSduboff 
603f8919bdaSduboff int gem_getlongprop_buf(dev_t dev, dev_info_t *dip,
604f8919bdaSduboff 	int flags, char *name, void *buf, int *lenp);
605f8919bdaSduboff int gem_getprop(dev_t dev, dev_info_t *dip,
606f8919bdaSduboff 	int flags, char *name, int defvalue);
607f8919bdaSduboff 
608f8919bdaSduboff struct rxbuf *gem_get_rxbuf(struct gem_dev *, int);
609f8919bdaSduboff 
610f8919bdaSduboff void gem_rx_desc_dma_sync(struct gem_dev *, int, int, int);
611f8919bdaSduboff void gem_tx_desc_dma_sync(struct gem_dev *, int, int, int);
612f8919bdaSduboff 
613f8919bdaSduboff int gem_resume(dev_info_t *);
614f8919bdaSduboff int gem_suspend(dev_info_t *);
615f8919bdaSduboff uint8_t gem_search_pci_cap(dev_info_t *dip, ddi_acc_handle_t, uint8_t);
616f8919bdaSduboff int gem_pci_set_power_state(dev_info_t *, ddi_acc_handle_t, uint_t);
617f8919bdaSduboff int gem_pci_regs_map_setup(dev_info_t *, uint32_t, uint32_t,
618f8919bdaSduboff 	struct ddi_device_acc_attr *, caddr_t *, ddi_acc_handle_t *);
619f8919bdaSduboff void gem_mod_init(struct dev_ops *, char *);
620f8919bdaSduboff void gem_mod_fini(struct dev_ops *);
621f8919bdaSduboff 
622f8919bdaSduboff #define	GEM_GET_DEV(dip) \
623f8919bdaSduboff 	((struct gem_dev *)(ddi_get_driver_private(dip)))
624f8919bdaSduboff #endif /* _SFE_UTIL_H_ */
625