Home | History | Annotate | Line # | Download | only in pci
if_ste.c revision 1.6.2.6
      1  1.6.2.6  nathanw /*	$NetBSD: if_ste.c,v 1.6.2.6 2002/11/11 22:11:09 nathanw Exp $	*/
      2  1.6.2.2  nathanw 
      3  1.6.2.2  nathanw /*-
      4  1.6.2.2  nathanw  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.6.2.2  nathanw  * All rights reserved.
      6  1.6.2.2  nathanw  *
      7  1.6.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.6.2.2  nathanw  * by Jason R. Thorpe.
      9  1.6.2.2  nathanw  *
     10  1.6.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.6.2.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.6.2.2  nathanw  * are met:
     13  1.6.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.6.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.6.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.6.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.6.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.6.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.6.2.2  nathanw  *    must display the following acknowledgement:
     20  1.6.2.2  nathanw  *	This product includes software developed by the NetBSD
     21  1.6.2.2  nathanw  *	Foundation, Inc. and its contributors.
     22  1.6.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.6.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.6.2.2  nathanw  *    from this software without specific prior written permission.
     25  1.6.2.2  nathanw  *
     26  1.6.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.6.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.6.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.6.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.6.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.6.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.6.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.6.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.6.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.6.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.6.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.6.2.2  nathanw  */
     38  1.6.2.2  nathanw 
     39  1.6.2.2  nathanw /*
     40  1.6.2.2  nathanw  * Device driver for the Sundance Tech. ST-201 10/100
     41  1.6.2.2  nathanw  * Ethernet controller.
     42  1.6.2.2  nathanw  */
     43  1.6.2.2  nathanw 
     44  1.6.2.3  nathanw #include <sys/cdefs.h>
     45  1.6.2.6  nathanw __KERNEL_RCSID(0, "$NetBSD: if_ste.c,v 1.6.2.6 2002/11/11 22:11:09 nathanw Exp $");
     46  1.6.2.3  nathanw 
     47  1.6.2.2  nathanw #include "bpfilter.h"
     48  1.6.2.2  nathanw 
     49  1.6.2.2  nathanw #include <sys/param.h>
     50  1.6.2.2  nathanw #include <sys/systm.h>
     51  1.6.2.2  nathanw #include <sys/callout.h>
     52  1.6.2.2  nathanw #include <sys/mbuf.h>
     53  1.6.2.2  nathanw #include <sys/malloc.h>
     54  1.6.2.2  nathanw #include <sys/kernel.h>
     55  1.6.2.2  nathanw #include <sys/socket.h>
     56  1.6.2.2  nathanw #include <sys/ioctl.h>
     57  1.6.2.2  nathanw #include <sys/errno.h>
     58  1.6.2.2  nathanw #include <sys/device.h>
     59  1.6.2.2  nathanw #include <sys/queue.h>
     60  1.6.2.2  nathanw 
     61  1.6.2.2  nathanw #include <uvm/uvm_extern.h>		/* for PAGE_SIZE */
     62  1.6.2.2  nathanw 
     63  1.6.2.2  nathanw #include <net/if.h>
     64  1.6.2.2  nathanw #include <net/if_dl.h>
     65  1.6.2.2  nathanw #include <net/if_media.h>
     66  1.6.2.2  nathanw #include <net/if_ether.h>
     67  1.6.2.2  nathanw 
     68  1.6.2.2  nathanw #if NBPFILTER > 0
     69  1.6.2.2  nathanw #include <net/bpf.h>
     70  1.6.2.2  nathanw #endif
     71  1.6.2.2  nathanw 
     72  1.6.2.2  nathanw #include <machine/bus.h>
     73  1.6.2.2  nathanw #include <machine/intr.h>
     74  1.6.2.2  nathanw 
     75  1.6.2.2  nathanw #include <dev/mii/mii.h>
     76  1.6.2.2  nathanw #include <dev/mii/miivar.h>
     77  1.6.2.2  nathanw #include <dev/mii/mii_bitbang.h>
     78  1.6.2.2  nathanw 
     79  1.6.2.2  nathanw #include <dev/pci/pcireg.h>
     80  1.6.2.2  nathanw #include <dev/pci/pcivar.h>
     81  1.6.2.2  nathanw #include <dev/pci/pcidevs.h>
     82  1.6.2.2  nathanw 
     83  1.6.2.2  nathanw #include <dev/pci/if_stereg.h>
     84  1.6.2.2  nathanw 
     85  1.6.2.2  nathanw /*
     86  1.6.2.2  nathanw  * Transmit descriptor list size.
     87  1.6.2.2  nathanw  */
     88  1.6.2.2  nathanw #define	STE_NTXDESC		256
     89  1.6.2.2  nathanw #define	STE_NTXDESC_MASK	(STE_NTXDESC - 1)
     90  1.6.2.2  nathanw #define	STE_NEXTTX(x)		(((x) + 1) & STE_NTXDESC_MASK)
     91  1.6.2.2  nathanw 
     92  1.6.2.2  nathanw /*
     93  1.6.2.2  nathanw  * Receive descriptor list size.
     94  1.6.2.2  nathanw  */
     95  1.6.2.2  nathanw #define	STE_NRXDESC		128
     96  1.6.2.2  nathanw #define	STE_NRXDESC_MASK	(STE_NRXDESC - 1)
     97  1.6.2.2  nathanw #define	STE_NEXTRX(x)		(((x) + 1) & STE_NRXDESC_MASK)
     98  1.6.2.2  nathanw 
     99  1.6.2.2  nathanw /*
    100  1.6.2.2  nathanw  * Control structures are DMA'd to the ST-201 chip.  We allocate them in
    101  1.6.2.2  nathanw  * a single clump that maps to a single DMA segment to make several things
    102  1.6.2.2  nathanw  * easier.
    103  1.6.2.2  nathanw  */
    104  1.6.2.2  nathanw struct ste_control_data {
    105  1.6.2.2  nathanw 	/*
    106  1.6.2.2  nathanw 	 * The transmit descriptors.
    107  1.6.2.2  nathanw 	 */
    108  1.6.2.2  nathanw 	struct ste_tfd scd_txdescs[STE_NTXDESC];
    109  1.6.2.2  nathanw 
    110  1.6.2.2  nathanw 	/*
    111  1.6.2.2  nathanw 	 * The receive descriptors.
    112  1.6.2.2  nathanw 	 */
    113  1.6.2.2  nathanw 	struct ste_rfd scd_rxdescs[STE_NRXDESC];
    114  1.6.2.2  nathanw };
    115  1.6.2.2  nathanw 
    116  1.6.2.2  nathanw #define	STE_CDOFF(x)	offsetof(struct ste_control_data, x)
    117  1.6.2.2  nathanw #define	STE_CDTXOFF(x)	STE_CDOFF(scd_txdescs[(x)])
    118  1.6.2.2  nathanw #define	STE_CDRXOFF(x)	STE_CDOFF(scd_rxdescs[(x)])
    119  1.6.2.2  nathanw 
    120  1.6.2.2  nathanw /*
    121  1.6.2.2  nathanw  * Software state for transmit and receive jobs.
    122  1.6.2.2  nathanw  */
    123  1.6.2.2  nathanw struct ste_descsoft {
    124  1.6.2.2  nathanw 	struct mbuf *ds_mbuf;		/* head of our mbuf chain */
    125  1.6.2.2  nathanw 	bus_dmamap_t ds_dmamap;		/* our DMA map */
    126  1.6.2.2  nathanw };
    127  1.6.2.2  nathanw 
    128  1.6.2.2  nathanw /*
    129  1.6.2.2  nathanw  * Software state per device.
    130  1.6.2.2  nathanw  */
    131  1.6.2.2  nathanw struct ste_softc {
    132  1.6.2.2  nathanw 	struct device sc_dev;		/* generic device information */
    133  1.6.2.2  nathanw 	bus_space_tag_t sc_st;		/* bus space tag */
    134  1.6.2.2  nathanw 	bus_space_handle_t sc_sh;	/* bus space handle */
    135  1.6.2.2  nathanw 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
    136  1.6.2.2  nathanw 	struct ethercom sc_ethercom;	/* ethernet common data */
    137  1.6.2.2  nathanw 	void *sc_sdhook;		/* shutdown hook */
    138  1.6.2.2  nathanw 
    139  1.6.2.2  nathanw 	void *sc_ih;			/* interrupt cookie */
    140  1.6.2.2  nathanw 
    141  1.6.2.2  nathanw 	struct mii_data sc_mii;		/* MII/media information */
    142  1.6.2.2  nathanw 
    143  1.6.2.2  nathanw 	struct callout sc_tick_ch;	/* tick callout */
    144  1.6.2.2  nathanw 
    145  1.6.2.2  nathanw 	bus_dmamap_t sc_cddmamap;	/* control data DMA map */
    146  1.6.2.2  nathanw #define	sc_cddma	sc_cddmamap->dm_segs[0].ds_addr
    147  1.6.2.2  nathanw 
    148  1.6.2.2  nathanw 	/*
    149  1.6.2.2  nathanw 	 * Software state for transmit and receive descriptors.
    150  1.6.2.2  nathanw 	 */
    151  1.6.2.2  nathanw 	struct ste_descsoft sc_txsoft[STE_NTXDESC];
    152  1.6.2.2  nathanw 	struct ste_descsoft sc_rxsoft[STE_NRXDESC];
    153  1.6.2.2  nathanw 
    154  1.6.2.2  nathanw 	/*
    155  1.6.2.2  nathanw 	 * Control data structures.
    156  1.6.2.2  nathanw 	 */
    157  1.6.2.2  nathanw 	struct ste_control_data *sc_control_data;
    158  1.6.2.2  nathanw #define	sc_txdescs	sc_control_data->scd_txdescs
    159  1.6.2.2  nathanw #define	sc_rxdescs	sc_control_data->scd_rxdescs
    160  1.6.2.2  nathanw 
    161  1.6.2.2  nathanw 	int	sc_txpending;		/* number of Tx requests pending */
    162  1.6.2.2  nathanw 	int	sc_txdirty;		/* first dirty Tx descriptor */
    163  1.6.2.2  nathanw 	int	sc_txlast;		/* last used Tx descriptor */
    164  1.6.2.2  nathanw 
    165  1.6.2.2  nathanw 	int	sc_rxptr;		/* next ready Rx descriptor/descsoft */
    166  1.6.2.2  nathanw 
    167  1.6.2.2  nathanw 	int	sc_txthresh;		/* Tx threshold */
    168  1.6.2.2  nathanw 	uint32_t sc_DMACtrl;		/* prototype DMACtrl register */
    169  1.6.2.2  nathanw 	uint16_t sc_IntEnable;		/* prototype IntEnable register */
    170  1.6.2.2  nathanw 	uint16_t sc_MacCtrl0;		/* prototype MacCtrl0 register */
    171  1.6.2.2  nathanw 	uint8_t	sc_ReceiveMode;		/* prototype ReceiveMode register */
    172  1.6.2.2  nathanw };
    173  1.6.2.2  nathanw 
    174  1.6.2.2  nathanw #define	STE_CDTXADDR(sc, x)	((sc)->sc_cddma + STE_CDTXOFF((x)))
    175  1.6.2.2  nathanw #define	STE_CDRXADDR(sc, x)	((sc)->sc_cddma + STE_CDRXOFF((x)))
    176  1.6.2.2  nathanw 
    177  1.6.2.2  nathanw #define	STE_CDTXSYNC(sc, x, ops)					\
    178  1.6.2.2  nathanw 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    179  1.6.2.2  nathanw 	    STE_CDTXOFF((x)), sizeof(struct ste_tfd), (ops))
    180  1.6.2.2  nathanw 
    181  1.6.2.2  nathanw #define	STE_CDRXSYNC(sc, x, ops)					\
    182  1.6.2.2  nathanw 	bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap,		\
    183  1.6.2.2  nathanw 	    STE_CDRXOFF((x)), sizeof(struct ste_rfd), (ops))
    184  1.6.2.2  nathanw 
    185  1.6.2.2  nathanw #define	STE_INIT_RXDESC(sc, x)						\
    186  1.6.2.2  nathanw do {									\
    187  1.6.2.2  nathanw 	struct ste_descsoft *__ds = &(sc)->sc_rxsoft[(x)];		\
    188  1.6.2.2  nathanw 	struct ste_rfd *__rfd = &(sc)->sc_rxdescs[(x)];			\
    189  1.6.2.2  nathanw 	struct mbuf *__m = __ds->ds_mbuf;				\
    190  1.6.2.2  nathanw 									\
    191  1.6.2.2  nathanw 	/*								\
    192  1.6.2.2  nathanw 	 * Note: We scoot the packet forward 2 bytes in the buffer	\
    193  1.6.2.2  nathanw 	 * so that the payload after the Ethernet header is aligned	\
    194  1.6.2.2  nathanw 	 * to a 4-byte boundary.					\
    195  1.6.2.2  nathanw 	 */								\
    196  1.6.2.2  nathanw 	__m->m_data = __m->m_ext.ext_buf + 2;				\
    197  1.6.2.2  nathanw 	__rfd->rfd_frag.frag_addr =					\
    198  1.6.2.2  nathanw 	    htole32(__ds->ds_dmamap->dm_segs[0].ds_addr + 2);		\
    199  1.6.2.2  nathanw 	__rfd->rfd_frag.frag_len = htole32((MCLBYTES - 2) | FRAG_LAST);	\
    200  1.6.2.2  nathanw 	__rfd->rfd_next = htole32(STE_CDRXADDR((sc), STE_NEXTRX((x))));	\
    201  1.6.2.2  nathanw 	__rfd->rfd_status = 0;						\
    202  1.6.2.2  nathanw 	STE_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
    203  1.6.2.2  nathanw } while (/*CONSTCOND*/0)
    204  1.6.2.2  nathanw 
    205  1.6.2.2  nathanw #define STE_TIMEOUT 1000
    206  1.6.2.2  nathanw 
    207  1.6.2.2  nathanw void	ste_start(struct ifnet *);
    208  1.6.2.2  nathanw void	ste_watchdog(struct ifnet *);
    209  1.6.2.2  nathanw int	ste_ioctl(struct ifnet *, u_long, caddr_t);
    210  1.6.2.2  nathanw int	ste_init(struct ifnet *);
    211  1.6.2.2  nathanw void	ste_stop(struct ifnet *, int);
    212  1.6.2.2  nathanw 
    213  1.6.2.2  nathanw void	ste_shutdown(void *);
    214  1.6.2.2  nathanw 
    215  1.6.2.4  nathanw void	ste_reset(struct ste_softc *, u_int32_t);
    216  1.6.2.4  nathanw void	ste_setthresh(struct ste_softc *);
    217  1.6.2.4  nathanw void	ste_txrestart(struct ste_softc *, u_int8_t);
    218  1.6.2.2  nathanw void	ste_rxdrain(struct ste_softc *);
    219  1.6.2.2  nathanw int	ste_add_rxbuf(struct ste_softc *, int);
    220  1.6.2.2  nathanw void	ste_read_eeprom(struct ste_softc *, int, uint16_t *);
    221  1.6.2.2  nathanw void	ste_tick(void *);
    222  1.6.2.2  nathanw 
    223  1.6.2.2  nathanw void	ste_stats_update(struct ste_softc *);
    224  1.6.2.2  nathanw 
    225  1.6.2.2  nathanw void	ste_set_filter(struct ste_softc *);
    226  1.6.2.2  nathanw 
    227  1.6.2.2  nathanw int	ste_intr(void *);
    228  1.6.2.2  nathanw void	ste_txintr(struct ste_softc *);
    229  1.6.2.2  nathanw void	ste_rxintr(struct ste_softc *);
    230  1.6.2.2  nathanw 
    231  1.6.2.2  nathanw int	ste_mii_readreg(struct device *, int, int);
    232  1.6.2.2  nathanw void	ste_mii_writereg(struct device *, int, int, int);
    233  1.6.2.2  nathanw void	ste_mii_statchg(struct device *);
    234  1.6.2.2  nathanw 
    235  1.6.2.2  nathanw int	ste_mediachange(struct ifnet *);
    236  1.6.2.2  nathanw void	ste_mediastatus(struct ifnet *, struct ifmediareq *);
    237  1.6.2.2  nathanw 
    238  1.6.2.2  nathanw int	ste_match(struct device *, struct cfdata *, void *);
    239  1.6.2.2  nathanw void	ste_attach(struct device *, struct device *, void *);
    240  1.6.2.2  nathanw 
    241  1.6.2.2  nathanw int	ste_copy_small = 0;
    242  1.6.2.2  nathanw 
    243  1.6.2.5  nathanw CFATTACH_DECL(ste, sizeof(struct ste_softc),
    244  1.6.2.5  nathanw     ste_match, ste_attach, NULL, NULL);
    245  1.6.2.2  nathanw 
    246  1.6.2.2  nathanw uint32_t ste_mii_bitbang_read(struct device *);
    247  1.6.2.2  nathanw void	ste_mii_bitbang_write(struct device *, uint32_t);
    248  1.6.2.2  nathanw 
    249  1.6.2.2  nathanw const struct mii_bitbang_ops ste_mii_bitbang_ops = {
    250  1.6.2.2  nathanw 	ste_mii_bitbang_read,
    251  1.6.2.2  nathanw 	ste_mii_bitbang_write,
    252  1.6.2.2  nathanw 	{
    253  1.6.2.2  nathanw 		PC_MgmtData,		/* MII_BIT_MDO */
    254  1.6.2.2  nathanw 		PC_MgmtData,		/* MII_BIT_MDI */
    255  1.6.2.2  nathanw 		PC_MgmtClk,		/* MII_BIT_MDC */
    256  1.6.2.2  nathanw 		PC_MgmtDir,		/* MII_BIT_DIR_HOST_PHY */
    257  1.6.2.2  nathanw 		0,			/* MII_BIT_DIR_PHY_HOST */
    258  1.6.2.2  nathanw 	}
    259  1.6.2.2  nathanw };
    260  1.6.2.2  nathanw 
    261  1.6.2.2  nathanw /*
    262  1.6.2.2  nathanw  * Devices supported by this driver.
    263  1.6.2.2  nathanw  */
    264  1.6.2.2  nathanw const struct ste_product {
    265  1.6.2.2  nathanw 	pci_vendor_id_t		ste_vendor;
    266  1.6.2.2  nathanw 	pci_product_id_t	ste_product;
    267  1.6.2.2  nathanw 	const char		*ste_name;
    268  1.6.2.2  nathanw } ste_products[] = {
    269  1.6.2.2  nathanw 	{ PCI_VENDOR_SUNDANCETI,	PCI_PRODUCT_SUNDANCETI_ST201,
    270  1.6.2.2  nathanw 	  "Sundance ST-201 10/100 Ethernet" },
    271  1.6.2.2  nathanw 
    272  1.6.2.2  nathanw 	{ PCI_VENDOR_DLINK,		PCI_PRODUCT_DLINK_DL1002,
    273  1.6.2.2  nathanw 	  "D-Link DL-1002 10/100 Ethernet" },
    274  1.6.2.2  nathanw 
    275  1.6.2.2  nathanw 	{ 0,				0,
    276  1.6.2.2  nathanw 	  NULL },
    277  1.6.2.2  nathanw };
    278  1.6.2.2  nathanw 
    279  1.6.2.2  nathanw static const struct ste_product *
    280  1.6.2.2  nathanw ste_lookup(const struct pci_attach_args *pa)
    281  1.6.2.2  nathanw {
    282  1.6.2.2  nathanw 	const struct ste_product *sp;
    283  1.6.2.2  nathanw 
    284  1.6.2.2  nathanw 	for (sp = ste_products; sp->ste_name != NULL; sp++) {
    285  1.6.2.2  nathanw 		if (PCI_VENDOR(pa->pa_id) == sp->ste_vendor &&
    286  1.6.2.2  nathanw 		    PCI_PRODUCT(pa->pa_id) == sp->ste_product)
    287  1.6.2.2  nathanw 			return (sp);
    288  1.6.2.2  nathanw 	}
    289  1.6.2.2  nathanw 	return (NULL);
    290  1.6.2.2  nathanw }
    291  1.6.2.2  nathanw 
    292  1.6.2.2  nathanw int
    293  1.6.2.2  nathanw ste_match(struct device *parent, struct cfdata *cf, void *aux)
    294  1.6.2.2  nathanw {
    295  1.6.2.2  nathanw 	struct pci_attach_args *pa = aux;
    296  1.6.2.2  nathanw 
    297  1.6.2.2  nathanw 	if (ste_lookup(pa) != NULL)
    298  1.6.2.2  nathanw 		return (1);
    299  1.6.2.2  nathanw 
    300  1.6.2.2  nathanw 	return (0);
    301  1.6.2.2  nathanw }
    302  1.6.2.2  nathanw 
    303  1.6.2.2  nathanw void
    304  1.6.2.2  nathanw ste_attach(struct device *parent, struct device *self, void *aux)
    305  1.6.2.2  nathanw {
    306  1.6.2.2  nathanw 	struct ste_softc *sc = (struct ste_softc *) self;
    307  1.6.2.2  nathanw 	struct pci_attach_args *pa = aux;
    308  1.6.2.2  nathanw 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    309  1.6.2.2  nathanw 	pci_chipset_tag_t pc = pa->pa_pc;
    310  1.6.2.2  nathanw 	pci_intr_handle_t ih;
    311  1.6.2.2  nathanw 	const char *intrstr = NULL;
    312  1.6.2.2  nathanw 	bus_space_tag_t iot, memt;
    313  1.6.2.2  nathanw 	bus_space_handle_t ioh, memh;
    314  1.6.2.2  nathanw 	bus_dma_segment_t seg;
    315  1.6.2.2  nathanw 	int ioh_valid, memh_valid;
    316  1.6.2.2  nathanw 	int i, rseg, error;
    317  1.6.2.2  nathanw 	const struct ste_product *sp;
    318  1.6.2.2  nathanw 	pcireg_t pmode;
    319  1.6.2.2  nathanw 	uint8_t enaddr[ETHER_ADDR_LEN];
    320  1.6.2.2  nathanw 	uint16_t myea[ETHER_ADDR_LEN / 2];
    321  1.6.2.2  nathanw 	int pmreg;
    322  1.6.2.2  nathanw 
    323  1.6.2.2  nathanw 	callout_init(&sc->sc_tick_ch);
    324  1.6.2.2  nathanw 
    325  1.6.2.2  nathanw 	sp = ste_lookup(pa);
    326  1.6.2.2  nathanw 	if (sp == NULL) {
    327  1.6.2.2  nathanw 		printf("\n");
    328  1.6.2.2  nathanw 		panic("ste_attach: impossible");
    329  1.6.2.2  nathanw 	}
    330  1.6.2.2  nathanw 
    331  1.6.2.2  nathanw 	printf(": %s\n", sp->ste_name);
    332  1.6.2.2  nathanw 
    333  1.6.2.2  nathanw 	/*
    334  1.6.2.2  nathanw 	 * Map the device.
    335  1.6.2.2  nathanw 	 */
    336  1.6.2.2  nathanw 	ioh_valid = (pci_mapreg_map(pa, STE_PCI_IOBA,
    337  1.6.2.2  nathanw 	    PCI_MAPREG_TYPE_IO, 0,
    338  1.6.2.2  nathanw 	    &iot, &ioh, NULL, NULL) == 0);
    339  1.6.2.2  nathanw 	memh_valid = (pci_mapreg_map(pa, STE_PCI_MMBA,
    340  1.6.2.2  nathanw 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    341  1.6.2.2  nathanw 	    &memt, &memh, NULL, NULL) == 0);
    342  1.6.2.2  nathanw 
    343  1.6.2.2  nathanw 	if (memh_valid) {
    344  1.6.2.2  nathanw 		sc->sc_st = memt;
    345  1.6.2.2  nathanw 		sc->sc_sh = memh;
    346  1.6.2.2  nathanw 	} else if (ioh_valid) {
    347  1.6.2.2  nathanw 		sc->sc_st = iot;
    348  1.6.2.2  nathanw 		sc->sc_sh = ioh;
    349  1.6.2.2  nathanw 	} else {
    350  1.6.2.2  nathanw 		printf("%s: unable to map device registers\n",
    351  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname);
    352  1.6.2.2  nathanw 		return;
    353  1.6.2.2  nathanw 	}
    354  1.6.2.2  nathanw 
    355  1.6.2.2  nathanw 	sc->sc_dmat = pa->pa_dmat;
    356  1.6.2.2  nathanw 
    357  1.6.2.2  nathanw 	/* Enable bus mastering. */
    358  1.6.2.2  nathanw 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    359  1.6.2.2  nathanw 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    360  1.6.2.2  nathanw 	    PCI_COMMAND_MASTER_ENABLE);
    361  1.6.2.2  nathanw 
    362  1.6.2.2  nathanw 	/* Get it out of power save mode if needed. */
    363  1.6.2.2  nathanw 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
    364  1.6.2.2  nathanw 		pmode = pci_conf_read(pc, pa->pa_tag, pmreg + 4) & 0x3;
    365  1.6.2.2  nathanw 		if (pmode == 3) {
    366  1.6.2.2  nathanw 			/*
    367  1.6.2.2  nathanw 			 * The card has lost all configuration data in
    368  1.6.2.2  nathanw 			 * this state, so punt.
    369  1.6.2.2  nathanw 			 */
    370  1.6.2.2  nathanw 			printf("%s: unable to wake up from power state D3\n",
    371  1.6.2.2  nathanw 			    sc->sc_dev.dv_xname);
    372  1.6.2.2  nathanw 			return;
    373  1.6.2.2  nathanw 		}
    374  1.6.2.2  nathanw 		if (pmode != 0) {
    375  1.6.2.2  nathanw 			printf("%s: waking up from power state D%d\n",
    376  1.6.2.2  nathanw 			    sc->sc_dev.dv_xname, pmode);
    377  1.6.2.2  nathanw 			pci_conf_write(pc, pa->pa_tag, pmreg + 4, 0);
    378  1.6.2.2  nathanw 		}
    379  1.6.2.2  nathanw 	}
    380  1.6.2.2  nathanw 
    381  1.6.2.2  nathanw 	/*
    382  1.6.2.2  nathanw 	 * Map and establish our interrupt.
    383  1.6.2.2  nathanw 	 */
    384  1.6.2.2  nathanw 	if (pci_intr_map(pa, &ih)) {
    385  1.6.2.2  nathanw 		printf("%s: unable to map interrupt\n", sc->sc_dev.dv_xname);
    386  1.6.2.2  nathanw 		return;
    387  1.6.2.2  nathanw 	}
    388  1.6.2.2  nathanw 	intrstr = pci_intr_string(pc, ih);
    389  1.6.2.2  nathanw 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ste_intr, sc);
    390  1.6.2.2  nathanw 	if (sc->sc_ih == NULL) {
    391  1.6.2.2  nathanw 		printf("%s: unable to establish interrupt",
    392  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname);
    393  1.6.2.2  nathanw 		if (intrstr != NULL)
    394  1.6.2.2  nathanw 			printf(" at %s", intrstr);
    395  1.6.2.2  nathanw 		printf("\n");
    396  1.6.2.2  nathanw 		return;
    397  1.6.2.2  nathanw 	}
    398  1.6.2.2  nathanw 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    399  1.6.2.2  nathanw 
    400  1.6.2.2  nathanw 	/*
    401  1.6.2.2  nathanw 	 * Allocate the control data structures, and create and load the
    402  1.6.2.2  nathanw 	 * DMA map for it.
    403  1.6.2.2  nathanw 	 */
    404  1.6.2.2  nathanw 	if ((error = bus_dmamem_alloc(sc->sc_dmat,
    405  1.6.2.2  nathanw 	    sizeof(struct ste_control_data), PAGE_SIZE, 0, &seg, 1, &rseg,
    406  1.6.2.2  nathanw 	    0)) != 0) {
    407  1.6.2.2  nathanw 		printf("%s: unable to allocate control data, error = %d\n",
    408  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname, error);
    409  1.6.2.2  nathanw 		goto fail_0;
    410  1.6.2.2  nathanw 	}
    411  1.6.2.2  nathanw 
    412  1.6.2.2  nathanw 	if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
    413  1.6.2.2  nathanw 	    sizeof(struct ste_control_data), (caddr_t *)&sc->sc_control_data,
    414  1.6.2.2  nathanw 	    BUS_DMA_COHERENT)) != 0) {
    415  1.6.2.2  nathanw 		printf("%s: unable to map control data, error = %d\n",
    416  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname, error);
    417  1.6.2.2  nathanw 		goto fail_1;
    418  1.6.2.2  nathanw 	}
    419  1.6.2.2  nathanw 
    420  1.6.2.2  nathanw 	if ((error = bus_dmamap_create(sc->sc_dmat,
    421  1.6.2.2  nathanw 	    sizeof(struct ste_control_data), 1,
    422  1.6.2.2  nathanw 	    sizeof(struct ste_control_data), 0, 0, &sc->sc_cddmamap)) != 0) {
    423  1.6.2.2  nathanw 		printf("%s: unable to create control data DMA map, "
    424  1.6.2.2  nathanw 		    "error = %d\n", sc->sc_dev.dv_xname, error);
    425  1.6.2.2  nathanw 		goto fail_2;
    426  1.6.2.2  nathanw 	}
    427  1.6.2.2  nathanw 
    428  1.6.2.2  nathanw 	if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap,
    429  1.6.2.2  nathanw 	    sc->sc_control_data, sizeof(struct ste_control_data), NULL,
    430  1.6.2.2  nathanw 	    0)) != 0) {
    431  1.6.2.2  nathanw 		printf("%s: unable to load control data DMA map, error = %d\n",
    432  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname, error);
    433  1.6.2.2  nathanw 		goto fail_3;
    434  1.6.2.2  nathanw 	}
    435  1.6.2.2  nathanw 
    436  1.6.2.2  nathanw 	/*
    437  1.6.2.2  nathanw 	 * Create the transmit buffer DMA maps.
    438  1.6.2.2  nathanw 	 */
    439  1.6.2.2  nathanw 	for (i = 0; i < STE_NTXDESC; i++) {
    440  1.6.2.2  nathanw 		if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
    441  1.6.2.2  nathanw 		    STE_NTXFRAGS, MCLBYTES, 0, 0,
    442  1.6.2.2  nathanw 		    &sc->sc_txsoft[i].ds_dmamap)) != 0) {
    443  1.6.2.2  nathanw 			printf("%s: unable to create tx DMA map %d, "
    444  1.6.2.2  nathanw 			    "error = %d\n", sc->sc_dev.dv_xname, i, error);
    445  1.6.2.2  nathanw 			goto fail_4;
    446  1.6.2.2  nathanw 		}
    447  1.6.2.2  nathanw 	}
    448  1.6.2.2  nathanw 
    449  1.6.2.2  nathanw 	/*
    450  1.6.2.2  nathanw 	 * Create the receive buffer DMA maps.
    451  1.6.2.2  nathanw 	 */
    452  1.6.2.2  nathanw 	for (i = 0; i < STE_NRXDESC; i++) {
    453  1.6.2.2  nathanw 		if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
    454  1.6.2.2  nathanw 		    MCLBYTES, 0, 0, &sc->sc_rxsoft[i].ds_dmamap)) != 0) {
    455  1.6.2.2  nathanw 			printf("%s: unable to create rx DMA map %d, "
    456  1.6.2.2  nathanw 			    "error = %d\n", sc->sc_dev.dv_xname, i, error);
    457  1.6.2.2  nathanw 			goto fail_5;
    458  1.6.2.2  nathanw 		}
    459  1.6.2.2  nathanw 		sc->sc_rxsoft[i].ds_mbuf = NULL;
    460  1.6.2.2  nathanw 	}
    461  1.6.2.2  nathanw 
    462  1.6.2.2  nathanw 	/*
    463  1.6.2.2  nathanw 	 * Reset the chip to a known state.
    464  1.6.2.2  nathanw 	 */
    465  1.6.2.4  nathanw 	ste_reset(sc, AC_GlobalReset | AC_RxReset | AC_TxReset | AC_DMA |
    466  1.6.2.4  nathanw 	    AC_FIFO | AC_Network | AC_Host | AC_AutoInit | AC_RstOut);
    467  1.6.2.2  nathanw 
    468  1.6.2.2  nathanw 	/*
    469  1.6.2.2  nathanw 	 * Read the Ethernet address from the EEPROM.
    470  1.6.2.2  nathanw 	 */
    471  1.6.2.2  nathanw 	for (i = 0; i < 3; i++) {
    472  1.6.2.2  nathanw 		ste_read_eeprom(sc, STE_EEPROM_StationAddress0 + i, &myea[i]);
    473  1.6.2.2  nathanw 		myea[i] = le16toh(myea[i]);
    474  1.6.2.2  nathanw 	}
    475  1.6.2.2  nathanw 	memcpy(enaddr, myea, sizeof(enaddr));
    476  1.6.2.2  nathanw 
    477  1.6.2.2  nathanw 	printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
    478  1.6.2.2  nathanw 	    ether_sprintf(enaddr));
    479  1.6.2.2  nathanw 
    480  1.6.2.2  nathanw 	/*
    481  1.6.2.2  nathanw 	 * Initialize our media structures and probe the MII.
    482  1.6.2.2  nathanw 	 */
    483  1.6.2.2  nathanw 	sc->sc_mii.mii_ifp = ifp;
    484  1.6.2.2  nathanw 	sc->sc_mii.mii_readreg = ste_mii_readreg;
    485  1.6.2.2  nathanw 	sc->sc_mii.mii_writereg = ste_mii_writereg;
    486  1.6.2.2  nathanw 	sc->sc_mii.mii_statchg = ste_mii_statchg;
    487  1.6.2.6  nathanw 	ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, ste_mediachange,
    488  1.6.2.2  nathanw 	    ste_mediastatus);
    489  1.6.2.2  nathanw 	mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
    490  1.6.2.2  nathanw 	    MII_OFFSET_ANY, 0);
    491  1.6.2.2  nathanw 	if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
    492  1.6.2.2  nathanw 		ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
    493  1.6.2.2  nathanw 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
    494  1.6.2.2  nathanw 	} else
    495  1.6.2.2  nathanw 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
    496  1.6.2.2  nathanw 
    497  1.6.2.2  nathanw 	ifp = &sc->sc_ethercom.ec_if;
    498  1.6.2.2  nathanw 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
    499  1.6.2.2  nathanw 	ifp->if_softc = sc;
    500  1.6.2.2  nathanw 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    501  1.6.2.2  nathanw 	ifp->if_ioctl = ste_ioctl;
    502  1.6.2.2  nathanw 	ifp->if_start = ste_start;
    503  1.6.2.2  nathanw 	ifp->if_watchdog = ste_watchdog;
    504  1.6.2.2  nathanw 	ifp->if_init = ste_init;
    505  1.6.2.2  nathanw 	ifp->if_stop = ste_stop;
    506  1.6.2.2  nathanw 	IFQ_SET_READY(&ifp->if_snd);
    507  1.6.2.2  nathanw 
    508  1.6.2.2  nathanw 	/*
    509  1.6.2.2  nathanw 	 * Default the transmit threshold to 128 bytes.
    510  1.6.2.2  nathanw 	 */
    511  1.6.2.2  nathanw 	sc->sc_txthresh = 128;
    512  1.6.2.2  nathanw 
    513  1.6.2.2  nathanw 	/*
    514  1.6.2.2  nathanw 	 * Disable MWI if the PCI layer tells us to.
    515  1.6.2.2  nathanw 	 */
    516  1.6.2.2  nathanw 	sc->sc_DMACtrl = 0;
    517  1.6.2.2  nathanw 	if ((pa->pa_flags & PCI_FLAGS_MWI_OKAY) == 0)
    518  1.6.2.2  nathanw 		sc->sc_DMACtrl |= DC_MWIDisable;
    519  1.6.2.2  nathanw 
    520  1.6.2.2  nathanw 	/*
    521  1.6.2.2  nathanw 	 * We can support 802.1Q VLAN-sized frames.
    522  1.6.2.2  nathanw 	 */
    523  1.6.2.2  nathanw 	sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
    524  1.6.2.2  nathanw 
    525  1.6.2.2  nathanw 	/*
    526  1.6.2.2  nathanw 	 * Attach the interface.
    527  1.6.2.2  nathanw 	 */
    528  1.6.2.2  nathanw 	if_attach(ifp);
    529  1.6.2.2  nathanw 	ether_ifattach(ifp, enaddr);
    530  1.6.2.2  nathanw 
    531  1.6.2.2  nathanw 	/*
    532  1.6.2.2  nathanw 	 * Make sure the interface is shutdown during reboot.
    533  1.6.2.2  nathanw 	 */
    534  1.6.2.2  nathanw 	sc->sc_sdhook = shutdownhook_establish(ste_shutdown, sc);
    535  1.6.2.2  nathanw 	if (sc->sc_sdhook == NULL)
    536  1.6.2.2  nathanw 		printf("%s: WARNING: unable to establish shutdown hook\n",
    537  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname);
    538  1.6.2.2  nathanw 	return;
    539  1.6.2.2  nathanw 
    540  1.6.2.2  nathanw 	/*
    541  1.6.2.2  nathanw 	 * Free any resources we've allocated during the failed attach
    542  1.6.2.2  nathanw 	 * attempt.  Do this in reverse order and fall through.
    543  1.6.2.2  nathanw 	 */
    544  1.6.2.2  nathanw  fail_5:
    545  1.6.2.2  nathanw 	for (i = 0; i < STE_NRXDESC; i++) {
    546  1.6.2.2  nathanw 		if (sc->sc_rxsoft[i].ds_dmamap != NULL)
    547  1.6.2.2  nathanw 			bus_dmamap_destroy(sc->sc_dmat,
    548  1.6.2.2  nathanw 			    sc->sc_rxsoft[i].ds_dmamap);
    549  1.6.2.2  nathanw 	}
    550  1.6.2.2  nathanw  fail_4:
    551  1.6.2.2  nathanw 	for (i = 0; i < STE_NTXDESC; i++) {
    552  1.6.2.2  nathanw 		if (sc->sc_txsoft[i].ds_dmamap != NULL)
    553  1.6.2.2  nathanw 			bus_dmamap_destroy(sc->sc_dmat,
    554  1.6.2.2  nathanw 			    sc->sc_txsoft[i].ds_dmamap);
    555  1.6.2.2  nathanw 	}
    556  1.6.2.2  nathanw 	bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap);
    557  1.6.2.2  nathanw  fail_3:
    558  1.6.2.2  nathanw 	bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap);
    559  1.6.2.2  nathanw  fail_2:
    560  1.6.2.2  nathanw 	bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_control_data,
    561  1.6.2.2  nathanw 	    sizeof(struct ste_control_data));
    562  1.6.2.2  nathanw  fail_1:
    563  1.6.2.2  nathanw 	bus_dmamem_free(sc->sc_dmat, &seg, rseg);
    564  1.6.2.2  nathanw  fail_0:
    565  1.6.2.2  nathanw 	return;
    566  1.6.2.2  nathanw }
    567  1.6.2.2  nathanw 
    568  1.6.2.2  nathanw /*
    569  1.6.2.2  nathanw  * ste_shutdown:
    570  1.6.2.2  nathanw  *
    571  1.6.2.2  nathanw  *	Make sure the interface is stopped at reboot time.
    572  1.6.2.2  nathanw  */
    573  1.6.2.2  nathanw void
    574  1.6.2.2  nathanw ste_shutdown(void *arg)
    575  1.6.2.2  nathanw {
    576  1.6.2.2  nathanw 	struct ste_softc *sc = arg;
    577  1.6.2.2  nathanw 
    578  1.6.2.2  nathanw 	ste_stop(&sc->sc_ethercom.ec_if, 1);
    579  1.6.2.2  nathanw }
    580  1.6.2.2  nathanw 
    581  1.6.2.2  nathanw static void
    582  1.6.2.2  nathanw ste_dmahalt_wait(struct ste_softc *sc)
    583  1.6.2.2  nathanw {
    584  1.6.2.2  nathanw 	int i;
    585  1.6.2.2  nathanw 
    586  1.6.2.2  nathanw 	for (i = 0; i < STE_TIMEOUT; i++) {
    587  1.6.2.2  nathanw 		delay(2);
    588  1.6.2.2  nathanw 		if ((bus_space_read_4(sc->sc_st, sc->sc_sh, STE_DMACtrl) &
    589  1.6.2.2  nathanw 		     DC_DMAHaltBusy) == 0)
    590  1.6.2.2  nathanw 			break;
    591  1.6.2.2  nathanw 	}
    592  1.6.2.2  nathanw 
    593  1.6.2.2  nathanw 	if (i == STE_TIMEOUT)
    594  1.6.2.2  nathanw 		printf("%s: DMA halt timed out\n", sc->sc_dev.dv_xname);
    595  1.6.2.2  nathanw }
    596  1.6.2.2  nathanw 
    597  1.6.2.2  nathanw /*
    598  1.6.2.2  nathanw  * ste_start:		[ifnet interface function]
    599  1.6.2.2  nathanw  *
    600  1.6.2.2  nathanw  *	Start packet transmission on the interface.
    601  1.6.2.2  nathanw  */
    602  1.6.2.2  nathanw void
    603  1.6.2.2  nathanw ste_start(struct ifnet *ifp)
    604  1.6.2.2  nathanw {
    605  1.6.2.2  nathanw 	struct ste_softc *sc = ifp->if_softc;
    606  1.6.2.2  nathanw 	struct mbuf *m0, *m;
    607  1.6.2.2  nathanw 	struct ste_descsoft *ds;
    608  1.6.2.2  nathanw 	struct ste_tfd *tfd;
    609  1.6.2.2  nathanw 	bus_dmamap_t dmamap;
    610  1.6.2.2  nathanw 	int error, olasttx, nexttx, opending, seg, totlen;
    611  1.6.2.2  nathanw 
    612  1.6.2.2  nathanw 	if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
    613  1.6.2.2  nathanw 		return;
    614  1.6.2.2  nathanw 
    615  1.6.2.2  nathanw 	/*
    616  1.6.2.2  nathanw 	 * Remember the previous number of pending transmissions
    617  1.6.2.2  nathanw 	 * and the current last descriptor in the list.
    618  1.6.2.2  nathanw 	 */
    619  1.6.2.2  nathanw 	opending = sc->sc_txpending;
    620  1.6.2.2  nathanw 	olasttx = sc->sc_txlast;
    621  1.6.2.2  nathanw 
    622  1.6.2.2  nathanw 	/*
    623  1.6.2.2  nathanw 	 * Loop through the send queue, setting up transmit descriptors
    624  1.6.2.2  nathanw 	 * until we drain the queue, or use up all available transmit
    625  1.6.2.2  nathanw 	 * descriptors.
    626  1.6.2.2  nathanw 	 */
    627  1.6.2.2  nathanw 	while (sc->sc_txpending < STE_NTXDESC) {
    628  1.6.2.2  nathanw 		/*
    629  1.6.2.2  nathanw 		 * Grab a packet off the queue.
    630  1.6.2.2  nathanw 		 */
    631  1.6.2.2  nathanw 		IFQ_POLL(&ifp->if_snd, m0);
    632  1.6.2.2  nathanw 		if (m0 == NULL)
    633  1.6.2.2  nathanw 			break;
    634  1.6.2.2  nathanw 		m = NULL;
    635  1.6.2.2  nathanw 
    636  1.6.2.2  nathanw 		/*
    637  1.6.2.2  nathanw 		 * Get the last and next available transmit descriptor.
    638  1.6.2.2  nathanw 		 */
    639  1.6.2.2  nathanw 		nexttx = STE_NEXTTX(sc->sc_txlast);
    640  1.6.2.2  nathanw 		tfd = &sc->sc_txdescs[nexttx];
    641  1.6.2.2  nathanw 		ds = &sc->sc_txsoft[nexttx];
    642  1.6.2.2  nathanw 
    643  1.6.2.2  nathanw 		dmamap = ds->ds_dmamap;
    644  1.6.2.2  nathanw 
    645  1.6.2.2  nathanw 		/*
    646  1.6.2.2  nathanw 		 * Load the DMA map.  If this fails, the packet either
    647  1.6.2.2  nathanw 		 * didn't fit in the alloted number of segments, or we
    648  1.6.2.2  nathanw 		 * were short on resources.  In this case, we'll copy
    649  1.6.2.2  nathanw 		 * and try again.
    650  1.6.2.2  nathanw 		 */
    651  1.6.2.2  nathanw 		if (bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0,
    652  1.6.2.2  nathanw 		    BUS_DMA_WRITE|BUS_DMA_NOWAIT) != 0) {
    653  1.6.2.2  nathanw 			MGETHDR(m, M_DONTWAIT, MT_DATA);
    654  1.6.2.2  nathanw 			if (m == NULL) {
    655  1.6.2.2  nathanw 				printf("%s: unable to allocate Tx mbuf\n",
    656  1.6.2.2  nathanw 				    sc->sc_dev.dv_xname);
    657  1.6.2.2  nathanw 				break;
    658  1.6.2.2  nathanw 			}
    659  1.6.2.2  nathanw 			if (m0->m_pkthdr.len > MHLEN) {
    660  1.6.2.2  nathanw 				MCLGET(m, M_DONTWAIT);
    661  1.6.2.2  nathanw 				if ((m->m_flags & M_EXT) == 0) {
    662  1.6.2.2  nathanw 					printf("%s: unable to allocate Tx "
    663  1.6.2.2  nathanw 					    "cluster\n", sc->sc_dev.dv_xname);
    664  1.6.2.2  nathanw 					m_freem(m);
    665  1.6.2.2  nathanw 					break;
    666  1.6.2.2  nathanw 				}
    667  1.6.2.2  nathanw 			}
    668  1.6.2.2  nathanw 			m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, caddr_t));
    669  1.6.2.2  nathanw 			m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
    670  1.6.2.2  nathanw 			error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap,
    671  1.6.2.2  nathanw 			    m, BUS_DMA_WRITE|BUS_DMA_NOWAIT);
    672  1.6.2.2  nathanw 			if (error) {
    673  1.6.2.2  nathanw 				printf("%s: unable to load Tx buffer, "
    674  1.6.2.2  nathanw 				    "error = %d\n", sc->sc_dev.dv_xname, error);
    675  1.6.2.2  nathanw 				break;
    676  1.6.2.2  nathanw 			}
    677  1.6.2.2  nathanw 		}
    678  1.6.2.2  nathanw 
    679  1.6.2.2  nathanw 		IFQ_DEQUEUE(&ifp->if_snd, m0);
    680  1.6.2.2  nathanw 		if (m != NULL) {
    681  1.6.2.2  nathanw 			m_freem(m0);
    682  1.6.2.2  nathanw 			m0 = m;
    683  1.6.2.2  nathanw 		}
    684  1.6.2.2  nathanw 
    685  1.6.2.2  nathanw 		/*
    686  1.6.2.2  nathanw 		 * WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
    687  1.6.2.2  nathanw 		 */
    688  1.6.2.2  nathanw 
    689  1.6.2.2  nathanw 		/* Sync the DMA map. */
    690  1.6.2.2  nathanw 		bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
    691  1.6.2.2  nathanw 		    BUS_DMASYNC_PREWRITE);
    692  1.6.2.2  nathanw 
    693  1.6.2.2  nathanw 		/* Initialize the fragment list. */
    694  1.6.2.2  nathanw 		for (totlen = 0, seg = 0; seg < dmamap->dm_nsegs; seg++) {
    695  1.6.2.2  nathanw 			tfd->tfd_frags[seg].frag_addr =
    696  1.6.2.2  nathanw 			    htole32(dmamap->dm_segs[seg].ds_addr);
    697  1.6.2.2  nathanw 			tfd->tfd_frags[seg].frag_len =
    698  1.6.2.2  nathanw 			    htole32(dmamap->dm_segs[seg].ds_len);
    699  1.6.2.2  nathanw 			totlen += dmamap->dm_segs[seg].ds_len;
    700  1.6.2.2  nathanw 		}
    701  1.6.2.2  nathanw 		tfd->tfd_frags[seg - 1].frag_len |= htole32(FRAG_LAST);
    702  1.6.2.2  nathanw 
    703  1.6.2.2  nathanw 		/* Initialize the descriptor. */
    704  1.6.2.2  nathanw 		tfd->tfd_next = htole32(STE_CDTXADDR(sc, nexttx));
    705  1.6.2.2  nathanw 		tfd->tfd_control = htole32(TFD_FrameId(nexttx) | (totlen & 3));
    706  1.6.2.2  nathanw 
    707  1.6.2.2  nathanw 		/* Sync the descriptor. */
    708  1.6.2.2  nathanw 		STE_CDTXSYNC(sc, nexttx,
    709  1.6.2.2  nathanw 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
    710  1.6.2.2  nathanw 
    711  1.6.2.2  nathanw 		/*
    712  1.6.2.2  nathanw 		 * Store a pointer to the packet so we can free it later,
    713  1.6.2.2  nathanw 		 * and remember what txdirty will be once the packet is
    714  1.6.2.2  nathanw 		 * done.
    715  1.6.2.2  nathanw 		 */
    716  1.6.2.2  nathanw 		ds->ds_mbuf = m0;
    717  1.6.2.2  nathanw 
    718  1.6.2.2  nathanw 		/* Advance the tx pointer. */
    719  1.6.2.2  nathanw 		sc->sc_txpending++;
    720  1.6.2.2  nathanw 		sc->sc_txlast = nexttx;
    721  1.6.2.2  nathanw 
    722  1.6.2.2  nathanw #if NBPFILTER > 0
    723  1.6.2.2  nathanw 		/*
    724  1.6.2.2  nathanw 		 * Pass the packet to any BPF listeners.
    725  1.6.2.2  nathanw 		 */
    726  1.6.2.2  nathanw 		if (ifp->if_bpf)
    727  1.6.2.2  nathanw 			bpf_mtap(ifp->if_bpf, m0);
    728  1.6.2.2  nathanw #endif /* NBPFILTER > 0 */
    729  1.6.2.2  nathanw 	}
    730  1.6.2.2  nathanw 
    731  1.6.2.2  nathanw 	if (sc->sc_txpending == STE_NTXDESC) {
    732  1.6.2.2  nathanw 		/* No more slots left; notify upper layer. */
    733  1.6.2.2  nathanw 		ifp->if_flags |= IFF_OACTIVE;
    734  1.6.2.2  nathanw 	}
    735  1.6.2.2  nathanw 
    736  1.6.2.2  nathanw 	if (sc->sc_txpending != opending) {
    737  1.6.2.2  nathanw 		/*
    738  1.6.2.2  nathanw 		 * We enqueued packets.  If the transmitter was idle,
    739  1.6.2.2  nathanw 		 * reset the txdirty pointer.
    740  1.6.2.2  nathanw 		 */
    741  1.6.2.2  nathanw 		if (opending == 0)
    742  1.6.2.2  nathanw 			sc->sc_txdirty = STE_NEXTTX(olasttx);
    743  1.6.2.2  nathanw 
    744  1.6.2.2  nathanw 		/*
    745  1.6.2.2  nathanw 		 * Cause a descriptor interrupt to happen on the
    746  1.6.2.2  nathanw 		 * last packet we enqueued, and also cause the
    747  1.6.2.2  nathanw 		 * DMA engine to wait after is has finished processing
    748  1.6.2.2  nathanw 		 * it.
    749  1.6.2.2  nathanw 		 */
    750  1.6.2.2  nathanw 		sc->sc_txdescs[sc->sc_txlast].tfd_next = 0;
    751  1.6.2.2  nathanw 		sc->sc_txdescs[sc->sc_txlast].tfd_control |=
    752  1.6.2.2  nathanw 		    htole32(TFD_TxDMAIndicate);
    753  1.6.2.2  nathanw 		STE_CDTXSYNC(sc, sc->sc_txlast,
    754  1.6.2.2  nathanw 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
    755  1.6.2.2  nathanw 
    756  1.6.2.2  nathanw 		/*
    757  1.6.2.2  nathanw 		 * Link up the new chain of descriptors to the
    758  1.6.2.2  nathanw 		 * last.
    759  1.6.2.2  nathanw 		 */
    760  1.6.2.2  nathanw 		sc->sc_txdescs[olasttx].tfd_next =
    761  1.6.2.2  nathanw 		    STE_CDTXADDR(sc, STE_NEXTTX(olasttx));
    762  1.6.2.2  nathanw 		STE_CDTXSYNC(sc, olasttx,
    763  1.6.2.2  nathanw 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
    764  1.6.2.2  nathanw 
    765  1.6.2.2  nathanw 		/*
    766  1.6.2.2  nathanw 		 * Kick the transmit DMA logic.  Note that since we're
    767  1.6.2.2  nathanw 		 * using auto-polling, reading the Tx desc pointer will
    768  1.6.2.2  nathanw 		 * give it the nudge it needs to get going.
    769  1.6.2.2  nathanw 		 */
    770  1.6.2.2  nathanw 		if (bus_space_read_4(sc->sc_st, sc->sc_sh,
    771  1.6.2.2  nathanw 		    STE_TxDMAListPtr) == 0) {
    772  1.6.2.2  nathanw 			bus_space_write_4(sc->sc_st, sc->sc_sh,
    773  1.6.2.2  nathanw 			    STE_DMACtrl, DC_TxDMAHalt);
    774  1.6.2.2  nathanw 			ste_dmahalt_wait(sc);
    775  1.6.2.2  nathanw 			bus_space_write_4(sc->sc_st, sc->sc_sh,
    776  1.6.2.2  nathanw 			    STE_TxDMAListPtr,
    777  1.6.2.2  nathanw 			    STE_CDTXADDR(sc, STE_NEXTTX(olasttx)));
    778  1.6.2.2  nathanw 			bus_space_write_4(sc->sc_st, sc->sc_sh,
    779  1.6.2.2  nathanw 			    STE_DMACtrl, DC_TxDMAResume);
    780  1.6.2.2  nathanw 		}
    781  1.6.2.2  nathanw 
    782  1.6.2.2  nathanw 		/* Set a watchdog timer in case the chip flakes out. */
    783  1.6.2.2  nathanw 		ifp->if_timer = 5;
    784  1.6.2.2  nathanw 	}
    785  1.6.2.2  nathanw }
    786  1.6.2.2  nathanw 
    787  1.6.2.2  nathanw /*
    788  1.6.2.2  nathanw  * ste_watchdog:	[ifnet interface function]
    789  1.6.2.2  nathanw  *
    790  1.6.2.2  nathanw  *	Watchdog timer handler.
    791  1.6.2.2  nathanw  */
    792  1.6.2.2  nathanw void
    793  1.6.2.2  nathanw ste_watchdog(struct ifnet *ifp)
    794  1.6.2.2  nathanw {
    795  1.6.2.2  nathanw 	struct ste_softc *sc = ifp->if_softc;
    796  1.6.2.2  nathanw 
    797  1.6.2.2  nathanw 	printf("%s: device timeout\n", sc->sc_dev.dv_xname);
    798  1.6.2.2  nathanw 	ifp->if_oerrors++;
    799  1.6.2.2  nathanw 
    800  1.6.2.2  nathanw 	(void) ste_init(ifp);
    801  1.6.2.2  nathanw 
    802  1.6.2.2  nathanw 	/* Try to get more packets going. */
    803  1.6.2.2  nathanw 	ste_start(ifp);
    804  1.6.2.2  nathanw }
    805  1.6.2.2  nathanw 
    806  1.6.2.2  nathanw /*
    807  1.6.2.2  nathanw  * ste_ioctl:		[ifnet interface function]
    808  1.6.2.2  nathanw  *
    809  1.6.2.2  nathanw  *	Handle control requests from the operator.
    810  1.6.2.2  nathanw  */
    811  1.6.2.2  nathanw int
    812  1.6.2.2  nathanw ste_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
    813  1.6.2.2  nathanw {
    814  1.6.2.2  nathanw 	struct ste_softc *sc = ifp->if_softc;
    815  1.6.2.2  nathanw 	struct ifreq *ifr = (struct ifreq *)data;
    816  1.6.2.2  nathanw 	int s, error;
    817  1.6.2.2  nathanw 
    818  1.6.2.2  nathanw 	s = splnet();
    819  1.6.2.2  nathanw 
    820  1.6.2.2  nathanw 	switch (cmd) {
    821  1.6.2.2  nathanw 	case SIOCSIFMEDIA:
    822  1.6.2.2  nathanw 	case SIOCGIFMEDIA:
    823  1.6.2.2  nathanw 		error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii.mii_media, cmd);
    824  1.6.2.2  nathanw 		break;
    825  1.6.2.2  nathanw 
    826  1.6.2.2  nathanw 	default:
    827  1.6.2.2  nathanw 		error = ether_ioctl(ifp, cmd, data);
    828  1.6.2.2  nathanw 		if (error == ENETRESET) {
    829  1.6.2.2  nathanw 			/*
    830  1.6.2.2  nathanw 			 * Multicast list has changed; set the hardware filter
    831  1.6.2.2  nathanw 			 * accordingly.
    832  1.6.2.2  nathanw 			 */
    833  1.6.2.2  nathanw 			ste_set_filter(sc);
    834  1.6.2.2  nathanw 			error = 0;
    835  1.6.2.2  nathanw 		}
    836  1.6.2.2  nathanw 		break;
    837  1.6.2.2  nathanw 	}
    838  1.6.2.2  nathanw 
    839  1.6.2.2  nathanw 	/* Try to get more packets going. */
    840  1.6.2.2  nathanw 	ste_start(ifp);
    841  1.6.2.2  nathanw 
    842  1.6.2.2  nathanw 	splx(s);
    843  1.6.2.2  nathanw 	return (error);
    844  1.6.2.2  nathanw }
    845  1.6.2.2  nathanw 
    846  1.6.2.2  nathanw /*
    847  1.6.2.2  nathanw  * ste_intr:
    848  1.6.2.2  nathanw  *
    849  1.6.2.2  nathanw  *	Interrupt service routine.
    850  1.6.2.2  nathanw  */
    851  1.6.2.2  nathanw int
    852  1.6.2.2  nathanw ste_intr(void *arg)
    853  1.6.2.2  nathanw {
    854  1.6.2.2  nathanw 	struct ste_softc *sc = arg;
    855  1.6.2.2  nathanw 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    856  1.6.2.2  nathanw 	uint16_t isr;
    857  1.6.2.2  nathanw 	uint8_t txstat;
    858  1.6.2.2  nathanw 	int wantinit;
    859  1.6.2.2  nathanw 
    860  1.6.2.2  nathanw 	if ((bus_space_read_2(sc->sc_st, sc->sc_sh, STE_IntStatus) &
    861  1.6.2.2  nathanw 	     IS_InterruptStatus) == 0)
    862  1.6.2.2  nathanw 		return (0);
    863  1.6.2.2  nathanw 
    864  1.6.2.2  nathanw 	for (wantinit = 0; wantinit == 0;) {
    865  1.6.2.2  nathanw 		isr = bus_space_read_2(sc->sc_st, sc->sc_sh, STE_IntStatusAck);
    866  1.6.2.2  nathanw 		if ((isr & sc->sc_IntEnable) == 0)
    867  1.6.2.2  nathanw 			break;
    868  1.6.2.2  nathanw 
    869  1.6.2.2  nathanw 		/* Receive interrupts. */
    870  1.6.2.2  nathanw 		if (isr & IE_RxDMAComplete)
    871  1.6.2.2  nathanw 			ste_rxintr(sc);
    872  1.6.2.2  nathanw 
    873  1.6.2.2  nathanw 		/* Transmit interrupts. */
    874  1.6.2.2  nathanw 		if (isr & (IE_TxDMAComplete|IE_TxComplete))
    875  1.6.2.2  nathanw 			ste_txintr(sc);
    876  1.6.2.2  nathanw 
    877  1.6.2.2  nathanw 		/* Statistics overflow. */
    878  1.6.2.2  nathanw 		if (isr & IE_UpdateStats)
    879  1.6.2.2  nathanw 			ste_stats_update(sc);
    880  1.6.2.2  nathanw 
    881  1.6.2.2  nathanw 		/* Transmission errors. */
    882  1.6.2.2  nathanw 		if (isr & IE_TxComplete) {
    883  1.6.2.2  nathanw 			for (;;) {
    884  1.6.2.2  nathanw 				txstat = bus_space_read_1(sc->sc_st, sc->sc_sh,
    885  1.6.2.2  nathanw 				    STE_TxStatus);
    886  1.6.2.2  nathanw 				if ((txstat & TS_TxComplete) == 0)
    887  1.6.2.2  nathanw 					break;
    888  1.6.2.2  nathanw 				if (txstat & TS_TxUnderrun) {
    889  1.6.2.2  nathanw 					sc->sc_txthresh += 32;
    890  1.6.2.2  nathanw 					if (sc->sc_txthresh > 0x1ffc)
    891  1.6.2.2  nathanw 						sc->sc_txthresh = 0x1ffc;
    892  1.6.2.2  nathanw 					printf("%s: transmit underrun, new "
    893  1.6.2.2  nathanw 					    "threshold: %d bytes\n",
    894  1.6.2.2  nathanw 					    sc->sc_dev.dv_xname,
    895  1.6.2.2  nathanw 					    sc->sc_txthresh);
    896  1.6.2.4  nathanw 					ste_reset(sc, AC_TxReset | AC_DMA |
    897  1.6.2.4  nathanw 					    AC_FIFO | AC_Network);
    898  1.6.2.4  nathanw 					ste_setthresh(sc);
    899  1.6.2.4  nathanw 					bus_space_write_1(sc->sc_st, sc->sc_sh,
    900  1.6.2.4  nathanw 					    STE_TxDMAPollPeriod, 127);
    901  1.6.2.4  nathanw 					ste_txrestart(sc,
    902  1.6.2.4  nathanw 					    bus_space_read_1(sc->sc_st,
    903  1.6.2.4  nathanw 						sc->sc_sh, STE_TxFrameId));
    904  1.6.2.2  nathanw 				}
    905  1.6.2.4  nathanw 				if (txstat & TS_TxReleaseError) {
    906  1.6.2.2  nathanw 					printf("%s: Tx FIFO release error\n",
    907  1.6.2.2  nathanw 					    sc->sc_dev.dv_xname);
    908  1.6.2.4  nathanw 					wantinit = 1;
    909  1.6.2.4  nathanw 				}
    910  1.6.2.4  nathanw 				if (txstat & TS_MaxCollisions) {
    911  1.6.2.2  nathanw 					printf("%s: excessive collisions\n",
    912  1.6.2.2  nathanw 					    sc->sc_dev.dv_xname);
    913  1.6.2.4  nathanw 					wantinit = 1;
    914  1.6.2.4  nathanw 				}
    915  1.6.2.4  nathanw 				if (txstat & TS_TxStatusOverflow) {
    916  1.6.2.4  nathanw 					printf("%s: status overflow\n",
    917  1.6.2.4  nathanw 					    sc->sc_dev.dv_xname);
    918  1.6.2.4  nathanw 					wantinit = 1;
    919  1.6.2.4  nathanw 				}
    920  1.6.2.2  nathanw 				bus_space_write_2(sc->sc_st, sc->sc_sh,
    921  1.6.2.2  nathanw 				    STE_TxStatus, 0);
    922  1.6.2.2  nathanw 			}
    923  1.6.2.2  nathanw 		}
    924  1.6.2.2  nathanw 
    925  1.6.2.2  nathanw 		/* Host interface errors. */
    926  1.6.2.2  nathanw 		if (isr & IE_HostError) {
    927  1.6.2.2  nathanw 			printf("%s: Host interface error\n",
    928  1.6.2.2  nathanw 			    sc->sc_dev.dv_xname);
    929  1.6.2.2  nathanw 			wantinit = 1;
    930  1.6.2.2  nathanw 		}
    931  1.6.2.2  nathanw 	}
    932  1.6.2.2  nathanw 
    933  1.6.2.2  nathanw 	if (wantinit)
    934  1.6.2.2  nathanw 		ste_init(ifp);
    935  1.6.2.2  nathanw 
    936  1.6.2.2  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh, STE_IntEnable,
    937  1.6.2.2  nathanw 	    sc->sc_IntEnable);
    938  1.6.2.2  nathanw 
    939  1.6.2.2  nathanw 	/* Try to get more packets going. */
    940  1.6.2.2  nathanw 	ste_start(ifp);
    941  1.6.2.2  nathanw 
    942  1.6.2.2  nathanw 	return (1);
    943  1.6.2.2  nathanw }
    944  1.6.2.2  nathanw 
    945  1.6.2.2  nathanw /*
    946  1.6.2.2  nathanw  * ste_txintr:
    947  1.6.2.2  nathanw  *
    948  1.6.2.2  nathanw  *	Helper; handle transmit interrupts.
    949  1.6.2.2  nathanw  */
    950  1.6.2.2  nathanw void
    951  1.6.2.2  nathanw ste_txintr(struct ste_softc *sc)
    952  1.6.2.2  nathanw {
    953  1.6.2.2  nathanw 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    954  1.6.2.2  nathanw 	struct ste_descsoft *ds;
    955  1.6.2.2  nathanw 	uint32_t control;
    956  1.6.2.2  nathanw 	int i;
    957  1.6.2.2  nathanw 
    958  1.6.2.2  nathanw 	ifp->if_flags &= ~IFF_OACTIVE;
    959  1.6.2.2  nathanw 
    960  1.6.2.2  nathanw 	/*
    961  1.6.2.2  nathanw 	 * Go through our Tx list and free mbufs for those
    962  1.6.2.2  nathanw 	 * frames which have been transmitted.
    963  1.6.2.2  nathanw 	 */
    964  1.6.2.2  nathanw 	for (i = sc->sc_txdirty; sc->sc_txpending != 0;
    965  1.6.2.2  nathanw 	     i = STE_NEXTTX(i), sc->sc_txpending--) {
    966  1.6.2.2  nathanw 		ds = &sc->sc_txsoft[i];
    967  1.6.2.2  nathanw 
    968  1.6.2.2  nathanw 		STE_CDTXSYNC(sc, i,
    969  1.6.2.2  nathanw 		    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
    970  1.6.2.2  nathanw 
    971  1.6.2.2  nathanw 		control = le32toh(sc->sc_txdescs[i].tfd_control);
    972  1.6.2.2  nathanw 		if ((control & TFD_TxDMAComplete) == 0)
    973  1.6.2.2  nathanw 			break;
    974  1.6.2.2  nathanw 
    975  1.6.2.2  nathanw 		bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap,
    976  1.6.2.2  nathanw 		    0, ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
    977  1.6.2.2  nathanw 		bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
    978  1.6.2.2  nathanw 		m_freem(ds->ds_mbuf);
    979  1.6.2.2  nathanw 		ds->ds_mbuf = NULL;
    980  1.6.2.2  nathanw 	}
    981  1.6.2.2  nathanw 
    982  1.6.2.2  nathanw 	/* Update the dirty transmit buffer pointer. */
    983  1.6.2.2  nathanw 	sc->sc_txdirty = i;
    984  1.6.2.2  nathanw 
    985  1.6.2.2  nathanw 	/*
    986  1.6.2.2  nathanw 	 * If there are no more pending transmissions, cancel the watchdog
    987  1.6.2.2  nathanw 	 * timer.
    988  1.6.2.2  nathanw 	 */
    989  1.6.2.2  nathanw 	if (sc->sc_txpending == 0)
    990  1.6.2.2  nathanw 		ifp->if_timer = 0;
    991  1.6.2.2  nathanw }
    992  1.6.2.2  nathanw 
    993  1.6.2.2  nathanw /*
    994  1.6.2.2  nathanw  * ste_rxintr:
    995  1.6.2.2  nathanw  *
    996  1.6.2.2  nathanw  *	Helper; handle receive interrupts.
    997  1.6.2.2  nathanw  */
    998  1.6.2.2  nathanw void
    999  1.6.2.2  nathanw ste_rxintr(struct ste_softc *sc)
   1000  1.6.2.2  nathanw {
   1001  1.6.2.2  nathanw 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1002  1.6.2.2  nathanw 	struct ste_descsoft *ds;
   1003  1.6.2.2  nathanw 	struct mbuf *m;
   1004  1.6.2.2  nathanw 	uint32_t status;
   1005  1.6.2.2  nathanw 	int i, len;
   1006  1.6.2.2  nathanw 
   1007  1.6.2.2  nathanw 	for (i = sc->sc_rxptr;; i = STE_NEXTRX(i)) {
   1008  1.6.2.2  nathanw 		ds = &sc->sc_rxsoft[i];
   1009  1.6.2.2  nathanw 
   1010  1.6.2.2  nathanw 		STE_CDRXSYNC(sc, i, BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1011  1.6.2.2  nathanw 
   1012  1.6.2.2  nathanw 		status = le32toh(sc->sc_rxdescs[i].rfd_status);
   1013  1.6.2.2  nathanw 
   1014  1.6.2.2  nathanw 		if ((status & RFD_RxDMAComplete) == 0)
   1015  1.6.2.2  nathanw 			break;
   1016  1.6.2.2  nathanw 
   1017  1.6.2.2  nathanw 		/*
   1018  1.6.2.2  nathanw 		 * If the packet had an error, simply recycle the
   1019  1.6.2.2  nathanw 		 * buffer.  Note, we count the error later in the
   1020  1.6.2.2  nathanw 		 * periodic stats update.
   1021  1.6.2.2  nathanw 		 */
   1022  1.6.2.2  nathanw 		if (status & RFD_RxFrameError) {
   1023  1.6.2.2  nathanw 			STE_INIT_RXDESC(sc, i);
   1024  1.6.2.2  nathanw 			continue;
   1025  1.6.2.2  nathanw 		}
   1026  1.6.2.2  nathanw 
   1027  1.6.2.2  nathanw 		bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
   1028  1.6.2.2  nathanw 		    ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
   1029  1.6.2.2  nathanw 
   1030  1.6.2.2  nathanw 		/*
   1031  1.6.2.2  nathanw 		 * No errors; receive the packet.  Note, we have
   1032  1.6.2.2  nathanw 		 * configured the chip to not include the CRC at
   1033  1.6.2.2  nathanw 		 * the end of the packet.
   1034  1.6.2.2  nathanw 		 */
   1035  1.6.2.2  nathanw 		len = RFD_RxDMAFrameLen(status);
   1036  1.6.2.2  nathanw 
   1037  1.6.2.2  nathanw 		/*
   1038  1.6.2.2  nathanw 		 * If the packet is small enough to fit in a
   1039  1.6.2.2  nathanw 		 * single header mbuf, allocate one and copy
   1040  1.6.2.2  nathanw 		 * the data into it.  This greatly reduces
   1041  1.6.2.2  nathanw 		 * memory consumption when we receive lots
   1042  1.6.2.2  nathanw 		 * of small packets.
   1043  1.6.2.2  nathanw 		 *
   1044  1.6.2.2  nathanw 		 * Otherwise, we add a new buffer to the receive
   1045  1.6.2.2  nathanw 		 * chain.  If this fails, we drop the packet and
   1046  1.6.2.2  nathanw 		 * recycle the old buffer.
   1047  1.6.2.2  nathanw 		 */
   1048  1.6.2.2  nathanw 		if (ste_copy_small != 0 && len <= (MHLEN - 2)) {
   1049  1.6.2.2  nathanw 			MGETHDR(m, M_DONTWAIT, MT_DATA);
   1050  1.6.2.2  nathanw 			if (m == NULL)
   1051  1.6.2.2  nathanw 				goto dropit;
   1052  1.6.2.2  nathanw 			m->m_data += 2;
   1053  1.6.2.2  nathanw 			memcpy(mtod(m, caddr_t),
   1054  1.6.2.2  nathanw 			    mtod(ds->ds_mbuf, caddr_t), len);
   1055  1.6.2.2  nathanw 			STE_INIT_RXDESC(sc, i);
   1056  1.6.2.2  nathanw 			bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
   1057  1.6.2.2  nathanw 			    ds->ds_dmamap->dm_mapsize,
   1058  1.6.2.2  nathanw 			    BUS_DMASYNC_PREREAD);
   1059  1.6.2.2  nathanw 		} else {
   1060  1.6.2.2  nathanw 			m = ds->ds_mbuf;
   1061  1.6.2.2  nathanw 			if (ste_add_rxbuf(sc, i) != 0) {
   1062  1.6.2.2  nathanw  dropit:
   1063  1.6.2.2  nathanw 				ifp->if_ierrors++;
   1064  1.6.2.2  nathanw 				STE_INIT_RXDESC(sc, i);
   1065  1.6.2.2  nathanw 				bus_dmamap_sync(sc->sc_dmat,
   1066  1.6.2.2  nathanw 				    ds->ds_dmamap, 0,
   1067  1.6.2.2  nathanw 				    ds->ds_dmamap->dm_mapsize,
   1068  1.6.2.2  nathanw 				    BUS_DMASYNC_PREREAD);
   1069  1.6.2.2  nathanw 				continue;
   1070  1.6.2.2  nathanw 			}
   1071  1.6.2.2  nathanw 		}
   1072  1.6.2.2  nathanw 
   1073  1.6.2.2  nathanw 		m->m_pkthdr.rcvif = ifp;
   1074  1.6.2.2  nathanw 		m->m_pkthdr.len = m->m_len = len;
   1075  1.6.2.2  nathanw 
   1076  1.6.2.2  nathanw #if NBPFILTER > 0
   1077  1.6.2.2  nathanw 		/*
   1078  1.6.2.2  nathanw 		 * Pass this up to any BPF listeners, but only
   1079  1.6.2.2  nathanw 		 * pass if up the stack if it's for us.
   1080  1.6.2.2  nathanw 		 */
   1081  1.6.2.2  nathanw 		if (ifp->if_bpf)
   1082  1.6.2.2  nathanw 			bpf_mtap(ifp->if_bpf, m);
   1083  1.6.2.2  nathanw #endif /* NBPFILTER > 0 */
   1084  1.6.2.2  nathanw 
   1085  1.6.2.2  nathanw 		/* Pass it on. */
   1086  1.6.2.2  nathanw 		(*ifp->if_input)(ifp, m);
   1087  1.6.2.2  nathanw 	}
   1088  1.6.2.2  nathanw 
   1089  1.6.2.2  nathanw 	/* Update the receive pointer. */
   1090  1.6.2.2  nathanw 	sc->sc_rxptr = i;
   1091  1.6.2.2  nathanw }
   1092  1.6.2.2  nathanw 
   1093  1.6.2.2  nathanw /*
   1094  1.6.2.2  nathanw  * ste_tick:
   1095  1.6.2.2  nathanw  *
   1096  1.6.2.2  nathanw  *	One second timer, used to tick the MII.
   1097  1.6.2.2  nathanw  */
   1098  1.6.2.2  nathanw void
   1099  1.6.2.2  nathanw ste_tick(void *arg)
   1100  1.6.2.2  nathanw {
   1101  1.6.2.2  nathanw 	struct ste_softc *sc = arg;
   1102  1.6.2.2  nathanw 	int s;
   1103  1.6.2.2  nathanw 
   1104  1.6.2.2  nathanw 	s = splnet();
   1105  1.6.2.2  nathanw 	mii_tick(&sc->sc_mii);
   1106  1.6.2.2  nathanw 	ste_stats_update(sc);
   1107  1.6.2.2  nathanw 	splx(s);
   1108  1.6.2.2  nathanw 
   1109  1.6.2.2  nathanw 	callout_reset(&sc->sc_tick_ch, hz, ste_tick, sc);
   1110  1.6.2.2  nathanw }
   1111  1.6.2.2  nathanw 
   1112  1.6.2.2  nathanw /*
   1113  1.6.2.2  nathanw  * ste_stats_update:
   1114  1.6.2.2  nathanw  *
   1115  1.6.2.2  nathanw  *	Read the ST-201 statistics counters.
   1116  1.6.2.2  nathanw  */
   1117  1.6.2.2  nathanw void
   1118  1.6.2.2  nathanw ste_stats_update(struct ste_softc *sc)
   1119  1.6.2.2  nathanw {
   1120  1.6.2.2  nathanw 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1121  1.6.2.2  nathanw 	bus_space_tag_t st = sc->sc_st;
   1122  1.6.2.2  nathanw 	bus_space_handle_t sh = sc->sc_sh;
   1123  1.6.2.2  nathanw 
   1124  1.6.2.2  nathanw 	(void) bus_space_read_2(st, sh, STE_OctetsReceivedOk0);
   1125  1.6.2.2  nathanw 	(void) bus_space_read_2(st, sh, STE_OctetsReceivedOk1);
   1126  1.6.2.2  nathanw 
   1127  1.6.2.2  nathanw 	(void) bus_space_read_2(st, sh, STE_OctetsTransmittedOk0);
   1128  1.6.2.2  nathanw 	(void) bus_space_read_2(st, sh, STE_OctetsTransmittedOk1);
   1129  1.6.2.2  nathanw 
   1130  1.6.2.2  nathanw 	ifp->if_opackets +=
   1131  1.6.2.2  nathanw 	    (u_int) bus_space_read_2(st, sh, STE_FramesTransmittedOK);
   1132  1.6.2.2  nathanw 	ifp->if_ipackets +=
   1133  1.6.2.2  nathanw 	    (u_int) bus_space_read_2(st, sh, STE_FramesReceivedOK);
   1134  1.6.2.2  nathanw 
   1135  1.6.2.2  nathanw 	ifp->if_collisions +=
   1136  1.6.2.2  nathanw 	    (u_int) bus_space_read_1(st, sh, STE_LateCollisions) +
   1137  1.6.2.2  nathanw 	    (u_int) bus_space_read_1(st, sh, STE_MultipleColFrames) +
   1138  1.6.2.2  nathanw 	    (u_int) bus_space_read_1(st, sh, STE_SingleColFrames);
   1139  1.6.2.2  nathanw 
   1140  1.6.2.2  nathanw 	(void) bus_space_read_1(st, sh, STE_FramesWDeferredXmt);
   1141  1.6.2.2  nathanw 
   1142  1.6.2.2  nathanw 	ifp->if_ierrors +=
   1143  1.6.2.2  nathanw 	    (u_int) bus_space_read_1(st, sh, STE_FramesLostRxErrors);
   1144  1.6.2.2  nathanw 
   1145  1.6.2.2  nathanw 	ifp->if_oerrors +=
   1146  1.6.2.2  nathanw 	    (u_int) bus_space_read_1(st, sh, STE_FramesWExDeferral) +
   1147  1.6.2.4  nathanw 	    (u_int) bus_space_read_1(st, sh, STE_FramesXbortXSColls) +
   1148  1.6.2.4  nathanw 	    bus_space_read_1(st, sh, STE_CarrierSenseErrors);
   1149  1.6.2.2  nathanw 
   1150  1.6.2.2  nathanw 	(void) bus_space_read_1(st, sh, STE_BcstFramesXmtdOk);
   1151  1.6.2.2  nathanw 	(void) bus_space_read_1(st, sh, STE_BcstFramesRcvdOk);
   1152  1.6.2.2  nathanw 	(void) bus_space_read_1(st, sh, STE_McstFramesXmtdOk);
   1153  1.6.2.2  nathanw 	(void) bus_space_read_1(st, sh, STE_McstFramesRcvdOk);
   1154  1.6.2.2  nathanw }
   1155  1.6.2.2  nathanw 
   1156  1.6.2.2  nathanw /*
   1157  1.6.2.2  nathanw  * ste_reset:
   1158  1.6.2.2  nathanw  *
   1159  1.6.2.2  nathanw  *	Perform a soft reset on the ST-201.
   1160  1.6.2.2  nathanw  */
   1161  1.6.2.2  nathanw void
   1162  1.6.2.4  nathanw ste_reset(struct ste_softc *sc, u_int32_t rstbits)
   1163  1.6.2.2  nathanw {
   1164  1.6.2.2  nathanw 	uint32_t ac;
   1165  1.6.2.2  nathanw 	int i;
   1166  1.6.2.2  nathanw 
   1167  1.6.2.2  nathanw 	ac = bus_space_read_4(sc->sc_st, sc->sc_sh, STE_AsicCtrl);
   1168  1.6.2.2  nathanw 
   1169  1.6.2.4  nathanw 	bus_space_write_4(sc->sc_st, sc->sc_sh, STE_AsicCtrl, ac | rstbits);
   1170  1.6.2.2  nathanw 
   1171  1.6.2.2  nathanw 	delay(50000);
   1172  1.6.2.2  nathanw 
   1173  1.6.2.2  nathanw 	for (i = 0; i < STE_TIMEOUT; i++) {
   1174  1.6.2.2  nathanw 		delay(1000);
   1175  1.6.2.2  nathanw 		if ((bus_space_read_4(sc->sc_st, sc->sc_sh, STE_AsicCtrl) &
   1176  1.6.2.2  nathanw 		     AC_ResetBusy) == 0)
   1177  1.6.2.2  nathanw 			break;
   1178  1.6.2.2  nathanw 	}
   1179  1.6.2.2  nathanw 
   1180  1.6.2.2  nathanw 	if (i == STE_TIMEOUT)
   1181  1.6.2.2  nathanw 		printf("%s: reset failed to complete\n", sc->sc_dev.dv_xname);
   1182  1.6.2.2  nathanw 
   1183  1.6.2.2  nathanw 	delay(1000);
   1184  1.6.2.2  nathanw }
   1185  1.6.2.2  nathanw 
   1186  1.6.2.2  nathanw /*
   1187  1.6.2.4  nathanw  * ste_setthresh:
   1188  1.6.2.4  nathanw  *
   1189  1.6.2.4  nathanw  * 	set the various transmit threshold registers
   1190  1.6.2.4  nathanw  */
   1191  1.6.2.4  nathanw void
   1192  1.6.2.4  nathanw ste_setthresh(struct ste_softc *sc)
   1193  1.6.2.4  nathanw {
   1194  1.6.2.4  nathanw 	/* set the TX threhold */
   1195  1.6.2.4  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh,
   1196  1.6.2.4  nathanw 	    STE_TxStartThresh, sc->sc_txthresh);
   1197  1.6.2.4  nathanw 	/* Urgent threshold: set to sc_txthresh / 2 */
   1198  1.6.2.4  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh, STE_TxDMAUrgentThresh,
   1199  1.6.2.4  nathanw 	    sc->sc_txthresh >> 6);
   1200  1.6.2.4  nathanw 	/* Burst threshold: use default value (256 bytes) */
   1201  1.6.2.4  nathanw }
   1202  1.6.2.4  nathanw 
   1203  1.6.2.4  nathanw /*
   1204  1.6.2.4  nathanw  * restart TX at the given frame ID in the transmitter ring
   1205  1.6.2.4  nathanw  */
   1206  1.6.2.4  nathanw 
   1207  1.6.2.4  nathanw void
   1208  1.6.2.4  nathanw ste_txrestart(struct ste_softc *sc, u_int8_t id)
   1209  1.6.2.4  nathanw {
   1210  1.6.2.4  nathanw 	u_int32_t control;
   1211  1.6.2.4  nathanw 
   1212  1.6.2.4  nathanw 	STE_CDTXSYNC(sc, id, BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1213  1.6.2.4  nathanw 	control = le32toh(sc->sc_txdescs[id].tfd_control);
   1214  1.6.2.4  nathanw 	control &= ~TFD_TxDMAComplete;
   1215  1.6.2.4  nathanw 	sc->sc_txdescs[id].tfd_control = htole32(control);
   1216  1.6.2.4  nathanw 	STE_CDTXSYNC(sc, id, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1217  1.6.2.4  nathanw 
   1218  1.6.2.4  nathanw 	bus_space_write_4(sc->sc_st, sc->sc_sh, STE_TxDMAListPtr, 0);
   1219  1.6.2.4  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh, STE_MacCtrl1, MC1_TxEnable);
   1220  1.6.2.4  nathanw 	bus_space_write_4(sc->sc_st, sc->sc_sh, STE_DMACtrl, DC_TxDMAHalt);
   1221  1.6.2.4  nathanw 	ste_dmahalt_wait(sc);
   1222  1.6.2.4  nathanw 	bus_space_write_4(sc->sc_st, sc->sc_sh, STE_TxDMAListPtr,
   1223  1.6.2.4  nathanw 	    STE_CDTXADDR(sc, id));
   1224  1.6.2.4  nathanw 	bus_space_write_4(sc->sc_st, sc->sc_sh, STE_DMACtrl, DC_TxDMAResume);
   1225  1.6.2.4  nathanw }
   1226  1.6.2.4  nathanw 
   1227  1.6.2.4  nathanw /*
   1228  1.6.2.2  nathanw  * ste_init:		[ ifnet interface function ]
   1229  1.6.2.2  nathanw  *
   1230  1.6.2.2  nathanw  *	Initialize the interface.  Must be called at splnet().
   1231  1.6.2.2  nathanw  */
   1232  1.6.2.2  nathanw int
   1233  1.6.2.2  nathanw ste_init(struct ifnet *ifp)
   1234  1.6.2.2  nathanw {
   1235  1.6.2.2  nathanw 	struct ste_softc *sc = ifp->if_softc;
   1236  1.6.2.2  nathanw 	bus_space_tag_t st = sc->sc_st;
   1237  1.6.2.2  nathanw 	bus_space_handle_t sh = sc->sc_sh;
   1238  1.6.2.2  nathanw 	struct ste_descsoft *ds;
   1239  1.6.2.2  nathanw 	int i, error = 0;
   1240  1.6.2.2  nathanw 
   1241  1.6.2.2  nathanw 	/*
   1242  1.6.2.2  nathanw 	 * Cancel any pending I/O.
   1243  1.6.2.2  nathanw 	 */
   1244  1.6.2.2  nathanw 	ste_stop(ifp, 0);
   1245  1.6.2.2  nathanw 
   1246  1.6.2.2  nathanw 	/*
   1247  1.6.2.2  nathanw 	 * Reset the chip to a known state.
   1248  1.6.2.2  nathanw 	 */
   1249  1.6.2.4  nathanw 	ste_reset(sc, AC_GlobalReset | AC_RxReset | AC_TxReset | AC_DMA |
   1250  1.6.2.4  nathanw 	    AC_FIFO | AC_Network | AC_Host | AC_AutoInit | AC_RstOut);
   1251  1.6.2.2  nathanw 
   1252  1.6.2.2  nathanw 	/*
   1253  1.6.2.2  nathanw 	 * Initialize the transmit descriptor ring.
   1254  1.6.2.2  nathanw 	 */
   1255  1.6.2.2  nathanw 	memset(sc->sc_txdescs, 0, sizeof(sc->sc_txdescs));
   1256  1.6.2.2  nathanw 	sc->sc_txpending = 0;
   1257  1.6.2.2  nathanw 	sc->sc_txdirty = 0;
   1258  1.6.2.2  nathanw 	sc->sc_txlast = STE_NTXDESC - 1;
   1259  1.6.2.2  nathanw 
   1260  1.6.2.2  nathanw 	/*
   1261  1.6.2.2  nathanw 	 * Initialize the receive descriptor and receive job
   1262  1.6.2.2  nathanw 	 * descriptor rings.
   1263  1.6.2.2  nathanw 	 */
   1264  1.6.2.2  nathanw 	for (i = 0; i < STE_NRXDESC; i++) {
   1265  1.6.2.2  nathanw 		ds = &sc->sc_rxsoft[i];
   1266  1.6.2.2  nathanw 		if (ds->ds_mbuf == NULL) {
   1267  1.6.2.2  nathanw 			if ((error = ste_add_rxbuf(sc, i)) != 0) {
   1268  1.6.2.2  nathanw 				printf("%s: unable to allocate or map rx "
   1269  1.6.2.2  nathanw 				    "buffer %d, error = %d\n",
   1270  1.6.2.2  nathanw 				    sc->sc_dev.dv_xname, i, error);
   1271  1.6.2.2  nathanw 				/*
   1272  1.6.2.2  nathanw 				 * XXX Should attempt to run with fewer receive
   1273  1.6.2.2  nathanw 				 * XXX buffers instead of just failing.
   1274  1.6.2.2  nathanw 				 */
   1275  1.6.2.2  nathanw 				ste_rxdrain(sc);
   1276  1.6.2.2  nathanw 				goto out;
   1277  1.6.2.2  nathanw 			}
   1278  1.6.2.2  nathanw 		} else
   1279  1.6.2.2  nathanw 			STE_INIT_RXDESC(sc, i);
   1280  1.6.2.2  nathanw 	}
   1281  1.6.2.2  nathanw 	sc->sc_rxptr = 0;
   1282  1.6.2.2  nathanw 
   1283  1.6.2.2  nathanw 	/* Set the station address. */
   1284  1.6.2.2  nathanw 	for (i = 0; i < ETHER_ADDR_LEN; i++)
   1285  1.6.2.2  nathanw 		bus_space_write_1(st, sh, STE_StationAddress0 + 1,
   1286  1.6.2.2  nathanw 		    LLADDR(ifp->if_sadl)[i]);
   1287  1.6.2.2  nathanw 
   1288  1.6.2.2  nathanw 	/* Set up the receive filter. */
   1289  1.6.2.2  nathanw 	ste_set_filter(sc);
   1290  1.6.2.2  nathanw 
   1291  1.6.2.2  nathanw 	/*
   1292  1.6.2.2  nathanw 	 * Give the receive ring to the chip.
   1293  1.6.2.2  nathanw 	 */
   1294  1.6.2.2  nathanw 	bus_space_write_4(st, sh, STE_RxDMAListPtr,
   1295  1.6.2.2  nathanw 	    STE_CDRXADDR(sc, sc->sc_rxptr));
   1296  1.6.2.2  nathanw 
   1297  1.6.2.2  nathanw 	/*
   1298  1.6.2.2  nathanw 	 * We defer giving the transmit ring to the chip until we
   1299  1.6.2.2  nathanw 	 * transmit the first packet.
   1300  1.6.2.2  nathanw 	 */
   1301  1.6.2.2  nathanw 
   1302  1.6.2.2  nathanw 	/*
   1303  1.6.2.2  nathanw 	 * Initialize the Tx auto-poll period.  It's OK to make this number
   1304  1.6.2.2  nathanw 	 * large (127 is the max) -- we explicitly kick the transmit engine
   1305  1.6.2.2  nathanw 	 * when there's actually a packet.  We are using auto-polling only
   1306  1.6.2.2  nathanw 	 * to make the interface to the transmit engine not suck.
   1307  1.6.2.2  nathanw 	 */
   1308  1.6.2.2  nathanw 	bus_space_write_1(sc->sc_st, sc->sc_sh, STE_TxDMAPollPeriod, 127);
   1309  1.6.2.2  nathanw 
   1310  1.6.2.2  nathanw 	/* ..and the Rx auto-poll period. */
   1311  1.6.2.2  nathanw 	bus_space_write_1(st, sh, STE_RxDMAPollPeriod, 64);
   1312  1.6.2.2  nathanw 
   1313  1.6.2.2  nathanw 	/* Initialize the Tx start threshold. */
   1314  1.6.2.4  nathanw 	ste_setthresh(sc);
   1315  1.6.2.2  nathanw 
   1316  1.6.2.2  nathanw 	/* Set the FIFO release threshold to 512 bytes. */
   1317  1.6.2.2  nathanw 	bus_space_write_1(st, sh, STE_TxReleaseThresh, 512 >> 4);
   1318  1.6.2.2  nathanw 
   1319  1.6.2.2  nathanw 	/*
   1320  1.6.2.2  nathanw 	 * Initialize the interrupt mask.
   1321  1.6.2.2  nathanw 	 */
   1322  1.6.2.2  nathanw 	sc->sc_IntEnable = IE_HostError | IE_TxComplete | IE_UpdateStats |
   1323  1.6.2.2  nathanw 	    IE_TxDMAComplete | IE_RxDMAComplete;
   1324  1.6.2.4  nathanw 
   1325  1.6.2.2  nathanw 	bus_space_write_2(st, sh, STE_IntStatus, 0xffff);
   1326  1.6.2.2  nathanw 	bus_space_write_2(st, sh, STE_IntEnable, sc->sc_IntEnable);
   1327  1.6.2.2  nathanw 
   1328  1.6.2.2  nathanw 	/*
   1329  1.6.2.2  nathanw 	 * Start the receive DMA engine.
   1330  1.6.2.2  nathanw 	 */
   1331  1.6.2.2  nathanw 	bus_space_write_4(st, sh, STE_DMACtrl, sc->sc_DMACtrl | DC_RxDMAResume);
   1332  1.6.2.2  nathanw 
   1333  1.6.2.2  nathanw 	/*
   1334  1.6.2.2  nathanw 	 * Initialize MacCtrl0 -- do it before setting the media,
   1335  1.6.2.2  nathanw 	 * as setting the media will actually program the register.
   1336  1.6.2.2  nathanw 	 */
   1337  1.6.2.2  nathanw 	sc->sc_MacCtrl0 = MC0_IFSSelect(0);
   1338  1.6.2.2  nathanw 	if (sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU)
   1339  1.6.2.2  nathanw 		sc->sc_MacCtrl0 |= MC0_RcvLargeFrames;
   1340  1.6.2.2  nathanw 
   1341  1.6.2.2  nathanw 	/*
   1342  1.6.2.2  nathanw 	 * Set the current media.
   1343  1.6.2.2  nathanw 	 */
   1344  1.6.2.2  nathanw 	mii_mediachg(&sc->sc_mii);
   1345  1.6.2.2  nathanw 
   1346  1.6.2.2  nathanw 	/*
   1347  1.6.2.2  nathanw 	 * Start the MAC.
   1348  1.6.2.2  nathanw 	 */
   1349  1.6.2.2  nathanw 	bus_space_write_2(st, sh, STE_MacCtrl1,
   1350  1.6.2.2  nathanw 	    MC1_StatisticsEnable | MC1_TxEnable | MC1_RxEnable);
   1351  1.6.2.2  nathanw 
   1352  1.6.2.2  nathanw 	/*
   1353  1.6.2.2  nathanw 	 * Start the one second MII clock.
   1354  1.6.2.2  nathanw 	 */
   1355  1.6.2.2  nathanw 	callout_reset(&sc->sc_tick_ch, hz, ste_tick, sc);
   1356  1.6.2.2  nathanw 
   1357  1.6.2.2  nathanw 	/*
   1358  1.6.2.2  nathanw 	 * ...all done!
   1359  1.6.2.2  nathanw 	 */
   1360  1.6.2.2  nathanw 	ifp->if_flags |= IFF_RUNNING;
   1361  1.6.2.2  nathanw 	ifp->if_flags &= ~IFF_OACTIVE;
   1362  1.6.2.2  nathanw 
   1363  1.6.2.2  nathanw  out:
   1364  1.6.2.2  nathanw 	if (error)
   1365  1.6.2.2  nathanw 		printf("%s: interface not running\n", sc->sc_dev.dv_xname);
   1366  1.6.2.2  nathanw 	return (error);
   1367  1.6.2.2  nathanw }
   1368  1.6.2.2  nathanw 
   1369  1.6.2.2  nathanw /*
   1370  1.6.2.2  nathanw  * ste_drain:
   1371  1.6.2.2  nathanw  *
   1372  1.6.2.2  nathanw  *	Drain the receive queue.
   1373  1.6.2.2  nathanw  */
   1374  1.6.2.2  nathanw void
   1375  1.6.2.2  nathanw ste_rxdrain(struct ste_softc *sc)
   1376  1.6.2.2  nathanw {
   1377  1.6.2.2  nathanw 	struct ste_descsoft *ds;
   1378  1.6.2.2  nathanw 	int i;
   1379  1.6.2.2  nathanw 
   1380  1.6.2.2  nathanw 	for (i = 0; i < STE_NRXDESC; i++) {
   1381  1.6.2.2  nathanw 		ds = &sc->sc_rxsoft[i];
   1382  1.6.2.2  nathanw 		if (ds->ds_mbuf != NULL) {
   1383  1.6.2.2  nathanw 			bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
   1384  1.6.2.2  nathanw 			m_freem(ds->ds_mbuf);
   1385  1.6.2.2  nathanw 			ds->ds_mbuf = NULL;
   1386  1.6.2.2  nathanw 		}
   1387  1.6.2.2  nathanw 	}
   1388  1.6.2.2  nathanw }
   1389  1.6.2.2  nathanw 
   1390  1.6.2.2  nathanw /*
   1391  1.6.2.2  nathanw  * ste_stop:		[ ifnet interface function ]
   1392  1.6.2.2  nathanw  *
   1393  1.6.2.2  nathanw  *	Stop transmission on the interface.
   1394  1.6.2.2  nathanw  */
   1395  1.6.2.2  nathanw void
   1396  1.6.2.2  nathanw ste_stop(struct ifnet *ifp, int disable)
   1397  1.6.2.2  nathanw {
   1398  1.6.2.2  nathanw 	struct ste_softc *sc = ifp->if_softc;
   1399  1.6.2.2  nathanw 	struct ste_descsoft *ds;
   1400  1.6.2.2  nathanw 	int i;
   1401  1.6.2.2  nathanw 
   1402  1.6.2.2  nathanw 	/*
   1403  1.6.2.2  nathanw 	 * Stop the one second clock.
   1404  1.6.2.2  nathanw 	 */
   1405  1.6.2.2  nathanw 	callout_stop(&sc->sc_tick_ch);
   1406  1.6.2.2  nathanw 
   1407  1.6.2.2  nathanw 	/* Down the MII. */
   1408  1.6.2.2  nathanw 	mii_down(&sc->sc_mii);
   1409  1.6.2.2  nathanw 
   1410  1.6.2.2  nathanw 	/*
   1411  1.6.2.2  nathanw 	 * Disable interrupts.
   1412  1.6.2.2  nathanw 	 */
   1413  1.6.2.2  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh, STE_IntEnable, 0);
   1414  1.6.2.2  nathanw 
   1415  1.6.2.2  nathanw 	/*
   1416  1.6.2.2  nathanw 	 * Stop receiver, transmitter, and stats update.
   1417  1.6.2.2  nathanw 	 */
   1418  1.6.2.2  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh, STE_MacCtrl1,
   1419  1.6.2.2  nathanw 	    MC1_StatisticsDisable | MC1_TxDisable | MC1_RxDisable);
   1420  1.6.2.2  nathanw 
   1421  1.6.2.2  nathanw 	/*
   1422  1.6.2.2  nathanw 	 * Stop the transmit and receive DMA.
   1423  1.6.2.2  nathanw 	 */
   1424  1.6.2.2  nathanw 	bus_space_write_4(sc->sc_st, sc->sc_sh, STE_DMACtrl,
   1425  1.6.2.2  nathanw 	    DC_RxDMAHalt | DC_TxDMAHalt);
   1426  1.6.2.2  nathanw 	ste_dmahalt_wait(sc);
   1427  1.6.2.2  nathanw 
   1428  1.6.2.2  nathanw 	/*
   1429  1.6.2.2  nathanw 	 * Release any queued transmit buffers.
   1430  1.6.2.2  nathanw 	 */
   1431  1.6.2.2  nathanw 	for (i = 0; i < STE_NTXDESC; i++) {
   1432  1.6.2.2  nathanw 		ds = &sc->sc_txsoft[i];
   1433  1.6.2.2  nathanw 		if (ds->ds_mbuf != NULL) {
   1434  1.6.2.2  nathanw 			bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
   1435  1.6.2.2  nathanw 			m_freem(ds->ds_mbuf);
   1436  1.6.2.2  nathanw 			ds->ds_mbuf = NULL;
   1437  1.6.2.2  nathanw 		}
   1438  1.6.2.2  nathanw 	}
   1439  1.6.2.2  nathanw 
   1440  1.6.2.2  nathanw 	if (disable)
   1441  1.6.2.2  nathanw 		ste_rxdrain(sc);
   1442  1.6.2.2  nathanw 
   1443  1.6.2.2  nathanw 	/*
   1444  1.6.2.2  nathanw 	 * Mark the interface down and cancel the watchdog timer.
   1445  1.6.2.2  nathanw 	 */
   1446  1.6.2.2  nathanw 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
   1447  1.6.2.2  nathanw 	ifp->if_timer = 0;
   1448  1.6.2.2  nathanw }
   1449  1.6.2.2  nathanw 
   1450  1.6.2.2  nathanw static int
   1451  1.6.2.2  nathanw ste_eeprom_wait(struct ste_softc *sc)
   1452  1.6.2.2  nathanw {
   1453  1.6.2.2  nathanw 	int i;
   1454  1.6.2.2  nathanw 
   1455  1.6.2.2  nathanw 	for (i = 0; i < STE_TIMEOUT; i++) {
   1456  1.6.2.2  nathanw 		delay(1000);
   1457  1.6.2.2  nathanw 		if ((bus_space_read_2(sc->sc_st, sc->sc_sh, STE_EepromCtrl) &
   1458  1.6.2.2  nathanw 		     EC_EepromBusy) == 0)
   1459  1.6.2.2  nathanw 			return (0);
   1460  1.6.2.2  nathanw 	}
   1461  1.6.2.2  nathanw 	return (1);
   1462  1.6.2.2  nathanw }
   1463  1.6.2.2  nathanw 
   1464  1.6.2.2  nathanw /*
   1465  1.6.2.2  nathanw  * ste_read_eeprom:
   1466  1.6.2.2  nathanw  *
   1467  1.6.2.2  nathanw  *	Read data from the serial EEPROM.
   1468  1.6.2.2  nathanw  */
   1469  1.6.2.2  nathanw void
   1470  1.6.2.2  nathanw ste_read_eeprom(struct ste_softc *sc, int offset, uint16_t *data)
   1471  1.6.2.2  nathanw {
   1472  1.6.2.2  nathanw 
   1473  1.6.2.2  nathanw 	if (ste_eeprom_wait(sc))
   1474  1.6.2.2  nathanw 		printf("%s: EEPROM failed to come ready\n",
   1475  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname);
   1476  1.6.2.2  nathanw 
   1477  1.6.2.2  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh, STE_EepromCtrl,
   1478  1.6.2.2  nathanw 	    EC_EepromAddress(offset) | EC_EepromOpcode(EC_OP_R));
   1479  1.6.2.2  nathanw 	if (ste_eeprom_wait(sc))
   1480  1.6.2.2  nathanw 		printf("%s: EEPROM read timed out\n",
   1481  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname);
   1482  1.6.2.2  nathanw 	*data = bus_space_read_2(sc->sc_st, sc->sc_sh, STE_EepromData);
   1483  1.6.2.2  nathanw }
   1484  1.6.2.2  nathanw 
   1485  1.6.2.2  nathanw /*
   1486  1.6.2.2  nathanw  * ste_add_rxbuf:
   1487  1.6.2.2  nathanw  *
   1488  1.6.2.2  nathanw  *	Add a receive buffer to the indicated descriptor.
   1489  1.6.2.2  nathanw  */
   1490  1.6.2.2  nathanw int
   1491  1.6.2.2  nathanw ste_add_rxbuf(struct ste_softc *sc, int idx)
   1492  1.6.2.2  nathanw {
   1493  1.6.2.2  nathanw 	struct ste_descsoft *ds = &sc->sc_rxsoft[idx];
   1494  1.6.2.2  nathanw 	struct mbuf *m;
   1495  1.6.2.2  nathanw 	int error;
   1496  1.6.2.2  nathanw 
   1497  1.6.2.2  nathanw 	MGETHDR(m, M_DONTWAIT, MT_DATA);
   1498  1.6.2.2  nathanw 	if (m == NULL)
   1499  1.6.2.2  nathanw 		return (ENOBUFS);
   1500  1.6.2.2  nathanw 
   1501  1.6.2.2  nathanw 	MCLGET(m, M_DONTWAIT);
   1502  1.6.2.2  nathanw 	if ((m->m_flags & M_EXT) == 0) {
   1503  1.6.2.2  nathanw 		m_freem(m);
   1504  1.6.2.2  nathanw 		return (ENOBUFS);
   1505  1.6.2.2  nathanw 	}
   1506  1.6.2.2  nathanw 
   1507  1.6.2.2  nathanw 	if (ds->ds_mbuf != NULL)
   1508  1.6.2.2  nathanw 		bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
   1509  1.6.2.2  nathanw 
   1510  1.6.2.2  nathanw 	ds->ds_mbuf = m;
   1511  1.6.2.2  nathanw 
   1512  1.6.2.2  nathanw 	error = bus_dmamap_load(sc->sc_dmat, ds->ds_dmamap,
   1513  1.6.2.2  nathanw 	    m->m_ext.ext_buf, m->m_ext.ext_size, NULL,
   1514  1.6.2.2  nathanw 	    BUS_DMA_READ|BUS_DMA_NOWAIT);
   1515  1.6.2.2  nathanw 	if (error) {
   1516  1.6.2.2  nathanw 		printf("%s: can't load rx DMA map %d, error = %d\n",
   1517  1.6.2.2  nathanw 		    sc->sc_dev.dv_xname, idx, error);
   1518  1.6.2.2  nathanw 		panic("ste_add_rxbuf");		/* XXX */
   1519  1.6.2.2  nathanw 	}
   1520  1.6.2.2  nathanw 
   1521  1.6.2.2  nathanw 	bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
   1522  1.6.2.2  nathanw 	    ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
   1523  1.6.2.2  nathanw 
   1524  1.6.2.2  nathanw 	STE_INIT_RXDESC(sc, idx);
   1525  1.6.2.2  nathanw 
   1526  1.6.2.2  nathanw 	return (0);
   1527  1.6.2.2  nathanw }
   1528  1.6.2.2  nathanw 
   1529  1.6.2.2  nathanw /*
   1530  1.6.2.2  nathanw  * ste_set_filter:
   1531  1.6.2.2  nathanw  *
   1532  1.6.2.2  nathanw  *	Set up the receive filter.
   1533  1.6.2.2  nathanw  */
   1534  1.6.2.2  nathanw void
   1535  1.6.2.2  nathanw ste_set_filter(struct ste_softc *sc)
   1536  1.6.2.2  nathanw {
   1537  1.6.2.2  nathanw 	struct ethercom *ec = &sc->sc_ethercom;
   1538  1.6.2.2  nathanw 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1539  1.6.2.2  nathanw 	struct ether_multi *enm;
   1540  1.6.2.2  nathanw 	struct ether_multistep step;
   1541  1.6.2.2  nathanw 	uint32_t crc;
   1542  1.6.2.2  nathanw 	uint16_t mchash[4];
   1543  1.6.2.2  nathanw 
   1544  1.6.2.2  nathanw 	sc->sc_ReceiveMode = RM_ReceiveUnicast;
   1545  1.6.2.2  nathanw 	if (ifp->if_flags & IFF_BROADCAST)
   1546  1.6.2.2  nathanw 		sc->sc_ReceiveMode |= RM_ReceiveBroadcast;
   1547  1.6.2.2  nathanw 
   1548  1.6.2.2  nathanw 	if (ifp->if_flags & IFF_PROMISC) {
   1549  1.6.2.2  nathanw 		sc->sc_ReceiveMode |= RM_ReceiveAllFrames;
   1550  1.6.2.2  nathanw 		goto allmulti;
   1551  1.6.2.2  nathanw 	}
   1552  1.6.2.2  nathanw 
   1553  1.6.2.2  nathanw 	/*
   1554  1.6.2.2  nathanw 	 * Set up the multicast address filter by passing all multicast
   1555  1.6.2.2  nathanw 	 * addresses through a CRC generator, and then using the low-order
   1556  1.6.2.2  nathanw 	 * 6 bits as an index into the 64 bit multicast hash table.  The
   1557  1.6.2.2  nathanw 	 * high order bits select the register, while the rest of the bits
   1558  1.6.2.2  nathanw 	 * select the bit within the register.
   1559  1.6.2.2  nathanw 	 */
   1560  1.6.2.2  nathanw 
   1561  1.6.2.2  nathanw 	memset(mchash, 0, sizeof(mchash));
   1562  1.6.2.2  nathanw 
   1563  1.6.2.2  nathanw 	ETHER_FIRST_MULTI(step, ec, enm);
   1564  1.6.2.2  nathanw 	if (enm == NULL)
   1565  1.6.2.2  nathanw 		goto done;
   1566  1.6.2.2  nathanw 
   1567  1.6.2.2  nathanw 	while (enm != NULL) {
   1568  1.6.2.2  nathanw 		if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
   1569  1.6.2.2  nathanw 			/*
   1570  1.6.2.2  nathanw 			 * We must listen to a range of multicast addresses.
   1571  1.6.2.2  nathanw 			 * For now, just accept all multicasts, rather than
   1572  1.6.2.2  nathanw 			 * trying to set only those filter bits needed to match
   1573  1.6.2.2  nathanw 			 * the range.  (At this time, the only use of address
   1574  1.6.2.2  nathanw 			 * ranges is for IP multicast routing, for which the
   1575  1.6.2.2  nathanw 			 * range is big enough to require all bits set.)
   1576  1.6.2.2  nathanw 			 */
   1577  1.6.2.2  nathanw 			goto allmulti;
   1578  1.6.2.2  nathanw 		}
   1579  1.6.2.2  nathanw 
   1580  1.6.2.2  nathanw 		crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
   1581  1.6.2.2  nathanw 
   1582  1.6.2.2  nathanw 		/* Just want the 6 least significant bits. */
   1583  1.6.2.2  nathanw 		crc &= 0x3f;
   1584  1.6.2.2  nathanw 
   1585  1.6.2.2  nathanw 		/* Set the corresponding bit in the hash table. */
   1586  1.6.2.2  nathanw 		mchash[crc >> 4] |= 1 << (crc & 0xf);
   1587  1.6.2.2  nathanw 
   1588  1.6.2.2  nathanw 		ETHER_NEXT_MULTI(step, enm);
   1589  1.6.2.2  nathanw 	}
   1590  1.6.2.2  nathanw 
   1591  1.6.2.2  nathanw 	sc->sc_ReceiveMode |= RM_ReceiveMulticastHash;
   1592  1.6.2.2  nathanw 
   1593  1.6.2.2  nathanw 	ifp->if_flags &= ~IFF_ALLMULTI;
   1594  1.6.2.2  nathanw 	goto done;
   1595  1.6.2.2  nathanw 
   1596  1.6.2.2  nathanw  allmulti:
   1597  1.6.2.2  nathanw 	ifp->if_flags |= IFF_ALLMULTI;
   1598  1.6.2.2  nathanw 	sc->sc_ReceiveMode |= RM_ReceiveMulticast;
   1599  1.6.2.2  nathanw 
   1600  1.6.2.2  nathanw  done:
   1601  1.6.2.2  nathanw 	if ((ifp->if_flags & IFF_ALLMULTI) == 0) {
   1602  1.6.2.2  nathanw 		/*
   1603  1.6.2.2  nathanw 		 * Program the multicast hash table.
   1604  1.6.2.2  nathanw 		 */
   1605  1.6.2.2  nathanw 		bus_space_write_2(sc->sc_st, sc->sc_sh, STE_HashTable0,
   1606  1.6.2.2  nathanw 		    mchash[0]);
   1607  1.6.2.2  nathanw 		bus_space_write_2(sc->sc_st, sc->sc_sh, STE_HashTable1,
   1608  1.6.2.2  nathanw 		    mchash[1]);
   1609  1.6.2.2  nathanw 		bus_space_write_2(sc->sc_st, sc->sc_sh, STE_HashTable2,
   1610  1.6.2.2  nathanw 		    mchash[2]);
   1611  1.6.2.2  nathanw 		bus_space_write_2(sc->sc_st, sc->sc_sh, STE_HashTable3,
   1612  1.6.2.2  nathanw 		    mchash[3]);
   1613  1.6.2.2  nathanw 	}
   1614  1.6.2.2  nathanw 
   1615  1.6.2.2  nathanw 	bus_space_write_1(sc->sc_st, sc->sc_sh, STE_ReceiveMode,
   1616  1.6.2.2  nathanw 	    sc->sc_ReceiveMode);
   1617  1.6.2.2  nathanw }
   1618  1.6.2.2  nathanw 
   1619  1.6.2.2  nathanw /*
   1620  1.6.2.2  nathanw  * ste_mii_readreg:	[mii interface function]
   1621  1.6.2.2  nathanw  *
   1622  1.6.2.2  nathanw  *	Read a PHY register on the MII of the ST-201.
   1623  1.6.2.2  nathanw  */
   1624  1.6.2.2  nathanw int
   1625  1.6.2.2  nathanw ste_mii_readreg(struct device *self, int phy, int reg)
   1626  1.6.2.2  nathanw {
   1627  1.6.2.2  nathanw 
   1628  1.6.2.2  nathanw 	return (mii_bitbang_readreg(self, &ste_mii_bitbang_ops, phy, reg));
   1629  1.6.2.2  nathanw }
   1630  1.6.2.2  nathanw 
   1631  1.6.2.2  nathanw /*
   1632  1.6.2.2  nathanw  * ste_mii_writereg:	[mii interface function]
   1633  1.6.2.2  nathanw  *
   1634  1.6.2.2  nathanw  *	Write a PHY register on the MII of the ST-201.
   1635  1.6.2.2  nathanw  */
   1636  1.6.2.2  nathanw void
   1637  1.6.2.2  nathanw ste_mii_writereg(struct device *self, int phy, int reg, int val)
   1638  1.6.2.2  nathanw {
   1639  1.6.2.2  nathanw 
   1640  1.6.2.2  nathanw 	mii_bitbang_writereg(self, &ste_mii_bitbang_ops, phy, reg, val);
   1641  1.6.2.2  nathanw }
   1642  1.6.2.2  nathanw 
   1643  1.6.2.2  nathanw /*
   1644  1.6.2.2  nathanw  * ste_mii_statchg:	[mii interface function]
   1645  1.6.2.2  nathanw  *
   1646  1.6.2.2  nathanw  *	Callback from MII layer when media changes.
   1647  1.6.2.2  nathanw  */
   1648  1.6.2.2  nathanw void
   1649  1.6.2.2  nathanw ste_mii_statchg(struct device *self)
   1650  1.6.2.2  nathanw {
   1651  1.6.2.2  nathanw 	struct ste_softc *sc = (struct ste_softc *) self;
   1652  1.6.2.2  nathanw 
   1653  1.6.2.2  nathanw 	if (sc->sc_mii.mii_media_active & IFM_FDX)
   1654  1.6.2.2  nathanw 		sc->sc_MacCtrl0 |= MC0_FullDuplexEnable;
   1655  1.6.2.2  nathanw 	else
   1656  1.6.2.2  nathanw 		sc->sc_MacCtrl0 &= ~MC0_FullDuplexEnable;
   1657  1.6.2.2  nathanw 
   1658  1.6.2.2  nathanw 	/* XXX 802.1x flow-control? */
   1659  1.6.2.2  nathanw 
   1660  1.6.2.2  nathanw 	bus_space_write_2(sc->sc_st, sc->sc_sh, STE_MacCtrl0, sc->sc_MacCtrl0);
   1661  1.6.2.2  nathanw }
   1662  1.6.2.2  nathanw 
   1663  1.6.2.2  nathanw /*
   1664  1.6.2.2  nathanw  * ste_mii_bitbang_read: [mii bit-bang interface function]
   1665  1.6.2.2  nathanw  *
   1666  1.6.2.2  nathanw  *	Read the MII serial port for the MII bit-bang module.
   1667  1.6.2.2  nathanw  */
   1668  1.6.2.2  nathanw uint32_t
   1669  1.6.2.2  nathanw ste_mii_bitbang_read(struct device *self)
   1670  1.6.2.2  nathanw {
   1671  1.6.2.2  nathanw 	struct ste_softc *sc = (void *) self;
   1672  1.6.2.2  nathanw 
   1673  1.6.2.2  nathanw 	return (bus_space_read_1(sc->sc_st, sc->sc_sh, STE_PhyCtrl));
   1674  1.6.2.2  nathanw }
   1675  1.6.2.2  nathanw 
   1676  1.6.2.2  nathanw /*
   1677  1.6.2.2  nathanw  * ste_mii_bitbang_write: [mii big-bang interface function]
   1678  1.6.2.2  nathanw  *
   1679  1.6.2.2  nathanw  *	Write the MII serial port for the MII bit-bang module.
   1680  1.6.2.2  nathanw  */
   1681  1.6.2.2  nathanw void
   1682  1.6.2.2  nathanw ste_mii_bitbang_write(struct device *self, uint32_t val)
   1683  1.6.2.2  nathanw {
   1684  1.6.2.2  nathanw 	struct ste_softc *sc = (void *) self;
   1685  1.6.2.2  nathanw 
   1686  1.6.2.2  nathanw 	bus_space_write_1(sc->sc_st, sc->sc_sh, STE_PhyCtrl, val);
   1687  1.6.2.2  nathanw }
   1688  1.6.2.2  nathanw 
   1689  1.6.2.2  nathanw /*
   1690  1.6.2.2  nathanw  * ste_mediastatus:	[ifmedia interface function]
   1691  1.6.2.2  nathanw  *
   1692  1.6.2.2  nathanw  *	Get the current interface media status.
   1693  1.6.2.2  nathanw  */
   1694  1.6.2.2  nathanw void
   1695  1.6.2.2  nathanw ste_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
   1696  1.6.2.2  nathanw {
   1697  1.6.2.2  nathanw 	struct ste_softc *sc = ifp->if_softc;
   1698  1.6.2.2  nathanw 
   1699  1.6.2.2  nathanw 	mii_pollstat(&sc->sc_mii);
   1700  1.6.2.2  nathanw 	ifmr->ifm_status = sc->sc_mii.mii_media_status;
   1701  1.6.2.2  nathanw 	ifmr->ifm_active = sc->sc_mii.mii_media_active;
   1702  1.6.2.2  nathanw }
   1703  1.6.2.2  nathanw 
   1704  1.6.2.2  nathanw /*
   1705  1.6.2.2  nathanw  * ste_mediachange:	[ifmedia interface function]
   1706  1.6.2.2  nathanw  *
   1707  1.6.2.2  nathanw  *	Set hardware to newly-selected media.
   1708  1.6.2.2  nathanw  */
   1709  1.6.2.2  nathanw int
   1710  1.6.2.2  nathanw ste_mediachange(struct ifnet *ifp)
   1711  1.6.2.2  nathanw {
   1712  1.6.2.2  nathanw 	struct ste_softc *sc = ifp->if_softc;
   1713  1.6.2.2  nathanw 
   1714  1.6.2.2  nathanw 	if (ifp->if_flags & IFF_UP)
   1715  1.6.2.2  nathanw 		mii_mediachg(&sc->sc_mii);
   1716  1.6.2.2  nathanw 	return (0);
   1717  1.6.2.2  nathanw }
   1718