Home | History | Annotate | Line # | Download | only in ic
gemvar.h revision 1.1.2.5
      1  1.1.2.5  nathanw /*	$NetBSD: gemvar.h,v 1.1.2.5 2002/06/20 03:44:35 nathanw Exp $ */
      2  1.1.2.2  nathanw 
      3  1.1.2.2  nathanw /*
      4  1.1.2.2  nathanw  *
      5  1.1.2.2  nathanw  * Copyright (C) 2001 Eduardo Horvath.
      6  1.1.2.2  nathanw  * All rights reserved.
      7  1.1.2.2  nathanw  *
      8  1.1.2.2  nathanw  *
      9  1.1.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     10  1.1.2.2  nathanw  * modification, are permitted provided that the following conditions
     11  1.1.2.2  nathanw  * are met:
     12  1.1.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     13  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     14  1.1.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     17  1.1.2.2  nathanw  *
     18  1.1.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
     19  1.1.2.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20  1.1.2.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  1.1.2.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
     22  1.1.2.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  1.1.2.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24  1.1.2.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  1.1.2.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26  1.1.2.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.1.2.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.1.2.2  nathanw  * SUCH DAMAGE.
     29  1.1.2.2  nathanw  *
     30  1.1.2.2  nathanw  */
     31  1.1.2.2  nathanw 
     32  1.1.2.2  nathanw #ifndef	_IF_GEMVAR_H
     33  1.1.2.2  nathanw #define	_IF_GEMVAR_H
     34  1.1.2.2  nathanw 
     35  1.1.2.2  nathanw 
     36  1.1.2.2  nathanw #include "rnd.h"
     37  1.1.2.2  nathanw 
     38  1.1.2.2  nathanw #include <sys/queue.h>
     39  1.1.2.2  nathanw #include <sys/callout.h>
     40  1.1.2.2  nathanw 
     41  1.1.2.2  nathanw #if NRND > 0
     42  1.1.2.2  nathanw #include <sys/rnd.h>
     43  1.1.2.2  nathanw #endif
     44  1.1.2.2  nathanw 
     45  1.1.2.2  nathanw /*
     46  1.1.2.2  nathanw  * Misc. definitions for the Sun ``Gem'' Ethernet controller family driver.
     47  1.1.2.2  nathanw  */
     48  1.1.2.2  nathanw 
     49  1.1.2.2  nathanw /*
     50  1.1.2.2  nathanw  * Transmit descriptor list size.  This is arbitrary, but allocate
     51  1.1.2.2  nathanw  * enough descriptors for 64 pending transmissions and 16 segments
     52  1.1.2.2  nathanw  * per packet.
     53  1.1.2.2  nathanw  */
     54  1.1.2.2  nathanw #define	GEM_NTXSEGS		16
     55  1.1.2.2  nathanw 
     56  1.1.2.2  nathanw #define	GEM_TXQUEUELEN		64
     57  1.1.2.2  nathanw #define	GEM_NTXDESC		(GEM_TXQUEUELEN * GEM_NTXSEGS)
     58  1.1.2.2  nathanw #define	GEM_NTXDESC_MASK	(GEM_NTXDESC - 1)
     59  1.1.2.2  nathanw #define	GEM_NEXTTX(x)		((x + 1) & GEM_NTXDESC_MASK)
     60  1.1.2.2  nathanw 
     61  1.1.2.2  nathanw /*
     62  1.1.2.2  nathanw  * Receive descriptor list size.  We have one Rx buffer per incoming
     63  1.1.2.2  nathanw  * packet, so this logic is a little simpler.
     64  1.1.2.2  nathanw  */
     65  1.1.2.3  nathanw #define	GEM_NRXDESC		128
     66  1.1.2.2  nathanw #define	GEM_NRXDESC_MASK	(GEM_NRXDESC - 1)
     67  1.1.2.5  nathanw #define	GEM_PREVRX(x)		((x - 1) & GEM_NRXDESC_MASK)
     68  1.1.2.2  nathanw #define	GEM_NEXTRX(x)		((x + 1) & GEM_NRXDESC_MASK)
     69  1.1.2.2  nathanw 
     70  1.1.2.2  nathanw /*
     71  1.1.2.2  nathanw  * Control structures are DMA'd to the GEM chip.  We allocate them in
     72  1.1.2.2  nathanw  * a single clump that maps to a single DMA segment to make several things
     73  1.1.2.2  nathanw  * easier.
     74  1.1.2.2  nathanw  */
     75  1.1.2.2  nathanw struct gem_control_data {
     76  1.1.2.2  nathanw 	/*
     77  1.1.2.2  nathanw 	 * The transmit descriptors.
     78  1.1.2.2  nathanw 	 */
     79  1.1.2.2  nathanw 	struct gem_desc gcd_txdescs[GEM_NTXDESC];
     80  1.1.2.2  nathanw 
     81  1.1.2.2  nathanw 	/*
     82  1.1.2.2  nathanw 	 * The receive descriptors.
     83  1.1.2.2  nathanw 	 */
     84  1.1.2.2  nathanw 	struct gem_desc gcd_rxdescs[GEM_NRXDESC];
     85  1.1.2.2  nathanw };
     86  1.1.2.2  nathanw 
     87  1.1.2.2  nathanw #define	GEM_CDOFF(x)		offsetof(struct gem_control_data, x)
     88  1.1.2.2  nathanw #define	GEM_CDTXOFF(x)		GEM_CDOFF(gcd_txdescs[(x)])
     89  1.1.2.2  nathanw #define	GEM_CDRXOFF(x)		GEM_CDOFF(gcd_rxdescs[(x)])
     90  1.1.2.2  nathanw 
     91  1.1.2.2  nathanw /*
     92  1.1.2.2  nathanw  * Software state for transmit jobs.
     93  1.1.2.2  nathanw  */
     94  1.1.2.2  nathanw struct gem_txsoft {
     95  1.1.2.2  nathanw 	struct mbuf *txs_mbuf;		/* head of our mbuf chain */
     96  1.1.2.2  nathanw 	bus_dmamap_t txs_dmamap;	/* our DMA map */
     97  1.1.2.2  nathanw 	int txs_firstdesc;		/* first descriptor in packet */
     98  1.1.2.2  nathanw 	int txs_lastdesc;		/* last descriptor in packet */
     99  1.1.2.2  nathanw 	int txs_ndescs;			/* number of descriptors */
    100  1.1.2.2  nathanw 	SIMPLEQ_ENTRY(gem_txsoft) txs_q;
    101  1.1.2.2  nathanw };
    102  1.1.2.2  nathanw 
    103  1.1.2.2  nathanw SIMPLEQ_HEAD(gem_txsq, gem_txsoft);
    104  1.1.2.2  nathanw 
    105  1.1.2.2  nathanw /*
    106  1.1.2.2  nathanw  * Software state for receive jobs.
    107  1.1.2.2  nathanw  */
    108  1.1.2.2  nathanw struct gem_rxsoft {
    109  1.1.2.2  nathanw 	struct mbuf *rxs_mbuf;		/* head of our mbuf chain */
    110  1.1.2.2  nathanw 	bus_dmamap_t rxs_dmamap;	/* our DMA map */
    111  1.1.2.2  nathanw };
    112  1.1.2.2  nathanw 
    113  1.1.2.2  nathanw /*
    114  1.1.2.2  nathanw  * Software state per device.
    115  1.1.2.2  nathanw  */
    116  1.1.2.2  nathanw struct gem_softc {
    117  1.1.2.2  nathanw 	struct device	sc_dev;		/* generic device information */
    118  1.1.2.2  nathanw 	struct ethercom sc_ethercom;	/* ethernet common data */
    119  1.1.2.2  nathanw 	struct mii_data	sc_mii;		/* MII media control */
    120  1.1.2.2  nathanw #define sc_media	sc_mii.mii_media/* shorthand */
    121  1.1.2.2  nathanw 	struct callout	sc_tick_ch;	/* tick callout */
    122  1.1.2.2  nathanw 
    123  1.1.2.2  nathanw 	/* The following bus handles are to be provided by the bus front-end */
    124  1.1.2.2  nathanw 	bus_space_tag_t	sc_bustag;	/* bus tag */
    125  1.1.2.2  nathanw 	bus_dma_tag_t	sc_dmatag;	/* bus dma tag */
    126  1.1.2.2  nathanw 	bus_dmamap_t	sc_dmamap;	/* bus dma handle */
    127  1.1.2.2  nathanw 	bus_space_handle_t sc_h;	/* bus space handle for all regs */
    128  1.1.2.4  nathanw 
    129  1.1.2.2  nathanw 	int		sc_phys[2];	/* MII instance -> PHY map */
    130  1.1.2.2  nathanw 
    131  1.1.2.2  nathanw 	int		sc_mif_config;	/* Selected MII reg setting */
    132  1.1.2.2  nathanw 
    133  1.1.2.2  nathanw 	int		sc_pci;		/* XXXXX -- PCI buses are LE. */
    134  1.1.2.5  nathanw 	u_int		sc_variant;	/* which GEM are we dealing with? */
    135  1.1.2.5  nathanw #define	GEM_UNKNOWN		0	/* don't know */
    136  1.1.2.5  nathanw #define	GEM_SUN_GEM		1	/* Sun GEM variant */
    137  1.1.2.5  nathanw #define	GEM_APPLE_GMAC		2	/* Apple GMAC variant */
    138  1.1.2.5  nathanw 
    139  1.1.2.5  nathanw 	u_int		sc_flags;	/* */
    140  1.1.2.5  nathanw #define	GEM_GIGABIT		0x0001	/* has a gigabit PHY */
    141  1.1.2.2  nathanw 
    142  1.1.2.2  nathanw 	void *sc_sdhook;		/* shutdown hook */
    143  1.1.2.2  nathanw 	void *sc_powerhook;		/* power management hook */
    144  1.1.2.2  nathanw 
    145  1.1.2.2  nathanw 	/*
    146  1.1.2.2  nathanw 	 * Ring buffer DMA stuff.
    147  1.1.2.2  nathanw 	 */
    148  1.1.2.2  nathanw 	bus_dma_segment_t sc_cdseg;	/* control data memory */
    149  1.1.2.2  nathanw 	int		sc_cdnseg;	/* number of segments */
    150  1.1.2.2  nathanw 	bus_dmamap_t sc_cddmamap;	/* control data DMA map */
    151  1.1.2.2  nathanw #define	sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
    152  1.1.2.2  nathanw 
    153  1.1.2.2  nathanw 	/*
    154  1.1.2.2  nathanw 	 * Software state for transmit and receive descriptors.
    155  1.1.2.2  nathanw 	 */
    156  1.1.2.2  nathanw 	struct gem_txsoft sc_txsoft[GEM_TXQUEUELEN];
    157  1.1.2.2  nathanw 	struct gem_rxsoft sc_rxsoft[GEM_NRXDESC];
    158  1.1.2.2  nathanw 
    159  1.1.2.2  nathanw 	/*
    160  1.1.2.2  nathanw 	 * Control data structures.
    161  1.1.2.2  nathanw 	 */
    162  1.1.2.2  nathanw 	struct gem_control_data *sc_control_data;
    163  1.1.2.2  nathanw #define	sc_txdescs	sc_control_data->gcd_txdescs
    164  1.1.2.2  nathanw #define	sc_rxdescs	sc_control_data->gcd_rxdescs
    165  1.1.2.2  nathanw 
    166  1.1.2.4  nathanw 	int		sc_txfree;	/* number of free Tx descriptors */
    167  1.1.2.4  nathanw 	int		sc_txnext;	/* next ready Tx descriptor */
    168  1.1.2.5  nathanw 	int		sc_txwin;	/* Tx descriptors since last Tx int */
    169  1.1.2.2  nathanw 
    170  1.1.2.4  nathanw 	struct gem_txsq	sc_txfreeq;	/* free Tx descsofts */
    171  1.1.2.4  nathanw 	struct gem_txsq	sc_txdirtyq;	/* dirty Tx descsofts */
    172  1.1.2.2  nathanw 
    173  1.1.2.4  nathanw 	int		sc_rxptr;	/* next ready RX descriptor/descsoft */
    174  1.1.2.5  nathanw 	int		sc_rxfifosize;	/* Rx FIFO size (bytes) */
    175  1.1.2.2  nathanw 
    176  1.1.2.2  nathanw 	/* ========== */
    177  1.1.2.4  nathanw 	int		sc_inited;
    178  1.1.2.4  nathanw 	int		sc_debug;
    179  1.1.2.4  nathanw 	void		*sc_sh;		/* shutdownhook cookie */
    180  1.1.2.2  nathanw 
    181  1.1.2.2  nathanw 	/* Special hardware hooks */
    182  1.1.2.2  nathanw 	void	(*sc_hwreset) __P((struct gem_softc *));
    183  1.1.2.2  nathanw 	void	(*sc_hwinit) __P((struct gem_softc *));
    184  1.1.2.2  nathanw 
    185  1.1.2.2  nathanw #if NRND > 0
    186  1.1.2.2  nathanw 	rndsource_element_t	rnd_source;
    187  1.1.2.2  nathanw #endif
    188  1.1.2.5  nathanw 
    189  1.1.2.5  nathanw 	struct evcnt sc_ev_intr;
    190  1.1.2.5  nathanw #ifdef GEM_COUNTERS
    191  1.1.2.5  nathanw 	struct evcnt sc_ev_txint;
    192  1.1.2.5  nathanw 	struct evcnt sc_ev_rxint;
    193  1.1.2.5  nathanw 	struct evcnt sc_ev_rxnobuf;
    194  1.1.2.5  nathanw 	struct evcnt sc_ev_rxfull;
    195  1.1.2.5  nathanw 	struct evcnt sc_ev_rxhist[9];
    196  1.1.2.5  nathanw #endif
    197  1.1.2.2  nathanw };
    198  1.1.2.2  nathanw 
    199  1.1.2.5  nathanw #ifdef GEM_COUNTERS
    200  1.1.2.5  nathanw #define	GEM_COUNTER_INCR(sc, ctr)	((void) (sc->ctr.ev_count++))
    201  1.1.2.5  nathanw #else
    202  1.1.2.5  nathanw #define	GEM_COUNTER_INCR(sc, ctr)	((void) sc)
    203  1.1.2.5  nathanw #endif
    204  1.1.2.5  nathanw 
    205  1.1.2.2  nathanw 
    206  1.1.2.3  nathanw #define	GEM_DMA_READ(sc, v)	(((sc)->sc_pci) ? le64toh(v) : be64toh(v))
    207  1.1.2.3  nathanw #define	GEM_DMA_WRITE(sc, v)	(((sc)->sc_pci) ? htole64(v) : htobe64(v))
    208  1.1.2.2  nathanw 
    209  1.1.2.2  nathanw #define	GEM_CDTXADDR(sc, x)	((sc)->sc_cddma + GEM_CDTXOFF((x)))
    210  1.1.2.2  nathanw #define	GEM_CDRXADDR(sc, x)	((sc)->sc_cddma + GEM_CDRXOFF((x)))
    211  1.1.2.2  nathanw 
    212  1.1.2.2  nathanw #define	GEM_CDSPADDR(sc)	((sc)->sc_cddma + GEM_CDSPOFF)
    213  1.1.2.2  nathanw 
    214  1.1.2.2  nathanw #define	GEM_CDTXSYNC(sc, x, n, ops)					\
    215  1.1.2.2  nathanw do {									\
    216  1.1.2.2  nathanw 	int __x, __n;							\
    217  1.1.2.2  nathanw 									\
    218  1.1.2.2  nathanw 	__x = (x);							\
    219  1.1.2.2  nathanw 	__n = (n);							\
    220  1.1.2.2  nathanw 									\
    221  1.1.2.2  nathanw 	/* If it will wrap around, sync to the end of the ring. */	\
    222  1.1.2.2  nathanw 	if ((__x + __n) > GEM_NTXDESC) {				\
    223  1.1.2.2  nathanw 		bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,	\
    224  1.1.2.2  nathanw 		    GEM_CDTXOFF(__x), sizeof(struct gem_desc) *		\
    225  1.1.2.2  nathanw 		    (GEM_NTXDESC - __x), (ops));			\
    226  1.1.2.2  nathanw 		__n -= (GEM_NTXDESC - __x);				\
    227  1.1.2.2  nathanw 		__x = 0;						\
    228  1.1.2.2  nathanw 	}								\
    229  1.1.2.2  nathanw 									\
    230  1.1.2.2  nathanw 	/* Now sync whatever is left. */				\
    231  1.1.2.2  nathanw 	bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,		\
    232  1.1.2.2  nathanw 	    GEM_CDTXOFF(__x), sizeof(struct gem_desc) * __n, (ops));	\
    233  1.1.2.2  nathanw } while (0)
    234  1.1.2.2  nathanw 
    235  1.1.2.2  nathanw #define	GEM_CDRXSYNC(sc, x, ops)					\
    236  1.1.2.2  nathanw 	bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,		\
    237  1.1.2.2  nathanw 	    GEM_CDRXOFF((x)), sizeof(struct gem_desc), (ops))
    238  1.1.2.2  nathanw 
    239  1.1.2.2  nathanw #define	GEM_CDSPSYNC(sc, ops)						\
    240  1.1.2.2  nathanw 	bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,		\
    241  1.1.2.2  nathanw 	    GEM_CDSPOFF, GEM_SETUP_PACKET_LEN, (ops))
    242  1.1.2.2  nathanw 
    243  1.1.2.2  nathanw #define	GEM_INIT_RXDESC(sc, x)						\
    244  1.1.2.2  nathanw do {									\
    245  1.1.2.2  nathanw 	struct gem_rxsoft *__rxs = &sc->sc_rxsoft[(x)];			\
    246  1.1.2.2  nathanw 	struct gem_desc *__rxd = &sc->sc_rxdescs[(x)];			\
    247  1.1.2.2  nathanw 	struct mbuf *__m = __rxs->rxs_mbuf;				\
    248  1.1.2.2  nathanw 									\
    249  1.1.2.2  nathanw 	__m->m_data = __m->m_ext.ext_buf;				\
    250  1.1.2.2  nathanw 	__rxd->gd_addr =						\
    251  1.1.2.3  nathanw 	    GEM_DMA_WRITE((sc), __rxs->rxs_dmamap->dm_segs[0].ds_addr);	\
    252  1.1.2.2  nathanw 	__rxd->gd_flags =						\
    253  1.1.2.3  nathanw 	    GEM_DMA_WRITE((sc),						\
    254  1.1.2.3  nathanw 			(((__m->m_ext.ext_size)<<GEM_RD_BUFSHIFT)	\
    255  1.1.2.3  nathanw 				& GEM_RD_BUFSIZE) | GEM_RD_OWN);	\
    256  1.1.2.2  nathanw 	GEM_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
    257  1.1.2.2  nathanw } while (0)
    258  1.1.2.2  nathanw 
    259  1.1.2.2  nathanw #ifdef _KERNEL
    260  1.1.2.4  nathanw void	gem_attach __P((struct gem_softc *, const uint8_t *));
    261  1.1.2.2  nathanw int	gem_intr __P((void *));
    262  1.1.2.2  nathanw 
    263  1.1.2.2  nathanw void	gem_reset __P((struct gem_softc *));
    264  1.1.2.2  nathanw #endif /* _KERNEL */
    265  1.1.2.2  nathanw 
    266  1.1.2.2  nathanw 
    267  1.1.2.2  nathanw #endif
    268