1 /* 2 * Copyright (c) 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Micom-Interlan Inc. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the University of California, Berkeley. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * 20 * @(#)if_ix.c 7.4 (Berkeley) 08/04/88 21 */ 22 23 #include "np.h" 24 #if NNP > 0 25 26 /* 27 * Interlan NP100 Ethernet Communications Controller interface 28 */ 29 #include "../machine/pte.h" 30 31 #include "param.h" 32 #include "systm.h" 33 #include "mbuf.h" 34 #include "buf.h" 35 #include "protosw.h" 36 #include "socket.h" 37 #include "vmmac.h" 38 #include "ioctl.h" 39 #include "errno.h" 40 41 #include "../net/if.h" 42 #include "../net/netisr.h" 43 #include "../net/route.h" 44 45 #ifdef INET 46 #include "../netinet/in.h" 47 #include "../netinet/in_systm.h" 48 #include "../netinet/in_var.h" 49 #include "../netinet/ip.h" 50 #include "../netinet/if_ether.h" 51 #endif 52 53 #ifdef NS 54 #include "../netns/ns.h" 55 #include "../netns/ns_if.h" 56 #endif 57 58 #include "../vax/cpu.h" 59 #include "../vax/mtpr.h" 60 #include "../vaxif/if_uba.h" 61 #include "../vaxuba/ubareg.h" 62 #include "../vaxuba/ubavar.h" 63 #include "../vaxuba/npreg.h" 64 #include "../vaxif/if_ix.h" 65 66 int ixattach(), ixrint(), ixcint(); 67 #define ILUNIT(x) minor(x) 68 int ixinit(), ixoutput(), ixioctl(), ixreset(), ixwatch(); 69 int (*IxAttach)() = ixattach; 70 int (*IxReset)() = ixreset; 71 72 /* 73 * Ethernet software status per interface. 74 * 75 * Each interface is referenced by a network interface structure, 76 * ix_if, which the routing code uses to locate the interface. 77 * This structure contains the output queue for the interface, its address, ... 78 * We also have, for each interface, a UBA interface structure, which 79 * contains information about the UNIBUS resources held by the interface: 80 * map registers, buffered data paths, etc. Information is cached in this 81 * structure for use by the if_uba.c routines in running the interface 82 * efficiently. 83 */ 84 struct ix_softc { 85 struct arpcom ix_ac; /* Ethernet common part */ 86 #define ix_if ix_ac.ac_if /* network-visible interface */ 87 #define ix_addr ix_ac.ac_enaddr /* hardware Ethernet address */ 88 int ix_flags; 89 #define IXF_OACTIVE 0x1 /* output is active */ 90 #define IXF_RCVPENDING 0x2 /* start rcv in ilcint */ 91 #define IXF_GOTUBA 0x4 /* unibus resources mapped */ 92 #define IXF_RUNNING 0x8 /* board is running */ 93 #define IXF_SETADDR 0x10 /* physical address is changed */ 94 #define IXF_STATPENDING 0x20 /* stat cmd pending */ 95 #define IXF_GOTCQE 0x40 /* np resources available */ 96 #define IXF_OWATCH 0x80 /* is output hung? */ 97 #define IXF_RWATCH 0x100 /* is input hung? */ 98 struct ifuba ix_ifuba; /* unibus resources */ 99 u_short ix_aid; /* Access Id returned by open DDL */ 100 u_short ix_badcqe; 101 struct npmaster *ix_mp; /* Board physio request header */ 102 struct npreq *ix_rrp; /* Cached npreq for recv */ 103 struct npreq *ix_wrp; /* Cached npreq for xmit */ 104 short ix_scaninterval; /* interval of stat collection */ 105 #define IXWATCHINTERVAL 60 /* once every 60 seconds */ 106 union ix_stats ix_stats; /* holds on-board statistics */ 107 int ix_ubaddr; /* mapping registers of ix_stats */ 108 } ix_softc[NNP]; 109 extern struct uba_device *npdinfo[]; 110 111 /* 112 * Interface exists: make available by filling in network interface 113 * record. System will initialize the interface when it is ready 114 * to accept packets. We can't even get the ethernet address 115 * or other interesting data until the board has been downloaded. 116 * running ifconfig will attempt to start unit. 117 */ 118 ixattach(ui) 119 struct uba_device *ui; 120 { 121 register struct ix_softc *ix = &ix_softc[ui->ui_unit]; 122 register struct ifnet *ifp = &ix->ix_if; 123 extern struct npmaster npmasters[]; 124 125 ifp->if_unit = ui->ui_unit; 126 ifp->if_name = "ix"; 127 ifp->if_mtu = ETHERMTU; 128 ifp->if_flags = IFF_BROADCAST; 129 130 ifp->if_init = ixinit; 131 ifp->if_output = ixoutput; 132 ifp->if_ioctl = ixioctl; 133 ifp->if_reset = ixreset; 134 135 ix->ix_mp = npmasters + ui->ui_unit; 136 ix->ix_ifuba.ifu_flags = UBA_CANTWAIT; 137 138 if_attach(ifp); 139 } 140 141 struct npreq * 142 ix_GetReq(mp, addr, len) 143 struct npmaster *mp; 144 caddr_t addr; 145 { 146 int unit = mp->unit; 147 register struct npreq *rp; 148 register struct CQE *ep; 149 struct ix_softc *ix = ix_softc + unit; 150 extern struct npreq *NpGetReq(); 151 152 while ((rp = NpGetReq(mp->reqtab)) == NULL) { 153 mp->reqtab->flags |= WANTREQ; 154 sleep((caddr_t)(mp->reqtab), PZERO - 1); 155 } 156 rp->flags = KERNREQ; /* Clear flags */ 157 158 ep = rp->element; /* Associated CQE */ 159 ep->cqe_famid = (unsign32)ix; /* Process ID */ 160 ep->cqe_wind = 0; /* Amount of buffer mapped */ 161 ep->cqe_nbuf = 1; /* Must be 1, no buffer chain */ 162 ep->cqe_char = 1; /* Driver owns this CQE */ 163 ep->cqe_prot = NPDLA; /* Data Link Access protocol */ 164 ep->cqe_bcnt = len; /* Byte count */ 165 rp->bufaddr = (caddr_t) (UBADDRMASK & (int) addr);/* mapped buffer */ 166 ep->cqe_dma[0] = (unsign16)LOWORD(rp->bufaddr); 167 ep->cqe_dma[1] = (unsign16)HIWORD(rp->bufaddr); 168 return (rp); 169 } 170 171 ix_DoReq(mp, rp, cmd, addr, len, rpb, routine) 172 struct npmaster *mp; 173 register struct npreq *rp; 174 u_short cmd; 175 caddr_t addr; 176 int len; 177 register u_short *rpb; 178 int (*routine)(); 179 { 180 register struct CQE *ep = rp->element; 181 register u_short *p = &ep->rpb1; 182 u_short cnt = *rpb++; 183 extern long NpDebug; 184 int pri; 185 int result = 0; 186 187 ep->cqe_ust0 = ep->cqe_ust1 = NPCLEAR; /* Clear status */ 188 ep->cqe_bcnt = len; /* Byte count */ 189 rp->flags = KERNREQ | REQALOC; /* Clear flags */ 190 rp->bufaddr = (caddr_t) (UBADDRMASK & (int) addr);/* mapped buffer */ 191 rp->intr = routine; 192 rp->user = (caddr_t) (ep->cqe_func = cmd);/* In case pissed on in CQE */ 193 ep->cqe_dma[0] = (unsign16)LOWORD(rp->bufaddr); 194 ep->cqe_dma[1] = (unsign16)HIWORD(rp->bufaddr); 195 ep->cqe_lenrpb = cnt + cnt; 196 for (; cnt > 0; cnt--) *p++ = *rpb++; 197 198 if (NpDebug & DEBCQE) 199 printf("Function is %x ep %x reqid %x\n", ep->cqe_func, ep, ep->cqe_reqid); 200 if (NpDebug & DEBCQE) 201 printf("irp len = %x rp = %x\n", ep->cqe_lenrpb, rp); 202 if (routine == 0) { 203 NpAddReq(mp->reqtab, rp); /* Queue onto active list */ 204 while (!(rp->flags & REQDONE)) { 205 pri = spl5(); 206 NpAddCQE(ep, &mp->shmemp->devcq, mp); 207 sleep((caddr_t)rp, PZERO - 1); 208 splx(pri); 209 } 210 if (rp->flags & IOABORT || ep->cqe_sts != NPDONE 211 || ep->cqe_ust0 != NPDONE 212 || ep->cqe_ust1 != NPOK) { 213 struct ix_softc *ix = (struct ix_softc *)ep->cqe_famid; 214 printf("ix%d: Req failed, cmd %x, stat %x, flags %x, ", 215 ix->ix_if.if_unit, rp->user, 216 ep->cqe_sts, rp->flags); 217 printf("ust error %x,%x\n", ep->cqe_ust0, ep->cqe_ust1); 218 result = 1; 219 } 220 NpRemReq(rp); /* Clear request */ 221 } else { 222 pri = spl5(); 223 NpAddCQE(ep, &mp->shmemp->devcq, mp); 224 splx(pri); 225 } 226 return(result); 227 } 228 229 /* 230 * Ethernet output routine. 231 * Encapsulate a packet of type family for the local net. 232 * Use trailer local net encapsulation if enough data in first 233 * packet leaves a multiple of 512 bytes of data in remainder. 234 */ 235 ixoutput(ifp, m0, dst) 236 struct ifnet *ifp; 237 struct mbuf *m0; 238 struct sockaddr *dst; 239 { 240 int type, s, error; 241 u_char edst[6]; 242 struct in_addr idst; 243 register struct ix_softc *ix = &ix_softc[ifp->if_unit]; 244 register struct mbuf *m = m0; 245 register struct ether_header *il; 246 register int off; 247 int usetrailers; 248 249 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) { 250 error = ENETDOWN; 251 goto bad; 252 } 253 switch (dst->sa_family) { 254 255 #ifdef INET 256 case AF_INET: 257 idst = ((struct sockaddr_in *)dst)->sin_addr; 258 if (!arpresolve(&ix->ix_ac, m, &idst, edst, &usetrailers)) 259 return (0); /* if not yet resolved */ 260 off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len; 261 if (usetrailers && off > 0 && (off & 0x1ff) == 0 && 262 m->m_off >= MMINOFF + 2 * sizeof (u_short)) { 263 type = ETHERTYPE_TRAIL + (off>>9); 264 m->m_off -= 2 * sizeof (u_short); 265 m->m_len += 2 * sizeof (u_short); 266 *mtod(m, u_short *) = htons((u_short)ETHERTYPE_IP); 267 *(mtod(m, u_short *) + 1) = htons((u_short)m->m_len); 268 goto gottrailertype; 269 } 270 type = ETHERTYPE_IP; 271 off = 0; 272 goto gottype; 273 #endif 274 #ifdef NS 275 case AF_NS: 276 type = ETHERTYPE_NS; 277 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 278 (caddr_t)edst, sizeof (edst)); 279 off = 0; 280 goto gottype; 281 #endif 282 283 case AF_UNSPEC: 284 il = (struct ether_header *)dst->sa_data; 285 bcopy((caddr_t)il->ether_dhost, (caddr_t)edst, sizeof (edst)); 286 type = il->ether_type; 287 goto gottype; 288 289 default: 290 printf("ix%d: can't handle af%d\n", ifp->if_unit, 291 dst->sa_family); 292 error = EAFNOSUPPORT; 293 goto bad; 294 } 295 296 gottrailertype: 297 /* 298 * Packet to be sent as trailer: move first packet 299 * (control information) to end of chain. 300 */ 301 while (m->m_next) 302 m = m->m_next; 303 m->m_next = m0; 304 m = m0->m_next; 305 m0->m_next = 0; 306 m0 = m; 307 308 gottype: 309 /* 310 * Add local net header. If no space in first mbuf, 311 * allocate another. 312 */ 313 if (m->m_off > MMAXOFF || 314 MMINOFF + sizeof (struct ether_header) > m->m_off) { 315 m = m_get(M_DONTWAIT, MT_HEADER); 316 if (m == 0) { 317 error = ENOBUFS; 318 goto bad; 319 } 320 m->m_next = m0; 321 m->m_off = MMINOFF; 322 m->m_len = sizeof (struct ether_header); 323 } else { 324 m->m_off -= sizeof (struct ether_header); 325 m->m_len += sizeof (struct ether_header); 326 } 327 il = mtod(m, struct ether_header *); 328 il->ether_type = htons((u_short)type); 329 bcopy((caddr_t)edst, (caddr_t)il->ether_dhost, sizeof (edst)); 330 bcopy((caddr_t)ix->ix_addr, (caddr_t)il->ether_shost, 331 sizeof(il->ether_shost)); 332 333 /* 334 * Queue message on interface, and start output if interface 335 * not yet active. 336 */ 337 s = splimp(); 338 if (IF_QFULL(&ifp->if_snd)) { 339 IF_DROP(&ifp->if_snd); 340 splx(s); 341 m_freem(m); 342 return (ENOBUFS); 343 } 344 IF_ENQUEUE(&ifp->if_snd, m); 345 if ((ix->ix_flags & IXF_OACTIVE) == 0) 346 ixstart(ifp->if_unit); 347 splx(s); 348 return (0); 349 350 bad: 351 m_freem(m0); 352 return (error); 353 } 354 /* 355 * Reset of interface after UNIBUS reset. 356 * If interface is on specified uba, reset its state. 357 */ 358 ixreset(unit, uban, softp) 359 int unit, uban; 360 caddr_t softp; 361 { 362 register struct uba_device *ui; 363 int mask = IXF_SETADDR; /* Only remember new physaddr */ 364 365 if (unit >= NNP || (ui = npdinfo[unit]) == 0 || ui->ui_alive == 0 || 366 ui->ui_ubanum != uban) 367 return; 368 printf(" ix%d reset", unit); 369 if (softp) 370 mask |= IXF_GOTUBA; /* UBA mapping regs still valid; */ 371 ix_softc[unit].ix_if.if_flags &= ~IFF_RUNNING; 372 ix_softc[unit].ix_flags &= mask; 373 } 374 375 int ix_MacLoop = 0; 376 377 /* 378 * Initialization of interface; clear recorded pending 379 * operations, and reinitialize UNIBUS usage. 380 */ 381 ixinit(unit) 382 int unit; 383 { 384 register struct ix_softc *ix = &ix_softc[unit]; 385 struct uba_device *ui = npdinfo[unit]; 386 register struct ifnet *ifp = &ix->ix_if; 387 register struct CQE *ep; 388 struct npreq *rp; 389 struct npmaster *mp = ix->ix_mp; 390 register u_short *dpmp = & mp->shmemp->statblock.sb_dpm; 391 u_short rpb[7]; 392 int s; 393 394 /* not yet, if address still unknown */ 395 if ((ifp->if_addrlist == (struct ifaddr *)0) || 396 (ix->ix_flags & IXF_RUNNING)) 397 return; 398 if ((mp->flags & AVAILABLE) == 0 || (*dpmp & PROTOMASK(NPDLA)) == 0) { 399 ifp->if_flags &= ~IFF_UP; 400 return; 401 } 402 if ((ix->ix_flags & IXF_GOTUBA) == 0) { 403 ix->ix_ifuba.ifu_flags = UBA_CANTWAIT; 404 if (if_ubainit(&ix->ix_ifuba, ui->ui_ubanum, 405 sizeof (struct ether_header), (int)btoc(ETHERMTU)) == 0) { 406 printf("ix%d: can't initialize\n", unit); 407 ix->ix_if.if_flags &= ~IFF_UP; 408 return; 409 } 410 ix->ix_ubaddr = uballoc(ui->ui_ubanum, (caddr_t)&ix->ix_stats, 411 sizeof (union ix_stats), 0); 412 ix->ix_flags |= IXF_GOTUBA; 413 } 414 if ((ix->ix_flags & IXF_GOTCQE) == 0) { 415 ix->ix_rrp = ix_GetReq(mp, ix->ix_ifuba.ifu_r.ifrw_info, 416 ETHERMTU); 417 ix->ix_wrp = ix_GetReq(mp, 0, 0); 418 ix->ix_flags |= IXF_GOTCQE; 419 } 420 421 rp = ix->ix_wrp; 422 ep = rp->element; 423 424 /* Changing the ethernet address resets the dla module, 425 so must do it before opening the channel */ 426 if (ix->ix_flags & IXF_SETADDR) { 427 register char *cp = (char *) &ix->ix_stats; 428 int spincount; 429 int x; 430 /* Try Issuing an open channel request before reprogramming 431 the physical address */ 432 rpb[0] = 6; /* RPB length */ 433 rpb[2] = 0x10; /* Share with any smart users */ 434 rpb[3] = 0; /* Take (a copy of) all frames */ 435 rpb[5] = 8; /* On board rcv queue length */ 436 rpb[6] = 0; /* XMT packets as is */ 437 if (ix_DoReq(mp, rp, IXC_OPEN, 0, 0, rpb, 0)) 438 return; 439 /* Proceed with LDPA */ 440 *cp++ = 1; 441 bcopy(ix->ix_addr, (caddr_t)cp, 6); 442 rpb[0] = 1; /* RPB length */ 443 if (ix_DoReq(mp, rp, IXC_LDPA, ix->ix_ubaddr, 7, rpb, 0)) 444 return; 445 #ifndef TheyFinallyFixedTheBoard 446 /* Board requires some time to reinitialize its protocols */ 447 x = spl1(); 448 spincount = 2000000; 449 while (((*dpmp & PROTOMASK(NPDLA))==0) && spincount > 0) 450 spincount--; 451 if (spincount==0) { 452 printf("ix%d: failed to reinitialize DLA module\n", 453 unit); 454 splx(x); 455 } 456 splx(x); 457 #endif 458 } 459 rpb[0] = 6; /* RPB length */ 460 rpb[2] = 0x10; /* Share with any smart users */ 461 if (ix_MacLoop) rpb[2] |= 0x8; 462 /* Enable software loopback on board */ 463 rpb[3] = 0; /* Take (a copy of) all frames */ 464 rpb[5] = 8; /* On board rcv queue length */ 465 rpb[6] = 0; /* XMT packets as is */ 466 if (ix_DoReq(mp, rp, IXC_OPEN, 0, 0, rpb, 0)) 467 return; 468 469 ix->ix_aid = ep->rpb1; 470 471 /* Here we request our ethernet address, if we didn't reset it*/ 472 if ((ix->ix_flags & IXF_SETADDR)==0) { 473 rpb[0] = 2; 474 rpb[1] = ix->ix_aid; 475 rpb[2] = 0; /* get all stats */ 476 if (ix_DoReq(mp, rp, IXC_GSTAT, /* Get Stats */ 477 (caddr_t) ix->ix_ubaddr, sizeof(ix->ix_stats) - 8, 478 rpb, 0)) 479 return; 480 bcopy((caddr_t) &ix->ix_stats, (caddr_t) ix->ix_addr, 6); 481 } 482 ix->ix_if.if_flags |= IFF_RUNNING; 483 ix->ix_flags |= IXF_RUNNING; 484 ifp->if_watchdog = ixwatch; 485 ifp->if_timer = ix->ix_scaninterval = IXWATCHINTERVAL; 486 ixrint(mp, 0); 487 } 488 489 /* 490 * Start output on interface. 491 * Get another datagram to send off of the interface queue, 492 * and map it to the interface before starting the output. 493 */ 494 ixstart(dev) 495 dev_t dev; 496 { 497 int len = 0; 498 int unit = minor(dev); 499 register struct ix_softc *ix = &ix_softc[unit]; 500 register struct mbuf *n; 501 struct mbuf *m; 502 int s, error = 0; 503 struct npmaster *mp = ix->ix_mp; 504 struct npreq *rp = ix->ix_wrp; 505 struct CQE *ep; 506 u_short rpb[8]; 507 508 IF_DEQUEUE(&ix->ix_if.if_snd, m); 509 if (m == 0) { 510 if (ix->ix_flags & IXF_STATPENDING) { 511 ix->ix_flags &= ~IXF_STATPENDING; 512 ix->ix_flags |= IXF_OACTIVE; 513 rpb[0] = 2; 514 rpb[1] = ix->ix_aid; 515 rpb[2] = 0; /* get all stats */ 516 ix_DoReq(mp, rp, IXC_GSTAT, /* general Stats */ 517 (caddr_t) ix->ix_ubaddr, sizeof(ix->ix_stats) - 8, 518 rpb, ixcint); 519 } 520 return; 521 } 522 /* 523 * Ensure minimum packet length. 524 * This makes the safe assumtion that there are no virtual holes 525 * after the data. 526 * For security, it might be wise to zero out the added bytes, 527 * but we're mainly interested in speed at the moment. 528 */ 529 len = if_wubaput(&ix->ix_ifuba, m); 530 if (len - sizeof(struct ether_header) < ETHERMIN) 531 len = ETHERMIN + sizeof(struct ether_header); 532 533 ix->ix_flags |= IXF_OACTIVE; 534 535 /* Now setup to call np driver */ 536 rpb[0] = 8; 537 rpb[1] = ix->ix_aid; 538 ix_DoReq(mp, rp, IXC_XMIT, /* send frame */ 539 ix->ix_ifuba.ifu_w.ifrw_info, len, rpb, ixcint); 540 } 541 542 /* 543 * Command done interrupt. (almost) 544 */ 545 ixcint(mp, rp) 546 struct npmaster *mp; 547 struct npreq *rp; 548 { 549 struct CQE *ep; 550 register struct ix_softc *ix; 551 int s = splimp(); 552 553 ep = rp->element; 554 ix = (struct ix_softc *)ep->cqe_famid; 555 ix->ix_flags &= ~IXF_OWATCH; 556 if ((ix->ix_flags & IXF_OACTIVE) == 0) { 557 printf("ix%d: stray xmit interrupt, npreq=%x\n", 558 ix->ix_if.if_unit, rp); 559 } 560 ix->ix_flags &= ~IXF_OACTIVE; 561 if (rp->flags & IOABORT || ep->cqe_sts != NPDONE 562 || ep->cqe_ust0 != NPDONE || ep->cqe_ust1 != NPOK) { 563 if (ep->cqe_ust1 == 0x48) 564 ix->ix_if.if_oerrors++; 565 else { 566 struct ix_softc *ix = (struct ix_softc *)ep->cqe_famid; 567 printf( 568 "ix%d: ixcint failed, cmd %x, stat %x, flags %x, ", 569 ix->ix_if.if_unit, rp->user, 570 ep->cqe_sts, rp->flags); 571 printf("ust error %x,%x\n", ep->cqe_ust0, ep->cqe_ust1); 572 if (++ix->ix_badcqe > 65) { 573 ix->ix_badcqe = 0; 574 printf("ixcint: shutting down unix dla\n"); 575 ix->ix_if.if_flags &= ~IFF_UP; 576 } 577 } 578 } 579 else switch (ep->cqe_func) { 580 581 case IXC_XMIT: 582 ix->ix_if.if_opackets++; 583 break; 584 585 case IXC_GSTAT: 586 ix->ix_if.if_collisions += ix->ix_stats.ixg.macg_xrty; 587 } 588 done: 589 if (ix->ix_ifuba.ifu_xtofree) { 590 m_freem(ix->ix_ifuba.ifu_xtofree); 591 ix->ix_ifuba.ifu_xtofree = 0; 592 } 593 if ((ix->ix_if.if_flags & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING)) 594 ixstart(ix->ix_if.if_unit); 595 splx(s); 596 } 597 598 /* 599 * Ethernet interface receiver interrupt. 600 * If input error just drop packet. 601 * Otherwise purge input buffered data path and examine 602 * packet to determine type. If can't determine length 603 * from type, then have to drop packet. Othewise decapsulate 604 * packet based on type and pass to type specific higher-level 605 * input routine. 606 */ 607 ixrint(mp, rp) 608 struct npmaster *mp; 609 struct npreq *rp; 610 { 611 struct CQE *ep; 612 register struct ix_softc *ix = ix_softc + mp->unit; 613 register struct ether_header *il; 614 struct mbuf *m; 615 int len, off, resid, s; 616 register struct ifqueue *inq; 617 618 if ((ix->ix_flags & IXF_RUNNING) == 0) 619 return; 620 if (rp == 0) 621 goto setup; 622 ix->ix_flags &= ~(IXF_RCVPENDING|IXF_RWATCH); 623 ep = rp->element; 624 ix->ix_if.if_ipackets++; 625 if (ix->ix_ifuba.ifu_flags & UBA_NEEDBDP) 626 UBAPURGE(ix->ix_ifuba.ifu_uba, ix->ix_ifuba.ifu_r.ifrw_bdp); 627 il = (struct ether_header *)(ix->ix_ifuba.ifu_r.ifrw_addr); 628 len = ep->cqe_bcnt - sizeof (struct ether_header); 629 if (ep->cqe_sts != NPDONE || rp->flags & IOABORT 630 || ep->cqe_ust0 != NPDONE 631 || ep->cqe_ust1 != NPOK) { 632 printf("ix%drint: cqe error, cmd %x, stat %x, flags %x, ", 633 ix->ix_if.if_unit, rp->user, ep->cqe_sts, rp->flags); 634 printf("ust error %x,%x\n", ep->cqe_ust0, ep->cqe_ust1); 635 if (++ix->ix_badcqe > 50) { 636 ix->ix_badcqe = 0; 637 printf("ixrint: shutting down unix dla\n"); 638 ix->ix_if.if_flags &= ~IFF_UP; 639 return; 640 } 641 goto setup; 642 } 643 644 if ( len < 46 || len > ETHERMTU) { 645 ix->ix_if.if_ierrors++; 646 #ifdef notdef 647 if (ix->ix_if.if_ierrors % 100 == 0) 648 printf("ix%d: += 100 input errors\n", unit); 649 #endif 650 goto setup; 651 } 652 653 /* 654 * Deal with trailer protocol: if type is trailer type 655 * get true type from first 16-bit word past data. 656 * Remember that type was trailer by setting off. 657 */ 658 il->ether_type = ntohs((u_short)il->ether_type); 659 #define ildataaddr(il, off, type) ((type)(((caddr_t)((il)+1)+(off)))) 660 if (il->ether_type >= ETHERTYPE_TRAIL && 661 il->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { 662 off = (il->ether_type - ETHERTYPE_TRAIL) * 512; 663 if (off >= ETHERMTU) 664 goto setup; /* sanity */ 665 il->ether_type = ntohs(*ildataaddr(il, off, u_short *)); 666 resid = ntohs(*(ildataaddr(il, off+2, u_short *))); 667 if (off + resid > len) 668 goto setup; /* sanity */ 669 len = off + resid; 670 } else 671 off = 0; 672 if (len == 0) 673 goto setup; 674 675 /* 676 * Pull packet off interface. Off is nonzero if packet 677 * has trailing header; ilget will then force this header 678 * information to be at the front, but we still have to drop 679 * the type and length which are at the front of any trailer data. 680 */ 681 m = if_rubaget(&ix->ix_ifuba, len, off, &ix->ix_if); 682 if (m == 0) 683 goto setup; 684 if (off) { 685 struct ifnet *ifp; 686 687 ifp = *(mtod(m, struct ifnet **)); 688 m->m_off += 2 * sizeof (u_short); 689 m->m_len -= 2 * sizeof (u_short); 690 *(mtod(m, struct ifnet **)) = ifp; 691 } 692 switch (il->ether_type) { 693 694 #ifdef INET 695 case ETHERTYPE_IP: 696 schednetisr(NETISR_IP); 697 inq = &ipintrq; 698 break; 699 700 case ETHERTYPE_ARP: 701 arpinput(&ix->ix_ac, m); 702 goto setup; 703 #endif 704 #ifdef NS 705 case ETHERTYPE_NS: 706 schednetisr(NETISR_NS); 707 inq = &nsintrq; 708 break; 709 710 #endif 711 default: 712 m_freem(m); 713 goto setup; 714 } 715 716 s = splimp(); 717 if (IF_QFULL(inq)) { 718 IF_DROP(inq); 719 m_freem(m); 720 } else 721 IF_ENQUEUE(inq, m); 722 splx(s); 723 724 setup: 725 /* 726 * Reset for next packet if possible. 727 * If waiting for transmit command completion, set flag 728 * and wait until command completes. 729 */ 730 if (rp == 0) { 731 rp = ix->ix_rrp; 732 rp->intr = ixrint; 733 ep = rp->element; 734 } 735 len = ETHERMTU + sizeof(struct ether_header); 736 737 /* Now setup to call np driver */ 738 /* Initializations of request structure */ 739 740 ep->cqe_func = IXC_RECV; /* get frame */ 741 ep->cqe_ust0 = ep->cqe_ust1 = NPCLEAR; /* Clear status */ 742 ep->cqe_bcnt = len; /* Byte count */ 743 ep->cqe_lenrpb = 10; /* RPB length */ 744 ep->rpb1 = ix->ix_aid; /* which channel */ 745 ep->rpb2 = 65535; /* Timeout */ 746 747 ix->ix_flags |= IXF_RCVPENDING; 748 749 s = spl5(); 750 NpAddCQE(ep, &mp->shmemp->devcq, mp); /* Add CQE to device's queue */ 751 splx(s); 752 } 753 754 755 long ixwatchcount; 756 /* 757 * Watchdog routine, request statistics from board. 758 */ 759 ixwatch(unit) 760 int unit; 761 { 762 register struct ix_softc *ix = &ix_softc[unit]; 763 register struct ifnet *ifp = &ix->ix_if; 764 int s; 765 766 ixwatchcount++; 767 if (ix->ix_badcqe > 1) { 768 ix->ix_badcqe--; /* If errors aren't happening too fast, 769 give the board a reprieve */ 770 } 771 s = splimp(); 772 if (ix->ix_flags & IXF_STATPENDING) { 773 ifp->if_timer = ix->ix_scaninterval; 774 ix->ix_flags |= IXF_OWATCH; 775 splx(s); 776 return; 777 } 778 ix->ix_flags |= IXF_STATPENDING; 779 if ((ix->ix_flags & IXF_OACTIVE) == 0) 780 ixstart(ifp->if_unit); 781 else 782 ix->ix_flags |= IXF_OWATCH; 783 if (ix->ix_flags & IXF_RCVPENDING) 784 ix->ix_flags |= IXF_RWATCH; 785 splx(s); 786 ifp->if_timer = ix->ix_scaninterval; 787 } 788 /* 789 * Process an ioctl request. 790 */ 791 ixioctl(ifp, cmd, data) 792 register struct ifnet *ifp; 793 int cmd; 794 caddr_t data; 795 { 796 register struct ifaddr *ifa = (struct ifaddr *)data; 797 register struct ix_softc *ix = &ix_softc[ifp->if_unit]; 798 int s = splimp(), error = 0; 799 800 switch (cmd) { 801 802 case SIOCSIFADDR: 803 ifp->if_flags |= IFF_UP; 804 ixinit(ifp->if_unit); 805 if ((ifp->if_flags & IFF_UP) == 0) 806 return (EBUSY); 807 808 switch (ifa->ifa_addr.sa_family) { 809 #ifdef INET 810 case AF_INET: 811 ((struct arpcom *)ifp)->ac_ipaddr = 812 IA_SIN(ifa)->sin_addr; 813 arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); 814 break; 815 #endif 816 #ifdef NS 817 case AF_NS: 818 { 819 register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 820 821 if (ns_nullhost(*ina)) { 822 ina->x_host = * (union ns_host *) 823 (ix_softc[ifp->if_unit].ix_addr); 824 } else { 825 return 826 ix_setaddr(ina->x_host.c_host, ifp->if_unit); 827 } 828 break; 829 } 830 #endif 831 } 832 break; 833 834 case SIOCSIFFLAGS: 835 if ((ifp->if_flags & IFF_UP) == 0 && 836 ix->ix_flags & IXF_RUNNING) { 837 ix->ix_flags &= ~IXF_RUNNING; 838 NpReset(ix->ix_mp, 0); 839 } else if (ifp->if_flags & IFF_UP && 840 (ix->ix_flags & IXF_RUNNING) == 0) 841 ixinit(ifp->if_unit); 842 break; 843 844 default: 845 error = EINVAL; 846 } 847 splx(s); 848 return (error); 849 } 850 851 /* 852 * set ethernet address for unit 853 */ 854 ix_setaddr(physaddr, unit) 855 u_char *physaddr; 856 int unit; 857 { 858 register struct ix_softc *ix = &ix_softc[unit]; 859 860 if (! (ix->ix_flags & IXF_RUNNING)) 861 return (EBUSY); 862 863 /* The following is a big cop out due to the fact that 864 Changing the ethernet address resets the dla module, 865 so must re-open the channel, anyway. */ 866 867 868 bcopy((caddr_t)physaddr, (caddr_t)ix->ix_addr, sizeof ix->ix_addr); 869 ix->ix_flags &= ~IXF_RUNNING; 870 ix->ix_flags |= IXF_SETADDR; 871 ixinit(unit); 872 NpKill(ix->ix_mp, ix->ix_rrp); 873 } 874 static showme() { 875 return ((int) &(ix_softc->ix_badcqe)); 876 } 877 #endif 878