if_aue.c revision 1.31 1 /* $NetBSD: if_aue.c,v 1.31 2000/03/16 18:27:21 uch 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 USB to ethernet driver. Datasheet is available
38 * 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 #if defined(__NetBSD__) || defined(__OpenBSD__)
80 #include "opt_inet.h"
81 #include "opt_ns.h"
82 #include "bpfilter.h"
83 #include "rnd.h"
84 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
85
86 #include <sys/param.h>
87 #include <sys/systm.h>
88 #include <sys/sockio.h>
89 #include <sys/mbuf.h>
90 #include <sys/malloc.h>
91 #include <sys/kernel.h>
92 #include <sys/socket.h>
93
94 #if defined(__FreeBSD__)
95
96 #include <net/ethernet.h>
97 #include <machine/clock.h> /* for DELAY */
98 #include <sys/bus.h>
99 /* "controller miibus0" required. See GENERIC if you get errors here. */
100 #include "miibus_if.h"
101
102 #elif defined(__NetBSD__) || defined(__OpenBSD__)
103
104 #include <sys/device.h>
105 #if NRND > 0
106 #include <sys/rnd.h>
107 #endif
108
109 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
110
111 #include <net/if.h>
112 #include <net/if_arp.h>
113 #include <net/if_dl.h>
114 #include <net/if_media.h>
115
116 #if defined(__NetBSD__) || defined(__OpenBSD__)
117 #include <net/if_ether.h>
118 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
119 #else
120 #define BPF_MTAP(ifp, m) bpf_mtap((ifp), (m))
121 #endif
122
123 #if defined(__FreeBSD__) || NBPFILTER > 0
124 #include <net/bpf.h>
125 #endif
126
127 #if defined(__NetBSD__) || defined(__OpenBSD__)
128 #ifdef INET
129 #include <netinet/in.h>
130 #include <netinet/if_inarp.h>
131 #endif
132
133 #ifdef NS
134 #include <netns/ns.h>
135 #include <netns/ns_if.h>
136 #endif
137 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
138
139 #include <dev/mii/mii.h>
140 #include <dev/mii/miivar.h>
141
142 #include <dev/usb/usb.h>
143 #include <dev/usb/usbdi.h>
144 #include <dev/usb/usbdi_util.h>
145 #include <dev/usb/usbdevs.h>
146
147 #ifdef __FreeBSD__
148 #include <dev/usb/usb_ethersubr.h>
149 #endif
150
151 #include <dev/usb/if_auereg.h>
152
153 #ifdef AUE_DEBUG
154 #define DPRINTF(x) if (auedebug) logprintf x
155 #define DPRINTFN(n,x) if (auedebug >= (n)) logprintf x
156 int auedebug = 0;
157 #else
158 #define DPRINTF(x)
159 #define DPRINTFN(n,x)
160 #endif
161
162 /*
163 * Various supported device vendors/products.
164 */
165 static struct aue_type aue_devs[] = {
166 { USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100 },
167 { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX },
168 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX },
169 { USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS },
170 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX },
171 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA },
172 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB },
173 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX },
174 { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX },
175 { 0, 0 }
176 };
177
178 USB_DECLARE_DRIVER(aue);
179
180 static int aue_tx_list_init __P((struct aue_softc *));
181 static int aue_rx_list_init __P((struct aue_softc *));
182 static int aue_newbuf __P((struct aue_softc *, struct aue_chain *,
183 struct mbuf *));
184 static int aue_send __P((struct aue_softc *, struct mbuf *, int));
185 static void aue_intr __P((usbd_xfer_handle,
186 usbd_private_handle, usbd_status));
187 static void aue_rxeof __P((usbd_xfer_handle,
188 usbd_private_handle, usbd_status));
189 static void aue_txeof __P((usbd_xfer_handle,
190 usbd_private_handle, usbd_status));
191 static void aue_tick __P((void *));
192 static void aue_start __P((struct ifnet *));
193 static int aue_ioctl __P((struct ifnet *, u_long, caddr_t));
194 static void aue_init __P((void *));
195 static void aue_stop __P((struct aue_softc *));
196 static void aue_watchdog __P((struct ifnet *));
197 #ifdef __FreeBSD__
198 static void aue_shutdown __P((device_ptr_t));
199 #endif
200 static int aue_openpipes __P((struct aue_softc *));
201 static int aue_ifmedia_upd __P((struct ifnet *));
202 static void aue_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
203
204 static int aue_eeprom_getword __P((struct aue_softc *, int));
205 static void aue_read_mac __P((struct aue_softc *, u_char *));
206 static int aue_miibus_readreg __P((device_ptr_t, int, int));
207 #if defined(__FreeBSD__)
208 static int aue_miibus_writereg __P((device_ptr_t, int, int, int));
209 #elif defined(__NetBSD__) || defined(__OpenBSD__)
210 static void aue_miibus_writereg __P((device_ptr_t, int, int, int));
211 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
212 static void aue_miibus_statchg __P((device_ptr_t));
213
214 static void aue_setmulti __P((struct aue_softc *));
215 static u_int32_t aue_crc __P((caddr_t));
216 static void aue_reset __P((struct aue_softc *));
217
218 static int aue_csr_read_1 __P((struct aue_softc *, int));
219 static int aue_csr_write_1 __P((struct aue_softc *, int, int));
220 static int aue_csr_read_2 __P((struct aue_softc *, int));
221 static int aue_csr_write_2 __P((struct aue_softc *, int, int));
222
223 #if defined(__FreeBSD__)
224 #if !defined(lint)
225 static const char rcsid[] =
226 "$FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $";
227 #endif
228
229 static void aue_rxstart __P((struct ifnet *));
230
231 static struct usb_qdat aue_qdat;
232
233 static device_method_t aue_methods[] = {
234 /* Device interface */
235 DEVMETHOD(device_probe, aue_match),
236 DEVMETHOD(device_attach, aue_attach),
237 DEVMETHOD(device_detach, aue_detach),
238 DEVMETHOD(device_shutdown, aue_shutdown),
239
240 /* bus interface */
241 DEVMETHOD(bus_print_child, bus_generic_print_child),
242 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
243
244 /* MII interface */
245 DEVMETHOD(miibus_readreg, aue_miibus_readreg),
246 DEVMETHOD(miibus_writereg, aue_miibus_writereg),
247 DEVMETHOD(miibus_statchg, aue_miibus_statchg),
248
249 { 0, 0 }
250 };
251
252 static driver_t aue_driver = {
253 "aue",
254 aue_methods,
255 sizeof(struct aue_softc)
256 };
257
258 static devclass_t aue_devclass;
259
260 DRIVER_MODULE(if_aue, uhub, aue_driver, aue_devclass, usbd_driver_load, 0);
261 DRIVER_MODULE(miibus, aue, miibus_driver, miibus_devclass, 0, 0);
262
263 #endif /* __FreeBSD__ */
264
265 #define AUE_DO_REQUEST(dev, req, data) \
266 usbd_do_request_flags(dev, req, data, USBD_NO_TSLEEP, NULL)
267
268 #define AUE_SETBIT(sc, reg, x) \
269 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x))
270
271 #define AUE_CLRBIT(sc, reg, x) \
272 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x))
273
274 static int
275 aue_csr_read_1(sc, reg)
276 struct aue_softc *sc;
277 int reg;
278 {
279 usb_device_request_t req;
280 usbd_status err;
281 uByte val = 0;
282 int s;
283
284 if (sc->aue_dying)
285 return (0);
286
287 req.bmRequestType = UT_READ_VENDOR_DEVICE;
288 req.bRequest = AUE_UR_READREG;
289 USETW(req.wValue, 0);
290 USETW(req.wIndex, reg);
291 USETW(req.wLength, 1);
292
293 s = splusb();
294 err = AUE_DO_REQUEST(sc->aue_udev, &req, &val);
295 splx(s);
296
297 if (err) {
298 DPRINTF(("%s: aue_csr_read_1: reg=0x%x err=%s\n",
299 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
300 return (0);
301 }
302
303 return (val);
304 }
305
306 static int
307 aue_csr_read_2(sc, reg)
308 struct aue_softc *sc;
309 int reg;
310 {
311 usb_device_request_t req;
312 usbd_status err;
313 uWord val;
314 int s;
315
316 if (sc->aue_dying)
317 return (0);
318
319 req.bmRequestType = UT_READ_VENDOR_DEVICE;
320 req.bRequest = AUE_UR_READREG;
321 USETW(req.wValue, 0);
322 USETW(req.wIndex, reg);
323 USETW(req.wLength, 2);
324
325 s = splusb();
326 err = AUE_DO_REQUEST(sc->aue_udev, &req, &val);
327 splx(s);
328
329 if (err) {
330 DPRINTF(("%s: aue_csr_read_2: reg=0x%x err=%s\n",
331 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
332 return (0);
333 }
334
335 return (UGETW(val));
336 }
337
338 static int
339 aue_csr_write_1(sc, reg, aval)
340 struct aue_softc *sc;
341 int reg, aval;
342 {
343 usb_device_request_t req;
344 usbd_status err;
345 int s;
346 uByte val;
347
348 if (sc->aue_dying)
349 return (0);
350
351 val = aval;
352 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
353 req.bRequest = AUE_UR_WRITEREG;
354 USETW(req.wValue, val);
355 USETW(req.wIndex, reg);
356 USETW(req.wLength, 1);
357
358 s = splusb();
359 err = AUE_DO_REQUEST(sc->aue_udev, &req, &val);
360 splx(s);
361
362 if (err) {
363 DPRINTF(("%s: aue_csr_write_1: reg=0x%x err=%s\n",
364 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
365 return (-1);
366 }
367
368 return (0);
369 }
370
371 static int
372 aue_csr_write_2(sc, reg, aval)
373 struct aue_softc *sc;
374 int reg, aval;
375 {
376 usb_device_request_t req;
377 usbd_status err;
378 int s;
379 uWord val;
380
381 if (sc->aue_dying)
382 return (0);
383
384 USETW(val, aval);
385 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
386 req.bRequest = AUE_UR_WRITEREG;
387 USETW(req.wValue, aval);
388 USETW(req.wIndex, reg);
389 USETW(req.wLength, 2);
390
391 s = splusb();
392 err = AUE_DO_REQUEST(sc->aue_udev, &req, &val);
393 splx(s);
394
395 if (err) {
396 DPRINTF(("%s: aue_csr_write_2: reg=0x%x err=%s\n",
397 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err)));
398 return (-1);
399 }
400
401 return (0);
402 }
403
404 /*
405 * Read a word of data stored in the EEPROM at address 'addr.'
406 */
407 static int
408 aue_eeprom_getword(sc, addr)
409 struct aue_softc *sc;
410 int addr;
411 {
412 int i;
413
414 aue_csr_write_1(sc, AUE_EE_REG, addr);
415 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ);
416
417 for (i = 0; i < AUE_TIMEOUT; i++) {
418 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE)
419 break;
420 }
421
422 if (i == AUE_TIMEOUT) {
423 printf("%s: EEPROM read timed out\n",
424 USBDEVNAME(sc->aue_dev));
425 }
426
427 return (aue_csr_read_2(sc, AUE_EE_DATA));
428 }
429
430 /*
431 * Read the MAC from the EEPROM. It's at offset 0.
432 */
433 static void
434 aue_read_mac(sc, dest)
435 struct aue_softc *sc;
436 u_char *dest;
437 {
438 int i;
439 int off = 0;
440 int word;
441
442 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
443
444 for (i = 0; i < 3; i++) {
445 word = aue_eeprom_getword(sc, off + i);
446 dest[2 * i] = (u_char)word;
447 dest[2 * i + 1] = (u_char)(word >> 8);
448 }
449 }
450
451 static int
452 aue_miibus_readreg(dev, phy, reg)
453 device_ptr_t dev;
454 int phy, reg;
455 {
456 struct aue_softc *sc = USBGETSOFTC(dev);
457 int i;
458 u_int16_t val;
459
460 /*
461 * The Am79C901 HomePNA PHY actually contains
462 * two transceivers: a 1Mbps HomePNA PHY and a
463 * 10Mbps full/half duplex ethernet PHY with
464 * NWAY autoneg. However in the ADMtek adapter,
465 * only the 1Mbps PHY is actually connected to
466 * anything, so we ignore the 10Mbps one. It
467 * happens to be configured for MII address 3,
468 * so we filter that out.
469 */
470 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
471 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
472 if (phy != 1)
473 return (0);
474 }
475
476 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
477 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ);
478
479 for (i = 0; i < AUE_TIMEOUT; i++) {
480 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
481 break;
482 }
483
484 if (i == AUE_TIMEOUT) {
485 printf("%s: MII read timed out\n",
486 USBDEVNAME(sc->aue_dev));
487 }
488
489 val = aue_csr_read_2(sc, AUE_PHY_DATA);
490
491 DPRINTFN(11,("%s: %s: phy=%d reg=%d => 0x%04x\n",
492 USBDEVNAME(sc->aue_dev), __FUNCTION__, phy, reg, val));
493
494 return (val);
495 }
496
497 #if defined(__FreeBSD__)
498 static int
499 #elif defined(__NetBSD__) || defined(__OpenBSD__)
500 static void
501 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
502 aue_miibus_writereg(dev, phy, reg, data)
503 device_ptr_t dev;
504 int phy, reg, data;
505 {
506 struct aue_softc *sc = USBGETSOFTC(dev);
507 int i;
508
509 if (sc->aue_vendor == USB_VENDOR_ADMTEK &&
510 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) {
511 if (phy == 3)
512 #if defined(__FreeBSD__)
513 return (0);
514 #elif defined(__NetBSD__) || defined(__OpenBSD__)
515 return;
516 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
517 }
518
519 DPRINTFN(11,("%s: %s: phy=%d reg=%d data=0x%04x\n",
520 USBDEVNAME(sc->aue_dev), __FUNCTION__, phy, reg, data));
521
522 aue_csr_write_2(sc, AUE_PHY_DATA, data);
523 aue_csr_write_1(sc, AUE_PHY_ADDR, phy);
524 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE);
525
526 for (i = 0; i < AUE_TIMEOUT; i++) {
527 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE)
528 break;
529 }
530
531 if (i == AUE_TIMEOUT) {
532 printf("%s: MII read timed out\n",
533 USBDEVNAME(sc->aue_dev));
534 }
535
536 #if defined(__FreeBSD__)
537 return (0);
538 #endif
539 }
540
541 static void
542 aue_miibus_statchg(dev)
543 device_ptr_t dev;
544 {
545 struct aue_softc *sc = USBGETSOFTC(dev);
546 struct mii_data *mii = GET_MII(sc);
547
548 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
549
550 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
551
552 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) {
553 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
554 } else {
555 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL);
556 }
557
558 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX)
559 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
560 else
561 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX);
562
563 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB);
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_vendor == USB_VENDOR_LINKSYS &&
571 sc->aue_product == USB_PRODUCT_LINKSYS_USB100TX) ||
572 (sc->aue_vendor == USB_VENDOR_DLINK &&
573 sc->aue_product == USB_PRODUCT_DLINK_DSB650TX)) {
574 u_int16_t auxmode;
575 auxmode = aue_miibus_readreg(dev, 0, 0x1b);
576 aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04);
577 }
578 }
579
580 #define AUE_POLY 0xEDB88320
581 #define AUE_BITS 6
582
583 static u_int32_t
584 aue_crc(addr)
585 caddr_t addr;
586 {
587 u_int32_t idx, bit, data, crc;
588
589 /* Compute CRC for the address value. */
590 crc = 0xFFFFFFFF; /* initial value */
591
592 for (idx = 0; idx < 6; idx++) {
593 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1)
594 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0);
595 }
596
597 return (crc & ((1 << AUE_BITS) - 1));
598 }
599
600 static void
601 aue_setmulti(sc)
602 struct aue_softc *sc;
603 {
604 struct ifnet *ifp;
605 #if defined(__FreeBSD__)
606 struct ifmultiaddr *ifma;
607 #elif defined(__NetBSD__) || defined(__OpenBSD__)
608 struct ether_multi *enm;
609 struct ether_multistep step;
610 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
611 u_int32_t h = 0, i;
612
613 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
614
615 ifp = GET_IFP(sc);
616
617 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
618 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
619 return;
620 }
621
622 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
623
624 /* first, zot all the existing hash bits */
625 for (i = 0; i < 8; i++)
626 aue_csr_write_1(sc, AUE_MAR0 + i, 0);
627
628 /* now program new ones */
629 #if defined(__FreeBSD__)
630 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
631 ifma = ifma->ifma_link.le_next) {
632 if (ifma->ifma_addr->sa_family != AF_LINK)
633 continue;
634 h = aue_crc(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
635 AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0xF));
636 }
637 #elif defined(__NetBSD__) || defined(__OpenBSD__)
638 ETHER_FIRST_MULTI(step, &sc->aue_ec, enm);
639 while (enm != NULL) {
640 #if 1
641 if (memcmp(enm->enm_addrlo,
642 enm->enm_addrhi, ETHER_ADDR_LEN) != 0) {
643 ifp->if_flags |= IFF_ALLMULTI;
644 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI);
645 return;
646 }
647 #endif
648 h = aue_crc(enm->enm_addrlo);
649 AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0xF));
650 ETHER_NEXT_MULTI(step, enm);
651 }
652 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
653 }
654
655 static void
656 aue_reset(sc)
657 struct aue_softc *sc;
658 {
659 int i;
660
661 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
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 /*
674 * The PHY(s) attached to the Pegasus chip may be held
675 * in reset until we flip on the GPIO outputs. Make sure
676 * to set the GPIO pins high so that the PHY(s) will
677 * be enabled.
678 *
679 * Note: We force all of the GPIO pins low first, *then*
680 * enable the ones we want.
681 */
682 aue_csr_write_1(sc, AUE_GPIO0,
683 AUE_GPIO_OUT0 | AUE_GPIO_SEL0);
684 aue_csr_write_1(sc, AUE_GPIO0,
685 AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
686
687 /* Grrr. LinkSys has to be different from everyone else. */
688 if ((sc->aue_vendor == USB_VENDOR_LINKSYS &&
689 sc->aue_product == USB_PRODUCT_LINKSYS_USB100TX) ||
690 (sc->aue_vendor == USB_VENDOR_DLINK &&
691 sc->aue_product == USB_PRODUCT_DLINK_DSB650TX)) {
692 aue_csr_write_1(sc, AUE_GPIO0,
693 AUE_GPIO_SEL0 | AUE_GPIO_SEL1);
694 aue_csr_write_1(sc, AUE_GPIO0,
695 AUE_GPIO_SEL0 | AUE_GPIO_SEL1 | AUE_GPIO_OUT0);
696 }
697
698 /* Wait a little while for the chip to get its brains in order. */
699 delay(10000); /* XXX */
700 }
701
702 /*
703 * Probe for a Pegasus chip.
704 */
705 USB_MATCH(aue)
706 {
707 USB_MATCH_START(aue, uaa);
708 struct aue_type *t;
709
710 if (uaa->iface != NULL)
711 return (UMATCH_NONE);
712
713 for (t = aue_devs; t->aue_vid != 0; t++)
714 if (uaa->vendor == t->aue_vid && uaa->product == t->aue_did)
715 return (UMATCH_VENDOR_PRODUCT);
716
717 return (UMATCH_NONE);
718 }
719
720 /*
721 * Attach the interface. Allocate softc structures, do ifmedia
722 * setup and ethernet/BPF attach.
723 */
724 USB_ATTACH(aue)
725 {
726 USB_ATTACH_START(aue, sc, uaa);
727 char devinfo[1024];
728 int s;
729 u_char eaddr[ETHER_ADDR_LEN];
730 struct ifnet *ifp;
731 struct mii_data *mii;
732 usbd_device_handle dev = uaa->device;
733 usbd_interface_handle iface;
734 usbd_status err;
735 usb_interface_descriptor_t *id;
736 usb_endpoint_descriptor_t *ed;
737 int i;
738
739 #ifdef __FreeBSD__
740 bzero(sc, sizeof(struct aue_softc));
741 #endif
742
743 DPRINTFN(5,(" : aue_attach: sc=%p", sc));
744
745 usbd_devinfo(dev, 0, devinfo);
746 USB_ATTACH_SETUP;
747 printf("%s: %s\n", USBDEVNAME(sc->aue_dev), devinfo);
748
749 err = usbd_set_config_no(dev, AUE_CONFIG_NO, 0);
750 if (err) {
751 printf("%s: setting config no failed\n",
752 USBDEVNAME(sc->aue_dev));
753 USB_ATTACH_ERROR_RETURN;
754 }
755
756 err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &iface);
757 if (err) {
758 printf("%s: getting interface handle failed\n",
759 USBDEVNAME(sc->aue_dev));
760 USB_ATTACH_ERROR_RETURN;
761 }
762
763 sc->aue_udev = dev;
764 sc->aue_iface = iface;
765 sc->aue_product = uaa->product;
766 sc->aue_vendor = uaa->vendor;
767
768 id = usbd_get_interface_descriptor(iface);
769
770 /* Find endpoints. */
771 for (i = 0; i < id->bNumEndpoints; i++) {
772 ed = usbd_interface2endpoint_descriptor(iface, i);
773 if (ed == NULL) {
774 printf("%s: couldn't get endpoint descriptor %d\n",
775 USBDEVNAME(sc->aue_dev), i);
776 USB_ATTACH_ERROR_RETURN;
777 }
778 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
779 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
780 sc->aue_ed[AUE_ENDPT_RX] = ed->bEndpointAddress;
781 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
782 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
783 sc->aue_ed[AUE_ENDPT_TX] = ed->bEndpointAddress;
784 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
785 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
786 sc->aue_ed[AUE_ENDPT_INTR] = ed->bEndpointAddress;
787 }
788 }
789
790 if (sc->aue_ed[AUE_ENDPT_RX] == 0 || sc->aue_ed[AUE_ENDPT_TX] == 0 ||
791 sc->aue_ed[AUE_ENDPT_INTR] == 0) {
792 printf("%s: missing endpoint\n", USBDEVNAME(sc->aue_dev));
793 USB_ATTACH_ERROR_RETURN;
794 }
795
796
797 s = splimp();
798
799 /* Reset the adapter. */
800 aue_reset(sc);
801
802 /*
803 * Get station address from the EEPROM.
804 */
805 aue_read_mac(sc, eaddr);
806
807 /*
808 * A Pegasus chip was detected. Inform the world.
809 */
810 #if defined(__FreeBSD__)
811 printf("%s: Ethernet address: %6D\n", USBDEVNAME(sc->aue_dev),
812 eaddr, ":");
813
814 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
815
816 ifp = &sc->arpcom.ac_if;
817 ifp->if_softc = sc;
818 ifp->if_unit = sc->aue_unit;
819 ifp->if_name = "aue";
820 ifp->if_mtu = ETHERMTU;
821 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
822 ifp->if_ioctl = aue_ioctl;
823 ifp->if_output = ether_output;
824 ifp->if_start = aue_start;
825 ifp->if_watchdog = aue_watchdog;
826 ifp->if_init = aue_init;
827 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
828
829 /*
830 * Do MII setup.
831 * NOTE: Doing this causes child devices to be attached to us,
832 * which we would normally disconnect at in the detach routine
833 * using device_delete_child(). However the USB code is set up
834 * such that when this driver is removed, all childred devices
835 * are removed as well. In effect, the USB code ends up detaching
836 * all of our children for us, so we don't have to do is ourselves
837 * in aue_detach(). It's important to point this out since if
838 * we *do* try to detach the child devices ourselves, we will
839 * end up getting the children deleted twice, which will crash
840 * the system.
841 */
842 if (mii_phy_probe(self, &sc->aue_miibus,
843 aue_ifmedia_upd, aue_ifmedia_sts)) {
844 printf("%s: MII without any PHY!\n", USBDEVNAME(sc->aue_dev));
845 splx(s);
846 USB_ATTACH_ERROR_RETURN;
847 }
848
849 aue_qdat.ifp = ifp;
850 aue_qdat.if_rxstart = aue_rxstart;
851
852 /*
853 * Call MI attach routines.
854 */
855 if_attach(ifp);
856 ether_ifattach(ifp);
857 callout_handle_init(&sc->aue_stat_ch);
858 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
859
860 usb_register_netisr();
861
862 #elif defined(__NetBSD__) || defined(__OpenBSD__)
863
864 printf("%s: Ethernet address %s\n", USBDEVNAME(sc->aue_dev),
865 ether_sprintf(eaddr));
866
867 /* Initialize interface info.*/
868 ifp = &sc->aue_ec.ec_if;
869 ifp->if_softc = sc;
870 ifp->if_mtu = ETHERMTU;
871 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
872 ifp->if_ioctl = aue_ioctl;
873 ifp->if_start = aue_start;
874 ifp->if_watchdog = aue_watchdog;
875 strncpy(ifp->if_xname, USBDEVNAME(sc->aue_dev), IFNAMSIZ);
876
877 /* Initialize MII/media info. */
878 mii = &sc->aue_mii;
879 mii->mii_ifp = ifp;
880 mii->mii_readreg = aue_miibus_readreg;
881 mii->mii_writereg = aue_miibus_writereg;
882 mii->mii_statchg = aue_miibus_statchg;
883 ifmedia_init(&mii->mii_media, 0, aue_ifmedia_upd, aue_ifmedia_sts);
884 mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0);
885 if (LIST_FIRST(&mii->mii_phys) == NULL) {
886 ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
887 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
888 } else
889 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
890
891 /* Attach the interface. */
892 if_attach(ifp);
893 ether_ifattach(ifp, eaddr);
894
895 #if NBPFILTER > 0
896 bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB,
897 sizeof(struct ether_header));
898 #endif
899 #if NRND > 0
900 rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->aue_dev),
901 RND_TYPE_NET, 0);
902 #endif
903
904 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
905
906 sc->aue_attached = 1;
907 splx(s);
908
909 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->aue_udev,
910 USBDEV(sc->aue_dev));
911
912 USB_ATTACH_SUCCESS_RETURN;
913 }
914
915 USB_DETACH(aue)
916 {
917 USB_DETACH_START(aue, sc);
918 struct ifnet *ifp = GET_IFP(sc);
919 int s;
920
921 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
922
923 s = splusb();
924
925 usb_untimeout(aue_tick, sc, sc->aue_stat_ch);
926
927 if (!sc->aue_attached) {
928 /* Detached before attached finished, so just bail out. */
929 splx(s);
930 return (0);
931 }
932
933 if (ifp->if_flags & IFF_RUNNING)
934 aue_stop(sc);
935
936 #if defined(__NetBSD__)
937 #if NRND > 0
938 rnd_detach_source(&sc->rnd_source);
939 #endif
940 mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY);
941 ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY);
942 #if NBPFILTER > 0
943 bpfdetach(ifp);
944 #endif
945 ether_ifdetach(ifp);
946 #endif /* __NetBSD__ */
947
948 if_detach(ifp);
949
950 #ifdef DIAGNOSTIC
951 if (sc->aue_ep[AUE_ENDPT_TX] != NULL ||
952 sc->aue_ep[AUE_ENDPT_RX] != NULL ||
953 sc->aue_ep[AUE_ENDPT_INTR] != NULL)
954 printf("%s: detach has active endpoints\n",
955 USBDEVNAME(sc->aue_dev));
956 #endif
957
958 sc->aue_attached = 0;
959 splx(s);
960
961 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->aue_udev,
962 USBDEV(sc->aue_dev));
963
964 return (0);
965 }
966
967 #if defined(__NetBSD__) || defined(__OpenBSD__)
968 int
969 aue_activate(self, act)
970 device_ptr_t self;
971 enum devact act;
972 {
973 struct aue_softc *sc = (struct aue_softc *)self;
974
975 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
976
977 switch (act) {
978 case DVACT_ACTIVATE:
979 return (EOPNOTSUPP);
980 break;
981
982 case DVACT_DEACTIVATE:
983 if_deactivate(&sc->aue_ec.ec_if);
984 sc->aue_dying = 1;
985 break;
986 }
987 return (0);
988 }
989 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
990
991 /*
992 * Initialize an RX descriptor and attach an MBUF cluster.
993 */
994 static int
995 aue_newbuf(sc, c, m)
996 struct aue_softc *sc;
997 struct aue_chain *c;
998 struct mbuf *m;
999 {
1000 struct mbuf *m_new = NULL;
1001
1002 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
1003
1004 if (m == NULL) {
1005 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
1006 if (m_new == NULL) {
1007 printf("%s: no memory for rx list "
1008 "-- packet dropped!\n", USBDEVNAME(sc->aue_dev));
1009 return (ENOBUFS);
1010 }
1011
1012 MCLGET(m_new, M_DONTWAIT);
1013 if (!(m_new->m_flags & M_EXT)) {
1014 printf("%s: no memory for rx list "
1015 "-- packet dropped!\n", USBDEVNAME(sc->aue_dev));
1016 m_freem(m_new);
1017 return (ENOBUFS);
1018 }
1019 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
1020 } else {
1021 m_new = m;
1022 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
1023 m_new->m_data = m_new->m_ext.ext_buf;
1024 }
1025
1026 m_adj(m_new, ETHER_ALIGN);
1027 c->aue_mbuf = m_new;
1028
1029 return (0);
1030 }
1031
1032 static int
1033 aue_rx_list_init(sc)
1034 struct aue_softc *sc;
1035 {
1036 struct aue_cdata *cd;
1037 struct aue_chain *c;
1038 int i;
1039
1040 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1041
1042 cd = &sc->aue_cdata;
1043 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1044 c = &cd->aue_rx_chain[i];
1045 c->aue_sc = sc;
1046 c->aue_idx = i;
1047 if (aue_newbuf(sc, c, NULL) == ENOBUFS)
1048 return (ENOBUFS);
1049 if (c->aue_xfer == NULL) {
1050 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
1051 if (c->aue_xfer == NULL)
1052 return (ENOBUFS);
1053 c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ);
1054 if (c->aue_buf == NULL)
1055 return (ENOBUFS); /* XXX free xfer */
1056 }
1057 }
1058
1059 return (0);
1060 }
1061
1062 static int
1063 aue_tx_list_init(sc)
1064 struct aue_softc *sc;
1065 {
1066 struct aue_cdata *cd;
1067 struct aue_chain *c;
1068 int i;
1069
1070 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1071
1072 cd = &sc->aue_cdata;
1073 for (i = 0; i < AUE_TX_LIST_CNT; i++) {
1074 c = &cd->aue_tx_chain[i];
1075 c->aue_sc = sc;
1076 c->aue_idx = i;
1077 c->aue_mbuf = NULL;
1078 if (c->aue_xfer == NULL) {
1079 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev);
1080 if (c->aue_xfer == NULL)
1081 return (ENOBUFS);
1082 c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ);
1083 if (c->aue_buf == NULL)
1084 return (ENOBUFS);
1085 }
1086 }
1087
1088 return (0);
1089 }
1090
1091 static void
1092 aue_intr(xfer, priv, status)
1093 usbd_xfer_handle xfer;
1094 usbd_private_handle priv;
1095 usbd_status status;
1096 {
1097 struct aue_softc *sc = priv;
1098 struct ifnet *ifp = GET_IFP(sc);
1099 struct aue_intrpkt *p = &sc->aue_cdata.aue_ibuf;
1100
1101 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
1102
1103 if (sc->aue_dying)
1104 return;
1105
1106 if (!(ifp->if_flags & IFF_RUNNING))
1107 return;
1108
1109 if (status != USBD_NORMAL_COMPLETION) {
1110 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
1111 return;
1112 }
1113 printf("%s: usb error on intr: %s\n", USBDEVNAME(sc->aue_dev),
1114 usbd_errstr(status));
1115 if (status == USBD_STALLED)
1116 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]);
1117 return;
1118 }
1119
1120 if (p->aue_txstat0)
1121 ifp->if_oerrors++;
1122
1123 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL))
1124 ifp->if_collisions++;
1125 }
1126
1127 #if defined(__FreeBSD__)
1128 static void
1129 aue_rxstart(ifp)
1130 struct ifnet *ifp;
1131 {
1132 struct aue_softc *sc;
1133 struct aue_chain *c;
1134
1135 sc = ifp->if_softc;
1136 c = &sc->aue_cdata.aue_rx_chain[sc->aue_cdata.aue_rx_prod];
1137
1138 if (aue_newbuf(sc, c, NULL) == ENOBUFS) {
1139 ifp->if_ierrors++;
1140 return;
1141 }
1142
1143 /* Setup new transfer. */
1144 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX],
1145 c, mtod(c->aue_mbuf, char *), AUE_BUFSZ, USBD_SHORT_XFER_OK,
1146 USBD_NO_TIMEOUT, aue_rxeof);
1147 usbd_transfer(c->aue_xfer);
1148 }
1149 #endif
1150
1151 /*
1152 * A frame has been uploaded: pass the resulting mbuf chain up to
1153 * the higher level protocols.
1154 *
1155 * Grrr. Receiving transfers larger than about 1152 bytes sometimes
1156 * doesn't work. We get an incomplete frame. In order to avoid
1157 * this, we queue up RX transfers that are shorter than a full sized
1158 * frame. If the received frame is larger than our transfer size,
1159 * we snag the rest of the data using a second transfer. Does this
1160 * hurt performance? Yes. But after fighting with this stupid thing
1161 * for three days, I'm willing to settle. I'd rather have reliable
1162 * receive performance that fast but spotty performance.
1163 */
1164 static void
1165 aue_rxeof(xfer, priv, status)
1166 usbd_xfer_handle xfer;
1167 usbd_private_handle priv;
1168 usbd_status status;
1169 {
1170 struct aue_chain *c = priv;
1171 struct aue_softc *sc = c->aue_sc;
1172 struct ifnet *ifp = GET_IFP(sc);
1173 struct mbuf *m;
1174 u_int32_t total_len;
1175 struct aue_rxpkt r;
1176 #if defined(__NetBSD__) || defined(__OpenBSD__)
1177 int s;
1178 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1179
1180 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
1181
1182 if (sc->aue_dying)
1183 return;
1184
1185 if (!(ifp->if_flags & IFF_RUNNING))
1186 return;
1187
1188 if (status != USBD_NORMAL_COMPLETION) {
1189 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
1190 return;
1191 sc->aue_rx_errs++;
1192 if (usbd_ratecheck(&sc->aue_rx_notice)) {
1193 printf("%s: %u usb errors on rx: %s\n",
1194 USBDEVNAME(sc->aue_dev), sc->aue_rx_errs,
1195 usbd_errstr(status));
1196 sc->aue_rx_errs = 0;
1197 }
1198 if (status == USBD_STALLED)
1199 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]);
1200 goto done;
1201 }
1202
1203 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
1204
1205 memcpy(mtod(c->aue_mbuf, char*), c->aue_buf, total_len);
1206
1207 if (total_len <= 4 + ETHER_CRC_LEN) {
1208 ifp->if_ierrors++;
1209 goto done;
1210 }
1211
1212 memcpy(&r, c->aue_buf + total_len - 4, sizeof(r));
1213
1214 /* Turn off all the non-error bits in the rx status word. */
1215 r.aue_rxstat &= AUE_RXSTAT_MASK;
1216 if (r.aue_rxstat) {
1217 ifp->if_ierrors++;
1218 goto done;
1219 }
1220
1221 /* No errors; receive the packet. */
1222 m = c->aue_mbuf;
1223 total_len -= ETHER_CRC_LEN + 4;
1224 m->m_pkthdr.len = m->m_len = total_len;
1225 ifp->if_ipackets++;
1226
1227 #if defined(__FreeBSD__)
1228 m->m_pkthdr.rcvif = (struct ifnet *)&kue_qdat;
1229 /* Put the packet on the special USB input queue. */
1230 usb_ether_input(m);
1231
1232 return;
1233
1234 #elif defined(__NetBSD__) || defined(__OpenBSD__)
1235 m->m_pkthdr.rcvif = ifp;
1236
1237 s = splimp();
1238
1239 /* XXX ugly */
1240 if (aue_newbuf(sc, c, NULL) == ENOBUFS) {
1241 ifp->if_ierrors++;
1242 goto done1;
1243 }
1244
1245 #if NBPFILTER > 0
1246 /*
1247 * Handle BPF listeners. Let the BPF user see the packet, but
1248 * don't pass it up to the ether_input() layer unless it's
1249 * a broadcast packet, multicast packet, matches our ethernet
1250 * address or the interface is in promiscuous mode.
1251 */
1252 if (ifp->if_bpf) {
1253 struct ether_header *eh = mtod(m, struct ether_header *);
1254 BPF_MTAP(ifp, m);
1255 if ((ifp->if_flags & IFF_PROMISC) &&
1256 memcmp(eh->ether_dhost, LLADDR(ifp->if_sadl),
1257 ETHER_ADDR_LEN) &&
1258 !(eh->ether_dhost[0] & 1)) {
1259 m_freem(m);
1260 goto done1;
1261 }
1262 }
1263 #endif
1264
1265 DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->aue_dev),
1266 __FUNCTION__, m->m_len));
1267 (*ifp->if_input)(ifp, m);
1268 done1:
1269 splx(s);
1270 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1271
1272 done:
1273
1274 /* Setup new transfer. */
1275 usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX],
1276 c, c->aue_buf, AUE_BUFSZ,
1277 USBD_SHORT_XFER_OK | USBD_NO_COPY,
1278 USBD_NO_TIMEOUT, aue_rxeof);
1279 usbd_transfer(xfer);
1280
1281 DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->aue_dev),
1282 __FUNCTION__));
1283 }
1284
1285 /*
1286 * A frame was downloaded to the chip. It's safe for us to clean up
1287 * the list buffers.
1288 */
1289
1290 static void
1291 aue_txeof(xfer, priv, status)
1292 usbd_xfer_handle xfer;
1293 usbd_private_handle priv;
1294 usbd_status status;
1295 {
1296 struct aue_chain *c = priv;
1297 struct aue_softc *sc = c->aue_sc;
1298 struct ifnet *ifp = GET_IFP(sc);
1299 int s;
1300
1301 if (sc->aue_dying)
1302 return;
1303
1304 s = splimp();
1305
1306 DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->aue_dev),
1307 __FUNCTION__, status));
1308
1309 ifp->if_timer = 0;
1310 ifp->if_flags &= ~IFF_OACTIVE;
1311
1312 if (status != USBD_NORMAL_COMPLETION) {
1313 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
1314 splx(s);
1315 return;
1316 }
1317 ifp->if_oerrors++;
1318 printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->aue_dev),
1319 usbd_errstr(status));
1320 if (status == USBD_STALLED)
1321 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_TX]);
1322 splx(s);
1323 return;
1324 }
1325
1326 ifp->if_opackets++;
1327
1328 #if defined(__FreeBSD__)
1329 c->aue_mbuf->m_pkthdr.rcvif = ifp;
1330 usb_tx_done(c->aue_mbuf);
1331 c->aue_mbuf = NULL;
1332 #elif defined(__NetBSD__) || defined(__OpenBSD__)
1333 m_freem(c->aue_mbuf);
1334 c->aue_mbuf = NULL;
1335
1336 if (ifp->if_snd.ifq_head != NULL)
1337 aue_start(ifp);
1338 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1339
1340 splx(s);
1341 }
1342
1343 static void
1344 aue_tick(xsc)
1345 void *xsc;
1346 {
1347 struct aue_softc *sc = xsc;
1348 struct ifnet *ifp;
1349 struct mii_data *mii;
1350 int s;
1351
1352 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
1353
1354 if (sc == NULL)
1355 return;
1356
1357 if (sc->aue_dying)
1358 return;
1359
1360 ifp = GET_IFP(sc);
1361 mii = GET_MII(sc);
1362 if (mii == NULL)
1363 return;
1364
1365 s = splimp();
1366
1367 mii_tick(mii);
1368 if (!sc->aue_link) {
1369 mii_pollstat(mii);
1370 if (mii->mii_media_status & IFM_ACTIVE &&
1371 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
1372 DPRINTFN(2,("%s: %s: got link\n",
1373 USBDEVNAME(sc->aue_dev),__FUNCTION__));
1374 sc->aue_link++;
1375 if (ifp->if_snd.ifq_head != NULL)
1376 aue_start(ifp);
1377 }
1378 }
1379
1380 usb_timeout(aue_tick, sc, hz, sc->aue_stat_ch);
1381
1382 splx(s);
1383 }
1384
1385 static int
1386 aue_send(sc, m, idx)
1387 struct aue_softc *sc;
1388 struct mbuf *m;
1389 int idx;
1390 {
1391 int total_len;
1392 struct aue_chain *c;
1393 usbd_status err;
1394
1395 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__FUNCTION__));
1396
1397 c = &sc->aue_cdata.aue_tx_chain[idx];
1398
1399 /*
1400 * Copy the mbuf data into a contiguous buffer, leaving two
1401 * bytes at the beginning to hold the frame length.
1402 */
1403 m_copydata(m, 0, m->m_pkthdr.len, c->aue_buf + 2);
1404 c->aue_mbuf = m;
1405
1406 /*
1407 * The ADMtek documentation says that the packet length is
1408 * supposed to be specified in the first two bytes of the
1409 * transfer, however it actually seems to ignore this info
1410 * and base the frame size on the bulk transfer length.
1411 */
1412 c->aue_buf[0] = (u_int8_t)m->m_pkthdr.len;
1413 c->aue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8);
1414 total_len = m->m_pkthdr.len + 2;
1415
1416 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_TX],
1417 c, c->aue_buf, total_len, USBD_FORCE_SHORT_XFER | USBD_NO_COPY,
1418 AUE_TX_TIMEOUT, aue_txeof);
1419
1420 /* Transmit */
1421 err = usbd_transfer(c->aue_xfer);
1422 if (err != USBD_IN_PROGRESS) {
1423 aue_stop(sc);
1424 return (EIO);
1425 }
1426 DPRINTFN(5,("%s: %s: send %d bytes\n", USBDEVNAME(sc->aue_dev),
1427 __FUNCTION__, total_len));
1428
1429 sc->aue_cdata.aue_tx_cnt++;
1430
1431 return (0);
1432 }
1433
1434 static void
1435 aue_start(ifp)
1436 struct ifnet *ifp;
1437 {
1438 struct aue_softc *sc = ifp->if_softc;
1439 struct mbuf *m_head = NULL;
1440
1441 DPRINTFN(5,("%s: %s: enter, link=%d\n", USBDEVNAME(sc->aue_dev),
1442 __FUNCTION__, sc->aue_link));
1443
1444 if (sc->aue_dying)
1445 return;
1446
1447 if (!sc->aue_link)
1448 return;
1449
1450 if (ifp->if_flags & IFF_OACTIVE)
1451 return;
1452
1453 IF_DEQUEUE(&ifp->if_snd, m_head);
1454 if (m_head == NULL)
1455 return;
1456
1457 if (aue_send(sc, m_head, 0)) {
1458 IF_PREPEND(&ifp->if_snd, m_head);
1459 ifp->if_flags |= IFF_OACTIVE;
1460 return;
1461 }
1462
1463 #if NBPFILTER > 0
1464 /*
1465 * If there's a BPF listener, bounce a copy of this frame
1466 * to him.
1467 */
1468 if (ifp->if_bpf)
1469 BPF_MTAP(ifp, m_head);
1470 #endif
1471
1472 ifp->if_flags |= IFF_OACTIVE;
1473
1474 /*
1475 * Set a timeout in case the chip goes out to lunch.
1476 */
1477 ifp->if_timer = 5;
1478 }
1479
1480 static void
1481 aue_init(xsc)
1482 void *xsc;
1483 {
1484 struct aue_softc *sc = xsc;
1485 struct ifnet *ifp = GET_IFP(sc);
1486 struct mii_data *mii = GET_MII(sc);
1487 int i, s;
1488 u_char *eaddr;
1489
1490 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1491
1492 if (sc->aue_dying)
1493 return;
1494
1495 if (ifp->if_flags & IFF_RUNNING)
1496 return;
1497
1498 s = splimp();
1499
1500 /*
1501 * Cancel pending I/O and free all RX/TX buffers.
1502 */
1503 aue_reset(sc);
1504
1505 #if defined(__FreeBSD__)
1506 eaddr = sc->arpcom.ac_enaddr;
1507 #elif defined(__NetBSD__) || defined(__OpenBSD__)
1508 eaddr = LLADDR(ifp->if_sadl);
1509 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1510 for (i = 0; i < ETHER_ADDR_LEN; i++)
1511 aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]);
1512
1513 /* If we want promiscuous mode, set the allframes bit. */
1514 if (ifp->if_flags & IFF_PROMISC)
1515 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1516 else
1517 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1518
1519 /* Init TX ring. */
1520 if (aue_tx_list_init(sc) == ENOBUFS) {
1521 printf("%s: tx list init failed\n", USBDEVNAME(sc->aue_dev));
1522 splx(s);
1523 return;
1524 }
1525
1526 /* Init RX ring. */
1527 if (aue_rx_list_init(sc) == ENOBUFS) {
1528 printf("%s: rx list init failed\n", USBDEVNAME(sc->aue_dev));
1529 splx(s);
1530 return;
1531 }
1532
1533 /* Load the multicast filter. */
1534 aue_setmulti(sc);
1535
1536 /* Enable RX and TX */
1537 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB);
1538 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB);
1539 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR);
1540
1541 mii_mediachg(mii);
1542
1543 if (sc->aue_ep[AUE_ENDPT_RX] == NULL) {
1544 if (aue_openpipes(sc)) {
1545 splx(s);
1546 return;
1547 }
1548 }
1549
1550 ifp->if_flags |= IFF_RUNNING;
1551 ifp->if_flags &= ~IFF_OACTIVE;
1552
1553 splx(s);
1554
1555 usb_untimeout(aue_tick, sc, sc->aue_stat_ch);
1556 usb_timeout(aue_tick, sc, hz, sc->aue_stat_ch);
1557 }
1558
1559 static int
1560 aue_openpipes(sc)
1561 struct aue_softc *sc;
1562 {
1563 struct aue_chain *c;
1564 usbd_status err;
1565 int i;
1566
1567 /* Open RX and TX pipes. */
1568 err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_RX],
1569 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_RX]);
1570 if (err) {
1571 printf("%s: open rx pipe failed: %s\n",
1572 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1573 return (EIO);
1574 }
1575 usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX],
1576 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]);
1577 if (err) {
1578 printf("%s: open tx pipe failed: %s\n",
1579 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1580 return (EIO);
1581 }
1582 err = usbd_open_pipe_intr(sc->aue_iface, sc->aue_ed[AUE_ENDPT_INTR],
1583 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_INTR], sc,
1584 &sc->aue_cdata.aue_ibuf, AUE_INTR_PKTLEN, aue_intr,
1585 AUE_INTR_INTERVAL);
1586 if (err) {
1587 printf("%s: open intr pipe failed: %s\n",
1588 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1589 return (EIO);
1590 }
1591
1592 /* Start up the receive pipe. */
1593 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1594 c = &sc->aue_cdata.aue_rx_chain[i];
1595 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX],
1596 c, c->aue_buf, AUE_BUFSZ,
1597 USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT,
1598 aue_rxeof);
1599 (void)usbd_transfer(c->aue_xfer); /* XXX */
1600 DPRINTFN(5,("%s: %s: start read\n", USBDEVNAME(sc->aue_dev),
1601 __FUNCTION__));
1602
1603 }
1604 return (0);
1605 }
1606
1607 /*
1608 * Set media options.
1609 */
1610 static int
1611 aue_ifmedia_upd(ifp)
1612 struct ifnet *ifp;
1613 {
1614 struct aue_softc *sc = ifp->if_softc;
1615 struct mii_data *mii = GET_MII(sc);
1616
1617 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1618
1619 if (sc->aue_dying)
1620 return (0);
1621
1622 sc->aue_link = 0;
1623 if (mii->mii_instance) {
1624 struct mii_softc *miisc;
1625 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
1626 miisc = LIST_NEXT(miisc, mii_list))
1627 mii_phy_reset(miisc);
1628 }
1629 mii_mediachg(mii);
1630
1631 return (0);
1632 }
1633
1634 /*
1635 * Report current media status.
1636 */
1637 static void
1638 aue_ifmedia_sts(ifp, ifmr)
1639 struct ifnet *ifp;
1640 struct ifmediareq *ifmr;
1641 {
1642 struct aue_softc *sc = ifp->if_softc;
1643 struct mii_data *mii = GET_MII(sc);
1644
1645 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1646
1647 mii_pollstat(mii);
1648 ifmr->ifm_active = mii->mii_media_active;
1649 ifmr->ifm_status = mii->mii_media_status;
1650 }
1651
1652 static int
1653 aue_ioctl(ifp, command, data)
1654 struct ifnet *ifp;
1655 u_long command;
1656 caddr_t data;
1657 {
1658 struct aue_softc *sc = ifp->if_softc;
1659 #if defined(__NetBSD__) || defined(__OpenBSD__)
1660 struct ifaddr *ifa = (struct ifaddr *)data;
1661 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1662 struct ifreq *ifr = (struct ifreq *)data;
1663 struct mii_data *mii;
1664 int s, error = 0;
1665
1666 if (sc->aue_dying)
1667 return (EIO);
1668
1669 s = splimp();
1670
1671 switch(command) {
1672 #if defined(__FreeBSD__)
1673 case SIOCSIFADDR:
1674 case SIOCGIFADDR:
1675 case SIOCSIFMTU:
1676 error = ether_ioctl(ifp, command, data);
1677 break;
1678 #elif defined(__NetBSD__) || defined(__OpenBSD__)
1679 case SIOCSIFADDR:
1680 ifp->if_flags |= IFF_UP;
1681 aue_init(sc);
1682
1683 switch (ifa->ifa_addr->sa_family) {
1684 #ifdef INET
1685 case AF_INET:
1686 arp_ifinit(ifp, ifa);
1687 break;
1688 #endif /* INET */
1689 #ifdef NS
1690 case AF_NS:
1691 {
1692 struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
1693
1694 if (ns_nullhost(*ina))
1695 ina->x_host = *(union ns_host *)
1696 LLADDR(ifp->if_sadl);
1697 else
1698 memcpy(LLADDR(ifp->if_sadl),
1699 ina->x_host.c_host,
1700 ifp->if_addrlen);
1701 break;
1702 }
1703 #endif /* NS */
1704 }
1705 break;
1706
1707 case SIOCSIFMTU:
1708 if (ifr->ifr_mtu > ETHERMTU)
1709 error = EINVAL;
1710 else
1711 ifp->if_mtu = ifr->ifr_mtu;
1712 break;
1713
1714 #endif /* defined(__NetBSD__) || defined(__OpenBSD__) */
1715 case SIOCSIFFLAGS:
1716 if (ifp->if_flags & IFF_UP) {
1717 if (ifp->if_flags & IFF_RUNNING &&
1718 ifp->if_flags & IFF_PROMISC &&
1719 !(sc->aue_if_flags & IFF_PROMISC)) {
1720 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1721 } else if (ifp->if_flags & IFF_RUNNING &&
1722 !(ifp->if_flags & IFF_PROMISC) &&
1723 sc->aue_if_flags & IFF_PROMISC) {
1724 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC);
1725 } else if (!(ifp->if_flags & IFF_RUNNING))
1726 aue_init(sc);
1727 } else {
1728 if (ifp->if_flags & IFF_RUNNING)
1729 aue_stop(sc);
1730 }
1731 sc->aue_if_flags = ifp->if_flags;
1732 error = 0;
1733 break;
1734 case SIOCADDMULTI:
1735 case SIOCDELMULTI:
1736 aue_setmulti(sc);
1737 error = 0;
1738 break;
1739 case SIOCGIFMEDIA:
1740 case SIOCSIFMEDIA:
1741 mii = GET_MII(sc);
1742 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1743 break;
1744 default:
1745 error = EINVAL;
1746 break;
1747 }
1748
1749 splx(s);
1750
1751 return (error);
1752 }
1753
1754 static void
1755 aue_watchdog(ifp)
1756 struct ifnet *ifp;
1757 {
1758 struct aue_softc *sc = ifp->if_softc;
1759
1760 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1761
1762 ifp->if_oerrors++;
1763 printf("%s: watchdog timeout\n", USBDEVNAME(sc->aue_dev));
1764
1765 /*
1766 * The polling business is a kludge to avoid allowing the
1767 * USB code to call tsleep() in usbd_delay_ms(), which will
1768 * kill us since the watchdog routine is invoked from
1769 * interrupt context.
1770 */
1771 usbd_set_polling(sc->aue_udev, 1);
1772 aue_stop(sc);
1773 aue_init(sc);
1774 usbd_set_polling(sc->aue_udev, 0);
1775
1776 if (ifp->if_snd.ifq_head != NULL)
1777 aue_start(ifp);
1778 }
1779
1780 /*
1781 * Stop the adapter and free any mbufs allocated to the
1782 * RX and TX lists.
1783 */
1784 static void
1785 aue_stop(sc)
1786 struct aue_softc *sc;
1787 {
1788 usbd_status err;
1789 struct ifnet *ifp;
1790 int i;
1791
1792 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1793
1794 ifp = GET_IFP(sc);
1795 ifp->if_timer = 0;
1796
1797 aue_csr_write_1(sc, AUE_CTL0, 0);
1798 aue_csr_write_1(sc, AUE_CTL1, 0);
1799 aue_reset(sc);
1800 usb_untimeout(aue_tick, sc, sc->aue_stat_ch);
1801
1802 /* Stop transfers. */
1803 if (sc->aue_ep[AUE_ENDPT_RX] != NULL) {
1804 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1805 if (err) {
1806 printf("%s: abort rx pipe failed: %s\n",
1807 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1808 }
1809 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_RX]);
1810 if (err) {
1811 printf("%s: close rx pipe failed: %s\n",
1812 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1813 }
1814 sc->aue_ep[AUE_ENDPT_RX] = NULL;
1815 }
1816
1817 if (sc->aue_ep[AUE_ENDPT_TX] != NULL) {
1818 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1819 if (err) {
1820 printf("%s: abort tx pipe failed: %s\n",
1821 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1822 }
1823 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_TX]);
1824 if (err) {
1825 printf("%s: close tx pipe failed: %s\n",
1826 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1827 }
1828 sc->aue_ep[AUE_ENDPT_TX] = NULL;
1829 }
1830
1831 if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) {
1832 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1833 if (err) {
1834 printf("%s: abort intr pipe failed: %s\n",
1835 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1836 }
1837 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_INTR]);
1838 if (err) {
1839 printf("%s: close intr pipe failed: %s\n",
1840 USBDEVNAME(sc->aue_dev), usbd_errstr(err));
1841 }
1842 sc->aue_ep[AUE_ENDPT_INTR] = NULL;
1843 }
1844
1845 /* Free RX resources. */
1846 for (i = 0; i < AUE_RX_LIST_CNT; i++) {
1847 if (sc->aue_cdata.aue_rx_chain[i].aue_mbuf != NULL) {
1848 m_freem(sc->aue_cdata.aue_rx_chain[i].aue_mbuf);
1849 sc->aue_cdata.aue_rx_chain[i].aue_mbuf = NULL;
1850 }
1851 if (sc->aue_cdata.aue_rx_chain[i].aue_xfer != NULL) {
1852 usbd_free_xfer(sc->aue_cdata.aue_rx_chain[i].aue_xfer);
1853 sc->aue_cdata.aue_rx_chain[i].aue_xfer = NULL;
1854 }
1855 }
1856
1857 /* Free TX resources. */
1858 for (i = 0; i < AUE_TX_LIST_CNT; i++) {
1859 if (sc->aue_cdata.aue_tx_chain[i].aue_mbuf != NULL) {
1860 m_freem(sc->aue_cdata.aue_tx_chain[i].aue_mbuf);
1861 sc->aue_cdata.aue_tx_chain[i].aue_mbuf = NULL;
1862 }
1863 if (sc->aue_cdata.aue_tx_chain[i].aue_xfer != NULL) {
1864 usbd_free_xfer(sc->aue_cdata.aue_tx_chain[i].aue_xfer);
1865 sc->aue_cdata.aue_tx_chain[i].aue_xfer = NULL;
1866 }
1867 }
1868
1869 sc->aue_link = 0;
1870
1871 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1872 }
1873
1874 #ifdef __FreeBSD__
1875 /*
1876 * Stop all chip I/O so that the kernel's probe routines don't
1877 * get confused by errant DMAs when rebooting.
1878 */
1879 static void
1880 aue_shutdown(dev)
1881 device_ptr_t dev;
1882 {
1883 struct aue_softc *sc = USBGETSOFTC(dev);
1884
1885 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __FUNCTION__));
1886
1887 aue_reset(sc);
1888 aue_stop(sc);
1889 }
1890 #endif
1891