Home | History | Annotate | Line # | Download | only in dev
if_admswvar.h revision 1.1
      1  1.1  dyoung /* $NetBSD: if_admswvar.h,v 1.1 2007/03/20 08:52:02 dyoung Exp $ */
      2  1.1  dyoung 
      3  1.1  dyoung /*-
      4  1.1  dyoung  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
      5  1.1  dyoung  * All rights reserved.
      6  1.1  dyoung  *
      7  1.1  dyoung  * Redistribution and use in source and binary forms, with or
      8  1.1  dyoung  * without modification, are permitted provided that the following
      9  1.1  dyoung  * conditions are met:
     10  1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     11  1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     12  1.1  dyoung  * 2. Redistributions in binary form must reproduce the above
     13  1.1  dyoung  *    copyright notice, this list of conditions and the following
     14  1.1  dyoung  *    disclaimer in the documentation and/or other materials provided
     15  1.1  dyoung  *    with the distribution.
     16  1.1  dyoung  * 3. The names of the authors may not be used to endorse or promote
     17  1.1  dyoung  *    products derived from this software without specific prior
     18  1.1  dyoung  *    written permission.
     19  1.1  dyoung  *
     20  1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
     21  1.1  dyoung  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     22  1.1  dyoung  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     23  1.1  dyoung  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS
     24  1.1  dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     25  1.1  dyoung  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     26  1.1  dyoung  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
     27  1.1  dyoung  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  dyoung  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     29  1.1  dyoung  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     30  1.1  dyoung  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
     31  1.1  dyoung  * OF SUCH DAMAGE.
     32  1.1  dyoung  */
     33  1.1  dyoung #ifndef	_IF_ADMSWVAR_H_
     34  1.1  dyoung #define	_IF_ADMSWVAR_H_
     35  1.1  dyoung 
     36  1.1  dyoung #include <sys/cdefs.h>
     37  1.1  dyoung __KERNEL_RCSID(0, "$NetBSD: if_admswvar.h,v 1.1 2007/03/20 08:52:02 dyoung Exp $");
     38  1.1  dyoung 
     39  1.1  dyoung #include "bpfilter.h"
     40  1.1  dyoung 
     41  1.1  dyoung #include <sys/param.h>
     42  1.1  dyoung #include <sys/systm.h>
     43  1.1  dyoung #include <sys/callout.h>
     44  1.1  dyoung #include <sys/mbuf.h>
     45  1.1  dyoung #include <sys/malloc.h>
     46  1.1  dyoung #include <sys/kernel.h>
     47  1.1  dyoung #include <sys/socket.h>
     48  1.1  dyoung #include <sys/ioctl.h>
     49  1.1  dyoung #include <sys/errno.h>
     50  1.1  dyoung #include <sys/device.h>
     51  1.1  dyoung #include <sys/queue.h>
     52  1.1  dyoung #include <sys/wdog.h>
     53  1.1  dyoung 
     54  1.1  dyoung #include <uvm/uvm_extern.h>		/* for PAGE_SIZE */
     55  1.1  dyoung 
     56  1.1  dyoung #include <net/if.h>
     57  1.1  dyoung #include <net/if_dl.h>
     58  1.1  dyoung #include <net/if_media.h>
     59  1.1  dyoung #include <net/if_ether.h>
     60  1.1  dyoung 
     61  1.1  dyoung #if NBPFILTER > 0
     62  1.1  dyoung #include <net/bpf.h>
     63  1.1  dyoung #endif
     64  1.1  dyoung 
     65  1.1  dyoung #include <machine/bus.h>
     66  1.1  dyoung #include <machine/intr.h>
     67  1.1  dyoung #include <machine/endian.h>
     68  1.1  dyoung 
     69  1.1  dyoung #include <dev/mii/mii.h>
     70  1.1  dyoung #include <dev/mii/miivar.h>
     71  1.1  dyoung 
     72  1.1  dyoung #include <dev/sysmon/sysmonvar.h>
     73  1.1  dyoung 
     74  1.1  dyoung #include <mips/adm5120/include/adm5120reg.h>
     75  1.1  dyoung #include <mips/adm5120/include/adm5120var.h>
     76  1.1  dyoung #include <mips/adm5120/include/adm5120_obiovar.h>
     77  1.1  dyoung 
     78  1.1  dyoung #include <mips/adm5120/dev/if_admswreg.h>
     79  1.1  dyoung 
     80  1.1  dyoung #define	ADMSW_EVENT_COUNTERS
     81  1.1  dyoung 
     82  1.1  dyoung #define	MAC_BUFLEN	0x07ff
     83  1.1  dyoung 
     84  1.1  dyoung #define	ADMSW_NTXHDESC	4
     85  1.1  dyoung #define	ADMSW_NRXHDESC	32
     86  1.1  dyoung #define	ADMSW_NTXLDESC	32
     87  1.1  dyoung #define	ADMSW_NRXLDESC	32
     88  1.1  dyoung 
     89  1.1  dyoung #define	ADMSW_NTXHDESC_MASK	(ADMSW_NTXHDESC - 1)
     90  1.1  dyoung #define	ADMSW_NRXHDESC_MASK	(ADMSW_NRXHDESC - 1)
     91  1.1  dyoung #define	ADMSW_NTXLDESC_MASK	(ADMSW_NTXLDESC - 1)
     92  1.1  dyoung #define	ADMSW_NRXLDESC_MASK	(ADMSW_NRXLDESC - 1)
     93  1.1  dyoung 
     94  1.1  dyoung #define	ADMSW_NEXTTXH(x)	(((x) + 1) & ADMSW_NTXHDESC_MASK)
     95  1.1  dyoung #define	ADMSW_NEXTRXH(x)	(((x) + 1) & ADMSW_NRXHDESC_MASK)
     96  1.1  dyoung #define	ADMSW_NEXTTXL(x)	(((x) + 1) & ADMSW_NTXLDESC_MASK)
     97  1.1  dyoung #define	ADMSW_NEXTRXL(x)	(((x) + 1) & ADMSW_NRXLDESC_MASK)
     98  1.1  dyoung 
     99  1.1  dyoung struct admsw_control_data {
    100  1.1  dyoung 	/* The transmit descriptors. */
    101  1.1  dyoung 	struct admsw_desc acd_txhdescs[ADMSW_NTXHDESC];
    102  1.1  dyoung 
    103  1.1  dyoung 	/* The receive descriptors. */
    104  1.1  dyoung 	struct admsw_desc acd_rxhdescs[ADMSW_NRXHDESC];
    105  1.1  dyoung 
    106  1.1  dyoung 	/* The transmit descriptors. */
    107  1.1  dyoung 	struct admsw_desc acd_txldescs[ADMSW_NTXLDESC];
    108  1.1  dyoung 
    109  1.1  dyoung 	/* The receive descriptors. */
    110  1.1  dyoung 	struct admsw_desc acd_rxldescs[ADMSW_NRXLDESC];
    111  1.1  dyoung };
    112  1.1  dyoung 
    113  1.1  dyoung #define	ADMSW_CDOFF(x)		offsetof(struct admsw_control_data, x)
    114  1.1  dyoung #define	ADMSW_CDTXHOFF(x)	ADMSW_CDOFF(acd_txhdescs[(x)])
    115  1.1  dyoung #define	ADMSW_CDTXLOFF(x)	ADMSW_CDOFF(acd_txldescs[(x)])
    116  1.1  dyoung #define	ADMSW_CDRXHOFF(x)	ADMSW_CDOFF(acd_rxhdescs[(x)])
    117  1.1  dyoung #define	ADMSW_CDRXLOFF(x)	ADMSW_CDOFF(acd_rxldescs[(x)])
    118  1.1  dyoung 
    119  1.1  dyoung struct admsw_descsoft {
    120  1.1  dyoung 	struct mbuf *ds_mbuf;
    121  1.1  dyoung 	bus_dmamap_t ds_dmamap;
    122  1.1  dyoung };
    123  1.1  dyoung 
    124  1.1  dyoung /*
    125  1.1  dyoung  * Software state per device.
    126  1.1  dyoung  */
    127  1.1  dyoung struct admsw_softc {
    128  1.1  dyoung 	struct device sc_dev;		/* generic device information */
    129  1.1  dyoung 	uint8_t		sc_enaddr[ETHER_ADDR_LEN];
    130  1.1  dyoung 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
    131  1.1  dyoung 	bus_space_tag_t sc_st;		/* bus space tag */
    132  1.1  dyoung 	bus_space_handle_t sc_ioh;	/* MAC space handle */
    133  1.1  dyoung 	struct sysmon_wdog	sc_smw;
    134  1.1  dyoung 	struct ifmedia sc_ifmedia[SW_DEVS];
    135  1.1  dyoung 	int ndevs;			/* number of IFF_RUNNING interfaces */
    136  1.1  dyoung 	struct ethercom sc_ethercom[SW_DEVS];	/* Ethernet common data */
    137  1.1  dyoung 	void *sc_sdhook;		/* shutdown hook */
    138  1.1  dyoung 	void *sc_ih;			/* interrupt cookie */
    139  1.1  dyoung 	struct admsw_descsoft sc_txhsoft[ADMSW_NTXHDESC];
    140  1.1  dyoung 	struct admsw_descsoft sc_rxhsoft[ADMSW_NRXHDESC];
    141  1.1  dyoung 	struct admsw_descsoft sc_txlsoft[ADMSW_NTXLDESC];
    142  1.1  dyoung 	struct admsw_descsoft sc_rxlsoft[ADMSW_NRXLDESC];
    143  1.1  dyoung 	bus_dmamap_t sc_cddmamap;	/* control data DMA map */
    144  1.1  dyoung #define	sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
    145  1.1  dyoung 	struct admsw_control_data *sc_control_data;
    146  1.1  dyoung #define	sc_txhdescs	sc_control_data->acd_txhdescs
    147  1.1  dyoung #define	sc_rxhdescs	sc_control_data->acd_rxhdescs
    148  1.1  dyoung #define	sc_txldescs	sc_control_data->acd_txldescs
    149  1.1  dyoung #define	sc_rxldescs	sc_control_data->acd_rxldescs
    150  1.1  dyoung 
    151  1.1  dyoung 	int sc_txfree;			/* number of free Tx descriptors */
    152  1.1  dyoung 	int sc_txnext;			/* next Tx descriptor to use */
    153  1.1  dyoung 	int sc_txdirty;			/* first dirty Tx descriptor */
    154  1.1  dyoung 
    155  1.1  dyoung 	int sc_rxptr;			/* next ready Rx descriptor */
    156  1.1  dyoung 
    157  1.1  dyoung #ifdef ADMSW_EVENT_COUNTERS
    158  1.1  dyoung 	struct evcnt sc_ev_txstall;	/* Tx stalled */
    159  1.1  dyoung 	struct evcnt sc_ev_rxstall;	/* Rx stalled */
    160  1.1  dyoung 	struct evcnt sc_ev_txintr;	/* Tx interrupts */
    161  1.1  dyoung 	struct evcnt sc_ev_rxintr;	/* Rx interrupts */
    162  1.1  dyoung #if 1
    163  1.1  dyoung 	struct evcnt sc_ev_rxsync;	/* Rx syncs */
    164  1.1  dyoung #endif
    165  1.1  dyoung #endif
    166  1.1  dyoung 
    167  1.1  dyoung };
    168  1.1  dyoung 
    169  1.1  dyoung #define	ADMSW_CDTXHADDR(sc, x)	((sc)->sc_cddma + ADMSW_CDTXHOFF((x)))
    170  1.1  dyoung #define	ADMSW_CDTXLADDR(sc, x)	((sc)->sc_cddma + ADMSW_CDTXLOFF((x)))
    171  1.1  dyoung #define	ADMSW_CDRXHADDR(sc, x)	((sc)->sc_cddma + ADMSW_CDRXHOFF((x)))
    172  1.1  dyoung #define	ADMSW_CDRXLADDR(sc, x)	((sc)->sc_cddma + ADMSW_CDRXLOFF((x)))
    173  1.1  dyoung 
    174  1.1  dyoung #define	ADMSW_CDTXHSYNC(sc, x, ops)					\
    175  1.1  dyoung 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    176  1.1  dyoung 	    ADMSW_CDTXHOFF((x)), sizeof(struct admsw_desc), (ops))
    177  1.1  dyoung 
    178  1.1  dyoung #define	ADMSW_CDTXLSYNC(sc, x, ops)					\
    179  1.1  dyoung 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    180  1.1  dyoung 	    ADMSW_CDTXLOFF((x)), sizeof(struct admsw_desc), (ops))
    181  1.1  dyoung 
    182  1.1  dyoung #define	ADMSW_CDRXHSYNC(sc, x, ops)					\
    183  1.1  dyoung 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    184  1.1  dyoung 	    ADMSW_CDRXHOFF((x)), sizeof(struct admsw_desc), (ops))
    185  1.1  dyoung 
    186  1.1  dyoung #define	ADMSW_CDRXLSYNC(sc, x, ops)					\
    187  1.1  dyoung 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    188  1.1  dyoung 	    ADMSW_CDRXLOFF((x)), sizeof(struct admsw_desc), (ops))
    189  1.1  dyoung 
    190  1.1  dyoung #define	ADMSW_INIT_RXHDESC(sc, x)				\
    191  1.1  dyoung do {								\
    192  1.1  dyoung 	struct admsw_descsoft *__ds = &(sc)->sc_rxhsoft[(x)];	\
    193  1.1  dyoung 	struct admsw_desc *__desc = &(sc)->sc_rxhdescs[(x)];	\
    194  1.1  dyoung 	struct mbuf *__m = __ds->ds_mbuf;			\
    195  1.1  dyoung 								\
    196  1.1  dyoung 	__m->m_data = __m->m_ext.ext_buf + 2;			\
    197  1.1  dyoung 	__desc->data = __ds->ds_dmamap->dm_segs[0].ds_addr + 2;	\
    198  1.1  dyoung 	__desc->cntl = 0;					\
    199  1.1  dyoung 	__desc->len = min(MCLBYTES - 2, MAC_BUFLEN - 2);	\
    200  1.1  dyoung 	__desc->status = 0;					\
    201  1.1  dyoung 	if ((x) == ADMSW_NRXHDESC - 1)				\
    202  1.1  dyoung 		__desc->data |= ADM5120_DMA_RINGEND;		\
    203  1.1  dyoung 	__desc->data |= ADM5120_DMA_OWN;			\
    204  1.1  dyoung 	ADMSW_CDRXHSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
    205  1.1  dyoung } while (0)
    206  1.1  dyoung 
    207  1.1  dyoung #define	ADMSW_INIT_RXLDESC(sc, x)				\
    208  1.1  dyoung do {								\
    209  1.1  dyoung 	struct admsw_descsoft *__ds = &(sc)->sc_rxlsoft[(x)];	\
    210  1.1  dyoung 	struct admsw_desc *__desc = &(sc)->sc_rxldescs[(x)];	\
    211  1.1  dyoung 	struct mbuf *__m = __ds->ds_mbuf;			\
    212  1.1  dyoung 								\
    213  1.1  dyoung 	__m->m_data = __m->m_ext.ext_buf + 2;			\
    214  1.1  dyoung 	__desc->data = __ds->ds_dmamap->dm_segs[0].ds_addr + 2;	\
    215  1.1  dyoung 	__desc->cntl = 0;					\
    216  1.1  dyoung 	__desc->len = min(MCLBYTES - 2, MAC_BUFLEN - 2);	\
    217  1.1  dyoung 	__desc->status = 0;					\
    218  1.1  dyoung 	if ((x) == ADMSW_NRXLDESC - 1)				\
    219  1.1  dyoung 		__desc->data |= ADM5120_DMA_RINGEND;		\
    220  1.1  dyoung 	__desc->data |= ADM5120_DMA_OWN;			\
    221  1.1  dyoung 	ADMSW_CDRXLSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
    222  1.1  dyoung } while (0)
    223  1.1  dyoung 
    224  1.1  dyoung void admwdog_attach(struct admsw_softc *);
    225  1.1  dyoung 
    226  1.1  dyoung #endif /* _IF_ADMSWVAR_H_ */
    227