Home | History | Annotate | Line # | Download | only in dev
aevar.h revision 1.4
      1  1.4      tls /*	$NetBSD: aevar.h,v 1.4 2011/11/19 22:51:20 tls Exp $	*/
      2  1.1  gdamore 
      3  1.1  gdamore /*-
      4  1.1  gdamore  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
      5  1.1  gdamore  * All rights reserved.
      6  1.1  gdamore  *
      7  1.1  gdamore  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  gdamore  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1  gdamore  * NASA Ames Research Center.
     10  1.1  gdamore  *
     11  1.1  gdamore  * Redistribution and use in source and binary forms, with or without
     12  1.1  gdamore  * modification, are permitted provided that the following conditions
     13  1.1  gdamore  * are met:
     14  1.1  gdamore  * 1. Redistributions of source code must retain the above copyright
     15  1.1  gdamore  *    notice, this list of conditions and the following disclaimer.
     16  1.1  gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  gdamore  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  gdamore  *    documentation and/or other materials provided with the distribution.
     19  1.1  gdamore  *
     20  1.1  gdamore  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1  gdamore  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1  gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1  gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1  gdamore  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1  gdamore  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1  gdamore  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1  gdamore  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  gdamore  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1  gdamore  */
     32  1.1  gdamore 
     33  1.1  gdamore #ifndef _MIPS_ATHEROS_DEV_AEVAR_H_
     34  1.1  gdamore #define	_MIPS_ATHEROS_DEV_AEVAR_H_
     35  1.1  gdamore 
     36  1.1  gdamore #include "rnd.h"
     37  1.1  gdamore 
     38  1.1  gdamore #include <sys/queue.h>
     39  1.1  gdamore #include <sys/callout.h>
     40  1.1  gdamore 
     41  1.1  gdamore #if NRND > 0
     42  1.1  gdamore #include <sys/rnd.h>
     43  1.1  gdamore #endif
     44  1.1  gdamore 
     45  1.1  gdamore /*
     46  1.1  gdamore  * Misc. definitions for the Digital Semiconductor ``Tulip'' (21x4x)
     47  1.1  gdamore  * Ethernet controller family driver.
     48  1.1  gdamore  */
     49  1.1  gdamore 
     50  1.1  gdamore /*
     51  1.1  gdamore  * Transmit descriptor list size.  This is arbitrary, but allocate
     52  1.1  gdamore  * enough descriptors for 64 pending transmissions and 16 segments
     53  1.1  gdamore  * per packet.  Since a descriptor holds 2 buffer addresses, that's
     54  1.1  gdamore  * 8 descriptors per packet.  This MUST work out to a power of 2.
     55  1.1  gdamore  */
     56  1.1  gdamore #define	AE_NTXSEGS		16
     57  1.1  gdamore 
     58  1.1  gdamore #define	AE_TXQUEUELEN		64
     59  1.1  gdamore #define	AE_NTXDESC		(AE_TXQUEUELEN * AE_NTXSEGS)
     60  1.1  gdamore #define	AE_NTXDESC_MASK		(AE_NTXDESC - 1)
     61  1.1  gdamore #define	AE_NEXTTX(x)		((x + 1) & AE_NTXDESC_MASK)
     62  1.1  gdamore 
     63  1.1  gdamore /*
     64  1.1  gdamore  * Receive descriptor list size.  We have one Rx buffer per incoming
     65  1.1  gdamore  * packet, so this logic is a little simpler.
     66  1.1  gdamore  */
     67  1.1  gdamore #define	AE_NRXDESC		64
     68  1.1  gdamore #define	AE_NRXDESC_MASK		(AE_NRXDESC - 1)
     69  1.1  gdamore #define	AE_NEXTRX(x)		((x + 1) & AE_NRXDESC_MASK)
     70  1.1  gdamore 
     71  1.1  gdamore /*
     72  1.1  gdamore  * Control structures are DMA'd to the TULIP chip.  We allocate them in
     73  1.1  gdamore  * a single clump that maps to a single DMA segment to make several things
     74  1.1  gdamore  * easier.
     75  1.1  gdamore  */
     76  1.1  gdamore struct ae_control_data {
     77  1.1  gdamore 	/*
     78  1.1  gdamore 	 * The transmit descriptors.
     79  1.1  gdamore 	 */
     80  1.1  gdamore 	struct ae_desc acd_txdescs[AE_NTXDESC];
     81  1.1  gdamore 
     82  1.1  gdamore 	/*
     83  1.1  gdamore 	 * The receive descriptors.
     84  1.1  gdamore 	 */
     85  1.1  gdamore 	struct ae_desc acd_rxdescs[AE_NRXDESC];
     86  1.1  gdamore };
     87  1.1  gdamore 
     88  1.1  gdamore #define	AE_CDOFF(x)		offsetof(struct ae_control_data, x)
     89  1.1  gdamore #define	AE_CDTXOFF(x)		AE_CDOFF(acd_txdescs[(x)])
     90  1.1  gdamore #define	AE_CDRXOFF(x)		AE_CDOFF(acd_rxdescs[(x)])
     91  1.1  gdamore 
     92  1.1  gdamore /*
     93  1.1  gdamore  * Software state for transmit jobs.
     94  1.1  gdamore  */
     95  1.1  gdamore struct ae_txsoft {
     96  1.1  gdamore 	struct mbuf *txs_mbuf;		/* head of our mbuf chain */
     97  1.1  gdamore 	bus_dmamap_t txs_dmamap;	/* our DMA map */
     98  1.1  gdamore 	int txs_firstdesc;		/* first descriptor in packet */
     99  1.1  gdamore 	int txs_lastdesc;		/* last descriptor in packet */
    100  1.1  gdamore 	int txs_ndescs;			/* number of descriptors */
    101  1.1  gdamore 	SIMPLEQ_ENTRY(ae_txsoft) txs_q;
    102  1.1  gdamore };
    103  1.1  gdamore 
    104  1.1  gdamore SIMPLEQ_HEAD(ae_txsq, ae_txsoft);
    105  1.1  gdamore 
    106  1.1  gdamore /*
    107  1.1  gdamore  * Software state for receive jobs.
    108  1.1  gdamore  */
    109  1.1  gdamore struct ae_rxsoft {
    110  1.1  gdamore 	struct mbuf *rxs_mbuf;		/* head of our mbuf chain */
    111  1.1  gdamore 	bus_dmamap_t rxs_dmamap;	/* our DMA map */
    112  1.1  gdamore };
    113  1.1  gdamore 
    114  1.1  gdamore struct ae_softc;
    115  1.1  gdamore 
    116  1.1  gdamore /*
    117  1.1  gdamore  * Some misc. statics, useful for debugging.
    118  1.1  gdamore  */
    119  1.1  gdamore struct ae_stats {
    120  1.1  gdamore 	u_long		ts_tx_uf;	/* transmit underflow errors */
    121  1.1  gdamore 	u_long		ts_tx_to;	/* transmit jabber timeouts */
    122  1.1  gdamore 	u_long		ts_tx_ec;	/* excessive collision count */
    123  1.1  gdamore 	u_long		ts_tx_lc;	/* late collision count */
    124  1.1  gdamore };
    125  1.1  gdamore 
    126  1.1  gdamore #ifndef _STANDALONE
    127  1.1  gdamore /*
    128  1.1  gdamore  * Software state per device.
    129  1.1  gdamore  */
    130  1.1  gdamore struct ae_softc {
    131  1.1  gdamore 	struct device sc_dev;		/* generic device information */
    132  1.1  gdamore 	bus_space_tag_t sc_st;		/* bus space tag */
    133  1.1  gdamore 	bus_space_handle_t sc_sh;	/* bus space handle */
    134  1.1  gdamore 	bus_size_t sc_size;		/* bus space size */
    135  1.1  gdamore 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
    136  1.1  gdamore 	void *sc_ih;			/* interrupt handle */
    137  1.2  gdamore 	int sc_cirq;			/* interrupt request line (cpu) */
    138  1.2  gdamore 	int sc_mirq;			/* interrupt request line (misc) */
    139  1.1  gdamore 	struct ethercom sc_ethercom;	/* ethernet common data */
    140  1.1  gdamore 	void *sc_sdhook;		/* shutdown hook */
    141  1.1  gdamore 	void *sc_powerhook;		/* power management hook */
    142  1.1  gdamore 
    143  1.1  gdamore 	struct ae_stats sc_stats;	/* debugging stats */
    144  1.1  gdamore 
    145  1.1  gdamore 	int		sc_flags;	/* misc flags. */
    146  1.1  gdamore 
    147  1.1  gdamore 	struct mii_data sc_mii;		/* MII/media information */
    148  1.1  gdamore 
    149  1.1  gdamore 	int		sc_txthresh;	/* current transmit threshold */
    150  1.1  gdamore 
    151  1.1  gdamore 	/* Media tick function. */
    152  1.1  gdamore 	void		(*sc_tick)(void *);
    153  1.1  gdamore 	struct callout sc_tick_callout;
    154  1.1  gdamore 
    155  1.1  gdamore 	u_int32_t	sc_inten;	/* copy of CSR_INTEN */
    156  1.1  gdamore 
    157  1.1  gdamore 	u_int32_t	sc_rxint_mask;	/* mask of Rx interrupts we want */
    158  1.1  gdamore 	u_int32_t	sc_txint_mask;	/* mask of Tx interrupts we want */
    159  1.1  gdamore 
    160  1.1  gdamore 	bus_dma_segment_t sc_cdseg;	/* control data memory */
    161  1.1  gdamore 	int		sc_cdnseg;	/* number of segments */
    162  1.1  gdamore 	bus_dmamap_t sc_cddmamap;	/* control data DMA map */
    163  1.1  gdamore #define	sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
    164  1.1  gdamore 
    165  1.1  gdamore 	/*
    166  1.1  gdamore 	 * Software state for transmit and receive descriptors.
    167  1.1  gdamore 	 */
    168  1.1  gdamore 	struct ae_txsoft sc_txsoft[AE_TXQUEUELEN];
    169  1.1  gdamore 	struct ae_rxsoft sc_rxsoft[AE_NRXDESC];
    170  1.1  gdamore 
    171  1.1  gdamore 	/*
    172  1.1  gdamore 	 * Control data structures.
    173  1.1  gdamore 	 */
    174  1.1  gdamore 	struct ae_control_data *sc_control_data;
    175  1.1  gdamore #define	sc_txdescs	sc_control_data->acd_txdescs
    176  1.1  gdamore #define	sc_rxdescs	sc_control_data->acd_rxdescs
    177  1.1  gdamore #define	sc_setup_desc	sc_control_data->acd_setup_desc
    178  1.1  gdamore 
    179  1.1  gdamore 	int	sc_txfree;		/* number of free Tx descriptors */
    180  1.1  gdamore 	int	sc_txnext;		/* next ready Tx descriptor */
    181  1.1  gdamore 
    182  1.1  gdamore 	struct ae_txsq sc_txfreeq;	/* free Tx descsofts */
    183  1.1  gdamore 	struct ae_txsq sc_txdirtyq;	/* dirty Tx descsofts */
    184  1.1  gdamore 
    185  1.1  gdamore 	short	sc_if_flags;
    186  1.1  gdamore 
    187  1.1  gdamore 	int	sc_rxptr;		/* next ready RX descriptor/descsoft */
    188  1.1  gdamore 
    189  1.1  gdamore #if NRND > 0
    190  1.4      tls 	krndsource_t sc_rnd_source; /* random source */
    191  1.1  gdamore #endif
    192  1.1  gdamore };
    193  1.1  gdamore #endif
    194  1.1  gdamore 
    195  1.1  gdamore /* sc_flags */
    196  1.1  gdamore #define	AE_ATTACHED		0x00000800	/* attach has succeeded */
    197  1.1  gdamore #define	AE_ENABLED		0x00001000	/* chip is enabled */
    198  1.1  gdamore 
    199  1.1  gdamore #define	AE_IS_ENABLED(sc)	((sc)->sc_flags & AE_ENABLED)
    200  1.1  gdamore 
    201  1.1  gdamore /*
    202  1.1  gdamore  * This macro returns the current media entry.
    203  1.1  gdamore  */
    204  1.1  gdamore #define	AE_CURRENT_MEDIA(sc) ((sc)->sc_mii.mii_media.ifm_cur)
    205  1.1  gdamore 
    206  1.1  gdamore /*
    207  1.1  gdamore  * This macro determines if a change to media-related OPMODE bits requires
    208  1.1  gdamore  * a chip reset.
    209  1.1  gdamore  */
    210  1.1  gdamore #define	TULIP_MEDIA_NEEDSRESET(sc, newbits)				\
    211  1.1  gdamore 	(((sc)->sc_opmode & OPMODE_MEDIA_BITS) !=			\
    212  1.1  gdamore 	 ((newbits) & OPMODE_MEDIA_BITS))
    213  1.1  gdamore 
    214  1.1  gdamore #define	AE_CDTXADDR(sc, x)	((sc)->sc_cddma + AE_CDTXOFF((x)))
    215  1.1  gdamore #define	AE_CDRXADDR(sc, x)	((sc)->sc_cddma + AE_CDRXOFF((x)))
    216  1.1  gdamore 
    217  1.1  gdamore #define	AE_CDTXSYNC(sc, x, n, ops)					\
    218  1.1  gdamore do {									\
    219  1.1  gdamore 	int __x, __n;							\
    220  1.1  gdamore 									\
    221  1.1  gdamore 	__x = (x);							\
    222  1.1  gdamore 	__n = (n);							\
    223  1.1  gdamore 									\
    224  1.1  gdamore 	/* If it will wrap around, sync to the end of the ring. */	\
    225  1.1  gdamore 	if ((__x + __n) > AE_NTXDESC) {					\
    226  1.1  gdamore 		bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,	\
    227  1.1  gdamore 		    AE_CDTXOFF(__x), sizeof(struct ae_desc) *		\
    228  1.1  gdamore 		    (AE_NTXDESC - __x), (ops));				\
    229  1.1  gdamore 		__n -= (AE_NTXDESC - __x);				\
    230  1.1  gdamore 		__x = 0;						\
    231  1.1  gdamore 	}								\
    232  1.1  gdamore 									\
    233  1.1  gdamore 	/* Now sync whatever is left. */				\
    234  1.1  gdamore 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    235  1.1  gdamore 	    AE_CDTXOFF(__x), sizeof(struct ae_desc) * __n, (ops));	\
    236  1.1  gdamore } while (0)
    237  1.1  gdamore 
    238  1.1  gdamore #define	AE_CDRXSYNC(sc, x, ops)						\
    239  1.1  gdamore 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    240  1.1  gdamore 	    AE_CDRXOFF((x)), sizeof(struct ae_desc), (ops))
    241  1.1  gdamore 
    242  1.1  gdamore /*
    243  1.1  gdamore  * Note we rely on MCLBYTES being a power of two.  Because the `length'
    244  1.1  gdamore  * field is only 11 bits, we must subtract 1 from the length to avoid
    245  1.1  gdamore  * having it truncated to 0!
    246  1.1  gdamore  */
    247  1.1  gdamore #define	AE_INIT_RXDESC(sc, x)						\
    248  1.1  gdamore do {									\
    249  1.1  gdamore 	struct ae_rxsoft *__rxs = &sc->sc_rxsoft[(x)];			\
    250  1.1  gdamore 	struct ae_desc *__rxd = &sc->sc_rxdescs[(x)];			\
    251  1.1  gdamore 	struct mbuf *__m = __rxs->rxs_mbuf;				\
    252  1.1  gdamore 									\
    253  1.1  gdamore 	__m->m_data = __m->m_ext.ext_buf;				\
    254  1.1  gdamore 	__rxd->ad_bufaddr1 =						\
    255  1.1  gdamore 	    (__rxs->rxs_dmamap->dm_segs[0].ds_addr);			\
    256  1.1  gdamore 	__rxd->ad_bufaddr2 =						\
    257  1.1  gdamore 	    AE_CDRXADDR((sc), AE_NEXTRX((x)));				\
    258  1.1  gdamore 	__rxd->ad_ctl =							\
    259  1.1  gdamore 	    ((((__m->m_ext.ext_size - 1) & ~0x3U)			\
    260  1.1  gdamore 	    << ADCTL_SIZE1_SHIFT) | 					\
    261  1.1  gdamore 	    ((x) == (AE_NRXDESC - 1) ? ADCTL_ER : 0));			\
    262  1.1  gdamore 	__rxd->ad_status = ADSTAT_OWN|ADSTAT_Rx_FS|ADSTAT_Rx_LS;	\
    263  1.1  gdamore 	AE_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
    264  1.1  gdamore } while (0)
    265  1.1  gdamore 
    266  1.1  gdamore /* CSR access */
    267  1.1  gdamore 
    268  1.1  gdamore #define	AE_READ(sc, reg)						\
    269  1.1  gdamore 	bus_space_read_4((sc)->sc_st, (sc)->sc_sh, (reg))
    270  1.1  gdamore 
    271  1.1  gdamore #define	AE_WRITE(sc, reg, val)						\
    272  1.1  gdamore 	bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
    273  1.1  gdamore 
    274  1.1  gdamore #define	AE_SET(sc, reg, mask)						\
    275  1.1  gdamore 	AE_WRITE((sc), (reg), AE_READ((sc), (reg)) | (mask))
    276  1.1  gdamore 
    277  1.1  gdamore #define	AE_CLR(sc, reg, mask)						\
    278  1.1  gdamore 	AE_WRITE((sc), (reg), AE_READ((sc), (reg)) & ~(mask))
    279  1.1  gdamore 
    280  1.1  gdamore #define	AE_ISSET(sc, reg, mask)						\
    281  1.1  gdamore 	(AE_READ((sc), (reg)) & (mask))
    282  1.1  gdamore 
    283  1.1  gdamore #define	AE_BARRIER(sc)							\
    284  1.1  gdamore 	bus_space_barrier((sc)->sc_st, (sc)->sc_sh, 0, (sc)->sc_size,	\
    285  1.1  gdamore 	    BUS_SPACE_BARRIER_WRITE)
    286  1.1  gdamore 
    287  1.1  gdamore #endif /* _MIPS_ATHEROS_DEV_AEVAR_H_ */
    288