2 * Copyright (c) 1997, 1998, 1999, 2000
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
6 * Alfred Perlstein <alfred@FreeBSD.org>. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Bill Paul.
19 * 4. Neither the name of the author nor the names of any co-contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
40 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver.
41 * Datasheet is available from http://www.admtek.com.tw.
43 * Written by Bill Paul <wpaul@ee.columbia.edu>
44 * Electrical Engineering Department
45 * Columbia University, New York City
47 * SMP locking by Alfred Perlstein <alfred@FreeBSD.org>.
52 * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet
53 * support: the control endpoint for reading/writing registers, burst
54 * read endpoint for packet reception, burst write for packet transmission
55 * and one for "interrupts." The chip uses the same RX filter scheme
56 * as the other ADMtek ethernet parts: one perfect filter entry for the
57 * the station address and a 64-bit multicast hash table. The chip supports
58 * both MII and HomePNA attachments.
60 * Since the maximum data transfer speed of USB is supposed to be 12Mbps,
61 * you're never really going to get 100Mbps speeds from this device. I
62 * think the idea is to allow the device to connect to 10 or 100Mbps
63 * networks, not necessarily to provide 100Mbps performance. Also, since
64 * the controller uses an external PHY chip, it's possible that board
65 * designers might simply choose a 10Mbps PHY.
67 * Registers are accessed using uether_do_request(). Packet
68 * transfers are done using usbd_transfer() and friends.
71 #include <sys/stdint.h>
72 #include <sys/stddef.h>
73 #include <sys/param.h>
74 #include <sys/queue.h>
75 #include <sys/types.h>
76 #include <sys/systm.h>
77 #include <sys/kernel.h>
79 #include <sys/linker_set.h>
80 #include <sys/module.h>
82 #include <sys/mutex.h>
83 #include <sys/condvar.h>
84 #include <sys/sysctl.h>
86 #include <sys/unistd.h>
87 #include <sys/callout.h>
88 #include <sys/malloc.h>
91 #include <dev/usb/usb.h>
92 #include <dev/usb/usbdi.h>
93 #include <dev/usb/usbdi_util.h>
96 #define USB_DEBUG_VAR aue_debug
97 #include <dev/usb/usb_debug.h>
98 #include <dev/usb/usb_process.h>
100 #include <dev/usb/net/usb_ethernet.h>
101 #include <dev/usb/net/if_auereg.h>
104 static int aue_debug = 0;
106 SYSCTL_NODE(_hw_usb, OID_AUTO, aue, CTLFLAG_RW, 0, "USB aue");
107 SYSCTL_INT(_hw_usb_aue, OID_AUTO, debug, CTLFLAG_RW, &aue_debug, 0,
112 * Various supported device vendors/products.
114 static const struct usb_device_id aue_devs[] = {
115 {USB_VPI(USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B, AUE_FLAG_PII)},
116 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA, 0)},
117 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000, AUE_FLAG_LSYS)},
118 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10, 0)},
119 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1, AUE_FLAG_PNA | AUE_FLAG_PII)},
120 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2, AUE_FLAG_PII)},
121 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4, AUE_FLAG_PNA)},
122 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5, AUE_FLAG_PNA)},
123 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6, AUE_FLAG_PII)},
124 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7, AUE_FLAG_PII)},
125 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8, AUE_FLAG_PII)},
126 {USB_VPI(USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9, AUE_FLAG_PNA)},
127 {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001, AUE_FLAG_PII)},
128 {USB_VPI(USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC, 0)},
129 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2, AUE_FLAG_PII)},
130 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3, AUE_FLAG_PII)},
131 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_4, AUE_FLAG_PII)},
132 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII, AUE_FLAG_PII)},
133 {USB_VPI(USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS, AUE_FLAG_PNA | AUE_FLAG_DUAL_PHY)},
134 {USB_VPI(USB_VENDOR_AEI, USB_PRODUCT_AEI_FASTETHERNET, AUE_FLAG_PII)},
135 {USB_VPI(USB_VENDOR_ALLIEDTELESYN, USB_PRODUCT_ALLIEDTELESYN_ATUSB100, AUE_FLAG_PII)},
136 {USB_VPI(USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC110T, AUE_FLAG_PII)},
137 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN, AUE_FLAG_PII)},
138 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100, 0)},
139 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100, AUE_FLAG_PII)},
140 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100, 0)},
141 {USB_VPI(USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100, AUE_FLAG_PNA)},
142 {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS, AUE_FLAG_PII)},
143 {USB_VPI(USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX, 0)},
144 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1, AUE_FLAG_LSYS)},
145 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)},
146 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3, AUE_FLAG_LSYS | AUE_FLAG_PII)},
147 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4, AUE_FLAG_LSYS | AUE_FLAG_PII)},
148 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA, AUE_FLAG_PNA)},
149 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX, AUE_FLAG_LSYS)},
150 {USB_VPI(USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650, AUE_FLAG_LSYS)},
151 {USB_VPI(USB_VENDOR_ELCON, USB_PRODUCT_ELCON_PLAN, AUE_FLAG_PNA | AUE_FLAG_PII)},
152 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSB20, AUE_FLAG_PII)},
153 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX, AUE_FLAG_PII)},
154 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0, 0)},
155 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1, AUE_FLAG_LSYS)},
156 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2, 0)},
157 {USB_VPI(USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3, AUE_FLAG_LSYS)},
158 {USB_VPI(USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET, 0)},
159 {USB_VPI(USB_VENDOR_GIGABYTE, USB_PRODUCT_GIGABYTE_GNBR402W, 0)},
160 {USB_VPI(USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100, AUE_FLAG_PII)},
161 {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HN210E, AUE_FLAG_PII)},
162 {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS, AUE_FLAG_PII)},
163 {USB_VPI(USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX, 0)},
164 {USB_VPI(USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX, 0)},
165 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1, AUE_FLAG_LSYS | AUE_FLAG_PNA)},
166 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX, AUE_FLAG_LSYS)},
167 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA, AUE_FLAG_LSYS)},
168 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1, AUE_FLAG_LSYS | AUE_FLAG_PII)},
169 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2, AUE_FLAG_LSYS | AUE_FLAG_PII)},
170 {USB_VPI(USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T, AUE_FLAG_LSYS)},
171 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5, AUE_FLAG_PII)},
172 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1, 0)},
173 {USB_VPI(USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5, 0)},
174 {USB_VPI(USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110, AUE_FLAG_PII)},
175 {USB_VPI(USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101, AUE_FLAG_PII)},
176 {USB_VPI(USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM, AUE_FLAG_PII)},
177 {USB_VPI(USB_VENDOR_SIIG2, USB_PRODUCT_SIIG2_USBTOETHER, AUE_FLAG_PII)},
178 {USB_VPI(USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC, AUE_FLAG_PII)},
179 {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB, 0)},
180 {USB_VPI(USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB, AUE_FLAG_PII)},
181 {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100, 0)},
182 {USB_VPI(USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB110, AUE_FLAG_PII)},
187 static device_probe_t aue_probe;
188 static device_attach_t aue_attach;
189 static device_detach_t aue_detach;
190 static miibus_readreg_t aue_miibus_readreg;
191 static miibus_writereg_t aue_miibus_writereg;
192 static miibus_statchg_t aue_miibus_statchg;
194 static usb_callback_t aue_intr_callback;
195 static usb_callback_t aue_bulk_read_callback;
196 static usb_callback_t aue_bulk_write_callback;
198 static uether_fn_t aue_attach_post;
199 static uether_fn_t aue_init;
200 static uether_fn_t aue_stop;
201 static uether_fn_t aue_start;
202 static uether_fn_t aue_tick;
203 static uether_fn_t aue_setmulti;
204 static uether_fn_t aue_setpromisc;
206 static uint8_t aue_csr_read_1(struct aue_softc *, uint16_t);
207 static uint16_t aue_csr_read_2(struct aue_softc *, uint16_t);
208 static void aue_csr_write_1(struct aue_softc *, uint16_t, uint8_t);
209 static void aue_csr_write_2(struct aue_softc *, uint16_t, uint16_t);
210 static void aue_eeprom_getword(struct aue_softc *, int, uint16_t *);
211 static void aue_read_eeprom(struct aue_softc *, uint8_t *, uint16_t,
213 static void aue_reset(struct aue_softc *);
214 static void aue_reset_pegasus_II(struct aue_softc *);
216 static int aue_ifmedia_upd(struct ifnet *);
217 static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
219 static const struct usb_config aue_config[AUE_N_TRANSFER] = {
223 .endpoint = UE_ADDR_ANY,
224 .direction = UE_DIR_OUT,
225 .bufsize = (MCLBYTES + 2),
226 .flags = {.pipe_bof = 1,.force_short_xfer = 1,},
227 .callback = aue_bulk_write_callback,
228 .timeout = 10000, /* 10 seconds */
233 .endpoint = UE_ADDR_ANY,
234 .direction = UE_DIR_IN,
235 .bufsize = (MCLBYTES + 4 + ETHER_CRC_LEN),
236 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
237 .callback = aue_bulk_read_callback,
241 .type = UE_INTERRUPT,
242 .endpoint = UE_ADDR_ANY,
243 .direction = UE_DIR_IN,
244 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
245 .bufsize = 0, /* use wMaxPacketSize */
246 .callback = aue_intr_callback,
250 static device_method_t aue_methods[] = {
251 /* Device interface */
252 DEVMETHOD(device_probe, aue_probe),
253 DEVMETHOD(device_attach, aue_attach),
254 DEVMETHOD(device_detach, aue_detach),
257 DEVMETHOD(bus_print_child, bus_generic_print_child),
258 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
261 DEVMETHOD(miibus_readreg, aue_miibus_readreg),
262 DEVMETHOD(miibus_writereg, aue_miibus_writereg),
263 DEVMETHOD(miibus_statchg, aue_miibus_statchg),
268 static driver_t aue_driver = {
270 .methods = aue_methods,
271 .size = sizeof(struct aue_softc)
274 static devclass_t aue_devclass;
276 DRIVER_MODULE(aue, uhub, aue_driver, aue_devclass, NULL, 0);
277 DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0);
278 MODULE_DEPEND(aue, uether, 1, 1, 1);
279 MODULE_DEPEND(aue, usb, 1, 1, 1);
280 MODULE_DEPEND(aue, ether, 1, 1, 1);
281 MODULE_DEPEND(aue, miibus, 1, 1, 1);
283 static const struct usb_ether_methods aue_ue_methods = {
284 .ue_attach_post = aue_attach_post,
285 .ue_start = aue_start,
289 .ue_setmulti = aue_setmulti,
290 .ue_setpromisc = aue_setpromisc,
291 .ue_mii_upd = aue_ifmedia_upd,
292 .ue_mii_sts = aue_ifmedia_sts,
295 #define AUE_SETBIT(sc, reg, x) \
296 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
298 #define AUE_CLRBIT(sc, reg, x) \
299 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
302 aue_csr_read_1(struct aue_softc *sc, uint16_t reg)
304 struct usb_device_request req;
308 req.bmRequestType = UT_READ_VENDOR_DEVICE;
309 req.bRequest = AUE_UR_READREG;
310 USETW(req.wValue, 0);
311 USETW(req.wIndex, reg);
312 USETW(req.wLength, 1);
314 err = uether_do_request(&sc->sc_ue, &req, &val, 1000);
321 aue_csr_read_2(struct aue_softc *sc, uint16_t reg)
323 struct usb_device_request req;
327 req.bmRequestType = UT_READ_VENDOR_DEVICE;
328 req.bRequest = AUE_UR_READREG;
329 USETW(req.wValue, 0);
330 USETW(req.wIndex, reg);
331 USETW(req.wLength, 2);
333 err = uether_do_request(&sc->sc_ue, &req, &val, 1000);
336 return (le16toh(val));
340 aue_csr_write_1(struct aue_softc *sc, uint16_t reg, uint8_t val)
342 struct usb_device_request req;
344 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
345 req.bRequest = AUE_UR_WRITEREG;
348 USETW(req.wIndex, reg);
349 USETW(req.wLength, 1);
351 if (uether_do_request(&sc->sc_ue, &req, &val, 1000)) {
357 aue_csr_write_2(struct aue_softc *sc, uint16_t reg, uint16_t val)
359 struct usb_device_request req;
361 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
362 req.bRequest = AUE_UR_WRITEREG;
363 USETW(req.wValue, val);
364 USETW(req.wIndex, reg);
365 USETW(req.wLength, 2);
369 if (uether_do_request(&sc->sc_ue, &req, &val, 1000)) {
375 * Read a word of data stored in the EEPROM at address 'addr.'
378 aue_eeprom_getword(struct aue_softc *sc, int addr, uint16_t *dest)
383 aue_csr_write_1(sc, AUE_EE_REG, addr);
384 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
386 for (i = 0; i != AUE_TIMEOUT; i++) {
387 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
389 if (uether_pause(&sc->sc_ue, hz / 100))
393 if (i == AUE_TIMEOUT)
394 device_printf(sc->sc_ue.ue_dev, "EEPROM read timed out\n");
396 word = aue_csr_read_2(sc, AUE_EE_DATA);
401 * Read a sequence of words from the EEPROM.
404 aue_read_eeprom(struct aue_softc *sc, uint8_t *dest,
405 uint16_t off, uint16_t len)
407 uint16_t *ptr = (uint16_t *)dest;
410 for (i = 0; i != len; i++, ptr++)
411 aue_eeprom_getword(sc, off + i, ptr);
415 aue_miibus_readreg(device_t dev, int phy, int reg)
417 struct aue_softc *sc = device_get_softc(dev);
421 locked = mtx_owned(&sc->sc_mtx);
426 * The Am79C901 HomePNA PHY actually contains two transceivers: a 1Mbps
427 * HomePNA PHY and a 10Mbps full/half duplex ethernet PHY with NWAY
428 * autoneg. However in the ADMtek adapter, only the 1Mbps PHY is
429 * actually connected to anything, so we ignore the 10Mbps one. It
430 * happens to be configured for MII address 3, so we filter that out.
432 if (sc->sc_flags & AUE_FLAG_DUAL_PHY) {
440 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
441 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ);
443 for (i = 0; i != AUE_TIMEOUT; i++) {
444 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
446 if (uether_pause(&sc->sc_ue, hz / 100))
450 if (i == AUE_TIMEOUT)
451 device_printf(sc->sc_ue.ue_dev, "MII read timed out\n");
453 val = aue_csr_read_2(sc, AUE_PHY_DATA);
462 aue_miibus_writereg(device_t dev, int phy, int reg, int data)
464 struct aue_softc *sc = device_get_softc(dev);
471 locked = mtx_owned(&sc->sc_mtx);
475 aue_csr_write_2(sc, AUE_PHY_DATA, data);
476 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
477 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE);
479 for (i = 0; i != AUE_TIMEOUT; i++) {
480 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
482 if (uether_pause(&sc->sc_ue, hz / 100))
486 if (i == AUE_TIMEOUT)
487 device_printf(sc->sc_ue.ue_dev, "MII read timed out\n");
495 aue_miibus_statchg(device_t dev)
497 struct aue_softc *sc = device_get_softc(dev);
498 struct mii_data *mii = GET_MII(sc);
501 locked = mtx_owned(&sc->sc_mtx);
505 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
506 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX)
507 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
509 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
511 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
512 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
514 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
516 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
519 * Set the LED modes on the LinkSys adapter.
520 * This turns on the 'dual link LED' bin in the auxmode
521 * register of the Broadcom PHY.
523 if (sc->sc_flags & AUE_FLAG_LSYS) {
526 auxmode = aue_miibus_readreg(dev, 0, 0x1b);
527 aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04);
535 aue_setmulti(struct usb_ether *ue)
537 struct aue_softc *sc = uether_getsc(ue);
538 struct ifnet *ifp = uether_getifp(ue);
539 struct ifmultiaddr *ifma;
542 uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
544 AUE_LOCK_ASSERT(sc, MA_OWNED);
546 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
547 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
551 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
553 /* now program new ones */
555 TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
556 if (ifma->ifma_addr->sa_family != AF_LINK)
558 h = ether_crc32_le(LLADDR((struct sockaddr_dl *)
559 ifma->ifma_addr), ETHER_ADDR_LEN) & ((1 << AUE_BITS) - 1);
560 hashtbl[(h >> 3)] |= 1 << (h & 0x7);
562 if_maddr_runlock(ifp);
564 /* write the hashtable */
565 for (i = 0; i != 8; i++)
566 aue_csr_write_1(sc, AUE_MAR0 + i, hashtbl[i]);
570 aue_reset_pegasus_II(struct aue_softc *sc)
572 /* Magic constants taken from Linux driver. */
573 aue_csr_write_1(sc, AUE_REG_1D, 0);
574 aue_csr_write_1(sc, AUE_REG_7B, 2);
576 if ((sc->sc_flags & HAS_HOME_PNA) && mii_mode)
577 aue_csr_write_1(sc, AUE_REG_81, 6);
580 aue_csr_write_1(sc, AUE_REG_81, 2);
584 aue_reset(struct aue_softc *sc)
588 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
590 for (i = 0; i != AUE_TIMEOUT; i++) {
591 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
593 if (uether_pause(&sc->sc_ue, hz / 100))
597 if (i == AUE_TIMEOUT)
598 device_printf(sc->sc_ue.ue_dev, "reset failed\n");
601 * The PHY(s) attached to the Pegasus chip may be held
602 * in reset until we flip on the GPIO outputs. Make sure
603 * to set the GPIO pins high so that the PHY(s) will
606 * Note: We force all of the GPIO pins low first, *then*
607 * enable the ones we want.
609 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0);
610 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_OUT0|AUE_GPIO_SEL0|AUE_GPIO_SEL1);
612 if (sc->sc_flags & AUE_FLAG_LSYS) {
613 /* Grrr. LinkSys has to be different from everyone else. */
614 aue_csr_write_1(sc, AUE_GPIO0, AUE_GPIO_SEL0|AUE_GPIO_SEL1);
615 aue_csr_write_1(sc, AUE_GPIO0,
616 AUE_GPIO_SEL0|AUE_GPIO_SEL1|AUE_GPIO_OUT0);
618 if (sc->sc_flags & AUE_FLAG_PII)
619 aue_reset_pegasus_II(sc);
621 /* Wait a little while for the chip to get its brains in order: */
622 uether_pause(&sc->sc_ue, hz / 100);
626 aue_attach_post(struct usb_ether *ue)
628 struct aue_softc *sc = uether_getsc(ue);
630 /* reset the adapter */
633 /* get station address from the EEPROM */
634 aue_read_eeprom(sc, ue->ue_eaddr, 0, 3);
638 * Probe for a Pegasus chip.
641 aue_probe(device_t dev)
643 struct usb_attach_arg *uaa = device_get_ivars(dev);
645 if (uaa->usb_mode != USB_MODE_HOST)
647 if (uaa->info.bConfigIndex != AUE_CONFIG_INDEX)
649 if (uaa->info.bIfaceIndex != AUE_IFACE_IDX)
652 * Belkin USB Bluetooth dongles of the F8T012xx1 model series conflict
653 * with older Belkin USB2LAN adapters. Skip if_aue if we detect one of
654 * the devices that look like Bluetooth adapters.
656 if (uaa->info.idVendor == USB_VENDOR_BELKIN &&
657 uaa->info.idProduct == USB_PRODUCT_BELKIN_F8T012 &&
658 uaa->info.bcdDevice == 0x0413)
661 return (usbd_lookup_id_by_uaa(aue_devs, sizeof(aue_devs), uaa));
665 * Attach the interface. Allocate softc structures, do ifmedia
666 * setup and ethernet/BPF attach.
669 aue_attach(device_t dev)
671 struct usb_attach_arg *uaa = device_get_ivars(dev);
672 struct aue_softc *sc = device_get_softc(dev);
673 struct usb_ether *ue = &sc->sc_ue;
677 sc->sc_flags = USB_GET_DRIVER_INFO(uaa);
679 if (uaa->info.bcdDevice >= 0x0201) {
680 /* XXX currently undocumented */
681 sc->sc_flags |= AUE_FLAG_VER_2;
684 device_set_usb_desc(dev);
685 mtx_init(&sc->sc_mtx, device_get_nameunit(dev), NULL, MTX_DEF);
687 iface_index = AUE_IFACE_IDX;
688 error = usbd_transfer_setup(uaa->device, &iface_index,
689 sc->sc_xfer, aue_config, AUE_N_TRANSFER,
692 device_printf(dev, "allocating USB transfers failed!\n");
698 ue->ue_udev = uaa->device;
699 ue->ue_mtx = &sc->sc_mtx;
700 ue->ue_methods = &aue_ue_methods;
702 error = uether_ifattach(ue);
704 device_printf(dev, "could not attach interface\n");
707 return (0); /* success */
711 return (ENXIO); /* failure */
715 aue_detach(device_t dev)
717 struct aue_softc *sc = device_get_softc(dev);
718 struct usb_ether *ue = &sc->sc_ue;
720 usbd_transfer_unsetup(sc->sc_xfer, AUE_N_TRANSFER);
722 mtx_destroy(&sc->sc_mtx);
728 aue_intr_callback(struct usb_xfer *xfer, usb_error_t error)
730 struct aue_softc *sc = usbd_xfer_softc(xfer);
731 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
732 struct aue_intrpkt pkt;
733 struct usb_page_cache *pc;
736 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
738 switch (USB_GET_STATE(xfer)) {
739 case USB_ST_TRANSFERRED:
741 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) &&
742 actlen >= sizeof(pkt)) {
744 pc = usbd_xfer_get_frame(xfer, 0);
745 usbd_copy_out(pc, 0, &pkt, sizeof(pkt));
749 if (pkt.aue_txstat0 & (AUE_TXSTAT0_LATECOLL &
750 AUE_TXSTAT0_EXCESSCOLL))
751 ifp->if_collisions++;
756 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
757 usbd_transfer_submit(xfer);
761 if (error != USB_ERR_CANCELLED) {
762 /* try to clear stall first */
763 usbd_xfer_set_stall(xfer);
771 aue_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
773 struct aue_softc *sc = usbd_xfer_softc(xfer);
774 struct usb_ether *ue = &sc->sc_ue;
775 struct ifnet *ifp = uether_getifp(ue);
776 struct aue_rxpkt stat;
777 struct usb_page_cache *pc;
780 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
781 pc = usbd_xfer_get_frame(xfer, 0);
783 switch (USB_GET_STATE(xfer)) {
784 case USB_ST_TRANSFERRED:
785 DPRINTFN(11, "received %d bytes\n", actlen);
787 if (sc->sc_flags & AUE_FLAG_VER_2) {
795 if (actlen <= sizeof(stat) + ETHER_CRC_LEN) {
799 usbd_copy_out(pc, actlen - sizeof(stat), &stat,
803 * turn off all the non-error bits in the rx status
806 stat.aue_rxstat &= AUE_RXSTAT_MASK;
807 if (stat.aue_rxstat) {
811 /* No errors; receive the packet. */
812 actlen -= (sizeof(stat) + ETHER_CRC_LEN);
814 uether_rxbuf(ue, pc, 0, actlen);
819 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
820 usbd_transfer_submit(xfer);
825 DPRINTF("bulk read error, %s\n",
828 if (error != USB_ERR_CANCELLED) {
829 /* try to clear stall first */
830 usbd_xfer_set_stall(xfer);
838 aue_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
840 struct aue_softc *sc = usbd_xfer_softc(xfer);
841 struct ifnet *ifp = uether_getifp(&sc->sc_ue);
842 struct usb_page_cache *pc;
847 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
848 pc = usbd_xfer_get_frame(xfer, 0);
850 switch (USB_GET_STATE(xfer)) {
851 case USB_ST_TRANSFERRED:
852 DPRINTFN(11, "transfer of %d bytes complete\n", actlen);
858 if ((sc->sc_flags & AUE_FLAG_LINK) == 0) {
860 * don't send anything if there is no link !
864 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
868 if (m->m_pkthdr.len > MCLBYTES)
869 m->m_pkthdr.len = MCLBYTES;
870 if (sc->sc_flags & AUE_FLAG_VER_2) {
872 usbd_xfer_set_frame_len(xfer, 0, m->m_pkthdr.len);
874 usbd_m_copy_in(pc, 0, m, 0, m->m_pkthdr.len);
878 usbd_xfer_set_frame_len(xfer, 0, (m->m_pkthdr.len + 2));
881 * The ADMtek documentation says that the
882 * packet length is supposed to be specified
883 * in the first two bytes of the transfer,
884 * however it actually seems to ignore this
885 * info and base the frame size on the bulk
888 buf[0] = (uint8_t)(m->m_pkthdr.len);
889 buf[1] = (uint8_t)(m->m_pkthdr.len >> 8);
891 usbd_copy_in(pc, 0, buf, 2);
892 usbd_m_copy_in(pc, 2, m, 0, m->m_pkthdr.len);
896 * if there's a BPF listener, bounce a copy
897 * of this frame to him:
903 usbd_transfer_submit(xfer);
907 DPRINTFN(11, "transfer error, %s\n",
912 if (error != USB_ERR_CANCELLED) {
913 /* try to clear stall first */
914 usbd_xfer_set_stall(xfer);
922 aue_tick(struct usb_ether *ue)
924 struct aue_softc *sc = uether_getsc(ue);
925 struct mii_data *mii = GET_MII(sc);
927 AUE_LOCK_ASSERT(sc, MA_OWNED);
930 if ((sc->sc_flags & AUE_FLAG_LINK) == 0
931 && mii->mii_media_status & IFM_ACTIVE &&
932 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
933 sc->sc_flags |= AUE_FLAG_LINK;
939 aue_start(struct usb_ether *ue)
941 struct aue_softc *sc = uether_getsc(ue);
944 * start the USB transfers, if not already started:
946 usbd_transfer_start(sc->sc_xfer[AUE_INTR_DT_RD]);
947 usbd_transfer_start(sc->sc_xfer[AUE_BULK_DT_RD]);
948 usbd_transfer_start(sc->sc_xfer[AUE_BULK_DT_WR]);
952 aue_init(struct usb_ether *ue)
954 struct aue_softc *sc = uether_getsc(ue);
955 struct ifnet *ifp = uether_getifp(ue);
958 AUE_LOCK_ASSERT(sc, MA_OWNED);
965 /* Set MAC address */
966 for (i = 0; i != ETHER_ADDR_LEN; i++)
967 aue_csr_write_1(sc, AUE_PAR0 + i, IF_LLADDR(ifp)[i]);
969 /* update promiscuous setting */
972 /* Load the multicast filter. */
975 /* Enable RX and TX */
976 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB);
977 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
978 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
980 usbd_xfer_set_stall(sc->sc_xfer[AUE_BULK_DT_WR]);
982 ifp->if_drv_flags |= IFF_DRV_RUNNING;
987 aue_setpromisc(struct usb_ether *ue)
989 struct aue_softc *sc = uether_getsc(ue);
990 struct ifnet *ifp = uether_getifp(ue);
992 AUE_LOCK_ASSERT(sc, MA_OWNED);
994 /* if we want promiscuous mode, set the allframes bit: */
995 if (ifp->if_flags & IFF_PROMISC)
996 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
998 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1002 * Set media options.
1005 aue_ifmedia_upd(struct ifnet *ifp)
1007 struct aue_softc *sc = ifp->if_softc;
1008 struct mii_data *mii = GET_MII(sc);
1010 AUE_LOCK_ASSERT(sc, MA_OWNED);
1012 sc->sc_flags &= ~AUE_FLAG_LINK;
1013 if (mii->mii_instance) {
1014 struct mii_softc *miisc;
1016 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
1017 mii_phy_reset(miisc);
1024 * Report current media status.
1027 aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1029 struct aue_softc *sc = ifp->if_softc;
1030 struct mii_data *mii = GET_MII(sc);
1035 ifmr->ifm_active = mii->mii_media_active;
1036 ifmr->ifm_status = mii->mii_media_status;
1040 * Stop the adapter and free any mbufs allocated to the
1044 aue_stop(struct usb_ether *ue)
1046 struct aue_softc *sc = uether_getsc(ue);
1047 struct ifnet *ifp = uether_getifp(ue);
1049 AUE_LOCK_ASSERT(sc, MA_OWNED);
1051 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1052 sc->sc_flags &= ~AUE_FLAG_LINK;
1055 * stop all the transfers, if not already stopped:
1057 usbd_transfer_stop(sc->sc_xfer[AUE_BULK_DT_WR]);
1058 usbd_transfer_stop(sc->sc_xfer[AUE_BULK_DT_RD]);
1059 usbd_transfer_stop(sc->sc_xfer[AUE_INTR_DT_RD]);
1061 aue_csr_write_1(sc, AUE_CTL0, 0);
1062 aue_csr_write_1(sc, AUE_CTL1, 0);