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