Home | History | Annotate | Line # | Download | only in dev
if_le.c revision 1.1
      1  1.1  cgd /*
      2  1.1  cgd  * Copyright (c) 1982, 1990 The Regents of the University of California.
      3  1.1  cgd  * All rights reserved.
      4  1.1  cgd  *
      5  1.1  cgd  * Redistribution and use in source and binary forms, with or without
      6  1.1  cgd  * modification, are permitted provided that the following conditions
      7  1.1  cgd  * are met:
      8  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
      9  1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     10  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     13  1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     14  1.1  cgd  *    must display the following acknowledgement:
     15  1.1  cgd  *	This product includes software developed by the University of
     16  1.1  cgd  *	California, Berkeley and its contributors.
     17  1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     18  1.1  cgd  *    may be used to endorse or promote products derived from this software
     19  1.1  cgd  *    without specific prior written permission.
     20  1.1  cgd  *
     21  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  cgd  * SUCH DAMAGE.
     32  1.1  cgd  *
     33  1.1  cgd  *	@(#)if_le.c	7.6 (Berkeley) 5/8/91
     34  1.1  cgd  */
     35  1.1  cgd 
     36  1.1  cgd #include "le.h"
     37  1.1  cgd #if NLE > 0
     38  1.1  cgd 
     39  1.1  cgd #include "bpfilter.h"
     40  1.1  cgd 
     41  1.1  cgd /*
     42  1.1  cgd  * AMD 7990 LANCE
     43  1.1  cgd  *
     44  1.1  cgd  * This driver will generate and accept tailer encapsulated packets even
     45  1.1  cgd  * though it buys us nothing.  The motivation was to avoid incompatibilities
     46  1.1  cgd  * with VAXen, SUNs, and others that handle and benefit from them.
     47  1.1  cgd  * This reasoning is dubious.
     48  1.1  cgd  */
     49  1.1  cgd #include "sys/param.h"
     50  1.1  cgd #include "sys/systm.h"
     51  1.1  cgd #include "sys/mbuf.h"
     52  1.1  cgd #include "sys/buf.h"
     53  1.1  cgd #include "sys/protosw.h"
     54  1.1  cgd #include "sys/socket.h"
     55  1.1  cgd #include "sys/syslog.h"
     56  1.1  cgd #include "sys/ioctl.h"
     57  1.1  cgd #include "sys/errno.h"
     58  1.1  cgd 
     59  1.1  cgd #include "net/if.h"
     60  1.1  cgd #include "net/netisr.h"
     61  1.1  cgd #include "net/route.h"
     62  1.1  cgd 
     63  1.1  cgd #ifdef INET
     64  1.1  cgd #include "netinet/in.h"
     65  1.1  cgd #include "netinet/in_systm.h"
     66  1.1  cgd #include "netinet/in_var.h"
     67  1.1  cgd #include "netinet/ip.h"
     68  1.1  cgd #include "netinet/if_ether.h"
     69  1.1  cgd #endif
     70  1.1  cgd 
     71  1.1  cgd #ifdef NS
     72  1.1  cgd #include "netns/ns.h"
     73  1.1  cgd #include "netns/ns_if.h"
     74  1.1  cgd #endif
     75  1.1  cgd 
     76  1.1  cgd #ifdef RMP
     77  1.1  cgd #include "netrmp/rmp.h"
     78  1.1  cgd #include "netrmp/rmp_var.h"
     79  1.1  cgd #endif
     80  1.1  cgd 
     81  1.1  cgd #include "../include/cpu.h"
     82  1.1  cgd #include "../hp300/isr.h"
     83  1.1  cgd #include "../include/mtpr.h"
     84  1.1  cgd #include "device.h"
     85  1.1  cgd #include "if_lereg.h"
     86  1.1  cgd 
     87  1.1  cgd #if NBPFILTER > 0
     88  1.1  cgd #include "../net/bpf.h"
     89  1.1  cgd #include "../net/bpfdesc.h"
     90  1.1  cgd #endif
     91  1.1  cgd 
     92  1.1  cgd /* offsets for:	   ID,   REGS,    MEM,  NVRAM */
     93  1.1  cgd int	lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
     94  1.1  cgd 
     95  1.1  cgd int	leattach();
     96  1.1  cgd struct	driver ledriver = {
     97  1.1  cgd 	leattach, "le",
     98  1.1  cgd };
     99  1.1  cgd 
    100  1.1  cgd struct	isr le_isr[NLE];
    101  1.1  cgd int	ledebug = 0;		/* console error messages */
    102  1.1  cgd 
    103  1.1  cgd int	leintr(), leinit(), leioctl(), lestart(), ether_output();
    104  1.1  cgd struct	mbuf *leget();
    105  1.1  cgd extern	struct ifnet loif;
    106  1.1  cgd 
    107  1.1  cgd /*
    108  1.1  cgd  * Ethernet software status per interface.
    109  1.1  cgd  *
    110  1.1  cgd  * Each interface is referenced by a network interface structure,
    111  1.1  cgd  * le_if, which the routing code uses to locate the interface.
    112  1.1  cgd  * This structure contains the output queue for the interface, its address, ...
    113  1.1  cgd  */
    114  1.1  cgd struct	le_softc {
    115  1.1  cgd 	struct	arpcom sc_ac;	/* common Ethernet structures */
    116  1.1  cgd #define	sc_if	sc_ac.ac_if	/* network-visible interface */
    117  1.1  cgd #define	sc_addr	sc_ac.ac_enaddr	/* hardware Ethernet address */
    118  1.1  cgd 	struct	lereg0 *sc_r0;	/* DIO registers */
    119  1.1  cgd 	struct	lereg1 *sc_r1;	/* LANCE registers */
    120  1.1  cgd 	struct	lereg2 *sc_r2;	/* dual-port RAM */
    121  1.1  cgd 	int	sc_rmd;		/* predicted next rmd to process */
    122  1.1  cgd 	int	sc_runt;
    123  1.1  cgd 	int	sc_jab;
    124  1.1  cgd 	int	sc_merr;
    125  1.1  cgd 	int	sc_babl;
    126  1.1  cgd 	int	sc_cerr;
    127  1.1  cgd 	int	sc_miss;
    128  1.1  cgd 	int	sc_xint;
    129  1.1  cgd 	int	sc_xown;
    130  1.1  cgd 	int	sc_uflo;
    131  1.1  cgd 	int	sc_rxlen;
    132  1.1  cgd 	int	sc_rxoff;
    133  1.1  cgd 	int	sc_txoff;
    134  1.1  cgd 	int	sc_busy;
    135  1.1  cgd 	short	sc_iflags;
    136  1.1  cgd #if NBPFILTER > 0
    137  1.1  cgd 	caddr_t sc_bpf;
    138  1.1  cgd #endif
    139  1.1  cgd } le_softc[NLE];
    140  1.1  cgd 
    141  1.1  cgd /* access LANCE registers */
    142  1.1  cgd #define	LERDWR(cntl, src, dst) \
    143  1.1  cgd 	do { \
    144  1.1  cgd 		(dst) = (src); \
    145  1.1  cgd 	} while (((cntl)->ler0_status & LE_ACK) == 0);
    146  1.1  cgd 
    147  1.1  cgd /*
    148  1.1  cgd  * Interface exists: make available by filling in network interface
    149  1.1  cgd  * record.  System will initialize the interface when it is ready
    150  1.1  cgd  * to accept packets.
    151  1.1  cgd  */
    152  1.1  cgd leattach(hd)
    153  1.1  cgd 	struct hp_device *hd;
    154  1.1  cgd {
    155  1.1  cgd 	register struct lereg0 *ler0;
    156  1.1  cgd 	register struct lereg2 *ler2;
    157  1.1  cgd 	struct lereg2 *lemem = 0;
    158  1.1  cgd 	struct le_softc *le = &le_softc[hd->hp_unit];
    159  1.1  cgd 	struct ifnet *ifp = &le->sc_if;
    160  1.1  cgd 	char *cp;
    161  1.1  cgd 	int i;
    162  1.1  cgd 
    163  1.1  cgd 	ler0 = le->sc_r0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
    164  1.1  cgd 	le->sc_r1 = (struct lereg1 *)(lestd[1] + (int)hd->hp_addr);
    165  1.1  cgd 	ler2 = le->sc_r2 = (struct lereg2 *)(lestd[2] + (int)hd->hp_addr);
    166  1.1  cgd 	if (ler0->ler0_id != LEID)
    167  1.1  cgd 		return(0);
    168  1.1  cgd 	le_isr[hd->hp_unit].isr_intr = leintr;
    169  1.1  cgd 	hd->hp_ipl = le_isr[hd->hp_unit].isr_ipl = LE_IPL(ler0->ler0_status);
    170  1.1  cgd 	le_isr[hd->hp_unit].isr_arg = hd->hp_unit;
    171  1.1  cgd 	ler0->ler0_id = 0xFF;
    172  1.1  cgd 	DELAY(100);
    173  1.1  cgd 
    174  1.1  cgd 	/*
    175  1.1  cgd 	 * Read the ethernet address off the board, one nibble at a time.
    176  1.1  cgd 	 */
    177  1.1  cgd 	cp = (char *)(lestd[3] + (int)hd->hp_addr);
    178  1.1  cgd 	for (i = 0; i < sizeof(le->sc_addr); i++) {
    179  1.1  cgd 		le->sc_addr[i] = (*++cp & 0xF) << 4;
    180  1.1  cgd 		cp++;
    181  1.1  cgd 		le->sc_addr[i] |= *++cp & 0xF;
    182  1.1  cgd 		cp++;
    183  1.1  cgd 	}
    184  1.1  cgd 	printf("le%d: hardware address %s\n", hd->hp_unit,
    185  1.1  cgd 		ether_sprintf(le->sc_addr));
    186  1.1  cgd 
    187  1.1  cgd 	/*
    188  1.1  cgd 	 * Setup for transmit/receive
    189  1.1  cgd 	 */
    190  1.1  cgd 	ler2->ler2_mode = LE_MODE;
    191  1.1  cgd 	ler2->ler2_padr[0] = le->sc_addr[1];
    192  1.1  cgd 	ler2->ler2_padr[1] = le->sc_addr[0];
    193  1.1  cgd 	ler2->ler2_padr[2] = le->sc_addr[3];
    194  1.1  cgd 	ler2->ler2_padr[3] = le->sc_addr[2];
    195  1.1  cgd 	ler2->ler2_padr[4] = le->sc_addr[5];
    196  1.1  cgd 	ler2->ler2_padr[5] = le->sc_addr[4];
    197  1.1  cgd #ifdef RMP
    198  1.1  cgd 	/*
    199  1.1  cgd 	 * Set up logical addr filter to accept multicast 9:0:9:0:0:4
    200  1.1  cgd 	 * This should be an ioctl() to the driver.  (XXX)
    201  1.1  cgd 	 */
    202  1.1  cgd 	ler2->ler2_ladrf0 = 0x00100000;
    203  1.1  cgd 	ler2->ler2_ladrf1 = 0x0;
    204  1.1  cgd #else
    205  1.1  cgd 	ler2->ler2_ladrf0 = 0;
    206  1.1  cgd 	ler2->ler2_ladrf1 = 0;
    207  1.1  cgd #endif
    208  1.1  cgd 	ler2->ler2_rlen = LE_RLEN;
    209  1.1  cgd 	ler2->ler2_rdra = (int)lemem->ler2_rmd;
    210  1.1  cgd 	ler2->ler2_tlen = LE_TLEN;
    211  1.1  cgd 	ler2->ler2_tdra = (int)lemem->ler2_tmd;
    212  1.1  cgd 	isrlink(&le_isr[hd->hp_unit]);
    213  1.1  cgd 	ler0->ler0_status = LE_IE;
    214  1.1  cgd 
    215  1.1  cgd 	ifp->if_unit = hd->hp_unit;
    216  1.1  cgd 	ifp->if_name = "le";
    217  1.1  cgd 	ifp->if_mtu = ETHERMTU;
    218  1.1  cgd 	ifp->if_init = leinit;
    219  1.1  cgd 	ifp->if_ioctl = leioctl;
    220  1.1  cgd 	ifp->if_output = ether_output;
    221  1.1  cgd 	ifp->if_start = lestart;
    222  1.1  cgd 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
    223  1.1  cgd #if NBPFILTER > 0
    224  1.1  cgd 	bpfattach(&le->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
    225  1.1  cgd #endif
    226  1.1  cgd 	if_attach(ifp);
    227  1.1  cgd 	return (1);
    228  1.1  cgd }
    229  1.1  cgd 
    230  1.1  cgd ledrinit(ler2)
    231  1.1  cgd 	register struct lereg2 *ler2;
    232  1.1  cgd {
    233  1.1  cgd 	register struct lereg2 *lemem = 0;
    234  1.1  cgd 	register int i;
    235  1.1  cgd 
    236  1.1  cgd 	for (i = 0; i < LERBUF; i++) {
    237  1.1  cgd 		ler2->ler2_rmd[i].rmd0 = (int)lemem->ler2_rbuf[i];
    238  1.1  cgd 		ler2->ler2_rmd[i].rmd1 = LE_OWN;
    239  1.1  cgd 		ler2->ler2_rmd[i].rmd2 = -LEMTU;
    240  1.1  cgd 		ler2->ler2_rmd[i].rmd3 = 0;
    241  1.1  cgd 	}
    242  1.1  cgd 	for (i = 0; i < LETBUF; i++) {
    243  1.1  cgd 		ler2->ler2_tmd[i].tmd0 = (int)lemem->ler2_tbuf[i];
    244  1.1  cgd 		ler2->ler2_tmd[i].tmd1 = 0;
    245  1.1  cgd 		ler2->ler2_tmd[i].tmd2 = 0;
    246  1.1  cgd 		ler2->ler2_tmd[i].tmd3 = 0;
    247  1.1  cgd 	}
    248  1.1  cgd }
    249  1.1  cgd 
    250  1.1  cgd lereset(unit)
    251  1.1  cgd 	register int unit;
    252  1.1  cgd {
    253  1.1  cgd 	register struct le_softc *le = &le_softc[unit];
    254  1.1  cgd 	register struct lereg0 *ler0 = le->sc_r0;
    255  1.1  cgd 	register struct lereg1 *ler1 = le->sc_r1;
    256  1.1  cgd 	register struct lereg2 *lemem = 0;
    257  1.1  cgd 	register int timo = 100000;
    258  1.1  cgd 	register int stat;
    259  1.1  cgd 
    260  1.1  cgd #ifdef lint
    261  1.1  cgd 	stat = unit;
    262  1.1  cgd #endif
    263  1.1  cgd #if NBPFILTER > 0
    264  1.1  cgd 	if (le->sc_if.if_flags & IFF_PROMISC)
    265  1.1  cgd 		/* set the promiscuous bit */
    266  1.1  cgd 		le->sc_r2->ler2_mode = LE_MODE|0x8000;
    267  1.1  cgd 	else
    268  1.1  cgd 		le->sc_r2->ler2_mode = LE_MODE;
    269  1.1  cgd #endif
    270  1.1  cgd 	LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
    271  1.1  cgd 	LERDWR(ler0, LE_STOP, ler1->ler1_rdp);
    272  1.1  cgd 	ledrinit(le->sc_r2);
    273  1.1  cgd 	le->sc_rmd = 0;
    274  1.1  cgd 	LERDWR(ler0, LE_CSR1, ler1->ler1_rap);
    275  1.1  cgd 	LERDWR(ler0, (int)&lemem->ler2_mode, ler1->ler1_rdp);
    276  1.1  cgd 	LERDWR(ler0, LE_CSR2, ler1->ler1_rap);
    277  1.1  cgd 	LERDWR(ler0, 0, ler1->ler1_rdp);
    278  1.1  cgd 	LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
    279  1.1  cgd 	LERDWR(ler0, LE_INIT, ler1->ler1_rdp);
    280  1.1  cgd 	do {
    281  1.1  cgd 		if (--timo == 0) {
    282  1.1  cgd 			printf("le%d: init timeout, stat = 0x%x\n",
    283  1.1  cgd 			       unit, stat);
    284  1.1  cgd 			break;
    285  1.1  cgd 		}
    286  1.1  cgd 		LERDWR(ler0, ler1->ler1_rdp, stat);
    287  1.1  cgd 	} while ((stat & LE_IDON) == 0);
    288  1.1  cgd 	LERDWR(ler0, LE_STOP, ler1->ler1_rdp);
    289  1.1  cgd 	LERDWR(ler0, LE_CSR3, ler1->ler1_rap);
    290  1.1  cgd 	LERDWR(ler0, LE_BSWP, ler1->ler1_rdp);
    291  1.1  cgd 	LERDWR(ler0, LE_CSR0, ler1->ler1_rap);
    292  1.1  cgd 	LERDWR(ler0, LE_STRT | LE_INEA, ler1->ler1_rdp);
    293  1.1  cgd 	le->sc_if.if_flags &= ~IFF_OACTIVE;
    294  1.1  cgd }
    295  1.1  cgd 
    296  1.1  cgd /*
    297  1.1  cgd  * Initialization of interface
    298  1.1  cgd  */
    299  1.1  cgd leinit(unit)
    300  1.1  cgd 	int unit;
    301  1.1  cgd {
    302  1.1  cgd 	struct le_softc *le = &le_softc[unit];
    303  1.1  cgd 	register struct ifnet *ifp = &le->sc_if;
    304  1.1  cgd 	int s;
    305  1.1  cgd 
    306  1.1  cgd 	/* not yet, if address still unknown */
    307  1.1  cgd 	if (ifp->if_addrlist == (struct ifaddr *)0)
    308  1.1  cgd 		return;
    309  1.1  cgd 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
    310  1.1  cgd 		s = splimp();
    311  1.1  cgd 		ifp->if_flags |= IFF_RUNNING;
    312  1.1  cgd 		lereset(unit);
    313  1.1  cgd 	        (void) lestart(ifp);
    314  1.1  cgd 		splx(s);
    315  1.1  cgd 	}
    316  1.1  cgd }
    317  1.1  cgd 
    318  1.1  cgd /*
    319  1.1  cgd  * Start output on interface.  Get another datagram to send
    320  1.1  cgd  * off of the interface queue, and copy it to the interface
    321  1.1  cgd  * before starting the output.
    322  1.1  cgd  */
    323  1.1  cgd lestart(ifp)
    324  1.1  cgd 	struct ifnet *ifp;
    325  1.1  cgd {
    326  1.1  cgd 	register struct le_softc *le = &le_softc[ifp->if_unit];
    327  1.1  cgd 	register struct letmd *tmd;
    328  1.1  cgd 	register struct mbuf *m;
    329  1.1  cgd 	int len;
    330  1.1  cgd 
    331  1.1  cgd 	if ((le->sc_if.if_flags & IFF_RUNNING) == 0)
    332  1.1  cgd 		return (0);
    333  1.1  cgd 	IF_DEQUEUE(&le->sc_if.if_snd, m);
    334  1.1  cgd 	if (m == 0)
    335  1.1  cgd 		return (0);
    336  1.1  cgd 	len = leput(le->sc_r2->ler2_tbuf[0], m);
    337  1.1  cgd #if NBPFILTER > 0
    338  1.1  cgd 	/*
    339  1.1  cgd 	 * If bpf is listening on this interface, let it
    340  1.1  cgd 	 * see the packet before we commit it to the wire.
    341  1.1  cgd 	 */
    342  1.1  cgd 	if (le->sc_bpf)
    343  1.1  cgd                 bpf_tap(le->sc_bpf, le->sc_r2->ler2_tbuf[0], len);
    344  1.1  cgd #endif
    345  1.1  cgd 	tmd = le->sc_r2->ler2_tmd;
    346  1.1  cgd 	tmd->tmd3 = 0;
    347  1.1  cgd 	tmd->tmd2 = -len;
    348  1.1  cgd 	tmd->tmd1 = LE_OWN | LE_STP | LE_ENP;
    349  1.1  cgd 	le->sc_if.if_flags |= IFF_OACTIVE;
    350  1.1  cgd 	return (0);
    351  1.1  cgd }
    352  1.1  cgd 
    353  1.1  cgd leintr(unit)
    354  1.1  cgd 	register int unit;
    355  1.1  cgd {
    356  1.1  cgd 	register struct le_softc *le = &le_softc[unit];
    357  1.1  cgd 	register struct lereg0 *ler0 = le->sc_r0;
    358  1.1  cgd 	register struct lereg1 *ler1;
    359  1.1  cgd 	register int stat;
    360  1.1  cgd 
    361  1.1  cgd 	if ((ler0->ler0_status & LE_IR) == 0)
    362  1.1  cgd 		return(0);
    363  1.1  cgd 	if (ler0->ler0_status & LE_JAB) {
    364  1.1  cgd 		le->sc_jab++;
    365  1.1  cgd 		lereset(unit);
    366  1.1  cgd 		return(1);
    367  1.1  cgd 	}
    368  1.1  cgd 	ler1 = le->sc_r1;
    369  1.1  cgd 	LERDWR(ler0, ler1->ler1_rdp, stat);
    370  1.1  cgd 	if (stat & LE_SERR) {
    371  1.1  cgd 		leerror(unit, stat);
    372  1.1  cgd 		if (stat & LE_MERR) {
    373  1.1  cgd 			le->sc_merr++;
    374  1.1  cgd 			lereset(unit);
    375  1.1  cgd 			return(1);
    376  1.1  cgd 		}
    377  1.1  cgd 		if (stat & LE_BABL)
    378  1.1  cgd 			le->sc_babl++;
    379  1.1  cgd 		if (stat & LE_CERR)
    380  1.1  cgd 			le->sc_cerr++;
    381  1.1  cgd 		if (stat & LE_MISS)
    382  1.1  cgd 			le->sc_miss++;
    383  1.1  cgd 		LERDWR(ler0, LE_BABL|LE_CERR|LE_MISS|LE_INEA, ler1->ler1_rdp);
    384  1.1  cgd 	}
    385  1.1  cgd 	if ((stat & LE_RXON) == 0) {
    386  1.1  cgd 		le->sc_rxoff++;
    387  1.1  cgd 		lereset(unit);
    388  1.1  cgd 		return(1);
    389  1.1  cgd 	}
    390  1.1  cgd 	if ((stat & LE_TXON) == 0) {
    391  1.1  cgd 		le->sc_txoff++;
    392  1.1  cgd 		lereset(unit);
    393  1.1  cgd 		return(1);
    394  1.1  cgd 	}
    395  1.1  cgd 	if (stat & LE_RINT) {
    396  1.1  cgd 		/* interrupt is cleared in lerint */
    397  1.1  cgd 		lerint(unit);
    398  1.1  cgd 	}
    399  1.1  cgd 	if (stat & LE_TINT) {
    400  1.1  cgd 		LERDWR(ler0, LE_TINT|LE_INEA, ler1->ler1_rdp);
    401  1.1  cgd 		lexint(unit);
    402  1.1  cgd 	}
    403  1.1  cgd 	return(1);
    404  1.1  cgd }
    405  1.1  cgd 
    406  1.1  cgd /*
    407  1.1  cgd  * Ethernet interface transmitter interrupt.
    408  1.1  cgd  * Start another output if more data to send.
    409  1.1  cgd  */
    410  1.1  cgd lexint(unit)
    411  1.1  cgd 	register int unit;
    412  1.1  cgd {
    413  1.1  cgd 	register struct le_softc *le = &le_softc[unit];
    414  1.1  cgd 	register struct letmd *tmd = le->sc_r2->ler2_tmd;
    415  1.1  cgd 
    416  1.1  cgd 	if ((le->sc_if.if_flags & IFF_OACTIVE) == 0) {
    417  1.1  cgd 		le->sc_xint++;
    418  1.1  cgd 		return;
    419  1.1  cgd 	}
    420  1.1  cgd 	if (tmd->tmd1 & LE_OWN) {
    421  1.1  cgd 		le->sc_xown++;
    422  1.1  cgd 		return;
    423  1.1  cgd 	}
    424  1.1  cgd 	if (tmd->tmd1 & LE_ERR) {
    425  1.1  cgd err:
    426  1.1  cgd 		lexerror(unit);
    427  1.1  cgd 		le->sc_if.if_oerrors++;
    428  1.1  cgd 		if (tmd->tmd3 & (LE_TBUFF|LE_UFLO)) {
    429  1.1  cgd 			le->sc_uflo++;
    430  1.1  cgd 			lereset(unit);
    431  1.1  cgd 		}
    432  1.1  cgd 		else if (tmd->tmd3 & LE_LCOL)
    433  1.1  cgd 			le->sc_if.if_collisions++;
    434  1.1  cgd 		else if (tmd->tmd3 & LE_RTRY)
    435  1.1  cgd 			le->sc_if.if_collisions += 16;
    436  1.1  cgd 	}
    437  1.1  cgd 	else if (tmd->tmd3 & LE_TBUFF)
    438  1.1  cgd 		/* XXX documentation says BUFF not included in ERR */
    439  1.1  cgd 		goto err;
    440  1.1  cgd 	else if (tmd->tmd1 & LE_ONE)
    441  1.1  cgd 		le->sc_if.if_collisions++;
    442  1.1  cgd 	else if (tmd->tmd1 & LE_MORE)
    443  1.1  cgd 		/* what is the real number? */
    444  1.1  cgd 		le->sc_if.if_collisions += 2;
    445  1.1  cgd 	else
    446  1.1  cgd 		le->sc_if.if_opackets++;
    447  1.1  cgd 	le->sc_if.if_flags &= ~IFF_OACTIVE;
    448  1.1  cgd 	(void) lestart(&le->sc_if);
    449  1.1  cgd }
    450  1.1  cgd 
    451  1.1  cgd #define	LENEXTRMP \
    452  1.1  cgd 	if (++bix == LERBUF) bix = 0, rmd = le->sc_r2->ler2_rmd; else ++rmd
    453  1.1  cgd 
    454  1.1  cgd /*
    455  1.1  cgd  * Ethernet interface receiver interrupt.
    456  1.1  cgd  * If input error just drop packet.
    457  1.1  cgd  * Decapsulate packet based on type and pass to type specific
    458  1.1  cgd  * higher-level input routine.
    459  1.1  cgd  */
    460  1.1  cgd lerint(unit)
    461  1.1  cgd 	int unit;
    462  1.1  cgd {
    463  1.1  cgd 	register struct le_softc *le = &le_softc[unit];
    464  1.1  cgd 	register int bix = le->sc_rmd;
    465  1.1  cgd 	register struct lermd *rmd = &le->sc_r2->ler2_rmd[bix];
    466  1.1  cgd 
    467  1.1  cgd 	/*
    468  1.1  cgd 	 * Out of sync with hardware, should never happen?
    469  1.1  cgd 	 */
    470  1.1  cgd 	if (rmd->rmd1 & LE_OWN) {
    471  1.1  cgd 		LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
    472  1.1  cgd 		return;
    473  1.1  cgd 	}
    474  1.1  cgd 
    475  1.1  cgd 	/*
    476  1.1  cgd 	 * Process all buffers with valid data
    477  1.1  cgd 	 */
    478  1.1  cgd 	while ((rmd->rmd1 & LE_OWN) == 0) {
    479  1.1  cgd 		int len = rmd->rmd3;
    480  1.1  cgd 
    481  1.1  cgd 		/* Clear interrupt to avoid race condition */
    482  1.1  cgd 		LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
    483  1.1  cgd 
    484  1.1  cgd 		if (rmd->rmd1 & LE_ERR) {
    485  1.1  cgd 			le->sc_rmd = bix;
    486  1.1  cgd 			lererror(unit, "bad packet");
    487  1.1  cgd 			le->sc_if.if_ierrors++;
    488  1.1  cgd 		} else if ((rmd->rmd1 & (LE_STP|LE_ENP)) != (LE_STP|LE_ENP)) {
    489  1.1  cgd 			/*
    490  1.1  cgd 			 * Find the end of the packet so we can see how long
    491  1.1  cgd 			 * it was.  We still throw it away.
    492  1.1  cgd 			 */
    493  1.1  cgd 			do {
    494  1.1  cgd 				LERDWR(le->sc_r0, LE_RINT|LE_INEA,
    495  1.1  cgd 				       le->sc_r1->ler1_rdp);
    496  1.1  cgd 				rmd->rmd3 = 0;
    497  1.1  cgd 				rmd->rmd1 = LE_OWN;
    498  1.1  cgd 				LENEXTRMP;
    499  1.1  cgd 			} while (!(rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)));
    500  1.1  cgd 			le->sc_rmd = bix;
    501  1.1  cgd 			lererror(unit, "chained buffer");
    502  1.1  cgd 			le->sc_rxlen++;
    503  1.1  cgd 			/*
    504  1.1  cgd 			 * If search terminated without successful completion
    505  1.1  cgd 			 * we reset the hardware (conservative).
    506  1.1  cgd 			 */
    507  1.1  cgd 			if ((rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)) !=
    508  1.1  cgd 			    LE_ENP) {
    509  1.1  cgd 				lereset(unit);
    510  1.1  cgd 				return;
    511  1.1  cgd 			}
    512  1.1  cgd 		} else
    513  1.1  cgd 			leread(unit, le->sc_r2->ler2_rbuf[bix], len);
    514  1.1  cgd 		rmd->rmd3 = 0;
    515  1.1  cgd 		rmd->rmd1 = LE_OWN;
    516  1.1  cgd 		LENEXTRMP;
    517  1.1  cgd 	}
    518  1.1  cgd 	le->sc_rmd = bix;
    519  1.1  cgd }
    520  1.1  cgd 
    521  1.1  cgd leread(unit, buf, len)
    522  1.1  cgd 	int unit;
    523  1.1  cgd 	char *buf;
    524  1.1  cgd 	int len;
    525  1.1  cgd {
    526  1.1  cgd 	register struct le_softc *le = &le_softc[unit];
    527  1.1  cgd 	register struct ether_header *et;
    528  1.1  cgd     	struct mbuf *m;
    529  1.1  cgd 	int off, resid;
    530  1.1  cgd 
    531  1.1  cgd 	le->sc_if.if_ipackets++;
    532  1.1  cgd 	et = (struct ether_header *)buf;
    533  1.1  cgd 	et->ether_type = ntohs((u_short)et->ether_type);
    534  1.1  cgd 	/* adjust input length to account for header and CRC */
    535  1.1  cgd 	len = len - sizeof(struct ether_header) - 4;
    536  1.1  cgd 
    537  1.1  cgd #ifdef RMP
    538  1.1  cgd 	/*  (XXX)
    539  1.1  cgd 	 *
    540  1.1  cgd 	 *  If Ethernet Type field is < MaxPacketSize, we probably have
    541  1.1  cgd 	 *  a IEEE802 packet here.  Make sure that the size is at least
    542  1.1  cgd 	 *  that of the HP LLC.  Also do sanity checks on length of LLC
    543  1.1  cgd 	 *  (old Ethernet Type field) and packet length.
    544  1.1  cgd 	 *
    545  1.1  cgd 	 *  Provided the above checks succeed, change `len' to reflect
    546  1.1  cgd 	 *  the length of the LLC (i.e. et->ether_type) and change the
    547  1.1  cgd 	 *  type field to ETHERTYPE_IEEE so we can switch() on it later.
    548  1.1  cgd 	 *  Yes, this is a hack and will eventually be done "right".
    549  1.1  cgd 	 */
    550  1.1  cgd 	if (et->ether_type <= IEEE802LEN_MAX && len >= sizeof(struct hp_llc) &&
    551  1.1  cgd 	    len >= et->ether_type && len >= IEEE802LEN_MIN) {
    552  1.1  cgd 		len = et->ether_type;
    553  1.1  cgd 		et->ether_type = ETHERTYPE_IEEE;	/* hack! */
    554  1.1  cgd 	}
    555  1.1  cgd #endif
    556  1.1  cgd 
    557  1.1  cgd #define	ledataaddr(et, off, type)	((type)(((caddr_t)((et)+1)+(off))))
    558  1.1  cgd 	if (et->ether_type >= ETHERTYPE_TRAIL &&
    559  1.1  cgd 	    et->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
    560  1.1  cgd 		off = (et->ether_type - ETHERTYPE_TRAIL) * 512;
    561  1.1  cgd 		if (off >= ETHERMTU)
    562  1.1  cgd 			return;		/* sanity */
    563  1.1  cgd 		et->ether_type = ntohs(*ledataaddr(et, off, u_short *));
    564  1.1  cgd 		resid = ntohs(*(ledataaddr(et, off+2, u_short *)));
    565  1.1  cgd 		if (off + resid > len)
    566  1.1  cgd 			return;		/* sanity */
    567  1.1  cgd 		len = off + resid;
    568  1.1  cgd 	} else
    569  1.1  cgd 		off = 0;
    570  1.1  cgd 
    571  1.1  cgd 	if (len <= 0) {
    572  1.1  cgd 		if (ledebug)
    573  1.1  cgd 			log(LOG_WARNING,
    574  1.1  cgd 			    "le%d: ierror(runt packet): from %s: len=%d\n",
    575  1.1  cgd 			    unit, ether_sprintf(et->ether_shost), len);
    576  1.1  cgd 		le->sc_runt++;
    577  1.1  cgd 		le->sc_if.if_ierrors++;
    578  1.1  cgd 		return;
    579  1.1  cgd 	}
    580  1.1  cgd #if NBPFILTER > 0
    581  1.1  cgd 	/*
    582  1.1  cgd 	 * Check if there's a bpf filter listening on this interface.
    583  1.1  cgd 	 * If so, hand off the raw packet to bpf, which must deal with
    584  1.1  cgd 	 * trailers in its own way.
    585  1.1  cgd 	 */
    586  1.1  cgd 	if (le->sc_bpf) {
    587  1.1  cgd 		bpf_tap(le->sc_bpf, buf, len + sizeof(struct ether_header));
    588  1.1  cgd 
    589  1.1  cgd 		/*
    590  1.1  cgd 		 * Note that the interface cannot be in promiscuous mode if
    591  1.1  cgd 		 * there are no bpf listeners.  And if we are in promiscuous
    592  1.1  cgd 		 * mode, we have to check if this packet is really ours.
    593  1.1  cgd 		 *
    594  1.1  cgd 		 * XXX This test does not support multicasts.
    595  1.1  cgd 		 */
    596  1.1  cgd 		if ((le->sc_if.if_flags & IFF_PROMISC)
    597  1.1  cgd 		    && bcmp(et->ether_dhost, le->sc_addr,
    598  1.1  cgd 			    sizeof(et->ether_dhost)) != 0
    599  1.1  cgd 		    && bcmp(et->ether_dhost, etherbroadcastaddr,
    600  1.1  cgd 			    sizeof(et->ether_dhost)) != 0)
    601  1.1  cgd 			return;
    602  1.1  cgd 	}
    603  1.1  cgd #endif
    604  1.1  cgd 	/*
    605  1.1  cgd 	 * Pull packet off interface.  Off is nonzero if packet
    606  1.1  cgd 	 * has trailing header; leget will then force this header
    607  1.1  cgd 	 * information to be at the front, but we still have to drop
    608  1.1  cgd 	 * the type and length which are at the front of any trailer data.
    609  1.1  cgd 	 */
    610  1.1  cgd 	m = leget(buf, len, off, &le->sc_if);
    611  1.1  cgd 	if (m == 0)
    612  1.1  cgd 		return;
    613  1.1  cgd #ifdef RMP
    614  1.1  cgd 	/*
    615  1.1  cgd 	 * (XXX)
    616  1.1  cgd 	 * This needs to be integrated with the ISO stuff in ether_input()
    617  1.1  cgd 	 */
    618  1.1  cgd 	if (et->ether_type == ETHERTYPE_IEEE) {
    619  1.1  cgd 		/*
    620  1.1  cgd 		 *  Snag the Logical Link Control header (IEEE 802.2).
    621  1.1  cgd 		 */
    622  1.1  cgd 		struct hp_llc *llc = &(mtod(m, struct rmp_packet *)->hp_llc);
    623  1.1  cgd 
    624  1.1  cgd 		/*
    625  1.1  cgd 		 *  If the DSAP (and HP's extended DXSAP) indicate this
    626  1.1  cgd 		 *  is an RMP packet, hand it to the raw input routine.
    627  1.1  cgd 		 */
    628  1.1  cgd 		if (llc->dsap == IEEE_DSAP_HP && llc->dxsap == HPEXT_DXSAP) {
    629  1.1  cgd 			static struct sockproto rmp_sp = {AF_RMP,RMPPROTO_BOOT};
    630  1.1  cgd 			static struct sockaddr rmp_src = {AF_RMP};
    631  1.1  cgd 			static struct sockaddr rmp_dst = {AF_RMP};
    632  1.1  cgd 
    633  1.1  cgd 			bcopy(et->ether_shost, rmp_src.sa_data,
    634  1.1  cgd 			      sizeof(et->ether_shost));
    635  1.1  cgd 			bcopy(et->ether_dhost, rmp_dst.sa_data,
    636  1.1  cgd 			      sizeof(et->ether_dhost));
    637  1.1  cgd 
    638  1.1  cgd 			raw_input(m, &rmp_sp, &rmp_src, &rmp_dst);
    639  1.1  cgd 			return;
    640  1.1  cgd 		}
    641  1.1  cgd 	}
    642  1.1  cgd #endif
    643  1.1  cgd 	ether_input(&le->sc_if, et, m);
    644  1.1  cgd }
    645  1.1  cgd 
    646  1.1  cgd /*
    647  1.1  cgd  * Routine to copy from mbuf chain to transmit
    648  1.1  cgd  * buffer in board local memory.
    649  1.1  cgd  */
    650  1.1  cgd leput(lebuf, m)
    651  1.1  cgd 	register char *lebuf;
    652  1.1  cgd 	register struct mbuf *m;
    653  1.1  cgd {
    654  1.1  cgd 	register struct mbuf *mp;
    655  1.1  cgd 	register int len, tlen = 0;
    656  1.1  cgd 
    657  1.1  cgd 	for (mp = m; mp; mp = mp->m_next) {
    658  1.1  cgd 		len = mp->m_len;
    659  1.1  cgd 		if (len == 0)
    660  1.1  cgd 			continue;
    661  1.1  cgd 		tlen += len;
    662  1.1  cgd 		bcopy(mtod(mp, char *), lebuf, len);
    663  1.1  cgd 		lebuf += len;
    664  1.1  cgd 	}
    665  1.1  cgd 	m_freem(m);
    666  1.1  cgd 	if (tlen < LEMINSIZE) {
    667  1.1  cgd 		bzero(lebuf, LEMINSIZE - tlen);
    668  1.1  cgd 		tlen = LEMINSIZE;
    669  1.1  cgd 	}
    670  1.1  cgd 	return(tlen);
    671  1.1  cgd }
    672  1.1  cgd 
    673  1.1  cgd /*
    674  1.1  cgd  * Routine to copy from board local memory into mbufs.
    675  1.1  cgd  */
    676  1.1  cgd struct mbuf *
    677  1.1  cgd leget(lebuf, totlen, off0, ifp)
    678  1.1  cgd 	char *lebuf;
    679  1.1  cgd 	int totlen, off0;
    680  1.1  cgd 	struct ifnet *ifp;
    681  1.1  cgd {
    682  1.1  cgd 	register struct mbuf *m;
    683  1.1  cgd 	struct mbuf *top = 0, **mp = &top;
    684  1.1  cgd 	register int off = off0, len;
    685  1.1  cgd 	register char *cp;
    686  1.1  cgd 	char *epkt;
    687  1.1  cgd 
    688  1.1  cgd 	lebuf += sizeof (struct ether_header);
    689  1.1  cgd 	cp = lebuf;
    690  1.1  cgd 	epkt = cp + totlen;
    691  1.1  cgd 	if (off) {
    692  1.1  cgd 		cp += off + 2 * sizeof(u_short);
    693  1.1  cgd 		totlen -= 2 * sizeof(u_short);
    694  1.1  cgd 	}
    695  1.1  cgd 
    696  1.1  cgd 	MGETHDR(m, M_DONTWAIT, MT_DATA);
    697  1.1  cgd 	if (m == 0)
    698  1.1  cgd 		return (0);
    699  1.1  cgd 	m->m_pkthdr.rcvif = ifp;
    700  1.1  cgd 	m->m_pkthdr.len = totlen;
    701  1.1  cgd 	m->m_len = MHLEN;
    702  1.1  cgd 
    703  1.1  cgd 	while (totlen > 0) {
    704  1.1  cgd 		if (top) {
    705  1.1  cgd 			MGET(m, M_DONTWAIT, MT_DATA);
    706  1.1  cgd 			if (m == 0) {
    707  1.1  cgd 				m_freem(top);
    708  1.1  cgd 				return (0);
    709  1.1  cgd 			}
    710  1.1  cgd 			m->m_len = MLEN;
    711  1.1  cgd 		}
    712  1.1  cgd 		len = min(totlen, epkt - cp);
    713  1.1  cgd 		if (len >= MINCLSIZE) {
    714  1.1  cgd 			MCLGET(m, M_DONTWAIT);
    715  1.1  cgd 			if (m->m_flags & M_EXT)
    716  1.1  cgd 				m->m_len = len = min(len, MCLBYTES);
    717  1.1  cgd 			else
    718  1.1  cgd 				len = m->m_len;
    719  1.1  cgd 		} else {
    720  1.1  cgd 			/*
    721  1.1  cgd 			 * Place initial small packet/header at end of mbuf.
    722  1.1  cgd 			 */
    723  1.1  cgd 			if (len < m->m_len) {
    724  1.1  cgd 				if (top == 0 && len + max_linkhdr <= m->m_len)
    725  1.1  cgd 					m->m_data += max_linkhdr;
    726  1.1  cgd 				m->m_len = len;
    727  1.1  cgd 			} else
    728  1.1  cgd 				len = m->m_len;
    729  1.1  cgd 		}
    730  1.1  cgd 		bcopy(cp, mtod(m, caddr_t), (unsigned)len);
    731  1.1  cgd 		cp += len;
    732  1.1  cgd 		*mp = m;
    733  1.1  cgd 		mp = &m->m_next;
    734  1.1  cgd 		totlen -= len;
    735  1.1  cgd 		if (cp == epkt)
    736  1.1  cgd 			cp = lebuf;
    737  1.1  cgd 	}
    738  1.1  cgd 	return (top);
    739  1.1  cgd }
    740  1.1  cgd 
    741  1.1  cgd /*
    742  1.1  cgd  * Process an ioctl request.
    743  1.1  cgd  */
    744  1.1  cgd leioctl(ifp, cmd, data)
    745  1.1  cgd 	register struct ifnet *ifp;
    746  1.1  cgd 	int cmd;
    747  1.1  cgd 	caddr_t data;
    748  1.1  cgd {
    749  1.1  cgd 	register struct ifaddr *ifa = (struct ifaddr *)data;
    750  1.1  cgd 	struct le_softc *le = &le_softc[ifp->if_unit];
    751  1.1  cgd 	struct lereg1 *ler1 = le->sc_r1;
    752  1.1  cgd 	int s = splimp(), error = 0;
    753  1.1  cgd 
    754  1.1  cgd 	switch (cmd) {
    755  1.1  cgd 
    756  1.1  cgd 	case SIOCSIFADDR:
    757  1.1  cgd 		ifp->if_flags |= IFF_UP;
    758  1.1  cgd 		switch (ifa->ifa_addr->sa_family) {
    759  1.1  cgd #ifdef INET
    760  1.1  cgd 		case AF_INET:
    761  1.1  cgd 			leinit(ifp->if_unit);	/* before arpwhohas */
    762  1.1  cgd 			((struct arpcom *)ifp)->ac_ipaddr =
    763  1.1  cgd 				IA_SIN(ifa)->sin_addr;
    764  1.1  cgd 			arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
    765  1.1  cgd 			break;
    766  1.1  cgd #endif
    767  1.1  cgd #ifdef NS
    768  1.1  cgd 		case AF_NS:
    769  1.1  cgd 		    {
    770  1.1  cgd 			register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
    771  1.1  cgd 
    772  1.1  cgd 			if (ns_nullhost(*ina))
    773  1.1  cgd 				ina->x_host = *(union ns_host *)(le->sc_addr);
    774  1.1  cgd 			else {
    775  1.1  cgd 				/*
    776  1.1  cgd 				 * The manual says we can't change the address
    777  1.1  cgd 				 * while the receiver is armed,
    778  1.1  cgd 				 * so reset everything
    779  1.1  cgd 				 */
    780  1.1  cgd 				ifp->if_flags &= ~IFF_RUNNING;
    781  1.1  cgd 				bcopy((caddr_t)ina->x_host.c_host,
    782  1.1  cgd 				    (caddr_t)le->sc_addr, sizeof(le->sc_addr));
    783  1.1  cgd 			}
    784  1.1  cgd 			leinit(ifp->if_unit); /* does le_setaddr() */
    785  1.1  cgd 			break;
    786  1.1  cgd 		    }
    787  1.1  cgd #endif
    788  1.1  cgd 		default:
    789  1.1  cgd 			leinit(ifp->if_unit);
    790  1.1  cgd 			break;
    791  1.1  cgd 		}
    792  1.1  cgd 		break;
    793  1.1  cgd 
    794  1.1  cgd 	case SIOCSIFFLAGS:
    795  1.1  cgd 		if ((ifp->if_flags & IFF_UP) == 0 &&
    796  1.1  cgd 		    ifp->if_flags & IFF_RUNNING) {
    797  1.1  cgd 			LERDWR(le->sc_r0, LE_STOP, ler1->ler1_rdp);
    798  1.1  cgd 			ifp->if_flags &= ~IFF_RUNNING;
    799  1.1  cgd 		} else if (ifp->if_flags & IFF_UP &&
    800  1.1  cgd 		    (ifp->if_flags & IFF_RUNNING) == 0)
    801  1.1  cgd 			leinit(ifp->if_unit);
    802  1.1  cgd 		/*
    803  1.1  cgd 		 * If the state of the promiscuous bit changes, the interface
    804  1.1  cgd 		 * must be reset to effect the change.
    805  1.1  cgd 		 */
    806  1.1  cgd 		if (((ifp->if_flags ^ le->sc_iflags) & IFF_PROMISC) &&
    807  1.1  cgd 		    (ifp->if_flags & IFF_RUNNING)) {
    808  1.1  cgd 			le->sc_iflags = ifp->if_flags;
    809  1.1  cgd 			lereset(ifp->if_unit);
    810  1.1  cgd 			lestart(ifp);
    811  1.1  cgd 		}
    812  1.1  cgd 		break;
    813  1.1  cgd 
    814  1.1  cgd 	default:
    815  1.1  cgd 		error = EINVAL;
    816  1.1  cgd 	}
    817  1.1  cgd 	splx(s);
    818  1.1  cgd 	return (error);
    819  1.1  cgd }
    820  1.1  cgd 
    821  1.1  cgd leerror(unit, stat)
    822  1.1  cgd 	int unit;
    823  1.1  cgd 	int stat;
    824  1.1  cgd {
    825  1.1  cgd 	if (!ledebug)
    826  1.1  cgd 		return;
    827  1.1  cgd 
    828  1.1  cgd 	/*
    829  1.1  cgd 	 * Not all transceivers implement heartbeat
    830  1.1  cgd 	 * so we only log CERR once.
    831  1.1  cgd 	 */
    832  1.1  cgd 	if ((stat & LE_CERR) && le_softc[unit].sc_cerr)
    833  1.1  cgd 		return;
    834  1.1  cgd 	log(LOG_WARNING,
    835  1.1  cgd 	    "le%d: error: stat=%b\n", unit,
    836  1.1  cgd 	    stat,
    837  1.1  cgd 	    "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT");
    838  1.1  cgd }
    839  1.1  cgd 
    840  1.1  cgd lererror(unit, msg)
    841  1.1  cgd 	int unit;
    842  1.1  cgd 	char *msg;
    843  1.1  cgd {
    844  1.1  cgd 	register struct le_softc *le = &le_softc[unit];
    845  1.1  cgd 	register struct lermd *rmd;
    846  1.1  cgd 	int len;
    847  1.1  cgd 
    848  1.1  cgd 	if (!ledebug)
    849  1.1  cgd 		return;
    850  1.1  cgd 
    851  1.1  cgd 	rmd = &le->sc_r2->ler2_rmd[le->sc_rmd];
    852  1.1  cgd 	len = rmd->rmd3;
    853  1.1  cgd 	log(LOG_WARNING,
    854  1.1  cgd 	    "le%d: ierror(%s): from %s: buf=%d, len=%d, rmd1=%b\n",
    855  1.1  cgd 	    unit, msg,
    856  1.1  cgd 	    len > 11 ? ether_sprintf(&le->sc_r2->ler2_rbuf[le->sc_rmd][6]) : "unknown",
    857  1.1  cgd 	    le->sc_rmd, len,
    858  1.1  cgd 	    rmd->rmd1,
    859  1.1  cgd 	    "\20\20OWN\17ERR\16FRAM\15OFLO\14CRC\13RBUF\12STP\11ENP");
    860  1.1  cgd }
    861  1.1  cgd 
    862  1.1  cgd lexerror(unit)
    863  1.1  cgd 	int unit;
    864  1.1  cgd {
    865  1.1  cgd 	register struct le_softc *le = &le_softc[unit];
    866  1.1  cgd 	register struct letmd *tmd;
    867  1.1  cgd 	int len;
    868  1.1  cgd 
    869  1.1  cgd 	if (!ledebug)
    870  1.1  cgd 		return;
    871  1.1  cgd 
    872  1.1  cgd 	tmd = le->sc_r2->ler2_tmd;
    873  1.1  cgd 	len = -tmd->tmd2;
    874  1.1  cgd 	log(LOG_WARNING,
    875  1.1  cgd 	    "le%d: oerror: to %s: buf=%d, len=%d, tmd1=%b, tmd3=%b\n",
    876  1.1  cgd 	    unit,
    877  1.1  cgd 	    len > 5 ? ether_sprintf(&le->sc_r2->ler2_tbuf[0][0]) : "unknown",
    878  1.1  cgd 	    0, len,
    879  1.1  cgd 	    tmd->tmd1,
    880  1.1  cgd 	    "\20\20OWN\17ERR\16RES\15MORE\14ONE\13DEF\12STP\11ENP",
    881  1.1  cgd 	    tmd->tmd3,
    882  1.1  cgd 	    "\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY");
    883  1.1  cgd }
    884  1.1  cgd #endif
    885