diff options
author | wpaul <wpaul@FreeBSD.org> | 1999-12-28 02:01:18 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1999-12-28 02:01:18 +0000 |
commit | b39a79861ddfb250e941d89c255bcb8cda9481dc (patch) | |
tree | aef1cc68bd5dbcc4e16d18beae0a106b6535f3da /sys | |
parent | 293c4f50f0f5561061a3452727209e02d889e8f9 (diff) | |
download | FreeBSD-src-b39a79861ddfb250e941d89c255bcb8cda9481dc.zip FreeBSD-src-b39a79861ddfb250e941d89c255bcb8cda9481dc.tar.gz |
This commit adds device driver support for the ADMtek AN986 Pegasus
USB ethernet chip. Adapters that use this chip include the LinkSys
USB100TX. There are a few others, but I'm not certain of their
availability in the U.S. I used an ADMtek eval board for development.
Note that while the ADMtek chip is a 100Mbps device, you can't really
get 100Mbps speeds over USB. Regardless, this driver uses miibus to
allow speed and duplex mode selection as well as autonegotiation.
Building and kldloading the driver as a module is also supported.
Note that in order to make this driver work, I had to make what some
may consider an ugly hack to sys/dev/usb/usbdi.c. The usbd_transfer()
function will use tsleep() for synchronous transfers that don't complete
right away. This is a problem since there are times when we need to
do sync transfers from an interrupt context (i.e. when reading registers
from the MAC via the control endpoint), where tsleep() us a no-no.
My hack allows the driver to have the code poll for transfer completion
subject to the xfer->timeout timeout rather that calling tsleep().
This hack is controlled by a quirk entry and is only enabled for the
ADMtek device.
Now, I'm sure there are a few of you out there ready to jump on me
and suggest some other approach that doesn't involve a busy wait. The
only solution that might work is to handle the interrupts in a kernel
thread, where you may have something resembling a process context that
makes it okay to tsleep(). This is lovely, except we don't have any
mechanism like that now, and I'm not about to implement such a thing
myself since it's beyond the scope of driver development. (Translation:
I'll be damned if I know how to do it.) If FreeBSD ever aquires such
a mechanism, I'll be glad to revisit the driver to take advantage of
it. In the meantime, I settled for what I perceived to be the solution
that involved the least amount of code changes. In general, the hit
is pretty light.
Also note that my only USB test box has a UHCI controller: I haven't
I don't have a machine with an OHCI controller available.
Highlights:
- Updated usb_quirks.* to add UQ_NO_TSLEEP quirk for ADMtek part.
- Updated usbdevs and regenerated generated files
- Updated HARDWARE.TXT and RELNOTES.TXT files
- Updated sysinstall/device.c and userconfig.c
- Updated kernel configs -- device aue0 is commented out by default
- Updated /sys/conf/files
- Added new kld module directory
Diffstat (limited to 'sys')
-rw-r--r-- | sys/alpha/conf/GENERIC | 1 | ||||
-rw-r--r-- | sys/alpha/conf/NOTES | 1 | ||||
-rw-r--r-- | sys/amd64/conf/GENERIC | 1 | ||||
-rw-r--r-- | sys/boot/forth/loader.conf | 2 | ||||
-rw-r--r-- | sys/conf/NOTES | 4 | ||||
-rw-r--r-- | sys/conf/files | 1 | ||||
-rw-r--r-- | sys/dev/usb/if_aue.c | 1517 | ||||
-rw-r--r-- | sys/dev/usb/if_auereg.h | 253 | ||||
-rw-r--r-- | sys/dev/usb/usb_quirks.c | 4 | ||||
-rw-r--r-- | sys/dev/usb/usb_quirks.h | 2 | ||||
-rw-r--r-- | sys/dev/usb/usbdevs | 12 | ||||
-rw-r--r-- | sys/dev/usb/usbdevs.h | 18 | ||||
-rw-r--r-- | sys/dev/usb/usbdevs_data.h | 54 | ||||
-rw-r--r-- | sys/dev/usb/usbdi.c | 15 | ||||
-rw-r--r-- | sys/i386/conf/GENERIC | 1 | ||||
-rw-r--r-- | sys/i386/conf/LINT | 4 | ||||
-rw-r--r-- | sys/i386/conf/NEWCARD | 1 | ||||
-rw-r--r-- | sys/i386/conf/NOTES | 4 | ||||
-rw-r--r-- | sys/i386/conf/PCCARD | 1 | ||||
-rw-r--r-- | sys/i386/i386/userconfig.c | 1 | ||||
-rw-r--r-- | sys/modules/Makefile | 4 | ||||
-rw-r--r-- | sys/modules/aue/Makefile | 11 |
22 files changed, 1888 insertions, 24 deletions
diff --git a/sys/alpha/conf/GENERIC b/sys/alpha/conf/GENERIC index cfbe2f8..ed56c3f 100644 --- a/sys/alpha/conf/GENERIC +++ b/sys/alpha/conf/GENERIC @@ -153,3 +153,4 @@ pseudo-device bpf #Berkeley packet filter #device ulpt0 # Printer #controller umass0 # Disks/Mass storage - Requires scbus and da0 #device ums0 # Mouse +#device aue0 # ADMtek USB ethernet diff --git a/sys/alpha/conf/NOTES b/sys/alpha/conf/NOTES index cfbe2f8..ed56c3f 100644 --- a/sys/alpha/conf/NOTES +++ b/sys/alpha/conf/NOTES @@ -153,3 +153,4 @@ pseudo-device bpf #Berkeley packet filter #device ulpt0 # Printer #controller umass0 # Disks/Mass storage - Requires scbus and da0 #device ums0 # Mouse +#device aue0 # ADMtek USB ethernet diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC index 856f6c7..3d570d2 100644 --- a/sys/amd64/conf/GENERIC +++ b/sys/amd64/conf/GENERIC @@ -214,3 +214,4 @@ pseudo-device bpf #Berkeley packet filter #device ulpt0 # Printer #controller umass0 # Disks/Mass storage - Requires scbus and da0 #device ums0 # Mouse +#device aue0 # ADMtek USB ethernet diff --git a/sys/boot/forth/loader.conf b/sys/boot/forth/loader.conf index e1fd0a3..4421df4 100644 --- a/sys/boot/forth/loader.conf +++ b/sys/boot/forth/loader.conf @@ -166,7 +166,7 @@ ukbd_load="NO" # Keyboard ulpt_load="NO" # Printer ums_load="NO" # Mouse umass_load="NO" # Mass Storage Devices - +if_aue_load="NO" # ADMtek USB ethernet ############################################################## ### Other modules ########################################## diff --git a/sys/conf/NOTES b/sys/conf/NOTES index c67e6f2..963f5c0 100644 --- a/sys/conf/NOTES +++ b/sys/conf/NOTES @@ -2328,6 +2328,10 @@ controller umass0 # USB mouse device ums0 # +# ADMtek USB ethernet. Supports the LinkSys USB100TX, +# the Billionton USB100 and the Melco LU-ATX NICs. Also +# works with the ADMtek AN986 Pegasus eval board. +device aue0 # debugging options for the USB subsystem # diff --git a/sys/conf/files b/sys/conf/files index 4dc43fb..2c222ca 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -877,6 +877,7 @@ dev/usb/ulpt.c optional ulpt dev/usb/ukbd.c optional ukbd dev/usb/umass.c optional umass dev/usb/uhub.c optional usb +dev/usb/if_aue.c optional aue isa_if.o optional isa \ dependency "isa_if.c isa_if.h" \ compile-with "${NORMAL_C}" \ diff --git a/sys/dev/usb/if_aue.c b/sys/dev/usb/if_aue.c new file mode 100644 index 0000000..fb46b22 --- /dev/null +++ b/sys/dev/usb/if_aue.c @@ -0,0 +1,1517 @@ +/* + * Copyright (c) 1997, 1998, 1999 + * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * ADMtek AN986 Pegasus USB to ethernet driver. Datasheet is available + * from http://www.admtek.com.tw. + * + * Written by Bill Paul <wpaul@ee.columbia.edu> + * Electrical Engineering Department + * Columbia University, New York City + */ + +/* + * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet + * support: the control endpoint for reading/writing registers, burst + * read endpoint for packet reception, burst write for packet transmission + * and one for "interrupts." The chip uses the same RX filter scheme + * as the other ADMtek ethernet parts: one perfect filter entry for the + * the station address and a 64-bit multicast hash table. The chip supports + * both MII and HomePNA attachments. + * + * Since the maximum data transfer speed of USB is supposed to be 12Mbps, + * you're never really going to get 100Mbps speeds from this device. I + * think the idea is to allow the device to connect to 10 or 100Mbps + * networks, not necessarily to provide 100Mbps performance. Also, since + * the controller uses an external PHY chip, it's possible that board + * designers might simply choose a 10Mbps PHY. + * + * Registers are accessed using usbd_do_request(). Packet transfers are + * done using usbd_transfer() and friends. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/sockio.h> +#include <sys/mbuf.h> +#include <sys/malloc.h> +#include <sys/kernel.h> +#include <sys/socket.h> + +#include <net/if.h> +#include <net/if_arp.h> +#include <net/ethernet.h> +#include <net/if_dl.h> +#include <net/if_media.h> + +#include <net/bpf.h> + +#include <vm/vm.h> /* for vtophys */ +#include <vm/pmap.h> /* for vtophys */ +#include <machine/clock.h> /* for DELAY */ +#include <machine/bus_pio.h> +#include <machine/bus_memio.h> +#include <machine/bus.h> +#include <machine/resource.h> +#include <sys/bus.h> +#include <sys/rman.h> + +#include <dev/usb/usb.h> +#include <dev/usb/usbdi.h> +#include <dev/usb/usbdi_util.h> +#include <dev/usb/usbdivar.h> +#include <dev/usb/usbdevs.h> + +#include <dev/mii/mii.h> +#include <dev/mii/miivar.h> + +#include <dev/usb/if_auereg.h> + +/* "controller miibus0" required. See GENERIC if you get errors here. */ +#include "miibus_if.h" + +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif + +/* + * Various supported device vendors/types and their names. + */ +static struct aue_type aue_devs[] = { + { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, + "ADMtek AN986 Pegasus 10/100BaseTX" }, + { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, + "ADMtek AN986 Pegasus 10/100BaseTX" }, + { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX, + "ADMtek AN986 Pegasus 10/100BaseTX" }, + { 0, 0, NULL } +}; + +static int aue_match __P((device_t)); +static int aue_attach __P((device_t)); +static int aue_detach __P((device_t)); + +static int aue_tx_list_init __P((struct aue_softc *)); +static int aue_rx_list_init __P((struct aue_softc *)); +static int aue_newbuf __P((struct aue_softc *, struct aue_chain *, + struct mbuf *)); +static int aue_encap __P((struct aue_softc *, struct mbuf *, int)); +static void aue_intr __P((usbd_xfer_handle, + usbd_private_handle, usbd_status)); +static void aue_rxeof __P((usbd_xfer_handle, + usbd_private_handle, usbd_status)); +static void aue_txeof __P((usbd_xfer_handle, + usbd_private_handle, usbd_status)); +static void aue_tick __P((void *)); +static void aue_start __P((struct ifnet *)); +static int aue_ioctl __P((struct ifnet *, u_long, caddr_t)); +static void aue_init __P((void *)); +static void aue_stop __P((struct aue_softc *)); +static void aue_watchdog __P((struct ifnet *)); +static void aue_shutdown __P((device_t)); +static int aue_ifmedia_upd __P((struct ifnet *)); +static void aue_ifmedia_sts __P((struct ifnet *, struct ifmediareq *)); + +static void aue_eeprom_getword __P((struct aue_softc *, int, u_int16_t *)); +static void aue_read_eeprom __P((struct aue_softc *, caddr_t, int, + int, int)); +static int aue_miibus_readreg __P((device_t, int, int)); +static int aue_miibus_writereg __P((device_t, int, int, int)); +static void aue_miibus_statchg __P((device_t)); + +static void aue_setmulti __P((struct aue_softc *)); +static u_int32_t aue_crc __P((caddr_t)); +static void aue_reset __P((struct aue_softc *)); + +static int csr_read_1 __P((struct aue_softc *, int)); +static int csr_write_1 __P((struct aue_softc *, int, int)); +static int csr_read_2 __P((struct aue_softc *, int)); +static int csr_write_2 __P((struct aue_softc *, int, int)); + +static device_method_t aue_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, aue_match), + DEVMETHOD(device_attach, aue_attach), + DEVMETHOD(device_detach, aue_detach), + DEVMETHOD(device_shutdown, aue_shutdown), + + /* bus interface */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_driver_added, bus_generic_driver_added), + + /* MII interface */ + DEVMETHOD(miibus_readreg, aue_miibus_readreg), + DEVMETHOD(miibus_writereg, aue_miibus_writereg), + DEVMETHOD(miibus_statchg, aue_miibus_statchg), + + { 0, 0 } +}; + +static driver_t aue_driver = { + "aue", + aue_methods, + sizeof(struct aue_softc) +}; + +static devclass_t aue_devclass; + +DRIVER_MODULE(if_aue, uhub, aue_driver, aue_devclass, usbd_driver_load, 0); +DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0); + +#define AUE_SETBIT(sc, reg, x) \ + csr_write_1(sc, reg, csr_read_1(sc, reg) | (x)) + +#define AUE_CLRBIT(sc, reg, x) \ + csr_write_1(sc, reg, csr_read_1(sc, reg) & ~(x)) + +static int csr_read_1(sc, reg) + struct aue_softc *sc; + int reg; +{ + usb_device_request_t req; + usbd_status err; + u_int8_t val = 0; + int s; + + s = splusb(); + + req.bmRequestType = UT_READ_VENDOR_DEVICE; + req.bRequest = AUE_UR_READREG; + USETW(req.wValue, 0); + USETW(req.wIndex, reg); + USETW(req.wLength, 1); + + err = usbd_do_request(sc->aue_udev, &req, &val); + + splx(s); + + if (err) + return(0); + + return(val); +} + +static int csr_read_2(sc, reg) + struct aue_softc *sc; + int reg; +{ + usb_device_request_t req; + usbd_status err; + u_int16_t val = 0; + int s; + + s = splusb(); + + req.bmRequestType = UT_READ_VENDOR_DEVICE; + req.bRequest = AUE_UR_READREG; + USETW(req.wValue, 0); + USETW(req.wIndex, reg); + USETW(req.wLength, 2); + + err = usbd_do_request(sc->aue_udev, &req, &val); + + splx(s); + + if (err) + return(0); + + return(val); +} + +static int csr_write_1(sc, reg, val) + struct aue_softc *sc; + int reg, val; +{ + usb_device_request_t req; + usbd_status err; + int s; + + s = splusb(); + + req.bmRequestType = UT_WRITE_VENDOR_DEVICE; + req.bRequest = AUE_UR_WRITEREG; + USETW(req.wValue, val); + USETW(req.wIndex, reg); + USETW(req.wLength, 1); + + err = usbd_do_request(sc->aue_udev, &req, &val); + + splx(s); + + if (err) + return(-1); + + return(0); +} + +static int csr_write_2(sc, reg, val) + struct aue_softc *sc; + int reg, val; +{ + usb_device_request_t req; + usbd_status err; + int s; + + s = splusb(); + + req.bmRequestType = UT_WRITE_VENDOR_DEVICE; + req.bRequest = AUE_UR_WRITEREG; + USETW(req.wValue, val); + USETW(req.wIndex, reg); + USETW(req.wLength, 2); + + err = usbd_do_request(sc->aue_udev, &req, &val); + + splx(s); + + if (err) + return(-1); + + return(0); +} + +/* + * Read a word of data stored in the EEPROM at address 'addr.' + */ +static void aue_eeprom_getword(sc, addr, dest) + struct aue_softc *sc; + int addr; + u_int16_t *dest; +{ + register int i; + u_int16_t word = 0; + + csr_write_1(sc, AUE_EE_REG, addr); + csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); + + for (i = 0; i < AUE_TIMEOUT; i++) { + if (csr_read_1(sc, AUE_EE_CTL) & + AUE_EECTL_DONE) + break; + } + + if (i == AUE_TIMEOUT) { + printf("aue%d: EEPROM read timed out\n", + sc->aue_unit); + } + + word = csr_read_2(sc, AUE_EE_DATA); + *dest = word; + + return; +} + +/* + * Read a sequence of words from the EEPROM. + */ +static void aue_read_eeprom(sc, dest, off, cnt, swap) + struct aue_softc *sc; + caddr_t dest; + int off; + int cnt; + int swap; +{ + int i; + u_int16_t word = 0, *ptr; + + for (i = 0; i < cnt; i++) { + aue_eeprom_getword(sc, off + i, &word); + ptr = (u_int16_t *)(dest + (i * 2)); + if (swap) + *ptr = ntohs(word); + else + *ptr = word; + } + + return; +} + +static int aue_miibus_readreg(dev, phy, reg) + device_t dev; + int phy, reg; +{ + struct aue_softc *sc; + int i; + u_int16_t val = 0; + + /* + * The Am79C901 HomePNA PHY actually contains + * two transceivers: a 1Mbps HomePNA PHY and a + * 10Mbps full/half duplex ethernet PHY with + * NWAY autoneg. However in the ADMtek adapter, + * only the 1Mbps PHY is actually connected to + * anything, so we ignore the 10Mbps one. It + * happens to be configured for MII address 3, + * so we filter that out. + */ + if (phy == 3) + return(0); + + if (phy != 1) + return(0); + + sc = device_get_softc(dev); + + csr_write_1(sc, AUE_PHY_ADDR, phy); + csr_write_1(sc, AUE_PHY_CTL, reg|AUE_PHYCTL_READ); + + for (i = 0; i < AUE_TIMEOUT; i++) { + if (csr_read_1(sc, AUE_PHY_CTL) & + AUE_PHYCTL_DONE) + break; + } + + if (i == AUE_TIMEOUT) { + printf("aue%d: MII read timed out\n", + sc->aue_unit); + } + + val = csr_read_2(sc, AUE_PHY_DATA); + + return(val); +} + +static int aue_miibus_writereg(dev, phy, reg, data) + device_t dev; + int phy, reg, data; +{ + struct aue_softc *sc; + int i; + + if (phy == 3) + return(0); + + sc = device_get_softc(dev); + + csr_write_2(sc, AUE_PHY_DATA, data); + csr_write_1(sc, AUE_PHY_ADDR, phy); + csr_write_1(sc, AUE_PHY_CTL, reg|AUE_PHYCTL_WRITE); + + for (i = 0; i < AUE_TIMEOUT; i++) { + if (csr_read_1(sc, AUE_PHY_CTL) & + AUE_PHYCTL_DONE) + break; + } + + if (i == AUE_TIMEOUT) { + printf("aue%d: MII read timed out\n", + sc->aue_unit); + } + + return(0); +} + +static void aue_miibus_statchg(dev) + device_t dev; +{ + struct aue_softc *sc; + struct mii_data *mii; + + sc = device_get_softc(dev); + mii = device_get_softc(sc->aue_miibus); + + AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB|AUE_CTL0_TX_ENB); + if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) { + AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); + } else { + AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); + } + + if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) { + AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); + } else { + AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); + } + AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB|AUE_CTL0_TX_ENB); + + return; +} + +#define AUE_POLY 0xEDB88320 +#define AUE_BITS 6 + +static u_int32_t aue_crc(addr) + caddr_t addr; +{ + u_int32_t idx, bit, data, crc; + + /* Compute CRC for the address value. */ + crc = 0xFFFFFFFF; /* initial value */ + + for (idx = 0; idx < 6; idx++) { + for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) + crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0); + } + + return (crc & ((1 << AUE_BITS) - 1)); +} + +static void aue_setmulti(sc) + struct aue_softc *sc; +{ + struct ifnet *ifp; + struct ifmultiaddr *ifma; + u_int32_t h = 0, i; + + ifp = &sc->arpcom.ac_if; + + if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { + AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); + return; + } + + AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); + + /* first, zot all the existing hash bits */ + for (i = 0; i < 8; i++) + csr_write_1(sc, AUE_MAR0 + i, 0); + + /* now program new ones */ + for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL; + ifma = ifma->ifma_link.le_next) { + if (ifma->ifma_addr->sa_family != AF_LINK) + continue; + h = aue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr)); + AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0xF)); + } + + return; +} + +static void aue_reset(sc) + struct aue_softc *sc; +{ + register int i; + + AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); + + for (i = 0; i < AUE_TIMEOUT; i++) { + if (!(csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) + break; + } + + if (i == AUE_TIMEOUT) + printf("aue%d: reset failed\n", sc->aue_unit); + + /* + * The PHY(s) attached to the Pegasus chip may be held + * in reset until we flip on the GPIO outputs. Make sure + * to set the GPIO pins high so that the PHY(s) will + * be enabled. + */ + csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0|AUE_GPIO_SEL1); + + /* Wait a little while for the chip to get its brains in order. */ + DELAY(1000); + return; +} + +/* + * Probe for a Pegasus chip. + */ +USB_MATCH(aue) +{ + USB_MATCH_START(aue, uaa); + struct aue_type *t; + + if (!uaa->iface) + return(UMATCH_NONE); + + t = aue_devs; + while(t->aue_name != NULL) { + if (uaa->vendor == t->aue_vid && + uaa->product == t->aue_did) { + device_set_desc(self, t->aue_name); + return(UMATCH_VENDOR_PRODUCT); + } + t++; + } + + return(UMATCH_NONE); +} + +/* + * Attach the interface. Allocate softc structures, do ifmedia + * setup and ethernet/BPF attach. + */ +USB_ATTACH(aue) +{ + USB_ATTACH_START(aue, sc, uaa); + char devinfo[1024]; + int s; + u_char eaddr[ETHER_ADDR_LEN]; + struct ifnet *ifp; + usb_interface_descriptor_t *id; + usb_endpoint_descriptor_t *ed; + int i; + + s = splimp(); + + bzero(sc, sizeof(struct aue_softc)); + sc->aue_iface = uaa->iface; + sc->aue_udev = uaa->device; + sc->aue_unit = device_get_unit(self); + + id = usbd_get_interface_descriptor(uaa->iface); + + usbd_devinfo(uaa->device, 0, devinfo); + device_set_desc_copy(self, devinfo); + printf("%s: %s\n", USBDEVNAME(self), devinfo); + + /* Find endpoints. */ + for (i = 0; i < id->bNumEndpoints; i++) { + ed = usbd_interface2endpoint_descriptor(uaa->iface, i); + if (!ed) { + printf("aue%d: couldn't get ep %d\n", + sc->aue_unit, i); + splx(s); + USB_ATTACH_ERROR_RETURN; + } + if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && + (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { + sc->aue_ed[AUE_ENDPT_RX] = ed->bEndpointAddress; + } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && + (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) { + sc->aue_ed[AUE_ENDPT_TX] = ed->bEndpointAddress; + } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && + (ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT) { + sc->aue_ed[AUE_ENDPT_INTR] = ed->bEndpointAddress; + } + } + + /* Reset the adapter. */ + aue_reset(sc); + + /* + * Get station address from the EEPROM. + */ + aue_read_eeprom(sc, (caddr_t)&eaddr, 0, 3, 0); + + /* + * A Pegasus chip was detected. Inform the world. + */ + printf("aue%d: Ethernet address: %6D\n", sc->aue_unit, eaddr, ":"); + + bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); + + ifp = &sc->arpcom.ac_if; + ifp->if_softc = sc; + ifp->if_unit = sc->aue_unit; + ifp->if_name = "aue"; + ifp->if_mtu = ETHERMTU; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = aue_ioctl; + ifp->if_output = ether_output; + ifp->if_start = aue_start; + ifp->if_watchdog = aue_watchdog; + ifp->if_init = aue_init; + ifp->if_baudrate = 10000000; + ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; + + /* + * Do MII setup. + * NOTE: Doing this causes child devices to be attached to us, + * which we would normally disconnect at in the detach routine + * using device_delete_child(). However the USB code is set up + * such that when this driver is removed, all childred devices + * are removed as well. In effect, the USB code ends up detaching + * all of our children for us, so we don't have to do is ourselves + * in aue_detach(). It's important to point this out since if + * we *do* try to detach the child devices ourselves, we will + * end up getting the children deleted twice, which will crash + * the system. + */ + if (mii_phy_probe(self, &sc->aue_miibus, + aue_ifmedia_upd, aue_ifmedia_sts)) { + printf("aue%d: MII without any PHY!\n", sc->aue_unit); + splx(s); + USB_ATTACH_ERROR_RETURN; + } + + /* + * Call MI attach routines. + */ + if_attach(ifp); + ether_ifattach(ifp); + callout_handle_init(&sc->aue_stat_ch); + bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); + + splx(s); + USB_ATTACH_SUCCESS_RETURN; +} + +static int aue_detach(dev) + device_t dev; +{ + struct aue_softc *sc; + struct ifnet *ifp; + int s; + + s = splusb(); + + sc = device_get_softc(dev); + ifp = &sc->arpcom.ac_if; + + untimeout(aue_tick, sc, sc->aue_stat_ch); + if_detach(ifp); + + if (sc->aue_ep[AUE_ENDPT_TX] != NULL) + usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]); + if (sc->aue_ep[AUE_ENDPT_RX] != NULL) + usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]); + if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) + usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]); + + splx(s); + + return(0); +} + +/* + * Initialize an RX descriptor and attach an MBUF cluster. + */ +static int aue_newbuf(sc, c, m) + struct aue_softc *sc; + struct aue_chain *c; + struct mbuf *m; +{ + struct mbuf *m_new = NULL; + + if (m == NULL) { + MGETHDR(m_new, M_DONTWAIT, MT_DATA); + if (m_new == NULL) { + printf("aue%d: no memory for rx list " + "-- packet dropped!\n", sc->aue_unit); + return(ENOBUFS); + } + + MCLGET(m_new, M_DONTWAIT); + if (!(m_new->m_flags & M_EXT)) { + printf("aue%d: no memory for rx list " + "-- packet dropped!\n", sc->aue_unit); + m_freem(m_new); + return(ENOBUFS); + } + m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; + } else { + m_new = m; + m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; + m_new->m_data = m_new->m_ext.ext_buf; + } + + m_adj(m_new, ETHER_ALIGN); + c->aue_mbuf = m_new; + + return(0); +} + +static int aue_rx_list_init(sc) + struct aue_softc *sc; +{ + struct aue_cdata *cd; + struct aue_chain *c; + int i; + + cd = &sc->aue_cdata; + for (i = 0; i < AUE_RX_LIST_CNT; i++) { + c = &cd->aue_rx_chain[i]; + c->aue_sc = sc; + c->aue_idx = i; + c->aue_accum = 0; + if (aue_newbuf(sc, c, NULL) == ENOBUFS) + return(ENOBUFS); + if (c->aue_xfer == NULL) { + c->aue_xfer = usbd_alloc_xfer(sc->aue_udev); + if (c->aue_xfer == NULL) + return(ENOBUFS); + } + } + + return(0); +} + +static int aue_tx_list_init(sc) + struct aue_softc *sc; +{ + struct aue_cdata *cd; + struct aue_chain *c; + int i; + + cd = &sc->aue_cdata; + for (i = 0; i < AUE_TX_LIST_CNT; i++) { + c = &cd->aue_tx_chain[i]; + c->aue_sc = sc; + c->aue_idx = i; + c->aue_mbuf = NULL; + if (c->aue_xfer == NULL) { + c->aue_xfer = usbd_alloc_xfer(sc->aue_udev); + if (c->aue_xfer == NULL) + return(ENOBUFS); + } + c->aue_buf = malloc(AUE_BUFSZ, M_USBDEV, M_NOWAIT); + if (c->aue_buf == NULL) + return(ENOBUFS); + } + + return(0); +} + +static void aue_intr(xfer, priv, status) + usbd_xfer_handle xfer; + usbd_private_handle priv; + usbd_status status; +{ + struct aue_softc *sc; + struct ifnet *ifp; + struct aue_intrpkt *p; + int s; + + s = splimp(); + + sc = priv; + ifp = &sc->arpcom.ac_if; + + if (!(ifp->if_flags & IFF_RUNNING)) { + splx(s); + return; + } + + if (status != USBD_NORMAL_COMPLETION) { + if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { + splx(s); + return; + } + printf("aue%d: usb error on intr: %s\n", sc->aue_unit, + usbd_errstr(status)); + if (status == USBD_STALLED) + usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]); + splx(s); + return; + } + + usbd_get_xfer_status(xfer, NULL, (void **)&p, NULL, NULL); + + if (p->aue_txstat0) + ifp->if_oerrors++; + + if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL & AUE_TXSTAT0_EXCESSCOLL)) + ifp->if_collisions++; + + splx(s); + return; +} + +/* + * A frame has been uploaded: pass the resulting mbuf chain up to + * the higher level protocols. + * + * Grrr. Receiving transfers larger than about 1152 bytes sometimes + * doesn't work. We get an incomplete frame. In order to avoid + * this, we queue up RX transfers that are shorter than a full sized + * frame. If the received frame is larger than our transfer size, + * we snag the rest of the data using a second transfer. Does this + * hurt performance? Yes. But after fighting with this stupid thing + * for three days, I'm willing to settle. I'd rather have reliable + * receive performance that fast but spotty performance. + */ +static void aue_rxeof(xfer, priv, status) + usbd_xfer_handle xfer; + usbd_private_handle priv; + usbd_status status; +{ + struct aue_softc *sc; + struct aue_chain *c; + struct ether_header *eh; + struct mbuf *m; + struct ifnet *ifp; + int total_len = 0; + struct aue_rxpkt r; + int s; + + s = splimp(); + + c = priv; + sc = c->aue_sc; + ifp = &sc->arpcom.ac_if; + + if (!(ifp->if_flags & IFF_RUNNING)) { + return; + splx(s); + } + + if (status != USBD_NORMAL_COMPLETION) { + if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { + splx(s); + return; + } + printf("aue%d: usb error on rx: %s\n", sc->aue_unit, + usbd_errstr(status)); + if (status == USBD_STALLED) + usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]); + goto done; + } + + usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); + + /* + * See if we've already accumulated some data from + * a previous transfer. + */ + if (c->aue_accum) { + total_len += c->aue_accum; + c->aue_accum = 0; + } + + if (total_len <= 4 + ETHER_CRC_LEN) { + ifp->if_ierrors++; + goto done; + } + + m = c->aue_mbuf; + bcopy(mtod(m, char *) + total_len - 4, (char *)&r, sizeof(r)); + + /* Turn off all the non-error bits in the rx status word. */ + r.aue_rxstat &= AUE_RXSTAT_MASK; + + /* + * Check to see if this is just the first chunk of a + * split transfer. We really need a more reliable way + * to detect this. + */ + if (r.aue_pktlen != total_len && total_len == AUE_CUTOFF) { + c->aue_accum = AUE_CUTOFF; + usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX], + c, mtod(c->aue_mbuf, char *) + AUE_CUTOFF, + AUE_CUTOFF, USBD_SHORT_XFER_OK, + USBD_NO_TIMEOUT, aue_rxeof); + usbd_transfer(xfer); + splx(s); + return; + } + + if (r.aue_rxstat) { + ifp->if_ierrors++; + goto done; + } + + /* No errors; receive the packet. */ + total_len -= (4 + ETHER_CRC_LEN); + if (aue_newbuf(sc, c, NULL) == ENOBUFS) { + ifp->if_ierrors++; + goto done; + } + + + ifp->if_ipackets++; + eh = mtod(m, struct ether_header *); + m->m_pkthdr.rcvif = ifp; + m->m_pkthdr.len = m->m_len = total_len; + + /* + * Handle BPF listeners. Let the BPF user see the packet, but + * don't pass it up to the ether_input() layer unless it's + * a broadcast packet, multicast packet, matches our ethernet + * address or the interface is in promiscuous mode. + */ + if (ifp->if_bpf) { + bpf_mtap(ifp, m); + if (ifp->if_flags & IFF_PROMISC && + (bcmp(eh->ether_dhost, sc->arpcom.ac_enaddr, + ETHER_ADDR_LEN) && !(eh->ether_dhost[0] & 1))) { + m_freem(m); + goto done; + } + } + + /* Remove header from mbuf and pass it on. */ + m_adj(m, sizeof(struct ether_header)); + ether_input(ifp, eh, m); + +done: + + /* Setup new transfer. */ + usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX], + c, mtod(c->aue_mbuf, char *), AUE_CUTOFF, USBD_SHORT_XFER_OK, + USBD_NO_TIMEOUT, aue_rxeof); + usbd_transfer(xfer); + + splx(s); + + return; +} + +/* + * A frame was downloaded to the chip. It's safe for us to clean up + * the list buffers. + */ + +static void aue_txeof(xfer, priv, status) + usbd_xfer_handle xfer; + usbd_private_handle priv; + usbd_status status; +{ + struct aue_softc *sc; + struct aue_chain *c; + struct ifnet *ifp; + usbd_status err; + int s; + + s = splimp(); + + c = priv; + sc = c->aue_sc; + ifp = &sc->arpcom.ac_if; + + if (status != USBD_NORMAL_COMPLETION) { + if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { + splx(s); + return; + } + printf("aue%d: usb error on tx: %s\n", sc->aue_unit, + usbd_errstr(status)); + if (status == USBD_STALLED) + usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_TX]); + splx(s); + return; + } + + ifp->if_timer = 0; + ifp->if_flags &= ~IFF_OACTIVE; + usbd_get_xfer_status(c->aue_xfer, NULL, NULL, NULL, &err); + + m_freem(c->aue_mbuf); + c->aue_mbuf = NULL; + + if (err) + ifp->if_oerrors++; + else + ifp->if_opackets++; + + if (ifp->if_snd.ifq_head != NULL) + aue_start(ifp); + + splx(s); + + return; +} + +static void aue_tick(xsc) + void *xsc; +{ + struct aue_softc *sc; + struct ifnet *ifp; + struct mii_data *mii; + int s; + + s = splimp(); + + sc = xsc; + + if (sc == NULL) { + splx(s); + return; + } + + ifp = &sc->arpcom.ac_if; + mii = device_get_softc(sc->aue_miibus); + if (mii == NULL) { + splx(s); + return; + } + + mii_tick(mii); + if (!sc->aue_link) { + mii_pollstat(mii); + if (mii->mii_media_status & IFM_ACTIVE && + IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) + sc->aue_link++; + if (ifp->if_snd.ifq_head != NULL) + aue_start(ifp); + } + + sc->aue_stat_ch = timeout(aue_tick, sc, hz); + + splx(s); + + return; +} + +static int aue_encap(sc, m, idx) + struct aue_softc *sc; + struct mbuf *m; + int idx; +{ + int total_len; + struct aue_chain *c; + usbd_status err; + + c = &sc->aue_cdata.aue_tx_chain[idx]; + + /* + * Copy the mbuf data into a contiguous buffer, leaving two + * bytes at the beginning to hold the frame length. + */ + m_copydata(m, 0, m->m_pkthdr.len, c->aue_buf + 2); + c->aue_mbuf = m; + + /* + * XXX I don't understand why, but transfers that + * are exactly a multiple of 64 bytes in size don't + * work. I'm not sure why. If we detect such a + * transfer, we pad it out by one extra byte. + */ + total_len = m->m_pkthdr.len + 2; + if (!(total_len % 64)) + total_len++; + + /* + * The ADMtek documentation says that the packet length is + * supposed to be specified in the first two bytes of the + * transfer, however it actually seems to ignore this info + * and base the frame size on the bulk transfer length. + */ + c->aue_buf[0] = (u_int8_t)m->m_pkthdr.len; + c->aue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 3) & 0xE0; + + usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_TX], + c, c->aue_buf, total_len, 0, 10000, aue_txeof); + + /* Transmit */ + err = usbd_transfer(c->aue_xfer); + if (err != USBD_IN_PROGRESS) { + aue_stop(sc); + return(EIO); + } + + sc->aue_cdata.aue_tx_cnt++; + + return(0); +} + +static void aue_start(ifp) + struct ifnet *ifp; +{ + struct aue_softc *sc; + struct mbuf *m_head = NULL; + + sc = ifp->if_softc; + + if (!sc->aue_link) + return; + + if (ifp->if_flags & IFF_OACTIVE) + return; + + IF_DEQUEUE(&ifp->if_snd, m_head); + if (m_head == NULL) + return; + + if (aue_encap(sc, m_head, 0)) { + IF_PREPEND(&ifp->if_snd, m_head); + ifp->if_flags |= IFF_OACTIVE; + return; + } + + /* + * If there's a BPF listener, bounce a copy of this frame + * to him. + */ + if (ifp->if_bpf) + bpf_mtap(ifp, m_head); + + ifp->if_flags |= IFF_OACTIVE; + + /* + * Set a timeout in case the chip goes out to lunch. + */ + ifp->if_timer = 5; + + return; +} + +static void aue_init(xsc) + void *xsc; +{ + struct aue_softc *sc = xsc; + struct ifnet *ifp = &sc->arpcom.ac_if; + struct mii_data *mii; + struct aue_chain *c; + usbd_status err; + int i, s; + + if (ifp->if_flags & IFF_RUNNING) + return; + + s = splimp(); + + /* + * Cancel pending I/O and free all RX/TX buffers. + */ + aue_reset(sc); + + mii = device_get_softc(sc->aue_miibus); + + /* Set MAC address */ + for (i = 0; i < ETHER_ADDR_LEN; i++) + csr_write_1(sc, AUE_PAR0 + i, sc->arpcom.ac_enaddr[i]); + + /* If we want promiscuous mode, set the allframes bit. */ + if (ifp->if_flags & IFF_PROMISC) { + AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); + } else { + AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); + } + + /* Init TX ring. */ + if (aue_tx_list_init(sc) == ENOBUFS) { + printf("aue%d: tx list init failed\n", sc->aue_unit); + splx(s); + return; + } + + /* Init RX ring. */ + if (aue_rx_list_init(sc) == ENOBUFS) { + printf("aue%d: rx list init failed\n", sc->aue_unit); + splx(s); + return; + } + + sc->aue_cdata.aue_ibuf = malloc(AUE_INTR_PKTLEN, M_USBDEV, M_NOWAIT); + + /* Load the multicast filter. */ + aue_setmulti(sc); + + /* Enable RX and TX */ + csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND|AUE_CTL0_RX_ENB); + AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); + AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); + + mii_mediachg(mii); + + /* Open RX and TX pipes. */ + err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_RX], + USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_RX]); + if (err) { + printf("aue%d: open rx pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + splx(s); + return; + } + usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX], + USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]); + if (err) { + printf("aue%d: open tx pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + splx(s); + return; + } + + err = usbd_open_pipe_intr(sc->aue_iface, sc->aue_ed[AUE_ENDPT_INTR], + USBD_SHORT_XFER_OK, &sc->aue_ep[AUE_ENDPT_INTR], sc, + sc->aue_cdata.aue_ibuf, AUE_INTR_PKTLEN, aue_intr); + if (err) { + printf("aue%d: open intr pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + splx(s); + return; + } + + /* Start up the receive pipe. */ + for (i = 0; i < AUE_RX_LIST_CNT; i++) { + c = &sc->aue_cdata.aue_rx_chain[i]; + usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX], + c, mtod(c->aue_mbuf, char *), AUE_CUTOFF, + USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, aue_rxeof); + usbd_transfer(c->aue_xfer); + } + + ifp->if_flags |= IFF_RUNNING; + ifp->if_flags &= ~IFF_OACTIVE; + + (void)splx(s); + + sc->aue_stat_ch = timeout(aue_tick, sc, hz); + + return; +} + +/* + * Set media options. + */ +static int aue_ifmedia_upd(ifp) + struct ifnet *ifp; +{ + struct aue_softc *sc; + struct mii_data *mii; + + sc = ifp->if_softc; + + mii = device_get_softc(sc->aue_miibus); + sc->aue_link = 0; + if (mii->mii_instance) { + struct mii_softc *miisc; + for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL; + miisc = LIST_NEXT(miisc, mii_list)) + mii_phy_reset(miisc); + } + mii_mediachg(mii); + + return(0); +} + +/* + * Report current media status. + */ +static void aue_ifmedia_sts(ifp, ifmr) + struct ifnet *ifp; + struct ifmediareq *ifmr; +{ + struct aue_softc *sc; + struct mii_data *mii; + + sc = ifp->if_softc; + + mii = device_get_softc(sc->aue_miibus); + mii_pollstat(mii); + ifmr->ifm_active = mii->mii_media_active; + ifmr->ifm_status = mii->mii_media_status; + + return; +} + +static int aue_ioctl(ifp, command, data) + struct ifnet *ifp; + u_long command; + caddr_t data; +{ + struct aue_softc *sc = ifp->if_softc; + struct ifreq *ifr = (struct ifreq *) data; + struct mii_data *mii; + int s, error = 0; + + s = splimp(); + + switch(command) { + case SIOCSIFADDR: + case SIOCGIFADDR: + case SIOCSIFMTU: + error = ether_ioctl(ifp, command, data); + break; + case SIOCSIFFLAGS: + if (ifp->if_flags & IFF_UP) { + if (ifp->if_flags & IFF_RUNNING && + ifp->if_flags & IFF_PROMISC && + !(sc->aue_if_flags & IFF_PROMISC)) { + AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); + } else if (ifp->if_flags & IFF_RUNNING && + !(ifp->if_flags & IFF_PROMISC) && + sc->aue_if_flags & IFF_PROMISC) { + AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); + } else if (!(ifp->if_flags & IFF_RUNNING)) + aue_init(sc); + } else { + if (ifp->if_flags & IFF_RUNNING) + aue_stop(sc); + } + sc->aue_if_flags = ifp->if_flags; + error = 0; + break; + case SIOCADDMULTI: + case SIOCDELMULTI: + aue_setmulti(sc); + error = 0; + break; + case SIOCGIFMEDIA: + case SIOCSIFMEDIA: + mii = device_get_softc(sc->aue_miibus); + error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); + break; + default: + error = EINVAL; + break; + } + + (void)splx(s); + + return(error); +} + +static void aue_watchdog(ifp) + struct ifnet *ifp; +{ + struct aue_softc *sc; + + sc = ifp->if_softc; + + ifp->if_oerrors++; + printf("aue%d: watchdog timeout\n", sc->aue_unit); + + /* + * The polling business is a kludge to avoid allowing the + * USB code to call tsleep() in usbd_delay_ms(), which will + * kill us since the watchdog routine is invoked from + * interrupt context. + */ + sc->aue_udev->bus->use_polling++; + aue_stop(sc); + aue_init(sc); + sc->aue_udev->bus->use_polling--; + + if (ifp->if_snd.ifq_head != NULL) + aue_start(ifp); + + return; +} + +/* + * Stop the adapter and free any mbufs allocated to the + * RX and TX lists. + */ +static void aue_stop(sc) + struct aue_softc *sc; +{ + usbd_status err; + struct ifnet *ifp; + int i; + + ifp = &sc->arpcom.ac_if; + ifp->if_timer = 0; + + csr_write_1(sc, AUE_CTL0, 0); + csr_write_1(sc, AUE_CTL1, 0); + aue_reset(sc); + untimeout(aue_tick, sc, sc->aue_stat_ch); + + /* Stop transfers. */ + if (sc->aue_ep[AUE_ENDPT_RX] != NULL) { + err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]); + if (err) { + printf("aue%d: abort rx pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + } + err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_RX]); + if (err) { + printf("aue%d: close rx pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + } + sc->aue_ep[AUE_ENDPT_RX] = NULL; + } + + if (sc->aue_ep[AUE_ENDPT_TX] != NULL) { + err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]); + if (err) { + printf("aue%d: abort tx pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + } + err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_TX]); + if (err) { + printf("aue%d: close tx pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + } + sc->aue_ep[AUE_ENDPT_TX] = NULL; + } + + if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) { + err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]); + if (err) { + printf("aue%d: abort intr pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + } + err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_INTR]); + if (err) { + printf("aue%d: close intr pipe failed: %s\n", + sc->aue_unit, usbd_errstr(err)); + } + sc->aue_ep[AUE_ENDPT_INTR] = NULL; + } + + /* Free RX resources. */ + for (i = 0; i < AUE_RX_LIST_CNT; i++) { + if (sc->aue_cdata.aue_rx_chain[i].aue_buf != NULL) { + free(sc->aue_cdata.aue_rx_chain[i].aue_buf, M_USBDEV); + sc->aue_cdata.aue_rx_chain[i].aue_buf = NULL; + } + if (sc->aue_cdata.aue_rx_chain[i].aue_mbuf != NULL) { + m_freem(sc->aue_cdata.aue_rx_chain[i].aue_mbuf); + sc->aue_cdata.aue_rx_chain[i].aue_mbuf = NULL; + } + if (sc->aue_cdata.aue_rx_chain[i].aue_xfer != NULL) { + usbd_free_xfer(sc->aue_cdata.aue_rx_chain[i].aue_xfer); + sc->aue_cdata.aue_rx_chain[i].aue_xfer = NULL; + } + } + + /* Free TX resources. */ + for (i = 0; i < AUE_TX_LIST_CNT; i++) { + if (sc->aue_cdata.aue_tx_chain[i].aue_buf != NULL) { + free(sc->aue_cdata.aue_tx_chain[i].aue_buf, M_USBDEV); + sc->aue_cdata.aue_tx_chain[i].aue_buf = NULL; + } + if (sc->aue_cdata.aue_tx_chain[i].aue_mbuf != NULL) { + m_freem(sc->aue_cdata.aue_tx_chain[i].aue_mbuf); + sc->aue_cdata.aue_tx_chain[i].aue_mbuf = NULL; + } + if (sc->aue_cdata.aue_tx_chain[i].aue_xfer != NULL) { + usbd_free_xfer(sc->aue_cdata.aue_tx_chain[i].aue_xfer); + sc->aue_cdata.aue_tx_chain[i].aue_xfer = NULL; + } + } + + free(sc->aue_cdata.aue_ibuf, M_USBDEV); + sc->aue_cdata.aue_ibuf = NULL; + + sc->aue_link = 0; + + ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); + + return; +} + +/* + * Stop all chip I/O so that the kernel's probe routines don't + * get confused by errant DMAs when rebooting. + */ +static void aue_shutdown(dev) + device_t dev; +{ + struct aue_softc *sc; + + sc = device_get_softc(dev); + + aue_reset(sc); + aue_stop(sc); + + return; +} diff --git a/sys/dev/usb/if_auereg.h b/sys/dev/usb/if_auereg.h new file mode 100644 index 0000000..2bbe567 --- /dev/null +++ b/sys/dev/usb/if_auereg.h @@ -0,0 +1,253 @@ +/* + * Copyright (c) 1997, 1998, 1999 + * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Register definitions for ADMtek Pegasus AN986 USB to Ethernet + * chip. The Pegasus uses a total of four USB endpoints: the control + * endpoint (0), a bulk read endpoint for receiving packets (1), + * a bulk write endpoint for sending packets (2) and an interrupt + * endpoint for passing RX and TX status (3). Endpoint 0 is used + * to read and write the ethernet module's registers. All registers + * are 8 bits wide. + * + * Packet transfer is done in 64 byte chunks. The last chunk in a + * transfer is denoted by having a length less that 64 bytes. For + * the RX case, the data includes an optional RX status word. + */ + +#define AUE_VENDORID_ADMTEK 0x07A6 +#define AUE_DEVICEID_PEGASUS 0x0986 + +#define AUE_VENDORID_BILLIONTON 0x08DD +#define AUE_DEVICEID_USB100 0x0986 + +#define AUE_VENDORID_MELCO 0x0411 +#define AUE_DEVICEID_LUATX 0x0001 + + +#define AUE_UR_READREG 0xF0 +#define AUE_UR_WRITEREG 0xF1 + +/* + * Note that while the ADMtek technically has four + * endpoints, the control endpoint (endpoint 0) is + * regarded as special by the USB code and drivers + * don't have direct access to it. (We access it + * using usbd_do_request() when reading/writing + * registers.) Consequently, our endpoint indexes + * don't match those in the ADMtek Pegasus manual: + * we consider the RX data endpoint to be index 0 + * and work up from there. + */ +#define AUE_ENDPT_RX 0x0 +#define AUE_ENDPT_TX 0x1 +#define AUE_ENDPT_INTR 0x2 +#define AUE_ENDPT_MAX 0x3 + +#define AUE_INTR_PKTLEN 0x8 + +#define AUE_CTL0 0x00 +#define AUE_CTL1 0x01 +#define AUE_CTL2 0x02 +#define AUE_MAR0 0x08 +#define AUE_MAR1 0x09 +#define AUE_MAR2 0x0A +#define AUE_MAR3 0x0B +#define AUE_MAR4 0x0C +#define AUE_MAR5 0x0D +#define AUE_MAR6 0x0E +#define AUE_MAR7 0x0F +#define AUE_MAR AUE_MAR0 +#define AUE_PAR0 0x10 +#define AUE_PAR1 0x11 +#define AUE_PAR2 0x12 +#define AUE_PAR3 0x13 +#define AUE_PAR4 0x14 +#define AUE_PAR5 0x15 +#define AUE_PAR AUE_PAR0 +#define AUE_PAUSE0 0x18 +#define AUE_PAUSE1 0x19 +#define AUE_PAUSE AUE_PAUSE0 +#define AUE_RX_FLOWCTL_CNT 0x1A +#define AUE_RX_FLOWCTL_FIFO 0x1B +#define AUE_EE_REG 0x20 +#define AUE_EE_DATA0 0x21 +#define AUE_EE_DATA1 0x22 +#define AUE_EE_DATA AUE_EE_DATA0 +#define AUE_EE_CTL 0x23 +#define AUE_PHY_ADDR 0x25 +#define AUE_PHY_DATA0 0x26 +#define AUE_PHY_DATA1 0x27 +#define AUE_PHY_DATA AUE_PHY_DATA0 +#define AUE_PHY_CTL 0x28 +#define AUE_USB_STS 0x2A +#define AUE_TXSTAT0 0x2B +#define AUE_TXSTAT1 0x2C +#define AUE_TXSTAT AUE_TXSTAT0 +#define AUE_RXSTAT 0x2D +#define AUE_PKTLOST0 0x2E +#define AUE_PKTLOST1 0x2F +#define AUE_PKTLOST AUE_PKTLOST0 + +#define AUE_GPIO0 0x7E +#define AUE_GPIO1 0x7F + +#define AUE_CTL0_INCLUDE_RXCRC 0x01 +#define AUE_CTL0_ALLMULTI 0x02 +#define AUE_CTL0_STOP_BACKOFF 0x04 +#define AUE_CTL0_RXSTAT_APPEND 0x08 +#define AUE_CTL0_WAKEON_ENB 0x10 +#define AUE_CTL0_RXPAUSE_ENB 0x20 +#define AUE_CTL0_RX_ENB 0x40 +#define AUE_CTL0_TX_ENB 0x80 + +#define AUE_CTL1_HOMELAN 0x04 +#define AUE_CTL1_RESETMAC 0x08 +#define AUE_CTL1_SPEEDSEL 0x10 /* 0 = 10mbps, 1 = 100mbps */ +#define AUE_CTL1_DUPLEX 0x20 /* 0 = half, 1 = full */ +#define AUE_CTL1_DELAYHOME 0x40 + +#define AUE_CTL2_EP3_CLR 0x01 /* reading EP3 clrs status regs */ +#define AUE_CTL2_RX_BADFRAMES 0x02 +#define AUE_CTL2_RX_PROMISC 0x04 +#define AUE_CTL2_LOOPBACK 0x08 +#define AUE_CTL2_EEPROMWR_ENB 0x10 +#define AUE_CTL2_EEPROM_LOAD 0x20 + +#define AUE_EECTL_WRITE 0x01 +#define AUE_EECTL_READ 0x02 +#define AUE_EECTL_DONE 0x04 + +#define AUE_PHYCTL_PHYREG 0x1F +#define AUE_PHYCTL_WRITE 0x20 +#define AUE_PHYCTL_READ 0x40 +#define AUE_PHYCTL_DONE 0x80 + +#define AUE_USBSTS_SUSPEND 0x01 +#define AUE_USBSTS_RESUME 0x02 + +#define AUE_TXSTAT0_JABTIMO 0x04 +#define AUE_TXSTAT0_CARLOSS 0x08 +#define AUE_TXSTAT0_NOCARRIER 0x10 +#define AUE_TXSTAT0_LATECOLL 0x20 +#define AUE_TXSTAT0_EXCESSCOLL 0x40 +#define AUE_TXSTAT0_UNDERRUN 0x80 + +#define AUE_TXSTAT1_PKTCNT 0x0F +#define AUE_TXSTAT1_FIFO_EMPTY 0x40 +#define AUE_TXSTAT1_FIFO_FULL 0x80 + +#define AUE_RXSTAT_OVERRUN 0x01 +#define AUE_RXSTAT_PAUSE 0x02 + +#define AUE_GPIO_IN0 0x01 +#define AUE_GPIO_OUT0 0x02 +#define AUE_GPIO_SEL0 0x04 +#define AUE_GPIO_IN1 0x08 +#define AUE_GPIO_OUT1 0x10 +#define AUE_GPIO_SEL1 0x20 + +struct aue_intrpkt { + u_int8_t aue_txstat0; + u_int8_t aue_txstat1; + u_int8_t aue_rxstat; + u_int8_t aue_rxlostpkt0; + u_int8_t aue_rxlostpkt1; + u_int8_t aue_wakeupstat; + u_int8_t aue_rsvd; +}; + +struct aue_rxpkt { + u_int16_t aue_pktlen; + u_int8_t aue_rxstat; +}; + +#define AUE_RXSTAT_MCAST 0x01 +#define AUE_RXSTAT_GIANT 0x02 +#define AUE_RXSTAT_RUNT 0x04 +#define AUE_RXSTAT_CRCERR 0x08 +#define AUE_RXSTAT_DRIBBLE 0x10 +#define AUE_RXSTAT_MASK 0x1E + +struct aue_type { + u_int16_t aue_vid; + u_int16_t aue_did; + char *aue_name; +}; + +#define AUE_TX_LIST_CNT 1 +#define AUE_RX_LIST_CNT 1 + +struct aue_softc; + +struct aue_chain { + struct aue_softc *aue_sc; + usbd_xfer_handle aue_xfer; + char *aue_buf; + struct mbuf *aue_mbuf; + int aue_accum; + int aue_idx; +}; + +struct aue_cdata { + struct aue_chain aue_tx_chain[AUE_TX_LIST_CNT]; + struct aue_chain aue_rx_chain[AUE_RX_LIST_CNT]; + struct aue_intrpkt *aue_ibuf; + int aue_tx_prod; + int aue_tx_cons; + int aue_tx_cnt; + int aue_rx_prod; +}; + +#define AUE_INC(x, y) (x) = (x + 1) % y + +struct aue_softc { + struct arpcom arpcom; + device_t aue_miibus; + usbd_device_handle aue_udev; + usbd_interface_handle aue_iface; + int aue_ed[AUE_ENDPT_MAX]; + usbd_pipe_handle aue_ep[AUE_ENDPT_MAX]; + int aue_unit; + u_int8_t aue_link; + int aue_if_flags; + struct aue_cdata aue_cdata; + struct callout_handle aue_stat_ch; +}; + +#define AUE_TIMEOUT 1000 +#define ETHER_ALIGN 2 +#define AUE_BUFSZ 1536 +#define AUE_CUTOFF 1088 +#define AUE_MIN_FRAMELEN 60 diff --git a/sys/dev/usb/usb_quirks.c b/sys/dev/usb/usb_quirks.c index a3e746e..e591860 100644 --- a/sys/dev/usb/usb_quirks.c +++ b/sys/dev/usb/usb_quirks.c @@ -66,6 +66,10 @@ static struct usbd_quirk_entry { { USB_VENDOR_LOGITECH, USB_PRODUCT_LOGITECH_N48, 0x110, { UQ_MS_REVZ }}, { USB_VENDOR_ALTEC, USB_PRODUCT_ALTEC_ASC495, 0x000, { UQ_BAD_AUDIO }}, { USB_VENDOR_QTRONIX, USB_PRODUCT_QTRONIX_980N, 0x110, { UQ_SPUR_BUT_UP }}, + { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, 0x101, { UQ_NO_TSLEEP }}, + { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, + 0x101, { UQ_NO_TSLEEP }}, + { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX, 0x101, { UQ_NO_TSLEEP }}, { 0, 0, 0, { 0 } } }; diff --git a/sys/dev/usb/usb_quirks.h b/sys/dev/usb/usb_quirks.h index 6a3c216..3f81bc1 100644 --- a/sys/dev/usb/usb_quirks.h +++ b/sys/dev/usb/usb_quirks.h @@ -48,6 +48,8 @@ struct usbd_quirks { #define UQ_BUS_POWERED 0x20 /* device is bus powered, despite claim */ #define UQ_BAD_AUDIO 0x40 /* device claims audio class, but isn't */ #define UQ_SPUR_BUT_UP 0x80 /* spurious mouse button up events */ +#define UQ_NO_TSLEEP 0x100 /* device needs to work at interrupt + * context, must avoid tsleep! */ }; extern struct usbd_quirks usbd_no_quirk; diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs index 2a80084..f57b72e 100644 --- a/sys/dev/usb/usbdevs +++ b/sys/dev/usb/usbdevs @@ -44,6 +44,7 @@ $FreeBSD$ vendor HP 0x03f0 Hewlett Packard vendor NEC 0x0409 NEC vendor KODAK 0x040a Eastman Kodak Corp. +vendor MELCO 0x0411 Melco Inc. vendor CATC 0x0423 Computer Access Technology Corp. vendor GRAVIS 0x0428 Advanced Gravis Computer Tech. Ltd. vendor LEXMARK 0x043d Lexmark International Inc. @@ -101,9 +102,11 @@ vendor MULTITECH 0x06e0 MultiTech vendor ADS 0x06e1 ADS Technologies vendor MIDIMAN 0x0763 Midiman vendor SANDISK 0x0781 SanDisk Corp +vendor ADMTEK 0x07a6 ADMtek Inc. vendor SIIG 0x07cc SIIG vendor HANDSPRING 0x082d Handspring Inc. vendor ACTIVEWIRE 0x0854 ActiveWire Inc. +vendor BILLIONTON 0x08DD Billionton Systems vendor MOTOROLA 0x1063 Motorola vendor PLX 0x10b5 PLX vendor INSIDEOUT 0x1608 Inside Out Networks @@ -127,6 +130,9 @@ product KODAK DC260 0x0110 Digital Science DC260 product KODAK DC240 0x0120 Digital Science DC240 product KODAK DC280 0x0130 Digital Science DC280 +/* Melco products */ +product MELCO LUATX 0x0001 LU-ATX Ethernet adapter + /* CATC products */ product CATC ANDROMEDA 0x1237 Andromeda hub product CATC CHIEF 0x000d USB Chief Bus & Protocol Analyzer @@ -314,6 +320,9 @@ product MIDIMAN MIDISPORT2X2 0x1001 Midisport 2x2 /* SanDisk products */ product SANDISK IMAGEMATE 0x0001 USB ImageMate +/* ADMtek products */ +product ADMTEK PEGASUS 0x0986 AN986 USB Ethernet adapter + /* SIIG products */ product SIIG DIGIFILMREADER 0x0004 DigiFilm-Combo Reader @@ -324,6 +333,9 @@ product HANDSPRING VISOR 0x0100 Handspring Visor product ACTIVEWIRE IOBOARD 0x0100 I/O Board product ACTIVEWIRE IOBOARD_FW1 0x0101 I/O Board, rev. 1 firmware +/* Billionton products */ +product BILLIONTON USB100 0x0986 USB100 Ethernet adapter + /* Motorola products */ product MOTOROLA MC141555 0x1555 MC141555 hub controller diff --git a/sys/dev/usb/usbdevs.h b/sys/dev/usb/usbdevs.h index 4fbebdd..9b5ac13 100644 --- a/sys/dev/usb/usbdevs.h +++ b/sys/dev/usb/usbdevs.h @@ -51,6 +51,7 @@ #define USB_VENDOR_HP 0x03f0 /* Hewlett Packard */ #define USB_VENDOR_NEC 0x0409 /* NEC */ #define USB_VENDOR_KODAK 0x040a /* Eastman Kodak Corp. */ +#define USB_VENDOR_MELCO 0x0411 /* Melco Inc. */ #define USB_VENDOR_CATC 0x0423 /* Computer Access Technology Corp. */ #define USB_VENDOR_GRAVIS 0x0428 /* Advanced Gravis Computer Tech. Ltd. */ #define USB_VENDOR_LEXMARK 0x043d /* Lexmark International Inc. */ @@ -81,7 +82,6 @@ #define USB_VENDOR_BELKIN 0x050d /* Belkin Components */ #define USB_VENDOR_KAWATSU 0x050f /* Kawatsu Semiconductor, Inc. */ #define USB_VENDOR_APC 0x051d /* American Power Conversion */ -#define USB_VENDOR_NETCHIP 0x0525 /* NetChip Technology */ #define USB_VENDOR_AKS 0x0529 /* Fast Security AG */ #define USB_VENDOR_UNIACCESS 0x0540 /* Universal Access */ #define USB_VENDOR_ANCHOR 0x0547 /* Anchor Chips Inc. */ @@ -109,9 +109,11 @@ #define USB_VENDOR_ADS 0x06e1 /* ADS Technologies */ #define USB_VENDOR_MIDIMAN 0x0763 /* Midiman */ #define USB_VENDOR_SANDISK 0x0781 /* SanDisk Corp */ +#define USB_VENDOR_ADMTEK 0x07a6 /* ADMtek Inc. */ #define USB_VENDOR_SIIG 0x07cc /* SIIG */ #define USB_VENDOR_HANDSPRING 0x082d /* Handspring Inc. */ #define USB_VENDOR_ACTIVEWIRE 0x0854 /* ActiveWire Inc. */ +#define USB_VENDOR_BILLIONTON 0x08DD /* Billionton Systems */ #define USB_VENDOR_MOTOROLA 0x1063 /* Motorola */ #define USB_VENDOR_PLX 0x10b5 /* PLX */ #define USB_VENDOR_INSIDEOUT 0x1608 /* Inside Out Networks */ @@ -135,9 +137,12 @@ #define USB_PRODUCT_KODAK_DC240 0x0120 /* Digital Science DC240 */ #define USB_PRODUCT_KODAK_DC280 0x0130 /* Digital Science DC280 */ +/* Melco products */ +#define USB_PRODUCT_MELCO_LUATX 0x0001 /* LU-ATX Ethernet adapter */ + /* CATC products */ -#define USB_PRODUCT_CATC_CHIEF 0x000d /* USB Chief Bus & Protocol Analyzer */ #define USB_PRODUCT_CATC_ANDROMEDA 0x1237 /* Andromeda hub */ +#define USB_PRODUCT_CATC_CHIEF 0x000d /* USB Chief Bus & Protocol Analyzer */ /* Gravis products */ #define USB_PRODUCT_GRAVIS_GAMEPADPRO 0x4001 /* GamePad Pro */ @@ -226,9 +231,6 @@ /* American Power Conversion products */ #define USB_PRODUCT_APC_UPSPRO500 0x0002 /* Back-UPS Pro 500 */ -/* NetChip Technology Products */ -#define USB_PRODUCT_NETCHIP_TURBOCONNECT 0x1080 /* Turbo-Connect */ - /* AKS products */ #define USB_PRODUCT_AKS_USBHASP 0x0001 /* USB-HASP 0.06 */ @@ -325,6 +327,9 @@ /* SanDisk products */ #define USB_PRODUCT_SANDISK_IMAGEMATE 0x0001 /* USB ImageMate */ +/* ADMtek products */ +#define USB_PRODUCT_ADMTEK_PEGASUS 0x0986 /* AN986 USB Ethernet adapter */ + /* SIIG products */ #define USB_PRODUCT_SIIG_DIGIFILMREADER 0x0004 /* DigiFilm-Combo Reader */ @@ -335,6 +340,9 @@ #define USB_PRODUCT_ACTIVEWIRE_IOBOARD 0x0100 /* I/O Board */ #define USB_PRODUCT_ACTIVEWIRE_IOBOARD_FW1 0x0101 /* I/O Board, rev. 1 firmware */ +/* Billionton products */ +#define USB_PRODUCT_BILLIONTON_USB100 0x0986 /* USB100 Ethernet adapter */ + /* Motorola products */ #define USB_PRODUCT_MOTOROLA_MC141555 0x1555 /* MC141555 hub controller */ diff --git a/sys/dev/usb/usbdevs_data.h b/sys/dev/usb/usbdevs_data.h index 1bfe30a..6aa755e 100644 --- a/sys/dev/usb/usbdevs_data.h +++ b/sys/dev/usb/usbdevs_data.h @@ -88,10 +88,10 @@ struct usb_knowndev usb_knowndevs[] = { "Digital Science DC280", }, { - USB_VENDOR_CATC, USB_PRODUCT_CATC_CHIEF, + USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX, 0, - "Computer Access Technology Corp.", - "USB Chief Bus & Protocol Analyzer", + "Melco Inc.", + "LU-ATX Ethernet adapter", }, { USB_VENDOR_CATC, USB_PRODUCT_CATC_ANDROMEDA, @@ -100,6 +100,12 @@ struct usb_knowndev usb_knowndevs[] = { "Andromeda hub", }, { + USB_VENDOR_CATC, USB_PRODUCT_CATC_CHIEF, + 0, + "Computer Access Technology Corp.", + "USB Chief Bus & Protocol Analyzer", + }, + { USB_VENDOR_GRAVIS, USB_PRODUCT_GRAVIS_GAMEPADPRO, 0, "Advanced Gravis Computer Tech. Ltd.", @@ -310,12 +316,6 @@ struct usb_knowndev usb_knowndevs[] = { "Back-UPS Pro 500", }, { - USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_TURBOCONNECT, - 0, - "NetChip Technology", - "Turbo-Connect", - }, - { USB_VENDOR_AKS, USB_PRODUCT_AKS_USBHASP, 0, "Fast Security AG", @@ -568,6 +568,12 @@ struct usb_knowndev usb_knowndevs[] = { "USB ImageMate", }, { + USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, + 0, + "ADMtek Inc.", + "AN986 USB Ethernet adapter", + }, + { USB_VENDOR_SIIG, USB_PRODUCT_SIIG_DIGIFILMREADER, 0, "SIIG", @@ -592,6 +598,12 @@ struct usb_knowndev usb_knowndevs[] = { "I/O Board, rev. 1 firmware", }, { + USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, + 0, + "Billionton Systems", + "USB100 Ethernet adapter", + }, + { USB_VENDOR_MOTOROLA, USB_PRODUCT_MOTOROLA_MC141555, 0, "Motorola", @@ -634,6 +646,12 @@ struct usb_knowndev usb_knowndevs[] = { NULL, }, { + USB_VENDOR_MELCO, 0, + USB_KNOWNDEV_NOPROD, + "Melco Inc.", + NULL, + }, + { USB_VENDOR_CATC, 0, USB_KNOWNDEV_NOPROD, "Computer Access Technology Corp.", @@ -814,12 +832,6 @@ struct usb_knowndev usb_knowndevs[] = { NULL, }, { - USB_VENDOR_NETCHIP, 0, - USB_KNOWNDEV_NOPROD, - "NetChip Technology", - NULL, - }, - { USB_VENDOR_AKS, 0, USB_KNOWNDEV_NOPROD, "Fast Security AG", @@ -982,6 +994,12 @@ struct usb_knowndev usb_knowndevs[] = { NULL, }, { + USB_VENDOR_ADMTEK, 0, + USB_KNOWNDEV_NOPROD, + "ADMtek Inc.", + NULL, + }, + { USB_VENDOR_SIIG, 0, USB_KNOWNDEV_NOPROD, "SIIG", @@ -1000,6 +1018,12 @@ struct usb_knowndev usb_knowndevs[] = { NULL, }, { + USB_VENDOR_BILLIONTON, 0, + USB_KNOWNDEV_NOPROD, + "Billionton Systems", + NULL, + }, + { USB_VENDOR_MOTOROLA, 0, USB_KNOWNDEV_NOPROD, "Motorola", diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c index bbd5f93..9b9fafd 100644 --- a/sys/dev/usb/usbdi.c +++ b/sys/dev/usb/usbdi.c @@ -56,12 +56,14 @@ #include <sys/proc.h> #include <machine/bus.h> +#include <machine/clock.h> #include <dev/usb/usb.h> #include <dev/usb/usbdi.h> #include <dev/usb/usbdi_util.h> #include <dev/usb/usbdivar.h> #include <dev/usb/usb_mem.h> +#include <dev/usb/usb_quirks.h> #if defined(__FreeBSD__) #include "usb_if.h" @@ -297,7 +299,18 @@ usbd_transfer(xfer) if (!xfer->done) { if (pipe->device->bus->use_polling) panic("usbd_transfer: not done\n"); - tsleep(xfer, PRIBIO, "usbsyn", 0); + if (pipe->device->quirks->uq_flags & UQ_NO_TSLEEP) { + int i; + for (i = 0; i < xfer->timeout + 1; i++) { + DELAY(1); + pipe->device->bus->methods->do_poll(pipe->device->bus); + if (xfer->done) + break; + } + if (!xfer->done) + pipe->methods->abort(xfer); + } else + tsleep(xfer, PRIBIO, "usbsyn", 0); } splx(s); return (xfer->status); diff --git a/sys/i386/conf/GENERIC b/sys/i386/conf/GENERIC index 856f6c7..3d570d2 100644 --- a/sys/i386/conf/GENERIC +++ b/sys/i386/conf/GENERIC @@ -214,3 +214,4 @@ pseudo-device bpf #Berkeley packet filter #device ulpt0 # Printer #controller umass0 # Disks/Mass storage - Requires scbus and da0 #device ums0 # Mouse +#device aue0 # ADMtek USB ethernet diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT index c67e6f2..963f5c0 100644 --- a/sys/i386/conf/LINT +++ b/sys/i386/conf/LINT @@ -2328,6 +2328,10 @@ controller umass0 # USB mouse device ums0 # +# ADMtek USB ethernet. Supports the LinkSys USB100TX, +# the Billionton USB100 and the Melco LU-ATX NICs. Also +# works with the ADMtek AN986 Pegasus eval board. +device aue0 # debugging options for the USB subsystem # diff --git a/sys/i386/conf/NEWCARD b/sys/i386/conf/NEWCARD index 68b8ac0..013585c 100644 --- a/sys/i386/conf/NEWCARD +++ b/sys/i386/conf/NEWCARD @@ -224,5 +224,6 @@ pseudo-device bpf #Berkeley packet filter #device ulpt0 # Printer #controller umass0 # Disks/Mass storage - Requires scbus and da0 #device ums0 # Mouse +#device aue0 # ADMtek USB ethernet options DDB diff --git a/sys/i386/conf/NOTES b/sys/i386/conf/NOTES index c67e6f2..963f5c0 100644 --- a/sys/i386/conf/NOTES +++ b/sys/i386/conf/NOTES @@ -2328,6 +2328,10 @@ controller umass0 # USB mouse device ums0 # +# ADMtek USB ethernet. Supports the LinkSys USB100TX, +# the Billionton USB100 and the Melco LU-ATX NICs. Also +# works with the ADMtek AN986 Pegasus eval board. +device aue0 # debugging options for the USB subsystem # diff --git a/sys/i386/conf/PCCARD b/sys/i386/conf/PCCARD index 0233551..613482b 100644 --- a/sys/i386/conf/PCCARD +++ b/sys/i386/conf/PCCARD @@ -215,3 +215,4 @@ pseudo-device bpf #Berkeley packet filter #device ulpt0 # Printer #controller umass0 # Disks/Mass storage - Requires scbus and da0 #device ums0 # Mouse +#device aue0 # ADMtek USB ethernet diff --git a/sys/i386/i386/userconfig.c b/sys/i386/i386/userconfig.c index 1c7de75..460463d 100644 --- a/sys/i386/i386/userconfig.c +++ b/sys/i386/i386/userconfig.c @@ -377,6 +377,7 @@ static DEV_INFO device_info[] = { {"amd", "Tekram DC-390(T) / AMD 53c974 based PCI SCSI", FLG_FIXED, CLS_STORAGE}, {"plip", "Parallel Port IP link", FLG_FIXED, CLS_NETWORK}, +{"aue", "ADMtek AN986 USB ethernet adapter", FLG_FIXED, CLS_NETWORK}, {"cs", "IBM EtherJet, CS89x0-based Ethernet adapters",0, CLS_NETWORK}, {"ed", "NE1000,NE2000,3C503,WD/SMC80xx Ethernet adapters",0, CLS_NETWORK}, {"el", "3C501 Ethernet adapter", 0, CLS_NETWORK}, diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 8593fab..357f098 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -2,8 +2,8 @@ # XXX present but broken: ip_mroute_mod pcic -SUBDIR= aha amr ccd cd9660 coda dc fdesc fxp if_disc if_ef if_ppp if_sl \ - if_tun ipfilter ipfw joy kernfs md mfs mii mlx msdos \ +SUBDIR= aha amr aue ccd cd9660 coda dc fdesc fxp if_disc if_ef if_ppp \ + if_sl if_tun ipfilter ipfw joy kernfs md mfs mii mlx msdos \ ncp netgraph nfs ntfs nullfs \ nwfs portal procfs rl sf sis sk ste ti tl \ ugen uhid ukbd ulpt umapfs umass umodem ums union usb vn vr wb xl diff --git a/sys/modules/aue/Makefile b/sys/modules/aue/Makefile new file mode 100644 index 0000000..f478794 --- /dev/null +++ b/sys/modules/aue/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +S = ${.CURDIR}/../.. +.PATH: $S/dev/usb +KMOD = if_aue +SRCS = if_aue.c opt_bdg.h opt_usb.h device_if.h bus_if.h +SRCS += miibus_if.h +CFLAGS += ${DEBUG_FLAGS} +KMODDEPS = miibus + +.include <bsd.kmod.mk> |