if_aue.c revision 1.107 1 /* $NetBSD: if_aue.c,v 1.107 2008/01/12 22:32:51 cube Exp $ */
2 /*
3 * Copyright (c) 1997, 1998, 1999, 2000
4 * Bill Paul <wpaul (at) ee.columbia.edu>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
20 *
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.
32 *
33 * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $
34 */
35
36 /*
37 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver.
38 * Datasheet is available from http://www.admtek.com.tw.
39 *
40 * Written by Bill Paul <wpaul (at) ee.columbia.edu>
41 * Electrical Engineering Department
42 * Columbia University, New York City
43 */
44
45 /*
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.
53 *
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.
60 *
61 * Registers are accessed using usbd_do_request(). Packet transfers are
62 * done using usbd_transfer() and friends.
63 */
64
65 /*
66 * Ported to NetBSD and somewhat rewritten by Lennart Augustsson.
67 */
68
69 /*
70 * TODO:
71 * better error messages from rxstat
72 * split out if_auevar.h
73 * add thread to avoid register reads from interrupt context
74 * more error checks
75 * investigate short rx problem
76 * proper cleanup on errors
77 */
78
79 #include <sys/cdefs.h>
80 __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.107 2008/01/12 22:32:51 cube Exp $");
81
82 #if defined(__NetBSD__)
83 #include "opt_inet.h"
84 #include "bpfilter.h"
85 #include "rnd.h"
86 #elif defined(__OpenBSD__)
87 #include "bpfilter.h"
88 #endif /* defined(__OpenBSD__) */
89
90 #include <sys/param.h>
91 #include <sys/systm.h>
92 #include <sys/sockio.h>
93 #include <sys/mutex.h>
94 #include <sys/mbuf.h>
95 #include <sys/malloc.h>
96 #include <sys/kernel.h>
97 #include <sys/socket.h>
98 #include <sys/device.h>
99 #if NRND > 0
100 #include <sys/rnd.h>
101 #endif
102
103 #include <net/if.h>
104 #if defined(__NetBSD__)
105 #include <net/if_arp.h>
106 #endif
107 #include <net/if_dl.h>
108 #include <net/if_media.h>
109
110 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
111
112 #if NBPFILTER > 0
113 #include <net/bpf.h>
114 #endif
115
116 #if defined(__NetBSD__)
117 #include <net/if_ether.h>
118 #ifdef INET
119 #include <netinet/in.h>
120 #include <netinet/if_inarp.h>
121 #endif
122 #endif /* defined(__NetBSD__) */
123
124 #if defined(__OpenBSD__)
125 #ifdef INET
126 #include <netinet/in.h>
127 #include <netinet/in_systm.h>
128 #include <netinet/in_var.h>
129 #include <netinet/ip.h>
130 #include <netinet/if_ether.h>
131 #endif
132 #endif /* defined(__OpenBSD__) */
133
134
135 #include <dev/mii/mii.h>
136 #include <dev/mii/miivar.h>
137
138 #include <dev/usb/usb.h>
139 #include <dev/usb/usbdi.h>
140 #include <dev/usb/usbdi_util.h>
141 #include <dev/usb/usbdevs.h>
142
143 #if defined(__NetBSD__)
144 #include <sys/workqueue.h>
145 #endif
146
147 #include <dev/usb/if_auereg.h>
148
149 #ifdef AUE_DEBUG
150 #define DPRINTF(x) if (auedebug) logprintf x
151 #define DPRINTFN(n,x) if (auedebug >= (n)) logprintf x
152 int auedebug = 0;
153 #else
154 #define DPRINTF(x)
155 #define DPRINTFN(n,x)
156 #endif
157
158 /*
159 * Various supported device vendors/products.
160 */
161 struct aue_type {
162 struct usb_devno aue_dev;
163 u_int16_t aue_flags;
164 #define LSYS 0x0001 /* use Linksys reset */
165 #define PNA 0x0002 /* has Home PNA */
166 #define PII 0x0004 /* Pegasus II chip */
167 };
168
169 Static const struct aue_type aue_devs[] = {
170 {{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B}, PII },
171 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1}, PNA|PII },
172 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2}, PII },
173 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000}, LSYS },
174 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4}, PNA },
175 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5}, PNA },
176 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6}, PII },
177 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7}, PII },
178 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8}, PII },
179 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9}, PNA },
180 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10}, 0 },
181 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA}, 0 },
182 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC}, 0 },
183 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001}, PII },
184 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS}, PNA },
185 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII}, PII },
186 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2}, PII },
187 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_3}, PII },
188 {{ USB_VENDOR_AEI, USB_PRODUCT_AEI_USBTOLAN}, PII },
189 {{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN}, PII },
190 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100}, 0 },
191 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100}, PNA },
192 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100}, 0 },
193 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100}, PII },
194 {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_HNE200}, PII },
195 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX}, 0 },
196 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS},PII },
197 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4}, LSYS|PII },
198 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1}, LSYS },
199 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX}, LSYS },
200 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA}, PNA },
201 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3}, LSYS|PII },
202 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2}, LSYS|PII },
203 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650}, 0 },
204 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0}, 0 },
205 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1}, LSYS },
206 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2}, 0 },
207 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3}, LSYS },
208 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX}, PII },
209 {{ USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET}, 0 },
210 {{ USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100}, PII },
211 {{ USB_VENDOR_HP, USB_PRODUCT_HP_HN210E}, PII },
212 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX}, 0 },
213 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS}, PII },
214 {{ USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX}, 0 },
215 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1}, LSYS|PII },
216 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T}, LSYS },
217 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX}, LSYS },
218 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1}, LSYS|PNA },
219 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA}, LSYS },
220 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2}, LSYS|PII },
221 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1}, 0 },
222 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5}, 0 },
223 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5}, PII },
224 {{ USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110}, PII },
225 {{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101}, PII },
226 {{ USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM}, PII },
227 {{ USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC},PII },
228 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB}, 0 },
229 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB}, PII },
230 {{ USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100}, 0 },
231 };
232 #define aue_lookup(v, p) ((const struct aue_type *)usb_lookup(aue_devs, v, p))
233
234 USB_DECLARE_DRIVER(aue);
235
236 #if defined(__NetBSD__)
237 Static void aue_multiwork(struct work *wkp, void *arg);
238 #endif
239
240 Static void aue_reset_pegasus_II(struct aue_softc *sc);
241 Static int aue_tx_list_init(struct aue_softc *);
242 Static int aue_rx_list_init(struct aue_softc *);
243 Static int aue_newbuf(struct aue_softc *, struct aue_chain *, struct mbuf *);
244 Static int aue_send(struct aue_softc *, struct mbuf *, int);
245 Static void aue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
246 Static void aue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
247 Static void aue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
248 Static void aue_tick(void *);
249 Static void aue_tick_task(void *);
250 Static void aue_start(struct ifnet *);
251 Static int aue_ioctl(struct ifnet *, u_long, void *);
252 Static void aue_init(void *);
253 Static void aue_stop(struct aue_softc *);
254 Static void aue_watchdog(struct ifnet *);
255 Static int aue_openpipes(struct aue_softc *);
256 Static int aue_ifmedia_upd(struct ifnet *);
257 Static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *);
258
259 Static int aue_eeprom_getword(struct aue_softc *, int);
260 Static void aue_read_mac(struct aue_softc *, u_char *);
261 Static int aue_miibus_readreg(device_ptr_t, int, int);
262 Static void aue_miibus_writereg(device_ptr_t, int, int, int);
263 Static void aue_miibus_statchg(device_ptr_t);
264
265 Static void aue_lock_mii(struct aue_softc *);
266 Static void aue_unlock_mii(struct aue_softc *);
267
268 Static void aue_setmulti(struct aue_softc *);
269 Static u_int32_t aue_crc(void *);
270 Static void aue_reset(struct aue_softc *);
271
272 Static int aue_csr_read_1(struct aue_softc *, int);
273 Static int aue_csr_write_1(struct aue_softc *, int, int);
274 Static int aue_csr_read_2(struct aue_softc *, int);
275 Static int aue_csr_write_2(struct aue_softc *, int, int);
276
277 #define AUE_SETBIT(sc, reg, x) \
278 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
279
280 #define AUE_CLRBIT(sc, reg, x) \
281 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
282
283 Static int
284 aue_csr_read_1(struct aue_softc *sc, int reg)
285 {
286 usb_device_request_t req;
287 usbd_status err;
288 uByte val = 0;
289
290 if (sc->aue_dying)
291 return (0);
292
293 req.bmRequestType = UT_READ_VENDOR_DEVICE;
294 req.bRequest = AUE_UR_READREG;
295 USETW(req.wValue, 0);
296 USETW(req.wIndex, reg);
297 USETW(req.wLength, 1);
298
299 err = usbd_do_request(sc->aue_udev, &req, &val);
300
301 if (err) {
302 DPRINTF(("%s: aue_csr_read_1: reg=0x%x err=%s\n",
303 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
304 return (0);
305 }
306
307 return (val);
308 }
309
310 Static int
311 aue_csr_read_2(struct aue_softc *sc, int reg)
312 {
313 usb_device_request_t req;
314 usbd_status err;
315 uWord val;
316
317 if (sc->aue_dying)
318 return (0);
319
320 req.bmRequestType = UT_READ_VENDOR_DEVICE;
321 req.bRequest = AUE_UR_READREG;
322 USETW(req.wValue, 0);
323 USETW(req.wIndex, reg);
324 USETW(req.wLength, 2);
325
326 err = usbd_do_request(sc->aue_udev, &req, &val);
327
328 if (err) {
329 DPRINTF(("%s: aue_csr_read_2: reg=0x%x err=%s\n",
330 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
331 return (0);
332 }
333
334 return (UGETW(val));
335 }
336
337 Static int
338 aue_csr_write_1(struct aue_softc *sc, int reg, int aval)
339 {
340 usb_device_request_t req;
341 usbd_status err;
342 uByte val;
343
344 if (sc->aue_dying)
345 return (0);
346
347 val = aval;
348 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
349 req.bRequest = AUE_UR_WRITEREG;
350 USETW(req.wValue, val);
351 USETW(req.wIndex, reg);
352 USETW(req.wLength, 1);
353
354 err = usbd_do_request(sc->aue_udev, &req, &val);
355
356 if (err) {
357 DPRINTF(("%s: aue_csr_write_1: reg=0x%x err=%s\n",
358 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
359 return (-1);
360 }
361
362 return (0);
363 }
364
365 Static int
366 aue_csr_write_2(struct aue_softc *sc, int reg, int aval)
367 {
368 usb_device_request_t req;
369 usbd_status err;
370 uWord val;
371
372 if (sc->aue_dying)
373 return (0);
374
375 USETW(val, aval);
376 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
377 req.bRequest = AUE_UR_WRITEREG;
378 USETW(req.wValue, aval);
379 USETW(req.wIndex, reg);
380 USETW(req.wLength, 2);
381
382 err = usbd_do_request(sc->aue_udev, &req, &val);
383
384 if (err) {
385 DPRINTF(("%s: aue_csr_write_2: reg=0x%x err=%s\n",
386 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
387 return (-1);
388 }
389
390 return (0);
391 }
392
393 /*
394 * Read a word of data stored in the EEPROM at address 'addr.'
395 */
396 Static int
397 aue_eeprom_getword(struct aue_softc *sc, int addr)
398 {
399 int i;
400
401 aue_csr_write_1(sc, AUE_EE_REG, addr);
402 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
403
404 for (i = 0; i < AUE_TIMEOUT; i++) {
405 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
406 break;
407 }
408
409 if (i == AUE_TIMEOUT) {
410 printf("%s: EEPROM read timed out\n",
411 USBDEVNAME(sc->aue_dev));
412 }
413
414 return (aue_csr_read_2(sc, AUE_EE_DATA));
415 }
416
417 /*
418 * Read the MAC from the EEPROM. It's at offset 0.
419 */
420 Static void
421 aue_read_mac(struct aue_softc *sc, u_char *dest)
422 {
423 int i;
424 int off = 0;
425 int word;
426
427 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
428
429 for (i = 0; i < 3; i++) {
430 word = aue_eeprom_getword(sc, off + i);
431 dest[2 * i] = (u_char)word;
432 dest[2 * i + 1] = (u_char)(word >> 8);
433 }
434 }
435
436 /* Get exclusive access to the MII registers */
437 Static void
438 aue_lock_mii(struct aue_softc *sc)
439 {
440 sc->aue_refcnt++;
441 mutex_enter(&sc->aue_mii_lock);
442 }
443
444 Static void
445 aue_unlock_mii(struct aue_softc *sc)
446 {
447 mutex_exit(&sc->aue_mii_lock);
448 if (--sc->aue_refcnt < 0)
449 usb_detach_wakeup(USBDEV(sc->aue_dev));
450 }
451
452 Static int
453 aue_miibus_readreg(device_ptr_t dev, int phy, int reg)
454 {
455 struct aue_softc *sc = USBGETSOFTC(dev);
456 int i;
457 u_int16_t val;
458
459 if (sc->aue_dying) {
460 #ifdef DIAGNOSTIC
461 printf("%s: dying\n", USBDEVNAME(sc->aue_dev));
462 #endif
463 return 0;
464 }
465
466 #if 0
467 /*
468 * The Am79C901 HomePNA PHY actually contains
469 * two transceivers: a 1Mbps HomePNA PHY and a
470 * 10Mbps full/half duplex ethernet PHY with
471 * NWAY autoneg. However in the ADMtek adapter,
472 * only the 1Mbps PHY is actually connected to
473 * anything, so we ignore the 10Mbps one. It
474 * happens to be configured for MII address 3,
475 * so we filter that out.
476 */
477 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
478 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
479 if (phy == 3)
480 return (0);
481 }
482 #endif
483
484 aue_lock_mii(sc);
485 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
486 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ);
487
488 for (i = 0; i < AUE_TIMEOUT; i++) {
489 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
490 break;
491 }
492
493 if (i == AUE_TIMEOUT) {
494 printf("%s: MII read timed out\n", USBDEVNAME(sc->aue_dev));
495 }
496
497 val = aue_csr_read_2(sc, AUE_PHY_DATA);
498
499 DPRINTFN(11,("%s: %s: phy=%d reg=%d => 0x%04x\n",
500 USBDEVNAME(sc->aue_dev), __func__, phy, reg, val));
501
502 aue_unlock_mii(sc);
503 return (val);
504 }
505
506 Static void
507 aue_miibus_writereg(device_ptr_t dev, int phy, int reg, int data)
508 {
509 struct aue_softc *sc = USBGETSOFTC(dev);
510 int i;
511
512 #if 0
513 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
514 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
515 if (phy == 3)
516 return;
517 }
518 #endif
519
520 DPRINTFN(11,("%s: %s: phy=%d reg=%d data=0x%04x\n",
521 USBDEVNAME(sc->aue_dev), __func__, phy, reg, data));
522
523 aue_lock_mii(sc);
524 aue_csr_write_2(sc, AUE_PHY_DATA, data);
525 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
526 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE);
527
528 for (i = 0; i < AUE_TIMEOUT; i++) {
529 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
530 break;
531 }
532
533 if (i == AUE_TIMEOUT) {
534 printf("%s: MII read timed out\n",
535 USBDEVNAME(sc->aue_dev));
536 }
537 aue_unlock_mii(sc);
538 }
539
540 Static void
541 aue_miibus_statchg(device_ptr_t dev)
542 {
543 struct aue_softc *sc = USBGETSOFTC(dev);
544 struct mii_data *mii = GET_MII(sc);
545
546 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
547
548 aue_lock_mii(sc);
549 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
550
551 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) {
552 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
553 } else {
554 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
555 }
556
557 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
558 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
559 else
560 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
561
562 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
563 aue_unlock_mii(sc);
564
565 /*
566 * Set the LED modes on the LinkSys adapter.
567 * This turns on the 'dual link LED' bin in the auxmode
568 * register of the Broadcom PHY.
569 */
570 if (!sc->aue_dying && (sc->aue_flags & LSYS)) {
571 u_int16_t auxmode;
572 auxmode = aue_miibus_readreg(dev, 0, 0x1b);
573 aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04);
574 }
575 DPRINTFN(5,("%s: %s: exit\n", USBDEVNAME(sc->aue_dev), __func__));
576 }
577
578 #define AUE_POLY 0xEDB88320
579 #define AUE_BITS 6
580
581 Static u_int32_t
582 aue_crc(void *addrv)
583 {
584 u_int32_t idx, bit, data, crc;
585 char *addr = addrv;
586
587 /* Compute CRC for the address value. */
588 crc = 0xFFFFFFFF; /* initial value */
589
590 for (idx = 0; idx < 6; idx++) {
591 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
592 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
593 }
594
595 return (crc & ((1 << AUE_BITS) - 1));
596 }
597
598 Static void
599 aue_setmulti(struct aue_softc *sc)
600 {
601 struct ifnet *ifp;
602 struct ether_multi *enm;
603 struct ether_multistep step;
604 u_int32_t h = 0, i;
605
606 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
607
608 ifp = GET_IFP(sc);
609
610 if (ifp->if_flags & IFF_PROMISC) {
611 allmulti:
612 ifp->if_flags |= IFF_ALLMULTI;
613 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
614 return;
615 }
616
617 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
618
619 /* first, zot all the existing hash bits */
620 for (i = 0; i < 8; i++)
621 aue_csr_write_1(sc, AUE_MAR0 + i, 0);
622
623 /* now program new ones */
624 #if defined(__NetBSD__)
625 ETHER_FIRST_MULTI(step, &sc->aue_ec, enm);
626 #else
627 ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
628 #endif
629 while (enm != NULL) {
630 if (memcmp(enm->enm_addrlo,
631 enm->enm_addrhi, ETHER_ADDR_LEN) != 0)
632 goto allmulti;
633
634 h = aue_crc(enm->enm_addrlo);
635 AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7));
636 ETHER_NEXT_MULTI(step, enm);
637 }
638
639 ifp->if_flags &= ~IFF_ALLMULTI;
640 }
641
642 Static void
643 aue_reset_pegasus_II(struct aue_softc *sc)
644 {
645 /* Magic constants taken from Linux driver. */
646 aue_csr_write_1(sc, AUE_REG_1D, 0);
647 aue_csr_write_1(sc, AUE_REG_7B, 2);
648 #if 0
649 if ((sc->aue_flags & HAS_HOME_PNA) && mii_mode)
650 aue_csr_write_1(sc, AUE_REG_81, 6);
651 else
652 #endif
653 aue_csr_write_1(sc, AUE_REG_81, 2);
654 }
655
656 Static void
657 aue_reset(struct aue_softc *sc)
658 {
659 int i;
660
661 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
662
663 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC);
664
665 for (i = 0; i < AUE_TIMEOUT; i++) {
666 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC))
667 break;
668 }
669
670 if (i == AUE_TIMEOUT)
671 printf("%s: reset failed\n", USBDEVNAME(sc->aue_dev));
672
673 #if 0
674 /* XXX what is mii_mode supposed to be */
675 if (sc->aue_mii_mode && (sc->aue_flags & PNA))
676 aue_csr_write_1(sc, AUE_GPIO1, 0x34);
677 else
678 aue_csr_write_1(sc, AUE_GPIO1, 0x26);
679 #endif
680
681 /*
682 * The PHY(s) attached to the Pegasus chip may be held
683 * in reset until we flip on the GPIO outputs. Make sure
684 * to set the GPIO pins high so that the PHY(s) will
685 * be enabled.
686 *
687 * Note: We force all of the GPIO pins low first, *then*
688 * enable the ones we want.
689 */
690 if (sc->aue_flags & LSYS) {
691 /* Grrr. LinkSys has to be different from everyone else. */
692 aue_csr_write_1(sc, AUE_GPIO0,
693 AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
694 } else {
695 aue_csr_write_1(sc, AUE_GPIO0,
696 AUE_GPIO_OUT0 | AUE_GPIO_SEL0);
697 }
698 aue_csr_write_1(sc, AUE_GPIO0,
699 AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
700
701 if (sc->aue_flags & PII)
702 aue_reset_pegasus_II(sc);
703
704 /* Wait a little while for the chip to get its brains in order. */
705 delay(10000); /* XXX */
706 }
707
708 /*
709 * Probe for a Pegasus chip.
710 */
711 USB_MATCH(aue)
712 {
713 USB_MATCH_START(aue, uaa);
714
715 /*
716 * Some manufacturers use the same vendor and product id for
717 * different devices. We need to sanity check the DeviceClass
718 * in this case
719 * Currently known guilty products:
720 * 0x050d/0x0121 Belkin Bluetooth and USB2LAN
721 *
722 * If this turns out to be more common, we could use a quirk
723 * table.
724 */
725 if (uaa->vendor == USB_VENDOR_BELKIN &&
726 uaa->product == USB_PRODUCT_BELKIN_USB2LAN) {
727 usb_device_descriptor_t *dd;
728
729 dd = usbd_get_device_descriptor(uaa->device);
730 if (dd != NULL &&
731 dd->bDeviceClass != UDCLASS_IN_INTERFACE)
732 return (UMATCH_NONE);
733 }
734
735 return (aue_lookup(uaa->vendor, uaa->product) != NULL ?
736 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
737 }
738
739 /*
740 * Attach the interface. Allocate softc structures, do ifmedia
741 * setup and ethernet/BPF attach.
742 */
743 USB_ATTACH(aue)
744 {
745 USB_ATTACH_START(aue, sc, uaa);
746 char *devinfop;
747 int s;
748 u_char eaddr[ETHER_ADDR_LEN];
749 struct ifnet *ifp;
750 struct mii_data *mii;
751 usbd_device_handle dev = uaa->device;
752 usbd_interface_handle iface;
753 usbd_status err;
754 usb_interface_descriptor_t *id;
755 usb_endpoint_descriptor_t *ed;
756 int i;
757
758 DPRINTFN(5,(" : aue_attach: sc=%p", sc));
759
760 devinfop = usbd_devinfo_alloc(uaa->device, 0);
761 USB_ATTACH_SETUP;
762 printf("%s: %s\n", USBDEVNAME(sc->aue_dev), devinfop);
763 usbd_devinfo_free(devinfop);
764
765 err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1);
766 if (err) {
767 printf("%s: setting config no failed\n",
768 USBDEVNAME(sc->aue_dev));
769 USB_ATTACH_ERROR_RETURN;
770 }
771
772 usb_init_task(&sc->aue_tick_task, aue_tick_task, sc);
773 usb_init_task(&sc->aue_stop_task, (void (*)(void *))aue_stop, sc);
774 mutex_init(&sc->aue_mii_lock, MUTEX_DEFAULT, IPL_NONE);
775
776 err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &iface);
777 if (err) {
778 printf("%s: getting interface handle failed\n",
779 USBDEVNAME(sc->aue_dev));
780 USB_ATTACH_ERROR_RETURN;
781 }
782 #if defined(__NetBSD__)
783 err = workqueue_create(&sc->wqp, USBDEVNAME(sc->aue_dev),
784 aue_multiwork, sc, 0, IPL_NET, 0);
785
786 if (err) {
787 printf("%s: creating multicast configuration work queue\n",
788 USBDEVNAME(sc->aue_dev));
789 USB_ATTACH_ERROR_RETURN;
790 }
791 sc->wksem = 0;
792 mutex_init(&sc->wkmtx, MUTEX_DRIVER, IPL_NET);
793 cv_init(&sc->wkdone, "auewk");
794 #endif
795 sc->aue_flags = aue_lookup(uaa->vendor, uaa->product)->aue_flags;
796
797 sc->aue_udev = dev;
798 sc->aue_iface = iface;
799 sc->aue_product = uaa->product;
800 sc->aue_vendor = uaa->vendor;
801
802 id = usbd_get_interface_descriptor(iface);
803
804 /* Find endpoints. */
805 for (i = 0; i < id->bNumEndpoints; i++) {
806 ed = usbd_interface2endpoint_descriptor(iface, i);
807 if (ed == NULL) {
808 printf("%s: couldn't get endpoint descriptor %d\n",
809 USBDEVNAME(sc->aue_dev), i);
810 USB_ATTACH_ERROR_RETURN;
811 }
812 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
813 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
814 sc->aue_ed[AUE_ENDPT_RX] = ed->bEndpointAddress;
815 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
816 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
817 sc->aue_ed[AUE_ENDPT_TX] = ed->bEndpointAddress;
818 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
819 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
820 sc->aue_ed[AUE_ENDPT_INTR] = ed->bEndpointAddress;
821 }
822 }
823
824 if (sc->aue_ed[AUE_ENDPT_RX] == 0 || sc->aue_ed[AUE_ENDPT_TX] == 0 ||
825 sc->aue_ed[AUE_ENDPT_INTR] == 0) {
826 printf("%s: missing endpoint\n", USBDEVNAME(sc->aue_dev));
827 USB_ATTACH_ERROR_RETURN;
828 }
829
830
831 s = splnet();
832
833 /* Reset the adapter. */
834 aue_reset(sc);
835
836 /*
837 * Get station address from the EEPROM.
838 */
839 aue_read_mac(sc, eaddr);
840
841 /*
842 * A Pegasus chip was detected. Inform the world.
843 */
844 ifp = GET_IFP(sc);
845 printf("%s: Ethernet address %s\n", USBDEVNAME(sc->aue_dev),
846 ether_sprintf(eaddr));
847
848 /* Initialize interface info.*/
849 ifp->if_softc = sc;
850 ifp->if_mtu = ETHERMTU;
851 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
852 ifp->if_ioctl = aue_ioctl;
853 ifp->if_start = aue_start;
854 ifp->if_watchdog = aue_watchdog;
855 #if defined(__OpenBSD__)
856 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
857 #endif
858 strncpy(ifp->if_xname, USBDEVNAME(sc->aue_dev), IFNAMSIZ);
859
860 IFQ_SET_READY(&ifp->if_snd);
861
862 /* Initialize MII/media info. */
863 mii = &sc->aue_mii;
864 mii->mii_ifp = ifp;
865 mii->mii_readreg = aue_miibus_readreg;
866 mii->mii_writereg = aue_miibus_writereg;
867 mii->mii_statchg = aue_miibus_statchg;
868 mii->mii_flags = MIIF_AUTOTSLEEP;
869 ifmedia_init(&mii->mii_media, 0, aue_ifmedia_upd, aue_ifmedia_sts);
870 mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0);
871 if (LIST_FIRST(&mii->mii_phys) == NULL) {
872 ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
873 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
874 } else
875 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
876
877 /* Attach the interface. */
878 if_attach(ifp);
879 Ether_ifattach(ifp, eaddr);
880 #if NRND > 0
881 rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->aue_dev),
882 RND_TYPE_NET, 0);
883 #endif
884
885 usb_callout_init(sc->aue_stat_ch);
886
887 sc->aue_attached = 1;
888 splx(s);
889
890 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->aue_udev,
891 USBDEV(sc->aue_dev));
892
893 USB_ATTACH_SUCCESS_RETURN;
894 }
895
896 USB_DETACH(aue)
897 {
898 USB_DETACH_START(aue, sc);
899 struct ifnet *ifp = GET_IFP(sc);
900 int s;
901
902 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
903
904 if (!sc->aue_attached) {
905 /* Detached before attached finished, so just bail out. */
906 return (0);
907 }
908
909 mutex_enter(&sc->wkmtx);
910 while (sc->wksem != 0)
911 cv_wait(&sc->wkdone, &sc->wkmtx);
912 sc->wksem = 1;
913 mutex_exit(&sc->wkmtx);
914
915 /* It is now safe to terminate the worker */
916 workqueue_destroy(sc->wqp);
917
918 usb_uncallout(sc->aue_stat_ch, aue_tick, sc);
919 /*
920 * Remove any pending tasks. They cannot be executing because they run
921 * in the same thread as detach.
922 */
923 usb_rem_task(sc->aue_udev, &sc->aue_tick_task);
924 usb_rem_task(sc->aue_udev, &sc->aue_stop_task);
925
926 s = splusb();
927
928 if (ifp->if_flags & IFF_RUNNING)
929 aue_stop(sc);
930
931 #if defined(__NetBSD__)
932 #if NRND > 0
933 rnd_detach_source(&sc->rnd_source);
934 #endif
935 mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY);
936 ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY);
937 ether_ifdetach(ifp);
938 #endif /* __NetBSD__ */
939
940 if_detach(ifp);
941
942 #ifdef DIAGNOSTIC
943 if (sc->aue_ep[AUE_ENDPT_TX] != NULL ||
944 sc->aue_ep[AUE_ENDPT_RX] != NULL ||
945 sc->aue_ep[AUE_ENDPT_INTR] != NULL)
946 printf("%s: detach has active endpoints\n",
947 USBDEVNAME(sc->aue_dev));
948 #endif
949
950 sc->aue_attached = 0;
951
952 if (--sc->aue_refcnt >= 0) {
953 /* Wait for processes to go away. */
954 usb_detach_wait(USBDEV(sc->aue_dev));
955 }
956 splx(s);
957
958 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->aue_udev,
959 USBDEV(sc->aue_dev));
960
961 mutex_destroy(&sc->aue_mii_lock);
962 mutex_destroy(&sc->wkmtx);
963
964 return (0);
965 }
966
967 int
968 aue_activate(device_ptr_t self, enum devact act)
969 {
970 struct aue_softc *sc = (struct aue_softc *)self;
971
972 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
973
974 switch (act) {
975 case DVACT_ACTIVATE:
976 return (EOPNOTSUPP);
977 break;
978
979 case DVACT_DEACTIVATE:
980 if_deactivate(&sc->aue_ec.ec_if);
981 sc->aue_dying = 1;
982 break;
983 }
984 return (0);
985 }
986
987 /*
988 * Initialize an RX descriptor and attach an MBUF cluster.
989 */
990 Static int
991 aue_newbuf(struct aue_softc *sc, struct aue_chain *c, struct mbuf *m)
992 {
993 struct mbuf *m_new = NULL;
994
995 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
996
997 if (m == NULL) {
998 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
999 if (m_new == NULL) {
1000 printf("%s: no memory for rx list "
1001 "-- packet dropped!\n", USBDEVNAME(sc->aue_dev));
1002 return (ENOBUFS);
1003 }
1004
1005 MCLGET(m_new, M_DONTWAIT);
1006 if (!(m_new->m_flags & M_EXT)) {
1007 printf("%s: no memory for rx list "
1008 "-- packet dropped!\n", USBDEVNAME(sc->aue_dev));
1009 m_freem(m_new);
1010 return (ENOBUFS);
1011 }
1012 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
1013 } else {
1014 m_new = m;
1015 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
1016 m_new->m_data = m_new->m_ext.ext_buf;
1017 }
1018
1019 m_adj(m_new, ETHER_ALIGN);
1020 c->aue_mbuf = m_new;
1021
1022 return (0);
1023 }
1024
1025 Static int
1026 aue_rx_list_init(struct aue_softc *sc)
1027 {
1028 struct aue_cdata *cd;
1029 struct aue_chain *c;
1030 int i;
1031
1032 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1033
1034 cd = &sc->aue_cdata;
1035 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1036 c = &cd->aue_rx_chain[i];
1037 c->aue_sc = sc;
1038 c->aue_idx = i;
1039 if (aue_newbuf(sc, c, NULL) == ENOBUFS)
1040 return (ENOBUFS);
1041 if (c->aue_xfer == NULL) {
1042 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
1043 if (c->aue_xfer == NULL)
1044 return (ENOBUFS);
1045 c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ);
1046 if (c->aue_buf == NULL)
1047 return (ENOBUFS); /* XXX free xfer */
1048 }
1049 }
1050
1051 return (0);
1052 }
1053
1054 Static int
1055 aue_tx_list_init(struct aue_softc *sc)
1056 {
1057 struct aue_cdata *cd;
1058 struct aue_chain *c;
1059 int i;
1060
1061 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1062
1063 cd = &sc->aue_cdata;
1064 for (i = 0; i < AUE_TX_LIST_CNT; i++) {
1065 c = &cd->aue_tx_chain[i];
1066 c->aue_sc = sc;
1067 c->aue_idx = i;
1068 c->aue_mbuf = NULL;
1069 if (c->aue_xfer == NULL) {
1070 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
1071 if (c->aue_xfer == NULL)
1072 return (ENOBUFS);
1073 c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ);
1074 if (c->aue_buf == NULL)
1075 return (ENOBUFS);
1076 }
1077 }
1078
1079 return (0);
1080 }
1081
1082 Static void
1083 aue_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
1084 usbd_status status)
1085 {
1086 struct aue_softc *sc = priv;
1087 struct ifnet *ifp = GET_IFP(sc);
1088 struct aue_intrpkt *p = &sc->aue_cdata.aue_ibuf;
1089
1090 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1091
1092 if (sc->aue_dying)
1093 return;
1094
1095 if (!(ifp->if_flags & IFF_RUNNING))
1096 return;
1097
1098 if (status != USBD_NORMAL_COMPLETION) {
1099 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
1100 return;
1101 }
1102 sc->aue_intr_errs++;
1103 if (usbd_ratecheck(&sc->aue_rx_notice)) {
1104 printf("%s: %u usb errors on intr: %s\n",
1105 USBDEVNAME(sc->aue_dev), sc->aue_intr_errs,
1106 usbd_errstr(status));
1107 sc->aue_intr_errs = 0;
1108 }
1109 if (status == USBD_STALLED)
1110 usbd_clear_endpoint_stall_async(sc->aue_ep[AUE_ENDPT_RX]);
1111 return;
1112 }
1113
1114 if (p->aue_txstat0)
1115 ifp->if_oerrors++;
1116
1117 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL))
1118 ifp->if_collisions++;
1119 }
1120
1121 /*
1122 * A frame has been uploaded: pass the resulting mbuf chain up to
1123 * the higher level protocols.
1124 */
1125 Static void
1126 aue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
1127 {
1128 struct aue_chain *c = priv;
1129 struct aue_softc *sc = c->aue_sc;
1130 struct ifnet *ifp = GET_IFP(sc);
1131 struct mbuf *m;
1132 u_int32_t total_len;
1133 struct aue_rxpkt r;
1134 int s;
1135
1136 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1137
1138 if (sc->aue_dying)
1139 return;
1140
1141 if (!(ifp->if_flags & IFF_RUNNING))
1142 return;
1143
1144 if (status != USBD_NORMAL_COMPLETION) {
1145 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
1146 return;
1147 sc->aue_rx_errs++;
1148 if (usbd_ratecheck(&sc->aue_rx_notice)) {
1149 printf("%s: %u usb errors on rx: %s\n",
1150 USBDEVNAME(sc->aue_dev), sc->aue_rx_errs,
1151 usbd_errstr(status));
1152 sc->aue_rx_errs = 0;
1153 }
1154 if (status == USBD_STALLED)
1155 usbd_clear_endpoint_stall_async(sc->aue_ep[AUE_ENDPT_RX]);
1156 goto done;
1157 }
1158
1159 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
1160
1161 memcpy(mtod(c->aue_mbuf, char *), c->aue_buf, total_len);
1162
1163 if (total_len <= 4 + ETHER_CRC_LEN) {
1164 ifp->if_ierrors++;
1165 goto done;
1166 }
1167
1168 memcpy(&r, c->aue_buf + total_len - 4, sizeof(r));
1169
1170 /* Turn off all the non-error bits in the rx status word. */
1171 r.aue_rxstat &= AUE_RXSTAT_MASK;
1172 if (r.aue_rxstat) {
1173 ifp->if_ierrors++;
1174 goto done;
1175 }
1176
1177 /* No errors; receive the packet. */
1178 m = c->aue_mbuf;
1179 total_len -= ETHER_CRC_LEN + 4;
1180 m->m_pkthdr.len = m->m_len = total_len;
1181 ifp->if_ipackets++;
1182
1183 m->m_pkthdr.rcvif = ifp;
1184
1185 s = splnet();
1186
1187 /* XXX ugly */
1188 if (aue_newbuf(sc, c, NULL) == ENOBUFS) {
1189 ifp->if_ierrors++;
1190 goto done1;
1191 }
1192
1193 #if NBPFILTER > 0
1194 /*
1195 * Handle BPF listeners. Let the BPF user see the packet, but
1196 * don't pass it up to the ether_input() layer unless it's
1197 * a broadcast packet, multicast packet, matches our ethernet
1198 * address or the interface is in promiscuous mode.
1199 */
1200 if (ifp->if_bpf)
1201 BPF_MTAP(ifp, m);
1202 #endif
1203
1204 DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->aue_dev),
1205 __func__, m->m_len));
1206 IF_INPUT(ifp, m);
1207 done1:
1208 splx(s);
1209
1210 done:
1211
1212 /* Setup new transfer. */
1213 usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX],
1214 c, c->aue_buf, AUE_BUFSZ,
1215 USBD_SHORT_XFER_OK | USBD_NO_COPY,
1216 USBD_NO_TIMEOUT, aue_rxeof);
1217 usbd_transfer(xfer);
1218
1219 DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->aue_dev),
1220 __func__));
1221 }
1222
1223 /*
1224 * A frame was downloaded to the chip. It's safe for us to clean up
1225 * the list buffers.
1226 */
1227
1228 Static void
1229 aue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv,
1230 usbd_status status)
1231 {
1232 struct aue_chain *c = priv;
1233 struct aue_softc *sc = c->aue_sc;
1234 struct ifnet *ifp = GET_IFP(sc);
1235 int s;
1236
1237 if (sc->aue_dying)
1238 return;
1239
1240 s = splnet();
1241
1242 DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->aue_dev),
1243 __func__, status));
1244
1245 ifp->if_timer = 0;
1246 ifp->if_flags &= ~IFF_OACTIVE;
1247
1248 if (status != USBD_NORMAL_COMPLETION) {
1249 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
1250 splx(s);
1251 return;
1252 }
1253 ifp->if_oerrors++;
1254 printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->aue_dev),
1255 usbd_errstr(status));
1256 if (status == USBD_STALLED)
1257 usbd_clear_endpoint_stall_async(sc->aue_ep[AUE_ENDPT_TX]);
1258 splx(s);
1259 return;
1260 }
1261
1262 ifp->if_opackets++;
1263
1264 m_freem(c->aue_mbuf);
1265 c->aue_mbuf = NULL;
1266
1267 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
1268 aue_start(ifp);
1269
1270 splx(s);
1271 }
1272
1273 Static void
1274 aue_tick(void *xsc)
1275 {
1276 struct aue_softc *sc = xsc;
1277
1278 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1279
1280 if (sc == NULL)
1281 return;
1282
1283 if (sc->aue_dying)
1284 return;
1285
1286 /* Perform periodic stuff in process context. */
1287 usb_add_task(sc->aue_udev, &sc->aue_tick_task, USB_TASKQ_DRIVER);
1288 }
1289
1290 Static void
1291 aue_tick_task(void *xsc)
1292 {
1293 struct aue_softc *sc = xsc;
1294 struct ifnet *ifp;
1295 struct mii_data *mii;
1296 int s;
1297
1298 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1299
1300 if (sc->aue_dying)
1301 return;
1302
1303 ifp = GET_IFP(sc);
1304 mii = GET_MII(sc);
1305 if (mii == NULL)
1306 return;
1307
1308 s = splnet();
1309
1310 mii_tick(mii);
1311 if (!sc->aue_link) {
1312 mii_pollstat(mii); /* XXX FreeBSD has removed this call */
1313 if (mii->mii_media_status & IFM_ACTIVE &&
1314 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1315 DPRINTFN(2,("%s: %s: got link\n",
1316 USBDEVNAME(sc->aue_dev),__func__));
1317 sc->aue_link++;
1318 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
1319 aue_start(ifp);
1320 }
1321 }
1322
1323 usb_callout(sc->aue_stat_ch, hz, aue_tick, sc);
1324
1325 splx(s);
1326 }
1327
1328 Static int
1329 aue_send(struct aue_softc *sc, struct mbuf *m, int idx)
1330 {
1331 int total_len;
1332 struct aue_chain *c;
1333 usbd_status err;
1334
1335 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__));
1336
1337 c = &sc->aue_cdata.aue_tx_chain[idx];
1338
1339 /*
1340 * Copy the mbuf data into a contiguous buffer, leaving two
1341 * bytes at the beginning to hold the frame length.
1342 */
1343 m_copydata(m, 0, m->m_pkthdr.len, c->aue_buf + 2);
1344 c->aue_mbuf = m;
1345
1346 /*
1347 * The ADMtek documentation says that the packet length is
1348 * supposed to be specified in the first two bytes of the
1349 * transfer, however it actually seems to ignore this info
1350 * and base the frame size on the bulk transfer length.
1351 */
1352 c->aue_buf[0] = (u_int8_t)m->m_pkthdr.len;
1353 c->aue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
1354 total_len = m->m_pkthdr.len + 2;
1355
1356 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_TX],
1357 c, c->aue_buf, total_len, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
1358 AUE_TX_TIMEOUT, aue_txeof);
1359
1360 /* Transmit */
1361 err = usbd_transfer(c->aue_xfer);
1362 if (err != USBD_IN_PROGRESS) {
1363 printf("%s: aue_send error=%s\n", USBDEVNAME(sc->aue_dev),
1364 usbd_errstr(err));
1365 /* Stop the interface from process context. */
1366 usb_add_task(sc->aue_udev, &sc->aue_stop_task,
1367 USB_TASKQ_DRIVER);
1368 return (EIO);
1369 }
1370 DPRINTFN(5,("%s: %s: send %d bytes\n", USBDEVNAME(sc->aue_dev),
1371 __func__, total_len));
1372
1373 sc->aue_cdata.aue_tx_cnt++;
1374
1375 return (0);
1376 }
1377
1378 Static void
1379 aue_start(struct ifnet *ifp)
1380 {
1381 struct aue_softc *sc = ifp->if_softc;
1382 struct mbuf *m_head = NULL;
1383
1384 DPRINTFN(5,("%s: %s: enter, link=%d\n", USBDEVNAME(sc->aue_dev),
1385 __func__, sc->aue_link));
1386
1387 if (sc->aue_dying)
1388 return;
1389
1390 if (!sc->aue_link)
1391 return;
1392
1393 if (ifp->if_flags & IFF_OACTIVE)
1394 return;
1395
1396 IFQ_POLL(&ifp->if_snd, m_head);
1397 if (m_head == NULL)
1398 return;
1399
1400 if (aue_send(sc, m_head, 0)) {
1401 ifp->if_flags |= IFF_OACTIVE;
1402 return;
1403 }
1404
1405 IFQ_DEQUEUE(&ifp->if_snd, m_head);
1406
1407 #if NBPFILTER > 0
1408 /*
1409 * If there's a BPF listener, bounce a copy of this frame
1410 * to him.
1411 */
1412 if (ifp->if_bpf)
1413 BPF_MTAP(ifp, m_head);
1414 #endif
1415
1416 ifp->if_flags |= IFF_OACTIVE;
1417
1418 /*
1419 * Set a timeout in case the chip goes out to lunch.
1420 */
1421 ifp->if_timer = 5;
1422 }
1423
1424 Static void
1425 aue_init(void *xsc)
1426 {
1427 struct aue_softc *sc = xsc;
1428 struct ifnet *ifp = GET_IFP(sc);
1429 struct mii_data *mii = GET_MII(sc);
1430 int i, s;
1431 const u_char *eaddr;
1432
1433 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1434
1435 if (sc->aue_dying)
1436 return;
1437
1438 if (ifp->if_flags & IFF_RUNNING)
1439 return;
1440
1441 s = splnet();
1442
1443 /*
1444 * Cancel pending I/O and free all RX/TX buffers.
1445 */
1446 aue_reset(sc);
1447
1448 #if defined(__OpenBSD__)
1449 eaddr = sc->arpcom.ac_enaddr;
1450 #elif defined(__NetBSD__)
1451 eaddr = CLLADDR(ifp->if_sadl);
1452 #endif /* defined(__NetBSD__) */
1453 for (i = 0; i < ETHER_ADDR_LEN; i++)
1454 aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]);
1455
1456 /* If we want promiscuous mode, set the allframes bit. */
1457 if (ifp->if_flags & IFF_PROMISC)
1458 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1459 else
1460 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1461
1462 /* Init TX ring. */
1463 if (aue_tx_list_init(sc) == ENOBUFS) {
1464 printf("%s: tx list init failed\n", USBDEVNAME(sc->aue_dev));
1465 splx(s);
1466 return;
1467 }
1468
1469 /* Init RX ring. */
1470 if (aue_rx_list_init(sc) == ENOBUFS) {
1471 printf("%s: rx list init failed\n", USBDEVNAME(sc->aue_dev));
1472 splx(s);
1473 return;
1474 }
1475
1476 /* Load the multicast filter. */
1477 aue_setmulti(sc);
1478
1479 /* Enable RX and TX */
1480 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB);
1481 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
1482 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
1483
1484 mii_mediachg(mii);
1485
1486 if (sc->aue_ep[AUE_ENDPT_RX] == NULL) {
1487 if (aue_openpipes(sc)) {
1488 splx(s);
1489 return;
1490 }
1491 }
1492
1493 ifp->if_flags |= IFF_RUNNING;
1494 ifp->if_flags &= ~IFF_OACTIVE;
1495
1496 splx(s);
1497
1498 usb_callout(sc->aue_stat_ch, hz, aue_tick, sc);
1499 }
1500
1501 Static int
1502 aue_openpipes(struct aue_softc *sc)
1503 {
1504 struct aue_chain *c;
1505 usbd_status err;
1506 int i;
1507
1508 /* Open RX and TX pipes. */
1509 err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_RX],
1510 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_RX]);
1511 if (err) {
1512 printf("%s: open rx pipe failed: %s\n",
1513 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1514 return (EIO);
1515 }
1516 err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX],
1517 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]);
1518 if (err) {
1519 printf("%s: open tx pipe failed: %s\n",
1520 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1521 return (EIO);
1522 }
1523 err = usbd_open_pipe_intr(sc->aue_iface, sc->aue_ed[AUE_ENDPT_INTR],
1524 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_INTR], sc,
1525 &sc->aue_cdata.aue_ibuf, AUE_INTR_PKTLEN, aue_intr,
1526 AUE_INTR_INTERVAL);
1527 if (err) {
1528 printf("%s: open intr pipe failed: %s\n",
1529 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1530 return (EIO);
1531 }
1532
1533 /* Start up the receive pipe. */
1534 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1535 c = &sc->aue_cdata.aue_rx_chain[i];
1536 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX],
1537 c, c->aue_buf, AUE_BUFSZ,
1538 USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT,
1539 aue_rxeof);
1540 (void)usbd_transfer(c->aue_xfer); /* XXX */
1541 DPRINTFN(5,("%s: %s: start read\n", USBDEVNAME(sc->aue_dev),
1542 __func__));
1543
1544 }
1545 return (0);
1546 }
1547
1548 /*
1549 * Set media options.
1550 */
1551 Static int
1552 aue_ifmedia_upd(struct ifnet *ifp)
1553 {
1554 struct aue_softc *sc = ifp->if_softc;
1555 struct mii_data *mii = GET_MII(sc);
1556
1557 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1558
1559 if (sc->aue_dying)
1560 return (0);
1561
1562 sc->aue_link = 0;
1563 if (mii->mii_instance) {
1564 struct mii_softc *miisc;
1565 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
1566 miisc = LIST_NEXT(miisc, mii_list))
1567 mii_phy_reset(miisc);
1568 }
1569 mii_mediachg(mii);
1570
1571 return (0);
1572 }
1573
1574 /*
1575 * Report current media status.
1576 */
1577 Static void
1578 aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
1579 {
1580 struct aue_softc *sc = ifp->if_softc;
1581 struct mii_data *mii = GET_MII(sc);
1582
1583 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1584
1585 mii_pollstat(mii);
1586 ifmr->ifm_active = mii->mii_media_active;
1587 ifmr->ifm_status = mii->mii_media_status;
1588 }
1589
1590 Static int
1591 aue_ioctl(struct ifnet *ifp, u_long command, void *data)
1592 {
1593 struct aue_softc *sc = ifp->if_softc;
1594 struct ifaddr *ifa = (struct ifaddr *)data;
1595 struct ifreq *ifr = (struct ifreq *)data;
1596 struct mii_data *mii;
1597 int s, error = 0;
1598
1599 if (sc->aue_dying)
1600 return (EIO);
1601
1602 s = splnet();
1603
1604 switch(command) {
1605 case SIOCSIFADDR:
1606 ifp->if_flags |= IFF_UP;
1607 aue_init(sc);
1608
1609 switch (ifa->ifa_addr->sa_family) {
1610 #ifdef INET
1611 case AF_INET:
1612 #if defined(__NetBSD__)
1613 arp_ifinit(ifp, ifa);
1614 #else
1615 arp_ifinit(&sc->arpcom, ifa);
1616 #endif
1617 break;
1618 #endif /* INET */
1619 }
1620 break;
1621
1622 case SIOCSIFMTU:
1623 if (ifr->ifr_mtu > ETHERMTU)
1624 error = EINVAL;
1625 else
1626 ifp->if_mtu = ifr->ifr_mtu;
1627 break;
1628
1629 case SIOCSIFFLAGS:
1630 if (ifp->if_flags & IFF_UP) {
1631 if (ifp->if_flags & IFF_RUNNING &&
1632 ifp->if_flags & IFF_PROMISC &&
1633 !(sc->aue_if_flags & IFF_PROMISC)) {
1634 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1635 } else if (ifp->if_flags & IFF_RUNNING &&
1636 !(ifp->if_flags & IFF_PROMISC) &&
1637 sc->aue_if_flags & IFF_PROMISC) {
1638 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1639 } else if (!(ifp->if_flags & IFF_RUNNING))
1640 aue_init(sc);
1641 } else {
1642 if (ifp->if_flags & IFF_RUNNING)
1643 aue_stop(sc);
1644 }
1645 sc->aue_if_flags = ifp->if_flags;
1646 error = 0;
1647 break;
1648 case SIOCADDMULTI:
1649 case SIOCDELMULTI:
1650 if ((error = ether_ioctl(ifp, command, data)) == ENETRESET) {
1651 if (ifp->if_flags & IFF_RUNNING) {
1652 #if defined(__NetBSD__)
1653 mutex_enter(&sc->wkmtx);
1654 if (sc->wksem == 0)
1655 workqueue_enqueue(sc->wqp,&sc->wk, NULL);
1656 mutex_exit(&sc->wkmtx);
1657 #else
1658 aue_init(sc);
1659 aue_setmulti(sc);
1660 #endif
1661 }
1662 error = 0;
1663 }
1664 break;
1665 case SIOCGIFMEDIA:
1666 case SIOCSIFMEDIA:
1667 mii = GET_MII(sc);
1668 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1669 break;
1670 default:
1671 error = EINVAL;
1672 break;
1673 }
1674
1675 splx(s);
1676
1677 return (error);
1678 }
1679
1680 Static void
1681 aue_watchdog(struct ifnet *ifp)
1682 {
1683 struct aue_softc *sc = ifp->if_softc;
1684 struct aue_chain *c;
1685 usbd_status stat;
1686 int s;
1687
1688 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1689
1690 ifp->if_oerrors++;
1691 printf("%s: watchdog timeout\n", USBDEVNAME(sc->aue_dev));
1692
1693 s = splusb();
1694 c = &sc->aue_cdata.aue_tx_chain[0];
1695 usbd_get_xfer_status(c->aue_xfer, NULL, NULL, NULL, &stat);
1696 aue_txeof(c->aue_xfer, c, stat);
1697
1698 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
1699 aue_start(ifp);
1700 splx(s);
1701 }
1702
1703 /*
1704 * Stop the adapter and free any mbufs allocated to the
1705 * RX and TX lists.
1706 */
1707 Static void
1708 aue_stop(struct aue_softc *sc)
1709 {
1710 usbd_status err;
1711 struct ifnet *ifp;
1712 int i;
1713
1714 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__));
1715
1716 ifp = GET_IFP(sc);
1717 ifp->if_timer = 0;
1718
1719 aue_csr_write_1(sc, AUE_CTL0, 0);
1720 aue_csr_write_1(sc, AUE_CTL1, 0);
1721 aue_reset(sc);
1722 usb_uncallout(sc->aue_stat_ch, aue_tick, sc);
1723
1724 /* Stop transfers. */
1725 if (sc->aue_ep[AUE_ENDPT_RX] != NULL) {
1726 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1727 if (err) {
1728 printf("%s: abort rx pipe failed: %s\n",
1729 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1730 }
1731 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1732 if (err) {
1733 printf("%s: close rx pipe failed: %s\n",
1734 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1735 }
1736 sc->aue_ep[AUE_ENDPT_RX] = NULL;
1737 }
1738
1739 if (sc->aue_ep[AUE_ENDPT_TX] != NULL) {
1740 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1741 if (err) {
1742 printf("%s: abort tx pipe failed: %s\n",
1743 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1744 }
1745 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1746 if (err) {
1747 printf("%s: close tx pipe failed: %s\n",
1748 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1749 }
1750 sc->aue_ep[AUE_ENDPT_TX] = NULL;
1751 }
1752
1753 if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) {
1754 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1755 if (err) {
1756 printf("%s: abort intr pipe failed: %s\n",
1757 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1758 }
1759 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1760 if (err) {
1761 printf("%s: close intr pipe failed: %s\n",
1762 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1763 }
1764 sc->aue_ep[AUE_ENDPT_INTR] = NULL;
1765 }
1766
1767 /* Free RX resources. */
1768 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1769 if (sc->aue_cdata.aue_rx_chain[i].aue_mbuf != NULL) {
1770 m_freem(sc->aue_cdata.aue_rx_chain[i].aue_mbuf);
1771 sc->aue_cdata.aue_rx_chain[i].aue_mbuf = NULL;
1772 }
1773 if (sc->aue_cdata.aue_rx_chain[i].aue_xfer != NULL) {
1774 usbd_free_xfer(sc->aue_cdata.aue_rx_chain[i].aue_xfer);
1775 sc->aue_cdata.aue_rx_chain[i].aue_xfer = NULL;
1776 }
1777 }
1778
1779 /* Free TX resources. */
1780 for (i = 0; i < AUE_TX_LIST_CNT; i++) {
1781 if (sc->aue_cdata.aue_tx_chain[i].aue_mbuf != NULL) {
1782 m_freem(sc->aue_cdata.aue_tx_chain[i].aue_mbuf);
1783 sc->aue_cdata.aue_tx_chain[i].aue_mbuf = NULL;
1784 }
1785 if (sc->aue_cdata.aue_tx_chain[i].aue_xfer != NULL) {
1786 usbd_free_xfer(sc->aue_cdata.aue_tx_chain[i].aue_xfer);
1787 sc->aue_cdata.aue_tx_chain[i].aue_xfer = NULL;
1788 }
1789 }
1790
1791 sc->aue_link = 0;
1792
1793 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1794 }
1795
1796 #if defined(__NetBSD__)
1797 Static void
1798 aue_multiwork(struct work *wkp, void *arg) {
1799 struct aue_softc *sc;
1800
1801 sc = (struct aue_softc *)arg;
1802
1803 aue_init(sc);
1804 /* XXX called by aue_init, but rc ifconfig hangs without it: */
1805 aue_setmulti(sc);
1806
1807 mutex_enter(&sc->wkmtx);
1808 sc->wksem = 0;
1809 cv_signal(&sc->wkdone);
1810 mutex_exit(&sc->wkmtx);
1811 }
1812 #endif
1813