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