if_le.c revision 1.7 1 /* $NetBSD: if_le.c,v 1.7 2003/11/14 16:52:40 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 1993 Adam Glass
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Adam Glass.
18 * 4. The name of the Author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #include <sys/param.h>
35 #include <sys/types.h>
36
37 #include <net/if_ether.h>
38 #include <netinet/in.h>
39 #include <netinet/in_systm.h>
40
41 #include <lib/libsa/stand.h>
42 #include <lib/libsa/net.h>
43 #include <lib/libsa/netif.h>
44
45 #include <lib/libkern/libkern.h>
46
47 #include <hp300/stand/common/device.h>
48 #include <hp300/stand/common/if_lereg.h>
49 #include <hp300/stand/common/samachdep.h>
50
51 #ifndef NLE
52 #define NLE 1
53 #endif
54
55 struct le_softc {
56 struct lereg0 *sc_r0; /* DIO registers */
57 struct lereg1 *sc_r1; /* LANCE registers */
58 void *sc_mem;
59 struct init_block *sc_init;
60 struct mds *sc_rd, *sc_td;
61 u_char *sc_rbuf, *sc_tbuf;
62 int sc_next_rd, sc_next_td;
63 u_char sc_addr[ETHER_ADDR_LEN];
64 };
65
66 struct le_sel {
67 int le_id;
68 int le_regs;
69 int le_mem;
70 int le_nvram;
71 int le_heat;
72 int le_bonus;
73 };
74
75 int le_probe(struct netif *, void *);
76 int le_match(struct netif *, void *);
77 void le_init(struct iodesc *, void *);
78 int le_get(struct iodesc *, void *, size_t, time_t);
79 int le_put(struct iodesc *, void *, size_t);
80 void le_end(struct netif *);
81
82 static inline void lewrcsr(struct le_softc *, uint16_t, uint16_t);
83 static inline uint16_t lerdcsr(struct le_softc *, uint16_t);
84
85 static void leinit(void);
86 static void le_error(int, char *, uint16_t);
87 static void lememinit(struct le_softc *);
88 static void le_reset(int, u_char *);
89 static int le_poll(struct iodesc *, void *, int);
90
91 #ifdef LE_DEBUG
92 int le_debug = 0;
93 #endif
94
95 struct le_sel le0conf[] = {
96 /* offsets for: ID REGS MEM NVRAM le_heat le_bonus*/
97 { 0, 0x4000, 0x8000, 0xC008, 1, 10 }
98 };
99 #define NLE0CONF (sizeof(le0conf) / sizeof(le0conf[0]))
100
101 extern struct netif_stats le_stats[];
102
103 struct netif_dif le_ifs[] = {
104 /* dif_unit dif_nsel dif_stats dif_private */
105 { 0, NLE0CONF, &le_stats[0], le0conf, },
106 };
107 #define NLE_IFS (sizeof(le_ifs) / sizeof(le_ifs[0]))
108
109 struct netif_stats le_stats[NLE_IFS];
110
111 struct netif_driver le_driver = {
112 "le", /* netif_bname */
113 le_match, /* netif_match */
114 le_probe, /* netif_probe */
115 le_init, /* netif_init */
116 le_get, /* netif_get */
117 le_put, /* netif_put */
118 le_end, /* netif_end */
119 le_ifs, /* netif_ifs */
120 NLE_IFS /* netif_nifs */
121 };
122
123 struct le_softc le_softc[NLE];
124
125 static inline void
126 lewrcsr(sc, port, val)
127 struct le_softc *sc;
128 uint16_t port;
129 uint16_t val;
130 {
131 struct lereg0 *ler0 = sc->sc_r0;
132 struct lereg1 *ler1 = sc->sc_r1;
133
134 do {
135 ler1->ler1_rap = port;
136 } while ((ler0->ler0_status & LE_ACK) == 0);
137 do {
138 ler1->ler1_rdp = val;
139 } while ((ler0->ler0_status & LE_ACK) == 0);
140 }
141
142 static inline uint16_t
143 lerdcsr(sc, port)
144 struct le_softc *sc;
145 uint16_t port;
146 {
147 struct lereg0 *ler0 = sc->sc_r0;
148 struct lereg1 *ler1 = sc->sc_r1;
149 uint16_t val;
150
151 do {
152 ler1->ler1_rap = port;
153 } while ((ler0->ler0_status & LE_ACK) == 0);
154 do {
155 val = ler1->ler1_rdp;
156 } while ((ler0->ler0_status & LE_ACK) == 0);
157 return val;
158 }
159
160 static void
161 leinit()
162 {
163 struct hp_hw *hw;
164 struct le_softc *sc;
165 struct le_sel *sels;
166 int i, n;
167 char *cp;
168
169 i = 0;
170
171 for (hw = sc_table; i < NLE && hw < &sc_table[MAXCTLRS]; hw++) {
172 #ifdef LE_DEBUG
173 if (le_debug)
174 printf("found type %x\n", hw->hw_type);
175 #endif
176
177 #if 0
178 if (!HW_ISDEV(hw, D_LAN))
179 continue;
180 #endif
181
182 sels = (struct le_sel *)le_ifs[i].dif_private;
183
184 sc = &le_softc[i];
185 sc->sc_r0 = (struct lereg0 *)(sels->le_id + (int)hw->hw_kva);
186
187 if (sc->sc_r0->ler0_id != LEID)
188 continue;
189
190 sc->sc_r1 = (struct lereg1 *)(sels->le_regs + (int)hw->hw_kva);
191 sc->sc_mem = (struct lereg2 *)(sels->le_mem + (int)hw->hw_kva);
192
193 #ifdef LE_DEBUG
194 if (le_debug)
195 printf("le%d: DIO=%x regs=%x mem=%x\n",
196 i, sc->sc_r0, sc->sc_r1, sc->sc_mem);
197 #endif
198
199 /*
200 * Read the ethernet address off the board, one nibble at a time.
201 */
202 cp = (char *)(sels->le_nvram + (int)hw->hw_kva);
203 for (n = 0; n < sizeof(sc->sc_addr); n++) {
204 sc->sc_addr[n] = (*++cp & 0xF) << 4;
205 cp++;
206 sc->sc_addr[n] |= *++cp & 0xF;
207 cp++;
208 }
209 #ifdef LE_DEBUG
210 if (le_debug)
211 printf("le%d at sc%d physical address %s\n",
212 i, hw->hw_sc, ether_sprintf(sc->sc_addr));
213 #endif
214 hw->hw_pa = (caddr_t) i; /* XXX for autoconfig */
215 i++;
216 }
217 }
218
219 int
220 le_match(nif, machdep_hint)
221 struct netif *nif;
222 void *machdep_hint;
223 {
224 struct le_sel *sels;
225 char *name = machdep_hint;
226 int rv = 0;
227
228 if (nif->nif_sel < le_ifs[nif->nif_unit].dif_nsel) {
229 sels = (struct le_sel *)le_ifs[nif->nif_unit].dif_private;
230 rv = sels[nif->nif_sel].le_heat;
231 if (name && !strncmp(le_driver.netif_bname, name, 2))
232 rv += sels[nif->nif_sel].le_bonus;
233 }
234 #ifdef LE_DEBUG
235 if (le_debug)
236 printf("le%d: sel %d --> %d\n", nif->nif_unit, nif->nif_sel,
237 rv);
238 #endif
239 return rv;
240 }
241
242 int
243 le_probe(nif, machdep_hint)
244 struct netif *nif;
245 void *machdep_hint;
246 {
247 #if 0
248 char *cp;
249 int i;
250 #endif
251
252 /* the set unit is the current unit */
253 #ifdef LE_DEBUG
254 if (le_debug)
255 printf("le%d.%d: le_probe called\n", nif->nif_unit, nif->nif_sel);
256 #endif
257 /* XXX reset controller */
258 return 0;
259 }
260
261 #ifdef MEM_SUMMARY
262 void
263 le_mem_summary(unit)
264 int unit;
265 {
266 struct lereg1 *ler1 = le_softc.sc_r1;
267 struct lereg2 *ler2 = le_softc.sc_r2;
268 int i;
269
270 printf("le%d: ler1 = %x\n", unit, ler1);
271 printf("le%d: ler2 = %x\n", unit, ler2);
272
273 #if 0
274 ler1->ler1_rap = LE_CSR0;
275 ler1->ler1_rdp = LE_STOP;
276 printf("le%d: csr0 = %x\n", unit, ler1->ler1_rdp);
277 ler1->ler1_rap = LE_CSR1;
278 printf("le%d: csr1 = %x\n", unit, ler1->ler1_rdp);
279 ler1->ler1_rap = LE_CSR2;
280 printf("le%d: csr2 = %x\n", unit, ler1->ler1_rdp);
281 ler1->ler1_rap = LE_CSR3;
282 printf("le%d: csr3 = %x\n", unit, ler1->ler1_rdp);
283 #endif
284 printf("le%d: ladrf[0] = %x\n", unit, ler2->ler2_ladrf[0]);
285 printf("le%d: ladrf[1] = %x\n", unit, ler2->ler2_ladrf[1]);
286 printf("le%d: ler2_rdra = %x\n", unit, ler2->ler2_rdra);
287 printf("le%d: ler2_rlen = %x\n", unit, ler2->ler2_rlen);
288 printf("le%d: ler2_tdra = %x\n", unit, ler2->ler2_tdra);
289 printf("le%d: ler2_tlen = %x\n", unit, ler2->ler2_tlen);
290
291 for (i = 0; i < LERBUF; i++) {
292 printf("le%d: ler2_rmd[%d].rmd0 (ladr) = %x\n", unit, i,
293 ler2->ler2_rmd[i].rmd0);
294 printf("le%d: ler2_rmd[%d].rmd1 = %x\n", unit, i,
295 ler2->ler2_rmd[i].rmd1);
296 printf("le%d: ler2_rmd[%d].rmd2 (-bcnt) = %x\n", unit, i,
297 ler2->ler2_rmd[i].rmd2);
298 printf("le%d: ler2_rmd[%d].rmd3 (mcnt) = %x\n", unit, i,
299 ler2->ler2_rmd[i].rmd3);
300 printf("le%d: ler2_rbuf[%d] addr = %x\n", unit, i,
301 &ler2->ler2_rbuf[i]);
302 }
303 for (i = 0; i < LETBUF; i++) {
304 printf("le%d: ler2_tmd[%d].tmd0 = %x\n", unit, i,
305 ler2->ler2_tmd[i].tmd0);
306 printf("le%d: ler2_tmd[%d].tmd1 = %x\n", unit, i,
307 ler2->ler2_tmd[i].tmd1);
308 printf("le%d: ler2_tmd[%d].tmd2 (bcnt) = %x\n", unit, i,
309 ler2->ler2_tmd[i].tmd2);
310 printf("le%d: ler2_tmd[%d].tmd3 = %x\n", unit, i,
311 ler2->ler2_tmd[i].tmd3);
312 printf("le%d: ler2_tbuf[%d] addr = %x\n", unit, i,
313 &ler2->ler2_tbuf[i]);
314 }
315 }
316 #else
317 #define le_mem_summary(u)
318 #endif
319
320 void
321 le_error(unit, str, stat)
322 int unit;
323 char *str;
324 uint16_t stat;
325 {
326
327 if (stat & LE_BABL)
328 panic("le%d: been babbling, found by '%s'", unit, str);
329 if (stat & LE_CERR)
330 le_stats[unit].collision_error++;
331 if (stat & LE_MISS)
332 le_stats[unit].missed++;
333 if (stat & LE_MERR) {
334 printf("le%d: memory error in '%s'\n", unit, str);
335 le_mem_summary(unit);
336 panic("bye");
337 }
338 }
339
340 #define LANCE_ADDR(sc, a) \
341 ((u_long)(a) - (u_long)sc->sc_mem)
342
343 /* LANCE initialization block set up. */
344 void
345 lememinit(sc)
346 struct le_softc *sc;
347 {
348 int i;
349 u_char *mem;
350 u_long a;
351
352 /*
353 * At this point we assume that the memory allocated to the Lance is
354 * quadword aligned. If it isn't then the initialisation is going
355 * fail later on.
356 */
357 mem = sc->sc_mem;
358
359 sc->sc_init = (void *)mem;
360 sc->sc_init->mode = LE_NORMAL;
361 for (i = 0; i < ETHER_ADDR_LEN; i++)
362 sc->sc_init->padr[i] = sc->sc_addr[i^1];
363 sc->sc_init->ladrf[0] = sc->sc_init->ladrf[1] = 0;
364 mem += sizeof(struct init_block);
365
366 sc->sc_rd = (void *)mem;
367 a = LANCE_ADDR(sc, mem);
368 sc->sc_init->rdra = a;
369 sc->sc_init->rlen = ((a >> 16) & 0xff) | (RLEN << 13);
370 mem += NRBUF * sizeof(struct mds);
371
372 sc->sc_td = (void *)mem;
373 a = LANCE_ADDR(sc, mem);
374 sc->sc_init->tdra = a;
375 sc->sc_init->tlen = ((a >> 16) & 0xff) | (TLEN << 13);
376 mem += NTBUF * sizeof(struct mds);
377
378 /*
379 * Set up receive ring descriptors.
380 */
381 sc->sc_rbuf = mem;
382 for (i = 0; i < NRBUF; i++) {
383 a = LANCE_ADDR(sc, mem);
384 sc->sc_rd[i].addr = a;
385 sc->sc_rd[i].flags = ((a >> 16) & 0xff) | LE_OWN;
386 sc->sc_rd[i].bcnt = -BUFSIZE;
387 sc->sc_rd[i].mcnt = 0;
388 mem += BUFSIZE;
389 }
390
391 /*
392 * Set up transmit ring descriptors.
393 */
394 sc->sc_tbuf = mem;
395 for (i = 0; i < NTBUF; i++) {
396 a = LANCE_ADDR(sc, mem);
397 sc->sc_td[i].addr = a;
398 sc->sc_td[i].flags = ((a >> 16) & 0xff);
399 sc->sc_td[i].bcnt = 0xf000;
400 sc->sc_td[i].mcnt = 0;
401 mem += BUFSIZE;
402 }
403 }
404
405 void
406 le_reset(unit, myea)
407 int unit;
408 u_char *myea;
409 {
410 struct le_softc *sc = &le_softc[unit];
411 u_long a;
412 int timo = 100000;
413
414 #ifdef LE_DEBUG
415 if (le_debug) {
416 printf("le%d: le_reset called\n", unit);
417 printf(" r0=%x, r1=%x, mem=%x, addr=%x:%x:%x:%x:%x:%x\n",
418 sc->sc_r0, sc->sc_r1, sc->sc_mem,
419 sc->sc_addr[0], sc->sc_addr[1], sc->sc_addr[2],
420 sc->sc_addr[3], sc->sc_addr[4], sc->sc_addr[5]);
421 }
422 #endif
423 lewrcsr(sc, 0, LE_STOP);
424 for (timo = 1000; timo; timo--);
425
426 sc->sc_next_rd = sc->sc_next_td = 0;
427
428 /* Set up LANCE init block. */
429 lememinit(sc);
430
431 if (myea)
432 memcpy(myea, sc->sc_addr, ETHER_ADDR_LEN);
433
434 /* Turn on byte swapping. */
435 lewrcsr(sc, 3, LE_BSWP);
436
437 /* Give LANCE the physical address of its init block. */
438 a = LANCE_ADDR(sc, sc->sc_init);
439 lewrcsr(sc, 1, a);
440 lewrcsr(sc, 2, (a >> 16) & 0xff);
441
442 #ifdef LE_DEBUG
443 if (le_debug)
444 printf("le%d: before init\n", unit);
445 #endif
446
447 /* Try to initialize the LANCE. */
448 lewrcsr(sc, 0, LE_INIT);
449
450 /* Wait for initialization to finish. */
451 for (timo = 100000; timo; timo--)
452 if (lerdcsr(sc, 0) & LE_IDON)
453 break;
454
455 if (lerdcsr(sc, 0) & LE_IDON) {
456 /* Start the LANCE. */
457 lewrcsr(sc, 0, LE_INEA | LE_STRT | LE_IDON);
458 } else
459 printf("le%d: card failed to initialize\n", unit);
460
461 #ifdef LE_DEBUG
462 if (le_debug)
463 printf("le%d: after init\n", unit);
464 #endif
465
466 le_mem_summary(unit);
467 }
468
469 int
470 le_poll(desc, pkt, len)
471 struct iodesc *desc;
472 void *pkt;
473 int len;
474 {
475 int unit = /*nif->nif_unit*/0;
476 struct le_softc *sc = &le_softc[unit];
477 int length;
478 volatile struct mds *cdm;
479 int stat;
480
481 #ifdef LE_DEBUG
482 if (/*le_debug*/0)
483 printf("le%d: le_poll called. next_rd=%d\n", unit, sc->sc_next_rd);
484 #endif
485 stat = lerdcsr(sc, 0);
486 lewrcsr(sc, 0, stat & (LE_BABL | LE_MISS | LE_MERR | LE_RINT));
487 cdm = &sc->sc_rd[sc->sc_next_rd];
488 if (cdm->flags & LE_OWN)
489 return 0;
490 #ifdef LE_DEBUG
491 if (le_debug) {
492 printf("next_rd %d\n", sc->sc_next_rd);
493 printf("cdm->flags %x\n", cdm->flags);
494 printf("cdm->bcnt %x, cdm->mcnt %x\n", cdm->bcnt, cdm->mcnt);
495 printf("cdm->rbuf msg %d buf %d\n", cdm->mcnt, -cdm->bcnt );
496 }
497 #endif
498 if (stat & (LE_BABL | LE_CERR | LE_MISS | LE_MERR))
499 le_error(unit, "le_poll", stat);
500 if (cdm->flags & (LE_FRAM | LE_OFLO | LE_CRC | LE_RBUFF)) {
501 printf("le%d_poll: rmd status 0x%x\n", unit, cdm->flags);
502 length = 0;
503 goto cleanup;
504 }
505 if ((cdm->flags & (LE_STP|LE_ENP)) != (LE_STP|LE_ENP))
506 panic("le_poll: chained packet");
507
508 length = cdm->mcnt;
509 #ifdef LE_DEBUG
510 if (le_debug)
511 printf("le_poll: length %d\n", length);
512 #endif
513 if (length >= BUFSIZE) {
514 length = 0;
515 panic("csr0 when bad things happen: %x", stat);
516 goto cleanup;
517 }
518 if (!length)
519 goto cleanup;
520 length -= 4;
521
522 if (length > 0) {
523 /*
524 * If the length of the packet is greater than the size of the
525 * buffer, we have to truncate it, to avoid Bad Things.
526 * XXX Is this the right thing to do?
527 */
528 if (length > len)
529 length = len;
530
531 memcpy(pkt, sc->sc_rbuf + (BUFSIZE * sc->sc_next_rd), length);
532 }
533
534 cleanup:
535 cdm->mcnt = 0;
536 cdm->flags |= LE_OWN;
537 if (++sc->sc_next_rd >= NRBUF)
538 sc->sc_next_rd = 0;
539 #ifdef LE_DEBUG
540 if (le_debug)
541 printf("new next_rd %d\n", sc->sc_next_rd);
542 #endif
543
544 return length;
545 }
546
547 int
548 le_put(desc, pkt, len)
549 struct iodesc *desc;
550 void *pkt;
551 size_t len;
552 {
553 int unit = /*nif->nif_unit*/0;
554 struct le_softc *sc = &le_softc[unit];
555 volatile struct mds *cdm;
556 int timo, i, stat;
557
558 le_put_loop:
559 timo = 100000;
560
561 #ifdef LE_DEBUG
562 if (le_debug)
563 printf("le%d: le_put called. next_td=%d\n", unit, sc->sc_next_td);
564 #endif
565 stat = lerdcsr(sc, 0);
566 lewrcsr(sc, 0, stat & (LE_BABL | LE_MISS | LE_MERR | LE_TINT));
567 if (stat & (LE_BABL | LE_CERR | LE_MISS | LE_MERR))
568 le_error(unit, "le_put(way before xmit)", stat);
569 cdm = &sc->sc_td[sc->sc_next_td];
570 i = 0;
571 #if 0
572 while (cdm->flags & LE_OWN) {
573 if ((i % 100) == 0)
574 printf("le%d: output buffer busy - flags=%x\n",
575 unit, cdm->flags);
576 if (i++ > 500) break;
577 }
578 if (cdm->flags & LE_OWN)
579 getchar();
580 #else
581 while (cdm->flags & LE_OWN);
582 #endif
583 memcpy(sc->sc_tbuf + (BUFSIZE * sc->sc_next_td), pkt, len);
584 if (len < ETHER_MIN_LEN)
585 cdm->bcnt = -ETHER_MIN_LEN;
586 else
587 cdm->bcnt = -len;
588 cdm->mcnt = 0;
589 cdm->flags |= LE_OWN | LE_STP | LE_ENP;
590 stat = lerdcsr(sc, 0);
591 if (stat & (LE_BABL | LE_CERR | LE_MISS | LE_MERR))
592 le_error(unit, "le_put(before xmit)", stat);
593 lewrcsr(sc, 0, LE_TDMD);
594 stat = lerdcsr(sc, 0);
595 if (stat & (LE_BABL | LE_CERR | LE_MISS | LE_MERR))
596 le_error(unit, "le_put(after xmit)", stat);
597 do {
598 if (--timo == 0) {
599 printf("le%d: transmit timeout, stat = 0x%x\n",
600 unit, stat);
601 if (stat & LE_SERR)
602 le_error(unit, "le_put(timeout)", stat);
603 if (stat & LE_INIT) {
604 printf("le%d: reset and retry packet\n", unit);
605 lewrcsr(sc, 0, LE_TINT); /* sanity */
606 leinit();
607 goto le_put_loop;
608 }
609 break;
610 }
611 stat = lerdcsr(sc, 0);
612 } while ((stat & LE_TINT) == 0);
613 lewrcsr(sc, 0, LE_TINT);
614 if (stat & (LE_BABL |/* LE_CERR |*/ LE_MISS | LE_MERR)) {
615 printf("le_put: xmit error, buf %d\n", sc->sc_next_td);
616 le_error(unit, "le_put(xmit error)", stat);
617 }
618 if (++sc->sc_next_td >= NTBUF)
619 sc->sc_next_td = 0;
620 if (cdm->flags & LE_DEF)
621 le_stats[unit].deferred++;
622 if (cdm->flags & LE_ONE)
623 le_stats[unit].collisions++;
624 if (cdm->flags & LE_MORE)
625 le_stats[unit].collisions += 2;
626 if (cdm->flags & LE_ERR) {
627 if (cdm->mcnt & LE_UFLO)
628 printf("le%d: transmit underflow\n", unit);
629 if (cdm->mcnt & LE_LCOL)
630 le_stats[unit].collisions++;
631 if (cdm->mcnt & LE_LCAR)
632 printf("le%d: lost carrier\n", unit);
633 if (cdm->mcnt & LE_RTRY)
634 le_stats[unit].collisions += 16;
635 return -1;
636 }
637 #ifdef LE_DEBUG
638 if (le_debug) {
639 printf("le%d: le_put() successful: sent %d\n", unit, len);
640 printf("le%d: le_put(): flags: %x mcnt: %x\n", unit,
641 (unsigned int) cdm->flags,
642 (unsigned int) cdm->mcnt);
643 }
644 #endif
645 return len;
646 }
647
648
649 int
650 le_get(desc, pkt, len, timeout)
651 struct iodesc *desc;
652 void *pkt;
653 size_t len;
654 time_t timeout;
655 {
656 time_t t;
657 int cc;
658
659 t = getsecs();
660 cc = 0;
661 while (((getsecs() - t) < timeout) && !cc) {
662 cc = le_poll(desc, pkt, len);
663 }
664 return cc;
665 }
666
667 void
668 le_init(desc, machdep_hint)
669 struct iodesc *desc;
670 void *machdep_hint;
671 {
672 struct netif *nif = desc->io_netif;
673 int unit = nif->nif_unit;
674
675 /* Get machine's common ethernet interface. This is done in leinit() */
676 /* machdep_common_ether(myea); */
677 leinit();
678
679 #ifdef LE_DEBUG
680 if (le_debug)
681 printf("le%d: le_init called\n", unit);
682 #endif
683 unit = 0;
684 le_reset(unit, desc->myea);
685 }
686
687 void
688 le_end(nif)
689 struct netif *nif;
690 {
691 int unit = nif->nif_unit;
692
693 #ifdef LE_DEBUG
694 if (le_debug)
695 printf("le%d: le_end called\n", unit);
696 #endif
697
698 lewrcsr(&le_softc[unit], 0, LE_STOP);
699 }
700