Home | History | Annotate | Line # | Download | only in ic
rtl81x9var.h revision 1.35
      1  1.35   tsutsui /*	$NetBSD: rtl81x9var.h,v 1.35 2006/11/17 21:29:36 tsutsui 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.16       dan #include "rnd.h"
     38  1.16       dan 
     39  1.16       dan #if NRND > 0
     40  1.16       dan #include <sys/rnd.h>
     41  1.16       dan #endif
     42  1.16       dan 
     43  1.32   tsutsui #define RTK_ETHER_ALIGN	2
     44  1.32   tsutsui #define RTK_RXSTAT_LEN	4
     45  1.32   tsutsui 
     46  1.22   tsutsui #ifdef __NO_STRICT_ALIGNMENT
     47  1.32   tsutsui /*
     48  1.32   tsutsui  * XXX According to PR kern/33763, some 8168 and variants can't DMA
     49  1.32   tsutsui  * XXX RX packet data into unaligned buffer. This means such chips will
     50  1.32   tsutsui  * XXX never work on !__NO_STRICT_ALIGNMENT hosts without copying buffer.
     51  1.32   tsutsui  */
     52  1.32   tsutsui #define RE_ETHER_ALIGN	0
     53  1.21  christos #else
     54  1.32   tsutsui #define RE_ETHER_ALIGN	2
     55  1.21  christos #endif
     56   1.1   tsutsui 
     57   1.4   thorpej struct rtk_type {
     58  1.24   tsutsui 	uint16_t		rtk_vid;
     59  1.24   tsutsui 	uint16_t		rtk_did;
     60  1.11      fvdl 	int			rtk_basetype;
     61   1.4   thorpej 	const char		*rtk_name;
     62  1.11      fvdl };
     63  1.11      fvdl 
     64  1.11      fvdl struct rtk_hwrev {
     65  1.11      fvdl 	uint32_t		rtk_rev;
     66   1.4   thorpej 	int			rtk_type;
     67  1.19  christos 	const char		*rtk_desc;
     68   1.1   tsutsui };
     69   1.1   tsutsui 
     70  1.30   tsutsui #define RTK_8129		1
     71  1.30   tsutsui #define RTK_8139		2
     72  1.30   tsutsui #define RTK_8139CPLUS		3
     73  1.30   tsutsui #define RTK_8169		4
     74  1.30   tsutsui 
     75  1.30   tsutsui #define RTK_ISCPLUS(x)	((x)->rtk_type == RTK_8139CPLUS || \
     76  1.30   tsutsui 			 (x)->rtk_type == RTK_8169)
     77  1.30   tsutsui 
     78  1.30   tsutsui 
     79   1.4   thorpej struct rtk_mii_frame {
     80  1.24   tsutsui 	uint8_t			mii_stdelim;
     81  1.24   tsutsui 	uint8_t			mii_opcode;
     82  1.24   tsutsui 	uint8_t			mii_phyaddr;
     83  1.24   tsutsui 	uint8_t			mii_regaddr;
     84  1.24   tsutsui 	uint8_t			mii_turnaround;
     85  1.24   tsutsui 	uint16_t		mii_data;
     86   1.1   tsutsui };
     87   1.1   tsutsui 
     88   1.1   tsutsui /*
     89   1.1   tsutsui  * MII constants
     90   1.1   tsutsui  */
     91   1.5   tsutsui #define RTK_MII_STARTDELIM	0x01
     92   1.5   tsutsui #define RTK_MII_READOP		0x02
     93   1.5   tsutsui #define RTK_MII_WRITEOP		0x01
     94   1.5   tsutsui #define RTK_MII_TURNAROUND	0x02
     95   1.1   tsutsui 
     96  1.11      fvdl 
     97  1.30   tsutsui /*
     98  1.30   tsutsui  * The RealTek doesn't use a fragment-based descriptor mechanism.
     99  1.30   tsutsui  * Instead, there are only four register sets, each or which represents
    100  1.30   tsutsui  * one 'descriptor.' Basically, each TX descriptor is just a contiguous
    101  1.30   tsutsui  * packet buffer (32-bit aligned!) and we place the buffer addresses in
    102  1.30   tsutsui  * the registers so the chip knows where they are.
    103  1.30   tsutsui  *
    104  1.30   tsutsui  * We can sort of kludge together the same kind of buffer management
    105  1.30   tsutsui  * used in previous drivers, but we have to do buffer copies almost all
    106  1.30   tsutsui  * the time, so it doesn't really buy us much.
    107  1.30   tsutsui  *
    108  1.30   tsutsui  * For reception, there's just one large buffer where the chip stores
    109  1.30   tsutsui  * all received packets.
    110  1.30   tsutsui  */
    111   1.1   tsutsui 
    112  1.30   tsutsui #ifdef dreamcast
    113  1.32   tsutsui /*
    114  1.32   tsutsui  * XXX dreamcast has only 32KB DMA'able memory on its PCI bridge.
    115  1.32   tsutsui  * XXX Maybe this should be handled by prop_dictionary, or
    116  1.32   tsutsui  * XXX some other new API which returns available DMA resources.
    117  1.32   tsutsui  */
    118  1.30   tsutsui #define RTK_RX_BUF_SZ		RTK_RXBUF_16
    119  1.30   tsutsui #else
    120  1.30   tsutsui #define RTK_RX_BUF_SZ		RTK_RXBUF_64
    121  1.30   tsutsui #endif
    122  1.30   tsutsui #define RTK_RXBUFLEN		RTK_RXBUF_LEN(RTK_RX_BUF_SZ)
    123  1.30   tsutsui #define RTK_TX_LIST_CNT		4
    124  1.18      yamt 
    125  1.12    toshii /*
    126  1.30   tsutsui  * The 8139C+ and 8169 gigE chips support descriptor-based TX
    127  1.12    toshii  * and RX. In fact, they even support TCP large send. Descriptors
    128  1.12    toshii  * must be allocated in contiguous blocks that are aligned on a
    129  1.30   tsutsui  * 256-byte boundary. The RX rings can hold a maximum of 64 descriptors.
    130  1.30   tsutsui  * The TX rings can hold upto 64 descriptors on 8139C+, and
    131  1.30   tsutsui  * 1024 descriptors on 8169 gigE chips.
    132  1.12    toshii  */
    133  1.32   tsutsui #define RE_RING_ALIGN		256
    134  1.30   tsutsui 
    135  1.32   tsutsui #define RE_RX_DESC_CNT		64
    136  1.32   tsutsui #define RE_TX_DESC_CNT_8139	64
    137  1.32   tsutsui #define RE_TX_DESC_CNT_8169	1024
    138  1.32   tsutsui #define RE_TX_QLEN		64
    139  1.12    toshii 
    140  1.34   tsutsui #define RE_NTXDESC_RSVD		4
    141  1.34   tsutsui 
    142  1.32   tsutsui struct re_rxsoft {
    143  1.28   tsutsui 	struct mbuf		*rxs_mbuf;
    144  1.28   tsutsui 	bus_dmamap_t		rxs_dmamap;
    145  1.28   tsutsui };
    146  1.28   tsutsui 
    147  1.33   tsutsui struct re_txq {
    148  1.33   tsutsui 	struct mbuf *txq_mbuf;
    149  1.33   tsutsui 	bus_dmamap_t txq_dmamap;
    150  1.33   tsutsui 	int txq_descidx;
    151  1.35   tsutsui 	int txq_nsegs;
    152  1.33   tsutsui };
    153  1.33   tsutsui 
    154  1.32   tsutsui struct re_list_data {
    155  1.33   tsutsui 	struct re_txq		re_txq[RE_TX_QLEN];
    156  1.32   tsutsui 	int			re_txq_considx;
    157  1.32   tsutsui 	int			re_txq_prodidx;
    158  1.34   tsutsui 	int			re_txq_free;
    159  1.33   tsutsui 
    160  1.32   tsutsui 	bus_dmamap_t		re_tx_list_map;
    161  1.32   tsutsui 	struct re_desc		*re_tx_list;
    162  1.32   tsutsui 	int			re_tx_free;	/* # of free descriptors */
    163  1.32   tsutsui 	int			re_tx_nextfree; /* next descriptor to use */
    164  1.32   tsutsui 	int			re_tx_desc_cnt; /* # of descriptors */
    165  1.33   tsutsui 	bus_dma_segment_t 	re_tx_listseg;
    166  1.32   tsutsui 	int			re_tx_listnseg;
    167  1.32   tsutsui 
    168  1.32   tsutsui 	struct re_rxsoft	re_rxsoft[RE_RX_DESC_CNT];
    169  1.32   tsutsui 	bus_dmamap_t		re_rx_list_map;
    170  1.32   tsutsui 	struct re_desc		*re_rx_list;
    171  1.33   tsutsui 	int			re_rx_prodidx;
    172  1.32   tsutsui 	bus_dma_segment_t 	re_rx_listseg;
    173  1.32   tsutsui 	int			re_rx_listnseg;
    174  1.12    toshii };
    175  1.32   tsutsui 
    176   1.9   thorpej struct rtk_tx_desc {
    177   1.9   thorpej 	SIMPLEQ_ENTRY(rtk_tx_desc) txd_q;
    178   1.9   thorpej 	struct mbuf		*txd_mbuf;
    179   1.9   thorpej 	bus_dmamap_t		txd_dmamap;
    180   1.9   thorpej 	bus_addr_t		txd_txaddr;
    181   1.9   thorpej 	bus_addr_t		txd_txstat;
    182   1.9   thorpej };
    183   1.9   thorpej 
    184   1.4   thorpej struct rtk_softc {
    185   1.1   tsutsui 	struct device sc_dev;		/* generic device structures */
    186   1.5   tsutsui 	struct ethercom		ethercom;	/* interface info */
    187   1.1   tsutsui 	struct mii_data		mii;
    188   1.4   thorpej 	struct callout		rtk_tick_ch;	/* tick callout */
    189   1.4   thorpej 	bus_space_handle_t	rtk_bhandle;	/* bus space handle */
    190   1.4   thorpej 	bus_space_tag_t		rtk_btag;	/* bus space tag */
    191   1.7   tsutsui 	int			rtk_type;
    192   1.5   tsutsui 	bus_dma_tag_t 		sc_dmat;
    193   1.8   thorpej 
    194  1.32   tsutsui 	bus_dma_segment_t 	sc_dmaseg;	/* for rtk(4) */
    195  1.32   tsutsui 	int			sc_dmanseg;	/* for rtk(4) */
    196  1.32   tsutsui 
    197  1.32   tsutsui 	bus_dmamap_t 		recv_dmamap;	/* for rtk(4) */
    198   1.8   thorpej 	caddr_t			rtk_rx_buf;
    199   1.8   thorpej 
    200   1.9   thorpej 	struct rtk_tx_desc	rtk_tx_descs[RTK_TX_LIST_CNT];
    201   1.9   thorpej 	SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_free;
    202   1.9   thorpej 	SIMPLEQ_HEAD(, rtk_tx_desc) rtk_tx_dirty;
    203  1.32   tsutsui 
    204  1.32   tsutsui 	struct re_list_data	re_ldata;
    205  1.32   tsutsui 	struct mbuf		*re_head;
    206  1.32   tsutsui 	struct mbuf		*re_tail;
    207  1.32   tsutsui 	uint32_t		re_rxlenmask;
    208  1.32   tsutsui 	int			re_testmode;
    209   1.5   tsutsui 
    210   1.5   tsutsui 	int			sc_flags;	/* misc flags */
    211  1.10   kanaoka 	int			sc_txthresh;	/* Early tx threshold */
    212  1.14  jonathan 	int			sc_rev;		/* revision within rtk_type */
    213  1.10   kanaoka 
    214   1.5   tsutsui 	void	*sc_sdhook;			/* shutdown hook */
    215   1.5   tsutsui 	void	*sc_powerhook;			/* power management hook */
    216   1.5   tsutsui 
    217   1.5   tsutsui 	/* Power management hooks. */
    218  1.17     perry 	int	(*sc_enable)	(struct rtk_softc *);
    219  1.17     perry 	void	(*sc_disable)	(struct rtk_softc *);
    220  1.17     perry 	void	(*sc_power)	(struct rtk_softc *, int);
    221  1.16       dan #if NRND > 0
    222  1.16       dan 	rndsource_element_t     rnd_source;
    223  1.16       dan #endif
    224   1.1   tsutsui };
    225   1.1   tsutsui 
    226  1.32   tsutsui #define RE_TX_DESC_CNT(sc)	((sc)->re_ldata.re_tx_desc_cnt)
    227  1.32   tsutsui #define RE_TX_LIST_SZ(sc)	(RE_TX_DESC_CNT(sc) * sizeof(struct re_desc))
    228  1.32   tsutsui #define RE_NEXT_TX_DESC(sc, x)	(((x) + 1) % RE_TX_DESC_CNT(sc))
    229  1.30   tsutsui 
    230  1.32   tsutsui #define RE_RX_LIST_SZ		(RE_RX_DESC_CNT * sizeof(struct re_desc))
    231  1.32   tsutsui #define RE_NEXT_RX_DESC(sc, x)	(((x) + 1) % RE_RX_DESC_CNT)
    232  1.30   tsutsui 
    233  1.32   tsutsui #define RE_NEXT_TXQ(sc, x)	(((x) + 1) % RE_TX_QLEN)
    234  1.18      yamt 
    235  1.32   tsutsui #define RE_TXDESCSYNC(sc, idx, ops)					\
    236  1.23   tsutsui 	bus_dmamap_sync((sc)->sc_dmat,					\
    237  1.32   tsutsui 	    (sc)->re_ldata.re_tx_list_map,				\
    238  1.32   tsutsui 	    sizeof(struct re_desc) * (idx),				\
    239  1.32   tsutsui 	    sizeof(struct re_desc),					\
    240  1.23   tsutsui 	    (ops))
    241  1.32   tsutsui #define RE_RXDESCSYNC(sc, idx, ops)					\
    242  1.23   tsutsui 	bus_dmamap_sync((sc)->sc_dmat,					\
    243  1.32   tsutsui 	    (sc)->re_ldata.re_rx_list_map,				\
    244  1.32   tsutsui 	    sizeof(struct re_desc) * (idx),				\
    245  1.32   tsutsui 	    sizeof(struct re_desc),					\
    246  1.23   tsutsui 	    (ops))
    247  1.23   tsutsui 
    248  1.35   tsutsui /*
    249  1.35   tsutsui  * re(4) hardware ip4csum-tx could be mangled with 28 byte or less IP packets
    250  1.35   tsutsui  */
    251  1.35   tsutsui #define RE_IP4CSUMTX_MINLEN	28
    252  1.35   tsutsui #define RE_IP4CSUMTX_PADLEN	(ETHER_HDR_LEN + RE_IP4CSUMTX_MINLEN)
    253  1.35   tsutsui /*
    254  1.35   tsutsui  * XXX
    255  1.35   tsutsui  * We are allocating pad DMA buffer after RX DMA descs for now
    256  1.35   tsutsui  * because RE_TX_LIST_SZ(sc) always occupies whole page but
    257  1.35   tsutsui  * RE_RX_LIST_SZ is less than PAGE_SIZE so there is some unused region.
    258  1.35   tsutsui  */
    259  1.35   tsutsui #define RE_TXPADOFF		RE_RX_LIST_SZ
    260  1.35   tsutsui #define RE_TXPADDADDR(sc)	\
    261  1.35   tsutsui 	((sc)->re_ldata.re_rx_list_map->dm_segs[0].ds_addr + RE_TXPADOFF)
    262  1.35   tsutsui 
    263  1.35   tsutsui 
    264   1.5   tsutsui #define RTK_ATTACHED 0x00000001 /* attach has succeeded */
    265   1.5   tsutsui #define RTK_ENABLED  0x00000002 /* chip is enabled	*/
    266   1.5   tsutsui 
    267   1.5   tsutsui #define RTK_IS_ENABLED(sc)	((sc)->sc_flags & RTK_ENABLED)
    268  1.10   kanaoka 
    269  1.31   tsutsui #define RTK_TXTH_MAX	RTK_TXTH_1536
    270  1.10   kanaoka 
    271   1.1   tsutsui /*
    272   1.1   tsutsui  * register space access macros
    273   1.1   tsutsui  */
    274   1.1   tsutsui #define CSR_WRITE_4(sc, reg, val)	\
    275   1.4   thorpej 	bus_space_write_4(sc->rtk_btag, sc->rtk_bhandle, reg, val)
    276   1.1   tsutsui #define CSR_WRITE_2(sc, reg, val)	\
    277   1.4   thorpej 	bus_space_write_2(sc->rtk_btag, sc->rtk_bhandle, reg, val)
    278   1.1   tsutsui #define CSR_WRITE_1(sc, reg, val)	\
    279   1.4   thorpej 	bus_space_write_1(sc->rtk_btag, sc->rtk_bhandle, reg, val)
    280   1.1   tsutsui 
    281   1.1   tsutsui #define CSR_READ_4(sc, reg)		\
    282   1.4   thorpej 	bus_space_read_4(sc->rtk_btag, sc->rtk_bhandle, reg)
    283   1.1   tsutsui #define CSR_READ_2(sc, reg)		\
    284   1.4   thorpej 	bus_space_read_2(sc->rtk_btag, sc->rtk_bhandle, reg)
    285   1.1   tsutsui #define CSR_READ_1(sc, reg)		\
    286   1.4   thorpej 	bus_space_read_1(sc->rtk_btag, sc->rtk_bhandle, reg)
    287   1.1   tsutsui 
    288   1.5   tsutsui #define RTK_TIMEOUT		1000
    289   1.1   tsutsui 
    290   1.1   tsutsui /*
    291  1.26   tsutsui  * PCI low memory base and low I/O base registers
    292   1.1   tsutsui  */
    293   1.1   tsutsui 
    294   1.5   tsutsui #define RTK_PCI_LOIO		0x10
    295   1.5   tsutsui #define RTK_PCI_LOMEM		0x14
    296   1.1   tsutsui 
    297   1.1   tsutsui #ifdef _KERNEL
    298  1.24   tsutsui uint16_t rtk_read_eeprom(struct rtk_softc *, int, int);
    299  1.17     perry void	rtk_setmulti(struct rtk_softc *);
    300  1.17     perry void	rtk_attach(struct rtk_softc *);
    301  1.17     perry int	rtk_detach(struct rtk_softc *);
    302  1.17     perry int	rtk_activate(struct device *, enum devact);
    303  1.17     perry int	rtk_intr(void *);
    304   1.1   tsutsui #endif /* _KERNEL */
    305