1 /* $NetBSD: if_aue.c,v 1.116 2009/12/06 20:20:12 dyoung Exp $ */
3 * Copyright (c) 1997, 1998, 1999, 2000
4 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Bill Paul.
17 * 4. Neither the name of the author nor the names of any co-contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
33 * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $
37 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver.
38 * Datasheet is available from http://www.admtek.com.tw.
40 * Written by Bill Paul <wpaul@ee.columbia.edu>
41 * Electrical Engineering Department
42 * Columbia University, New York City
46 * The Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet
47 * support: the control endpoint for reading/writing registers, burst
48 * read endpoint for packet reception, burst write for packet transmission
49 * and one for "interrupts." The chip uses the same RX filter scheme
50 * as the other ADMtek ethernet parts: one perfect filter entry for the
51 * the station address and a 64-bit multicast hash table. The chip supports
52 * both MII and HomePNA attachments.
54 * Since the maximum data transfer speed of USB is supposed to be 12Mbps,
55 * you're never really going to get 100Mbps speeds from this device. I
56 * think the idea is to allow the device to connect to 10 or 100Mbps
57 * networks, not necessarily to provide 100Mbps performance. Also, since
58 * the controller uses an external PHY chip, it's possible that board
59 * designers might simply choose a 10Mbps PHY.
61 * Registers are accessed using usbd_do_request(). Packet transfers are
62 * done using usbd_transfer() and friends.
66 * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
71 * better error messages from rxstat
72 * split out if_auevar.h
73 * add thread to avoid register reads from interrupt context
75 * investigate short rx problem
76 * proper cleanup on errors
79 #include <sys/cdefs.h>
80 __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.116 2009/12/06 20:20:12 dyoung Exp $");
86 #include <sys/param.h>
87 #include <sys/systm.h>
88 #include <sys/sockio.h>
89 #include <sys/mutex.h>
91 #include <sys/malloc.h>
92 #include <sys/kernel.h>
93 #include <sys/socket.h>
94 #include <sys/device.h>
100 #include <net/if_arp.h>
101 #include <net/if_dl.h>
102 #include <net/if_media.h>
104 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
110 #include <net/if_ether.h>
112 #include <netinet/in.h>
113 #include <netinet/if_inarp.h>
118 #include <dev/mii/mii.h>
119 #include <dev/mii/miivar.h>
121 #include <dev/usb/usb.h>
122 #include <dev/usb/usbdi.h>
123 #include <dev/usb/usbdi_util.h>
124 #include <dev/usb/usbdevs.h>
126 #include <sys/condvar.h>
127 #include <sys/kthread.h>
129 #include <dev/usb/if_auereg.h>
132 #define DPRINTF(x) if (auedebug) logprintf x
133 #define DPRINTFN(n,x) if (auedebug >= (n)) logprintf x
137 #define DPRINTFN(n,x)
141 * Various supported device vendors/products.
144 struct usb_devno aue_dev
;
146 #define LSYS 0x0001 /* use Linksys reset */
147 #define PNA 0x0002 /* has Home PNA */
148 #define PII 0x0004 /* Pegasus II chip */
151 Static
const struct aue_type aue_devs
[] = {
152 {{ USB_VENDOR_3COM
, USB_PRODUCT_3COM_3C460B
}, PII
},
153 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX1
}, PNA
|PII
},
154 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX2
}, PII
},
155 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_UFE1000
}, LSYS
},
156 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX4
}, PNA
},
157 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX5
}, PNA
},
158 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX6
}, PII
},
159 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX7
}, PII
},
160 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX8
}, PII
},
161 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX9
}, PNA
},
162 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_XX10
}, 0 },
163 {{ USB_VENDOR_ABOCOM
, USB_PRODUCT_ABOCOM_DSB650TX_PNA
}, 0 },
164 {{ USB_VENDOR_ACCTON
, USB_PRODUCT_ACCTON_USB320_EC
}, 0 },
165 {{ USB_VENDOR_ACCTON
, USB_PRODUCT_ACCTON_SS1001
}, PII
},
166 {{ USB_VENDOR_ADMTEK
, USB_PRODUCT_ADMTEK_PEGASUS
}, PNA
},
167 {{ USB_VENDOR_ADMTEK
, USB_PRODUCT_ADMTEK_PEGASUSII
}, PII
},
168 {{ USB_VENDOR_ADMTEK
, USB_PRODUCT_ADMTEK_PEGASUSII_2
}, PII
},
169 {{ USB_VENDOR_ADMTEK
, USB_PRODUCT_ADMTEK_PEGASUSII_3
}, PII
},
170 {{ USB_VENDOR_AEI
, USB_PRODUCT_AEI_USBTOLAN
}, PII
},
171 {{ USB_VENDOR_BELKIN
, USB_PRODUCT_BELKIN_USB2LAN
}, PII
},
172 {{ USB_VENDOR_BILLIONTON
, USB_PRODUCT_BILLIONTON_USB100
}, 0 },
173 {{ USB_VENDOR_BILLIONTON
, USB_PRODUCT_BILLIONTON_USBLP100
}, PNA
},
174 {{ USB_VENDOR_BILLIONTON
, USB_PRODUCT_BILLIONTON_USBEL100
}, 0 },
175 {{ USB_VENDOR_BILLIONTON
, USB_PRODUCT_BILLIONTON_USBE100
}, PII
},
176 {{ USB_VENDOR_COMPAQ
, USB_PRODUCT_COMPAQ_HNE200
}, PII
},
177 {{ USB_VENDOR_COREGA
, USB_PRODUCT_COREGA_FETHER_USB_TX
}, 0 },
178 {{ USB_VENDOR_COREGA
, USB_PRODUCT_COREGA_FETHER_USB_TXS
},PII
},
179 {{ USB_VENDOR_DLINK
, USB_PRODUCT_DLINK_DSB650TX4
}, LSYS
|PII
},
180 {{ USB_VENDOR_DLINK
, USB_PRODUCT_DLINK_DSB650TX1
}, LSYS
},
181 {{ USB_VENDOR_DLINK
, USB_PRODUCT_DLINK_DSB650TX
}, LSYS
},
182 {{ USB_VENDOR_DLINK
, USB_PRODUCT_DLINK_DSB650TX_PNA
}, PNA
},
183 {{ USB_VENDOR_DLINK
, USB_PRODUCT_DLINK_DSB650TX3
}, LSYS
|PII
},
184 {{ USB_VENDOR_DLINK
, USB_PRODUCT_DLINK_DSB650TX2
}, LSYS
|PII
},
185 {{ USB_VENDOR_DLINK
, USB_PRODUCT_DLINK_DSB650
}, 0 },
186 {{ USB_VENDOR_ELECOM
, USB_PRODUCT_ELECOM_LDUSBTX0
}, 0 },
187 {{ USB_VENDOR_ELECOM
, USB_PRODUCT_ELECOM_LDUSBTX1
}, LSYS
},
188 {{ USB_VENDOR_ELECOM
, USB_PRODUCT_ELECOM_LDUSBTX2
}, 0 },
189 {{ USB_VENDOR_ELECOM
, USB_PRODUCT_ELECOM_LDUSBTX3
}, LSYS
},
190 {{ USB_VENDOR_ELECOM
, USB_PRODUCT_ELECOM_LDUSBLTX
}, PII
},
191 {{ USB_VENDOR_ELSA
, USB_PRODUCT_ELSA_USB2ETHERNET
}, 0 },
192 {{ USB_VENDOR_HAWKING
, USB_PRODUCT_HAWKING_UF100
}, PII
},
193 {{ USB_VENDOR_HP
, USB_PRODUCT_HP_HN210E
}, PII
},
194 {{ USB_VENDOR_IODATA
, USB_PRODUCT_IODATA_USBETTX
}, 0 },
195 {{ USB_VENDOR_IODATA
, USB_PRODUCT_IODATA_USBETTXS
}, PII
},
196 {{ USB_VENDOR_KINGSTON
, USB_PRODUCT_KINGSTON_KNU101TX
}, 0 },
197 {{ USB_VENDOR_LINKSYS
, USB_PRODUCT_LINKSYS_USB10TX1
}, LSYS
|PII
},
198 {{ USB_VENDOR_LINKSYS
, USB_PRODUCT_LINKSYS_USB10T
}, LSYS
},
199 {{ USB_VENDOR_LINKSYS
, USB_PRODUCT_LINKSYS_USB100TX
}, LSYS
},
200 {{ USB_VENDOR_LINKSYS
, USB_PRODUCT_LINKSYS_USB100H1
}, LSYS
|PNA
},
201 {{ USB_VENDOR_LINKSYS
, USB_PRODUCT_LINKSYS_USB10TA
}, LSYS
},
202 {{ USB_VENDOR_LINKSYS
, USB_PRODUCT_LINKSYS_USB10TX2
}, LSYS
|PII
},
203 {{ USB_VENDOR_MELCO
, USB_PRODUCT_MELCO_LUATX1
}, 0 },
204 {{ USB_VENDOR_MELCO
, USB_PRODUCT_MELCO_LUATX5
}, 0 },
205 {{ USB_VENDOR_MELCO
, USB_PRODUCT_MELCO_LUA2TX5
}, PII
},
206 {{ USB_VENDOR_MICROSOFT
, USB_PRODUCT_MICROSOFT_MN110
}, PII
},
207 {{ USB_VENDOR_NETGEAR
, USB_PRODUCT_NETGEAR_FA101
}, PII
},
208 {{ USB_VENDOR_SIEMENS
, USB_PRODUCT_SIEMENS_SPEEDSTREAM
}, PII
},
209 {{ USB_VENDOR_SMARTBRIDGES
, USB_PRODUCT_SMARTBRIDGES_SMARTNIC
},PII
},
210 {{ USB_VENDOR_SMC
, USB_PRODUCT_SMC_2202USB
}, 0 },
211 {{ USB_VENDOR_SMC
, USB_PRODUCT_SMC_2206USB
}, PII
},
212 {{ USB_VENDOR_SOHOWARE
, USB_PRODUCT_SOHOWARE_NUB100
}, 0 },
214 #define aue_lookup(v, p) ((const struct aue_type *)usb_lookup(aue_devs, v, p))
216 int aue_match(device_t
, cfdata_t
, void *);
217 void aue_attach(device_t
, device_t
, void *);
218 int aue_detach(device_t
, int);
219 int aue_activate(device_t
, enum devact
);
220 extern struct cfdriver aue_cd
;
221 CFATTACH_DECL_NEW(aue
, sizeof(struct aue_softc
), aue_match
, aue_attach
,
222 aue_detach
, aue_activate
);
224 Static
void aue_multithread(void *);
226 Static
void aue_reset_pegasus_II(struct aue_softc
*sc
);
227 Static
int aue_tx_list_init(struct aue_softc
*);
228 Static
int aue_rx_list_init(struct aue_softc
*);
229 Static
int aue_newbuf(struct aue_softc
*, struct aue_chain
*, struct mbuf
*);
230 Static
int aue_send(struct aue_softc
*, struct mbuf
*, int);
231 Static
void aue_intr(usbd_xfer_handle
, usbd_private_handle
, usbd_status
);
232 Static
void aue_rxeof(usbd_xfer_handle
, usbd_private_handle
, usbd_status
);
233 Static
void aue_txeof(usbd_xfer_handle
, usbd_private_handle
, usbd_status
);
234 Static
void aue_tick(void *);
235 Static
void aue_tick_task(void *);
236 Static
void aue_start(struct ifnet
*);
237 Static
int aue_ioctl(struct ifnet
*, u_long
, void *);
238 Static
void aue_init(void *);
239 Static
void aue_stop(struct aue_softc
*);
240 Static
void aue_watchdog(struct ifnet
*);
241 Static
int aue_openpipes(struct aue_softc
*);
242 Static
int aue_ifmedia_upd(struct ifnet
*);
244 Static
int aue_eeprom_getword(struct aue_softc
*, int);
245 Static
void aue_read_mac(struct aue_softc
*, u_char
*);
246 Static
int aue_miibus_readreg(device_t
, int, int);
247 Static
void aue_miibus_writereg(device_t
, int, int, int);
248 Static
void aue_miibus_statchg(device_t
);
250 Static
void aue_lock_mii(struct aue_softc
*);
251 Static
void aue_unlock_mii(struct aue_softc
*);
253 Static
void aue_setmulti(struct aue_softc
*);
254 Static u_int32_t
aue_crc(void *);
255 Static
void aue_reset(struct aue_softc
*);
257 Static
int aue_csr_read_1(struct aue_softc
*, int);
258 Static
int aue_csr_write_1(struct aue_softc
*, int, int);
259 Static
int aue_csr_read_2(struct aue_softc
*, int);
260 Static
int aue_csr_write_2(struct aue_softc
*, int, int);
262 #define AUE_SETBIT(sc, reg, x) \
263 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
265 #define AUE_CLRBIT(sc, reg, x) \
266 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
269 aue_csr_read_1(struct aue_softc
*sc
, int reg
)
271 usb_device_request_t req
;
278 req
.bmRequestType
= UT_READ_VENDOR_DEVICE
;
279 req
.bRequest
= AUE_UR_READREG
;
280 USETW(req
.wValue
, 0);
281 USETW(req
.wIndex
, reg
);
282 USETW(req
.wLength
, 1);
284 err
= usbd_do_request(sc
->aue_udev
, &req
, &val
);
287 DPRINTF(("%s: aue_csr_read_1: reg=0x%x err=%s\n",
288 device_xname(sc
->aue_dev
), reg
, usbd_errstr(err
)));
296 aue_csr_read_2(struct aue_softc
*sc
, int reg
)
298 usb_device_request_t req
;
305 req
.bmRequestType
= UT_READ_VENDOR_DEVICE
;
306 req
.bRequest
= AUE_UR_READREG
;
307 USETW(req
.wValue
, 0);
308 USETW(req
.wIndex
, reg
);
309 USETW(req
.wLength
, 2);
311 err
= usbd_do_request(sc
->aue_udev
, &req
, &val
);
314 DPRINTF(("%s: aue_csr_read_2: reg=0x%x err=%s\n",
315 device_xname(sc
->aue_dev
), reg
, usbd_errstr(err
)));
323 aue_csr_write_1(struct aue_softc
*sc
, int reg
, int aval
)
325 usb_device_request_t req
;
333 req
.bmRequestType
= UT_WRITE_VENDOR_DEVICE
;
334 req
.bRequest
= AUE_UR_WRITEREG
;
335 USETW(req
.wValue
, val
);
336 USETW(req
.wIndex
, reg
);
337 USETW(req
.wLength
, 1);
339 err
= usbd_do_request(sc
->aue_udev
, &req
, &val
);
342 DPRINTF(("%s: aue_csr_write_1: reg=0x%x err=%s\n",
343 device_xname(sc
->aue_dev
), reg
, usbd_errstr(err
)));
351 aue_csr_write_2(struct aue_softc
*sc
, int reg
, int aval
)
353 usb_device_request_t req
;
361 req
.bmRequestType
= UT_WRITE_VENDOR_DEVICE
;
362 req
.bRequest
= AUE_UR_WRITEREG
;
363 USETW(req
.wValue
, aval
);
364 USETW(req
.wIndex
, reg
);
365 USETW(req
.wLength
, 2);
367 err
= usbd_do_request(sc
->aue_udev
, &req
, &val
);
370 DPRINTF(("%s: aue_csr_write_2: reg=0x%x err=%s\n",
371 device_xname(sc
->aue_dev
), reg
, usbd_errstr(err
)));
379 * Read a word of data stored in the EEPROM at address 'addr.'
382 aue_eeprom_getword(struct aue_softc
*sc
, int addr
)
386 aue_csr_write_1(sc
, AUE_EE_REG
, addr
);
387 aue_csr_write_1(sc
, AUE_EE_CTL
, AUE_EECTL_READ
);
389 for (i
= 0; i
< AUE_TIMEOUT
; i
++) {
390 if (aue_csr_read_1(sc
, AUE_EE_CTL
) & AUE_EECTL_DONE
)
394 if (i
== AUE_TIMEOUT
) {
395 printf("%s: EEPROM read timed out\n",
396 device_xname(sc
->aue_dev
));
399 return (aue_csr_read_2(sc
, AUE_EE_DATA
));
403 * Read the MAC from the EEPROM. It's at offset 0.
406 aue_read_mac(struct aue_softc
*sc
, u_char
*dest
)
412 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
414 for (i
= 0; i
< 3; i
++) {
415 word
= aue_eeprom_getword(sc
, off
+ i
);
416 dest
[2 * i
] = (u_char
)word
;
417 dest
[2 * i
+ 1] = (u_char
)(word
>> 8);
421 /* Get exclusive access to the MII registers */
423 aue_lock_mii(struct aue_softc
*sc
)
426 mutex_enter(&sc
->aue_mii_lock
);
430 aue_unlock_mii(struct aue_softc
*sc
)
432 mutex_exit(&sc
->aue_mii_lock
);
433 if (--sc
->aue_refcnt
< 0)
434 usb_detach_wakeup((sc
->aue_dev
));
438 aue_miibus_readreg(device_t dev
, int phy
, int reg
)
440 struct aue_softc
*sc
= device_private(dev
);
446 printf("%s: dying\n", device_xname(sc
->aue_dev
));
453 * The Am79C901 HomePNA PHY actually contains
454 * two transceivers: a 1Mbps HomePNA PHY and a
455 * 10Mbps full/half duplex ethernet PHY with
456 * NWAY autoneg. However in the ADMtek adapter,
457 * only the 1Mbps PHY is actually connected to
458 * anything, so we ignore the 10Mbps one. It
459 * happens to be configured for MII address 3,
460 * so we filter that out.
462 if (sc
->aue_vendor
== USB_VENDOR_ADMTEK
&&
463 sc
->aue_product
== USB_PRODUCT_ADMTEK_PEGASUS
) {
470 aue_csr_write_1(sc
, AUE_PHY_ADDR
, phy
);
471 aue_csr_write_1(sc
, AUE_PHY_CTL
, reg
| AUE_PHYCTL_READ
);
473 for (i
= 0; i
< AUE_TIMEOUT
; i
++) {
474 if (aue_csr_read_1(sc
, AUE_PHY_CTL
) & AUE_PHYCTL_DONE
)
478 if (i
== AUE_TIMEOUT
) {
479 printf("%s: MII read timed out\n", device_xname(sc
->aue_dev
));
482 val
= aue_csr_read_2(sc
, AUE_PHY_DATA
);
484 DPRINTFN(11,("%s: %s: phy=%d reg=%d => 0x%04x\n",
485 device_xname(sc
->aue_dev
), __func__
, phy
, reg
, val
));
492 aue_miibus_writereg(device_t dev
, int phy
, int reg
, int data
)
494 struct aue_softc
*sc
= device_private(dev
);
498 if (sc
->aue_vendor
== USB_VENDOR_ADMTEK
&&
499 sc
->aue_product
== USB_PRODUCT_ADMTEK_PEGASUS
) {
505 DPRINTFN(11,("%s: %s: phy=%d reg=%d data=0x%04x\n",
506 device_xname(sc
->aue_dev
), __func__
, phy
, reg
, data
));
509 aue_csr_write_2(sc
, AUE_PHY_DATA
, data
);
510 aue_csr_write_1(sc
, AUE_PHY_ADDR
, phy
);
511 aue_csr_write_1(sc
, AUE_PHY_CTL
, reg
| AUE_PHYCTL_WRITE
);
513 for (i
= 0; i
< AUE_TIMEOUT
; i
++) {
514 if (aue_csr_read_1(sc
, AUE_PHY_CTL
) & AUE_PHYCTL_DONE
)
518 if (i
== AUE_TIMEOUT
) {
519 printf("%s: MII read timed out\n", device_xname(sc
->aue_dev
));
525 aue_miibus_statchg(device_t dev
)
527 struct aue_softc
*sc
= device_private(dev
);
528 struct mii_data
*mii
= GET_MII(sc
);
530 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
533 AUE_CLRBIT(sc
, AUE_CTL0
, AUE_CTL0_RX_ENB
| AUE_CTL0_TX_ENB
);
535 if (IFM_SUBTYPE(mii
->mii_media_active
) == IFM_100_TX
) {
536 AUE_SETBIT(sc
, AUE_CTL1
, AUE_CTL1_SPEEDSEL
);
538 AUE_CLRBIT(sc
, AUE_CTL1
, AUE_CTL1_SPEEDSEL
);
541 if ((mii
->mii_media_active
& IFM_GMASK
) == IFM_FDX
)
542 AUE_SETBIT(sc
, AUE_CTL1
, AUE_CTL1_DUPLEX
);
544 AUE_CLRBIT(sc
, AUE_CTL1
, AUE_CTL1_DUPLEX
);
546 AUE_SETBIT(sc
, AUE_CTL0
, AUE_CTL0_RX_ENB
| AUE_CTL0_TX_ENB
);
550 * Set the LED modes on the LinkSys adapter.
551 * This turns on the 'dual link LED' bin in the auxmode
552 * register of the Broadcom PHY.
554 if (!sc
->aue_dying
&& (sc
->aue_flags
& LSYS
)) {
556 auxmode
= aue_miibus_readreg(dev
, 0, 0x1b);
557 aue_miibus_writereg(dev
, 0, 0x1b, auxmode
| 0x04);
559 DPRINTFN(5,("%s: %s: exit\n", device_xname(sc
->aue_dev
), __func__
));
562 #define AUE_POLY 0xEDB88320
568 u_int32_t idx
, bit
, data
, crc
;
571 /* Compute CRC for the address value. */
572 crc
= 0xFFFFFFFF; /* initial value */
574 for (idx
= 0; idx
< 6; idx
++) {
575 for (data
= *addr
++, bit
= 0; bit
< 8; bit
++, data
>>= 1)
576 crc
= (crc
>> 1) ^ (((crc
^ data
) & 1) ? AUE_POLY
: 0);
579 return (crc
& ((1 << AUE_BITS
) - 1));
583 aue_setmulti(struct aue_softc
*sc
)
586 struct ether_multi
*enm
;
587 struct ether_multistep step
;
590 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
594 if (ifp
->if_flags
& IFF_PROMISC
) {
596 ifp
->if_flags
|= IFF_ALLMULTI
;
597 AUE_SETBIT(sc
, AUE_CTL0
, AUE_CTL0_ALLMULTI
);
601 AUE_CLRBIT(sc
, AUE_CTL0
, AUE_CTL0_ALLMULTI
);
603 /* first, zot all the existing hash bits */
604 for (i
= 0; i
< 8; i
++)
605 aue_csr_write_1(sc
, AUE_MAR0
+ i
, 0);
607 /* now program new ones */
608 ETHER_FIRST_MULTI(step
, &sc
->aue_ec
, enm
);
609 while (enm
!= NULL
) {
610 if (memcmp(enm
->enm_addrlo
,
611 enm
->enm_addrhi
, ETHER_ADDR_LEN
) != 0)
614 h
= aue_crc(enm
->enm_addrlo
);
615 AUE_SETBIT(sc
, AUE_MAR
+ (h
>> 3), 1 << (h
& 0x7));
616 ETHER_NEXT_MULTI(step
, enm
);
619 ifp
->if_flags
&= ~IFF_ALLMULTI
;
623 aue_reset_pegasus_II(struct aue_softc
*sc
)
625 /* Magic constants taken from Linux driver. */
626 aue_csr_write_1(sc
, AUE_REG_1D
, 0);
627 aue_csr_write_1(sc
, AUE_REG_7B
, 2);
629 if ((sc
->aue_flags
& HAS_HOME_PNA
) && mii_mode
)
630 aue_csr_write_1(sc
, AUE_REG_81
, 6);
633 aue_csr_write_1(sc
, AUE_REG_81
, 2);
637 aue_reset(struct aue_softc
*sc
)
641 DPRINTFN(2,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
643 AUE_SETBIT(sc
, AUE_CTL1
, AUE_CTL1_RESETMAC
);
645 for (i
= 0; i
< AUE_TIMEOUT
; i
++) {
646 if (!(aue_csr_read_1(sc
, AUE_CTL1
) & AUE_CTL1_RESETMAC
))
650 if (i
== AUE_TIMEOUT
)
651 printf("%s: reset failed\n", device_xname(sc
->aue_dev
));
654 /* XXX what is mii_mode supposed to be */
655 if (sc
->aue_mii_mode
&& (sc
->aue_flags
& PNA
))
656 aue_csr_write_1(sc
, AUE_GPIO1
, 0x34);
658 aue_csr_write_1(sc
, AUE_GPIO1
, 0x26);
662 * The PHY(s) attached to the Pegasus chip may be held
663 * in reset until we flip on the GPIO outputs. Make sure
664 * to set the GPIO pins high so that the PHY(s) will
667 * Note: We force all of the GPIO pins low first, *then*
668 * enable the ones we want.
670 if (sc
->aue_flags
& LSYS
) {
671 /* Grrr. LinkSys has to be different from everyone else. */
672 aue_csr_write_1(sc
, AUE_GPIO0
,
673 AUE_GPIO_SEL0
| AUE_GPIO_SEL1
);
675 aue_csr_write_1(sc
, AUE_GPIO0
,
676 AUE_GPIO_OUT0
| AUE_GPIO_SEL0
);
678 aue_csr_write_1(sc
, AUE_GPIO0
,
679 AUE_GPIO_OUT0
| AUE_GPIO_SEL0
| AUE_GPIO_SEL1
);
681 if (sc
->aue_flags
& PII
)
682 aue_reset_pegasus_II(sc
);
684 /* Wait a little while for the chip to get its brains in order. */
685 delay(10000); /* XXX */
689 * Probe for a Pegasus chip.
692 aue_match(device_t parent
, cfdata_t match
, void *aux
)
694 struct usb_attach_arg
*uaa
= aux
;
697 * Some manufacturers use the same vendor and product id for
698 * different devices. We need to sanity check the DeviceClass
700 * Currently known guilty products:
701 * 0x050d/0x0121 Belkin Bluetooth and USB2LAN
703 * If this turns out to be more common, we could use a quirk
706 if (uaa
->vendor
== USB_VENDOR_BELKIN
&&
707 uaa
->product
== USB_PRODUCT_BELKIN_USB2LAN
) {
708 usb_device_descriptor_t
*dd
;
710 dd
= usbd_get_device_descriptor(uaa
->device
);
712 dd
->bDeviceClass
!= UDCLASS_IN_INTERFACE
)
713 return (UMATCH_NONE
);
716 return (aue_lookup(uaa
->vendor
, uaa
->product
) != NULL
?
717 UMATCH_VENDOR_PRODUCT
: UMATCH_NONE
);
721 * Attach the interface. Allocate softc structures, do ifmedia
722 * setup and ethernet/BPF attach.
725 aue_attach(device_t parent
, device_t self
, void *aux
)
727 struct aue_softc
*sc
= device_private(self
);
728 struct usb_attach_arg
*uaa
= aux
;
731 u_char eaddr
[ETHER_ADDR_LEN
];
733 struct mii_data
*mii
;
734 usbd_device_handle dev
= uaa
->device
;
735 usbd_interface_handle iface
;
737 usb_interface_descriptor_t
*id
;
738 usb_endpoint_descriptor_t
*ed
;
741 DPRINTFN(5,(" : aue_attach: sc=%p", sc
));
748 devinfop
= usbd_devinfo_alloc(uaa
->device
, 0);
749 aprint_normal_dev(self
, "%s\n", devinfop
);
750 usbd_devinfo_free(devinfop
);
752 err
= usbd_set_config_no(dev
, AUE_CONFIG_NO
, 1);
754 aprint_error_dev(self
, "setting config no failed\n");
758 usb_init_task(&sc
->aue_tick_task
, aue_tick_task
, sc
);
759 usb_init_task(&sc
->aue_stop_task
, (void (*)(void *))aue_stop
, sc
);
760 mutex_init(&sc
->aue_mii_lock
, MUTEX_DEFAULT
, IPL_NONE
);
762 err
= usbd_device2interface_handle(dev
, AUE_IFACE_IDX
, &iface
);
764 aprint_error_dev(self
, "getting interface handle failed\n");
769 mutex_init(&sc
->aue_mcmtx
, MUTEX_DRIVER
, IPL_NET
);
770 cv_init(&sc
->aue_domc
, "auemc");
771 cv_init(&sc
->aue_closemc
, "auemccl");
773 err
= kthread_create(PRI_NONE
, 0, NULL
,
774 aue_multithread
, sc
, &sc
->aue_thread
,
775 "%s-mc", device_xname(sc
->aue_dev
));
778 aprint_error_dev(self
,
779 "creating multicast configuration thread\n");
782 sc
->aue_flags
= aue_lookup(uaa
->vendor
, uaa
->product
)->aue_flags
;
785 sc
->aue_iface
= iface
;
786 sc
->aue_product
= uaa
->product
;
787 sc
->aue_vendor
= uaa
->vendor
;
789 id
= usbd_get_interface_descriptor(iface
);
791 /* Find endpoints. */
792 for (i
= 0; i
< id
->bNumEndpoints
; i
++) {
793 ed
= usbd_interface2endpoint_descriptor(iface
, i
);
795 aprint_error_dev(self
,
796 "couldn't get endpoint descriptor %d\n", i
);
799 if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
&&
800 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
) {
801 sc
->aue_ed
[AUE_ENDPT_RX
] = ed
->bEndpointAddress
;
802 } else if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_OUT
&&
803 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_BULK
) {
804 sc
->aue_ed
[AUE_ENDPT_TX
] = ed
->bEndpointAddress
;
805 } else if (UE_GET_DIR(ed
->bEndpointAddress
) == UE_DIR_IN
&&
806 UE_GET_XFERTYPE(ed
->bmAttributes
) == UE_INTERRUPT
) {
807 sc
->aue_ed
[AUE_ENDPT_INTR
] = ed
->bEndpointAddress
;
811 if (sc
->aue_ed
[AUE_ENDPT_RX
] == 0 || sc
->aue_ed
[AUE_ENDPT_TX
] == 0 ||
812 sc
->aue_ed
[AUE_ENDPT_INTR
] == 0) {
813 aprint_error_dev(self
, "missing endpoint\n");
820 /* Reset the adapter. */
824 * Get station address from the EEPROM.
826 aue_read_mac(sc
, eaddr
);
829 * A Pegasus chip was detected. Inform the world.
832 aprint_normal_dev(self
, "Ethernet address %s\n", ether_sprintf(eaddr
));
834 /* Initialize interface info.*/
836 ifp
->if_mtu
= ETHERMTU
;
837 ifp
->if_flags
= IFF_BROADCAST
| IFF_SIMPLEX
| IFF_MULTICAST
;
838 ifp
->if_ioctl
= aue_ioctl
;
839 ifp
->if_start
= aue_start
;
840 ifp
->if_watchdog
= aue_watchdog
;
841 strncpy(ifp
->if_xname
, device_xname(sc
->aue_dev
), IFNAMSIZ
);
843 IFQ_SET_READY(&ifp
->if_snd
);
845 /* Initialize MII/media info. */
848 mii
->mii_readreg
= aue_miibus_readreg
;
849 mii
->mii_writereg
= aue_miibus_writereg
;
850 mii
->mii_statchg
= aue_miibus_statchg
;
851 mii
->mii_flags
= MIIF_AUTOTSLEEP
;
852 sc
->aue_ec
.ec_mii
= mii
;
853 ifmedia_init(&mii
->mii_media
, 0, aue_ifmedia_upd
, ether_mediastatus
);
854 mii_attach(self
, mii
, 0xffffffff, MII_PHY_ANY
, MII_OFFSET_ANY
, 0);
855 if (LIST_FIRST(&mii
->mii_phys
) == NULL
) {
856 ifmedia_add(&mii
->mii_media
, IFM_ETHER
| IFM_NONE
, 0, NULL
);
857 ifmedia_set(&mii
->mii_media
, IFM_ETHER
| IFM_NONE
);
859 ifmedia_set(&mii
->mii_media
, IFM_ETHER
| IFM_AUTO
);
861 /* Attach the interface. */
863 ether_ifattach(ifp
, eaddr
);
865 rnd_attach_source(&sc
->rnd_source
, device_xname(sc
->aue_dev
),
869 callout_init(&(sc
->aue_stat_ch
), 0);
871 sc
->aue_attached
= 1;
874 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH
, sc
->aue_udev
, sc
->aue_dev
);
880 aue_detach(device_t self
, int flags
)
882 struct aue_softc
*sc
= device_private(self
);
883 struct ifnet
*ifp
= GET_IFP(sc
);
886 DPRINTFN(2,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
888 if (!sc
->aue_attached
) {
889 /* Detached before attached finished, so just bail out. */
893 callout_stop(&(sc
->aue_stat_ch
));
895 * Remove any pending tasks. They cannot be executing because they run
896 * in the same thread as detach.
898 usb_rem_task(sc
->aue_udev
, &sc
->aue_tick_task
);
899 usb_rem_task(sc
->aue_udev
, &sc
->aue_stop_task
);
902 cv_signal(&sc
->aue_domc
);
904 mutex_enter(&sc
->aue_mcmtx
);
905 cv_wait(&sc
->aue_closemc
,&sc
->aue_mcmtx
);
906 mutex_exit(&sc
->aue_mcmtx
);
908 mutex_destroy(&sc
->aue_mcmtx
);
909 cv_destroy(&sc
->aue_domc
);
910 cv_destroy(&sc
->aue_closemc
);
914 if (ifp
->if_flags
& IFF_RUNNING
)
918 rnd_detach_source(&sc
->rnd_source
);
920 mii_detach(&sc
->aue_mii
, MII_PHY_ANY
, MII_OFFSET_ANY
);
921 ifmedia_delete_instance(&sc
->aue_mii
.mii_media
, IFM_INST_ANY
);
927 if (sc
->aue_ep
[AUE_ENDPT_TX
] != NULL
||
928 sc
->aue_ep
[AUE_ENDPT_RX
] != NULL
||
929 sc
->aue_ep
[AUE_ENDPT_INTR
] != NULL
)
930 aprint_error_dev(self
, "detach has active endpoints\n");
933 sc
->aue_attached
= 0;
935 if (--sc
->aue_refcnt
>= 0) {
936 /* Wait for processes to go away. */
937 usb_detach_wait((sc
->aue_dev
));
941 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH
, sc
->aue_udev
, sc
->aue_dev
);
943 mutex_destroy(&sc
->aue_mii_lock
);
945 mutex_destroy(&sc
->wkmtx
);
951 aue_activate(device_t self
, enum devact act
)
953 struct aue_softc
*sc
= device_private(self
);
955 DPRINTFN(2,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
958 case DVACT_DEACTIVATE
:
959 if_deactivate(&sc
->aue_ec
.ec_if
);
968 * Initialize an RX descriptor and attach an MBUF cluster.
971 aue_newbuf(struct aue_softc
*sc
, struct aue_chain
*c
, struct mbuf
*m
)
973 struct mbuf
*m_new
= NULL
;
975 DPRINTFN(10,("%s: %s: enter\n", device_xname(sc
->aue_dev
),__func__
));
978 MGETHDR(m_new
, M_DONTWAIT
, MT_DATA
);
980 aprint_error_dev(sc
->aue_dev
, "no memory for rx list "
981 "-- packet dropped!\n");
985 MCLGET(m_new
, M_DONTWAIT
);
986 if (!(m_new
->m_flags
& M_EXT
)) {
987 aprint_error_dev(sc
->aue_dev
, "no memory for rx "
988 "list -- packet dropped!\n");
992 m_new
->m_len
= m_new
->m_pkthdr
.len
= MCLBYTES
;
995 m_new
->m_len
= m_new
->m_pkthdr
.len
= MCLBYTES
;
996 m_new
->m_data
= m_new
->m_ext
.ext_buf
;
999 m_adj(m_new
, ETHER_ALIGN
);
1000 c
->aue_mbuf
= m_new
;
1006 aue_rx_list_init(struct aue_softc
*sc
)
1008 struct aue_cdata
*cd
;
1009 struct aue_chain
*c
;
1012 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
1014 cd
= &sc
->aue_cdata
;
1015 for (i
= 0; i
< AUE_RX_LIST_CNT
; i
++) {
1016 c
= &cd
->aue_rx_chain
[i
];
1019 if (aue_newbuf(sc
, c
, NULL
) == ENOBUFS
)
1021 if (c
->aue_xfer
== NULL
) {
1022 c
->aue_xfer
= usbd_alloc_xfer(sc
->aue_udev
);
1023 if (c
->aue_xfer
== NULL
)
1025 c
->aue_buf
= usbd_alloc_buffer(c
->aue_xfer
, AUE_BUFSZ
);
1026 if (c
->aue_buf
== NULL
)
1027 return (ENOBUFS
); /* XXX free xfer */
1035 aue_tx_list_init(struct aue_softc
*sc
)
1037 struct aue_cdata
*cd
;
1038 struct aue_chain
*c
;
1041 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
1043 cd
= &sc
->aue_cdata
;
1044 for (i
= 0; i
< AUE_TX_LIST_CNT
; i
++) {
1045 c
= &cd
->aue_tx_chain
[i
];
1049 if (c
->aue_xfer
== NULL
) {
1050 c
->aue_xfer
= usbd_alloc_xfer(sc
->aue_udev
);
1051 if (c
->aue_xfer
== NULL
)
1053 c
->aue_buf
= usbd_alloc_buffer(c
->aue_xfer
, AUE_BUFSZ
);
1054 if (c
->aue_buf
== NULL
)
1063 aue_intr(usbd_xfer_handle xfer
, usbd_private_handle priv
,
1066 struct aue_softc
*sc
= priv
;
1067 struct ifnet
*ifp
= GET_IFP(sc
);
1068 struct aue_intrpkt
*p
= &sc
->aue_cdata
.aue_ibuf
;
1070 DPRINTFN(15,("%s: %s: enter\n", device_xname(sc
->aue_dev
),__func__
));
1075 if (!(ifp
->if_flags
& IFF_RUNNING
))
1078 if (status
!= USBD_NORMAL_COMPLETION
) {
1079 if (status
== USBD_NOT_STARTED
|| status
== USBD_CANCELLED
) {
1082 sc
->aue_intr_errs
++;
1083 if (usbd_ratecheck(&sc
->aue_rx_notice
)) {
1084 aprint_error_dev(sc
->aue_dev
,
1085 "%u usb errors on intr: %s\n", sc
->aue_intr_errs
,
1086 usbd_errstr(status
));
1087 sc
->aue_intr_errs
= 0;
1089 if (status
== USBD_STALLED
)
1090 usbd_clear_endpoint_stall_async(sc
->aue_ep
[AUE_ENDPT_RX
]);
1097 if (p
->aue_txstat0
& (AUE_TXSTAT0_LATECOLL
| AUE_TXSTAT0_EXCESSCOLL
))
1098 ifp
->if_collisions
++;
1102 * A frame has been uploaded: pass the resulting mbuf chain up to
1103 * the higher level protocols.
1106 aue_rxeof(usbd_xfer_handle xfer
, usbd_private_handle priv
, usbd_status status
)
1108 struct aue_chain
*c
= priv
;
1109 struct aue_softc
*sc
= c
->aue_sc
;
1110 struct ifnet
*ifp
= GET_IFP(sc
);
1112 u_int32_t total_len
;
1116 DPRINTFN(10,("%s: %s: enter\n", device_xname(sc
->aue_dev
),__func__
));
1121 if (!(ifp
->if_flags
& IFF_RUNNING
))
1124 if (status
!= USBD_NORMAL_COMPLETION
) {
1125 if (status
== USBD_NOT_STARTED
|| status
== USBD_CANCELLED
)
1128 if (usbd_ratecheck(&sc
->aue_rx_notice
)) {
1129 aprint_error_dev(sc
->aue_dev
,
1130 "%u usb errors on rx: %s\n", sc
->aue_rx_errs
,
1131 usbd_errstr(status
));
1132 sc
->aue_rx_errs
= 0;
1134 if (status
== USBD_STALLED
)
1135 usbd_clear_endpoint_stall_async(sc
->aue_ep
[AUE_ENDPT_RX
]);
1139 usbd_get_xfer_status(xfer
, NULL
, NULL
, &total_len
, NULL
);
1141 memcpy(mtod(c
->aue_mbuf
, char *), c
->aue_buf
, total_len
);
1143 if (total_len
<= 4 + ETHER_CRC_LEN
) {
1148 memcpy(&r
, c
->aue_buf
+ total_len
- 4, sizeof(r
));
1150 /* Turn off all the non-error bits in the rx status word. */
1151 r
.aue_rxstat
&= AUE_RXSTAT_MASK
;
1157 /* No errors; receive the packet. */
1159 total_len
-= ETHER_CRC_LEN
+ 4;
1160 m
->m_pkthdr
.len
= m
->m_len
= total_len
;
1163 m
->m_pkthdr
.rcvif
= ifp
;
1168 if (aue_newbuf(sc
, c
, NULL
) == ENOBUFS
) {
1175 * Handle BPF listeners. Let the BPF user see the packet, but
1176 * don't pass it up to the ether_input() layer unless it's
1177 * a broadcast packet, multicast packet, matches our ethernet
1178 * address or the interface is in promiscuous mode.
1184 DPRINTFN(10,("%s: %s: deliver %d\n", device_xname(sc
->aue_dev
),
1185 __func__
, m
->m_len
));
1186 (*(ifp
)->if_input
)((ifp
), (m
));
1192 /* Setup new transfer. */
1193 usbd_setup_xfer(xfer
, sc
->aue_ep
[AUE_ENDPT_RX
],
1194 c
, c
->aue_buf
, AUE_BUFSZ
,
1195 USBD_SHORT_XFER_OK
| USBD_NO_COPY
,
1196 USBD_NO_TIMEOUT
, aue_rxeof
);
1197 usbd_transfer(xfer
);
1199 DPRINTFN(10,("%s: %s: start rx\n", device_xname(sc
->aue_dev
),
1204 * A frame was downloaded to the chip. It's safe for us to clean up
1209 aue_txeof(usbd_xfer_handle xfer
, usbd_private_handle priv
,
1212 struct aue_chain
*c
= priv
;
1213 struct aue_softc
*sc
= c
->aue_sc
;
1214 struct ifnet
*ifp
= GET_IFP(sc
);
1222 DPRINTFN(10,("%s: %s: enter status=%d\n", device_xname(sc
->aue_dev
),
1226 ifp
->if_flags
&= ~IFF_OACTIVE
;
1228 if (status
!= USBD_NORMAL_COMPLETION
) {
1229 if (status
== USBD_NOT_STARTED
|| status
== USBD_CANCELLED
) {
1234 aprint_error_dev(sc
->aue_dev
, "usb error on tx: %s\n",
1235 usbd_errstr(status
));
1236 if (status
== USBD_STALLED
)
1237 usbd_clear_endpoint_stall_async(sc
->aue_ep
[AUE_ENDPT_TX
]);
1244 m_freem(c
->aue_mbuf
);
1247 if (IFQ_IS_EMPTY(&ifp
->if_snd
) == 0)
1256 struct aue_softc
*sc
= xsc
;
1258 DPRINTFN(15,("%s: %s: enter\n", device_xname(sc
->aue_dev
),__func__
));
1266 /* Perform periodic stuff in process context. */
1267 usb_add_task(sc
->aue_udev
, &sc
->aue_tick_task
, USB_TASKQ_DRIVER
);
1271 aue_tick_task(void *xsc
)
1273 struct aue_softc
*sc
= xsc
;
1275 struct mii_data
*mii
;
1278 DPRINTFN(15,("%s: %s: enter\n", device_xname(sc
->aue_dev
),__func__
));
1291 if (!sc
->aue_link
) {
1292 mii_pollstat(mii
); /* XXX FreeBSD has removed this call */
1293 if (mii
->mii_media_status
& IFM_ACTIVE
&&
1294 IFM_SUBTYPE(mii
->mii_media_active
) != IFM_NONE
) {
1295 DPRINTFN(2,("%s: %s: got link\n",
1296 device_xname(sc
->aue_dev
), __func__
));
1298 if (IFQ_IS_EMPTY(&ifp
->if_snd
) == 0)
1303 callout_reset(&(sc
->aue_stat_ch
), (hz
), (aue_tick
), (sc
));
1309 aue_send(struct aue_softc
*sc
, struct mbuf
*m
, int idx
)
1312 struct aue_chain
*c
;
1315 DPRINTFN(10,("%s: %s: enter\n", device_xname(sc
->aue_dev
),__func__
));
1317 c
= &sc
->aue_cdata
.aue_tx_chain
[idx
];
1320 * Copy the mbuf data into a contiguous buffer, leaving two
1321 * bytes at the beginning to hold the frame length.
1323 m_copydata(m
, 0, m
->m_pkthdr
.len
, c
->aue_buf
+ 2);
1327 * The ADMtek documentation says that the packet length is
1328 * supposed to be specified in the first two bytes of the
1329 * transfer, however it actually seems to ignore this info
1330 * and base the frame size on the bulk transfer length.
1332 c
->aue_buf
[0] = (u_int8_t
)m
->m_pkthdr
.len
;
1333 c
->aue_buf
[1] = (u_int8_t
)(m
->m_pkthdr
.len
>> 8);
1334 total_len
= m
->m_pkthdr
.len
+ 2;
1336 usbd_setup_xfer(c
->aue_xfer
, sc
->aue_ep
[AUE_ENDPT_TX
],
1337 c
, c
->aue_buf
, total_len
, USBD_FORCE_SHORT_XFER
| USBD_NO_COPY
,
1338 AUE_TX_TIMEOUT
, aue_txeof
);
1341 err
= usbd_transfer(c
->aue_xfer
);
1342 if (err
!= USBD_IN_PROGRESS
) {
1343 aprint_error_dev(sc
->aue_dev
, "aue_send error=%s\n",
1345 /* Stop the interface from process context. */
1346 usb_add_task(sc
->aue_udev
, &sc
->aue_stop_task
,
1350 DPRINTFN(5,("%s: %s: send %d bytes\n", device_xname(sc
->aue_dev
),
1351 __func__
, total_len
));
1353 sc
->aue_cdata
.aue_tx_cnt
++;
1359 aue_start(struct ifnet
*ifp
)
1361 struct aue_softc
*sc
= ifp
->if_softc
;
1362 struct mbuf
*m_head
= NULL
;
1364 DPRINTFN(5,("%s: %s: enter, link=%d\n", device_xname(sc
->aue_dev
),
1365 __func__
, sc
->aue_link
));
1373 if (ifp
->if_flags
& IFF_OACTIVE
)
1376 IFQ_POLL(&ifp
->if_snd
, m_head
);
1380 if (aue_send(sc
, m_head
, 0)) {
1381 ifp
->if_flags
|= IFF_OACTIVE
;
1385 IFQ_DEQUEUE(&ifp
->if_snd
, m_head
);
1389 * If there's a BPF listener, bounce a copy of this frame
1393 BPF_MTAP(ifp
, m_head
);
1396 ifp
->if_flags
|= IFF_OACTIVE
;
1399 * Set a timeout in case the chip goes out to lunch.
1407 struct aue_softc
*sc
= xsc
;
1408 struct ifnet
*ifp
= GET_IFP(sc
);
1409 struct mii_data
*mii
= GET_MII(sc
);
1411 const u_char
*eaddr
;
1413 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
1418 if (ifp
->if_flags
& IFF_RUNNING
)
1424 * Cancel pending I/O and free all RX/TX buffers.
1428 eaddr
= CLLADDR(ifp
->if_sadl
);
1429 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++)
1430 aue_csr_write_1(sc
, AUE_PAR0
+ i
, eaddr
[i
]);
1432 /* If we want promiscuous mode, set the allframes bit. */
1433 if (ifp
->if_flags
& IFF_PROMISC
)
1434 AUE_SETBIT(sc
, AUE_CTL2
, AUE_CTL2_RX_PROMISC
);
1436 AUE_CLRBIT(sc
, AUE_CTL2
, AUE_CTL2_RX_PROMISC
);
1439 if (aue_tx_list_init(sc
) == ENOBUFS
) {
1440 aprint_error_dev(sc
->aue_dev
, "tx list init failed\n");
1446 if (aue_rx_list_init(sc
) == ENOBUFS
) {
1447 aprint_error_dev(sc
->aue_dev
, "rx list init failed\n");
1452 /* Load the multicast filter. */
1455 /* Enable RX and TX */
1456 aue_csr_write_1(sc
, AUE_CTL0
, AUE_CTL0_RXSTAT_APPEND
| AUE_CTL0_RX_ENB
);
1457 AUE_SETBIT(sc
, AUE_CTL0
, AUE_CTL0_TX_ENB
);
1458 AUE_SETBIT(sc
, AUE_CTL2
, AUE_CTL2_EP3_CLR
);
1462 if (sc
->aue_ep
[AUE_ENDPT_RX
] == NULL
) {
1463 if (aue_openpipes(sc
)) {
1469 ifp
->if_flags
|= IFF_RUNNING
;
1470 ifp
->if_flags
&= ~IFF_OACTIVE
;
1474 callout_reset(&(sc
->aue_stat_ch
), (hz
), (aue_tick
), (sc
));
1478 aue_openpipes(struct aue_softc
*sc
)
1480 struct aue_chain
*c
;
1484 /* Open RX and TX pipes. */
1485 err
= usbd_open_pipe(sc
->aue_iface
, sc
->aue_ed
[AUE_ENDPT_RX
],
1486 USBD_EXCLUSIVE_USE
, &sc
->aue_ep
[AUE_ENDPT_RX
]);
1488 aprint_error_dev(sc
->aue_dev
, "open rx pipe failed: %s\n",
1492 err
= usbd_open_pipe(sc
->aue_iface
, sc
->aue_ed
[AUE_ENDPT_TX
],
1493 USBD_EXCLUSIVE_USE
, &sc
->aue_ep
[AUE_ENDPT_TX
]);
1495 aprint_error_dev(sc
->aue_dev
, "open tx pipe failed: %s\n",
1499 err
= usbd_open_pipe_intr(sc
->aue_iface
, sc
->aue_ed
[AUE_ENDPT_INTR
],
1500 USBD_EXCLUSIVE_USE
, &sc
->aue_ep
[AUE_ENDPT_INTR
], sc
,
1501 &sc
->aue_cdata
.aue_ibuf
, AUE_INTR_PKTLEN
, aue_intr
,
1504 aprint_error_dev(sc
->aue_dev
, "open intr pipe failed: %s\n",
1509 /* Start up the receive pipe. */
1510 for (i
= 0; i
< AUE_RX_LIST_CNT
; i
++) {
1511 c
= &sc
->aue_cdata
.aue_rx_chain
[i
];
1512 usbd_setup_xfer(c
->aue_xfer
, sc
->aue_ep
[AUE_ENDPT_RX
],
1513 c
, c
->aue_buf
, AUE_BUFSZ
,
1514 USBD_SHORT_XFER_OK
| USBD_NO_COPY
, USBD_NO_TIMEOUT
,
1516 (void)usbd_transfer(c
->aue_xfer
); /* XXX */
1517 DPRINTFN(5,("%s: %s: start read\n", device_xname(sc
->aue_dev
),
1525 * Set media options.
1528 aue_ifmedia_upd(struct ifnet
*ifp
)
1530 struct aue_softc
*sc
= ifp
->if_softc
;
1531 struct mii_data
*mii
= GET_MII(sc
);
1534 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
1541 if ((rc
= mii_mediachg(mii
)) == ENXIO
)
1547 aue_ioctl(struct ifnet
*ifp
, u_long command
, void *data
)
1549 struct aue_softc
*sc
= ifp
->if_softc
;
1550 struct ifaddr
*ifa
= (struct ifaddr
*)data
;
1551 struct ifreq
*ifr
= (struct ifreq
*)data
;
1560 case SIOCINITIFADDR
:
1561 ifp
->if_flags
|= IFF_UP
;
1564 switch (ifa
->ifa_addr
->sa_family
) {
1567 arp_ifinit(ifp
, ifa
);
1574 if (ifr
->ifr_mtu
< ETHERMIN
|| ifr
->ifr_mtu
> ETHERMTU
)
1576 else if ((error
= ifioctl_common(ifp
, command
, data
)) == ENETRESET
)
1581 if ((error
= ifioctl_common(ifp
, command
, data
)) != 0)
1583 if (ifp
->if_flags
& IFF_UP
) {
1584 if (ifp
->if_flags
& IFF_RUNNING
&&
1585 ifp
->if_flags
& IFF_PROMISC
&&
1586 !(sc
->aue_if_flags
& IFF_PROMISC
)) {
1587 AUE_SETBIT(sc
, AUE_CTL2
, AUE_CTL2_RX_PROMISC
);
1588 } else if (ifp
->if_flags
& IFF_RUNNING
&&
1589 !(ifp
->if_flags
& IFF_PROMISC
) &&
1590 sc
->aue_if_flags
& IFF_PROMISC
) {
1591 AUE_CLRBIT(sc
, AUE_CTL2
, AUE_CTL2_RX_PROMISC
);
1592 } else if (!(ifp
->if_flags
& IFF_RUNNING
))
1595 if (ifp
->if_flags
& IFF_RUNNING
)
1598 sc
->aue_if_flags
= ifp
->if_flags
;
1605 if ((error
= ether_ioctl(ifp
, command
, data
)) == ENETRESET
) {
1606 if (ifp
->if_flags
& IFF_RUNNING
) {
1607 cv_signal(&sc
->aue_domc
);
1613 error
= ether_ioctl(ifp
, command
, data
);
1623 aue_watchdog(struct ifnet
*ifp
)
1625 struct aue_softc
*sc
= ifp
->if_softc
;
1626 struct aue_chain
*c
;
1630 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
1633 aprint_error_dev(sc
->aue_dev
, "watchdog timeout\n");
1636 c
= &sc
->aue_cdata
.aue_tx_chain
[0];
1637 usbd_get_xfer_status(c
->aue_xfer
, NULL
, NULL
, NULL
, &stat
);
1638 aue_txeof(c
->aue_xfer
, c
, stat
);
1640 if (IFQ_IS_EMPTY(&ifp
->if_snd
) == 0)
1646 * Stop the adapter and free any mbufs allocated to the
1650 aue_stop(struct aue_softc
*sc
)
1656 DPRINTFN(5,("%s: %s: enter\n", device_xname(sc
->aue_dev
), __func__
));
1661 aue_csr_write_1(sc
, AUE_CTL0
, 0);
1662 aue_csr_write_1(sc
, AUE_CTL1
, 0);
1664 callout_stop(&(sc
->aue_stat_ch
));
1666 /* Stop transfers. */
1667 if (sc
->aue_ep
[AUE_ENDPT_RX
] != NULL
) {
1668 err
= usbd_abort_pipe(sc
->aue_ep
[AUE_ENDPT_RX
]);
1670 printf("%s: abort rx pipe failed: %s\n",
1671 device_xname(sc
->aue_dev
), usbd_errstr(err
));
1673 err
= usbd_close_pipe(sc
->aue_ep
[AUE_ENDPT_RX
]);
1675 printf("%s: close rx pipe failed: %s\n",
1676 device_xname(sc
->aue_dev
), usbd_errstr(err
));
1678 sc
->aue_ep
[AUE_ENDPT_RX
] = NULL
;
1681 if (sc
->aue_ep
[AUE_ENDPT_TX
] != NULL
) {
1682 err
= usbd_abort_pipe(sc
->aue_ep
[AUE_ENDPT_TX
]);
1684 printf("%s: abort tx pipe failed: %s\n",
1685 device_xname(sc
->aue_dev
), usbd_errstr(err
));
1687 err
= usbd_close_pipe(sc
->aue_ep
[AUE_ENDPT_TX
]);
1689 printf("%s: close tx pipe failed: %s\n",
1690 device_xname(sc
->aue_dev
), usbd_errstr(err
));
1692 sc
->aue_ep
[AUE_ENDPT_TX
] = NULL
;
1695 if (sc
->aue_ep
[AUE_ENDPT_INTR
] != NULL
) {
1696 err
= usbd_abort_pipe(sc
->aue_ep
[AUE_ENDPT_INTR
]);
1698 printf("%s: abort intr pipe failed: %s\n",
1699 device_xname(sc
->aue_dev
), usbd_errstr(err
));
1701 err
= usbd_close_pipe(sc
->aue_ep
[AUE_ENDPT_INTR
]);
1703 printf("%s: close intr pipe failed: %s\n",
1704 device_xname(sc
->aue_dev
), usbd_errstr(err
));
1706 sc
->aue_ep
[AUE_ENDPT_INTR
] = NULL
;
1709 /* Free RX resources. */
1710 for (i
= 0; i
< AUE_RX_LIST_CNT
; i
++) {
1711 if (sc
->aue_cdata
.aue_rx_chain
[i
].aue_mbuf
!= NULL
) {
1712 m_freem(sc
->aue_cdata
.aue_rx_chain
[i
].aue_mbuf
);
1713 sc
->aue_cdata
.aue_rx_chain
[i
].aue_mbuf
= NULL
;
1715 if (sc
->aue_cdata
.aue_rx_chain
[i
].aue_xfer
!= NULL
) {
1716 usbd_free_xfer(sc
->aue_cdata
.aue_rx_chain
[i
].aue_xfer
);
1717 sc
->aue_cdata
.aue_rx_chain
[i
].aue_xfer
= NULL
;
1721 /* Free TX resources. */
1722 for (i
= 0; i
< AUE_TX_LIST_CNT
; i
++) {
1723 if (sc
->aue_cdata
.aue_tx_chain
[i
].aue_mbuf
!= NULL
) {
1724 m_freem(sc
->aue_cdata
.aue_tx_chain
[i
].aue_mbuf
);
1725 sc
->aue_cdata
.aue_tx_chain
[i
].aue_mbuf
= NULL
;
1727 if (sc
->aue_cdata
.aue_tx_chain
[i
].aue_xfer
!= NULL
) {
1728 usbd_free_xfer(sc
->aue_cdata
.aue_tx_chain
[i
].aue_xfer
);
1729 sc
->aue_cdata
.aue_tx_chain
[i
].aue_xfer
= NULL
;
1735 ifp
->if_flags
&= ~(IFF_RUNNING
| IFF_OACTIVE
);
1739 aue_multithread(void *arg
)
1741 struct aue_softc
*sc
;
1744 sc
= (struct aue_softc
*)arg
;
1747 mutex_enter(&sc
->aue_mcmtx
);
1748 cv_wait(&sc
->aue_domc
,&sc
->aue_mcmtx
);
1749 mutex_exit(&sc
->aue_mcmtx
);
1751 if (sc
->aue_closing
)
1756 /* XXX called by aue_init, but rc ifconfig hangs without it: */
1761 cv_signal(&sc
->aue_closemc
);