if_aue.c revision 192502
1218885Sdim/*- 2218885Sdim * Copyright (c) 1997, 1998, 1999, 2000 3218885Sdim * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 4218885Sdim * 5218885Sdim * Copyright (c) 2006 6218885Sdim * Alfred Perlstein <alfred@FreeBSD.org>. All rights reserved. 7218885Sdim * 8218885Sdim * Redistribution and use in source and binary forms, with or without 9218885Sdim * modification, are permitted provided that the following conditions 10218885Sdim * are met: 11218885Sdim * 1. Redistributions of source code must retain the above copyright 12218885Sdim * notice, this list of conditions and the following disclaimer. 13218885Sdim * 2. Redistributions in binary form must reproduce the above copyright 14218885Sdim * notice, this list of conditions and the following disclaimer in the 15218885Sdim * documentation and/or other materials provided with the distribution. 16218885Sdim * 3. All advertising materials mentioning features or use of this software 17218885Sdim * must display the following acknowledgement: 18218885Sdim * This product includes software developed by Bill Paul. 19218885Sdim * 4. Neither the name of the author nor the names of any co-contributors 20218885Sdim * may be used to endorse or promote products derived from this software 21218885Sdim * without specific prior written permission. 22218885Sdim * 23218885Sdim * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 24218885Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25218885Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26218885Sdim * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 27218885Sdim * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28218885Sdim * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29218885Sdim * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30218885Sdim * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31218885Sdim * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32218885Sdim * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33218885Sdim * THE POSSIBILITY OF SUCH DAMAGE. 34249423Sdim */ 35249423Sdim 36249423Sdim#include <sys/cdefs.h> 37249423Sdim__FBSDID("$FreeBSD: head/sys/dev/usb/net/if_aue.c 192502 2009-05-21 01:48:42Z thompsa $"); 38234353Sdim 39234353Sdim/* 40234353Sdim * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver. 41234353Sdim * Datasheet is available from http://www.admtek.com.tw. 42218885Sdim * 43218885Sdim * Written by Bill Paul <wpaul@ee.columbia.edu> 44218885Sdim * Electrical Engineering Department 45218885Sdim * Columbia University, New York City 46218885Sdim * 47218885Sdim * SMP locking by Alfred Perlstein <alfred@FreeBSD.org>. 48218885Sdim * RED Inc. 49218885Sdim */ 50218885Sdim 51218885Sdim/* 52218885Sdim * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet 53218885Sdim * support: the control endpoint for reading/writing registers, burst 54218885Sdim * read endpoint for packet reception, burst write for packet transmission 55218885Sdim * and one for "interrupts." The chip uses the same RX filter scheme 56218885Sdim * as the other ADMtek ethernet parts: one perfect filter entry for the 57218885Sdim * the station address and a 64-bit multicast hash table. The chip supports 58218885Sdim * both MII and HomePNA attachments. 59218885Sdim * 60218885Sdim * Since the maximum data transfer speed of USB is supposed to be 12Mbps, 61218885Sdim * you're never really going to get 100Mbps speeds from this device. I 62218885Sdim * think the idea is to allow the device to connect to 10 or 100Mbps 63218885Sdim * networks, not necessarily to provide 100Mbps performance. Also, since 64218885Sdim * the controller uses an external PHY chip, it's possible that board 65218885Sdim * designers might simply choose a 10Mbps PHY. 66218885Sdim * 67218885Sdim * Registers are accessed using usb2_ether_do_request(). Packet 68218885Sdim * transfers are done using usb2_transfer() and friends. 69218885Sdim */ 70218885Sdim 71218885Sdim#include "usbdevs.h" 72218885Sdim#include <dev/usb/usb.h> 73263508Sdim#include <dev/usb/usb_mfunc.h> 74243830Sdim#include <dev/usb/usb_error.h> 75218885Sdim 76263508Sdim#define USB_DEBUG_VAR aue_debug 77249423Sdim 78218885Sdim#include <dev/usb/usb_core.h> 79226633Sdim#include <dev/usb/usb_lookup.h> 80239462Sdim#include <dev/usb/usb_process.h> 81234353Sdim#include <dev/usb/usb_debug.h> 82223017Sdim#include <dev/usb/usb_request.h> 83218885Sdim#include <dev/usb/usb_busdma.h> 84249423Sdim#include <dev/usb/usb_util.h> 85249423Sdim 86218885Sdim#include <dev/usb/net/usb_ethernet.h> 87218885Sdim#include <dev/usb/net/if_auereg.h> 88218885Sdim 89218885Sdim#if USB_DEBUG 90263508Sdimstatic int aue_debug = 0; 91263508Sdim 92218885SdimSYSCTL_NODE(_hw_usb, OID_AUTO, aue, CTLFLAG_RW, 0, "USB aue"); 93218885SdimSYSCTL_INT(_hw_usb_aue, OID_AUTO, debug, CTLFLAG_RW, &aue_debug, 0, 94218885Sdim "Debug level"); 95218885Sdim#endif 96234353Sdim 97243830Sdim/* 98218885Sdim * Various supported device vendors/products. 99218885Sdim */ 100218885Sdimstatic const struct usb2_device_id aue_devs[] = { 101218885Sdim {USB_VPI(USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B, AUE_FLAG_PII)}, 102218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA, 0)}, 103263508Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000, AUE_FLAG_LSYS)}, 104218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10, 0)}, 105218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1, AUE_FLAG_PNA | AUE_FLAG_PII)}, 106263508Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2, AUE_FLAG_PII)}, 107243830Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4, AUE_FLAG_PNA)}, 108218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5, AUE_FLAG_PNA)}, 109218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6, AUE_FLAG_PII)}, 110218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7, AUE_FLAG_PII)}, 111218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8, AUE_FLAG_PII)}, 112218885Sdim {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9, AUE_FLAG_PNA)}, 113218885Sdim {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001, AUE_FLAG_PII)}, 114239462Sdim {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC, 0)}, 115218885Sdim {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2, AUE_FLAG_PII)}, 116234353Sdim {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3, AUE_FLAG_PII)}, 117221345Sdim {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_4, AUE_FLAG_PII)}, 118234353Sdim {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII, AUE_FLAG_PII)}, 119249423Sdim {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, AUE_FLAG_PNA | AUE_FLAG_DUAL_PHY)}, 120249423Sdim {USB_VPI(USB_VENDOR_AEI, USB_PRODUCT_AEI_FASTETHERNET, AUE_FLAG_PII)}, 121234353Sdim {USB_VPI(USB_VENDOR_ALLIEDTELESYN, USB_PRODUCT_ALLIEDTELESYN_ATUSB100, AUE_FLAG_PII)}, 122263508Sdim {USB_VPI(USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC110T, AUE_FLAG_PII)}, 123218885Sdim {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN, AUE_FLAG_PII)}, 124218885Sdim {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, 0)}, 125218885Sdim {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100, AUE_FLAG_PII)}, 126218885Sdim {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100, 0)}, 127234353Sdim {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100, AUE_FLAG_PNA)}, 128218885Sdim {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS, AUE_FLAG_PII)}, 129218885Sdim {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX, 0)}, 130218885Sdim {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1, AUE_FLAG_LSYS)}, 131218885Sdim {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 132218885Sdim {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 133218885Sdim {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 134218885Sdim {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA, AUE_FLAG_PNA)}, 135218885Sdim {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX, AUE_FLAG_LSYS)}, 136218885Sdim {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650, AUE_FLAG_LSYS)}, 137218885Sdim {USB_VPI(USB_VENDOR_ELCON, USB_PRODUCT_ELCON_PLAN, AUE_FLAG_PNA | AUE_FLAG_PII)}, 138249423Sdim {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSB20, AUE_FLAG_PII)}, 139218885Sdim {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX, AUE_FLAG_PII)}, 140218885Sdim {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0, 0)}, 141218885Sdim {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1, AUE_FLAG_LSYS)}, 142218885Sdim {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2, 0)}, 143218885Sdim {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3, AUE_FLAG_LSYS)}, 144218885Sdim {USB_VPI(USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET, 0)}, 145218885Sdim {USB_VPI(USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNBR402W, 0)}, 146218885Sdim {USB_VPI(USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100, AUE_FLAG_PII)}, 147218885Sdim {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HN210E, AUE_FLAG_PII)}, 148218885Sdim {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS, AUE_FLAG_PII)}, 149218885Sdim {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX, 0)}, 150218885Sdim {USB_VPI(USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX, 0)}, 151218885Sdim {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1, AUE_FLAG_LSYS | AUE_FLAG_PNA)}, 152239462Sdim {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX, AUE_FLAG_LSYS)}, 153218885Sdim {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA, AUE_FLAG_LSYS)}, 154218885Sdim {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 155218885Sdim {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)}, 156234353Sdim {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T, AUE_FLAG_LSYS)}, 157218885Sdim {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5, AUE_FLAG_PII)}, 158218885Sdim {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1, 0)}, 159218885Sdim {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5, 0)}, 160218885Sdim {USB_VPI(USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110, AUE_FLAG_PII)}, 161218885Sdim {USB_VPI(USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101, AUE_FLAG_PII)}, 162218885Sdim {USB_VPI(USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM, AUE_FLAG_PII)}, 163218885Sdim {USB_VPI(USB_VENDOR_SIIG2, USB_PRODUCT_SIIG2_USBTOETHER, AUE_FLAG_PII)}, 164234353Sdim {USB_VPI(USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC, AUE_FLAG_PII)}, 165263508Sdim {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB, 0)}, 166218885Sdim {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB, AUE_FLAG_PII)}, 167218885Sdim {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100, 0)}, 168218885Sdim {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB110, AUE_FLAG_PII)}, 169218885Sdim}; 170224145Sdim 171218885Sdim/* prototypes */ 172218885Sdim 173218885Sdimstatic device_probe_t aue_probe; 174226633Sdimstatic device_attach_t aue_attach; 175234353Sdimstatic device_detach_t aue_detach; 176234353Sdimstatic miibus_readreg_t aue_miibus_readreg; 177224145Sdimstatic miibus_writereg_t aue_miibus_writereg; 178218885Sdimstatic miibus_statchg_t aue_miibus_statchg; 179218885Sdim 180243830Sdimstatic usb2_callback_t aue_intr_callback; 181218885Sdimstatic usb2_callback_t aue_bulk_read_callback; 182218885Sdimstatic usb2_callback_t aue_bulk_write_callback; 183218885Sdim 184234353Sdimstatic usb2_ether_fn_t aue_attach_post; 185218885Sdimstatic usb2_ether_fn_t aue_init; 186239462Sdimstatic usb2_ether_fn_t aue_stop; 187218885Sdimstatic usb2_ether_fn_t aue_start; 188218885Sdimstatic usb2_ether_fn_t aue_tick; 189218885Sdimstatic usb2_ether_fn_t aue_setmulti; 190218885Sdimstatic usb2_ether_fn_t aue_setpromisc; 191243830Sdim 192218885Sdimstatic uint8_t aue_csr_read_1(struct aue_softc *, uint16_t); 193218885Sdimstatic uint16_t aue_csr_read_2(struct aue_softc *, uint16_t); 194218885Sdimstatic void aue_csr_write_1(struct aue_softc *, uint16_t, uint8_t); 195224145Sdimstatic void aue_csr_write_2(struct aue_softc *, uint16_t, uint16_t); 196234353Sdimstatic void aue_eeprom_getword(struct aue_softc *, int, uint16_t *); 197224145Sdimstatic void aue_read_eeprom(struct aue_softc *, uint8_t *, uint16_t, 198224145Sdim uint16_t); 199224145Sdimstatic void aue_reset(struct aue_softc *); 200218885Sdimstatic void aue_reset_pegasus_II(struct aue_softc *); 201263508Sdim 202218885Sdimstatic int aue_ifmedia_upd(struct ifnet *); 203218885Sdimstatic void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *); 204218885Sdim 205218885Sdimstatic const struct usb2_config aue_config[AUE_N_TRANSFER] = { 206218885Sdim 207218885Sdim [AUE_BULK_DT_WR] = { 208218885Sdim .type = UE_BULK, 209218885Sdim .endpoint = UE_ADDR_ANY, 210218885Sdim .direction = UE_DIR_OUT, 211234353Sdim .bufsize = (MCLBYTES + 2), 212218885Sdim .flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 213218885Sdim .callback = aue_bulk_write_callback, 214218885Sdim .timeout = 10000, /* 10 seconds */ 215249423Sdim }, 216218885Sdim 217218885Sdim [AUE_BULK_DT_RD] = { 218218885Sdim .type = UE_BULK, 219218885Sdim .endpoint = UE_ADDR_ANY, 220218885Sdim .direction = UE_DIR_IN, 221218885Sdim .bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN), 222218885Sdim .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 223218885Sdim .callback = aue_bulk_read_callback, 224218885Sdim }, 225218885Sdim 226218885Sdim [AUE_INTR_DT_RD] = { 227243830Sdim .type = UE_INTERRUPT, 228218885Sdim .endpoint = UE_ADDR_ANY, 229218885Sdim .direction = UE_DIR_IN, 230218885Sdim .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 231218885Sdim .bufsize = 0, /* use wMaxPacketSize */ 232218885Sdim .callback = aue_intr_callback, 233224145Sdim }, 234218885Sdim}; 235218885Sdim 236218885Sdimstatic device_method_t aue_methods[] = { 237218885Sdim /* Device interface */ 238218885Sdim DEVMETHOD(device_probe, aue_probe), 239243830Sdim DEVMETHOD(device_attach, aue_attach), 240218885Sdim DEVMETHOD(device_detach, aue_detach), 241218885Sdim 242218885Sdim /* bus interface */ 243218885Sdim DEVMETHOD(bus_print_child, bus_generic_print_child), 244218885Sdim DEVMETHOD(bus_driver_added, bus_generic_driver_added), 245218885Sdim 246218885Sdim /* MII interface */ 247234353Sdim DEVMETHOD(miibus_readreg, aue_miibus_readreg), 248234353Sdim DEVMETHOD(miibus_writereg, aue_miibus_writereg), 249243830Sdim DEVMETHOD(miibus_statchg, aue_miibus_statchg), 250249423Sdim 251249423Sdim {0, 0} 252218885Sdim}; 253218885Sdim 254218885Sdimstatic driver_t aue_driver = { 255218885Sdim .name = "aue", 256218885Sdim .methods = aue_methods, 257218885Sdim .size = sizeof(struct aue_softc) 258218885Sdim}; 259218885Sdim 260239462Sdimstatic devclass_t aue_devclass; 261218885Sdim 262234353SdimDRIVER_MODULE(aue, uhub, aue_driver, aue_devclass, NULL, 0); 263234353SdimDRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0); 264243830SdimMODULE_DEPEND(aue, uether, 1, 1, 1); 265251662SdimMODULE_DEPEND(aue, usb, 1, 1, 1); 266234353SdimMODULE_DEPEND(aue, ether, 1, 1, 1); 267239462SdimMODULE_DEPEND(aue, miibus, 1, 1, 1); 268218885Sdim 269218885Sdimstatic const struct usb2_ether_methods aue_ue_methods = { 270218885Sdim .ue_attach_post = aue_attach_post, 271 .ue_start = aue_start, 272 .ue_init = aue_init, 273 .ue_stop = aue_stop, 274 .ue_tick = aue_tick, 275 .ue_setmulti = aue_setmulti, 276 .ue_setpromisc = aue_setpromisc, 277 .ue_mii_upd = aue_ifmedia_upd, 278 .ue_mii_sts = aue_ifmedia_sts, 279}; 280 281#define AUE_SETBIT(sc, reg, x) \ 282 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x)) 283 284#define AUE_CLRBIT(sc, reg, x) \ 285 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x)) 286 287static uint8_t 288aue_csr_read_1(struct aue_softc *sc, uint16_t reg) 289{ 290 struct usb2_device_request req; 291 usb2_error_t err; 292 uint8_t val; 293 294 req.bmRequestType = UT_READ_VENDOR_DEVICE; 295 req.bRequest = AUE_UR_READREG; 296 USETW(req.wValue, 0); 297 USETW(req.wIndex, reg); 298 USETW(req.wLength, 1); 299 300 err = usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000); 301 if (err) 302 return (0); 303 return (val); 304} 305 306static uint16_t 307aue_csr_read_2(struct aue_softc *sc, uint16_t reg) 308{ 309 struct usb2_device_request req; 310 usb2_error_t err; 311 uint16_t val; 312 313 req.bmRequestType = UT_READ_VENDOR_DEVICE; 314 req.bRequest = AUE_UR_READREG; 315 USETW(req.wValue, 0); 316 USETW(req.wIndex, reg); 317 USETW(req.wLength, 2); 318 319 err = usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000); 320 if (err) 321 return (0); 322 return (le16toh(val)); 323} 324 325static void 326aue_csr_write_1(struct aue_softc *sc, uint16_t reg, uint8_t val) 327{ 328 struct usb2_device_request req; 329 330 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 331 req.bRequest = AUE_UR_WRITEREG; 332 req.wValue[0] = val; 333 req.wValue[1] = 0; 334 USETW(req.wIndex, reg); 335 USETW(req.wLength, 1); 336 337 if (usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000)) { 338 /* error ignored */ 339 } 340} 341 342static void 343aue_csr_write_2(struct aue_softc *sc, uint16_t reg, uint16_t val) 344{ 345 struct usb2_device_request req; 346 347 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 348 req.bRequest = AUE_UR_WRITEREG; 349 USETW(req.wValue, val); 350 USETW(req.wIndex, reg); 351 USETW(req.wLength, 2); 352 353 val = htole16(val); 354 355 if (usb2_ether_do_request(&sc->sc_ue, &req, &val, 1000)) { 356 /* error ignored */ 357 } 358} 359 360/* 361 * Read a word of data stored in the EEPROM at address 'addr.' 362 */ 363static void 364aue_eeprom_getword(struct aue_softc *sc, int addr, uint16_t *dest) 365{ 366 int i; 367 uint16_t word = 0; 368 369 aue_csr_write_1(sc, AUE_EE_REG, addr); 370 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); 371 372 for (i = 0; i != AUE_TIMEOUT; i++) { 373 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) 374 break; 375 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 376 break; 377 } 378 379 if (i == AUE_TIMEOUT) 380 device_printf(sc->sc_ue.ue_dev, "EEPROM read timed out\n"); 381 382 word = aue_csr_read_2(sc, AUE_EE_DATA); 383 *dest = word; 384} 385 386/* 387 * Read a sequence of words from the EEPROM. 388 */ 389static void 390aue_read_eeprom(struct aue_softc *sc, uint8_t *dest, 391 uint16_t off, uint16_t len) 392{ 393 uint16_t *ptr = (uint16_t *)dest; 394 int i; 395 396 for (i = 0; i != len; i++, ptr++) 397 aue_eeprom_getword(sc, off + i, ptr); 398} 399 400static int 401aue_miibus_readreg(device_t dev, int phy, int reg) 402{ 403 struct aue_softc *sc = device_get_softc(dev); 404 int i, locked; 405 uint16_t val = 0; 406 407 locked = mtx_owned(&sc->sc_mtx); 408 if (!locked) 409 AUE_LOCK(sc); 410 411 /* 412 * The Am79C901 HomePNA PHY actually contains two transceivers: a 1Mbps 413 * HomePNA PHY and a 10Mbps full/half duplex ethernet PHY with NWAY 414 * autoneg. However in the ADMtek adapter, only the 1Mbps PHY is 415 * actually connected to anything, so we ignore the 10Mbps one. It 416 * happens to be configured for MII address 3, so we filter that out. 417 */ 418 if (sc->sc_flags & AUE_FLAG_DUAL_PHY) { 419 if (phy == 3) 420 goto done; 421#if 0 422 if (phy != 1) 423 goto done; 424#endif 425 } 426 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 427 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); 428 429 for (i = 0; i != AUE_TIMEOUT; i++) { 430 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 431 break; 432 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 433 break; 434 } 435 436 if (i == AUE_TIMEOUT) 437 device_printf(sc->sc_ue.ue_dev, "MII read timed out\n"); 438 439 val = aue_csr_read_2(sc, AUE_PHY_DATA); 440 441done: 442 if (!locked) 443 AUE_UNLOCK(sc); 444 return (val); 445} 446 447static int 448aue_miibus_writereg(device_t dev, int phy, int reg, int data) 449{ 450 struct aue_softc *sc = device_get_softc(dev); 451 int i; 452 int locked; 453 454 if (phy == 3) 455 return (0); 456 457 locked = mtx_owned(&sc->sc_mtx); 458 if (!locked) 459 AUE_LOCK(sc); 460 461 aue_csr_write_2(sc, AUE_PHY_DATA, data); 462 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 463 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); 464 465 for (i = 0; i != AUE_TIMEOUT; i++) { 466 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 467 break; 468 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 469 break; 470 } 471 472 if (i == AUE_TIMEOUT) 473 device_printf(sc->sc_ue.ue_dev, "MII read timed out\n"); 474 475 if (!locked) 476 AUE_UNLOCK(sc); 477 return (0); 478} 479 480static void 481aue_miibus_statchg(device_t dev) 482{ 483 struct aue_softc *sc = device_get_softc(dev); 484 struct mii_data *mii = GET_MII(sc); 485 int locked; 486 487 locked = mtx_owned(&sc->sc_mtx); 488 if (!locked) 489 AUE_LOCK(sc); 490 491 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 492 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) 493 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 494 else 495 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 496 497 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) 498 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 499 else 500 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 501 502 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 503 504 /* 505 * Set the LED modes on the LinkSys adapter. 506 * This turns on the 'dual link LED' bin in the auxmode 507 * register of the Broadcom PHY. 508 */ 509 if (sc->sc_flags & AUE_FLAG_LSYS) { 510 uint16_t auxmode; 511 512 auxmode = aue_miibus_readreg(dev, 0, 0x1b); 513 aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04); 514 } 515 if (!locked) 516 AUE_UNLOCK(sc); 517} 518 519#define AUE_BITS 6 520static void 521aue_setmulti(struct usb2_ether *ue) 522{ 523 struct aue_softc *sc = usb2_ether_getsc(ue); 524 struct ifnet *ifp = usb2_ether_getifp(ue); 525 struct ifmultiaddr *ifma; 526 uint32_t h = 0; 527 uint32_t i; 528 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 529 530 AUE_LOCK_ASSERT(sc, MA_OWNED); 531 532 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 533 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 534 return; 535 } 536 537 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 538 539 /* now program new ones */ 540 IF_ADDR_LOCK(ifp); 541 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 542 if (ifma->ifma_addr->sa_family != AF_LINK) 543 continue; 544 h = ether_crc32_le(LLADDR((struct sockaddr_dl *) 545 ifma->ifma_addr), ETHER_ADDR_LEN) & ((1 << AUE_BITS) - 1); 546 hashtbl[(h >> 3)] |= 1 << (h & 0x7); 547 } 548 IF_ADDR_UNLOCK(ifp); 549 550 /* write the hashtable */ 551 for (i = 0; i != 8; i++) 552 aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]); 553} 554 555static void 556aue_reset_pegasus_II(struct aue_softc *sc) 557{ 558 /* Magic constants taken from Linux driver. */ 559 aue_csr_write_1(sc, AUE_REG_1D, 0); 560 aue_csr_write_1(sc, AUE_REG_7B, 2); 561#if 0 562 if ((sc->sc_flags & HAS_HOME_PNA) && mii_mode) 563 aue_csr_write_1(sc, AUE_REG_81, 6); 564 else 565#endif 566 aue_csr_write_1(sc, AUE_REG_81, 2); 567} 568 569static void 570aue_reset(struct aue_softc *sc) 571{ 572 int i; 573 574 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); 575 576 for (i = 0; i != AUE_TIMEOUT; i++) { 577 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) 578 break; 579 if (usb2_ether_pause(&sc->sc_ue, hz / 100)) 580 break; 581 } 582 583 if (i == AUE_TIMEOUT) 584 device_printf(sc->sc_ue.ue_dev, "reset failed\n"); 585 586 /* 587 * The PHY(s) attached to the Pegasus chip may be held 588 * in reset until we flip on the GPIO outputs. Make sure 589 * to set the GPIO pins high so that the PHY(s) will 590 * be enabled. 591 * 592 * Note: We force all of the GPIO pins low first, *then* 593 * enable the ones we want. 594 */ 595 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0); 596 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0|AUE_GPIO_SEL1); 597 598 if (sc->sc_flags & AUE_FLAG_LSYS) { 599 /* Grrr. LinkSys has to be different from everyone else. */ 600 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1); 601 aue_csr_write_1(sc, AUE_GPIO0, 602 AUE_GPIO_SEL0|AUE_GPIO_SEL1|AUE_GPIO_OUT0); 603 } 604 if (sc->sc_flags & AUE_FLAG_PII) 605 aue_reset_pegasus_II(sc); 606 607 /* Wait a little while for the chip to get its brains in order: */ 608 usb2_ether_pause(&sc->sc_ue, hz / 100); 609} 610 611static void 612aue_attach_post(struct usb2_ether *ue) 613{ 614 struct aue_softc *sc = usb2_ether_getsc(ue); 615 616 /* reset the adapter */ 617 aue_reset(sc); 618 619 /* get station address from the EEPROM */ 620 aue_read_eeprom(sc, ue->ue_eaddr, 0, 3); 621} 622 623/* 624 * Probe for a Pegasus chip. 625 */ 626static int 627aue_probe(device_t dev) 628{ 629 struct usb2_attach_arg *uaa = device_get_ivars(dev); 630 631 if (uaa->usb_mode != USB_MODE_HOST) 632 return (ENXIO); 633 if (uaa->info.bConfigIndex != AUE_CONFIG_INDEX) 634 return (ENXIO); 635 if (uaa->info.bIfaceIndex != AUE_IFACE_IDX) 636 return (ENXIO); 637 /* 638 * Belkin USB Bluetooth dongles of the F8T012xx1 model series conflict 639 * with older Belkin USB2LAN adapters. Skip if_aue if we detect one of 640 * the devices that look like Bluetooth adapters. 641 */ 642 if (uaa->info.idVendor == USB_VENDOR_BELKIN && 643 uaa->info.idProduct == USB_PRODUCT_BELKIN_F8T012 && 644 uaa->info.bcdDevice == 0x0413) 645 return (ENXIO); 646 647 return (usb2_lookup_id_by_uaa(aue_devs, sizeof(aue_devs), uaa)); 648} 649 650/* 651 * Attach the interface. Allocate softc structures, do ifmedia 652 * setup and ethernet/BPF attach. 653 */ 654static int 655aue_attach(device_t dev) 656{ 657 struct usb2_attach_arg *uaa = device_get_ivars(dev); 658 struct aue_softc *sc = device_get_softc(dev); 659 struct usb2_ether *ue = &sc->sc_ue; 660 uint8_t iface_index; 661 int error; 662 663 sc->sc_flags = USB_GET_DRIVER_INFO(uaa); 664 665 if (uaa->info.bcdDevice >= 0x0201) { 666 /* XXX currently undocumented */ 667 sc->sc_flags |= AUE_FLAG_VER_2; 668 } 669 670 device_set_usb2_desc(dev); 671 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF); 672 673 iface_index = AUE_IFACE_IDX; 674 error = usb2_transfer_setup(uaa->device, &iface_index, 675 sc->sc_xfer, aue_config, AUE_N_TRANSFER, 676 sc, &sc->sc_mtx); 677 if (error) { 678 device_printf(dev, "allocating USB transfers failed!\n"); 679 goto detach; 680 } 681 682 ue->ue_sc = sc; 683 ue->ue_dev = dev; 684 ue->ue_udev = uaa->device; 685 ue->ue_mtx = &sc->sc_mtx; 686 ue->ue_methods = &aue_ue_methods; 687 688 error = usb2_ether_ifattach(ue); 689 if (error) { 690 device_printf(dev, "could not attach interface\n"); 691 goto detach; 692 } 693 return (0); /* success */ 694 695detach: 696 aue_detach(dev); 697 return (ENXIO); /* failure */ 698} 699 700static int 701aue_detach(device_t dev) 702{ 703 struct aue_softc *sc = device_get_softc(dev); 704 struct usb2_ether *ue = &sc->sc_ue; 705 706 usb2_transfer_unsetup(sc->sc_xfer, AUE_N_TRANSFER); 707 usb2_ether_ifdetach(ue); 708 mtx_destroy(&sc->sc_mtx); 709 710 return (0); 711} 712 713static void 714aue_intr_callback(struct usb2_xfer *xfer) 715{ 716 struct aue_softc *sc = xfer->priv_sc; 717 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); 718 struct aue_intrpkt pkt; 719 720 switch (USB_GET_STATE(xfer)) { 721 case USB_ST_TRANSFERRED: 722 723 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) && 724 xfer->actlen >= sizeof(pkt)) { 725 726 usb2_copy_out(xfer->frbuffers, 0, &pkt, sizeof(pkt)); 727 728 if (pkt.aue_txstat0) 729 ifp->if_oerrors++; 730 if (pkt.aue_txstat0 & (AUE_TXSTAT0_LATECOLL & 731 AUE_TXSTAT0_EXCESSCOLL)) 732 ifp->if_collisions++; 733 } 734 /* FALLTHROUGH */ 735 case USB_ST_SETUP: 736tr_setup: 737 xfer->frlengths[0] = xfer->max_data_length; 738 usb2_start_hardware(xfer); 739 return; 740 741 default: /* Error */ 742 if (xfer->error != USB_ERR_CANCELLED) { 743 /* try to clear stall first */ 744 xfer->flags.stall_pipe = 1; 745 goto tr_setup; 746 } 747 return; 748 } 749} 750 751static void 752aue_bulk_read_callback(struct usb2_xfer *xfer) 753{ 754 struct aue_softc *sc = xfer->priv_sc; 755 struct usb2_ether *ue = &sc->sc_ue; 756 struct ifnet *ifp = usb2_ether_getifp(ue); 757 struct aue_rxpkt stat; 758 759 switch (USB_GET_STATE(xfer)) { 760 case USB_ST_TRANSFERRED: 761 DPRINTFN(11, "received %d bytes\n", xfer->actlen); 762 763 if (sc->sc_flags & AUE_FLAG_VER_2) { 764 765 if (xfer->actlen == 0) { 766 ifp->if_ierrors++; 767 goto tr_setup; 768 } 769 } else { 770 771 if (xfer->actlen <= (sizeof(stat) + ETHER_CRC_LEN)) { 772 ifp->if_ierrors++; 773 goto tr_setup; 774 } 775 usb2_copy_out(xfer->frbuffers, 776 xfer->actlen - sizeof(stat), &stat, sizeof(stat)); 777 778 /* 779 * turn off all the non-error bits in the rx status 780 * word: 781 */ 782 stat.aue_rxstat &= AUE_RXSTAT_MASK; 783 if (stat.aue_rxstat) { 784 ifp->if_ierrors++; 785 goto tr_setup; 786 } 787 /* No errors; receive the packet. */ 788 xfer->actlen -= (sizeof(stat) + ETHER_CRC_LEN); 789 } 790 usb2_ether_rxbuf(ue, xfer->frbuffers, 0, xfer->actlen); 791 792 /* FALLTHROUGH */ 793 case USB_ST_SETUP: 794tr_setup: 795 xfer->frlengths[0] = xfer->max_data_length; 796 usb2_start_hardware(xfer); 797 usb2_ether_rxflush(ue); 798 return; 799 800 default: /* Error */ 801 DPRINTF("bulk read error, %s\n", 802 usb2_errstr(xfer->error)); 803 804 if (xfer->error != USB_ERR_CANCELLED) { 805 /* try to clear stall first */ 806 xfer->flags.stall_pipe = 1; 807 goto tr_setup; 808 } 809 return; 810 } 811} 812 813static void 814aue_bulk_write_callback(struct usb2_xfer *xfer) 815{ 816 struct aue_softc *sc = xfer->priv_sc; 817 struct ifnet *ifp = usb2_ether_getifp(&sc->sc_ue); 818 struct mbuf *m; 819 uint8_t buf[2]; 820 821 switch (USB_GET_STATE(xfer)) { 822 case USB_ST_TRANSFERRED: 823 DPRINTFN(11, "transfer of %d bytes complete\n", xfer->actlen); 824 ifp->if_opackets++; 825 826 /* FALLTHROUGH */ 827 case USB_ST_SETUP: 828tr_setup: 829 if ((sc->sc_flags & AUE_FLAG_LINK) == 0) { 830 /* 831 * don't send anything if there is no link ! 832 */ 833 return; 834 } 835 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 836 837 if (m == NULL) 838 return; 839 if (m->m_pkthdr.len > MCLBYTES) 840 m->m_pkthdr.len = MCLBYTES; 841 if (sc->sc_flags & AUE_FLAG_VER_2) { 842 843 xfer->frlengths[0] = m->m_pkthdr.len; 844 845 usb2_m_copy_in(xfer->frbuffers, 0, 846 m, 0, m->m_pkthdr.len); 847 848 } else { 849 850 xfer->frlengths[0] = (m->m_pkthdr.len + 2); 851 852 /* 853 * The ADMtek documentation says that the 854 * packet length is supposed to be specified 855 * in the first two bytes of the transfer, 856 * however it actually seems to ignore this 857 * info and base the frame size on the bulk 858 * transfer length. 859 */ 860 buf[0] = (uint8_t)(m->m_pkthdr.len); 861 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8); 862 863 usb2_copy_in(xfer->frbuffers, 0, buf, 2); 864 865 usb2_m_copy_in(xfer->frbuffers, 2, 866 m, 0, m->m_pkthdr.len); 867 } 868 869 /* 870 * if there's a BPF listener, bounce a copy 871 * of this frame to him: 872 */ 873 BPF_MTAP(ifp, m); 874 875 m_freem(m); 876 877 usb2_start_hardware(xfer); 878 return; 879 880 default: /* Error */ 881 DPRINTFN(11, "transfer error, %s\n", 882 usb2_errstr(xfer->error)); 883 884 ifp->if_oerrors++; 885 886 if (xfer->error != USB_ERR_CANCELLED) { 887 /* try to clear stall first */ 888 xfer->flags.stall_pipe = 1; 889 goto tr_setup; 890 } 891 return; 892 } 893} 894 895static void 896aue_tick(struct usb2_ether *ue) 897{ 898 struct aue_softc *sc = usb2_ether_getsc(ue); 899 struct mii_data *mii = GET_MII(sc); 900 901 AUE_LOCK_ASSERT(sc, MA_OWNED); 902 903 mii_tick(mii); 904 if ((sc->sc_flags & AUE_FLAG_LINK) == 0 905 && mii->mii_media_status & IFM_ACTIVE && 906 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 907 sc->sc_flags |= AUE_FLAG_LINK; 908 aue_start(ue); 909 } 910} 911 912static void 913aue_start(struct usb2_ether *ue) 914{ 915 struct aue_softc *sc = usb2_ether_getsc(ue); 916 917 /* 918 * start the USB transfers, if not already started: 919 */ 920 usb2_transfer_start(sc->sc_xfer[AUE_INTR_DT_RD]); 921 usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_RD]); 922 usb2_transfer_start(sc->sc_xfer[AUE_BULK_DT_WR]); 923} 924 925static void 926aue_init(struct usb2_ether *ue) 927{ 928 struct aue_softc *sc = usb2_ether_getsc(ue); 929 struct ifnet *ifp = usb2_ether_getifp(ue); 930 int i; 931 932 AUE_LOCK_ASSERT(sc, MA_OWNED); 933 934 /* 935 * Cancel pending I/O 936 */ 937 aue_reset(sc); 938 939 /* Set MAC address */ 940 for (i = 0; i != ETHER_ADDR_LEN; i++) 941 aue_csr_write_1(sc, AUE_PAR0 + i, IF_LLADDR(ifp)[i]); 942 943 /* update promiscuous setting */ 944 aue_setpromisc(ue); 945 946 /* Load the multicast filter. */ 947 aue_setmulti(ue); 948 949 /* Enable RX and TX */ 950 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB); 951 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 952 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); 953 954 usb2_transfer_set_stall(sc->sc_xfer[AUE_BULK_DT_WR]); 955 956 ifp->if_drv_flags |= IFF_DRV_RUNNING; 957 aue_start(ue); 958} 959 960static void 961aue_setpromisc(struct usb2_ether *ue) 962{ 963 struct aue_softc *sc = usb2_ether_getsc(ue); 964 struct ifnet *ifp = usb2_ether_getifp(ue); 965 966 AUE_LOCK_ASSERT(sc, MA_OWNED); 967 968 /* if we want promiscuous mode, set the allframes bit: */ 969 if (ifp->if_flags & IFF_PROMISC) 970 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 971 else 972 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 973} 974 975/* 976 * Set media options. 977 */ 978static int 979aue_ifmedia_upd(struct ifnet *ifp) 980{ 981 struct aue_softc *sc = ifp->if_softc; 982 struct mii_data *mii = GET_MII(sc); 983 984 AUE_LOCK_ASSERT(sc, MA_OWNED); 985 986 sc->sc_flags &= ~AUE_FLAG_LINK; 987 if (mii->mii_instance) { 988 struct mii_softc *miisc; 989 990 LIST_FOREACH(miisc, &mii->mii_phys, mii_list) 991 mii_phy_reset(miisc); 992 } 993 mii_mediachg(mii); 994 return (0); 995} 996 997/* 998 * Report current media status. 999 */ 1000static void 1001aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 1002{ 1003 struct aue_softc *sc = ifp->if_softc; 1004 struct mii_data *mii = GET_MII(sc); 1005 1006 AUE_LOCK(sc); 1007 mii_pollstat(mii); 1008 AUE_UNLOCK(sc); 1009 ifmr->ifm_active = mii->mii_media_active; 1010 ifmr->ifm_status = mii->mii_media_status; 1011} 1012 1013/* 1014 * Stop the adapter and free any mbufs allocated to the 1015 * RX and TX lists. 1016 */ 1017static void 1018aue_stop(struct usb2_ether *ue) 1019{ 1020 struct aue_softc *sc = usb2_ether_getsc(ue); 1021 struct ifnet *ifp = usb2_ether_getifp(ue); 1022 1023 AUE_LOCK_ASSERT(sc, MA_OWNED); 1024 1025 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; 1026 sc->sc_flags &= ~AUE_FLAG_LINK; 1027 1028 /* 1029 * stop all the transfers, if not already stopped: 1030 */ 1031 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_WR]); 1032 usb2_transfer_stop(sc->sc_xfer[AUE_BULK_DT_RD]); 1033 usb2_transfer_stop(sc->sc_xfer[AUE_INTR_DT_RD]); 1034 1035 aue_csr_write_1(sc, AUE_CTL0, 0); 1036 aue_csr_write_1(sc, AUE_CTL1, 0); 1037 aue_reset(sc); 1038} 1039