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