xref: /openbsd/sys/dev/pci/if_tlreg.h (revision cdd8442e)
1*cdd8442eSbrad /*	$OpenBSD: if_tlreg.h,v 1.10 2014/01/31 06:05:40 brad Exp $	*/
20c480523Sjason 
370c52ebfSjason /*
470c52ebfSjason  * Copyright (c) 1997, 1998
570c52ebfSjason  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
670c52ebfSjason  *
770c52ebfSjason  * Redistribution and use in source and binary forms, with or without
870c52ebfSjason  * modification, are permitted provided that the following conditions
970c52ebfSjason  * are met:
1070c52ebfSjason  * 1. Redistributions of source code must retain the above copyright
1170c52ebfSjason  *    notice, this list of conditions and the following disclaimer.
1270c52ebfSjason  * 2. Redistributions in binary form must reproduce the above copyright
1370c52ebfSjason  *    notice, this list of conditions and the following disclaimer in the
1470c52ebfSjason  *    documentation and/or other materials provided with the distribution.
1570c52ebfSjason  * 3. All advertising materials mentioning features or use of this software
1670c52ebfSjason  *    must display the following acknowledgement:
1770c52ebfSjason  *	This product includes software developed by Bill Paul.
1870c52ebfSjason  * 4. Neither the name of the author nor the names of any co-contributors
1970c52ebfSjason  *    may be used to endorse or promote products derived from this software
2070c52ebfSjason  *    without specific prior written permission.
2170c52ebfSjason  *
2270c52ebfSjason  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2370c52ebfSjason  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2470c52ebfSjason  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2570c52ebfSjason  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
2670c52ebfSjason  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2770c52ebfSjason  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2870c52ebfSjason  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2970c52ebfSjason  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3070c52ebfSjason  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3170c52ebfSjason  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3270c52ebfSjason  * THE POSSIBILITY OF SUCH DAMAGE.
3370c52ebfSjason  *
34733605cbSjason  * $FreeBSD: src/sys/pci/if_tlreg.h,v 1.17 2001/02/09 06:11:21 bmilekic Exp $
3570c52ebfSjason  */
3670c52ebfSjason 
3770c52ebfSjason 
3870c52ebfSjason struct tl_type {
3970c52ebfSjason 	u_int16_t		tl_vid;
4070c52ebfSjason 	u_int16_t		tl_did;
4170c52ebfSjason 	char			*tl_name;
4270c52ebfSjason };
4370c52ebfSjason 
4470c52ebfSjason /*
4570c52ebfSjason  * ThunderLAN TX/RX list format. The TX and RX lists are pretty much
4670c52ebfSjason  * identical: the list begins with a 32-bit forward pointer which points
4770c52ebfSjason  * at the next list in the chain, followed by 16 bits for the total
4870c52ebfSjason  * frame size, and a 16 bit status field. This is followed by a series
4970c52ebfSjason  * of 10 32-bit data count/data address pairs that point to the fragments
5070c52ebfSjason  * that make up the complete frame.
5170c52ebfSjason  */
5270c52ebfSjason 
5370c52ebfSjason #define TL_MAXFRAGS		10
54cfe52e88Sjason #define TL_RX_LIST_CNT		20
55733605cbSjason #define TL_TX_LIST_CNT		64
56733605cbSjason #define TL_MIN_FRAMELEN		128
5770c52ebfSjason 
5870c52ebfSjason struct tl_frag {
5970c52ebfSjason 	u_int32_t		tlist_dcnt;
6070c52ebfSjason 	u_int32_t		tlist_dadr;
6170c52ebfSjason };
6270c52ebfSjason 
6370c52ebfSjason struct tl_list {
6470c52ebfSjason 	u_int32_t		tlist_fptr;	/* phys address of next list */
6570c52ebfSjason 	u_int16_t		tlist_cstat;	/* status word */
6670c52ebfSjason 	u_int16_t		tlist_frsize;	/* size of data in frame */
6770c52ebfSjason 	struct tl_frag		tl_frag[TL_MAXFRAGS];
6870c52ebfSjason };
6970c52ebfSjason 
7070c52ebfSjason /*
7170c52ebfSjason  * This is a special case of an RX list. By setting the One_Frag
7270c52ebfSjason  * bit in the NETCONFIG register, the driver can force the ThunderLAN
7370c52ebfSjason  * chip to use only one fragment when DMAing RX frames.
7470c52ebfSjason  */
7570c52ebfSjason 
7670c52ebfSjason struct tl_list_onefrag {
7770c52ebfSjason 	u_int32_t		tlist_fptr;
7870c52ebfSjason 	u_int16_t		tlist_cstat;
7970c52ebfSjason 	u_int16_t		tlist_frsize;
8070c52ebfSjason 	struct tl_frag		tl_frag;
8170c52ebfSjason };
8270c52ebfSjason 
8370c52ebfSjason struct tl_list_data {
8470c52ebfSjason 	struct tl_list_onefrag	tl_rx_list[TL_RX_LIST_CNT];
8570c52ebfSjason 	struct tl_list		tl_tx_list[TL_TX_LIST_CNT];
8670c52ebfSjason 	unsigned char		tl_pad[TL_MIN_FRAMELEN];
8770c52ebfSjason };
8870c52ebfSjason 
8970c52ebfSjason struct tl_chain {
9070c52ebfSjason 	struct tl_list		*tl_ptr;
9170c52ebfSjason 	struct mbuf		*tl_mbuf;
9270c52ebfSjason 	struct tl_chain		*tl_next;
9370c52ebfSjason };
9470c52ebfSjason 
9570c52ebfSjason struct tl_chain_onefrag {
9670c52ebfSjason 	struct tl_list_onefrag	*tl_ptr;
9770c52ebfSjason 	struct mbuf		*tl_mbuf;
9870c52ebfSjason 	struct tl_chain_onefrag	*tl_next;
9970c52ebfSjason };
10070c52ebfSjason 
10170c52ebfSjason struct tl_chain_data {
10270c52ebfSjason 	struct tl_chain_onefrag	tl_rx_chain[TL_RX_LIST_CNT];
10370c52ebfSjason 	struct tl_chain		tl_tx_chain[TL_TX_LIST_CNT];
10470c52ebfSjason 
10570c52ebfSjason 	struct tl_chain_onefrag	*tl_rx_head;
10670c52ebfSjason 	struct tl_chain_onefrag	*tl_rx_tail;
10770c52ebfSjason 
10870c52ebfSjason 	struct tl_chain		*tl_tx_head;
10970c52ebfSjason 	struct tl_chain		*tl_tx_tail;
11070c52ebfSjason 	struct tl_chain		*tl_tx_free;
11170c52ebfSjason };
11270c52ebfSjason 
113733605cbSjason struct tl_products {
114733605cbSjason 	u_int16_t	tp_vend;
115733605cbSjason 	u_int16_t	tp_prod;
116733605cbSjason 	u_int32_t	tp_tlphymedia;
117733605cbSjason };
118733605cbSjason 
11970c52ebfSjason struct tl_softc {
12070c52ebfSjason 	struct device		sc_dev;		/* generic device structure */
12170c52ebfSjason 	void *			sc_ih;		/* interrupt handler cookie */
12270c52ebfSjason 	struct arpcom		arpcom;		/* interface info */
12370c52ebfSjason 	struct ifmedia		ifmedia;	/* media info */
12464b3e8fdSmickey 	struct timeout		tl_stats_tmo, tl_wait_tmo;
1250c480523Sjason 	bus_space_handle_t	tl_bhandle;
1260c480523Sjason 	bus_space_tag_t		tl_btag;
127733605cbSjason 	bus_dma_tag_t		sc_dmat;
12870c52ebfSjason 	struct tl_type		*tl_dinfo;	/* ThunderLAN adapter info */
12970c52ebfSjason 	struct tl_type		*tl_pinfo;	/* PHY info struct */
13070c52ebfSjason 	u_int8_t		tl_ctlr;	/* chip number */
13170c52ebfSjason 	u_int8_t		tl_eeaddr;
13270c52ebfSjason 	struct tl_list_data	*tl_ldata;	/* TX/RX lists and mbufs */
13370c52ebfSjason 	struct tl_chain_data	tl_cdata;
1340c480523Sjason 	u_int8_t		tl_txeoc;
1350c480523Sjason 	u_int8_t		tl_bitrate;
136733605cbSjason 	struct mii_data		sc_mii;
137733605cbSjason 	const struct tl_products *tl_product;
13870c52ebfSjason };
13970c52ebfSjason 
14070c52ebfSjason /*
14170c52ebfSjason  * Transmit interrupt threshold.
14270c52ebfSjason  */
143cfe52e88Sjason #define TX_THR		0x00000004
14470c52ebfSjason 
14570c52ebfSjason /*
14670c52ebfSjason  * General constants that are fun to know.
14770c52ebfSjason  *
14870c52ebfSjason  * The ThunderLAN controller is made by Texas Instruments. The
14970c52ebfSjason  * manual indicates that if the EEPROM checksum fails, the PCI
15070c52ebfSjason  * vendor and device ID registers will be loaded with TI-specific
15170c52ebfSjason  * values.
15270c52ebfSjason  */
15370c52ebfSjason #define	TI_VENDORID		0x104C
15470c52ebfSjason #define	TI_DEVICEID_THUNDERLAN	0x0500
15570c52ebfSjason 
15670c52ebfSjason /*
15770c52ebfSjason  * These are the PCI vendor and device IDs for Compaq ethernet
15870c52ebfSjason  * adapters based on the ThunderLAN controller.
15970c52ebfSjason  */
16070c52ebfSjason #define COMPAQ_VENDORID				0x0E11
16170c52ebfSjason #define COMPAQ_DEVICEID_NETEL_10_100		0xAE32
16270c52ebfSjason #define COMPAQ_DEVICEID_NETEL_UNKNOWN		0xAE33
16370c52ebfSjason #define COMPAQ_DEVICEID_NETEL_10		0xAE34
16470c52ebfSjason #define COMPAQ_DEVICEID_NETFLEX_3P_INTEGRATED	0xAE35
16570c52ebfSjason #define COMPAQ_DEVICEID_NETEL_10_100_DUAL	0xAE40
16670c52ebfSjason #define COMPAQ_DEVICEID_NETEL_10_100_PROLIANT	0xAE43
16770c52ebfSjason #define COMPAQ_DEVICEID_NETEL_10_100_EMBEDDED	0xB011
16870c52ebfSjason #define COMPAQ_DEVICEID_NETEL_10_T2_UTP_COAX	0xB012
16970c52ebfSjason #define COMPAQ_DEVICEID_NETEL_10_100_TX_UTP	0xB030
17070c52ebfSjason #define COMPAQ_DEVICEID_NETFLEX_3P		0xF130
17170c52ebfSjason #define COMPAQ_DEVICEID_NETFLEX_3P_BNC		0xF150
17270c52ebfSjason 
17370c52ebfSjason /*
17470c52ebfSjason  * These are the PCI vendor and device IDs for Olicom
17570c52ebfSjason  * adapters based on the ThunderLAN controller.
17670c52ebfSjason  */
17770c52ebfSjason #define OLICOM_VENDORID				0x108D
17870c52ebfSjason #define OLICOM_DEVICEID_OC2183			0x0013
17970c52ebfSjason #define OLICOM_DEVICEID_OC2325			0x0012
18070c52ebfSjason #define OLICOM_DEVICEID_OC2326			0x0014
18170c52ebfSjason 
18270c52ebfSjason /*
18370c52ebfSjason  * PCI low memory base and low I/O base
18470c52ebfSjason  */
18570c52ebfSjason #define TL_PCI_LOIO		0x10
18670c52ebfSjason #define TL_PCI_LOMEM		0x14
18770c52ebfSjason 
18870c52ebfSjason /*
18970c52ebfSjason  * PCI latency timer (it's actually 0x0D, but we want a value
19070c52ebfSjason  * that's longword aligned).
19170c52ebfSjason  */
19270c52ebfSjason #define TL_PCI_LATENCY_TIMER	0x0C
19370c52ebfSjason 
19470c52ebfSjason #define	TL_DIO_ADDR_INC		0x8000	/* Increment addr on each read */
19570c52ebfSjason #define TL_DIO_RAM_SEL		0x4000	/* RAM address select */
19670c52ebfSjason #define	TL_DIO_ADDR_MASK	0x3FFF	/* address bits mask */
19770c52ebfSjason 
19870c52ebfSjason /*
19970c52ebfSjason  * Interrupt types
20070c52ebfSjason  */
20170c52ebfSjason #define TL_INTR_INVALID		0x0
20270c52ebfSjason #define TL_INTR_TXEOF		0x1
20370c52ebfSjason #define TL_INTR_STATOFLOW	0x2
20470c52ebfSjason #define TL_INTR_RXEOF		0x3
20570c52ebfSjason #define TL_INTR_DUMMY		0x4
20670c52ebfSjason #define TL_INTR_TXEOC		0x5
20770c52ebfSjason #define TL_INTR_ADCHK		0x6
20870c52ebfSjason #define TL_INTR_RXEOC		0x7
20970c52ebfSjason 
21070c52ebfSjason #define TL_INT_MASK		0x001C
21170c52ebfSjason #define TL_VEC_MASK		0x1FE0
21270c52ebfSjason /*
21370c52ebfSjason  * Host command register bits
21470c52ebfSjason  */
21570c52ebfSjason #define TL_CMD_GO               0x80000000
21670c52ebfSjason #define TL_CMD_STOP             0x40000000
21770c52ebfSjason #define TL_CMD_ACK              0x20000000
21870c52ebfSjason #define TL_CMD_CHSEL7		0x10000000
21970c52ebfSjason #define TL_CMD_CHSEL6		0x08000000
22070c52ebfSjason #define TL_CMD_CHSEL5		0x04000000
22170c52ebfSjason #define TL_CMD_CHSEL4		0x02000000
22270c52ebfSjason #define TL_CMD_CHSEL3		0x01000000
22370c52ebfSjason #define TL_CMD_CHSEL2           0x00800000
22470c52ebfSjason #define TL_CMD_CHSEL1           0x00400000
22570c52ebfSjason #define TL_CMD_CHSEL0           0x00200000
22670c52ebfSjason #define TL_CMD_EOC              0x00100000
22770c52ebfSjason #define TL_CMD_RT               0x00080000
22870c52ebfSjason #define TL_CMD_NES              0x00040000
22970c52ebfSjason #define TL_CMD_ZERO0            0x00020000
23070c52ebfSjason #define TL_CMD_ZERO1            0x00010000
23170c52ebfSjason #define TL_CMD_ADRST            0x00008000
23270c52ebfSjason #define TL_CMD_LDTMR            0x00004000
23370c52ebfSjason #define TL_CMD_LDTHR            0x00002000
23470c52ebfSjason #define TL_CMD_REQINT           0x00001000
23570c52ebfSjason #define TL_CMD_INTSOFF          0x00000800
23670c52ebfSjason #define TL_CMD_INTSON		0x00000400
23770c52ebfSjason #define TL_CMD_RSVD0		0x00000200
23870c52ebfSjason #define TL_CMD_RSVD1		0x00000100
23970c52ebfSjason #define TL_CMD_ACK7		0x00000080
24070c52ebfSjason #define TL_CMD_ACK6		0x00000040
24170c52ebfSjason #define TL_CMD_ACK5		0x00000020
24270c52ebfSjason #define TL_CMD_ACK4		0x00000010
24370c52ebfSjason #define TL_CMD_ACK3		0x00000008
24470c52ebfSjason #define TL_CMD_ACK2		0x00000004
24570c52ebfSjason #define TL_CMD_ACK1		0x00000002
24670c52ebfSjason #define TL_CMD_ACK0		0x00000001
24770c52ebfSjason 
24870c52ebfSjason #define TL_CMD_CHSEL_MASK	0x01FE0000
24970c52ebfSjason #define TL_CMD_ACK_MASK		0xFF
25070c52ebfSjason 
25170c52ebfSjason /*
25270c52ebfSjason  * EEPROM address where station address resides.
25370c52ebfSjason  */
25470c52ebfSjason #define TL_EEPROM_EADDR		0x83
25570c52ebfSjason #define TL_EEPROM_EADDR2	0x99
25670c52ebfSjason #define TL_EEPROM_EADDR3	0xAF
25770c52ebfSjason #define TL_EEPROM_EADDR_OC	0xF8	/* Olicom cards use a different
25870c52ebfSjason 					   address than Compaqs. */
25970c52ebfSjason /*
26070c52ebfSjason  * ThunderLAN host command register offsets.
26170c52ebfSjason  * (Can be accessed either by IO ports or memory map.)
26270c52ebfSjason  */
26370c52ebfSjason #define TL_HOSTCMD		0x00
26470c52ebfSjason #define TL_CH_PARM		0x04
26570c52ebfSjason #define TL_DIO_ADDR		0x08
26670c52ebfSjason #define TL_HOST_INT		0x0A
26770c52ebfSjason #define TL_DIO_DATA		0x0C
26870c52ebfSjason 
26970c52ebfSjason /*
27070c52ebfSjason  * ThunderLAN internal registers
27170c52ebfSjason  */
27270c52ebfSjason #define TL_NETCMD		0x00
27370c52ebfSjason #define TL_NETSIO		0x01
27470c52ebfSjason #define TL_NETSTS		0x02
27570c52ebfSjason #define TL_NETMASK		0x03
27670c52ebfSjason 
27770c52ebfSjason #define TL_NETCONFIG		0x04
27870c52ebfSjason #define TL_MANTEST		0x06
27970c52ebfSjason 
28070c52ebfSjason #define TL_VENID_LSB		0x08
28170c52ebfSjason #define TL_VENID_MSB		0x09
28270c52ebfSjason #define TL_DEVID_LSB		0x0A
28370c52ebfSjason #define TL_DEVID_MSB		0x0B
28470c52ebfSjason 
28570c52ebfSjason #define TL_REVISION		0x0C
28670c52ebfSjason #define TL_SUBCLASS		0x0D
28770c52ebfSjason #define TL_MINLAT		0x0E
28870c52ebfSjason #define TL_MAXLAT		0x0F
28970c52ebfSjason 
29070c52ebfSjason #define TL_AREG0_B5		0x10
29170c52ebfSjason #define TL_AREG0_B4		0x11
29270c52ebfSjason #define TL_AREG0_B3		0x12
29370c52ebfSjason #define TL_AREG0_B2		0x13
29470c52ebfSjason 
29570c52ebfSjason #define TL_AREG0_B1		0x14
29670c52ebfSjason #define TL_AREG0_B0		0x15
29770c52ebfSjason #define TL_AREG1_B5		0x16
29870c52ebfSjason #define TL_AREG1_B4		0x17
29970c52ebfSjason 
30070c52ebfSjason #define TL_AREG1_B3		0x18
30170c52ebfSjason #define TL_AREG1_B2		0x19
30270c52ebfSjason #define TL_AREG1_B1		0x1A
30370c52ebfSjason #define TL_AREG1_B0		0x1B
30470c52ebfSjason 
30570c52ebfSjason #define TL_AREG2_B5		0x1C
30670c52ebfSjason #define TL_AREG2_B4		0x1D
30770c52ebfSjason #define TL_AREG2_B3		0x1E
30870c52ebfSjason #define TL_AREG2_B2		0x1F
30970c52ebfSjason 
31070c52ebfSjason #define TL_AREG2_B1		0x20
31170c52ebfSjason #define TL_AREG2_B0		0x21
31270c52ebfSjason #define TL_AREG3_B5		0x22
31370c52ebfSjason #define TL_AREG3_B4		0x23
31470c52ebfSjason 
31570c52ebfSjason #define TL_AREG3_B3		0x24
31670c52ebfSjason #define TL_AREG3_B2		0x25
31770c52ebfSjason #define TL_AREG3_B1		0x26
31870c52ebfSjason #define TL_AREG3_B0		0x27
31970c52ebfSjason 
32070c52ebfSjason #define TL_HASH1		0x28
32170c52ebfSjason #define TL_HASH2		0x2C
32270c52ebfSjason #define TL_TXGOODFRAMES		0x30
32370c52ebfSjason #define TL_TXUNDERRUN		0x33
32470c52ebfSjason #define TL_RXGOODFRAMES		0x34
32570c52ebfSjason #define TL_RXOVERRUN		0x37
32670c52ebfSjason #define TL_DEFEREDTX		0x38
32770c52ebfSjason #define TL_CRCERROR		0x3A
32870c52ebfSjason #define TL_CODEERROR		0x3B
32970c52ebfSjason #define TL_MULTICOLTX		0x3C
33070c52ebfSjason #define TL_SINGLECOLTX		0x3E
33170c52ebfSjason #define TL_EXCESSIVECOL		0x40
33270c52ebfSjason #define TL_LATECOL		0x41
33370c52ebfSjason #define TL_CARRIERLOSS		0x42
33470c52ebfSjason #define TL_ACOMMIT		0x43
33570c52ebfSjason #define TL_LDREG		0x44
33670c52ebfSjason #define TL_BSIZEREG		0x45
33770c52ebfSjason #define TL_MAXRX		0x46
33870c52ebfSjason 
33970c52ebfSjason /*
34070c52ebfSjason  * ThunderLAN SIO register bits
34170c52ebfSjason  */
34270c52ebfSjason #define TL_SIO_MINTEN		0x80
34370c52ebfSjason #define TL_SIO_ECLOK		0x40
34470c52ebfSjason #define TL_SIO_ETXEN		0x20
34570c52ebfSjason #define TL_SIO_EDATA		0x10
34670c52ebfSjason #define TL_SIO_NMRST		0x08
34770c52ebfSjason #define TL_SIO_MCLK		0x04
34870c52ebfSjason #define TL_SIO_MTXEN		0x02
34970c52ebfSjason #define TL_SIO_MDATA		0x01
35070c52ebfSjason 
35170c52ebfSjason /*
35270c52ebfSjason  * Thunderlan NETCONFIG bits
35370c52ebfSjason  */
35470c52ebfSjason #define TL_CFG_RCLKTEST		0x8000
35570c52ebfSjason #define TL_CFG_TCLKTEST		0x4000
35670c52ebfSjason #define TL_CFG_BITRATE		0x2000
35770c52ebfSjason #define TL_CFG_RXCRC		0x1000
35870c52ebfSjason #define TL_CFG_PEF		0x0800
35970c52ebfSjason #define TL_CFG_ONEFRAG		0x0400
36070c52ebfSjason #define TL_CFG_ONECHAN		0x0200
36170c52ebfSjason #define TL_CFG_MTEST		0x0100
36270c52ebfSjason #define TL_CFG_PHYEN		0x0080
36370c52ebfSjason #define TL_CFG_MACSEL6		0x0040
36470c52ebfSjason #define TL_CFG_MACSEL5		0x0020
36570c52ebfSjason #define TL_CFG_MACSEL4		0x0010
36670c52ebfSjason #define TL_CFG_MACSEL3		0x0008
36770c52ebfSjason #define TL_CFG_MACSEL2		0x0004
36870c52ebfSjason #define TL_CFG_MACSEL1		0x0002
36970c52ebfSjason #define TL_CFG_MACSEL0		0x0001
37070c52ebfSjason 
37170c52ebfSjason /*
37270c52ebfSjason  * ThunderLAN NETSTS bits
37370c52ebfSjason  */
37470c52ebfSjason #define TL_STS_MIRQ		0x80
37570c52ebfSjason #define TL_STS_HBEAT		0x40
37670c52ebfSjason #define TL_STS_TXSTOP		0x20
37770c52ebfSjason #define TL_STS_RXSTOP		0x10
37870c52ebfSjason 
37970c52ebfSjason /*
38070c52ebfSjason  * ThunderLAN NETCMD bits
38170c52ebfSjason  */
38270c52ebfSjason #define TL_CMD_NRESET		0x80
38370c52ebfSjason #define TL_CMD_NWRAP		0x40
38470c52ebfSjason #define TL_CMD_CSF		0x20
38570c52ebfSjason #define TL_CMD_CAF		0x10
38670c52ebfSjason #define TL_CMD_NOBRX		0x08
38770c52ebfSjason #define TL_CMD_DUPLEX		0x04
38870c52ebfSjason #define TL_CMD_TRFRAM		0x02
38970c52ebfSjason #define TL_CMD_TXPACE		0x01
39070c52ebfSjason 
39170c52ebfSjason /*
39270c52ebfSjason  * ThunderLAN NETMASK bits
39370c52ebfSjason  */
39470c52ebfSjason #define TL_MASK_MASK7		0x80
39570c52ebfSjason #define TL_MASK_MASK6		0x40
39670c52ebfSjason #define TL_MASK_MASK5		0x20
39770c52ebfSjason #define TL_MASK_MASK4		0x10
39870c52ebfSjason 
39970c52ebfSjason /*
40070c52ebfSjason  * MII frame format
40170c52ebfSjason  */
40270c52ebfSjason #ifdef ANSI_DOESNT_ALLOW_BITFIELDS
40370c52ebfSjason struct tl_mii_frame {
40470c52ebfSjason 	u_int16_t		mii_stdelim:2,
40570c52ebfSjason 				mii_opcode:2,
40670c52ebfSjason 				mii_phyaddr:5,
40770c52ebfSjason 				mii_regaddr:5,
40870c52ebfSjason 				mii_turnaround:2;
40970c52ebfSjason 	u_int16_t		mii_data;
41070c52ebfSjason };
41170c52ebfSjason #else
41270c52ebfSjason struct tl_mii_frame {
41370c52ebfSjason 	u_int8_t		mii_stdelim;
41470c52ebfSjason 	u_int8_t		mii_opcode;
41570c52ebfSjason 	u_int8_t		mii_phyaddr;
41670c52ebfSjason 	u_int8_t		mii_regaddr;
41770c52ebfSjason 	u_int8_t		mii_turnaround;
41870c52ebfSjason 	u_int16_t		mii_data;
41970c52ebfSjason };
42070c52ebfSjason #endif
42170c52ebfSjason /*
42270c52ebfSjason  * MII constants
42370c52ebfSjason  */
42470c52ebfSjason #define TL_MII_STARTDELIM	0x01
42570c52ebfSjason #define TL_MII_READOP		0x02
42670c52ebfSjason #define TL_MII_WRITEOP		0x01
42770c52ebfSjason #define TL_MII_TURNAROUND	0x02
42870c52ebfSjason 
42970c52ebfSjason #define TL_LAST_FRAG		0x80000000
43070c52ebfSjason #define TL_CSTAT_UNUSED		0x8000
43170c52ebfSjason #define TL_CSTAT_FRAMECMP	0x4000
43270c52ebfSjason #define TL_CSTAT_READY		0x3000
43370c52ebfSjason #define TL_CSTAT_UNUSED13	0x2000
43470c52ebfSjason #define TL_CSTAT_UNUSED12	0x1000
43570c52ebfSjason #define TL_CSTAT_EOC		0x0800
43670c52ebfSjason #define TL_CSTAT_RXERROR	0x0400
43770c52ebfSjason #define TL_CSTAT_PASSCRC	0x0200
43870c52ebfSjason #define TL_CSTAT_DPRIO		0x0100
43970c52ebfSjason 
44070c52ebfSjason #define TL_FRAME_MASK		0x00FFFFFF
44170c52ebfSjason #define tl_tx_goodframes(x)	(x.tl_txstat & TL_FRAME_MASK)
44270c52ebfSjason #define tl_tx_underrun(x)	((x.tl_txstat & ~TL_FRAME_MASK) >> 24)
44370c52ebfSjason #define tl_rx_goodframes(x)	(x.tl_rxstat & TL_FRAME_MASK)
44470c52ebfSjason #define tl_rx_overrun(x)	((x.tl_rxstat & ~TL_FRAME_MASK) >> 24)
44570c52ebfSjason 
44670c52ebfSjason struct tl_stats {
44770c52ebfSjason 	u_int32_t		tl_txstat;
44870c52ebfSjason 	u_int32_t		tl_rxstat;
44970c52ebfSjason 	u_int16_t		tl_deferred;
45070c52ebfSjason 	u_int8_t		tl_crc_errors;
45170c52ebfSjason 	u_int8_t		tl_code_errors;
45270c52ebfSjason 	u_int16_t		tl_tx_multi_collision;
45370c52ebfSjason 	u_int16_t		tl_tx_single_collision;
45470c52ebfSjason 	u_int8_t		tl_excessive_collision;
45570c52ebfSjason 	u_int8_t		tl_late_collision;
45670c52ebfSjason 	u_int8_t		tl_carrier_loss;
45770c52ebfSjason 	u_int8_t		acommit;
45870c52ebfSjason };
45970c52ebfSjason 
46070c52ebfSjason /*
4610c480523Sjason  * ACOMMIT register bits. These are used only when a bitrate
4620c480523Sjason  * PHY is selected ('bitrate' bit in netconfig register is set).
4630c480523Sjason  */
4640c480523Sjason #define TL_AC_MTXER		0x01	/* reserved */
4650c480523Sjason #define TL_AC_MTXD1		0x02	/* 0 == 10baseT 1 == AUI */
4660c480523Sjason #define TL_AC_MTXD2		0x04	/* loopback disable */
4670c480523Sjason #define TL_AC_MTXD3		0x08	/* full duplex disable */
4680c480523Sjason 
469733605cbSjason #define TL_AC_TXTHRESH		0xF0
470733605cbSjason #define TL_AC_TXTHRESH_16LONG	0x00
471733605cbSjason #define TL_AC_TXTHRESH_32LONG	0x10
472733605cbSjason #define TL_AC_TXTHRESH_64LONG	0x20
473733605cbSjason #define TL_AC_TXTHRESH_128LONG	0x30
474733605cbSjason #define TL_AC_TXTHRESH_256LONG	0x40
475733605cbSjason #define TL_AC_TXTHRESH_WHOLEPKT	0x50
476733605cbSjason 
477733605cbSjason /*
478733605cbSjason  * PCI burst size register (TL_BSIZEREG).
479733605cbSjason  */
480733605cbSjason #define TL_RXBURST		0x0F
481733605cbSjason #define TL_TXBURST		0xF0
482733605cbSjason 
483733605cbSjason #define TL_RXBURST_4LONG	0x00
484733605cbSjason #define TL_RXBURST_8LONG	0x01
485733605cbSjason #define TL_RXBURST_16LONG	0x02
486733605cbSjason #define TL_RXBURST_32LONG	0x03
487733605cbSjason #define TL_RXBURST_64LONG	0x04
488733605cbSjason #define TL_RXBURST_128LONG	0x05
489733605cbSjason 
490733605cbSjason #define TL_TXBURST_4LONG	0x00
491733605cbSjason #define TL_TXBURST_8LONG	0x10
492733605cbSjason #define TL_TXBURST_16LONG	0x20
493733605cbSjason #define TL_TXBURST_32LONG	0x30
494733605cbSjason #define TL_TXBURST_64LONG	0x40
495733605cbSjason #define TL_TXBURST_128LONG	0x50
496733605cbSjason 
4970c480523Sjason /*
49870c52ebfSjason  * register space access macros
49970c52ebfSjason  */
50070c52ebfSjason #define CSR_WRITE_4(sc, reg, val) \
5010c480523Sjason 	bus_space_write_4(sc->tl_btag, sc->tl_bhandle, reg, val)
50270c52ebfSjason #define CSR_WRITE_2(sc, reg, val) \
5030c480523Sjason 	bus_space_write_2(sc->tl_btag, sc->tl_bhandle, reg, val)
50470c52ebfSjason #define CSR_WRITE_1(sc, reg, val) \
5050c480523Sjason 	bus_space_write_1(sc->tl_btag, sc->tl_bhandle, reg, val)
50670c52ebfSjason 
50770c52ebfSjason #define CSR_READ_4(sc, reg) \
5080c480523Sjason 	bus_space_read_4(sc->tl_btag, sc->tl_bhandle, reg)
50970c52ebfSjason #define CSR_READ_2(sc, reg) \
5100c480523Sjason 	bus_space_read_2(sc->tl_btag, sc->tl_bhandle, reg)
51170c52ebfSjason #define CSR_READ_1(sc, reg) \
5120c480523Sjason 	bus_space_read_1(sc->tl_btag, sc->tl_bhandle, reg)
51370c52ebfSjason 
51470c52ebfSjason #define CMD_PUT(sc, x) CSR_WRITE_4(sc, TL_HOSTCMD, x)
51570c52ebfSjason #define CMD_SET(sc, x)	\
51670c52ebfSjason 	CSR_WRITE_4(sc, TL_HOSTCMD, CSR_READ_4(sc, TL_HOSTCMD) | (x))
51770c52ebfSjason #define CMD_CLR(sc, x)	\
51870c52ebfSjason 	CSR_WRITE_4(sc, TL_HOSTCMD, CSR_READ_4(sc, TL_HOSTCMD) & ~(x))
51970c52ebfSjason 
52070c52ebfSjason /*
52170c52ebfSjason  * ThunderLAN adapters typically have a serial EEPROM containing
52270c52ebfSjason  * configuration information. The main reason we're interested in
52370c52ebfSjason  * it is because it also contains the adapters's station address.
52470c52ebfSjason  *
52570c52ebfSjason  * Access to the EEPROM is a bit goofy since it is a serial device:
52670c52ebfSjason  * you have to do reads and writes one bit at a time. The state of
52770c52ebfSjason  * the DATA bit can only change while the CLOCK line is held low.
52870c52ebfSjason  * Transactions work basically like this:
52970c52ebfSjason  *
53070c52ebfSjason  * 1) Send the EEPROM_START sequence to prepare the EEPROM for
53170c52ebfSjason  *    accepting commands. This pulls the clock high, sets
53270c52ebfSjason  *    the data bit to 0, enables transmission to the EEPROM,
53370c52ebfSjason  *    pulls the data bit up to 1, then pulls the clock low.
53470c52ebfSjason  *    The idea is to do a 0 to 1 transition of the data bit
53570c52ebfSjason  *    while the clock pin is held high.
53670c52ebfSjason  *
53770c52ebfSjason  * 2) To write a bit to the EEPROM, set the TXENABLE bit, then
53870c52ebfSjason  *    set the EDATA bit to send a 1 or clear it to send a 0.
53970c52ebfSjason  *    Finally, set and then clear ECLOK. Strobing the clock
54070c52ebfSjason  *    transmits the bit. After 8 bits have been written, the
54170c52ebfSjason  *    EEPROM should respond with an ACK, which should be read.
54270c52ebfSjason  *
54370c52ebfSjason  * 3) To read a bit from the EEPROM, clear the TXENABLE bit,
54470c52ebfSjason  *    then set ECLOK. The bit can then be read by reading EDATA.
54570c52ebfSjason  *    ECLOCK should then be cleared again. This can be repeated
54670c52ebfSjason  *    8 times to read a whole byte, after which the
54770c52ebfSjason  *
54870c52ebfSjason  * 4) We need to send the address byte to the EEPROM. For this
54970c52ebfSjason  *    we have to send the write control byte to the EEPROM to
55070c52ebfSjason  *    tell it to accept data. The byte is 0xA0. The EEPROM should
55170c52ebfSjason  *    ack this. The address byte can be send after that.
55270c52ebfSjason  *
55370c52ebfSjason  * 5) Now we have to tell the EEPROM to send us data. For that we
55470c52ebfSjason  *    have to transmit the read control byte, which is 0xA1. This
55570c52ebfSjason  *    byte should also be acked. We can then read the data bits
55670c52ebfSjason  *    from the EEPROM.
55770c52ebfSjason  *
55870c52ebfSjason  * 6) When we're all finished, send the EEPROM_STOP sequence.
55970c52ebfSjason  *
56070c52ebfSjason  * Note that we use the ThunderLAN's NetSio register to access the
56170c52ebfSjason  * EEPROM, however there is an alternate method. There is a PCI NVRAM
56270c52ebfSjason  * register at PCI offset 0xB4 which can also be used with minor changes.
56370c52ebfSjason  * The difference is that access to PCI registers via pci_conf_read()
56470c52ebfSjason  * and pci_conf_write() is done using programmed I/O, which we want to
56570c52ebfSjason  * avoid.
56670c52ebfSjason  */
56770c52ebfSjason 
56870c52ebfSjason /*
56970c52ebfSjason  * Note that EEPROM_START leaves transmission enabled.
57070c52ebfSjason  */
57170c52ebfSjason #define EEPROM_START							\
57270c52ebfSjason 	tl_dio_setbit(sc, TL_NETSIO, TL_SIO_ECLOK); /* Pull clock pin high */\
57370c52ebfSjason 	tl_dio_setbit(sc, TL_NETSIO, TL_SIO_EDATA); /* Set DATA bit to 1 */	\
57470c52ebfSjason 	tl_dio_setbit(sc, TL_NETSIO, TL_SIO_ETXEN); /* Enable xmit to write bit */\
57570c52ebfSjason 	tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_EDATA); /* Pull DATA bit to 0 again */\
57670c52ebfSjason 	tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_ECLOK); /* Pull clock low again */
57770c52ebfSjason 
57870c52ebfSjason /*
57970c52ebfSjason  * EEPROM_STOP ends access to the EEPROM and clears the ETXEN bit so
58070c52ebfSjason  * that no further data can be written to the EEPROM I/O pin.
58170c52ebfSjason  */
58270c52ebfSjason #define EEPROM_STOP							\
58370c52ebfSjason 	tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_ETXEN); /* Disable xmit */	\
58470c52ebfSjason 	tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_EDATA); /* Pull DATA to 0 */	\
58570c52ebfSjason 	tl_dio_setbit(sc, TL_NETSIO, TL_SIO_ECLOK); /* Pull clock high */	\
58670c52ebfSjason 	tl_dio_setbit(sc, TL_NETSIO, TL_SIO_ETXEN); /* Enable xmit */	\
58770c52ebfSjason 	tl_dio_setbit(sc, TL_NETSIO, TL_SIO_EDATA); /* Toggle DATA to 1 */	\
58870c52ebfSjason 	tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_ETXEN); /* Disable xmit. */	\
58970c52ebfSjason 	tl_dio_clrbit(sc, TL_NETSIO, TL_SIO_ECLOK); /* Pull clock low again */
59070c52ebfSjason 
59170c52ebfSjason /*
59270c52ebfSjason  * Microchip Technology 24Cxx EEPROM control bytes
59370c52ebfSjason  */
59470c52ebfSjason #define EEPROM_CTL_READ			0xA1	/* 0101 0001 */
59570c52ebfSjason #define EEPROM_CTL_WRITE		0xA0	/* 0101 0000 */
5960c480523Sjason 
5970c480523Sjason #ifdef __alpha__
5980c480523Sjason #undef vtophys
599e02071cfSmiod #define vtophys(va)		alpha_XXX_dmamap((vaddr_t)va)
6000c480523Sjason #endif
601