1 /* $NetBSD: if_qt.c,v 1.18 2010/04/05 07:21:47 joerg Exp $ */ 2 /* 3 * Copyright (c) 1992 Steven M. Schultz 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * @(#)if_qt.c 1.2 (2.11BSD) 2/20/93 29 */ 30 /* 31 * 32 * Modification History 33 * 23-Feb-92 -- sms 34 * Rewrite the buffer handling so that fewer than the maximum number of 35 * buffers may be used (32 receive and 12 transmit buffers consume 66+kb 36 * of main system memory in addition to the internal structures in the 37 * networking code). A freelist of available buffers is maintained now. 38 * When I/O operations complete the associated buffer is placed on the 39 * freelist (a single linked list for simplicity) and when an I/O is 40 * started a buffer is pulled off the list. 41 * 42 * 20-Feb-92 -- sms 43 * It works! Darned board couldn't handle "short" rings - those rings 44 * where only half the entries were made available to the board (the 45 * ring descriptors were the full size, merely half the entries were 46 * flagged as belonging always to the driver). Grrrr. Would have thought 47 * the board could skip over those entries reserved by the driver. 48 * Now to find a way not to have to allocated 32+12 times 1.5kb worth of 49 * buffers... 50 * 51 * 03-Feb-92 -- sms 52 * Released but still not working. The driver now responds to arp and 53 * ping requests. The board is apparently not returning ring descriptors 54 * to the driver so eventually we run out of buffers. Back to the 55 * drawing board. 56 * 57 * 28-Dec-92 -- sms 58 * Still not released. Hiatus in finding free time and thin-netting 59 * the systems (many thanks Terry!). 60 * Added logic to dynamically allocate a vector and initialize it. 61 * 62 * 23-Oct-92 -- sms 63 * The INIT block must (apparently) be quadword aligned [no thanks to 64 * the manual for not mentioning that fact]. The necessary alignment 65 * is achieved by allocating the INIT block from main memory ('malloc' 66 * guarantees click alignment) and mapping it as needed (which is _very_ 67 * infrequently). A check for quadword alignment of the ring descriptors 68 * was added - at present the descriptors are properly aligned, if this 69 * should change then something will have to be done (like do it "right"). 70 * Darned alignment restrictions! 71 * 72 * A couple of typos were corrected (missing parentheses, reversed 73 * arguments to printf calls, etc). 74 * 75 * 13-Oct-92 -- sms@wlv.iipo.gtegsc.com 76 * Created based on the DELQA-PLUS addendum to DELQA User's Guide. 77 * This driver ('qt') is selected at system configuration time. If the 78 * board * is not a DELQA-YM an error message will be printed and the 79 * interface will not be attached. 80 */ 81 82 #include <sys/cdefs.h> 83 __KERNEL_RCSID(0, "$NetBSD: if_qt.c,v 1.18 2010/04/05 07:21:47 joerg Exp $"); 84 85 #include "opt_inet.h" 86 87 #include <sys/param.h> 88 #include <sys/systm.h> 89 #include <sys/mbuf.h> 90 #include <sys/protosw.h> 91 #include <sys/socket.h> 92 #include <sys/ioctl.h> 93 #include <sys/device.h> 94 #include <sys/errno.h> 95 #include <sys/syslog.h> 96 #include <sys/time.h> 97 #include <sys/kernel.h> 98 99 #include <net/if.h> 100 #include <net/if_ether.h> 101 #include <net/netisr.h> 102 #include <net/route.h> 103 104 #ifdef INET 105 #include <sys/domain.h> 106 #include <netinet/in.h> 107 #include <netinet/in_systm.h> 108 #include <netinet/in_var.h> 109 #include <netinet/ip.h> 110 #endif 111 112 #include <net/bpf.h> 113 #include <net/bpfdesc.h> 114 115 116 #include <sys/bus.h> 117 118 #include <dev/qbus/ubavar.h> 119 #include <dev/qbus/if_uba.h> 120 #include <dev/qbus/if_qtreg.h> 121 122 #define NRCV QT_MAX_RCV /* Receive descriptors (must be == 32) */ 123 #define NXMT QT_MAX_XMT /* Transmit descriptors (must be == 12) */ 124 #if NRCV != 32 || NXMT != 12 125 hardware requires these sizes. 126 #endif 127 128 /* 129 * Control data structures, must be in DMA-friendly memory. 130 */ 131 struct qt_cdata { 132 struct qt_init qc_init; /* Init block */ 133 struct qt_rring qc_r[NRCV]; /* Receive descriptor ring */ 134 struct qt_tring qc_t[NXMT]; /* Transmit descriptor ring */ 135 }; 136 137 struct qt_softc { 138 device_t sc_dev; /* Configuration common part */ 139 struct ethercom is_ec; /* common part - must be first */ 140 struct uba_softc *sc_uh; 141 struct evcnt sc_intrcnt; /* Interrupt counting */ 142 #define is_if is_ec.ec_if /* network-visible interface */ 143 u_int8_t is_addr[ETHER_ADDR_LEN]; /* hardware Ethernet address */ 144 bus_space_tag_t sc_iot; 145 bus_addr_t sc_ioh; 146 147 struct ubinfo sc_ui; /* control block address desc */ 148 struct qt_cdata *sc_ib; /* virt address of ctrl block */ 149 struct qt_cdata *sc_pib; /* phys address of ctrl block */ 150 151 struct ifubinfo sc_ifuba; /* UNIBUS resources */ 152 struct ifrw sc_ifr[NRCV]; /* UNIBUS receive buffer maps */ 153 struct ifxmt sc_ifw[NXMT]; /* UNIBUS receive buffer maps */ 154 155 int rindex; /* Receive Completed Index */ 156 int nxtrcv; /* Next Receive Index */ 157 int nrcv; /* Number of Receives active */ 158 159 int xnext; /* Next descriptor to transmit */ 160 int xlast; /* Last descriptor transmitted */ 161 int nxmit; /* # packets in send queue */ 162 163 short vector; /* Interrupt vector assigned */ 164 }; 165 166 static int qtmatch(device_t, cfdata_t, void *); 167 static void qtattach(device_t, device_t, void *); 168 static void qtintr(void *); 169 static int qtinit(struct ifnet *); 170 static int qtioctl(struct ifnet *, u_long, void *); 171 static int qtturbo(struct qt_softc *); 172 static void qtstart(struct ifnet *ifp); 173 static void qtstop(struct ifnet *ifp, int disable); 174 static void qtsrr(struct qt_softc *, int); 175 static void qtrint(struct qt_softc *sc); 176 static void qttint(struct qt_softc *sc); 177 178 /* static void qtrestart(struct qt_softc *sc); */ 179 180 CFATTACH_DECL_NEW(qt, sizeof(struct qt_softc), 181 qtmatch, qtattach, NULL, NULL); 182 183 /* 184 * Maximum packet size needs to include 4 bytes for the CRC 185 * on received packets. 186 */ 187 #define MAXPACKETSIZE (ETHERMTU + sizeof (struct ether_header) + 4) 188 #define MINPACKETSIZE 64 189 190 #define QT_WCSR(csr, val) \ 191 bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val) 192 #define QT_RCSR(csr) \ 193 bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr) 194 195 196 #define loint(x) ((int)(x) & 0xffff) 197 #define hiint(x) (((int)(x) >> 16) & 0x3f) 198 199 /* 200 * Check if this card is a turbo delqa. 201 */ 202 int 203 qtmatch(device_t parent, cfdata_t cf, void *aux) 204 { 205 struct qt_softc ssc; 206 struct qt_softc *sc = &ssc; 207 struct uba_attach_args *ua = aux; 208 struct uba_softc *uh = device_private(parent); 209 struct qt_init *qi; 210 struct ubinfo ui; 211 212 sc->sc_iot = ua->ua_iot; 213 sc->sc_ioh = ua->ua_ioh; 214 if (qtturbo(sc) == 0) 215 return 0; /* Not a turbo card */ 216 217 /* Force the card to interrupt */ 218 ui.ui_size = sizeof(struct qt_init); 219 if (ubmemalloc(uh, &ui, 0)) 220 return 0; /* Failed */ 221 qi = (struct qt_init *)ui.ui_vaddr; 222 memset(qi, 0, sizeof(struct qt_init)); 223 qi->vector = uh->uh_lastiv - 4; 224 qi->options = INIT_OPTIONS_INT; 225 226 QT_WCSR(CSR_IBAL, loint(ui.ui_baddr)); 227 QT_WCSR(CSR_IBAH, hiint(ui.ui_baddr)); 228 QT_WCSR(CSR_SRQR, 2); 229 delay(100000); /* Wait some time for interrupt */ 230 QT_WCSR(CSR_SRQR, 3); /* Stop card */ 231 232 ubmemfree(uh, &ui); 233 234 return 10; 235 } 236 237 238 /* 239 * Interface exists. More accurately, something exists at the CSR (see 240 * sys/sys_net.c) -- there's no guarantee it's a DELQA-YM. 241 * 242 * The ring descriptors are initialized, the buffers allocated using first the 243 * DMA region allocated at network load time and then later main memory. The 244 * INIT block is filled in and the device is poked/probed to see if it really 245 * is a DELQA-YM. If the device is not a -YM then a message is printed and 246 * the 'if_attach' call is skipped. For a -YM the START command is issued, 247 * but the device is not marked as running|up - that happens at interrupt level 248 * when the device interrupts to say it has started. 249 */ 250 251 void 252 qtattach(device_t parent, device_t self, void *aux) 253 { 254 struct qt_softc *sc = device_private(self); 255 struct ifnet *ifp = &sc->is_if; 256 struct uba_attach_args *ua = aux; 257 258 sc->sc_dev = self; 259 260 uba_intr_establish(ua->ua_icookie, ua->ua_cvec, qtintr, sc, 261 &sc->sc_intrcnt); 262 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt, 263 device_xname(sc->sc_dev), "intr"); 264 265 sc->sc_uh = device_private(parent); 266 sc->sc_iot = ua->ua_iot; 267 sc->sc_ioh = ua->ua_ioh; 268 sc->sc_uh->uh_lastiv -= 4; 269 sc->vector = sc->sc_uh->uh_lastiv; 270 271 /* 272 * Now allocate the buffers and initialize the buffers. This should _never_ 273 * fail because main memory is allocated after the DMA pool is used up. 274 */ 275 276 sc->is_addr[0] = QT_RCSR(0); 277 sc->is_addr[1] = QT_RCSR(2); 278 sc->is_addr[2] = QT_RCSR(4); 279 sc->is_addr[3] = QT_RCSR(6); 280 sc->is_addr[4] = QT_RCSR(8); 281 sc->is_addr[5] = QT_RCSR(10); 282 283 strcpy(ifp->if_xname, device_xname(sc->sc_dev)); 284 ifp->if_softc = sc; 285 ifp->if_flags = IFF_BROADCAST|IFF_MULTICAST; 286 ifp->if_ioctl = qtioctl; 287 ifp->if_start = qtstart; 288 ifp->if_init = qtinit; 289 ifp->if_stop = qtstop; 290 IFQ_SET_READY(&ifp->if_snd); 291 292 printf("\n%s: delqa-plus in Turbo mode, hardware address %s\n", 293 device_xname(sc->sc_dev), ether_sprintf(sc->is_addr)); 294 if_attach(ifp); 295 ether_ifattach(ifp, sc->is_addr); 296 } 297 298 int 299 qtturbo(struct qt_softc *sc) 300 { 301 int i; 302 303 /* 304 * Issue the software reset. Delay 150us. The board should now be in 305 * DELQA-Normal mode. Set ITB and DEQTA select. If both bits do not 306 * stay turned on then the board is not a DELQA-YM. 307 */ 308 QT_WCSR(CSR_ARQR, ARQR_SR); 309 QT_WCSR(CSR_ARQR, 0); 310 delay(150L); 311 312 QT_WCSR(CSR_SRR, 0x8001); /* MS | ITB */ 313 i = QT_RCSR(CSR_SRR); 314 QT_WCSR(CSR_SRR, 0x8000); /* Turn off ITB, set DELQA select */ 315 if (i != 0x8001) 316 return(0); 317 /* 318 * Board is a DELQA-YM. Send the commands to enable Turbo mode. Delay 319 * 1 second, testing the SRR register every millisecond to see if the 320 * board has shifted to Turbo mode. 321 */ 322 QT_WCSR(CSR_XCR0, 0x0baf); 323 QT_WCSR(CSR_XCR1, 0xff00); 324 for (i = 0; i < 1000; i++) 325 { 326 if ((QT_RCSR(CSR_SRR) & SRR_RESP) == 1) 327 break; 328 delay(1000L); 329 } 330 if (i >= 1000) 331 { 332 printf("qt !Turbo\n"); 333 return(0); 334 } 335 return(1); 336 } 337 338 int 339 qtinit(struct ifnet *ifp) 340 { 341 struct qt_softc *sc = ifp->if_softc; 342 struct qt_init *iniblk; 343 struct ifrw *ifrw; 344 struct ifxmt *ifxp; 345 struct qt_rring *rp; 346 struct qt_tring *tp; 347 int i, error; 348 349 if (ifp->if_flags & IFF_RUNNING) { 350 /* Cancel any pending I/O. */ 351 qtstop(ifp, 0); 352 } 353 354 if (sc->sc_ib == NULL) { 355 if (if_ubaminit(&sc->sc_ifuba, sc->sc_uh, 356 MCLBYTES, sc->sc_ifr, NRCV, sc->sc_ifw, NXMT)) { 357 printf("%s: can't initialize\n", device_xname(sc->sc_dev)); 358 ifp->if_flags &= ~IFF_UP; 359 return 0; 360 } 361 sc->sc_ui.ui_size = sizeof(struct qt_cdata); 362 if ((error = ubmemalloc(sc->sc_uh, &sc->sc_ui, 0))) { 363 printf(": failed ubmemalloc(), error = %d\n", error); 364 return error; 365 } 366 sc->sc_ib = (struct qt_cdata *)sc->sc_ui.ui_vaddr; 367 sc->sc_pib = (struct qt_cdata *)sc->sc_ui.ui_baddr; 368 369 /* 370 * Fill in most of the INIT block: vector, options (interrupt enable), ring 371 * locations. The physical address is copied from the ROMs as part of the 372 * -YM testing proceedure. The CSR is saved here rather than in qtinit() 373 * because the qtturbo() routine needs it. 374 * 375 * The INIT block must be quadword aligned. Using malloc() guarantees click 376 * (64 byte) alignment. Since the only time the INIT block is referenced is 377 * at 'startup' or 'reset' time there is really no time penalty (and a modest 378 * D space savings) involved. 379 */ 380 memset(sc->sc_ib, 0, sizeof(struct qt_cdata)); 381 iniblk = &sc->sc_ib->qc_init; 382 383 iniblk->vector = sc->vector; 384 memcpy(iniblk->paddr, sc->is_addr, 6); 385 386 iniblk->options = INIT_OPTIONS_INT; 387 iniblk->rx_lo = loint(&sc->sc_pib->qc_r); 388 iniblk->rx_hi = hiint(&sc->sc_pib->qc_r); 389 iniblk->tx_lo = loint(&sc->sc_pib->qc_t); 390 iniblk->tx_hi = hiint(&sc->sc_pib->qc_t); 391 } 392 iniblk = &sc->sc_ib->qc_init; 393 iniblk->mode = ifp->if_flags & IFF_PROMISC ? INIT_MODE_PRO : 0; 394 395 396 /* 397 * Now initialize the receive ring descriptors. Because this routine can be 398 * called with outstanding I/O operations we check the ring descriptors for 399 * a non-zero 'rhost0' (or 'thost0') word and place those buffers back on 400 * the free list. 401 */ 402 for (i = 0; i < NRCV; i++) { 403 rp = &sc->sc_ib->qc_r[i]; 404 ifrw = &sc->sc_ifr[i]; 405 rp->rmd1 = MCLBYTES; 406 rp->rmd4 = loint(ifrw->ifrw_info); 407 rp->rmd5 = hiint(ifrw->ifrw_info); 408 rp->rmd3 = 0; /* clear RMD3_OWN */ 409 } 410 for (i = 0; i < NXMT; i++) { 411 tp = &sc->sc_ib->qc_t[i]; 412 ifxp = &sc->sc_ifw[i]; 413 tp->tmd4 = loint(ifxp->ifw_info); 414 tp->tmd5 = hiint(ifxp->ifw_info); 415 tp->tmd3 = TMD3_OWN; 416 } 417 418 sc->xnext = sc->xlast = sc->nxmit = 0; 419 sc->rindex = 0; 420 sc->nxtrcv = 0; 421 sc->nrcv = 0; 422 423 /* 424 * Now we tell the device the address of the INIT block. The device 425 * _must_ be in the Turbo mode at this time. The "START" command is 426 * then issued to the device. A 1 second timeout is then started. 427 * When the interrupt occurs the IFF_UP|IFF_RUNNING state is entered and 428 * full operations will proceed. If the timeout expires without an interrupt 429 * being received an error is printed, the flags cleared and the device left 430 * marked down. 431 */ 432 QT_WCSR(CSR_IBAL, loint(&sc->sc_pib->qc_init)); 433 QT_WCSR(CSR_IBAH, hiint(&sc->sc_pib->qc_init)); 434 QT_WCSR(CSR_SRQR, 2); 435 436 sc->is_if.if_flags |= IFF_RUNNING; 437 return 0; 438 } 439 440 /* 441 * Start output on interface. 442 */ 443 444 void 445 qtstart(struct ifnet *ifp) 446 { 447 int len, nxmit; 448 struct qt_softc *sc = ifp->if_softc; 449 struct qt_tring *rp; 450 struct mbuf *m = NULL; 451 452 for (nxmit = sc->nxmit; nxmit < NXMT; nxmit++) { 453 IF_DEQUEUE(&sc->is_if.if_snd, m); 454 if (m == 0) 455 break; 456 457 rp = &sc->sc_ib->qc_t[sc->xnext]; 458 if ((rp->tmd3 & TMD3_OWN) == 0) 459 panic("qtstart"); 460 461 bpf_mtap(ifp, m); 462 463 len = if_ubaput(&sc->sc_ifuba, &sc->sc_ifw[sc->xnext], m); 464 if (len < MINPACKETSIZE) 465 len = MINPACKETSIZE; 466 rp->tmd3 = len & TMD3_BCT; /* set length,clear ownership */ 467 QT_WCSR(CSR_ARQR, ARQR_TRQ); /* tell device it has buffer */ 468 469 if (++sc->xnext >= NXMT) 470 sc->xnext = 0; 471 } 472 if (sc->nxmit != nxmit) 473 sc->nxmit = nxmit; 474 /* XXX - set OACTIVE */ 475 } 476 477 /* 478 * General interrupt service routine. Receive, transmit, device start 479 * interrupts and timeouts come here. Check for hard device errors and print a 480 * message if any errors are found. If we are waiting for the device to 481 * START then check if the device is now running. 482 */ 483 484 void 485 qtintr(void *arg) 486 { 487 struct qt_softc *sc = arg; 488 struct ifnet *ifp = &sc->is_if; 489 short status; 490 491 492 status = QT_RCSR(CSR_SRR); 493 if (status < 0) 494 /* should we reset the device after a bunch of these errs? */ 495 qtsrr(sc, status); 496 if ((ifp->if_flags & IFF_UP) == 0) 497 return; /* Unwanted interrupt */ 498 qtrint(sc); 499 qttint(sc); 500 qtstart(&sc->is_ec.ec_if); 501 } 502 503 /* 504 * Transmit interrupt service. Only called if there are outstanding transmit 505 * requests which could have completed. The DELQA-YM doesn't provide the 506 * status bits telling the kind (receive, transmit) of interrupt. 507 */ 508 509 #define BBLMIS (TMD2_BBL|TMD2_MIS) 510 511 void 512 qttint(struct qt_softc *sc) 513 { 514 struct qt_tring *rp; 515 516 while (sc->nxmit > 0) 517 { 518 rp = &sc->sc_ib->qc_t[sc->xlast]; 519 if ((rp->tmd3 & TMD3_OWN) == 0) 520 break; 521 sc->is_if.if_opackets++; 522 /* 523 * Collisions don't count as output errors, but babbling and missing packets 524 * do count as output errors. 525 */ 526 if (rp->tmd2 & TMD2_CER) 527 sc->is_if.if_collisions++; 528 if ((rp->tmd0 & TMD0_ERR1) || 529 ((rp->tmd2 & TMD2_ERR2) && (rp->tmd2 & BBLMIS))) 530 { 531 #ifdef QTDEBUG 532 char buf[100]; 533 snprintb(buf, sizeof(buf), TMD2_BITS, rp->tmd2); 534 printf("%s: tmd2 %s\n", device_xname(sc->sc_dev), buf); 535 #endif 536 sc->is_if.if_oerrors++; 537 } 538 if_ubaend(&sc->sc_ifuba, &sc->sc_ifw[sc->xlast]); 539 if (++sc->xlast >= NXMT) 540 sc->xlast = 0; 541 sc->nxmit--; 542 } 543 } 544 545 /* 546 * Receive interrupt service. Pull packet off the interface and put into 547 * a mbuf chain for processing later. 548 */ 549 550 void 551 qtrint(struct qt_softc *sc) 552 { 553 struct qt_rring *rp; 554 struct ifnet *ifp = &sc->is_ec.ec_if; 555 struct mbuf *m; 556 int len; 557 558 while (sc->sc_ib->qc_r[(int)sc->rindex].rmd3 & RMD3_OWN) 559 { 560 rp = &sc->sc_ib->qc_r[(int)sc->rindex]; 561 if ((rp->rmd0 & (RMD0_STP|RMD0_ENP)) != (RMD0_STP|RMD0_ENP)) 562 { 563 printf("%s: chained packet\n", device_xname(sc->sc_dev)); 564 sc->is_if.if_ierrors++; 565 goto rnext; 566 } 567 len = (rp->rmd1 & RMD1_MCNT) - 4; /* -4 for CRC */ 568 sc->is_if.if_ipackets++; 569 570 if ((rp->rmd0 & RMD0_ERR3) || (rp->rmd2 & RMD2_ERR4)) 571 { 572 #ifdef QTDEBUG 573 char buf[100]; 574 snprintb(buf, sizeof(buf), RMD0_BITS, rp->rmd0); 575 printf("%s: rmd0 %s\n", device_xname(sc->sc_dev), buf); 576 snprintb(buf, sizeof(buf), RMD2_BITS, rp->rmd2); 577 printf("%s: rmd2 %s\n", device_xname(sc->sc_dev), buf); 578 #endif 579 sc->is_if.if_ierrors++; 580 goto rnext; 581 } 582 m = if_ubaget(&sc->sc_ifuba, &sc->sc_ifr[(int)sc->rindex], 583 ifp, len); 584 if (m == 0) { 585 sc->is_if.if_ierrors++; 586 goto rnext; 587 } 588 bpf_mtap(ifp, m); 589 (*ifp->if_input)(ifp, m); 590 rnext: 591 --sc->nrcv; 592 rp->rmd3 = 0; 593 rp->rmd1 = MCLBYTES; 594 if (++sc->rindex >= NRCV) 595 sc->rindex = 0; 596 } 597 QT_WCSR(CSR_ARQR, ARQR_RRQ); /* tell device it has buffer */ 598 } 599 600 int 601 qtioctl(struct ifnet *ifp, u_long cmd, void *data) 602 { 603 int s, error; 604 605 s = splnet(); 606 607 error = ether_ioctl(ifp, cmd, data); 608 if (error == ENETRESET) { 609 if (ifp->if_flags & IFF_RUNNING) 610 error = qtinit(ifp); 611 else 612 error = 0; 613 } 614 splx(s); 615 return (error); 616 } 617 618 void 619 qtsrr(struct qt_softc *sc, int srrbits) 620 { 621 char buf[100]; 622 snprintb(buf, sizeof(buf), SRR_BITS, srrbits); 623 printf("%s: srr=%s\n", device_xname(sc->sc_dev), buf); 624 } 625 626 /* 627 * Stop activity on the interface. 628 * Lose outstanding transmit requests. XXX - not good for multicast. 629 */ 630 void 631 qtstop(struct ifnet *ifp, int disable) 632 { 633 struct qt_softc *sc = ifp->if_softc; 634 int i; 635 636 QT_WCSR(CSR_SRQR, 3); 637 for (i = 0; i < 100; i++) 638 if ((QT_RCSR(CSR_SRR) & SRR_RESP) == 3) 639 break; 640 if (QT_RCSR(CSR_SRR) & SRR_FES) 641 qtsrr(sc, QT_RCSR(CSR_SRR)); 642 /* Forget already queued transmit requests */ 643 while (sc->nxmit > 0) { 644 if_ubaend(&sc->sc_ifuba, &sc->sc_ifw[sc->xlast]); 645 if (++sc->xlast >= NXMT) 646 sc->xlast = 0; 647 sc->nxmit--; 648 } 649 /* Handle late received packets */ 650 qtrint(sc); 651 ifp->if_flags &= ~IFF_RUNNING; 652 } 653 654 #ifdef notyet 655 /* 656 * Reset the device. This moves it from DELQA-T mode to DELQA-Normal mode. 657 * After the reset put the device back in -T mode. Then call qtinit() to 658 * reinitialize the ring structures and issue the 'timeout' for the "device 659 * started interrupt". 660 */ 661 662 void 663 qtreset(sc) 664 struct qt_softc *sc; 665 { 666 667 qtturbo(sc); 668 qtinit(&sc->is_ec.ec_if); 669 } 670 #endif 671