Home | History | Annotate | Line # | Download | only in ic
smc90cx6.c revision 1.33.2.1
      1  1.33.2.1    bouyer /*	$NetBSD: smc90cx6.c,v 1.33.2.1 2000/11/20 11:40:56 bouyer Exp $ */
      2       1.2    chopps 
      3      1.28        is /*-
      4      1.29        is  * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
      5       1.1    chopps  * All rights reserved.
      6       1.1    chopps  *
      7      1.28        is  * This code is derived from software contributed to The NetBSD Foundation
      8      1.28        is  * by Ignatios Souvatzis.
      9      1.28        is  *
     10       1.1    chopps  * Redistribution and use in source and binary forms, with or without
     11       1.1    chopps  * modification, are permitted provided that the following conditions
     12       1.1    chopps  * are met:
     13       1.1    chopps  * 1. Redistributions of source code must retain the above copyright
     14       1.1    chopps  *    notice, this list of conditions and the following disclaimer.
     15       1.1    chopps  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1    chopps  *    notice, this list of conditions and the following disclaimer in the
     17       1.1    chopps  *    documentation and/or other materials provided with the distribution.
     18       1.1    chopps  * 3. All advertising materials mentioning features or use of this software
     19       1.1    chopps  *    must display the following acknowledgement:
     20      1.28        is  *        This product includes software developed by the NetBSD
     21      1.28        is  *        Foundation, Inc. and its contributors.
     22      1.28        is  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.28        is  *    contributors may be used to endorse or promote products derived
     24      1.28        is  *    from this software without specific prior written permission.
     25       1.1    chopps  *
     26      1.28        is  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.28        is  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.28        is  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.28        is  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.28        is  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.28        is  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.28        is  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.28        is  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.28        is  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.28        is  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.28        is  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1    chopps  */
     38       1.1    chopps 
     39       1.1    chopps /*
     40      1.25        is  * Chip core driver for the SMC90c26 / SMC90c56 (and SMC90c66 in '56
     41      1.25        is  * compatibility mode) boards
     42       1.1    chopps  */
     43       1.1    chopps 
     44      1.33        is /* #define BAHSOFTCOPY */
     45      1.14    chopps #define BAHRETRANSMIT /**/
     46      1.16        is 
     47      1.24  jonathan #include "opt_inet.h"
     48       1.1    chopps #include "bpfilter.h"
     49       1.1    chopps 
     50       1.1    chopps #include <sys/param.h>
     51       1.1    chopps #include <sys/systm.h>
     52       1.1    chopps #include <sys/mbuf.h>
     53       1.1    chopps #include <sys/buf.h>
     54       1.1    chopps #include <sys/device.h>
     55       1.1    chopps #include <sys/protosw.h>
     56       1.1    chopps #include <sys/socket.h>
     57       1.1    chopps #include <sys/syslog.h>
     58       1.1    chopps #include <sys/ioctl.h>
     59       1.1    chopps #include <sys/errno.h>
     60       1.1    chopps 
     61       1.1    chopps #include <net/if.h>
     62       1.1    chopps #include <net/if_dl.h>
     63       1.1    chopps #include <net/if_types.h>
     64      1.25        is #include <net/if_arc.h>
     65       1.1    chopps 
     66       1.1    chopps #ifdef INET
     67       1.1    chopps #include <netinet/in.h>
     68       1.1    chopps #include <netinet/in_systm.h>
     69       1.1    chopps #include <netinet/in_var.h>
     70       1.1    chopps #include <netinet/ip.h>
     71      1.25        is #include <netinet/if_inarp.h>
     72       1.1    chopps #endif
     73       1.1    chopps 
     74       1.1    chopps #if NBPFILTER > 0
     75       1.1    chopps #include <net/bpf.h>
     76       1.1    chopps #include <net/bpfdesc.h>
     77       1.1    chopps #endif
     78       1.1    chopps 
     79       1.1    chopps #include <sys/kernel.h>
     80      1.25        is #include <machine/bus.h>
     81       1.1    chopps #include <machine/cpu.h>
     82      1.25        is #include <machine/intr.h>
     83       1.1    chopps #include <machine/mtpr.h>
     84       1.1    chopps 
     85      1.25        is #include <dev/ic/smc90cx6reg.h>
     86      1.25        is #include <dev/ic/smc90cx6var.h>
     87       1.1    chopps 
     88       1.1    chopps /* these should be elsewhere */
     89       1.1    chopps 
     90       1.1    chopps #define ARC_MIN_LEN 1
     91       1.1    chopps #define ARC_MIN_FORBID_LEN 254
     92       1.1    chopps #define ARC_MAX_FORBID_LEN 256
     93       1.1    chopps #define ARC_MAX_LEN 508
     94       1.1    chopps #define ARC_ADDR_LEN 1
     95       1.1    chopps 
     96       1.6    chopps /* for watchdog timer. This should be more than enough. */
     97       1.6    chopps #define ARCTIMEOUT (5*IFNET_SLOWHZ)
     98       1.6    chopps 
     99       1.1    chopps /*
    100       1.1    chopps  * This currently uses 2 bufs for tx, 2 for rx
    101       1.1    chopps  *
    102       1.1    chopps  * New rx protocol:
    103       1.1    chopps  *
    104       1.1    chopps  * rx has a fillcount variable. If fillcount > (NRXBUF-1),
    105       1.1    chopps  * rx can be switched off from rx hard int.
    106       1.1    chopps  * Else rx is restarted on the other receiver.
    107       1.1    chopps  * rx soft int counts down. if it is == (NRXBUF-1), it restarts
    108       1.1    chopps  * the receiver.
    109       1.1    chopps  * To ensure packet ordering (we need that for 1201 later), we have a counter
    110       1.1    chopps  * which is incremented modulo 256 on each receive and a per buffer
    111       1.1    chopps  * variable, which is set to the counter on filling. The soft int can
    112       1.1    chopps  * compare both values to determine the older packet.
    113       1.1    chopps  *
    114       1.1    chopps  * Transmit direction:
    115       1.1    chopps  *
    116       1.1    chopps  * bah_start checks tx_fillcount
    117       1.1    chopps  * case 2: return
    118       1.1    chopps  *
    119       1.1    chopps  * else fill tx_act ^ 1 && inc tx_fillcount
    120       1.1    chopps  *
    121       1.1    chopps  * check tx_fillcount again.
    122       1.1    chopps  * case 2: set IFF_OACTIVE to stop arc_output from filling us.
    123       1.1    chopps  * case 1: start tx
    124       1.1    chopps  *
    125       1.1    chopps  * tint clears IFF_OCATIVE, decrements and checks tx_fillcount
    126       1.1    chopps  * case 1: start tx on tx_act ^ 1, softcall bah_start
    127       1.1    chopps  * case 0: softcall bah_start
    128       1.1    chopps  *
    129       1.1    chopps  * #define fill(i) get mbuf && copy mbuf to chip(i)
    130       1.1    chopps  */
    131       1.1    chopps 
    132       1.8       cgd void	bah_init __P((struct bah_softc *));
    133       1.7       cgd void	bah_reset __P((struct bah_softc *));
    134       1.7       cgd void	bah_stop __P((struct bah_softc *));
    135       1.7       cgd void	bah_start __P((struct ifnet *));
    136      1.25        is int	bahintr __P((void *));
    137       1.7       cgd int	bah_ioctl __P((struct ifnet *, unsigned long, caddr_t));
    138      1.17   thorpej void	bah_watchdog __P((struct ifnet *));
    139      1.25        is void	bah_srint __P((void *vsc));
    140      1.25        is static	void bah_tint __P((struct bah_softc *, int));
    141      1.25        is void	bah_reconwatch(void *);
    142      1.25        is 
    143      1.25        is /* short notation */
    144      1.25        is 
    145      1.25        is #define GETREG(off)	bus_space_read_1(bst_r, regs, (off))
    146      1.25        is #define PUTREG(off, v)	bus_space_write_1(bst_r, regs, (off), (v))
    147      1.25        is #define GETMEM(off)	bus_space_read_1(bst_m, mem, (off))
    148      1.25        is #define PUTMEM(off, v)	bus_space_write_1(bst_m, mem, (off), (v))
    149       1.1    chopps 
    150       1.1    chopps void
    151      1.25        is bah_attach_subr(sc)
    152      1.25        is 	struct bah_softc *sc;
    153       1.1    chopps {
    154       1.4   mycroft 	struct ifnet *ifp = &sc->sc_arccom.ac_if;
    155      1.25        is 	int s;
    156      1.25        is 	u_int8_t linkaddress;
    157      1.25        is 
    158      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
    159      1.25        is 	bus_space_tag_t bst_m = sc->sc_bst_m;
    160      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
    161      1.25        is 	bus_space_handle_t mem = sc->sc_mem;
    162       1.1    chopps 
    163       1.1    chopps #if (defined(BAH_DEBUG) && (BAH_DEBUG > 2))
    164      1.19  christos 	printf("\n%s: attach(0x%x, 0x%x, 0x%x)\n",
    165       1.4   mycroft 	    sc->sc_dev.dv_xname, parent, self, aux);
    166       1.1    chopps #endif
    167       1.1    chopps 	s = splhigh();
    168       1.1    chopps 
    169       1.1    chopps 	/*
    170       1.1    chopps 	 * read the arcnet address from the board
    171       1.1    chopps 	 */
    172       1.1    chopps 
    173      1.25        is 	(*sc->sc_reset)(sc, 1);
    174       1.1    chopps 
    175       1.1    chopps 	do {
    176      1.25        is 		delay(200);
    177      1.25        is 	} while (!(GETREG(BAHSTAT) & BAH_POR));
    178       1.1    chopps 
    179      1.25        is 	linkaddress = GETMEM(BAHMACOFF);
    180       1.1    chopps 
    181      1.25        is 	printf(": link addr 0x%02x(%d)\n", linkaddress, linkaddress);
    182       1.1    chopps 
    183       1.1    chopps 	/* clear the int mask... */
    184       1.1    chopps 
    185      1.25        is 	sc->sc_intmask = 0;
    186      1.25        is 	PUTREG(BAHSTAT, 0);
    187       1.1    chopps 
    188      1.25        is 	PUTREG(BAHCMD, BAH_CONF(CONF_LONG));
    189      1.25        is 	PUTREG(BAHCMD, BAH_CLR(CLR_POR|CLR_RECONFIG));
    190       1.3    chopps 	sc->sc_recontime = sc->sc_reconcount = 0;
    191       1.1    chopps 
    192       1.1    chopps 	/* and reenable kernel int level */
    193       1.1    chopps 	splx(s);
    194       1.1    chopps 
    195       1.1    chopps 	/*
    196       1.1    chopps 	 * set interface to stopped condition (reset)
    197       1.1    chopps 	 */
    198       1.1    chopps 	bah_stop(sc);
    199       1.1    chopps 
    200      1.17   thorpej 	bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
    201      1.17   thorpej 	ifp->if_softc = sc;
    202       1.1    chopps 	ifp->if_start = bah_start;
    203       1.1    chopps 	ifp->if_ioctl = bah_ioctl;
    204       1.6    chopps 	ifp->if_timer = 0;
    205       1.6    chopps 	ifp->if_watchdog  = bah_watchdog;
    206       1.6    chopps 
    207      1.25        is 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
    208       1.6    chopps 
    209       1.6    chopps 	ifp->if_mtu = ARCMTU;
    210       1.1    chopps 
    211      1.25        is 	arc_ifattach(ifp, linkaddress);
    212       1.1    chopps 
    213       1.1    chopps #if NBPFILTER > 0
    214       1.4   mycroft 	bpfattach(&ifp->if_bpf, ifp, DLT_ARCNET, ARC_HDRLEN);
    215       1.1    chopps #endif
    216      1.25        is #ifdef BAHSOFTCOPY
    217      1.27        is 	sc->sc_rxcookie = softintr_establish(IPL_SOFTNET, bah_srint, sc);
    218      1.27        is 	sc->sc_txcookie = softintr_establish(IPL_SOFTNET,
    219      1.27        is 		(void (*) __P((void *)))bah_start, ifp);
    220      1.25        is #endif
    221      1.25        is 
    222  1.33.2.1    bouyer 	callout_init(&sc->sc_recon_ch);
    223       1.1    chopps }
    224       1.1    chopps 
    225       1.1    chopps /*
    226       1.1    chopps  * Initialize device
    227       1.1    chopps  *
    228       1.1    chopps  */
    229       1.1    chopps void
    230       1.1    chopps bah_init(sc)
    231       1.1    chopps 	struct bah_softc *sc;
    232       1.1    chopps {
    233       1.3    chopps 	struct ifnet *ifp;
    234       1.1    chopps 	int s;
    235       1.3    chopps 
    236       1.3    chopps 	ifp = &sc->sc_arccom.ac_if;
    237       1.1    chopps 
    238       1.1    chopps 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
    239      1.13   mycroft 		s = splnet();
    240       1.1    chopps 		ifp->if_flags |= IFF_RUNNING;
    241       1.1    chopps 		bah_reset(sc);
    242       1.4   mycroft 		bah_start(ifp);
    243       1.1    chopps 		splx(s);
    244       1.1    chopps 	}
    245       1.1    chopps }
    246       1.1    chopps 
    247       1.1    chopps /*
    248       1.1    chopps  * Reset the interface...
    249       1.1    chopps  *
    250       1.1    chopps  * this assumes that it is called inside a critical section...
    251       1.1    chopps  *
    252       1.1    chopps  */
    253       1.1    chopps void
    254       1.1    chopps bah_reset(sc)
    255       1.1    chopps 	struct bah_softc *sc;
    256       1.1    chopps {
    257       1.3    chopps 	struct ifnet *ifp;
    258      1.14    chopps 	int linkaddress;
    259       1.1    chopps 
    260      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
    261      1.25        is         bus_space_tag_t bst_m = sc->sc_bst_m;
    262      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
    263      1.25        is 	bus_space_handle_t mem = sc->sc_mem;
    264      1.25        is 
    265       1.1    chopps 	ifp = &sc->sc_arccom.ac_if;
    266       1.1    chopps 
    267       1.1    chopps #ifdef BAH_DEBUG
    268      1.19  christos 	printf("%s: reset\n", sc->sc_dev.dv_xname);
    269       1.1    chopps #endif
    270      1.25        is 	/* stop and restart hardware */
    271       1.1    chopps 
    272      1.25        is 	(*sc->sc_reset)(sc, 1);
    273       1.1    chopps 	do {
    274      1.14    chopps 		DELAY(200);
    275      1.25        is 	} while (!(GETREG(BAHSTAT) & BAH_POR));
    276       1.1    chopps 
    277      1.25        is 	linkaddress = GETMEM(BAHMACOFF);
    278       1.6    chopps 
    279       1.1    chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 2)
    280      1.19  christos 	printf("%s: reset: card reset, link addr = 0x%02x (%ld)\n",
    281      1.17   thorpej 	    sc->sc_dev.dv_xname, linkaddress, linkaddress);
    282       1.1    chopps #endif
    283       1.6    chopps 
    284       1.6    chopps 	/* tell the routing level about the (possibly changed) link address */
    285      1.32        is 	arc_storelladdr(ifp, linkaddress);
    286       1.6    chopps 
    287       1.1    chopps 	/* POR is NMI, but we need it below: */
    288      1.25        is 	sc->sc_intmask = BAH_RECON|BAH_POR;
    289      1.25        is 	PUTREG(BAHSTAT, sc->sc_intmask);
    290      1.25        is 	PUTREG(BAHCMD, BAH_CONF(CONF_LONG));
    291       1.1    chopps 
    292       1.1    chopps #ifdef BAH_DEBUG
    293      1.19  christos 	printf("%s: reset: chip configured, status=0x%02x\n",
    294      1.25        is 	    sc->sc_dev.dv_xname, GETREG(BAHSTAT));
    295       1.1    chopps #endif
    296      1.25        is 	PUTREG(BAHCMD, BAH_CLR(CLR_POR|CLR_RECONFIG));
    297       1.1    chopps 
    298       1.1    chopps #ifdef BAH_DEBUG
    299      1.19  christos 	printf("%s: reset: bits cleared, status=0x%02x\n",
    300      1.25        is 	    sc->sc_dev.dv_xname, GETREG(BAHSTAT);
    301       1.1    chopps #endif
    302       1.1    chopps 
    303       1.1    chopps 	sc->sc_reconcount_excessive = ARC_EXCESSIVE_RECONS;
    304       1.1    chopps 
    305       1.1    chopps 	/* start receiver */
    306       1.1    chopps 
    307      1.25        is 	sc->sc_intmask  |= BAH_RI;
    308      1.14    chopps 	sc->sc_rx_fillcount = 0;
    309       1.1    chopps 	sc->sc_rx_act = 2;
    310       1.1    chopps 
    311      1.25        is 	PUTREG(BAHCMD, BAH_RXBC(2));
    312      1.25        is 	PUTREG(BAHSTAT, sc->sc_intmask);
    313       1.1    chopps 
    314       1.1    chopps #ifdef BAH_DEBUG
    315      1.19  christos 	printf("%s: reset: started receiver, status=0x%02x\n",
    316      1.25        is 	    sc->sc_dev.dv_xname, GETREG(BAHSTAT);
    317       1.1    chopps #endif
    318       1.1    chopps 
    319       1.1    chopps 	/* and init transmitter status */
    320       1.1    chopps 	sc->sc_tx_act = 0;
    321       1.1    chopps 	sc->sc_tx_fillcount = 0;
    322       1.1    chopps 
    323       1.1    chopps 	ifp->if_flags |= IFF_RUNNING;
    324       1.1    chopps 	ifp->if_flags &= ~IFF_OACTIVE;
    325       1.1    chopps 
    326       1.1    chopps 	bah_start(ifp);
    327       1.1    chopps }
    328       1.1    chopps 
    329       1.1    chopps /*
    330       1.1    chopps  * Take interface offline
    331       1.1    chopps  */
    332       1.1    chopps void
    333       1.1    chopps bah_stop(sc)
    334       1.1    chopps 	struct bah_softc *sc;
    335       1.1    chopps {
    336      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
    337      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
    338      1.25        is 
    339       1.1    chopps 	/* Stop the interrupts */
    340      1.25        is 	PUTREG(BAHSTAT, 0);
    341       1.1    chopps 
    342       1.1    chopps 	/* Stop the interface */
    343      1.25        is 	(*sc->sc_reset)(sc, 0);
    344       1.1    chopps 
    345       1.6    chopps 	/* Stop watchdog timer */
    346       1.6    chopps 	sc->sc_arccom.ac_if.if_timer = 0;
    347       1.1    chopps }
    348       1.1    chopps 
    349       1.1    chopps /*
    350       1.1    chopps  * Start output on interface. Get another datagram to send
    351       1.1    chopps  * off the interface queue, and copy it to the
    352       1.1    chopps  * interface becore starting the output
    353       1.1    chopps  *
    354       1.1    chopps  * this assumes that it is called inside a critical section...
    355       1.1    chopps  * XXX hm... does it still?
    356       1.1    chopps  *
    357       1.1    chopps  */
    358       1.4   mycroft void
    359       1.1    chopps bah_start(ifp)
    360       1.1    chopps 	struct ifnet *ifp;
    361       1.1    chopps {
    362      1.25        is 	struct bah_softc *sc = ifp->if_softc;
    363       1.1    chopps 	struct mbuf *m,*mp;
    364      1.25        is 
    365      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
    366      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
    367      1.25        is 	bus_space_tag_t bst_m = sc->sc_bst_m;
    368      1.25        is 	bus_space_handle_t mem = sc->sc_mem;
    369      1.25        is 
    370      1.25        is 	int bah_ram_ptr;
    371      1.14    chopps 	int len, tlen, offset, s, buffer;
    372       1.1    chopps #ifdef BAHTIMINGS
    373       1.7       cgd 	u_long copystart, lencopy, perbyte;
    374       1.1    chopps #endif
    375       1.1    chopps 
    376       1.1    chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 3)
    377      1.19  christos 	printf("%s: start(0x%x)\n", sc->sc_dev.dv_xname, ifp);
    378       1.1    chopps #endif
    379       1.1    chopps 
    380       1.4   mycroft 	if ((ifp->if_flags & IFF_RUNNING) == 0)
    381       1.5    chopps 		return;
    382       1.1    chopps 
    383      1.13   mycroft 	s = splnet();
    384       1.1    chopps 
    385       1.1    chopps 	if (sc->sc_tx_fillcount >= 2) {
    386       1.1    chopps 		splx(s);
    387       1.5    chopps 		return;
    388       1.1    chopps 	}
    389       1.1    chopps 
    390       1.1    chopps 	IF_DEQUEUE(&ifp->if_snd, m);
    391       1.1    chopps 	buffer = sc->sc_tx_act ^ 1;
    392       1.1    chopps 
    393       1.1    chopps 	splx(s);
    394       1.1    chopps 
    395       1.1    chopps 	if (m == 0)
    396       1.5    chopps 		return;
    397       1.1    chopps 
    398       1.1    chopps #if NBPFILTER > 0
    399       1.1    chopps 	/*
    400       1.1    chopps 	 * If bpf is listening on this interface, let it
    401       1.1    chopps 	 * see the packet before we commit it to the wire
    402       1.1    chopps 	 *
    403       1.1    chopps 	 * (can't give the copy in A2060 card RAM to bpf, because
    404       1.1    chopps 	 * that RAM is just accessed as on every other byte)
    405       1.1    chopps 	 */
    406       1.4   mycroft 	if (ifp->if_bpf)
    407       1.4   mycroft 		bpf_mtap(ifp->if_bpf, m);
    408       1.4   mycroft #endif
    409       1.1    chopps 
    410       1.1    chopps #ifdef BAH_DEBUG
    411      1.33        is 	if (m->m_len < ARC_HDRLEN)
    412      1.33        is 		m = m_pullup(m, ARC_HDRLEN);/* gcc does structure padding */
    413      1.19  christos 	printf("%s: start: filling %ld from %ld to %ld type %ld\n",
    414       1.7       cgd 	    sc->sc_dev.dv_xname, buffer, mtod(m, u_char *)[0],
    415       1.7       cgd 	    mtod(m, u_char *)[1], mtod(m, u_char *)[2]);
    416       1.1    chopps #else
    417      1.33        is 	if (m->m_len < 2)
    418      1.33        is 		m = m_pullup(m, 2);
    419       1.1    chopps #endif
    420      1.25        is 	bah_ram_ptr = buffer*512;
    421       1.1    chopps 
    422      1.33        is 	if (m == 0)
    423      1.33        is 		return;
    424      1.33        is 
    425       1.1    chopps 	/* write the addresses to RAM and throw them away */
    426       1.1    chopps 
    427       1.1    chopps 	/*
    428       1.1    chopps 	 * Hardware does this: Yet Another Microsecond Saved.
    429       1.1    chopps 	 * (btw, timing code says usually 2 microseconds)
    430      1.25        is 	 * PUTMEM(bah_ram_ptr + 0, mtod(m, u_char *)[0]);
    431       1.1    chopps 	 */
    432      1.25        is 
    433      1.25        is 	PUTMEM(bah_ram_ptr + 1, mtod(m, u_char *)[1]);
    434       1.4   mycroft 	m_adj(m, 2);
    435       1.1    chopps 
    436      1.14    chopps 	/* get total length left at this point */
    437      1.14    chopps 	tlen = m->m_pkthdr.len;
    438       1.3    chopps 	if (tlen < ARC_MIN_FORBID_LEN) {
    439       1.7       cgd 		offset = 256 - tlen;
    440      1.25        is 		PUTMEM(bah_ram_ptr + 2, offset);
    441       1.3    chopps 	} else {
    442      1.25        is 		PUTMEM(bah_ram_ptr + 2, 0);
    443      1.14    chopps 		if (tlen <= ARC_MAX_FORBID_LEN)
    444      1.14    chopps 			offset = 255;		/* !!! */
    445       1.1    chopps 		else {
    446       1.1    chopps 			if (tlen > ARC_MAX_LEN)
    447       1.1    chopps 				tlen = ARC_MAX_LEN;
    448       1.7       cgd 			offset = 512 - tlen;
    449       1.1    chopps 		}
    450      1.25        is 		PUTMEM(bah_ram_ptr + 3, offset);
    451       1.1    chopps 
    452       1.1    chopps 	}
    453      1.25        is 	bah_ram_ptr += offset;
    454       1.1    chopps 
    455      1.14    chopps 	/* lets loop through the mbuf chain */
    456       1.1    chopps 
    457       1.7       cgd 	for (mp = m; mp; mp = mp->m_next) {
    458      1.14    chopps 		if ((len = mp->m_len)) {		/* YAMS */
    459      1.25        is 			bus_space_write_region_1(bst_m, mem, bah_ram_ptr,
    460      1.25        is 			    mtod(mp, caddr_t), len);
    461       1.1    chopps 
    462      1.25        is 			bah_ram_ptr += len;
    463       1.1    chopps 		}
    464       1.1    chopps 	}
    465       1.1    chopps 
    466       1.1    chopps 	sc->sc_broadcast[buffer] = (m->m_flags & M_BCAST) != 0;
    467       1.4   mycroft 	sc->sc_retransmits[buffer] = (m->m_flags & M_BCAST) ? 1 : 5;
    468       1.1    chopps 
    469       1.1    chopps 	/* actually transmit the packet */
    470      1.13   mycroft 	s = splnet();
    471       1.1    chopps 
    472       1.3    chopps 	if (++sc->sc_tx_fillcount > 1) {
    473       1.3    chopps 		/*
    474       1.3    chopps 		 * We are filled up to the rim. No more bufs for the moment,
    475       1.3    chopps 		 * please.
    476       1.3    chopps 		 */
    477       1.3    chopps 		ifp->if_flags |= IFF_OACTIVE;
    478       1.3    chopps 	} else {
    479       1.1    chopps #ifdef BAH_DEBUG
    480      1.19  christos 		printf("%s: start: starting transmitter on buffer %d\n",
    481       1.4   mycroft 		    sc->sc_dev.dv_xname, buffer);
    482       1.1    chopps #endif
    483       1.1    chopps 		/* Transmitter was off, start it */
    484       1.1    chopps 		sc->sc_tx_act = buffer;
    485       1.1    chopps 
    486       1.1    chopps 		/*
    487       1.1    chopps 		 * We still can accept another buf, so don't:
    488       1.1    chopps 		 * ifp->if_flags |= IFF_OACTIVE;
    489       1.1    chopps 		 */
    490      1.25        is 		sc->sc_intmask |= BAH_TA;
    491      1.25        is 		PUTREG(BAHCMD, BAH_TX(buffer));
    492      1.25        is 		PUTREG(BAHSTAT, sc->sc_intmask);
    493       1.1    chopps 
    494       1.6    chopps 		sc->sc_arccom.ac_if.if_timer = ARCTIMEOUT;
    495       1.1    chopps 	}
    496       1.1    chopps 	splx(s);
    497       1.1    chopps 	m_freem(m);
    498       1.1    chopps 
    499       1.1    chopps 	/*
    500       1.6    chopps 	 * After 10 times reading the docs, I realized
    501       1.6    chopps 	 * that in the case the receiver NAKs the buffer request,
    502       1.1    chopps 	 * the hardware retries till shutdown.
    503       1.6    chopps 	 * This is integrated now in the code above.
    504       1.1    chopps 	 */
    505       1.6    chopps 
    506       1.6    chopps 	return;
    507       1.1    chopps }
    508       1.1    chopps 
    509       1.1    chopps /*
    510       1.1    chopps  * Arcnet interface receiver soft interrupt:
    511       1.1    chopps  * get the stuff out of any filled buffer we find.
    512       1.1    chopps  */
    513       1.1    chopps void
    514      1.25        is bah_srint(vsc)
    515      1.25        is 	void *vsc;
    516      1.14    chopps {
    517      1.25        is 	struct bah_softc *sc = (struct bah_softc *)vsc;
    518      1.25        is 	int buffer, len, len1, amount, offset, s, type;
    519      1.25        is 	int bah_ram_ptr;
    520       1.3    chopps 	struct mbuf *m, *dst, *head;
    521       1.3    chopps 	struct arc_header *ah;
    522       1.5    chopps 	struct ifnet *ifp;
    523      1.25        is 
    524      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
    525      1.25        is         bus_space_tag_t bst_m = sc->sc_bst_m;
    526      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
    527      1.25        is 	bus_space_handle_t mem = sc->sc_mem;
    528      1.25        is 
    529      1.14    chopps 	ifp = &sc->sc_arccom.ac_if;
    530       1.3    chopps 	head = 0;
    531       1.1    chopps 
    532      1.13   mycroft 	s = splnet();
    533      1.14    chopps 	buffer = sc->sc_rx_act ^ 1;
    534       1.1    chopps 	splx(s);
    535       1.1    chopps 
    536       1.1    chopps 	/* Allocate header mbuf */
    537       1.1    chopps 	MGETHDR(m, M_DONTWAIT, MT_DATA);
    538       1.1    chopps 
    539       1.1    chopps 	if (m == 0) {
    540       1.1    chopps 		/*
    541       1.1    chopps 	 	 * in case s.th. goes wrong with mem, drop it
    542       1.1    chopps 	 	 * to make sure the receiver can be started again
    543       1.1    chopps 		 * count it as input error (we dont have any other
    544       1.1    chopps 		 * detectable)
    545       1.1    chopps 	 	 */
    546       1.5    chopps 		ifp->if_ierrors++;
    547       1.1    chopps 		goto cleanup;
    548       1.1    chopps 	}
    549       1.1    chopps 
    550       1.5    chopps 	m->m_pkthdr.rcvif = ifp;
    551       1.1    chopps 
    552       1.1    chopps 	/*
    553       1.1    chopps 	 * Align so that IP packet will be longword aligned. Here we
    554       1.1    chopps 	 * assume that m_data of new packet is longword aligned.
    555       1.8       cgd 	 * When implementing PHDS, we might have to change it to 2,
    556       1.8       cgd 	 * (2*sizeof(ulong) - ARC_HDRNEWLEN)), packet type dependent.
    557       1.1    chopps 	 */
    558       1.1    chopps 
    559      1.25        is 	bah_ram_ptr = buffer*512;
    560      1.25        is 	offset = GETMEM(bah_ram_ptr + 2);
    561       1.3    chopps 	if (offset)
    562       1.1    chopps 		len = 256 - offset;
    563       1.3    chopps 	else {
    564      1.25        is 		offset = GETMEM(bah_ram_ptr + 3);
    565       1.1    chopps 		len = 512 - offset;
    566       1.1    chopps 	}
    567      1.33        is 	if (len+2 >= MINCLSIZE)
    568      1.33        is 		MCLGET(m, M_DONTWAIT);
    569      1.33        is 
    570      1.33        is 	if (m == 0) {
    571      1.33        is 		ifp->if_ierrors++;
    572      1.33        is 		goto cleanup;
    573      1.33        is 	}
    574      1.33        is 
    575      1.25        is 	type = GETMEM(bah_ram_ptr + offset);
    576       1.8       cgd 	m->m_data += 1 + arc_isphds(type);
    577       1.8       cgd 
    578       1.8       cgd 	head = m;
    579       1.8       cgd 	ah = mtod(head, struct arc_header *);
    580       1.8       cgd 
    581      1.25        is 	ah->arc_shost = GETMEM(bah_ram_ptr + 0);
    582      1.25        is 	ah->arc_dhost = GETMEM(bah_ram_ptr + 1);
    583       1.8       cgd 
    584       1.8       cgd 	m->m_pkthdr.len = len+2; /* whole packet length */
    585       1.8       cgd 	m->m_len = 2;		 /* mbuf filled with ARCnet addresses */
    586      1.25        is 	bah_ram_ptr += offset;	/* ram buffer continues there */
    587       1.1    chopps 
    588       1.1    chopps 	while (len > 0) {
    589       1.1    chopps 
    590       1.1    chopps 		len1 = len;
    591       1.1    chopps 		amount = M_TRAILINGSPACE(m);
    592       1.1    chopps 
    593       1.1    chopps 		if (amount == 0) {
    594       1.1    chopps 			dst = m;
    595       1.1    chopps 			MGET(m, M_DONTWAIT, MT_DATA);
    596       1.1    chopps 
    597       1.1    chopps 			if (m == 0) {
    598       1.5    chopps 				ifp->if_ierrors++;
    599       1.1    chopps 				goto cleanup;
    600       1.1    chopps 			}
    601       1.1    chopps 
    602      1.25        is 			if (len1 >= MINCLSIZE)
    603       1.1    chopps 				MCLGET(m, M_DONTWAIT);
    604      1.25        is 
    605       1.1    chopps 			m->m_len = 0;
    606       1.1    chopps 			dst->m_next = m;
    607       1.1    chopps 			amount = M_TRAILINGSPACE(m);
    608       1.1    chopps 		}
    609       1.1    chopps 
    610       1.1    chopps 		if (amount < len1)
    611       1.1    chopps 			len1 = amount;
    612       1.1    chopps 
    613      1.25        is 		bus_space_read_region_1(bst_m, mem, bah_ram_ptr,
    614      1.25        is 		    mtod(m, u_char *) + m->m_len, len1);
    615       1.1    chopps 
    616       1.1    chopps 		m->m_len += len1;
    617      1.25        is 		bah_ram_ptr += len1;
    618       1.1    chopps 		len -= len1;
    619       1.1    chopps 	}
    620       1.1    chopps 
    621       1.1    chopps #if NBPFILTER > 0
    622       1.4   mycroft 	if (ifp->if_bpf)
    623       1.4   mycroft 		bpf_mtap(ifp->if_bpf, head);
    624       1.1    chopps #endif
    625       1.1    chopps 
    626      1.30   thorpej 	(*sc->sc_arccom.ac_if.if_input)(&sc->sc_arccom.ac_if, head);
    627       1.1    chopps 
    628       1.1    chopps 	head = NULL;
    629       1.5    chopps 	ifp->if_ipackets++;
    630       1.1    chopps 
    631       1.1    chopps cleanup:
    632       1.1    chopps 
    633      1.14    chopps 	if (head != NULL)
    634       1.1    chopps 		m_freem(head);
    635       1.1    chopps 
    636      1.16        is 	/* mark buffer as invalid by source id 0 */
    637      1.25        is 	bus_space_write_1(bst_m, mem, buffer*512, 0);
    638      1.13   mycroft 	s = splnet();
    639       1.1    chopps 
    640      1.14    chopps 	if (--sc->sc_rx_fillcount == 2 - 1) {
    641       1.1    chopps 
    642       1.1    chopps 		/* was off, restart it on buffer just emptied */
    643       1.1    chopps 		sc->sc_rx_act = buffer;
    644      1.25        is 		sc->sc_intmask |= BAH_RI;
    645       1.1    chopps 
    646       1.1    chopps 		/* this also clears the RI flag interupt: */
    647      1.25        is 		PUTREG(BAHCMD, BAH_RXBC(buffer));
    648      1.25        is 		PUTREG(BAHSTAT, sc->sc_intmask);
    649       1.1    chopps 
    650       1.1    chopps #ifdef BAH_DEBUG
    651      1.19  christos 		printf("%s: srint: restarted rx on buf %ld\n",
    652       1.4   mycroft 		    sc->sc_dev.dv_xname, buffer);
    653       1.1    chopps #endif
    654       1.1    chopps 	}
    655       1.1    chopps 	splx(s);
    656       1.1    chopps }
    657       1.1    chopps 
    658       1.7       cgd __inline static void
    659      1.14    chopps bah_tint(sc, isr)
    660       1.1    chopps 	struct bah_softc *sc;
    661      1.14    chopps 	int isr;
    662       1.1    chopps {
    663      1.14    chopps 	struct ifnet *ifp;
    664      1.14    chopps 
    665      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
    666      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
    667      1.25        is 
    668      1.25        is 
    669       1.1    chopps 	int buffer;
    670      1.14    chopps #ifdef BAHTIMINGS
    671       1.1    chopps 	int clknow;
    672      1.14    chopps #endif
    673       1.1    chopps 
    674      1.14    chopps 	ifp = &(sc->sc_arccom.ac_if);
    675       1.1    chopps 	buffer = sc->sc_tx_act;
    676       1.1    chopps 
    677       1.6    chopps 	/*
    678      1.14    chopps 	 * retransmit code:
    679      1.14    chopps 	 * Normal situtations first for fast path:
    680      1.14    chopps 	 * If acknowledgement received ok or broadcast, we're ok.
    681      1.14    chopps 	 * else if
    682       1.6    chopps 	 */
    683       1.1    chopps 
    684      1.25        is 	if (isr & BAH_TMA || sc->sc_broadcast[buffer])
    685      1.14    chopps 		sc->sc_arccom.ac_if.if_opackets++;
    686      1.14    chopps #ifdef BAHRETRANSMIT
    687      1.14    chopps 	else if (ifp->if_flags & IFF_LINK2 && ifp->if_timer > 0
    688      1.14    chopps 	    && --sc->sc_retransmits[buffer] > 0) {
    689      1.14    chopps 		/* retransmit same buffer */
    690      1.25        is 		PUTREG(BAHCMD, BAH_TX(buffer));
    691      1.14    chopps 		return;
    692      1.14    chopps 	}
    693      1.14    chopps #endif
    694       1.3    chopps 	else
    695      1.14    chopps 		ifp->if_oerrors++;
    696      1.14    chopps 
    697      1.14    chopps 
    698       1.1    chopps 	/* We know we can accept another buffer at this point. */
    699      1.14    chopps 	ifp->if_flags &= ~IFF_OACTIVE;
    700       1.1    chopps 
    701       1.1    chopps 	if (--sc->sc_tx_fillcount > 0) {
    702       1.1    chopps 
    703       1.1    chopps 		/*
    704       1.1    chopps 		 * start tx on other buffer.
    705       1.1    chopps 		 * This also clears the int flag
    706       1.1    chopps 		 */
    707       1.1    chopps 		buffer ^= 1;
    708       1.1    chopps 		sc->sc_tx_act = buffer;
    709       1.1    chopps 
    710       1.1    chopps 		/*
    711       1.1    chopps 		 * already given:
    712      1.25        is 		 * sc->sc_intmask |= BAH_TA;
    713      1.25        is 		 * PUTREG(BAHSTAT, sc->sc_intmask);
    714       1.1    chopps 		 */
    715      1.25        is 		PUTREG(BAHCMD, BAH_TX(buffer));
    716       1.6    chopps 		/* init watchdog timer */
    717      1.14    chopps 		ifp->if_timer = ARCTIMEOUT;
    718       1.1    chopps 
    719       1.1    chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 1)
    720      1.19  christos 		printf("%s: tint: starting tx on buffer %d, status 0x%02x\n",
    721      1.25        is 		    sc->sc_dev.dv_xname, buffer, GETREG(BAHSTAT));
    722       1.1    chopps #endif
    723       1.1    chopps 	} else {
    724       1.1    chopps 		/* have to disable TX interrupt */
    725      1.25        is 		sc->sc_intmask &= ~BAH_TA;
    726      1.25        is 		PUTREG(BAHSTAT, sc->sc_intmask);
    727       1.6    chopps 		/* ... and watchdog timer */
    728      1.14    chopps 		ifp->if_timer = 0;
    729       1.1    chopps 
    730       1.1    chopps #ifdef BAH_DEBUG
    731      1.19  christos 		printf("%s: tint: no more buffers to send, status 0x%02x\n",
    732      1.25        is 		    sc->sc_dev.dv_xname, GETREG(BAHSTAT));
    733       1.1    chopps #endif
    734       1.1    chopps 	}
    735       1.1    chopps 
    736      1.25        is 	/* XXXX TODO */
    737       1.1    chopps #ifdef BAHSOFTCOPY
    738       1.1    chopps 	/* schedule soft int to fill a new buffer for us */
    739      1.27        is 	softintr_schedule(sc->sc_txcookie);
    740       1.1    chopps #else
    741       1.1    chopps 	/* call it directly */
    742      1.26        is 	bah_start(ifp);
    743       1.1    chopps #endif
    744       1.1    chopps }
    745       1.1    chopps 
    746       1.1    chopps /*
    747       1.1    chopps  * Our interrupt routine
    748       1.1    chopps  */
    749       1.1    chopps int
    750      1.25        is bahintr(arg)
    751      1.25        is 	void *arg;
    752       1.1    chopps {
    753      1.25        is 	struct bah_softc *sc = arg;
    754      1.25        is 
    755      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
    756      1.25        is         bus_space_tag_t bst_m = sc->sc_bst_m;
    757      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
    758      1.25        is 	bus_space_handle_t mem = sc->sc_mem;
    759      1.25        is 
    760      1.11    chopps 	u_char isr, maskedisr;
    761       1.1    chopps 	int buffer;
    762       1.1    chopps 	u_long newsec;
    763       1.1    chopps 
    764      1.25        is 	isr = GETREG(BAHSTAT);
    765      1.11    chopps 	maskedisr = isr & sc->sc_intmask;
    766      1.11    chopps 	if (!maskedisr)
    767       1.3    chopps 		return (0);
    768      1.25        is 	do {
    769       1.1    chopps 
    770       1.1    chopps #if defined(BAH_DEBUG) && (BAH_DEBUG>1)
    771      1.25        is 		printf("%s: intr: status 0x%02x, intmask 0x%02x\n",
    772      1.25        is 		    sc->sc_dev.dv_xname, isr, sc->sc_intmask);
    773       1.1    chopps #endif
    774       1.1    chopps 
    775      1.25        is 		if (maskedisr & BAH_POR) {
    776      1.25        is 		  	/*
    777      1.25        is 			 * XXX We should never see this. Don't bother to store
    778      1.25        is 			 * the address.
    779      1.25        is 			 * sc->sc_arccom.ac_anaddr = GETMEM(BAHMACOFF);
    780      1.25        is 			 */
    781      1.25        is 			PUTREG(BAHCMD, BAH_CLR(CLR_POR));
    782       1.3    chopps 			log(LOG_WARNING,
    783      1.25        is 			    "%s: intr: got spurious power on reset int\n",
    784       1.4   mycroft 			    sc->sc_dev.dv_xname);
    785       1.1    chopps 		}
    786       1.1    chopps 
    787      1.25        is 		if (maskedisr & BAH_RECON) {
    788      1.16        is 			/*
    789      1.25        is 			 * we dont need to:
    790      1.25        is 			 * PUTREG(BAHCMD, BAH_CONF(CONF_LONG));
    791      1.16        is 			 */
    792      1.25        is 			PUTREG(BAHCMD, BAH_CLR(CLR_RECONFIG));
    793      1.25        is 			sc->sc_arccom.ac_if.if_collisions++;
    794      1.25        is 
    795       1.1    chopps 			/*
    796      1.25        is 			 * If less than 2 seconds per reconfig:
    797      1.25        is 			 *	If ARC_EXCESSIVE_RECONFIGS
    798      1.25        is 			 *	since last burst, complain and set treshold for
    799      1.25        is 			 *	warnings to ARC_EXCESSIVE_RECONS_REWARN.
    800      1.25        is 			 *
    801      1.25        is 			 * This allows for, e.g., new stations on the cable, or
    802      1.25        is 			 * cable switching as long as it is over after
    803      1.25        is 			 * (normally) 16 seconds.
    804      1.25        is 			 *
    805      1.25        is 			 * XXX TODO: check timeout bits in status word and
    806      1.25        is 			 * double time if necessary.
    807       1.1    chopps 			 */
    808      1.25        is 
    809  1.33.2.1    bouyer 			callout_stop(&sc->sc_recon_ch);
    810      1.25        is 			newsec = time.tv_sec;
    811      1.25        is 			if ((newsec - sc->sc_recontime <= 2) &&
    812      1.25        is 			    (++sc->sc_reconcount == ARC_EXCESSIVE_RECONS)) {
    813      1.25        is 				log(LOG_WARNING,
    814      1.25        is 				    "%s: excessive token losses, "
    815      1.25        is 				    "cable problem?\n", sc->sc_dev.dv_xname);
    816      1.25        is 			}
    817      1.25        is 			sc->sc_recontime = newsec;
    818  1.33.2.1    bouyer 			callout_reset(&sc->sc_recon_ch, 15 * hz,
    819  1.33.2.1    bouyer 			    bah_reconwatch, (void *)sc);
    820      1.25        is 		}
    821      1.25        is 
    822      1.25        is 		if (maskedisr & BAH_RI) {
    823      1.25        is #if defined(BAH_DEBUG) && (BAH_DEBUG > 1)
    824      1.25        is 			printf("%s: intr: hard rint, act %ld\n",
    825      1.25        is 			    sc->sc_dev.dv_xname, sc->sc_rx_act);
    826      1.25        is #endif
    827       1.1    chopps 
    828      1.25        is 			buffer = sc->sc_rx_act;
    829      1.25        is 			/* look if buffer is marked invalid: */
    830      1.25        is 			if (GETMEM(buffer*512) == 0) {
    831      1.25        is 				/*
    832      1.25        is 				 * invalid marked buffer (or illegally
    833      1.25        is 				 * configured sender)
    834      1.25        is 				 */
    835      1.25        is 				log(LOG_WARNING,
    836      1.25        is 				    "%s: spurious RX interupt or sender 0 "
    837      1.25        is 				    " (ignored)\n", sc->sc_dev.dv_xname);
    838      1.25        is 				/*
    839      1.25        is 				 * restart receiver on same buffer.
    840      1.25        is 				 * XXX maybe better reset interface?
    841      1.25        is 				 */
    842      1.25        is 				PUTREG(BAHCMD, BAH_RXBC(buffer));
    843      1.25        is 			} else {
    844      1.25        is 				if (++sc->sc_rx_fillcount > 1) {
    845      1.25        is 					sc->sc_intmask &= ~BAH_RI;
    846      1.25        is 					PUTREG(BAHSTAT, sc->sc_intmask);
    847      1.25        is 				} else {
    848      1.25        is 					buffer ^= 1;
    849      1.25        is 					sc->sc_rx_act = buffer;
    850      1.25        is 
    851      1.25        is 					/*
    852      1.25        is 					 * Start receiver on other receive
    853      1.25        is 					 * buffer. This also clears the RI
    854      1.25        is 					 * interupt flag.
    855      1.25        is 					 */
    856      1.25        is 					PUTREG(BAHCMD, BAH_RXBC(buffer));
    857      1.25        is 					/* in RX intr, so mask is ok for RX */
    858      1.25        is 
    859       1.1    chopps #ifdef BAH_DEBUG
    860      1.25        is 					printf("%s: strt rx for buf %ld, "
    861      1.25        is 					    "stat 0x%02x\n",
    862      1.25        is 					    sc->sc_dev.dv_xname, sc->sc_rx_act,
    863      1.25        is 					    GETREG(BAHSTAT);
    864       1.1    chopps #endif
    865      1.25        is 				}
    866      1.25        is 
    867       1.1    chopps #ifdef BAHSOFTCOPY
    868      1.25        is 				/*
    869      1.25        is 				 * this one starts a soft int to copy out
    870      1.25        is 				 * of the hw
    871      1.25        is 				 */
    872      1.27        is 				softintr_schedule(sc->sc_rxcookie);
    873       1.1    chopps #else
    874      1.25        is 				/* this one does the copy here */
    875      1.25        is 				bah_srint(sc);
    876       1.1    chopps #endif
    877      1.25        is 			}
    878      1.25        is 		}
    879      1.25        is 		if (maskedisr & BAH_TA) {
    880      1.25        is 			bah_tint(sc, isr);
    881      1.25        is 		}
    882      1.25        is 		isr = GETREG(BAHSTAT);
    883      1.25        is 		maskedisr = isr & sc->sc_intmask;
    884      1.25        is 	} while (maskedisr);
    885      1.25        is 
    886      1.25        is 	return (1);
    887      1.25        is }
    888       1.1    chopps 
    889      1.25        is void
    890      1.25        is bah_reconwatch(arg)
    891      1.25        is 	void *arg;
    892      1.25        is {
    893      1.25        is 	struct bah_softc *sc = arg;
    894       1.1    chopps 
    895      1.25        is 	if (sc->sc_reconcount >= ARC_EXCESSIVE_RECONS) {
    896      1.25        is 		sc->sc_reconcount = 0;
    897      1.25        is 		log(LOG_WARNING, "%s: token valid again.\n",
    898      1.25        is 		    sc->sc_dev.dv_xname);
    899      1.25        is 	}
    900      1.25        is 	sc->sc_reconcount = 0;
    901       1.1    chopps }
    902       1.1    chopps 
    903      1.25        is 
    904       1.1    chopps /*
    905       1.1    chopps  * Process an ioctl request.
    906       1.1    chopps  * This code needs some work - it looks pretty ugly.
    907       1.1    chopps  */
    908       1.1    chopps int
    909       1.1    chopps bah_ioctl(ifp, command, data)
    910  1.33.2.1    bouyer 	struct ifnet *ifp;
    911       1.7       cgd 	u_long command;
    912       1.1    chopps 	caddr_t data;
    913       1.1    chopps {
    914       1.1    chopps 	struct bah_softc *sc;
    915  1.33.2.1    bouyer 	struct ifaddr *ifa;
    916      1.25        is 	struct ifreq *ifr;
    917       1.3    chopps 	int s, error;
    918       1.1    chopps 
    919       1.3    chopps 	error = 0;
    920      1.17   thorpej 	sc = ifp->if_softc;
    921       1.1    chopps 	ifa = (struct ifaddr *)data;
    922      1.25        is 	ifr = (struct ifreq *)data;
    923      1.13   mycroft 	s = splnet();
    924       1.1    chopps 
    925       1.1    chopps #if defined(BAH_DEBUG) && (BAH_DEBUG > 2)
    926      1.19  christos 	printf("%s: ioctl() called, cmd = 0x%x\n",
    927       1.4   mycroft 	    sc->sc_dev.dv_xname, command);
    928       1.1    chopps #endif
    929       1.1    chopps 
    930       1.4   mycroft 	switch (command) {
    931       1.1    chopps 	case SIOCSIFADDR:
    932       1.1    chopps 		ifp->if_flags |= IFF_UP;
    933       1.4   mycroft 		switch (ifa->ifa_addr->sa_family) {
    934       1.1    chopps #ifdef INET
    935       1.1    chopps 		case AF_INET:
    936       1.4   mycroft 			bah_init(sc);
    937      1.25        is 			arp_ifinit(ifp, ifa);
    938       1.1    chopps 			break;
    939       1.1    chopps #endif
    940       1.1    chopps 		default:
    941       1.1    chopps 			bah_init(sc);
    942       1.1    chopps 			break;
    943       1.1    chopps 		}
    944       1.1    chopps 
    945       1.1    chopps 	case SIOCSIFFLAGS:
    946       1.1    chopps 		if ((ifp->if_flags & IFF_UP) == 0 &&
    947       1.1    chopps 		    (ifp->if_flags & IFF_RUNNING) != 0) {
    948       1.1    chopps 			/*
    949       1.1    chopps 			 * If interface is marked down and it is running,
    950       1.1    chopps 			 * then stop it.
    951       1.1    chopps 			 */
    952       1.1    chopps 			bah_stop(sc);
    953       1.1    chopps 			ifp->if_flags &= ~IFF_RUNNING;
    954       1.4   mycroft 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
    955       1.4   mycroft 			   (ifp->if_flags & IFF_RUNNING) == 0) {
    956       1.1    chopps 			/*
    957       1.1    chopps 			 * If interface is marked up and it is stopped, then
    958       1.1    chopps 			 * start it.
    959       1.1    chopps 			 */
    960       1.1    chopps 			bah_init(sc);
    961       1.1    chopps 		}
    962       1.1    chopps 		break;
    963       1.1    chopps 
    964      1.25        is 	case SIOCADDMULTI:
    965      1.25        is 	case SIOCDELMULTI:
    966      1.33        is 		switch (ifr->ifr_addr.sa_family) {
    967      1.33        is 		case AF_INET:
    968      1.33        is 		case AF_INET6:
    969      1.25        is 			error = 0;
    970      1.33        is 			break;
    971      1.33        is 		default:
    972      1.25        is 			error = EAFNOSUPPORT;
    973      1.33        is 			break;
    974      1.33        is 		}
    975      1.25        is 		break;
    976       1.4   mycroft 
    977       1.1    chopps 	default:
    978       1.1    chopps 		error = EINVAL;
    979       1.1    chopps 	}
    980       1.1    chopps 
    981       1.4   mycroft 	splx(s);
    982       1.3    chopps 	return (error);
    983       1.6    chopps }
    984       1.6    chopps 
    985       1.6    chopps /*
    986       1.6    chopps  * watchdog routine for transmitter.
    987       1.6    chopps  *
    988       1.6    chopps  * We need this, because else a receiver whose hardware is alive, but whose
    989       1.6    chopps  * software has not enabled the Receiver, would make our hardware wait forever
    990       1.6    chopps  * Discovered this after 20 times reading the docs.
    991       1.6    chopps  *
    992       1.6    chopps  * Only thing we do is disable transmitter. We'll get an transmit timeout,
    993       1.6    chopps  * and the int handler will have to decide not to retransmit (in case
    994       1.6    chopps  * retransmission is implemented).
    995       1.6    chopps  *
    996      1.25        is  * This one assumes being called inside splnet()
    997       1.6    chopps  */
    998       1.6    chopps 
    999       1.6    chopps void
   1000      1.17   thorpej bah_watchdog(ifp)
   1001      1.17   thorpej 	struct ifnet *ifp;
   1002       1.6    chopps {
   1003      1.17   thorpej 	struct bah_softc *sc = ifp->if_softc;
   1004       1.6    chopps 
   1005      1.25        is 	bus_space_tag_t bst_r = sc->sc_bst_r;
   1006      1.25        is 	bus_space_handle_t regs = sc->sc_regs;
   1007      1.25        is 
   1008      1.25        is 	PUTREG(BAHCMD, BAH_TXDIS);
   1009       1.6    chopps 	return;
   1010       1.1    chopps }
   1011      1.25        is 
   1012