1 /* 2 * Copyright (c) 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Digital Equipment Corp. 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_qe.c 7.14 (Berkeley) 10/30/89 21 */ 22 23 /* from @(#)if_qe.c 1.15 (ULTRIX) 4/16/86 */ 24 25 /**************************************************************** 26 * * 27 * Licensed from Digital Equipment Corporation * 28 * Copyright (c) * 29 * Digital Equipment Corporation * 30 * Maynard, Massachusetts * 31 * 1985, 1986 * 32 * All rights reserved. * 33 * * 34 * The Information in this software is subject to change * 35 * without notice and should not be construed as a commitment * 36 * by Digital Equipment Corporation. Digital makes no * 37 * representations about the suitability of this software for * 38 * any purpose. It is supplied "As Is" without expressed or * 39 * implied warranty. * 40 * * 41 * If the Regents of the University of California or its * 42 * licensees modify the software in a manner creating * 43 * derivative copyright rights, appropriate copyright * 44 * legends may be placed on the derivative work in addition * 45 * to that set forth above. * 46 * * 47 ****************************************************************/ 48 /* --------------------------------------------------------------------- 49 * Modification History 50 * 51 * 15-Apr-86 -- afd 52 * Rename "unused_multi" to "qunused_multi" for extending Generic 53 * kernel to MicroVAXen. 54 * 55 * 18-mar-86 -- jaw br/cvec changed to NOT use registers. 56 * 57 * 12 March 86 -- Jeff Chase 58 * Modified to handle the new MCLGET macro 59 * Changed if_qe_data.c to use more receive buffers 60 * Added a flag to poke with adb to log qe_restarts on console 61 * 62 * 19 Oct 85 -- rjl 63 * Changed the watch dog timer from 30 seconds to 3. VMS is using 64 * less than 1 second in their's. Also turned the printf into an 65 * mprintf. 66 * 67 * 09/16/85 -- Larry Cohen 68 * Add 43bsd alpha tape changes for subnet routing 69 * 70 * 1 Aug 85 -- rjl 71 * Panic on a non-existent memory interrupt and the case where a packet 72 * was chained. The first should never happen because non-existant 73 * memory interrupts cause a bus reset. The second should never happen 74 * because we hang 2k input buffers on the device. 75 * 76 * 1 Aug 85 -- rich 77 * Fixed the broadcast loopback code to handle Clusters without 78 * wedging the system. 79 * 80 * 27 Feb. 85 -- ejf 81 * Return default hardware address on ioctl request. 82 * 83 * 12 Feb. 85 -- ejf 84 * Added internal extended loopback capability. 85 * 86 * 27 Dec. 84 -- rjl 87 * Fixed bug that caused every other transmit descriptor to be used 88 * instead of every descriptor. 89 * 90 * 21 Dec. 84 -- rjl 91 * Added watchdog timer to mask hardware bug that causes device lockup. 92 * 93 * 18 Dec. 84 -- rjl 94 * Reworked driver to use q-bus mapping routines. MicroVAX-I now does 95 * copying instead of m-buf shuffleing. 96 * A number of deficencies in the hardware/firmware were compensated 97 * for. See comments in qestart and qerint. 98 * 99 * 14 Nov. 84 -- jf 100 * Added usage counts for multicast addresses. 101 * Updated general protocol support to allow access to the Ethernet 102 * header. 103 * 104 * 04 Oct. 84 -- jf 105 * Added support for new ioctls to add and delete multicast addresses 106 * and set the physical address. 107 * Add support for general protocols. 108 * 109 * 14 Aug. 84 -- rjl 110 * Integrated Shannon changes. (allow arp above 1024 and ? ) 111 * 112 * 13 Feb. 84 -- rjl 113 * 114 * Initial version of driver. derived from IL driver. 115 * 116 * --------------------------------------------------------------------- 117 */ 118 119 #include "qe.h" 120 #if NQE > 0 121 /* 122 * Digital Q-BUS to NI Adapter 123 */ 124 #include "param.h" 125 #include "systm.h" 126 #include "mbuf.h" 127 #include "buf.h" 128 #include "protosw.h" 129 #include "socket.h" 130 #include "vmmac.h" 131 #include "ioctl.h" 132 #include "errno.h" 133 #include "syslog.h" 134 #include "time.h" 135 #include "kernel.h" 136 137 #include "../net/if.h" 138 #include "../net/netisr.h" 139 #include "../net/route.h" 140 141 #ifdef INET 142 #include "../netinet/in.h" 143 #include "../netinet/in_systm.h" 144 #include "../netinet/in_var.h" 145 #include "../netinet/ip.h" 146 #include "../netinet/if_ether.h" 147 #endif 148 149 #ifdef NS 150 #include "../netns/ns.h" 151 #include "../netns/ns_if.h" 152 #endif 153 154 #ifdef ISO 155 #include "../netiso/iso.h" 156 #include "../netiso/iso_var.h" 157 #include "../netiso/iso_snpac.h" 158 extern struct snpa_cache all_es, all_is; 159 #endif 160 161 #include "../vax/pte.h" 162 #include "../vax/cpu.h" 163 #include "../vax/mtpr.h" 164 #include "if_qereg.h" 165 #include "if_uba.h" 166 #include "../vaxuba/ubareg.h" 167 #include "../vaxuba/ubavar.h" 168 169 #if NQE == 1 && !defined(QNIVERT) 170 #define NRCV 15 /* Receive descriptors */ 171 #else 172 #define NRCV 10 /* Receive descriptors */ 173 #endif 174 #define NXMT 5 /* Transmit descriptors */ 175 #define NTOT (NXMT + NRCV) 176 177 #define QETIMEOUT 2 /* transmit timeout, must be > 1 */ 178 #define QESLOWTIMEOUT 40 /* timeout when no xmits in progress */ 179 180 /* 181 * This constant should really be 60 because the qna adds 4 bytes of crc. 182 * However when set to 60 our packets are ignored by deuna's , 3coms are 183 * okay ?????????????????????????????????????????? 184 */ 185 #define MINDATA 64 186 187 /* 188 * Ethernet software status per interface. 189 * 190 * Each interface is referenced by a network interface structure, 191 * qe_if, which the routing code uses to locate the interface. 192 * This structure contains the output queue for the interface, its address, ... 193 */ 194 struct qe_softc { 195 struct arpcom qe_ac; /* Ethernet common part */ 196 #define qe_if qe_ac.ac_if /* network-visible interface */ 197 #define qe_addr qe_ac.ac_enaddr /* hardware Ethernet address */ 198 struct ifubinfo qe_uba; /* Q-bus resources */ 199 struct ifrw qe_ifr[NRCV]; /* for receive buffers; */ 200 struct ifxmt qe_ifw[NXMT]; /* for xmit buffers; */ 201 int qe_flags; /* software state */ 202 #define QEF_RUNNING 0x01 203 #define QEF_SETADDR 0x02 204 #define QEF_FASTTIMEO 0x04 205 int setupaddr; /* mapping info for setup pkts */ 206 int ipl; /* interrupt priority */ 207 struct qe_ring *rringaddr; /* mapping info for rings */ 208 struct qe_ring *tringaddr; /* "" */ 209 struct qe_ring rring[NRCV+1]; /* Receive ring descriptors */ 210 struct qe_ring tring[NXMT+1]; /* Transmit ring descriptors */ 211 u_char setup_pkt[16][8]; /* Setup packet */ 212 int rindex; /* Receive index */ 213 int tindex; /* Transmit index */ 214 int otindex; /* Old transmit index */ 215 int qe_intvec; /* Interrupt vector */ 216 struct qedevice *addr; /* device addr */ 217 int setupqueued; /* setup packet queued */ 218 int nxmit; /* Transmits in progress */ 219 int qe_restarts; /* timeouts */ 220 } qe_softc[NQE]; 221 222 struct uba_device *qeinfo[NQE]; 223 224 extern struct timeval time; 225 226 int qeprobe(), qeattach(), qeintr(), qetimeout(); 227 int qeinit(), qeioctl(), qereset(), qestart(); 228 229 u_short qestd[] = { 0 }; 230 struct uba_driver qedriver = 231 { qeprobe, 0, qeattach, 0, qestd, "qe", qeinfo }; 232 233 #define QEUNIT(x) minor(x) 234 /* 235 * The deqna shouldn't receive more than ETHERMTU + sizeof(struct ether_header) 236 * but will actually take in up to 2048 bytes. To guard against the receiver 237 * chaining buffers (which we aren't prepared to handle) we allocate 2kb 238 * size buffers. 239 */ 240 #define MAXPACKETSIZE 2048 /* Should really be ETHERMTU */ 241 /* 242 * Probe the QNA to see if it's there 243 */ 244 qeprobe(reg, ui) 245 caddr_t reg; 246 struct uba_device *ui; 247 { 248 register int br, cvec; /* r11, r10 value-result */ 249 register struct qedevice *addr = (struct qedevice *)reg; 250 register struct qe_ring *rp; 251 register struct qe_ring *prp; /* physical rp */ 252 register int i; 253 register struct qe_softc *sc = &qe_softc[ui->ui_unit]; 254 255 #ifdef lint 256 br = 0; cvec = br; br = cvec; 257 qeintr(0); 258 #endif 259 260 /* 261 * The QNA interrupts on i/o operations. To do an I/O operation 262 * we have to setup the interface by transmitting a setup packet. 263 */ 264 addr->qe_csr = QE_RESET; 265 addr->qe_csr &= ~QE_RESET; 266 addr->qe_vector = (uba_hd[numuba].uh_lastiv -= 4); 267 268 /* 269 * Map the communications area and the setup packet. 270 */ 271 sc->setupaddr = 272 uballoc(0, (caddr_t)sc->setup_pkt, sizeof(sc->setup_pkt), 0); 273 sc->rringaddr = (struct qe_ring *) uballoc(0, (caddr_t)sc->rring, 274 sizeof(struct qe_ring) * (NTOT+2), 0); 275 prp = (struct qe_ring *)UBAI_ADDR((int)sc->rringaddr); 276 277 /* 278 * The QNA will loop the setup packet back to the receive ring 279 * for verification, therefore we initialize the first 280 * receive & transmit ring descriptors and link the setup packet 281 * to them. 282 */ 283 qeinitdesc(sc->tring, (caddr_t)UBAI_ADDR(sc->setupaddr), 284 sizeof(sc->setup_pkt)); 285 qeinitdesc(sc->rring, (caddr_t)UBAI_ADDR(sc->setupaddr), 286 sizeof(sc->setup_pkt)); 287 288 rp = (struct qe_ring *)sc->tring; 289 rp->qe_setup = 1; 290 rp->qe_eomsg = 1; 291 rp->qe_flag = rp->qe_status1 = QE_NOTYET; 292 rp->qe_valid = 1; 293 294 rp = (struct qe_ring *)sc->rring; 295 rp->qe_flag = rp->qe_status1 = QE_NOTYET; 296 rp->qe_valid = 1; 297 298 /* 299 * Get the addr off of the interface and place it into the setup 300 * packet. This code looks strange due to the fact that the address 301 * is placed in the setup packet in col. major order. 302 */ 303 for( i = 0 ; i < 6 ; i++ ) 304 sc->setup_pkt[i][1] = addr->qe_sta_addr[i]; 305 306 qesetup( sc ); 307 /* 308 * Start the interface and wait for the packet. 309 */ 310 (void) spl6(); 311 addr->qe_csr = QE_INT_ENABLE | QE_XMIT_INT | QE_RCV_INT; 312 addr->qe_rcvlist_lo = (short)prp; 313 addr->qe_rcvlist_hi = (short)((int)prp >> 16); 314 prp += NRCV+1; 315 addr->qe_xmtlist_lo = (short)prp; 316 addr->qe_xmtlist_hi = (short)((int)prp >> 16); 317 DELAY(10000); 318 /* 319 * All done with the bus resources. 320 */ 321 ubarelse(0, &sc->setupaddr); 322 ubarelse(0, (int *)&sc->rringaddr); 323 sc->ipl = br = qbgetpri(); 324 return( sizeof(struct qedevice) ); 325 } 326 327 /* 328 * Interface exists: make available by filling in network interface 329 * record. System will initialize the interface when it is ready 330 * to accept packets. 331 */ 332 qeattach(ui) 333 struct uba_device *ui; 334 { 335 register struct qe_softc *sc = &qe_softc[ui->ui_unit]; 336 register struct ifnet *ifp = &sc->qe_if; 337 register struct qedevice *addr = (struct qedevice *)ui->ui_addr; 338 register int i; 339 340 ifp->if_unit = ui->ui_unit; 341 ifp->if_name = "qe"; 342 ifp->if_mtu = ETHERMTU; 343 ifp->if_flags = IFF_BROADCAST; 344 345 /* 346 * Read the address from the prom and save it. 347 */ 348 for( i=0 ; i<6 ; i++ ) 349 sc->setup_pkt[i][1] = sc->qe_addr[i] = addr->qe_sta_addr[i] & 0xff; 350 addr->qe_vector |= 1; 351 printf("qe%d: %s, hardware address %s\n", ui->ui_unit, 352 addr->qe_vector&01 ? "delqa":"deqna", 353 ether_sprintf(sc->qe_addr)); 354 addr->qe_vector &= ~1; 355 356 /* 357 * Save the vector for initialization at reset time. 358 */ 359 sc->qe_intvec = addr->qe_vector; 360 361 ifp->if_init = qeinit; 362 ifp->if_output = ether_output; 363 ifp->if_start = qestart; 364 ifp->if_ioctl = qeioctl; 365 ifp->if_reset = qereset; 366 ifp->if_watchdog = qetimeout; 367 sc->qe_uba.iff_flags = UBA_CANTWAIT; 368 if_attach(ifp); 369 } 370 371 /* 372 * Reset of interface after UNIBUS reset. 373 * If interface is on specified uba, reset its state. 374 */ 375 qereset(unit, uban) 376 int unit, uban; 377 { 378 register struct uba_device *ui; 379 380 if (unit >= NQE || (ui = qeinfo[unit]) == 0 || ui->ui_alive == 0 || 381 ui->ui_ubanum != uban) 382 return; 383 printf(" qe%d", unit); 384 qe_softc[unit].qe_if.if_flags &= ~IFF_RUNNING; 385 qeinit(unit); 386 } 387 388 /* 389 * Initialization of interface. 390 */ 391 qeinit(unit) 392 int unit; 393 { 394 register struct qe_softc *sc = &qe_softc[unit]; 395 register struct uba_device *ui = qeinfo[unit]; 396 register struct qedevice *addr = (struct qedevice *)ui->ui_addr; 397 register struct ifnet *ifp = &sc->qe_if; 398 register i; 399 int s; 400 401 /* address not known */ 402 if (ifp->if_addrlist == (struct ifaddr *)0) 403 return; 404 if (sc->qe_flags & QEF_RUNNING) 405 return; 406 407 if ((ifp->if_flags & IFF_RUNNING) == 0) { 408 /* 409 * map the communications area onto the device 410 */ 411 i = uballoc(0, (caddr_t)sc->rring, 412 sizeof(struct qe_ring) * (NTOT+2), 0); 413 if (i == 0) 414 goto fail; 415 sc->rringaddr = (struct qe_ring *)UBAI_ADDR(i); 416 sc->tringaddr = sc->rringaddr + NRCV + 1; 417 i = uballoc(0, (caddr_t)sc->setup_pkt, 418 sizeof(sc->setup_pkt), 0); 419 if (i == 0) 420 goto fail; 421 sc->setupaddr = UBAI_ADDR(i); 422 /* 423 * init buffers and maps 424 */ 425 if (if_ubaminit(&sc->qe_uba, ui->ui_ubanum, 426 sizeof (struct ether_header), (int)btoc(MAXPACKETSIZE), 427 sc->qe_ifr, NRCV, sc->qe_ifw, NXMT) == 0) { 428 fail: 429 printf("qe%d: can't allocate uba resources\n", unit); 430 sc->qe_if.if_flags &= ~IFF_UP; 431 return; 432 } 433 } 434 /* 435 * Init the buffer descriptors and indexes for each of the lists and 436 * loop them back to form a ring. 437 */ 438 for (i = 0; i < NRCV; i++) { 439 qeinitdesc( &sc->rring[i], 440 (caddr_t)UBAI_ADDR(sc->qe_ifr[i].ifrw_info), MAXPACKETSIZE); 441 sc->rring[i].qe_flag = sc->rring[i].qe_status1 = QE_NOTYET; 442 sc->rring[i].qe_valid = 1; 443 } 444 qeinitdesc(&sc->rring[i], (caddr_t)NULL, 0); 445 446 sc->rring[i].qe_addr_lo = (short)sc->rringaddr; 447 sc->rring[i].qe_addr_hi = (short)((int)sc->rringaddr >> 16); 448 sc->rring[i].qe_chain = 1; 449 sc->rring[i].qe_flag = sc->rring[i].qe_status1 = QE_NOTYET; 450 sc->rring[i].qe_valid = 1; 451 452 for( i = 0 ; i <= NXMT ; i++ ) 453 qeinitdesc(&sc->tring[i], (caddr_t)NULL, 0); 454 i--; 455 456 sc->tring[i].qe_addr_lo = (short)sc->tringaddr; 457 sc->tring[i].qe_addr_hi = (short)((int)sc->tringaddr >> 16); 458 sc->tring[i].qe_chain = 1; 459 sc->tring[i].qe_flag = sc->tring[i].qe_status1 = QE_NOTYET; 460 sc->tring[i].qe_valid = 1; 461 462 sc->nxmit = sc->otindex = sc->tindex = sc->rindex = 0; 463 464 /* 465 * Take the interface out of reset, program the vector, 466 * enable interrupts, and tell the world we are up. 467 */ 468 s = splimp(); 469 addr->qe_vector = sc->qe_intvec; 470 sc->addr = addr; 471 addr->qe_csr = QE_RCV_ENABLE | QE_INT_ENABLE | QE_XMIT_INT | 472 QE_RCV_INT | QE_ILOOP; 473 addr->qe_rcvlist_lo = (short)sc->rringaddr; 474 addr->qe_rcvlist_hi = (short)((int)sc->rringaddr >> 16); 475 ifp->if_flags |= IFF_UP | IFF_RUNNING; 476 sc->qe_flags |= QEF_RUNNING; 477 qesetup( sc ); 478 (void) qestart( ifp ); 479 sc->qe_if.if_timer = QESLOWTIMEOUT; /* Start watchdog */ 480 splx( s ); 481 } 482 483 /* 484 * Start output on interface. 485 * 486 */ 487 qestart(ifp) 488 struct ifnet *ifp; 489 { 490 int unit = ifp->if_unit; 491 struct uba_device *ui = qeinfo[unit]; 492 register struct qe_softc *sc = &qe_softc[unit]; 493 register struct qedevice *addr; 494 register struct qe_ring *rp; 495 register index; 496 struct mbuf *m; 497 int buf_addr, len, s; 498 499 500 s = splimp(); 501 addr = (struct qedevice *)ui->ui_addr; 502 /* 503 * The deqna doesn't look at anything but the valid bit 504 * to determine if it should transmit this packet. If you have 505 * a ring and fill it the device will loop indefinately on the 506 * packet and continue to flood the net with packets until you 507 * break the ring. For this reason we never queue more than n-1 508 * packets in the transmit ring. 509 * 510 * The microcoders should have obeyed their own defination of the 511 * flag and status words, but instead we have to compensate. 512 */ 513 for( index = sc->tindex; 514 sc->tring[index].qe_valid == 0 && sc->nxmit < (NXMT-1) ; 515 sc->tindex = index = ++index % NXMT){ 516 rp = &sc->tring[index]; 517 if( sc->setupqueued ) { 518 buf_addr = sc->setupaddr; 519 len = 128; 520 rp->qe_setup = 1; 521 sc->setupqueued = 0; 522 } else { 523 IF_DEQUEUE(&sc->qe_if.if_snd, m); 524 if( m == 0 ){ 525 splx(s); 526 return (0); 527 } 528 buf_addr = sc->qe_ifw[index].ifw_info; 529 len = if_ubaput(&sc->qe_uba, &sc->qe_ifw[index], m); 530 } 531 /* 532 * Does buffer end on odd byte ? 533 */ 534 if( len & 1 ) { 535 len++; 536 rp->qe_odd_end = 1; 537 } 538 if( len < MINDATA ) 539 len = MINDATA; 540 rp->qe_buf_len = -(len/2); 541 buf_addr = UBAI_ADDR(buf_addr); 542 rp->qe_flag = rp->qe_status1 = QE_NOTYET; 543 rp->qe_addr_lo = (short)buf_addr; 544 rp->qe_addr_hi = (short)(buf_addr >> 16); 545 rp->qe_eomsg = 1; 546 rp->qe_flag = rp->qe_status1 = QE_NOTYET; 547 rp->qe_valid = 1; 548 if (sc->nxmit++ == 0) { 549 sc->qe_flags |= QEF_FASTTIMEO; 550 sc->qe_if.if_timer = QETIMEOUT; 551 } 552 553 /* 554 * See if the xmit list is invalid. 555 */ 556 if( addr->qe_csr & QE_XL_INVALID ) { 557 buf_addr = (int)(sc->tringaddr+index); 558 addr->qe_xmtlist_lo = (short)buf_addr; 559 addr->qe_xmtlist_hi = (short)(buf_addr >> 16); 560 } 561 } 562 splx( s ); 563 return (0); 564 } 565 566 /* 567 * Ethernet interface interrupt processor 568 */ 569 qeintr(unit) 570 int unit; 571 { 572 register struct qe_softc *sc = &qe_softc[unit]; 573 struct qedevice *addr = (struct qedevice *)qeinfo[unit]->ui_addr; 574 int buf_addr, csr; 575 576 #ifdef notdef 577 splx(sc->ipl); 578 #else 579 (void) splimp(); 580 #endif 581 if (!(sc->qe_flags & QEF_FASTTIMEO)) 582 sc->qe_if.if_timer = QESLOWTIMEOUT; /* Restart timer clock */ 583 csr = addr->qe_csr; 584 addr->qe_csr = QE_RCV_ENABLE | QE_INT_ENABLE | QE_XMIT_INT | QE_RCV_INT | QE_ILOOP; 585 if( csr & QE_RCV_INT ) 586 qerint( unit ); 587 if( csr & QE_XMIT_INT ) 588 qetint( unit ); 589 if( csr & QE_NEX_MEM_INT ) 590 printf("qe%d: Nonexistent memory interrupt\n", unit); 591 592 if( addr->qe_csr & QE_RL_INVALID && sc->rring[sc->rindex].qe_status1 == QE_NOTYET ) { 593 buf_addr = (int)&sc->rringaddr[sc->rindex]; 594 addr->qe_rcvlist_lo = (short)buf_addr; 595 addr->qe_rcvlist_hi = (short)(buf_addr >> 16); 596 } 597 } 598 599 /* 600 * Ethernet interface transmit interrupt. 601 */ 602 603 qetint(unit) 604 int unit; 605 { 606 register struct qe_softc *sc = &qe_softc[unit]; 607 register struct qe_ring *rp; 608 register struct ifxmt *ifxp; 609 int status1, setupflag; 610 short len; 611 612 613 while( sc->otindex != sc->tindex && sc->tring[sc->otindex].qe_status1 != QE_NOTYET && sc->nxmit > 0 ) { 614 /* 615 * Save the status words from the descriptor so that it can 616 * be released. 617 */ 618 rp = &sc->tring[sc->otindex]; 619 status1 = rp->qe_status1; 620 setupflag = rp->qe_setup; 621 len = (-rp->qe_buf_len) * 2; 622 if( rp->qe_odd_end ) 623 len++; 624 /* 625 * Init the buffer descriptor 626 */ 627 bzero((caddr_t)rp, sizeof(struct qe_ring)); 628 if( --sc->nxmit == 0 ) { 629 sc->qe_flags &= ~QEF_FASTTIMEO; 630 sc->qe_if.if_timer = QESLOWTIMEOUT; 631 } 632 if( !setupflag ) { 633 /* 634 * Do some statistics. 635 */ 636 sc->qe_if.if_opackets++; 637 sc->qe_if.if_collisions += ( status1 & QE_CCNT ) >> 4; 638 if (status1 & QE_ERROR) 639 sc->qe_if.if_oerrors++; 640 /* 641 * If this was a broadcast packet loop it 642 * back because the hardware can't hear its own 643 * transmits. 644 */ 645 ifxp = &sc->qe_ifw[sc->otindex]; 646 if (bcmp((caddr_t)((struct ether_header *)ifxp->ifw_addr)->ether_dhost, 647 (caddr_t)etherbroadcastaddr, 648 sizeof(etherbroadcastaddr)) == 0) 649 qeread(sc, &ifxp->ifrw, 650 len - sizeof(struct ether_header)); 651 if (ifxp->ifw_xtofree) { 652 m_freem(ifxp->ifw_xtofree); 653 ifxp->ifw_xtofree = 0; 654 } 655 } 656 sc->otindex = ++sc->otindex % NXMT; 657 } 658 (void) qestart( &sc->qe_if ); 659 } 660 661 /* 662 * Ethernet interface receiver interrupt. 663 * If can't determine length from type, then have to drop packet. 664 * Othewise decapsulate packet based on type and pass to type specific 665 * higher-level input routine. 666 */ 667 qerint(unit) 668 int unit; 669 { 670 register struct qe_softc *sc = &qe_softc[unit]; 671 register struct qe_ring *rp; 672 int len, status1, status2; 673 int bufaddr; 674 675 /* 676 * Traverse the receive ring looking for packets to pass back. 677 * The search is complete when we find a descriptor not in use. 678 * 679 * As in the transmit case the deqna doesn't honor it's own protocols 680 * so there exists the possibility that the device can beat us around 681 * the ring. The proper way to guard against this is to insure that 682 * there is always at least one invalid descriptor. We chose instead 683 * to make the ring large enough to minimize the problem. With a ring 684 * size of 4 we haven't been able to see the problem. To be safe we 685 * doubled that to 8. 686 * 687 */ 688 for( ; sc->rring[sc->rindex].qe_status1 != QE_NOTYET ; sc->rindex = ++sc->rindex % NRCV ){ 689 rp = &sc->rring[sc->rindex]; 690 status1 = rp->qe_status1; 691 status2 = rp->qe_status2; 692 bzero((caddr_t)rp, sizeof(struct qe_ring)); 693 if( (status1 & QE_MASK) == QE_MASK ) 694 panic("qe: chained packet"); 695 len = ((status1 & QE_RBL_HI) | (status2 & QE_RBL_LO)) + 60; 696 sc->qe_if.if_ipackets++; 697 698 if (status1 & QE_ERROR) { 699 if ((status1 & QE_RUNT) == 0) 700 sc->qe_if.if_ierrors++; 701 } else { 702 /* 703 * We don't process setup packets. 704 */ 705 if( !(status1 & QE_ESETUP) ) 706 qeread(sc, &sc->qe_ifr[sc->rindex], 707 len - sizeof(struct ether_header)); 708 } 709 /* 710 * Return the buffer to the ring 711 */ 712 bufaddr = (int)UBAI_ADDR(sc->qe_ifr[sc->rindex].ifrw_info); 713 rp->qe_buf_len = -((MAXPACKETSIZE)/2); 714 rp->qe_addr_lo = (short)bufaddr; 715 rp->qe_addr_hi = (short)((int)bufaddr >> 16); 716 rp->qe_flag = rp->qe_status1 = QE_NOTYET; 717 rp->qe_valid = 1; 718 } 719 } 720 721 /* 722 * Process an ioctl request. 723 */ 724 qeioctl(ifp, cmd, data) 725 register struct ifnet *ifp; 726 int cmd; 727 caddr_t data; 728 { 729 struct qe_softc *sc = &qe_softc[ifp->if_unit]; 730 struct ifaddr *ifa = (struct ifaddr *)data; 731 int s = splimp(), error = 0; 732 733 switch (cmd) { 734 735 case SIOCSIFADDR: 736 ifp->if_flags |= IFF_UP; 737 qeinit(ifp->if_unit); 738 switch(ifa->ifa_addr->sa_family) { 739 #ifdef INET 740 case AF_INET: 741 ((struct arpcom *)ifp)->ac_ipaddr = 742 IA_SIN(ifa)->sin_addr; 743 arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr); 744 break; 745 #endif 746 #ifdef NS 747 case AF_NS: 748 { 749 register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 750 751 if (ns_nullhost(*ina)) 752 ina->x_host = *(union ns_host *)(sc->qe_addr); 753 else 754 qe_setaddr(ina->x_host.c_host, ifp->if_unit); 755 break; 756 } 757 #endif 758 } 759 break; 760 761 case SIOCSIFFLAGS: 762 if ((ifp->if_flags & IFF_UP) == 0 && 763 sc->qe_flags & QEF_RUNNING) { 764 ((struct qedevice *) 765 (qeinfo[ifp->if_unit]->ui_addr))->qe_csr = QE_RESET; 766 sc->qe_flags &= ~QEF_RUNNING; 767 } else if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) == 768 IFF_RUNNING && (sc->qe_flags & QEF_RUNNING) == 0) 769 qerestart(sc); 770 break; 771 772 default: 773 error = EINVAL; 774 775 } 776 splx(s); 777 return (error); 778 } 779 780 /* 781 * set ethernet address for unit 782 */ 783 qe_setaddr(physaddr, unit) 784 u_char *physaddr; 785 int unit; 786 { 787 register struct qe_softc *sc = &qe_softc[unit]; 788 register int i; 789 790 for (i = 0; i < 6; i++) 791 sc->setup_pkt[i][1] = sc->qe_addr[i] = physaddr[i]; 792 sc->qe_flags |= QEF_SETADDR; 793 if (sc->qe_if.if_flags & IFF_RUNNING) 794 qesetup(sc); 795 qeinit(unit); 796 } 797 798 799 /* 800 * Initialize a ring descriptor with mbuf allocation side effects 801 */ 802 qeinitdesc(rp, addr, len) 803 register struct qe_ring *rp; 804 caddr_t addr; /* mapped address */ 805 int len; 806 { 807 /* 808 * clear the entire descriptor 809 */ 810 bzero((caddr_t)rp, sizeof(struct qe_ring)); 811 812 if( len ) { 813 rp->qe_buf_len = -(len/2); 814 rp->qe_addr_lo = (short)addr; 815 rp->qe_addr_hi = (short)((int)addr >> 16); 816 } 817 } 818 /* 819 * Build a setup packet - the physical address will already be present 820 * in first column. 821 */ 822 qesetup( sc ) 823 struct qe_softc *sc; 824 { 825 register i, j; 826 827 /* 828 * Copy the target address to the rest of the entries in this row. 829 */ 830 for ( j = 0; j < 6 ; j++ ) 831 for ( i = 2 ; i < 8 ; i++ ) 832 sc->setup_pkt[j][i] = sc->setup_pkt[j][1]; 833 /* 834 * Duplicate the first half. 835 */ 836 bcopy((caddr_t)sc->setup_pkt[0], (caddr_t)sc->setup_pkt[8], 64); 837 /* 838 * Fill in the broadcast (and ISO multicast) address(es). 839 */ 840 for ( i = 0; i < 6 ; i++ ) { 841 sc->setup_pkt[i][2] = 0xff; 842 #ifdef ISO 843 sc->setup_pkt[i][3] = all_es.sc_snpa[i]; 844 sc->setup_pkt[i][4] = all_is.sc_snpa[i]; 845 #endif 846 } 847 sc->setupqueued++; 848 } 849 850 /* 851 * Pass a packet to the higher levels. 852 * We deal with the trailer protocol here. 853 */ 854 qeread(sc, ifrw, len) 855 register struct qe_softc *sc; 856 struct ifrw *ifrw; 857 int len; 858 { 859 struct ether_header *eh; 860 struct mbuf *m; 861 int off, resid, s; 862 struct ifqueue *inq; 863 864 /* 865 * Deal with trailer protocol: if type is INET trailer 866 * get true type from first 16-bit word past data. 867 * Remember that type was trailer by setting off. 868 */ 869 870 eh = (struct ether_header *)ifrw->ifrw_addr; 871 eh->ether_type = ntohs((u_short)eh->ether_type); 872 #define qedataaddr(eh, off, type) ((type)(((caddr_t)((eh)+1)+(off)))) 873 if (eh->ether_type >= ETHERTYPE_TRAIL && 874 eh->ether_type < ETHERTYPE_TRAIL+ETHERTYPE_NTRAILER) { 875 off = (eh->ether_type - ETHERTYPE_TRAIL) * 512; 876 if (off >= ETHERMTU) 877 return; /* sanity */ 878 eh->ether_type = ntohs(*qedataaddr(eh,off, u_short *)); 879 resid = ntohs(*(qedataaddr(eh, off+2, u_short *))); 880 if (off + resid > len) 881 return; /* sanity */ 882 len = off + resid; 883 } else 884 off = 0; 885 if (len == 0) 886 return; 887 888 /* 889 * Pull packet off interface. Off is nonzero if packet 890 * has trailing header; qeget will then force this header 891 * information to be at the front, but we still have to drop 892 * the type and length which are at the front of any trailer data. 893 */ 894 m = if_ubaget(&sc->qe_uba, ifrw, len, off, &sc->qe_if); 895 896 if (m) 897 ether_input(&sc->qe_if, eh, m); 898 } 899 900 /* 901 * Watchdog timeout routine. There is a condition in the hardware that 902 * causes the board to lock up under heavy load. This routine detects 903 * the hang up and restarts the device. 904 */ 905 qetimeout(unit) 906 int unit; 907 { 908 register struct qe_softc *sc; 909 910 sc = &qe_softc[unit]; 911 #ifdef notdef 912 log(LOG_ERR, "qe%d: transmit timeout, restarted %d\n", 913 unit, sc->qe_restarts++); 914 #endif 915 qerestart(sc); 916 } 917 /* 918 * Restart for board lockup problem. 919 */ 920 qerestart(sc) 921 register struct qe_softc *sc; 922 { 923 register struct ifnet *ifp = &sc->qe_if; 924 register struct qedevice *addr = sc->addr; 925 register struct qe_ring *rp; 926 register i; 927 928 addr->qe_csr = QE_RESET; 929 addr->qe_csr &= ~QE_RESET; 930 qesetup( sc ); 931 for (i = 0, rp = sc->tring; i < NXMT; rp++, i++) { 932 rp->qe_flag = rp->qe_status1 = QE_NOTYET; 933 rp->qe_valid = 0; 934 } 935 sc->nxmit = sc->otindex = sc->tindex = sc->rindex = 0; 936 addr->qe_csr = QE_RCV_ENABLE | QE_INT_ENABLE | QE_XMIT_INT | 937 QE_RCV_INT | QE_ILOOP; 938 addr->qe_rcvlist_lo = (short)sc->rringaddr; 939 addr->qe_rcvlist_hi = (short)((int)sc->rringaddr >> 16); 940 sc->qe_flags |= QEF_RUNNING; 941 (void) qestart(ifp); 942 } 943 #endif 944