Home | History | Annotate | Line # | Download | only in netboot
if_le.c revision 1.7.16.1
      1  1.7.16.1      yamt /*	$NetBSD: if_le.c,v 1.7.16.1 2008/01/21 09:37:50 yamt Exp $	*/
      2       1.1     chuck 
      3       1.1     chuck /*
      4       1.1     chuck  * Copyright (c) 1995 Theo de Raadt
      5       1.1     chuck  *
      6       1.1     chuck  * Redistribution and use in source and binary forms, with or without
      7       1.1     chuck  * modification, are permitted provided that the following conditions
      8       1.1     chuck  * are met:
      9       1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     10       1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     11       1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     13       1.1     chuck  *    documentation and/or other materials provided with the distribution.
     14       1.1     chuck  *
     15       1.1     chuck  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16       1.1     chuck  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17       1.1     chuck  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18       1.1     chuck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     19       1.1     chuck  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20       1.1     chuck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21       1.1     chuck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22       1.1     chuck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23       1.1     chuck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24       1.1     chuck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25       1.1     chuck  * SUCH DAMAGE.
     26       1.1     chuck  *
     27       1.1     chuck  * Copyright (c) 1993 Adam Glass
     28       1.1     chuck  * All rights reserved.
     29       1.1     chuck  *
     30       1.1     chuck  * Redistribution and use in source and binary forms, with or without
     31       1.1     chuck  * modification, are permitted provided that the following conditions
     32       1.1     chuck  * are met:
     33       1.1     chuck  * 1. Redistributions of source code must retain the above copyright
     34       1.1     chuck  *    notice, this list of conditions and the following disclaimer.
     35       1.1     chuck  * 2. Redistributions in binary form must reproduce the above copyright
     36       1.1     chuck  *    notice, this list of conditions and the following disclaimer in the
     37       1.1     chuck  *    documentation and/or other materials provided with the distribution.
     38       1.1     chuck  * 3. All advertising materials mentioning features or use of this software
     39       1.1     chuck  *    must display the following acknowledgement:
     40       1.1     chuck  *	This product includes software developed by Adam Glass.
     41       1.1     chuck  * 4. The name of the Author may not be used to endorse or promote products
     42       1.1     chuck  *    derived from this software without specific prior written permission.
     43       1.1     chuck  *
     44       1.1     chuck  * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
     45       1.1     chuck  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     46       1.1     chuck  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     47       1.1     chuck  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     48       1.1     chuck  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     49       1.1     chuck  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     50       1.1     chuck  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     51       1.1     chuck  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     52       1.1     chuck  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     53       1.1     chuck  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     54       1.1     chuck  * SUCH DAMAGE.
     55       1.1     chuck  */
     56       1.1     chuck 
     57       1.1     chuck #include <sys/param.h>
     58       1.1     chuck #include <sys/types.h>
     59       1.1     chuck 
     60       1.1     chuck #include <netinet/in.h>
     61       1.1     chuck #include <netinet/in_systm.h>
     62       1.1     chuck 
     63       1.1     chuck #include <machine/prom.h>
     64       1.1     chuck 
     65       1.2  jdolecek #include <lib/libkern/libkern.h>
     66       1.2  jdolecek #include <lib/libsa/stand.h>
     67       1.2  jdolecek #include <lib/libsa/net.h>
     68       1.2  jdolecek 
     69       1.1     chuck #include "libsa.h"
     70       1.1     chuck #include "netif.h"
     71       1.1     chuck #include "config.h"
     72       1.2  jdolecek #include "dev_net.h"
     73       1.1     chuck 
     74       1.1     chuck #include "if_lereg.h"
     75       1.1     chuck 
     76       1.1     chuck int     le_debug = 0;
     77       1.1     chuck 
     78  1.7.16.1      yamt void le_end(struct netif *);
     79  1.7.16.1      yamt void le_error(struct netif *, char *, volatile struct lereg1 *);
     80  1.7.16.1      yamt int le_get(struct iodesc *, void *, size_t, time_t);
     81  1.7.16.1      yamt void le_init(struct iodesc *, void *);
     82  1.7.16.1      yamt int le_match(struct netif *, void *);
     83  1.7.16.1      yamt int le_poll(struct iodesc *, void *, int);
     84  1.7.16.1      yamt int le_probe(struct netif *, void *);
     85  1.7.16.1      yamt int le_put(struct iodesc *, void *, size_t);
     86  1.7.16.1      yamt void le_reset(struct netif *, u_char *);
     87       1.1     chuck 
     88       1.1     chuck struct netif_stats le_stats;
     89       1.1     chuck 
     90       1.1     chuck struct netif_dif le0_dif = {
     91       1.1     chuck 	0,			/* unit */
     92       1.1     chuck 	1,			/* nsel */
     93       1.1     chuck 	&le_stats,
     94       1.1     chuck 	0,
     95       1.1     chuck 	0,
     96       1.1     chuck };
     97       1.1     chuck 
     98       1.1     chuck struct netif_driver le_driver = {
     99       1.1     chuck 	"le",			/* netif_bname */
    100       1.1     chuck 	le_match,		/* match */
    101       1.1     chuck 	le_probe,		/* probe */
    102       1.1     chuck 	le_init,		/* init */
    103       1.1     chuck 	le_get,			/* get */
    104       1.1     chuck 	le_put,			/* put */
    105       1.1     chuck 	le_end,			/* end */
    106       1.1     chuck 	&le0_dif,		/* netif_ifs */
    107       1.1     chuck 	1,			/* netif_nifs */
    108       1.1     chuck };
    109       1.1     chuck 
    110       1.1     chuck struct le_configuration {
    111       1.1     chuck 	unsigned int phys_addr;
    112       1.1     chuck 	int     used;
    113       1.1     chuck } le_config[] = {
    114       1.1     chuck 	{ LANCE_REG_ADDR, 0 }
    115       1.1     chuck };
    116       1.1     chuck 
    117  1.7.16.1      yamt int     nle_config = __arraycount(le_config);
    118       1.1     chuck 
    119       1.1     chuck struct {
    120       1.1     chuck 	struct lereg1 *sc_r1;	/* LANCE registers */
    121       1.1     chuck 	struct lereg2 *sc_r2;	/* RAM */
    122       1.1     chuck 	int     next_rmd;
    123       1.1     chuck 	int     next_tmd;
    124       1.1     chuck }       le_softc;
    125       1.1     chuck 
    126       1.1     chuck int
    127  1.7.16.1      yamt le_match(struct netif *nif, void *machdep_hint)
    128       1.1     chuck {
    129       1.1     chuck 	char   *name;
    130       1.1     chuck 	int     i, val = 0;
    131       1.1     chuck 
    132       1.1     chuck 	if (bugargs.cputyp != CPU_147)
    133  1.7.16.1      yamt 		return 0;
    134       1.1     chuck 	name = machdep_hint;
    135       1.3       scw 	if (name && !memcmp(le_driver.netif_bname, name, 2))
    136       1.1     chuck 		val += 10;
    137       1.1     chuck 	for (i = 0; i < nle_config; i++) {
    138       1.1     chuck 		if (le_config[i].used)
    139       1.1     chuck 			continue;
    140       1.1     chuck 		if (le_debug)
    141       1.1     chuck 			printf("le%d: le_match --> %d\n", i, val + 1);
    142       1.1     chuck 		le_config[i].used++;
    143       1.1     chuck 		return val + 1;
    144       1.1     chuck 	}
    145       1.1     chuck 	if (le_debug)
    146       1.1     chuck 		printf("le%d: le_match --> 0\n", i);
    147       1.1     chuck 	return 0;
    148       1.1     chuck }
    149       1.1     chuck 
    150       1.1     chuck int
    151  1.7.16.1      yamt le_probe(struct netif *nif, void *machdep_hint)
    152       1.1     chuck {
    153       1.1     chuck 
    154       1.1     chuck 	/* the set unit is the current unit */
    155       1.1     chuck 	if (le_debug)
    156       1.1     chuck 		printf("le%d: le_probe called\n", nif->nif_unit);
    157       1.1     chuck 
    158       1.1     chuck 	if (bugargs.cputyp == CPU_147)
    159       1.1     chuck 		return 0;
    160       1.1     chuck 	return 1;
    161       1.1     chuck }
    162       1.1     chuck 
    163       1.1     chuck void
    164  1.7.16.1      yamt le_error(struct netif *nif, char *str, volatile struct lereg1 *ler1)
    165       1.1     chuck {
    166  1.7.16.1      yamt 
    167       1.1     chuck 	/* ler1->ler1_rap = LE_CSRO done in caller */
    168       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_BABL)
    169       1.5    provos 		panic("le%d: been babbling, found by '%s'", nif->nif_unit, str);
    170       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_CERR) {
    171       1.1     chuck 		le_stats.collision_error++;
    172       1.1     chuck 		ler1->ler1_rdp = LE_C0_CERR;
    173       1.1     chuck 	}
    174       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_MISS) {
    175       1.1     chuck 		le_stats.missed++;
    176       1.1     chuck 		ler1->ler1_rdp = LE_C0_MISS;
    177       1.1     chuck 	}
    178       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_MERR) {
    179       1.1     chuck 		printf("le%d: memory error in '%s'\n", nif->nif_unit, str);
    180       1.1     chuck 		panic("memory error");
    181       1.1     chuck 	}
    182       1.1     chuck }
    183       1.1     chuck 
    184       1.1     chuck void
    185  1.7.16.1      yamt le_reset(struct netif *nif, u_char *myea)
    186       1.1     chuck {
    187       1.1     chuck 	struct lereg1 *ler1 = le_softc.sc_r1;
    188       1.1     chuck 	struct lereg2 *ler2 = le_softc.sc_r2;
    189       1.1     chuck 	unsigned int a;
    190       1.4       scw 	int     timo = 100000, stat = 0, i;
    191       1.1     chuck 
    192       1.1     chuck 	if (le_debug)
    193       1.1     chuck 		printf("le%d: le_reset called\n", nif->nif_unit);
    194       1.1     chuck 	ler1->ler1_rap = LE_CSR0;
    195       1.1     chuck 	ler1->ler1_rdp = LE_C0_STOP;	/* do nothing until we are finished */
    196       1.1     chuck 
    197       1.3       scw 	memset(ler2, 0, sizeof(*ler2));
    198       1.1     chuck 
    199       1.1     chuck 	ler2->ler2_mode = LE_MODE_NORMAL;
    200       1.1     chuck 	ler2->ler2_padr[0] = myea[1];
    201       1.1     chuck 	ler2->ler2_padr[1] = myea[0];
    202       1.1     chuck 	ler2->ler2_padr[2] = myea[3];
    203       1.1     chuck 	ler2->ler2_padr[3] = myea[2];
    204       1.1     chuck 	ler2->ler2_padr[4] = myea[5];
    205       1.1     chuck 	ler2->ler2_padr[5] = myea[4];
    206       1.1     chuck 
    207       1.1     chuck 
    208       1.1     chuck 	ler2->ler2_ladrf0 = 0;
    209       1.1     chuck 	ler2->ler2_ladrf1 = 0;
    210       1.1     chuck 
    211  1.7.16.1      yamt 	a = (u_int)ler2->ler2_rmd;
    212       1.1     chuck 	ler2->ler2_rlen = LE_RLEN | (a >> 16);
    213       1.1     chuck 	ler2->ler2_rdra = a & LE_ADDR_LOW_MASK;
    214       1.1     chuck 
    215  1.7.16.1      yamt 	a = (u_int)ler2->ler2_tmd;
    216       1.1     chuck 	ler2->ler2_tlen = LE_TLEN | (a >> 16);
    217       1.1     chuck 	ler2->ler2_tdra = a & LE_ADDR_LOW_MASK;
    218       1.1     chuck 
    219       1.1     chuck 	ler1->ler1_rap = LE_CSR1;
    220  1.7.16.1      yamt 	a = (u_int)ler2;
    221       1.1     chuck 	ler1->ler1_rdp = a & LE_ADDR_LOW_MASK;
    222       1.1     chuck 	ler1->ler1_rap = LE_CSR2;
    223       1.1     chuck 	ler1->ler1_rdp = a >> 16;
    224       1.1     chuck 
    225       1.1     chuck 	for (i = 0; i < LERBUF; i++) {
    226  1.7.16.1      yamt 		a = (u_int)&ler2->ler2_rbuf[i];
    227       1.1     chuck 		ler2->ler2_rmd[i].rmd0 = a & LE_ADDR_LOW_MASK;
    228       1.1     chuck 		ler2->ler2_rmd[i].rmd1_bits = LE_R1_OWN;
    229       1.1     chuck 		ler2->ler2_rmd[i].rmd1_hadr = a >> 16;
    230       1.1     chuck 		ler2->ler2_rmd[i].rmd2 = -LEMTU;
    231       1.1     chuck 		ler2->ler2_rmd[i].rmd3 = 0;
    232       1.1     chuck 	}
    233       1.1     chuck 	for (i = 0; i < LETBUF; i++) {
    234  1.7.16.1      yamt 		a = (u_int)&ler2->ler2_tbuf[i];
    235       1.1     chuck 		ler2->ler2_tmd[i].tmd0 = a & LE_ADDR_LOW_MASK;
    236       1.1     chuck 		ler2->ler2_tmd[i].tmd1_bits = 0;
    237       1.1     chuck 		ler2->ler2_tmd[i].tmd1_hadr = a >> 16;
    238       1.1     chuck 		ler2->ler2_tmd[i].tmd2 = 0;
    239       1.1     chuck 		ler2->ler2_tmd[i].tmd3 = 0;
    240       1.1     chuck 	}
    241       1.1     chuck 
    242       1.1     chuck 	ler1->ler1_rap = LE_CSR3;
    243       1.1     chuck 	ler1->ler1_rdp = LE_C3_BSWP;
    244       1.1     chuck 
    245       1.1     chuck 	ler1->ler1_rap = LE_CSR0;
    246       1.1     chuck 	ler1->ler1_rdp = LE_C0_INIT;
    247       1.1     chuck 	do {
    248       1.1     chuck 		if (--timo == 0) {
    249       1.1     chuck 			printf("le%d: init timeout, stat = 0x%x\n",
    250       1.1     chuck 			    nif->nif_unit, stat);
    251       1.1     chuck 			break;
    252       1.1     chuck 		}
    253       1.1     chuck 		stat = ler1->ler1_rdp;
    254       1.1     chuck 	} while ((stat & LE_C0_IDON) == 0);
    255       1.1     chuck 
    256       1.1     chuck 	ler1->ler1_rdp = LE_C0_IDON;
    257       1.1     chuck 	le_softc.next_rmd = 0;
    258       1.1     chuck 	le_softc.next_tmd = 0;
    259       1.1     chuck 	ler1->ler1_rap = LE_CSR0;
    260       1.1     chuck 	ler1->ler1_rdp = LE_C0_STRT;
    261       1.1     chuck }
    262       1.1     chuck 
    263       1.1     chuck int
    264  1.7.16.1      yamt le_poll(struct iodesc *desc, void  *pkt, int len)
    265       1.1     chuck {
    266       1.1     chuck 	struct lereg1 *ler1 = le_softc.sc_r1;
    267       1.1     chuck 	struct lereg2 *ler2 = le_softc.sc_r2;
    268       1.1     chuck 	unsigned int a;
    269       1.1     chuck 	int     length;
    270       1.1     chuck 	struct lermd *rmd;
    271       1.1     chuck 
    272       1.1     chuck 
    273       1.1     chuck 	ler1->ler1_rap = LE_CSR0;
    274       1.1     chuck 	if ((ler1->ler1_rdp & LE_C0_RINT) != 0)
    275       1.1     chuck 		ler1->ler1_rdp = LE_C0_RINT;
    276       1.1     chuck 	rmd = &ler2->ler2_rmd[le_softc.next_rmd];
    277       1.1     chuck 	if (rmd->rmd1_bits & LE_R1_OWN) {
    278  1.7.16.1      yamt 		return 0;
    279       1.1     chuck 	}
    280       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_ERR)
    281       1.1     chuck 		le_error(desc->io_netif, "le_poll", ler1);
    282       1.1     chuck 	if (rmd->rmd1_bits & LE_R1_ERR) {
    283       1.6  drochner 		printf("le%d_poll: rmd status 0x%x\n",
    284       1.6  drochner 		    ((struct netif *)desc->io_netif)->nif_unit,
    285       1.1     chuck 		    rmd->rmd1_bits);
    286       1.1     chuck 		length = 0;
    287       1.1     chuck 		goto cleanup;
    288       1.1     chuck 	}
    289  1.7.16.1      yamt 	if ((rmd->rmd1_bits & (LE_R1_STP | LE_R1_ENP)) !=
    290  1.7.16.1      yamt 	    (LE_R1_STP | LE_R1_ENP))
    291       1.5    provos 		panic("le_poll: chained packet");
    292       1.1     chuck 
    293       1.1     chuck 	length = rmd->rmd3;
    294       1.1     chuck 	if (length >= LEMTU) {
    295       1.1     chuck 		length = 0;
    296       1.5    provos 		panic("csr0 when bad things happen: %x", ler1->ler1_rdp);
    297       1.1     chuck 		goto cleanup;
    298       1.1     chuck 	}
    299  1.7.16.1      yamt 	if (length == 0)
    300       1.1     chuck 		goto cleanup;
    301       1.1     chuck 	length -= 4;
    302       1.1     chuck 	if (length > 0) {
    303       1.1     chuck 
    304       1.1     chuck 		/*
    305       1.1     chuck 	         * if buffer is smaller than the packet truncate it.
    306       1.1     chuck 	         * (is this wise?)
    307       1.1     chuck 	         */
    308       1.1     chuck 		if (length > len)
    309       1.1     chuck 			length = len;
    310       1.1     chuck 
    311       1.3       scw 		memcpy(pkt, (void *)&ler2->ler2_rbuf[le_softc.next_rmd],
    312       1.3       scw 		    length);
    313       1.1     chuck 	}
    314       1.1     chuck cleanup:
    315  1.7.16.1      yamt 	a = (u_int)&ler2->ler2_rbuf[le_softc.next_rmd];
    316       1.1     chuck 	rmd->rmd0 = a & LE_ADDR_LOW_MASK;
    317       1.1     chuck 	rmd->rmd1_hadr = a >> 16;
    318       1.1     chuck 	rmd->rmd2 = -LEMTU;
    319       1.1     chuck 	le_softc.next_rmd =
    320       1.1     chuck 	    (le_softc.next_rmd == (LERBUF - 1)) ? 0 : (le_softc.next_rmd + 1);
    321       1.1     chuck 	rmd->rmd1_bits = LE_R1_OWN;
    322       1.1     chuck 	return length;
    323       1.1     chuck }
    324       1.1     chuck 
    325       1.1     chuck int
    326  1.7.16.1      yamt le_put(struct iodesc *desc, void *pkt, size_t len)
    327       1.1     chuck {
    328       1.1     chuck 	volatile struct lereg1 *ler1 = le_softc.sc_r1;
    329       1.1     chuck 	volatile struct lereg2 *ler2 = le_softc.sc_r2;
    330       1.1     chuck 	volatile struct letmd *tmd;
    331       1.4       scw 	int     timo = 100000, stat = 0;
    332       1.1     chuck 	unsigned int a;
    333       1.6  drochner 	int nifunit = ((struct netif *)desc->io_netif)->nif_unit;
    334       1.1     chuck 
    335       1.1     chuck 	ler1->ler1_rap = LE_CSR0;
    336       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_ERR)
    337       1.1     chuck 		le_error(desc->io_netif, "le_put(way before xmit)", ler1);
    338       1.1     chuck 	tmd = &ler2->ler2_tmd[le_softc.next_tmd];
    339       1.1     chuck 	while (tmd->tmd1_bits & LE_T1_OWN) {
    340       1.6  drochner 		printf("le%d: output buffer busy\n", nifunit);
    341       1.1     chuck 	}
    342       1.3       scw 	memcpy((void *)ler2->ler2_tbuf[le_softc.next_tmd], pkt, len);
    343       1.1     chuck 	if (len < 64)
    344       1.1     chuck 		tmd->tmd2 = -64;
    345       1.1     chuck 	else
    346       1.1     chuck 		tmd->tmd2 = -len;
    347       1.1     chuck 	tmd->tmd3 = 0;
    348       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_ERR)
    349       1.1     chuck 		le_error(desc->io_netif, "le_put(before xmit)", ler1);
    350       1.1     chuck 	tmd->tmd1_bits = LE_T1_STP | LE_T1_ENP | LE_T1_OWN;
    351  1.7.16.1      yamt 	a = (u_int)&ler2->ler2_tbuf[le_softc.next_tmd];
    352       1.1     chuck 	tmd->tmd0 = a & LE_ADDR_LOW_MASK;
    353       1.1     chuck 	tmd->tmd1_hadr = a >> 16;
    354       1.1     chuck 	ler1->ler1_rdp = LE_C0_TDMD;
    355       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_ERR)
    356       1.1     chuck 		le_error(desc->io_netif, "le_put(after xmit)", ler1);
    357       1.1     chuck 	do {
    358       1.1     chuck 		if (--timo == 0) {
    359       1.1     chuck 			printf("le%d: transmit timeout, stat = 0x%x\n",
    360       1.6  drochner 			    nifunit, stat);
    361       1.1     chuck 			if (ler1->ler1_rdp & LE_C0_ERR)
    362  1.7.16.1      yamt 				le_error(desc->io_netif, "le_put(timeout)",
    363  1.7.16.1      yamt 				    ler1);
    364       1.1     chuck 			break;
    365       1.1     chuck 		}
    366       1.1     chuck 		stat = ler1->ler1_rdp;
    367       1.1     chuck 	} while ((stat & LE_C0_TINT) == 0);
    368       1.1     chuck 	ler1->ler1_rdp = LE_C0_TINT;
    369       1.1     chuck 	if (ler1->ler1_rdp & LE_C0_ERR) {
    370       1.1     chuck 		if ((ler1->ler1_rdp & (LE_C0_BABL | LE_C0_CERR | LE_C0_MISS |
    371       1.1     chuck 		    LE_C0_MERR)) !=
    372       1.1     chuck 		    LE_C0_CERR)
    373  1.7.16.1      yamt 			printf("le_put: xmit error, buf %d\n",
    374  1.7.16.1      yamt 			    le_softc.next_tmd);
    375       1.1     chuck 		le_error(desc->io_netif, "le_put(xmit error)", ler1);
    376       1.1     chuck 	}
    377       1.1     chuck 	le_softc.next_tmd = 0;
    378       1.1     chuck /*	(le_softc.next_tmd == (LETBUF - 1)) ? 0 : le_softc.next_tmd + 1;*/
    379       1.1     chuck 	if (tmd->tmd1_bits & LE_T1_DEF)
    380       1.1     chuck 		le_stats.deferred++;
    381       1.1     chuck 	if (tmd->tmd1_bits & LE_T1_ONE)
    382       1.1     chuck 		le_stats.collisions++;
    383       1.1     chuck 	if (tmd->tmd1_bits & LE_T1_MORE)
    384       1.1     chuck 		le_stats.collisions += 2;
    385       1.1     chuck 	if (tmd->tmd1_bits & LE_T1_ERR) {
    386       1.6  drochner 		printf("le%d: transmit error, error = 0x%x\n", nifunit,
    387       1.1     chuck 		    tmd->tmd3);
    388       1.1     chuck 		return -1;
    389       1.1     chuck 	}
    390       1.1     chuck 	if (le_debug) {
    391       1.1     chuck 		printf("le%d: le_put() successful: sent %d\n",
    392       1.6  drochner 		    nifunit, len);
    393       1.1     chuck 		printf("le%d: le_put(): tmd1_bits: %x tmd3: %x\n",
    394       1.6  drochner 		    nifunit,
    395  1.7.16.1      yamt 		    (unsigned int)tmd->tmd1_bits,
    396  1.7.16.1      yamt 		    (unsigned int)tmd->tmd3);
    397       1.1     chuck 	}
    398       1.1     chuck 	return len;
    399       1.1     chuck }
    400       1.1     chuck 
    401       1.1     chuck int
    402  1.7.16.1      yamt le_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
    403       1.1     chuck {
    404       1.1     chuck 	time_t  t;
    405       1.1     chuck 	int     cc;
    406       1.1     chuck 
    407       1.1     chuck 	t = getsecs();
    408       1.1     chuck 	cc = 0;
    409       1.1     chuck 	while (((getsecs() - t) < timeout) && !cc) {
    410       1.1     chuck 		cc = le_poll(desc, pkt, len);
    411       1.1     chuck 	}
    412       1.1     chuck 	return cc;
    413       1.1     chuck }
    414       1.1     chuck /*
    415       1.1     chuck  * init le device.   return 0 on failure, 1 if ok.
    416       1.1     chuck  */
    417       1.1     chuck void
    418  1.7.16.1      yamt le_init(struct iodesc *desc, void *machdep_hint)
    419       1.1     chuck {
    420  1.7.16.1      yamt 	u_long eram = 4 * 1024 * 1024;
    421       1.1     chuck 	struct netif *nif = desc->io_netif;
    422       1.1     chuck 
    423       1.1     chuck 	if (le_debug)
    424       1.6  drochner 		printf("le%d: le_init called\n", nif->nif_unit);
    425       1.1     chuck 	machdep_common_ether(desc->myea);
    426       1.3       scw 	memset(&le_softc, 0, sizeof(le_softc));
    427       1.1     chuck 	le_softc.sc_r1 =
    428  1.7.16.1      yamt 	    (struct lereg1 *)le_config[nif->nif_unit].phys_addr;
    429  1.7.16.1      yamt 	le_softc.sc_r2 = (struct lereg2 *)(eram - (1024 * 1024));
    430       1.1     chuck 	le_reset(desc->io_netif, desc->myea);
    431       1.1     chuck 	printf("device: %s%d attached to %s\n", nif->nif_driver->netif_bname,
    432       1.1     chuck 	    nif->nif_unit, ether_sprintf(desc->myea));
    433       1.1     chuck }
    434       1.1     chuck 
    435       1.1     chuck void
    436  1.7.16.1      yamt le_end(struct netif *nif)
    437       1.1     chuck {
    438       1.1     chuck 	struct lereg1 *ler1 = le_softc.sc_r1;
    439       1.1     chuck 
    440       1.1     chuck 	if (le_debug)
    441       1.1     chuck 		printf("le%d: le_end called\n", nif->nif_unit);
    442       1.1     chuck 	ler1->ler1_rap = LE_CSR0;
    443       1.1     chuck 	ler1->ler1_rdp = LE_C0_STOP;
    444       1.1     chuck }
    445