102ac6454SAndrew Thompson /*- 2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause 3df57947fSPedro F. Giffuni * 402ac6454SAndrew Thompson * Copyright (c) 1997, 1998, 1999, 2000 502ac6454SAndrew Thompson * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 602ac6454SAndrew Thompson * 702ac6454SAndrew Thompson * Copyright (c) 2006 85d38a4d4SEd Schouten * Alfred Perlstein <alfred@FreeBSD.org>. All rights reserved. 902ac6454SAndrew Thompson * 1002ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 1102ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 1202ac6454SAndrew Thompson * are met: 1302ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1402ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1502ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1602ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1702ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1802ac6454SAndrew Thompson * 3. All advertising materials mentioning features or use of this software 1902ac6454SAndrew Thompson * must display the following acknowledgement: 2002ac6454SAndrew Thompson * This product includes software developed by Bill Paul. 2102ac6454SAndrew Thompson * 4. Neither the name of the author nor the names of any co-contributors 2202ac6454SAndrew Thompson * may be used to endorse or promote products derived from this software 2302ac6454SAndrew Thompson * without specific prior written permission. 2402ac6454SAndrew Thompson * 2502ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2602ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2702ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2802ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 2902ac6454SAndrew Thompson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3002ac6454SAndrew Thompson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3102ac6454SAndrew Thompson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3202ac6454SAndrew Thompson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3302ac6454SAndrew Thompson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3402ac6454SAndrew Thompson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 3502ac6454SAndrew Thompson * THE POSSIBILITY OF SUCH DAMAGE. 3602ac6454SAndrew Thompson */ 3702ac6454SAndrew Thompson 3802ac6454SAndrew Thompson #include <sys/cdefs.h> 3902ac6454SAndrew Thompson __FBSDID("$FreeBSD$"); 4002ac6454SAndrew Thompson 4102ac6454SAndrew Thompson /* 4202ac6454SAndrew Thompson * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver. 4302ac6454SAndrew Thompson * Datasheet is available from http://www.admtek.com.tw. 4402ac6454SAndrew Thompson * 4502ac6454SAndrew Thompson * Written by Bill Paul <wpaul@ee.columbia.edu> 4602ac6454SAndrew Thompson * Electrical Engineering Department 4702ac6454SAndrew Thompson * Columbia University, New York City 4802ac6454SAndrew Thompson * 495d38a4d4SEd Schouten * SMP locking by Alfred Perlstein <alfred@FreeBSD.org>. 5002ac6454SAndrew Thompson * RED Inc. 5102ac6454SAndrew Thompson */ 5202ac6454SAndrew Thompson 5302ac6454SAndrew Thompson /* 5402ac6454SAndrew Thompson * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet 5502ac6454SAndrew Thompson * support: the control endpoint for reading/writing registers, burst 5602ac6454SAndrew Thompson * read endpoint for packet reception, burst write for packet transmission 5702ac6454SAndrew Thompson * and one for "interrupts." The chip uses the same RX filter scheme 5802ac6454SAndrew Thompson * as the other ADMtek ethernet parts: one perfect filter entry for the 5902ac6454SAndrew Thompson * the station address and a 64-bit multicast hash table. The chip supports 6002ac6454SAndrew Thompson * both MII and HomePNA attachments. 6102ac6454SAndrew Thompson * 6202ac6454SAndrew Thompson * Since the maximum data transfer speed of USB is supposed to be 12Mbps, 6302ac6454SAndrew Thompson * you're never really going to get 100Mbps speeds from this device. I 6402ac6454SAndrew Thompson * think the idea is to allow the device to connect to 10 or 100Mbps 6502ac6454SAndrew Thompson * networks, not necessarily to provide 100Mbps performance. Also, since 6602ac6454SAndrew Thompson * the controller uses an external PHY chip, it's possible that board 6702ac6454SAndrew Thompson * designers might simply choose a 10Mbps PHY. 6802ac6454SAndrew Thompson * 69a593f6b8SAndrew Thompson * Registers are accessed using uether_do_request(). Packet 70a593f6b8SAndrew Thompson * transfers are done using usbd_transfer() and friends. 7102ac6454SAndrew Thompson */ 7202ac6454SAndrew Thompson 73ed6d949aSAndrew Thompson #include <sys/stdint.h> 74ed6d949aSAndrew Thompson #include <sys/stddef.h> 75ed6d949aSAndrew Thompson #include <sys/param.h> 76ed6d949aSAndrew Thompson #include <sys/queue.h> 77ed6d949aSAndrew Thompson #include <sys/types.h> 78ed6d949aSAndrew Thompson #include <sys/systm.h> 7976039bc8SGleb Smirnoff #include <sys/socket.h> 80ed6d949aSAndrew Thompson #include <sys/kernel.h> 81ed6d949aSAndrew Thompson #include <sys/bus.h> 82ed6d949aSAndrew Thompson #include <sys/module.h> 83ed6d949aSAndrew Thompson #include <sys/lock.h> 84ed6d949aSAndrew Thompson #include <sys/mutex.h> 85ed6d949aSAndrew Thompson #include <sys/condvar.h> 86ed6d949aSAndrew Thompson #include <sys/sysctl.h> 87ed6d949aSAndrew Thompson #include <sys/sx.h> 88ed6d949aSAndrew Thompson #include <sys/unistd.h> 89ed6d949aSAndrew Thompson #include <sys/callout.h> 90ed6d949aSAndrew Thompson #include <sys/malloc.h> 91ed6d949aSAndrew Thompson #include <sys/priv.h> 92ed6d949aSAndrew Thompson 9376039bc8SGleb Smirnoff #include <net/if.h> 9476039bc8SGleb Smirnoff #include <net/if_var.h> 9531c484adSJustin Hibbits #include <net/if_media.h> 9631c484adSJustin Hibbits 9731c484adSJustin Hibbits #include <dev/mii/mii.h> 9831c484adSJustin Hibbits #include <dev/mii/miivar.h> 9976039bc8SGleb Smirnoff 10002ac6454SAndrew Thompson #include <dev/usb/usb.h> 101ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h> 102ed6d949aSAndrew Thompson #include <dev/usb/usbdi_util.h> 103ed6d949aSAndrew Thompson #include "usbdevs.h" 10402ac6454SAndrew Thompson 10502ac6454SAndrew Thompson #define USB_DEBUG_VAR aue_debug 10602ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 107ed6d949aSAndrew Thompson #include <dev/usb/usb_process.h> 10802ac6454SAndrew Thompson 10902ac6454SAndrew Thompson #include <dev/usb/net/usb_ethernet.h> 11002ac6454SAndrew Thompson #include <dev/usb/net/if_auereg.h> 11102ac6454SAndrew Thompson 11231c484adSJustin Hibbits #include "miibus_if.h" 11331c484adSJustin Hibbits 114b850ecc1SAndrew Thompson #ifdef USB_DEBUG 11502ac6454SAndrew Thompson static int aue_debug = 0; 11602ac6454SAndrew Thompson 117*f8d2b1f3SPawel Biernacki static SYSCTL_NODE(_hw_usb, OID_AUTO, aue, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 118*f8d2b1f3SPawel Biernacki "USB aue"); 119ece4b0bdSHans Petter Selasky SYSCTL_INT(_hw_usb_aue, OID_AUTO, debug, CTLFLAG_RWTUN, &aue_debug, 0, 12002ac6454SAndrew Thompson "Debug level"); 12102ac6454SAndrew Thompson #endif 12202ac6454SAndrew Thompson 12302ac6454SAndrew Thompson /* 12402ac6454SAndrew Thompson * Various supported device vendors/products. 12502ac6454SAndrew Thompson */ 126f1a16106SHans Petter Selasky static const STRUCT_USB_HOST_ID aue_devs[] = { 1279e6b5313SAndrew Thompson #define AUE_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) } 1289e6b5313SAndrew Thompson AUE_DEV(3COM, 3C460B, AUE_FLAG_PII), 1299e6b5313SAndrew Thompson AUE_DEV(ABOCOM, DSB650TX_PNA, 0), 1309e6b5313SAndrew Thompson AUE_DEV(ABOCOM, UFE1000, AUE_FLAG_LSYS), 1319e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX10, 0), 1329e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX1, AUE_FLAG_PNA | AUE_FLAG_PII), 1339e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX2, AUE_FLAG_PII), 1349e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX4, AUE_FLAG_PNA), 1359e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX5, AUE_FLAG_PNA), 1369e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX6, AUE_FLAG_PII), 1379e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX7, AUE_FLAG_PII), 1389e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX8, AUE_FLAG_PII), 1399e6b5313SAndrew Thompson AUE_DEV(ABOCOM, XX9, AUE_FLAG_PNA), 1409e6b5313SAndrew Thompson AUE_DEV(ACCTON, SS1001, AUE_FLAG_PII), 1419e6b5313SAndrew Thompson AUE_DEV(ACCTON, USB320_EC, 0), 1429e6b5313SAndrew Thompson AUE_DEV(ADMTEK, PEGASUSII_2, AUE_FLAG_PII), 1439e6b5313SAndrew Thompson AUE_DEV(ADMTEK, PEGASUSII_3, AUE_FLAG_PII), 1449e6b5313SAndrew Thompson AUE_DEV(ADMTEK, PEGASUSII_4, AUE_FLAG_PII), 1459e6b5313SAndrew Thompson AUE_DEV(ADMTEK, PEGASUSII, AUE_FLAG_PII), 1469e6b5313SAndrew Thompson AUE_DEV(ADMTEK, PEGASUS, AUE_FLAG_PNA | AUE_FLAG_DUAL_PHY), 1479e6b5313SAndrew Thompson AUE_DEV(AEI, FASTETHERNET, AUE_FLAG_PII), 1489e6b5313SAndrew Thompson AUE_DEV(ALLIEDTELESYN, ATUSB100, AUE_FLAG_PII), 1499e6b5313SAndrew Thompson AUE_DEV(ATEN, UC110T, AUE_FLAG_PII), 1509e6b5313SAndrew Thompson AUE_DEV(BELKIN, USB2LAN, AUE_FLAG_PII), 1519e6b5313SAndrew Thompson AUE_DEV(BILLIONTON, USB100, 0), 1529e6b5313SAndrew Thompson AUE_DEV(BILLIONTON, USBE100, AUE_FLAG_PII), 1539e6b5313SAndrew Thompson AUE_DEV(BILLIONTON, USBEL100, 0), 1549e6b5313SAndrew Thompson AUE_DEV(BILLIONTON, USBLP100, AUE_FLAG_PNA), 1559e6b5313SAndrew Thompson AUE_DEV(COREGA, FETHER_USB_TXS, AUE_FLAG_PII), 1569e6b5313SAndrew Thompson AUE_DEV(COREGA, FETHER_USB_TX, 0), 1579e6b5313SAndrew Thompson AUE_DEV(DLINK, DSB650TX1, AUE_FLAG_LSYS), 1589e6b5313SAndrew Thompson AUE_DEV(DLINK, DSB650TX2, AUE_FLAG_LSYS | AUE_FLAG_PII), 1599e6b5313SAndrew Thompson AUE_DEV(DLINK, DSB650TX3, AUE_FLAG_LSYS | AUE_FLAG_PII), 1609e6b5313SAndrew Thompson AUE_DEV(DLINK, DSB650TX4, AUE_FLAG_LSYS | AUE_FLAG_PII), 1619e6b5313SAndrew Thompson AUE_DEV(DLINK, DSB650TX_PNA, AUE_FLAG_PNA), 1629e6b5313SAndrew Thompson AUE_DEV(DLINK, DSB650TX, AUE_FLAG_LSYS), 1639e6b5313SAndrew Thompson AUE_DEV(DLINK, DSB650, AUE_FLAG_LSYS), 1649e6b5313SAndrew Thompson AUE_DEV(ELCON, PLAN, AUE_FLAG_PNA | AUE_FLAG_PII), 1659e6b5313SAndrew Thompson AUE_DEV(ELECOM, LDUSB20, AUE_FLAG_PII), 1669e6b5313SAndrew Thompson AUE_DEV(ELECOM, LDUSBLTX, AUE_FLAG_PII), 1679e6b5313SAndrew Thompson AUE_DEV(ELECOM, LDUSBTX0, 0), 1689e6b5313SAndrew Thompson AUE_DEV(ELECOM, LDUSBTX1, AUE_FLAG_LSYS), 1699e6b5313SAndrew Thompson AUE_DEV(ELECOM, LDUSBTX2, 0), 1709e6b5313SAndrew Thompson AUE_DEV(ELECOM, LDUSBTX3, AUE_FLAG_LSYS), 1719e6b5313SAndrew Thompson AUE_DEV(ELSA, USB2ETHERNET, 0), 1729e6b5313SAndrew Thompson AUE_DEV(GIGABYTE, GNBR402W, 0), 1739e6b5313SAndrew Thompson AUE_DEV(HAWKING, UF100, AUE_FLAG_PII), 1749e6b5313SAndrew Thompson AUE_DEV(HP, HN210E, AUE_FLAG_PII), 1759e6b5313SAndrew Thompson AUE_DEV(IODATA, USBETTXS, AUE_FLAG_PII), 1769e6b5313SAndrew Thompson AUE_DEV(IODATA, USBETTX, 0), 1779e6b5313SAndrew Thompson AUE_DEV(KINGSTON, KNU101TX, 0), 1789e6b5313SAndrew Thompson AUE_DEV(LINKSYS, USB100H1, AUE_FLAG_LSYS | AUE_FLAG_PNA), 1799e6b5313SAndrew Thompson AUE_DEV(LINKSYS, USB100TX, AUE_FLAG_LSYS), 1809e6b5313SAndrew Thompson AUE_DEV(LINKSYS, USB10TA, AUE_FLAG_LSYS), 1819e6b5313SAndrew Thompson AUE_DEV(LINKSYS, USB10TX1, AUE_FLAG_LSYS | AUE_FLAG_PII), 1829e6b5313SAndrew Thompson AUE_DEV(LINKSYS, USB10TX2, AUE_FLAG_LSYS | AUE_FLAG_PII), 1839e6b5313SAndrew Thompson AUE_DEV(LINKSYS, USB10T, AUE_FLAG_LSYS), 1849e6b5313SAndrew Thompson AUE_DEV(MELCO, LUA2TX5, AUE_FLAG_PII), 1859e6b5313SAndrew Thompson AUE_DEV(MELCO, LUATX1, 0), 1869e6b5313SAndrew Thompson AUE_DEV(MELCO, LUATX5, 0), 1879e6b5313SAndrew Thompson AUE_DEV(MICROSOFT, MN110, AUE_FLAG_PII), 1889e6b5313SAndrew Thompson AUE_DEV(NETGEAR, FA101, AUE_FLAG_PII), 1899e6b5313SAndrew Thompson AUE_DEV(SIEMENS, SPEEDSTREAM, AUE_FLAG_PII), 1909e6b5313SAndrew Thompson AUE_DEV(SIIG2, USBTOETHER, AUE_FLAG_PII), 1919e6b5313SAndrew Thompson AUE_DEV(SMARTBRIDGES, SMARTNIC, AUE_FLAG_PII), 1929e6b5313SAndrew Thompson AUE_DEV(SMC, 2202USB, 0), 1939e6b5313SAndrew Thompson AUE_DEV(SMC, 2206USB, AUE_FLAG_PII), 1949e6b5313SAndrew Thompson AUE_DEV(SOHOWARE, NUB100, 0), 1959e6b5313SAndrew Thompson AUE_DEV(SOHOWARE, NUB110, AUE_FLAG_PII), 1969e6b5313SAndrew Thompson #undef AUE_DEV 19702ac6454SAndrew Thompson }; 19802ac6454SAndrew Thompson 19902ac6454SAndrew Thompson /* prototypes */ 20002ac6454SAndrew Thompson 20102ac6454SAndrew Thompson static device_probe_t aue_probe; 20202ac6454SAndrew Thompson static device_attach_t aue_attach; 20302ac6454SAndrew Thompson static device_detach_t aue_detach; 20402ac6454SAndrew Thompson static miibus_readreg_t aue_miibus_readreg; 20502ac6454SAndrew Thompson static miibus_writereg_t aue_miibus_writereg; 20602ac6454SAndrew Thompson static miibus_statchg_t aue_miibus_statchg; 20702ac6454SAndrew Thompson 208e0a69b51SAndrew Thompson static usb_callback_t aue_intr_callback; 209e0a69b51SAndrew Thompson static usb_callback_t aue_bulk_read_callback; 210e0a69b51SAndrew Thompson static usb_callback_t aue_bulk_write_callback; 21102ac6454SAndrew Thompson 212e0a69b51SAndrew Thompson static uether_fn_t aue_attach_post; 213e0a69b51SAndrew Thompson static uether_fn_t aue_init; 214e0a69b51SAndrew Thompson static uether_fn_t aue_stop; 215e0a69b51SAndrew Thompson static uether_fn_t aue_start; 216e0a69b51SAndrew Thompson static uether_fn_t aue_tick; 217e0a69b51SAndrew Thompson static uether_fn_t aue_setmulti; 218e0a69b51SAndrew Thompson static uether_fn_t aue_setpromisc; 21902ac6454SAndrew Thompson 22002ac6454SAndrew Thompson static uint8_t aue_csr_read_1(struct aue_softc *, uint16_t); 22102ac6454SAndrew Thompson static uint16_t aue_csr_read_2(struct aue_softc *, uint16_t); 22202ac6454SAndrew Thompson static void aue_csr_write_1(struct aue_softc *, uint16_t, uint8_t); 22302ac6454SAndrew Thompson static void aue_csr_write_2(struct aue_softc *, uint16_t, uint16_t); 224759d4563SPyun YongHyeon static uint16_t aue_eeprom_getword(struct aue_softc *, int); 22502ac6454SAndrew Thompson static void aue_reset(struct aue_softc *); 22602ac6454SAndrew Thompson static void aue_reset_pegasus_II(struct aue_softc *); 22702ac6454SAndrew Thompson 22802ac6454SAndrew Thompson static int aue_ifmedia_upd(struct ifnet *); 22902ac6454SAndrew Thompson static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *); 23002ac6454SAndrew Thompson 231760bc48eSAndrew Thompson static const struct usb_config aue_config[AUE_N_TRANSFER] = { 23202ac6454SAndrew Thompson 23302ac6454SAndrew Thompson [AUE_BULK_DT_WR] = { 23402ac6454SAndrew Thompson .type = UE_BULK, 23502ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 23602ac6454SAndrew Thompson .direction = UE_DIR_OUT, 2374eae601eSAndrew Thompson .bufsize = (MCLBYTES + 2), 2384eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 2394eae601eSAndrew Thompson .callback = aue_bulk_write_callback, 2404eae601eSAndrew Thompson .timeout = 10000, /* 10 seconds */ 24102ac6454SAndrew Thompson }, 24202ac6454SAndrew Thompson 24302ac6454SAndrew Thompson [AUE_BULK_DT_RD] = { 24402ac6454SAndrew Thompson .type = UE_BULK, 24502ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 24602ac6454SAndrew Thompson .direction = UE_DIR_IN, 2474eae601eSAndrew Thompson .bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN), 2484eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 2494eae601eSAndrew Thompson .callback = aue_bulk_read_callback, 25002ac6454SAndrew Thompson }, 25102ac6454SAndrew Thompson 25202ac6454SAndrew Thompson [AUE_INTR_DT_RD] = { 25302ac6454SAndrew Thompson .type = UE_INTERRUPT, 25402ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 25502ac6454SAndrew Thompson .direction = UE_DIR_IN, 2564eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 2574eae601eSAndrew Thompson .bufsize = 0, /* use wMaxPacketSize */ 2584eae601eSAndrew Thompson .callback = aue_intr_callback, 25902ac6454SAndrew Thompson }, 26002ac6454SAndrew Thompson }; 26102ac6454SAndrew Thompson 26202ac6454SAndrew Thompson static device_method_t aue_methods[] = { 26302ac6454SAndrew Thompson /* Device interface */ 26402ac6454SAndrew Thompson DEVMETHOD(device_probe, aue_probe), 26502ac6454SAndrew Thompson DEVMETHOD(device_attach, aue_attach), 26602ac6454SAndrew Thompson DEVMETHOD(device_detach, aue_detach), 26702ac6454SAndrew Thompson 26802ac6454SAndrew Thompson /* MII interface */ 26902ac6454SAndrew Thompson DEVMETHOD(miibus_readreg, aue_miibus_readreg), 27002ac6454SAndrew Thompson DEVMETHOD(miibus_writereg, aue_miibus_writereg), 27102ac6454SAndrew Thompson DEVMETHOD(miibus_statchg, aue_miibus_statchg), 27202ac6454SAndrew Thompson 2734b7ec270SMarius Strobl DEVMETHOD_END 27402ac6454SAndrew Thompson }; 27502ac6454SAndrew Thompson 27602ac6454SAndrew Thompson static driver_t aue_driver = { 27702ac6454SAndrew Thompson .name = "aue", 27802ac6454SAndrew Thompson .methods = aue_methods, 27902ac6454SAndrew Thompson .size = sizeof(struct aue_softc) 28002ac6454SAndrew Thompson }; 28102ac6454SAndrew Thompson 28202ac6454SAndrew Thompson static devclass_t aue_devclass; 28302ac6454SAndrew Thompson 2849aef556dSAndrew Thompson DRIVER_MODULE(aue, uhub, aue_driver, aue_devclass, NULL, 0); 28502ac6454SAndrew Thompson DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0); 28602ac6454SAndrew Thompson MODULE_DEPEND(aue, uether, 1, 1, 1); 28702ac6454SAndrew Thompson MODULE_DEPEND(aue, usb, 1, 1, 1); 28802ac6454SAndrew Thompson MODULE_DEPEND(aue, ether, 1, 1, 1); 28902ac6454SAndrew Thompson MODULE_DEPEND(aue, miibus, 1, 1, 1); 290910cb8feSAndrew Thompson MODULE_VERSION(aue, 1); 291f809f280SWarner Losh USB_PNP_HOST_INFO(aue_devs); 29202ac6454SAndrew Thompson 293760bc48eSAndrew Thompson static const struct usb_ether_methods aue_ue_methods = { 29402ac6454SAndrew Thompson .ue_attach_post = aue_attach_post, 29502ac6454SAndrew Thompson .ue_start = aue_start, 29602ac6454SAndrew Thompson .ue_init = aue_init, 29702ac6454SAndrew Thompson .ue_stop = aue_stop, 29802ac6454SAndrew Thompson .ue_tick = aue_tick, 29902ac6454SAndrew Thompson .ue_setmulti = aue_setmulti, 30002ac6454SAndrew Thompson .ue_setpromisc = aue_setpromisc, 30102ac6454SAndrew Thompson .ue_mii_upd = aue_ifmedia_upd, 30202ac6454SAndrew Thompson .ue_mii_sts = aue_ifmedia_sts, 30302ac6454SAndrew Thompson }; 30402ac6454SAndrew Thompson 30502ac6454SAndrew Thompson #define AUE_SETBIT(sc, reg, x) \ 30602ac6454SAndrew Thompson aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x)) 30702ac6454SAndrew Thompson 30802ac6454SAndrew Thompson #define AUE_CLRBIT(sc, reg, x) \ 30902ac6454SAndrew Thompson aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x)) 31002ac6454SAndrew Thompson 31102ac6454SAndrew Thompson static uint8_t 31202ac6454SAndrew Thompson aue_csr_read_1(struct aue_softc *sc, uint16_t reg) 31302ac6454SAndrew Thompson { 314760bc48eSAndrew Thompson struct usb_device_request req; 315e0a69b51SAndrew Thompson usb_error_t err; 31602ac6454SAndrew Thompson uint8_t val; 31702ac6454SAndrew Thompson 31802ac6454SAndrew Thompson req.bmRequestType = UT_READ_VENDOR_DEVICE; 31902ac6454SAndrew Thompson req.bRequest = AUE_UR_READREG; 32002ac6454SAndrew Thompson USETW(req.wValue, 0); 32102ac6454SAndrew Thompson USETW(req.wIndex, reg); 32202ac6454SAndrew Thompson USETW(req.wLength, 1); 32302ac6454SAndrew Thompson 324a593f6b8SAndrew Thompson err = uether_do_request(&sc->sc_ue, &req, &val, 1000); 32502ac6454SAndrew Thompson if (err) 32602ac6454SAndrew Thompson return (0); 32702ac6454SAndrew Thompson return (val); 32802ac6454SAndrew Thompson } 32902ac6454SAndrew Thompson 33002ac6454SAndrew Thompson static uint16_t 33102ac6454SAndrew Thompson aue_csr_read_2(struct aue_softc *sc, uint16_t reg) 33202ac6454SAndrew Thompson { 333760bc48eSAndrew Thompson struct usb_device_request req; 334e0a69b51SAndrew Thompson usb_error_t err; 33502ac6454SAndrew Thompson uint16_t val; 33602ac6454SAndrew Thompson 33702ac6454SAndrew Thompson req.bmRequestType = UT_READ_VENDOR_DEVICE; 33802ac6454SAndrew Thompson req.bRequest = AUE_UR_READREG; 33902ac6454SAndrew Thompson USETW(req.wValue, 0); 34002ac6454SAndrew Thompson USETW(req.wIndex, reg); 34102ac6454SAndrew Thompson USETW(req.wLength, 2); 34202ac6454SAndrew Thompson 343a593f6b8SAndrew Thompson err = uether_do_request(&sc->sc_ue, &req, &val, 1000); 34402ac6454SAndrew Thompson if (err) 34502ac6454SAndrew Thompson return (0); 34602ac6454SAndrew Thompson return (le16toh(val)); 34702ac6454SAndrew Thompson } 34802ac6454SAndrew Thompson 34902ac6454SAndrew Thompson static void 35002ac6454SAndrew Thompson aue_csr_write_1(struct aue_softc *sc, uint16_t reg, uint8_t val) 35102ac6454SAndrew Thompson { 352760bc48eSAndrew Thompson struct usb_device_request req; 35302ac6454SAndrew Thompson 35402ac6454SAndrew Thompson req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 35502ac6454SAndrew Thompson req.bRequest = AUE_UR_WRITEREG; 35602ac6454SAndrew Thompson req.wValue[0] = val; 35702ac6454SAndrew Thompson req.wValue[1] = 0; 35802ac6454SAndrew Thompson USETW(req.wIndex, reg); 35902ac6454SAndrew Thompson USETW(req.wLength, 1); 36002ac6454SAndrew Thompson 361a593f6b8SAndrew Thompson if (uether_do_request(&sc->sc_ue, &req, &val, 1000)) { 36202ac6454SAndrew Thompson /* error ignored */ 36302ac6454SAndrew Thompson } 36402ac6454SAndrew Thompson } 36502ac6454SAndrew Thompson 36602ac6454SAndrew Thompson static void 36702ac6454SAndrew Thompson aue_csr_write_2(struct aue_softc *sc, uint16_t reg, uint16_t val) 36802ac6454SAndrew Thompson { 369760bc48eSAndrew Thompson struct usb_device_request req; 37002ac6454SAndrew Thompson 37102ac6454SAndrew Thompson req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 37202ac6454SAndrew Thompson req.bRequest = AUE_UR_WRITEREG; 37302ac6454SAndrew Thompson USETW(req.wValue, val); 37402ac6454SAndrew Thompson USETW(req.wIndex, reg); 37502ac6454SAndrew Thompson USETW(req.wLength, 2); 37602ac6454SAndrew Thompson 37702ac6454SAndrew Thompson val = htole16(val); 37802ac6454SAndrew Thompson 379a593f6b8SAndrew Thompson if (uether_do_request(&sc->sc_ue, &req, &val, 1000)) { 38002ac6454SAndrew Thompson /* error ignored */ 38102ac6454SAndrew Thompson } 38202ac6454SAndrew Thompson } 38302ac6454SAndrew Thompson 38402ac6454SAndrew Thompson /* 38502ac6454SAndrew Thompson * Read a word of data stored in the EEPROM at address 'addr.' 38602ac6454SAndrew Thompson */ 387759d4563SPyun YongHyeon static uint16_t 388759d4563SPyun YongHyeon aue_eeprom_getword(struct aue_softc *sc, int addr) 38902ac6454SAndrew Thompson { 39002ac6454SAndrew Thompson int i; 39102ac6454SAndrew Thompson 39202ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_EE_REG, addr); 39302ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); 39402ac6454SAndrew Thompson 39502ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 39602ac6454SAndrew Thompson if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) 39702ac6454SAndrew Thompson break; 398a593f6b8SAndrew Thompson if (uether_pause(&sc->sc_ue, hz / 100)) 39902ac6454SAndrew Thompson break; 40002ac6454SAndrew Thompson } 40102ac6454SAndrew Thompson 40202ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 40302ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "EEPROM read timed out\n"); 40402ac6454SAndrew Thompson 405759d4563SPyun YongHyeon return (aue_csr_read_2(sc, AUE_EE_DATA)); 40602ac6454SAndrew Thompson } 40702ac6454SAndrew Thompson 40802ac6454SAndrew Thompson /* 409759d4563SPyun YongHyeon * Read station address(offset 0) from the EEPROM. 41002ac6454SAndrew Thompson */ 41102ac6454SAndrew Thompson static void 412759d4563SPyun YongHyeon aue_read_mac(struct aue_softc *sc, uint8_t *eaddr) 41302ac6454SAndrew Thompson { 414759d4563SPyun YongHyeon int i, offset; 415759d4563SPyun YongHyeon uint16_t word; 41602ac6454SAndrew Thompson 417759d4563SPyun YongHyeon for (i = 0, offset = 0; i < ETHER_ADDR_LEN / 2; i++) { 418759d4563SPyun YongHyeon word = aue_eeprom_getword(sc, offset + i); 419759d4563SPyun YongHyeon eaddr[i * 2] = (uint8_t)word; 420759d4563SPyun YongHyeon eaddr[i * 2 + 1] = (uint8_t)(word >> 8); 421759d4563SPyun YongHyeon } 42202ac6454SAndrew Thompson } 42302ac6454SAndrew Thompson 42402ac6454SAndrew Thompson static int 42502ac6454SAndrew Thompson aue_miibus_readreg(device_t dev, int phy, int reg) 42602ac6454SAndrew Thompson { 42702ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 42802ac6454SAndrew Thompson int i, locked; 42902ac6454SAndrew Thompson uint16_t val = 0; 43002ac6454SAndrew Thompson 43102ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 43202ac6454SAndrew Thompson if (!locked) 43302ac6454SAndrew Thompson AUE_LOCK(sc); 43402ac6454SAndrew Thompson 43502ac6454SAndrew Thompson /* 43602ac6454SAndrew Thompson * The Am79C901 HomePNA PHY actually contains two transceivers: a 1Mbps 43702ac6454SAndrew Thompson * HomePNA PHY and a 10Mbps full/half duplex ethernet PHY with NWAY 43802ac6454SAndrew Thompson * autoneg. However in the ADMtek adapter, only the 1Mbps PHY is 43902ac6454SAndrew Thompson * actually connected to anything, so we ignore the 10Mbps one. It 44002ac6454SAndrew Thompson * happens to be configured for MII address 3, so we filter that out. 44102ac6454SAndrew Thompson */ 44202ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_DUAL_PHY) { 44302ac6454SAndrew Thompson if (phy == 3) 44402ac6454SAndrew Thompson goto done; 44502ac6454SAndrew Thompson #if 0 44602ac6454SAndrew Thompson if (phy != 1) 44702ac6454SAndrew Thompson goto done; 44802ac6454SAndrew Thompson #endif 44902ac6454SAndrew Thompson } 45002ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 45102ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); 45202ac6454SAndrew Thompson 45302ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 45402ac6454SAndrew Thompson if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 45502ac6454SAndrew Thompson break; 456a593f6b8SAndrew Thompson if (uether_pause(&sc->sc_ue, hz / 100)) 45702ac6454SAndrew Thompson break; 45802ac6454SAndrew Thompson } 45902ac6454SAndrew Thompson 46002ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 46102ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "MII read timed out\n"); 46202ac6454SAndrew Thompson 46302ac6454SAndrew Thompson val = aue_csr_read_2(sc, AUE_PHY_DATA); 46402ac6454SAndrew Thompson 46502ac6454SAndrew Thompson done: 46602ac6454SAndrew Thompson if (!locked) 46702ac6454SAndrew Thompson AUE_UNLOCK(sc); 46802ac6454SAndrew Thompson return (val); 46902ac6454SAndrew Thompson } 47002ac6454SAndrew Thompson 47102ac6454SAndrew Thompson static int 47202ac6454SAndrew Thompson aue_miibus_writereg(device_t dev, int phy, int reg, int data) 47302ac6454SAndrew Thompson { 47402ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 47502ac6454SAndrew Thompson int i; 47602ac6454SAndrew Thompson int locked; 47702ac6454SAndrew Thompson 47802ac6454SAndrew Thompson if (phy == 3) 47902ac6454SAndrew Thompson return (0); 48002ac6454SAndrew Thompson 48102ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 48202ac6454SAndrew Thompson if (!locked) 48302ac6454SAndrew Thompson AUE_LOCK(sc); 48402ac6454SAndrew Thompson 48502ac6454SAndrew Thompson aue_csr_write_2(sc, AUE_PHY_DATA, data); 48602ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 48702ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); 48802ac6454SAndrew Thompson 48902ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 49002ac6454SAndrew Thompson if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 49102ac6454SAndrew Thompson break; 492a593f6b8SAndrew Thompson if (uether_pause(&sc->sc_ue, hz / 100)) 49302ac6454SAndrew Thompson break; 49402ac6454SAndrew Thompson } 49502ac6454SAndrew Thompson 49602ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 497069f9a8bSAlfred Perlstein device_printf(sc->sc_ue.ue_dev, "MII write timed out\n"); 49802ac6454SAndrew Thompson 49902ac6454SAndrew Thompson if (!locked) 50002ac6454SAndrew Thompson AUE_UNLOCK(sc); 50102ac6454SAndrew Thompson return (0); 50202ac6454SAndrew Thompson } 50302ac6454SAndrew Thompson 50402ac6454SAndrew Thompson static void 50502ac6454SAndrew Thompson aue_miibus_statchg(device_t dev) 50602ac6454SAndrew Thompson { 50702ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 50802ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 50902ac6454SAndrew Thompson int locked; 51002ac6454SAndrew Thompson 51102ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 51202ac6454SAndrew Thompson if (!locked) 51302ac6454SAndrew Thompson AUE_LOCK(sc); 51402ac6454SAndrew Thompson 51502ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 51602ac6454SAndrew Thompson if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) 51702ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 51802ac6454SAndrew Thompson else 51902ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 52002ac6454SAndrew Thompson 52102ac6454SAndrew Thompson if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) 52202ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 52302ac6454SAndrew Thompson else 52402ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 52502ac6454SAndrew Thompson 52602ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 52702ac6454SAndrew Thompson 52802ac6454SAndrew Thompson /* 52902ac6454SAndrew Thompson * Set the LED modes on the LinkSys adapter. 53002ac6454SAndrew Thompson * This turns on the 'dual link LED' bin in the auxmode 53102ac6454SAndrew Thompson * register of the Broadcom PHY. 53202ac6454SAndrew Thompson */ 53302ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_LSYS) { 53402ac6454SAndrew Thompson uint16_t auxmode; 53502ac6454SAndrew Thompson 53602ac6454SAndrew Thompson auxmode = aue_miibus_readreg(dev, 0, 0x1b); 53702ac6454SAndrew Thompson aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04); 53802ac6454SAndrew Thompson } 53902ac6454SAndrew Thompson if (!locked) 54002ac6454SAndrew Thompson AUE_UNLOCK(sc); 54102ac6454SAndrew Thompson } 54202ac6454SAndrew Thompson 54302ac6454SAndrew Thompson #define AUE_BITS 6 5449b64a6dbSGleb Smirnoff static u_int 5459b64a6dbSGleb Smirnoff aue_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) 5469b64a6dbSGleb Smirnoff { 5479b64a6dbSGleb Smirnoff uint8_t *hashtbl = arg; 5489b64a6dbSGleb Smirnoff uint32_t h; 5499b64a6dbSGleb Smirnoff 5509b64a6dbSGleb Smirnoff h = ether_crc32_le(LLADDR(sdl), ETHER_ADDR_LEN) & ((1 << AUE_BITS) - 1); 5519b64a6dbSGleb Smirnoff hashtbl[(h >> 3)] |= 1 << (h & 0x7); 5529b64a6dbSGleb Smirnoff 5539b64a6dbSGleb Smirnoff return (1); 5549b64a6dbSGleb Smirnoff } 5559b64a6dbSGleb Smirnoff 55602ac6454SAndrew Thompson static void 557760bc48eSAndrew Thompson aue_setmulti(struct usb_ether *ue) 55802ac6454SAndrew Thompson { 559a593f6b8SAndrew Thompson struct aue_softc *sc = uether_getsc(ue); 560a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 56102ac6454SAndrew Thompson uint32_t i; 56202ac6454SAndrew Thompson uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 56302ac6454SAndrew Thompson 56402ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 56502ac6454SAndrew Thompson 56602ac6454SAndrew Thompson if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 56702ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 56802ac6454SAndrew Thompson return; 56902ac6454SAndrew Thompson } 57002ac6454SAndrew Thompson 57102ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 57202ac6454SAndrew Thompson 57302ac6454SAndrew Thompson /* now program new ones */ 5749b64a6dbSGleb Smirnoff if_foreach_llmaddr(ifp, aue_hash_maddr, hashtbl); 57502ac6454SAndrew Thompson 57602ac6454SAndrew Thompson /* write the hashtable */ 57702ac6454SAndrew Thompson for (i = 0; i != 8; i++) 57802ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]); 57902ac6454SAndrew Thompson } 58002ac6454SAndrew Thompson 58102ac6454SAndrew Thompson static void 58202ac6454SAndrew Thompson aue_reset_pegasus_II(struct aue_softc *sc) 58302ac6454SAndrew Thompson { 58402ac6454SAndrew Thompson /* Magic constants taken from Linux driver. */ 58502ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_1D, 0); 58602ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_7B, 2); 58702ac6454SAndrew Thompson #if 0 58802ac6454SAndrew Thompson if ((sc->sc_flags & HAS_HOME_PNA) && mii_mode) 58902ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_81, 6); 59002ac6454SAndrew Thompson else 59102ac6454SAndrew Thompson #endif 59202ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_81, 2); 59302ac6454SAndrew Thompson } 59402ac6454SAndrew Thompson 59502ac6454SAndrew Thompson static void 59602ac6454SAndrew Thompson aue_reset(struct aue_softc *sc) 59702ac6454SAndrew Thompson { 59802ac6454SAndrew Thompson int i; 59902ac6454SAndrew Thompson 60002ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); 60102ac6454SAndrew Thompson 60202ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 60302ac6454SAndrew Thompson if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) 60402ac6454SAndrew Thompson break; 605a593f6b8SAndrew Thompson if (uether_pause(&sc->sc_ue, hz / 100)) 60602ac6454SAndrew Thompson break; 60702ac6454SAndrew Thompson } 60802ac6454SAndrew Thompson 60902ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 61002ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "reset failed\n"); 61102ac6454SAndrew Thompson 61202ac6454SAndrew Thompson /* 61302ac6454SAndrew Thompson * The PHY(s) attached to the Pegasus chip may be held 61402ac6454SAndrew Thompson * in reset until we flip on the GPIO outputs. Make sure 61502ac6454SAndrew Thompson * to set the GPIO pins high so that the PHY(s) will 61602ac6454SAndrew Thompson * be enabled. 61702ac6454SAndrew Thompson * 618069f9a8bSAlfred Perlstein * NOTE: We used to force all of the GPIO pins low first and then 619069f9a8bSAlfred Perlstein * enable the ones we want. This has been changed to better 620069f9a8bSAlfred Perlstein * match the ADMtek's reference design to avoid setting the 621069f9a8bSAlfred Perlstein * power-down configuration line of the PHY at the same time 622069f9a8bSAlfred Perlstein * it is reset. 62302ac6454SAndrew Thompson */ 624069f9a8bSAlfred Perlstein aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1); 625069f9a8bSAlfred Perlstein aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1|AUE_GPIO_OUT0); 62602ac6454SAndrew Thompson 62702ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_LSYS) { 62802ac6454SAndrew Thompson /* Grrr. LinkSys has to be different from everyone else. */ 62902ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1); 63002ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_GPIO0, 63102ac6454SAndrew Thompson AUE_GPIO_SEL0|AUE_GPIO_SEL1|AUE_GPIO_OUT0); 63202ac6454SAndrew Thompson } 63302ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_PII) 63402ac6454SAndrew Thompson aue_reset_pegasus_II(sc); 63502ac6454SAndrew Thompson 63602ac6454SAndrew Thompson /* Wait a little while for the chip to get its brains in order: */ 637a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 100); 63802ac6454SAndrew Thompson } 63902ac6454SAndrew Thompson 64002ac6454SAndrew Thompson static void 641760bc48eSAndrew Thompson aue_attach_post(struct usb_ether *ue) 64202ac6454SAndrew Thompson { 643a593f6b8SAndrew Thompson struct aue_softc *sc = uether_getsc(ue); 64402ac6454SAndrew Thompson 64502ac6454SAndrew Thompson /* reset the adapter */ 64602ac6454SAndrew Thompson aue_reset(sc); 64702ac6454SAndrew Thompson 64802ac6454SAndrew Thompson /* get station address from the EEPROM */ 649759d4563SPyun YongHyeon aue_read_mac(sc, ue->ue_eaddr); 65002ac6454SAndrew Thompson } 65102ac6454SAndrew Thompson 65202ac6454SAndrew Thompson /* 65302ac6454SAndrew Thompson * Probe for a Pegasus chip. 65402ac6454SAndrew Thompson */ 65502ac6454SAndrew Thompson static int 65602ac6454SAndrew Thompson aue_probe(device_t dev) 65702ac6454SAndrew Thompson { 658760bc48eSAndrew Thompson struct usb_attach_arg *uaa = device_get_ivars(dev); 65902ac6454SAndrew Thompson 660f29a0724SAndrew Thompson if (uaa->usb_mode != USB_MODE_HOST) 66102ac6454SAndrew Thompson return (ENXIO); 66202ac6454SAndrew Thompson if (uaa->info.bConfigIndex != AUE_CONFIG_INDEX) 66302ac6454SAndrew Thompson return (ENXIO); 66402ac6454SAndrew Thompson if (uaa->info.bIfaceIndex != AUE_IFACE_IDX) 66502ac6454SAndrew Thompson return (ENXIO); 66602ac6454SAndrew Thompson /* 66702ac6454SAndrew Thompson * Belkin USB Bluetooth dongles of the F8T012xx1 model series conflict 66802ac6454SAndrew Thompson * with older Belkin USB2LAN adapters. Skip if_aue if we detect one of 66902ac6454SAndrew Thompson * the devices that look like Bluetooth adapters. 67002ac6454SAndrew Thompson */ 67102ac6454SAndrew Thompson if (uaa->info.idVendor == USB_VENDOR_BELKIN && 67202ac6454SAndrew Thompson uaa->info.idProduct == USB_PRODUCT_BELKIN_F8T012 && 67302ac6454SAndrew Thompson uaa->info.bcdDevice == 0x0413) 67402ac6454SAndrew Thompson return (ENXIO); 67502ac6454SAndrew Thompson 676a593f6b8SAndrew Thompson return (usbd_lookup_id_by_uaa(aue_devs, sizeof(aue_devs), uaa)); 67702ac6454SAndrew Thompson } 67802ac6454SAndrew Thompson 67902ac6454SAndrew Thompson /* 68002ac6454SAndrew Thompson * Attach the interface. Allocate softc structures, do ifmedia 68102ac6454SAndrew Thompson * setup and ethernet/BPF attach. 68202ac6454SAndrew Thompson */ 68302ac6454SAndrew Thompson static int 68402ac6454SAndrew Thompson aue_attach(device_t dev) 68502ac6454SAndrew Thompson { 686760bc48eSAndrew Thompson struct usb_attach_arg *uaa = device_get_ivars(dev); 68702ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 688760bc48eSAndrew Thompson struct usb_ether *ue = &sc->sc_ue; 68902ac6454SAndrew Thompson uint8_t iface_index; 69002ac6454SAndrew Thompson int error; 69102ac6454SAndrew Thompson 69202ac6454SAndrew Thompson sc->sc_flags = USB_GET_DRIVER_INFO(uaa); 69302ac6454SAndrew Thompson 69402ac6454SAndrew Thompson if (uaa->info.bcdDevice >= 0x0201) { 69502ac6454SAndrew Thompson /* XXX currently undocumented */ 69602ac6454SAndrew Thompson sc->sc_flags |= AUE_FLAG_VER_2; 69702ac6454SAndrew Thompson } 69802ac6454SAndrew Thompson 699a593f6b8SAndrew Thompson device_set_usb_desc(dev); 70002ac6454SAndrew Thompson mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); 70102ac6454SAndrew Thompson 70202ac6454SAndrew Thompson iface_index = AUE_IFACE_IDX; 703a593f6b8SAndrew Thompson error = usbd_transfer_setup(uaa->device, &iface_index, 70402ac6454SAndrew Thompson sc->sc_xfer, aue_config, AUE_N_TRANSFER, 70502ac6454SAndrew Thompson sc, &sc->sc_mtx); 70602ac6454SAndrew Thompson if (error) { 707767cb2e2SAndrew Thompson device_printf(dev, "allocating USB transfers failed\n"); 70802ac6454SAndrew Thompson goto detach; 70902ac6454SAndrew Thompson } 71002ac6454SAndrew Thompson 71102ac6454SAndrew Thompson ue->ue_sc = sc; 71202ac6454SAndrew Thompson ue->ue_dev = dev; 71302ac6454SAndrew Thompson ue->ue_udev = uaa->device; 71402ac6454SAndrew Thompson ue->ue_mtx = &sc->sc_mtx; 71502ac6454SAndrew Thompson ue->ue_methods = &aue_ue_methods; 71602ac6454SAndrew Thompson 717a593f6b8SAndrew Thompson error = uether_ifattach(ue); 71802ac6454SAndrew Thompson if (error) { 71902ac6454SAndrew Thompson device_printf(dev, "could not attach interface\n"); 72002ac6454SAndrew Thompson goto detach; 72102ac6454SAndrew Thompson } 72202ac6454SAndrew Thompson return (0); /* success */ 72302ac6454SAndrew Thompson 72402ac6454SAndrew Thompson detach: 72502ac6454SAndrew Thompson aue_detach(dev); 72602ac6454SAndrew Thompson return (ENXIO); /* failure */ 72702ac6454SAndrew Thompson } 72802ac6454SAndrew Thompson 72902ac6454SAndrew Thompson static int 73002ac6454SAndrew Thompson aue_detach(device_t dev) 73102ac6454SAndrew Thompson { 73202ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 733760bc48eSAndrew Thompson struct usb_ether *ue = &sc->sc_ue; 73402ac6454SAndrew Thompson 735a593f6b8SAndrew Thompson usbd_transfer_unsetup(sc->sc_xfer, AUE_N_TRANSFER); 736a593f6b8SAndrew Thompson uether_ifdetach(ue); 73702ac6454SAndrew Thompson mtx_destroy(&sc->sc_mtx); 73802ac6454SAndrew Thompson 73902ac6454SAndrew Thompson return (0); 74002ac6454SAndrew Thompson } 74102ac6454SAndrew Thompson 74202ac6454SAndrew Thompson static void 743ed6d949aSAndrew Thompson aue_intr_callback(struct usb_xfer *xfer, usb_error_t error) 74402ac6454SAndrew Thompson { 745ed6d949aSAndrew Thompson struct aue_softc *sc = usbd_xfer_softc(xfer); 746a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(&sc->sc_ue); 74702ac6454SAndrew Thompson struct aue_intrpkt pkt; 748ed6d949aSAndrew Thompson struct usb_page_cache *pc; 749ed6d949aSAndrew Thompson int actlen; 750ed6d949aSAndrew Thompson 751ed6d949aSAndrew Thompson usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 75202ac6454SAndrew Thompson 75302ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 75402ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 75502ac6454SAndrew Thompson 75602ac6454SAndrew Thompson if ((ifp->if_drv_flags & IFF_DRV_RUNNING) && 7576d917491SHans Petter Selasky actlen >= (int)sizeof(pkt)) { 75802ac6454SAndrew Thompson 759ed6d949aSAndrew Thompson pc = usbd_xfer_get_frame(xfer, 0); 760ed6d949aSAndrew Thompson usbd_copy_out(pc, 0, &pkt, sizeof(pkt)); 76102ac6454SAndrew Thompson 76202ac6454SAndrew Thompson if (pkt.aue_txstat0) 763ecc70d3fSGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); 7646084a8c0SHans Petter Selasky if (pkt.aue_txstat0 & (AUE_TXSTAT0_LATECOLL | 76502ac6454SAndrew Thompson AUE_TXSTAT0_EXCESSCOLL)) 766ecc70d3fSGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); 76702ac6454SAndrew Thompson } 76802ac6454SAndrew Thompson /* FALLTHROUGH */ 76902ac6454SAndrew Thompson case USB_ST_SETUP: 77002ac6454SAndrew Thompson tr_setup: 771ed6d949aSAndrew Thompson usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 772a593f6b8SAndrew Thompson usbd_transfer_submit(xfer); 77302ac6454SAndrew Thompson return; 77402ac6454SAndrew Thompson 77502ac6454SAndrew Thompson default: /* Error */ 776ed6d949aSAndrew Thompson if (error != USB_ERR_CANCELLED) { 77702ac6454SAndrew Thompson /* try to clear stall first */ 778ed6d949aSAndrew Thompson usbd_xfer_set_stall(xfer); 77902ac6454SAndrew Thompson goto tr_setup; 78002ac6454SAndrew Thompson } 78102ac6454SAndrew Thompson return; 78202ac6454SAndrew Thompson } 78302ac6454SAndrew Thompson } 78402ac6454SAndrew Thompson 78502ac6454SAndrew Thompson static void 786ed6d949aSAndrew Thompson aue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) 78702ac6454SAndrew Thompson { 788ed6d949aSAndrew Thompson struct aue_softc *sc = usbd_xfer_softc(xfer); 789760bc48eSAndrew Thompson struct usb_ether *ue = &sc->sc_ue; 790a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 79102ac6454SAndrew Thompson struct aue_rxpkt stat; 792ed6d949aSAndrew Thompson struct usb_page_cache *pc; 793ed6d949aSAndrew Thompson int actlen; 794ed6d949aSAndrew Thompson 795ed6d949aSAndrew Thompson usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 796ed6d949aSAndrew Thompson pc = usbd_xfer_get_frame(xfer, 0); 79702ac6454SAndrew Thompson 79802ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 79902ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 800ed6d949aSAndrew Thompson DPRINTFN(11, "received %d bytes\n", actlen); 80102ac6454SAndrew Thompson 80202ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_VER_2) { 80302ac6454SAndrew Thompson 804ed6d949aSAndrew Thompson if (actlen == 0) { 805ecc70d3fSGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); 80602ac6454SAndrew Thompson goto tr_setup; 80702ac6454SAndrew Thompson } 80802ac6454SAndrew Thompson } else { 80902ac6454SAndrew Thompson 8106d917491SHans Petter Selasky if (actlen <= (int)(sizeof(stat) + ETHER_CRC_LEN)) { 811ecc70d3fSGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); 81202ac6454SAndrew Thompson goto tr_setup; 81302ac6454SAndrew Thompson } 814ed6d949aSAndrew Thompson usbd_copy_out(pc, actlen - sizeof(stat), &stat, 815ed6d949aSAndrew Thompson sizeof(stat)); 81602ac6454SAndrew Thompson 81702ac6454SAndrew Thompson /* 81802ac6454SAndrew Thompson * turn off all the non-error bits in the rx status 81902ac6454SAndrew Thompson * word: 82002ac6454SAndrew Thompson */ 82102ac6454SAndrew Thompson stat.aue_rxstat &= AUE_RXSTAT_MASK; 82202ac6454SAndrew Thompson if (stat.aue_rxstat) { 823ecc70d3fSGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); 82402ac6454SAndrew Thompson goto tr_setup; 82502ac6454SAndrew Thompson } 82602ac6454SAndrew Thompson /* No errors; receive the packet. */ 827ed6d949aSAndrew Thompson actlen -= (sizeof(stat) + ETHER_CRC_LEN); 82802ac6454SAndrew Thompson } 829ed6d949aSAndrew Thompson uether_rxbuf(ue, pc, 0, actlen); 83002ac6454SAndrew Thompson 83102ac6454SAndrew Thompson /* FALLTHROUGH */ 83202ac6454SAndrew Thompson case USB_ST_SETUP: 83302ac6454SAndrew Thompson tr_setup: 834ed6d949aSAndrew Thompson usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 835a593f6b8SAndrew Thompson usbd_transfer_submit(xfer); 836a593f6b8SAndrew Thompson uether_rxflush(ue); 83702ac6454SAndrew Thompson return; 83802ac6454SAndrew Thompson 83902ac6454SAndrew Thompson default: /* Error */ 84002ac6454SAndrew Thompson DPRINTF("bulk read error, %s\n", 841ed6d949aSAndrew Thompson usbd_errstr(error)); 84202ac6454SAndrew Thompson 843ed6d949aSAndrew Thompson if (error != USB_ERR_CANCELLED) { 84402ac6454SAndrew Thompson /* try to clear stall first */ 845ed6d949aSAndrew Thompson usbd_xfer_set_stall(xfer); 84602ac6454SAndrew Thompson goto tr_setup; 84702ac6454SAndrew Thompson } 84802ac6454SAndrew Thompson return; 84902ac6454SAndrew Thompson } 85002ac6454SAndrew Thompson } 85102ac6454SAndrew Thompson 85202ac6454SAndrew Thompson static void 853ed6d949aSAndrew Thompson aue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error) 85402ac6454SAndrew Thompson { 855ed6d949aSAndrew Thompson struct aue_softc *sc = usbd_xfer_softc(xfer); 856a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(&sc->sc_ue); 857ed6d949aSAndrew Thompson struct usb_page_cache *pc; 85802ac6454SAndrew Thompson struct mbuf *m; 85902ac6454SAndrew Thompson uint8_t buf[2]; 860ed6d949aSAndrew Thompson int actlen; 861ed6d949aSAndrew Thompson 862ed6d949aSAndrew Thompson usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 863ed6d949aSAndrew Thompson pc = usbd_xfer_get_frame(xfer, 0); 86402ac6454SAndrew Thompson 86502ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 86602ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 867ed6d949aSAndrew Thompson DPRINTFN(11, "transfer of %d bytes complete\n", actlen); 868ecc70d3fSGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); 86902ac6454SAndrew Thompson 87002ac6454SAndrew Thompson /* FALLTHROUGH */ 87102ac6454SAndrew Thompson case USB_ST_SETUP: 87202ac6454SAndrew Thompson tr_setup: 87302ac6454SAndrew Thompson if ((sc->sc_flags & AUE_FLAG_LINK) == 0) { 87402ac6454SAndrew Thompson /* 87502ac6454SAndrew Thompson * don't send anything if there is no link ! 87602ac6454SAndrew Thompson */ 87702ac6454SAndrew Thompson return; 87802ac6454SAndrew Thompson } 87902ac6454SAndrew Thompson IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 88002ac6454SAndrew Thompson 88102ac6454SAndrew Thompson if (m == NULL) 88202ac6454SAndrew Thompson return; 88302ac6454SAndrew Thompson if (m->m_pkthdr.len > MCLBYTES) 88402ac6454SAndrew Thompson m->m_pkthdr.len = MCLBYTES; 88502ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_VER_2) { 88602ac6454SAndrew Thompson 887ed6d949aSAndrew Thompson usbd_xfer_set_frame_len(xfer, 0, m->m_pkthdr.len); 88802ac6454SAndrew Thompson 889ed6d949aSAndrew Thompson usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len); 89002ac6454SAndrew Thompson 89102ac6454SAndrew Thompson } else { 89202ac6454SAndrew Thompson 893ed6d949aSAndrew Thompson usbd_xfer_set_frame_len(xfer, 0, (m->m_pkthdr.len + 2)); 89402ac6454SAndrew Thompson 89502ac6454SAndrew Thompson /* 89602ac6454SAndrew Thompson * The ADMtek documentation says that the 89702ac6454SAndrew Thompson * packet length is supposed to be specified 89802ac6454SAndrew Thompson * in the first two bytes of the transfer, 89902ac6454SAndrew Thompson * however it actually seems to ignore this 90002ac6454SAndrew Thompson * info and base the frame size on the bulk 90102ac6454SAndrew Thompson * transfer length. 90202ac6454SAndrew Thompson */ 90302ac6454SAndrew Thompson buf[0] = (uint8_t)(m->m_pkthdr.len); 90402ac6454SAndrew Thompson buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 90502ac6454SAndrew Thompson 906ed6d949aSAndrew Thompson usbd_copy_in(pc, 0, buf, 2); 907ed6d949aSAndrew Thompson usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len); 90802ac6454SAndrew Thompson } 90902ac6454SAndrew Thompson 91002ac6454SAndrew Thompson /* 91102ac6454SAndrew Thompson * if there's a BPF listener, bounce a copy 91202ac6454SAndrew Thompson * of this frame to him: 91302ac6454SAndrew Thompson */ 91402ac6454SAndrew Thompson BPF_MTAP(ifp, m); 91502ac6454SAndrew Thompson 91602ac6454SAndrew Thompson m_freem(m); 91702ac6454SAndrew Thompson 918a593f6b8SAndrew Thompson usbd_transfer_submit(xfer); 91902ac6454SAndrew Thompson return; 92002ac6454SAndrew Thompson 92102ac6454SAndrew Thompson default: /* Error */ 92202ac6454SAndrew Thompson DPRINTFN(11, "transfer error, %s\n", 923ed6d949aSAndrew Thompson usbd_errstr(error)); 92402ac6454SAndrew Thompson 925ecc70d3fSGleb Smirnoff if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); 92602ac6454SAndrew Thompson 927ed6d949aSAndrew Thompson if (error != USB_ERR_CANCELLED) { 92802ac6454SAndrew Thompson /* try to clear stall first */ 929ed6d949aSAndrew Thompson usbd_xfer_set_stall(xfer); 93002ac6454SAndrew Thompson goto tr_setup; 93102ac6454SAndrew Thompson } 93202ac6454SAndrew Thompson return; 93302ac6454SAndrew Thompson } 93402ac6454SAndrew Thompson } 93502ac6454SAndrew Thompson 93602ac6454SAndrew Thompson static void 937760bc48eSAndrew Thompson aue_tick(struct usb_ether *ue) 93802ac6454SAndrew Thompson { 939a593f6b8SAndrew Thompson struct aue_softc *sc = uether_getsc(ue); 94002ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 94102ac6454SAndrew Thompson 94202ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 94302ac6454SAndrew Thompson 94402ac6454SAndrew Thompson mii_tick(mii); 94502ac6454SAndrew Thompson if ((sc->sc_flags & AUE_FLAG_LINK) == 0 94602ac6454SAndrew Thompson && mii->mii_media_status & IFM_ACTIVE && 94702ac6454SAndrew Thompson IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 94802ac6454SAndrew Thompson sc->sc_flags |= AUE_FLAG_LINK; 94902ac6454SAndrew Thompson aue_start(ue); 95002ac6454SAndrew Thompson } 95102ac6454SAndrew Thompson } 95202ac6454SAndrew Thompson 95302ac6454SAndrew Thompson static void 954760bc48eSAndrew Thompson aue_start(struct usb_ether *ue) 95502ac6454SAndrew Thompson { 956a593f6b8SAndrew Thompson struct aue_softc *sc = uether_getsc(ue); 95702ac6454SAndrew Thompson 95802ac6454SAndrew Thompson /* 95902ac6454SAndrew Thompson * start the USB transfers, if not already started: 96002ac6454SAndrew Thompson */ 961a593f6b8SAndrew Thompson usbd_transfer_start(sc->sc_xfer[AUE_INTR_DT_RD]); 962a593f6b8SAndrew Thompson usbd_transfer_start(sc->sc_xfer[AUE_BULK_DT_RD]); 963a593f6b8SAndrew Thompson usbd_transfer_start(sc->sc_xfer[AUE_BULK_DT_WR]); 96402ac6454SAndrew Thompson } 96502ac6454SAndrew Thompson 96602ac6454SAndrew Thompson static void 967760bc48eSAndrew Thompson aue_init(struct usb_ether *ue) 96802ac6454SAndrew Thompson { 969a593f6b8SAndrew Thompson struct aue_softc *sc = uether_getsc(ue); 970a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 97102ac6454SAndrew Thompson int i; 97202ac6454SAndrew Thompson 97302ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 97402ac6454SAndrew Thompson 97502ac6454SAndrew Thompson /* 97602ac6454SAndrew Thompson * Cancel pending I/O 97702ac6454SAndrew Thompson */ 97802ac6454SAndrew Thompson aue_reset(sc); 97902ac6454SAndrew Thompson 98002ac6454SAndrew Thompson /* Set MAC address */ 98102ac6454SAndrew Thompson for (i = 0; i != ETHER_ADDR_LEN; i++) 98202ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PAR0 + i, IF_LLADDR(ifp)[i]); 98302ac6454SAndrew Thompson 98402ac6454SAndrew Thompson /* update promiscuous setting */ 98502ac6454SAndrew Thompson aue_setpromisc(ue); 98602ac6454SAndrew Thompson 98702ac6454SAndrew Thompson /* Load the multicast filter. */ 98802ac6454SAndrew Thompson aue_setmulti(ue); 98902ac6454SAndrew Thompson 99002ac6454SAndrew Thompson /* Enable RX and TX */ 99102ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB); 99202ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 99302ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); 99402ac6454SAndrew Thompson 995ed6d949aSAndrew Thompson usbd_xfer_set_stall(sc->sc_xfer[AUE_BULK_DT_WR]); 99602ac6454SAndrew Thompson 99702ac6454SAndrew Thompson ifp->if_drv_flags |= IFF_DRV_RUNNING; 99802ac6454SAndrew Thompson aue_start(ue); 99902ac6454SAndrew Thompson } 100002ac6454SAndrew Thompson 100102ac6454SAndrew Thompson static void 1002760bc48eSAndrew Thompson aue_setpromisc(struct usb_ether *ue) 100302ac6454SAndrew Thompson { 1004a593f6b8SAndrew Thompson struct aue_softc *sc = uether_getsc(ue); 1005a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 100602ac6454SAndrew Thompson 100702ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 100802ac6454SAndrew Thompson 100902ac6454SAndrew Thompson /* if we want promiscuous mode, set the allframes bit: */ 101002ac6454SAndrew Thompson if (ifp->if_flags & IFF_PROMISC) 101102ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 101202ac6454SAndrew Thompson else 101302ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 101402ac6454SAndrew Thompson } 101502ac6454SAndrew Thompson 101602ac6454SAndrew Thompson /* 101702ac6454SAndrew Thompson * Set media options. 101802ac6454SAndrew Thompson */ 101902ac6454SAndrew Thompson static int 102002ac6454SAndrew Thompson aue_ifmedia_upd(struct ifnet *ifp) 102102ac6454SAndrew Thompson { 102202ac6454SAndrew Thompson struct aue_softc *sc = ifp->if_softc; 102302ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 10243fcb7a53SMarius Strobl struct mii_softc *miisc; 1025ebe01023SKevin Lo int error; 102602ac6454SAndrew Thompson 102702ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 102802ac6454SAndrew Thompson 102902ac6454SAndrew Thompson sc->sc_flags &= ~AUE_FLAG_LINK; 103002ac6454SAndrew Thompson LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 10313fcb7a53SMarius Strobl PHY_RESET(miisc); 1032ebe01023SKevin Lo error = mii_mediachg(mii); 1033ebe01023SKevin Lo return (error); 103402ac6454SAndrew Thompson } 103502ac6454SAndrew Thompson 103602ac6454SAndrew Thompson /* 103702ac6454SAndrew Thompson * Report current media status. 103802ac6454SAndrew Thompson */ 103902ac6454SAndrew Thompson static void 104002ac6454SAndrew Thompson aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 104102ac6454SAndrew Thompson { 104202ac6454SAndrew Thompson struct aue_softc *sc = ifp->if_softc; 104302ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 104402ac6454SAndrew Thompson 104502ac6454SAndrew Thompson AUE_LOCK(sc); 104602ac6454SAndrew Thompson mii_pollstat(mii); 104702ac6454SAndrew Thompson ifmr->ifm_active = mii->mii_media_active; 104802ac6454SAndrew Thompson ifmr->ifm_status = mii->mii_media_status; 1049e9e549efSPyun YongHyeon AUE_UNLOCK(sc); 105002ac6454SAndrew Thompson } 105102ac6454SAndrew Thompson 105202ac6454SAndrew Thompson /* 105302ac6454SAndrew Thompson * Stop the adapter and free any mbufs allocated to the 105402ac6454SAndrew Thompson * RX and TX lists. 105502ac6454SAndrew Thompson */ 105602ac6454SAndrew Thompson static void 1057760bc48eSAndrew Thompson aue_stop(struct usb_ether *ue) 105802ac6454SAndrew Thompson { 1059a593f6b8SAndrew Thompson struct aue_softc *sc = uether_getsc(ue); 1060a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 106102ac6454SAndrew Thompson 106202ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 106302ac6454SAndrew Thompson 106402ac6454SAndrew Thompson ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 106502ac6454SAndrew Thompson sc->sc_flags &= ~AUE_FLAG_LINK; 106602ac6454SAndrew Thompson 106702ac6454SAndrew Thompson /* 106802ac6454SAndrew Thompson * stop all the transfers, if not already stopped: 106902ac6454SAndrew Thompson */ 1070a593f6b8SAndrew Thompson usbd_transfer_stop(sc->sc_xfer[AUE_BULK_DT_WR]); 1071a593f6b8SAndrew Thompson usbd_transfer_stop(sc->sc_xfer[AUE_BULK_DT_RD]); 1072a593f6b8SAndrew Thompson usbd_transfer_stop(sc->sc_xfer[AUE_INTR_DT_RD]); 107302ac6454SAndrew Thompson 107402ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_CTL0, 0); 107502ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_CTL1, 0); 107602ac6454SAndrew Thompson aue_reset(sc); 107702ac6454SAndrew Thompson } 1078