102ac6454SAndrew Thompson /*- 202ac6454SAndrew Thompson * Copyright (c) 1997, 1998, 1999, 2000 302ac6454SAndrew Thompson * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 402ac6454SAndrew Thompson * 502ac6454SAndrew Thompson * Copyright (c) 2006 65d38a4d4SEd Schouten * Alfred Perlstein <alfred@FreeBSD.org>. All rights reserved. 702ac6454SAndrew Thompson * 802ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 902ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 1002ac6454SAndrew Thompson * are met: 1102ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1202ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1302ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1402ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1502ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1602ac6454SAndrew Thompson * 3. All advertising materials mentioning features or use of this software 1702ac6454SAndrew Thompson * must display the following acknowledgement: 1802ac6454SAndrew Thompson * This product includes software developed by Bill Paul. 1902ac6454SAndrew Thompson * 4. Neither the name of the author nor the names of any co-contributors 2002ac6454SAndrew Thompson * may be used to endorse or promote products derived from this software 2102ac6454SAndrew Thompson * without specific prior written permission. 2202ac6454SAndrew Thompson * 2302ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2402ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2502ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2602ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 2702ac6454SAndrew Thompson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2802ac6454SAndrew Thompson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2902ac6454SAndrew Thompson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3002ac6454SAndrew Thompson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3102ac6454SAndrew Thompson * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3202ac6454SAndrew Thompson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 3302ac6454SAndrew Thompson * THE POSSIBILITY OF SUCH DAMAGE. 3402ac6454SAndrew Thompson */ 3502ac6454SAndrew Thompson 3602ac6454SAndrew Thompson #include <sys/cdefs.h> 3702ac6454SAndrew Thompson __FBSDID("$FreeBSD$"); 3802ac6454SAndrew Thompson 3902ac6454SAndrew Thompson /* 4002ac6454SAndrew Thompson * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver. 4102ac6454SAndrew Thompson * Datasheet is available from http://www.admtek.com.tw. 4202ac6454SAndrew Thompson * 4302ac6454SAndrew Thompson * Written by Bill Paul <wpaul@ee.columbia.edu> 4402ac6454SAndrew Thompson * Electrical Engineering Department 4502ac6454SAndrew Thompson * Columbia University, New York City 4602ac6454SAndrew Thompson * 475d38a4d4SEd Schouten * SMP locking by Alfred Perlstein <alfred@FreeBSD.org>. 4802ac6454SAndrew Thompson * RED Inc. 4902ac6454SAndrew Thompson */ 5002ac6454SAndrew Thompson 5102ac6454SAndrew Thompson /* 5202ac6454SAndrew Thompson * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet 5302ac6454SAndrew Thompson * support: the control endpoint for reading/writing registers, burst 5402ac6454SAndrew Thompson * read endpoint for packet reception, burst write for packet transmission 5502ac6454SAndrew Thompson * and one for "interrupts." The chip uses the same RX filter scheme 5602ac6454SAndrew Thompson * as the other ADMtek ethernet parts: one perfect filter entry for the 5702ac6454SAndrew Thompson * the station address and a 64-bit multicast hash table. The chip supports 5802ac6454SAndrew Thompson * both MII and HomePNA attachments. 5902ac6454SAndrew Thompson * 6002ac6454SAndrew Thompson * Since the maximum data transfer speed of USB is supposed to be 12Mbps, 6102ac6454SAndrew Thompson * you're never really going to get 100Mbps speeds from this device. I 6202ac6454SAndrew Thompson * think the idea is to allow the device to connect to 10 or 100Mbps 6302ac6454SAndrew Thompson * networks, not necessarily to provide 100Mbps performance. Also, since 6402ac6454SAndrew Thompson * the controller uses an external PHY chip, it's possible that board 6502ac6454SAndrew Thompson * designers might simply choose a 10Mbps PHY. 6602ac6454SAndrew Thompson * 6702ac6454SAndrew Thompson * Registers are accessed using usb2_ether_do_request(). Packet 6802ac6454SAndrew Thompson * transfers are done using usb2_transfer() and friends. 6902ac6454SAndrew Thompson */ 7002ac6454SAndrew Thompson 7102ac6454SAndrew Thompson #include "usbdevs.h" 7202ac6454SAndrew Thompson #include <dev/usb/usb.h> 7302ac6454SAndrew Thompson #include <dev/usb/usb_mfunc.h> 7402ac6454SAndrew Thompson #include <dev/usb/usb_error.h> 7502ac6454SAndrew Thompson 7602ac6454SAndrew Thompson #define USB_DEBUG_VAR aue_debug 7702ac6454SAndrew Thompson 7802ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 7902ac6454SAndrew Thompson #include <dev/usb/usb_lookup.h> 8002ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 8102ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 8202ac6454SAndrew Thompson #include <dev/usb/usb_request.h> 8302ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h> 8402ac6454SAndrew Thompson #include <dev/usb/usb_util.h> 8502ac6454SAndrew Thompson 8602ac6454SAndrew Thompson #include <dev/usb/net/usb_ethernet.h> 8702ac6454SAndrew Thompson #include <dev/usb/net/if_auereg.h> 8802ac6454SAndrew Thompson 8902ac6454SAndrew Thompson #if USB_DEBUG 9002ac6454SAndrew Thompson static int aue_debug = 0; 9102ac6454SAndrew Thompson 9202ac6454SAndrew Thompson SYSCTL_NODE(_hw_usb2, OID_AUTO, aue, CTLFLAG_RW, 0, "USB aue"); 9302ac6454SAndrew Thompson SYSCTL_INT(_hw_usb2_aue, OID_AUTO, debug, CTLFLAG_RW, &aue_debug, 0, 9402ac6454SAndrew Thompson "Debug level"); 9502ac6454SAndrew Thompson #endif 9602ac6454SAndrew Thompson 9702ac6454SAndrew Thompson /* 9802ac6454SAndrew Thompson * Various supported device vendors/products. 9902ac6454SAndrew Thompson */ 10002ac6454SAndrew Thompson static const struct usb2_device_id aue_devs[] = { 10102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B, AUE_FLAG_PII)}, 10202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA, 0)}, 10302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000, AUE_FLAG_LSYS)}, 10402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10, 0)}, 10502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1, AUE_FLAG_PNA | AUE_FLAG_PII)}, 10602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2, AUE_FLAG_PII)}, 10702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4, AUE_FLAG_PNA)}, 10802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5, AUE_FLAG_PNA)}, 10902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6, AUE_FLAG_PII)}, 11002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7, AUE_FLAG_PII)}, 11102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8, AUE_FLAG_PII)}, 11202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9, AUE_FLAG_PNA)}, 11302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001, AUE_FLAG_PII)}, 11402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC, 0)}, 11502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2, AUE_FLAG_PII)}, 11602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3, AUE_FLAG_PII)}, 11702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_4, AUE_FLAG_PII)}, 11802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII, AUE_FLAG_PII)}, 11902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, AUE_FLAG_PNA | AUE_FLAG_DUAL_PHY)}, 12002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_AEI, USB_PRODUCT_AEI_FASTETHERNET, AUE_FLAG_PII)}, 12102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ALLIEDTELESYN, USB_PRODUCT_ALLIEDTELESYN_ATUSB100, AUE_FLAG_PII)}, 12202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC110T, AUE_FLAG_PII)}, 12302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN, AUE_FLAG_PII)}, 12402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, 0)}, 12502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100, AUE_FLAG_PII)}, 12602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100, 0)}, 12702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100, AUE_FLAG_PNA)}, 12802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS, AUE_FLAG_PII)}, 12902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX, 0)}, 13002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1, AUE_FLAG_LSYS)}, 13102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 13202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 13302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 13402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA, AUE_FLAG_PNA)}, 13502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX, AUE_FLAG_LSYS)}, 13602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650, AUE_FLAG_LSYS)}, 13702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELCON, USB_PRODUCT_ELCON_PLAN, AUE_FLAG_PNA | AUE_FLAG_PII)}, 13802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSB20, AUE_FLAG_PII)}, 13902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX, AUE_FLAG_PII)}, 14002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0, 0)}, 14102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1, AUE_FLAG_LSYS)}, 14202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2, 0)}, 14302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3, AUE_FLAG_LSYS)}, 14402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET, 0)}, 14502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNBR402W, 0)}, 14602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100, AUE_FLAG_PII)}, 14702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HN210E, AUE_FLAG_PII)}, 14802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS, AUE_FLAG_PII)}, 14902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX, 0)}, 15002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX, 0)}, 15102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1, AUE_FLAG_LSYS | AUE_FLAG_PNA)}, 15202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX, AUE_FLAG_LSYS)}, 15302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA, AUE_FLAG_LSYS)}, 15402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 15502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 15602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T, AUE_FLAG_LSYS)}, 15702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5, AUE_FLAG_PII)}, 15802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1, 0)}, 15902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5, 0)}, 16002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110, AUE_FLAG_PII)}, 16102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101, AUE_FLAG_PII)}, 16202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM, AUE_FLAG_PII)}, 16302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIIG2, USB_PRODUCT_SIIG2_USBTOETHER, AUE_FLAG_PII)}, 16402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC, AUE_FLAG_PII)}, 16502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB, 0)}, 16602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB, AUE_FLAG_PII)}, 16702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100, 0)}, 16802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB110, AUE_FLAG_PII)}, 16902ac6454SAndrew Thompson }; 17002ac6454SAndrew Thompson 17102ac6454SAndrew Thompson /* prototypes */ 17202ac6454SAndrew Thompson 17302ac6454SAndrew Thompson static device_probe_t aue_probe; 17402ac6454SAndrew Thompson static device_attach_t aue_attach; 17502ac6454SAndrew Thompson static device_detach_t aue_detach; 17602ac6454SAndrew Thompson static device_shutdown_t aue_shutdown; 17702ac6454SAndrew Thompson static miibus_readreg_t aue_miibus_readreg; 17802ac6454SAndrew Thompson static miibus_writereg_t aue_miibus_writereg; 17902ac6454SAndrew Thompson static miibus_statchg_t aue_miibus_statchg; 18002ac6454SAndrew Thompson 18102ac6454SAndrew Thompson static usb2_callback_t aue_intr_callback; 18202ac6454SAndrew Thompson static usb2_callback_t aue_bulk_read_callback; 18302ac6454SAndrew Thompson static usb2_callback_t aue_bulk_write_callback; 18402ac6454SAndrew Thompson 18502ac6454SAndrew Thompson static usb2_ether_fn_t aue_attach_post; 18602ac6454SAndrew Thompson static usb2_ether_fn_t aue_init; 18702ac6454SAndrew Thompson static usb2_ether_fn_t aue_stop; 18802ac6454SAndrew Thompson static usb2_ether_fn_t aue_start; 18902ac6454SAndrew Thompson static usb2_ether_fn_t aue_tick; 19002ac6454SAndrew Thompson static usb2_ether_fn_t aue_setmulti; 19102ac6454SAndrew Thompson static usb2_ether_fn_t aue_setpromisc; 19202ac6454SAndrew Thompson 19302ac6454SAndrew Thompson static uint8_t aue_csr_read_1(struct aue_softc *, uint16_t); 19402ac6454SAndrew Thompson static uint16_t aue_csr_read_2(struct aue_softc *, uint16_t); 19502ac6454SAndrew Thompson static void aue_csr_write_1(struct aue_softc *, uint16_t, uint8_t); 19602ac6454SAndrew Thompson static void aue_csr_write_2(struct aue_softc *, uint16_t, uint16_t); 19702ac6454SAndrew Thompson static void aue_eeprom_getword(struct aue_softc *, int, uint16_t *); 19802ac6454SAndrew Thompson static void aue_read_eeprom(struct aue_softc *, uint8_t *, uint16_t, 19902ac6454SAndrew Thompson uint16_t); 20002ac6454SAndrew Thompson static void aue_reset(struct aue_softc *); 20102ac6454SAndrew Thompson static void aue_reset_pegasus_II(struct aue_softc *); 20202ac6454SAndrew Thompson 20302ac6454SAndrew Thompson static int aue_ifmedia_upd(struct ifnet *); 20402ac6454SAndrew Thompson static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *); 20502ac6454SAndrew Thompson 20602ac6454SAndrew Thompson static const struct usb2_config aue_config[AUE_N_TRANSFER] = { 20702ac6454SAndrew Thompson 20802ac6454SAndrew Thompson [AUE_BULK_DT_WR] = { 20902ac6454SAndrew Thompson .type = UE_BULK, 21002ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 21102ac6454SAndrew Thompson .direction = UE_DIR_OUT, 2124eae601eSAndrew Thompson .bufsize = (MCLBYTES + 2), 2134eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 2144eae601eSAndrew Thompson .callback = aue_bulk_write_callback, 2154eae601eSAndrew Thompson .timeout = 10000, /* 10 seconds */ 21602ac6454SAndrew Thompson }, 21702ac6454SAndrew Thompson 21802ac6454SAndrew Thompson [AUE_BULK_DT_RD] = { 21902ac6454SAndrew Thompson .type = UE_BULK, 22002ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 22102ac6454SAndrew Thompson .direction = UE_DIR_IN, 2224eae601eSAndrew Thompson .bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN), 2234eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 2244eae601eSAndrew Thompson .callback = aue_bulk_read_callback, 22502ac6454SAndrew Thompson }, 22602ac6454SAndrew Thompson 22702ac6454SAndrew Thompson [AUE_INTR_DT_RD] = { 22802ac6454SAndrew Thompson .type = UE_INTERRUPT, 22902ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 23002ac6454SAndrew Thompson .direction = UE_DIR_IN, 2314eae601eSAndrew Thompson .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 2324eae601eSAndrew Thompson .bufsize = 0, /* use wMaxPacketSize */ 2334eae601eSAndrew Thompson .callback = aue_intr_callback, 23402ac6454SAndrew Thompson }, 23502ac6454SAndrew Thompson }; 23602ac6454SAndrew Thompson 23702ac6454SAndrew Thompson static device_method_t aue_methods[] = { 23802ac6454SAndrew Thompson /* Device interface */ 23902ac6454SAndrew Thompson DEVMETHOD(device_probe, aue_probe), 24002ac6454SAndrew Thompson DEVMETHOD(device_attach, aue_attach), 24102ac6454SAndrew Thompson DEVMETHOD(device_detach, aue_detach), 24202ac6454SAndrew Thompson DEVMETHOD(device_shutdown, aue_shutdown), 24302ac6454SAndrew Thompson 24402ac6454SAndrew Thompson /* bus interface */ 24502ac6454SAndrew Thompson DEVMETHOD(bus_print_child, bus_generic_print_child), 24602ac6454SAndrew Thompson DEVMETHOD(bus_driver_added, bus_generic_driver_added), 24702ac6454SAndrew Thompson 24802ac6454SAndrew Thompson /* MII interface */ 24902ac6454SAndrew Thompson DEVMETHOD(miibus_readreg, aue_miibus_readreg), 25002ac6454SAndrew Thompson DEVMETHOD(miibus_writereg, aue_miibus_writereg), 25102ac6454SAndrew Thompson DEVMETHOD(miibus_statchg, aue_miibus_statchg), 25202ac6454SAndrew Thompson 25302ac6454SAndrew Thompson {0, 0} 25402ac6454SAndrew Thompson }; 25502ac6454SAndrew Thompson 25602ac6454SAndrew Thompson static driver_t aue_driver = { 25702ac6454SAndrew Thompson .name = "aue", 25802ac6454SAndrew Thompson .methods = aue_methods, 25902ac6454SAndrew Thompson .size = sizeof(struct aue_softc) 26002ac6454SAndrew Thompson }; 26102ac6454SAndrew Thompson 26202ac6454SAndrew Thompson static devclass_t aue_devclass; 26302ac6454SAndrew Thompson 2649aef556dSAndrew Thompson DRIVER_MODULE(aue, uhub, aue_driver, aue_devclass, NULL, 0); 26502ac6454SAndrew Thompson DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0); 26602ac6454SAndrew Thompson MODULE_DEPEND(aue, uether, 1, 1, 1); 26702ac6454SAndrew Thompson MODULE_DEPEND(aue, usb, 1, 1, 1); 26802ac6454SAndrew Thompson MODULE_DEPEND(aue, ether, 1, 1, 1); 26902ac6454SAndrew Thompson MODULE_DEPEND(aue, miibus, 1, 1, 1); 27002ac6454SAndrew Thompson 27102ac6454SAndrew Thompson static const struct usb2_ether_methods aue_ue_methods = { 27202ac6454SAndrew Thompson .ue_attach_post = aue_attach_post, 27302ac6454SAndrew Thompson .ue_start = aue_start, 27402ac6454SAndrew Thompson .ue_init = aue_init, 27502ac6454SAndrew Thompson .ue_stop = aue_stop, 27602ac6454SAndrew Thompson .ue_tick = aue_tick, 27702ac6454SAndrew Thompson .ue_setmulti = aue_setmulti, 27802ac6454SAndrew Thompson .ue_setpromisc = aue_setpromisc, 27902ac6454SAndrew Thompson .ue_mii_upd = aue_ifmedia_upd, 28002ac6454SAndrew Thompson .ue_mii_sts = aue_ifmedia_sts, 28102ac6454SAndrew Thompson }; 28202ac6454SAndrew Thompson 28302ac6454SAndrew Thompson #define AUE_SETBIT(sc, reg, x) \ 28402ac6454SAndrew Thompson aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x)) 28502ac6454SAndrew Thompson 28602ac6454SAndrew Thompson #define AUE_CLRBIT(sc, reg, x) \ 28702ac6454SAndrew Thompson aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x)) 28802ac6454SAndrew Thompson 28902ac6454SAndrew Thompson static uint8_t 29002ac6454SAndrew Thompson aue_csr_read_1(struct aue_softc *sc, uint16_t reg) 29102ac6454SAndrew Thompson { 29202ac6454SAndrew Thompson struct usb2_device_request req; 29302ac6454SAndrew Thompson usb2_error_t err; 29402ac6454SAndrew Thompson uint8_t val; 29502ac6454SAndrew Thompson 29602ac6454SAndrew Thompson req.bmRequestType = UT_READ_VENDOR_DEVICE; 29702ac6454SAndrew Thompson req.bRequest = AUE_UR_READREG; 29802ac6454SAndrew Thompson USETW(req.wValue, 0); 29902ac6454SAndrew Thompson USETW(req.wIndex, reg); 30002ac6454SAndrew Thompson USETW(req.wLength, 1); 30102ac6454SAndrew Thompson 30202ac6454SAndrew Thompson err = usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000); 30302ac6454SAndrew Thompson if (err) 30402ac6454SAndrew Thompson return (0); 30502ac6454SAndrew Thompson return (val); 30602ac6454SAndrew Thompson } 30702ac6454SAndrew Thompson 30802ac6454SAndrew Thompson static uint16_t 30902ac6454SAndrew Thompson aue_csr_read_2(struct aue_softc *sc, uint16_t reg) 31002ac6454SAndrew Thompson { 31102ac6454SAndrew Thompson struct usb2_device_request req; 31202ac6454SAndrew Thompson usb2_error_t err; 31302ac6454SAndrew Thompson uint16_t val; 31402ac6454SAndrew Thompson 31502ac6454SAndrew Thompson req.bmRequestType = UT_READ_VENDOR_DEVICE; 31602ac6454SAndrew Thompson req.bRequest = AUE_UR_READREG; 31702ac6454SAndrew Thompson USETW(req.wValue, 0); 31802ac6454SAndrew Thompson USETW(req.wIndex, reg); 31902ac6454SAndrew Thompson USETW(req.wLength, 2); 32002ac6454SAndrew Thompson 32102ac6454SAndrew Thompson err = usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000); 32202ac6454SAndrew Thompson if (err) 32302ac6454SAndrew Thompson return (0); 32402ac6454SAndrew Thompson return (le16toh(val)); 32502ac6454SAndrew Thompson } 32602ac6454SAndrew Thompson 32702ac6454SAndrew Thompson static void 32802ac6454SAndrew Thompson aue_csr_write_1(struct aue_softc *sc, uint16_t reg, uint8_t val) 32902ac6454SAndrew Thompson { 33002ac6454SAndrew Thompson struct usb2_device_request req; 33102ac6454SAndrew Thompson 33202ac6454SAndrew Thompson req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 33302ac6454SAndrew Thompson req.bRequest = AUE_UR_WRITEREG; 33402ac6454SAndrew Thompson req.wValue[0] = val; 33502ac6454SAndrew Thompson req.wValue[1] = 0; 33602ac6454SAndrew Thompson USETW(req.wIndex, reg); 33702ac6454SAndrew Thompson USETW(req.wLength, 1); 33802ac6454SAndrew Thompson 33902ac6454SAndrew Thompson if (usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000)) { 34002ac6454SAndrew Thompson /* error ignored */ 34102ac6454SAndrew Thompson } 34202ac6454SAndrew Thompson } 34302ac6454SAndrew Thompson 34402ac6454SAndrew Thompson static void 34502ac6454SAndrew Thompson aue_csr_write_2(struct aue_softc *sc, uint16_t reg, uint16_t val) 34602ac6454SAndrew Thompson { 34702ac6454SAndrew Thompson struct usb2_device_request req; 34802ac6454SAndrew Thompson 34902ac6454SAndrew Thompson req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 35002ac6454SAndrew Thompson req.bRequest = AUE_UR_WRITEREG; 35102ac6454SAndrew Thompson USETW(req.wValue, val); 35202ac6454SAndrew Thompson USETW(req.wIndex, reg); 35302ac6454SAndrew Thompson USETW(req.wLength, 2); 35402ac6454SAndrew Thompson 35502ac6454SAndrew Thompson val = htole16(val); 35602ac6454SAndrew Thompson 35702ac6454SAndrew Thompson if (usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000)) { 35802ac6454SAndrew Thompson /* error ignored */ 35902ac6454SAndrew Thompson } 36002ac6454SAndrew Thompson } 36102ac6454SAndrew Thompson 36202ac6454SAndrew Thompson /* 36302ac6454SAndrew Thompson * Read a word of data stored in the EEPROM at address 'addr.' 36402ac6454SAndrew Thompson */ 36502ac6454SAndrew Thompson static void 36602ac6454SAndrew Thompson aue_eeprom_getword(struct aue_softc *sc, int addr, uint16_t *dest) 36702ac6454SAndrew Thompson { 36802ac6454SAndrew Thompson int i; 36902ac6454SAndrew Thompson uint16_t word = 0; 37002ac6454SAndrew Thompson 37102ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_EE_REG, addr); 37202ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); 37302ac6454SAndrew Thompson 37402ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 37502ac6454SAndrew Thompson if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) 37602ac6454SAndrew Thompson break; 37702ac6454SAndrew Thompson if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 37802ac6454SAndrew Thompson break; 37902ac6454SAndrew Thompson } 38002ac6454SAndrew Thompson 38102ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 38202ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "EEPROM read timed out\n"); 38302ac6454SAndrew Thompson 38402ac6454SAndrew Thompson word = aue_csr_read_2(sc, AUE_EE_DATA); 38502ac6454SAndrew Thompson *dest = word; 38602ac6454SAndrew Thompson } 38702ac6454SAndrew Thompson 38802ac6454SAndrew Thompson /* 38902ac6454SAndrew Thompson * Read a sequence of words from the EEPROM. 39002ac6454SAndrew Thompson */ 39102ac6454SAndrew Thompson static void 39202ac6454SAndrew Thompson aue_read_eeprom(struct aue_softc *sc, uint8_t *dest, 39302ac6454SAndrew Thompson uint16_t off, uint16_t len) 39402ac6454SAndrew Thompson { 39502ac6454SAndrew Thompson uint16_t *ptr = (uint16_t *)dest; 39602ac6454SAndrew Thompson int i; 39702ac6454SAndrew Thompson 39802ac6454SAndrew Thompson for (i = 0; i != len; i++, ptr++) 39902ac6454SAndrew Thompson aue_eeprom_getword(sc, off + i, ptr); 40002ac6454SAndrew Thompson } 40102ac6454SAndrew Thompson 40202ac6454SAndrew Thompson static int 40302ac6454SAndrew Thompson aue_miibus_readreg(device_t dev, int phy, int reg) 40402ac6454SAndrew Thompson { 40502ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 40602ac6454SAndrew Thompson int i, locked; 40702ac6454SAndrew Thompson uint16_t val = 0; 40802ac6454SAndrew Thompson 40902ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 41002ac6454SAndrew Thompson if (!locked) 41102ac6454SAndrew Thompson AUE_LOCK(sc); 41202ac6454SAndrew Thompson 41302ac6454SAndrew Thompson /* 41402ac6454SAndrew Thompson * The Am79C901 HomePNA PHY actually contains two transceivers: a 1Mbps 41502ac6454SAndrew Thompson * HomePNA PHY and a 10Mbps full/half duplex ethernet PHY with NWAY 41602ac6454SAndrew Thompson * autoneg. However in the ADMtek adapter, only the 1Mbps PHY is 41702ac6454SAndrew Thompson * actually connected to anything, so we ignore the 10Mbps one. It 41802ac6454SAndrew Thompson * happens to be configured for MII address 3, so we filter that out. 41902ac6454SAndrew Thompson */ 42002ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_DUAL_PHY) { 42102ac6454SAndrew Thompson if (phy == 3) 42202ac6454SAndrew Thompson goto done; 42302ac6454SAndrew Thompson #if 0 42402ac6454SAndrew Thompson if (phy != 1) 42502ac6454SAndrew Thompson goto done; 42602ac6454SAndrew Thompson #endif 42702ac6454SAndrew Thompson } 42802ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 42902ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); 43002ac6454SAndrew Thompson 43102ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 43202ac6454SAndrew Thompson if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 43302ac6454SAndrew Thompson break; 43402ac6454SAndrew Thompson if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 43502ac6454SAndrew Thompson break; 43602ac6454SAndrew Thompson } 43702ac6454SAndrew Thompson 43802ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 43902ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "MII read timed out\n"); 44002ac6454SAndrew Thompson 44102ac6454SAndrew Thompson val = aue_csr_read_2(sc, AUE_PHY_DATA); 44202ac6454SAndrew Thompson 44302ac6454SAndrew Thompson done: 44402ac6454SAndrew Thompson if (!locked) 44502ac6454SAndrew Thompson AUE_UNLOCK(sc); 44602ac6454SAndrew Thompson return (val); 44702ac6454SAndrew Thompson } 44802ac6454SAndrew Thompson 44902ac6454SAndrew Thompson static int 45002ac6454SAndrew Thompson aue_miibus_writereg(device_t dev, int phy, int reg, int data) 45102ac6454SAndrew Thompson { 45202ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 45302ac6454SAndrew Thompson int i; 45402ac6454SAndrew Thompson int locked; 45502ac6454SAndrew Thompson 45602ac6454SAndrew Thompson if (phy == 3) 45702ac6454SAndrew Thompson return (0); 45802ac6454SAndrew Thompson 45902ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 46002ac6454SAndrew Thompson if (!locked) 46102ac6454SAndrew Thompson AUE_LOCK(sc); 46202ac6454SAndrew Thompson 46302ac6454SAndrew Thompson aue_csr_write_2(sc, AUE_PHY_DATA, data); 46402ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 46502ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); 46602ac6454SAndrew Thompson 46702ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 46802ac6454SAndrew Thompson if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 46902ac6454SAndrew Thompson break; 47002ac6454SAndrew Thompson if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 47102ac6454SAndrew Thompson break; 47202ac6454SAndrew Thompson } 47302ac6454SAndrew Thompson 47402ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 47502ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "MII read timed out\n"); 47602ac6454SAndrew Thompson 47702ac6454SAndrew Thompson if (!locked) 47802ac6454SAndrew Thompson AUE_UNLOCK(sc); 47902ac6454SAndrew Thompson return (0); 48002ac6454SAndrew Thompson } 48102ac6454SAndrew Thompson 48202ac6454SAndrew Thompson static void 48302ac6454SAndrew Thompson aue_miibus_statchg(device_t dev) 48402ac6454SAndrew Thompson { 48502ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 48602ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 48702ac6454SAndrew Thompson int locked; 48802ac6454SAndrew Thompson 48902ac6454SAndrew Thompson locked = mtx_owned(&sc->sc_mtx); 49002ac6454SAndrew Thompson if (!locked) 49102ac6454SAndrew Thompson AUE_LOCK(sc); 49202ac6454SAndrew Thompson 49302ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 49402ac6454SAndrew Thompson if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) 49502ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 49602ac6454SAndrew Thompson else 49702ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 49802ac6454SAndrew Thompson 49902ac6454SAndrew Thompson if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) 50002ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 50102ac6454SAndrew Thompson else 50202ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 50302ac6454SAndrew Thompson 50402ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 50502ac6454SAndrew Thompson 50602ac6454SAndrew Thompson /* 50702ac6454SAndrew Thompson * Set the LED modes on the LinkSys adapter. 50802ac6454SAndrew Thompson * This turns on the 'dual link LED' bin in the auxmode 50902ac6454SAndrew Thompson * register of the Broadcom PHY. 51002ac6454SAndrew Thompson */ 51102ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_LSYS) { 51202ac6454SAndrew Thompson uint16_t auxmode; 51302ac6454SAndrew Thompson 51402ac6454SAndrew Thompson auxmode = aue_miibus_readreg(dev, 0, 0x1b); 51502ac6454SAndrew Thompson aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04); 51602ac6454SAndrew Thompson } 51702ac6454SAndrew Thompson if (!locked) 51802ac6454SAndrew Thompson AUE_UNLOCK(sc); 51902ac6454SAndrew Thompson } 52002ac6454SAndrew Thompson 52102ac6454SAndrew Thompson #define AUE_BITS 6 52202ac6454SAndrew Thompson static void 52302ac6454SAndrew Thompson aue_setmulti(struct usb2_ether *ue) 52402ac6454SAndrew Thompson { 52502ac6454SAndrew Thompson struct aue_softc *sc = usb2_ether_getsc(ue); 52602ac6454SAndrew Thompson struct ifnet *ifp = usb2_ether_getifp(ue); 52702ac6454SAndrew Thompson struct ifmultiaddr *ifma; 52802ac6454SAndrew Thompson uint32_t h = 0; 52902ac6454SAndrew Thompson uint32_t i; 53002ac6454SAndrew Thompson uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 53102ac6454SAndrew Thompson 53202ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 53302ac6454SAndrew Thompson 53402ac6454SAndrew Thompson if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 53502ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 53602ac6454SAndrew Thompson return; 53702ac6454SAndrew Thompson } 53802ac6454SAndrew Thompson 53902ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 54002ac6454SAndrew Thompson 54102ac6454SAndrew Thompson /* now program new ones */ 54202ac6454SAndrew Thompson IF_ADDR_LOCK(ifp); 54302ac6454SAndrew Thompson TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 54402ac6454SAndrew Thompson if (ifma->ifma_addr->sa_family != AF_LINK) 54502ac6454SAndrew Thompson continue; 54602ac6454SAndrew Thompson h = ether_crc32_le(LLADDR((struct sockaddr_dl *) 54702ac6454SAndrew Thompson ifma->ifma_addr), ETHER_ADDR_LEN) & ((1 << AUE_BITS) - 1); 54802ac6454SAndrew Thompson hashtbl[(h >> 3)] |= 1 << (h & 0x7); 54902ac6454SAndrew Thompson } 55002ac6454SAndrew Thompson IF_ADDR_UNLOCK(ifp); 55102ac6454SAndrew Thompson 55202ac6454SAndrew Thompson /* write the hashtable */ 55302ac6454SAndrew Thompson for (i = 0; i != 8; i++) 55402ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]); 55502ac6454SAndrew Thompson } 55602ac6454SAndrew Thompson 55702ac6454SAndrew Thompson static void 55802ac6454SAndrew Thompson aue_reset_pegasus_II(struct aue_softc *sc) 55902ac6454SAndrew Thompson { 56002ac6454SAndrew Thompson /* Magic constants taken from Linux driver. */ 56102ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_1D, 0); 56202ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_7B, 2); 56302ac6454SAndrew Thompson #if 0 56402ac6454SAndrew Thompson if ((sc->sc_flags & HAS_HOME_PNA) && mii_mode) 56502ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_81, 6); 56602ac6454SAndrew Thompson else 56702ac6454SAndrew Thompson #endif 56802ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_REG_81, 2); 56902ac6454SAndrew Thompson } 57002ac6454SAndrew Thompson 57102ac6454SAndrew Thompson static void 57202ac6454SAndrew Thompson aue_reset(struct aue_softc *sc) 57302ac6454SAndrew Thompson { 57402ac6454SAndrew Thompson int i; 57502ac6454SAndrew Thompson 57602ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); 57702ac6454SAndrew Thompson 57802ac6454SAndrew Thompson for (i = 0; i != AUE_TIMEOUT; i++) { 57902ac6454SAndrew Thompson if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) 58002ac6454SAndrew Thompson break; 58102ac6454SAndrew Thompson if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 58202ac6454SAndrew Thompson break; 58302ac6454SAndrew Thompson } 58402ac6454SAndrew Thompson 58502ac6454SAndrew Thompson if (i == AUE_TIMEOUT) 58602ac6454SAndrew Thompson device_printf(sc->sc_ue.ue_dev, "reset failed\n"); 58702ac6454SAndrew Thompson 58802ac6454SAndrew Thompson /* 58902ac6454SAndrew Thompson * The PHY(s) attached to the Pegasus chip may be held 59002ac6454SAndrew Thompson * in reset until we flip on the GPIO outputs. Make sure 59102ac6454SAndrew Thompson * to set the GPIO pins high so that the PHY(s) will 59202ac6454SAndrew Thompson * be enabled. 59302ac6454SAndrew Thompson * 59402ac6454SAndrew Thompson * Note: We force all of the GPIO pins low first, *then* 59502ac6454SAndrew Thompson * enable the ones we want. 59602ac6454SAndrew Thompson */ 59702ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0); 59802ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0|AUE_GPIO_SEL1); 59902ac6454SAndrew Thompson 60002ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_LSYS) { 60102ac6454SAndrew Thompson /* Grrr. LinkSys has to be different from everyone else. */ 60202ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1); 60302ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_GPIO0, 60402ac6454SAndrew Thompson AUE_GPIO_SEL0|AUE_GPIO_SEL1|AUE_GPIO_OUT0); 60502ac6454SAndrew Thompson } 60602ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_PII) 60702ac6454SAndrew Thompson aue_reset_pegasus_II(sc); 60802ac6454SAndrew Thompson 60902ac6454SAndrew Thompson /* Wait a little while for the chip to get its brains in order: */ 61002ac6454SAndrew Thompson usb2_ether_pause(&sc->sc_ue, hz / 100); 61102ac6454SAndrew Thompson } 61202ac6454SAndrew Thompson 61302ac6454SAndrew Thompson static void 61402ac6454SAndrew Thompson aue_attach_post(struct usb2_ether *ue) 61502ac6454SAndrew Thompson { 61602ac6454SAndrew Thompson struct aue_softc *sc = usb2_ether_getsc(ue); 61702ac6454SAndrew Thompson 61802ac6454SAndrew Thompson /* reset the adapter */ 61902ac6454SAndrew Thompson aue_reset(sc); 62002ac6454SAndrew Thompson 62102ac6454SAndrew Thompson /* get station address from the EEPROM */ 62202ac6454SAndrew Thompson aue_read_eeprom(sc, ue->ue_eaddr, 0, 3); 62302ac6454SAndrew Thompson } 62402ac6454SAndrew Thompson 62502ac6454SAndrew Thompson /* 62602ac6454SAndrew Thompson * Probe for a Pegasus chip. 62702ac6454SAndrew Thompson */ 62802ac6454SAndrew Thompson static int 62902ac6454SAndrew Thompson aue_probe(device_t dev) 63002ac6454SAndrew Thompson { 63102ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(dev); 63202ac6454SAndrew Thompson 63302ac6454SAndrew Thompson if (uaa->usb2_mode != USB_MODE_HOST) 63402ac6454SAndrew Thompson return (ENXIO); 63502ac6454SAndrew Thompson if (uaa->info.bConfigIndex != AUE_CONFIG_INDEX) 63602ac6454SAndrew Thompson return (ENXIO); 63702ac6454SAndrew Thompson if (uaa->info.bIfaceIndex != AUE_IFACE_IDX) 63802ac6454SAndrew Thompson return (ENXIO); 63902ac6454SAndrew Thompson /* 64002ac6454SAndrew Thompson * Belkin USB Bluetooth dongles of the F8T012xx1 model series conflict 64102ac6454SAndrew Thompson * with older Belkin USB2LAN adapters. Skip if_aue if we detect one of 64202ac6454SAndrew Thompson * the devices that look like Bluetooth adapters. 64302ac6454SAndrew Thompson */ 64402ac6454SAndrew Thompson if (uaa->info.idVendor == USB_VENDOR_BELKIN && 64502ac6454SAndrew Thompson uaa->info.idProduct == USB_PRODUCT_BELKIN_F8T012 && 64602ac6454SAndrew Thompson uaa->info.bcdDevice == 0x0413) 64702ac6454SAndrew Thompson return (ENXIO); 64802ac6454SAndrew Thompson 64902ac6454SAndrew Thompson return (usb2_lookup_id_by_uaa(aue_devs, sizeof(aue_devs), uaa)); 65002ac6454SAndrew Thompson } 65102ac6454SAndrew Thompson 65202ac6454SAndrew Thompson /* 65302ac6454SAndrew Thompson * Attach the interface. Allocate softc structures, do ifmedia 65402ac6454SAndrew Thompson * setup and ethernet/BPF attach. 65502ac6454SAndrew Thompson */ 65602ac6454SAndrew Thompson static int 65702ac6454SAndrew Thompson aue_attach(device_t dev) 65802ac6454SAndrew Thompson { 65902ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(dev); 66002ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 66102ac6454SAndrew Thompson struct usb2_ether *ue = &sc->sc_ue; 66202ac6454SAndrew Thompson uint8_t iface_index; 66302ac6454SAndrew Thompson int error; 66402ac6454SAndrew Thompson 66502ac6454SAndrew Thompson sc->sc_flags = USB_GET_DRIVER_INFO(uaa); 66602ac6454SAndrew Thompson 66702ac6454SAndrew Thompson if (uaa->info.bcdDevice >= 0x0201) { 66802ac6454SAndrew Thompson /* XXX currently undocumented */ 66902ac6454SAndrew Thompson sc->sc_flags |= AUE_FLAG_VER_2; 67002ac6454SAndrew Thompson } 67102ac6454SAndrew Thompson 67202ac6454SAndrew Thompson device_set_usb2_desc(dev); 67302ac6454SAndrew Thompson mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); 67402ac6454SAndrew Thompson 67502ac6454SAndrew Thompson iface_index = AUE_IFACE_IDX; 67602ac6454SAndrew Thompson error = usb2_transfer_setup(uaa->device, &iface_index, 67702ac6454SAndrew Thompson sc->sc_xfer, aue_config, AUE_N_TRANSFER, 67802ac6454SAndrew Thompson sc, &sc->sc_mtx); 67902ac6454SAndrew Thompson if (error) { 68002ac6454SAndrew Thompson device_printf(dev, "allocating USB transfers failed!\n"); 68102ac6454SAndrew Thompson goto detach; 68202ac6454SAndrew Thompson } 68302ac6454SAndrew Thompson 68402ac6454SAndrew Thompson ue->ue_sc = sc; 68502ac6454SAndrew Thompson ue->ue_dev = dev; 68602ac6454SAndrew Thompson ue->ue_udev = uaa->device; 68702ac6454SAndrew Thompson ue->ue_mtx = &sc->sc_mtx; 68802ac6454SAndrew Thompson ue->ue_methods = &aue_ue_methods; 68902ac6454SAndrew Thompson 69002ac6454SAndrew Thompson error = usb2_ether_ifattach(ue); 69102ac6454SAndrew Thompson if (error) { 69202ac6454SAndrew Thompson device_printf(dev, "could not attach interface\n"); 69302ac6454SAndrew Thompson goto detach; 69402ac6454SAndrew Thompson } 69502ac6454SAndrew Thompson return (0); /* success */ 69602ac6454SAndrew Thompson 69702ac6454SAndrew Thompson detach: 69802ac6454SAndrew Thompson aue_detach(dev); 69902ac6454SAndrew Thompson return (ENXIO); /* failure */ 70002ac6454SAndrew Thompson } 70102ac6454SAndrew Thompson 70202ac6454SAndrew Thompson static int 70302ac6454SAndrew Thompson aue_detach(device_t dev) 70402ac6454SAndrew Thompson { 70502ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 70602ac6454SAndrew Thompson struct usb2_ether *ue = &sc->sc_ue; 70702ac6454SAndrew Thompson 70802ac6454SAndrew Thompson usb2_transfer_unsetup(sc->sc_xfer, AUE_N_TRANSFER); 70902ac6454SAndrew Thompson usb2_ether_ifdetach(ue); 71002ac6454SAndrew Thompson mtx_destroy(&sc->sc_mtx); 71102ac6454SAndrew Thompson 71202ac6454SAndrew Thompson return (0); 71302ac6454SAndrew Thompson } 71402ac6454SAndrew Thompson 71502ac6454SAndrew Thompson static void 71602ac6454SAndrew Thompson aue_intr_callback(struct usb2_xfer *xfer) 71702ac6454SAndrew Thompson { 71802ac6454SAndrew Thompson struct aue_softc *sc = xfer->priv_sc; 71902ac6454SAndrew Thompson struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); 72002ac6454SAndrew Thompson struct aue_intrpkt pkt; 72102ac6454SAndrew Thompson 72202ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 72302ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 72402ac6454SAndrew Thompson 72502ac6454SAndrew Thompson if ((ifp->if_drv_flags & IFF_DRV_RUNNING) && 72602ac6454SAndrew Thompson xfer->actlen >= sizeof(pkt)) { 72702ac6454SAndrew Thompson 72802ac6454SAndrew Thompson usb2_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt)); 72902ac6454SAndrew Thompson 73002ac6454SAndrew Thompson if (pkt.aue_txstat0) 73102ac6454SAndrew Thompson ifp->if_oerrors++; 73202ac6454SAndrew Thompson if (pkt.aue_txstat0 & (AUE_TXSTAT0_LATECOLL & 73302ac6454SAndrew Thompson AUE_TXSTAT0_EXCESSCOLL)) 73402ac6454SAndrew Thompson ifp->if_collisions++; 73502ac6454SAndrew Thompson } 73602ac6454SAndrew Thompson /* FALLTHROUGH */ 73702ac6454SAndrew Thompson case USB_ST_SETUP: 73802ac6454SAndrew Thompson tr_setup: 73902ac6454SAndrew Thompson xfer->frlengths[0] = xfer->max_data_length; 74002ac6454SAndrew Thompson usb2_start_hardware(xfer); 74102ac6454SAndrew Thompson return; 74202ac6454SAndrew Thompson 74302ac6454SAndrew Thompson default: /* Error */ 74402ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 74502ac6454SAndrew Thompson /* try to clear stall first */ 74602ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 74702ac6454SAndrew Thompson goto tr_setup; 74802ac6454SAndrew Thompson } 74902ac6454SAndrew Thompson return; 75002ac6454SAndrew Thompson } 75102ac6454SAndrew Thompson } 75202ac6454SAndrew Thompson 75302ac6454SAndrew Thompson static void 75402ac6454SAndrew Thompson aue_bulk_read_callback(struct usb2_xfer *xfer) 75502ac6454SAndrew Thompson { 75602ac6454SAndrew Thompson struct aue_softc *sc = xfer->priv_sc; 75702ac6454SAndrew Thompson struct usb2_ether *ue = &sc->sc_ue; 75802ac6454SAndrew Thompson struct ifnet *ifp = usb2_ether_getifp(ue); 75902ac6454SAndrew Thompson struct aue_rxpkt stat; 76002ac6454SAndrew Thompson 76102ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 76202ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 76302ac6454SAndrew Thompson DPRINTFN(11, "received %d bytes\n", xfer->actlen); 76402ac6454SAndrew Thompson 76502ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_VER_2) { 76602ac6454SAndrew Thompson 76702ac6454SAndrew Thompson if (xfer->actlen == 0) { 76802ac6454SAndrew Thompson ifp->if_ierrors++; 76902ac6454SAndrew Thompson goto tr_setup; 77002ac6454SAndrew Thompson } 77102ac6454SAndrew Thompson } else { 77202ac6454SAndrew Thompson 77302ac6454SAndrew Thompson if (xfer->actlen <= (sizeof(stat) + ETHER_CRC_LEN)) { 77402ac6454SAndrew Thompson ifp->if_ierrors++; 77502ac6454SAndrew Thompson goto tr_setup; 77602ac6454SAndrew Thompson } 77702ac6454SAndrew Thompson usb2_copy_out(xfer->frbuffers, 77802ac6454SAndrew Thompson xfer->actlen - sizeof(stat), &stat, sizeof(stat)); 77902ac6454SAndrew Thompson 78002ac6454SAndrew Thompson /* 78102ac6454SAndrew Thompson * turn off all the non-error bits in the rx status 78202ac6454SAndrew Thompson * word: 78302ac6454SAndrew Thompson */ 78402ac6454SAndrew Thompson stat.aue_rxstat &= AUE_RXSTAT_MASK; 78502ac6454SAndrew Thompson if (stat.aue_rxstat) { 78602ac6454SAndrew Thompson ifp->if_ierrors++; 78702ac6454SAndrew Thompson goto tr_setup; 78802ac6454SAndrew Thompson } 78902ac6454SAndrew Thompson /* No errors; receive the packet. */ 79002ac6454SAndrew Thompson xfer->actlen -= (sizeof(stat) + ETHER_CRC_LEN); 79102ac6454SAndrew Thompson } 79202ac6454SAndrew Thompson usb2_ether_rxbuf(ue, xfer->frbuffers, 0, xfer->actlen); 79302ac6454SAndrew Thompson 79402ac6454SAndrew Thompson /* FALLTHROUGH */ 79502ac6454SAndrew Thompson case USB_ST_SETUP: 79602ac6454SAndrew Thompson tr_setup: 79702ac6454SAndrew Thompson xfer->frlengths[0] = xfer->max_data_length; 79802ac6454SAndrew Thompson usb2_start_hardware(xfer); 79902ac6454SAndrew Thompson usb2_ether_rxflush(ue); 80002ac6454SAndrew Thompson return; 80102ac6454SAndrew Thompson 80202ac6454SAndrew Thompson default: /* Error */ 80302ac6454SAndrew Thompson DPRINTF("bulk read error, %s\n", 80402ac6454SAndrew Thompson usb2_errstr(xfer->error)); 80502ac6454SAndrew Thompson 80602ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 80702ac6454SAndrew Thompson /* try to clear stall first */ 80802ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 80902ac6454SAndrew Thompson goto tr_setup; 81002ac6454SAndrew Thompson } 81102ac6454SAndrew Thompson return; 81202ac6454SAndrew Thompson } 81302ac6454SAndrew Thompson } 81402ac6454SAndrew Thompson 81502ac6454SAndrew Thompson static void 81602ac6454SAndrew Thompson aue_bulk_write_callback(struct usb2_xfer *xfer) 81702ac6454SAndrew Thompson { 81802ac6454SAndrew Thompson struct aue_softc *sc = xfer->priv_sc; 81902ac6454SAndrew Thompson struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); 82002ac6454SAndrew Thompson struct mbuf *m; 82102ac6454SAndrew Thompson uint8_t buf[2]; 82202ac6454SAndrew Thompson 82302ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 82402ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 82502ac6454SAndrew Thompson DPRINTFN(11, "transfer of %d bytes complete\n", xfer->actlen); 82602ac6454SAndrew Thompson ifp->if_opackets++; 82702ac6454SAndrew Thompson 82802ac6454SAndrew Thompson /* FALLTHROUGH */ 82902ac6454SAndrew Thompson case USB_ST_SETUP: 83002ac6454SAndrew Thompson tr_setup: 83102ac6454SAndrew Thompson if ((sc->sc_flags & AUE_FLAG_LINK) == 0) { 83202ac6454SAndrew Thompson /* 83302ac6454SAndrew Thompson * don't send anything if there is no link ! 83402ac6454SAndrew Thompson */ 83502ac6454SAndrew Thompson return; 83602ac6454SAndrew Thompson } 83702ac6454SAndrew Thompson IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 83802ac6454SAndrew Thompson 83902ac6454SAndrew Thompson if (m == NULL) 84002ac6454SAndrew Thompson return; 84102ac6454SAndrew Thompson if (m->m_pkthdr.len > MCLBYTES) 84202ac6454SAndrew Thompson m->m_pkthdr.len = MCLBYTES; 84302ac6454SAndrew Thompson if (sc->sc_flags & AUE_FLAG_VER_2) { 84402ac6454SAndrew Thompson 84502ac6454SAndrew Thompson xfer->frlengths[0] = m->m_pkthdr.len; 84602ac6454SAndrew Thompson 84702ac6454SAndrew Thompson usb2_m_copy_in(xfer->frbuffers, 0, 84802ac6454SAndrew Thompson m, 0, m->m_pkthdr.len); 84902ac6454SAndrew Thompson 85002ac6454SAndrew Thompson } else { 85102ac6454SAndrew Thompson 85202ac6454SAndrew Thompson xfer->frlengths[0] = (m->m_pkthdr.len + 2); 85302ac6454SAndrew Thompson 85402ac6454SAndrew Thompson /* 85502ac6454SAndrew Thompson * The ADMtek documentation says that the 85602ac6454SAndrew Thompson * packet length is supposed to be specified 85702ac6454SAndrew Thompson * in the first two bytes of the transfer, 85802ac6454SAndrew Thompson * however it actually seems to ignore this 85902ac6454SAndrew Thompson * info and base the frame size on the bulk 86002ac6454SAndrew Thompson * transfer length. 86102ac6454SAndrew Thompson */ 86202ac6454SAndrew Thompson buf[0] = (uint8_t)(m->m_pkthdr.len); 86302ac6454SAndrew Thompson buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 86402ac6454SAndrew Thompson 86502ac6454SAndrew Thompson usb2_copy_in(xfer->frbuffers, 0, buf, 2); 86602ac6454SAndrew Thompson 86702ac6454SAndrew Thompson usb2_m_copy_in(xfer->frbuffers, 2, 86802ac6454SAndrew Thompson m, 0, m->m_pkthdr.len); 86902ac6454SAndrew Thompson } 87002ac6454SAndrew Thompson 87102ac6454SAndrew Thompson /* 87202ac6454SAndrew Thompson * if there's a BPF listener, bounce a copy 87302ac6454SAndrew Thompson * of this frame to him: 87402ac6454SAndrew Thompson */ 87502ac6454SAndrew Thompson BPF_MTAP(ifp, m); 87602ac6454SAndrew Thompson 87702ac6454SAndrew Thompson m_freem(m); 87802ac6454SAndrew Thompson 87902ac6454SAndrew Thompson usb2_start_hardware(xfer); 88002ac6454SAndrew Thompson return; 88102ac6454SAndrew Thompson 88202ac6454SAndrew Thompson default: /* Error */ 88302ac6454SAndrew Thompson DPRINTFN(11, "transfer error, %s\n", 88402ac6454SAndrew Thompson usb2_errstr(xfer->error)); 88502ac6454SAndrew Thompson 88602ac6454SAndrew Thompson ifp->if_oerrors++; 88702ac6454SAndrew Thompson 88802ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 88902ac6454SAndrew Thompson /* try to clear stall first */ 89002ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 89102ac6454SAndrew Thompson goto tr_setup; 89202ac6454SAndrew Thompson } 89302ac6454SAndrew Thompson return; 89402ac6454SAndrew Thompson } 89502ac6454SAndrew Thompson } 89602ac6454SAndrew Thompson 89702ac6454SAndrew Thompson static void 89802ac6454SAndrew Thompson aue_tick(struct usb2_ether *ue) 89902ac6454SAndrew Thompson { 90002ac6454SAndrew Thompson struct aue_softc *sc = usb2_ether_getsc(ue); 90102ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 90202ac6454SAndrew Thompson 90302ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 90402ac6454SAndrew Thompson 90502ac6454SAndrew Thompson mii_tick(mii); 90602ac6454SAndrew Thompson if ((sc->sc_flags & AUE_FLAG_LINK) == 0 90702ac6454SAndrew Thompson && mii->mii_media_status & IFM_ACTIVE && 90802ac6454SAndrew Thompson IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 90902ac6454SAndrew Thompson sc->sc_flags |= AUE_FLAG_LINK; 91002ac6454SAndrew Thompson aue_start(ue); 91102ac6454SAndrew Thompson } 91202ac6454SAndrew Thompson } 91302ac6454SAndrew Thompson 91402ac6454SAndrew Thompson static void 91502ac6454SAndrew Thompson aue_start(struct usb2_ether *ue) 91602ac6454SAndrew Thompson { 91702ac6454SAndrew Thompson struct aue_softc *sc = usb2_ether_getsc(ue); 91802ac6454SAndrew Thompson 91902ac6454SAndrew Thompson /* 92002ac6454SAndrew Thompson * start the USB transfers, if not already started: 92102ac6454SAndrew Thompson */ 92202ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[AUE_INTR_DT_RD]); 92302ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_RD]); 92402ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_WR]); 92502ac6454SAndrew Thompson } 92602ac6454SAndrew Thompson 92702ac6454SAndrew Thompson static void 92802ac6454SAndrew Thompson aue_init(struct usb2_ether *ue) 92902ac6454SAndrew Thompson { 93002ac6454SAndrew Thompson struct aue_softc *sc = usb2_ether_getsc(ue); 93102ac6454SAndrew Thompson struct ifnet *ifp = usb2_ether_getifp(ue); 93202ac6454SAndrew Thompson int i; 93302ac6454SAndrew Thompson 93402ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 93502ac6454SAndrew Thompson 93602ac6454SAndrew Thompson /* 93702ac6454SAndrew Thompson * Cancel pending I/O 93802ac6454SAndrew Thompson */ 93902ac6454SAndrew Thompson aue_reset(sc); 94002ac6454SAndrew Thompson 94102ac6454SAndrew Thompson /* Set MAC address */ 94202ac6454SAndrew Thompson for (i = 0; i != ETHER_ADDR_LEN; i++) 94302ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_PAR0 + i, IF_LLADDR(ifp)[i]); 94402ac6454SAndrew Thompson 94502ac6454SAndrew Thompson /* update promiscuous setting */ 94602ac6454SAndrew Thompson aue_setpromisc(ue); 94702ac6454SAndrew Thompson 94802ac6454SAndrew Thompson /* Load the multicast filter. */ 94902ac6454SAndrew Thompson aue_setmulti(ue); 95002ac6454SAndrew Thompson 95102ac6454SAndrew Thompson /* Enable RX and TX */ 95202ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB); 95302ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 95402ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); 95502ac6454SAndrew Thompson 95602ac6454SAndrew Thompson usb2_transfer_set_stall(sc->sc_xfer[AUE_BULK_DT_WR]); 95702ac6454SAndrew Thompson 95802ac6454SAndrew Thompson ifp->if_drv_flags |= IFF_DRV_RUNNING; 95902ac6454SAndrew Thompson aue_start(ue); 96002ac6454SAndrew Thompson } 96102ac6454SAndrew Thompson 96202ac6454SAndrew Thompson static void 96302ac6454SAndrew Thompson aue_setpromisc(struct usb2_ether *ue) 96402ac6454SAndrew Thompson { 96502ac6454SAndrew Thompson struct aue_softc *sc = usb2_ether_getsc(ue); 96602ac6454SAndrew Thompson struct ifnet *ifp = usb2_ether_getifp(ue); 96702ac6454SAndrew Thompson 96802ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 96902ac6454SAndrew Thompson 97002ac6454SAndrew Thompson /* if we want promiscuous mode, set the allframes bit: */ 97102ac6454SAndrew Thompson if (ifp->if_flags & IFF_PROMISC) 97202ac6454SAndrew Thompson AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 97302ac6454SAndrew Thompson else 97402ac6454SAndrew Thompson AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 97502ac6454SAndrew Thompson } 97602ac6454SAndrew Thompson 97702ac6454SAndrew Thompson /* 97802ac6454SAndrew Thompson * Set media options. 97902ac6454SAndrew Thompson */ 98002ac6454SAndrew Thompson static int 98102ac6454SAndrew Thompson aue_ifmedia_upd(struct ifnet *ifp) 98202ac6454SAndrew Thompson { 98302ac6454SAndrew Thompson struct aue_softc *sc = ifp->if_softc; 98402ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 98502ac6454SAndrew Thompson 98602ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 98702ac6454SAndrew Thompson 98802ac6454SAndrew Thompson sc->sc_flags &= ~AUE_FLAG_LINK; 98902ac6454SAndrew Thompson if (mii->mii_instance) { 99002ac6454SAndrew Thompson struct mii_softc *miisc; 99102ac6454SAndrew Thompson 99202ac6454SAndrew Thompson LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 99302ac6454SAndrew Thompson mii_phy_reset(miisc); 99402ac6454SAndrew Thompson } 99502ac6454SAndrew Thompson mii_mediachg(mii); 99602ac6454SAndrew Thompson return (0); 99702ac6454SAndrew Thompson } 99802ac6454SAndrew Thompson 99902ac6454SAndrew Thompson /* 100002ac6454SAndrew Thompson * Report current media status. 100102ac6454SAndrew Thompson */ 100202ac6454SAndrew Thompson static void 100302ac6454SAndrew Thompson aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 100402ac6454SAndrew Thompson { 100502ac6454SAndrew Thompson struct aue_softc *sc = ifp->if_softc; 100602ac6454SAndrew Thompson struct mii_data *mii = GET_MII(sc); 100702ac6454SAndrew Thompson 100802ac6454SAndrew Thompson AUE_LOCK(sc); 100902ac6454SAndrew Thompson mii_pollstat(mii); 101002ac6454SAndrew Thompson AUE_UNLOCK(sc); 101102ac6454SAndrew Thompson ifmr->ifm_active = mii->mii_media_active; 101202ac6454SAndrew Thompson ifmr->ifm_status = mii->mii_media_status; 101302ac6454SAndrew Thompson } 101402ac6454SAndrew Thompson 101502ac6454SAndrew Thompson /* 101602ac6454SAndrew Thompson * Stop the adapter and free any mbufs allocated to the 101702ac6454SAndrew Thompson * RX and TX lists. 101802ac6454SAndrew Thompson */ 101902ac6454SAndrew Thompson static void 102002ac6454SAndrew Thompson aue_stop(struct usb2_ether *ue) 102102ac6454SAndrew Thompson { 102202ac6454SAndrew Thompson struct aue_softc *sc = usb2_ether_getsc(ue); 102302ac6454SAndrew Thompson struct ifnet *ifp = usb2_ether_getifp(ue); 102402ac6454SAndrew Thompson 102502ac6454SAndrew Thompson AUE_LOCK_ASSERT(sc, MA_OWNED); 102602ac6454SAndrew Thompson 102702ac6454SAndrew Thompson ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 102802ac6454SAndrew Thompson sc->sc_flags &= ~AUE_FLAG_LINK; 102902ac6454SAndrew Thompson 103002ac6454SAndrew Thompson /* 103102ac6454SAndrew Thompson * stop all the transfers, if not already stopped: 103202ac6454SAndrew Thompson */ 103302ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_WR]); 103402ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_RD]); 103502ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[AUE_INTR_DT_RD]); 103602ac6454SAndrew Thompson 103702ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_CTL0, 0); 103802ac6454SAndrew Thompson aue_csr_write_1(sc, AUE_CTL1, 0); 103902ac6454SAndrew Thompson aue_reset(sc); 104002ac6454SAndrew Thompson } 104102ac6454SAndrew Thompson 104202ac6454SAndrew Thompson /* 104302ac6454SAndrew Thompson * Stop all chip I/O so that the kernel's probe routines don't 104402ac6454SAndrew Thompson * get confused by errant DMAs when rebooting. 104502ac6454SAndrew Thompson */ 104602ac6454SAndrew Thompson static int 104702ac6454SAndrew Thompson aue_shutdown(device_t dev) 104802ac6454SAndrew Thompson { 104902ac6454SAndrew Thompson struct aue_softc *sc = device_get_softc(dev); 105002ac6454SAndrew Thompson 105102ac6454SAndrew Thompson usb2_ether_ifshutdown(&sc->sc_ue); 105202ac6454SAndrew Thompson 105302ac6454SAndrew Thompson return (0); 105402ac6454SAndrew Thompson } 1055