if_le.c revision 1.2 1 /*
2 * Copyright (c) 1982, 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 * from: @(#)if_le.c 7.6 (Berkeley) 5/8/91
34 * if_le.c,v 1.2 1993/05/22 07:56:23 cgd Exp
35 */
36
37 #include "bpfilter.h"
38
39 /*
40 * AMD 7990 LANCE
41 *
42 * This driver will generate and accept tailer encapsulated packets even
43 * though it buys us nothing. The motivation was to avoid incompatibilities
44 * with VAXen, SUNs, and others that handle and benefit from them.
45 * This reasoning is dubious.
46 */
47 #include "sys/param.h"
48 #include "sys/systm.h"
49 #include "sys/mbuf.h"
50 #include "sys/buf.h"
51 #include "sys/protosw.h"
52 #include "sys/socket.h"
53 #include "sys/syslog.h"
54 #include "sys/ioctl.h"
55 #include "sys/errno.h"
56 #include "sys/device.h"
57
58 #include "net/if.h"
59 #include "net/netisr.h"
60 #include "net/route.h"
61
62 #ifdef INET
63 #include "netinet/in.h"
64 #include "netinet/in_systm.h"
65 #include "netinet/in_var.h"
66 #include "netinet/ip.h"
67 #include "netinet/if_ether.h"
68 #endif
69
70 #ifdef NS
71 #include "netns/ns.h"
72 #include "netns/ns_if.h"
73 #endif
74
75 #ifdef RMP
76 #include "netrmp/rmp.h"
77 #include "netrmp/rmp_var.h"
78 #endif
79
80 #include "machine/autoconf.h"
81
82 #include "if_lereg.h"
83
84 #if NBPFILTER > 0
85 #include "../net/bpf.h"
86 #include "../net/bpfdesc.h"
87 #endif
88
89 #include "if_le.h"
90 #include "if_le_subr.h"
91
92 int ledebug = 0; /* console error messages */
93
94 int leintr(), leinit(), leioctl(), lestart(), ether_output();
95 struct mbuf *leget();
96 extern struct ifnet loif;
97
98 /* access LANCE registers */
99
100 void leattach __P((struct device *, struct device *, void *));
101 int lematch __P((struct device *, struct cfdata *, void *args));
102
103 struct cfdriver lecd =
104 { NULL, "le", lematch, leattach, DV_DULL, sizeof(struct le_softc), 0};
105
106 int lematch(parent, cf, args)
107 struct device *parent;
108 struct cfdata *cf;
109 void *args;
110 {
111 return le_machdep_match(parent, cf, args);
112 }
113 /*
114 * Interface exists: make available by filling in network interface
115 * record. System will initialize the interface when it is ready
116 * to accept packets.
117 */
118 void leattach(parent, self, args)
119 struct device *parent;
120 struct device *self;
121 void *args;
122 {
123 register struct lereg2 *ler2;
124 struct lereg2 *lemem = 0;
125 struct le_softc *le = (struct le_softc *) self;
126 struct ifnet *ifp = &le->sc_if;
127 char *cp;
128 int i, unit;
129
130 unit = le->sc_dev.dv_unit;
131 if (le_machdep_attach(parent, self, args)) {
132 printf(": bad attach??\n");
133 return;
134 }
135 ler2 = le->sc_r2;
136 printf(": ether address %s\n", ether_sprintf(le->sc_addr));
137
138 /*
139 * Setup for transmit/receive
140 */
141 ler2->ler2_mode = LE_MODE;
142 ler2->ler2_padr[0] = le->sc_addr[1];
143 ler2->ler2_padr[1] = le->sc_addr[0];
144 ler2->ler2_padr[2] = le->sc_addr[3];
145 ler2->ler2_padr[3] = le->sc_addr[2];
146 ler2->ler2_padr[4] = le->sc_addr[5];
147 ler2->ler2_padr[5] = le->sc_addr[4];
148 #ifdef RMP
149 /*
150 * Set up logical addr filter to accept multicast 9:0:9:0:0:4
151 * This should be an ioctl() to the driver. (XXX)
152 */
153 ler2->ler2_ladrf0 = 0x00100000;
154 ler2->ler2_ladrf1 = 0x0;
155 #else
156 ler2->ler2_ladrf0 = 0;
157 ler2->ler2_ladrf1 = 0;
158 #endif
159 ler2->ler2_rlen = LE_RLEN;
160 ler2->ler2_rdra = (int)lemem->ler2_rmd;
161 ler2->ler2_tlen = LE_TLEN;
162 ler2->ler2_tdra = (int)lemem->ler2_tmd;
163
164 ifp->if_unit = unit;
165 ifp->if_name = "le";
166 ifp->if_mtu = ETHERMTU;
167 ifp->if_init = leinit;
168 ifp->if_ioctl = leioctl;
169 ifp->if_output = ether_output;
170 ifp->if_start = lestart;
171 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX;
172 #if NBPFILTER > 0
173 bpfattach(&le->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
174 #endif
175 if_attach(ifp);
176 }
177
178 ledrinit(ler2)
179 register struct lereg2 *ler2;
180 {
181 register struct lereg2 *lemem = 0;
182 register int i;
183
184 for (i = 0; i < LERBUF; i++) {
185 ler2->ler2_rmd[i].rmd0 = (int)lemem->ler2_rbuf[i];
186 ler2->ler2_rmd[i].rmd1 = LE_OWN;
187 ler2->ler2_rmd[i].rmd2 = -LEMTU;
188 ler2->ler2_rmd[i].rmd3 = 0;
189 }
190 for (i = 0; i < LETBUF; i++) {
191 ler2->ler2_tmd[i].tmd0 = (int)lemem->ler2_tbuf[i];
192 ler2->ler2_tmd[i].tmd1 = 0;
193 ler2->ler2_tmd[i].tmd2 = 0;
194 ler2->ler2_tmd[i].tmd3 = 0;
195 }
196 }
197
198 lereset(unit)
199 register int unit;
200 {
201 register struct le_softc *le = (struct le_softc *) &lecd.cd_devs[unit];
202 register struct lereg1 *ler1 = le->sc_r1;
203 register struct lereg2 *lemem = 0;
204 register int timo = 100000;
205 register int stat;
206
207 #ifdef lint
208 stat = unit;
209 #endif
210 #if NBPFILTER > 0
211 if (le->sc_if.if_flags & IFF_PROMISC)
212 /* set the promiscuous bit */
213 le->sc_r2->ler2_mode = LE_MODE|0x8000;
214 else
215 le->sc_r2->ler2_mode = LE_MODE;
216 #endif
217 LERDWR(le, LE_CSR0, ler1->ler1_rap);
218 LERDWR(le, LE_STOP, ler1->ler1_rdp);
219 ledrinit(le->sc_r2);
220 le->sc_rmd = 0;
221 LERDWR(le, LE_CSR1, ler1->ler1_rap);
222 LERDWR(le, (int)&lemem->ler2_mode, ler1->ler1_rdp);
223 LERDWR(le, LE_CSR2, ler1->ler1_rap);
224 LERDWR(le, 0, ler1->ler1_rdp);
225 LERDWR(le, LE_CSR0, ler1->ler1_rap);
226 LERDWR(le, LE_INIT, ler1->ler1_rdp);
227 do {
228 if (--timo == 0) {
229 printf("le%d: init timeout, stat = 0x%x\n",
230 unit, stat);
231 break;
232 }
233 LERDWR(le, ler1->ler1_rdp, stat);
234 } while ((stat & LE_IDON) == 0);
235 LERDWR(le, LE_STOP, ler1->ler1_rdp);
236 LERDWR(le, LE_CSR3, ler1->ler1_rap);
237 LERDWR(le, LE_BSWP, ler1->ler1_rdp);
238 LERDWR(le, LE_CSR0, ler1->ler1_rap);
239 LERDWR(le, LE_STRT | LE_INEA, ler1->ler1_rdp);
240 le->sc_if.if_flags &= ~IFF_OACTIVE;
241 }
242
243 /*
244 * Initialization of interface
245 */
246 leinit(unit)
247 int unit;
248 {
249 struct le_softc *le = lecd.cd_devs[unit];
250 register struct ifnet *ifp = &le->sc_if;
251 int s;
252
253 /* not yet, if address still unknown */
254 if (ifp->if_addrlist == (struct ifaddr *)0)
255 return;
256 if ((ifp->if_flags & IFF_RUNNING) == 0) {
257 s = splimp();
258 ifp->if_flags |= IFF_RUNNING;
259 lereset(unit);
260 (void) lestart(ifp);
261 splx(s);
262 }
263 }
264
265 /*
266 * Start output on interface. Get another datagram to send
267 * off of the interface queue, and copy it to the interface
268 * before starting the output.
269 */
270 lestart(ifp)
271 struct ifnet *ifp;
272 {
273 register struct le_softc *le = lecd.cd_devs[ifp->if_unit];
274 register struct letmd *tmd;
275 register struct mbuf *m;
276 int len;
277
278 if ((le->sc_if.if_flags & IFF_RUNNING) == 0)
279 return (0);
280 IF_DEQUEUE(&le->sc_if.if_snd, m);
281 if (m == 0)
282 return (0);
283 len = leput(le->sc_r2->ler2_tbuf[0], m);
284 #if NBPFILTER > 0
285 /*
286 * If bpf is listening on this interface, let it
287 * see the packet before we commit it to the wire.
288 */
289 if (le->sc_bpf)
290 bpf_tap(le->sc_bpf, le->sc_r2->ler2_tbuf[0], len);
291 #endif
292 tmd = le->sc_r2->ler2_tmd;
293 tmd->tmd3 = 0;
294 tmd->tmd2 = -len;
295 tmd->tmd1 = LE_OWN | LE_STP | LE_ENP;
296 le->sc_if.if_flags |= IFF_OACTIVE;
297 return (0);
298 }
299
300 leintr(unit)
301 register int unit;
302 {
303 register struct le_softc *le = lecd.cd_devs[unit];
304 register struct lereg1 *ler1;
305 register int stat;
306
307 le_machdep_intrcheck(le, unit);
308 ler1 = le->sc_r1;
309 LERDWR(le, ler1->ler1_rdp, stat);
310 if (stat & LE_SERR) {
311 leerror(unit, stat);
312 if (stat & LE_MERR) {
313 le->sc_merr++;
314 lereset(unit);
315 return(1);
316 }
317 if (stat & LE_BABL)
318 le->sc_babl++;
319 if (stat & LE_CERR)
320 le->sc_cerr++;
321 if (stat & LE_MISS)
322 le->sc_miss++;
323 LERDWR(le, LE_BABL|LE_CERR|LE_MISS|LE_INEA, ler1->ler1_rdp);
324 }
325 if ((stat & LE_RXON) == 0) {
326 le->sc_rxoff++;
327 lereset(unit);
328 return(1);
329 }
330 if ((stat & LE_TXON) == 0) {
331 le->sc_txoff++;
332 lereset(unit);
333 return(1);
334 }
335 if (stat & LE_RINT) {
336 /* interrupt is cleared in lerint */
337 lerint(unit);
338 }
339 if (stat & LE_TINT) {
340 LERDWR(le, LE_TINT|LE_INEA, ler1->ler1_rdp);
341 lexint(unit);
342 }
343 return(1);
344 }
345
346 /*
347 * Ethernet interface transmitter interrupt.
348 * Start another output if more data to send.
349 */
350 lexint(unit)
351 register int unit;
352 {
353 register struct le_softc *le = lecd.cd_devs[unit];
354 register struct letmd *tmd = le->sc_r2->ler2_tmd;
355
356 if ((le->sc_if.if_flags & IFF_OACTIVE) == 0) {
357 le->sc_xint++;
358 return;
359 }
360 if (tmd->tmd1 & LE_OWN) {
361 le->sc_xown++;
362 return;
363 }
364 if (tmd->tmd1 & LE_ERR) {
365 err:
366 lexerror(unit);
367 le->sc_if.if_oerrors++;
368 if (tmd->tmd3 & (LE_TBUFF|LE_UFLO)) {
369 le->sc_uflo++;
370 lereset(unit);
371 }
372 else if (tmd->tmd3 & LE_LCOL)
373 le->sc_if.if_collisions++;
374 else if (tmd->tmd3 & LE_RTRY)
375 le->sc_if.if_collisions += 16;
376 }
377 else if (tmd->tmd3 & LE_TBUFF)
378 /* XXX documentation says BUFF not included in ERR */
379 goto err;
380 else if (tmd->tmd1 & LE_ONE)
381 le->sc_if.if_collisions++;
382 else if (tmd->tmd1 & LE_MORE)
383 /* what is the real number? */
384 le->sc_if.if_collisions += 2;
385 else
386 le->sc_if.if_opackets++;
387 le->sc_if.if_flags &= ~IFF_OACTIVE;
388 (void) lestart(&le->sc_if);
389 }
390
391 #define LENEXTRMP \
392 if (++bix == LERBUF) bix = 0, rmd = le->sc_r2->ler2_rmd; else ++rmd
393
394 /*
395 * Ethernet interface receiver interrupt.
396 * If input error just drop packet.
397 * Decapsulate packet based on type and pass to type specific
398 * higher-level input routine.
399 */
400 lerint(unit)
401 int unit;
402 {
403 register struct le_softc *le = lecd.cd_devs[unit];
404 register int bix = le->sc_rmd;
405 register struct lermd *rmd = &le->sc_r2->ler2_rmd[bix];
406
407 /*
408 * Out of sync with hardware, should never happen?
409 */
410 if (rmd->rmd1 & LE_OWN) {
411 LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
412 return;
413 }
414
415 /*
416 * Process all buffers with valid data
417 */
418 while ((rmd->rmd1 & LE_OWN) == 0) {
419 int len = rmd->rmd3;
420
421 /* Clear interrupt to avoid race condition */
422 LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp);
423
424 if (rmd->rmd1 & LE_ERR) {
425 le->sc_rmd = bix;
426 lererror(unit, "bad packet");
427 le->sc_if.if_ierrors++;
428 } else if ((rmd->rmd1 & (LE_STP|LE_ENP)) != (LE_STP|LE_ENP)) {
429 /*
430 * Find the end of the packet so we can see how long
431 * it was. We still throw it away.
432 */
433 do {
434 LERDWR(le->sc_r0, LE_RINT|LE_INEA,
435 le->sc_r1->ler1_rdp);
436 rmd->rmd3 = 0;
437 rmd->rmd1 = LE_OWN;
438 LENEXTRMP;
439 } while (!(rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)));
440 le->sc_rmd = bix;
441 lererror(unit, "chained buffer");
442 le->sc_rxlen++;
443 /*
444 * If search terminated without successful completion
445 * we reset the hardware (conservative).
446 */
447 if ((rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)) !=
448 LE_ENP) {
449 lereset(unit);
450 return;
451 }
452 } else
453 leread(unit, le->sc_r2->ler2_rbuf[bix], len);
454 rmd->rmd3 = 0;
455 rmd->rmd1 = LE_OWN;
456 LENEXTRMP;
457 }
458 le->sc_rmd = bix;
459 }
460
461 leread(unit, buf, len)
462 int unit;
463 char *buf;
464 int len;
465 {
466 register struct le_softc *le = lecd.cd_devs[unit];
467 register struct ether_header *et;
468 struct mbuf *m;
469 int off, resid;
470
471 le->sc_if.if_ipackets++;
472 et = (struct ether_header *)buf;
473 et->ether_type = ntohs((u_short)et->ether_type);
474 /* adjust input length to account for header and CRC */
475 len = len - sizeof(struct ether_header) - 4;
476
477 #ifdef RMP
478 /* (XXX)
479 *
480 * If Ethernet Type field is < MaxPacketSize, we probably have
481 * a IEEE802 packet here. Make sure that the size is at least
482 * that of the HP LLC. Also do sanity checks on length of LLC
483 * (old Ethernet Type field) and packet length.
484 *
485 * Provided the above checks succeed, change `len' to reflect
486 * the length of the LLC (i.e. et->ether_type) and change the
487 * type field to ETHERTYPE_IEEE so we can switch() on it later.
488 * Yes, this is a hack and will eventually be done "right".
489 */
490 if (et->ether_type <= IEEE802LEN_MAX && len >= sizeof(struct hp_llc) &&
491 len >= et->ether_type && len >= IEEE802LEN_MIN) {
492 len = et->ether_type;
493 et->ether_type = ETHERTYPE_IEEE; /* hack! */
494 }
495 #endif
496
497 #define ledataaddr(et, off, type) ((type)(((caddr_t)((et)+1)+(off))))
498 if (et->ether_type >= ETHERTYPE_TRAIL &&
499 et->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) {
500 off = (et->ether_type - ETHERTYPE_TRAIL) * 512;
501 if (off >= ETHERMTU)
502 return; /* sanity */
503 et->ether_type = ntohs(*ledataaddr(et, off, u_short *));
504 resid = ntohs(*(ledataaddr(et, off+2, u_short *)));
505 if (off + resid > len)
506 return; /* sanity */
507 len = off + resid;
508 } else
509 off = 0;
510
511 if (len <= 0) {
512 if (ledebug)
513 log(LOG_WARNING,
514 "le%d: ierror(runt packet): from %s: len=%d\n",
515 unit, ether_sprintf(et->ether_shost), len);
516 le->sc_runt++;
517 le->sc_if.if_ierrors++;
518 return;
519 }
520 #if NBPFILTER > 0
521 /*
522 * Check if there's a bpf filter listening on this interface.
523 * If so, hand off the raw packet to bpf, which must deal with
524 * trailers in its own way.
525 */
526 if (le->sc_bpf) {
527 bpf_tap(le->sc_bpf, buf, len + sizeof(struct ether_header));
528
529 /*
530 * Note that the interface cannot be in promiscuous mode if
531 * there are no bpf listeners. And if we are in promiscuous
532 * mode, we have to check if this packet is really ours.
533 *
534 * XXX This test does not support multicasts.
535 */
536 if ((le->sc_if.if_flags & IFF_PROMISC)
537 && bcmp(et->ether_dhost, le->sc_addr,
538 sizeof(et->ether_dhost)) != 0
539 && bcmp(et->ether_dhost, etherbroadcastaddr,
540 sizeof(et->ether_dhost)) != 0)
541 return;
542 }
543 #endif
544 /*
545 * Pull packet off interface. Off is nonzero if packet
546 * has trailing header; leget will then force this header
547 * information to be at the front, but we still have to drop
548 * the type and length which are at the front of any trailer data.
549 */
550 m = leget(buf, len, off, &le->sc_if);
551 if (m == 0)
552 return;
553 #ifdef RMP
554 /*
555 * (XXX)
556 * This needs to be integrated with the ISO stuff in ether_input()
557 */
558 if (et->ether_type == ETHERTYPE_IEEE) {
559 /*
560 * Snag the Logical Link Control header (IEEE 802.2).
561 */
562 struct hp_llc *llc = &(mtod(m, struct rmp_packet *)->hp_llc);
563
564 /*
565 * If the DSAP (and HP's extended DXSAP) indicate this
566 * is an RMP packet, hand it to the raw input routine.
567 */
568 if (llc->dsap == IEEE_DSAP_HP && llc->dxsap == HPEXT_DXSAP) {
569 static struct sockproto rmp_sp = {AF_RMP,RMPPROTO_BOOT};
570 static struct sockaddr rmp_src = {AF_RMP};
571 static struct sockaddr rmp_dst = {AF_RMP};
572
573 bcopy(et->ether_shost, rmp_src.sa_data,
574 sizeof(et->ether_shost));
575 bcopy(et->ether_dhost, rmp_dst.sa_data,
576 sizeof(et->ether_dhost));
577
578 raw_input(m, &rmp_sp, &rmp_src, &rmp_dst);
579 return;
580 }
581 }
582 #endif
583 ether_input(&le->sc_if, et, m);
584 }
585
586 /*
587 * Routine to copy from mbuf chain to transmit
588 * buffer in board local memory.
589 */
590 leput(lebuf, m)
591 register char *lebuf;
592 register struct mbuf *m;
593 {
594 register struct mbuf *mp;
595 register int len, tlen = 0;
596
597 for (mp = m; mp; mp = mp->m_next) {
598 len = mp->m_len;
599 if (len == 0)
600 continue;
601 tlen += len;
602 bcopy(mtod(mp, char *), lebuf, len);
603 lebuf += len;
604 }
605 m_freem(m);
606 if (tlen < LEMINSIZE) {
607 bzero(lebuf, LEMINSIZE - tlen);
608 tlen = LEMINSIZE;
609 }
610 return(tlen);
611 }
612
613 /*
614 * Routine to copy from board local memory into mbufs.
615 */
616 struct mbuf *
617 leget(lebuf, totlen, off0, ifp)
618 char *lebuf;
619 int totlen, off0;
620 struct ifnet *ifp;
621 {
622 register struct mbuf *m;
623 struct mbuf *top = 0, **mp = ⊤
624 register int off = off0, len;
625 register char *cp;
626 char *epkt;
627
628 lebuf += sizeof (struct ether_header);
629 cp = lebuf;
630 epkt = cp + totlen;
631 if (off) {
632 cp += off + 2 * sizeof(u_short);
633 totlen -= 2 * sizeof(u_short);
634 }
635
636 MGETHDR(m, M_DONTWAIT, MT_DATA);
637 if (m == 0)
638 return (0);
639 m->m_pkthdr.rcvif = ifp;
640 m->m_pkthdr.len = totlen;
641 m->m_len = MHLEN;
642
643 while (totlen > 0) {
644 if (top) {
645 MGET(m, M_DONTWAIT, MT_DATA);
646 if (m == 0) {
647 m_freem(top);
648 return (0);
649 }
650 m->m_len = MLEN;
651 }
652 len = min(totlen, epkt - cp);
653 if (len >= MINCLSIZE) {
654 MCLGET(m, M_DONTWAIT);
655 if (m->m_flags & M_EXT)
656 m->m_len = len = min(len, MCLBYTES);
657 else
658 len = m->m_len;
659 } else {
660 /*
661 * Place initial small packet/header at end of mbuf.
662 */
663 if (len < m->m_len) {
664 if (top == 0 && len + max_linkhdr <= m->m_len)
665 m->m_data += max_linkhdr;
666 m->m_len = len;
667 } else
668 len = m->m_len;
669 }
670 bcopy(cp, mtod(m, caddr_t), (unsigned)len);
671 cp += len;
672 *mp = m;
673 mp = &m->m_next;
674 totlen -= len;
675 if (cp == epkt)
676 cp = lebuf;
677 }
678 return (top);
679 }
680
681 /*
682 * Process an ioctl request.
683 */
684 leioctl(ifp, cmd, data)
685 register struct ifnet *ifp;
686 int cmd;
687 caddr_t data;
688 {
689 register struct ifaddr *ifa = (struct ifaddr *)data;
690 struct le_softc *le = (struct le_softc *) lecd.cd_devs[ifp->if_unit];
691 struct lereg1 *ler1 = le->sc_r1;
692 int s = splimp(), error = 0;
693
694 switch (cmd) {
695
696 case SIOCSIFADDR:
697 ifp->if_flags |= IFF_UP;
698 switch (ifa->ifa_addr->sa_family) {
699 #ifdef INET
700 case AF_INET:
701 leinit(ifp->if_unit); /* before arpwhohas */
702 ((struct arpcom *)ifp)->ac_ipaddr =
703 IA_SIN(ifa)->sin_addr;
704 arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
705 break;
706 #endif
707 #ifdef NS
708 case AF_NS:
709 {
710 register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
711
712 if (ns_nullhost(*ina))
713 ina->x_host = *(union ns_host *)(le->sc_addr);
714 else {
715 /*
716 * The manual says we can't change the address
717 * while the receiver is armed,
718 * so reset everything
719 */
720 ifp->if_flags &= ~IFF_RUNNING;
721 bcopy((caddr_t)ina->x_host.c_host,
722 (caddr_t)le->sc_addr, sizeof(le->sc_addr));
723 }
724 leinit(ifp->if_unit); /* does le_setaddr() */
725 break;
726 }
727 #endif
728 default:
729 leinit(ifp->if_unit);
730 break;
731 }
732 break;
733
734 case SIOCSIFFLAGS:
735 if ((ifp->if_flags & IFF_UP) == 0 &&
736 ifp->if_flags & IFF_RUNNING) {
737 LERDWR(le->sc_r0, LE_STOP, ler1->ler1_rdp);
738 ifp->if_flags &= ~IFF_RUNNING;
739 } else if (ifp->if_flags & IFF_UP &&
740 (ifp->if_flags & IFF_RUNNING) == 0)
741 leinit(ifp->if_unit);
742 /*
743 * If the state of the promiscuous bit changes, the interface
744 * must be reset to effect the change.
745 */
746 if (((ifp->if_flags ^ le->sc_iflags) & IFF_PROMISC) &&
747 (ifp->if_flags & IFF_RUNNING)) {
748 le->sc_iflags = ifp->if_flags;
749 lereset(ifp->if_unit);
750 lestart(ifp);
751 }
752 break;
753
754 default:
755 error = EINVAL;
756 }
757 splx(s);
758 return (error);
759 }
760
761 leerror(unit, stat)
762 int unit;
763 int stat;
764 {
765 struct le_softc *le = NULL;
766
767
768 if (!ledebug)
769 return;
770
771 le = (struct le_softc *) lecd.cd_devs[unit];
772 /*
773 * Not all transceivers implement heartbeat
774 * so we only log CERR once.
775 */
776 if ((stat & LE_CERR) && le->sc_cerr)
777 return;
778 log(LOG_WARNING,
779 "le%d: error: stat=%b\n", unit,
780 stat,
781 "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT");
782 }
783
784 lererror(unit, msg)
785 int unit;
786 char *msg;
787 {
788 register struct le_softc *le = lecd.cd_devs[unit];
789 register struct lermd *rmd;
790 int len;
791
792 if (!ledebug)
793 return;
794
795 rmd = &le->sc_r2->ler2_rmd[le->sc_rmd];
796 len = rmd->rmd3;
797 log(LOG_WARNING,
798 "le%d: ierror(%s): from %s: buf=%d, len=%d, rmd1=%b\n",
799 unit, msg,
800 len > 11 ? ether_sprintf(&le->sc_r2->ler2_rbuf[le->sc_rmd][6]) : "unknown",
801 le->sc_rmd, len,
802 rmd->rmd1,
803 "\20\20OWN\17ERR\16FRAM\15OFLO\14CRC\13RBUF\12STP\11ENP");
804 }
805
806 lexerror(unit)
807 int unit;
808 {
809 register struct le_softc *le = lecd.cd_devs[unit];
810 register struct letmd *tmd;
811 int len;
812
813 if (!ledebug)
814 return;
815
816 tmd = le->sc_r2->ler2_tmd;
817 len = -tmd->tmd2;
818 log(LOG_WARNING,
819 "le%d: oerror: to %s: buf=%d, len=%d, tmd1=%b, tmd3=%b\n",
820 unit,
821 len > 5 ? ether_sprintf(&le->sc_r2->ler2_tbuf[0][0]) : "unknown",
822 0, len,
823 tmd->tmd1,
824 "\20\20OWN\17ERR\16RES\15MORE\14ONE\13DEF\12STP\11ENP",
825 tmd->tmd3,
826 "\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY");
827 }
828