xref: /onnv-gate/usr/src/uts/sun/io/eri/eri.h (revision 7394:fd446675db41)
16833Sgd78059 /*
26833Sgd78059  * CDDL HEADER START
36833Sgd78059  *
46833Sgd78059  * The contents of this file are subject to the terms of the
56833Sgd78059  * Common Development and Distribution License (the "License").
66833Sgd78059  * You may not use this file except in compliance with the License.
76833Sgd78059  *
86833Sgd78059  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96833Sgd78059  * or http://www.opensolaris.org/os/licensing.
106833Sgd78059  * See the License for the specific language governing permissions
116833Sgd78059  * and limitations under the License.
126833Sgd78059  *
136833Sgd78059  * When distributing Covered Code, include this CDDL HEADER in each
146833Sgd78059  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156833Sgd78059  * If applicable, add the following below this CDDL HEADER, with the
166833Sgd78059  * fields enclosed by brackets "[]" replaced with your own identifying
176833Sgd78059  * information: Portions Copyright [yyyy] [name of copyright owner]
186833Sgd78059  *
196833Sgd78059  * CDDL HEADER END
206833Sgd78059  */
216833Sgd78059 /*
22*7394Sgdamore@opensolaris.org  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
236833Sgd78059  * Use is subject to license terms.
246833Sgd78059  */
256833Sgd78059 
266833Sgd78059 #ifndef	_SYS_ERI_H
276833Sgd78059 #define	_SYS_ERI_H
286833Sgd78059 
296833Sgd78059 #ifdef	__cplusplus
306833Sgd78059 extern "C" {
316833Sgd78059 #endif
326833Sgd78059 
336833Sgd78059 
346833Sgd78059 #ifdef _KERNEL
356833Sgd78059 
366833Sgd78059 /* Named Dispatch Parameter Management Structure */
376833Sgd78059 typedef struct param_s {
386833Sgd78059 	uint32_t param_min;
396833Sgd78059 	uint32_t param_max;
406833Sgd78059 	uint32_t param_val;
416833Sgd78059 	char   *param_name;
426833Sgd78059 } param_t;
436833Sgd78059 
446833Sgd78059 #define	ERI_PARAM_CNT	51
456833Sgd78059 
466833Sgd78059 typedef enum  {
476833Sgd78059 	MIF_POLL_STOP,
486833Sgd78059 	MIF_POLL_START
496833Sgd78059 } soft_mif_enable_t;
506833Sgd78059 
516833Sgd78059 
526833Sgd78059 /*
536833Sgd78059  * kstats
546833Sgd78059  */
556833Sgd78059 typedef struct stats {
566833Sgd78059 	/*
576833Sgd78059 	 * Link Input/Output stats
586833Sgd78059 	 * ifspeed is now in bits/second.
596833Sgd78059 	 */
606833Sgd78059 	uint64_t	ipackets64;
616833Sgd78059 	uint64_t	iipackets64;
626833Sgd78059 	uint32_t	ierrors;
636833Sgd78059 	uint64_t	opackets64;
646833Sgd78059 	uint64_t	oerrors;
656833Sgd78059 	uint32_t	collisions;
666833Sgd78059 	uint64_t	ifspeed;
676833Sgd78059 
686833Sgd78059 	/*
696833Sgd78059 	 * MAC TX Event stats
706833Sgd78059 	 */
716833Sgd78059 	uint32_t	txmac_urun;
726833Sgd78059 	uint32_t	txmac_maxpkt_err;
736833Sgd78059 	uint32_t	excessive_coll;
746833Sgd78059 	uint32_t	late_coll;
756833Sgd78059 	uint32_t	first_coll;
766833Sgd78059 	uint32_t	defer_timer_exp;
776833Sgd78059 	uint32_t	peak_attempt_cnt;
786833Sgd78059 	uint32_t	tx_hang;
796833Sgd78059 
806833Sgd78059 	/*
816833Sgd78059 	 * MAC RX Event stats
826833Sgd78059 	 */
836833Sgd78059 	uint32_t	rx_corr;
846833Sgd78059 	uint32_t	no_free_rx_desc;	/* no free rx desc. */
856833Sgd78059 	uint32_t	rx_overflow;
866833Sgd78059 	uint32_t	rx_ovrflpkts;
876833Sgd78059 	uint32_t	rx_hang;
886833Sgd78059 	uint32_t	rx_align_err;
896833Sgd78059 	uint32_t	rx_crc_err;
906833Sgd78059 	uint32_t	rx_length_err;
916833Sgd78059 	uint32_t	rx_code_viol_err;
926833Sgd78059 
936833Sgd78059 	/*
946833Sgd78059 	 * MAC Control event stats
956833Sgd78059 	 */
966833Sgd78059 	uint32_t	pause_rxcount;	/* PAUSE Receive cnt */
976833Sgd78059 	uint32_t	pause_oncount;
986833Sgd78059 	uint32_t	pause_offcount;
996833Sgd78059 	uint32_t	pause_time_count;
1006833Sgd78059 	uint32_t	pausing;
1016833Sgd78059 
1026833Sgd78059 	/*
1036833Sgd78059 	 * Software event stats
1046833Sgd78059 	 */
1056833Sgd78059 	uint32_t	inits;
1066833Sgd78059 	uint32_t	rx_inits;
1076833Sgd78059 	uint32_t	tx_inits;
1086833Sgd78059 	uint32_t	tnocar;	/* Link down counter */
1096833Sgd78059 
1106833Sgd78059 	uint32_t	jab;
1116833Sgd78059 	uint32_t	notmds;
1126833Sgd78059 	uint32_t	nocanput;
1136833Sgd78059 	uint32_t	allocbfail;
1146833Sgd78059 	uint32_t	drop;
1156833Sgd78059 	uint32_t	rx_corrupted;
1166833Sgd78059 	uint32_t	rx_bad_pkts;
1176833Sgd78059 	uint32_t	rx_runt;
1186833Sgd78059 	uint32_t	rx_toolong_pkts;
1196833Sgd78059 
1206833Sgd78059 
1216833Sgd78059 	/*
1226833Sgd78059 	 * Fatal errors
1236833Sgd78059 	 */
1246833Sgd78059 	uint32_t	rxtag_err;
1256833Sgd78059 
1266833Sgd78059 	/*
1276833Sgd78059 	 * parity error
1286833Sgd78059 	 */
1296833Sgd78059 	uint32_t	parity_error;
1306833Sgd78059 
1316833Sgd78059 	/*
1326833Sgd78059 	 * Fatal error stats
1336833Sgd78059 	 */
1346833Sgd78059 	uint32_t	pci_error_int;	/* PCI error interrupt */
1356833Sgd78059 	uint32_t	unknown_fatal;	/* unknown fatal errors */
1366833Sgd78059 
1376833Sgd78059 	/*
1386833Sgd78059 	 * PCI Configuration space staus register
1396833Sgd78059 	 */
1406833Sgd78059 	uint32_t	pci_data_parity_err;	/* Data parity err */
1416833Sgd78059 	uint32_t	pci_signal_target_abort;
1426833Sgd78059 	uint32_t	pci_rcvd_target_abort;
1436833Sgd78059 	uint32_t	pci_rcvd_master_abort;
1446833Sgd78059 	uint32_t	pci_signal_system_err;
1456833Sgd78059 	uint32_t	pci_det_parity_err;
1466833Sgd78059 
1476833Sgd78059 	/*
1486833Sgd78059 	 * MIB II variables
1496833Sgd78059 	 */
1506833Sgd78059 	uint64_t	rbytes64;	/* # bytes received */
1516833Sgd78059 	uint64_t	obytes64;	/* # bytes transmitted */
1526833Sgd78059 	uint32_t	multircv;	/* # multicast packets received */
1536833Sgd78059 	uint32_t	multixmt;	/* # multicast packets for xmit */
1546833Sgd78059 	uint32_t	brdcstrcv;	/* # broadcast packets received */
1556833Sgd78059 	uint32_t	brdcstxmt;	/* # broadcast packets for xmit */
1566833Sgd78059 	uint32_t	norcvbuf;	/* # rcv packets discarded */
1576833Sgd78059 	uint32_t	noxmtbuf;	/* # xmit packets discarded */
1586833Sgd78059 
1596833Sgd78059 	uint32_t	pmcap;		/* power management */
1606833Sgd78059 
1616833Sgd78059 	/*
1626833Sgd78059 	 * Link Status
1636833Sgd78059 	 */
1646833Sgd78059 	uint32_t	link_up;
1656833Sgd78059 	uint32_t	link_duplex;
1666833Sgd78059 } stats_t;
1676833Sgd78059 
1686833Sgd78059 #define	HSTAT(erip, x)		erip->stats.x++;
1696833Sgd78059 #define	HSTATN(erip, x, n)	erip->stats.x += n;
1706833Sgd78059 
1716833Sgd78059 
1726833Sgd78059 #define	RX_BCOPY_MAX		704	/* bcopy for packets < 704 bytes */
1736833Sgd78059 
1746833Sgd78059 /*
1756833Sgd78059  * Per-Stream instance state information.
1766833Sgd78059  *
1776833Sgd78059  * Each instance is dynamically allocated at open() and free'd
1786833Sgd78059  * at close().  Each per-Stream instance points to at most one
1796833Sgd78059  * per-device structure using the sb_erip field.  All instances
1806833Sgd78059  * are threaded together into one list of active instances
1816833Sgd78059  * ordered on minor device number.
1826833Sgd78059  */
1836833Sgd78059 
1846833Sgd78059 #define	NMCFILTER_BITS	256		/* # of multicast filter bits */
1856833Sgd78059 
1866833Sgd78059 
1876833Sgd78059 /*
1886833Sgd78059  * Maximum number of receive descriptors posted to the chip.
1896833Sgd78059  */
1906833Sgd78059 #define	ERI_RPENDING		(erip->rpending)
1916833Sgd78059 
1926833Sgd78059 /*
1936833Sgd78059  * Maximum number of transmit descriptors for lazy reclaim.
1946833Sgd78059  */
1956833Sgd78059 #define	ERI_TPENDING	(erip->tpending)
1966833Sgd78059 
1976833Sgd78059 /*
1986833Sgd78059  * Return the address of an adjacent descriptor in the given ring.
1996833Sgd78059  */
2006833Sgd78059 #define	NEXTRMD(erip, rmdp)	(((rmdp) + 1) == (erip)->rmdlimp ?	\
2016833Sgd78059 	(erip)->rmdp : ((rmdp) + 1))
2026833Sgd78059 #define	NEXTTMD(erip, tmdp)	(((tmdp) + 1) == (erip)->eri_tmdlimp ?	\
2036833Sgd78059 	(erip)->eri_tmdp : ((tmdp) + 1))
2046833Sgd78059 #define	PREVTMD(erip, tmdp)	((tmdp) == (erip)->eri_tmdp ?		\
2056833Sgd78059 	((erip)->eri_tmdlimp - 1) : ((tmdp) - 1))
2066833Sgd78059 
2076833Sgd78059 #define	MSECOND(t)	t
2086833Sgd78059 #define	SECOND(t)	t*1000
2096833Sgd78059 #define	ERI_TICKS	MSECOND(100)
2106833Sgd78059 
2116833Sgd78059 #define	ERI_NTRIES_LOW		(SECOND(5)/ERI_TICKS)   /* 5 Seconds */
2126833Sgd78059 #define	ERI_NTRIES_HIGH		(SECOND(5)/ERI_TICKS)   /* 5 Seconds */
2136833Sgd78059 #define	ERI_NTRIES_LOW_10	(SECOND(2)/ERI_TICKS)   /* 2 Seconds */
2146833Sgd78059 #define	ERI_LINKDOWN_TIME	(SECOND(2)/ERI_TICKS)   /* 2 Seconds */
2156833Sgd78059 
2166833Sgd78059 
2176833Sgd78059 /*
2186833Sgd78059  * ERI ASIC Revision Numbers
2196833Sgd78059  */
2206833Sgd78059 #define	ERI_ERIREV_1_0	0x1
2216833Sgd78059 
2226833Sgd78059 /*
2236833Sgd78059  * Link poll interval for detecting change of transceivers
2246833Sgd78059  */
2256833Sgd78059 #define	ERI_LINKCHECK_TIMER	SECOND(3)
2266833Sgd78059 
2276833Sgd78059 /*
2286833Sgd78059  * Parallel detection Fault restart timer
2296833Sgd78059  */
2306833Sgd78059 #define	ERI_P_FAULT_TIMER	SECOND(3)
2316833Sgd78059 
2326833Sgd78059 /*
2336833Sgd78059  * Check rmac hang restart timer
2346833Sgd78059  */
2356833Sgd78059 #define	ERI_CHECK_HANG_TIMER	MSECOND(400)
2366833Sgd78059 #define	ERI_RMAC_HANG_WORKAROUND
2376833Sgd78059 
2386833Sgd78059 /*
2396833Sgd78059  * undefine ERI_PM_WORKAROUND this time. With ERI_PM_WORKAROUND defined,
2406833Sgd78059  * each non_fatal error causes pci clock to go up for 30 seconds. Therefore,
2416833Sgd78059  * no TXMAC_UNDERRUN or excessive RXFIFO_OVERFLOW should happen.
2426833Sgd78059  */
2436833Sgd78059 
2446833Sgd78059 
2456833Sgd78059 /*
2466833Sgd78059  * Link bringup modes
2476833Sgd78059  */
2486833Sgd78059 #define	ERI_AUTO_BRINGUP	0
2496833Sgd78059 #define	ERI_FORCED_BRINGUP	1
2506833Sgd78059 
2516833Sgd78059 /*
2526833Sgd78059  * Transceivers selected for use by the driver.
2536833Sgd78059  */
2546833Sgd78059 #define	NO_XCVR		2
2556833Sgd78059 #define	INTERNAL_XCVR	0
2566833Sgd78059 #define	EXTERNAL_XCVR	1
2576833Sgd78059 
2586833Sgd78059 /*
2596833Sgd78059  * states for manually creating the link down condition
2606833Sgd78059  */
2616833Sgd78059 #define	ERI_LINKDOWN_OK		0
2626833Sgd78059 #define	ERI_FORCE_LINKDOWN	1
2636833Sgd78059 #define	ERI_LINKDOWN_STARTED	2
2646833Sgd78059 #define	ERI_LINKDOWN_DONE	3
2656833Sgd78059 
2666833Sgd78059 /*
2676833Sgd78059  * states for bringing up the link in auto-negotiation mode
2686833Sgd78059  */
2696833Sgd78059 #define	ERI_HWAN_TRY		0 /* Try Hardware autonegotiation */
2706833Sgd78059 #define	ERI_HWAN_INPROGRESS	1 /* Hardware autonegotiation in progress */
2716833Sgd78059 #define	ERI_HWAN_SUCCESFUL	2 /* Hardware autonegotiation succesful */
2726833Sgd78059 #define	ERI_HWAN_FAILED		3 /* Hardware autonegotiation failed */
2736833Sgd78059 
2746833Sgd78059 /*
2756833Sgd78059  * states for resetting the transceiver
2766833Sgd78059  */
2776833Sgd78059 #define	RESET_TO_BE_ISSUED	0 /* Reset command to be issued to the PHY */
2786833Sgd78059 #define	RESET_ISSUED		1 /* Reset command has been issued */
2796833Sgd78059 #define	ISOLATE_ISSUED		2 /* Isolate-remove command has been issued */
2806833Sgd78059 
2816833Sgd78059 /*
2826833Sgd78059  * ERI Supported PHY devices
2836833Sgd78059  * ERI ASIC supports a built in Gigabit Serial LInk Interface and MII
2846833Sgd78059  * External SERDES interfaces with shared pins.
2856833Sgd78059  * On some product implementations, the built-in Serial Link may not be present
2866833Sgd78059  * either because the Serial Link circuitry does not work or because the product
2876833Sgd78059  * needs to use only the MII interface.
2886833Sgd78059  * When both the Serial Link and MII PHY's are present, the driver normally
2896833Sgd78059  * tries to bring up both the links. If both of them come up, it will select the
2906833Sgd78059  * link defined by the "eri_default_link" variable by default.
2916833Sgd78059  * The user may use the configuration variable
2926833Sgd78059  * eri_select_link to manually select
2936833Sgd78059  * either the Serial Link or the MII PHY to be used.
2946833Sgd78059  */
2956833Sgd78059 
2966833Sgd78059 /*
2976833Sgd78059  * Values for the eri_serial_link field
2986833Sgd78059  */
2996833Sgd78059 #define	ERI_SERIAL_LINK_NOT_PRESENT	0
3006833Sgd78059 #define	ERI_SERIAL_LINK_PRESENT		1
3016833Sgd78059 
3026833Sgd78059 /*
3036833Sgd78059  * Values for the eri_non-serial-link field
3046833Sgd78059  */
3056833Sgd78059 #define	ERI_NO_SHARED_PIN_PHY		0
3066833Sgd78059 #define	ERI_MII_PRESENT			1
3076833Sgd78059 #define	ERI_SERDES_PRESENT		2
3086833Sgd78059 
3096833Sgd78059 /*
3106833Sgd78059  * Values for the default selection when both the serial link and
3116833Sgd78059  * the MII links are present.
3126833Sgd78059  */
3136833Sgd78059 #define	ERI_DEFAULT_SERIAL_LINK	0
3146833Sgd78059 #define	ERI_DEFAULT_MII_LINK	1
3156833Sgd78059 
3166833Sgd78059 /*
3176833Sgd78059  * Values for the eri_select_link field to manually select the PHY
3186833Sgd78059  */
3196833Sgd78059 #define	ERI_AUTO_PHY			0	/* Select PHY automatically */
3206833Sgd78059 #define	ERI_USE_SERIAL_LINK		1	/* Select serial-link */
3216833Sgd78059 #define	ERI_USE_NON_SERIAL_LINK		2	/* Select non-serial-link */
3226833Sgd78059 
3236833Sgd78059 /*
3246833Sgd78059  * eri_linkup_state" definitions
3256833Sgd78059  */
3266833Sgd78059 #define	ERI_START_LINK_BRINGUP	0
3276833Sgd78059 #define	ERI_SERIAL_LINK_BRINGUP	1
3286833Sgd78059 #define	ERI_SERDES_LINK_BRINGUP	2
3296833Sgd78059 #define	ERI_MII_LINK_BRINGUP	3
3306833Sgd78059 #define	ERI_DEFAULT_LINK_BRINGUP	4
3316833Sgd78059 #define	ERI_ALT_LINK_BRINGUP	5
3326833Sgd78059 
3336833Sgd78059 /*
3346833Sgd78059  * structure used to detect tx hang condition
3356833Sgd78059  */
3366833Sgd78059 struct	erisave {
3376833Sgd78059 	ulong_t	starts;		  /* # of tx packets posted to the hw */
3386833Sgd78059 	uint64_t reclaim_opackets; /* # of tx packets reclaimed */
3396833Sgd78059 };
3406833Sgd78059 
3416833Sgd78059 /*
3426833Sgd78059  * ERI Device Channel instance state information.
3436833Sgd78059  *
3446833Sgd78059  * Each instance is dynamically allocated on first attach.
3456833Sgd78059  */
3466833Sgd78059 struct	eri {
3476833Sgd78059 	mac_handle_t		mh;		/* GLDv3 handle */
3486833Sgd78059 	dev_info_t		*dip;		/* associated dev_info */
3496833Sgd78059 	uint_t			instance;	/* instance */
3506833Sgd78059 
3516833Sgd78059 	int			pci_mode;	/* sbus/pci device (future) */
3526833Sgd78059 	int			cpci_mode;	/* compact pci dev (future) */
3536833Sgd78059 	int			low_power_mode; /* E* (low power) */
3546833Sgd78059 	int			asic_rev;	/* ERI ASIC rev no. */
3556833Sgd78059 	int			board_rev;	/* ERI ASIC rev no. */
3566833Sgd78059 	int			burstsizes;	/* binary encoded val */
3576833Sgd78059 	int			pagesize;	/* btop(9f) */
3586833Sgd78059 	uint32_t		rxfifo_size;	/* RX FIFO size */
3596833Sgd78059 
3606833Sgd78059 	int			rpending;	/* Max.no. of RX bufs post */
3616833Sgd78059 	int			tpending;	/* Max.no. of tX bufs post */
3626833Sgd78059 	int			tx_cur_cnt;	/* # of packets for int_me */
3636833Sgd78059 
3646833Sgd78059 	uint_t			multi_refcnt;
3656833Sgd78059 	boolean_t		promisc;
3666833Sgd78059 
3676833Sgd78059 	int			mifpoll_enable;
3686833Sgd78059 	int			frame_enable;
3696833Sgd78059 	int			lance_mode_enable;
3706833Sgd78059 	int			ngu_enable;
3716833Sgd78059 	int			link_pulse_disabled;
3726833Sgd78059 	int			xmit_dma_mode;
3736833Sgd78059 	int			rcv_dma_mode;
3746833Sgd78059 	uint8_t			ouraddr[ETHERADDRL];	/* unicast address */
3756833Sgd78059 	uint32_t		flags;		/* misc. flags */
3766833Sgd78059 	uint32_t		alloc_flag;	/* Buff alloc. status flags */
3776833Sgd78059 	boolean_t		wantw;		/* xmit: out of resources */
3786833Sgd78059 
3796833Sgd78059 	uint16_t		ladrf[NMCFILTER_BITS/16]; /* Multicast filter */
3806833Sgd78059 	uint16_t		ladrf_refcnt[NMCFILTER_BITS];
3816833Sgd78059 
3826833Sgd78059 	volatile struct	global	*globregp;	/* ERI global regs */
3836833Sgd78059 	volatile struct	etx	*etxregp;	/* ERI ETX regs */
3846833Sgd78059 	volatile struct	erx	*erxregp;	/* ERI ERX regs */
3856833Sgd78059 
3866833Sgd78059 	volatile struct	bmac	*bmacregp;	/* MAC regs */
3876833Sgd78059 	volatile struct	mif	*mifregp;	/* ERI transceiver */
3886833Sgd78059 	volatile struct	pcslink	*pcsregp;	/* ERI PCS regs */
3896833Sgd78059 
3906833Sgd78059 	uint32_t		*sw_reset_reg;
3916833Sgd78059 
3926833Sgd78059 	uint32_t		rx_kick;	/* RX kick register val */
3936833Sgd78059 	uint32_t		rx_completion;	/* RX completion reg val */
3946833Sgd78059 #ifdef	RCV_OVRFLOW_CORRUPTION_BUG
3956833Sgd78059 	uint32_t		rx_ovrflpks;	/* RX recompute checksum */
3966833Sgd78059 #endif
3976833Sgd78059 	uint32_t		tx_kick;	/* TX kick register val */
3986833Sgd78059 	uint32_t		tx_completion;	/* TX completion reg val */
3996833Sgd78059 
4006833Sgd78059 	struct	rmd		*rmdp;		/* rcv descript  ring start */
4016833Sgd78059 	struct	rmd		*rmdlimp;	/* rcv  descript ring end */
4026833Sgd78059 	struct	eri_tmd		*eri_tmdp;	/* xmit descript ring start */
4036833Sgd78059 	struct	eri_tmd		*eri_tmdlimp;	/* xmit descript ring end */
4046833Sgd78059 	volatile struct	rmd	*rnextp;	/* next chip rmd */
4056833Sgd78059 	volatile struct	rmd	*rlastp;	/* last free rmd */
4066833Sgd78059 	volatile struct	eri_tmd	*tnextp;	/* next free tmd */
4076833Sgd78059 
4086833Sgd78059 	volatile struct	eri_tmd	*tcurp;	/* nxt tmd to reclaim(used) */
4096833Sgd78059 	/*
4106833Sgd78059 	 * these are handles for the dvma resources reserved
4116833Sgd78059 	 * by dvma_reserve
4126833Sgd78059 	 */
4136833Sgd78059 	ddi_dma_handle_t	eri_dvmarh;	/* dvma recv handle */
4146833Sgd78059 
4156833Sgd78059 	/*
4166833Sgd78059 	 * these are used if dvma reserve fails, and we have to fall
4176833Sgd78059 	 * back on the older ddi_dma_addr_setup routines
4186833Sgd78059 	 */
4196833Sgd78059 	ddi_dma_handle_t	ndmarh[ERI_RMDMAX];
4206833Sgd78059 
4216833Sgd78059 	ddi_dma_handle_t	tbuf_handle;
422*7394Sgdamore@opensolaris.org 	ddi_acc_handle_t	tbuf_acch;
4236833Sgd78059 	caddr_t			tbuf_kaddr;
4246833Sgd78059 	uint32_t		tbuf_ioaddr;
4256833Sgd78059 
4266833Sgd78059 	int			rcv_handle_cnt;
4276833Sgd78059 
4286833Sgd78059 	int			rx_reset_issued;
4296833Sgd78059 	int			tx_reset_issued;
4306833Sgd78059 	int			rxmac_reset_issued;
4316833Sgd78059 	int			txmac_reset_issued;
4326833Sgd78059 
4336833Sgd78059 	int			global_reset_issued;
4346833Sgd78059 	uint32_t		rpending_mask;
4356833Sgd78059 	int			rmdmax_mask;
4366833Sgd78059 	int			init_macregs;
4376833Sgd78059 
4386833Sgd78059 	int			phyad;	/* addr of the PHY in use */
4396833Sgd78059 	int			xcvr;  /* current PHY in use */
4406833Sgd78059 
4416833Sgd78059 	int			openloop_autoneg;
4426833Sgd78059 
4436833Sgd78059 	uint16_t		mif_config;
4446833Sgd78059 	uint16_t		mif_mask;
4456833Sgd78059 
4466833Sgd78059 	uint32_t		tx_config;
4476833Sgd78059 
4486833Sgd78059 	uint32_t		vendor_id;	/* Vendor ID	*/
4496833Sgd78059 	uint16_t		device_id;	/* Device Model	*/
4506833Sgd78059 	uint16_t		device_rev;	/* Device Rev.	*/
4516833Sgd78059 	uint32_t		phy_address;	/* PHY Address	*/
4526833Sgd78059 	uint32_t		xcvr_status;	/* xcvr_status	*/
4536833Sgd78059 	uint32_t		xcvr_state;	/* xcvr_state	*/
4546833Sgd78059 	uint32_t		bringup_mode;	/* Bringup Mode	*/
4556833Sgd78059 	uint32_t		speed;		/* Current speed */
4566833Sgd78059 	uint32_t		duplex;		/* Xcvr Duplex	*/
4576833Sgd78059 	uint32_t		capability;	/* Xcvr Capability */
4586833Sgd78059 
4596833Sgd78059 	uint16_t		mii_control;
4606833Sgd78059 	uint16_t		mii_status;
4616833Sgd78059 	uint16_t		mii_anar;
4626833Sgd78059 	uint16_t		mii_lpanar;
4636833Sgd78059 
4646833Sgd78059 	int			autoneg;
4656833Sgd78059 	int			force_linkdown;
4666833Sgd78059 	int			mode;
4676833Sgd78059 
4686833Sgd78059 	int			linkup_10;
4696833Sgd78059 	int			pace_count;	/* pacing pkt count */
4706833Sgd78059 
4716833Sgd78059 	int			nlasttries;
4726833Sgd78059 	int			ntries;
4736833Sgd78059 	int			delay;
4746833Sgd78059 	int			linkup_attempts;
4756833Sgd78059 
4766833Sgd78059 	int			polling_on;
4776833Sgd78059 	int			mifpoll_data;
4786833Sgd78059 	int			mifpoll_flag; /* indicates MIF intr */
4796833Sgd78059 
4806833Sgd78059 	int			pauseTX;	/* pcs link-pause TX enable */
4816833Sgd78059 	int			pauseRX;	/* pcs link-pause RX enable */
4826833Sgd78059 	int			macfdx;	/* mac full-duplex mode */
4836833Sgd78059 	timeout_id_t		timerid;	/* timer id for links */
4846833Sgd78059 	int			linkup_cnt;
4856833Sgd78059 
4866833Sgd78059 	uint16_t		aner;	/* MII ANER register */
4876833Sgd78059 
4886833Sgd78059 	int			linkup;		/* selected link status */
4896833Sgd78059 	int			linkup_state; /* link bringup state */
4906833Sgd78059 	int			linkup_changed; /* link bringup state */
4916833Sgd78059 
4926833Sgd78059 	int			linkcheck;
4936833Sgd78059 	caddr_t			g_nd;	/* head of the */
4946833Sgd78059 						/* named dispatch table */
4956833Sgd78059 
4966833Sgd78059 	ddi_device_acc_attr_t	dev_attr;
4976833Sgd78059 	ddi_iblock_cookie_t	cookie;	/* interrupt cookie */
4986833Sgd78059 	ddi_acc_handle_t	globregh;   /* ERI global regs */
4996833Sgd78059 	ddi_acc_handle_t	etxregh;    /* ERI ETX regs */
5006833Sgd78059 	ddi_acc_handle_t	erxregh;    /* ERI ERX regs */
5016833Sgd78059 	ddi_acc_handle_t	bmacregh;   /* BigMAC registers */
5026833Sgd78059 	ddi_acc_handle_t	mifregh;    /* ERI transceiver */
5036833Sgd78059 	ddi_acc_handle_t	pcsregh;    /* ERI PCS regs */
5046833Sgd78059 
5056833Sgd78059 	ddi_acc_handle_t	sw_reset_regh;	/* ERI Reset Reg */
5066833Sgd78059 
5076833Sgd78059 	ddi_dma_cookie_t	md_c;	/* trmd dma cookie */
5086833Sgd78059 	ddi_acc_handle_t	mdm_h;	/* trmd memory handle */
5096833Sgd78059 	ddi_dma_handle_t	md_h;	/* trmdp dma handle */
5106833Sgd78059 
5116833Sgd78059 	ddi_acc_handle_t	pci_config_handle; /* ERI PCI config */
5126833Sgd78059 
5136833Sgd78059 	/*
5146833Sgd78059 	 * DDI dma handle, kernel virtual base,
5156833Sgd78059 	 * and io virtual base of IOPB area.
5166833Sgd78059 	 */
5176833Sgd78059 	ddi_dma_handle_t	iopbhandle;
5186833Sgd78059 	uintptr_t		iopbkbase;
5196833Sgd78059 	uintptr_t		iopbiobase;
5206833Sgd78059 	kstat_t			*ksp;		/* kstat pointer */
5216833Sgd78059 
5226833Sgd78059 	kmutex_t		xmitlock;	/* protect xmit-side fields */
5236833Sgd78059 	kmutex_t		xcvrlock;	/* */
5246833Sgd78059 	kmutex_t		intrlock;	/* protect intr-side fields */
5256833Sgd78059 	kmutex_t		linklock;	/* protect link-side fields */
5266833Sgd78059 
5276833Sgd78059 	mblk_t		*tmblkp[ERI_TMDMAX]; /* mblks assoc with TMD */
5286833Sgd78059 	mblk_t		*rmblkp[ERI_RMDMAX]; /* mblks assoc with RMD */
5296833Sgd78059 	param_t		param_arr[ERI_PARAM_CNT];
5306833Sgd78059 
5316833Sgd78059 	struct	stats stats;	/* kstats */
5326833Sgd78059 
5336833Sgd78059 	/*
5346833Sgd78059 	 * Check if transmitter is hung
5356833Sgd78059 	 */
5366833Sgd78059 	uint32_t	starts;
5376833Sgd78059 	uint32_t	txhung;
5386833Sgd78059 	struct		erisave erisave;
5396833Sgd78059 
5406833Sgd78059 	uint64_t	ifspeed_old;
5416833Sgd78059 
5426833Sgd78059 #ifdef ERI_RMAC_HANG_WORKAROUND
5436833Sgd78059 	uint32_t	check_rmac_hang;
5446833Sgd78059 	uint32_t	check2_rmac_hang;
5456833Sgd78059 	uint32_t	rxfifo_wr_ptr;
5466833Sgd78059 	uint32_t	rxfifo_rd_ptr;
5476833Sgd78059 	uint32_t	rxfifo_wr_ptr_c;
5486833Sgd78059 	uint32_t	rxfifo_rd_ptr_c;
5496833Sgd78059 #endif
5506833Sgd78059 	uint32_t	tx_int_me;
5516833Sgd78059 };
5526833Sgd78059 
5536833Sgd78059 /*
5546833Sgd78059  * LADRF bit array manipulation macros.  These are for working within the
5556833Sgd78059  * array of words defined by erip->ladrf, converting a bit (0-255) into
5566833Sgd78059  * the index and offset in the ladrf bit array.  Note that the array is
5576833Sgd78059  * provided in "Big Endian" order.
5586833Sgd78059  */
5596833Sgd78059 #define	LADRF_MASK(bit)		(1 << ((bit) % 16))
5606833Sgd78059 #define	LADRF_WORD(erip, bit)	erip->ladrf[(15 - ((bit) / 16))]
5616833Sgd78059 #define	LADRF_SET(erip, bit)	(LADRF_WORD(erip, bit) |= LADRF_MASK(bit))
5626833Sgd78059 #define	LADRF_CLR(erip, bit)	(LADRF_WORD(erip, bit) &= ~LADRF_MASK(bit))
5636833Sgd78059 
5646833Sgd78059 /*
5656833Sgd78059  * ERI IOCTLS.
5666833Sgd78059  * Change : TODO : MBE
5676833Sgd78059  */
5686833Sgd78059 #define	ERIIOC		('G' << 8)
5696833Sgd78059 #define	ERI_SET_LOOP_MODE	(ERIIOC|1)	/* Set Rio Loopback mode */
5706833Sgd78059 #define	ERI_GET_LOOP_MODE	(ERIIOC|2)	/* Get Rio Loopback modes */
5716833Sgd78059 #define	ERI_GET_LOOP_IFCNT	(ERIIOC|4)	/* Get Rio IF Count */
5726833Sgd78059 
5736833Sgd78059 /*
5746833Sgd78059  * Loopback modes: For diagnostic testing purposes the ERI card
5756833Sgd78059  * can be placed in loopback mode.
5766833Sgd78059  * There are three modes of loopback provided by the driver,
5776833Sgd78059  * Mac loopback, PCS loopback and Serdes loopback.
5786833Sgd78059  */
5796833Sgd78059 #define	ERI_LOOPBACK_OFF		0
5806833Sgd78059 #define	ERI_MAC_LOOPBACK_ON		1
5816833Sgd78059 #define	ERI_PCS_LOOPBACK_ON 		2
5826833Sgd78059 #define	ERI_SER_LOOPBACK_ON 		4
5836833Sgd78059 typedef struct {
5846833Sgd78059 	int loopback;
5856833Sgd78059 } loopback_t;
5866833Sgd78059 
5876833Sgd78059 
5886833Sgd78059 /*
5896833Sgd78059  * flags
5906833Sgd78059  * TODO : MBE
5916833Sgd78059  */
5926833Sgd78059 #define	ERI_UNKOWN	0x00	/* unknown state	*/
5936833Sgd78059 #define	ERI_RUNNING	0x01	/* chip is initialized	*/
5946833Sgd78059 #define	ERI_STARTED	0x02	/* mac layer started */
5956833Sgd78059 #define	ERI_SUSPENDED	0x08	/* suspended interface	*/
5966833Sgd78059 #define	ERI_INITIALIZED	0x10	/* interface initialized */
5976833Sgd78059 #define	ERI_NOTIMEOUTS	0x20	/* disallow timeout rescheduling */
5986833Sgd78059 #define	ERI_TXINIT	0x40	/* TX Portion Init'ed	*/
5996833Sgd78059 #define	ERI_RXINIT	0x80	/* RX Portion Init'ed	*/
6006833Sgd78059 #define	ERI_MACLOOPBACK	0x100	/* device has MAC int lpbk (DIAG) */
6016833Sgd78059 #define	ERI_SERLOOPBACK	0x200	/* device has SERDES int lpbk (DIAG) */
6026833Sgd78059 #define	ERI_DLPI_LINKUP	0x400	/* */
6036833Sgd78059 
6046833Sgd78059 /*
6056833Sgd78059  * Mac address flags
6066833Sgd78059  */
6076833Sgd78059 #define	ERI_FACTADDR_PRESENT	0x01	/* factory MAC id present */
6086833Sgd78059 #define	ERI_FACTADDR_USE	0x02	/* use factory MAC id */
6096833Sgd78059 
6106833Sgd78059 struct erikstat {
6116833Sgd78059 	/*
6126833Sgd78059 	 * Software event stats
6136833Sgd78059 	 */
6146833Sgd78059 	struct kstat_named	erik_inits;
6156833Sgd78059 	struct kstat_named	erik_rx_inits;
6166833Sgd78059 	struct kstat_named	erik_tx_inits;
6176833Sgd78059 
6186833Sgd78059 	struct kstat_named	erik_allocbfail;
6196833Sgd78059 	struct kstat_named	erik_drop;
6206833Sgd78059 
6216833Sgd78059 	/*
6226833Sgd78059 	 * MAC Control event stats
6236833Sgd78059 	 */
6246833Sgd78059 	struct kstat_named	erik_pause_rxcount; /* PAUSE Receive count */
6256833Sgd78059 	struct kstat_named	erik_pause_oncount;
6266833Sgd78059 	struct kstat_named	erik_pause_offcount;
6276833Sgd78059 	struct kstat_named	erik_pause_time_count;
6286833Sgd78059 
6296833Sgd78059 	/*
6306833Sgd78059 	 * MAC TX Event stats
6316833Sgd78059 	 */
6326833Sgd78059 	struct kstat_named	erik_txmac_maxpkt_err;
6336833Sgd78059 	struct kstat_named	erik_defer_timer_exp;
6346833Sgd78059 	struct kstat_named	erik_peak_attempt_cnt;
6356833Sgd78059 	struct kstat_named	erik_jab;
6366833Sgd78059 	struct kstat_named	erik_notmds;
6376833Sgd78059 	struct kstat_named	erik_tx_hang;
6386833Sgd78059 
6396833Sgd78059 	/*
6406833Sgd78059 	 * MAC RX Event stats
6416833Sgd78059 	 */
6426833Sgd78059 	struct kstat_named	erik_no_free_rx_desc; /* no free rx desc. */
6436833Sgd78059 	struct kstat_named	erik_rx_hang;
6446833Sgd78059 	struct kstat_named	erik_rx_length_err;
6456833Sgd78059 	struct kstat_named	erik_rx_code_viol_err;
6466833Sgd78059 	struct kstat_named	erik_rx_bad_pkts;
6476833Sgd78059 
6486833Sgd78059 	/*
6496833Sgd78059 	 * Fatal errors
6506833Sgd78059 	 */
6516833Sgd78059 	struct kstat_named	erik_rxtag_err;
6526833Sgd78059 
6536833Sgd78059 	/*
6546833Sgd78059 	 * Parity error
6556833Sgd78059 	 */
6566833Sgd78059 	struct kstat_named	erik_parity_error;
6576833Sgd78059 
6586833Sgd78059 	/*
6596833Sgd78059 	 * PCI fatal error stats
6606833Sgd78059 	 */
6616833Sgd78059 	struct kstat_named	erik_pci_error_int;  /* PCI error interrupt */
6626833Sgd78059 	struct kstat_named	erik_unknown_fatal;	/* unknow fatal error */
6636833Sgd78059 
6646833Sgd78059 	/*
6656833Sgd78059 	 * PCI Configuration space staus register
6666833Sgd78059 	 */
6676833Sgd78059 	struct kstat_named	erik_pci_data_parity_err; /* dparity err */
6686833Sgd78059 	struct kstat_named	erik_pci_signal_target_abort;
6696833Sgd78059 	struct kstat_named	erik_pci_rcvd_target_abort;
6706833Sgd78059 	struct kstat_named	erik_pci_rcvd_master_abort;
6716833Sgd78059 	struct kstat_named	erik_pci_signal_system_err;
6726833Sgd78059 	struct kstat_named	erik_pci_det_parity_err;
6736833Sgd78059 
6746833Sgd78059 
6756833Sgd78059 	struct kstat_named	erik_pmcap;	/* Power management */
6766833Sgd78059 };
6776833Sgd78059 
6786833Sgd78059 /* TBD: new value ? */
6796833Sgd78059 #define	ERI_DRAINTIME	(400000)	/* # microseconds xmit drain */
6806833Sgd78059 
6816833Sgd78059 #define	ROUNDUP(a, n)	(((a) + ((n) - 1)) & ~((n) - 1))
6826833Sgd78059 #define	ROUNDUP2(a, n)	(uchar_t *)((((uintptr_t)(a)) + ((n) - 1)) & ~((n) - 1))
6836833Sgd78059 
6846833Sgd78059 /*
6856833Sgd78059  * Xmit/receive buffer structure.
6866833Sgd78059  * This structure is organized to meet the following requirements:
6876833Sgd78059  * - hb_buf starts on an ERI_BURSTSIZE boundary.
6886833Sgd78059  * - eribuf is an even multiple of ERI_BURSTSIZE
6896833Sgd78059  * - hb_buf[] is large enough to contain max frame (1518) plus
6906833Sgd78059  *   (3 x ERI_BURSTSIZE) rounded up to the next ERI_BURSTSIZE
6916833Sgd78059  */
6926833Sgd78059 /*
6936833Sgd78059  * #define		ERI_BURSTSIZE	(64)
6946833Sgd78059  */
6956833Sgd78059 #define		ERI_BURSTSIZE	(128)
6966833Sgd78059 #define		ERI_BURSTMASK	(ERIBURSTSIZE - 1)
6976833Sgd78059 #define		ERI_BUFSIZE	(1728)	/* (ETHERMTU + 228) */
6986833Sgd78059 #define		ERI_HEADROOM	(34)
6996833Sgd78059 
7006833Sgd78059 /* Offset for the first byte in the receive buffer */
7016833Sgd78059 #define	ERI_FSTBYTE_OFFSET	2
7026833Sgd78059 #define	ERI_CKSUM_OFFSET	14
7036833Sgd78059 
7046833Sgd78059 
7056833Sgd78059 #define	ERI_PMCAP_NONE	0
7066833Sgd78059 #define	ERI_PMCAP_4MHZ	4
7076833Sgd78059 
7086833Sgd78059 #endif	/* _KERNEL */
7096833Sgd78059 
7106833Sgd78059 #ifdef	__cplusplus
7116833Sgd78059 }
7126833Sgd78059 #endif
7136833Sgd78059 
7146833Sgd78059 #endif	/* _SYS_ERI_H */
715