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