if_qt.c revision 1.21.14.1 1 /* $NetBSD: if_qt.c,v 1.21.14.1 2018/06/25 07:26:01 pgoyette 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 (at) 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.21.14.1 2018/06/25 07:26:01 pgoyette 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 #include <net/bpf.h>
104
105 #ifdef INET
106 #include <sys/domain.h>
107 #include <netinet/in.h>
108 #include <netinet/in_systm.h>
109 #include <netinet/in_var.h>
110 #include <netinet/ip.h>
111 #endif
112
113 #include <sys/bus.h>
114
115 #include <dev/qbus/ubavar.h>
116 #include <dev/qbus/if_uba.h>
117 #include <dev/qbus/if_qtreg.h>
118
119 #define NRCV QT_MAX_RCV /* Receive descriptors (must be == 32) */
120 #define NXMT QT_MAX_XMT /* Transmit descriptors (must be == 12) */
121 #if NRCV != 32 || NXMT != 12
122 hardware requires these sizes.
123 #endif
124
125 /*
126 * Control data structures, must be in DMA-friendly memory.
127 */
128 struct qt_cdata {
129 struct qt_init qc_init; /* Init block */
130 struct qt_rring qc_r[NRCV]; /* Receive descriptor ring */
131 struct qt_tring qc_t[NXMT]; /* Transmit descriptor ring */
132 };
133
134 struct qt_softc {
135 device_t sc_dev; /* Configuration common part */
136 struct ethercom is_ec; /* common part - must be first */
137 struct uba_softc *sc_uh;
138 struct evcnt sc_intrcnt; /* Interrupt counting */
139 #define is_if is_ec.ec_if /* network-visible interface */
140 u_int8_t is_addr[ETHER_ADDR_LEN]; /* hardware Ethernet address */
141 bus_space_tag_t sc_iot;
142 bus_addr_t sc_ioh;
143
144 struct ubinfo sc_ui; /* control block address desc */
145 struct qt_cdata *sc_ib; /* virt address of ctrl block */
146 struct qt_cdata *sc_pib; /* phys address of ctrl block */
147
148 struct ifubinfo sc_ifuba; /* UNIBUS resources */
149 struct ifrw sc_ifr[NRCV]; /* UNIBUS receive buffer maps */
150 struct ifxmt sc_ifw[NXMT]; /* UNIBUS receive buffer maps */
151
152 int rindex; /* Receive Completed Index */
153 int nxtrcv; /* Next Receive Index */
154 int nrcv; /* Number of Receives active */
155
156 int xnext; /* Next descriptor to transmit */
157 int xlast; /* Last descriptor transmitted */
158 int nxmit; /* # packets in send queue */
159
160 short vector; /* Interrupt vector assigned */
161 };
162
163 static int qtmatch(device_t, cfdata_t, void *);
164 static void qtattach(device_t, device_t, void *);
165 static void qtintr(void *);
166 static int qtinit(struct ifnet *);
167 static int qtioctl(struct ifnet *, u_long, void *);
168 static int qtturbo(struct qt_softc *);
169 static void qtstart(struct ifnet *ifp);
170 static void qtstop(struct ifnet *ifp, int disable);
171 static void qtsrr(struct qt_softc *, int);
172 static void qtrint(struct qt_softc *sc);
173 static void qttint(struct qt_softc *sc);
174
175 /* static void qtrestart(struct qt_softc *sc); */
176
177 CFATTACH_DECL_NEW(qt, sizeof(struct qt_softc),
178 qtmatch, qtattach, NULL, NULL);
179
180 /*
181 * Maximum packet size needs to include 4 bytes for the CRC
182 * on received packets.
183 */
184 #define MAXPACKETSIZE (ETHERMTU + sizeof (struct ether_header) + 4)
185 #define MINPACKETSIZE 64
186
187 #define QT_WCSR(csr, val) \
188 bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
189 #define QT_RCSR(csr) \
190 bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
191
192
193 #define loint(x) ((int)(x) & 0xffff)
194 #define hiint(x) (((int)(x) >> 16) & 0x3f)
195
196 /*
197 * Check if this card is a turbo delqa.
198 */
199 int
200 qtmatch(device_t parent, cfdata_t cf, void *aux)
201 {
202 struct qt_softc ssc;
203 struct qt_softc *sc = &ssc;
204 struct uba_attach_args *ua = aux;
205 struct uba_softc *uh = device_private(parent);
206 struct qt_init *qi;
207 struct ubinfo ui;
208
209 sc->sc_iot = ua->ua_iot;
210 sc->sc_ioh = ua->ua_ioh;
211 if (qtturbo(sc) == 0)
212 return 0; /* Not a turbo card */
213
214 /* Force the card to interrupt */
215 ui.ui_size = sizeof(struct qt_init);
216 if (ubmemalloc(uh, &ui, 0))
217 return 0; /* Failed */
218 qi = (struct qt_init *)ui.ui_vaddr;
219 memset(qi, 0, sizeof(struct qt_init));
220 qi->vector = uh->uh_lastiv - 4;
221 qi->options = INIT_OPTIONS_INT;
222
223 QT_WCSR(CSR_IBAL, loint(ui.ui_baddr));
224 QT_WCSR(CSR_IBAH, hiint(ui.ui_baddr));
225 QT_WCSR(CSR_SRQR, 2);
226 delay(100000); /* Wait some time for interrupt */
227 QT_WCSR(CSR_SRQR, 3); /* Stop card */
228
229 ubmemfree(uh, &ui);
230
231 return 10;
232 }
233
234
235 /*
236 * Interface exists. More accurately, something exists at the CSR (see
237 * sys/sys_net.c) -- there's no guarantee it's a DELQA-YM.
238 *
239 * The ring descriptors are initialized, the buffers allocated using first the
240 * DMA region allocated at network load time and then later main memory. The
241 * INIT block is filled in and the device is poked/probed to see if it really
242 * is a DELQA-YM. If the device is not a -YM then a message is printed and
243 * the 'if_attach' call is skipped. For a -YM the START command is issued,
244 * but the device is not marked as running|up - that happens at interrupt level
245 * when the device interrupts to say it has started.
246 */
247
248 void
249 qtattach(device_t parent, device_t self, void *aux)
250 {
251 struct qt_softc *sc = device_private(self);
252 struct ifnet *ifp = &sc->is_if;
253 struct uba_attach_args *ua = aux;
254
255 sc->sc_dev = self;
256
257 uba_intr_establish(ua->ua_icookie, ua->ua_cvec, qtintr, sc,
258 &sc->sc_intrcnt);
259 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
260 device_xname(sc->sc_dev), "intr");
261
262 sc->sc_uh = device_private(parent);
263 sc->sc_iot = ua->ua_iot;
264 sc->sc_ioh = ua->ua_ioh;
265 sc->sc_uh->uh_lastiv -= 4;
266 sc->vector = sc->sc_uh->uh_lastiv;
267
268 /*
269 * Now allocate the buffers and initialize the buffers. This should _never_
270 * fail because main memory is allocated after the DMA pool is used up.
271 */
272
273 sc->is_addr[0] = QT_RCSR(0);
274 sc->is_addr[1] = QT_RCSR(2);
275 sc->is_addr[2] = QT_RCSR(4);
276 sc->is_addr[3] = QT_RCSR(6);
277 sc->is_addr[4] = QT_RCSR(8);
278 sc->is_addr[5] = QT_RCSR(10);
279
280 strcpy(ifp->if_xname, device_xname(sc->sc_dev));
281 ifp->if_softc = sc;
282 ifp->if_flags = IFF_BROADCAST|IFF_MULTICAST;
283 ifp->if_ioctl = qtioctl;
284 ifp->if_start = qtstart;
285 ifp->if_init = qtinit;
286 ifp->if_stop = qtstop;
287 IFQ_SET_READY(&ifp->if_snd);
288
289 printf("\n%s: delqa-plus in Turbo mode, hardware address %s\n",
290 device_xname(sc->sc_dev), ether_sprintf(sc->is_addr));
291 if_attach(ifp);
292 ether_ifattach(ifp, sc->is_addr);
293 }
294
295 int
296 qtturbo(struct qt_softc *sc)
297 {
298 int i;
299
300 /*
301 * Issue the software reset. Delay 150us. The board should now be in
302 * DELQA-Normal mode. Set ITB and DEQTA select. If both bits do not
303 * stay turned on then the board is not a DELQA-YM.
304 */
305 QT_WCSR(CSR_ARQR, ARQR_SR);
306 QT_WCSR(CSR_ARQR, 0);
307 delay(150L);
308
309 QT_WCSR(CSR_SRR, 0x8001); /* MS | ITB */
310 i = QT_RCSR(CSR_SRR);
311 QT_WCSR(CSR_SRR, 0x8000); /* Turn off ITB, set DELQA select */
312 if (i != 0x8001)
313 return(0);
314 /*
315 * Board is a DELQA-YM. Send the commands to enable Turbo mode. Delay
316 * 1 second, testing the SRR register every millisecond to see if the
317 * board has shifted to Turbo mode.
318 */
319 QT_WCSR(CSR_XCR0, 0x0baf);
320 QT_WCSR(CSR_XCR1, 0xff00);
321 for (i = 0; i < 1000; i++)
322 {
323 if ((QT_RCSR(CSR_SRR) & SRR_RESP) == 1)
324 break;
325 delay(1000L);
326 }
327 if (i >= 1000)
328 {
329 printf("qt !Turbo\n");
330 return(0);
331 }
332 return(1);
333 }
334
335 int
336 qtinit(struct ifnet *ifp)
337 {
338 struct qt_softc *sc = ifp->if_softc;
339 struct qt_init *iniblk;
340 struct ifrw *ifrw;
341 struct ifxmt *ifxp;
342 struct qt_rring *rp;
343 struct qt_tring *tp;
344 int i, error;
345
346 if (ifp->if_flags & IFF_RUNNING) {
347 /* Cancel any pending I/O. */
348 qtstop(ifp, 0);
349 }
350
351 if (sc->sc_ib == NULL) {
352 if (if_ubaminit(&sc->sc_ifuba, sc->sc_uh,
353 MCLBYTES, sc->sc_ifr, NRCV, sc->sc_ifw, NXMT)) {
354 printf("%s: can't initialize\n", device_xname(sc->sc_dev));
355 ifp->if_flags &= ~IFF_UP;
356 return 0;
357 }
358 sc->sc_ui.ui_size = sizeof(struct qt_cdata);
359 if ((error = ubmemalloc(sc->sc_uh, &sc->sc_ui, 0))) {
360 printf(": failed ubmemalloc(), error = %d\n", error);
361 return error;
362 }
363 sc->sc_ib = (struct qt_cdata *)sc->sc_ui.ui_vaddr;
364 sc->sc_pib = (struct qt_cdata *)sc->sc_ui.ui_baddr;
365
366 /*
367 * Fill in most of the INIT block: vector, options (interrupt enable), ring
368 * locations. The physical address is copied from the ROMs as part of the
369 * -YM testing procedure. The CSR is saved here rather than in qtinit()
370 * because the qtturbo() routine needs it.
371 *
372 * The INIT block must be quadword aligned. Using malloc() guarantees click
373 * (64 byte) alignment. Since the only time the INIT block is referenced is
374 * at 'startup' or 'reset' time there is really no time penalty (and a modest
375 * D space savings) involved.
376 */
377 memset(sc->sc_ib, 0, sizeof(struct qt_cdata));
378 iniblk = &sc->sc_ib->qc_init;
379
380 iniblk->vector = sc->vector;
381 memcpy(iniblk->paddr, sc->is_addr, 6);
382
383 iniblk->options = INIT_OPTIONS_INT;
384 iniblk->rx_lo = loint(&sc->sc_pib->qc_r);
385 iniblk->rx_hi = hiint(&sc->sc_pib->qc_r);
386 iniblk->tx_lo = loint(&sc->sc_pib->qc_t);
387 iniblk->tx_hi = hiint(&sc->sc_pib->qc_t);
388 }
389 iniblk = &sc->sc_ib->qc_init;
390 iniblk->mode = ifp->if_flags & IFF_PROMISC ? INIT_MODE_PRO : 0;
391
392
393 /*
394 * Now initialize the receive ring descriptors. Because this routine can be
395 * called with outstanding I/O operations we check the ring descriptors for
396 * a non-zero 'rhost0' (or 'thost0') word and place those buffers back on
397 * the free list.
398 */
399 for (i = 0; i < NRCV; i++) {
400 rp = &sc->sc_ib->qc_r[i];
401 ifrw = &sc->sc_ifr[i];
402 rp->rmd1 = MCLBYTES;
403 rp->rmd4 = loint(ifrw->ifrw_info);
404 rp->rmd5 = hiint(ifrw->ifrw_info);
405 rp->rmd3 = 0; /* clear RMD3_OWN */
406 }
407 for (i = 0; i < NXMT; i++) {
408 tp = &sc->sc_ib->qc_t[i];
409 ifxp = &sc->sc_ifw[i];
410 tp->tmd4 = loint(ifxp->ifw_info);
411 tp->tmd5 = hiint(ifxp->ifw_info);
412 tp->tmd3 = TMD3_OWN;
413 }
414
415 sc->xnext = sc->xlast = sc->nxmit = 0;
416 sc->rindex = 0;
417 sc->nxtrcv = 0;
418 sc->nrcv = 0;
419
420 /*
421 * Now we tell the device the address of the INIT block. The device
422 * _must_ be in the Turbo mode at this time. The "START" command is
423 * then issued to the device. A 1 second timeout is then started.
424 * When the interrupt occurs the IFF_UP|IFF_RUNNING state is entered and
425 * full operations will proceed. If the timeout expires without an interrupt
426 * being received an error is printed, the flags cleared and the device left
427 * marked down.
428 */
429 QT_WCSR(CSR_IBAL, loint(&sc->sc_pib->qc_init));
430 QT_WCSR(CSR_IBAH, hiint(&sc->sc_pib->qc_init));
431 QT_WCSR(CSR_SRQR, 2);
432
433 sc->is_if.if_flags |= IFF_RUNNING;
434 return 0;
435 }
436
437 /*
438 * Start output on interface.
439 */
440
441 void
442 qtstart(struct ifnet *ifp)
443 {
444 int len, nxmit;
445 struct qt_softc *sc = ifp->if_softc;
446 struct qt_tring *rp;
447 struct mbuf *m = NULL;
448
449 for (nxmit = sc->nxmit; nxmit < NXMT; nxmit++) {
450 IF_DEQUEUE(&sc->is_if.if_snd, m);
451 if (m == 0)
452 break;
453
454 rp = &sc->sc_ib->qc_t[sc->xnext];
455 if ((rp->tmd3 & TMD3_OWN) == 0)
456 panic("qtstart");
457
458 bpf_mtap(ifp, m);
459
460 len = if_ubaput(&sc->sc_ifuba, &sc->sc_ifw[sc->xnext], m);
461 if (len < MINPACKETSIZE)
462 len = MINPACKETSIZE;
463 rp->tmd3 = len & TMD3_BCT; /* set length,clear ownership */
464 QT_WCSR(CSR_ARQR, ARQR_TRQ); /* tell device it has buffer */
465
466 if (++sc->xnext >= NXMT)
467 sc->xnext = 0;
468 }
469 if (sc->nxmit != nxmit)
470 sc->nxmit = nxmit;
471 /* XXX - set OACTIVE */
472 }
473
474 /*
475 * General interrupt service routine. Receive, transmit, device start
476 * interrupts and timeouts come here. Check for hard device errors and print a
477 * message if any errors are found. If we are waiting for the device to
478 * START then check if the device is now running.
479 */
480
481 void
482 qtintr(void *arg)
483 {
484 struct qt_softc *sc = arg;
485 struct ifnet *ifp = &sc->is_if;
486 short status;
487
488
489 status = QT_RCSR(CSR_SRR);
490 if (status < 0)
491 /* should we reset the device after a bunch of these errs? */
492 qtsrr(sc, status);
493 if ((ifp->if_flags & IFF_UP) == 0)
494 return; /* Unwanted interrupt */
495 qtrint(sc);
496 qttint(sc);
497 qtstart(&sc->is_ec.ec_if);
498 }
499
500 /*
501 * Transmit interrupt service. Only called if there are outstanding transmit
502 * requests which could have completed. The DELQA-YM doesn't provide the
503 * status bits telling the kind (receive, transmit) of interrupt.
504 */
505
506 #define BBLMIS (TMD2_BBL|TMD2_MIS)
507
508 void
509 qttint(struct qt_softc *sc)
510 {
511 struct qt_tring *rp;
512
513 while (sc->nxmit > 0)
514 {
515 rp = &sc->sc_ib->qc_t[sc->xlast];
516 if ((rp->tmd3 & TMD3_OWN) == 0)
517 break;
518 sc->is_if.if_opackets++;
519 /*
520 * Collisions don't count as output errors, but babbling and missing packets
521 * do count as output errors.
522 */
523 if (rp->tmd2 & TMD2_CER)
524 sc->is_if.if_collisions++;
525 if ((rp->tmd0 & TMD0_ERR1) ||
526 ((rp->tmd2 & TMD2_ERR2) && (rp->tmd2 & BBLMIS)))
527 {
528 #ifdef QTDEBUG
529 char buf[100];
530 snprintb(buf, sizeof(buf), TMD2_BITS, rp->tmd2);
531 printf("%s: tmd2 %s\n", device_xname(sc->sc_dev), buf);
532 #endif
533 sc->is_if.if_oerrors++;
534 }
535 if_ubaend(&sc->sc_ifuba, &sc->sc_ifw[sc->xlast]);
536 if (++sc->xlast >= NXMT)
537 sc->xlast = 0;
538 sc->nxmit--;
539 }
540 }
541
542 /*
543 * Receive interrupt service. Pull packet off the interface and put into
544 * a mbuf chain for processing later.
545 */
546
547 void
548 qtrint(struct qt_softc *sc)
549 {
550 struct qt_rring *rp;
551 struct ifnet *ifp = &sc->is_ec.ec_if;
552 struct mbuf *m;
553 int len;
554
555 while (sc->sc_ib->qc_r[(int)sc->rindex].rmd3 & RMD3_OWN)
556 {
557 rp = &sc->sc_ib->qc_r[(int)sc->rindex];
558 if ((rp->rmd0 & (RMD0_STP|RMD0_ENP)) != (RMD0_STP|RMD0_ENP))
559 {
560 printf("%s: chained packet\n", device_xname(sc->sc_dev));
561 sc->is_if.if_ierrors++;
562 goto rnext;
563 }
564 len = (rp->rmd1 & RMD1_MCNT) - 4; /* -4 for CRC */
565 sc->is_if.if_ipackets++;
566
567 if ((rp->rmd0 & RMD0_ERR3) || (rp->rmd2 & RMD2_ERR4))
568 {
569 #ifdef QTDEBUG
570 char buf[100];
571 snprintb(buf, sizeof(buf), RMD0_BITS, rp->rmd0);
572 printf("%s: rmd0 %s\n", device_xname(sc->sc_dev), buf);
573 snprintb(buf, sizeof(buf), RMD2_BITS, rp->rmd2);
574 printf("%s: rmd2 %s\n", device_xname(sc->sc_dev), buf);
575 #endif
576 sc->is_if.if_ierrors++;
577 goto rnext;
578 }
579 m = if_ubaget(&sc->sc_ifuba, &sc->sc_ifr[(int)sc->rindex],
580 ifp, len);
581 if (m == 0) {
582 sc->is_if.if_ierrors++;
583 goto rnext;
584 }
585 if_percpuq_enqueue(ifp->if_percpuq, m);
586 rnext:
587 --sc->nrcv;
588 rp->rmd3 = 0;
589 rp->rmd1 = MCLBYTES;
590 if (++sc->rindex >= NRCV)
591 sc->rindex = 0;
592 }
593 QT_WCSR(CSR_ARQR, ARQR_RRQ); /* tell device it has buffer */
594 }
595
596 int
597 qtioctl(struct ifnet *ifp, u_long cmd, void *data)
598 {
599 int s, error;
600
601 s = splnet();
602
603 error = ether_ioctl(ifp, cmd, data);
604 if (error == ENETRESET) {
605 if (ifp->if_flags & IFF_RUNNING)
606 error = qtinit(ifp);
607 else
608 error = 0;
609 }
610 splx(s);
611 return (error);
612 }
613
614 void
615 qtsrr(struct qt_softc *sc, int srrbits)
616 {
617 char buf[100];
618 snprintb(buf, sizeof(buf), SRR_BITS, srrbits);
619 printf("%s: srr=%s\n", device_xname(sc->sc_dev), buf);
620 }
621
622 /*
623 * Stop activity on the interface.
624 * Lose outstanding transmit requests. XXX - not good for multicast.
625 */
626 void
627 qtstop(struct ifnet *ifp, int disable)
628 {
629 struct qt_softc *sc = ifp->if_softc;
630 int i;
631
632 QT_WCSR(CSR_SRQR, 3);
633 for (i = 0; i < 100; i++)
634 if ((QT_RCSR(CSR_SRR) & SRR_RESP) == 3)
635 break;
636 if (QT_RCSR(CSR_SRR) & SRR_FES)
637 qtsrr(sc, QT_RCSR(CSR_SRR));
638 /* Forget already queued transmit requests */
639 while (sc->nxmit > 0) {
640 if_ubaend(&sc->sc_ifuba, &sc->sc_ifw[sc->xlast]);
641 if (++sc->xlast >= NXMT)
642 sc->xlast = 0;
643 sc->nxmit--;
644 }
645 /* Handle late received packets */
646 qtrint(sc);
647 ifp->if_flags &= ~IFF_RUNNING;
648 }
649
650 #ifdef notyet
651 /*
652 * Reset the device. This moves it from DELQA-T mode to DELQA-Normal mode.
653 * After the reset put the device back in -T mode. Then call qtinit() to
654 * reinitialize the ring structures and issue the 'timeout' for the "device
655 * started interrupt".
656 */
657
658 void
659 qtreset(sc)
660 struct qt_softc *sc;
661 {
662
663 qtturbo(sc);
664 qtinit(&sc->is_ec.ec_if);
665 }
666 #endif
667