Home | History | Annotate | Line # | Download | only in ep93xx
epe.c revision 1.38.2.2
      1  1.38.2.2    martin /*	$NetBSD: epe.c,v 1.38.2.2 2020/04/08 14:07:29 martin Exp $	*/
      2       1.1      joff 
      3       1.1      joff /*
      4       1.1      joff  * Copyright (c) 2004 Jesse Off
      5       1.1      joff  * All rights reserved.
      6       1.1      joff  *
      7       1.1      joff  * Redistribution and use in source and binary forms, with or without
      8       1.1      joff  * modification, are permitted provided that the following conditions
      9       1.1      joff  * are met:
     10       1.1      joff  * 1. Redistributions of source code must retain the above copyright
     11       1.1      joff  *    notice, this list of conditions and the following disclaimer.
     12       1.1      joff  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1      joff  *    notice, this list of conditions and the following disclaimer in the
     14       1.1      joff  *    documentation and/or other materials provided with the distribution.
     15       1.1      joff  *
     16       1.1      joff  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17       1.1      joff  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.1      joff  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.1      joff  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20       1.1      joff  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.1      joff  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.1      joff  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.1      joff  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.1      joff  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.1      joff  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1      joff  * POSSIBILITY OF SUCH DAMAGE.
     27       1.1      joff  */
     28       1.1      joff 
     29       1.1      joff #include <sys/cdefs.h>
     30  1.38.2.2    martin __KERNEL_RCSID(0, "$NetBSD: epe.c,v 1.38.2.2 2020/04/08 14:07:29 martin Exp $");
     31       1.1      joff 
     32       1.1      joff #include <sys/types.h>
     33       1.1      joff #include <sys/param.h>
     34       1.1      joff #include <sys/systm.h>
     35       1.1      joff #include <sys/ioctl.h>
     36       1.1      joff #include <sys/kernel.h>
     37       1.1      joff #include <sys/proc.h>
     38       1.1      joff #include <sys/malloc.h>
     39       1.1      joff #include <sys/time.h>
     40       1.1      joff #include <sys/device.h>
     41       1.1      joff #include <uvm/uvm_extern.h>
     42       1.1      joff 
     43      1.26    dyoung #include <sys/bus.h>
     44       1.1      joff #include <machine/intr.h>
     45       1.1      joff 
     46       1.1      joff #include <arm/cpufunc.h>
     47       1.1      joff 
     48  1.38.2.1  christos #include <arm/ep93xx/epsocvar.h>
     49       1.1      joff #include <arm/ep93xx/ep93xxvar.h>
     50       1.1      joff 
     51       1.1      joff #include <net/if.h>
     52       1.1      joff #include <net/if_dl.h>
     53       1.1      joff #include <net/if_types.h>
     54       1.1      joff #include <net/if_media.h>
     55       1.1      joff #include <net/if_ether.h>
     56      1.37   msaitoh #include <net/bpf.h>
     57       1.1      joff 
     58       1.1      joff #include <dev/mii/mii.h>
     59       1.1      joff #include <dev/mii/miivar.h>
     60       1.1      joff 
     61       1.1      joff #ifdef INET
     62       1.1      joff #include <netinet/in.h>
     63       1.1      joff #include <netinet/in_systm.h>
     64       1.1      joff #include <netinet/in_var.h>
     65       1.1      joff #include <netinet/ip.h>
     66       1.1      joff #include <netinet/if_inarp.h>
     67       1.1      joff #endif
     68       1.1      joff 
     69       1.2      joff #include <arm/ep93xx/ep93xxreg.h>
     70  1.38.2.1  christos #include <arm/ep93xx/epereg.h>
     71  1.38.2.1  christos #include <arm/ep93xx/epevar.h>
     72       1.1      joff 
     73       1.4  hamajima #define DEFAULT_MDCDIV	32
     74       1.4  hamajima 
     75       1.2      joff #ifndef EPE_FAST
     76       1.2      joff #define EPE_FAST
     77       1.2      joff #endif
     78       1.1      joff 
     79       1.2      joff #ifndef EPE_FAST
     80       1.1      joff #define EPE_READ(x) \
     81       1.1      joff 	bus_space_read_4(sc->sc_iot, sc->sc_ioh, (EPE_ ## x))
     82       1.1      joff #define EPE_WRITE(x, y) \
     83       1.1      joff 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, (EPE_ ## x), (y))
     84       1.2      joff #define CTRLPAGE_DMASYNC(x, y, z) \
     85       1.2      joff 	bus_dmamap_sync(sc->sc_dmat, sc->ctrlpage_dmamap, (x), (y), (z))
     86       1.2      joff #else
     87      1.29     skrll #define EPE_READ(x) *(volatile uint32_t *) \
     88       1.2      joff 	(EP93XX_AHB_VBASE + EP93XX_AHB_EPE + (EPE_ ## x))
     89      1.29     skrll #define EPE_WRITE(x, y) *(volatile uint32_t *) \
     90       1.2      joff 	(EP93XX_AHB_VBASE + EP93XX_AHB_EPE + (EPE_ ## x)) = y
     91       1.2      joff #define CTRLPAGE_DMASYNC(x, y, z)
     92       1.2      joff #endif /* ! EPE_FAST */
     93       1.1      joff 
     94      1.27      matt static int	epe_match(device_t , cfdata_t, void *);
     95      1.27      matt static void	epe_attach(device_t, device_t, void *);
     96       1.1      joff static void	epe_init(struct epe_softc *);
     97  1.38.2.1  christos static int	epe_intr(void* arg);
     98       1.2      joff static int	epe_gctx(struct epe_softc *);
     99  1.38.2.1  christos int		epe_mii_readreg (device_t, int, int, uint16_t *);
    100  1.38.2.1  christos int		epe_mii_writereg (device_t, int, int, uint16_t);
    101      1.27      matt void		epe_statchg (struct ifnet *);
    102       1.1      joff void		epe_tick (void *);
    103      1.10  christos static int	epe_ifioctl (struct ifnet *, u_long, void *);
    104       1.1      joff static void	epe_ifstart (struct ifnet *);
    105       1.1      joff static void	epe_ifwatchdog (struct ifnet *);
    106       1.1      joff static int	epe_ifinit (struct ifnet *);
    107       1.1      joff static void	epe_ifstop (struct ifnet *, int);
    108       1.1      joff static void	epe_setaddr (struct ifnet *);
    109       1.1      joff 
    110      1.28       chs CFATTACH_DECL_NEW(epe, sizeof(struct epe_softc),
    111       1.1      joff     epe_match, epe_attach, NULL, NULL);
    112       1.1      joff 
    113       1.1      joff static int
    114      1.27      matt epe_match(device_t parent, cfdata_t match, void *aux)
    115       1.1      joff {
    116       1.1      joff 	return 2;
    117       1.1      joff }
    118       1.1      joff 
    119       1.1      joff static void
    120      1.27      matt epe_attach(device_t parent, device_t self, void *aux)
    121       1.1      joff {
    122      1.27      matt 	struct epe_softc		*sc = device_private(self);
    123       1.1      joff 	struct epsoc_attach_args	*sa;
    124       1.8   thorpej 	prop_data_t			 enaddr;
    125       1.1      joff 
    126      1.27      matt 	aprint_normal("\n");
    127       1.1      joff 	sa = aux;
    128      1.27      matt 	sc->sc_dev = self;
    129       1.1      joff 	sc->sc_iot = sa->sa_iot;
    130       1.1      joff 	sc->sc_intr = sa->sa_intr;
    131       1.1      joff 	sc->sc_dmat = sa->sa_dmat;
    132       1.1      joff 
    133  1.38.2.1  christos 	if (bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size,
    134       1.1      joff 		0, &sc->sc_ioh))
    135      1.28       chs 		panic("%s: Cannot map registers", device_xname(self));
    136       1.1      joff 
    137       1.4  hamajima 	/* Fetch the Ethernet address from property if set. */
    138      1.24    martin 	enaddr = prop_dictionary_get(device_properties(self), "mac-address");
    139       1.8   thorpej 	if (enaddr != NULL) {
    140       1.8   thorpej 		KASSERT(prop_object_type(enaddr) == PROP_TYPE_DATA);
    141       1.8   thorpej 		KASSERT(prop_data_size(enaddr) == ETHER_ADDR_LEN);
    142       1.8   thorpej 		memcpy(sc->sc_enaddr, prop_data_data_nocopy(enaddr),
    143       1.8   thorpej 		       ETHER_ADDR_LEN);
    144       1.4  hamajima 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, EPE_AFP, 0);
    145       1.4  hamajima 		bus_space_write_region_1(sc->sc_iot, sc->sc_ioh, EPE_IndAd,
    146       1.4  hamajima 					 sc->sc_enaddr, ETHER_ADDR_LEN);
    147       1.4  hamajima 	}
    148       1.4  hamajima 
    149  1.38.2.1  christos 	ep93xx_intr_establish(sc->sc_intr, IPL_NET, epe_intr, sc);
    150       1.1      joff 	epe_init(sc);
    151       1.1      joff }
    152       1.1      joff 
    153       1.1      joff static int
    154       1.2      joff epe_gctx(struct epe_softc *sc)
    155       1.2      joff {
    156       1.2      joff 	struct ifnet * ifp = &sc->sc_ec.ec_if;
    157      1.29     skrll 	uint32_t *cur, ndq = 0;
    158       1.2      joff 
    159       1.2      joff 	/* Handle transmit completions */
    160      1.29     skrll 	cur = (uint32_t *)(EPE_READ(TXStsQCurAdd) -
    161      1.11        he 		sc->ctrlpage_dsaddr + (char*)sc->ctrlpage);
    162       1.2      joff 
    163  1.38.2.1  christos 	if (sc->TXStsQ_cur != cur) {
    164  1.38.2.1  christos 		CTRLPAGE_DMASYNC(TX_QLEN * 2 * sizeof(uint32_t),
    165      1.29     skrll 			TX_QLEN * sizeof(uint32_t), BUS_DMASYNC_PREREAD);
    166  1.38.2.1  christos 	} else
    167       1.2      joff 		return 0;
    168       1.2      joff 
    169       1.2      joff 	do {
    170      1.29     skrll 		uint32_t tbi = *sc->TXStsQ_cur & 0x7fff;
    171       1.2      joff 		struct mbuf *m = sc->txq[tbi].m;
    172       1.2      joff 
    173  1.38.2.1  christos 		if ((*sc->TXStsQ_cur & TXStsQ_TxWE) == 0)
    174  1.38.2.2    martin 			if_statinc(ifp, if_oerrors);
    175  1.38.2.1  christos 
    176       1.2      joff 		bus_dmamap_unload(sc->sc_dmat, sc->txq[tbi].m_dmamap);
    177       1.2      joff 		m_freem(m);
    178       1.2      joff 		do {
    179       1.2      joff 			sc->txq[tbi].m = NULL;
    180       1.2      joff 			ndq++;
    181       1.2      joff 			tbi = (tbi + 1) % TX_QLEN;
    182       1.2      joff 		} while (sc->txq[tbi].m == m);
    183       1.2      joff 
    184  1.38.2.2    martin 		if_statinc(ifp, if_opackets);
    185       1.2      joff 		sc->TXStsQ_cur++;
    186       1.2      joff 		if (sc->TXStsQ_cur >= sc->TXStsQ + TX_QLEN) {
    187       1.2      joff 			sc->TXStsQ_cur = sc->TXStsQ;
    188       1.2      joff 		}
    189  1.38.2.1  christos 	} while (sc->TXStsQ_cur != cur);
    190       1.2      joff 
    191       1.2      joff 	sc->TXDQ_avail += ndq;
    192       1.2      joff 	if (ifp->if_flags & IFF_OACTIVE) {
    193       1.2      joff 		ifp->if_flags &= ~IFF_OACTIVE;
    194       1.2      joff 		/* Disable end-of-tx-chain interrupt */
    195       1.2      joff 		EPE_WRITE(IntEn, IntEn_REOFIE);
    196       1.2      joff 	}
    197       1.2      joff 	return ndq;
    198       1.2      joff }
    199       1.2      joff 
    200       1.2      joff static int
    201       1.1      joff epe_intr(void *arg)
    202       1.1      joff {
    203       1.1      joff 	struct epe_softc *sc = (struct epe_softc *)arg;
    204       1.1      joff 	struct ifnet * ifp = &sc->sc_ec.ec_if;
    205      1.29     skrll 	uint32_t ndq = 0, irq, *cur;
    206       1.1      joff 
    207       1.1      joff 	irq = EPE_READ(IntStsC);
    208       1.1      joff begin:
    209      1.29     skrll 	cur = (uint32_t *)(EPE_READ(RXStsQCurAdd) -
    210      1.11        he 		sc->ctrlpage_dsaddr + (char*)sc->ctrlpage);
    211      1.29     skrll 	CTRLPAGE_DMASYNC(TX_QLEN * 3 * sizeof(uint32_t),
    212  1.38.2.1  christos 		RX_QLEN * 4 * sizeof(uint32_t),
    213       1.1      joff 		BUS_DMASYNC_PREREAD);
    214       1.1      joff 	while (sc->RXStsQ_cur != cur) {
    215  1.38.2.1  christos 		if ((sc->RXStsQ_cur[0] & (RXStsQ_RWE | RXStsQ_RFP |RXStsQ_EOB))
    216  1.38.2.1  christos 		    == (RXStsQ_RWE | RXStsQ_RFP | RXStsQ_EOB)) {
    217      1.29     skrll 			uint32_t bi = (sc->RXStsQ_cur[1] >> 16) & 0x7fff;
    218      1.29     skrll 			uint32_t fl = sc->RXStsQ_cur[1] & 0xffff;
    219       1.1      joff 			struct mbuf *m;
    220       1.1      joff 
    221       1.1      joff 			MGETHDR(m, M_DONTWAIT, MT_DATA);
    222       1.1      joff 			if (m != NULL) MCLGET(m, M_DONTWAIT);
    223       1.1      joff 			if (m != NULL && (m->m_flags & M_EXT)) {
    224  1.38.2.1  christos 				bus_dmamap_unload(sc->sc_dmat,
    225       1.1      joff 					sc->rxq[bi].m_dmamap);
    226      1.34     ozaki 				m_set_rcvif(sc->rxq[bi].m, ifp);
    227  1.38.2.1  christos 				sc->rxq[bi].m->m_pkthdr.len =
    228       1.1      joff 					sc->rxq[bi].m->m_len = fl;
    229      1.33     ozaki 				if_percpuq_enqueue(ifp->if_percpuq,
    230      1.33     ozaki 				    sc->rxq[bi].m);
    231       1.1      joff 				sc->rxq[bi].m = m;
    232  1.38.2.1  christos 				bus_dmamap_load(sc->sc_dmat,
    233  1.38.2.1  christos 					sc->rxq[bi].m_dmamap,
    234       1.1      joff 					m->m_ext.ext_buf, MCLBYTES,
    235       1.1      joff 					NULL, BUS_DMA_NOWAIT);
    236  1.38.2.1  christos 				sc->RXDQ[bi * 2] =
    237       1.1      joff 					sc->rxq[bi].m_dmamap->dm_segs[0].ds_addr;
    238       1.1      joff 			} else {
    239       1.1      joff 				/* Drop packets until we can get replacement
    240       1.1      joff 				 * empty mbufs for the RXDQ.
    241       1.1      joff 				 */
    242  1.38.2.1  christos 				if (m != NULL)
    243       1.1      joff 					m_freem(m);
    244  1.38.2.1  christos 
    245  1.38.2.2    martin 				if_statinc(ifp, if_ierrors);
    246  1.38.2.1  christos 			}
    247  1.38.2.1  christos 		} else
    248  1.38.2.2    martin 			if_statinc(ifp, if_ierrors);
    249       1.1      joff 
    250       1.1      joff 		ndq++;
    251       1.1      joff 
    252       1.1      joff 		sc->RXStsQ_cur += 2;
    253  1.38.2.1  christos 		if (sc->RXStsQ_cur >= sc->RXStsQ + (RX_QLEN * 2))
    254       1.1      joff 			sc->RXStsQ_cur = sc->RXStsQ;
    255       1.1      joff 	}
    256       1.1      joff 
    257       1.1      joff 	if (ndq > 0) {
    258       1.1      joff 		ifp->if_ipackets += ndq;
    259      1.29     skrll 		CTRLPAGE_DMASYNC(TX_QLEN * 3 * sizeof(uint32_t),
    260  1.38.2.1  christos 			RX_QLEN * 4 * sizeof(uint32_t),
    261  1.38.2.1  christos 			BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
    262       1.1      joff 		EPE_WRITE(RXStsEnq, ndq);
    263       1.1      joff 		EPE_WRITE(RXDEnq, ndq);
    264       1.1      joff 		ndq = 0;
    265       1.1      joff 	}
    266       1.1      joff 
    267       1.2      joff 	if (epe_gctx(sc) > 0 && IFQ_IS_EMPTY(&ifp->if_snd) == 0) {
    268      1.36    nonaka 		if_schedule_deferred_start(ifp);
    269  1.38.2.1  christos 	}
    270       1.1      joff 
    271       1.1      joff 	irq = EPE_READ(IntStsC);
    272  1.38.2.1  christos 	if ((irq & (IntSts_RxSQ | IntSts_ECI)) != 0)
    273       1.1      joff 		goto begin;
    274       1.2      joff 
    275  1.38.2.1  christos 	return 1;
    276       1.1      joff }
    277       1.1      joff 
    278       1.1      joff 
    279       1.1      joff static void
    280       1.1      joff epe_init(struct epe_softc *sc)
    281       1.1      joff {
    282       1.1      joff 	bus_dma_segment_t segs;
    283      1.11        he 	char *addr;
    284       1.1      joff 	int rsegs, err, i;
    285       1.1      joff 	struct ifnet * ifp = &sc->sc_ec.ec_if;
    286  1.38.2.1  christos 	struct mii_data *mii = &sc->sc_mii;
    287       1.4  hamajima 	int mdcdiv = DEFAULT_MDCDIV;
    288       1.1      joff 
    289      1.12        ad 	callout_init(&sc->epe_tick_ch, 0);
    290       1.1      joff 
    291       1.1      joff 	/* Select primary Individual Address in Address Filter Pointer */
    292       1.1      joff 	EPE_WRITE(AFP, 0);
    293       1.1      joff 	/* Read ethernet MAC, should already be set by bootrom */
    294       1.1      joff 	bus_space_read_region_1(sc->sc_iot, sc->sc_ioh, EPE_IndAd,
    295       1.1      joff 		sc->sc_enaddr, ETHER_ADDR_LEN);
    296  1.38.2.1  christos 	aprint_normal_dev(sc->sc_dev, "MAC address %s\n",
    297       1.1      joff 		ether_sprintf(sc->sc_enaddr));
    298       1.1      joff 
    299       1.1      joff 	/* Soft Reset the MAC */
    300       1.1      joff 	EPE_WRITE(SelfCtl, SelfCtl_RESET);
    301  1.38.2.1  christos 	while (EPE_READ(SelfCtl) & SelfCtl_RESET)
    302  1.38.2.1  christos 		;
    303       1.1      joff 
    304       1.1      joff 	/* suggested magic initialization values from datasheet */
    305       1.1      joff 	EPE_WRITE(RXBufThrshld, 0x800040);
    306       1.1      joff 	EPE_WRITE(TXBufThrshld, 0x200010);
    307       1.1      joff 	EPE_WRITE(RXStsThrshld, 0x40002);
    308       1.1      joff 	EPE_WRITE(TXStsThrshld, 0x40002);
    309       1.1      joff 	EPE_WRITE(RXDThrshld, 0x40002);
    310       1.1      joff 	EPE_WRITE(TXDThrshld, 0x40002);
    311       1.1      joff 
    312       1.1      joff 	/* Allocate a page of memory for descriptor and status queues */
    313  1.38.2.1  christos 	err = bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, 0, PAGE_SIZE,
    314       1.1      joff 		&segs, 1, &rsegs, BUS_DMA_WAITOK);
    315       1.1      joff 	if (err == 0) {
    316  1.38.2.1  christos 		err = bus_dmamem_map(sc->sc_dmat, &segs, 1, PAGE_SIZE,
    317  1.38.2.1  christos 			&sc->ctrlpage, (BUS_DMA_WAITOK | BUS_DMA_COHERENT));
    318       1.1      joff 	}
    319       1.1      joff 	if (err == 0) {
    320       1.1      joff 		err = bus_dmamap_create(sc->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE,
    321       1.1      joff 			0, BUS_DMA_WAITOK, &sc->ctrlpage_dmamap);
    322       1.1      joff 	}
    323       1.1      joff 	if (err == 0) {
    324       1.1      joff 		err = bus_dmamap_load(sc->sc_dmat, sc->ctrlpage_dmamap,
    325       1.1      joff 			sc->ctrlpage, PAGE_SIZE, NULL, BUS_DMA_WAITOK);
    326       1.1      joff 	}
    327       1.1      joff 	if (err != 0) {
    328      1.27      matt 		panic("%s: Cannot get DMA memory", device_xname(sc->sc_dev));
    329       1.1      joff 	}
    330       1.2      joff 	sc->ctrlpage_dsaddr = sc->ctrlpage_dmamap->dm_segs[0].ds_addr;
    331      1.21    cegger 	memset(sc->ctrlpage, 0, PAGE_SIZE);
    332  1.38.2.1  christos 
    333       1.1      joff 	/* Set up pointers to start of each queue in kernel addr space.
    334       1.1      joff 	 * Each descriptor queue or status queue entry uses 2 words
    335       1.1      joff 	 */
    336      1.29     skrll 	sc->TXDQ = (uint32_t *)sc->ctrlpage;
    337       1.1      joff 	sc->TXDQ_cur = sc->TXDQ;
    338       1.1      joff 	sc->TXDQ_avail = TX_QLEN - 1;
    339       1.1      joff 	sc->TXStsQ = &sc->TXDQ[TX_QLEN * 2];
    340       1.1      joff 	sc->TXStsQ_cur = sc->TXStsQ;
    341       1.1      joff 	sc->RXDQ = &sc->TXStsQ[TX_QLEN];
    342       1.1      joff 	sc->RXStsQ = &sc->RXDQ[RX_QLEN * 2];
    343       1.1      joff 	sc->RXStsQ_cur = sc->RXStsQ;
    344       1.1      joff 
    345       1.1      joff 	/* Program each queue's start addr, cur addr, and len registers
    346  1.38.2.1  christos 	 * with the physical addresses.
    347       1.1      joff 	 */
    348      1.11        he 	addr = (char *)sc->ctrlpage_dmamap->dm_segs[0].ds_addr;
    349      1.29     skrll 	EPE_WRITE(TXDQBAdd, (uint32_t)addr);
    350      1.29     skrll 	EPE_WRITE(TXDQCurAdd, (uint32_t)addr);
    351  1.38.2.1  christos 	EPE_WRITE(TXDQBLen, TX_QLEN * 2 * sizeof(uint32_t));
    352      1.29     skrll 
    353      1.29     skrll 	addr += (sc->TXStsQ - sc->TXDQ) * sizeof(uint32_t);
    354      1.29     skrll 	EPE_WRITE(TXStsQBAdd, (uint32_t)addr);
    355      1.29     skrll 	EPE_WRITE(TXStsQCurAdd, (uint32_t)addr);
    356      1.29     skrll 	EPE_WRITE(TXStsQBLen, TX_QLEN * sizeof(uint32_t));
    357      1.29     skrll 
    358      1.29     skrll 	addr += (sc->RXDQ - sc->TXStsQ) * sizeof(uint32_t);
    359      1.29     skrll 	EPE_WRITE(RXDQBAdd, (uint32_t)addr);
    360      1.29     skrll 	EPE_WRITE(RXDCurAdd, (uint32_t)addr);
    361      1.29     skrll 	EPE_WRITE(RXDQBLen, RX_QLEN * 2 * sizeof(uint32_t));
    362  1.38.2.1  christos 
    363      1.29     skrll 	addr += (sc->RXStsQ - sc->RXDQ) * sizeof(uint32_t);
    364      1.29     skrll 	EPE_WRITE(RXStsQBAdd, (uint32_t)addr);
    365      1.29     skrll 	EPE_WRITE(RXStsQCurAdd, (uint32_t)addr);
    366      1.29     skrll 	EPE_WRITE(RXStsQBLen, RX_QLEN * 2 * sizeof(uint32_t));
    367       1.1      joff 
    368       1.1      joff 	/* Populate the RXDQ with mbufs */
    369  1.38.2.1  christos 	for (i = 0; i < RX_QLEN; i++) {
    370       1.1      joff 		struct mbuf *m;
    371       1.1      joff 
    372  1.38.2.1  christos 		bus_dmamap_create(sc->sc_dmat, MCLBYTES, TX_QLEN/4, MCLBYTES,
    373  1.38.2.1  christos 		    0, BUS_DMA_WAITOK, &sc->rxq[i].m_dmamap);
    374       1.1      joff 		MGETHDR(m, M_WAIT, MT_DATA);
    375       1.1      joff 		MCLGET(m, M_WAIT);
    376       1.1      joff 		sc->rxq[i].m = m;
    377  1.38.2.1  christos 		bus_dmamap_load(sc->sc_dmat, sc->rxq[i].m_dmamap,
    378  1.38.2.1  christos 			m->m_ext.ext_buf, MCLBYTES, NULL, BUS_DMA_WAITOK);
    379       1.1      joff 
    380       1.1      joff 		sc->RXDQ[i * 2] = sc->rxq[i].m_dmamap->dm_segs[0].ds_addr;
    381       1.1      joff 		sc->RXDQ[i * 2 + 1] = (i << 16) | MCLBYTES;
    382       1.1      joff 		bus_dmamap_sync(sc->sc_dmat, sc->rxq[i].m_dmamap, 0,
    383       1.1      joff 			MCLBYTES, BUS_DMASYNC_PREREAD);
    384       1.1      joff 	}
    385       1.1      joff 
    386  1.38.2.1  christos 	for (i = 0; i < TX_QLEN; i++) {
    387       1.1      joff 		bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1, MCLBYTES, 0,
    388  1.38.2.1  christos 			(BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW),
    389       1.1      joff 			&sc->txq[i].m_dmamap);
    390       1.1      joff 		sc->txq[i].m = NULL;
    391       1.1      joff 		sc->TXDQ[i * 2 + 1] = (i << 16);
    392       1.1      joff 	}
    393       1.1      joff 
    394       1.1      joff 	/* Divide HCLK by 32 for MDC clock */
    395      1.27      matt 	if (device_cfdata(sc->sc_dev)->cf_flags)
    396      1.27      matt 		mdcdiv = device_cfdata(sc->sc_dev)->cf_flags;
    397  1.38.2.1  christos 	EPE_WRITE(SelfCtl, (SelfCtl_MDCDIV(mdcdiv) | SelfCtl_PSPRS));
    398       1.1      joff 
    399  1.38.2.1  christos 	mii->mii_ifp = ifp;
    400  1.38.2.1  christos 	mii->mii_readreg = epe_mii_readreg;
    401  1.38.2.1  christos 	mii->mii_writereg = epe_mii_writereg;
    402  1.38.2.1  christos 	mii->mii_statchg = epe_statchg;
    403  1.38.2.1  christos 	sc->sc_ec.ec_mii = mii;
    404  1.38.2.2    martin 	ifmedia_init(&mii->mii_media, IFM_IMASK, ether_mediachange,
    405      1.15    dyoung 		ether_mediastatus);
    406  1.38.2.1  christos 	mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY,
    407  1.38.2.1  christos 	    MII_OFFSET_ANY, 0);
    408  1.38.2.1  christos 	ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
    409       1.1      joff 
    410  1.38.2.1  christos 	EPE_WRITE(BMCtl, BMCtl_RxEn | BMCtl_TxEn);
    411       1.2      joff 	EPE_WRITE(IntEn, IntEn_REOFIE);
    412       1.1      joff 	/* maximum valid max frame length */
    413  1.38.2.1  christos 	EPE_WRITE(MaxFrmLen, (0x7ff << 16) | MHLEN);
    414       1.1      joff 	/* wait for receiver ready */
    415  1.38.2.1  christos 	while ((EPE_READ(BMSts) & BMSts_RxAct) == 0)
    416      1.30     joerg 		continue;
    417       1.1      joff 	/* enqueue the entries in RXStsQ and RXDQ */
    418  1.38.2.1  christos 	CTRLPAGE_DMASYNC(0, sc->ctrlpage_dmamap->dm_mapsize,
    419  1.38.2.1  christos 		BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
    420       1.1      joff 	EPE_WRITE(RXDEnq, RX_QLEN - 1);
    421       1.1      joff 	EPE_WRITE(RXStsEnq, RX_QLEN - 1);
    422       1.1      joff 
    423       1.1      joff 	/*
    424       1.1      joff 	 * We can support 802.1Q VLAN-sized frames.
    425       1.1      joff 	 */
    426       1.1      joff 	sc->sc_ec.ec_capabilities |= ETHERCAP_VLAN_MTU;
    427       1.1      joff 
    428  1.38.2.1  christos 	strcpy(ifp->if_xname, device_xname(sc->sc_dev));
    429  1.38.2.1  christos 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    430  1.38.2.1  christos 	ifp->if_ioctl = epe_ifioctl;
    431  1.38.2.1  christos 	ifp->if_start = epe_ifstart;
    432  1.38.2.1  christos 	ifp->if_watchdog = epe_ifwatchdog;
    433  1.38.2.1  christos 	ifp->if_init = epe_ifinit;
    434  1.38.2.1  christos 	ifp->if_stop = epe_ifstop;
    435  1.38.2.1  christos 	ifp->if_timer = 0;
    436       1.1      joff 	ifp->if_softc = sc;
    437  1.38.2.1  christos 	IFQ_SET_READY(&ifp->if_snd);
    438  1.38.2.1  christos 	if_attach(ifp);
    439      1.36    nonaka 	if_deferred_start_init(ifp, NULL);
    440  1.38.2.1  christos 	ether_ifattach(ifp, (sc)->sc_enaddr);
    441       1.1      joff }
    442       1.1      joff 
    443       1.1      joff int
    444  1.38.2.1  christos epe_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
    445       1.1      joff {
    446  1.38.2.1  christos 	uint32_t d;
    447       1.1      joff 
    448       1.1      joff 	d = EPE_READ(SelfCtl);
    449       1.1      joff 	EPE_WRITE(SelfCtl, d & ~SelfCtl_PSPRS); /* no preamble suppress */
    450       1.1      joff 	EPE_WRITE(MIICmd, (MIICmd_READ | (phy << 5) | reg));
    451  1.38.2.1  christos 	while (EPE_READ(MIISts) & MIISts_BUSY)
    452  1.38.2.1  christos 		;
    453  1.38.2.1  christos 	*val = EPE_READ(MIIData) & 0xffff;
    454       1.1      joff 	EPE_WRITE(SelfCtl, d); /* restore old value */
    455  1.38.2.1  christos 	return 0;
    456       1.1      joff }
    457       1.1      joff 
    458  1.38.2.1  christos int
    459  1.38.2.1  christos epe_mii_writereg(device_t self, int phy, int reg, uint16_t val)
    460       1.1      joff {
    461      1.29     skrll 	uint32_t d;
    462       1.1      joff 
    463       1.1      joff 	d = EPE_READ(SelfCtl);
    464       1.1      joff 	EPE_WRITE(SelfCtl, d & ~SelfCtl_PSPRS); /* no preamble suppress */
    465       1.3  hamajima 	EPE_WRITE(MIIData, val);
    466       1.1      joff 	EPE_WRITE(MIICmd, (MIICmd_WRITE | (phy << 5) | reg));
    467  1.38.2.1  christos 	while (EPE_READ(MIISts) & MIISts_BUSY)
    468  1.38.2.1  christos 		;
    469       1.1      joff 	EPE_WRITE(SelfCtl, d); /* restore old value */
    470  1.38.2.1  christos 
    471  1.38.2.1  christos 	return 0;
    472       1.1      joff }
    473       1.1      joff 
    474       1.1      joff void
    475      1.27      matt epe_statchg(struct ifnet *ifp)
    476       1.1      joff {
    477  1.38.2.1  christos 	struct epe_softc *sc = ifp->if_softc;
    478  1.38.2.1  christos 	uint32_t reg;
    479       1.1      joff 
    480  1.38.2.1  christos 	/*
    481  1.38.2.1  christos 	 * We must keep the MAC and the PHY in sync as
    482  1.38.2.1  christos 	 * to the status of full-duplex!
    483  1.38.2.1  christos 	 */
    484  1.38.2.1  christos 	reg = EPE_READ(TestCtl);
    485  1.38.2.1  christos 	if (sc->sc_mii.mii_media_active & IFM_FDX)
    486  1.38.2.1  christos 		reg |= TestCtl_MFDX;
    487  1.38.2.1  christos 	else
    488  1.38.2.1  christos 		reg &= ~TestCtl_MFDX;
    489       1.1      joff 	EPE_WRITE(TestCtl, reg);
    490       1.1      joff }
    491       1.1      joff 
    492       1.1      joff void
    493      1.19       dsl epe_tick(void *arg)
    494       1.1      joff {
    495       1.1      joff 	struct epe_softc* sc = (struct epe_softc *)arg;
    496       1.1      joff 	struct ifnet * ifp = &sc->sc_ec.ec_if;
    497       1.2      joff 	int s;
    498      1.29     skrll 	uint32_t misses;
    499       1.1      joff 
    500  1.38.2.2    martin 	if_statadd(ifp, if_collisions, EPE_READ(TXCollCnt));
    501       1.1      joff 	/* These misses are ok, they will happen if the RAM/CPU can't keep up */
    502       1.1      joff 	misses = EPE_READ(RXMissCnt);
    503  1.38.2.1  christos 	if (misses > 0)
    504      1.27      matt 		printf("%s: %d rx misses\n", device_xname(sc->sc_dev), misses);
    505  1.38.2.1  christos 
    506       1.2      joff 	s = splnet();
    507       1.2      joff 	if (epe_gctx(sc) > 0 && IFQ_IS_EMPTY(&ifp->if_snd) == 0) {
    508       1.2      joff 		epe_ifstart(ifp);
    509       1.2      joff 	}
    510       1.2      joff 	splx(s);
    511       1.2      joff 
    512       1.1      joff 	mii_tick(&sc->sc_mii);
    513       1.1      joff 	callout_reset(&sc->epe_tick_ch, hz, epe_tick, sc);
    514       1.1      joff }
    515       1.1      joff 
    516       1.1      joff 
    517       1.1      joff static int
    518      1.19       dsl epe_ifioctl(struct ifnet *ifp, u_long cmd, void *data)
    519       1.1      joff {
    520       1.1      joff 	int s, error;
    521       1.1      joff 
    522       1.1      joff 	s = splnet();
    523      1.15    dyoung 	error = ether_ioctl(ifp, cmd, data);
    524      1.15    dyoung 	if (error == ENETRESET) {
    525      1.15    dyoung 		if (ifp->if_flags & IFF_RUNNING)
    526      1.15    dyoung 			epe_setaddr(ifp);
    527      1.15    dyoung 		error = 0;
    528       1.1      joff 	}
    529       1.1      joff 	splx(s);
    530       1.1      joff 	return error;
    531       1.1      joff }
    532       1.1      joff 
    533       1.1      joff static void
    534      1.19       dsl epe_ifstart(struct ifnet *ifp)
    535       1.1      joff {
    536       1.1      joff 	struct epe_softc *sc = (struct epe_softc *)ifp->if_softc;
    537       1.1      joff 	struct mbuf *m;
    538       1.1      joff 	bus_dma_segment_t *segs;
    539       1.2      joff 	int s, bi, err, nsegs, ndq;
    540       1.2      joff 
    541  1.38.2.1  christos 	s = splnet();
    542       1.2      joff start:
    543       1.2      joff 	ndq = 0;
    544       1.1      joff 	if (sc->TXDQ_avail == 0) {
    545       1.2      joff 		if (epe_gctx(sc) == 0) {
    546       1.2      joff 			/* Enable End-Of-TX-Chain interrupt */
    547  1.38.2.1  christos 			EPE_WRITE(IntEn, IntEn_REOFIE | IntEn_ECIE);
    548       1.2      joff 			ifp->if_flags |= IFF_OACTIVE;
    549       1.2      joff 			ifp->if_timer = 10;
    550       1.2      joff 			splx(s);
    551       1.2      joff 			return;
    552       1.2      joff 		}
    553  1.38.2.1  christos 	}
    554       1.2      joff 
    555  1.38.2.1  christos 	bi = sc->TXDQ_cur - sc->TXDQ;
    556       1.1      joff 
    557       1.1      joff 	IFQ_POLL(&ifp->if_snd, m);
    558       1.1      joff 	if (m == NULL) {
    559       1.1      joff 		splx(s);
    560       1.1      joff 		return;
    561       1.1      joff 	}
    562       1.2      joff more:
    563       1.1      joff 	if ((err = bus_dmamap_load_mbuf(sc->sc_dmat, sc->txq[bi].m_dmamap, m,
    564  1.38.2.1  christos 		BUS_DMA_NOWAIT)) ||
    565       1.1      joff 		sc->txq[bi].m_dmamap->dm_segs[0].ds_addr & 0x3 ||
    566       1.1      joff 		sc->txq[bi].m_dmamap->dm_nsegs > (sc->TXDQ_avail - ndq)) {
    567       1.1      joff 		/* Copy entire mbuf chain to new and 32-bit aligned storage */
    568       1.1      joff 		struct mbuf *mn;
    569       1.1      joff 
    570  1.38.2.1  christos 		if (err == 0)
    571       1.1      joff 			bus_dmamap_unload(sc->sc_dmat, sc->txq[bi].m_dmamap);
    572       1.1      joff 
    573       1.1      joff 		MGETHDR(mn, M_DONTWAIT, MT_DATA);
    574       1.1      joff 		if (mn == NULL) goto stop;
    575       1.1      joff 		if (m->m_pkthdr.len > (MHLEN & (~0x3))) {
    576       1.1      joff 			MCLGET(mn, M_DONTWAIT);
    577       1.1      joff 			if ((mn->m_flags & M_EXT) == 0) {
    578       1.1      joff 				m_freem(mn);
    579       1.1      joff 				goto stop;
    580       1.1      joff 			}
    581       1.1      joff 		}
    582  1.38.2.1  christos 		mn->m_data = (void *)(((uint32_t)mn->m_data + 0x3) & (~0x3));
    583      1.10  christos 		m_copydata(m, 0, m->m_pkthdr.len, mtod(mn, void *));
    584       1.1      joff 		mn->m_pkthdr.len = mn->m_len = m->m_pkthdr.len;
    585       1.1      joff 		IFQ_DEQUEUE(&ifp->if_snd, m);
    586       1.1      joff 		m_freem(m);
    587       1.1      joff 		m = mn;
    588       1.1      joff 		bus_dmamap_load_mbuf(sc->sc_dmat, sc->txq[bi].m_dmamap, m,
    589       1.1      joff 			BUS_DMA_NOWAIT);
    590       1.1      joff 	} else {
    591       1.1      joff 		IFQ_DEQUEUE(&ifp->if_snd, m);
    592       1.1      joff 	}
    593       1.1      joff 
    594      1.38   msaitoh 	bpf_mtap(ifp, m, BPF_D_OUT);
    595       1.1      joff 
    596       1.1      joff 	nsegs = sc->txq[bi].m_dmamap->dm_nsegs;
    597       1.1      joff 	segs = sc->txq[bi].m_dmamap->dm_segs;
    598  1.38.2.1  christos 	bus_dmamap_sync(sc->sc_dmat, sc->txq[bi].m_dmamap, 0,
    599  1.38.2.1  christos 		sc->txq[bi].m_dmamap->dm_mapsize,
    600  1.38.2.1  christos 		BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
    601       1.1      joff 
    602       1.1      joff 	/* XXX: This driver hasn't been tested w/nsegs > 1 */
    603       1.1      joff 	while (nsegs > 0) {
    604       1.1      joff 		nsegs--;
    605       1.1      joff 		sc->txq[bi].m = m;
    606       1.1      joff 		sc->TXDQ[bi * 2] = segs->ds_addr;
    607       1.1      joff 		if (nsegs == 0)
    608       1.1      joff 			sc->TXDQ[bi * 2 + 1] = segs->ds_len | (bi << 16) |
    609       1.1      joff 				(1 << 31);
    610       1.1      joff 		else
    611       1.1      joff 			sc->TXDQ[bi * 2 + 1] = segs->ds_len | (bi << 16);
    612       1.1      joff 		segs++;
    613       1.1      joff 		bi = (bi + 1) % TX_QLEN;
    614       1.1      joff 		ndq++;
    615       1.1      joff 	}
    616       1.1      joff 
    617       1.1      joff 
    618       1.2      joff 	/*
    619       1.2      joff 	 * Enqueue another.  Don't do more than half the available
    620       1.2      joff 	 * descriptors before telling the MAC about them
    621       1.2      joff 	 */
    622       1.2      joff 	if ((sc->TXDQ_avail - ndq) > 0 && ndq < TX_QLEN / 2) {
    623       1.1      joff 		IFQ_POLL(&ifp->if_snd, m);
    624  1.38.2.1  christos 		if (m != NULL)
    625       1.2      joff 			goto more;
    626  1.38.2.1  christos 	}
    627       1.1      joff stop:
    628       1.1      joff 	if (ndq > 0) {
    629       1.1      joff 		sc->TXDQ_avail -= ndq;
    630       1.1      joff 		sc->TXDQ_cur = &sc->TXDQ[bi];
    631      1.29     skrll 		CTRLPAGE_DMASYNC(0, TX_QLEN * 2 * sizeof(uint32_t),
    632  1.38.2.1  christos 			BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
    633       1.1      joff 		EPE_WRITE(TXDEnq, ndq);
    634       1.1      joff 	}
    635       1.2      joff 
    636       1.2      joff 	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
    637       1.2      joff 		goto start;
    638       1.2      joff 
    639       1.1      joff 	splx(s);
    640       1.1      joff 	return;
    641       1.1      joff }
    642       1.1      joff 
    643       1.1      joff static void
    644      1.19       dsl epe_ifwatchdog(struct ifnet *ifp)
    645       1.1      joff {
    646       1.1      joff 	struct epe_softc *sc = (struct epe_softc *)ifp->if_softc;
    647       1.1      joff 
    648       1.1      joff 	if ((ifp->if_flags & IFF_RUNNING) == 0)
    649       1.1      joff 		return;
    650  1.38.2.1  christos 	printf("%s: device timeout, BMCtl = 0x%08x, BMSts = 0x%08x\n",
    651      1.27      matt 		device_xname(sc->sc_dev), EPE_READ(BMCtl), EPE_READ(BMSts));
    652       1.1      joff }
    653       1.1      joff 
    654       1.1      joff static int
    655      1.19       dsl epe_ifinit(struct ifnet *ifp)
    656       1.1      joff {
    657       1.1      joff 	struct epe_softc *sc = ifp->if_softc;
    658      1.15    dyoung 	int rc, s = splnet();
    659       1.1      joff 
    660       1.1      joff 	callout_stop(&sc->epe_tick_ch);
    661  1.38.2.1  christos 	EPE_WRITE(RXCtl, RXCtl_IA0 | RXCtl_BA | RXCtl_RCRCA | RXCtl_SRxON);
    662       1.1      joff 	EPE_WRITE(TXCtl, TXCtl_STxON);
    663       1.1      joff 	EPE_WRITE(GIIntMsk, GIIntMsk_INT); /* start interrupting */
    664      1.15    dyoung 
    665      1.15    dyoung 	if ((rc = mii_mediachg(&sc->sc_mii)) == ENXIO)
    666      1.15    dyoung 		rc = 0;
    667      1.15    dyoung 	else if (rc != 0)
    668      1.15    dyoung 		goto out;
    669      1.15    dyoung 
    670       1.1      joff 	callout_reset(&sc->epe_tick_ch, hz, epe_tick, sc);
    671  1.38.2.1  christos 	ifp->if_flags |= IFF_RUNNING;
    672      1.15    dyoung out:
    673       1.1      joff 	splx(s);
    674       1.1      joff 	return 0;
    675       1.1      joff }
    676       1.1      joff 
    677       1.1      joff static void
    678      1.19       dsl epe_ifstop(struct ifnet *ifp, int disable)
    679       1.1      joff {
    680       1.1      joff 	struct epe_softc *sc = ifp->if_softc;
    681       1.1      joff 
    682       1.1      joff 
    683       1.1      joff 	EPE_WRITE(RXCtl, 0);
    684       1.1      joff 	EPE_WRITE(TXCtl, 0);
    685       1.1      joff 	EPE_WRITE(GIIntMsk, 0);
    686       1.1      joff 	callout_stop(&sc->epe_tick_ch);
    687       1.1      joff 
    688       1.1      joff 	/* Down the MII. */
    689       1.1      joff 	mii_down(&sc->sc_mii);
    690       1.1      joff 
    691       1.1      joff 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
    692       1.1      joff 	ifp->if_timer = 0;
    693       1.1      joff 	sc->sc_mii.mii_media_status &= ~IFM_ACTIVE;
    694       1.1      joff }
    695       1.1      joff 
    696       1.1      joff static void
    697      1.19       dsl epe_setaddr(struct ifnet *ifp)
    698       1.1      joff {
    699       1.1      joff 	struct epe_softc *sc = ifp->if_softc;
    700  1.38.2.1  christos 	struct ethercom *ec = &sc->sc_ec;
    701       1.1      joff 	struct ether_multi *enm;
    702       1.1      joff 	struct ether_multistep step;
    703      1.29     skrll 	uint8_t ias[2][ETHER_ADDR_LEN];
    704      1.29     skrll 	uint32_t h, nma = 0, hashes[2] = { 0, 0 };
    705      1.29     skrll 	uint32_t rxctl = EPE_READ(RXCtl);
    706       1.1      joff 
    707       1.1      joff 	/* disable receiver temporarily */
    708       1.1      joff 	EPE_WRITE(RXCtl, rxctl & ~RXCtl_SRxON);
    709       1.1      joff 
    710  1.38.2.1  christos 	rxctl &= ~(RXCtl_MA | RXCtl_PA | RXCtl_IA2 | RXCtl_IA3);
    711  1.38.2.1  christos 
    712  1.38.2.1  christos 	if (ifp->if_flags & IFF_PROMISC)
    713       1.1      joff 		rxctl |= RXCtl_PA;
    714       1.1      joff 
    715       1.1      joff 	ifp->if_flags &= ~IFF_ALLMULTI;
    716       1.1      joff 
    717  1.38.2.1  christos 	ETHER_LOCK(ec);
    718  1.38.2.1  christos 	ETHER_FIRST_MULTI(step, ec, enm);
    719       1.1      joff 	while (enm != NULL) {
    720       1.1      joff 		if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
    721       1.1      joff 			/*
    722       1.1      joff 			 * We must listen to a range of multicast addresses.
    723       1.1      joff 			 * For now, just accept all multicasts, rather than
    724       1.1      joff 			 * trying to set only those filter bits needed to match
    725       1.1      joff 			 * the range.  (At this time, the only use of address
    726       1.1      joff 			 * ranges is for IP multicast routing, for which the
    727       1.1      joff 			 * range is big enough to require all bits set.)
    728       1.1      joff 			 */
    729  1.38.2.1  christos 			rxctl &= ~(RXCtl_IA2 | RXCtl_IA3);
    730       1.1      joff 			rxctl |= RXCtl_MA;
    731       1.1      joff 			hashes[0] = 0xffffffffUL;
    732       1.1      joff 			hashes[1] = 0xffffffffUL;
    733       1.1      joff 			ifp->if_flags |= IFF_ALLMULTI;
    734       1.1      joff 			break;
    735       1.1      joff 		}
    736       1.1      joff 
    737       1.1      joff 		if (nma < 2) {
    738       1.1      joff 			/* We can program 2 perfect address filters for mcast */
    739  1.38.2.1  christos 			memcpy(ias[nma], enm->enm_addrlo, ETHER_ADDR_LEN);
    740       1.1      joff 			rxctl |= (1 << (nma + 2));
    741       1.1      joff 		} else {
    742       1.1      joff 			/*
    743       1.1      joff 			 * XXX: Datasheet is not very clear here, I'm not sure
    744       1.1      joff 			 * if I'm doing this right.  --joff
    745       1.1      joff 			 */
    746       1.1      joff 			h = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
    747       1.1      joff 
    748       1.1      joff 			/* Just want the 6 most-significant bits. */
    749       1.1      joff 			h = h >> 26;
    750       1.1      joff 
    751       1.1      joff 			hashes[ h / 32 ] |=  (1 << (h % 32));
    752       1.1      joff 			rxctl |= RXCtl_MA;
    753       1.1      joff 		}
    754       1.1      joff 		ETHER_NEXT_MULTI(step, enm);
    755       1.1      joff 		nma++;
    756       1.1      joff 	}
    757  1.38.2.1  christos 	ETHER_UNLOCK(ec);
    758  1.38.2.1  christos 
    759       1.1      joff 	EPE_WRITE(AFP, 0);
    760  1.38.2.1  christos 	bus_space_write_region_1(sc->sc_iot, sc->sc_ioh, EPE_IndAd,
    761       1.1      joff 		sc->sc_enaddr, ETHER_ADDR_LEN);
    762       1.1      joff 	if (rxctl & RXCtl_IA2) {
    763       1.1      joff 		EPE_WRITE(AFP, 2);
    764       1.1      joff 		bus_space_write_region_1(sc->sc_iot, sc->sc_ioh, EPE_IndAd,
    765       1.1      joff 			ias[0], ETHER_ADDR_LEN);
    766       1.1      joff 	}
    767       1.1      joff 	if (rxctl & RXCtl_IA3) {
    768       1.1      joff 		EPE_WRITE(AFP, 3);
    769       1.1      joff 		bus_space_write_region_1(sc->sc_iot, sc->sc_ioh, EPE_IndAd,
    770       1.1      joff 			ias[1], ETHER_ADDR_LEN);
    771       1.1      joff 	}
    772       1.1      joff 	if (hashes[0] != 0 && hashes[1] != 0) {
    773       1.1      joff 		EPE_WRITE(AFP, 7);
    774       1.1      joff 		EPE_WRITE(HashTbl, hashes[0]);
    775       1.1      joff 		EPE_WRITE(HashTbl + 4, hashes[1]);
    776       1.1      joff 	}
    777       1.1      joff 	EPE_WRITE(RXCtl, rxctl);
    778       1.1      joff }
    779