Home | History | Annotate | Line # | Download | only in qbus
if_il.c revision 1.5
      1  1.5      wiz /*	$NetBSD: if_il.c,v 1.5 2002/05/22 16:03:17 wiz Exp $	*/
      2  1.1    ragge /*
      3  1.1    ragge  * Copyright (c) 1982, 1986 Regents of the University of California.
      4  1.1    ragge  * All rights reserved.
      5  1.1    ragge  *
      6  1.1    ragge  * Redistribution and use in source and binary forms, with or without
      7  1.1    ragge  * modification, are permitted provided that the following conditions
      8  1.1    ragge  * are met:
      9  1.1    ragge  * 1. Redistributions of source code must retain the above copyright
     10  1.1    ragge  *    notice, this list of conditions and the following disclaimer.
     11  1.1    ragge  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1    ragge  *    notice, this list of conditions and the following disclaimer in the
     13  1.1    ragge  *    documentation and/or other materials provided with the distribution.
     14  1.1    ragge  * 3. All advertising materials mentioning features or use of this software
     15  1.1    ragge  *    must display the following acknowledgement:
     16  1.1    ragge  *	This product includes software developed by the University of
     17  1.1    ragge  *	California, Berkeley and its contributors.
     18  1.1    ragge  * 4. Neither the name of the University nor the names of its contributors
     19  1.1    ragge  *    may be used to endorse or promote products derived from this software
     20  1.1    ragge  *    without specific prior written permission.
     21  1.1    ragge  *
     22  1.1    ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1    ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1    ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1    ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1    ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1    ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1    ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1    ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1    ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1    ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1    ragge  * SUCH DAMAGE.
     33  1.1    ragge  *
     34  1.1    ragge  *	@(#)if_il.c	7.8 (Berkeley) 12/16/90
     35  1.1    ragge  */
     36  1.1    ragge 
     37  1.1    ragge /*
     38  1.1    ragge  * Interlan Ethernet Communications Controller interface
     39  1.1    ragge  */
     40  1.2    lukem 
     41  1.2    lukem #include <sys/cdefs.h>
     42  1.5      wiz __KERNEL_RCSID(0, "$NetBSD: if_il.c,v 1.5 2002/05/22 16:03:17 wiz Exp $");
     43  1.2    lukem 
     44  1.1    ragge #include "opt_inet.h"
     45  1.1    ragge #include "opt_ns.h"
     46  1.1    ragge 
     47  1.1    ragge #include <sys/param.h>
     48  1.1    ragge #include <sys/systm.h>
     49  1.1    ragge #include <sys/mbuf.h>
     50  1.1    ragge #include <sys/buf.h>
     51  1.1    ragge #include <sys/protosw.h>
     52  1.1    ragge #include <sys/socket.h>
     53  1.1    ragge #include <sys/ioctl.h>
     54  1.1    ragge #include <sys/errno.h>
     55  1.1    ragge #include <sys/syslog.h>
     56  1.1    ragge #include <sys/device.h>
     57  1.1    ragge 
     58  1.1    ragge #include <net/if.h>
     59  1.1    ragge #include <net/if_ether.h>
     60  1.1    ragge #include <net/if_dl.h>
     61  1.1    ragge 
     62  1.1    ragge #ifdef INET
     63  1.1    ragge #include <netinet/in.h>
     64  1.1    ragge #endif
     65  1.1    ragge 
     66  1.1    ragge #ifdef NS
     67  1.1    ragge #include <netns/ns.h>
     68  1.1    ragge #include <netns/ns_if.h>
     69  1.1    ragge #endif
     70  1.1    ragge 
     71  1.1    ragge #include <machine/bus.h>
     72  1.1    ragge 
     73  1.1    ragge #include <dev/qbus/ubareg.h>
     74  1.1    ragge #include <dev/qbus/ubavar.h>
     75  1.1    ragge #include <dev/qbus/if_uba.h>
     76  1.1    ragge 
     77  1.1    ragge #include <dev/qbus/if_il.h>
     78  1.1    ragge #include <dev/qbus/if_ilreg.h>
     79  1.1    ragge 
     80  1.1    ragge /*
     81  1.1    ragge  * Ethernet software status per interface.
     82  1.1    ragge  *
     83  1.1    ragge  * Each interface is referenced by a network interface structure,
     84  1.1    ragge  * is_if, which the routing code uses to locate the interface.
     85  1.1    ragge  * This structure contains the output queue for the interface, its address, ...
     86  1.1    ragge  * We also have, for each interface, a UBA interface structure, which
     87  1.1    ragge  * contains information about the UNIBUS resources held by the interface:
     88  1.1    ragge  * map registers, buffered data paths, etc.  Information is cached in this
     89  1.1    ragge  * structure for use by the if_uba.c routines in running the interface
     90  1.1    ragge  * efficiently.
     91  1.1    ragge  */
     92  1.1    ragge 
     93  1.1    ragge struct	il_softc {
     94  1.1    ragge 	struct	device sc_dev;		/* Configuration common part */
     95  1.1    ragge 	struct	ethercom sc_ec;		/* Ethernet common part */
     96  1.1    ragge #define	sc_if	sc_ec.ec_if		/* network-visible interface */
     97  1.1    ragge 	struct	evcnt sc_cintrcnt;	/* Command interrupts */
     98  1.1    ragge 	struct  evcnt sc_rintrcnt;	/* Receive interrupts */
     99  1.1    ragge 	bus_space_tag_t sc_iot;
    100  1.1    ragge 	bus_addr_t sc_ioh;
    101  1.1    ragge 	bus_dma_tag_t sc_dmat;
    102  1.1    ragge 	struct	ubinfo sc_ui;
    103  1.1    ragge 
    104  1.1    ragge 	struct	ifuba sc_ifuba;		/* UNIBUS resources */
    105  1.1    ragge 	int	sc_flags;
    106  1.1    ragge #define	ILF_RCVPENDING	0x2		/* start rcv in ilcint */
    107  1.1    ragge #define	ILF_STATPENDING	0x4		/* stat cmd pending */
    108  1.1    ragge #define	ILF_RUNNING	0x8		/* board is running */
    109  1.1    ragge #define	ILF_SETADDR	0x10		/* physical address is changed */
    110  1.1    ragge 	short	sc_lastcmd;		/* can't read csr, so must save it */
    111  1.1    ragge 	short	sc_scaninterval;	/* interval of stat collection */
    112  1.1    ragge #define	ILWATCHINTERVAL	60		/* once every 60 seconds */
    113  1.1    ragge 	union {
    114  1.1    ragge 	    struct	il_stats isu_stats;	/* holds on-board statistics */
    115  1.1    ragge 	    struct	ether_addr isu_maddrs[63];	/* multicast addrs */
    116  1.1    ragge 	}	sc_isu;
    117  1.1    ragge #define sc_stats	sc_isu.isu_stats
    118  1.1    ragge #define sc_maddrs	sc_isu.isu_maddrs
    119  1.1    ragge 	struct	il_stats sc_sum;	/* summation over time */
    120  1.1    ragge 	int	sc_ubaddr;		/* mapping registers of is_stats */
    121  1.1    ragge };
    122  1.1    ragge 
    123  1.1    ragge static	int ilmatch(struct device *, struct cfdata *, void *);
    124  1.1    ragge static	void ilattach(struct device *, struct device *, void *);
    125  1.1    ragge static	void ilcint(void *);
    126  1.1    ragge static	void ilrint(void *);
    127  1.1    ragge static	void ilreset(struct device *);
    128  1.1    ragge static	int ilwait(struct il_softc *, char *);
    129  1.1    ragge static	int ilinit(struct ifnet *);
    130  1.1    ragge static	void ilstart(struct ifnet *);
    131  1.1    ragge static	void ilwatch(struct ifnet *);
    132  1.1    ragge static	void iltotal(struct il_softc *);
    133  1.1    ragge static	void ilstop(struct ifnet *, int);
    134  1.1    ragge 
    135  1.1    ragge struct	cfattach il_ca = {
    136  1.1    ragge 	sizeof(struct il_softc), ilmatch, ilattach
    137  1.1    ragge };
    138  1.1    ragge 
    139  1.1    ragge #define IL_WCSR(csr, val) \
    140  1.1    ragge 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
    141  1.1    ragge #define IL_RCSR(csr) \
    142  1.1    ragge 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
    143  1.1    ragge #define LOWORD(x)	((int)(x) & 0xffff)
    144  1.1    ragge #define HIWORD(x)	(((int)(x) >> 16) & 0x3)
    145  1.1    ragge 
    146  1.1    ragge int
    147  1.1    ragge ilmatch(struct device *parent, struct cfdata *cf, void *aux)
    148  1.1    ragge {
    149  1.1    ragge 	struct uba_attach_args *ua = aux;
    150  1.1    ragge 	volatile int i;
    151  1.1    ragge 
    152  1.1    ragge 	bus_space_write_2(ua->ua_iot, ua->ua_ioh, IL_CSR, ILC_OFFLINE|IL_CIE);
    153  1.1    ragge 	DELAY(100000);
    154  1.1    ragge 	i = bus_space_read_2(ua->ua_iot, ua->ua_ioh, IL_CSR); /* clear CDONE */
    155  1.1    ragge 
    156  1.1    ragge 	return 1;
    157  1.1    ragge }
    158  1.1    ragge 
    159  1.1    ragge /*
    160  1.1    ragge  * Interface exists: make available by filling in network interface
    161  1.1    ragge  * record.  System will initialize the interface when it is ready
    162  1.1    ragge  * to accept packets.  A STATUS command is done to get the ethernet
    163  1.1    ragge  * address and other interesting data.
    164  1.1    ragge  */
    165  1.1    ragge void
    166  1.1    ragge ilattach(struct device *parent, struct device *self, void *aux)
    167  1.1    ragge {
    168  1.1    ragge 	struct uba_attach_args *ua = aux;
    169  1.1    ragge 	struct il_softc *sc = (struct il_softc *)self;
    170  1.1    ragge 	struct ifnet *ifp = &sc->sc_if;
    171  1.1    ragge 	int error;
    172  1.1    ragge 
    173  1.1    ragge 	sc->sc_iot = ua->ua_iot;
    174  1.1    ragge 	sc->sc_ioh = ua->ua_ioh;
    175  1.1    ragge 	sc->sc_dmat = ua->ua_dmat;
    176  1.1    ragge 
    177  1.1    ragge 	/*
    178  1.1    ragge 	 * Map interrupt vectors and reset function.
    179  1.1    ragge 	 */
    180  1.1    ragge 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec, ilcint,
    181  1.1    ragge 	    sc, &sc->sc_cintrcnt);
    182  1.1    ragge 	evcnt_attach_dynamic(&sc->sc_cintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    183  1.1    ragge 	    sc->sc_dev.dv_xname, "intr");
    184  1.1    ragge 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec-4, ilrint,
    185  1.1    ragge 	    sc, &sc->sc_rintrcnt);
    186  1.1    ragge 	evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    187  1.1    ragge 	    sc->sc_dev.dv_xname, "intr");
    188  1.1    ragge 	uba_reset_establish(ilreset, &sc->sc_dev);
    189  1.1    ragge 
    190  1.1    ragge 	/*
    191  1.1    ragge 	 * Reset the board and map the statistics
    192  1.1    ragge 	 * buffer onto the Unibus.
    193  1.1    ragge 	 */
    194  1.1    ragge 	IL_WCSR(IL_CSR, ILC_RESET);
    195  1.1    ragge 	(void)ilwait(sc, "reset");
    196  1.1    ragge 	sc->sc_ui.ui_size = sizeof(struct il_stats);
    197  1.1    ragge 	sc->sc_ui.ui_vaddr = (caddr_t)&sc->sc_stats;
    198  1.1    ragge 	if ((error = uballoc((struct uba_softc *)parent, &sc->sc_ui, 0)))
    199  1.1    ragge 		return printf(": failed uballoc, error = %d\n", error);
    200  1.1    ragge 
    201  1.1    ragge 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    202  1.1    ragge 	IL_WCSR(IL_BCR, sizeof(struct il_stats));
    203  1.1    ragge 	IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT);
    204  1.1    ragge 	(void)ilwait(sc, "status");
    205  1.1    ragge 	ubfree((struct uba_softc *)parent, &sc->sc_ui);
    206  1.1    ragge 	printf("%s: module=%s firmware=%s\n", sc->sc_dev.dv_xname,
    207  1.1    ragge 		sc->sc_stats.ils_module, sc->sc_stats.ils_firmware);
    208  1.1    ragge 	printf("%s: hardware address %s\n", sc->sc_dev.dv_xname,
    209  1.1    ragge 		ether_sprintf(sc->sc_stats.ils_addr));
    210  1.1    ragge 
    211  1.1    ragge 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
    212  1.1    ragge 	ifp->if_softc = sc;
    213  1.1    ragge 	ifp->if_flags = IFF_BROADCAST;
    214  1.1    ragge 	ifp->if_init = ilinit;
    215  1.1    ragge 	ifp->if_stop = ilstop;
    216  1.1    ragge 	ifp->if_ioctl = ether_ioctl;
    217  1.1    ragge 	ifp->if_start = ilstart;
    218  1.1    ragge 	ifp->if_watchdog = ilwatch;
    219  1.4   itojun 	IFQ_SET_READY(&ifp->if_snd);
    220  1.1    ragge 
    221  1.1    ragge 	if_attach(ifp);
    222  1.1    ragge 	ether_ifattach(ifp, sc->sc_stats.ils_addr);
    223  1.1    ragge }
    224  1.1    ragge 
    225  1.1    ragge void
    226  1.1    ragge ilstop(struct ifnet *ifp, int a)
    227  1.1    ragge {
    228  1.1    ragge 	struct il_softc *sc = ifp->if_softc;
    229  1.1    ragge 
    230  1.1    ragge 	IL_WCSR(IL_CSR, ILC_RESET);
    231  1.1    ragge }
    232  1.1    ragge 
    233  1.1    ragge 
    234  1.1    ragge int
    235  1.1    ragge ilwait(struct il_softc *sc, char *op)
    236  1.1    ragge {
    237  1.1    ragge 
    238  1.1    ragge 	while ((IL_RCSR(IL_CSR)&IL_CDONE) == 0)
    239  1.1    ragge 		;
    240  1.1    ragge 	if (IL_RCSR(IL_CSR)&IL_STATUS) {
    241  1.1    ragge 		char bits[64];
    242  1.1    ragge 
    243  1.1    ragge 		printf("%s: %s failed, csr=%s\n", sc->sc_dev.dv_xname, op,
    244  1.1    ragge 		    bitmask_snprintf(IL_RCSR(IL_CSR), IL_BITS, bits,
    245  1.1    ragge 		    sizeof(bits)));
    246  1.1    ragge 		return (-1);
    247  1.1    ragge 	}
    248  1.1    ragge 	return (0);
    249  1.1    ragge }
    250  1.1    ragge 
    251  1.1    ragge /*
    252  1.1    ragge  * Reset of interface after UNIBUS reset.
    253  1.1    ragge  * If interface is on specified uba, reset its state.
    254  1.1    ragge  */
    255  1.1    ragge void
    256  1.1    ragge ilreset(struct device *dev)
    257  1.1    ragge {
    258  1.1    ragge 	struct il_softc *sc = (void *)dev;
    259  1.1    ragge 
    260  1.1    ragge 	printf(" %s", sc->sc_dev.dv_xname);
    261  1.1    ragge 	sc->sc_if.if_flags &= ~IFF_RUNNING;
    262  1.1    ragge 	sc->sc_flags &= ~ILF_RUNNING;
    263  1.1    ragge 	ilinit(&sc->sc_if);
    264  1.1    ragge }
    265  1.1    ragge 
    266  1.1    ragge /*
    267  1.1    ragge  * Initialization of interface; clear recorded pending
    268  1.1    ragge  * operations, and reinitialize UNIBUS usage.
    269  1.1    ragge  */
    270  1.1    ragge int
    271  1.1    ragge ilinit(struct ifnet *ifp)
    272  1.1    ragge {
    273  1.1    ragge 	struct il_softc *sc = ifp->if_softc;
    274  1.1    ragge 	int s;
    275  1.1    ragge 
    276  1.1    ragge 	if (sc->sc_flags & ILF_RUNNING)
    277  1.1    ragge 		return 0;
    278  1.1    ragge 
    279  1.1    ragge 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
    280  1.1    ragge 		if (if_ubainit(&sc->sc_ifuba, (void *)sc->sc_dev.dv_parent,
    281  1.1    ragge 		    ETHER_MAX_LEN)) {
    282  1.1    ragge 			printf("%s: can't initialize\n", sc->sc_dev.dv_xname);
    283  1.1    ragge 			sc->sc_if.if_flags &= ~IFF_UP;
    284  1.1    ragge 			return 0;
    285  1.1    ragge 		}
    286  1.1    ragge 		sc->sc_ui.ui_size = sizeof(sc->sc_isu);
    287  1.1    ragge 		sc->sc_ui.ui_vaddr = (caddr_t)&sc->sc_isu;
    288  1.1    ragge 		uballoc((void *)sc->sc_dev.dv_parent, &sc->sc_ui, 0);
    289  1.1    ragge 	}
    290  1.1    ragge 	sc->sc_scaninterval = ILWATCHINTERVAL;
    291  1.1    ragge 	ifp->if_timer = sc->sc_scaninterval;
    292  1.1    ragge 
    293  1.1    ragge 	/*
    294  1.1    ragge 	 * Turn off source address insertion (it's faster this way),
    295  1.1    ragge 	 * and set board online.  Former doesn't work if board is
    296  1.1    ragge 	 * already online (happens on ubareset), so we put it offline
    297  1.1    ragge 	 * first.
    298  1.1    ragge 	 */
    299  1.1    ragge 	s = splnet();
    300  1.1    ragge 	IL_WCSR(IL_CSR, ILC_RESET);
    301  1.1    ragge 	if (ilwait(sc, "hardware diag")) {
    302  1.1    ragge  		sc->sc_if.if_flags &= ~IFF_UP;
    303  1.1    ragge  		splx(s);
    304  1.1    ragge  		return 0;
    305  1.1    ragge  	}
    306  1.1    ragge 	IL_WCSR(IL_CSR, ILC_CISA);
    307  1.1    ragge 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    308  1.1    ragge 		;
    309  1.1    ragge 	/*
    310  1.1    ragge 	 * If we must reprogram this board's physical ethernet
    311  1.1    ragge 	 * address (as for secondary XNS interfaces), we do so
    312  1.1    ragge 	 * before putting it on line, and starting receive requests.
    313  1.1    ragge 	 * If you try this on an older 1010 board, it will total
    314  1.1    ragge 	 * wedge the board.
    315  1.1    ragge 	 */
    316  1.1    ragge 	if (sc->sc_flags & ILF_SETADDR) {
    317  1.1    ragge 		bcopy((caddr_t)LLADDR(ifp->if_sadl),
    318  1.1    ragge 		    (caddr_t)&sc->sc_isu, ETHER_ADDR_LEN);
    319  1.1    ragge 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    320  1.1    ragge 		IL_WCSR(IL_BCR, ETHER_ADDR_LEN);
    321  1.1    ragge 		IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_LDPA);
    322  1.1    ragge 		if (ilwait(sc, "setaddr"))
    323  1.1    ragge 			return 0;
    324  1.1    ragge 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    325  1.1    ragge 		IL_WCSR(IL_BCR, sizeof (struct il_stats));
    326  1.1    ragge 		IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT);
    327  1.1    ragge 		if (ilwait(sc, "verifying setaddr"))
    328  1.1    ragge 			return 0;
    329  1.5      wiz 		if (memcmp((caddr_t)sc->sc_stats.ils_addr,
    330  1.1    ragge 		    (caddr_t)LLADDR(ifp->if_sadl), ETHER_ADDR_LEN) != 0) {
    331  1.1    ragge 			printf("%s: setaddr didn't work\n",
    332  1.1    ragge 			    sc->sc_dev.dv_xname);
    333  1.1    ragge 			return 0;
    334  1.1    ragge 		}
    335  1.1    ragge 	}
    336  1.1    ragge #ifdef MULTICAST
    337  1.1    ragge 	if (is->is_if.if_flags & IFF_PROMISC) {
    338  1.1    ragge 		addr->il_csr = ILC_PRMSC;
    339  1.1    ragge 		if (ilwait(ui, "all multi"))
    340  1.1    ragge 			return 0;
    341  1.1    ragge 	} else if (is->is_if.if_flags & IFF_ALLMULTI) {
    342  1.1    ragge 	too_many_multis:
    343  1.1    ragge 		addr->il_csr = ILC_ALLMC;
    344  1.1    ragge 		if (ilwait(ui, "all multi"))
    345  1.1    ragge 			return 0;
    346  1.1    ragge 	else {
    347  1.1    ragge 		int i;
    348  1.1    ragge 		register struct ether_addr *ep = is->is_maddrs;
    349  1.1    ragge 		struct ether_multi *enm;
    350  1.1    ragge 		struct ether_multistep step;
    351  1.1    ragge 		/*
    352  1.1    ragge 		 * Step through our list of multicast addresses.  If we have
    353  1.1    ragge 		 * too many multicast addresses, or if we have to listen to
    354  1.1    ragge 		 * a range of multicast addresses, turn on reception of all
    355  1.1    ragge 		 * multicasts.
    356  1.1    ragge 		 */
    357  1.1    ragge 		i = 0;
    358  1.1    ragge 		ETHER_FIRST_MULTI(step, &is->is_ac, enm);
    359  1.1    ragge 		while (enm != NULL) {
    360  1.1    ragge 			if (++i > 63 && k != 0) {
    361  1.1    ragge 				break;
    362  1.1    ragge 			}
    363  1.1    ragge 			*ep++ = *(struct ether_addr *)enm->enm_addrlo;
    364  1.1    ragge 			ETHER_NEXT_MULTI(step, enm);
    365  1.1    ragge 		}
    366  1.1    ragge 		if (i = 0) {
    367  1.1    ragge 			/* no multicasts! */
    368  1.1    ragge 		} else if (i <= 63) {
    369  1.1    ragge 			addr->il_bar = is->is_ubaddr & 0xffff;
    370  1.1    ragge 			addr->il_bcr = i * sizeof (struct ether_addr);
    371  1.1    ragge 			addr->il_csr = ((is->is_ubaddr >> 2) & IL_EUA)|
    372  1.1    ragge 						LC_LDGRPS;
    373  1.1    ragge 			if (ilwait(ui, "load multi"))
    374  1.1    ragge 				return;
    375  1.1    ragge 		} else {
    376  1.1    ragge 		    is->is_if.if_flags |= IFF_ALLMULTI;
    377  1.1    ragge 		    goto too_many_multis;
    378  1.1    ragge 		}
    379  1.1    ragge 	}
    380  1.3  msaitoh #endif /* MULTICAST */
    381  1.1    ragge 	/*
    382  1.1    ragge 	 * Set board online.
    383  1.1    ragge 	 * Hang receive buffer and start any pending
    384  1.1    ragge 	 * writes by faking a transmit complete.
    385  1.1    ragge 	 * Receive bcr is not a multiple of 8 so buffer
    386  1.1    ragge 	 * chaining can't happen.
    387  1.1    ragge 	 */
    388  1.1    ragge 	IL_WCSR(IL_CSR, ILC_ONLINE);
    389  1.1    ragge 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    390  1.1    ragge 		;
    391  1.1    ragge 
    392  1.1    ragge 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
    393  1.1    ragge 	IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
    394  1.1    ragge 	IL_WCSR(IL_CSR,
    395  1.1    ragge 	    ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE);
    396  1.1    ragge 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    397  1.1    ragge 		;
    398  1.1    ragge 	ifp->if_flags |= IFF_RUNNING | IFF_OACTIVE;
    399  1.1    ragge 	sc->sc_flags |= ILF_RUNNING;
    400  1.1    ragge 	sc->sc_lastcmd = 0;
    401  1.1    ragge 	ilcint(sc);
    402  1.1    ragge 	splx(s);
    403  1.1    ragge 	return 0;
    404  1.1    ragge }
    405  1.1    ragge 
    406  1.1    ragge /*
    407  1.1    ragge  * Start output on interface.
    408  1.1    ragge  * Get another datagram to send off of the interface queue,
    409  1.1    ragge  * and map it to the interface before starting the output.
    410  1.1    ragge  */
    411  1.1    ragge void
    412  1.1    ragge ilstart(struct ifnet *ifp)
    413  1.1    ragge {
    414  1.1    ragge 	struct il_softc *sc = ifp->if_softc;
    415  1.1    ragge         int len;
    416  1.1    ragge 	struct mbuf *m;
    417  1.1    ragge 	short csr;
    418  1.1    ragge 
    419  1.4   itojun 	IFQ_DEQUEUE(&ifp->if_snd, m);
    420  1.1    ragge 	if (m == 0) {
    421  1.1    ragge 		if ((sc->sc_flags & ILF_STATPENDING) == 0)
    422  1.1    ragge 			return;
    423  1.1    ragge 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr));
    424  1.1    ragge 		IL_WCSR(IL_BCR, sizeof (struct il_stats));
    425  1.1    ragge 		csr = ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT|IL_RIE|IL_CIE;
    426  1.1    ragge 		sc->sc_flags &= ~ILF_STATPENDING;
    427  1.1    ragge 		goto startcmd;
    428  1.1    ragge 	}
    429  1.1    ragge 	len = if_wubaput(&sc->sc_ifuba, m);
    430  1.1    ragge 	/*
    431  1.1    ragge 	 * Ensure minimum packet length.
    432  1.1    ragge 	 * This makes the safe assumtion that there are no virtual holes
    433  1.1    ragge 	 * after the data.
    434  1.1    ragge 	 * For security, it might be wise to zero out the added bytes,
    435  1.1    ragge 	 * but we're mainly interested in speed at the moment.
    436  1.1    ragge 	 */
    437  1.1    ragge 	if (len - sizeof(struct ether_header) < ETHERMIN)
    438  1.1    ragge 		len = ETHERMIN + sizeof(struct ether_header);
    439  1.1    ragge #ifdef notdef
    440  1.1    ragge 	if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
    441  1.1    ragge 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_w.ifrw_bdp);
    442  1.1    ragge #endif
    443  1.1    ragge 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_w.ifrw_info));
    444  1.1    ragge 	IL_WCSR(IL_BCR, len);
    445  1.1    ragge 	csr =
    446  1.1    ragge 	  ((sc->sc_ifuba.ifu_w.ifrw_info >> 2) & IL_EUA)|ILC_XMIT|IL_CIE|IL_RIE;
    447  1.1    ragge 
    448  1.1    ragge startcmd:
    449  1.1    ragge 	sc->sc_lastcmd = csr & IL_CMD;
    450  1.1    ragge 	IL_WCSR(IL_CSR, csr);
    451  1.1    ragge 	ifp->if_flags |= IFF_OACTIVE;
    452  1.1    ragge 	return;
    453  1.1    ragge }
    454  1.1    ragge 
    455  1.1    ragge /*
    456  1.1    ragge  * Command done interrupt.
    457  1.1    ragge  */
    458  1.1    ragge void
    459  1.1    ragge ilcint(void *arg)
    460  1.1    ragge {
    461  1.1    ragge 	struct il_softc *sc = arg;
    462  1.1    ragge 	short csr;
    463  1.1    ragge 
    464  1.1    ragge 	if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0) {
    465  1.1    ragge 		char bits[64];
    466  1.1    ragge 
    467  1.1    ragge 		printf("%s: stray xmit interrupt, csr=%s\n",
    468  1.1    ragge 		    sc->sc_dev.dv_xname,
    469  1.1    ragge 		    bitmask_snprintf(IL_RCSR(IL_CSR), IL_BITS, bits,
    470  1.1    ragge 		    sizeof(bits)));
    471  1.1    ragge 		return;
    472  1.1    ragge 	}
    473  1.1    ragge 
    474  1.1    ragge 	csr = IL_RCSR(IL_CSR);
    475  1.1    ragge 	/*
    476  1.1    ragge 	 * Hang receive buffer if it couldn't
    477  1.1    ragge 	 * be done earlier (in ilrint).
    478  1.1    ragge 	 */
    479  1.1    ragge 	if (sc->sc_flags & ILF_RCVPENDING) {
    480  1.1    ragge 		int s;
    481  1.1    ragge 
    482  1.1    ragge 		IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
    483  1.1    ragge 		IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
    484  1.1    ragge 		IL_WCSR(IL_CSR,
    485  1.1    ragge 		  ((sc->sc_ifuba.ifu_r.ifrw_info>>2) & IL_EUA)|ILC_RCV|IL_RIE);
    486  1.1    ragge 		s = splhigh();
    487  1.1    ragge 		while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    488  1.1    ragge 			;
    489  1.1    ragge 		splx(s);
    490  1.1    ragge 		sc->sc_flags &= ~ILF_RCVPENDING;
    491  1.1    ragge 	}
    492  1.1    ragge 	sc->sc_if.if_flags &= ~IFF_OACTIVE;
    493  1.1    ragge 	csr &= IL_STATUS;
    494  1.1    ragge 	switch (sc->sc_lastcmd) {
    495  1.1    ragge 
    496  1.1    ragge 	case ILC_XMIT:
    497  1.1    ragge 		sc->sc_if.if_opackets++;
    498  1.1    ragge 		if (csr > ILERR_RETRIES)
    499  1.1    ragge 			sc->sc_if.if_oerrors++;
    500  1.1    ragge 		break;
    501  1.1    ragge 
    502  1.1    ragge 	case ILC_STAT:
    503  1.1    ragge 		if (csr == ILERR_SUCCESS)
    504  1.1    ragge 			iltotal(sc);
    505  1.1    ragge 		break;
    506  1.1    ragge 	}
    507  1.1    ragge 	if_wubaend(&sc->sc_ifuba);
    508  1.1    ragge 	ilstart(&sc->sc_if);
    509  1.1    ragge }
    510  1.1    ragge 
    511  1.1    ragge /*
    512  1.1    ragge  * Ethernet interface receiver interrupt.
    513  1.1    ragge  * If input error just drop packet.
    514  1.1    ragge  * Otherwise purge input buffered data path and examine
    515  1.1    ragge  * packet to determine type.  If can't determine length
    516  1.1    ragge  * from type, then have to drop packet.  Othewise decapsulate
    517  1.1    ragge  * packet based on type and pass to type specific higher-level
    518  1.1    ragge  * input routine.
    519  1.1    ragge  */
    520  1.1    ragge void
    521  1.1    ragge ilrint(void *arg)
    522  1.1    ragge {
    523  1.1    ragge 	struct il_softc *sc = arg;
    524  1.1    ragge 	struct il_rheader *il;
    525  1.1    ragge     	struct mbuf *m;
    526  1.1    ragge 	int len, s;
    527  1.1    ragge 
    528  1.1    ragge 	sc->sc_if.if_ipackets++;
    529  1.1    ragge #ifdef notyet
    530  1.1    ragge 	if (sc->sc_ifuba.ifu_flags & UBA_NEEDBDP)
    531  1.1    ragge 		UBAPURGE(is->is_ifuba.ifu_uba, is->is_ifuba.ifu_r.ifrw_bdp);
    532  1.1    ragge #endif
    533  1.1    ragge 	il = (struct il_rheader *)(sc->sc_ifuba.ifu_r.ifrw_addr);
    534  1.1    ragge 	len = il->ilr_length - sizeof(struct il_rheader);
    535  1.1    ragge 	if ((il->ilr_status&(ILFSTAT_A|ILFSTAT_C)) || len < 46 ||
    536  1.1    ragge 	    len > ETHERMTU) {
    537  1.1    ragge 		sc->sc_if.if_ierrors++;
    538  1.1    ragge #ifdef notdef
    539  1.1    ragge 		if (sc->sc_if.if_ierrors % 100 == 0)
    540  1.1    ragge 			printf("il%d: += 100 input errors\n", unit);
    541  1.1    ragge #endif
    542  1.1    ragge 		goto setup;
    543  1.1    ragge 	}
    544  1.1    ragge 
    545  1.1    ragge 	if (len == 0)
    546  1.1    ragge 		goto setup;
    547  1.1    ragge 
    548  1.1    ragge 	/*
    549  1.1    ragge 	 * Pull packet off interface.
    550  1.1    ragge 	 */
    551  1.1    ragge 	m = if_rubaget(&sc->sc_ifuba, &sc->sc_if, len);
    552  1.1    ragge 	if (m == NULL)
    553  1.1    ragge 		goto setup;
    554  1.1    ragge 
    555  1.1    ragge 	/* Shave off status hdr */
    556  1.1    ragge 	m_adj(m, 4);
    557  1.1    ragge 	(*sc->sc_if.if_input)(&sc->sc_if, m);
    558  1.1    ragge setup:
    559  1.1    ragge 	/*
    560  1.1    ragge 	 * Reset for next packet if possible.
    561  1.1    ragge 	 * If waiting for transmit command completion, set flag
    562  1.1    ragge 	 * and wait until command completes.
    563  1.1    ragge 	 */
    564  1.1    ragge 	if (sc->sc_if.if_flags & IFF_OACTIVE) {
    565  1.1    ragge 		sc->sc_flags |= ILF_RCVPENDING;
    566  1.1    ragge 		return;
    567  1.1    ragge 	}
    568  1.1    ragge 	IL_WCSR(IL_BAR, LOWORD(sc->sc_ifuba.ifu_r.ifrw_info));
    569  1.1    ragge 	IL_WCSR(IL_BCR, sizeof(struct il_rheader) + ETHERMTU + 6);
    570  1.1    ragge 	IL_WCSR(IL_CSR,
    571  1.1    ragge 	    ((sc->sc_ifuba.ifu_r.ifrw_info >> 2) & IL_EUA)|ILC_RCV|IL_RIE);
    572  1.1    ragge 	s = splhigh();
    573  1.1    ragge 	while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0)
    574  1.1    ragge 		;
    575  1.1    ragge 	splx(s);
    576  1.1    ragge }
    577  1.1    ragge /*
    578  1.1    ragge  * Watchdog routine, request statistics from board.
    579  1.1    ragge  */
    580  1.1    ragge void
    581  1.1    ragge ilwatch(struct ifnet *ifp)
    582  1.1    ragge {
    583  1.1    ragge 	struct il_softc *sc = ifp->if_softc;
    584  1.1    ragge 	int s;
    585  1.1    ragge 
    586  1.1    ragge 	if (sc->sc_flags & ILF_STATPENDING) {
    587  1.1    ragge 		ifp->if_timer = sc->sc_scaninterval;
    588  1.1    ragge 		return;
    589  1.1    ragge 	}
    590  1.1    ragge 	s = splnet();
    591  1.1    ragge 	sc->sc_flags |= ILF_STATPENDING;
    592  1.1    ragge 	if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0)
    593  1.1    ragge 		ilstart(ifp);
    594  1.1    ragge 	splx(s);
    595  1.1    ragge 	ifp->if_timer = sc->sc_scaninterval;
    596  1.1    ragge }
    597  1.1    ragge 
    598  1.1    ragge /*
    599  1.1    ragge  * Total up the on-board statistics.
    600  1.1    ragge  */
    601  1.1    ragge void
    602  1.1    ragge iltotal(struct il_softc *sc)
    603  1.1    ragge {
    604  1.1    ragge 	struct ifnet *ifp = &sc->sc_if;
    605  1.1    ragge 	u_short *interval, *sum, *end;
    606  1.1    ragge 
    607  1.1    ragge 	interval = &sc->sc_stats.ils_frames;
    608  1.1    ragge 	sum = &sc->sc_sum.ils_frames;
    609  1.1    ragge 	end = sc->sc_sum.ils_fill2;
    610  1.1    ragge 	while (sum < end)
    611  1.1    ragge 		*sum++ += *interval++;
    612  1.1    ragge 	sc->sc_if.if_collisions = sc->sc_sum.ils_collis;
    613  1.1    ragge 	if ((sc->sc_flags & ILF_SETADDR) &&
    614  1.5      wiz 	    (memcmp((caddr_t)sc->sc_stats.ils_addr, LLADDR(ifp->if_sadl),
    615  1.5      wiz 		    ETHER_ADDR_LEN) != 0)) {
    616  1.1    ragge 		log(LOG_ERR, "%s: physaddr reverted\n", sc->sc_dev.dv_xname);
    617  1.1    ragge 		sc->sc_flags &= ~ILF_RUNNING;
    618  1.1    ragge 		ilinit(&sc->sc_if);
    619  1.1    ragge 	}
    620  1.1    ragge }
    621  1.1    ragge 
    622  1.1    ragge #ifdef notyet
    623  1.1    ragge /*
    624  1.1    ragge  * set ethernet address for unit
    625  1.1    ragge  */
    626  1.1    ragge void
    627  1.1    ragge il_setaddr(u_char *physaddr, struct il_softc *sc)
    628  1.1    ragge {
    629  1.1    ragge 	if (! (sc->sc_flags & ILF_RUNNING))
    630  1.1    ragge 		return;
    631  1.1    ragge 
    632  1.1    ragge 	bcopy((caddr_t)physaddr, (caddr_t)is->is_addr, sizeof is->is_addr);
    633  1.1    ragge 	sc->sc_flags &= ~ILF_RUNNING;
    634  1.1    ragge 	sc->sc_flags |= ILF_SETADDR;
    635  1.1    ragge 	ilinit(&sc->sc_if);
    636  1.1    ragge }
    637  1.1    ragge #endif
    638