xref: /titanic_50/usr/src/uts/common/io/rge/rge.h (revision dfb96a4f56fb431b915bc67e5d9d5c8d4f4f6679)
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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _RGE_H
27 #define	_RGE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/types.h>
36 #include <sys/stream.h>
37 #include <sys/strsun.h>
38 #include <sys/strsubr.h>
39 #include <sys/stat.h>
40 #include <sys/pci.h>
41 #include <sys/note.h>
42 #include <sys/modctl.h>
43 #include <sys/kstat.h>
44 #include <sys/ethernet.h>
45 #include <sys/vlan.h>
46 #include <sys/errno.h>
47 #include <sys/dlpi.h>
48 #include <sys/devops.h>
49 #include <sys/debug.h>
50 #include <sys/cyclic.h>
51 #include <sys/conf.h>
52 
53 #include <netinet/ip6.h>
54 #include <inet/common.h>
55 #include <inet/ip.h>
56 #include <inet/mi.h>
57 #include <inet/nd.h>
58 #include <sys/pattr.h>
59 
60 #include <sys/dditypes.h>
61 #include <sys/ddi.h>
62 #include <sys/sunddi.h>
63 
64 #include <sys/mac.h>
65 #include <sys/mac_ether.h>
66 
67 /*
68  * Reconfiguring the network devices requires the net_config privilege
69  * in Solaris 10+.
70  */
71 extern int secpolicy_net_config(const cred_t *, boolean_t);
72 
73 #include <sys/netlb.h>			/* originally from cassini	*/
74 #include <sys/miiregs.h>		/* by fjlite out of intel 	*/
75 
76 #include "rge_hw.h"
77 
78 /*
79  * Name of the driver
80  */
81 #define	RGE_DRIVER_NAME		"rge"
82 
83 /*
84  * The driver supports the NDD ioctls ND_GET/ND_SET, and the loopback
85  * ioctls LB_GET_INFO_SIZE/LB_GET_INFO/LB_GET_MODE/LB_SET_MODE
86  *
87  * These are the values to use with LD_SET_MODE.
88  */
89 #define	RGE_LOOP_NONE		0
90 #define	RGE_LOOP_INTERNAL_PHY	1
91 #define	RGE_LOOP_INTERNAL_MAC	2
92 
93 /*
94  * RGE-specific ioctls ...
95  */
96 #define	RGE_IOC			((((('R' << 8) + 'G') << 8) + 'E') << 8)
97 
98 /*
99  * PHY register read/write ioctls, used by cable test software
100  */
101 #define	RGE_MII_READ		(RGE_IOC|1)
102 #define	RGE_MII_WRITE		(RGE_IOC|2)
103 
104 struct rge_mii_rw {
105 	uint32_t	mii_reg;	/* PHY register number [0..31]	*/
106 	uint32_t	mii_data;	/* data to write/data read	*/
107 };
108 
109 /*
110  * These diagnostic IOCTLS are enabled only in DEBUG drivers
111  */
112 #define	RGE_DIAG		(RGE_IOC|10)	/* currently a no-op	*/
113 #define	RGE_PEEK		(RGE_IOC|11)
114 #define	RGE_POKE		(RGE_IOC|12)
115 #define	RGE_PHY_RESET		(RGE_IOC|13)
116 #define	RGE_SOFT_RESET		(RGE_IOC|14)
117 #define	RGE_HARD_RESET		(RGE_IOC|15)
118 
119 typedef struct {
120 	uint64_t		pp_acc_size;	/* in bytes: 1,2,4,8	*/
121 	uint64_t		pp_acc_space;	/* See #defines below	*/
122 	uint64_t		pp_acc_offset;
123 	uint64_t		pp_acc_data;	/* output for peek	*/
124 						/* input for poke	*/
125 } rge_peekpoke_t;
126 
127 #define	RGE_PP_SPACE_CFG	0		/* PCI config space	*/
128 #define	RGE_PP_SPACE_REG	1		/* PCI memory space	*/
129 #define	RGE_PP_SPACE_MII	2		/* PHY's MII registers	*/
130 #define	RGE_PP_SPACE_RGE	3		/* driver's soft state	*/
131 #define	RGE_PP_SPACE_TXDESC	4		/* TX descriptors	*/
132 #define	RGE_PP_SPACE_TXBUFF	5		/* TX buffers		*/
133 #define	RGE_PP_SPACE_RXDESC	6		/* RX descriptors	*/
134 #define	RGE_PP_SPACE_RXBUFF	7		/* RX buffers		*/
135 #define	RGE_PP_SPACE_STATISTICS	8		/* statistics block	*/
136 
137 /*
138  * RTL8169 CRC poly
139  */
140 #define	RGE_HASH_POLY		0x04C11DB7	/* 0x04C11DB6 */
141 #define	RGE_HASH_CRC		0xFFFFFFFFU
142 #define	RGE_MCAST_BUF_SIZE	64	/* multicast hash table size in bits */
143 
144 /*
145  * Rx/Tx buffer parameters
146  */
147 #define	RGE_BUF_SLOTS		2048
148 #define	RGE_RECV_COPY_SIZE	256
149 #define	RGE_HEADROOM		6
150 
151 /*
152  * Driver chip operation parameters
153  */
154 #define	RGE_CYCLIC_PERIOD	(1000000000)	/* ~1s */
155 #define	RGE_LINK_SETTLE_TIME	(20000000000)	/* ~20.0s */
156 #define	CHIP_RESET_LOOP		1000
157 #define	PHY_RESET_LOOP		1000
158 #define	STATS_DUMP_LOOP		1000
159 #define	RXBUFF_FREE_LOOP	1000
160 #define	RGE_RX_INT_TIME		128
161 #define	RGE_RX_INT_PKTS		8
162 
163 /*
164  * Named Data (ND) Parameter Management Structure
165  */
166 typedef struct {
167 	int			ndp_info;
168 	int			ndp_min;
169 	int			ndp_max;
170 	int			ndp_val;
171 	char			*ndp_name;
172 } nd_param_t;				/* 0x18 (24) bytes	*/
173 
174 /*
175  * NDD parameter indexes, divided into:
176  *
177  *	read-only parameters describing the hardware's capabilities
178  *	read-write parameters controlling the advertised capabilities
179  *	read-only parameters describing the partner's capabilities
180  *	read-only parameters describing the link state
181  */
182 enum {
183 	PARAM_AUTONEG_CAP = 0,
184 	PARAM_PAUSE_CAP,
185 	PARAM_ASYM_PAUSE_CAP,
186 	PARAM_1000FDX_CAP,
187 	PARAM_1000HDX_CAP,
188 	PARAM_100T4_CAP,
189 	PARAM_100FDX_CAP,
190 	PARAM_100HDX_CAP,
191 	PARAM_10FDX_CAP,
192 	PARAM_10HDX_CAP,
193 
194 	PARAM_ADV_AUTONEG_CAP,
195 	PARAM_ADV_PAUSE_CAP,
196 	PARAM_ADV_ASYM_PAUSE_CAP,
197 	PARAM_ADV_1000FDX_CAP,
198 	PARAM_ADV_1000HDX_CAP,
199 	PARAM_ADV_100T4_CAP,
200 	PARAM_ADV_100FDX_CAP,
201 	PARAM_ADV_100HDX_CAP,
202 	PARAM_ADV_10FDX_CAP,
203 	PARAM_ADV_10HDX_CAP,
204 
205 	PARAM_LINK_STATUS,
206 	PARAM_LINK_SPEED,
207 	PARAM_LINK_DUPLEX,
208 
209 	PARAM_LOOP_MODE,
210 
211 	PARAM_COUNT
212 };
213 
214 enum rge_chip_state {
215 	RGE_CHIP_FAULT = -2,			/* fault, need reset	*/
216 	RGE_CHIP_ERROR,				/* error, want reset	*/
217 	RGE_CHIP_INITIAL,			/* Initial state only	*/
218 	RGE_CHIP_RESET,				/* reset, need init	*/
219 	RGE_CHIP_STOPPED,			/* Tx/Rx stopped	*/
220 	RGE_CHIP_RUNNING			/* with interrupts	*/
221 };
222 
223 enum rge_mac_state {
224 	RGE_MAC_ATTACH = 0,
225 	RGE_MAC_STOPPED,
226 	RGE_MAC_STARTED,
227 	RGE_MAC_UNATTACH
228 };
229 
230 enum rge_sync_op {
231 	RGE_OP_NULL,
232 	RGE_GET_MAC,				/* get mac address operation */
233 	RGE_SET_MAC,				/* set mac address operation */
234 	RGE_SET_MUL,				/* set multicast address op */
235 	RGE_SET_PROMISC				/* set promisc mode */
236 };
237 
238 /*
239  * (Internal) return values from ioctl subroutines
240  */
241 enum ioc_reply {
242 	IOC_INVAL = -1,				/* bad, NAK with EINVAL	*/
243 	IOC_DONE,				/* OK, reply sent	*/
244 	IOC_ACK,				/* OK, just send ACK	*/
245 	IOC_REPLY,				/* OK, just send reply	*/
246 	IOC_RESTART_ACK,			/* OK, restart & ACK	*/
247 	IOC_RESTART_REPLY			/* OK, restart & reply	*/
248 };
249 
250 /*
251  * (Internal) enumeration of this driver's kstats
252  */
253 enum {
254 	RGE_KSTAT_PARAMS = 0,
255 	RGE_KSTAT_DRIVER,
256 	RGE_KSTAT_COUNT
257 };
258 
259 /*
260  * Basic data types, for clarity in distinguishing 'numbers'
261  * used for different purposes ...
262  *
263  * A <rge_regno_t> is a register 'address' (offset) in any one of
264  * various address spaces (PCI config space, PCI memory-mapped I/O
265  * register space, MII registers, etc).  None of these exceeds 64K,
266  * so we could use a 16-bit representation but pointer-sized objects
267  * are more "natural" in most architectures; they seem to be handled
268  * more efficiently on SPARC and no worse on x86.
269  *
270  * RGE_REGNO_NONE represents the non-existent value in this space.
271  */
272 typedef uintptr_t rge_regno_t;			/* register # (offset)	*/
273 #define	RGE_REGNO_NONE		(~(uintptr_t)0u)
274 
275 /*
276  * Describes one chunk of allocated DMA-able memory
277  *
278  * In some cases, this is a single chunk as allocated from the system;
279  * but we also use this structure to represent slices carved off such
280  * a chunk.  Even when we don't really need all the information, we
281  * use this structure as a convenient way of correlating the various
282  * ways of looking at a piece of memory (kernel VA, IO space DVMA,
283  * handle+offset, etc).
284  */
285 typedef struct {
286 	ddi_acc_handle_t	acc_hdl;	/* handle for memory	*/
287 	void			*mem_va;	/* CPU VA of memory	*/
288 	uint32_t		nslots;		/* number of slots	*/
289 	uint32_t		size;		/* size per slot	*/
290 	size_t			alength;	/* allocated size */
291 	ddi_dma_handle_t	dma_hdl;	/* DMA handle */
292 	offset_t		offset;		/* relative to handle	*/
293 	ddi_dma_cookie_t	cookie;		/* associated cookie */
294 	uint32_t		ncookies;	/* must be 1 */
295 	uint32_t		token;		/* arbitrary identifier	*/
296 } dma_area_t;
297 
298 /*
299  * Software version of the Receive Buffer Descriptor
300  */
301 typedef struct {
302 	caddr_t			private;	/* pointer to rge */
303 	dma_area_t		pbuf;		/* (const) related	*/
304 						/* buffer area		*/
305 	frtn_t			rx_recycle;	/* recycle function */
306 	mblk_t			*mp;
307 } dma_buf_t;
308 
309 typedef struct sw_rbd {
310 	dma_buf_t		*rx_buf;
311 	uint8_t			flags;
312 } sw_rbd_t;
313 
314 /*
315  * Software version of the Send Buffer Descriptor
316  */
317 typedef struct sw_sbd {
318 	dma_area_t		desc;		/* (const) related h/w	*/
319 						/* descriptor area	*/
320 	dma_area_t		pbuf;		/* (const) related	*/
321 						/* buffer area		*/
322 } sw_sbd_t;
323 
324 
325 #define	HW_RBD_INIT(rbd, slot)					\
326 	rbd->flags_len |= RGE_BSWAP_32(BD_FLAG_HW_OWN);		\
327 	rbd->vlan_tag = 0;					\
328 	if (slot == (RGE_RECV_SLOTS -1))			\
329 		rbd->flags_len |= RGE_BSWAP_32(BD_FLAG_EOR);
330 #define	HW_SBD_INIT(sbd, slot)					\
331 	sbd->flags_len = 0;					\
332 	if (slot == (RGE_SEND_SLOTS -1))			\
333 		sbd->flags_len |= RGE_BSWAP_32(BD_FLAG_EOR);
334 #define	HW_SBD_SET(sbd, slot)					\
335 	sbd->flags_len |= RGE_BSWAP_32(SBD_FLAG_TX_PKT);	\
336 	if (slot == (RGE_SEND_SLOTS -1))			\
337 		sbd->flags_len |= RGE_BSWAP_32(BD_FLAG_EOR);
338 
339 /*
340  * Describes the characteristics of a specific chip
341  */
342 typedef struct {
343 	uint16_t		command;	/* saved during attach	*/
344 	uint16_t		vendor;		/* vendor-id		*/
345 	uint16_t		device;		/* device-id		*/
346 	uint16_t		subven;		/* subsystem-vendor-id	*/
347 	uint16_t		subdev;		/* subsystem-id		*/
348 	uint8_t			revision;	/* revision-id		*/
349 	uint8_t			clsize;		/* cache-line-size	*/
350 	uint8_t			latency;	/* latency-timer	*/
351 	boolean_t		is_pcie;
352 	uint32_t		mac_ver;
353 	uint32_t		phy_ver;
354 	uint32_t		rxconfig;
355 	uint32_t		txconfig;
356 } chip_id_t;
357 
358 typedef struct rge_stats {
359 	uint64_t	rbytes;
360 	uint64_t	obytes;
361 	uint32_t	overflow;
362 	uint32_t	defer;		/* dot3StatsDeferredTransmissions */
363 	uint32_t	crc_err;	/* dot3StatsFCSErrors */
364 	uint32_t	in_short;
365 	uint32_t	no_rcvbuf;	/* ifInDiscards */
366 	uint32_t	intr;		/* interrupt count */
367 	uint16_t	chip_reset;
368 	uint16_t	phy_reset;
369 } rge_stats_t;
370 
371 /*
372  * Per-instance soft-state structure
373  */
374 typedef struct rge {
375 	dev_info_t		*devinfo;	/* device instance	*/
376 	mac_handle_t		mh;		/* mac module handle	*/
377 	ddi_acc_handle_t	cfg_handle;	/* DDI I/O handle	*/
378 	ddi_acc_handle_t	io_handle;	/* DDI I/O handle	*/
379 	caddr_t			io_regs;	/* mapped registers	*/
380 	cyclic_id_t		cyclic_id;	/* cyclic callback	*/
381 	ddi_softint_handle_t	resched_hdl;	/* reschedule callback	*/
382 	ddi_softint_handle_t	factotum_hdl;	/* factotum callback	*/
383 	uint_t			soft_pri;
384 	ddi_intr_handle_t 	*htable;	/* For array of interrupts */
385 	int			intr_type;	/* What type of interrupt */
386 	int			intr_rqst;	/* # of request intrs count */
387 	int			intr_cnt;	/* # of intrs count returned */
388 	uint_t			intr_pri;	/* Interrupt priority	*/
389 	int			intr_cap;	/* Interrupt capabilities */
390 	boolean_t		msi_enable;
391 
392 	uint32_t		ethmax_size;
393 	uint32_t		default_mtu;
394 	uint32_t		rxbuf_size;
395 	uint32_t		txbuf_size;
396 	uint32_t		chip_flags;
397 	uint32_t		head_room;
398 	char			ifname[8];	/* "rge0" ... "rge999"	*/
399 	int32_t			instance;
400 	uint32_t		progress;	/* attach tracking	*/
401 	uint32_t		debug;		/* per-instance debug	*/
402 	chip_id_t		chipid;
403 
404 	/*
405 	 * These structures describe the blocks of memory allocated during
406 	 * attach().  They remain unchanged thereafter, although the memory
407 	 * they describe is carved up into various separate regions and may
408 	 * therefore be described by other structures as well.
409 	 */
410 	dma_area_t		dma_area_rxdesc;
411 	dma_area_t		dma_area_txdesc;
412 	dma_area_t		dma_area_stats;
413 				/* describes hardware statistics area	*/
414 
415 	uint8_t			netaddr[ETHERADDRL];	/* mac address	*/
416 	uint16_t		int_mask;	/* interrupt mask	*/
417 
418 	/* used for multicast/promisc mode set */
419 	char			mcast_refs[RGE_MCAST_BUF_SIZE];
420 	uint8_t			mcast_hash[RGE_MCAST_NUM];
421 	boolean_t		promisc;	/* promisc state flag	*/
422 
423 	/* used for recv */
424 	rge_bd_t		*rx_ring;
425 	dma_area_t		rx_desc;
426 	boolean_t		rx_bcopy;
427 	uint32_t		rx_next;	/* current rx bd index	*/
428 	sw_rbd_t		*sw_rbds;
429 	sw_rbd_t		*free_srbds;
430 	uint32_t		rf_next;	/* current free buf index */
431 	uint32_t		rc_next;	/* current recycle buf index */
432 	uint32_t		rx_free;	/* number of rx free buf */
433 	mac_resource_handle_t	handle;
434 
435 	/* used for send */
436 	rge_bd_t		*tx_ring;
437 	dma_area_t		tx_desc;
438 	uint32_t		tx_free;	/* number of free tx bd */
439 	uint32_t		tx_next;	/* current tx bd index	*/
440 	uint32_t		tc_next;	/* current tx recycle index */
441 	uint32_t		tx_flow;
442 	uint32_t		tc_tail;
443 	sw_sbd_t		*sw_sbds;
444 
445 	/* mutex */
446 	kmutex_t		genlock[1];	/* i/o reg access	*/
447 	krwlock_t		errlock[1];	/* rge restart */
448 	kmutex_t		tx_lock[1];	/* send access		*/
449 	kmutex_t		tc_lock[1];	/* send recycle access */
450 	kmutex_t		rx_lock[1];	/* receive access	*/
451 	kmutex_t		rc_lock[1];	/* receive recycle access */
452 
453 	/*
454 	 * Miscellaneous operating variables (not synchronised)
455 	 */
456 	uint32_t		watchdog;	/* watches for Tx stall	*/
457 	boolean_t		resched_needed;
458 	uint32_t		factotum_flag;	/* softint pending	*/
459 
460 	/*
461 	 * Link state data (protected by genlock)
462 	 */
463 	const char		*link_down_msg;	/* reason for link DOWN	*/
464 	const char		*link_up_msg;	/* comment on link UP	*/
465 
466 	/*
467 	 * Physical layer state data (protected by genlock)
468 	 */
469 	hrtime_t		phys_write_time; /* when last written	*/
470 	hrtime_t		phys_event_time; /* when status changed	*/
471 
472 	/*
473 	 * Physical layer
474 	 */
475 	rge_regno_t		phy_mii_addr;	/* should be (const) 1!	*/
476 	uint16_t		link_down_count;
477 
478 	/*
479 	 * NDD parameters (protected by genlock)
480 	 */
481 	caddr_t			nd_data_p;
482 	nd_param_t		nd_params[PARAM_COUNT];
483 
484 	/*
485 	 * Driver kstats, protected by <genlock> where necessary
486 	 */
487 	kstat_t			*rge_kstats[RGE_KSTAT_COUNT];
488 
489 	/* H/W statistics */
490 	rge_hw_stats_t		*hw_stats;
491 	rge_stats_t		stats;
492 	enum rge_mac_state	rge_mac_state;	/* definitions above	*/
493 	enum rge_chip_state	rge_chip_state;	/* definitions above	*/
494 } rge_t;
495 
496 /*
497  * 'Progress' bit flags ...
498  */
499 #define	PROGRESS_CFG		0x0001	/* config space mapped		*/
500 #define	PROGRESS_REGS		0x0002	/* registers mapped		*/
501 #define	PROGRESS_RESCHED	0x0010	/* resched softint registered	*/
502 #define	PROGRESS_FACTOTUM	0x0020	/* factotum softint registered	*/
503 #define	PROGRESS_INTR		0X0040	/* h/w interrupt registered	*/
504 					/* and mutexen initialised	*/
505 #define	PROGRESS_INIT		0x0080	/* rx/buf/tx ring initialised	*/
506 #define	PROGRESS_PHY		0x0100	/* PHY initialised		*/
507 #define	PROGRESS_NDD		0x1000	/* NDD parameters set up	*/
508 #define	PROGRESS_KSTATS		0x2000	/* kstats created		*/
509 #define	PROGRESS_READY		0x8000	/* ready for work		*/
510 
511 /*
512  * Special chip flags
513  */
514 #define	CHIP_FLAG_FORCE_BCOPY	0x10000000
515 
516 /*
517  * Shorthand for the NDD parameters
518  */
519 #define	param_adv_autoneg	nd_params[PARAM_ADV_AUTONEG_CAP].ndp_val
520 #define	param_adv_pause		nd_params[PARAM_ADV_PAUSE_CAP].ndp_val
521 #define	param_adv_asym_pause	nd_params[PARAM_ADV_ASYM_PAUSE_CAP].ndp_val
522 #define	param_adv_1000fdx	nd_params[PARAM_ADV_1000FDX_CAP].ndp_val
523 #define	param_adv_1000hdx	nd_params[PARAM_ADV_1000HDX_CAP].ndp_val
524 #define	param_adv_100fdx	nd_params[PARAM_ADV_100FDX_CAP].ndp_val
525 #define	param_adv_100hdx	nd_params[PARAM_ADV_100HDX_CAP].ndp_val
526 #define	param_adv_10fdx		nd_params[PARAM_ADV_10FDX_CAP].ndp_val
527 #define	param_adv_10hdx		nd_params[PARAM_ADV_10HDX_CAP].ndp_val
528 
529 #define	param_link_up		nd_params[PARAM_LINK_STATUS].ndp_val
530 #define	param_link_speed	nd_params[PARAM_LINK_SPEED].ndp_val
531 #define	param_link_duplex	nd_params[PARAM_LINK_DUPLEX].ndp_val
532 
533 #define	param_loop_mode		nd_params[PARAM_LOOP_MODE].ndp_val
534 
535 /*
536  * Sync a DMA area described by a dma_area_t
537  */
538 #define	DMA_SYNC(area, flag)	((void) ddi_dma_sync((area).dma_hdl,	\
539 				    (area).offset, (area).alength, (flag)))
540 
541 /*
542  * Find the (kernel virtual) address of block of memory
543  * described by a dma_area_t
544  */
545 #define	DMA_VPTR(area)		((area).mem_va)
546 
547 /*
548  * Zero a block of memory described by a dma_area_t
549  */
550 #define	DMA_ZERO(area)		bzero(DMA_VPTR(area), (area).alength)
551 
552 /*
553  * Next/Last value of a cyclic index
554  */
555 #define	NEXT(index, limit)	((index)+1 < (limit) ? (index)+1 : 0);
556 #define	LAST(index, limit)	((index) ? (index)-1 : (limit - 1));
557 /*
558  * Property lookups
559  */
560 #define	RGE_PROP_EXISTS(d, n)	ddi_prop_exists(DDI_DEV_T_ANY, (d),	\
561 					DDI_PROP_DONTPASS, (n))
562 #define	RGE_PROP_GET_INT(d, n)	ddi_prop_get_int(DDI_DEV_T_ANY, (d),	\
563 					DDI_PROP_DONTPASS, (n), -1)
564 
565 /*
566  * Endian swap
567  */
568 #ifdef	_BIG_ENDIAN
569 #define	RGE_BSWAP_16(x)		((((x) & 0xff00) >> 8)	|		\
570 				    (((x) & 0x00ff) << 8))
571 #define	RGE_BSWAP_32(x)		((((x) & 0xff000000) >> 24)	|	\
572 				    (((x) & 0x00ff0000) >> 8)	|	\
573 				    (((x) & 0x0000ff00) << 8)	|	\
574 				    (((x) & 0x000000ff) << 24))
575 #define	RGE_BSWAP_64(x)		(RGE_BSWAP_32((x) >> 32)	|	\
576 				    (RGE_BSWAP_32(x) << 32))
577 #else
578 #define	RGE_BSWAP_16(x)		(x)
579 #define	RGE_BSWAP_32(x)		(x)
580 #define	RGE_BSWAP_64(x)		(x)
581 #endif
582 
583 /*
584  * Bit test macros, returning boolean_t values
585  */
586 #define	BIS(w, b)	(((w) & (b)) ? B_TRUE : B_FALSE)
587 #define	BIC(w, b)	(((w) & (b)) ? B_FALSE : B_TRUE)
588 #define	UPORDOWN(x)	((x) ? "up" : "down")
589 
590 /*
591  * Bit flags in the 'debug' word ...
592  */
593 #define	RGE_DBG_STOP		0x00000001	/* early debug_enter()	*/
594 #define	RGE_DBG_TRACE		0x00000002	/* general flow tracing	*/
595 
596 #define	RGE_DBG_REGS		0x00000010	/* low-level accesses	*/
597 #define	RGE_DBG_MII		0x00000020	/* low-level MII access	*/
598 #define	RGE_DBG_SEEPROM		0x00000040	/* low-level SEEPROM IO	*/
599 #define	RGE_DBG_CHIP		0x00000080	/* low(ish)-level code	*/
600 
601 #define	RGE_DBG_RECV		0x00000100	/* receive-side code	*/
602 #define	RGE_DBG_SEND		0x00000200	/* packet-send code	*/
603 
604 #define	RGE_DBG_INT		0x00001000	/* interrupt handler	*/
605 #define	RGE_DBG_FACT		0x00002000	/* factotum (softint)	*/
606 
607 #define	RGE_DBG_PHY		0x00010000	/* Copper PHY code	*/
608 #define	RGE_DBG_SERDES		0x00020000	/* SerDes code		*/
609 #define	RGE_DBG_PHYS		0x00040000	/* Physical layer code	*/
610 #define	RGE_DBG_LINK		0x00080000	/* Link status check	*/
611 
612 #define	RGE_DBG_INIT		0x00100000	/* initialisation	*/
613 #define	RGE_DBG_NEMO		0x00200000	/* nemo interaction	*/
614 #define	RGE_DBG_ADDR		0x00400000	/* address-setting code	*/
615 #define	RGE_DBG_STATS		0x00800000	/* statistics		*/
616 
617 #define	RGE_DBG_IOCTL		0x01000000	/* ioctl handling	*/
618 #define	RGE_DBG_LOOP		0x02000000	/* loopback ioctl code	*/
619 #define	RGE_DBG_PPIO		0x04000000	/* Peek/poke ioctls	*/
620 #define	RGE_DBG_BADIOC		0x08000000	/* unknown ioctls	*/
621 
622 #define	RGE_DBG_MCTL		0x10000000	/* mctl (csum) code	*/
623 #define	RGE_DBG_NDD		0x20000000	/* NDD operations	*/
624 
625 /*
626  * Debugging ...
627  */
628 #ifdef	DEBUG
629 #define	RGE_DEBUGGING		1
630 #else
631 #define	RGE_DEBUGGING		0
632 #endif	/* DEBUG */
633 
634 
635 /*
636  * 'Do-if-debugging' macro.  The parameter <command> should be one or more
637  * C statements (but without the *final* semicolon), which will either be
638  * compiled inline or completely ignored, depending on the RGE_DEBUGGING
639  * compile-time flag.
640  *
641  * You should get a compile-time error (at least on a DEBUG build) if
642  * your statement isn't actually a statement, rather than unexpected
643  * run-time behaviour caused by unintended matching of if-then-elses etc.
644  *
645  * Note that the RGE_DDB() macro itself can only be used as a statement,
646  * not an expression, and should always be followed by a semicolon.
647  */
648 #if	RGE_DEBUGGING
649 #define	RGE_DDB(command)	do {					\
650 					{ command; }			\
651 					_NOTE(CONSTANTCONDITION)	\
652 				} while (0)
653 #else 	/* RGE_DEBUGGING */
654 #define	RGE_DDB(command)	do {					\
655 					{ _NOTE(EMPTY); }		\
656 					_NOTE(CONSTANTCONDITION)	\
657 				} while (0)
658 #endif	/* RGE_DEBUGGING */
659 
660 /*
661  * 'Internal' macros used to construct the TRACE/DEBUG macros below.
662  * These provide the primitive conditional-call capability required.
663  * Note: the parameter <args> is a parenthesised list of the actual
664  * printf-style arguments to be passed to the debug function ...
665  */
666 #define	RGE_XDB(b, w, f, args)	RGE_DDB(if ((b) & (w)) f args)
667 #define	RGE_GDB(b, args)	RGE_XDB(b, rge_debug, (*rge_gdb()), args)
668 #define	RGE_LDB(b, args)	RGE_XDB(b, rgep->debug, (*rge_db(rgep)), args)
669 #define	RGE_CDB(f, args)	RGE_XDB(RGE_DBG, rgep->debug, f, args)
670 
671 /*
672  * Conditional-print macros.
673  *
674  * Define RGE_DBG to be the relevant member of the set of RGE_DBG_* values
675  * above before using the RGE_GDEBUG() or RGE_DEBUG() macros.  The 'G'
676  * versions look at the Global debug flag word (rge_debug); the non-G
677  * versions look in the per-instance data (rgep->debug) and so require a
678  * variable called 'rgep' to be in scope (and initialised!) before use.
679  *
680  * You could redefine RGE_TRC too if you really need two different
681  * flavours of debugging output in the same area of code, but I don't
682  * really recommend it.
683  *
684  * Note: the parameter <args> is a parenthesised list of the actual
685  * arguments to be passed to the debug function, usually a printf-style
686  * format string and corresponding values to be formatted.
687  */
688 
689 #define	RGE_TRC			RGE_DBG_TRACE	/* default 'trace' bit	*/
690 #define	RGE_GTRACE(args)	RGE_GDB(RGE_TRC, args)
691 #define	RGE_GDEBUG(args)	RGE_GDB(RGE_DBG, args)
692 #define	RGE_TRACE(args)		RGE_LDB(RGE_TRC, args)
693 #define	RGE_DEBUG(args)		RGE_LDB(RGE_DBG, args)
694 
695 /*
696  * Debug-only action macros
697  */
698 #define	RGE_BRKPT(rgep, s)	RGE_DDB(rge_dbg_enter(rgep, s))
699 #define	RGE_MARK(rgep)		RGE_DDB(rge_led_mark(rgep))
700 #define	RGE_PCICHK(rgep)	RGE_DDB(rge_pci_check(rgep))
701 #define	RGE_PKTDUMP(args)	RGE_DDB(rge_pkt_dump args)
702 #define	RGE_REPORT(args)	RGE_DDB(rge_log args)
703 
704 /*
705  * Inter-source-file linkage ...
706  */
707 
708 /* rge_chip.c */
709 uint16_t rge_mii_get16(rge_t *rgep, uintptr_t mii);
710 void rge_mii_put16(rge_t *rgep, uintptr_t mii, uint16_t data);
711 void rge_chip_cfg_init(rge_t *rgep, chip_id_t *cidp);
712 void rge_chip_ident(rge_t *rgep);
713 int rge_chip_reset(rge_t *rgep);
714 void rge_chip_init(rge_t *rgep);
715 void rge_chip_start(rge_t *rgep);
716 void rge_chip_stop(rge_t *rgep, boolean_t fault);
717 void rge_chip_sync(rge_t *rgep, enum rge_sync_op todo);
718 void rge_chip_blank(void *arg, time_t ticks, uint_t count);
719 void rge_tx_trigger(rge_t *rgep);
720 void rge_hw_stats_dump(rge_t *rgep);
721 uint_t rge_intr(caddr_t arg1, caddr_t arg2);
722 uint_t rge_chip_factotum(caddr_t arg1, caddr_t arg2);
723 void rge_chip_cyclic(void *arg);
724 enum ioc_reply rge_chip_ioctl(rge_t *rgep, queue_t *wq, mblk_t *mp,
725 	struct iocblk *iocp);
726 boolean_t rge_phy_reset(rge_t *rgep);
727 void rge_phy_init(rge_t *rgep);
728 void rge_phy_update(rge_t *rgep);
729 
730 /* rge_kstats.c */
731 void rge_init_kstats(rge_t *rgep, int instance);
732 void rge_fini_kstats(rge_t *rgep);
733 int rge_m_stat(void *arg, uint_t stat, uint64_t *val);
734 
735 /* rge_log.c */
736 #if	RGE_DEBUGGING
737 void (*rge_db(rge_t *rgep))(const char *fmt, ...);
738 void (*rge_gdb(void))(const char *fmt, ...);
739 void rge_pkt_dump(rge_t *rgep, rge_bd_t *hbp, sw_rbd_t *sdp, const char *msg);
740 void rge_dbg_enter(rge_t *rgep, const char *msg);
741 #endif	/* RGE_DEBUGGING */
742 void rge_problem(rge_t *rgep, const char *fmt, ...);
743 void rge_notice(rge_t *rgep, const char *fmt, ...);
744 void rge_log(rge_t *rgep, const char *fmt, ...);
745 void rge_error(rge_t *rgep, const char *fmt, ...);
746 extern kmutex_t rge_log_mutex[1];
747 extern uint32_t rge_debug;
748 
749 /* rge_main.c */
750 void rge_restart(rge_t *rgep);
751 
752 /* rge_ndd.c */
753 int rge_nd_init(rge_t *rgep);
754 enum ioc_reply rge_nd_ioctl(rge_t *rgep, queue_t *wq, mblk_t *mp,
755 	struct iocblk *iocp);
756 void rge_nd_cleanup(rge_t *rgep);
757 
758 /* rge_rxtx.c */
759 void rge_rx_recycle(caddr_t arg);
760 void rge_receive(rge_t *rgep);
761 mblk_t *rge_m_tx(void *arg, mblk_t *mp);
762 uint_t rge_reschedule(caddr_t arg1, caddr_t arg2);
763 
764 #ifdef __cplusplus
765 }
766 #endif
767 
768 #endif	/* _RGE_H */
769