Home | History | Annotate | Line # | Download | only in usb
if_aue.c revision 1.59
      1 /*	$NetBSD: if_aue.c,v 1.59 2001/07/04 16:38:09 augustss Exp $	*/
      2 /*
      3  * Copyright (c) 1997, 1998, 1999, 2000
      4  *	Bill Paul <wpaul (at) ee.columbia.edu>.  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. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Bill Paul.
     17  * 4. Neither the name of the author nor the names of any co-contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31  * THE POSSIBILITY OF SUCH DAMAGE.
     32  *
     33  * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $
     34  */
     35 
     36 /*
     37  * ADMtek AN986 Pegasus USB to ethernet driver. Datasheet is available
     38  * from http://www.admtek.com.tw.
     39  *
     40  * Written by Bill Paul <wpaul (at) ee.columbia.edu>
     41  * Electrical Engineering Department
     42  * Columbia University, New York City
     43  */
     44 
     45 /*
     46  * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet
     47  * support: the control endpoint for reading/writing registers, burst
     48  * read endpoint for packet reception, burst write for packet transmission
     49  * and one for "interrupts." The chip uses the same RX filter scheme
     50  * as the other ADMtek ethernet parts: one perfect filter entry for the
     51  * the station address and a 64-bit multicast hash table. The chip supports
     52  * both MII and HomePNA attachments.
     53  *
     54  * Since the maximum data transfer speed of USB is supposed to be 12Mbps,
     55  * you're never really going to get 100Mbps speeds from this device. I
     56  * think the idea is to allow the device to connect to 10 or 100Mbps
     57  * networks, not necessarily to provide 100Mbps performance. Also, since
     58  * the controller uses an external PHY chip, it's possible that board
     59  * designers might simply choose a 10Mbps PHY.
     60  *
     61  * Registers are accessed using usbd_do_request(). Packet transfers are
     62  * done using usbd_transfer() and friends.
     63  */
     64 
     65 /*
     66  * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
     67  */
     68 
     69 /*
     70  * TODO:
     71  * better error messages from rxstat
     72  * split out if_auevar.h
     73  * add thread to avoid register reads from interrupt context
     74  * more error checks
     75  * investigate short rx problem
     76  * proper cleanup on errors
     77  */
     78 
     79 #if defined(__NetBSD__)
     80 #include "opt_inet.h"
     81 #include "opt_ns.h"
     82 #include "bpfilter.h"
     83 #include "rnd.h"
     84 #elif defined(__OpenBSD__)
     85 #include "bpfilter.h"
     86 #endif /* defined(__OpenBSD__) */
     87 
     88 #include <sys/param.h>
     89 #include <sys/systm.h>
     90 #include <sys/sockio.h>
     91 #include <sys/lock.h>
     92 #include <sys/mbuf.h>
     93 #include <sys/malloc.h>
     94 #include <sys/kernel.h>
     95 #include <sys/socket.h>
     96 
     97 #include <sys/device.h>
     98 #if NRND > 0
     99 #include <sys/rnd.h>
    100 #endif
    101 
    102 #include <net/if.h>
    103 #if defined(__NetBSD__)
    104 #include <net/if_arp.h>
    105 #endif
    106 #include <net/if_dl.h>
    107 #include <net/if_media.h>
    108 
    109 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
    110 
    111 #if NBPFILTER > 0
    112 #include <net/bpf.h>
    113 #endif
    114 
    115 #if defined(__NetBSD__)
    116 #include <net/if_ether.h>
    117 #ifdef INET
    118 #include <netinet/in.h>
    119 #include <netinet/if_inarp.h>
    120 #endif
    121 #endif /* defined(__NetBSD__) */
    122 
    123 #if defined(__OpenBSD__)
    124 #ifdef INET
    125 #include <netinet/in.h>
    126 #include <netinet/in_systm.h>
    127 #include <netinet/in_var.h>
    128 #include <netinet/ip.h>
    129 #include <netinet/if_ether.h>
    130 #endif
    131 #endif /* defined(__OpenBSD__) */
    132 
    133 #ifdef NS
    134 #include <netns/ns.h>
    135 #include <netns/ns_if.h>
    136 #endif
    137 
    138 #include <dev/mii/mii.h>
    139 #include <dev/mii/miivar.h>
    140 
    141 #include <dev/usb/usb.h>
    142 #include <dev/usb/usbdi.h>
    143 #include <dev/usb/usbdi_util.h>
    144 #include <dev/usb/usbdevs.h>
    145 
    146 #include <dev/usb/if_auereg.h>
    147 
    148 #ifdef AUE_DEBUG
    149 #define DPRINTF(x)	if (auedebug) logprintf x
    150 #define DPRINTFN(n,x)	if (auedebug >= (n)) logprintf x
    151 int	auedebug = 0;
    152 #else
    153 #define DPRINTF(x)
    154 #define DPRINTFN(n,x)
    155 #endif
    156 
    157 /*
    158  * Various supported device vendors/products.
    159  */
    160 struct aue_type {
    161 	u_int16_t		aue_vid;
    162 	u_int16_t		aue_did;
    163 	char			aue_linksys;
    164 };
    165 
    166 Static const struct aue_type aue_devs[] = {
    167   { USB_VENDOR_BILLIONTON,	USB_PRODUCT_BILLIONTON_USB100,	0 },
    168   { USB_VENDOR_MELCO, 		USB_PRODUCT_MELCO_LUATX1, 	0 },
    169   { USB_VENDOR_MELCO, 		USB_PRODUCT_MELCO_LUATX5, 	0 },
    170   { USB_VENDOR_LINKSYS,		USB_PRODUCT_LINKSYS_USB100TX,	1 },
    171   { USB_VENDOR_LINKSYS,		USB_PRODUCT_LINKSYS_USB100H1,	1 },
    172   { USB_VENDOR_LINKSYS,		USB_PRODUCT_LINKSYS_USB10TA,	1 },
    173   { USB_VENDOR_ADMTEK,		USB_PRODUCT_ADMTEK_PEGASUS,	0 },
    174   { USB_VENDOR_DLINK,		USB_PRODUCT_DLINK_DSB650,	1 },
    175   { USB_VENDOR_DLINK,		USB_PRODUCT_DLINK_DSB650TX,	1 },
    176   { USB_VENDOR_DLINK,		USB_PRODUCT_DLINK_DSB650TX_PNA,	0 },
    177   { USB_VENDOR_SMC,		USB_PRODUCT_SMC_2202USB,	0 },
    178   { USB_VENDOR_COREGA,		USB_PRODUCT_COREGA_FETHER_USB_TX, 0 },
    179   { USB_VENDOR_IODATA,		USB_PRODUCT_IODATA_USBETTX,	0 },
    180   { USB_VENDOR_KINGSTON,	USB_PRODUCT_KINGSTON_KNU101TX,  0 },
    181   { USB_VENDOR_ABOCOM,		USB_PRODUCT_ABOCOM_DSB650TX_PNA, 0 },
    182   { 0, 0, 0 }
    183 };
    184 
    185 USB_DECLARE_DRIVER(aue);
    186 
    187 Static const struct aue_type *aue_lookup(u_int16_t vendor, u_int16_t product);
    188 Static int aue_tx_list_init(struct aue_softc *);
    189 Static int aue_rx_list_init(struct aue_softc *);
    190 Static int aue_newbuf(struct aue_softc *, struct aue_chain *, struct mbuf *);
    191 Static int aue_send(struct aue_softc *, struct mbuf *, int);
    192 Static void aue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
    193 Static void aue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
    194 Static void aue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
    195 Static void aue_tick(void *);
    196 Static void aue_tick_task(void *);
    197 Static void aue_start(struct ifnet *);
    198 Static int aue_ioctl(struct ifnet *, u_long, caddr_t);
    199 Static void aue_init(void *);
    200 Static void aue_stop(struct aue_softc *);
    201 Static void aue_watchdog(struct ifnet *);
    202 Static int aue_openpipes(struct aue_softc *);
    203 Static int aue_ifmedia_upd(struct ifnet *);
    204 Static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
    205 
    206 Static int aue_eeprom_getword(struct aue_softc *, int);
    207 Static void aue_read_mac(struct aue_softc *, u_char *);
    208 Static int aue_miibus_readreg(device_ptr_t, int, int);
    209 Static void aue_miibus_writereg(device_ptr_t, int, int, int);
    210 Static void aue_miibus_statchg(device_ptr_t);
    211 
    212 Static void aue_lock_mii(struct aue_softc *);
    213 Static void aue_unlock_mii(struct aue_softc *);
    214 
    215 Static void aue_setmulti(struct aue_softc *);
    216 Static u_int32_t aue_crc(caddr_t);
    217 Static void aue_reset(struct aue_softc *);
    218 
    219 Static int aue_csr_read_1(struct aue_softc *, int);
    220 Static int aue_csr_write_1(struct aue_softc *, int, int);
    221 Static int aue_csr_read_2(struct aue_softc *, int);
    222 Static int aue_csr_write_2(struct aue_softc *, int, int);
    223 
    224 #define AUE_SETBIT(sc, reg, x)				\
    225 	aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
    226 
    227 #define AUE_CLRBIT(sc, reg, x)				\
    228 	aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
    229 
    230 Static int
    231 aue_csr_read_1(struct aue_softc *sc, int reg)
    232 {
    233 	usb_device_request_t	req;
    234 	usbd_status		err;
    235 	uByte			val = 0;
    236 
    237 	if (sc->aue_dying)
    238 		return (0);
    239 
    240 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    241 	req.bRequest = AUE_UR_READREG;
    242 	USETW(req.wValue, 0);
    243 	USETW(req.wIndex, reg);
    244 	USETW(req.wLength, 1);
    245 
    246 	err = usbd_do_request(sc->aue_udev, &req, &val);
    247 
    248 	if (err) {
    249 		DPRINTF(("%s: aue_csr_read_1: reg=0x%x err=%s\n",
    250 			 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
    251 		return (0);
    252 	}
    253 
    254 	return (val);
    255 }
    256 
    257 Static int
    258 aue_csr_read_2(struct aue_softc *sc, int reg)
    259 {
    260 	usb_device_request_t	req;
    261 	usbd_status		err;
    262 	uWord			val;
    263 
    264 	if (sc->aue_dying)
    265 		return (0);
    266 
    267 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    268 	req.bRequest = AUE_UR_READREG;
    269 	USETW(req.wValue, 0);
    270 	USETW(req.wIndex, reg);
    271 	USETW(req.wLength, 2);
    272 
    273 	err = usbd_do_request(sc->aue_udev, &req, &val);
    274 
    275 	if (err) {
    276 		DPRINTF(("%s: aue_csr_read_2: reg=0x%x err=%s\n",
    277 			 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
    278 		return (0);
    279 	}
    280 
    281 	return (UGETW(val));
    282 }
    283 
    284 Static int
    285 aue_csr_write_1(struct aue_softc *sc, int reg, int aval)
    286 {
    287 	usb_device_request_t	req;
    288 	usbd_status		err;
    289 	uByte			val;
    290 
    291 	if (sc->aue_dying)
    292 		return (0);
    293 
    294 	val = aval;
    295 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    296 	req.bRequest = AUE_UR_WRITEREG;
    297 	USETW(req.wValue, val);
    298 	USETW(req.wIndex, reg);
    299 	USETW(req.wLength, 1);
    300 
    301 	err = usbd_do_request(sc->aue_udev, &req, &val);
    302 
    303 	if (err) {
    304 		DPRINTF(("%s: aue_csr_write_1: reg=0x%x err=%s\n",
    305 			 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
    306 		return (-1);
    307 	}
    308 
    309 	return (0);
    310 }
    311 
    312 Static int
    313 aue_csr_write_2(struct aue_softc *sc, int reg, int aval)
    314 {
    315 	usb_device_request_t	req;
    316 	usbd_status		err;
    317 	uWord			val;
    318 
    319 	if (sc->aue_dying)
    320 		return (0);
    321 
    322 	USETW(val, aval);
    323 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    324 	req.bRequest = AUE_UR_WRITEREG;
    325 	USETW(req.wValue, aval);
    326 	USETW(req.wIndex, reg);
    327 	USETW(req.wLength, 2);
    328 
    329 	err = usbd_do_request(sc->aue_udev, &req, &val);
    330 
    331 	if (err) {
    332 		DPRINTF(("%s: aue_csr_write_2: reg=0x%x err=%s\n",
    333 			 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
    334 		return (-1);
    335 	}
    336 
    337 	return (0);
    338 }
    339 
    340 /*
    341  * Read a word of data stored in the EEPROM at address 'addr.'
    342  */
    343 Static int
    344 aue_eeprom_getword(struct aue_softc *sc, int addr)
    345 {
    346 	int		i;
    347 
    348 	aue_csr_write_1(sc, AUE_EE_REG, addr);
    349 	aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
    350 
    351 	for (i = 0; i < AUE_TIMEOUT; i++) {
    352 		if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
    353 			break;
    354 	}
    355 
    356 	if (i == AUE_TIMEOUT) {
    357 		printf("%s: EEPROM read timed out\n",
    358 		    USBDEVNAME(sc->aue_dev));
    359 	}
    360 
    361 	return (aue_csr_read_2(sc, AUE_EE_DATA));
    362 }
    363 
    364 /*
    365  * Read the MAC from the EEPROM.  It's at offset 0.
    366  */
    367 Static void
    368 aue_read_mac(struct aue_softc *sc, u_char *dest)
    369 {
    370 	int			i;
    371 	int			off = 0;
    372 	int			word;
    373 
    374 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    375 
    376 	for (i = 0; i < 3; i++) {
    377 		word = aue_eeprom_getword(sc, off + i);
    378 		dest[2 * i] = (u_char)word;
    379 		dest[2 * i + 1] = (u_char)(word >> 8);
    380 	}
    381 }
    382 
    383 /* Get exclusive access to the MII registers */
    384 Static void
    385 aue_lock_mii(struct aue_softc *sc)
    386 {
    387 	lockmgr(&sc->aue_mii_lock, LK_EXCLUSIVE, NULL);
    388 }
    389 
    390 Static void
    391 aue_unlock_mii(struct aue_softc *sc)
    392 {
    393 	lockmgr(&sc->aue_mii_lock, LK_RELEASE, NULL);
    394 }
    395 
    396 Static int
    397 aue_miibus_readreg(device_ptr_t dev, int phy, int reg)
    398 {
    399 	struct aue_softc	*sc = USBGETSOFTC(dev);
    400 	int			i;
    401 	u_int16_t		val;
    402 
    403 #if 0
    404 	/*
    405 	 * The Am79C901 HomePNA PHY actually contains
    406 	 * two transceivers: a 1Mbps HomePNA PHY and a
    407 	 * 10Mbps full/half duplex ethernet PHY with
    408 	 * NWAY autoneg. However in the ADMtek adapter,
    409 	 * only the 1Mbps PHY is actually connected to
    410 	 * anything, so we ignore the 10Mbps one. It
    411 	 * happens to be configured for MII address 3,
    412 	 * so we filter that out.
    413 	 */
    414 	if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
    415 	    sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
    416 		if (phy == 3)
    417 			return (0);
    418 	}
    419 #endif
    420 
    421 	aue_lock_mii(sc);
    422 	aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
    423 	aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ);
    424 
    425 	for (i = 0; i < AUE_TIMEOUT; i++) {
    426 		if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
    427 			break;
    428 	}
    429 
    430 	if (i == AUE_TIMEOUT) {
    431 		printf("%s: MII read timed out\n", USBDEVNAME(sc->aue_dev));
    432 	}
    433 
    434 	val = aue_csr_read_2(sc, AUE_PHY_DATA);
    435 
    436 	DPRINTFN(11,("%s: %s: phy=%d reg=%d => 0x%04x\n",
    437 		     USBDEVNAME(sc->aue_dev), __FUNCTION__, phy, reg, val));
    438 
    439 	aue_unlock_mii(sc);
    440 	return (val);
    441 }
    442 
    443 Static void
    444 aue_miibus_writereg(device_ptr_t dev, int phy, int reg, int data)
    445 {
    446 	struct aue_softc	*sc = USBGETSOFTC(dev);
    447 	int			i;
    448 
    449 #if 0
    450 	if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
    451 	    sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
    452 		if (phy == 3)
    453 			return;
    454 	}
    455 #endif
    456 
    457 	DPRINTFN(11,("%s: %s: phy=%d reg=%d data=0x%04x\n",
    458 		     USBDEVNAME(sc->aue_dev), __FUNCTION__, phy, reg, data));
    459 
    460 	aue_lock_mii(sc);
    461 	aue_csr_write_2(sc, AUE_PHY_DATA, data);
    462 	aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
    463 	aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE);
    464 
    465 	for (i = 0; i < AUE_TIMEOUT; i++) {
    466 		if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
    467 			break;
    468 	}
    469 
    470 	if (i == AUE_TIMEOUT) {
    471 		printf("%s: MII read timed out\n",
    472 		    USBDEVNAME(sc->aue_dev));
    473 	}
    474 	aue_unlock_mii(sc);
    475 }
    476 
    477 Static void
    478 aue_miibus_statchg(device_ptr_t dev)
    479 {
    480 	struct aue_softc	*sc = USBGETSOFTC(dev);
    481 	struct mii_data		*mii = GET_MII(sc);
    482 
    483 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    484 
    485 	aue_lock_mii(sc);
    486 	AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
    487 
    488 	if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) {
    489 		AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
    490 	} else {
    491 		AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
    492 	}
    493 
    494 	if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
    495 		AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
    496 	else
    497 		AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
    498 
    499 	AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
    500 	aue_unlock_mii(sc);
    501 
    502 	/*
    503 	 * Set the LED modes on the LinkSys adapter.
    504 	 * This turns on the 'dual link LED' bin in the auxmode
    505 	 * register of the Broadcom PHY.
    506 	 */
    507 	if (sc->aue_linksys) {
    508 		u_int16_t auxmode;
    509 		auxmode = aue_miibus_readreg(dev, 0, 0x1b);
    510 		aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04);
    511 	}
    512 }
    513 
    514 #define AUE_POLY	0xEDB88320
    515 #define AUE_BITS	6
    516 
    517 Static u_int32_t
    518 aue_crc(caddr_t addr)
    519 {
    520 	u_int32_t		idx, bit, data, crc;
    521 
    522 	/* Compute CRC for the address value. */
    523 	crc = 0xFFFFFFFF; /* initial value */
    524 
    525 	for (idx = 0; idx < 6; idx++) {
    526 		for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
    527 			crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
    528 	}
    529 
    530 	return (crc & ((1 << AUE_BITS) - 1));
    531 }
    532 
    533 Static void
    534 aue_setmulti(struct aue_softc *sc)
    535 {
    536 	struct ifnet		*ifp;
    537 	struct ether_multi	*enm;
    538 	struct ether_multistep	step;
    539 	u_int32_t		h = 0, i;
    540 
    541 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    542 
    543 	ifp = GET_IFP(sc);
    544 
    545 	if (ifp->if_flags & IFF_PROMISC) {
    546 allmulti:
    547 		ifp->if_flags |= IFF_ALLMULTI;
    548 		AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
    549 		return;
    550 	}
    551 
    552 	AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
    553 
    554 	/* first, zot all the existing hash bits */
    555 	for (i = 0; i < 8; i++)
    556 		aue_csr_write_1(sc, AUE_MAR0 + i, 0);
    557 
    558 	/* now program new ones */
    559 #if defined(__NetBSD__)
    560 	ETHER_FIRST_MULTI(step, &sc->aue_ec, enm);
    561 #else
    562 	ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
    563 #endif
    564 	while (enm != NULL) {
    565 		if (memcmp(enm->enm_addrlo,
    566 		    enm->enm_addrhi, ETHER_ADDR_LEN) != 0)
    567 			goto allmulti;
    568 
    569 		h = aue_crc(enm->enm_addrlo);
    570 		AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7));
    571 		ETHER_NEXT_MULTI(step, enm);
    572 	}
    573 
    574 	ifp->if_flags &= ~IFF_ALLMULTI;
    575 }
    576 
    577 Static void
    578 aue_reset(struct aue_softc *sc)
    579 {
    580 	int		i;
    581 
    582 	DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    583 
    584 	AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
    585 
    586 	for (i = 0; i < AUE_TIMEOUT; i++) {
    587 		if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
    588 			break;
    589 	}
    590 
    591 	if (i == AUE_TIMEOUT)
    592 		printf("%s: reset failed\n", USBDEVNAME(sc->aue_dev));
    593 
    594 	/*
    595 	 * The PHY(s) attached to the Pegasus chip may be held
    596 	 * in reset until we flip on the GPIO outputs. Make sure
    597 	 * to set the GPIO pins high so that the PHY(s) will
    598 	 * be enabled.
    599 	 *
    600 	 * Note: We force all of the GPIO pins low first, *then*
    601 	 * enable the ones we want.
    602   	 */
    603 	aue_csr_write_1(sc, AUE_GPIO0,
    604 	    AUE_GPIO_OUT0 | AUE_GPIO_SEL0);
    605   	aue_csr_write_1(sc, AUE_GPIO0,
    606 	    AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
    607 
    608 	/* Grrr. LinkSys has to be different from everyone else. */
    609 	if (sc->aue_linksys) {
    610 		aue_csr_write_1(sc, AUE_GPIO0,
    611 		    AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
    612 		aue_csr_write_1(sc, AUE_GPIO0,
    613 		    AUE_GPIO_SEL0 | AUE_GPIO_SEL1 | AUE_GPIO_OUT0);
    614 	}
    615 
    616 	/* Wait a little while for the chip to get its brains in order. */
    617 	delay(10000);		/* XXX */
    618 }
    619 
    620 Static const struct aue_type *
    621 aue_lookup(u_int16_t vendor, u_int16_t product)
    622 {
    623 	const struct aue_type	*t;
    624 
    625 	for (t = aue_devs; t->aue_vid != 0; t++)
    626 		if (vendor == t->aue_vid && product == t->aue_did)
    627 			return (t);
    628 	return (NULL);
    629 }
    630 
    631 /*
    632  * Probe for a Pegasus chip.
    633  */
    634 USB_MATCH(aue)
    635 {
    636 	USB_MATCH_START(aue, uaa);
    637 
    638 	if (uaa->iface != NULL)
    639 		return (UMATCH_NONE);
    640 
    641 	return (aue_lookup(uaa->vendor, uaa->product) != NULL ?
    642 		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
    643 }
    644 
    645 /*
    646  * Attach the interface. Allocate softc structures, do ifmedia
    647  * setup and ethernet/BPF attach.
    648  */
    649 USB_ATTACH(aue)
    650 {
    651 	USB_ATTACH_START(aue, sc, uaa);
    652 	char			devinfo[1024];
    653 	int			s;
    654 	u_char			eaddr[ETHER_ADDR_LEN];
    655 	struct ifnet		*ifp;
    656 	struct mii_data		*mii;
    657 	usbd_device_handle	dev = uaa->device;
    658 	usbd_interface_handle	iface;
    659 	usbd_status		err;
    660 	usb_interface_descriptor_t	*id;
    661 	usb_endpoint_descriptor_t	*ed;
    662 	int			i;
    663 
    664 	DPRINTFN(5,(" : aue_attach: sc=%p", sc));
    665 
    666 	usbd_devinfo(dev, 0, devinfo);
    667 	USB_ATTACH_SETUP;
    668 	printf("%s: %s\n", USBDEVNAME(sc->aue_dev), devinfo);
    669 
    670 	err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1);
    671 	if (err) {
    672 		printf("%s: setting config no failed\n",
    673 		    USBDEVNAME(sc->aue_dev));
    674 		USB_ATTACH_ERROR_RETURN;
    675 	}
    676 
    677 	usb_init_task(&sc->aue_tick_task, aue_tick_task, sc);
    678 	usb_init_task(&sc->aue_stop_task, (void (*)(void *))aue_stop, sc);
    679 	lockinit(&sc->aue_mii_lock, PZERO, "auemii", 0, 0);
    680 
    681 	err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &iface);
    682 	if (err) {
    683 		printf("%s: getting interface handle failed\n",
    684 		    USBDEVNAME(sc->aue_dev));
    685 		USB_ATTACH_ERROR_RETURN;
    686 	}
    687 
    688 	sc->aue_linksys = aue_lookup(uaa->vendor, uaa->product)->aue_linksys;
    689 
    690 	sc->aue_udev = dev;
    691 	sc->aue_iface = iface;
    692 	sc->aue_product = uaa->product;
    693 	sc->aue_vendor = uaa->vendor;
    694 
    695 	id = usbd_get_interface_descriptor(iface);
    696 
    697 	/* Find endpoints. */
    698 	for (i = 0; i < id->bNumEndpoints; i++) {
    699 		ed = usbd_interface2endpoint_descriptor(iface, i);
    700 		if (ed == NULL) {
    701 			printf("%s: couldn't get endpoint descriptor %d\n",
    702 			    USBDEVNAME(sc->aue_dev), i);
    703 			USB_ATTACH_ERROR_RETURN;
    704 		}
    705 		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    706 		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    707 			sc->aue_ed[AUE_ENDPT_RX] = ed->bEndpointAddress;
    708 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
    709 			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
    710 			sc->aue_ed[AUE_ENDPT_TX] = ed->bEndpointAddress;
    711 		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
    712 			   UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
    713 			sc->aue_ed[AUE_ENDPT_INTR] = ed->bEndpointAddress;
    714 		}
    715 	}
    716 
    717 	if (sc->aue_ed[AUE_ENDPT_RX] == 0 || sc->aue_ed[AUE_ENDPT_TX] == 0 ||
    718 	    sc->aue_ed[AUE_ENDPT_INTR] == 0) {
    719 		printf("%s: missing endpoint\n", USBDEVNAME(sc->aue_dev));
    720 		USB_ATTACH_ERROR_RETURN;
    721 	}
    722 
    723 
    724 	s = splnet();
    725 
    726 	/* Reset the adapter. */
    727 	aue_reset(sc);
    728 
    729 	/*
    730 	 * Get station address from the EEPROM.
    731 	 */
    732 	aue_read_mac(sc, eaddr);
    733 
    734 	/*
    735 	 * A Pegasus chip was detected. Inform the world.
    736 	 */
    737 	ifp = GET_IFP(sc);
    738 	printf("%s: Ethernet address %s\n", USBDEVNAME(sc->aue_dev),
    739 	    ether_sprintf(eaddr));
    740 
    741 	/* Initialize interface info.*/
    742 	ifp->if_softc = sc;
    743 	ifp->if_mtu = ETHERMTU;
    744 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
    745 	ifp->if_ioctl = aue_ioctl;
    746 	ifp->if_start = aue_start;
    747 	ifp->if_watchdog = aue_watchdog;
    748 #if defined(__OpenBSD__)
    749 	ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
    750 #endif
    751 	strncpy(ifp->if_xname, USBDEVNAME(sc->aue_dev), IFNAMSIZ);
    752 
    753 	IFQ_SET_READY(&ifp->if_snd);
    754 
    755 	/* Initialize MII/media info. */
    756 	mii = &sc->aue_mii;
    757 	mii->mii_ifp = ifp;
    758 	mii->mii_readreg = aue_miibus_readreg;
    759 	mii->mii_writereg = aue_miibus_writereg;
    760 	mii->mii_statchg = aue_miibus_statchg;
    761 	mii->mii_flags = MIIF_AUTOTSLEEP;
    762 	ifmedia_init(&mii->mii_media, 0, aue_ifmedia_upd, aue_ifmedia_sts);
    763 	mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0);
    764 	if (LIST_FIRST(&mii->mii_phys) == NULL) {
    765 		ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
    766 		ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
    767 	} else
    768 		ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
    769 
    770 	/* Attach the interface. */
    771 	if_attach(ifp);
    772 	Ether_ifattach(ifp, eaddr);
    773 #if NRND > 0
    774 	rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->aue_dev),
    775 	    RND_TYPE_NET, 0);
    776 #endif
    777 
    778 	usb_callout_init(sc->aue_stat_ch);
    779 
    780 	sc->aue_attached = 1;
    781 	splx(s);
    782 
    783 	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->aue_udev,
    784 			   USBDEV(sc->aue_dev));
    785 
    786 	USB_ATTACH_SUCCESS_RETURN;
    787 }
    788 
    789 USB_DETACH(aue)
    790 {
    791 	USB_DETACH_START(aue, sc);
    792 	struct ifnet		*ifp = GET_IFP(sc);
    793 	int			s;
    794 
    795 	DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    796 
    797 	if (!sc->aue_attached) {
    798 		/* Detached before attached finished, so just bail out. */
    799 		return (0);
    800 	}
    801 
    802 	usb_uncallout(sc->aue_stat_ch, aue_tick, sc);
    803 	/*
    804 	 * Remove any pending tasks.  They cannot be executing because they run
    805 	 * in the same thread as detach.
    806 	 */
    807 	usb_rem_task(sc->aue_udev, &sc->aue_tick_task);
    808 	usb_rem_task(sc->aue_udev, &sc->aue_stop_task);
    809 
    810 	s = splusb();
    811 
    812 	if (ifp->if_flags & IFF_RUNNING)
    813 		aue_stop(sc);
    814 
    815 #if defined(__NetBSD__)
    816 #if NRND > 0
    817 	rnd_detach_source(&sc->rnd_source);
    818 #endif
    819 	mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY);
    820 	ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY);
    821 	ether_ifdetach(ifp);
    822 #endif /* __NetBSD__ */
    823 
    824 	if_detach(ifp);
    825 
    826 #ifdef DIAGNOSTIC
    827 	if (sc->aue_ep[AUE_ENDPT_TX] != NULL ||
    828 	    sc->aue_ep[AUE_ENDPT_RX] != NULL ||
    829 	    sc->aue_ep[AUE_ENDPT_INTR] != NULL)
    830 		printf("%s: detach has active endpoints\n",
    831 		       USBDEVNAME(sc->aue_dev));
    832 #endif
    833 
    834 	sc->aue_attached = 0;
    835 	splx(s);
    836 
    837 	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->aue_udev,
    838 			   USBDEV(sc->aue_dev));
    839 
    840 	return (0);
    841 }
    842 
    843 int
    844 aue_activate(device_ptr_t self, enum devact act)
    845 {
    846 	struct aue_softc *sc = (struct aue_softc *)self;
    847 
    848 	DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    849 
    850 	switch (act) {
    851 	case DVACT_ACTIVATE:
    852 		return (EOPNOTSUPP);
    853 		break;
    854 
    855 	case DVACT_DEACTIVATE:
    856 		if_deactivate(&sc->aue_ec.ec_if);
    857 		sc->aue_dying = 1;
    858 		break;
    859 	}
    860 	return (0);
    861 }
    862 
    863 /*
    864  * Initialize an RX descriptor and attach an MBUF cluster.
    865  */
    866 Static int
    867 aue_newbuf(struct aue_softc *sc, struct aue_chain *c, struct mbuf *m)
    868 {
    869 	struct mbuf		*m_new = NULL;
    870 
    871 	DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
    872 
    873 	if (m == NULL) {
    874 		MGETHDR(m_new, M_DONTWAIT, MT_DATA);
    875 		if (m_new == NULL) {
    876 			printf("%s: no memory for rx list "
    877 			    "-- packet dropped!\n", USBDEVNAME(sc->aue_dev));
    878 			return (ENOBUFS);
    879 		}
    880 
    881 		MCLGET(m_new, M_DONTWAIT);
    882 		if (!(m_new->m_flags & M_EXT)) {
    883 			printf("%s: no memory for rx list "
    884 			    "-- packet dropped!\n", USBDEVNAME(sc->aue_dev));
    885 			m_freem(m_new);
    886 			return (ENOBUFS);
    887 		}
    888 		m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
    889 	} else {
    890 		m_new = m;
    891 		m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
    892 		m_new->m_data = m_new->m_ext.ext_buf;
    893 	}
    894 
    895 	m_adj(m_new, ETHER_ALIGN);
    896 	c->aue_mbuf = m_new;
    897 
    898 	return (0);
    899 }
    900 
    901 Static int
    902 aue_rx_list_init(struct aue_softc *sc)
    903 {
    904 	struct aue_cdata	*cd;
    905 	struct aue_chain	*c;
    906 	int			i;
    907 
    908 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    909 
    910 	cd = &sc->aue_cdata;
    911 	for (i = 0; i < AUE_RX_LIST_CNT; i++) {
    912 		c = &cd->aue_rx_chain[i];
    913 		c->aue_sc = sc;
    914 		c->aue_idx = i;
    915 		if (aue_newbuf(sc, c, NULL) == ENOBUFS)
    916 			return (ENOBUFS);
    917 		if (c->aue_xfer == NULL) {
    918 			c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
    919 			if (c->aue_xfer == NULL)
    920 				return (ENOBUFS);
    921 			c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ);
    922 			if (c->aue_buf == NULL)
    923 				return (ENOBUFS); /* XXX free xfer */
    924 		}
    925 	}
    926 
    927 	return (0);
    928 }
    929 
    930 Static int
    931 aue_tx_list_init(struct aue_softc *sc)
    932 {
    933 	struct aue_cdata	*cd;
    934 	struct aue_chain	*c;
    935 	int			i;
    936 
    937 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
    938 
    939 	cd = &sc->aue_cdata;
    940 	for (i = 0; i < AUE_TX_LIST_CNT; i++) {
    941 		c = &cd->aue_tx_chain[i];
    942 		c->aue_sc = sc;
    943 		c->aue_idx = i;
    944 		c->aue_mbuf = NULL;
    945 		if (c->aue_xfer == NULL) {
    946 			c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
    947 			if (c->aue_xfer == NULL)
    948 				return (ENOBUFS);
    949 			c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ);
    950 			if (c->aue_buf == NULL)
    951 				return (ENOBUFS);
    952 		}
    953 	}
    954 
    955 	return (0);
    956 }
    957 
    958 Static void
    959 aue_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
    960 {
    961 	struct aue_softc	*sc = priv;
    962 	struct ifnet		*ifp = GET_IFP(sc);
    963 	struct aue_intrpkt	*p = &sc->aue_cdata.aue_ibuf;
    964 
    965 	DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
    966 
    967 	if (sc->aue_dying)
    968 		return;
    969 
    970 	if (!(ifp->if_flags & IFF_RUNNING))
    971 		return;
    972 
    973 	if (status != USBD_NORMAL_COMPLETION) {
    974 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
    975 			return;
    976 		}
    977 		sc->aue_intr_errs++;
    978 		if (usbd_ratecheck(&sc->aue_rx_notice)) {
    979 			printf("%s: %u usb errors on intr: %s\n",
    980 			    USBDEVNAME(sc->aue_dev), sc->aue_intr_errs,
    981 			    usbd_errstr(status));
    982 			sc->aue_intr_errs = 0;
    983 		}
    984 		if (status == USBD_STALLED)
    985 			usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]);
    986 		return;
    987 	}
    988 
    989 	if (p->aue_txstat0)
    990 		ifp->if_oerrors++;
    991 
    992 	if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL))
    993 		ifp->if_collisions++;
    994 }
    995 
    996 /*
    997  * A frame has been uploaded: pass the resulting mbuf chain up to
    998  * the higher level protocols.
    999  */
   1000 Static void
   1001 aue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
   1002 {
   1003 	struct aue_chain	*c = priv;
   1004 	struct aue_softc	*sc = c->aue_sc;
   1005 	struct ifnet		*ifp = GET_IFP(sc);
   1006 	struct mbuf		*m;
   1007 	u_int32_t		total_len;
   1008 	struct aue_rxpkt	r;
   1009 	int			s;
   1010 
   1011 	DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
   1012 
   1013 	if (sc->aue_dying)
   1014 		return;
   1015 
   1016 	if (!(ifp->if_flags & IFF_RUNNING))
   1017 		return;
   1018 
   1019 	if (status != USBD_NORMAL_COMPLETION) {
   1020 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
   1021 			return;
   1022 		sc->aue_rx_errs++;
   1023 		if (usbd_ratecheck(&sc->aue_rx_notice)) {
   1024 			printf("%s: %u usb errors on rx: %s\n",
   1025 			    USBDEVNAME(sc->aue_dev), sc->aue_rx_errs,
   1026 			    usbd_errstr(status));
   1027 			sc->aue_rx_errs = 0;
   1028 		}
   1029 		if (status == USBD_STALLED)
   1030 			usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]);
   1031 		goto done;
   1032 	}
   1033 
   1034 	usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
   1035 
   1036 	memcpy(mtod(c->aue_mbuf, char*), c->aue_buf, total_len);
   1037 
   1038 	if (total_len <= 4 + ETHER_CRC_LEN) {
   1039 		ifp->if_ierrors++;
   1040 		goto done;
   1041 	}
   1042 
   1043 	memcpy(&r, c->aue_buf + total_len - 4, sizeof(r));
   1044 
   1045 	/* Turn off all the non-error bits in the rx status word. */
   1046 	r.aue_rxstat &= AUE_RXSTAT_MASK;
   1047 	if (r.aue_rxstat) {
   1048 		ifp->if_ierrors++;
   1049 		goto done;
   1050 	}
   1051 
   1052 	/* No errors; receive the packet. */
   1053 	m = c->aue_mbuf;
   1054 	total_len -= ETHER_CRC_LEN + 4;
   1055 	m->m_pkthdr.len = m->m_len = total_len;
   1056 	ifp->if_ipackets++;
   1057 
   1058 	m->m_pkthdr.rcvif = ifp;
   1059 
   1060 	s = splnet();
   1061 
   1062 	/* XXX ugly */
   1063 	if (aue_newbuf(sc, c, NULL) == ENOBUFS) {
   1064 		ifp->if_ierrors++;
   1065 		goto done1;
   1066 	}
   1067 
   1068 #if NBPFILTER > 0
   1069 	/*
   1070 	 * Handle BPF listeners. Let the BPF user see the packet, but
   1071 	 * don't pass it up to the ether_input() layer unless it's
   1072 	 * a broadcast packet, multicast packet, matches our ethernet
   1073 	 * address or the interface is in promiscuous mode.
   1074 	 */
   1075 	if (ifp->if_bpf)
   1076 		BPF_MTAP(ifp, m);
   1077 #endif
   1078 
   1079 	DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->aue_dev),
   1080 		    __FUNCTION__, m->m_len));
   1081 	IF_INPUT(ifp, m);
   1082  done1:
   1083 	splx(s);
   1084 
   1085  done:
   1086 
   1087 	/* Setup new transfer. */
   1088 	usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX],
   1089 	    c, c->aue_buf, AUE_BUFSZ,
   1090 	    USBD_SHORT_XFER_OK | USBD_NO_COPY,
   1091 	    USBD_NO_TIMEOUT, aue_rxeof);
   1092 	usbd_transfer(xfer);
   1093 
   1094 	DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->aue_dev),
   1095 		    __FUNCTION__));
   1096 }
   1097 
   1098 /*
   1099  * A frame was downloaded to the chip. It's safe for us to clean up
   1100  * the list buffers.
   1101  */
   1102 
   1103 Static void
   1104 aue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
   1105 {
   1106 	struct aue_chain	*c = priv;
   1107 	struct aue_softc	*sc = c->aue_sc;
   1108 	struct ifnet		*ifp = GET_IFP(sc);
   1109 	int			s;
   1110 
   1111 	if (sc->aue_dying)
   1112 		return;
   1113 
   1114 	s = splnet();
   1115 
   1116 	DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->aue_dev),
   1117 		    __FUNCTION__, status));
   1118 
   1119 	ifp->if_timer = 0;
   1120 	ifp->if_flags &= ~IFF_OACTIVE;
   1121 
   1122 	if (status != USBD_NORMAL_COMPLETION) {
   1123 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
   1124 			splx(s);
   1125 			return;
   1126 		}
   1127 		ifp->if_oerrors++;
   1128 		printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->aue_dev),
   1129 		    usbd_errstr(status));
   1130 		if (status == USBD_STALLED)
   1131 			usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_TX]);
   1132 		splx(s);
   1133 		return;
   1134 	}
   1135 
   1136 	ifp->if_opackets++;
   1137 
   1138 	m_freem(c->aue_mbuf);
   1139 	c->aue_mbuf = NULL;
   1140 
   1141 	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
   1142 		aue_start(ifp);
   1143 
   1144 	splx(s);
   1145 }
   1146 
   1147 Static void
   1148 aue_tick(void *xsc)
   1149 {
   1150 	struct aue_softc	*sc = xsc;
   1151 
   1152 	DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
   1153 
   1154 	if (sc == NULL)
   1155 		return;
   1156 
   1157 	if (sc->aue_dying)
   1158 		return;
   1159 
   1160 	/* Perform periodic stuff in process context. */
   1161 	usb_add_task(sc->aue_udev, &sc->aue_tick_task);
   1162 }
   1163 
   1164 Static void
   1165 aue_tick_task(void *xsc)
   1166 {
   1167 	struct aue_softc	*sc = xsc;
   1168 	struct ifnet		*ifp;
   1169 	struct mii_data		*mii;
   1170 	int			s;
   1171 
   1172 	DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
   1173 
   1174 	if (sc->aue_dying)
   1175 		return;
   1176 
   1177 	ifp = GET_IFP(sc);
   1178 	mii = GET_MII(sc);
   1179 	if (mii == NULL)
   1180 		return;
   1181 
   1182 	s = splnet();
   1183 
   1184 	mii_tick(mii);
   1185 	if (!sc->aue_link) {
   1186 		mii_pollstat(mii);
   1187 		if (mii->mii_media_status & IFM_ACTIVE &&
   1188 		    IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
   1189 			DPRINTFN(2,("%s: %s: got link\n",
   1190 				    USBDEVNAME(sc->aue_dev),__FUNCTION__));
   1191 			sc->aue_link++;
   1192 			if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
   1193 				aue_start(ifp);
   1194 		}
   1195 	}
   1196 
   1197 	usb_callout(sc->aue_stat_ch, hz, aue_tick, sc);
   1198 
   1199 	splx(s);
   1200 }
   1201 
   1202 Static int
   1203 aue_send(struct aue_softc *sc, struct mbuf *m, int idx)
   1204 {
   1205 	int			total_len;
   1206 	struct aue_chain	*c;
   1207 	usbd_status		err;
   1208 
   1209 	DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
   1210 
   1211 	c = &sc->aue_cdata.aue_tx_chain[idx];
   1212 
   1213 	/*
   1214 	 * Copy the mbuf data into a contiguous buffer, leaving two
   1215 	 * bytes at the beginning to hold the frame length.
   1216 	 */
   1217 	m_copydata(m, 0, m->m_pkthdr.len, c->aue_buf + 2);
   1218 	c->aue_mbuf = m;
   1219 
   1220 	/*
   1221 	 * The ADMtek documentation says that the packet length is
   1222 	 * supposed to be specified in the first two bytes of the
   1223 	 * transfer, however it actually seems to ignore this info
   1224 	 * and base the frame size on the bulk transfer length.
   1225 	 */
   1226 	c->aue_buf[0] = (u_int8_t)m->m_pkthdr.len;
   1227 	c->aue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
   1228 	total_len = m->m_pkthdr.len + 2;
   1229 
   1230 	usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_TX],
   1231 	    c, c->aue_buf, total_len, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
   1232 	    AUE_TX_TIMEOUT, aue_txeof);
   1233 
   1234 	/* Transmit */
   1235 	err = usbd_transfer(c->aue_xfer);
   1236 	if (err != USBD_IN_PROGRESS) {
   1237 		printf("%s: aue_send error=%s\n", USBDEVNAME(sc->aue_dev),
   1238 		       usbd_errstr(err));
   1239 		/* Stop the interface from process context. */
   1240 		usb_add_task(sc->aue_udev, &sc->aue_stop_task);
   1241 		return (EIO);
   1242 	}
   1243 	DPRINTFN(5,("%s: %s: send %d bytes\n", USBDEVNAME(sc->aue_dev),
   1244 		    __FUNCTION__, total_len));
   1245 
   1246 	sc->aue_cdata.aue_tx_cnt++;
   1247 
   1248 	return (0);
   1249 }
   1250 
   1251 Static void
   1252 aue_start(struct ifnet *ifp)
   1253 {
   1254 	struct aue_softc	*sc = ifp->if_softc;
   1255 	struct mbuf		*m_head = NULL;
   1256 
   1257 	DPRINTFN(5,("%s: %s: enter, link=%d\n", USBDEVNAME(sc->aue_dev),
   1258 		    __FUNCTION__, sc->aue_link));
   1259 
   1260 	if (sc->aue_dying)
   1261 		return;
   1262 
   1263 	if (!sc->aue_link)
   1264 		return;
   1265 
   1266 	if (ifp->if_flags & IFF_OACTIVE)
   1267 		return;
   1268 
   1269 	IFQ_POLL(&ifp->if_snd, m_head);
   1270 	if (m_head == NULL)
   1271 		return;
   1272 
   1273 	if (aue_send(sc, m_head, 0)) {
   1274 		ifp->if_flags |= IFF_OACTIVE;
   1275 		return;
   1276 	}
   1277 
   1278 	IFQ_DEQUEUE(&ifp->if_snd, m_head);
   1279 
   1280 #if NBPFILTER > 0
   1281 	/*
   1282 	 * If there's a BPF listener, bounce a copy of this frame
   1283 	 * to him.
   1284 	 */
   1285 	if (ifp->if_bpf)
   1286 		BPF_MTAP(ifp, m_head);
   1287 #endif
   1288 
   1289 	ifp->if_flags |= IFF_OACTIVE;
   1290 
   1291 	/*
   1292 	 * Set a timeout in case the chip goes out to lunch.
   1293 	 */
   1294 	ifp->if_timer = 5;
   1295 }
   1296 
   1297 Static void
   1298 aue_init(void *xsc)
   1299 {
   1300 	struct aue_softc	*sc = xsc;
   1301 	struct ifnet		*ifp = GET_IFP(sc);
   1302 	struct mii_data		*mii = GET_MII(sc);
   1303 	int			i, s;
   1304 	u_char			*eaddr;
   1305 
   1306 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
   1307 
   1308 	if (sc->aue_dying)
   1309 		return;
   1310 
   1311 	if (ifp->if_flags & IFF_RUNNING)
   1312 		return;
   1313 
   1314 	s = splnet();
   1315 
   1316 	/*
   1317 	 * Cancel pending I/O and free all RX/TX buffers.
   1318 	 */
   1319 	aue_reset(sc);
   1320 
   1321 #if defined(__OpenBSD__)
   1322 	eaddr = sc->arpcom.ac_enaddr;
   1323 #elif defined(__NetBSD__)
   1324 	eaddr = LLADDR(ifp->if_sadl);
   1325 #endif /* defined(__NetBSD__) */
   1326 	for (i = 0; i < ETHER_ADDR_LEN; i++)
   1327 		aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]);
   1328 
   1329 	 /* If we want promiscuous mode, set the allframes bit. */
   1330 	if (ifp->if_flags & IFF_PROMISC)
   1331 		AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
   1332 	else
   1333 		AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
   1334 
   1335 	/* Init TX ring. */
   1336 	if (aue_tx_list_init(sc) == ENOBUFS) {
   1337 		printf("%s: tx list init failed\n", USBDEVNAME(sc->aue_dev));
   1338 		splx(s);
   1339 		return;
   1340 	}
   1341 
   1342 	/* Init RX ring. */
   1343 	if (aue_rx_list_init(sc) == ENOBUFS) {
   1344 		printf("%s: rx list init failed\n", USBDEVNAME(sc->aue_dev));
   1345 		splx(s);
   1346 		return;
   1347 	}
   1348 
   1349 	/* Load the multicast filter. */
   1350 	aue_setmulti(sc);
   1351 
   1352 	/* Enable RX and TX */
   1353 	aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB);
   1354 	AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
   1355 	AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
   1356 
   1357 	mii_mediachg(mii);
   1358 
   1359 	if (sc->aue_ep[AUE_ENDPT_RX] == NULL) {
   1360 		if (aue_openpipes(sc)) {
   1361 			splx(s);
   1362 			return;
   1363 		}
   1364 	}
   1365 
   1366 	ifp->if_flags |= IFF_RUNNING;
   1367 	ifp->if_flags &= ~IFF_OACTIVE;
   1368 
   1369 	splx(s);
   1370 
   1371 	usb_callout(sc->aue_stat_ch, hz, aue_tick, sc);
   1372 }
   1373 
   1374 Static int
   1375 aue_openpipes(struct aue_softc *sc)
   1376 {
   1377 	struct aue_chain	*c;
   1378 	usbd_status		err;
   1379 	int i;
   1380 
   1381 	/* Open RX and TX pipes. */
   1382 	err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_RX],
   1383 	    USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_RX]);
   1384 	if (err) {
   1385 		printf("%s: open rx pipe failed: %s\n",
   1386 		    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1387 		return (EIO);
   1388 	}
   1389 	err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX],
   1390 	    USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]);
   1391 	if (err) {
   1392 		printf("%s: open tx pipe failed: %s\n",
   1393 		    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1394 		return (EIO);
   1395 	}
   1396 	err = usbd_open_pipe_intr(sc->aue_iface, sc->aue_ed[AUE_ENDPT_INTR],
   1397 	    USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_INTR], sc,
   1398 	    &sc->aue_cdata.aue_ibuf, AUE_INTR_PKTLEN, aue_intr,
   1399 	    AUE_INTR_INTERVAL);
   1400 	if (err) {
   1401 		printf("%s: open intr pipe failed: %s\n",
   1402 		    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1403 		return (EIO);
   1404 	}
   1405 
   1406 	/* Start up the receive pipe. */
   1407 	for (i = 0; i < AUE_RX_LIST_CNT; i++) {
   1408 		c = &sc->aue_cdata.aue_rx_chain[i];
   1409 		usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX],
   1410 		    c, c->aue_buf, AUE_BUFSZ,
   1411 		    USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT,
   1412 		    aue_rxeof);
   1413 		(void)usbd_transfer(c->aue_xfer); /* XXX */
   1414 		DPRINTFN(5,("%s: %s: start read\n", USBDEVNAME(sc->aue_dev),
   1415 			    __FUNCTION__));
   1416 
   1417 	}
   1418 	return (0);
   1419 }
   1420 
   1421 /*
   1422  * Set media options.
   1423  */
   1424 Static int
   1425 aue_ifmedia_upd(struct ifnet *ifp)
   1426 {
   1427 	struct aue_softc	*sc = ifp->if_softc;
   1428 	struct mii_data		*mii = GET_MII(sc);
   1429 
   1430 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
   1431 
   1432 	if (sc->aue_dying)
   1433 		return (0);
   1434 
   1435 	sc->aue_link = 0;
   1436 	if (mii->mii_instance) {
   1437 		struct mii_softc	*miisc;
   1438 		for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
   1439 		    miisc = LIST_NEXT(miisc, mii_list))
   1440 			 mii_phy_reset(miisc);
   1441 	}
   1442 	mii_mediachg(mii);
   1443 
   1444 	return (0);
   1445 }
   1446 
   1447 /*
   1448  * Report current media status.
   1449  */
   1450 Static void
   1451 aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
   1452 {
   1453 	struct aue_softc	*sc = ifp->if_softc;
   1454 	struct mii_data		*mii = GET_MII(sc);
   1455 
   1456 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
   1457 
   1458 	mii_pollstat(mii);
   1459 	ifmr->ifm_active = mii->mii_media_active;
   1460 	ifmr->ifm_status = mii->mii_media_status;
   1461 }
   1462 
   1463 Static int
   1464 aue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
   1465 {
   1466 	struct aue_softc	*sc = ifp->if_softc;
   1467 	struct ifaddr 		*ifa = (struct ifaddr *)data;
   1468 	struct ifreq		*ifr = (struct ifreq *)data;
   1469 	struct mii_data		*mii;
   1470 	int			s, error = 0;
   1471 
   1472 	if (sc->aue_dying)
   1473 		return (EIO);
   1474 
   1475 	s = splnet();
   1476 
   1477 	switch(command) {
   1478 	case SIOCSIFADDR:
   1479 		ifp->if_flags |= IFF_UP;
   1480 		aue_init(sc);
   1481 
   1482 		switch (ifa->ifa_addr->sa_family) {
   1483 #ifdef INET
   1484 		case AF_INET:
   1485 #if defined(__NetBSD__)
   1486 			arp_ifinit(ifp, ifa);
   1487 #else
   1488 			arp_ifinit(&sc->arpcom, ifa);
   1489 #endif
   1490 			break;
   1491 #endif /* INET */
   1492 #ifdef NS
   1493 		case AF_NS:
   1494 		    {
   1495 			struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
   1496 
   1497 			if (ns_nullhost(*ina))
   1498 				ina->x_host = *(union ns_host *)
   1499 					LLADDR(ifp->if_sadl);
   1500 			else
   1501 				memcpy(LLADDR(ifp->if_sadl),
   1502 				       ina->x_host.c_host,
   1503 				       ifp->if_addrlen);
   1504 			break;
   1505 		    }
   1506 #endif /* NS */
   1507 		}
   1508 		break;
   1509 
   1510 	case SIOCSIFMTU:
   1511 		if (ifr->ifr_mtu > ETHERMTU)
   1512 			error = EINVAL;
   1513 		else
   1514 			ifp->if_mtu = ifr->ifr_mtu;
   1515 		break;
   1516 
   1517 	case SIOCSIFFLAGS:
   1518 		if (ifp->if_flags & IFF_UP) {
   1519 			if (ifp->if_flags & IFF_RUNNING &&
   1520 			    ifp->if_flags & IFF_PROMISC &&
   1521 			    !(sc->aue_if_flags & IFF_PROMISC)) {
   1522 				AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
   1523 			} else if (ifp->if_flags & IFF_RUNNING &&
   1524 			    !(ifp->if_flags & IFF_PROMISC) &&
   1525 			    sc->aue_if_flags & IFF_PROMISC) {
   1526 				AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
   1527 			} else if (!(ifp->if_flags & IFF_RUNNING))
   1528 				aue_init(sc);
   1529 		} else {
   1530 			if (ifp->if_flags & IFF_RUNNING)
   1531 				aue_stop(sc);
   1532 		}
   1533 		sc->aue_if_flags = ifp->if_flags;
   1534 		error = 0;
   1535 		break;
   1536 	case SIOCADDMULTI:
   1537 	case SIOCDELMULTI:
   1538 		error = (command == SIOCADDMULTI) ?
   1539 			ether_addmulti(ifr, &sc->aue_ec) :
   1540 			ether_delmulti(ifr, &sc->aue_ec);
   1541 		if (error == ENETRESET) {
   1542 			aue_init(sc);
   1543 		}
   1544 		aue_setmulti(sc);
   1545 		error = 0;
   1546 		break;
   1547 	case SIOCGIFMEDIA:
   1548 	case SIOCSIFMEDIA:
   1549 		mii = GET_MII(sc);
   1550 		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
   1551 		break;
   1552 	default:
   1553 		error = EINVAL;
   1554 		break;
   1555 	}
   1556 
   1557 	splx(s);
   1558 
   1559 	return (error);
   1560 }
   1561 
   1562 Static void
   1563 aue_watchdog(struct ifnet *ifp)
   1564 {
   1565 	struct aue_softc	*sc = ifp->if_softc;
   1566 	struct aue_chain	*c;
   1567 	usbd_status		stat;
   1568 	int			s;
   1569 
   1570 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
   1571 
   1572 	ifp->if_oerrors++;
   1573 	printf("%s: watchdog timeout\n", USBDEVNAME(sc->aue_dev));
   1574 
   1575 	s = splusb();
   1576 	c = &sc->aue_cdata.aue_tx_chain[0];
   1577 	usbd_get_xfer_status(c->aue_xfer, NULL, NULL, NULL, &stat);
   1578 	aue_txeof(c->aue_xfer, c, stat);
   1579 
   1580 	if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
   1581 		aue_start(ifp);
   1582 	splx(s);
   1583 }
   1584 
   1585 /*
   1586  * Stop the adapter and free any mbufs allocated to the
   1587  * RX and TX lists.
   1588  */
   1589 Static void
   1590 aue_stop(struct aue_softc *sc)
   1591 {
   1592 	usbd_status		err;
   1593 	struct ifnet		*ifp;
   1594 	int			i;
   1595 
   1596 	DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
   1597 
   1598 	ifp = GET_IFP(sc);
   1599 	ifp->if_timer = 0;
   1600 
   1601 	aue_csr_write_1(sc, AUE_CTL0, 0);
   1602 	aue_csr_write_1(sc, AUE_CTL1, 0);
   1603 	aue_reset(sc);
   1604 	usb_uncallout(sc->aue_stat_ch, aue_tick, sc);
   1605 
   1606 	/* Stop transfers. */
   1607 	if (sc->aue_ep[AUE_ENDPT_RX] != NULL) {
   1608 		err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]);
   1609 		if (err) {
   1610 			printf("%s: abort rx pipe failed: %s\n",
   1611 			    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1612 		}
   1613 		err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_RX]);
   1614 		if (err) {
   1615 			printf("%s: close rx pipe failed: %s\n",
   1616 			    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1617 		}
   1618 		sc->aue_ep[AUE_ENDPT_RX] = NULL;
   1619 	}
   1620 
   1621 	if (sc->aue_ep[AUE_ENDPT_TX] != NULL) {
   1622 		err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]);
   1623 		if (err) {
   1624 			printf("%s: abort tx pipe failed: %s\n",
   1625 			    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1626 		}
   1627 		err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_TX]);
   1628 		if (err) {
   1629 			printf("%s: close tx pipe failed: %s\n",
   1630 			    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1631 		}
   1632 		sc->aue_ep[AUE_ENDPT_TX] = NULL;
   1633 	}
   1634 
   1635 	if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) {
   1636 		err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
   1637 		if (err) {
   1638 			printf("%s: abort intr pipe failed: %s\n",
   1639 			    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1640 		}
   1641 		err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
   1642 		if (err) {
   1643 			printf("%s: close intr pipe failed: %s\n",
   1644 			    USBDEVNAME(sc->aue_dev), usbd_errstr(err));
   1645 		}
   1646 		sc->aue_ep[AUE_ENDPT_INTR] = NULL;
   1647 	}
   1648 
   1649 	/* Free RX resources. */
   1650 	for (i = 0; i < AUE_RX_LIST_CNT; i++) {
   1651 		if (sc->aue_cdata.aue_rx_chain[i].aue_mbuf != NULL) {
   1652 			m_freem(sc->aue_cdata.aue_rx_chain[i].aue_mbuf);
   1653 			sc->aue_cdata.aue_rx_chain[i].aue_mbuf = NULL;
   1654 		}
   1655 		if (sc->aue_cdata.aue_rx_chain[i].aue_xfer != NULL) {
   1656 			usbd_free_xfer(sc->aue_cdata.aue_rx_chain[i].aue_xfer);
   1657 			sc->aue_cdata.aue_rx_chain[i].aue_xfer = NULL;
   1658 		}
   1659 	}
   1660 
   1661 	/* Free TX resources. */
   1662 	for (i = 0; i < AUE_TX_LIST_CNT; i++) {
   1663 		if (sc->aue_cdata.aue_tx_chain[i].aue_mbuf != NULL) {
   1664 			m_freem(sc->aue_cdata.aue_tx_chain[i].aue_mbuf);
   1665 			sc->aue_cdata.aue_tx_chain[i].aue_mbuf = NULL;
   1666 		}
   1667 		if (sc->aue_cdata.aue_tx_chain[i].aue_xfer != NULL) {
   1668 			usbd_free_xfer(sc->aue_cdata.aue_tx_chain[i].aue_xfer);
   1669 			sc->aue_cdata.aue_tx_chain[i].aue_xfer = NULL;
   1670 		}
   1671 	}
   1672 
   1673 	sc->aue_link = 0;
   1674 
   1675 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
   1676 }
   1677