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