2 * Copyright (c) 1997, 1998, 1999, 2000
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.19.2.18 2003/06/14 15:56:48 trhodes Exp $
36 * ADMtek AN986 Pegasus USB to ethernet driver. Datasheet is available
37 * from http://www.admtek.com.tw.
39 * Written by Bill Paul <wpaul@ee.columbia.edu>
40 * Electrical Engineering Department
41 * Columbia University, New York City
45 * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet
46 * support: the control endpoint for reading/writing registers, burst
47 * read endpoint for packet reception, burst write for packet transmission
48 * and one for "interrupts." The chip uses the same RX filter scheme
49 * as the other ADMtek ethernet parts: one perfect filter entry for the
50 * the station address and a 64-bit multicast hash table. The chip supports
51 * both MII and HomePNA attachments.
53 * Since the maximum data transfer speed of USB is supposed to be 12Mbps,
54 * you're never really going to get 100Mbps speeds from this device. I
55 * think the idea is to allow the device to connect to 10 or 100Mbps
56 * networks, not necessarily to provide 100Mbps performance. Also, since
57 * the controller uses an external PHY chip, it's possible that board
58 * designers might simply choose a 10Mbps PHY.
60 * Registers are accessed using usbd_do_request(). Packet transfers are
61 * done using usbd_transfer() and friends.
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/sockio.h>
68 #include <sys/malloc.h>
69 #include <sys/kernel.h>
70 #include <sys/socket.h>
73 #include <net/if_arp.h>
74 #include <net/ethernet.h>
75 #include <net/if_dl.h>
76 #include <net/if_media.h>
80 #include <machine/clock.h> /* for DELAY */
83 #include <dev/usb/usb.h>
84 #include <dev/usb/usbdi.h>
85 #include <dev/usb/usbdi_util.h>
86 #include <dev/usb/usbdivar.h>
87 #include <dev/usb/usbdevs.h>
88 #include <dev/usb/usb_ethersubr.h>
90 #include <dev/mii/mii.h>
91 #include <dev/mii/miivar.h>
93 #include <dev/usb/if_auereg.h>
95 /* "controller miibus0" required. See GENERIC if you get errors here. */
96 #include "miibus_if.h"
99 static const char rcsid[] =
100 "$FreeBSD: src/sys/dev/usb/if_aue.c,v 1.19.2.18 2003/06/14 15:56:48 trhodes Exp $";
104 * Various supported device vendors/products.
106 Static struct aue_type aue_devs[] = {
107 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1, PNA|PII },
108 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2, PII },
109 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000, LSYS },
110 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4, PNA },
111 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5, PNA },
112 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6, PII },
113 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7, PII },
114 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8, PII },
115 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9, PNA },
116 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10, 0 },
117 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA, 0 },
118 { USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC, 0 },
119 { USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001, PII },
120 { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, PNA },
121 { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII, PII },
122 { USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN, PII },
123 { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, 0 },
124 { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100, PNA },
125 { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100, 0 },
126 { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100, PII },
127 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX, 0 },
128 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS,PII },
129 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4, LSYS|PII },
130 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1, LSYS },
131 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX, LSYS },
132 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA, PNA },
133 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3, LSYS|PII },
134 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2, LSYS|PII },
135 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650, LSYS },
136 { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0, 0 },
137 { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1, LSYS },
138 { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2, 0 },
139 { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3, LSYS },
140 { USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX, PII },
141 { USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET, 0 },
142 { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX, 0 },
143 { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS, PII },
144 { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX, 0 },
145 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1, LSYS|PII },
146 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T, LSYS },
147 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX, LSYS },
148 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1, LSYS|PNA },
149 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA, LSYS },
150 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2, LSYS|PII },
151 { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1, 0 },
152 { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5, 0 },
153 { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5, PII },
154 { USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM, PII },
155 { USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC,PII },
156 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB, 0 },
157 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB, PII },
158 { USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100, 0 },
162 Static struct usb_qdat aue_qdat;
164 Static int aue_match(device_t);
165 Static int aue_attach(device_t);
166 Static int aue_detach(device_t);
168 Static void aue_reset_pegasus_II(struct aue_softc *);
169 Static int aue_tx_list_init(struct aue_softc *);
170 Static int aue_rx_list_init(struct aue_softc *);
171 Static int aue_newbuf(struct aue_softc *, struct aue_chain *, struct mbuf *);
172 Static int aue_encap(struct aue_softc *, struct mbuf *, int);
174 Static void aue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
176 Static void aue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
177 Static void aue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
178 Static void aue_tick(void *);
179 Static void aue_rxstart(struct ifnet *);
180 Static void aue_start(struct ifnet *);
181 Static int aue_ioctl(struct ifnet *, u_long, caddr_t);
182 Static void aue_init(void *);
183 Static void aue_stop(struct aue_softc *);
184 Static void aue_watchdog(struct ifnet *);
185 Static void aue_shutdown(device_t);
186 Static int aue_ifmedia_upd(struct ifnet *);
187 Static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
189 Static void aue_eeprom_getword(struct aue_softc *, int, u_int16_t *);
190 Static void aue_read_eeprom(struct aue_softc *, caddr_t, int, int, int);
191 Static int aue_miibus_readreg(device_t, int, int);
192 Static int aue_miibus_writereg(device_t, int, int, int);
193 Static void aue_miibus_statchg(device_t);
195 Static void aue_setmulti(struct aue_softc *);
196 Static u_int32_t aue_crc(caddr_t);
197 Static void aue_reset(struct aue_softc *);
199 Static int csr_read_1(struct aue_softc *, int);
200 Static int csr_write_1(struct aue_softc *, int, int);
201 Static int csr_read_2(struct aue_softc *, int);
202 Static int csr_write_2(struct aue_softc *, int, int);
204 Static device_method_t aue_methods[] = {
205 /* Device interface */
206 DEVMETHOD(device_probe, aue_match),
207 DEVMETHOD(device_attach, aue_attach),
208 DEVMETHOD(device_detach, aue_detach),
209 DEVMETHOD(device_shutdown, aue_shutdown),
212 DEVMETHOD(bus_print_child, bus_generic_print_child),
213 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
216 DEVMETHOD(miibus_readreg, aue_miibus_readreg),
217 DEVMETHOD(miibus_writereg, aue_miibus_writereg),
218 DEVMETHOD(miibus_statchg, aue_miibus_statchg),
223 Static driver_t aue_driver = {
226 sizeof(struct aue_softc)
229 Static devclass_t aue_devclass;
231 DRIVER_MODULE(if_aue, uhub, aue_driver, aue_devclass, usbd_driver_load, 0);
232 DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0);
234 #define AUE_SETBIT(sc, reg, x) \
235 csr_write_1(sc, reg, csr_read_1(sc, reg) | (x))
237 #define AUE_CLRBIT(sc, reg, x) \
238 csr_write_1(sc, reg, csr_read_1(sc, reg) & ~(x))
241 csr_read_1(struct aue_softc *sc, int reg)
243 usb_device_request_t req;
253 req.bmRequestType = UT_READ_VENDOR_DEVICE;
254 req.bRequest = AUE_UR_READREG;
255 USETW(req.wValue, 0);
256 USETW(req.wIndex, reg);
257 USETW(req.wLength, 1);
259 err = usbd_do_request_flags(sc->aue_udev, &req,
260 &val, USBD_NO_TSLEEP, NULL);
271 csr_read_2(struct aue_softc *sc, int reg)
273 usb_device_request_t req;
283 req.bmRequestType = UT_READ_VENDOR_DEVICE;
284 req.bRequest = AUE_UR_READREG;
285 USETW(req.wValue, 0);
286 USETW(req.wIndex, reg);
287 USETW(req.wLength, 2);
289 err = usbd_do_request_flags(sc->aue_udev, &req,
290 &val, USBD_NO_TSLEEP, NULL);
301 csr_write_1(struct aue_softc *sc, int reg, int val)
303 usb_device_request_t req;
312 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
313 req.bRequest = AUE_UR_WRITEREG;
314 USETW(req.wValue, val);
315 USETW(req.wIndex, reg);
316 USETW(req.wLength, 1);
318 err = usbd_do_request_flags(sc->aue_udev, &req,
319 &val, USBD_NO_TSLEEP, NULL);
330 csr_write_2(struct aue_softc *sc, int reg, int val)
332 usb_device_request_t req;
341 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
342 req.bRequest = AUE_UR_WRITEREG;
343 USETW(req.wValue, val);
344 USETW(req.wIndex, reg);
345 USETW(req.wLength, 2);
347 err = usbd_do_request_flags(sc->aue_udev, &req,
348 &val, USBD_NO_TSLEEP, NULL);
359 * Read a word of data stored in the EEPROM at address 'addr.'
362 aue_eeprom_getword(struct aue_softc *sc, int addr, u_int16_t *dest)
367 csr_write_1(sc, AUE_EE_REG, addr);
368 csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
370 for (i = 0; i < AUE_TIMEOUT; i++) {
371 if (csr_read_1(sc, AUE_EE_CTL) &
376 if (i == AUE_TIMEOUT) {
377 printf("aue%d: EEPROM read timed out\n",
381 word = csr_read_2(sc, AUE_EE_DATA);
388 * Read a sequence of words from the EEPROM.
391 aue_read_eeprom(struct aue_softc *sc, caddr_t dest, int off, int cnt, int swap)
394 u_int16_t word = 0, *ptr;
396 for (i = 0; i < cnt; i++) {
397 aue_eeprom_getword(sc, off + i, &word);
398 ptr = (u_int16_t *)(dest + (i * 2));
409 aue_miibus_readreg(device_t dev, int phy, int reg)
411 struct aue_softc *sc;
415 sc = device_get_softc(dev);
418 * The Am79C901 HomePNA PHY actually contains
419 * two transceivers: a 1Mbps HomePNA PHY and a
420 * 10Mbps full/half duplex ethernet PHY with
421 * NWAY autoneg. However in the ADMtek adapter,
422 * only the 1Mbps PHY is actually connected to
423 * anything, so we ignore the 10Mbps one. It
424 * happens to be configured for MII address 3,
425 * so we filter that out.
427 if (sc->aue_info->aue_vid == USB_VENDOR_ADMTEK &&
428 sc->aue_info->aue_did == USB_PRODUCT_ADMTEK_PEGASUS) {
437 csr_write_1(sc, AUE_PHY_ADDR, phy);
438 csr_write_1(sc, AUE_PHY_CTL, reg|AUE_PHYCTL_READ);
440 for (i = 0; i < AUE_TIMEOUT; i++) {
441 if (csr_read_1(sc, AUE_PHY_CTL) &
446 if (i == AUE_TIMEOUT) {
447 printf("aue%d: MII read timed out\n",
451 val = csr_read_2(sc, AUE_PHY_DATA);
457 aue_miibus_writereg(device_t dev, int phy, int reg, int data)
459 struct aue_softc *sc;
465 sc = device_get_softc(dev);
467 csr_write_2(sc, AUE_PHY_DATA, data);
468 csr_write_1(sc, AUE_PHY_ADDR, phy);
469 csr_write_1(sc, AUE_PHY_CTL, reg|AUE_PHYCTL_WRITE);
471 for (i = 0; i < AUE_TIMEOUT; i++) {
472 if (csr_read_1(sc, AUE_PHY_CTL) &
477 if (i == AUE_TIMEOUT) {
478 printf("aue%d: MII read timed out\n",
486 aue_miibus_statchg(device_t dev)
488 struct aue_softc *sc;
489 struct mii_data *mii;
491 sc = device_get_softc(dev);
492 mii = device_get_softc(sc->aue_miibus);
494 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB|AUE_CTL0_TX_ENB);
495 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) {
496 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
498 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
501 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) {
502 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
504 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
506 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB|AUE_CTL0_TX_ENB);
509 * Set the LED modes on the LinkSys adapter.
510 * This turns on the 'dual link LED' bin in the auxmode
511 * register of the Broadcom PHY.
513 if (sc->aue_info->aue_flags & LSYS) {
515 auxmode = aue_miibus_readreg(dev, 0, 0x1b);
516 aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04);
522 #define AUE_POLY 0xEDB88320
526 aue_crc(caddr_t addr)
528 u_int32_t idx, bit, data, crc;
530 /* Compute CRC for the address value. */
531 crc = 0xFFFFFFFF; /* initial value */
533 for (idx = 0; idx < 6; idx++) {
534 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
535 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
538 return (crc & ((1 << AUE_BITS) - 1));
542 aue_setmulti(struct aue_softc *sc)
545 struct ifmultiaddr *ifma;
548 ifp = &sc->arpcom.ac_if;
550 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
551 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
555 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
557 /* first, zot all the existing hash bits */
558 for (i = 0; i < 8; i++)
559 csr_write_1(sc, AUE_MAR0 + i, 0);
561 /* now program new ones */
562 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
563 ifma = ifma->ifma_link.le_next) {
564 if (ifma->ifma_addr->sa_family != AF_LINK)
566 h = aue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
567 AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7));
574 aue_reset_pegasus_II(struct aue_softc *sc)
576 /* Magic constants taken from Linux driver. */
577 csr_write_1(sc, AUE_REG_1D, 0);
578 csr_write_1(sc, AUE_REG_7B, 2);
580 if ((sc->aue_flags & HAS_HOME_PNA) && mii_mode)
581 csr_write_1(sc, AUE_REG_81, 6);
584 csr_write_1(sc, AUE_REG_81, 2);
588 aue_reset(struct aue_softc *sc)
592 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
594 for (i = 0; i < AUE_TIMEOUT; i++) {
595 if (!(csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
599 if (i == AUE_TIMEOUT)
600 printf("aue%d: reset failed\n", sc->aue_unit);
603 * The PHY(s) attached to the Pegasus chip may be held
604 * in reset until we flip on the GPIO outputs. Make sure
605 * to set the GPIO pins high so that the PHY(s) will
608 * Note: We force all of the GPIO pins low first, *then*
609 * enable the ones we want.
611 csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0);
612 csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0|AUE_GPIO_SEL1);
614 /* Grrr. LinkSys has to be different from everyone else. */
615 if (sc->aue_info->aue_flags & LSYS) {
616 csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1);
617 csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1|
621 if (sc->aue_info->aue_flags & PII)
622 aue_reset_pegasus_II(sc);
624 /* Wait a little while for the chip to get its brains in order. */
631 * Probe for a Pegasus chip.
635 USB_MATCH_START(aue, uaa);
643 if (uaa->vendor == t->aue_vid &&
644 uaa->product == t->aue_did) {
645 return(UMATCH_VENDOR_PRODUCT);
654 * Attach the interface. Allocate softc structures, do ifmedia
655 * setup and ethernet/BPF attach.
659 USB_ATTACH_START(aue, sc, uaa);
662 u_char eaddr[ETHER_ADDR_LEN];
664 usb_interface_descriptor_t *id;
665 usb_endpoint_descriptor_t *ed;
671 bzero(sc, sizeof(struct aue_softc));
672 sc->aue_iface = uaa->iface;
673 sc->aue_udev = uaa->device;
674 sc->aue_unit = device_get_unit(self);
676 if (usbd_set_config_no(sc->aue_udev, AUE_CONFIG_NO, 0)) {
677 printf("aue%d: getting interface handle failed\n",
680 USB_ATTACH_ERROR_RETURN;
685 if (uaa->vendor == t->aue_vid &&
686 uaa->product == t->aue_did) {
693 id = usbd_get_interface_descriptor(uaa->iface);
695 usbd_devinfo(uaa->device, 0, devinfo);
696 device_set_desc_copy(self, devinfo);
697 printf("%s: %s\n", USBDEVNAME(self), devinfo);
699 /* Find endpoints. */
700 for (i = 0; i < id->bNumEndpoints; i++) {
701 ed = usbd_interface2endpoint_descriptor(uaa->iface, i);
703 printf("aue%d: couldn't get ep %d\n",
706 USB_ATTACH_ERROR_RETURN;
708 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
709 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
710 sc->aue_ed[AUE_ENDPT_RX] = ed->bEndpointAddress;
711 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
712 (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
713 sc->aue_ed[AUE_ENDPT_TX] = ed->bEndpointAddress;
714 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
715 (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) {
716 sc->aue_ed[AUE_ENDPT_INTR] = ed->bEndpointAddress;
720 /* Reset the adapter. */
724 * Get station address from the EEPROM.
726 aue_read_eeprom(sc, (caddr_t)&eaddr, 0, 3, 0);
729 * A Pegasus chip was detected. Inform the world.
731 printf("aue%d: Ethernet address: %6D\n", sc->aue_unit, eaddr, ":");
733 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
735 ifp = &sc->arpcom.ac_if;
737 ifp->if_unit = sc->aue_unit;
738 ifp->if_name = "aue";
739 ifp->if_mtu = ETHERMTU;
740 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
741 ifp->if_ioctl = aue_ioctl;
742 ifp->if_output = ether_output;
743 ifp->if_start = aue_start;
744 ifp->if_watchdog = aue_watchdog;
745 ifp->if_init = aue_init;
746 ifp->if_baudrate = 10000000;
747 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
751 * NOTE: Doing this causes child devices to be attached to us,
752 * which we would normally disconnect at in the detach routine
753 * using device_delete_child(). However the USB code is set up
754 * such that when this driver is removed, all children devices
755 * are removed as well. In effect, the USB code ends up detaching
756 * all of our children for us, so we don't have to do is ourselves
757 * in aue_detach(). It's important to point this out since if
758 * we *do* try to detach the child devices ourselves, we will
759 * end up getting the children deleted twice, which will crash
762 if (mii_phy_probe(self, &sc->aue_miibus,
763 aue_ifmedia_upd, aue_ifmedia_sts)) {
764 printf("aue%d: MII without any PHY!\n", sc->aue_unit);
766 USB_ATTACH_ERROR_RETURN;
770 aue_qdat.if_rxstart = aue_rxstart;
773 * Call MI attach routine.
775 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
776 callout_handle_init(&sc->aue_stat_ch);
777 usb_register_netisr();
781 USB_ATTACH_SUCCESS_RETURN;
785 aue_detach(device_ptr_t dev)
787 struct aue_softc *sc;
793 sc = device_get_softc(dev);
794 ifp = &sc->arpcom.ac_if;
797 untimeout(aue_tick, sc, sc->aue_stat_ch);
798 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
800 if (sc->aue_ep[AUE_ENDPT_TX] != NULL)
801 usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]);
802 if (sc->aue_ep[AUE_ENDPT_RX] != NULL)
803 usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]);
805 if (sc->aue_ep[AUE_ENDPT_INTR] != NULL)
806 usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
814 * Initialize an RX descriptor and attach an MBUF cluster.
817 aue_newbuf(struct aue_softc *sc, struct aue_chain *c, struct mbuf *m)
819 struct mbuf *m_new = NULL;
822 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
824 printf("aue%d: no memory for rx list "
825 "-- packet dropped!\n", sc->aue_unit);
829 MCLGET(m_new, M_DONTWAIT);
830 if (!(m_new->m_flags & M_EXT)) {
831 printf("aue%d: no memory for rx list "
832 "-- packet dropped!\n", sc->aue_unit);
836 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
839 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
840 m_new->m_data = m_new->m_ext.ext_buf;
843 m_adj(m_new, ETHER_ALIGN);
850 aue_rx_list_init(struct aue_softc *sc)
852 struct aue_cdata *cd;
857 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
858 c = &cd->aue_rx_chain[i];
861 if (aue_newbuf(sc, c, NULL) == ENOBUFS)
863 if (c->aue_xfer == NULL) {
864 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
865 if (c->aue_xfer == NULL)
874 aue_tx_list_init(struct aue_softc *sc)
876 struct aue_cdata *cd;
881 for (i = 0; i < AUE_TX_LIST_CNT; i++) {
882 c = &cd->aue_tx_chain[i];
886 if (c->aue_xfer == NULL) {
887 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
888 if (c->aue_xfer == NULL)
891 c->aue_buf = malloc(AUE_BUFSZ, M_USBDEV, M_NOWAIT);
892 if (c->aue_buf == NULL)
901 aue_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
903 struct aue_softc *sc;
905 struct aue_intrpkt *p;
911 ifp = &sc->arpcom.ac_if;
913 if (!(ifp->if_flags & IFF_RUNNING)) {
918 if (status != USBD_NORMAL_COMPLETION) {
919 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
923 printf("aue%d: usb error on intr: %s\n", sc->aue_unit,
924 usbd_errstr(status));
925 if (status == USBD_STALLED)
926 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]);
931 usbd_get_xfer_status(xfer, NULL, (void **)&p, NULL, NULL);
936 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL & AUE_TXSTAT0_EXCESSCOLL))
937 ifp->if_collisions++;
945 aue_rxstart(struct ifnet *ifp)
947 struct aue_softc *sc;
951 c = &sc->aue_cdata.aue_rx_chain[sc->aue_cdata.aue_rx_prod];
953 if (aue_newbuf(sc, c, NULL) == ENOBUFS) {
958 /* Setup new transfer. */
959 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX],
960 c, mtod(c->aue_mbuf, char *), AUE_BUFSZ, USBD_SHORT_XFER_OK,
961 USBD_NO_TIMEOUT, aue_rxeof);
962 usbd_transfer(c->aue_xfer);
968 * A frame has been uploaded: pass the resulting mbuf chain up to
969 * the higher level protocols.
972 aue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
974 struct aue_chain *c = priv;
975 struct aue_softc *sc = c->aue_sc;
983 ifp = &sc->arpcom.ac_if;
985 if (!(ifp->if_flags & IFF_RUNNING))
988 if (status != USBD_NORMAL_COMPLETION) {
989 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
991 printf("aue%d: usb error on rx: %s\n", sc->aue_unit,
992 usbd_errstr(status));
993 if (status == USBD_STALLED)
994 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]);
998 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
1000 if (total_len <= 4 + ETHER_CRC_LEN) {
1006 bcopy(mtod(m, char *) + total_len - 4, (char *)&r, sizeof(r));
1008 /* Turn off all the non-error bits in the rx status word. */
1009 r.aue_rxstat &= AUE_RXSTAT_MASK;
1016 /* No errors; receive the packet. */
1017 total_len -= (4 + ETHER_CRC_LEN);
1020 m->m_pkthdr.rcvif = (struct ifnet *)&aue_qdat;
1021 m->m_pkthdr.len = m->m_len = total_len;
1023 /* Put the packet on the special USB input queue. */
1029 /* Setup new transfer. */
1030 usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX],
1031 c, mtod(c->aue_mbuf, char *), AUE_BUFSZ, USBD_SHORT_XFER_OK,
1032 USBD_NO_TIMEOUT, aue_rxeof);
1033 usbd_transfer(xfer);
1039 * A frame was downloaded to the chip. It's safe for us to clean up
1044 aue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
1046 struct aue_softc *sc;
1047 struct aue_chain *c;
1056 ifp = &sc->arpcom.ac_if;
1058 if (status != USBD_NORMAL_COMPLETION) {
1059 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
1063 printf("aue%d: usb error on tx: %s\n", sc->aue_unit,
1064 usbd_errstr(status));
1065 if (status == USBD_STALLED)
1066 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_TX]);
1072 ifp->if_flags &= ~IFF_OACTIVE;
1073 usbd_get_xfer_status(c->aue_xfer, NULL, NULL, NULL, &err);
1075 if (c->aue_mbuf != NULL) {
1076 c->aue_mbuf->m_pkthdr.rcvif = ifp;
1077 usb_tx_done(c->aue_mbuf);
1094 struct aue_softc *sc;
1096 struct mii_data *mii;
1108 ifp = &sc->arpcom.ac_if;
1109 mii = device_get_softc(sc->aue_miibus);
1116 if (!sc->aue_link) {
1118 if (mii->mii_media_status & IFM_ACTIVE &&
1119 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE)
1121 if (ifp->if_snd.ifq_head != NULL)
1125 sc->aue_stat_ch = timeout(aue_tick, sc, hz);
1133 aue_encap(struct aue_softc *sc, struct mbuf *m, int idx)
1136 struct aue_chain *c;
1139 c = &sc->aue_cdata.aue_tx_chain[idx];
1142 * Copy the mbuf data into a contiguous buffer, leaving two
1143 * bytes at the beginning to hold the frame length.
1145 m_copydata(m, 0, m->m_pkthdr.len, c->aue_buf + 2);
1148 total_len = m->m_pkthdr.len + 2;
1151 * The ADMtek documentation says that the packet length is
1152 * supposed to be specified in the first two bytes of the
1153 * transfer, however it actually seems to ignore this info
1154 * and base the frame size on the bulk transfer length.
1156 c->aue_buf[0] = (u_int8_t)m->m_pkthdr.len;
1157 c->aue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
1159 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_TX],
1160 c, c->aue_buf, total_len, USBD_FORCE_SHORT_XFER,
1164 err = usbd_transfer(c->aue_xfer);
1165 if (err != USBD_IN_PROGRESS) {
1170 sc->aue_cdata.aue_tx_cnt++;
1176 aue_start(struct ifnet *ifp)
1178 struct aue_softc *sc;
1179 struct mbuf *m_head = NULL;
1186 if (ifp->if_flags & IFF_OACTIVE)
1189 IF_DEQUEUE(&ifp->if_snd, m_head);
1193 if (aue_encap(sc, m_head, 0)) {
1194 IF_PREPEND(&ifp->if_snd, m_head);
1195 ifp->if_flags |= IFF_OACTIVE;
1200 * If there's a BPF listener, bounce a copy of this frame
1204 bpf_mtap(ifp, m_head);
1206 ifp->if_flags |= IFF_OACTIVE;
1209 * Set a timeout in case the chip goes out to lunch.
1219 struct aue_softc *sc = xsc;
1220 struct ifnet *ifp = &sc->arpcom.ac_if;
1221 struct mii_data *mii;
1222 struct aue_chain *c;
1226 if (ifp->if_flags & IFF_RUNNING)
1232 * Cancel pending I/O and free all RX/TX buffers.
1236 mii = device_get_softc(sc->aue_miibus);
1238 /* Set MAC address */
1239 for (i = 0; i < ETHER_ADDR_LEN; i++)
1240 csr_write_1(sc, AUE_PAR0 + i, sc->arpcom.ac_enaddr[i]);
1242 /* If we want promiscuous mode, set the allframes bit. */
1243 if (ifp->if_flags & IFF_PROMISC) {
1244 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1246 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1250 if (aue_tx_list_init(sc) == ENOBUFS) {
1251 printf("aue%d: tx list init failed\n", sc->aue_unit);
1257 if (aue_rx_list_init(sc) == ENOBUFS) {
1258 printf("aue%d: rx list init failed\n", sc->aue_unit);
1263 #ifdef AUE_INTR_PIPE
1264 sc->aue_cdata.aue_ibuf = malloc(AUE_INTR_PKTLEN, M_USBDEV, M_NOWAIT);
1267 /* Load the multicast filter. */
1270 /* Enable RX and TX */
1271 csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND|AUE_CTL0_RX_ENB);
1272 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
1273 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
1276 /* Open RX and TX pipes. */
1277 err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_RX],
1278 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_RX]);
1280 printf("aue%d: open rx pipe failed: %s\n",
1281 sc->aue_unit, usbd_errstr(err));
1285 err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX],
1286 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]);
1288 printf("aue%d: open tx pipe failed: %s\n",
1289 sc->aue_unit, usbd_errstr(err));
1294 #ifdef AUE_INTR_PIPE
1295 err = usbd_open_pipe_intr(sc->aue_iface, sc->aue_ed[AUE_ENDPT_INTR],
1296 USBD_SHORT_XFER_OK, &sc->aue_ep[AUE_ENDPT_INTR], sc,
1297 sc->aue_cdata.aue_ibuf, AUE_INTR_PKTLEN, aue_intr,
1300 printf("aue%d: open intr pipe failed: %s\n",
1301 sc->aue_unit, usbd_errstr(err));
1307 /* Start up the receive pipe. */
1308 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1309 c = &sc->aue_cdata.aue_rx_chain[i];
1310 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX],
1311 c, mtod(c->aue_mbuf, char *), AUE_BUFSZ,
1312 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, aue_rxeof);
1313 usbd_transfer(c->aue_xfer);
1316 ifp->if_flags |= IFF_RUNNING;
1317 ifp->if_flags &= ~IFF_OACTIVE;
1321 sc->aue_stat_ch = timeout(aue_tick, sc, hz);
1327 * Set media options.
1330 aue_ifmedia_upd(struct ifnet *ifp)
1332 struct aue_softc *sc;
1333 struct mii_data *mii;
1337 mii = device_get_softc(sc->aue_miibus);
1339 if (mii->mii_instance) {
1340 struct mii_softc *miisc;
1341 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
1342 miisc = LIST_NEXT(miisc, mii_list))
1343 mii_phy_reset(miisc);
1351 * Report current media status.
1354 aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1356 struct aue_softc *sc;
1357 struct mii_data *mii;
1361 mii = device_get_softc(sc->aue_miibus);
1363 ifmr->ifm_active = mii->mii_media_active;
1364 ifmr->ifm_status = mii->mii_media_status;
1370 aue_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
1372 struct aue_softc *sc = ifp->if_softc;
1373 struct ifreq *ifr = (struct ifreq *) data;
1374 struct mii_data *mii;
1383 error = ether_ioctl(ifp, command, data);
1386 if (ifp->if_flags & IFF_UP) {
1387 if (ifp->if_flags & IFF_RUNNING &&
1388 ifp->if_flags & IFF_PROMISC &&
1389 !(sc->aue_if_flags & IFF_PROMISC)) {
1390 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1391 } else if (ifp->if_flags & IFF_RUNNING &&
1392 !(ifp->if_flags & IFF_PROMISC) &&
1393 sc->aue_if_flags & IFF_PROMISC) {
1394 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1395 } else if (!(ifp->if_flags & IFF_RUNNING))
1398 if (ifp->if_flags & IFF_RUNNING)
1401 sc->aue_if_flags = ifp->if_flags;
1411 mii = device_get_softc(sc->aue_miibus);
1412 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1425 aue_watchdog(struct ifnet *ifp)
1427 struct aue_softc *sc;
1428 struct aue_chain *c;
1434 printf("aue%d: watchdog timeout\n", sc->aue_unit);
1436 c = &sc->aue_cdata.aue_tx_chain[0];
1437 usbd_get_xfer_status(c->aue_xfer, NULL, NULL, NULL, &stat);
1438 aue_txeof(c->aue_xfer, c, stat);
1440 if (ifp->if_snd.ifq_head != NULL)
1447 * Stop the adapter and free any mbufs allocated to the
1451 aue_stop(struct aue_softc *sc)
1457 ifp = &sc->arpcom.ac_if;
1460 csr_write_1(sc, AUE_CTL0, 0);
1461 csr_write_1(sc, AUE_CTL1, 0);
1463 untimeout(aue_tick, sc, sc->aue_stat_ch);
1465 /* Stop transfers. */
1466 if (sc->aue_ep[AUE_ENDPT_RX] != NULL) {
1467 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1469 printf("aue%d: abort rx pipe failed: %s\n",
1470 sc->aue_unit, usbd_errstr(err));
1472 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1474 printf("aue%d: close rx pipe failed: %s\n",
1475 sc->aue_unit, usbd_errstr(err));
1477 sc->aue_ep[AUE_ENDPT_RX] = NULL;
1480 if (sc->aue_ep[AUE_ENDPT_TX] != NULL) {
1481 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1483 printf("aue%d: abort tx pipe failed: %s\n",
1484 sc->aue_unit, usbd_errstr(err));
1486 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1488 printf("aue%d: close tx pipe failed: %s\n",
1489 sc->aue_unit, usbd_errstr(err));
1491 sc->aue_ep[AUE_ENDPT_TX] = NULL;
1494 #ifdef AUE_INTR_PIPE
1495 if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) {
1496 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1498 printf("aue%d: abort intr pipe failed: %s\n",
1499 sc->aue_unit, usbd_errstr(err));
1501 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1503 printf("aue%d: close intr pipe failed: %s\n",
1504 sc->aue_unit, usbd_errstr(err));
1506 sc->aue_ep[AUE_ENDPT_INTR] = NULL;
1510 /* Free RX resources. */
1511 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1512 if (sc->aue_cdata.aue_rx_chain[i].aue_buf != NULL) {
1513 free(sc->aue_cdata.aue_rx_chain[i].aue_buf, M_USBDEV);
1514 sc->aue_cdata.aue_rx_chain[i].aue_buf = NULL;
1516 if (sc->aue_cdata.aue_rx_chain[i].aue_mbuf != NULL) {
1517 m_freem(sc->aue_cdata.aue_rx_chain[i].aue_mbuf);
1518 sc->aue_cdata.aue_rx_chain[i].aue_mbuf = NULL;
1520 if (sc->aue_cdata.aue_rx_chain[i].aue_xfer != NULL) {
1521 usbd_free_xfer(sc->aue_cdata.aue_rx_chain[i].aue_xfer);
1522 sc->aue_cdata.aue_rx_chain[i].aue_xfer = NULL;
1526 /* Free TX resources. */
1527 for (i = 0; i < AUE_TX_LIST_CNT; i++) {
1528 if (sc->aue_cdata.aue_tx_chain[i].aue_buf != NULL) {
1529 free(sc->aue_cdata.aue_tx_chain[i].aue_buf, M_USBDEV);
1530 sc->aue_cdata.aue_tx_chain[i].aue_buf = NULL;
1532 if (sc->aue_cdata.aue_tx_chain[i].aue_mbuf != NULL) {
1533 m_freem(sc->aue_cdata.aue_tx_chain[i].aue_mbuf);
1534 sc->aue_cdata.aue_tx_chain[i].aue_mbuf = NULL;
1536 if (sc->aue_cdata.aue_tx_chain[i].aue_xfer != NULL) {
1537 usbd_free_xfer(sc->aue_cdata.aue_tx_chain[i].aue_xfer);
1538 sc->aue_cdata.aue_tx_chain[i].aue_xfer = NULL;
1542 #ifdef AUE_INTR_PIPE
1543 free(sc->aue_cdata.aue_ibuf, M_USBDEV);
1544 sc->aue_cdata.aue_ibuf = NULL;
1549 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1555 * Stop all chip I/O so that the kernel's probe routines don't
1556 * get confused by errant DMAs when rebooting.
1559 aue_shutdown(device_ptr_t dev)
1561 struct aue_softc *sc;
1563 sc = device_get_softc(dev);