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