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