1 /* 2 * Copyright (c) 1982, 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)if_le.c 7.11 (Berkeley) 06/05/92 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 generate and 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 #ifdef ISO 52 extern char all_es_snpa[], all_is_snpa[], all_l1is_snpa[], all_l2is_snpa[]; 53 #endif 54 55 #include "../include/cpu.h" 56 #include "../hp300/isr.h" 57 #include "../include/mtpr.h" 58 #include "hp/dev/device.h" 59 #include "if_lereg.h" 60 61 #if NBPFILTER > 0 62 #include "../net/bpf.h" 63 #include "../net/bpfdesc.h" 64 char hprmp_multi[] = { 9, 0, 9, 0, 0, 4}; 65 #endif 66 67 /* offsets for: ID, REGS, MEM, NVRAM */ 68 int lestd[] = { 0, 0x4000, 0x8000, 0xC008 }; 69 70 int leattach(); 71 struct driver ledriver = { 72 leattach, "le", 73 }; 74 75 struct isr le_isr[NLE]; 76 int ledebug = 0; /* console error messages */ 77 78 int leintr(), leinit(), leioctl(), lestart(), ether_output(); 79 struct mbuf *m_devget(); 80 extern struct ifnet loif; 81 82 /* 83 * Ethernet software status per interface. 84 * 85 * Each interface is referenced by a network interface structure, 86 * le_if, which the routing code uses to locate the interface. 87 * This structure contains the output queue for the interface, its address, ... 88 */ 89 struct le_softc { 90 struct arpcom sc_ac; /* common Ethernet structures */ 91 #define sc_if sc_ac.ac_if /* network-visible interface */ 92 #define sc_addr sc_ac.ac_enaddr /* hardware Ethernet address */ 93 struct lereg0 *sc_r0; /* DIO registers */ 94 struct lereg1 *sc_r1; /* LANCE registers */ 95 struct lereg2 *sc_r2; /* dual-port RAM */ 96 int sc_rmd; /* predicted next rmd to process */ 97 int sc_tmd; /* next available tmd */ 98 int sc_txcnt; /* # of transmit buffers in use */ 99 /* stats */ 100 int sc_runt; 101 int sc_jab; 102 int sc_merr; 103 int sc_babl; 104 int sc_cerr; 105 int sc_miss; 106 int sc_rown; 107 int sc_xown; 108 int sc_xown2; 109 int sc_uflo; 110 int sc_rxlen; 111 int sc_rxoff; 112 int sc_txoff; 113 int sc_busy; 114 short sc_iflags; 115 caddr_t sc_bpf; 116 } le_softc[NLE]; 117 118 /* access LANCE registers */ 119 #define LERDWR(cntl, src, dst) \ 120 do { \ 121 (dst) = (src); \ 122 } while (((cntl)->ler0_status & LE_ACK) == 0); 123 124 /* 125 * Interface exists: make available by filling in network interface 126 * record. System will initialize the interface when it is ready 127 * to accept packets. 128 */ 129 leattach(hd) 130 struct hp_device *hd; 131 { 132 register struct lereg0 *ler0; 133 register struct lereg2 *ler2; 134 struct lereg2 *lemem = 0; 135 struct le_softc *le = &le_softc[hd->hp_unit]; 136 struct ifnet *ifp = &le->sc_if; 137 char *cp; 138 int i; 139 140 ler0 = le->sc_r0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr); 141 le->sc_r1 = (struct lereg1 *)(lestd[1] + (int)hd->hp_addr); 142 ler2 = le->sc_r2 = (struct lereg2 *)(lestd[2] + (int)hd->hp_addr); 143 if (ler0->ler0_id != LEID) 144 return(0); 145 le_isr[hd->hp_unit].isr_intr = leintr; 146 hd->hp_ipl = le_isr[hd->hp_unit].isr_ipl = LE_IPL(ler0->ler0_status); 147 le_isr[hd->hp_unit].isr_arg = hd->hp_unit; 148 ler0->ler0_id = 0xFF; 149 DELAY(100); 150 151 /* 152 * Read the ethernet address off the board, one nibble at a time. 153 */ 154 cp = (char *)(lestd[3] + (int)hd->hp_addr); 155 for (i = 0; i < sizeof(le->sc_addr); i++) { 156 le->sc_addr[i] = (*++cp & 0xF) << 4; 157 cp++; 158 le->sc_addr[i] |= *++cp & 0xF; 159 cp++; 160 } 161 printf("le%d: hardware address %s\n", hd->hp_unit, 162 ether_sprintf(le->sc_addr)); 163 164 /* 165 * Setup for transmit/receive 166 */ 167 ler2->ler2_mode = LE_MODE; 168 #if defined(ISO) || NBPFILTER > 0 169 ler2->ler2_ladrf0 = 0xffffffff; 170 ler2->ler2_ladrf1 = 0xffffffff; 171 #else 172 ler2->ler2_ladrf0 = 0; 173 ler2->ler2_ladrf1 = 0; 174 #endif 175 ler2->ler2_rlen = LE_RLEN; 176 ler2->ler2_rdra = (int)lemem->ler2_rmd; 177 ler2->ler2_tlen = LE_TLEN; 178 ler2->ler2_tdra = (int)lemem->ler2_tmd; 179 isrlink(&le_isr[hd->hp_unit]); 180 ler0->ler0_status = LE_IE; 181 182 ifp->if_unit = hd->hp_unit; 183 ifp->if_name = "le"; 184 ifp->if_mtu = ETHERMTU; 185 ifp->if_init = leinit; 186 ifp->if_ioctl = leioctl; 187 ifp->if_output = ether_output; 188 ifp->if_start = lestart; 189 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; 190 #if NBPFILTER > 0 191 bpfattach(&le->sc_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); 192 #endif 193 if_attach(ifp); 194 return (1); 195 } 196 197 ledrinit(ler2, le) 198 register struct lereg2 *ler2; 199 register struct le_softc *le; 200 { 201 register struct lereg2 *lemem = 0; 202 register int i; 203 204 ler2->ler2_padr[0] = le->sc_addr[1]; 205 ler2->ler2_padr[1] = le->sc_addr[0]; 206 ler2->ler2_padr[2] = le->sc_addr[3]; 207 ler2->ler2_padr[3] = le->sc_addr[2]; 208 ler2->ler2_padr[4] = le->sc_addr[5]; 209 ler2->ler2_padr[5] = le->sc_addr[4]; 210 for (i = 0; i < LERBUF; i++) { 211 ler2->ler2_rmd[i].rmd0 = (int)lemem->ler2_rbuf[i]; 212 ler2->ler2_rmd[i].rmd1 = LE_OWN; 213 ler2->ler2_rmd[i].rmd2 = -LEMTU; 214 ler2->ler2_rmd[i].rmd3 = 0; 215 } 216 for (i = 0; i < LETBUF; i++) { 217 ler2->ler2_tmd[i].tmd0 = (int)lemem->ler2_tbuf[i]; 218 ler2->ler2_tmd[i].tmd1 = 0; 219 ler2->ler2_tmd[i].tmd2 = 0; 220 ler2->ler2_tmd[i].tmd3 = 0; 221 } 222 } 223 224 lereset(unit) 225 register int unit; 226 { 227 register struct le_softc *le = &le_softc[unit]; 228 register struct lereg0 *ler0 = le->sc_r0; 229 register struct lereg1 *ler1 = le->sc_r1; 230 register struct lereg2 *lemem = 0; 231 register int timo = 100000; 232 register int stat; 233 234 #ifdef lint 235 stat = unit; 236 #endif 237 #if NBPFILTER > 0 238 if (le->sc_if.if_flags & IFF_PROMISC) 239 /* set the promiscuous bit */ 240 le->sc_r2->ler2_mode = LE_MODE|0x8000; 241 else 242 le->sc_r2->ler2_mode = LE_MODE; 243 #endif 244 LERDWR(ler0, LE_CSR0, ler1->ler1_rap); 245 LERDWR(ler0, LE_STOP, ler1->ler1_rdp); 246 ledrinit(le->sc_r2, le); 247 le->sc_rmd = le->sc_tmd = 0; 248 LERDWR(ler0, LE_CSR1, ler1->ler1_rap); 249 LERDWR(ler0, (int)&lemem->ler2_mode, ler1->ler1_rdp); 250 LERDWR(ler0, LE_CSR2, ler1->ler1_rap); 251 LERDWR(ler0, 0, ler1->ler1_rdp); 252 LERDWR(ler0, LE_CSR0, ler1->ler1_rap); 253 LERDWR(ler0, LE_INIT, ler1->ler1_rdp); 254 do { 255 if (--timo == 0) { 256 printf("le%d: init timeout, stat = 0x%x\n", 257 unit, stat); 258 break; 259 } 260 LERDWR(ler0, ler1->ler1_rdp, stat); 261 } while ((stat & LE_IDON) == 0); 262 LERDWR(ler0, LE_STOP, ler1->ler1_rdp); 263 LERDWR(ler0, LE_CSR3, ler1->ler1_rap); 264 LERDWR(ler0, LE_BSWP, ler1->ler1_rdp); 265 LERDWR(ler0, LE_CSR0, ler1->ler1_rap); 266 LERDWR(ler0, LE_STRT | LE_INEA, ler1->ler1_rdp); 267 le->sc_if.if_flags &= ~IFF_OACTIVE; 268 le->sc_txcnt = 0; 269 } 270 271 /* 272 * Initialization of interface 273 */ 274 leinit(unit) 275 int unit; 276 { 277 register struct ifnet *ifp = &le_softc[unit].sc_if; 278 register struct ifaddr *ifa; 279 int s; 280 281 /* not yet, if address still unknown */ 282 for (ifa = ifp->if_addrlist;; ifa = ifa->ifa_next) 283 if (ifa == 0) 284 return; 285 else if (ifa->ifa_addr && ifa->ifa_addr->sa_family != AF_LINK) 286 break; 287 if ((ifp->if_flags & IFF_RUNNING) == 0) { 288 s = splimp(); 289 ifp->if_flags |= IFF_RUNNING; 290 lereset(unit); 291 (void) lestart(ifp); 292 splx(s); 293 } 294 } 295 296 /* 297 * Start output on interface. Get another datagram to send 298 * off of the interface queue, and copy it to the interface 299 * before starting the output. 300 */ 301 lestart(ifp) 302 struct ifnet *ifp; 303 { 304 register struct le_softc *le = &le_softc[ifp->if_unit]; 305 register struct letmd *tmd; 306 register struct mbuf *m; 307 int len; 308 309 if ((le->sc_if.if_flags & IFF_RUNNING) == 0) 310 return (0); 311 tmd = &le->sc_r2->ler2_tmd[le->sc_tmd]; 312 do { 313 if (tmd->tmd1 & LE_OWN) { 314 le->sc_xown2++; 315 return (0); 316 } 317 IF_DEQUEUE(&le->sc_if.if_snd, m); 318 if (m == 0) 319 return (0); 320 len = leput(le->sc_r2->ler2_tbuf[le->sc_tmd], m); 321 #if NBPFILTER > 0 322 /* 323 * If bpf is listening on this interface, let it 324 * see the packet before we commit it to the wire. 325 */ 326 if (le->sc_bpf) 327 bpf_tap(le->sc_bpf, le->sc_r2->ler2_tbuf[le->sc_tmd], 328 len); 329 #endif 330 331 tmd->tmd3 = 0; 332 tmd->tmd2 = -len; 333 tmd->tmd1 = LE_OWN | LE_STP | LE_ENP; 334 if (++le->sc_tmd == LETBUF) { 335 le->sc_tmd = 0; 336 tmd = le->sc_r2->ler2_tmd; 337 } else 338 tmd++; 339 } while (++le->sc_txcnt < LETBUF); 340 le->sc_if.if_flags |= IFF_OACTIVE; 341 return (0); 342 } 343 344 leintr(unit) 345 register int unit; 346 { 347 register struct le_softc *le = &le_softc[unit]; 348 register struct lereg0 *ler0 = le->sc_r0; 349 register struct lereg1 *ler1; 350 register int stat; 351 352 if ((ler0->ler0_status & LE_IR) == 0) 353 return(0); 354 if (ler0->ler0_status & LE_JAB) { 355 le->sc_jab++; 356 lereset(unit); 357 return(1); 358 } 359 ler1 = le->sc_r1; 360 LERDWR(ler0, ler1->ler1_rdp, stat); 361 if (stat & LE_SERR) { 362 leerror(unit, stat); 363 if (stat & LE_MERR) { 364 le->sc_merr++; 365 lereset(unit); 366 return(1); 367 } 368 if (stat & LE_BABL) 369 le->sc_babl++; 370 if (stat & LE_CERR) 371 le->sc_cerr++; 372 if (stat & LE_MISS) 373 le->sc_miss++; 374 LERDWR(ler0, LE_BABL|LE_CERR|LE_MISS|LE_INEA, ler1->ler1_rdp); 375 } 376 if ((stat & LE_RXON) == 0) { 377 le->sc_rxoff++; 378 lereset(unit); 379 return(1); 380 } 381 if ((stat & LE_TXON) == 0) { 382 le->sc_txoff++; 383 lereset(unit); 384 return(1); 385 } 386 if (stat & LE_RINT) 387 lerint(unit); 388 if (stat & LE_TINT) 389 lexint(unit); 390 return(1); 391 } 392 393 /* 394 * Ethernet interface transmitter interrupt. 395 * Start another output if more data to send. 396 */ 397 lexint(unit) 398 register int unit; 399 { 400 register struct le_softc *le = &le_softc[unit]; 401 register struct letmd *tmd; 402 int i, gotone = 0; 403 404 do { 405 if ((i = le->sc_tmd - le->sc_txcnt) < 0) 406 i += LETBUF; 407 tmd = &le->sc_r2->ler2_tmd[i]; 408 if (tmd->tmd1 & LE_OWN) { 409 if (gotone) 410 break; 411 le->sc_xown++; 412 return; 413 } 414 415 /* clear interrupt */ 416 LERDWR(le->sc_r0, LE_TINT|LE_INEA, le->sc_r1->ler1_rdp); 417 418 /* XXX documentation says BUFF not included in ERR */ 419 if ((tmd->tmd1 & LE_ERR) || (tmd->tmd3 & LE_TBUFF)) { 420 lexerror(unit); 421 le->sc_if.if_oerrors++; 422 if (tmd->tmd3 & (LE_TBUFF|LE_UFLO)) { 423 le->sc_uflo++; 424 lereset(unit); 425 } else if (tmd->tmd3 & LE_LCOL) 426 le->sc_if.if_collisions++; 427 else if (tmd->tmd3 & LE_RTRY) 428 le->sc_if.if_collisions += 16; 429 } else if (tmd->tmd1 & LE_ONE) 430 le->sc_if.if_collisions++; 431 else if (tmd->tmd1 & LE_MORE) 432 /* what is the real number? */ 433 le->sc_if.if_collisions += 2; 434 else 435 le->sc_if.if_opackets++; 436 gotone++; 437 } while (--le->sc_txcnt > 0); 438 le->sc_if.if_flags &= ~IFF_OACTIVE; 439 (void) lestart(&le->sc_if); 440 } 441 442 #define LENEXTRMP \ 443 if (++bix == LERBUF) bix = 0, rmd = le->sc_r2->ler2_rmd; else ++rmd 444 445 /* 446 * Ethernet interface receiver interrupt. 447 * If input error just drop packet. 448 * Decapsulate packet based on type and pass to type specific 449 * higher-level input routine. 450 */ 451 lerint(unit) 452 int unit; 453 { 454 register struct le_softc *le = &le_softc[unit]; 455 register int bix = le->sc_rmd; 456 register struct lermd *rmd = &le->sc_r2->ler2_rmd[bix]; 457 458 /* 459 * Out of sync with hardware, should never happen? 460 */ 461 if (rmd->rmd1 & LE_OWN) { 462 le->sc_rown++; 463 LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp); 464 return; 465 } 466 467 /* 468 * Process all buffers with valid data 469 */ 470 while ((rmd->rmd1 & LE_OWN) == 0) { 471 int len = rmd->rmd3; 472 473 /* Clear interrupt to avoid race condition */ 474 LERDWR(le->sc_r0, LE_RINT|LE_INEA, le->sc_r1->ler1_rdp); 475 476 if (rmd->rmd1 & LE_ERR) { 477 le->sc_rmd = bix; 478 lererror(unit, "bad packet"); 479 le->sc_if.if_ierrors++; 480 } else if ((rmd->rmd1 & (LE_STP|LE_ENP)) != (LE_STP|LE_ENP)) { 481 /* 482 * Find the end of the packet so we can see how long 483 * it was. We still throw it away. 484 */ 485 do { 486 LERDWR(le->sc_r0, LE_RINT|LE_INEA, 487 le->sc_r1->ler1_rdp); 488 rmd->rmd3 = 0; 489 rmd->rmd1 = LE_OWN; 490 LENEXTRMP; 491 } while (!(rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP))); 492 le->sc_rmd = bix; 493 lererror(unit, "chained buffer"); 494 le->sc_rxlen++; 495 /* 496 * If search terminated without successful completion 497 * we reset the hardware (conservative). 498 */ 499 if ((rmd->rmd1 & (LE_OWN|LE_ERR|LE_STP|LE_ENP)) != 500 LE_ENP) { 501 lereset(unit); 502 return; 503 } 504 } else 505 leread(unit, le->sc_r2->ler2_rbuf[bix], len); 506 rmd->rmd3 = 0; 507 rmd->rmd1 = LE_OWN; 508 LENEXTRMP; 509 } 510 le->sc_rmd = bix; 511 } 512 513 leread(unit, buf, len) 514 int unit; 515 char *buf; 516 int len; 517 { 518 register struct le_softc *le = &le_softc[unit]; 519 register struct ether_header *et; 520 struct mbuf *m; 521 int off, resid; 522 523 le->sc_if.if_ipackets++; 524 et = (struct ether_header *)buf; 525 et->ether_type = ntohs((u_short)et->ether_type); 526 /* adjust input length to account for header and CRC */ 527 len = len - sizeof(struct ether_header) - 4; 528 529 #define ledataaddr(et, off, type) ((type)(((caddr_t)((et)+1)+(off)))) 530 if (et->ether_type >= ETHERTYPE_TRAIL && 531 et->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { 532 off = (et->ether_type - ETHERTYPE_TRAIL) * 512; 533 if (off >= ETHERMTU) 534 return; /* sanity */ 535 et->ether_type = ntohs(*ledataaddr(et, off, u_short *)); 536 resid = ntohs(*(ledataaddr(et, off+2, u_short *))); 537 if (off + resid > len) 538 return; /* sanity */ 539 len = off + resid; 540 } else 541 off = 0; 542 543 if (len <= 0) { 544 if (ledebug) 545 log(LOG_WARNING, 546 "le%d: ierror(runt packet): from %s: len=%d\n", 547 unit, ether_sprintf(et->ether_shost), len); 548 le->sc_runt++; 549 le->sc_if.if_ierrors++; 550 return; 551 } 552 #if NBPFILTER > 0 553 /* 554 * Check if there's a bpf filter listening on this interface. 555 * If so, hand off the raw packet to bpf, which must deal with 556 * trailers in its own way. 557 */ 558 if (le->sc_bpf) 559 bpf_tap(le->sc_bpf, buf, len + sizeof(struct ether_header)); 560 #endif 561 #if defined(ISO) || NBPFILTER > 0 562 /* 563 * Note that the interface cannot be in promiscuous mode if 564 * there are no bpf listeners. If we are in promiscuous 565 * mode, we have to check if this packet is really ours. 566 * However, there may be appropriate multicate addresses involved 567 */ 568 #define NOT_TO(p) (bcmp(et->ether_dhost, p, sizeof(et->ether_dhost)) != 0) 569 if (et->ether_dhost[0] & 1) { 570 if (NOT_TO(etherbroadcastaddr) && NOT_TO(hprmp_multi) 571 #ifdef ISO 572 && NOT_TO(all_es_snpa) && NOT_TO(all_is_snpa) 573 && NOT_TO(all_l1is_snpa) && NOT_TO(all_l2is_snpa) 574 #endif 575 ) return; 576 } else if ((le->sc_if.if_flags & IFF_PROMISC) && NOT_TO(le->sc_addr)) 577 return; 578 #endif 579 /* 580 * Pull packet off interface. Off is nonzero if packet 581 * has trailing header; m_devget will then force this header 582 * information to be at the front, but we still have to drop 583 * the type and length which are at the front of any trailer data. 584 */ 585 m = m_devget((char *)(et + 1), len, off, &le->sc_if, 0); 586 if (m == 0) 587 return; 588 ether_input(&le->sc_if, et, m); 589 } 590 591 /* 592 * Routine to copy from mbuf chain to transmit 593 * buffer in board local memory. 594 */ 595 leput(lebuf, m) 596 register char *lebuf; 597 register struct mbuf *m; 598 { 599 register struct mbuf *mp; 600 register int len, tlen = 0; 601 602 for (mp = m; mp; mp = mp->m_next) { 603 len = mp->m_len; 604 if (len == 0) 605 continue; 606 tlen += len; 607 bcopy(mtod(mp, char *), lebuf, len); 608 lebuf += len; 609 } 610 m_freem(m); 611 if (tlen < LEMINSIZE) { 612 bzero(lebuf, LEMINSIZE - tlen); 613 tlen = LEMINSIZE; 614 } 615 return(tlen); 616 } 617 618 /* 619 * Process an ioctl request. 620 */ 621 leioctl(ifp, cmd, data) 622 register struct ifnet *ifp; 623 int cmd; 624 caddr_t data; 625 { 626 register struct ifaddr *ifa = (struct ifaddr *)data; 627 struct le_softc *le = &le_softc[ifp->if_unit]; 628 struct lereg1 *ler1 = le->sc_r1; 629 int s = splimp(), error = 0; 630 631 switch (cmd) { 632 633 case SIOCSIFADDR: 634 ifp->if_flags |= IFF_UP; 635 switch (ifa->ifa_addr->sa_family) { 636 #ifdef INET 637 case AF_INET: 638 leinit(ifp->if_unit); /* before arpwhohas */ 639 ((struct arpcom *)ifp)->ac_ipaddr = 640 IA_SIN(ifa)->sin_addr; 641 arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); 642 break; 643 #endif 644 #ifdef NS 645 case AF_NS: 646 { 647 register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 648 649 if (ns_nullhost(*ina)) 650 ina->x_host = *(union ns_host *)(le->sc_addr); 651 else { 652 /* 653 * The manual says we can't change the address 654 * while the receiver is armed, 655 * so reset everything 656 */ 657 ifp->if_flags &= ~IFF_RUNNING; 658 LERDWR(le->sc_r0, LE_STOP, ler1->ler1_rdp); 659 bcopy((caddr_t)ina->x_host.c_host, 660 (caddr_t)le->sc_addr, sizeof(le->sc_addr)); 661 } 662 leinit(ifp->if_unit); /* does le_setaddr() */ 663 break; 664 } 665 #endif 666 default: 667 leinit(ifp->if_unit); 668 break; 669 } 670 break; 671 672 case SIOCSIFFLAGS: 673 if ((ifp->if_flags & IFF_UP) == 0 && 674 ifp->if_flags & IFF_RUNNING) { 675 LERDWR(le->sc_r0, LE_STOP, ler1->ler1_rdp); 676 ifp->if_flags &= ~IFF_RUNNING; 677 } else if (ifp->if_flags & IFF_UP && 678 (ifp->if_flags & IFF_RUNNING) == 0) 679 leinit(ifp->if_unit); 680 /* 681 * If the state of the promiscuous bit changes, the interface 682 * must be reset to effect the change. 683 */ 684 if (((ifp->if_flags ^ le->sc_iflags) & IFF_PROMISC) && 685 (ifp->if_flags & IFF_RUNNING)) { 686 le->sc_iflags = ifp->if_flags; 687 lereset(ifp->if_unit); 688 lestart(ifp); 689 } 690 break; 691 692 default: 693 error = EINVAL; 694 } 695 splx(s); 696 return (error); 697 } 698 699 leerror(unit, stat) 700 int unit; 701 int stat; 702 { 703 if (!ledebug) 704 return; 705 706 /* 707 * Not all transceivers implement heartbeat 708 * so we only log CERR once. 709 */ 710 if ((stat & LE_CERR) && le_softc[unit].sc_cerr) 711 return; 712 log(LOG_WARNING, 713 "le%d: error: stat=%b\n", unit, 714 stat, 715 "\20\20ERR\17BABL\16CERR\15MISS\14MERR\13RINT\12TINT\11IDON\10INTR\07INEA\06RXON\05TXON\04TDMD\03STOP\02STRT\01INIT"); 716 } 717 718 lererror(unit, msg) 719 int unit; 720 char *msg; 721 { 722 register struct le_softc *le = &le_softc[unit]; 723 register struct lermd *rmd; 724 int len; 725 726 if (!ledebug) 727 return; 728 729 rmd = &le->sc_r2->ler2_rmd[le->sc_rmd]; 730 len = rmd->rmd3; 731 log(LOG_WARNING, 732 "le%d: ierror(%s): from %s: buf=%d, len=%d, rmd1=%b\n", 733 unit, msg, 734 len > 11 ? 735 ether_sprintf((u_char *)&le->sc_r2->ler2_rbuf[le->sc_rmd][6]) : 736 "unknown", 737 le->sc_rmd, len, 738 rmd->rmd1, 739 "\20\20OWN\17ERR\16FRAM\15OFLO\14CRC\13RBUF\12STP\11ENP"); 740 } 741 742 lexerror(unit) 743 int unit; 744 { 745 register struct le_softc *le = &le_softc[unit]; 746 register struct letmd *tmd; 747 int len; 748 749 if (!ledebug) 750 return; 751 752 tmd = le->sc_r2->ler2_tmd; 753 len = -tmd->tmd2; 754 log(LOG_WARNING, 755 "le%d: oerror: to %s: buf=%d, len=%d, tmd1=%b, tmd3=%b\n", 756 unit, 757 len > 5 ? 758 ether_sprintf((u_char *)&le->sc_r2->ler2_tbuf[0][0]) : 759 "unknown", 760 0, len, 761 tmd->tmd1, 762 "\20\20OWN\17ERR\16RES\15MORE\14ONE\13DEF\12STP\11ENP", 763 tmd->tmd3, 764 "\20\20BUFF\17UFLO\16RES\15LCOL\14LCAR\13RTRY"); 765 } 766 #endif 767