xref: /dflybsd-src/sys/dev/netif/wb/if_wbreg.h (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*
286d7f5d3SJohn Marino  * Copyright (c) 1997, 1998
386d7f5d3SJohn Marino  *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
486d7f5d3SJohn Marino  *
586d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
686d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
786d7f5d3SJohn Marino  * are met:
886d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
986d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1086d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1186d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1286d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
1386d7f5d3SJohn Marino  * 3. All advertising materials mentioning features or use of this software
1486d7f5d3SJohn Marino  *    must display the following acknowledgement:
1586d7f5d3SJohn Marino  *	This product includes software developed by Bill Paul.
1686d7f5d3SJohn Marino  * 4. Neither the name of the author nor the names of any co-contributors
1786d7f5d3SJohn Marino  *    may be used to endorse or promote products derived from this software
1886d7f5d3SJohn Marino  *    without specific prior written permission.
1986d7f5d3SJohn Marino  *
2086d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2186d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2286d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2386d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
2486d7f5d3SJohn Marino  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2586d7f5d3SJohn Marino  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2686d7f5d3SJohn Marino  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2786d7f5d3SJohn Marino  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2886d7f5d3SJohn Marino  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2986d7f5d3SJohn Marino  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3086d7f5d3SJohn Marino  * THE POSSIBILITY OF SUCH DAMAGE.
3186d7f5d3SJohn Marino  *
3286d7f5d3SJohn Marino  * $FreeBSD: src/sys/pci/if_wbreg.h,v 1.7 1999/08/30 23:08:30 wpaul Exp $
3386d7f5d3SJohn Marino  * $DragonFly: src/sys/dev/netif/wb/if_wbreg.h,v 1.8 2006/08/01 18:11:47 swildner Exp $
3486d7f5d3SJohn Marino  */
3586d7f5d3SJohn Marino 
3686d7f5d3SJohn Marino /*
3786d7f5d3SJohn Marino  * Winbond register definitions.
3886d7f5d3SJohn Marino  */
3986d7f5d3SJohn Marino 
4086d7f5d3SJohn Marino #define WB_BUSCTL		0x00	/* bus control */
4186d7f5d3SJohn Marino #define WB_TXSTART		0x04	/* tx start demand */
4286d7f5d3SJohn Marino #define WB_RXSTART		0x08	/* rx start demand */
4386d7f5d3SJohn Marino #define WB_RXADDR		0x0C	/* rx descriptor list start addr */
4486d7f5d3SJohn Marino #define WB_TXADDR		0x10	/* tx descriptor list start addr */
4586d7f5d3SJohn Marino #define WB_ISR			0x14	/* interrupt status register */
4686d7f5d3SJohn Marino #define WB_NETCFG		0x18	/* network config register */
4786d7f5d3SJohn Marino #define WB_IMR			0x1C	/* interrupt mask */
4886d7f5d3SJohn Marino #define WB_FRAMESDISCARDED	0x20	/* # of discarded frames */
4986d7f5d3SJohn Marino #define WB_SIO			0x24	/* MII and ROM/EEPROM access */
5086d7f5d3SJohn Marino #define WB_BOOTROMADDR		0x28
5186d7f5d3SJohn Marino #define WB_TIMER		0x2C	/* general timer */
5286d7f5d3SJohn Marino #define WB_CURRXCTL		0x30	/* current RX descriptor */
5386d7f5d3SJohn Marino #define WB_CURRXBUF		0x34	/* current RX buffer */
5486d7f5d3SJohn Marino #define WB_MAR0			0x38	/* multicast filter 0 */
5586d7f5d3SJohn Marino #define WB_MAR1			0x3C	/* multicast filter 1 */
5686d7f5d3SJohn Marino #define WB_NODE0		0x40	/* station address 0 */
5786d7f5d3SJohn Marino #define WB_NODE1		0x44	/* station address 1 */
5886d7f5d3SJohn Marino #define WB_BOOTROMSIZE		0x48	/* boot ROM size */
5986d7f5d3SJohn Marino #define WB_CURTXCTL		0x4C	/* current TX descriptor */
6086d7f5d3SJohn Marino #define WB_CURTXBUF		0x50	/* current TX buffer */
6186d7f5d3SJohn Marino 
6286d7f5d3SJohn Marino /*
6386d7f5d3SJohn Marino  * Bus control bits.
6486d7f5d3SJohn Marino  */
6586d7f5d3SJohn Marino #define WB_BUSCTL_RESET		0x00000001
6686d7f5d3SJohn Marino #define WB_BUSCTL_ARBITRATION	0x00000002
6786d7f5d3SJohn Marino #define WB_BUSCTL_SKIPLEN	0x0000007C
6886d7f5d3SJohn Marino #define WB_BUSCTL_BUF_BIGENDIAN	0x00000080
6986d7f5d3SJohn Marino #define WB_BUSCTL_BURSTLEN	0x00003F00
7086d7f5d3SJohn Marino #define WB_BUSCTL_CACHEALIGN	0x0000C000
7186d7f5d3SJohn Marino #define WB_BUSCTL_DES_BIGENDIAN	0x00100000
7286d7f5d3SJohn Marino #define WB_BUSCTL_WAIT		0x00200000
7386d7f5d3SJohn Marino #define WB_BUSCTL_MUSTBEONE	0x00400000
7486d7f5d3SJohn Marino 
7586d7f5d3SJohn Marino #define WB_SKIPLEN_1LONG	0x00000004
7686d7f5d3SJohn Marino #define WB_SKIPLEN_2LONG	0x00000008
7786d7f5d3SJohn Marino #define WB_SKIPLEN_3LONG	0x00000010
7886d7f5d3SJohn Marino #define WB_SKIPLEN_4LONG	0x00000020
7986d7f5d3SJohn Marino #define WB_SKIPLEN_5LONG	0x00000040
8086d7f5d3SJohn Marino 
8186d7f5d3SJohn Marino #define WB_CACHEALIGN_NONE	0x00000000
8286d7f5d3SJohn Marino #define WB_CACHEALIGN_8LONG	0x00004000
8386d7f5d3SJohn Marino #define WB_CACHEALIGN_16LONG	0x00008000
8486d7f5d3SJohn Marino #define WB_CACHEALIGN_32LONG	0x0000C000
8586d7f5d3SJohn Marino 
8686d7f5d3SJohn Marino #define WB_BURSTLEN_USECA	0x00000000
8786d7f5d3SJohn Marino #define WB_BURSTLEN_1LONG	0x00000100
8886d7f5d3SJohn Marino #define WB_BURSTLEN_2LONG	0x00000200
8986d7f5d3SJohn Marino #define WB_BURSTLEN_4LONG	0x00000400
9086d7f5d3SJohn Marino #define WB_BURSTLEN_8LONG	0x00000800
9186d7f5d3SJohn Marino #define WB_BURSTLEN_16LONG	0x00001000
9286d7f5d3SJohn Marino #define WB_BURSTLEN_32LONG	0x00002000
9386d7f5d3SJohn Marino 
9486d7f5d3SJohn Marino #define WB_BUSCTL_CONFIG	(WB_CACHEALIGN_8LONG|WB_SKIPLEN_3LONG| \
9586d7f5d3SJohn Marino 					WB_BURSTLEN_8LONG)
9686d7f5d3SJohn Marino 
9786d7f5d3SJohn Marino /*
9886d7f5d3SJohn Marino  * Interrupt status bits.
9986d7f5d3SJohn Marino  */
10086d7f5d3SJohn Marino #define WB_ISR_TX_OK		0x00000001
10186d7f5d3SJohn Marino #define WB_ISR_TX_IDLE		0x00000002
10286d7f5d3SJohn Marino #define WB_ISR_TX_NOBUF		0x00000004
10386d7f5d3SJohn Marino #define WB_ISR_RX_EARLY		0x00000008
10486d7f5d3SJohn Marino #define WB_ISR_RX_ERR		0x00000010
10586d7f5d3SJohn Marino #define WB_ISR_TX_UNDERRUN	0x00000020
10686d7f5d3SJohn Marino #define WB_ISR_RX_OK		0x00000040
10786d7f5d3SJohn Marino #define WB_ISR_RX_NOBUF		0x00000080
10886d7f5d3SJohn Marino #define WB_ISR_RX_IDLE		0x00000100
10986d7f5d3SJohn Marino #define WB_ISR_TX_EARLY		0x00000400
11086d7f5d3SJohn Marino #define WB_ISR_TIMER_EXPIRED	0x00000800
11186d7f5d3SJohn Marino #define WB_ISR_BUS_ERR		0x00002000
11286d7f5d3SJohn Marino #define WB_ISR_ABNORMAL		0x00008000
11386d7f5d3SJohn Marino #define WB_ISR_NORMAL		0x00010000
11486d7f5d3SJohn Marino #define WB_ISR_RX_STATE		0x000E0000
11586d7f5d3SJohn Marino #define WB_ISR_TX_STATE		0x00700000
11686d7f5d3SJohn Marino #define WB_ISR_BUSERRTYPE	0x03800000
11786d7f5d3SJohn Marino 
11886d7f5d3SJohn Marino /*
11986d7f5d3SJohn Marino  * The RX_STATE and TX_STATE fields are not described anywhere in the
12086d7f5d3SJohn Marino  * Winbond datasheet, however it appears that the Winbond chip is an
12186d7f5d3SJohn Marino  * attempt at a DEC 'tulip' clone, hence the ISR register is identical
12286d7f5d3SJohn Marino  * to that of the tulip chip and we can steal the bit definitions from
12386d7f5d3SJohn Marino  * the tulip documentation.
12486d7f5d3SJohn Marino  */
12586d7f5d3SJohn Marino #define WB_RXSTATE_STOPPED	0x00000000	/* 000 - Stopped */
12686d7f5d3SJohn Marino #define WB_RXSTATE_FETCH	0x00020000	/* 001 - Fetching descriptor */
12786d7f5d3SJohn Marino #define WB_RXSTATE_ENDCHECK	0x00040000	/* 010 - check for rx end */
12886d7f5d3SJohn Marino #define WB_RXSTATE_WAIT		0x00060000	/* 011 - waiting for packet */
12986d7f5d3SJohn Marino #define WB_RXSTATE_SUSPEND	0x00080000	/* 100 - suspend rx */
13086d7f5d3SJohn Marino #define WB_RXSTATE_CLOSE	0x000A0000	/* 101 - close tx desc */
13186d7f5d3SJohn Marino #define WB_RXSTATE_FLUSH	0x000C0000	/* 110 - flush from FIFO */
13286d7f5d3SJohn Marino #define WB_RXSTATE_DEQUEUE	0x000E0000	/* 111 - dequeue from FIFO */
13386d7f5d3SJohn Marino 
13486d7f5d3SJohn Marino #define WB_TXSTATE_RESET	0x00000000	/* 000 - reset */
13586d7f5d3SJohn Marino #define WB_TXSTATE_FETCH	0x00100000	/* 001 - fetching descriptor */
13686d7f5d3SJohn Marino #define WB_TXSTATE_WAITEND	0x00200000	/* 010 - wait for tx end */
13786d7f5d3SJohn Marino #define WB_TXSTATE_READING	0x00300000	/* 011 - read and enqueue */
13886d7f5d3SJohn Marino #define WB_TXSTATE_RSVD		0x00400000	/* 100 - reserved */
13986d7f5d3SJohn Marino #define WB_TXSTATE_SETUP	0x00500000	/* 101 - setup packet */
14086d7f5d3SJohn Marino #define WB_TXSTATE_SUSPEND	0x00600000	/* 110 - suspend tx */
14186d7f5d3SJohn Marino #define WB_TXSTATE_CLOSE	0x00700000	/* 111 - close tx desc */
14286d7f5d3SJohn Marino 
14386d7f5d3SJohn Marino /*
14486d7f5d3SJohn Marino  * Network config bits.
14586d7f5d3SJohn Marino  */
14686d7f5d3SJohn Marino #define WB_NETCFG_RX_ON		0x00000002
14786d7f5d3SJohn Marino #define WB_NETCFG_RX_ALLPHYS	0x00000008
14886d7f5d3SJohn Marino #define WB_NETCFG_RX_MULTI	0x00000010
14986d7f5d3SJohn Marino #define WB_NETCFG_RX_BROAD	0x00000020
15086d7f5d3SJohn Marino #define WB_NETCFG_RX_RUNT	0x00000040
15186d7f5d3SJohn Marino #define WB_NETCFG_RX_ERR	0x00000080
15286d7f5d3SJohn Marino #define WB_NETCFG_FULLDUPLEX	0x00000200
15386d7f5d3SJohn Marino #define WB_NETCFG_LOOPBACK	0x00000C00
15486d7f5d3SJohn Marino #define WB_NETCFG_TX_ON		0x00002000
15586d7f5d3SJohn Marino #define WB_NETCFG_TX_THRESH	0x001FC000
15686d7f5d3SJohn Marino #define WB_NETCFG_RX_EARLYTHRSH	0x1FE00000
15786d7f5d3SJohn Marino #define WB_NETCFG_100MBPS	0x20000000
15886d7f5d3SJohn Marino #define WB_NETCFG_TX_EARLY_ON	0x40000000
15986d7f5d3SJohn Marino #define WB_NETCFG_RX_EARLY_ON	0x80000000
16086d7f5d3SJohn Marino 
16186d7f5d3SJohn Marino /*
16286d7f5d3SJohn Marino  * The tx threshold can be adjusted in increments of 32 bytes.
16386d7f5d3SJohn Marino  */
16486d7f5d3SJohn Marino #define WB_TXTHRESH(x)		((x >> 5) << 14)
16586d7f5d3SJohn Marino #define WB_TXTHRESH_CHUNK	32
16686d7f5d3SJohn Marino #define WB_TXTHRESH_INIT	0 /*72*/
16786d7f5d3SJohn Marino 
16886d7f5d3SJohn Marino /*
16986d7f5d3SJohn Marino  * Interrupt mask bits.
17086d7f5d3SJohn Marino  */
17186d7f5d3SJohn Marino #define WB_IMR_TX_OK		0x00000001
17286d7f5d3SJohn Marino #define WB_IMR_TX_IDLE		0x00000002
17386d7f5d3SJohn Marino #define WB_IMR_TX_NOBUF		0x00000004
17486d7f5d3SJohn Marino #define WB_IMR_RX_EARLY		0x00000008
17586d7f5d3SJohn Marino #define WB_IMR_RX_ERR		0x00000010
17686d7f5d3SJohn Marino #define WB_IMR_TX_UNDERRUN	0x00000020
17786d7f5d3SJohn Marino #define WB_IMR_RX_OK		0x00000040
17886d7f5d3SJohn Marino #define WB_IMR_RX_NOBUF		0x00000080
17986d7f5d3SJohn Marino #define WB_IMR_RX_IDLE		0x00000100
18086d7f5d3SJohn Marino #define WB_IMR_TX_EARLY		0x00000400
18186d7f5d3SJohn Marino #define WB_IMR_TIMER_EXPIRED	0x00000800
18286d7f5d3SJohn Marino #define WB_IMR_BUS_ERR		0x00002000
18386d7f5d3SJohn Marino #define WB_IMR_ABNORMAL		0x00008000
18486d7f5d3SJohn Marino #define WB_IMR_NORMAL		0x00010000
18586d7f5d3SJohn Marino 
18686d7f5d3SJohn Marino #define WB_INTRS	\
18786d7f5d3SJohn Marino 	(WB_IMR_RX_OK|WB_IMR_TX_OK|WB_IMR_RX_NOBUF|WB_IMR_RX_ERR|	\
18886d7f5d3SJohn Marino 	WB_IMR_TX_NOBUF|WB_IMR_TX_UNDERRUN|WB_IMR_BUS_ERR|		\
18986d7f5d3SJohn Marino 	WB_IMR_ABNORMAL|WB_IMR_NORMAL|WB_IMR_TX_EARLY)
19086d7f5d3SJohn Marino /*
19186d7f5d3SJohn Marino  * Serial I/O (EEPROM/ROM) bits.
19286d7f5d3SJohn Marino  */
19386d7f5d3SJohn Marino #define WB_SIO_EE_CS		0x00000001	/* EEPROM chip select */
19486d7f5d3SJohn Marino #define WB_SIO_EE_CLK		0x00000002	/* EEPROM clock */
19586d7f5d3SJohn Marino #define WB_SIO_EE_DATAIN	0x00000004	/* EEPROM data output */
19686d7f5d3SJohn Marino #define WB_SIO_EE_DATAOUT	0x00000008	/* EEPROM data input */
19786d7f5d3SJohn Marino #define WB_SIO_ROMDATA4		0x00000010
19886d7f5d3SJohn Marino #define WB_SIO_ROMDATA5		0x00000020
19986d7f5d3SJohn Marino #define WB_SIO_ROMDATA6		0x00000040
20086d7f5d3SJohn Marino #define WB_SIO_ROMDATA7		0x00000080
20186d7f5d3SJohn Marino #define WB_SIO_ROMCTL_WRITE	0x00000200
20286d7f5d3SJohn Marino #define WB_SIO_ROMCTL_READ	0x00000400
20386d7f5d3SJohn Marino #define WB_SIO_EESEL		0x00000800
20486d7f5d3SJohn Marino #define WB_SIO_MII_CLK		0x00010000	/* MDIO clock */
20586d7f5d3SJohn Marino #define WB_SIO_MII_DATAIN	0x00020000	/* MDIO data out */
20686d7f5d3SJohn Marino #define WB_SIO_MII_DIR		0x00040000	/* MDIO dir */
20786d7f5d3SJohn Marino #define WB_SIO_MII_DATAOUT	0x00080000	/* MDIO data in */
20886d7f5d3SJohn Marino 
20986d7f5d3SJohn Marino #define WB_EECMD_WRITE		0x140
21086d7f5d3SJohn Marino #define WB_EECMD_READ		0x180
21186d7f5d3SJohn Marino #define WB_EECMD_ERASE		0x1c0
21286d7f5d3SJohn Marino 
21386d7f5d3SJohn Marino /*
21486d7f5d3SJohn Marino  * Winbond TX/RX descriptor structure.
21586d7f5d3SJohn Marino  */
21686d7f5d3SJohn Marino 
21786d7f5d3SJohn Marino struct wb_desc {
21886d7f5d3SJohn Marino 	uint32_t		wb_status;
21986d7f5d3SJohn Marino 	uint32_t		wb_ctl;
22086d7f5d3SJohn Marino 	uint32_t		wb_ptr1;
22186d7f5d3SJohn Marino 	uint32_t		wb_ptr2;
22286d7f5d3SJohn Marino };
22386d7f5d3SJohn Marino 
22486d7f5d3SJohn Marino #define wb_data		wb_ptr1
22586d7f5d3SJohn Marino #define wb_next		wb_ptr2
22686d7f5d3SJohn Marino 
22786d7f5d3SJohn Marino #define WB_RXSTAT_CRCERR	0x00000002
22886d7f5d3SJohn Marino #define WB_RXSTAT_DRIBBLE	0x00000004
22986d7f5d3SJohn Marino #define WB_RXSTAT_MIIERR	0x00000008
23086d7f5d3SJohn Marino #define WB_RXSTAT_LATEEVENT	0x00000040
23186d7f5d3SJohn Marino #define WB_RXSTAT_GIANT		0x00000080
23286d7f5d3SJohn Marino #define WB_RXSTAT_LASTFRAG	0x00000100
23386d7f5d3SJohn Marino #define WB_RXSTAT_FIRSTFRAG	0x00000200
23486d7f5d3SJohn Marino #define WB_RXSTAT_MULTICAST	0x00000400
23586d7f5d3SJohn Marino #define WB_RXSTAT_RUNT		0x00000800
23686d7f5d3SJohn Marino #define WB_RXSTAT_RXTYPE	0x00003000
23786d7f5d3SJohn Marino #define WB_RXSTAT_RXERR		0x00008000
23886d7f5d3SJohn Marino #define WB_RXSTAT_RXLEN		0x3FFF0000
23986d7f5d3SJohn Marino #define WB_RXSTAT_RXCMP		0x40000000
24086d7f5d3SJohn Marino #define WB_RXSTAT_OWN		0x80000000
24186d7f5d3SJohn Marino 
24286d7f5d3SJohn Marino #define WB_RXBYTES(x)		((x & WB_RXSTAT_RXLEN) >> 16)
24386d7f5d3SJohn Marino #define WB_RXSTAT (WB_RXSTAT_FIRSTFRAG|WB_RXSTAT_LASTFRAG|WB_RXSTAT_OWN)
24486d7f5d3SJohn Marino 
24586d7f5d3SJohn Marino #define WB_RXCTL_BUFLEN1	0x00000FFF
24686d7f5d3SJohn Marino #define WB_RXCTL_BUFLEN2	0x00FFF000
24786d7f5d3SJohn Marino #define WB_RXCTL_RLINK		0x01000000
24886d7f5d3SJohn Marino #define WB_RXCTL_RLAST		0x02000000
24986d7f5d3SJohn Marino 
25086d7f5d3SJohn Marino #define WB_TXSTAT_DEFER		0x00000001
25186d7f5d3SJohn Marino #define WB_TXSTAT_UNDERRUN	0x00000002
25286d7f5d3SJohn Marino #define WB_TXSTAT_COLLCNT	0x00000078
25386d7f5d3SJohn Marino #define WB_TXSTAT_SQE		0x00000080
25486d7f5d3SJohn Marino #define WB_TXSTAT_ABORT		0x00000100
25586d7f5d3SJohn Marino #define WB_TXSTAT_LATECOLL	0x00000200
25686d7f5d3SJohn Marino #define WB_TXSTAT_NOCARRIER	0x00000400
25786d7f5d3SJohn Marino #define WB_TXSTAT_CARRLOST	0x00000800
25886d7f5d3SJohn Marino #define WB_TXSTAT_TXERR		0x00001000
25986d7f5d3SJohn Marino #define WB_TXSTAT_OWN		0x80000000
26086d7f5d3SJohn Marino 
26186d7f5d3SJohn Marino #define WB_TXCTL_BUFLEN1	0x000007FF
26286d7f5d3SJohn Marino #define WB_TXCTL_BUFLEN2	0x003FF800
26386d7f5d3SJohn Marino #define WB_TXCTL_PAD		0x00800000
26486d7f5d3SJohn Marino #define WB_TXCTL_TLINK		0x01000000
26586d7f5d3SJohn Marino #define WB_TXCTL_TLAST		0x02000000
26686d7f5d3SJohn Marino #define WB_TXCTL_NOCRC		0x08000000
26786d7f5d3SJohn Marino #define WB_TXCTL_FIRSTFRAG	0x20000000
26886d7f5d3SJohn Marino #define WB_TXCTL_LASTFRAG	0x40000000
26986d7f5d3SJohn Marino #define WB_TXCTL_FINT		0x80000000
27086d7f5d3SJohn Marino 
27186d7f5d3SJohn Marino #define WB_MAXFRAGS		16
27286d7f5d3SJohn Marino #define WB_RX_LIST_CNT		64
27386d7f5d3SJohn Marino #define WB_TX_LIST_CNT		128
27486d7f5d3SJohn Marino #define WB_MIN_FRAMELEN		60
27586d7f5d3SJohn Marino #define ETHER_ALIGN		2
27686d7f5d3SJohn Marino 
27786d7f5d3SJohn Marino /*
27886d7f5d3SJohn Marino  * A transmit 'super descriptor' is actually WB_MAXFRAGS regular
27986d7f5d3SJohn Marino  * descriptors clumped together. The idea here is to emulate the
28086d7f5d3SJohn Marino  * multi-fragment descriptor layout found in devices such as the
28186d7f5d3SJohn Marino  * Texas Instruments ThunderLAN and 3Com boomerang and cylone chips.
28286d7f5d3SJohn Marino  * The advantage to using this scheme is that it avoids buffer copies.
28386d7f5d3SJohn Marino  * The disadvantage is that there's a certain amount of overhead due
28486d7f5d3SJohn Marino  * to the fact that each 'fragment' is 16 bytes long. In my tests,
28586d7f5d3SJohn Marino  * this limits top speed to about 10.5MB/sec. It should be more like
28686d7f5d3SJohn Marino  * 11.5MB/sec. However, the upshot is that you can achieve better
28786d7f5d3SJohn Marino  * results on slower machines: a Pentium 200 can pump out packets at
28886d7f5d3SJohn Marino  * same speed as a PII 400.
28986d7f5d3SJohn Marino  */
29086d7f5d3SJohn Marino struct wb_txdesc {
29186d7f5d3SJohn Marino 	struct wb_desc		wb_frag[WB_MAXFRAGS];
29286d7f5d3SJohn Marino };
29386d7f5d3SJohn Marino 
29486d7f5d3SJohn Marino #define WB_TXNEXT(x)	x->wb_ptr->wb_frag[x->wb_lastdesc].wb_next
29586d7f5d3SJohn Marino #define WB_TXSTATUS(x)	x->wb_ptr->wb_frag[x->wb_lastdesc].wb_status
29686d7f5d3SJohn Marino #define WB_TXCTL(x)	x->wb_ptr->wb_frag[x->wb_lastdesc].wb_ctl
29786d7f5d3SJohn Marino #define WB_TXDATA(x)	x->wb_ptr->wb_frag[x->wb_lastdesc].wb_data
29886d7f5d3SJohn Marino 
29986d7f5d3SJohn Marino #define WB_TXOWN(x)	x->wb_ptr->wb_frag[0].wb_status
30086d7f5d3SJohn Marino 
30186d7f5d3SJohn Marino #define WB_UNSENT	0x1234
30286d7f5d3SJohn Marino 
30386d7f5d3SJohn Marino #define WB_BUFBYTES	(1024 * sizeof(uint32_t))
30486d7f5d3SJohn Marino 
30586d7f5d3SJohn Marino struct wb_buf {
30686d7f5d3SJohn Marino 	uint32_t		wb_data[1024];
30786d7f5d3SJohn Marino };
30886d7f5d3SJohn Marino 
30986d7f5d3SJohn Marino struct wb_list_data {
31086d7f5d3SJohn Marino 	struct wb_buf		wb_rxbufs[WB_RX_LIST_CNT];
31186d7f5d3SJohn Marino 	struct wb_desc		wb_rx_list[WB_RX_LIST_CNT];
31286d7f5d3SJohn Marino 	struct wb_txdesc	wb_tx_list[WB_TX_LIST_CNT];
31386d7f5d3SJohn Marino };
31486d7f5d3SJohn Marino 
31586d7f5d3SJohn Marino struct wb_chain {
31686d7f5d3SJohn Marino 	struct wb_txdesc	*wb_ptr;
31786d7f5d3SJohn Marino 	struct mbuf		*wb_mbuf;
31886d7f5d3SJohn Marino 	struct wb_chain		*wb_nextdesc;
31986d7f5d3SJohn Marino 	uint8_t			wb_lastdesc;
32086d7f5d3SJohn Marino };
32186d7f5d3SJohn Marino 
32286d7f5d3SJohn Marino struct wb_chain_onefrag {
32386d7f5d3SJohn Marino 	struct wb_desc		*wb_ptr;
32486d7f5d3SJohn Marino 	struct mbuf		*wb_mbuf;
32586d7f5d3SJohn Marino 	void			*wb_buf;
32686d7f5d3SJohn Marino 	struct wb_chain_onefrag	*wb_nextdesc;
32786d7f5d3SJohn Marino 	uint8_t			wb_rlast;
32886d7f5d3SJohn Marino };
32986d7f5d3SJohn Marino 
33086d7f5d3SJohn Marino struct wb_chain_data {
33186d7f5d3SJohn Marino 	uint8_t			wb_pad[WB_MIN_FRAMELEN];
33286d7f5d3SJohn Marino 	struct wb_chain_onefrag	wb_rx_chain[WB_RX_LIST_CNT];
33386d7f5d3SJohn Marino 	struct wb_chain		wb_tx_chain[WB_TX_LIST_CNT];
33486d7f5d3SJohn Marino 
33586d7f5d3SJohn Marino 	struct wb_chain_onefrag	*wb_rx_head;
33686d7f5d3SJohn Marino 
33786d7f5d3SJohn Marino 	struct wb_chain		*wb_tx_head;
33886d7f5d3SJohn Marino 	struct wb_chain		*wb_tx_tail;
33986d7f5d3SJohn Marino 	struct wb_chain		*wb_tx_free;
34086d7f5d3SJohn Marino };
34186d7f5d3SJohn Marino 
34286d7f5d3SJohn Marino struct wb_type {
34386d7f5d3SJohn Marino 	uint16_t		wb_vid;
34486d7f5d3SJohn Marino 	uint16_t		wb_did;
34586d7f5d3SJohn Marino 	char			*wb_name;
34686d7f5d3SJohn Marino };
34786d7f5d3SJohn Marino 
34886d7f5d3SJohn Marino struct wb_mii_frame {
34986d7f5d3SJohn Marino 	uint8_t			mii_stdelim;
35086d7f5d3SJohn Marino 	uint8_t			mii_opcode;
35186d7f5d3SJohn Marino 	uint8_t			mii_phyaddr;
35286d7f5d3SJohn Marino 	uint8_t			mii_regaddr;
35386d7f5d3SJohn Marino 	uint8_t			mii_turnaround;
35486d7f5d3SJohn Marino 	uint16_t		mii_data;
35586d7f5d3SJohn Marino };
35686d7f5d3SJohn Marino 
35786d7f5d3SJohn Marino /*
35886d7f5d3SJohn Marino  * MII constants
35986d7f5d3SJohn Marino  */
36086d7f5d3SJohn Marino #define WB_MII_STARTDELIM	0x01
36186d7f5d3SJohn Marino #define WB_MII_READOP		0x02
36286d7f5d3SJohn Marino #define WB_MII_WRITEOP		0x01
36386d7f5d3SJohn Marino #define WB_MII_TURNAROUND	0x02
36486d7f5d3SJohn Marino 
36586d7f5d3SJohn Marino struct wb_softc {
36686d7f5d3SJohn Marino 	struct arpcom		arpcom;		/* interface info */
36786d7f5d3SJohn Marino 	device_t		wb_miibus;
36886d7f5d3SJohn Marino 	bus_space_handle_t	wb_bhandle;
36986d7f5d3SJohn Marino 	bus_space_tag_t		wb_btag;
37086d7f5d3SJohn Marino 	struct resource		*wb_res;
37186d7f5d3SJohn Marino 	struct resource		*wb_irq;
37286d7f5d3SJohn Marino 	void			*wb_intrhand;
37386d7f5d3SJohn Marino 	struct wb_type		*wb_info;	/* Winbond adapter info */
37486d7f5d3SJohn Marino 	uint8_t			wb_type;
37586d7f5d3SJohn Marino 	uint16_t		wb_txthresh;
37686d7f5d3SJohn Marino 	int			wb_cachesize;
37786d7f5d3SJohn Marino 	caddr_t			wb_ldata_ptr;
37886d7f5d3SJohn Marino 	struct wb_list_data	*wb_ldata;
37986d7f5d3SJohn Marino 	struct wb_chain_data	wb_cdata;
38086d7f5d3SJohn Marino 	struct callout		wb_stat_timer;
38186d7f5d3SJohn Marino };
38286d7f5d3SJohn Marino 
38386d7f5d3SJohn Marino /*
38486d7f5d3SJohn Marino  * register space access macros
38586d7f5d3SJohn Marino  */
38686d7f5d3SJohn Marino #define CSR_WRITE_4(sc, reg, val)	\
38786d7f5d3SJohn Marino 	bus_space_write_4(sc->wb_btag, sc->wb_bhandle, reg, val)
38886d7f5d3SJohn Marino #define CSR_WRITE_2(sc, reg, val)	\
38986d7f5d3SJohn Marino 	bus_space_write_2(sc->wb_btag, sc->wb_bhandle, reg, val)
39086d7f5d3SJohn Marino #define CSR_WRITE_1(sc, reg, val)	\
39186d7f5d3SJohn Marino 	bus_space_write_1(sc->wb_btag, sc->wb_bhandle, reg, val)
39286d7f5d3SJohn Marino 
39386d7f5d3SJohn Marino #define CSR_READ_4(sc, reg)	\
39486d7f5d3SJohn Marino 	bus_space_read_4(sc->wb_btag, sc->wb_bhandle, reg)
39586d7f5d3SJohn Marino #define CSR_READ_2(sc, reg)	\
39686d7f5d3SJohn Marino 	bus_space_read_2(sc->wb_btag, sc->wb_bhandle, reg)
39786d7f5d3SJohn Marino #define CSR_READ_1(sc, reg)	\
39886d7f5d3SJohn Marino 	bus_space_read_1(sc->wb_btag, sc->wb_bhandle, reg)
39986d7f5d3SJohn Marino 
40086d7f5d3SJohn Marino #define WB_TIMEOUT		1000
40186d7f5d3SJohn Marino 
40286d7f5d3SJohn Marino /*
40386d7f5d3SJohn Marino  * General constants that are fun to know.
40486d7f5d3SJohn Marino  *
40586d7f5d3SJohn Marino  * PCI low memory base and low I/O base register, and
40686d7f5d3SJohn Marino  * other PCI registers.
40786d7f5d3SJohn Marino  */
40886d7f5d3SJohn Marino 
40986d7f5d3SJohn Marino #define WB_PCI_VENDOR_ID	0x00
41086d7f5d3SJohn Marino #define WB_PCI_DEVICE_ID	0x02
41186d7f5d3SJohn Marino #define WB_PCI_COMMAND		0x04
41286d7f5d3SJohn Marino #define WB_PCI_STATUS		0x06
41386d7f5d3SJohn Marino #define WB_PCI_CLASSCODE	0x09
41486d7f5d3SJohn Marino #define WB_PCI_CACHELEN		0x0C
41586d7f5d3SJohn Marino #define WB_PCI_LATENCY_TIMER	0x0D
41686d7f5d3SJohn Marino #define WB_PCI_HEADER_TYPE	0x0E
41786d7f5d3SJohn Marino #define WB_PCI_LOIO		0x10
41886d7f5d3SJohn Marino #define WB_PCI_LOMEM		0x14
41986d7f5d3SJohn Marino #define WB_PCI_BIOSROM		0x30
42086d7f5d3SJohn Marino #define WB_PCI_INTLINE		0x3C
42186d7f5d3SJohn Marino #define WB_PCI_INTPIN		0x3D
42286d7f5d3SJohn Marino #define WB_PCI_MINGNT		0x3E
42386d7f5d3SJohn Marino #define WB_PCI_MINLAT		0x0F
42486d7f5d3SJohn Marino #define WB_PCI_RESETOPT		0x48
42586d7f5d3SJohn Marino #define WB_PCI_EEPROM_DATA	0x4C
42686d7f5d3SJohn Marino 
42786d7f5d3SJohn Marino /* power management registers */
42886d7f5d3SJohn Marino #define WB_PCI_CAPID		0xDC /* 8 bits */
42986d7f5d3SJohn Marino #define WB_PCI_NEXTPTR		0xDD /* 8 bits */
43086d7f5d3SJohn Marino #define WB_PCI_PWRMGMTCAP	0xDE /* 16 bits */
43186d7f5d3SJohn Marino #define WB_PCI_PWRMGMTCTRL	0xE0 /* 16 bits */
43286d7f5d3SJohn Marino 
43386d7f5d3SJohn Marino #define WB_PME_EN		0x0010
43486d7f5d3SJohn Marino #define WB_PME_STATUS		0x8000
435