Home | History | Annotate | Line # | Download | only in ic
mb86960.c revision 1.66.16.1
      1  1.66.16.1      matt /*	$NetBSD: mb86960.c,v 1.66.16.1 2007/11/06 23:26:52 matt Exp $	*/
      2       1.19     perry 
      3        1.1   mycroft /*
      4        1.1   mycroft  * All Rights Reserved, Copyright (C) Fujitsu Limited 1995
      5        1.1   mycroft  *
      6        1.1   mycroft  * This software may be used, modified, copied, distributed, and sold, in
      7        1.1   mycroft  * both source and binary form provided that the above copyright, these
      8        1.1   mycroft  * terms and the following disclaimer are retained.  The name of the author
      9        1.1   mycroft  * and/or the contributor may not be used to endorse or promote products
     10        1.1   mycroft  * derived from this software without specific prior written permission.
     11        1.1   mycroft  *
     12        1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND
     13        1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     14        1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     15        1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE
     16        1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     17        1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     18        1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION.
     19        1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     20        1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     21        1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     22        1.1   mycroft  * SUCH DAMAGE.
     23        1.1   mycroft  */
     24        1.1   mycroft 
     25        1.1   mycroft /*
     26        1.1   mycroft  * Portions copyright (C) 1993, David Greenman.  This software may be used,
     27        1.1   mycroft  * modified, copied, distributed, and sold, in both source and binary form
     28        1.1   mycroft  * provided that the above copyright and these terms are retained.  Under no
     29        1.1   mycroft  * circumstances is the author responsible for the proper functioning of this
     30        1.1   mycroft  * software, nor does the author assume any responsibility for damages
     31        1.1   mycroft  * incurred with its use.
     32        1.1   mycroft  */
     33       1.50     lukem 
     34       1.50     lukem #include <sys/cdefs.h>
     35  1.66.16.1      matt __KERNEL_RCSID(0, "$NetBSD: mb86960.c,v 1.66.16.1 2007/11/06 23:26:52 matt Exp $");
     36        1.1   mycroft 
     37        1.1   mycroft /*
     38        1.1   mycroft  * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards.
     39        1.1   mycroft  * Contributed by M.S. <seki (at) sysrap.cs.fujitsu.co.jp>
     40        1.1   mycroft  *
     41        1.1   mycroft  * This version is intended to be a generic template for various
     42        1.1   mycroft  * MB86960A/MB86965A based Ethernet cards.  It currently supports
     43        1.1   mycroft  * Fujitsu FMV-180 series (i.e., FMV-181 and FMV-182) and Allied-
     44        1.1   mycroft  * Telesis AT1700 series and RE2000 series.  There are some
     45        1.1   mycroft  * unnecessary hooks embedded, which are primarily intended to support
     46        1.1   mycroft  * other types of Ethernet cards, but the author is not sure whether
     47        1.1   mycroft  * they are useful.
     48        1.1   mycroft  */
     49        1.1   mycroft 
     50       1.25  jonathan #include "opt_inet.h"
     51        1.1   mycroft #include "bpfilter.h"
     52       1.18  explorer #include "rnd.h"
     53        1.1   mycroft 
     54        1.1   mycroft #include <sys/param.h>
     55        1.1   mycroft #include <sys/systm.h>
     56        1.1   mycroft #include <sys/errno.h>
     57        1.1   mycroft #include <sys/ioctl.h>
     58        1.1   mycroft #include <sys/mbuf.h>
     59        1.1   mycroft #include <sys/socket.h>
     60        1.1   mycroft #include <sys/syslog.h>
     61        1.1   mycroft #include <sys/device.h>
     62       1.18  explorer #if NRND > 0
     63       1.18  explorer #include <sys/rnd.h>
     64       1.18  explorer #endif
     65        1.1   mycroft 
     66        1.1   mycroft #include <net/if.h>
     67        1.1   mycroft #include <net/if_dl.h>
     68        1.1   mycroft #include <net/if_types.h>
     69       1.21     enami #include <net/if_media.h>
     70       1.17        is #include <net/if_ether.h>
     71        1.1   mycroft 
     72        1.1   mycroft #ifdef INET
     73        1.1   mycroft #include <netinet/in.h>
     74        1.1   mycroft #include <netinet/in_systm.h>
     75        1.1   mycroft #include <netinet/in_var.h>
     76        1.1   mycroft #include <netinet/ip.h>
     77       1.17        is #include <netinet/if_inarp.h>
     78        1.1   mycroft #endif
     79        1.1   mycroft 
     80        1.1   mycroft 
     81        1.1   mycroft #if NBPFILTER > 0
     82        1.1   mycroft #include <net/bpf.h>
     83        1.1   mycroft #include <net/bpfdesc.h>
     84        1.1   mycroft #endif
     85        1.1   mycroft 
     86  1.66.16.1      matt #include <sys/bus.h>
     87        1.1   mycroft 
     88        1.3       cgd #include <dev/ic/mb86960reg.h>
     89       1.21     enami #include <dev/ic/mb86960var.h>
     90        1.1   mycroft 
     91       1.35    itojun #ifndef __BUS_SPACE_HAS_STREAM_METHODS
     92       1.54   tsutsui #define bus_space_write_stream_2	bus_space_write_2
     93       1.35    itojun #define bus_space_write_multi_stream_2	bus_space_write_multi_2
     94       1.35    itojun #define bus_space_read_multi_stream_2	bus_space_read_multi_2
     95       1.35    itojun #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
     96       1.35    itojun 
     97        1.1   mycroft /* Standard driver entry points.  These can be static. */
     98       1.59   tsutsui void	mb86960_init(struct mb86960_softc *);
     99       1.66  christos int	mb86960_ioctl(struct ifnet *, u_long, void *);
    100       1.59   tsutsui void	mb86960_start(struct ifnet *);
    101       1.59   tsutsui void	mb86960_reset(struct mb86960_softc *);
    102       1.59   tsutsui void	mb86960_watchdog(struct ifnet *);
    103        1.1   mycroft 
    104        1.1   mycroft /* Local functions.  Order of declaration is confused.  FIXME. */
    105       1.59   tsutsui int	mb86960_get_packet(struct mb86960_softc *, u_int);
    106       1.59   tsutsui void	mb86960_stop(struct mb86960_softc *);
    107       1.59   tsutsui void	mb86960_tint(struct mb86960_softc *, uint8_t);
    108       1.59   tsutsui void	mb86960_rint(struct mb86960_softc *, uint8_t);
    109       1.62     perry static inline
    110       1.59   tsutsui void	mb86960_xmit(struct mb86960_softc *);
    111       1.59   tsutsui void	mb86960_write_mbufs(struct mb86960_softc *, struct mbuf *);
    112       1.62     perry static inline
    113       1.59   tsutsui void	mb86960_droppacket(struct mb86960_softc *);
    114       1.59   tsutsui void	mb86960_getmcaf(struct ethercom *, uint8_t *);
    115       1.59   tsutsui void	mb86960_setmode(struct mb86960_softc *);
    116       1.59   tsutsui void	mb86960_loadmar(struct mb86960_softc *);
    117        1.1   mycroft 
    118       1.59   tsutsui int	mb86960_mediachange(struct ifnet *);
    119       1.59   tsutsui void	mb86960_mediastatus(struct ifnet *, struct ifmediareq *);
    120        1.1   mycroft 
    121       1.21     enami #if FE_DEBUG >= 1
    122       1.59   tsutsui void	mb86960_dump(int, struct mb86960_softc *);
    123        1.1   mycroft #endif
    124        1.1   mycroft 
    125        1.1   mycroft void
    126       1.59   tsutsui mb86960_attach(struct mb86960_softc *sc, uint8_t *myea)
    127        1.1   mycroft {
    128       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
    129       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
    130        1.1   mycroft 
    131       1.21     enami 	/* Register values which depend on board design. */
    132       1.21     enami 	sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL;
    133       1.21     enami 	sc->proto_dlcr5 = 0;
    134       1.54   tsutsui 	sc->proto_dlcr7 = FE_D7_BYTSWP_LH;
    135       1.54   tsutsui 	if ((sc->sc_flags & FE_FLAGS_MB86960) != 0)
    136       1.54   tsutsui 		sc->proto_dlcr7 |= FE_D7_ED_TEST; /* XXX */
    137       1.21     enami 	sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO;
    138        1.1   mycroft 
    139        1.1   mycroft 	/*
    140       1.54   tsutsui 	 * Program the 86960 as following defaults:
    141        1.1   mycroft 	 *	SRAM: 32KB, 100ns, byte-wide access.
    142        1.1   mycroft 	 *	Transmission buffer: 4KB x 2.
    143        1.1   mycroft 	 *	System bus interface: 16 bits.
    144       1.54   tsutsui 	 * These values except TXBSIZE should be modified as per
    145       1.54   tsutsui 	 * sc_flags which is set in MD attachments, because they
    146       1.54   tsutsui 	 * are hard-wired on the board. Modifying TXBSIZE will affect
    147        1.1   mycroft 	 * the driver performance.
    148        1.1   mycroft 	 */
    149       1.21     enami 	sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB |
    150       1.56   tsutsui 	    FE_D6_BBW_BYTE | FE_D6_SRAM_100ns;
    151       1.54   tsutsui 	if (sc->sc_flags & FE_FLAGS_SBW_BYTE)
    152       1.55   tsutsui 		sc->proto_dlcr6 |= FE_D6_SBW_BYTE;
    153       1.56   tsutsui 	if (sc->sc_flags & FE_FLAGS_SRAM_150ns)
    154       1.56   tsutsui 		sc->proto_dlcr6 &= ~FE_D6_SRAM_100ns;
    155        1.1   mycroft 
    156        1.1   mycroft 	/*
    157        1.1   mycroft 	 * Minimum initialization of the hardware.
    158        1.1   mycroft 	 * We write into registers; hope I/O ports have no
    159        1.1   mycroft 	 * overlap with other boards.
    160        1.1   mycroft 	 */
    161        1.1   mycroft 
    162        1.1   mycroft 	/* Initialize 86960. */
    163       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR6,
    164       1.21     enami 	    sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
    165        1.1   mycroft 	delay(200);
    166        1.1   mycroft 
    167       1.21     enami #ifdef DIAGNOSTIC
    168       1.21     enami 	if (myea == NULL) {
    169       1.21     enami 		printf("%s: ethernet address shouldn't be NULL\n",
    170       1.21     enami 		    sc->sc_dev.dv_xname);
    171       1.21     enami 		panic("NULL ethernet address");
    172        1.1   mycroft 	}
    173        1.1   mycroft #endif
    174       1.48   thorpej 	memcpy(sc->sc_enaddr, myea, sizeof(sc->sc_enaddr));
    175        1.1   mycroft 
    176        1.1   mycroft 	/* Disable all interrupts. */
    177       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR2, 0);
    178       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR3, 0);
    179        1.1   mycroft }
    180        1.1   mycroft 
    181        1.1   mycroft /*
    182        1.1   mycroft  * Install interface into kernel networking data structures
    183        1.1   mycroft  */
    184        1.1   mycroft void
    185       1.59   tsutsui mb86960_config(struct mb86960_softc *sc, int *media, int nmedia, int defmedia)
    186        1.1   mycroft {
    187       1.64   thorpej 	struct cfdata *cf = device_cfdata(&sc->sc_dev);
    188       1.21     enami 	struct ifnet *ifp = &sc->sc_ec.ec_if;
    189       1.21     enami 	int i;
    190        1.1   mycroft 
    191        1.1   mycroft 	/* Stop the 86960. */
    192       1.21     enami 	mb86960_stop(sc);
    193        1.1   mycroft 
    194        1.1   mycroft 	/* Initialize ifnet structure. */
    195       1.48   thorpej 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
    196       1.12   thorpej 	ifp->if_softc = sc;
    197       1.21     enami 	ifp->if_start = mb86960_start;
    198       1.21     enami 	ifp->if_ioctl = mb86960_ioctl;
    199       1.21     enami 	ifp->if_watchdog = mb86960_watchdog;
    200        1.6   mycroft 	ifp->if_flags =
    201        1.6   mycroft 	    IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
    202       1.44   thorpej 	IFQ_SET_READY(&ifp->if_snd);
    203        1.1   mycroft 
    204        1.1   mycroft #if FE_DEBUG >= 3
    205       1.21     enami 	log(LOG_INFO, "%s: mb86960_config()\n", sc->sc_dev.dv_xname);
    206       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    207        1.1   mycroft #endif
    208        1.1   mycroft 
    209        1.1   mycroft #if FE_SINGLE_TRANSMISSION
    210        1.1   mycroft 	/* Override txb config to allocate minimum. */
    211       1.54   tsutsui 	sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
    212        1.1   mycroft 	sc->proto_dlcr6 |=  FE_D6_TXBSIZ_2x2KB;
    213        1.1   mycroft #endif
    214        1.1   mycroft 
    215        1.1   mycroft 	/* Modify hardware config if it is requested. */
    216        1.1   mycroft 	if ((cf->cf_flags & FE_FLAGS_OVERRIDE_DLCR6) != 0)
    217        1.1   mycroft 		sc->proto_dlcr6 = cf->cf_flags & FE_FLAGS_DLCR6_VALUE;
    218        1.1   mycroft 
    219        1.1   mycroft 	/* Find TX buffer size, based on the hardware dependent proto. */
    220        1.1   mycroft 	switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) {
    221        1.1   mycroft 	case FE_D6_TXBSIZ_2x2KB:
    222        1.1   mycroft 		sc->txb_size = 2048;
    223        1.1   mycroft 		break;
    224        1.1   mycroft 	case FE_D6_TXBSIZ_2x4KB:
    225        1.1   mycroft 		sc->txb_size = 4096;
    226        1.1   mycroft 		break;
    227        1.1   mycroft 	case FE_D6_TXBSIZ_2x8KB:
    228        1.1   mycroft 		sc->txb_size = 8192;
    229        1.1   mycroft 		break;
    230        1.1   mycroft 	default:
    231        1.1   mycroft 		/* Oops, we can't work with single buffer configuration. */
    232        1.1   mycroft #if FE_DEBUG >= 2
    233        1.1   mycroft 		log(LOG_WARNING, "%s: strange TXBSIZ config; fixing\n",
    234        1.1   mycroft 		    sc->sc_dev.dv_xname);
    235        1.1   mycroft #endif
    236        1.1   mycroft 		sc->proto_dlcr6 &= ~FE_D6_TXBSIZ;
    237        1.1   mycroft 		sc->proto_dlcr6 |=  FE_D6_TXBSIZ_2x2KB;
    238        1.1   mycroft 		sc->txb_size = 2048;
    239        1.1   mycroft 		break;
    240        1.1   mycroft 	}
    241        1.1   mycroft 
    242       1.21     enami 	/* Initialize media goo. */
    243       1.21     enami 	ifmedia_init(&sc->sc_media, 0, mb86960_mediachange,
    244       1.21     enami 	    mb86960_mediastatus);
    245       1.21     enami 	if (media != NULL) {
    246       1.21     enami 		for (i = 0; i < nmedia; i++)
    247       1.21     enami 			ifmedia_add(&sc->sc_media, media[i], 0, NULL);
    248       1.21     enami 		ifmedia_set(&sc->sc_media, defmedia);
    249       1.21     enami 	} else {
    250       1.21     enami 		ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
    251       1.21     enami 		ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
    252       1.21     enami 	}
    253       1.21     enami 
    254        1.1   mycroft 	/* Attach the interface. */
    255        1.1   mycroft 	if_attach(ifp);
    256       1.17        is 	ether_ifattach(ifp, sc->sc_enaddr);
    257        1.1   mycroft 
    258       1.21     enami #if NRND > 0
    259       1.21     enami 	rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
    260       1.37     enami 	    RND_TYPE_NET, 0);
    261       1.21     enami #endif
    262        1.1   mycroft 	/* Print additional info when attached. */
    263       1.21     enami 	printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
    264       1.21     enami 	    ether_sprintf(sc->sc_enaddr));
    265       1.21     enami 
    266        1.1   mycroft #if FE_DEBUG >= 3
    267        1.1   mycroft 	{
    268        1.1   mycroft 		int buf, txb, bbw, sbw, ram;
    269        1.1   mycroft 
    270        1.1   mycroft 		buf = txb = bbw = sbw = ram = -1;
    271        1.1   mycroft 		switch (sc->proto_dlcr6 & FE_D6_BUFSIZ) {
    272        1.1   mycroft 		case FE_D6_BUFSIZ_8KB:
    273        1.1   mycroft 			buf = 8;
    274        1.1   mycroft 			break;
    275        1.1   mycroft 		case FE_D6_BUFSIZ_16KB:
    276        1.1   mycroft 			buf = 16;
    277        1.1   mycroft 			break;
    278        1.1   mycroft 		case FE_D6_BUFSIZ_32KB:
    279        1.1   mycroft 			buf = 32;
    280        1.1   mycroft 			break;
    281        1.1   mycroft 		case FE_D6_BUFSIZ_64KB:
    282        1.1   mycroft 			buf = 64;
    283        1.1   mycroft 			break;
    284        1.1   mycroft 		}
    285        1.1   mycroft 		switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) {
    286        1.1   mycroft 		case FE_D6_TXBSIZ_2x2KB:
    287        1.1   mycroft 			txb = 2;
    288        1.1   mycroft 			break;
    289        1.1   mycroft 		case FE_D6_TXBSIZ_2x4KB:
    290        1.1   mycroft 			txb = 4;
    291        1.1   mycroft 			break;
    292        1.1   mycroft 		case FE_D6_TXBSIZ_2x8KB:
    293        1.1   mycroft 			txb = 8;
    294        1.1   mycroft 			break;
    295        1.1   mycroft 		}
    296        1.1   mycroft 		switch (sc->proto_dlcr6 & FE_D6_BBW) {
    297        1.1   mycroft 		case FE_D6_BBW_BYTE:
    298        1.1   mycroft 			bbw = 8;
    299        1.1   mycroft 			break;
    300        1.1   mycroft 		case FE_D6_BBW_WORD:
    301        1.1   mycroft 			bbw = 16;
    302        1.1   mycroft 			break;
    303        1.1   mycroft 		}
    304        1.1   mycroft 		switch (sc->proto_dlcr6 & FE_D6_SBW) {
    305        1.1   mycroft 		case FE_D6_SBW_BYTE:
    306        1.1   mycroft 			sbw = 8;
    307        1.1   mycroft 			break;
    308        1.1   mycroft 		case FE_D6_SBW_WORD:
    309        1.1   mycroft 			sbw = 16;
    310        1.1   mycroft 			break;
    311        1.1   mycroft 		}
    312        1.1   mycroft 		switch (sc->proto_dlcr6 & FE_D6_SRAM) {
    313        1.1   mycroft 		case FE_D6_SRAM_100ns:
    314        1.1   mycroft 			ram = 100;
    315        1.1   mycroft 			break;
    316        1.1   mycroft 		case FE_D6_SRAM_150ns:
    317        1.1   mycroft 			ram = 150;
    318        1.1   mycroft 			break;
    319        1.1   mycroft 		}
    320       1.15  christos 		printf("%s: SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n",
    321        1.1   mycroft 		    sc->sc_dev.dv_xname, buf, bbw, ram, txb, sbw);
    322        1.1   mycroft 	}
    323        1.1   mycroft #endif
    324       1.40     jhawk 
    325       1.40     jhawk 	/* The attach is successful. */
    326       1.54   tsutsui 	sc->sc_stat |= FE_STAT_ATTACHED;
    327       1.21     enami }
    328       1.21     enami 
    329       1.21     enami /*
    330       1.21     enami  * Media change callback.
    331       1.21     enami  */
    332       1.21     enami int
    333       1.59   tsutsui mb86960_mediachange(struct ifnet *ifp)
    334       1.21     enami {
    335       1.21     enami 	struct mb86960_softc *sc = ifp->if_softc;
    336        1.1   mycroft 
    337       1.21     enami 	if (sc->sc_mediachange)
    338       1.21     enami 		return ((*sc->sc_mediachange)(sc));
    339       1.34       abs 	return (0);
    340       1.21     enami }
    341        1.1   mycroft 
    342       1.21     enami /*
    343       1.21     enami  * Media status callback.
    344       1.21     enami  */
    345       1.21     enami void
    346       1.59   tsutsui mb86960_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
    347       1.21     enami {
    348       1.21     enami 	struct mb86960_softc *sc = ifp->if_softc;
    349       1.18  explorer 
    350       1.54   tsutsui 	if ((sc->sc_stat & FE_STAT_ENABLED) == 0) {
    351       1.21     enami 		ifmr->ifm_active = IFM_ETHER | IFM_NONE;
    352       1.21     enami 		ifmr->ifm_status = 0;
    353       1.21     enami 		return;
    354       1.21     enami 	}
    355       1.21     enami 
    356       1.21     enami 	if (sc->sc_mediastatus)
    357       1.21     enami 		(*sc->sc_mediastatus)(sc, ifmr);
    358        1.1   mycroft }
    359        1.1   mycroft 
    360        1.1   mycroft /*
    361        1.1   mycroft  * Reset interface.
    362        1.1   mycroft  */
    363        1.1   mycroft void
    364       1.59   tsutsui mb86960_reset(struct mb86960_softc *sc)
    365        1.1   mycroft {
    366        1.1   mycroft 	int s;
    367        1.1   mycroft 
    368        1.8   mycroft 	s = splnet();
    369       1.21     enami 	mb86960_stop(sc);
    370       1.21     enami 	mb86960_init(sc);
    371        1.1   mycroft 	splx(s);
    372        1.1   mycroft }
    373        1.1   mycroft 
    374        1.1   mycroft /*
    375        1.1   mycroft  * Stop everything on the interface.
    376        1.1   mycroft  *
    377        1.1   mycroft  * All buffered packets, both transmitting and receiving,
    378        1.1   mycroft  * if any, will be lost by stopping the interface.
    379        1.1   mycroft  */
    380        1.1   mycroft void
    381       1.59   tsutsui mb86960_stop(struct mb86960_softc *sc)
    382        1.1   mycroft {
    383       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
    384       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
    385        1.1   mycroft 
    386        1.1   mycroft #if FE_DEBUG >= 3
    387       1.21     enami 	log(LOG_INFO, "%s: top of mb86960_stop()\n", sc->sc_dev.dv_xname);
    388       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    389        1.1   mycroft #endif
    390        1.1   mycroft 
    391        1.1   mycroft 	/* Disable interrupts. */
    392       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR2, 0x00);
    393       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR3, 0x00);
    394        1.1   mycroft 
    395        1.1   mycroft 	/* Stop interface hardware. */
    396        1.1   mycroft 	delay(200);
    397       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR6,
    398       1.21     enami 	    sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
    399        1.1   mycroft 	delay(200);
    400        1.1   mycroft 
    401        1.1   mycroft 	/* Clear all interrupt status. */
    402       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF);
    403       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF);
    404        1.1   mycroft 
    405        1.1   mycroft 	/* Put the chip in stand-by mode. */
    406        1.1   mycroft 	delay(200);
    407       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
    408       1.21     enami 	    sc->proto_dlcr7 | FE_D7_POWER_DOWN);
    409        1.1   mycroft 	delay(200);
    410        1.1   mycroft 
    411        1.1   mycroft 	/* MAR loading can be delayed. */
    412        1.1   mycroft 	sc->filter_change = 0;
    413        1.1   mycroft 
    414        1.1   mycroft 	/* Call a hook. */
    415       1.21     enami 	if (sc->stop_card)
    416       1.21     enami 		(*sc->stop_card)(sc);
    417        1.1   mycroft 
    418       1.45     lukem #if FE_DEBUG >= 3
    419       1.21     enami 	log(LOG_INFO, "%s: end of mb86960_stop()\n", sc->sc_dev.dv_xname);
    420       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    421        1.1   mycroft #endif
    422        1.1   mycroft }
    423        1.1   mycroft 
    424        1.1   mycroft /*
    425        1.1   mycroft  * Device timeout/watchdog routine. Entered if the device neglects to
    426        1.1   mycroft  * generate an interrupt after a transmit has been started on it.
    427        1.1   mycroft  */
    428        1.1   mycroft void
    429       1.59   tsutsui mb86960_watchdog(struct ifnet *ifp)
    430        1.1   mycroft {
    431       1.21     enami 	struct mb86960_softc *sc = ifp->if_softc;
    432        1.1   mycroft 
    433        1.1   mycroft 	log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
    434        1.1   mycroft #if FE_DEBUG >= 3
    435       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    436        1.1   mycroft #endif
    437        1.1   mycroft 
    438        1.1   mycroft 	/* Record how many packets are lost by this accident. */
    439       1.21     enami 	sc->sc_ec.ec_if.if_oerrors += sc->txb_sched + sc->txb_count;
    440        1.1   mycroft 
    441       1.21     enami 	mb86960_reset(sc);
    442        1.1   mycroft }
    443        1.1   mycroft 
    444        1.1   mycroft /*
    445        1.6   mycroft  * Drop (skip) a packet from receive buffer in 86960 memory.
    446        1.6   mycroft  */
    447       1.62     perry static inline void
    448       1.59   tsutsui mb86960_droppacket(struct mb86960_softc *sc)
    449        1.6   mycroft {
    450       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
    451       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
    452        1.6   mycroft 
    453       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR14, FE_B14_FILTER | FE_B14_SKIP);
    454        1.6   mycroft }
    455        1.6   mycroft 
    456        1.6   mycroft /*
    457        1.1   mycroft  * Initialize device.
    458        1.1   mycroft  */
    459        1.1   mycroft void
    460       1.59   tsutsui mb86960_init(struct mb86960_softc *sc)
    461        1.1   mycroft {
    462       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
    463       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
    464       1.21     enami 	struct ifnet *ifp = &sc->sc_ec.ec_if;
    465        1.5   mycroft 	int i;
    466        1.1   mycroft 
    467        1.1   mycroft #if FE_DEBUG >= 3
    468       1.21     enami 	log(LOG_INFO, "%s: top of mb86960_init()\n", sc->sc_dev.dv_xname);
    469       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    470        1.1   mycroft #endif
    471        1.1   mycroft 
    472        1.1   mycroft 	/* Reset transmitter flags. */
    473        1.1   mycroft 	ifp->if_flags &= ~IFF_OACTIVE;
    474        1.1   mycroft 	ifp->if_timer = 0;
    475        1.1   mycroft 
    476        1.1   mycroft 	sc->txb_free = sc->txb_size;
    477        1.1   mycroft 	sc->txb_count = 0;
    478        1.1   mycroft 	sc->txb_sched = 0;
    479        1.1   mycroft 
    480       1.21     enami 	/* Do any card-specific initialization, if applicable. */
    481       1.21     enami 	if (sc->init_card)
    482       1.21     enami 		(*sc->init_card)(sc);
    483        1.1   mycroft 
    484        1.1   mycroft #if FE_DEBUG >= 3
    485        1.1   mycroft 	log(LOG_INFO, "%s: after init hook\n", sc->sc_dev.dv_xname);
    486       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    487        1.1   mycroft #endif
    488        1.1   mycroft 
    489        1.1   mycroft 	/*
    490        1.1   mycroft 	 * Make sure to disable the chip, also.
    491        1.1   mycroft 	 * This may also help re-programming the chip after
    492        1.1   mycroft 	 * hot insertion of PCMCIAs.
    493        1.1   mycroft 	 */
    494       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR6,
    495       1.21     enami 	    sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
    496       1.21     enami 	delay(200);
    497        1.1   mycroft 
    498        1.1   mycroft 	/* Power up the chip and select register bank for DLCRs. */
    499       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
    500        1.1   mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_DLCR | FE_D7_POWER_UP);
    501        1.1   mycroft 	delay(200);
    502        1.1   mycroft 
    503        1.1   mycroft 	/* Feed the station address. */
    504       1.21     enami 	bus_space_write_region_1(bst, bsh, FE_DLCR8,
    505       1.21     enami 	    sc->sc_enaddr, ETHER_ADDR_LEN);
    506        1.1   mycroft 
    507        1.1   mycroft 	/* Select the BMPR bank for runtime register access. */
    508       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
    509        1.1   mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
    510        1.1   mycroft 
    511        1.1   mycroft 	/* Initialize registers. */
    512       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF);	/* Clear all bits. */
    513       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF);	/* ditto. */
    514       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR2, 0x00);
    515       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR3, 0x00);
    516       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR4, sc->proto_dlcr4);
    517       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR5, sc->proto_dlcr5);
    518       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR10, 0x00);
    519       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR11, FE_B11_CTRL_SKIP);
    520       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR12, 0x00);
    521       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR13, sc->proto_bmpr13);
    522       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR14, FE_B14_FILTER);
    523       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR15, 0x00);
    524        1.1   mycroft 
    525        1.1   mycroft #if FE_DEBUG >= 3
    526        1.1   mycroft 	log(LOG_INFO, "%s: just before enabling DLC\n", sc->sc_dev.dv_xname);
    527       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    528        1.1   mycroft #endif
    529        1.1   mycroft 
    530        1.1   mycroft 	/* Enable interrupts. */
    531       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR2, FE_TMASK);
    532       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR3, FE_RMASK);
    533        1.1   mycroft 
    534        1.1   mycroft 	/* Enable transmitter and receiver. */
    535        1.1   mycroft 	delay(200);
    536       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR6,
    537       1.21     enami 	    sc->proto_dlcr6 | FE_D6_DLC_ENABLE);
    538        1.1   mycroft 	delay(200);
    539        1.1   mycroft 
    540        1.1   mycroft #if FE_DEBUG >= 3
    541        1.1   mycroft 	log(LOG_INFO, "%s: just after enabling DLC\n", sc->sc_dev.dv_xname);
    542       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    543        1.1   mycroft #endif
    544        1.1   mycroft 
    545        1.1   mycroft 	/*
    546        1.1   mycroft 	 * Make sure to empty the receive buffer.
    547        1.1   mycroft 	 *
    548        1.1   mycroft 	 * This may be redundant, but *if* the receive buffer were full
    549        1.1   mycroft 	 * at this point, the driver would hang.  I have experienced
    550        1.1   mycroft 	 * some strange hangups just after UP.  I hope the following
    551        1.1   mycroft 	 * code solve the problem.
    552        1.1   mycroft 	 *
    553        1.1   mycroft 	 * I have changed the order of hardware initialization.
    554        1.1   mycroft 	 * I think the receive buffer cannot have any packets at this
    555        1.1   mycroft 	 * point in this version.  The following code *must* be
    556        1.1   mycroft 	 * redundant now.  FIXME.
    557        1.1   mycroft 	 */
    558        1.1   mycroft 	for (i = 0; i < FE_MAX_RECV_COUNT; i++) {
    559       1.21     enami 		if (bus_space_read_1(bst, bsh, FE_DLCR5) & FE_D5_BUFEMP)
    560        1.1   mycroft 			break;
    561       1.21     enami 		mb86960_droppacket(sc);
    562        1.1   mycroft 	}
    563        1.1   mycroft #if FE_DEBUG >= 1
    564       1.21     enami 	if (i >= FE_MAX_RECV_COUNT)
    565        1.1   mycroft 		log(LOG_ERR, "%s: cannot empty receive buffer\n",
    566        1.1   mycroft 		    sc->sc_dev.dv_xname);
    567        1.1   mycroft #endif
    568        1.1   mycroft #if FE_DEBUG >= 3
    569       1.21     enami 	if (i < FE_MAX_RECV_COUNT)
    570        1.1   mycroft 		log(LOG_INFO, "%s: receive buffer emptied (%d)\n",
    571        1.1   mycroft 		    sc->sc_dev.dv_xname, i);
    572        1.1   mycroft #endif
    573        1.1   mycroft 
    574        1.1   mycroft #if FE_DEBUG >= 3
    575        1.1   mycroft 	log(LOG_INFO, "%s: after ERB loop\n", sc->sc_dev.dv_xname);
    576       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    577        1.1   mycroft #endif
    578        1.1   mycroft 
    579        1.1   mycroft 	/* Do we need this here? */
    580       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF);	/* Clear all bits. */
    581       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF);	/* ditto. */
    582        1.1   mycroft 
    583        1.1   mycroft #if FE_DEBUG >= 3
    584        1.1   mycroft 	log(LOG_INFO, "%s: after FIXME\n", sc->sc_dev.dv_xname);
    585       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    586        1.1   mycroft #endif
    587        1.1   mycroft 
    588        1.1   mycroft 	/* Set 'running' flag. */
    589        1.1   mycroft 	ifp->if_flags |= IFF_RUNNING;
    590        1.1   mycroft 
    591        1.1   mycroft 	/*
    592        1.1   mycroft 	 * At this point, the interface is runnung properly,
    593        1.1   mycroft 	 * except that it receives *no* packets.  we then call
    594       1.21     enami 	 * mb86960_setmode() to tell the chip what packets to be
    595        1.1   mycroft 	 * received, based on the if_flags and multicast group
    596        1.1   mycroft 	 * list.  It completes the initialization process.
    597        1.1   mycroft 	 */
    598       1.21     enami 	mb86960_setmode(sc);
    599        1.1   mycroft 
    600        1.1   mycroft #if FE_DEBUG >= 3
    601        1.1   mycroft 	log(LOG_INFO, "%s: after setmode\n", sc->sc_dev.dv_xname);
    602       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    603        1.1   mycroft #endif
    604        1.1   mycroft 
    605        1.1   mycroft 	/* ...and attempt to start output. */
    606       1.21     enami 	mb86960_start(ifp);
    607        1.1   mycroft 
    608        1.1   mycroft #if FE_DEBUG >= 3
    609       1.21     enami 	log(LOG_INFO, "%s: end of mb86960_init()\n", sc->sc_dev.dv_xname);
    610       1.21     enami 	mb86960_dump(LOG_INFO, sc);
    611        1.1   mycroft #endif
    612        1.1   mycroft }
    613        1.1   mycroft 
    614        1.1   mycroft /*
    615        1.1   mycroft  * This routine actually starts the transmission on the interface
    616        1.1   mycroft  */
    617       1.62     perry static inline void
    618       1.59   tsutsui mb86960_xmit(struct mb86960_softc *sc)
    619        1.1   mycroft {
    620       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
    621       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
    622        1.1   mycroft 
    623        1.1   mycroft 	/*
    624        1.1   mycroft 	 * Set a timer just in case we never hear from the board again.
    625        1.1   mycroft 	 * We use longer timeout for multiple packet transmission.
    626        1.1   mycroft 	 * I'm not sure this timer value is appropriate.  FIXME.
    627        1.1   mycroft 	 */
    628       1.21     enami 	sc->sc_ec.ec_if.if_timer = 1 + sc->txb_count;
    629        1.1   mycroft 
    630        1.1   mycroft 	/* Update txb variables. */
    631        1.1   mycroft 	sc->txb_sched = sc->txb_count;
    632        1.1   mycroft 	sc->txb_count = 0;
    633        1.1   mycroft 	sc->txb_free = sc->txb_size;
    634        1.1   mycroft 
    635        1.1   mycroft #if FE_DELAYED_PADDING
    636        1.1   mycroft 	/* Omit the postponed padding process. */
    637        1.1   mycroft 	sc->txb_padding = 0;
    638        1.1   mycroft #endif
    639        1.1   mycroft 
    640        1.1   mycroft 	/* Start transmitter, passing packets in TX buffer. */
    641       1.21     enami 	bus_space_write_1(bst, bsh, FE_BMPR10, sc->txb_sched | FE_B10_START);
    642        1.1   mycroft }
    643        1.1   mycroft 
    644        1.1   mycroft /*
    645        1.1   mycroft  * Start output on interface.
    646        1.1   mycroft  * We make two assumptions here:
    647        1.8   mycroft  *  1) that the current priority is set to splnet _before_ this code
    648        1.1   mycroft  *     is called *and* is returned to the appropriate priority after
    649        1.1   mycroft  *     return
    650        1.1   mycroft  *  2) that the IFF_OACTIVE flag is checked before this code is called
    651        1.1   mycroft  *     (i.e. that the output part of the interface is idle)
    652        1.1   mycroft  */
    653        1.1   mycroft void
    654       1.59   tsutsui mb86960_start(struct ifnet *ifp)
    655        1.1   mycroft {
    656       1.21     enami 	struct mb86960_softc *sc = ifp->if_softc;
    657        1.1   mycroft 	struct mbuf *m;
    658        1.1   mycroft 
    659        1.1   mycroft #if FE_DEBUG >= 1
    660        1.1   mycroft 	/* Just a sanity check. */
    661        1.1   mycroft 	if ((sc->txb_count == 0) != (sc->txb_free == sc->txb_size)) {
    662        1.1   mycroft 		/*
    663        1.1   mycroft 		 * Txb_count and txb_free co-works to manage the
    664        1.1   mycroft 		 * transmission buffer.  Txb_count keeps track of the
    665        1.1   mycroft 		 * used potion of the buffer, while txb_free does unused
    666        1.1   mycroft 		 * potion.  So, as long as the driver runs properly,
    667        1.1   mycroft 		 * txb_count is zero if and only if txb_free is same
    668        1.1   mycroft 		 * as txb_size (which represents whole buffer.)
    669        1.1   mycroft 		 */
    670        1.1   mycroft 		log(LOG_ERR, "%s: inconsistent txb variables (%d, %d)\n",
    671        1.1   mycroft 		    sc->sc_dev.dv_xname, sc->txb_count, sc->txb_free);
    672        1.1   mycroft 		/*
    673        1.1   mycroft 		 * So, what should I do, then?
    674        1.1   mycroft 		 *
    675        1.1   mycroft 		 * We now know txb_count and txb_free contradicts.  We
    676        1.1   mycroft 		 * cannot, however, tell which is wrong.  More
    677        1.1   mycroft 		 * over, we cannot peek 86960 transmission buffer or
    678        1.1   mycroft 		 * reset the transmission buffer.  (In fact, we can
    679        1.1   mycroft 		 * reset the entire interface.  I don't want to do it.)
    680        1.1   mycroft 		 *
    681        1.1   mycroft 		 * If txb_count is incorrect, leaving it as is will cause
    682        1.1   mycroft 		 * sending of gabages after next interrupt.  We have to
    683        1.1   mycroft 		 * avoid it.  Hence, we reset the txb_count here.  If
    684        1.1   mycroft 		 * txb_free was incorrect, resetting txb_count just loose
    685        1.1   mycroft 		 * some packets.  We can live with it.
    686        1.1   mycroft 		 */
    687        1.1   mycroft 		sc->txb_count = 0;
    688        1.1   mycroft 	}
    689        1.1   mycroft #endif
    690        1.1   mycroft 
    691        1.1   mycroft #if FE_DEBUG >= 1
    692        1.1   mycroft 	/*
    693        1.1   mycroft 	 * First, see if there are buffered packets and an idle
    694        1.1   mycroft 	 * transmitter - should never happen at this point.
    695        1.1   mycroft 	 */
    696        1.1   mycroft 	if ((sc->txb_count > 0) && (sc->txb_sched == 0)) {
    697        1.1   mycroft 		log(LOG_ERR, "%s: transmitter idle with %d buffered packets\n",
    698        1.1   mycroft 		    sc->sc_dev.dv_xname, sc->txb_count);
    699       1.21     enami 		mb86960_xmit(sc);
    700        1.1   mycroft 	}
    701        1.1   mycroft #endif
    702        1.1   mycroft 
    703        1.1   mycroft 	/*
    704        1.1   mycroft 	 * Stop accepting more transmission packets temporarily, when
    705        1.1   mycroft 	 * a filter change request is delayed.  Updating the MARs on
    706        1.1   mycroft 	 * 86960 flushes the transmisstion buffer, so it is delayed
    707        1.1   mycroft 	 * until all buffered transmission packets have been sent
    708        1.1   mycroft 	 * out.
    709        1.1   mycroft 	 */
    710        1.1   mycroft 	if (sc->filter_change) {
    711        1.1   mycroft 		/*
    712       1.57       wiz 		 * Filter change request is delayed only when the DLC is
    713        1.1   mycroft 		 * working.  DLC soon raise an interrupt after finishing
    714        1.1   mycroft 		 * the work.
    715        1.1   mycroft 		 */
    716        1.1   mycroft 		goto indicate_active;
    717        1.1   mycroft 	}
    718        1.1   mycroft 
    719        1.1   mycroft 	for (;;) {
    720        1.1   mycroft 		/*
    721        1.1   mycroft 		 * See if there is room to put another packet in the buffer.
    722        1.1   mycroft 		 * We *could* do better job by peeking the send queue to
    723        1.1   mycroft 		 * know the length of the next packet.  Current version just
    724        1.1   mycroft 		 * tests against the worst case (i.e., longest packet).  FIXME.
    725       1.60     perry 		 *
    726        1.1   mycroft 		 * When adding the packet-peek feature, don't forget adding a
    727        1.1   mycroft 		 * test on txb_count against QUEUEING_MAX.
    728        1.1   mycroft 		 * There is a little chance the packet count exceeds
    729        1.1   mycroft 		 * the limit.  Assume transmission buffer is 8KB (2x8KB
    730        1.1   mycroft 		 * configuration) and an application sends a bunch of small
    731        1.1   mycroft 		 * (i.e., minimum packet sized) packets rapidly.  An 8KB
    732        1.1   mycroft 		 * buffer can hold 130 blocks of 62 bytes long...
    733        1.1   mycroft 		 */
    734       1.32   thorpej 		if (sc->txb_free <
    735       1.54   tsutsui 		    (ETHER_MAX_LEN - ETHER_CRC_LEN) + FE_TXLEN_SIZE) {
    736        1.1   mycroft 			/* No room. */
    737        1.1   mycroft 			goto indicate_active;
    738        1.1   mycroft 		}
    739        1.1   mycroft 
    740        1.1   mycroft #if FE_SINGLE_TRANSMISSION
    741        1.1   mycroft 		if (sc->txb_count > 0) {
    742        1.1   mycroft 			/* Just one packet per a transmission buffer. */
    743        1.1   mycroft 			goto indicate_active;
    744        1.1   mycroft 		}
    745        1.1   mycroft #endif
    746        1.1   mycroft 
    747        1.1   mycroft 		/*
    748        1.1   mycroft 		 * Get the next mbuf chain for a packet to send.
    749        1.1   mycroft 		 */
    750       1.44   thorpej 		IFQ_DEQUEUE(&ifp->if_snd, m);
    751        1.1   mycroft 		if (m == 0) {
    752        1.1   mycroft 			/* No more packets to send. */
    753        1.1   mycroft 			goto indicate_inactive;
    754        1.1   mycroft 		}
    755        1.1   mycroft 
    756        1.6   mycroft #if NBPFILTER > 0
    757        1.6   mycroft 		/* Tap off here if there is a BPF listener. */
    758        1.6   mycroft 		if (ifp->if_bpf)
    759        1.6   mycroft 			bpf_mtap(ifp->if_bpf, m);
    760        1.6   mycroft #endif
    761        1.6   mycroft 
    762        1.1   mycroft 		/*
    763        1.1   mycroft 		 * Copy the mbuf chain into the transmission buffer.
    764        1.1   mycroft 		 * txb_* variables are updated as necessary.
    765        1.1   mycroft 		 */
    766       1.21     enami 		mb86960_write_mbufs(sc, m);
    767        1.1   mycroft 
    768        1.6   mycroft 		m_freem(m);
    769        1.6   mycroft 
    770        1.1   mycroft 		/* Start transmitter if it's idle. */
    771        1.1   mycroft 		if (sc->txb_sched == 0)
    772       1.21     enami 			mb86960_xmit(sc);
    773        1.1   mycroft 	}
    774        1.1   mycroft 
    775        1.1   mycroft indicate_inactive:
    776        1.1   mycroft 	/*
    777        1.1   mycroft 	 * We are using the !OACTIVE flag to indicate to
    778        1.1   mycroft 	 * the outside world that we can accept an
    779        1.1   mycroft 	 * additional packet rather than that the
    780        1.1   mycroft 	 * transmitter is _actually_ active.  Indeed, the
    781        1.1   mycroft 	 * transmitter may be active, but if we haven't
    782        1.1   mycroft 	 * filled all the buffers with data then we still
    783        1.1   mycroft 	 * want to accept more.
    784        1.1   mycroft 	 */
    785        1.1   mycroft 	ifp->if_flags &= ~IFF_OACTIVE;
    786        1.1   mycroft 	return;
    787        1.1   mycroft 
    788        1.1   mycroft indicate_active:
    789        1.1   mycroft 	/*
    790        1.1   mycroft 	 * The transmitter is active, and there are no room for
    791        1.1   mycroft 	 * more outgoing packets in the transmission buffer.
    792        1.1   mycroft 	 */
    793        1.1   mycroft 	ifp->if_flags |= IFF_OACTIVE;
    794        1.1   mycroft 	return;
    795        1.1   mycroft }
    796        1.1   mycroft 
    797        1.1   mycroft /*
    798        1.1   mycroft  * Transmission interrupt handler
    799        1.1   mycroft  * The control flow of this function looks silly.  FIXME.
    800        1.1   mycroft  */
    801        1.1   mycroft void
    802       1.59   tsutsui mb86960_tint(struct mb86960_softc *sc, uint8_t tstat)
    803        1.1   mycroft {
    804       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
    805       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
    806       1.21     enami 	struct ifnet *ifp = &sc->sc_ec.ec_if;
    807        1.1   mycroft 	int left;
    808        1.1   mycroft 	int col;
    809        1.1   mycroft 
    810        1.1   mycroft 	/*
    811        1.1   mycroft 	 * Handle "excessive collision" interrupt.
    812        1.1   mycroft 	 */
    813        1.1   mycroft 	if (tstat & FE_D0_COLL16) {
    814        1.1   mycroft 		/*
    815        1.1   mycroft 		 * Find how many packets (including this collided one)
    816        1.1   mycroft 		 * are left unsent in transmission buffer.
    817        1.1   mycroft 		 */
    818       1.21     enami 		left = bus_space_read_1(bst, bsh, FE_BMPR10);
    819        1.1   mycroft 
    820        1.1   mycroft #if FE_DEBUG >= 2
    821        1.1   mycroft 		log(LOG_WARNING, "%s: excessive collision (%d/%d)\n",
    822        1.1   mycroft 		    sc->sc_dev.dv_xname, left, sc->txb_sched);
    823        1.1   mycroft #endif
    824        1.1   mycroft #if FE_DEBUG >= 3
    825       1.21     enami 		mb86960_dump(LOG_INFO, sc);
    826        1.1   mycroft #endif
    827        1.1   mycroft 
    828        1.1   mycroft 		/*
    829        1.1   mycroft 		 * Update statistics.
    830        1.1   mycroft 		 */
    831        1.1   mycroft 		ifp->if_collisions += 16;
    832        1.1   mycroft 		ifp->if_oerrors++;
    833        1.1   mycroft 		ifp->if_opackets += sc->txb_sched - left;
    834        1.1   mycroft 
    835        1.1   mycroft 		/*
    836        1.1   mycroft 		 * Collision statistics has been updated.
    837        1.1   mycroft 		 * Clear the collision flag on 86960 now to avoid confusion.
    838        1.1   mycroft 		 */
    839       1.21     enami 		bus_space_write_1(bst, bsh, FE_DLCR0, FE_D0_COLLID);
    840        1.1   mycroft 
    841        1.1   mycroft 		/*
    842        1.1   mycroft 		 * Restart transmitter, skipping the
    843        1.1   mycroft 		 * collided packet.
    844        1.1   mycroft 		 *
    845        1.1   mycroft 		 * We *must* skip the packet to keep network running
    846        1.1   mycroft 		 * properly.  Excessive collision error is an
    847        1.1   mycroft 		 * indication of the network overload.  If we
    848        1.1   mycroft 		 * tried sending the same packet after excessive
    849        1.1   mycroft 		 * collision, the network would be filled with
    850        1.1   mycroft 		 * out-of-time packets.  Packets belonging
    851        1.1   mycroft 		 * to reliable transport (such as TCP) are resent
    852        1.1   mycroft 		 * by some upper layer.
    853        1.1   mycroft 		 */
    854       1.21     enami 		bus_space_write_1(bst, bsh, FE_BMPR11,
    855        1.1   mycroft 		    FE_B11_CTRL_SKIP | FE_B11_MODE1);
    856        1.1   mycroft 		sc->txb_sched = left - 1;
    857        1.1   mycroft 	}
    858        1.1   mycroft 
    859        1.1   mycroft 	/*
    860        1.1   mycroft 	 * Handle "transmission complete" interrupt.
    861        1.1   mycroft 	 */
    862        1.1   mycroft 	if (tstat & FE_D0_TXDONE) {
    863        1.1   mycroft 		/*
    864        1.1   mycroft 		 * Add in total number of collisions on last
    865        1.1   mycroft 		 * transmission.  We also clear "collision occurred" flag
    866        1.1   mycroft 		 * here.
    867        1.1   mycroft 		 *
    868        1.1   mycroft 		 * 86960 has a design flow on collision count on multiple
    869        1.1   mycroft 		 * packet transmission.  When we send two or more packets
    870        1.1   mycroft 		 * with one start command (that's what we do when the
    871        1.1   mycroft 		 * transmission queue is clauded), 86960 informs us number
    872       1.49       wiz 		 * of collisions occurred on the last packet on the
    873        1.1   mycroft 		 * transmission only.  Number of collisions on previous
    874        1.1   mycroft 		 * packets are lost.  I have told that the fact is clearly
    875        1.1   mycroft 		 * stated in the Fujitsu document.
    876        1.1   mycroft 		 *
    877        1.1   mycroft 		 * I considered not to mind it seriously.  Collision
    878        1.1   mycroft 		 * count is not so important, anyway.  Any comments?  FIXME.
    879        1.1   mycroft 		 */
    880        1.1   mycroft 
    881       1.21     enami 		if (bus_space_read_1(bst, bsh, FE_DLCR0) & FE_D0_COLLID) {
    882        1.1   mycroft 			/* Clear collision flag. */
    883       1.21     enami 			bus_space_write_1(bst, bsh, FE_DLCR0, FE_D0_COLLID);
    884        1.1   mycroft 
    885        1.1   mycroft 			/* Extract collision count from 86960. */
    886       1.21     enami 			col = bus_space_read_1(bst, bsh, FE_DLCR4) & FE_D4_COL;
    887        1.1   mycroft 			if (col == 0) {
    888        1.1   mycroft 				/*
    889        1.1   mycroft 				 * Status register indicates collisions,
    890        1.1   mycroft 				 * while the collision count is zero.
    891        1.1   mycroft 				 * This can happen after multiple packet
    892        1.1   mycroft 				 * transmission, indicating that one or more
    893        1.1   mycroft 				 * previous packet(s) had been collided.
    894        1.1   mycroft 				 *
    895        1.1   mycroft 				 * Since the accurate number of collisions
    896        1.1   mycroft 				 * has been lost, we just guess it as 1;
    897        1.1   mycroft 				 * Am I too optimistic?  FIXME.
    898        1.1   mycroft 				 */
    899        1.1   mycroft 				col = 1;
    900        1.1   mycroft 			} else
    901        1.1   mycroft 				col >>= FE_D4_COL_SHIFT;
    902        1.1   mycroft 			ifp->if_collisions += col;
    903        1.1   mycroft #if FE_DEBUG >= 4
    904        1.1   mycroft 			log(LOG_WARNING, "%s: %d collision%s (%d)\n",
    905        1.1   mycroft 			    sc->sc_dev.dv_xname, col, col == 1 ? "" : "s",
    906        1.1   mycroft 			    sc->txb_sched);
    907        1.1   mycroft #endif
    908        1.1   mycroft 		}
    909        1.1   mycroft 
    910        1.1   mycroft 		/*
    911        1.1   mycroft 		 * Update total number of successfully
    912        1.1   mycroft 		 * transmitted packets.
    913        1.1   mycroft 		 */
    914        1.1   mycroft 		ifp->if_opackets += sc->txb_sched;
    915        1.1   mycroft 		sc->txb_sched = 0;
    916       1.10   mycroft 	}
    917        1.1   mycroft 
    918       1.10   mycroft 	if (sc->txb_sched == 0) {
    919        1.1   mycroft 		/*
    920        1.1   mycroft 		 * The transmitter is no more active.
    921       1.60     perry 		 * Reset output active flag and watchdog timer.
    922        1.1   mycroft 		 */
    923        1.1   mycroft 		ifp->if_flags &= ~IFF_OACTIVE;
    924        1.1   mycroft 		ifp->if_timer = 0;
    925        1.1   mycroft 
    926        1.1   mycroft 		/*
    927        1.1   mycroft 		 * If more data is ready to transmit in the buffer, start
    928        1.1   mycroft 		 * transmitting them.  Otherwise keep transmitter idle,
    929        1.1   mycroft 		 * even if more data is queued.  This gives receive
    930        1.1   mycroft 		 * process a slight priority.
    931        1.1   mycroft 		 */
    932        1.1   mycroft 		if (sc->txb_count > 0)
    933       1.21     enami 			mb86960_xmit(sc);
    934        1.1   mycroft 	}
    935        1.1   mycroft }
    936        1.1   mycroft 
    937        1.1   mycroft /*
    938        1.1   mycroft  * Ethernet interface receiver interrupt.
    939        1.1   mycroft  */
    940        1.1   mycroft void
    941       1.59   tsutsui mb86960_rint(struct mb86960_softc *sc, uint8_t rstat)
    942        1.1   mycroft {
    943       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
    944       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
    945       1.21     enami 	struct ifnet *ifp = &sc->sc_ec.ec_if;
    946       1.54   tsutsui 	u_int status, len;
    947        1.1   mycroft 	int i;
    948        1.1   mycroft 
    949        1.1   mycroft 	/*
    950        1.1   mycroft 	 * Update statistics if this interrupt is caused by an error.
    951        1.1   mycroft 	 */
    952       1.21     enami 	if (rstat & (FE_D1_OVRFLO | FE_D1_CRCERR | FE_D1_ALGERR |
    953       1.21     enami 	    FE_D1_SRTPKT)) {
    954        1.1   mycroft #if FE_DEBUG >= 3
    955       1.41        tv 		char sbuf[sizeof(FE_D1_ERRBITS) + 64];
    956       1.41        tv 
    957       1.41        tv 		bitmask_snprintf(rstat, FE_D1_ERRBITS, sbuf, sizeof(sbuf));
    958       1.41        tv 		log(LOG_WARNING, "%s: receive error: %s\n",
    959       1.41        tv 		    sc->sc_dev.dv_xname, sbuf);
    960        1.1   mycroft #endif
    961        1.1   mycroft 		ifp->if_ierrors++;
    962        1.1   mycroft 	}
    963        1.1   mycroft 
    964        1.1   mycroft 	/*
    965        1.1   mycroft 	 * MB86960 has a flag indicating "receive queue empty."
    966       1.54   tsutsui 	 * We just loop checking the flag to pull out all received
    967        1.1   mycroft 	 * packets.
    968        1.1   mycroft 	 *
    969        1.1   mycroft 	 * We limit the number of iterrations to avoid infinite loop.
    970        1.1   mycroft 	 * It can be caused by a very slow CPU (some broken
    971        1.1   mycroft 	 * peripheral may insert incredible number of wait cycles)
    972        1.1   mycroft 	 * or, worse, by a broken MB86960 chip.
    973        1.1   mycroft 	 */
    974        1.1   mycroft 	for (i = 0; i < FE_MAX_RECV_COUNT; i++) {
    975        1.1   mycroft 		/* Stop the iterration if 86960 indicates no packets. */
    976       1.21     enami 		if (bus_space_read_1(bst, bsh, FE_DLCR5) & FE_D5_BUFEMP)
    977        1.1   mycroft 			break;
    978        1.1   mycroft 
    979        1.1   mycroft 		/*
    980       1.54   tsutsui 		 * Extract receive packet status from the receive
    981       1.54   tsutsui 		 * packet header.
    982        1.1   mycroft 		 */
    983       1.54   tsutsui 		if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
    984       1.54   tsutsui 			status = bus_space_read_1(bst, bsh, FE_BMPR8);
    985       1.54   tsutsui 			(void)bus_space_read_1(bst, bsh, FE_BMPR8);
    986       1.54   tsutsui 		} else
    987       1.54   tsutsui 			status = bus_space_read_2(bst, bsh, FE_BMPR8);
    988       1.54   tsutsui 
    989        1.1   mycroft #if FE_DEBUG >= 4
    990        1.1   mycroft 		log(LOG_INFO, "%s: receive status = %02x\n",
    991        1.1   mycroft 		    sc->sc_dev.dv_xname, status);
    992        1.1   mycroft #endif
    993        1.1   mycroft 
    994        1.1   mycroft 		/*
    995        1.1   mycroft 		 * If there was an error, update statistics and drop
    996        1.1   mycroft 		 * the packet, unless the interface is in promiscuous
    997        1.1   mycroft 		 * mode.
    998        1.1   mycroft 		 */
    999       1.54   tsutsui 		if ((status & FE_RXSTAT_GOODPKT) == 0) {
   1000        1.1   mycroft 			if ((ifp->if_flags & IFF_PROMISC) == 0) {
   1001        1.1   mycroft 				ifp->if_ierrors++;
   1002       1.21     enami 				mb86960_droppacket(sc);
   1003        1.1   mycroft 				continue;
   1004        1.1   mycroft 			}
   1005        1.1   mycroft 		}
   1006        1.1   mycroft 
   1007        1.1   mycroft 		/*
   1008       1.54   tsutsui 		 * Extract the packet length from the receive packet header.
   1009        1.1   mycroft 		 * It is a sum of a header (14 bytes) and a payload.
   1010        1.1   mycroft 		 * CRC has been stripped off by the 86960.
   1011        1.1   mycroft 		 */
   1012       1.54   tsutsui 		if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
   1013       1.54   tsutsui 			len  = bus_space_read_1(bst, bsh, FE_BMPR8);
   1014       1.54   tsutsui 			len |= bus_space_read_1(bst, bsh, FE_BMPR8) << 8;
   1015       1.54   tsutsui 		} else
   1016       1.54   tsutsui 			len = bus_space_read_2(bst, bsh, FE_BMPR8);
   1017        1.1   mycroft 
   1018        1.1   mycroft 		/*
   1019        1.1   mycroft 		 * MB86965 checks the packet length and drop big packet
   1020        1.1   mycroft 		 * before passing it to us.  There are no chance we can
   1021        1.1   mycroft 		 * get [crufty] packets.  Hence, if the length exceeds
   1022        1.1   mycroft 		 * the specified limit, it means some serious failure,
   1023        1.1   mycroft 		 * such as out-of-sync on receive buffer management.
   1024        1.1   mycroft 		 *
   1025        1.1   mycroft 		 * Is this statement true?  FIXME.
   1026        1.1   mycroft 		 */
   1027       1.32   thorpej 		if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN) ||
   1028       1.32   thorpej 		    len < ETHER_HDR_LEN) {
   1029        1.1   mycroft #if FE_DEBUG >= 2
   1030        1.1   mycroft 			log(LOG_WARNING,
   1031        1.1   mycroft 			    "%s: received a %s packet? (%u bytes)\n",
   1032        1.1   mycroft 			    sc->sc_dev.dv_xname,
   1033       1.32   thorpej 			    len < ETHER_HDR_LEN ? "partial" : "big", len);
   1034        1.1   mycroft #endif
   1035        1.1   mycroft 			ifp->if_ierrors++;
   1036       1.21     enami 			mb86960_droppacket(sc);
   1037        1.1   mycroft 			continue;
   1038        1.1   mycroft 		}
   1039        1.1   mycroft 
   1040        1.1   mycroft 		/*
   1041        1.1   mycroft 		 * Check for a short (RUNT) packet.  We *do* check
   1042        1.1   mycroft 		 * but do nothing other than print a message.
   1043        1.1   mycroft 		 * Short packets are illegal, but does nothing bad
   1044        1.1   mycroft 		 * if it carries data for upper layer.
   1045        1.1   mycroft 		 */
   1046        1.1   mycroft #if FE_DEBUG >= 2
   1047       1.32   thorpej 		if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN)) {
   1048        1.1   mycroft 			log(LOG_WARNING,
   1049       1.21     enami 			    "%s: received a short packet? (%u bytes)\n",
   1050       1.21     enami 			    sc->sc_dev.dv_xname, len);
   1051        1.1   mycroft 		}
   1052       1.60     perry #endif
   1053        1.1   mycroft 
   1054        1.1   mycroft 		/*
   1055        1.1   mycroft 		 * Go get a packet.
   1056        1.1   mycroft 		 */
   1057       1.54   tsutsui 		if (mb86960_get_packet(sc, len) == 0) {
   1058        1.1   mycroft 			/* Skip a packet, updating statistics. */
   1059        1.1   mycroft #if FE_DEBUG >= 2
   1060        1.1   mycroft 			log(LOG_WARNING,
   1061        1.1   mycroft 			    "%s: out of mbufs; dropping packet (%u bytes)\n",
   1062        1.1   mycroft 			    sc->sc_dev.dv_xname, len);
   1063        1.1   mycroft #endif
   1064        1.1   mycroft 			ifp->if_ierrors++;
   1065       1.21     enami 			mb86960_droppacket(sc);
   1066        1.1   mycroft 
   1067        1.1   mycroft 			/*
   1068        1.1   mycroft 			 * We stop receiving packets, even if there are
   1069        1.1   mycroft 			 * more in the buffer.  We hope we can get more
   1070        1.1   mycroft 			 * mbufs next time.
   1071        1.1   mycroft 			 */
   1072        1.1   mycroft 			return;
   1073        1.1   mycroft 		}
   1074        1.1   mycroft 
   1075        1.1   mycroft 		/* Successfully received a packet.  Update stat. */
   1076        1.1   mycroft 		ifp->if_ipackets++;
   1077        1.1   mycroft 	}
   1078        1.1   mycroft }
   1079        1.1   mycroft 
   1080        1.1   mycroft /*
   1081        1.1   mycroft  * Ethernet interface interrupt processor
   1082        1.1   mycroft  */
   1083        1.1   mycroft int
   1084       1.59   tsutsui mb86960_intr(void *arg)
   1085        1.1   mycroft {
   1086       1.21     enami 	struct mb86960_softc *sc = arg;
   1087       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
   1088       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
   1089       1.21     enami 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   1090       1.59   tsutsui 	uint8_t tstat, rstat;
   1091        1.1   mycroft 
   1092       1.54   tsutsui 	if ((sc->sc_stat & FE_STAT_ENABLED) == 0 ||
   1093       1.63   thorpej 	    !device_is_active(&sc->sc_dev))
   1094       1.21     enami 		return (0);
   1095       1.21     enami 
   1096        1.1   mycroft #if FE_DEBUG >= 4
   1097       1.21     enami 	log(LOG_INFO, "%s: mb86960_intr()\n", sc->sc_dev.dv_xname);
   1098       1.21     enami 	mb86960_dump(LOG_INFO, sc);
   1099        1.1   mycroft #endif
   1100        1.1   mycroft 
   1101        1.1   mycroft 	/*
   1102        1.1   mycroft 	 * Get interrupt conditions, masking unneeded flags.
   1103        1.1   mycroft 	 */
   1104       1.21     enami 	tstat = bus_space_read_1(bst, bsh, FE_DLCR0) & FE_TMASK;
   1105       1.21     enami 	rstat = bus_space_read_1(bst, bsh, FE_DLCR1) & FE_RMASK;
   1106        1.1   mycroft 	if (tstat == 0 && rstat == 0)
   1107        1.1   mycroft 		return (0);
   1108        1.1   mycroft 
   1109        1.1   mycroft 	/*
   1110        1.1   mycroft 	 * Loop until there are no more new interrupt conditions.
   1111        1.1   mycroft 	 */
   1112        1.1   mycroft 	for (;;) {
   1113        1.1   mycroft 		/*
   1114        1.1   mycroft 		 * Reset the conditions we are acknowledging.
   1115        1.1   mycroft 		 */
   1116       1.21     enami 		bus_space_write_1(bst, bsh, FE_DLCR0, tstat);
   1117       1.21     enami 		bus_space_write_1(bst, bsh, FE_DLCR1, rstat);
   1118        1.1   mycroft 
   1119        1.1   mycroft 		/*
   1120        1.1   mycroft 		 * Handle transmitter interrupts. Handle these first because
   1121        1.1   mycroft 		 * the receiver will reset the board under some conditions.
   1122        1.1   mycroft 		 */
   1123        1.1   mycroft 		if (tstat != 0)
   1124       1.21     enami 			mb86960_tint(sc, tstat);
   1125        1.1   mycroft 
   1126        1.1   mycroft 		/*
   1127        1.1   mycroft 		 * Handle receiver interrupts.
   1128        1.1   mycroft 		 */
   1129        1.1   mycroft 		if (rstat != 0)
   1130       1.21     enami 			mb86960_rint(sc, rstat);
   1131        1.1   mycroft 
   1132        1.1   mycroft 		/*
   1133        1.1   mycroft 		 * Update the multicast address filter if it is
   1134        1.1   mycroft 		 * needed and possible.  We do it now, because
   1135        1.1   mycroft 		 * we can make sure the transmission buffer is empty,
   1136        1.1   mycroft 		 * and there is a good chance that the receive queue
   1137        1.1   mycroft 		 * is empty.  It will minimize the possibility of
   1138        1.1   mycroft 		 * packet lossage.
   1139        1.1   mycroft 		 */
   1140        1.1   mycroft 		if (sc->filter_change &&
   1141        1.1   mycroft 		    sc->txb_count == 0 && sc->txb_sched == 0) {
   1142       1.21     enami 			mb86960_loadmar(sc);
   1143       1.21     enami 			ifp->if_flags &= ~IFF_OACTIVE;
   1144        1.1   mycroft 		}
   1145        1.1   mycroft 
   1146        1.1   mycroft 		/*
   1147        1.1   mycroft 		 * If it looks like the transmitter can take more data,
   1148        1.1   mycroft 		 * attempt to start output on the interface. This is done
   1149        1.1   mycroft 		 * after handling the receiver interrupt to give the
   1150        1.1   mycroft 		 * receive operation priority.
   1151        1.1   mycroft 		 */
   1152       1.21     enami 		if ((ifp->if_flags & IFF_OACTIVE) == 0)
   1153       1.21     enami 			mb86960_start(ifp);
   1154       1.18  explorer 
   1155       1.18  explorer #if NRND > 0
   1156       1.18  explorer 		if (rstat != 0 || tstat != 0)
   1157       1.18  explorer 			rnd_add_uint32(&sc->rnd_source, rstat + tstat);
   1158       1.18  explorer #endif
   1159        1.1   mycroft 
   1160        1.1   mycroft 		/*
   1161        1.1   mycroft 		 * Get interrupt conditions, masking unneeded flags.
   1162        1.1   mycroft 		 */
   1163       1.21     enami 		tstat = bus_space_read_1(bst, bsh, FE_DLCR0) & FE_TMASK;
   1164       1.21     enami 		rstat = bus_space_read_1(bst, bsh, FE_DLCR1) & FE_RMASK;
   1165        1.1   mycroft 		if (tstat == 0 && rstat == 0)
   1166        1.1   mycroft 			return (1);
   1167        1.1   mycroft 	}
   1168        1.1   mycroft }
   1169        1.1   mycroft 
   1170        1.1   mycroft /*
   1171        1.1   mycroft  * Process an ioctl request.  This code needs some work - it looks pretty ugly.
   1172        1.1   mycroft  */
   1173        1.1   mycroft int
   1174       1.66  christos mb86960_ioctl(struct ifnet *ifp, u_long cmd, void *data)
   1175        1.1   mycroft {
   1176       1.21     enami 	struct mb86960_softc *sc = ifp->if_softc;
   1177       1.21     enami 	struct ifaddr *ifa = (struct ifaddr *)data;
   1178        1.1   mycroft 	struct ifreq *ifr = (struct ifreq *)data;
   1179        1.1   mycroft 	int s, error = 0;
   1180        1.1   mycroft 
   1181        1.1   mycroft #if FE_DEBUG >= 3
   1182       1.21     enami 	log(LOG_INFO, "%s: ioctl(%lx)\n", sc->sc_dev.dv_xname, cmd);
   1183        1.1   mycroft #endif
   1184        1.1   mycroft 
   1185        1.8   mycroft 	s = splnet();
   1186        1.1   mycroft 
   1187       1.21     enami 	switch (cmd) {
   1188        1.1   mycroft 	case SIOCSIFADDR:
   1189       1.21     enami 		if ((error = mb86960_enable(sc)) != 0)
   1190       1.21     enami 			break;
   1191        1.1   mycroft 		ifp->if_flags |= IFF_UP;
   1192        1.1   mycroft 
   1193        1.1   mycroft 		switch (ifa->ifa_addr->sa_family) {
   1194        1.1   mycroft #ifdef INET
   1195        1.1   mycroft 		case AF_INET:
   1196       1.21     enami 			mb86960_init(sc);
   1197       1.17        is 			arp_ifinit(ifp, ifa);
   1198        1.1   mycroft 			break;
   1199        1.1   mycroft #endif
   1200        1.1   mycroft 		default:
   1201       1.21     enami 			mb86960_init(sc);
   1202        1.1   mycroft 			break;
   1203        1.1   mycroft 		}
   1204        1.1   mycroft 		break;
   1205        1.1   mycroft 
   1206        1.1   mycroft 	case SIOCSIFFLAGS:
   1207        1.1   mycroft 		if ((ifp->if_flags & IFF_UP) == 0 &&
   1208        1.1   mycroft 		    (ifp->if_flags & IFF_RUNNING) != 0) {
   1209        1.1   mycroft 			/*
   1210        1.1   mycroft 			 * If interface is marked down and it is running, then
   1211        1.1   mycroft 			 * stop it.
   1212        1.1   mycroft 			 */
   1213       1.21     enami 			mb86960_stop(sc);
   1214        1.1   mycroft 			ifp->if_flags &= ~IFF_RUNNING;
   1215       1.21     enami 			mb86960_disable(sc);
   1216        1.1   mycroft 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
   1217       1.21     enami 		    (ifp->if_flags & IFF_RUNNING) == 0) {
   1218        1.1   mycroft 			/*
   1219        1.1   mycroft 			 * If interface is marked up and it is stopped, then
   1220        1.1   mycroft 			 * start it.
   1221        1.1   mycroft 			 */
   1222       1.21     enami 			if ((error = mb86960_enable(sc)) != 0)
   1223       1.21     enami 				break;
   1224       1.21     enami 			mb86960_init(sc);
   1225       1.30   thorpej 		} else if ((ifp->if_flags & IFF_UP) != 0) {
   1226        1.1   mycroft 			/*
   1227        1.1   mycroft 			 * Reset the interface to pick up changes in any other
   1228        1.1   mycroft 			 * flags that affect hardware registers.
   1229        1.1   mycroft 			 */
   1230       1.21     enami 			mb86960_setmode(sc);
   1231        1.1   mycroft 		}
   1232       1.45     lukem #if FE_DEBUG >= 1
   1233        1.1   mycroft 		/* "ifconfig fe0 debug" to print register dump. */
   1234        1.1   mycroft 		if (ifp->if_flags & IFF_DEBUG) {
   1235       1.21     enami 			log(LOG_INFO, "%s: SIOCSIFFLAGS(DEBUG)\n",
   1236       1.21     enami 			    sc->sc_dev.dv_xname);
   1237       1.21     enami 			mb86960_dump(LOG_DEBUG, sc);
   1238        1.1   mycroft 		}
   1239        1.1   mycroft #endif
   1240        1.1   mycroft 		break;
   1241        1.1   mycroft 
   1242        1.1   mycroft 	case SIOCADDMULTI:
   1243        1.1   mycroft 	case SIOCDELMULTI:
   1244       1.54   tsutsui 		if ((sc->sc_stat & FE_STAT_ENABLED) == 0) {
   1245       1.21     enami 			error = EIO;
   1246       1.21     enami 			break;
   1247       1.21     enami 		}
   1248       1.21     enami 
   1249        1.1   mycroft 		/* Update our multicast list. */
   1250  1.66.16.1      matt 		if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) {
   1251        1.1   mycroft 			/*
   1252        1.1   mycroft 			 * Multicast list has changed; set the hardware filter
   1253        1.1   mycroft 			 * accordingly.
   1254        1.1   mycroft 			 */
   1255       1.58   thorpej 			if (ifp->if_flags & IFF_RUNNING)
   1256       1.58   thorpej 				mb86960_setmode(sc);
   1257        1.1   mycroft 			error = 0;
   1258        1.1   mycroft 		}
   1259        1.1   mycroft 		break;
   1260        1.1   mycroft 
   1261       1.21     enami 	case SIOCGIFMEDIA:
   1262       1.21     enami 	case SIOCSIFMEDIA:
   1263       1.21     enami 		error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
   1264       1.21     enami 		break;
   1265       1.21     enami 
   1266        1.1   mycroft 	default:
   1267        1.1   mycroft 		error = EINVAL;
   1268       1.21     enami 		break;
   1269        1.1   mycroft 	}
   1270        1.1   mycroft 
   1271        1.1   mycroft 	splx(s);
   1272        1.1   mycroft 	return (error);
   1273        1.1   mycroft }
   1274        1.1   mycroft 
   1275        1.1   mycroft /*
   1276       1.46       wiz  * Retrieve packet from receive buffer and send to the next level up via
   1277        1.1   mycroft  * ether_input(). If there is a BPF listener, give a copy to BPF, too.
   1278        1.1   mycroft  * Returns 0 if success, -1 if error (i.e., mbuf allocation failure).
   1279        1.1   mycroft  */
   1280        1.1   mycroft int
   1281       1.59   tsutsui mb86960_get_packet(struct mb86960_softc *sc, u_int len)
   1282        1.1   mycroft {
   1283       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
   1284       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
   1285       1.21     enami 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   1286        1.1   mycroft 	struct mbuf *m;
   1287        1.1   mycroft 
   1288        1.1   mycroft 	/* Allocate a header mbuf. */
   1289        1.1   mycroft 	MGETHDR(m, M_DONTWAIT, MT_DATA);
   1290        1.1   mycroft 	if (m == 0)
   1291        1.1   mycroft 		return (0);
   1292        1.1   mycroft 	m->m_pkthdr.rcvif = ifp;
   1293        1.1   mycroft 	m->m_pkthdr.len = len;
   1294        1.1   mycroft 
   1295        1.1   mycroft 	/* The following silliness is to make NFS happy. */
   1296        1.1   mycroft #define	EROUND	((sizeof(struct ether_header) + 3) & ~3)
   1297        1.1   mycroft #define	EOFF	(EROUND - sizeof(struct ether_header))
   1298        1.1   mycroft 
   1299        1.1   mycroft 	/*
   1300        1.1   mycroft 	 * Our strategy has one more problem.  There is a policy on
   1301        1.1   mycroft 	 * mbuf cluster allocation.  It says that we must have at
   1302        1.6   mycroft 	 * least MINCLSIZE (208 bytes) to allocate a cluster.  For a
   1303        1.6   mycroft 	 * packet of a size between (MHLEN - 2) to (MINCLSIZE - 2),
   1304        1.6   mycroft 	 * our code violates the rule...
   1305       1.54   tsutsui 	 * On the other hand, the current code is short, simple,
   1306        1.1   mycroft 	 * and fast, however.  It does no harmful thing, just waists
   1307        1.1   mycroft 	 * some memory.  Any comments?  FIXME.
   1308        1.1   mycroft 	 */
   1309        1.1   mycroft 
   1310        1.1   mycroft 	/* Attach a cluster if this packet doesn't fit in a normal mbuf. */
   1311        1.1   mycroft 	if (len > MHLEN - EOFF) {
   1312        1.1   mycroft 		MCLGET(m, M_DONTWAIT);
   1313        1.1   mycroft 		if ((m->m_flags & M_EXT) == 0) {
   1314        1.1   mycroft 			m_freem(m);
   1315        1.1   mycroft 			return (0);
   1316        1.1   mycroft 		}
   1317        1.1   mycroft 	}
   1318        1.1   mycroft 
   1319        1.1   mycroft 	/*
   1320        1.1   mycroft 	 * The following assumes there is room for the ether header in the
   1321        1.1   mycroft 	 * header mbuf.
   1322        1.1   mycroft 	 */
   1323        1.1   mycroft 	m->m_data += EOFF;
   1324        1.1   mycroft 
   1325        1.1   mycroft 	/* Set the length of this packet. */
   1326        1.1   mycroft 	m->m_len = len;
   1327        1.1   mycroft 
   1328        1.1   mycroft 	/* Get a packet. */
   1329       1.54   tsutsui 	if (sc->sc_flags & FE_FLAGS_SBW_BYTE)
   1330       1.54   tsutsui 		bus_space_read_multi_1(bst, bsh, FE_BMPR8,
   1331       1.59   tsutsui 		    mtod(m, uint8_t *), len);
   1332       1.54   tsutsui 	else
   1333       1.54   tsutsui 		bus_space_read_multi_stream_2(bst, bsh, FE_BMPR8,
   1334       1.59   tsutsui 		    mtod(m, uint16_t *), (len + 1) >> 1);
   1335        1.1   mycroft 
   1336        1.1   mycroft #if NBPFILTER > 0
   1337        1.1   mycroft 	/*
   1338        1.1   mycroft 	 * Check if there's a BPF listener on this interface.  If so, hand off
   1339        1.1   mycroft 	 * the raw packet to bpf.
   1340        1.1   mycroft 	 */
   1341       1.42   thorpej 	if (ifp->if_bpf)
   1342        1.1   mycroft 		bpf_mtap(ifp->if_bpf, m);
   1343        1.1   mycroft #endif
   1344        1.1   mycroft 
   1345       1.33   thorpej 	(*ifp->if_input)(ifp, m);
   1346        1.1   mycroft 	return (1);
   1347        1.1   mycroft }
   1348        1.1   mycroft 
   1349        1.1   mycroft /*
   1350        1.1   mycroft  * Write an mbuf chain to the transmission buffer memory using 16 bit PIO.
   1351        1.1   mycroft  * Returns number of bytes actually written, including length word.
   1352        1.1   mycroft  *
   1353        1.1   mycroft  * If an mbuf chain is too long for an Ethernet frame, it is not sent.
   1354        1.1   mycroft  * Packets shorter than Ethernet minimum are legal, and we pad them
   1355       1.60     perry  * before sending out.  An exception is "partial" packets which are
   1356        1.1   mycroft  * shorter than mandatory Ethernet header.
   1357        1.1   mycroft  *
   1358        1.1   mycroft  * I wrote a code for an experimental "delayed padding" technique.
   1359        1.1   mycroft  * When employed, it postpones the padding process for short packets.
   1360       1.49       wiz  * If xmit() occurred at the moment, the padding process is omitted, and
   1361        1.1   mycroft  * garbages are sent as pad data.  If next packet is stored in the
   1362        1.1   mycroft  * transmission buffer before xmit(), write_mbuf() pads the previous
   1363        1.1   mycroft  * packet before transmitting new packet.  This *may* gain the
   1364        1.1   mycroft  * system performance (slightly).
   1365        1.1   mycroft  */
   1366        1.1   mycroft void
   1367       1.59   tsutsui mb86960_write_mbufs(struct mb86960_softc *sc, struct mbuf *m)
   1368        1.1   mycroft {
   1369       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
   1370       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
   1371       1.54   tsutsui 	int totlen, len;
   1372       1.21     enami #if FE_DEBUG >= 2
   1373       1.21     enami 	struct mbuf *mp;
   1374       1.21     enami #endif
   1375       1.16   thorpej 
   1376        1.1   mycroft #if FE_DELAYED_PADDING
   1377        1.1   mycroft 	/* Do the "delayed padding." */
   1378       1.54   tsutsui 	if (sc->txb_padding > 0) {
   1379       1.54   tsutsui 		if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
   1380       1.54   tsutsui 			for (len = sc->txb_padding; len > 0; len--)
   1381       1.54   tsutsui 				bus_space_write_1(bst, bsh, FE_BMPR8, 0);
   1382       1.54   tsutsui 		} else {
   1383       1.54   tsutsui 			for (len = sc->txb_padding >> 1; len > 0; len--)
   1384       1.54   tsutsui 				bus_space_write_2(bst, bsh, FE_BMPR8, 0);
   1385       1.54   tsutsui 		}
   1386        1.1   mycroft 		sc->txb_padding = 0;
   1387        1.1   mycroft 	}
   1388        1.1   mycroft #endif
   1389        1.1   mycroft 
   1390        1.4   mycroft 	/* We need to use m->m_pkthdr.len, so require the header */
   1391        1.4   mycroft 	if ((m->m_flags & M_PKTHDR) == 0)
   1392       1.21     enami 	  	panic("mb86960_write_mbufs: no header mbuf");
   1393        1.4   mycroft 
   1394        1.1   mycroft #if FE_DEBUG >= 2
   1395        1.1   mycroft 	/* First, count up the total number of bytes to copy. */
   1396        1.1   mycroft 	for (totlen = 0, mp = m; mp != 0; mp = mp->m_next)
   1397        1.1   mycroft 		totlen += mp->m_len;
   1398        1.1   mycroft 	/* Check if this matches the one in the packet header. */
   1399        1.1   mycroft 	if (totlen != m->m_pkthdr.len)
   1400        1.1   mycroft 		log(LOG_WARNING, "%s: packet length mismatch? (%d/%d)\n",
   1401        1.1   mycroft 		    sc->sc_dev.dv_xname, totlen, m->m_pkthdr.len);
   1402        1.1   mycroft #else
   1403        1.1   mycroft 	/* Just use the length value in the packet header. */
   1404        1.1   mycroft 	totlen = m->m_pkthdr.len;
   1405        1.1   mycroft #endif
   1406        1.1   mycroft 
   1407        1.1   mycroft #if FE_DEBUG >= 1
   1408        1.1   mycroft 	/*
   1409        1.1   mycroft 	 * Should never send big packets.  If such a packet is passed,
   1410        1.1   mycroft 	 * it should be a bug of upper layer.  We just ignore it.
   1411        1.1   mycroft 	 * ... Partial (too short) packets, neither.
   1412        1.1   mycroft 	 */
   1413       1.32   thorpej 	if (totlen > (ETHER_MAX_LEN - ETHER_CRC_LEN) ||
   1414       1.32   thorpej 	    totlen < ETHER_HDR_LEN) {
   1415        1.1   mycroft 		log(LOG_ERR, "%s: got a %s packet (%u bytes) to send\n",
   1416        1.1   mycroft 		    sc->sc_dev.dv_xname,
   1417       1.32   thorpej 		    totlen < ETHER_HDR_LEN ? "partial" : "big", totlen);
   1418       1.21     enami 		sc->sc_ec.ec_if.if_oerrors++;
   1419        1.1   mycroft 		return;
   1420        1.1   mycroft 	}
   1421        1.1   mycroft #endif
   1422        1.1   mycroft 
   1423        1.1   mycroft 	/*
   1424        1.1   mycroft 	 * Put the length word for this frame.
   1425        1.1   mycroft 	 * Does 86960 accept odd length?  -- Yes.
   1426        1.1   mycroft 	 * Do we need to pad the length to minimum size by ourselves?
   1427        1.1   mycroft 	 * -- Generally yes.  But for (or will be) the last
   1428        1.1   mycroft 	 * packet in the transmission buffer, we can skip the
   1429        1.1   mycroft 	 * padding process.  It may gain performance slightly.  FIXME.
   1430        1.1   mycroft 	 */
   1431       1.54   tsutsui 	len = max(totlen, (ETHER_MIN_LEN - ETHER_CRC_LEN));
   1432       1.54   tsutsui 	if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
   1433       1.54   tsutsui 		bus_space_write_1(bst, bsh, FE_BMPR8, len);
   1434       1.54   tsutsui 		bus_space_write_1(bst, bsh, FE_BMPR8, len >> 8);
   1435       1.54   tsutsui 	} else {
   1436       1.54   tsutsui 		bus_space_write_2(bst, bsh, FE_BMPR8, len);
   1437       1.54   tsutsui 		/* roundup packet length since we will use word access */
   1438       1.54   tsutsui 		totlen = (totlen + 1) & ~1;
   1439       1.54   tsutsui 	}
   1440        1.1   mycroft 
   1441        1.1   mycroft 	/*
   1442        1.1   mycroft 	 * Update buffer status now.
   1443       1.54   tsutsui 	 * Truncate the length up to an even number
   1444       1.54   tsutsui 	 * if the chip is set in SBW_WORD mode.
   1445        1.1   mycroft 	 */
   1446       1.54   tsutsui 	sc->txb_free -= FE_TXLEN_SIZE +
   1447       1.32   thorpej 	    max(totlen, (ETHER_MIN_LEN - ETHER_CRC_LEN));
   1448        1.1   mycroft 	sc->txb_count++;
   1449        1.1   mycroft 
   1450        1.1   mycroft #if FE_DELAYED_PADDING
   1451        1.1   mycroft 	/* Postpone the packet padding if necessary. */
   1452       1.32   thorpej 	if (totlen < (ETHER_MIN_LEN - ETHER_CRC_LEN))
   1453       1.32   thorpej 		sc->txb_padding = (ETHER_MIN_LEN - ETHER_CRC_LEN) - totlen;
   1454        1.1   mycroft #endif
   1455        1.1   mycroft 
   1456        1.1   mycroft 	/*
   1457       1.60     perry 	 * Transfer the data from mbuf chain to the transmission buffer.
   1458       1.54   tsutsui 	 * If the MB86960 is configured in word mode, data needs to be
   1459       1.54   tsutsui 	 * transferred as words, and only words.
   1460       1.54   tsutsui 	 * So that we require some extra code to patch over odd-length
   1461       1.54   tsutsui 	 * or unaligned mbufs.
   1462       1.54   tsutsui 	 */
   1463       1.54   tsutsui 	if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
   1464       1.54   tsutsui 		/* It's simple in byte mode. */
   1465       1.54   tsutsui 		for (; m != NULL; m = m->m_next) {
   1466       1.54   tsutsui 			if (m->m_len) {
   1467       1.54   tsutsui 				bus_space_write_multi_1(bst, bsh, FE_BMPR8,
   1468       1.59   tsutsui 				    mtod(m, uint8_t *), m->m_len);
   1469       1.54   tsutsui 			}
   1470       1.54   tsutsui 		}
   1471       1.54   tsutsui 	} else {
   1472       1.54   tsutsui 		/* a bit trickier in word mode. */
   1473       1.59   tsutsui 		uint8_t *data, savebyte[2];
   1474       1.54   tsutsui 		int leftover;
   1475       1.54   tsutsui 
   1476       1.54   tsutsui 		leftover = 0;
   1477       1.54   tsutsui 		savebyte[0] = savebyte[1] = 0;
   1478       1.54   tsutsui 
   1479       1.54   tsutsui 		for (; m != NULL; m = m->m_next) {
   1480       1.54   tsutsui 			len = m->m_len;
   1481       1.54   tsutsui 			if (len == 0)
   1482       1.54   tsutsui 				continue;
   1483       1.59   tsutsui 			data = mtod(m, uint8_t *);
   1484       1.54   tsutsui 			while (len > 0) {
   1485       1.54   tsutsui 				if (leftover) {
   1486       1.54   tsutsui 					/*
   1487       1.54   tsutsui 					 * Data left over (from mbuf or
   1488       1.54   tsutsui 					 * realignment). Buffer the next
   1489       1.54   tsutsui 					 * byte, and write it and the
   1490       1.54   tsutsui 					 * leftover data out.
   1491       1.54   tsutsui 					 */
   1492       1.54   tsutsui 					savebyte[1] = *data++;
   1493       1.54   tsutsui 					len--;
   1494       1.54   tsutsui 					bus_space_write_stream_2(bst, bsh,
   1495       1.59   tsutsui 					   FE_BMPR8, *(uint16_t *)savebyte);
   1496       1.60     perry 					leftover = 0;
   1497       1.54   tsutsui 				} else if (BUS_SPACE_ALIGNED_POINTER(data,
   1498       1.59   tsutsui 				    uint16_t) == 0) {
   1499       1.54   tsutsui 					/*
   1500       1.54   tsutsui 					 * Unaligned data; buffer the next byte.
   1501       1.54   tsutsui 					 */
   1502       1.54   tsutsui 					savebyte[0] = *data++;
   1503       1.54   tsutsui 					len--;
   1504       1.54   tsutsui 					leftover = 1;
   1505       1.54   tsutsui 				} else {
   1506       1.54   tsutsui 					/*
   1507       1.54   tsutsui 					 * Aligned data; output contiguous
   1508       1.54   tsutsui 					 * words as much as we can, then
   1509       1.54   tsutsui 					 * buffer the remaining byte, if any.
   1510       1.54   tsutsui 					 */
   1511       1.54   tsutsui 					leftover = len & 1;
   1512       1.54   tsutsui 					len &= ~1;
   1513       1.54   tsutsui 					bus_space_write_multi_stream_2(bst, bsh,
   1514       1.59   tsutsui 					    FE_BMPR8, (uint16_t *)data,
   1515       1.54   tsutsui 					    len >> 1);
   1516       1.54   tsutsui 					data += len;
   1517       1.54   tsutsui 					if (leftover)
   1518       1.54   tsutsui 						savebyte[0] = *data++;
   1519       1.54   tsutsui 					len = 0;
   1520       1.54   tsutsui 				}
   1521       1.54   tsutsui 			}
   1522       1.54   tsutsui 			if (len < 0)
   1523       1.54   tsutsui 				panic("mb86960_write_mbufs: negative len");
   1524        1.1   mycroft 		}
   1525       1.54   tsutsui 		if (leftover) {
   1526       1.54   tsutsui 			savebyte[1] = 0;
   1527       1.54   tsutsui 			bus_space_write_stream_2(bst, bsh, FE_BMPR8,
   1528       1.59   tsutsui 			    *(uint16_t *)savebyte);
   1529        1.1   mycroft 		}
   1530        1.1   mycroft 	}
   1531       1.54   tsutsui #if FE_DELAYED_PADDING == 0
   1532        1.1   mycroft 	/*
   1533        1.1   mycroft 	 * Pad the packet to the minimum length if necessary.
   1534        1.1   mycroft 	 */
   1535       1.54   tsutsui 	len = (ETHER_MIN_LEN - ETHER_CRC_LEN) - totlen;
   1536       1.54   tsutsui 	if (len > 0) {
   1537       1.54   tsutsui 		if (sc->sc_flags & FE_FLAGS_SBW_BYTE) {
   1538       1.54   tsutsui 			while (len-- > 0)
   1539       1.54   tsutsui 				bus_space_write_1(bst, bsh, FE_BMPR8, 0);
   1540       1.54   tsutsui 		} else {
   1541       1.54   tsutsui 			len >>= 1;
   1542       1.54   tsutsui 			while (len-- > 0)
   1543       1.54   tsutsui 				bus_space_write_2(bst, bsh, FE_BMPR8, 0);
   1544       1.54   tsutsui 		}
   1545       1.54   tsutsui 	}
   1546        1.1   mycroft #endif
   1547        1.1   mycroft }
   1548        1.1   mycroft 
   1549        1.1   mycroft /*
   1550        1.1   mycroft  * Compute the multicast address filter from the
   1551        1.1   mycroft  * list of multicast addresses we need to listen to.
   1552        1.1   mycroft  */
   1553        1.1   mycroft void
   1554       1.59   tsutsui mb86960_getmcaf(struct ethercom *ec, uint8_t *af)
   1555        1.1   mycroft {
   1556       1.17        is 	struct ifnet *ifp = &ec->ec_if;
   1557        1.1   mycroft 	struct ether_multi *enm;
   1558       1.59   tsutsui 	uint32_t crc;
   1559        1.1   mycroft 	struct ether_multistep step;
   1560        1.1   mycroft 
   1561        1.1   mycroft 	/*
   1562        1.1   mycroft 	 * Set up multicast address filter by passing all multicast addresses
   1563        1.1   mycroft 	 * through a crc generator, and then using the high order 6 bits as an
   1564        1.1   mycroft 	 * index into the 64 bit logical address filter.  The high order bit
   1565        1.1   mycroft 	 * selects the word, while the rest of the bits select the bit within
   1566        1.1   mycroft 	 * the word.
   1567        1.1   mycroft 	 */
   1568        1.1   mycroft 
   1569        1.1   mycroft 	if ((ifp->if_flags & IFF_PROMISC) != 0)
   1570        1.1   mycroft 		goto allmulti;
   1571        1.1   mycroft 
   1572       1.54   tsutsui 	memset(af, 0, FE_FILTER_LEN);
   1573       1.17        is 	ETHER_FIRST_MULTI(step, ec, enm);
   1574        1.1   mycroft 	while (enm != NULL) {
   1575       1.47   thorpej 		if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
   1576        1.1   mycroft 		    sizeof(enm->enm_addrlo)) != 0) {
   1577        1.1   mycroft 			/*
   1578        1.1   mycroft 			 * We must listen to a range of multicast addresses.
   1579        1.1   mycroft 			 * For now, just accept all multicasts, rather than
   1580        1.1   mycroft 			 * trying to set only those filter bits needed to match
   1581        1.1   mycroft 			 * the range.  (At this time, the only use of address
   1582        1.1   mycroft 			 * ranges is for IP multicast routing, for which the
   1583        1.1   mycroft 			 * range is big enough to require all bits set.)
   1584        1.1   mycroft 			 */
   1585        1.1   mycroft 			goto allmulti;
   1586        1.1   mycroft 		}
   1587        1.1   mycroft 
   1588       1.39   thorpej 		crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
   1589       1.39   thorpej 
   1590        1.1   mycroft 		/* Just want the 6 most significant bits. */
   1591        1.1   mycroft 		crc >>= 26;
   1592        1.1   mycroft 
   1593        1.1   mycroft 		/* Turn on the corresponding bit in the filter. */
   1594        1.1   mycroft 		af[crc >> 3] |= 1 << (crc & 7);
   1595        1.1   mycroft 
   1596        1.1   mycroft 		ETHER_NEXT_MULTI(step, enm);
   1597        1.1   mycroft 	}
   1598        1.1   mycroft 	ifp->if_flags &= ~IFF_ALLMULTI;
   1599        1.1   mycroft 	return;
   1600        1.1   mycroft 
   1601        1.1   mycroft allmulti:
   1602        1.1   mycroft 	ifp->if_flags |= IFF_ALLMULTI;
   1603       1.54   tsutsui 	memset(af, 0xff, FE_FILTER_LEN);
   1604        1.1   mycroft }
   1605        1.1   mycroft 
   1606        1.1   mycroft /*
   1607        1.1   mycroft  * Calculate a new "multicast packet filter" and put the 86960
   1608        1.1   mycroft  * receiver in appropriate mode.
   1609        1.1   mycroft  */
   1610        1.1   mycroft void
   1611       1.59   tsutsui mb86960_setmode(struct mb86960_softc *sc)
   1612        1.1   mycroft {
   1613       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
   1614       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
   1615       1.21     enami 	int flags = sc->sc_ec.ec_if.if_flags;
   1616        1.1   mycroft 
   1617        1.1   mycroft 	/*
   1618        1.1   mycroft 	 * If the interface is not running, we postpone the update
   1619        1.1   mycroft 	 * process for receive modes and multicast address filter
   1620        1.1   mycroft 	 * until the interface is restarted.  It reduces some
   1621        1.1   mycroft 	 * complicated job on maintaining chip states.  (Earlier versions
   1622        1.1   mycroft 	 * of this driver had a bug on that point...)
   1623        1.1   mycroft 	 *
   1624       1.21     enami 	 * To complete the trick, mb86960_init() calls mb86960_setmode() after
   1625        1.1   mycroft 	 * restarting the interface.
   1626        1.1   mycroft 	 */
   1627        1.1   mycroft 	if ((flags & IFF_RUNNING) == 0)
   1628        1.1   mycroft 		return;
   1629        1.1   mycroft 
   1630        1.1   mycroft 	/*
   1631        1.1   mycroft 	 * Promiscuous mode is handled separately.
   1632        1.1   mycroft 	 */
   1633        1.1   mycroft 	if ((flags & IFF_PROMISC) != 0) {
   1634        1.1   mycroft 		/*
   1635        1.1   mycroft 		 * Program 86960 to receive all packets on the segment
   1636        1.1   mycroft 		 * including those directed to other stations.
   1637        1.1   mycroft 		 * Multicast filter stored in MARs are ignored
   1638        1.1   mycroft 		 * under this setting, so we don't need to update it.
   1639        1.1   mycroft 		 *
   1640        1.6   mycroft 		 * Promiscuous mode is used solely by BPF, and BPF only
   1641        1.6   mycroft 		 * listens to valid (no error) packets.  So, we ignore
   1642        1.6   mycroft 		 * errornous ones even in this mode.
   1643        1.1   mycroft 		 */
   1644       1.21     enami 		bus_space_write_1(bst, bsh, FE_DLCR5,
   1645        1.1   mycroft 		    sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1);
   1646        1.1   mycroft 		sc->filter_change = 0;
   1647        1.1   mycroft 
   1648        1.1   mycroft #if FE_DEBUG >= 3
   1649        1.1   mycroft 		log(LOG_INFO, "%s: promiscuous mode\n", sc->sc_dev.dv_xname);
   1650        1.1   mycroft #endif
   1651        1.1   mycroft 		return;
   1652        1.1   mycroft 	}
   1653        1.1   mycroft 
   1654        1.1   mycroft 	/*
   1655        1.1   mycroft 	 * Turn the chip to the normal (non-promiscuous) mode.
   1656        1.1   mycroft 	 */
   1657       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR5, sc->proto_dlcr5 | FE_D5_AFM1);
   1658        1.1   mycroft 
   1659        1.1   mycroft 	/*
   1660        1.1   mycroft 	 * Find the new multicast filter value.
   1661        1.1   mycroft 	 */
   1662       1.21     enami 	mb86960_getmcaf(&sc->sc_ec, sc->filter);
   1663        1.1   mycroft 	sc->filter_change = 1;
   1664        1.1   mycroft 
   1665        1.1   mycroft #if FE_DEBUG >= 3
   1666        1.1   mycroft 	log(LOG_INFO,
   1667        1.1   mycroft 	    "%s: address filter: [%02x %02x %02x %02x %02x %02x %02x %02x]\n",
   1668        1.1   mycroft 	    sc->sc_dev.dv_xname,
   1669        1.1   mycroft 	    sc->filter[0], sc->filter[1], sc->filter[2], sc->filter[3],
   1670        1.1   mycroft 	    sc->filter[4], sc->filter[5], sc->filter[6], sc->filter[7]);
   1671        1.1   mycroft #endif
   1672        1.1   mycroft 
   1673        1.1   mycroft 	/*
   1674        1.1   mycroft 	 * We have to update the multicast filter in the 86960, A.S.A.P.
   1675        1.1   mycroft 	 *
   1676        1.1   mycroft 	 * Note that the DLC (Data Linc Control unit, i.e. transmitter
   1677        1.1   mycroft 	 * and receiver) must be stopped when feeding the filter, and
   1678       1.54   tsutsui 	 * DLC trashes all packets in both transmission and receive
   1679        1.1   mycroft 	 * buffers when stopped.
   1680        1.1   mycroft 	 *
   1681        1.1   mycroft 	 * ... Are the above sentenses correct?  I have to check the
   1682        1.1   mycroft 	 *     manual of the MB86960A.  FIXME.
   1683        1.1   mycroft 	 *
   1684        1.1   mycroft 	 * To reduce the packet lossage, we delay the filter update
   1685        1.1   mycroft 	 * process until buffers are empty.
   1686        1.1   mycroft 	 */
   1687        1.1   mycroft 	if (sc->txb_sched == 0 && sc->txb_count == 0 &&
   1688       1.21     enami 	    (bus_space_read_1(bst, bsh, FE_DLCR1) & FE_D1_PKTRDY) == 0) {
   1689        1.1   mycroft 		/*
   1690        1.1   mycroft 		 * Buffers are (apparently) empty.  Load
   1691        1.1   mycroft 		 * the new filter value into MARs now.
   1692        1.1   mycroft 		 */
   1693       1.21     enami 		mb86960_loadmar(sc);
   1694        1.1   mycroft 	} else {
   1695        1.1   mycroft 		/*
   1696        1.1   mycroft 		 * Buffers are not empty.  Mark that we have to update
   1697       1.21     enami 		 * the MARs.  The new filter will be loaded by mb86960_intr()
   1698        1.1   mycroft 		 * later.
   1699        1.1   mycroft 		 */
   1700        1.1   mycroft #if FE_DEBUG >= 4
   1701       1.21     enami 		log(LOG_INFO, "%s: filter change delayed\n",
   1702       1.21     enami 		    sc->sc_dev.dv_xname);
   1703        1.1   mycroft #endif
   1704        1.1   mycroft 	}
   1705        1.1   mycroft }
   1706        1.1   mycroft 
   1707        1.1   mycroft /*
   1708        1.1   mycroft  * Load a new multicast address filter into MARs.
   1709        1.1   mycroft  *
   1710       1.21     enami  * The caller must have splnet'ed befor mb86960_loadmar.
   1711        1.1   mycroft  * This function starts the DLC upon return.  So it can be called only
   1712        1.1   mycroft  * when the chip is working, i.e., from the driver's point of view, when
   1713        1.1   mycroft  * a device is RUNNING.  (I mistook the point in previous versions.)
   1714        1.1   mycroft  */
   1715        1.1   mycroft void
   1716       1.59   tsutsui mb86960_loadmar(struct mb86960_softc *sc)
   1717        1.1   mycroft {
   1718       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
   1719       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
   1720        1.1   mycroft 
   1721        1.1   mycroft 	/* Stop the DLC (transmitter and receiver). */
   1722       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR6,
   1723       1.21     enami 	    sc->proto_dlcr6 | FE_D6_DLC_DISABLE);
   1724        1.1   mycroft 
   1725        1.1   mycroft 	/* Select register bank 1 for MARs. */
   1726       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
   1727        1.1   mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP);
   1728        1.1   mycroft 
   1729        1.1   mycroft 	/* Copy filter value into the registers. */
   1730       1.21     enami 	bus_space_write_region_1(bst, bsh, FE_MAR8, sc->filter, FE_FILTER_LEN);
   1731        1.1   mycroft 
   1732        1.1   mycroft 	/* Restore the bank selection for BMPRs (i.e., runtime registers). */
   1733       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
   1734        1.1   mycroft 	    sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP);
   1735        1.1   mycroft 
   1736        1.1   mycroft 	/* Restart the DLC. */
   1737       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR6,
   1738       1.21     enami 	    sc->proto_dlcr6 | FE_D6_DLC_ENABLE);
   1739        1.1   mycroft 
   1740        1.1   mycroft 	/* We have just updated the filter. */
   1741        1.1   mycroft 	sc->filter_change = 0;
   1742        1.1   mycroft 
   1743        1.1   mycroft #if FE_DEBUG >= 3
   1744        1.1   mycroft 	log(LOG_INFO, "%s: address filter changed\n", sc->sc_dev.dv_xname);
   1745        1.1   mycroft #endif
   1746        1.1   mycroft }
   1747        1.1   mycroft 
   1748       1.21     enami /*
   1749       1.21     enami  * Enable power on the interface.
   1750       1.21     enami  */
   1751       1.21     enami int
   1752       1.59   tsutsui mb86960_enable(struct mb86960_softc *sc)
   1753       1.21     enami {
   1754       1.21     enami 
   1755       1.21     enami #if FE_DEBUG >= 3
   1756       1.21     enami 	log(LOG_INFO, "%s: mb86960_enable()\n", sc->sc_dev.dv_xname);
   1757       1.21     enami #endif
   1758       1.21     enami 
   1759       1.54   tsutsui 	if ((sc->sc_stat & FE_STAT_ENABLED) == 0 && sc->sc_enable != NULL) {
   1760       1.21     enami 		if ((*sc->sc_enable)(sc) != 0) {
   1761       1.21     enami 			printf("%s: device enable failed\n",
   1762       1.21     enami 			    sc->sc_dev.dv_xname);
   1763       1.21     enami 			return (EIO);
   1764       1.21     enami 		}
   1765       1.21     enami 	}
   1766       1.21     enami 
   1767       1.54   tsutsui 	sc->sc_stat |= FE_STAT_ENABLED;
   1768       1.21     enami 	return (0);
   1769       1.21     enami }
   1770       1.21     enami 
   1771       1.21     enami /*
   1772       1.21     enami  * Disable power on the interface.
   1773       1.21     enami  */
   1774       1.21     enami void
   1775       1.59   tsutsui mb86960_disable(struct mb86960_softc *sc)
   1776       1.21     enami {
   1777       1.21     enami 
   1778       1.21     enami #if FE_DEBUG >= 3
   1779       1.21     enami 	log(LOG_INFO, "%s: mb86960_disable()\n", sc->sc_dev.dv_xname);
   1780       1.21     enami #endif
   1781       1.21     enami 
   1782       1.54   tsutsui 	if ((sc->sc_stat & FE_STAT_ENABLED) != 0 && sc->sc_disable != NULL) {
   1783       1.21     enami 		(*sc->sc_disable)(sc);
   1784       1.54   tsutsui 		sc->sc_stat &= ~FE_STAT_ENABLED;
   1785       1.21     enami 	}
   1786       1.28   thorpej }
   1787       1.28   thorpej 
   1788       1.36     enami /*
   1789       1.36     enami  * mbe_activate:
   1790       1.36     enami  *
   1791       1.36     enami  *	Handle device activation/deactivation requests.
   1792       1.36     enami  */
   1793       1.28   thorpej int
   1794       1.59   tsutsui mb86960_activate(struct device *self, enum devact act)
   1795       1.28   thorpej {
   1796       1.28   thorpej 	struct mb86960_softc *sc = (struct mb86960_softc *)self;
   1797       1.54   tsutsui 	int rv, s;
   1798       1.28   thorpej 
   1799       1.54   tsutsui 	rv = 0;
   1800       1.28   thorpej 	s = splnet();
   1801       1.28   thorpej 	switch (act) {
   1802       1.28   thorpej 	case DVACT_ACTIVATE:
   1803       1.28   thorpej 		rv = EOPNOTSUPP;
   1804       1.28   thorpej 		break;
   1805       1.28   thorpej 
   1806       1.28   thorpej 	case DVACT_DEACTIVATE:
   1807       1.36     enami 		if_deactivate(&sc->sc_ec.ec_if);
   1808       1.28   thorpej 		break;
   1809       1.28   thorpej 	}
   1810       1.28   thorpej 	splx(s);
   1811       1.28   thorpej 	return (rv);
   1812       1.36     enami }
   1813       1.36     enami 
   1814       1.36     enami /*
   1815       1.36     enami  * mb86960_detach:
   1816       1.36     enami  *
   1817       1.36     enami  *	Detach a MB86960 interface.
   1818       1.36     enami  */
   1819       1.36     enami int
   1820       1.59   tsutsui mb86960_detach(struct mb86960_softc *sc)
   1821       1.36     enami {
   1822       1.36     enami 	struct ifnet *ifp = &sc->sc_ec.ec_if;
   1823       1.40     jhawk 
   1824       1.40     jhawk 	/* Succeed now if there's no work to do. */
   1825       1.54   tsutsui 	if ((sc->sc_stat & FE_STAT_ATTACHED) == 0)
   1826       1.40     jhawk 		return (0);
   1827       1.36     enami 
   1828       1.36     enami 	/* Delete all media. */
   1829       1.36     enami 	ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY);
   1830       1.36     enami 
   1831       1.37     enami #if NRND > 0
   1832       1.37     enami 	/* Unhook the entropy source. */
   1833       1.37     enami 	rnd_detach_source(&sc->rnd_source);
   1834       1.36     enami #endif
   1835       1.36     enami 	ether_ifdetach(ifp);
   1836       1.36     enami 	if_detach(ifp);
   1837       1.36     enami 
   1838       1.36     enami 	mb86960_disable(sc);
   1839       1.36     enami 	return (0);
   1840       1.21     enami }
   1841       1.21     enami 
   1842       1.53   tsutsui /*
   1843       1.53   tsutsui  * Routines to read all bytes from the config EEPROM (93C06) through MB86965A.
   1844       1.53   tsutsui  */
   1845       1.53   tsutsui void
   1846       1.59   tsutsui mb86965_read_eeprom(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t *data)
   1847       1.53   tsutsui {
   1848       1.53   tsutsui 	int addr, op, bit;
   1849       1.59   tsutsui 	uint16_t val;
   1850       1.53   tsutsui 
   1851       1.53   tsutsui 	/* Read bytes from EEPROM; two bytes per an iteration. */
   1852       1.53   tsutsui 	for (addr = 0; addr < FE_EEPROM_SIZE / 2; addr++) {
   1853       1.53   tsutsui 		/* Reset the EEPROM interface. */
   1854       1.53   tsutsui 		bus_space_write_1(iot, ioh, FE_BMPR16, 0x00);
   1855       1.53   tsutsui 		bus_space_write_1(iot, ioh, FE_BMPR17, 0x00);
   1856       1.53   tsutsui 		bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
   1857       1.53   tsutsui 
   1858       1.53   tsutsui 		/* Send start bit. */
   1859       1.53   tsutsui 		bus_space_write_1(iot, ioh, FE_BMPR17, FE_B17_DATA);
   1860       1.53   tsutsui 		FE_EEPROM_DELAY();
   1861       1.53   tsutsui 		bus_space_write_1(iot, ioh,
   1862       1.53   tsutsui 		    FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
   1863       1.53   tsutsui 		FE_EEPROM_DELAY();
   1864       1.53   tsutsui 		bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
   1865       1.53   tsutsui 
   1866       1.53   tsutsui 		/* Send read command and read address. */
   1867       1.53   tsutsui 		op = 0x80 | addr;	/* READ instruction */
   1868       1.53   tsutsui 		for (bit = 8; bit > 0; bit--) {
   1869       1.53   tsutsui 			bus_space_write_1(iot, ioh, FE_BMPR17,
   1870       1.53   tsutsui 			    (op & (1 << (bit - 1))) ? FE_B17_DATA : 0);
   1871       1.53   tsutsui 			FE_EEPROM_DELAY();
   1872       1.53   tsutsui 			bus_space_write_1(iot, ioh,
   1873       1.53   tsutsui 			    FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
   1874       1.53   tsutsui 			FE_EEPROM_DELAY();
   1875       1.53   tsutsui 			bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT);
   1876       1.53   tsutsui 		}
   1877       1.53   tsutsui 		bus_space_write_1(iot, ioh, FE_BMPR17, 0x00);
   1878       1.53   tsutsui 
   1879       1.53   tsutsui 		/* Read two bytes in each address */
   1880       1.53   tsutsui 		val = 0;
   1881       1.53   tsutsui 		for (bit = 16; bit > 0; bit--) {
   1882       1.53   tsutsui 			FE_EEPROM_DELAY();
   1883       1.53   tsutsui 			bus_space_write_1(iot, ioh,
   1884       1.53   tsutsui 			    FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK);
   1885       1.53   tsutsui 			FE_EEPROM_DELAY();
   1886       1.53   tsutsui 			if (bus_space_read_1(iot, ioh, FE_BMPR17) &
   1887       1.53   tsutsui 			    FE_B17_DATA)
   1888       1.53   tsutsui 				val |= 1 << (bit - 1);
   1889       1.53   tsutsui 			bus_space_write_1(iot, ioh,
   1890       1.53   tsutsui 			    FE_BMPR16, FE_B16_SELECT);
   1891       1.53   tsutsui 		}
   1892       1.53   tsutsui 		data[addr * 2]     = val >> 8;
   1893       1.53   tsutsui 		data[addr * 2 + 1] = val & 0xff;
   1894       1.53   tsutsui 	}
   1895       1.53   tsutsui 
   1896       1.53   tsutsui 	/* Make sure the EEPROM is turned off. */
   1897       1.53   tsutsui 	bus_space_write_1(iot, ioh, FE_BMPR16, 0);
   1898       1.53   tsutsui 	bus_space_write_1(iot, ioh, FE_BMPR17, 0);
   1899       1.53   tsutsui 
   1900       1.53   tsutsui #if FE_DEBUG >= 3
   1901       1.53   tsutsui 	/* Report what we got. */
   1902       1.53   tsutsui 	log(LOG_INFO, "mb86965_read_eeprom: "
   1903       1.53   tsutsui 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
   1904       1.53   tsutsui 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
   1905       1.53   tsutsui 	    " %02x%02x%02x%02x %02x%02x%02x%02x -"
   1906       1.53   tsutsui 	    " %02x%02x%02x%02x %02x%02x%02x%02x\n",
   1907       1.53   tsutsui 	    data[ 0], data[ 1], data[ 2], data[ 3],
   1908       1.53   tsutsui 	    data[ 4], data[ 5], data[ 6], data[ 7],
   1909       1.53   tsutsui 	    data[ 8], data[ 9], data[10], data[11],
   1910       1.53   tsutsui 	    data[12], data[13], data[14], data[15],
   1911       1.53   tsutsui 	    data[16], data[17], data[18], data[19],
   1912       1.53   tsutsui 	    data[20], data[21], data[22], data[23],
   1913       1.53   tsutsui 	    data[24], data[25], data[26], data[27],
   1914       1.53   tsutsui 	    data[28], data[29], data[30], data[31]);
   1915       1.53   tsutsui #endif
   1916       1.53   tsutsui }
   1917       1.53   tsutsui 
   1918        1.1   mycroft #if FE_DEBUG >= 1
   1919        1.1   mycroft void
   1920       1.59   tsutsui mb86960_dump(int level, struct mb86960_softc *sc)
   1921        1.1   mycroft {
   1922       1.21     enami 	bus_space_tag_t bst = sc->sc_bst;
   1923       1.21     enami 	bus_space_handle_t bsh = sc->sc_bsh;
   1924       1.59   tsutsui 	uint8_t save_dlcr7;
   1925        1.1   mycroft 
   1926       1.21     enami 	save_dlcr7 = bus_space_read_1(bst, bsh, FE_DLCR7);
   1927        1.1   mycroft 
   1928       1.21     enami 	log(level, "\tDLCR = %02x %02x %02x %02x %02x %02x %02x %02x\n",
   1929       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR0),
   1930       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR1),
   1931       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR2),
   1932       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR3),
   1933       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR4),
   1934       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR5),
   1935       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR6),
   1936       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR7));
   1937       1.21     enami 
   1938       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
   1939       1.21     enami 	    (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_DLCR);
   1940       1.21     enami 	log(level, "\t       %02x %02x %02x %02x %02x %02x %02x %02x\n",
   1941       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR8),
   1942       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR9),
   1943       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR10),
   1944       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR11),
   1945       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR12),
   1946       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR13),
   1947       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR14),
   1948       1.21     enami 	    bus_space_read_1(bst, bsh, FE_DLCR15));
   1949       1.21     enami 
   1950       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
   1951       1.21     enami 	    (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_MAR);
   1952       1.21     enami 	log(level, "\tMAR  = %02x %02x %02x %02x %02x %02x %02x %02x\n",
   1953       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR8),
   1954       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR9),
   1955       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR10),
   1956       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR11),
   1957       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR12),
   1958       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR13),
   1959       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR14),
   1960       1.21     enami 	    bus_space_read_1(bst, bsh, FE_MAR15));
   1961       1.21     enami 
   1962       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7,
   1963       1.21     enami 	    (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_BMPR);
   1964       1.21     enami 	log(level,
   1965       1.21     enami 	    "\tBMPR = xx xx %02x %02x %02x %02x %02x %02x %02x %02x xx %02x\n",
   1966       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR10),
   1967       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR11),
   1968       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR12),
   1969       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR13),
   1970       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR14),
   1971       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR15),
   1972       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR16),
   1973       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR17),
   1974       1.21     enami 	    bus_space_read_1(bst, bsh, FE_BMPR19));
   1975        1.1   mycroft 
   1976       1.21     enami 	bus_space_write_1(bst, bsh, FE_DLCR7, save_dlcr7);
   1977        1.1   mycroft }
   1978        1.1   mycroft #endif
   1979       1.53   tsutsui 
   1980