102ac6454SAndrew Thompson /*- 202ac6454SAndrew Thompson * Copyright (c) 1997, 1998, 1999, 2000-2003 302ac6454SAndrew Thompson * Bill Paul <wpaul@windriver.com>. All rights reserved. 402ac6454SAndrew Thompson * 502ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 602ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 702ac6454SAndrew Thompson * are met: 802ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 902ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1002ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1102ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1202ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1302ac6454SAndrew Thompson * 3. All advertising materials mentioning features or use of this software 1402ac6454SAndrew Thompson * must display the following acknowledgement: 1502ac6454SAndrew Thompson * This product includes software developed by Bill Paul. 1602ac6454SAndrew Thompson * 4. Neither the name of the author nor the names of any co-contributors 1702ac6454SAndrew Thompson * may be used to endorse or promote products derived from this software 1802ac6454SAndrew Thompson * without specific prior written permission. 1902ac6454SAndrew Thompson * 2002ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2102ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2202ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2302ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 2402ac6454SAndrew Thompson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2502ac6454SAndrew Thompson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2602ac6454SAndrew Thompson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2702ac6454SAndrew Thompson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2802ac6454SAndrew Thompson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2902ac6454SAndrew Thompson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 3002ac6454SAndrew Thompson * THE POSSIBILITY OF SUCH DAMAGE. 3102ac6454SAndrew Thompson */ 3202ac6454SAndrew Thompson 3302ac6454SAndrew Thompson #include <sys/cdefs.h> 3402ac6454SAndrew Thompson __FBSDID("$FreeBSD$"); 3502ac6454SAndrew Thompson 3602ac6454SAndrew Thompson /* 3702ac6454SAndrew Thompson * ASIX Electronics AX88172/AX88178/AX88778 USB 2.0 ethernet driver. 3802ac6454SAndrew Thompson * Used in the LinkSys USB200M and various other adapters. 3902ac6454SAndrew Thompson * 4002ac6454SAndrew Thompson * Manuals available from: 4102ac6454SAndrew Thompson * http://www.asix.com.tw/datasheet/mac/Ax88172.PDF 4202ac6454SAndrew Thompson * Note: you need the manual for the AX88170 chip (USB 1.x ethernet 4302ac6454SAndrew Thompson * controller) to find the definitions for the RX control register. 4402ac6454SAndrew Thompson * http://www.asix.com.tw/datasheet/mac/Ax88170.PDF 4502ac6454SAndrew Thompson * 4602ac6454SAndrew Thompson * Written by Bill Paul <wpaul@windriver.com> 4702ac6454SAndrew Thompson * Senior Engineer 4802ac6454SAndrew Thompson * Wind River Systems 4902ac6454SAndrew Thompson */ 5002ac6454SAndrew Thompson 5102ac6454SAndrew Thompson /* 5202ac6454SAndrew Thompson * The AX88172 provides USB ethernet supports at 10 and 100Mbps. 5302ac6454SAndrew Thompson * It uses an external PHY (reference designs use a RealTek chip), 5402ac6454SAndrew Thompson * and has a 64-bit multicast hash filter. There is some information 5502ac6454SAndrew Thompson * missing from the manual which one needs to know in order to make 5602ac6454SAndrew Thompson * the chip function: 5702ac6454SAndrew Thompson * 5802ac6454SAndrew Thompson * - You must set bit 7 in the RX control register, otherwise the 5902ac6454SAndrew Thompson * chip won't receive any packets. 6002ac6454SAndrew Thompson * - You must initialize all 3 IPG registers, or you won't be able 6102ac6454SAndrew Thompson * to send any packets. 6202ac6454SAndrew Thompson * 6302ac6454SAndrew Thompson * Note that this device appears to only support loading the station 6402ac6454SAndrew Thompson * address via autload from the EEPROM (i.e. there's no way to manaully 6502ac6454SAndrew Thompson * set it). 6602ac6454SAndrew Thompson * 6702ac6454SAndrew Thompson * (Adam Weinberger wanted me to name this driver if_gir.c.) 6802ac6454SAndrew Thompson */ 6902ac6454SAndrew Thompson 7002ac6454SAndrew Thompson /* 7102ac6454SAndrew Thompson * Ax88178 and Ax88772 support backported from the OpenBSD driver. 7202ac6454SAndrew Thompson * 2007/02/12, J.R. Oldroyd, fbsd@opal.com 7302ac6454SAndrew Thompson * 7402ac6454SAndrew Thompson * Manual here: 7502ac6454SAndrew Thompson * http://www.asix.com.tw/FrootAttach/datasheet/AX88178_datasheet_Rev10.pdf 7602ac6454SAndrew Thompson * http://www.asix.com.tw/FrootAttach/datasheet/AX88772_datasheet_Rev10.pdf 7702ac6454SAndrew Thompson */ 7802ac6454SAndrew Thompson 79ed6d949aSAndrew Thompson #include <sys/stdint.h> 80ed6d949aSAndrew Thompson #include <sys/stddef.h> 81ed6d949aSAndrew Thompson #include <sys/param.h> 82ed6d949aSAndrew Thompson #include <sys/queue.h> 83ed6d949aSAndrew Thompson #include <sys/types.h> 84ed6d949aSAndrew Thompson #include <sys/systm.h> 85ed6d949aSAndrew Thompson #include <sys/kernel.h> 86ed6d949aSAndrew Thompson #include <sys/bus.h> 87ed6d949aSAndrew Thompson #include <sys/linker_set.h> 88ed6d949aSAndrew Thompson #include <sys/module.h> 89ed6d949aSAndrew Thompson #include <sys/lock.h> 90ed6d949aSAndrew Thompson #include <sys/mutex.h> 91ed6d949aSAndrew Thompson #include <sys/condvar.h> 92ed6d949aSAndrew Thompson #include <sys/sysctl.h> 93ed6d949aSAndrew Thompson #include <sys/sx.h> 94ed6d949aSAndrew Thompson #include <sys/unistd.h> 95ed6d949aSAndrew Thompson #include <sys/callout.h> 96ed6d949aSAndrew Thompson #include <sys/malloc.h> 97ed6d949aSAndrew Thompson #include <sys/priv.h> 98ed6d949aSAndrew Thompson 9902ac6454SAndrew Thompson #include <dev/usb/usb.h> 100ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h> 101ed6d949aSAndrew Thompson #include <dev/usb/usbdi_util.h> 102ed6d949aSAndrew Thompson #include "usbdevs.h" 10302ac6454SAndrew Thompson 10402ac6454SAndrew Thompson #define USB_DEBUG_VAR axe_debug 10502ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 106ed6d949aSAndrew Thompson #include <dev/usb/usb_process.h> 10702ac6454SAndrew Thompson 10802ac6454SAndrew Thompson #include <dev/usb/net/usb_ethernet.h> 10902ac6454SAndrew Thompson #include <dev/usb/net/if_axereg.h> 11002ac6454SAndrew Thompson 11102ac6454SAndrew Thompson /* 11202ac6454SAndrew Thompson * AXE_178_MAX_FRAME_BURST 11302ac6454SAndrew Thompson * max frame burst size for Ax88178 and Ax88772 11402ac6454SAndrew Thompson * 0 2048 bytes 11502ac6454SAndrew Thompson * 1 4096 bytes 11602ac6454SAndrew Thompson * 2 8192 bytes 11702ac6454SAndrew Thompson * 3 16384 bytes 11802ac6454SAndrew Thompson * use the largest your system can handle without USB stalling. 11902ac6454SAndrew Thompson * 12002ac6454SAndrew Thompson * NB: 88772 parts appear to generate lots of input errors with 12102ac6454SAndrew Thompson * a 2K rx buffer and 8K is only slightly faster than 4K on an 12202ac6454SAndrew Thompson * EHCI port on a T42 so change at your own risk. 12302ac6454SAndrew Thompson */ 12402ac6454SAndrew Thompson #define AXE_178_MAX_FRAME_BURST 1 12502ac6454SAndrew Thompson 12602ac6454SAndrew Thompson #if USB_DEBUG 12702ac6454SAndrew Thompson static int axe_debug = 0; 12802ac6454SAndrew Thompson 1299360ae40SAndrew Thompson SYSCTL_NODE(_hw_usb, OID_AUTO, axe, CTLFLAG_RW, 0, "USB axe"); 1309360ae40SAndrew Thompson SYSCTL_INT(_hw_usb_axe, OID_AUTO, debug, CTLFLAG_RW, &axe_debug, 0, 13102ac6454SAndrew Thompson "Debug level"); 13202ac6454SAndrew Thompson #endif 13302ac6454SAndrew Thompson 13402ac6454SAndrew Thompson /* 13502ac6454SAndrew Thompson * Various supported device vendors/products. 13602ac6454SAndrew Thompson */ 137760bc48eSAndrew Thompson static const struct usb_device_id axe_devs[] = { 1389e6b5313SAndrew Thompson #define AXE_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) } 1399e6b5313SAndrew Thompson AXE_DEV(ABOCOM, UF200, 0), 1409e6b5313SAndrew Thompson AXE_DEV(ACERCM, EP1427X2, 0), 1419e6b5313SAndrew Thompson AXE_DEV(APPLE, ETHERNET, AXE_FLAG_772), 1429e6b5313SAndrew Thompson AXE_DEV(ASIX, AX88172, 0), 1439e6b5313SAndrew Thompson AXE_DEV(ASIX, AX88178, AXE_FLAG_178), 1449e6b5313SAndrew Thompson AXE_DEV(ASIX, AX88772, AXE_FLAG_772), 1459e6b5313SAndrew Thompson AXE_DEV(ASIX, AX88772A, AXE_FLAG_772), 1469e6b5313SAndrew Thompson AXE_DEV(ATEN, UC210T, 0), 1479e6b5313SAndrew Thompson AXE_DEV(BELKIN, F5D5055, AXE_FLAG_178), 1489e6b5313SAndrew Thompson AXE_DEV(BILLIONTON, USB2AR, 0), 1499e6b5313SAndrew Thompson AXE_DEV(CISCOLINKSYS, USB200MV2, AXE_FLAG_772), 1509e6b5313SAndrew Thompson AXE_DEV(COREGA, FETHER_USB2_TX, 0), 1519e6b5313SAndrew Thompson AXE_DEV(DLINK, DUBE100, 0), 1529e6b5313SAndrew Thompson AXE_DEV(DLINK, DUBE100B1, AXE_FLAG_772), 1539e6b5313SAndrew Thompson AXE_DEV(GOODWAY, GWUSB2E, 0), 1549e6b5313SAndrew Thompson AXE_DEV(IODATA, ETGUS2, AXE_FLAG_178), 1559e6b5313SAndrew Thompson AXE_DEV(JVC, MP_PRX1, 0), 1569e6b5313SAndrew Thompson AXE_DEV(LINKSYS2, USB200M, 0), 1579e6b5313SAndrew Thompson AXE_DEV(LINKSYS4, USB1000, AXE_FLAG_178), 1589e6b5313SAndrew Thompson AXE_DEV(MELCO, LUAU2KTX, 0), 1599e6b5313SAndrew Thompson AXE_DEV(NETGEAR, FA120, 0), 1609e6b5313SAndrew Thompson AXE_DEV(OQO, ETHER01PLUS, AXE_FLAG_772), 1619e6b5313SAndrew Thompson AXE_DEV(PLANEX3, GU1000T, AXE_FLAG_178), 1629e6b5313SAndrew Thompson AXE_DEV(SITECOM, LN029, 0), 1639e6b5313SAndrew Thompson AXE_DEV(SITECOMEU, LN028, AXE_FLAG_178), 1649e6b5313SAndrew Thompson AXE_DEV(SYSTEMTALKS, SGCX2UL, 0), 1659e6b5313SAndrew Thompson #undef AXE_DEV 16602ac6454SAndrew Thompson }; 16702ac6454SAndrew Thompson 16802ac6454SAndrew Thompson static device_probe_t axe_probe; 16902ac6454SAndrew Thompson static device_attach_t axe_attach; 17002ac6454SAndrew Thompson static device_detach_t axe_detach; 17102ac6454SAndrew Thompson 172e0a69b51SAndrew Thompson static usb_callback_t axe_intr_callback; 173e0a69b51SAndrew Thompson static usb_callback_t axe_bulk_read_callback; 174e0a69b51SAndrew Thompson static usb_callback_t axe_bulk_write_callback; 17502ac6454SAndrew Thompson 17602ac6454SAndrew Thompson static miibus_readreg_t axe_miibus_readreg; 17702ac6454SAndrew Thompson static miibus_writereg_t axe_miibus_writereg; 17802ac6454SAndrew Thompson static miibus_statchg_t axe_miibus_statchg; 17902ac6454SAndrew Thompson 180e0a69b51SAndrew Thompson static uether_fn_t axe_attach_post; 181e0a69b51SAndrew Thompson static uether_fn_t axe_init; 182e0a69b51SAndrew Thompson static uether_fn_t axe_stop; 183e0a69b51SAndrew Thompson static uether_fn_t axe_start; 184e0a69b51SAndrew Thompson static uether_fn_t axe_tick; 185e0a69b51SAndrew Thompson static uether_fn_t axe_setmulti; 186e0a69b51SAndrew Thompson static uether_fn_t axe_setpromisc; 18702ac6454SAndrew Thompson 18802ac6454SAndrew Thompson static int axe_ifmedia_upd(struct ifnet *); 18902ac6454SAndrew Thompson static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *); 19002ac6454SAndrew Thompson static int axe_cmd(struct axe_softc *, int, int, int, void *); 19102ac6454SAndrew Thompson static void axe_ax88178_init(struct axe_softc *); 19202ac6454SAndrew Thompson static void axe_ax88772_init(struct axe_softc *); 19302ac6454SAndrew Thompson static int axe_get_phyno(struct axe_softc *, int); 19402ac6454SAndrew Thompson 195760bc48eSAndrew Thompson static const struct usb_config axe_config[AXE_N_TRANSFER] = { 19602ac6454SAndrew Thompson 19702ac6454SAndrew Thompson [AXE_BULK_DT_WR] = { 19802ac6454SAndrew Thompson .type = UE_BULK, 19902ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 20002ac6454SAndrew Thompson .direction = UE_DIR_OUT, 2014eae601eSAndrew Thompson .bufsize = AXE_BULK_BUF_SIZE, 2024eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 2034eae601eSAndrew Thompson .callback = axe_bulk_write_callback, 2044eae601eSAndrew Thompson .timeout = 10000, /* 10 seconds */ 20502ac6454SAndrew Thompson }, 20602ac6454SAndrew Thompson 20702ac6454SAndrew Thompson [AXE_BULK_DT_RD] = { 20802ac6454SAndrew Thompson .type = UE_BULK, 20902ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 21002ac6454SAndrew Thompson .direction = UE_DIR_IN, 2113ac526e0SAndrew Thompson .bufsize = 16384, /* bytes */ 2124eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 2134eae601eSAndrew Thompson .callback = axe_bulk_read_callback, 2144eae601eSAndrew Thompson .timeout = 0, /* no timeout */ 21502ac6454SAndrew Thompson }, 21602ac6454SAndrew Thompson 21702ac6454SAndrew Thompson [AXE_INTR_DT_RD] = { 21802ac6454SAndrew Thompson .type = UE_INTERRUPT, 21902ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 22002ac6454SAndrew Thompson .direction = UE_DIR_IN, 2214eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 2224eae601eSAndrew Thompson .bufsize = 0, /* use wMaxPacketSize */ 2234eae601eSAndrew Thompson .callback = axe_intr_callback, 22402ac6454SAndrew Thompson }, 22502ac6454SAndrew Thompson }; 22602ac6454SAndrew Thompson 22702ac6454SAndrew Thompson static device_method_t axe_methods[] = { 22802ac6454SAndrew Thompson /* Device interface */ 22902ac6454SAndrew Thompson DEVMETHOD(device_probe, axe_probe), 23002ac6454SAndrew Thompson DEVMETHOD(device_attach, axe_attach), 23102ac6454SAndrew Thompson DEVMETHOD(device_detach, axe_detach), 23202ac6454SAndrew Thompson 23302ac6454SAndrew Thompson /* bus interface */ 23402ac6454SAndrew Thompson DEVMETHOD(bus_print_child, bus_generic_print_child), 23502ac6454SAndrew Thompson DEVMETHOD(bus_driver_added, bus_generic_driver_added), 23602ac6454SAndrew Thompson 23702ac6454SAndrew Thompson /* MII interface */ 23802ac6454SAndrew Thompson DEVMETHOD(miibus_readreg, axe_miibus_readreg), 23902ac6454SAndrew Thompson DEVMETHOD(miibus_writereg, axe_miibus_writereg), 24002ac6454SAndrew Thompson DEVMETHOD(miibus_statchg, axe_miibus_statchg), 24102ac6454SAndrew Thompson 24202ac6454SAndrew Thompson {0, 0} 24302ac6454SAndrew Thompson }; 24402ac6454SAndrew Thompson 24502ac6454SAndrew Thompson static driver_t axe_driver = { 24602ac6454SAndrew Thompson .name = "axe", 24702ac6454SAndrew Thompson .methods = axe_methods, 24802ac6454SAndrew Thompson .size = sizeof(struct axe_softc), 24902ac6454SAndrew Thompson }; 25002ac6454SAndrew Thompson 25102ac6454SAndrew Thompson static devclass_t axe_devclass; 25202ac6454SAndrew Thompson 2539aef556dSAndrew Thompson DRIVER_MODULE(axe, uhub, axe_driver, axe_devclass, NULL, 0); 25402ac6454SAndrew Thompson DRIVER_MODULE(miibus, axe, miibus_driver, miibus_devclass, 0, 0); 25502ac6454SAndrew Thompson MODULE_DEPEND(axe, uether, 1, 1, 1); 25602ac6454SAndrew Thompson MODULE_DEPEND(axe, usb, 1, 1, 1); 25702ac6454SAndrew Thompson MODULE_DEPEND(axe, ether, 1, 1, 1); 25802ac6454SAndrew Thompson MODULE_DEPEND(axe, miibus, 1, 1, 1); 25902ac6454SAndrew Thompson 260760bc48eSAndrew Thompson static const struct usb_ether_methods axe_ue_methods = { 26102ac6454SAndrew Thompson .ue_attach_post = axe_attach_post, 26202ac6454SAndrew Thompson .ue_start = axe_start, 26302ac6454SAndrew Thompson .ue_init = axe_init, 26402ac6454SAndrew Thompson .ue_stop = axe_stop, 26502ac6454SAndrew Thompson .ue_tick = axe_tick, 26602ac6454SAndrew Thompson .ue_setmulti = axe_setmulti, 26702ac6454SAndrew Thompson .ue_setpromisc = axe_setpromisc, 26802ac6454SAndrew Thompson .ue_mii_upd = axe_ifmedia_upd, 26902ac6454SAndrew Thompson .ue_mii_sts = axe_ifmedia_sts, 27002ac6454SAndrew Thompson }; 27102ac6454SAndrew Thompson 27202ac6454SAndrew Thompson static int 27302ac6454SAndrew Thompson axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf) 27402ac6454SAndrew Thompson { 275760bc48eSAndrew Thompson struct usb_device_request req; 276e0a69b51SAndrew Thompson usb_error_t err; 27702ac6454SAndrew Thompson 27802ac6454SAndrew Thompson AXE_LOCK_ASSERT(sc, MA_OWNED); 27902ac6454SAndrew Thompson 28002ac6454SAndrew Thompson req.bmRequestType = (AXE_CMD_IS_WRITE(cmd) ? 28102ac6454SAndrew Thompson UT_WRITE_VENDOR_DEVICE : 28202ac6454SAndrew Thompson UT_READ_VENDOR_DEVICE); 28302ac6454SAndrew Thompson req.bRequest = AXE_CMD_CMD(cmd); 28402ac6454SAndrew Thompson USETW(req.wValue, val); 28502ac6454SAndrew Thompson USETW(req.wIndex, index); 28602ac6454SAndrew Thompson USETW(req.wLength, AXE_CMD_LEN(cmd)); 28702ac6454SAndrew Thompson 288a593f6b8SAndrew Thompson err = uether_do_request(&sc->sc_ue, &req, buf, 1000); 28902ac6454SAndrew Thompson 29002ac6454SAndrew Thompson return (err); 29102ac6454SAndrew Thompson } 29202ac6454SAndrew Thompson 29302ac6454SAndrew Thompson static int 29402ac6454SAndrew Thompson axe_miibus_readreg(device_t dev, int phy, int reg) 29502ac6454SAndrew Thompson { 29602ac6454SAndrew Thompson struct axe_softc *sc = device_get_softc(dev); 29702ac6454SAndrew Thompson uint16_t val; 29802ac6454SAndrew Thompson int locked; 29902ac6454SAndrew Thompson 30002ac6454SAndrew Thompson if (sc->sc_phyno != phy) 30102ac6454SAndrew Thompson return (0); 30202ac6454SAndrew Thompson 30302ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 30402ac6454SAndrew Thompson if (!locked) 30502ac6454SAndrew Thompson AXE_LOCK(sc); 30602ac6454SAndrew Thompson 30702ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL); 30802ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, &val); 30902ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL); 31002ac6454SAndrew Thompson 31102ac6454SAndrew Thompson val = le16toh(val); 31202ac6454SAndrew Thompson if ((sc->sc_flags & AXE_FLAG_772) != 0 && reg == MII_BMSR) { 31302ac6454SAndrew Thompson /* 31402ac6454SAndrew Thompson * BMSR of AX88772 indicates that it supports extended 31502ac6454SAndrew Thompson * capability but the extended status register is 31602ac6454SAndrew Thompson * revered for embedded ethernet PHY. So clear the 31702ac6454SAndrew Thompson * extended capability bit of BMSR. 31802ac6454SAndrew Thompson */ 31902ac6454SAndrew Thompson val &= ~BMSR_EXTCAP; 32002ac6454SAndrew Thompson } 32102ac6454SAndrew Thompson 32202ac6454SAndrew Thompson if (!locked) 32302ac6454SAndrew Thompson AXE_UNLOCK(sc); 32402ac6454SAndrew Thompson return (val); 32502ac6454SAndrew Thompson } 32602ac6454SAndrew Thompson 32702ac6454SAndrew Thompson static int 32802ac6454SAndrew Thompson axe_miibus_writereg(device_t dev, int phy, int reg, int val) 32902ac6454SAndrew Thompson { 33002ac6454SAndrew Thompson struct axe_softc *sc = device_get_softc(dev); 33102ac6454SAndrew Thompson int locked; 33202ac6454SAndrew Thompson 33336002e92SAndrew Thompson val = htole32(val); 33402ac6454SAndrew Thompson 33502ac6454SAndrew Thompson if (sc->sc_phyno != phy) 33602ac6454SAndrew Thompson return (0); 33702ac6454SAndrew Thompson 33802ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 33902ac6454SAndrew Thompson if (!locked) 34002ac6454SAndrew Thompson AXE_LOCK(sc); 34102ac6454SAndrew Thompson 34202ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL); 34302ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, &val); 34402ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL); 34502ac6454SAndrew Thompson 34602ac6454SAndrew Thompson if (!locked) 34702ac6454SAndrew Thompson AXE_UNLOCK(sc); 34802ac6454SAndrew Thompson return (0); 34902ac6454SAndrew Thompson } 35002ac6454SAndrew Thompson 35102ac6454SAndrew Thompson static void 35202ac6454SAndrew Thompson axe_miibus_statchg(device_t dev) 35302ac6454SAndrew Thompson { 35402ac6454SAndrew Thompson struct axe_softc *sc = device_get_softc(dev); 35502ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 35602ac6454SAndrew Thompson struct ifnet *ifp; 35702ac6454SAndrew Thompson uint16_t val; 35802ac6454SAndrew Thompson int err, locked; 35902ac6454SAndrew Thompson 36002ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 36102ac6454SAndrew Thompson if (!locked) 36202ac6454SAndrew Thompson AXE_LOCK(sc); 36302ac6454SAndrew Thompson 364a593f6b8SAndrew Thompson ifp = uether_getifp(&sc->sc_ue); 36502ac6454SAndrew Thompson if (mii == NULL || ifp == NULL || 36602ac6454SAndrew Thompson (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) 36702ac6454SAndrew Thompson goto done; 36802ac6454SAndrew Thompson 36902ac6454SAndrew Thompson sc->sc_flags &= ~AXE_FLAG_LINK; 37002ac6454SAndrew Thompson if ((mii->mii_media_status & (IFM_ACTIVE | IFM_AVALID)) == 37102ac6454SAndrew Thompson (IFM_ACTIVE | IFM_AVALID)) { 37202ac6454SAndrew Thompson switch (IFM_SUBTYPE(mii->mii_media_active)) { 37302ac6454SAndrew Thompson case IFM_10_T: 37402ac6454SAndrew Thompson case IFM_100_TX: 37502ac6454SAndrew Thompson sc->sc_flags |= AXE_FLAG_LINK; 37602ac6454SAndrew Thompson break; 37702ac6454SAndrew Thompson case IFM_1000_T: 37802ac6454SAndrew Thompson if ((sc->sc_flags & AXE_FLAG_178) == 0) 37902ac6454SAndrew Thompson break; 38002ac6454SAndrew Thompson sc->sc_flags |= AXE_FLAG_LINK; 38102ac6454SAndrew Thompson break; 38202ac6454SAndrew Thompson default: 38302ac6454SAndrew Thompson break; 38402ac6454SAndrew Thompson } 38502ac6454SAndrew Thompson } 38602ac6454SAndrew Thompson 38702ac6454SAndrew Thompson /* Lost link, do nothing. */ 38802ac6454SAndrew Thompson if ((sc->sc_flags & AXE_FLAG_LINK) == 0) 38902ac6454SAndrew Thompson goto done; 39002ac6454SAndrew Thompson 39102ac6454SAndrew Thompson val = 0; 39202ac6454SAndrew Thompson if ((IFM_OPTIONS(mii->mii_media_active) & IFM_FDX) != 0) 39302ac6454SAndrew Thompson val |= AXE_MEDIA_FULL_DUPLEX; 39402ac6454SAndrew Thompson if (sc->sc_flags & (AXE_FLAG_178 | AXE_FLAG_772)) { 39502ac6454SAndrew Thompson val |= AXE_178_MEDIA_RX_EN | AXE_178_MEDIA_MAGIC; 39602ac6454SAndrew Thompson if ((sc->sc_flags & AXE_FLAG_178) != 0) 39702ac6454SAndrew Thompson val |= AXE_178_MEDIA_ENCK; 39802ac6454SAndrew Thompson switch (IFM_SUBTYPE(mii->mii_media_active)) { 39902ac6454SAndrew Thompson case IFM_1000_T: 40002ac6454SAndrew Thompson val |= AXE_178_MEDIA_GMII | AXE_178_MEDIA_ENCK; 40102ac6454SAndrew Thompson break; 40202ac6454SAndrew Thompson case IFM_100_TX: 40302ac6454SAndrew Thompson val |= AXE_178_MEDIA_100TX; 40402ac6454SAndrew Thompson break; 40502ac6454SAndrew Thompson case IFM_10_T: 40602ac6454SAndrew Thompson /* doesn't need to be handled */ 40702ac6454SAndrew Thompson break; 40802ac6454SAndrew Thompson } 40902ac6454SAndrew Thompson } 41002ac6454SAndrew Thompson err = axe_cmd(sc, AXE_CMD_WRITE_MEDIA, 0, val, NULL); 41102ac6454SAndrew Thompson if (err) 41202ac6454SAndrew Thompson device_printf(dev, "media change failed, error %d\n", err); 41302ac6454SAndrew Thompson done: 41402ac6454SAndrew Thompson if (!locked) 41502ac6454SAndrew Thompson AXE_UNLOCK(sc); 41602ac6454SAndrew Thompson } 41702ac6454SAndrew Thompson 41802ac6454SAndrew Thompson /* 41902ac6454SAndrew Thompson * Set media options. 42002ac6454SAndrew Thompson */ 42102ac6454SAndrew Thompson static int 42202ac6454SAndrew Thompson axe_ifmedia_upd(struct ifnet *ifp) 42302ac6454SAndrew Thompson { 42402ac6454SAndrew Thompson struct axe_softc *sc = ifp->if_softc; 42502ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 42602ac6454SAndrew Thompson int error; 42702ac6454SAndrew Thompson 42802ac6454SAndrew Thompson AXE_LOCK_ASSERT(sc, MA_OWNED); 42902ac6454SAndrew Thompson 43002ac6454SAndrew Thompson if (mii->mii_instance) { 43102ac6454SAndrew Thompson struct mii_softc *miisc; 43202ac6454SAndrew Thompson 43302ac6454SAndrew Thompson LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 43402ac6454SAndrew Thompson mii_phy_reset(miisc); 43502ac6454SAndrew Thompson } 43602ac6454SAndrew Thompson error = mii_mediachg(mii); 43702ac6454SAndrew Thompson return (error); 43802ac6454SAndrew Thompson } 43902ac6454SAndrew Thompson 44002ac6454SAndrew Thompson /* 44102ac6454SAndrew Thompson * Report current media status. 44202ac6454SAndrew Thompson */ 44302ac6454SAndrew Thompson static void 44402ac6454SAndrew Thompson axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 44502ac6454SAndrew Thompson { 44602ac6454SAndrew Thompson struct axe_softc *sc = ifp->if_softc; 44702ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 44802ac6454SAndrew Thompson 44902ac6454SAndrew Thompson AXE_LOCK(sc); 45002ac6454SAndrew Thompson mii_pollstat(mii); 45102ac6454SAndrew Thompson AXE_UNLOCK(sc); 45202ac6454SAndrew Thompson ifmr->ifm_active = mii->mii_media_active; 45302ac6454SAndrew Thompson ifmr->ifm_status = mii->mii_media_status; 45402ac6454SAndrew Thompson } 45502ac6454SAndrew Thompson 45602ac6454SAndrew Thompson static void 457760bc48eSAndrew Thompson axe_setmulti(struct usb_ether *ue) 45802ac6454SAndrew Thompson { 459a593f6b8SAndrew Thompson struct axe_softc *sc = uether_getsc(ue); 460a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 46102ac6454SAndrew Thompson struct ifmultiaddr *ifma; 46202ac6454SAndrew Thompson uint32_t h = 0; 46302ac6454SAndrew Thompson uint16_t rxmode; 46402ac6454SAndrew Thompson uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 46502ac6454SAndrew Thompson 46602ac6454SAndrew Thompson AXE_LOCK_ASSERT(sc, MA_OWNED); 46702ac6454SAndrew Thompson 46802ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, &rxmode); 46902ac6454SAndrew Thompson rxmode = le16toh(rxmode); 47002ac6454SAndrew Thompson 47102ac6454SAndrew Thompson if (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) { 47202ac6454SAndrew Thompson rxmode |= AXE_RXCMD_ALLMULTI; 47302ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); 47402ac6454SAndrew Thompson return; 47502ac6454SAndrew Thompson } 47602ac6454SAndrew Thompson rxmode &= ~AXE_RXCMD_ALLMULTI; 47702ac6454SAndrew Thompson 478eb956cd0SRobert Watson if_maddr_rlock(ifp); 47902ac6454SAndrew Thompson TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) 48002ac6454SAndrew Thompson { 48102ac6454SAndrew Thompson if (ifma->ifma_addr->sa_family != AF_LINK) 48202ac6454SAndrew Thompson continue; 48302ac6454SAndrew Thompson h = ether_crc32_be(LLADDR((struct sockaddr_dl *) 48402ac6454SAndrew Thompson ifma->ifma_addr), ETHER_ADDR_LEN) >> 26; 48502ac6454SAndrew Thompson hashtbl[h / 8] |= 1 << (h % 8); 48602ac6454SAndrew Thompson } 487eb956cd0SRobert Watson if_maddr_runlock(ifp); 48802ac6454SAndrew Thompson 48902ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl); 49002ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); 49102ac6454SAndrew Thompson } 49202ac6454SAndrew Thompson 49302ac6454SAndrew Thompson static int 49402ac6454SAndrew Thompson axe_get_phyno(struct axe_softc *sc, int sel) 49502ac6454SAndrew Thompson { 49602ac6454SAndrew Thompson int phyno; 49702ac6454SAndrew Thompson 49802ac6454SAndrew Thompson switch (AXE_PHY_TYPE(sc->sc_phyaddrs[sel])) { 49902ac6454SAndrew Thompson case PHY_TYPE_100_HOME: 50002ac6454SAndrew Thompson case PHY_TYPE_GIG: 50102ac6454SAndrew Thompson phyno = AXE_PHY_NO(sc->sc_phyaddrs[sel]); 50202ac6454SAndrew Thompson break; 50302ac6454SAndrew Thompson case PHY_TYPE_SPECIAL: 50402ac6454SAndrew Thompson /* FALLTHROUGH */ 50502ac6454SAndrew Thompson case PHY_TYPE_RSVD: 50602ac6454SAndrew Thompson /* FALLTHROUGH */ 50702ac6454SAndrew Thompson case PHY_TYPE_NON_SUP: 50802ac6454SAndrew Thompson /* FALLTHROUGH */ 50902ac6454SAndrew Thompson default: 51002ac6454SAndrew Thompson phyno = -1; 51102ac6454SAndrew Thompson break; 51202ac6454SAndrew Thompson } 51302ac6454SAndrew Thompson 51402ac6454SAndrew Thompson return (phyno); 51502ac6454SAndrew Thompson } 51602ac6454SAndrew Thompson 51702ac6454SAndrew Thompson static void 51802ac6454SAndrew Thompson axe_ax88178_init(struct axe_softc *sc) 51902ac6454SAndrew Thompson { 52002ac6454SAndrew Thompson int gpio0 = 0, phymode = 0; 52102ac6454SAndrew Thompson uint16_t eeprom; 52202ac6454SAndrew Thompson 52302ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SROM_WR_ENABLE, 0, 0, NULL); 52402ac6454SAndrew Thompson /* XXX magic */ 52502ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SROM_READ, 0, 0x0017, &eeprom); 52602ac6454SAndrew Thompson eeprom = le16toh(eeprom); 52702ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SROM_WR_DISABLE, 0, 0, NULL); 52802ac6454SAndrew Thompson 52902ac6454SAndrew Thompson /* if EEPROM is invalid we have to use to GPIO0 */ 53002ac6454SAndrew Thompson if (eeprom == 0xffff) { 53102ac6454SAndrew Thompson phymode = 0; 53202ac6454SAndrew Thompson gpio0 = 1; 53302ac6454SAndrew Thompson } else { 53402ac6454SAndrew Thompson phymode = eeprom & 7; 53502ac6454SAndrew Thompson gpio0 = (eeprom & 0x80) ? 0 : 1; 53602ac6454SAndrew Thompson } 53702ac6454SAndrew Thompson 53802ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x008c, NULL); 539a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 16); 54002ac6454SAndrew Thompson 54102ac6454SAndrew Thompson if ((eeprom >> 8) != 0x01) { 54202ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x003c, NULL); 543a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 32); 54402ac6454SAndrew Thompson 54502ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x001c, NULL); 546a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 3); 54702ac6454SAndrew Thompson 54802ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x003c, NULL); 549a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 32); 55002ac6454SAndrew Thompson } else { 55102ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x0004, NULL); 552a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 32); 55302ac6454SAndrew Thompson 55402ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x000c, NULL); 555a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 32); 55602ac6454SAndrew Thompson } 55702ac6454SAndrew Thompson 55802ac6454SAndrew Thompson /* soft reset */ 55902ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, AXE_SW_RESET_CLEAR, NULL); 560a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 4); 56102ac6454SAndrew Thompson 56202ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, 56302ac6454SAndrew Thompson AXE_SW_RESET_PRL | AXE_178_RESET_MAGIC, NULL); 564a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 4); 56502ac6454SAndrew Thompson /* Enable MII/GMII/RGMII interface to work with external PHY. */ 56602ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0, NULL); 567a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 4); 56802ac6454SAndrew Thompson 56902ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, 0, NULL); 57002ac6454SAndrew Thompson } 57102ac6454SAndrew Thompson 57202ac6454SAndrew Thompson static void 57302ac6454SAndrew Thompson axe_ax88772_init(struct axe_softc *sc) 57402ac6454SAndrew Thompson { 57502ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_WRITE_GPIO, 0, 0x00b0, NULL); 576a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 16); 57702ac6454SAndrew Thompson 57802ac6454SAndrew Thompson if (sc->sc_phyno == AXE_772_PHY_NO_EPHY) { 57902ac6454SAndrew Thompson /* ask for the embedded PHY */ 58002ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0x01, NULL); 581a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 64); 58202ac6454SAndrew Thompson 58302ac6454SAndrew Thompson /* power down and reset state, pin reset state */ 58402ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, 58502ac6454SAndrew Thompson AXE_SW_RESET_CLEAR, NULL); 586a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 16); 58702ac6454SAndrew Thompson 58802ac6454SAndrew Thompson /* power down/reset state, pin operating state */ 58902ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, 59002ac6454SAndrew Thompson AXE_SW_RESET_IPPD | AXE_SW_RESET_PRL, NULL); 591a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 4); 59202ac6454SAndrew Thompson 59302ac6454SAndrew Thompson /* power up, reset */ 59402ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, AXE_SW_RESET_PRL, NULL); 59502ac6454SAndrew Thompson 59602ac6454SAndrew Thompson /* power up, operating */ 59702ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, 59802ac6454SAndrew Thompson AXE_SW_RESET_IPRL | AXE_SW_RESET_PRL, NULL); 59902ac6454SAndrew Thompson } else { 60002ac6454SAndrew Thompson /* ask for external PHY */ 60102ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_PHY_SELECT, 0, 0x00, NULL); 602a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 64); 60302ac6454SAndrew Thompson 60402ac6454SAndrew Thompson /* power down internal PHY */ 60502ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_SW_RESET_REG, 0, 60602ac6454SAndrew Thompson AXE_SW_RESET_IPPD | AXE_SW_RESET_PRL, NULL); 60702ac6454SAndrew Thompson } 60802ac6454SAndrew Thompson 609a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 4); 61002ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, 0, NULL); 61102ac6454SAndrew Thompson } 61202ac6454SAndrew Thompson 61302ac6454SAndrew Thompson static void 61402ac6454SAndrew Thompson axe_reset(struct axe_softc *sc) 61502ac6454SAndrew Thompson { 616760bc48eSAndrew Thompson struct usb_config_descriptor *cd; 617e0a69b51SAndrew Thompson usb_error_t err; 61802ac6454SAndrew Thompson 619a593f6b8SAndrew Thompson cd = usbd_get_config_descriptor(sc->sc_ue.ue_udev); 62002ac6454SAndrew Thompson 621a593f6b8SAndrew Thompson err = usbd_req_set_config(sc->sc_ue.ue_udev, &sc->sc_mtx, 62202ac6454SAndrew Thompson cd->bConfigurationValue); 62302ac6454SAndrew Thompson if (err) 62402ac6454SAndrew Thompson DPRINTF("reset failed (ignored)\n"); 62502ac6454SAndrew Thompson 62602ac6454SAndrew Thompson /* Wait a little while for the chip to get its brains in order. */ 627a593f6b8SAndrew Thompson uether_pause(&sc->sc_ue, hz / 100); 62802ac6454SAndrew Thompson } 62902ac6454SAndrew Thompson 63002ac6454SAndrew Thompson static void 631760bc48eSAndrew Thompson axe_attach_post(struct usb_ether *ue) 63202ac6454SAndrew Thompson { 633a593f6b8SAndrew Thompson struct axe_softc *sc = uether_getsc(ue); 63402ac6454SAndrew Thompson 63502ac6454SAndrew Thompson /* 63602ac6454SAndrew Thompson * Load PHY indexes first. Needed by axe_xxx_init(). 63702ac6454SAndrew Thompson */ 63802ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, sc->sc_phyaddrs); 63902ac6454SAndrew Thompson #if 1 64002ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "PHYADDR 0x%02x:0x%02x\n", 64102ac6454SAndrew Thompson sc->sc_phyaddrs[0], sc->sc_phyaddrs[1]); 64202ac6454SAndrew Thompson #endif 64302ac6454SAndrew Thompson sc->sc_phyno = axe_get_phyno(sc, AXE_PHY_SEL_PRI); 64402ac6454SAndrew Thompson if (sc->sc_phyno == -1) 64502ac6454SAndrew Thompson sc->sc_phyno = axe_get_phyno(sc, AXE_PHY_SEL_SEC); 64602ac6454SAndrew Thompson if (sc->sc_phyno == -1) { 64702ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, 64802ac6454SAndrew Thompson "no valid PHY address found, assuming PHY address 0\n"); 64902ac6454SAndrew Thompson sc->sc_phyno = 0; 65002ac6454SAndrew Thompson } 65102ac6454SAndrew Thompson 65202ac6454SAndrew Thompson if (sc->sc_flags & AXE_FLAG_178) 65302ac6454SAndrew Thompson axe_ax88178_init(sc); 65402ac6454SAndrew Thompson else if (sc->sc_flags & AXE_FLAG_772) 65502ac6454SAndrew Thompson axe_ax88772_init(sc); 65602ac6454SAndrew Thompson 65702ac6454SAndrew Thompson /* 65802ac6454SAndrew Thompson * Get station address. 65902ac6454SAndrew Thompson */ 66002ac6454SAndrew Thompson if (sc->sc_flags & (AXE_FLAG_178 | AXE_FLAG_772)) 66102ac6454SAndrew Thompson axe_cmd(sc, AXE_178_CMD_READ_NODEID, 0, 0, ue->ue_eaddr); 66202ac6454SAndrew Thompson else 66302ac6454SAndrew Thompson axe_cmd(sc, AXE_172_CMD_READ_NODEID, 0, 0, ue->ue_eaddr); 66402ac6454SAndrew Thompson 66502ac6454SAndrew Thompson /* 66602ac6454SAndrew Thompson * Fetch IPG values. 66702ac6454SAndrew Thompson */ 66802ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, sc->sc_ipgs); 66902ac6454SAndrew Thompson } 67002ac6454SAndrew Thompson 67102ac6454SAndrew Thompson /* 67202ac6454SAndrew Thompson * Probe for a AX88172 chip. 67302ac6454SAndrew Thompson */ 67402ac6454SAndrew Thompson static int 67502ac6454SAndrew Thompson axe_probe(device_t dev) 67602ac6454SAndrew Thompson { 677760bc48eSAndrew Thompson struct usb_attach_arg *uaa = device_get_ivars(dev); 67802ac6454SAndrew Thompson 679f29a0724SAndrew Thompson if (uaa->usb_mode != USB_MODE_HOST) 68002ac6454SAndrew Thompson return (ENXIO); 68102ac6454SAndrew Thompson if (uaa->info.bConfigIndex != AXE_CONFIG_IDX) 68202ac6454SAndrew Thompson return (ENXIO); 68302ac6454SAndrew Thompson if (uaa->info.bIfaceIndex != AXE_IFACE_IDX) 68402ac6454SAndrew Thompson return (ENXIO); 68502ac6454SAndrew Thompson 686a593f6b8SAndrew Thompson return (usbd_lookup_id_by_uaa(axe_devs, sizeof(axe_devs), uaa)); 68702ac6454SAndrew Thompson } 68802ac6454SAndrew Thompson 68902ac6454SAndrew Thompson /* 69002ac6454SAndrew Thompson * Attach the interface. Allocate softc structures, do ifmedia 69102ac6454SAndrew Thompson * setup and ethernet/BPF attach. 69202ac6454SAndrew Thompson */ 69302ac6454SAndrew Thompson static int 69402ac6454SAndrew Thompson axe_attach(device_t dev) 69502ac6454SAndrew Thompson { 696760bc48eSAndrew Thompson struct usb_attach_arg *uaa = device_get_ivars(dev); 69702ac6454SAndrew Thompson struct axe_softc *sc = device_get_softc(dev); 698760bc48eSAndrew Thompson struct usb_ether *ue = &sc->sc_ue; 69902ac6454SAndrew Thompson uint8_t iface_index; 70002ac6454SAndrew Thompson int error; 70102ac6454SAndrew Thompson 70202ac6454SAndrew Thompson sc->sc_flags = USB_GET_DRIVER_INFO(uaa); 70302ac6454SAndrew Thompson 704a593f6b8SAndrew Thompson device_set_usb_desc(dev); 70502ac6454SAndrew Thompson 70602ac6454SAndrew Thompson mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); 70702ac6454SAndrew Thompson 70802ac6454SAndrew Thompson iface_index = AXE_IFACE_IDX; 709a593f6b8SAndrew Thompson error = usbd_transfer_setup(uaa->device, &iface_index, sc->sc_xfer, 71002ac6454SAndrew Thompson axe_config, AXE_N_TRANSFER, sc, &sc->sc_mtx); 71102ac6454SAndrew Thompson if (error) { 712767cb2e2SAndrew Thompson device_printf(dev, "allocating USB transfers failed\n"); 71302ac6454SAndrew Thompson goto detach; 71402ac6454SAndrew Thompson } 71502ac6454SAndrew Thompson 71602ac6454SAndrew Thompson ue->ue_sc = sc; 71702ac6454SAndrew Thompson ue->ue_dev = dev; 71802ac6454SAndrew Thompson ue->ue_udev = uaa->device; 71902ac6454SAndrew Thompson ue->ue_mtx = &sc->sc_mtx; 72002ac6454SAndrew Thompson ue->ue_methods = &axe_ue_methods; 72102ac6454SAndrew Thompson 722a593f6b8SAndrew Thompson error = uether_ifattach(ue); 72302ac6454SAndrew Thompson if (error) { 72402ac6454SAndrew Thompson device_printf(dev, "could not attach interface\n"); 72502ac6454SAndrew Thompson goto detach; 72602ac6454SAndrew Thompson } 72702ac6454SAndrew Thompson return (0); /* success */ 72802ac6454SAndrew Thompson 72902ac6454SAndrew Thompson detach: 73002ac6454SAndrew Thompson axe_detach(dev); 73102ac6454SAndrew Thompson return (ENXIO); /* failure */ 73202ac6454SAndrew Thompson } 73302ac6454SAndrew Thompson 73402ac6454SAndrew Thompson static int 73502ac6454SAndrew Thompson axe_detach(device_t dev) 73602ac6454SAndrew Thompson { 73702ac6454SAndrew Thompson struct axe_softc *sc = device_get_softc(dev); 738760bc48eSAndrew Thompson struct usb_ether *ue = &sc->sc_ue; 73902ac6454SAndrew Thompson 740a593f6b8SAndrew Thompson usbd_transfer_unsetup(sc->sc_xfer, AXE_N_TRANSFER); 741a593f6b8SAndrew Thompson uether_ifdetach(ue); 74202ac6454SAndrew Thompson mtx_destroy(&sc->sc_mtx); 74302ac6454SAndrew Thompson 74402ac6454SAndrew Thompson return (0); 74502ac6454SAndrew Thompson } 74602ac6454SAndrew Thompson 74702ac6454SAndrew Thompson static void 748ed6d949aSAndrew Thompson axe_intr_callback(struct usb_xfer *xfer, usb_error_t error) 74902ac6454SAndrew Thompson { 75002ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 75102ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 75202ac6454SAndrew Thompson case USB_ST_SETUP: 75302ac6454SAndrew Thompson tr_setup: 754ed6d949aSAndrew Thompson usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 755a593f6b8SAndrew Thompson usbd_transfer_submit(xfer); 75602ac6454SAndrew Thompson return; 75702ac6454SAndrew Thompson 75802ac6454SAndrew Thompson default: /* Error */ 759ed6d949aSAndrew Thompson if (error != USB_ERR_CANCELLED) { 76002ac6454SAndrew Thompson /* try to clear stall first */ 761ed6d949aSAndrew Thompson usbd_xfer_set_stall(xfer); 76202ac6454SAndrew Thompson goto tr_setup; 76302ac6454SAndrew Thompson } 76402ac6454SAndrew Thompson return; 76502ac6454SAndrew Thompson } 76602ac6454SAndrew Thompson } 76702ac6454SAndrew Thompson 76802ac6454SAndrew Thompson #if (AXE_BULK_BUF_SIZE >= 0x10000) 76902ac6454SAndrew Thompson #error "Please update axe_bulk_read_callback()!" 77002ac6454SAndrew Thompson #endif 77102ac6454SAndrew Thompson 77202ac6454SAndrew Thompson static void 773ed6d949aSAndrew Thompson axe_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error) 77402ac6454SAndrew Thompson { 775ed6d949aSAndrew Thompson struct axe_softc *sc = usbd_xfer_softc(xfer); 776760bc48eSAndrew Thompson struct usb_ether *ue = &sc->sc_ue; 777a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 77802ac6454SAndrew Thompson struct axe_sframe_hdr hdr; 779ed6d949aSAndrew Thompson struct usb_page_cache *pc; 7803ac526e0SAndrew Thompson int err, pos, len; 781ed6d949aSAndrew Thompson int actlen; 782ed6d949aSAndrew Thompson 783ed6d949aSAndrew Thompson usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL); 78402ac6454SAndrew Thompson 78502ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 78602ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 78702ac6454SAndrew Thompson pos = 0; 7883ac526e0SAndrew Thompson len = 0; 7893ac526e0SAndrew Thompson err = 0; 7903ac526e0SAndrew Thompson 791ed6d949aSAndrew Thompson pc = usbd_xfer_get_frame(xfer, 0); 79202ac6454SAndrew Thompson if (sc->sc_flags & (AXE_FLAG_772 | AXE_FLAG_178)) { 7933ac526e0SAndrew Thompson while (pos < actlen) { 7943ac526e0SAndrew Thompson if ((pos + sizeof(hdr)) > actlen) { 79502ac6454SAndrew Thompson /* too little data */ 7963ac526e0SAndrew Thompson err = EINVAL; 79702ac6454SAndrew Thompson break; 79802ac6454SAndrew Thompson } 799ed6d949aSAndrew Thompson usbd_copy_out(pc, pos, &hdr, sizeof(hdr)); 80002ac6454SAndrew Thompson 80102ac6454SAndrew Thompson if ((hdr.len ^ hdr.ilen) != 0xFFFF) { 80202ac6454SAndrew Thompson /* we lost sync */ 8033ac526e0SAndrew Thompson err = EINVAL; 80402ac6454SAndrew Thompson break; 80502ac6454SAndrew Thompson } 80602ac6454SAndrew Thompson pos += sizeof(hdr); 80702ac6454SAndrew Thompson 80802ac6454SAndrew Thompson len = le16toh(hdr.len); 8093ac526e0SAndrew Thompson if ((pos + len) > actlen) { 81002ac6454SAndrew Thompson /* invalid length */ 8113ac526e0SAndrew Thompson err = EINVAL; 81202ac6454SAndrew Thompson break; 81302ac6454SAndrew Thompson } 814ed6d949aSAndrew Thompson err = uether_rxbuf(ue, pc, pos, len); 81502ac6454SAndrew Thompson 8163ac526e0SAndrew Thompson pos += len + (len % 2); 81702ac6454SAndrew Thompson } 8183ac526e0SAndrew Thompson } else { 8193ac526e0SAndrew Thompson err = uether_rxbuf(ue, pc, 0, actlen); 82002ac6454SAndrew Thompson } 82102ac6454SAndrew Thompson 8223ac526e0SAndrew Thompson if (err != 0) 82302ac6454SAndrew Thompson ifp->if_ierrors++; 82402ac6454SAndrew Thompson 82502ac6454SAndrew Thompson /* FALLTHROUGH */ 82602ac6454SAndrew Thompson case USB_ST_SETUP: 82702ac6454SAndrew Thompson tr_setup: 828ed6d949aSAndrew Thompson usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer)); 829a593f6b8SAndrew Thompson usbd_transfer_submit(xfer); 830a593f6b8SAndrew Thompson uether_rxflush(ue); 83102ac6454SAndrew Thompson return; 83202ac6454SAndrew Thompson 83302ac6454SAndrew Thompson default: /* Error */ 834ed6d949aSAndrew Thompson DPRINTF("bulk read error, %s\n", usbd_errstr(error)); 83502ac6454SAndrew Thompson 836ed6d949aSAndrew Thompson if (error != USB_ERR_CANCELLED) { 83702ac6454SAndrew Thompson /* try to clear stall first */ 838ed6d949aSAndrew Thompson usbd_xfer_set_stall(xfer); 83902ac6454SAndrew Thompson goto tr_setup; 84002ac6454SAndrew Thompson } 84102ac6454SAndrew Thompson return; 84202ac6454SAndrew Thompson 84302ac6454SAndrew Thompson } 84402ac6454SAndrew Thompson } 84502ac6454SAndrew Thompson 84602ac6454SAndrew Thompson #if ((AXE_BULK_BUF_SIZE >= 0x10000) || (AXE_BULK_BUF_SIZE < (MCLBYTES+4))) 84702ac6454SAndrew Thompson #error "Please update axe_bulk_write_callback()!" 84802ac6454SAndrew Thompson #endif 84902ac6454SAndrew Thompson 85002ac6454SAndrew Thompson static void 851ed6d949aSAndrew Thompson axe_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error) 85202ac6454SAndrew Thompson { 853ed6d949aSAndrew Thompson struct axe_softc *sc = usbd_xfer_softc(xfer); 85402ac6454SAndrew Thompson struct axe_sframe_hdr hdr; 855a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(&sc->sc_ue); 856ed6d949aSAndrew Thompson struct usb_page_cache *pc; 85702ac6454SAndrew Thompson struct mbuf *m; 85802ac6454SAndrew Thompson int pos; 85902ac6454SAndrew Thompson 86002ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 86102ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 86202ac6454SAndrew Thompson DPRINTFN(11, "transfer complete\n"); 86302ac6454SAndrew Thompson ifp->if_opackets++; 86402ac6454SAndrew Thompson /* FALLTHROUGH */ 86502ac6454SAndrew Thompson case USB_ST_SETUP: 86602ac6454SAndrew Thompson tr_setup: 86702ac6454SAndrew Thompson if ((sc->sc_flags & AXE_FLAG_LINK) == 0) { 86802ac6454SAndrew Thompson /* 86902ac6454SAndrew Thompson * don't send anything if there is no link ! 87002ac6454SAndrew Thompson */ 87102ac6454SAndrew Thompson return; 87202ac6454SAndrew Thompson } 87302ac6454SAndrew Thompson pos = 0; 874ed6d949aSAndrew Thompson pc = usbd_xfer_get_frame(xfer, 0); 87502ac6454SAndrew Thompson 87602ac6454SAndrew Thompson while (1) { 87702ac6454SAndrew Thompson 87802ac6454SAndrew Thompson IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 87902ac6454SAndrew Thompson 88002ac6454SAndrew Thompson if (m == NULL) { 88102ac6454SAndrew Thompson if (pos > 0) 88202ac6454SAndrew Thompson break; /* send out data */ 88302ac6454SAndrew Thompson return; 88402ac6454SAndrew Thompson } 88502ac6454SAndrew Thompson if (m->m_pkthdr.len > MCLBYTES) { 88602ac6454SAndrew Thompson m->m_pkthdr.len = MCLBYTES; 88702ac6454SAndrew Thompson } 88802ac6454SAndrew Thompson if (sc->sc_flags & (AXE_FLAG_772 | AXE_FLAG_178)) { 88902ac6454SAndrew Thompson 89002ac6454SAndrew Thompson hdr.len = htole16(m->m_pkthdr.len); 89102ac6454SAndrew Thompson hdr.ilen = ~hdr.len; 89202ac6454SAndrew Thompson 893ed6d949aSAndrew Thompson usbd_copy_in(pc, pos, &hdr, sizeof(hdr)); 89402ac6454SAndrew Thompson 89502ac6454SAndrew Thompson pos += sizeof(hdr); 89602ac6454SAndrew Thompson 89702ac6454SAndrew Thompson /* 89802ac6454SAndrew Thompson * NOTE: Some drivers force a short packet 89902ac6454SAndrew Thompson * by appending a dummy header with zero 90002ac6454SAndrew Thompson * length at then end of the USB transfer. 90102ac6454SAndrew Thompson * This driver uses the 90202ac6454SAndrew Thompson * USB_FORCE_SHORT_XFER flag instead. 90302ac6454SAndrew Thompson */ 90402ac6454SAndrew Thompson } 905ed6d949aSAndrew Thompson usbd_m_copy_in(pc, pos, m, 0, m->m_pkthdr.len); 90602ac6454SAndrew Thompson pos += m->m_pkthdr.len; 90702ac6454SAndrew Thompson 90802ac6454SAndrew Thompson /* 90902ac6454SAndrew Thompson * if there's a BPF listener, bounce a copy 91002ac6454SAndrew Thompson * of this frame to him: 91102ac6454SAndrew Thompson */ 91202ac6454SAndrew Thompson BPF_MTAP(ifp, m); 91302ac6454SAndrew Thompson 91402ac6454SAndrew Thompson m_freem(m); 91502ac6454SAndrew Thompson 91602ac6454SAndrew Thompson if (sc->sc_flags & (AXE_FLAG_772 | AXE_FLAG_178)) { 91702ac6454SAndrew Thompson if (pos > (AXE_BULK_BUF_SIZE - MCLBYTES - sizeof(hdr))) { 91802ac6454SAndrew Thompson /* send out frame(s) */ 91902ac6454SAndrew Thompson break; 92002ac6454SAndrew Thompson } 92102ac6454SAndrew Thompson } else { 92202ac6454SAndrew Thompson /* send out frame */ 92302ac6454SAndrew Thompson break; 92402ac6454SAndrew Thompson } 92502ac6454SAndrew Thompson } 92602ac6454SAndrew Thompson 927ed6d949aSAndrew Thompson usbd_xfer_set_frame_len(xfer, 0, pos); 928a593f6b8SAndrew Thompson usbd_transfer_submit(xfer); 92902ac6454SAndrew Thompson return; 93002ac6454SAndrew Thompson 93102ac6454SAndrew Thompson default: /* Error */ 93202ac6454SAndrew Thompson DPRINTFN(11, "transfer error, %s\n", 933ed6d949aSAndrew Thompson usbd_errstr(error)); 93402ac6454SAndrew Thompson 93502ac6454SAndrew Thompson ifp->if_oerrors++; 93602ac6454SAndrew Thompson 937ed6d949aSAndrew Thompson if (error != USB_ERR_CANCELLED) { 93802ac6454SAndrew Thompson /* try to clear stall first */ 939ed6d949aSAndrew Thompson usbd_xfer_set_stall(xfer); 94002ac6454SAndrew Thompson goto tr_setup; 94102ac6454SAndrew Thompson } 94202ac6454SAndrew Thompson return; 94302ac6454SAndrew Thompson 94402ac6454SAndrew Thompson } 94502ac6454SAndrew Thompson } 94602ac6454SAndrew Thompson 94702ac6454SAndrew Thompson static void 948760bc48eSAndrew Thompson axe_tick(struct usb_ether *ue) 94902ac6454SAndrew Thompson { 950a593f6b8SAndrew Thompson struct axe_softc *sc = uether_getsc(ue); 95102ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 95202ac6454SAndrew Thompson 95302ac6454SAndrew Thompson AXE_LOCK_ASSERT(sc, MA_OWNED); 95402ac6454SAndrew Thompson 95502ac6454SAndrew Thompson mii_tick(mii); 95602ac6454SAndrew Thompson if ((sc->sc_flags & AXE_FLAG_LINK) == 0) { 95702ac6454SAndrew Thompson axe_miibus_statchg(ue->ue_dev); 95802ac6454SAndrew Thompson if ((sc->sc_flags & AXE_FLAG_LINK) != 0) 95902ac6454SAndrew Thompson axe_start(ue); 96002ac6454SAndrew Thompson } 96102ac6454SAndrew Thompson } 96202ac6454SAndrew Thompson 96302ac6454SAndrew Thompson static void 964760bc48eSAndrew Thompson axe_start(struct usb_ether *ue) 96502ac6454SAndrew Thompson { 966a593f6b8SAndrew Thompson struct axe_softc *sc = uether_getsc(ue); 96702ac6454SAndrew Thompson 96802ac6454SAndrew Thompson /* 96902ac6454SAndrew Thompson * start the USB transfers, if not already started: 97002ac6454SAndrew Thompson */ 971a593f6b8SAndrew Thompson usbd_transfer_start(sc->sc_xfer[AXE_INTR_DT_RD]); 972a593f6b8SAndrew Thompson usbd_transfer_start(sc->sc_xfer[AXE_BULK_DT_RD]); 973a593f6b8SAndrew Thompson usbd_transfer_start(sc->sc_xfer[AXE_BULK_DT_WR]); 97402ac6454SAndrew Thompson } 97502ac6454SAndrew Thompson 97602ac6454SAndrew Thompson static void 977760bc48eSAndrew Thompson axe_init(struct usb_ether *ue) 97802ac6454SAndrew Thompson { 979a593f6b8SAndrew Thompson struct axe_softc *sc = uether_getsc(ue); 980a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 98102ac6454SAndrew Thompson uint16_t rxmode; 98202ac6454SAndrew Thompson 98302ac6454SAndrew Thompson AXE_LOCK_ASSERT(sc, MA_OWNED); 98402ac6454SAndrew Thompson 98502ac6454SAndrew Thompson /* Cancel pending I/O */ 98602ac6454SAndrew Thompson axe_stop(ue); 98702ac6454SAndrew Thompson 98887832c5eSAndrew Thompson /* Set MAC address. */ 98987832c5eSAndrew Thompson if (sc->sc_flags & (AXE_FLAG_178 | AXE_FLAG_772)) 99087832c5eSAndrew Thompson axe_cmd(sc, AXE_178_CMD_WRITE_NODEID, 0, 0, IF_LLADDR(ifp)); 99187832c5eSAndrew Thompson else 99287832c5eSAndrew Thompson axe_cmd(sc, AXE_172_CMD_WRITE_NODEID, 0, 0, IF_LLADDR(ifp)); 99302ac6454SAndrew Thompson 99402ac6454SAndrew Thompson /* Set transmitter IPG values */ 99502ac6454SAndrew Thompson if (sc->sc_flags & (AXE_FLAG_178 | AXE_FLAG_772)) { 99602ac6454SAndrew Thompson axe_cmd(sc, AXE_178_CMD_WRITE_IPG012, sc->sc_ipgs[2], 99702ac6454SAndrew Thompson (sc->sc_ipgs[1] << 8) | (sc->sc_ipgs[0]), NULL); 99802ac6454SAndrew Thompson } else { 99902ac6454SAndrew Thompson axe_cmd(sc, AXE_172_CMD_WRITE_IPG0, 0, sc->sc_ipgs[0], NULL); 100002ac6454SAndrew Thompson axe_cmd(sc, AXE_172_CMD_WRITE_IPG1, 0, sc->sc_ipgs[1], NULL); 100102ac6454SAndrew Thompson axe_cmd(sc, AXE_172_CMD_WRITE_IPG2, 0, sc->sc_ipgs[2], NULL); 100202ac6454SAndrew Thompson } 100302ac6454SAndrew Thompson 100402ac6454SAndrew Thompson /* Enable receiver, set RX mode */ 100502ac6454SAndrew Thompson rxmode = (AXE_RXCMD_MULTICAST | AXE_RXCMD_ENABLE); 100602ac6454SAndrew Thompson if (sc->sc_flags & (AXE_FLAG_178 | AXE_FLAG_772)) { 10073ac526e0SAndrew Thompson #if 0 100802ac6454SAndrew Thompson rxmode |= AXE_178_RXCMD_MFB_2048; /* chip default */ 10093ac526e0SAndrew Thompson #else 10103ac526e0SAndrew Thompson /* 10113ac526e0SAndrew Thompson * Default Rx buffer size is too small to get 10123ac526e0SAndrew Thompson * maximum performance. 10133ac526e0SAndrew Thompson */ 10143ac526e0SAndrew Thompson rxmode |= AXE_178_RXCMD_MFB_16384; 10153ac526e0SAndrew Thompson #endif 101602ac6454SAndrew Thompson } else { 101702ac6454SAndrew Thompson rxmode |= AXE_172_RXCMD_UNICAST; 101802ac6454SAndrew Thompson } 101902ac6454SAndrew Thompson 102002ac6454SAndrew Thompson /* If we want promiscuous mode, set the allframes bit. */ 102102ac6454SAndrew Thompson if (ifp->if_flags & IFF_PROMISC) 102202ac6454SAndrew Thompson rxmode |= AXE_RXCMD_PROMISC; 102302ac6454SAndrew Thompson 102402ac6454SAndrew Thompson if (ifp->if_flags & IFF_BROADCAST) 102502ac6454SAndrew Thompson rxmode |= AXE_RXCMD_BROADCAST; 102602ac6454SAndrew Thompson 102702ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); 102802ac6454SAndrew Thompson 102902ac6454SAndrew Thompson /* Load the multicast filter. */ 103002ac6454SAndrew Thompson axe_setmulti(ue); 103102ac6454SAndrew Thompson 1032ed6d949aSAndrew Thompson usbd_xfer_set_stall(sc->sc_xfer[AXE_BULK_DT_WR]); 103302ac6454SAndrew Thompson 103402ac6454SAndrew Thompson ifp->if_drv_flags |= IFF_DRV_RUNNING; 103502ac6454SAndrew Thompson axe_start(ue); 103602ac6454SAndrew Thompson } 103702ac6454SAndrew Thompson 103802ac6454SAndrew Thompson static void 1039760bc48eSAndrew Thompson axe_setpromisc(struct usb_ether *ue) 104002ac6454SAndrew Thompson { 1041a593f6b8SAndrew Thompson struct axe_softc *sc = uether_getsc(ue); 1042a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 104302ac6454SAndrew Thompson uint16_t rxmode; 104402ac6454SAndrew Thompson 104502ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, &rxmode); 104602ac6454SAndrew Thompson 104702ac6454SAndrew Thompson rxmode = le16toh(rxmode); 104802ac6454SAndrew Thompson 104902ac6454SAndrew Thompson if (ifp->if_flags & IFF_PROMISC) { 105002ac6454SAndrew Thompson rxmode |= AXE_RXCMD_PROMISC; 105102ac6454SAndrew Thompson } else { 105202ac6454SAndrew Thompson rxmode &= ~AXE_RXCMD_PROMISC; 105302ac6454SAndrew Thompson } 105402ac6454SAndrew Thompson 105502ac6454SAndrew Thompson axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); 105602ac6454SAndrew Thompson 105702ac6454SAndrew Thompson axe_setmulti(ue); 105802ac6454SAndrew Thompson } 105902ac6454SAndrew Thompson 106002ac6454SAndrew Thompson static void 1061760bc48eSAndrew Thompson axe_stop(struct usb_ether *ue) 106202ac6454SAndrew Thompson { 1063a593f6b8SAndrew Thompson struct axe_softc *sc = uether_getsc(ue); 1064a593f6b8SAndrew Thompson struct ifnet *ifp = uether_getifp(ue); 106502ac6454SAndrew Thompson 106602ac6454SAndrew Thompson AXE_LOCK_ASSERT(sc, MA_OWNED); 106702ac6454SAndrew Thompson 106802ac6454SAndrew Thompson ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 106902ac6454SAndrew Thompson sc->sc_flags &= ~AXE_FLAG_LINK; 107002ac6454SAndrew Thompson 107102ac6454SAndrew Thompson /* 107202ac6454SAndrew Thompson * stop all the transfers, if not already stopped: 107302ac6454SAndrew Thompson */ 1074a593f6b8SAndrew Thompson usbd_transfer_stop(sc->sc_xfer[AXE_BULK_DT_WR]); 1075a593f6b8SAndrew Thompson usbd_transfer_stop(sc->sc_xfer[AXE_BULK_DT_RD]); 1076a593f6b8SAndrew Thompson usbd_transfer_stop(sc->sc_xfer[AXE_INTR_DT_RD]); 107702ac6454SAndrew Thompson 107802ac6454SAndrew Thompson axe_reset(sc); 107902ac6454SAndrew Thompson } 1080