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