Home | History | Annotate | Line # | Download | only in ic
gemvar.h revision 1.21.10.2
      1  1.21.10.2      yamt /*	$NetBSD: gemvar.h,v 1.21.10.2 2012/10/30 17:21:03 yamt Exp $ */
      2        1.1       eeh 
      3        1.1       eeh /*
      4       1.10      heas  *
      5        1.1       eeh  * Copyright (C) 2001 Eduardo Horvath.
      6        1.1       eeh  * All rights reserved.
      7        1.1       eeh  *
      8        1.1       eeh  *
      9        1.1       eeh  * Redistribution and use in source and binary forms, with or without
     10        1.1       eeh  * modification, are permitted provided that the following conditions
     11        1.1       eeh  * are met:
     12        1.1       eeh  * 1. Redistributions of source code must retain the above copyright
     13        1.1       eeh  *    notice, this list of conditions and the following disclaimer.
     14        1.1       eeh  * 2. Redistributions in binary form must reproduce the above copyright
     15        1.1       eeh  *    notice, this list of conditions and the following disclaimer in the
     16        1.1       eeh  *    documentation and/or other materials provided with the distribution.
     17       1.10      heas  *
     18        1.1       eeh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
     19        1.1       eeh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20        1.1       eeh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21        1.1       eeh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
     22        1.1       eeh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23        1.1       eeh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24        1.1       eeh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25        1.1       eeh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26        1.1       eeh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27        1.1       eeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28        1.1       eeh  * SUCH DAMAGE.
     29        1.1       eeh  *
     30        1.1       eeh  */
     31        1.1       eeh 
     32        1.1       eeh #ifndef	_IF_GEMVAR_H
     33        1.1       eeh #define	_IF_GEMVAR_H
     34        1.1       eeh 
     35        1.1       eeh 
     36        1.1       eeh #include <sys/queue.h>
     37        1.1       eeh #include <sys/callout.h>
     38        1.1       eeh 
     39        1.1       eeh #include <sys/rnd.h>
     40        1.1       eeh 
     41        1.1       eeh /*
     42       1.10      heas  * Misc. definitions for the Sun ``Gem'' Ethernet controller family driver.
     43        1.1       eeh  */
     44        1.1       eeh 
     45        1.1       eeh /*
     46        1.1       eeh  * Transmit descriptor list size.  This is arbitrary, but allocate
     47        1.1       eeh  * enough descriptors for 64 pending transmissions and 16 segments
     48       1.10      heas  * per packet.
     49        1.1       eeh  */
     50        1.1       eeh #define	GEM_NTXSEGS		16
     51        1.1       eeh 
     52        1.1       eeh #define	GEM_TXQUEUELEN		64
     53        1.1       eeh #define	GEM_NTXDESC		(GEM_TXQUEUELEN * GEM_NTXSEGS)
     54        1.1       eeh #define	GEM_NTXDESC_MASK	(GEM_NTXDESC - 1)
     55        1.1       eeh #define	GEM_NEXTTX(x)		((x + 1) & GEM_NTXDESC_MASK)
     56        1.1       eeh 
     57        1.1       eeh /*
     58        1.1       eeh  * Receive descriptor list size.  We have one Rx buffer per incoming
     59        1.1       eeh  * packet, so this logic is a little simpler.
     60        1.1       eeh  */
     61        1.2       eeh #define	GEM_NRXDESC		128
     62        1.1       eeh #define	GEM_NRXDESC_MASK	(GEM_NRXDESC - 1)
     63        1.8      matt #define	GEM_PREVRX(x)		((x - 1) & GEM_NRXDESC_MASK)
     64        1.1       eeh #define	GEM_NEXTRX(x)		((x + 1) & GEM_NRXDESC_MASK)
     65        1.1       eeh 
     66        1.1       eeh /*
     67        1.1       eeh  * Control structures are DMA'd to the GEM chip.  We allocate them in
     68        1.1       eeh  * a single clump that maps to a single DMA segment to make several things
     69        1.1       eeh  * easier.
     70        1.1       eeh  */
     71        1.1       eeh struct gem_control_data {
     72        1.1       eeh 	/*
     73        1.1       eeh 	 * The transmit descriptors.
     74        1.1       eeh 	 */
     75        1.1       eeh 	struct gem_desc gcd_txdescs[GEM_NTXDESC];
     76        1.1       eeh 
     77        1.1       eeh 	/*
     78        1.1       eeh 	 * The receive descriptors.
     79        1.1       eeh 	 */
     80        1.1       eeh 	struct gem_desc gcd_rxdescs[GEM_NRXDESC];
     81        1.1       eeh };
     82        1.1       eeh 
     83        1.1       eeh #define	GEM_CDOFF(x)		offsetof(struct gem_control_data, x)
     84        1.1       eeh #define	GEM_CDTXOFF(x)		GEM_CDOFF(gcd_txdescs[(x)])
     85        1.1       eeh #define	GEM_CDRXOFF(x)		GEM_CDOFF(gcd_rxdescs[(x)])
     86        1.1       eeh 
     87        1.1       eeh /*
     88        1.1       eeh  * Software state for transmit jobs.
     89        1.1       eeh  */
     90        1.1       eeh struct gem_txsoft {
     91        1.1       eeh 	struct mbuf *txs_mbuf;		/* head of our mbuf chain */
     92        1.1       eeh 	bus_dmamap_t txs_dmamap;	/* our DMA map */
     93        1.1       eeh 	int txs_firstdesc;		/* first descriptor in packet */
     94        1.1       eeh 	int txs_lastdesc;		/* last descriptor in packet */
     95        1.1       eeh 	int txs_ndescs;			/* number of descriptors */
     96        1.1       eeh 	SIMPLEQ_ENTRY(gem_txsoft) txs_q;
     97        1.1       eeh };
     98        1.1       eeh 
     99        1.1       eeh SIMPLEQ_HEAD(gem_txsq, gem_txsoft);
    100        1.1       eeh 
    101        1.1       eeh /*
    102        1.1       eeh  * Software state for receive jobs.
    103        1.1       eeh  */
    104        1.1       eeh struct gem_rxsoft {
    105        1.1       eeh 	struct mbuf *rxs_mbuf;		/* head of our mbuf chain */
    106        1.1       eeh 	bus_dmamap_t rxs_dmamap;	/* our DMA map */
    107        1.1       eeh };
    108        1.1       eeh 
    109       1.19    dyoung enum gem_attach_stage {
    110       1.19    dyoung 	  GEM_ATT_BACKEND_2 = 0
    111       1.19    dyoung 	, GEM_ATT_BACKEND_1
    112       1.19    dyoung 	, GEM_ATT_FINISHED
    113       1.19    dyoung 	, GEM_ATT_MII
    114       1.19    dyoung 	, GEM_ATT_7
    115       1.19    dyoung 	, GEM_ATT_6
    116       1.19    dyoung 	, GEM_ATT_5
    117       1.19    dyoung 	, GEM_ATT_4
    118       1.19    dyoung 	, GEM_ATT_3
    119       1.19    dyoung 	, GEM_ATT_2
    120       1.19    dyoung 	, GEM_ATT_1
    121       1.19    dyoung 	, GEM_ATT_0
    122       1.19    dyoung 	, GEM_ATT_BACKEND_0
    123       1.19    dyoung };
    124       1.19    dyoung 
    125        1.1       eeh /*
    126        1.1       eeh  * Software state per device.
    127        1.1       eeh  */
    128        1.1       eeh struct gem_softc {
    129       1.19    dyoung 	device_t	sc_dev;		/* generic device information */
    130        1.1       eeh 	struct ethercom sc_ethercom;	/* ethernet common data */
    131        1.1       eeh 	struct mii_data	sc_mii;		/* MII media control */
    132        1.1       eeh 	struct callout	sc_tick_ch;	/* tick callout */
    133  1.21.10.2      yamt 	struct callout	sc_rx_watchdog;	/* RX watchdog callout */
    134        1.1       eeh 
    135        1.1       eeh 	/* The following bus handles are to be provided by the bus front-end */
    136        1.1       eeh 	bus_space_tag_t	sc_bustag;	/* bus tag */
    137        1.1       eeh 	bus_dma_tag_t	sc_dmatag;	/* bus dma tag */
    138        1.1       eeh 	bus_dmamap_t	sc_dmamap;	/* bus dma handle */
    139       1.15    martin 	bus_space_handle_t sc_h1;	/* bus space handle for bank 1 regs */
    140       1.15    martin 	bus_space_handle_t sc_h2;	/* bus space handle for bank 2 regs */
    141       1.19    dyoung 	bus_size_t	sc_size;	/* bank 1 size */
    142        1.5   thorpej 
    143        1.1       eeh 	int		sc_phys[2];	/* MII instance -> PHY map */
    144        1.1       eeh 
    145        1.1       eeh 	int		sc_mif_config;	/* Selected MII reg setting */
    146       1.16       jdc 	uint32_t	sc_mii_anar;	/* copy of PCS GEM_MII_ANAR register */
    147       1.16       jdc 	int		sc_mii_media;	/* Media selected for PCS MII */
    148        1.1       eeh 
    149        1.7      matt 	u_int		sc_variant;	/* which GEM are we dealing with? */
    150        1.7      matt #define	GEM_UNKNOWN		0	/* don't know */
    151        1.7      matt #define	GEM_SUN_GEM		1	/* Sun GEM variant */
    152       1.16       jdc #define	GEM_SUN_ERI		2	/* Sun ERI variant */
    153       1.16       jdc #define	GEM_APPLE_GMAC		3	/* Apple GMAC variant */
    154       1.16       jdc #define GEM_APPLE_K2_GMAC	4	/* Apple K2 GMAC */
    155       1.16       jdc 
    156       1.18       jdc #define GEM_IS_SUN(sc) \
    157       1.18       jdc 	((sc)->sc_variant == GEM_SUN_GEM || \
    158       1.18       jdc 	(sc)->sc_variant == GEM_SUN_ERI)
    159       1.16       jdc #define	GEM_IS_APPLE(sc) \
    160       1.16       jdc 	((sc)->sc_variant == GEM_APPLE_GMAC || \
    161       1.16       jdc 	(sc)->sc_variant == GEM_APPLE_K2_GMAC)
    162        1.7      matt 
    163       1.18       jdc 	int		sc_chiprev;	/* hardware revision */
    164       1.18       jdc 
    165        1.7      matt 	u_int		sc_flags;	/* */
    166       1.13  christos 	short		sc_if_flags;	/* copy of ifp->if_flags */
    167        1.7      matt #define	GEM_GIGABIT		0x0001	/* has a gigabit PHY */
    168       1.16       jdc #define GEM_LINK		0x0002	/* link is up */
    169       1.16       jdc #define	GEM_PCI			0x0004	/* XXX PCI busses are little-endian */
    170       1.16       jdc #define	GEM_SERDES		0x0008	/* use the SERDES */
    171       1.16       jdc #define	GEM_SERIAL		0x0010	/* use the serial link */
    172        1.1       eeh 
    173        1.1       eeh 	/*
    174        1.1       eeh 	 * Ring buffer DMA stuff.
    175        1.1       eeh 	 */
    176        1.1       eeh 	bus_dma_segment_t sc_cdseg;	/* control data memory */
    177        1.1       eeh 	int		sc_cdnseg;	/* number of segments */
    178        1.1       eeh 	bus_dmamap_t sc_cddmamap;	/* control data DMA map */
    179        1.1       eeh #define	sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
    180        1.1       eeh 
    181       1.12    bouyer 	bus_dmamap_t sc_nulldmamap;	/* for small packets padding */
    182       1.12    bouyer 
    183        1.1       eeh 	/*
    184        1.1       eeh 	 * Software state for transmit and receive descriptors.
    185        1.1       eeh 	 */
    186        1.1       eeh 	struct gem_txsoft sc_txsoft[GEM_TXQUEUELEN];
    187        1.1       eeh 	struct gem_rxsoft sc_rxsoft[GEM_NRXDESC];
    188        1.1       eeh 
    189        1.1       eeh 	/*
    190        1.1       eeh 	 * Control data structures.
    191        1.1       eeh 	 */
    192        1.1       eeh 	struct gem_control_data *sc_control_data;
    193        1.1       eeh #define	sc_txdescs	sc_control_data->gcd_txdescs
    194        1.1       eeh #define	sc_rxdescs	sc_control_data->gcd_rxdescs
    195        1.1       eeh 
    196        1.5   thorpej 	int		sc_txfree;	/* number of free Tx descriptors */
    197        1.5   thorpej 	int		sc_txnext;	/* next ready Tx descriptor */
    198        1.6      matt 	int		sc_txwin;	/* Tx descriptors since last Tx int */
    199        1.1       eeh 
    200        1.5   thorpej 	struct gem_txsq	sc_txfreeq;	/* free Tx descsofts */
    201        1.5   thorpej 	struct gem_txsq	sc_txdirtyq;	/* dirty Tx descsofts */
    202        1.1       eeh 
    203        1.5   thorpej 	int		sc_rxptr;	/* next ready RX descriptor/descsoft */
    204        1.7      matt 	int		sc_rxfifosize;	/* Rx FIFO size (bytes) */
    205        1.1       eeh 
    206        1.1       eeh 	/* ========== */
    207        1.5   thorpej 	int		sc_inited;
    208       1.16       jdc 	int		sc_meminited;
    209        1.5   thorpej 	int		sc_debug;
    210        1.5   thorpej 	void		*sc_sh;		/* shutdownhook cookie */
    211        1.1       eeh 
    212        1.1       eeh 	/* Special hardware hooks */
    213       1.11     perry 	void	(*sc_hwreset)(struct gem_softc *);
    214       1.11     perry 	void	(*sc_hwinit)(struct gem_softc *);
    215        1.1       eeh 
    216  1.21.10.1      yamt 	krndsource_t	rnd_source;
    217        1.8      matt 
    218        1.8      matt 	struct evcnt sc_ev_intr;
    219        1.9      matt #ifdef GEM_COUNTERS
    220        1.8      matt 	struct evcnt sc_ev_txint;
    221        1.8      matt 	struct evcnt sc_ev_rxint;
    222        1.8      matt 	struct evcnt sc_ev_rxnobuf;
    223        1.8      matt 	struct evcnt sc_ev_rxfull;
    224        1.8      matt 	struct evcnt sc_ev_rxhist[9];
    225        1.9      matt #endif
    226       1.19    dyoung 
    227  1.21.10.2      yamt 	/* For use by the RX watchdog */
    228  1.21.10.2      yamt 	u_int32_t 	sc_rx_fifo_wr_ptr;
    229  1.21.10.2      yamt 	u_int32_t	sc_rx_fifo_rd_ptr;
    230  1.21.10.2      yamt 
    231       1.19    dyoung 	enum gem_attach_stage	sc_att_stage;
    232        1.1       eeh };
    233        1.9      matt 
    234        1.9      matt #ifdef GEM_COUNTERS
    235        1.9      matt #define	GEM_COUNTER_INCR(sc, ctr)	((void) (sc->ctr.ev_count++))
    236        1.9      matt #else
    237        1.9      matt #define	GEM_COUNTER_INCR(sc, ctr)	((void) sc)
    238        1.9      matt #endif
    239        1.1       eeh 
    240        1.1       eeh 
    241       1.16       jdc #define	GEM_DMA_READ(sc, v)						\
    242       1.16       jdc 	(((sc)->sc_flags & GEM_PCI) ? le64toh(v) : be64toh(v))
    243       1.16       jdc #define	GEM_DMA_WRITE(sc, v)						\
    244       1.16       jdc 	(((sc)->sc_flags & GEM_PCI) ? htole64(v) : htobe64(v))
    245        1.1       eeh 
    246        1.1       eeh #define	GEM_CDTXADDR(sc, x)	((sc)->sc_cddma + GEM_CDTXOFF((x)))
    247        1.1       eeh #define	GEM_CDRXADDR(sc, x)	((sc)->sc_cddma + GEM_CDRXOFF((x)))
    248        1.1       eeh 
    249       1.16       jdc #define	GEM_CDADDR(sc)	((sc)->sc_cddma + GEM_CDOFF)
    250        1.1       eeh 
    251        1.1       eeh #define	GEM_CDTXSYNC(sc, x, n, ops)					\
    252        1.1       eeh do {									\
    253        1.1       eeh 	int __x, __n;							\
    254        1.1       eeh 									\
    255        1.1       eeh 	__x = (x);							\
    256        1.1       eeh 	__n = (n);							\
    257        1.1       eeh 									\
    258        1.1       eeh 	/* If it will wrap around, sync to the end of the ring. */	\
    259        1.1       eeh 	if ((__x + __n) > GEM_NTXDESC) {				\
    260        1.1       eeh 		bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,	\
    261        1.1       eeh 		    GEM_CDTXOFF(__x), sizeof(struct gem_desc) *		\
    262        1.1       eeh 		    (GEM_NTXDESC - __x), (ops));			\
    263        1.1       eeh 		__n -= (GEM_NTXDESC - __x);				\
    264        1.1       eeh 		__x = 0;						\
    265        1.1       eeh 	}								\
    266        1.1       eeh 									\
    267        1.1       eeh 	/* Now sync whatever is left. */				\
    268        1.1       eeh 	bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,		\
    269        1.1       eeh 	    GEM_CDTXOFF(__x), sizeof(struct gem_desc) * __n, (ops));	\
    270        1.1       eeh } while (0)
    271        1.1       eeh 
    272        1.1       eeh #define	GEM_CDRXSYNC(sc, x, ops)					\
    273        1.1       eeh 	bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,		\
    274        1.1       eeh 	    GEM_CDRXOFF((x)), sizeof(struct gem_desc), (ops))
    275        1.1       eeh 
    276       1.16       jdc #define	GEM_CDSYNC(sc, ops)						\
    277        1.1       eeh 	bus_dmamap_sync((sc)->sc_dmatag, (sc)->sc_cddmamap,		\
    278       1.16       jdc 	    0, sizeof(struct gem_control_data), (ops))
    279        1.1       eeh 
    280        1.1       eeh #define	GEM_INIT_RXDESC(sc, x)						\
    281        1.1       eeh do {									\
    282        1.1       eeh 	struct gem_rxsoft *__rxs = &sc->sc_rxsoft[(x)];			\
    283        1.1       eeh 	struct gem_desc *__rxd = &sc->sc_rxdescs[(x)];			\
    284        1.1       eeh 	struct mbuf *__m = __rxs->rxs_mbuf;				\
    285        1.1       eeh 									\
    286        1.1       eeh 	__m->m_data = __m->m_ext.ext_buf;				\
    287        1.1       eeh 	__rxd->gd_addr =						\
    288        1.2       eeh 	    GEM_DMA_WRITE((sc), __rxs->rxs_dmamap->dm_segs[0].ds_addr);	\
    289        1.1       eeh 	__rxd->gd_flags =						\
    290        1.2       eeh 	    GEM_DMA_WRITE((sc),						\
    291        1.2       eeh 			(((__m->m_ext.ext_size)<<GEM_RD_BUFSHIFT)	\
    292        1.2       eeh 				& GEM_RD_BUFSIZE) | GEM_RD_OWN);	\
    293        1.1       eeh 	GEM_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
    294        1.1       eeh } while (0)
    295        1.1       eeh 
    296       1.16       jdc #define GEM_UPDATE_RXDESC(sc, x)					\
    297       1.16       jdc do {									\
    298       1.16       jdc 	struct gem_rxsoft *__rxs = &sc->sc_rxsoft[(x)];			\
    299       1.16       jdc 	struct gem_desc *__rxd = &sc->sc_rxdescs[(x)];			\
    300       1.16       jdc 	struct mbuf *__m = __rxs->rxs_mbuf;				\
    301       1.16       jdc 									\
    302       1.16       jdc 	__rxd->gd_flags =						\
    303       1.16       jdc 	    GEM_DMA_WRITE((sc),						\
    304       1.16       jdc 			(((__m->m_ext.ext_size)<<GEM_RD_BUFSHIFT)	\
    305       1.16       jdc 				& GEM_RD_BUFSIZE) | GEM_RD_OWN);	\
    306       1.16       jdc } while (0)
    307       1.16       jdc 
    308        1.1       eeh #ifdef _KERNEL
    309       1.19    dyoung bool	gem_shutdown(device_t, int);
    310       1.21    dyoung bool	gem_suspend(device_t, const pmf_qual_t *);
    311       1.21    dyoung bool	gem_resume(device_t, const pmf_qual_t *);
    312       1.11     perry void	gem_attach(struct gem_softc *, const uint8_t *);
    313       1.11     perry int	gem_intr(void *);
    314       1.19    dyoung int	gem_detach(struct gem_softc *, int);
    315        1.1       eeh 
    316       1.11     perry void	gem_reset(struct gem_softc *);
    317        1.1       eeh #endif /* _KERNEL */
    318        1.1       eeh 
    319        1.1       eeh 
    320        1.1       eeh #endif
    321