Home | History | Annotate | Line # | Download | only in ic
rtl81x9var.h revision 1.10.20.2
      1  1.10.20.1    skrll /*	$NetBSD: rtl81x9var.h,v 1.10.20.2 2004/09/18 14:46:00 skrll Exp $	*/
      2        1.1  tsutsui 
      3        1.1  tsutsui /*
      4        1.1  tsutsui  * Copyright (c) 1997, 1998
      5        1.1  tsutsui  *	Bill Paul <wpaul (at) ctr.columbia.edu>.  All rights reserved.
      6        1.1  tsutsui  *
      7        1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      8        1.1  tsutsui  * modification, are permitted provided that the following conditions
      9        1.1  tsutsui  * are met:
     10        1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     11        1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     12        1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     14        1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     15        1.1  tsutsui  * 3. All advertising materials mentioning features or use of this software
     16        1.1  tsutsui  *    must display the following acknowledgement:
     17        1.1  tsutsui  *	This product includes software developed by Bill Paul.
     18        1.1  tsutsui  * 4. Neither the name of the author nor the names of any co-contributors
     19        1.1  tsutsui  *    may be used to endorse or promote products derived from this software
     20        1.1  tsutsui  *    without specific prior written permission.
     21        1.1  tsutsui  *
     22        1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     23        1.1  tsutsui  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24        1.1  tsutsui  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25        1.1  tsutsui  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
     26        1.1  tsutsui  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27        1.1  tsutsui  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28        1.1  tsutsui  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29        1.1  tsutsui  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30        1.1  tsutsui  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31        1.1  tsutsui  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     32        1.1  tsutsui  * THE POSSIBILITY OF SUCH DAMAGE.
     33        1.1  tsutsui  *
     34        1.1  tsutsui  *	FreeBSD Id: if_rlreg.h,v 1.9 1999/06/20 18:56:09 wpaul Exp
     35        1.1  tsutsui  */
     36        1.1  tsutsui 
     37        1.5  tsutsui #define RTK_ETHER_ALIGN	2
     38        1.6  tsutsui #define RTK_RXSTAT_LEN	4
     39        1.1  tsutsui 
     40        1.4  thorpej struct rtk_type {
     41        1.4  thorpej 	u_int16_t		rtk_vid;
     42        1.4  thorpej 	u_int16_t		rtk_did;
     43  1.10.20.1    skrll 	int			rtk_basetype;
     44        1.4  thorpej 	const char		*rtk_name;
     45  1.10.20.1    skrll };
     46  1.10.20.1    skrll 
     47  1.10.20.1    skrll struct rtk_hwrev {
     48  1.10.20.1    skrll 	uint32_t		rtk_rev;
     49        1.4  thorpej 	int			rtk_type;
     50  1.10.20.1    skrll 	char			*rtk_desc;
     51        1.1  tsutsui };
     52        1.1  tsutsui 
     53        1.4  thorpej struct rtk_mii_frame {
     54        1.1  tsutsui 	u_int8_t		mii_stdelim;
     55        1.1  tsutsui 	u_int8_t		mii_opcode;
     56        1.1  tsutsui 	u_int8_t		mii_phyaddr;
     57        1.1  tsutsui 	u_int8_t		mii_regaddr;
     58        1.1  tsutsui 	u_int8_t		mii_turnaround;
     59        1.1  tsutsui 	u_int16_t		mii_data;
     60        1.1  tsutsui };
     61        1.1  tsutsui 
     62        1.1  tsutsui /*
     63        1.1  tsutsui  * MII constants
     64        1.1  tsutsui  */
     65        1.5  tsutsui #define RTK_MII_STARTDELIM	0x01
     66        1.5  tsutsui #define RTK_MII_READOP		0x02
     67        1.5  tsutsui #define RTK_MII_WRITEOP		0x01
     68        1.5  tsutsui #define RTK_MII_TURNAROUND	0x02
     69        1.1  tsutsui 
     70        1.5  tsutsui #define RTK_8129		1
     71        1.5  tsutsui #define RTK_8139		2
     72  1.10.20.1    skrll #define RTK_8139CPLUS		3
     73  1.10.20.1    skrll #define RTK_8169		4
     74  1.10.20.1    skrll 
     75  1.10.20.1    skrll #define RTK_ISCPLUS(x)	((x)->rtk_type == RTK_8139CPLUS || \
     76  1.10.20.1    skrll 			 (x)->rtk_type == RTK_8169)
     77  1.10.20.1    skrll 
     78  1.10.20.1    skrll /*
     79  1.10.20.1    skrll  * The 8139C+ and 8160 gigE chips support descriptor-based TX
     80  1.10.20.1    skrll  * and RX. In fact, they even support TCP large send. Descriptors
     81  1.10.20.1    skrll  * must be allocated in contiguous blocks that are aligned on a
     82  1.10.20.1    skrll  * 256-byte boundary. The rings can hold a maximum of 64 descriptors.
     83  1.10.20.1    skrll  */
     84        1.1  tsutsui 
     85  1.10.20.1    skrll struct rtk_list_data {
     86  1.10.20.1    skrll 	struct mbuf		*rtk_tx_mbuf[RTK_TX_DESC_CNT];
     87  1.10.20.1    skrll 	struct mbuf		*rtk_rx_mbuf[RTK_RX_DESC_CNT];
     88  1.10.20.1    skrll 	int			rtk_tx_prodidx;
     89  1.10.20.1    skrll 	int			rtk_rx_prodidx;
     90  1.10.20.1    skrll 	int			rtk_tx_considx;
     91  1.10.20.1    skrll 	int			rtk_tx_free;
     92  1.10.20.1    skrll 	bus_dmamap_t		rtk_tx_dmamap[RTK_TX_DESC_CNT];
     93  1.10.20.1    skrll 	bus_dmamap_t		rtk_rx_dmamap[RTK_RX_DESC_CNT];
     94  1.10.20.1    skrll 	bus_dmamap_t		rtk_rx_list_map;
     95  1.10.20.1    skrll 	struct rtk_desc		*rtk_rx_list;
     96  1.10.20.1    skrll 	bus_dma_segment_t 	rtk_rx_listseg;
     97  1.10.20.1    skrll 	bus_dmamap_t		rtk_tx_list_map;
     98  1.10.20.1    skrll 	struct rtk_desc		*rtk_tx_list;
     99  1.10.20.1    skrll 	bus_dma_segment_t 	rtk_tx_listseg;
    100  1.10.20.1    skrll };
    101        1.9  thorpej struct rtk_tx_desc {
    102        1.9  thorpej 	SIMPLEQ_ENTRY(rtk_tx_desc) txd_q;
    103        1.9  thorpej 	struct mbuf		*txd_mbuf;
    104        1.9  thorpej 	bus_dmamap_t		txd_dmamap;
    105        1.9  thorpej 	bus_addr_t		txd_txaddr;
    106        1.9  thorpej 	bus_addr_t		txd_txstat;
    107        1.9  thorpej };
    108        1.9  thorpej 
    109        1.4  thorpej struct rtk_softc {
    110        1.1  tsutsui 	struct device sc_dev;		/* generic device structures */
    111        1.5  tsutsui 	struct ethercom		ethercom;	/* interface info */
    112        1.1  tsutsui 	struct mii_data		mii;
    113        1.4  thorpej 	struct callout		rtk_tick_ch;	/* tick callout */
    114        1.4  thorpej 	bus_space_handle_t	rtk_bhandle;	/* bus space handle */
    115        1.4  thorpej 	bus_space_tag_t		rtk_btag;	/* bus space tag */
    116        1.7  tsutsui 	int			rtk_type;
    117        1.5  tsutsui 	bus_dma_tag_t 		sc_dmat;
    118        1.5  tsutsui 	bus_dma_segment_t 	sc_dmaseg;
    119        1.5  tsutsui 	int			sc_dmanseg;
    120        1.8  thorpej 
    121        1.8  thorpej 	bus_dmamap_t 		recv_dmamap;
    122        1.8  thorpej 	caddr_t			rtk_rx_buf;
    123        1.8  thorpej 
    124        1.9  thorpej 	struct rtk_tx_desc	rtk_tx_descs[RTK_TX_LIST_CNT];
    125        1.9  thorpej 	SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_free;
    126        1.9  thorpej 	SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_dirty;
    127  1.10.20.1    skrll 	struct rtk_list_data	rtk_ldata;
    128  1.10.20.1    skrll 	struct mbuf		*rtk_head;
    129  1.10.20.1    skrll 	struct mbuf		*rtk_tail;
    130  1.10.20.1    skrll 	u_int32_t		rtk_rxlenmask;
    131  1.10.20.1    skrll 	int			rtk_testmode;
    132        1.5  tsutsui 
    133        1.5  tsutsui 	int			sc_flags;	/* misc flags */
    134       1.10  kanaoka 	int			sc_txthresh;	/* Early tx threshold */
    135       1.10  kanaoka 
    136        1.5  tsutsui 	void	*sc_sdhook;			/* shutdown hook */
    137        1.5  tsutsui 	void	*sc_powerhook;			/* power management hook */
    138        1.5  tsutsui 
    139        1.5  tsutsui 	/* Power management hooks. */
    140        1.5  tsutsui 	int	(*sc_enable)	__P((struct rtk_softc *));
    141        1.5  tsutsui 	void	(*sc_disable)	__P((struct rtk_softc *));
    142        1.5  tsutsui 	void	(*sc_power)	__P((struct rtk_softc *, int));
    143        1.1  tsutsui };
    144        1.1  tsutsui 
    145        1.5  tsutsui #define RTK_ATTACHED 0x00000001 /* attach has succeeded */
    146        1.5  tsutsui #define RTK_ENABLED  0x00000002 /* chip is enabled	*/
    147        1.5  tsutsui 
    148        1.5  tsutsui #define RTK_IS_ENABLED(sc)	((sc)->sc_flags & RTK_ENABLED)
    149       1.10  kanaoka #define RTK_TX_THRESH(sc)	(((sc)->sc_txthresh << 16) & 0x003F0000)
    150       1.10  kanaoka 
    151       1.10  kanaoka #define TXTH_256	8
    152       1.10  kanaoka #define TXTH_MAX	48
    153       1.10  kanaoka 
    154        1.1  tsutsui /*
    155        1.1  tsutsui  * register space access macros
    156        1.1  tsutsui  */
    157        1.1  tsutsui #define CSR_WRITE_4(sc, reg, val)	\
    158        1.4  thorpej 	bus_space_write_4(sc->rtk_btag, sc->rtk_bhandle, reg, val)
    159        1.1  tsutsui #define CSR_WRITE_2(sc, reg, val)	\
    160        1.4  thorpej 	bus_space_write_2(sc->rtk_btag, sc->rtk_bhandle, reg, val)
    161        1.1  tsutsui #define CSR_WRITE_1(sc, reg, val)	\
    162        1.4  thorpej 	bus_space_write_1(sc->rtk_btag, sc->rtk_bhandle, reg, val)
    163  1.10.20.1    skrll #define CSR_WRITE_STREAM_4(sc, reg, val)	\
    164  1.10.20.1    skrll 	bus_space_write_stream_4(sc->rtk_btag, sc->rtk_bhandle, reg, val)
    165  1.10.20.1    skrll 
    166        1.1  tsutsui 
    167        1.1  tsutsui #define CSR_READ_4(sc, reg)		\
    168        1.4  thorpej 	bus_space_read_4(sc->rtk_btag, sc->rtk_bhandle, reg)
    169        1.1  tsutsui #define CSR_READ_2(sc, reg)		\
    170        1.4  thorpej 	bus_space_read_2(sc->rtk_btag, sc->rtk_bhandle, reg)
    171        1.1  tsutsui #define CSR_READ_1(sc, reg)		\
    172        1.4  thorpej 	bus_space_read_1(sc->rtk_btag, sc->rtk_bhandle, reg)
    173        1.1  tsutsui 
    174        1.5  tsutsui #define RTK_TIMEOUT		1000
    175        1.1  tsutsui 
    176        1.1  tsutsui /*
    177        1.1  tsutsui  * PCI low memory base and low I/O base register, and
    178        1.1  tsutsui  * other PCI registers.
    179        1.1  tsutsui  */
    180        1.1  tsutsui 
    181        1.5  tsutsui #define RTK_PCI_LOIO		0x10
    182        1.5  tsutsui #define RTK_PCI_LOMEM		0x14
    183        1.1  tsutsui 
    184        1.5  tsutsui #define RTK_PSTATE_MASK		0x0003
    185        1.5  tsutsui #define RTK_PSTATE_D0		0x0000
    186        1.5  tsutsui #define RTK_PSTATE_D1		0x0002
    187        1.5  tsutsui #define RTK_PSTATE_D2		0x0002
    188        1.5  tsutsui #define RTK_PSTATE_D3		0x0003
    189        1.5  tsutsui #define RTK_PME_EN		0x0010
    190        1.5  tsutsui #define RTK_PME_STATUS		0x8000
    191        1.1  tsutsui 
    192        1.1  tsutsui #ifdef _KERNEL
    193  1.10.20.1    skrll u_int16_t rtk_read_eeprom __P((struct rtk_softc *, int, int));
    194  1.10.20.1    skrll void	rtk_setmulti	__P((struct rtk_softc *));
    195        1.5  tsutsui void	rtk_attach	__P((struct rtk_softc *));
    196        1.5  tsutsui int	rtk_detach	__P((struct rtk_softc *));
    197        1.5  tsutsui int	rtk_activate	__P((struct device *, enum devact));
    198        1.5  tsutsui int	rtk_intr	__P((void *));
    199        1.1  tsutsui #endif /* _KERNEL */
    200