Home | History | Annotate | Line # | Download | only in ic
i82557var.h revision 1.6
      1  1.6  thorpej /*	$NetBSD: i82557var.h,v 1.6 1999/08/05 01:35:41 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.2  thorpej  * Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1  thorpej  * NASA Ames Research Center.
     10  1.1  thorpej  *
     11  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.1  thorpej  * modification, are permitted provided that the following conditions
     13  1.1  thorpej  * are met:
     14  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.1  thorpej  *    must display the following acknowledgement:
     21  1.1  thorpej  *	This product includes software developed by the NetBSD
     22  1.1  thorpej  *	Foundation, Inc. and its contributors.
     23  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     25  1.1  thorpej  *    from this software without specific prior written permission.
     26  1.1  thorpej  *
     27  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  thorpej  */
     39  1.1  thorpej 
     40  1.1  thorpej /*
     41  1.1  thorpej  * Copyright (c) 1995, David Greenman
     42  1.1  thorpej  * All rights reserved.
     43  1.1  thorpej  *
     44  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     45  1.1  thorpej  * modification, are permitted provided that the following conditions
     46  1.1  thorpej  * are met:
     47  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     48  1.1  thorpej  *    notice unmodified, this list of conditions, and the following
     49  1.1  thorpej  *    disclaimer.
     50  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     51  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     52  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     53  1.1  thorpej  *
     54  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     55  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     58  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64  1.1  thorpej  * SUCH DAMAGE.
     65  1.1  thorpej  *
     66  1.1  thorpej  *	Id: if_fxpvar.h,v 1.4 1997/11/29 08:11:01 davidg Exp
     67  1.1  thorpej  */
     68  1.1  thorpej 
     69  1.1  thorpej /*
     70  1.1  thorpej  * Misc. defintions for the Intel i82557 fast Ethernet controller
     71  1.1  thorpej  * driver.
     72  1.1  thorpej  */
     73  1.1  thorpej 
     74  1.1  thorpej /*
     75  1.2  thorpej  * Transmit descriptor list size.
     76  1.1  thorpej  */
     77  1.2  thorpej #define	FXP_NTXCB		128
     78  1.2  thorpej #define	FXP_NTXCB_MASK		(FXP_NTXCB - 1)
     79  1.2  thorpej #define	FXP_NEXTTX(x)		((x + 1) & FXP_NTXCB_MASK)
     80  1.2  thorpej #define	FXP_NTXSEG		16
     81  1.1  thorpej 
     82  1.1  thorpej /*
     83  1.1  thorpej  * Number of receive frame area buffers.  These are large, so
     84  1.1  thorpej  * choose wisely.
     85  1.1  thorpej  */
     86  1.2  thorpej #define	FXP_NRFABUFS		64
     87  1.1  thorpej 
     88  1.1  thorpej /*
     89  1.1  thorpej  * Maximum number of seconds that the reciever can be idle before we
     90  1.1  thorpej  * assume it's dead and attempt to reset it by reprogramming the
     91  1.1  thorpej  * multicast filter.  This is part of a work-around for a bug in the
     92  1.1  thorpej  * NIC.  See fxp_stats_update().
     93  1.1  thorpej  */
     94  1.1  thorpej #define	FXP_MAX_RX_IDLE	15
     95  1.1  thorpej 
     96  1.1  thorpej /*
     97  1.1  thorpej  * Misc. DMA'd data structures are allocated in a single clump, that
     98  1.1  thorpej  * maps to a single DMA segment, to make several things easier (computing
     99  1.1  thorpej  * offsets, setting up DMA maps, etc.)
    100  1.1  thorpej  */
    101  1.1  thorpej struct fxp_control_data {
    102  1.1  thorpej 	/*
    103  1.1  thorpej 	 * The transmit control blocks.  The first if these
    104  1.1  thorpej 	 * is also used as the config CB.
    105  1.1  thorpej 	 */
    106  1.1  thorpej 	struct fxp_cb_tx fcd_txcbs[FXP_NTXCB];
    107  1.1  thorpej 
    108  1.1  thorpej 	/*
    109  1.2  thorpej 	 * The transmit buffer descriptors.
    110  1.2  thorpej 	 */
    111  1.2  thorpej 	struct fxp_tbdlist {
    112  1.2  thorpej 		struct fxp_tbd tbd_d[FXP_NTXSEG];
    113  1.2  thorpej 	} fcd_tbdl[FXP_NTXCB];
    114  1.2  thorpej 
    115  1.2  thorpej 	/*
    116  1.2  thorpej 	 * The configuration CB.
    117  1.2  thorpej 	 */
    118  1.2  thorpej 	struct fxp_cb_config fcd_configcb;
    119  1.2  thorpej 
    120  1.2  thorpej 	/*
    121  1.2  thorpej 	 * The Individual Address CB.
    122  1.2  thorpej 	 */
    123  1.2  thorpej 	struct fxp_cb_ias fcd_iascb;
    124  1.2  thorpej 
    125  1.2  thorpej 	/*
    126  1.1  thorpej 	 * The multicast setup CB.
    127  1.1  thorpej 	 */
    128  1.1  thorpej 	struct fxp_cb_mcs fcd_mcscb;
    129  1.1  thorpej 
    130  1.1  thorpej 	/*
    131  1.1  thorpej 	 * The NIC statistics.
    132  1.1  thorpej 	 */
    133  1.1  thorpej 	struct fxp_stats fcd_stats;
    134  1.1  thorpej };
    135  1.1  thorpej 
    136  1.1  thorpej #define	FXP_CDOFF(x)	offsetof(struct fxp_control_data, x)
    137  1.2  thorpej #define	FXP_CDTXOFF(x)	FXP_CDOFF(fcd_txcbs[(x)])
    138  1.2  thorpej #define	FXP_CDTBDOFF(x)	FXP_CDOFF(fcd_tbdl[(x)])
    139  1.2  thorpej #define	FXP_CDCONFIGOFF	FXP_CDOFF(fcd_configcb)
    140  1.2  thorpej #define	FXP_CDIASOFF	FXP_CDOFF(fcd_iascb)
    141  1.2  thorpej #define	FXP_CDMCSOFF	FXP_CDOFF(fcd_mcscb)
    142  1.2  thorpej #define	FXP_CDSTATSOFF	FXP_CDOFF(fcd_stats)
    143  1.2  thorpej 
    144  1.2  thorpej /*
    145  1.2  thorpej  * Software state for transmit descriptors.
    146  1.2  thorpej  */
    147  1.2  thorpej struct fxp_txsoft {
    148  1.2  thorpej 	struct mbuf *txs_mbuf;		/* head of mbuf chain */
    149  1.2  thorpej 	bus_dmamap_t txs_dmamap;	/* our DMA map */
    150  1.2  thorpej };
    151  1.1  thorpej 
    152  1.1  thorpej /*
    153  1.2  thorpej  * Software state per device.
    154  1.2  thorpej  */
    155  1.1  thorpej struct fxp_softc {
    156  1.1  thorpej 	struct device sc_dev;		/* generic device structures */
    157  1.1  thorpej 	bus_space_tag_t sc_st;		/* bus space tag */
    158  1.1  thorpej 	bus_space_handle_t sc_sh;	/* bus space handle */
    159  1.1  thorpej 	bus_dma_tag_t sc_dmat;		/* bus dma tag */
    160  1.1  thorpej 	struct ethercom sc_ethercom;	/* ethernet common part */
    161  1.2  thorpej 	void *sc_sdhook;		/* shutdown hook */
    162  1.2  thorpej 	void *sc_ih;			/* interrupt handler cookie */
    163  1.2  thorpej 
    164  1.2  thorpej 	struct mii_data sc_mii;		/* MII/media information */
    165  1.1  thorpej 
    166  1.1  thorpej 	/*
    167  1.1  thorpej 	 * We create a single DMA map that maps all data structure
    168  1.1  thorpej 	 * overhead, except for RFAs, which are mapped by the
    169  1.1  thorpej 	 * fxp_rxdesc DMA map on a per-mbuf basis.
    170  1.1  thorpej 	 */
    171  1.1  thorpej 	bus_dmamap_t sc_dmamap;
    172  1.1  thorpej #define	sc_cddma	sc_dmamap->dm_segs[0].ds_addr
    173  1.1  thorpej 
    174  1.1  thorpej 	/*
    175  1.5  thorpej 	 * Software state for transmit descriptors.
    176  1.1  thorpej 	 */
    177  1.2  thorpej 	struct fxp_txsoft sc_txsoft[FXP_NTXCB];
    178  1.2  thorpej 
    179  1.5  thorpej 	struct ifqueue sc_rxq;		/* receive buffer queue */
    180  1.5  thorpej 	bus_dmamap_t sc_rxmaps[FXP_NRFABUFS]; /* free receive buffer DMA maps */
    181  1.5  thorpej 	int	sc_rxfree;		/* free map index */
    182  1.5  thorpej 	int	sc_rxidle;		/* # of seconds RX has been idle */
    183  1.1  thorpej 
    184  1.1  thorpej 	/*
    185  1.2  thorpej 	 * Control data structures.
    186  1.1  thorpej 	 */
    187  1.2  thorpej 	struct fxp_control_data *sc_control_data;
    188  1.2  thorpej 
    189  1.2  thorpej 	int	sc_flags;		/* misc. flags */
    190  1.2  thorpej 
    191  1.6  thorpej #define	FXPF_WANTINIT		0x01	/* want a re-init */
    192  1.4  thorpej #define	FXPF_MII		0x02	/* device uses MII */
    193  1.2  thorpej 
    194  1.2  thorpej 	int	sc_txpending;		/* number of TX requests pending */
    195  1.2  thorpej 	int	sc_txdirty;		/* first dirty TX descriptor */
    196  1.2  thorpej 	int	sc_txlast;		/* last used TX descriptor */
    197  1.1  thorpej 
    198  1.1  thorpej 	int phy_primary_addr;		/* address of primary PHY */
    199  1.1  thorpej 	int phy_primary_device;		/* device type of primary PHY */
    200  1.1  thorpej 	int phy_10Mbps_only;		/* PHY is 10Mbps-only device */
    201  1.1  thorpej #if NRND > 0
    202  1.1  thorpej 	rndsource_element_t rnd_source;	/* random source */
    203  1.1  thorpej #endif
    204  1.1  thorpej };
    205  1.2  thorpej 
    206  1.5  thorpej #define	FXP_RXMAP_GET(sc)	((sc)->sc_rxmaps[(sc)->sc_rxfree++])
    207  1.5  thorpej #define	FXP_RXMAP_PUT(sc, map)	(sc)->sc_rxmaps[--(sc)->sc_rxfree] = (map)
    208  1.5  thorpej 
    209  1.2  thorpej #define	FXP_CDTXADDR(sc, x)	((sc)->sc_cddma + FXP_CDTXOFF((x)))
    210  1.2  thorpej #define	FXP_CDTBDADDR(sc, x)	((sc)->sc_cddma + FXP_CDTBDOFF((x)))
    211  1.2  thorpej 
    212  1.2  thorpej #define	FXP_CDTX(sc, x)		(&(sc)->sc_control_data->fcd_txcbs[(x)])
    213  1.2  thorpej #define	FXP_CDTBD(sc, x)	(&(sc)->sc_control_data->fcd_tbdl[(x)])
    214  1.2  thorpej 
    215  1.2  thorpej #define	FXP_DSTX(sc, x)		(&(sc)->sc_txsoft[(x)])
    216  1.2  thorpej 
    217  1.2  thorpej #define	FXP_CDTXSYNC(sc, x, ops)					\
    218  1.2  thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap,			\
    219  1.2  thorpej 	    FXP_CDTXOFF((x)), sizeof(struct fxp_cb_tx), (ops))
    220  1.2  thorpej 
    221  1.2  thorpej #define	FXP_CDTBDSYNC(sc, x, ops)					\
    222  1.2  thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap,			\
    223  1.2  thorpej 	    FXP_CDTBDOFF((x)), sizeof(struct fxp_tbdlist), (ops))
    224  1.2  thorpej 
    225  1.2  thorpej #define	FXP_CDCONFIGSYNC(sc, ops)					\
    226  1.2  thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap,			\
    227  1.2  thorpej 	    FXP_CDCONFIGOFF, sizeof(struct fxp_cb_config), (ops))
    228  1.2  thorpej 
    229  1.2  thorpej #define	FXP_CDIASSYNC(sc, ops)						\
    230  1.2  thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap,			\
    231  1.2  thorpej 	    FXP_CDIASOFF, sizeof(struct fxp_cb_ias), (ops))
    232  1.2  thorpej 
    233  1.2  thorpej #define	FXP_CDMCSSYNC(sc, ops)						\
    234  1.2  thorpej 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_dmamap,			\
    235  1.2  thorpej 	    FXP_CDMCSOFF, sizeof(struct fxp_cb_mcs), (ops))
    236  1.5  thorpej 
    237  1.5  thorpej #define	FXP_RXBUFSIZE(m)	((m)->m_ext.ext_size -			\
    238  1.5  thorpej 				 (sizeof(struct fxp_rfa) +		\
    239  1.5  thorpej 				  RFA_ALIGNMENT_FUDGE))
    240  1.5  thorpej 
    241  1.5  thorpej #define	FXP_RFASYNC(sc, m, ops)						\
    242  1.5  thorpej 	bus_dmamap_sync((sc)->sc_dmat, M_GETCTX((m), bus_dmamap_t),	\
    243  1.5  thorpej 	    RFA_ALIGNMENT_FUDGE, sizeof(struct fxp_rfa), (ops))
    244  1.5  thorpej 
    245  1.5  thorpej #define	FXP_RXBUFSYNC(sc, m, ops)					\
    246  1.5  thorpej 	bus_dmamap_sync((sc)->sc_dmat, M_GETCTX((m), bus_dmamap_t),	\
    247  1.5  thorpej 	    RFA_ALIGNMENT_FUDGE + sizeof(struct fxp_rfa),		\
    248  1.5  thorpej 	    FXP_RXBUFSIZE((m)), (ops))
    249  1.5  thorpej 
    250  1.5  thorpej #define	FXP_MTORFA(m)	(struct fxp_rfa *)((m)->m_ext.ext_buf +		\
    251  1.5  thorpej 					   RFA_ALIGNMENT_FUDGE)
    252  1.5  thorpej 
    253  1.5  thorpej #define	FXP_INIT_RFABUF(sc, m)						\
    254  1.5  thorpej do {									\
    255  1.5  thorpej 	bus_dmamap_t __rxmap = M_GETCTX((m), bus_dmamap_t);		\
    256  1.5  thorpej 	struct mbuf *__p_m;						\
    257  1.5  thorpej 	struct fxp_rfa *__rfa, *__p_rfa;				\
    258  1.5  thorpej 	u_int32_t __v;							\
    259  1.5  thorpej 									\
    260  1.5  thorpej 	(m)->m_data = (m)->m_ext.ext_buf + sizeof(struct fxp_rfa) +	\
    261  1.5  thorpej 	    RFA_ALIGNMENT_FUDGE;					\
    262  1.5  thorpej 									\
    263  1.5  thorpej 	__rfa = FXP_MTORFA((m));					\
    264  1.5  thorpej 	__rfa->size = FXP_RXBUFSIZE((m));				\
    265  1.5  thorpej 	__rfa->rfa_status = 0;						\
    266  1.5  thorpej 	__rfa->rfa_control = FXP_RFA_CONTROL_EL;			\
    267  1.5  thorpej 	__rfa->actual_size = 0;						\
    268  1.5  thorpej 									\
    269  1.5  thorpej 	/* NOTE: the RFA is misaligned, so we must copy. */		\
    270  1.5  thorpej 	__v = -1;							\
    271  1.5  thorpej 	memcpy((void *)&__rfa->link_addr, &__v, sizeof(__v));		\
    272  1.5  thorpej 	memcpy((void *)&__rfa->rbd_addr, &__v, sizeof(__v));		\
    273  1.5  thorpej 									\
    274  1.5  thorpej 	FXP_RFASYNC((sc), (m),						\
    275  1.5  thorpej 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);			\
    276  1.5  thorpej 									\
    277  1.5  thorpej 	FXP_RXBUFSYNC((sc), (m), BUS_DMASYNC_PREREAD);			\
    278  1.5  thorpej 									\
    279  1.5  thorpej 	if ((__p_m = (sc)->sc_rxq.ifq_tail) != NULL) {			\
    280  1.5  thorpej 		__p_rfa = FXP_MTORFA(__p_m);				\
    281  1.5  thorpej 		__v = __rxmap->dm_segs[0].ds_addr + RFA_ALIGNMENT_FUDGE;\
    282  1.5  thorpej 		FXP_RFASYNC((sc), __p_m,				\
    283  1.5  thorpej 		    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);	\
    284  1.5  thorpej 		memcpy((void *)&__p_rfa->link_addr, &__v,		\
    285  1.5  thorpej 		    sizeof(__v));					\
    286  1.5  thorpej 		__p_rfa->rfa_control &= ~FXP_RFA_CONTROL_EL;		\
    287  1.5  thorpej 		FXP_RFASYNC((sc), __p_m,				\
    288  1.5  thorpej 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);		\
    289  1.5  thorpej 	}								\
    290  1.5  thorpej 	IF_ENQUEUE(&(sc)->sc_rxq, (m));					\
    291  1.5  thorpej } while (0)
    292  1.1  thorpej 
    293  1.1  thorpej /* Macros to ease CSR access. */
    294  1.1  thorpej #define	CSR_READ_1(sc, reg)						\
    295  1.1  thorpej 	bus_space_read_1((sc)->sc_st, (sc)->sc_sh, (reg))
    296  1.1  thorpej #define	CSR_READ_2(sc, reg)						\
    297  1.1  thorpej 	bus_space_read_2((sc)->sc_st, (sc)->sc_sh, (reg))
    298  1.1  thorpej #define	CSR_READ_4(sc, reg)						\
    299  1.1  thorpej 	bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (reg))
    300  1.1  thorpej #define	CSR_WRITE_1(sc, reg, val)					\
    301  1.1  thorpej 	bus_space_write_1((sc)->sc_st, (sc)->sc_sh, (reg), (val))
    302  1.1  thorpej #define	CSR_WRITE_2(sc, reg, val)					\
    303  1.1  thorpej 	bus_space_write_2((sc)->sc_st, (sc)->sc_sh, (reg), (val))
    304  1.1  thorpej #define	CSR_WRITE_4(sc, reg, val)					\
    305  1.1  thorpej 	bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
    306  1.1  thorpej 
    307  1.1  thorpej void	fxp_attach __P((struct fxp_softc *));
    308  1.1  thorpej int	fxp_intr __P((void *));
    309