if_axe.c revision 1.4 1 /* $NetBSD: if_axe.c,v 1.4 2004/10/24 12:53:26 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1998, 1999, 2000-2003
5 * Bill Paul <wpaul (at) windriver.com>. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /*
36 * ASIX Electronics AX88172 USB 2.0 ethernet driver. Used in the
37 * LinkSys USB200M and various other adapters.
38 *
39 * Manuals available from:
40 * http://www.asix.com.tw/datasheet/mac/Ax88172.PDF
41 * Note: you need the manual for the AX88170 chip (USB 1.x ethernet
42 * controller) to find the definitions for the RX control register.
43 * http://www.asix.com.tw/datasheet/mac/Ax88170.PDF
44 *
45 * Written by Bill Paul <wpaul (at) windriver.com>
46 * Senior Engineer
47 * Wind River Systems
48 */
49
50 /*
51 * The AX88172 provides USB ethernet supports at 10 and 100Mbps.
52 * It uses an external PHY (reference designs use a RealTek chip),
53 * and has a 64-bit multicast hash filter. There is some information
54 * missing from the manual which one needs to know in order to make
55 * the chip function:
56 *
57 * - You must set bit 7 in the RX control register, otherwise the
58 * chip won't receive any packets.
59 * - You must initialize all 3 IPG registers, or you won't be able
60 * to send any packets.
61 *
62 * Note that this device appears to only support loading the station
63 * address via autload from the EEPROM (i.e. there's no way to manaully
64 * set it).
65 *
66 * (Adam Weinberger wanted me to name this driver if_gir.c.)
67 */
68
69 /*
70 * Ported to OpenBSD 3/28/2004 by Greg Taleck <taleck (at) oz.net>
71 * with bits and pieces from the aue and url drivers.
72 */
73
74 #include <sys/cdefs.h>
75 __KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.4 2004/10/24 12:53:26 augustss Exp $");
76
77 #if defined(__NetBSD__)
78 #include "opt_inet.h"
79 #include "opt_ns.h"
80 #include "rnd.h"
81 #endif
82
83 #include "bpfilter.h"
84
85 #include <sys/param.h>
86 #include <sys/systm.h>
87 #include <sys/sockio.h>
88 #include <sys/lock.h>
89 #include <sys/mbuf.h>
90 #include <sys/kernel.h>
91 #if defined(__OpenBSD__)
92 #include <sys/proc.h>
93 #endif
94 #include <sys/socket.h>
95
96 #include <sys/device.h>
97 #if NRND > 0
98 #include <sys/rnd.h>
99 #endif
100
101 #include <net/if.h>
102 #if defined(__NetBSD__)
103 #include <net/if_arp.h>
104 #endif
105 #include <net/if_dl.h>
106 #include <net/if_media.h>
107
108 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m))
109
110 #if NBPFILTER > 0
111 #include <net/bpf.h>
112 #endif
113
114 #if defined(__NetBSD__)
115 #include <net/if_ether.h>
116 #ifdef INET
117 #include <netinet/in.h>
118 #include <netinet/if_inarp.h>
119 #endif
120 #endif /* defined(__NetBSD__) */
121
122 #if defined(__OpenBSD__)
123 #ifdef INET
124 #include <netinet/in.h>
125 #include <netinet/in_systm.h>
126 #include <netinet/in_var.h>
127 #include <netinet/ip.h>
128 #include <netinet/if_ether.h>
129 #endif
130 #endif /* defined(__OpenBSD__) */
131
132 #ifdef NS
133 #include <netns/ns.h>
134 #include <netns/ns_if.h>
135 #endif
136
137 #include <dev/mii/mii.h>
138 #include <dev/mii/miivar.h>
139
140 #include <dev/usb/usb.h>
141 #include <dev/usb/usbdi.h>
142 #include <dev/usb/usbdi_util.h>
143 #include <dev/usb/usbdevs.h>
144
145 #include <dev/usb/if_axereg.h>
146
147 #ifdef AXE_DEBUG
148 #define DPRINTF(x) do { if (axedebug) logprintf x; } while (0)
149 #define DPRINTFN(n,x) do { if (axedebug >= (n)) logprintf x; } while (0)
150 int axedebug = 0;
151 #else
152 #define DPRINTF(x)
153 #define DPRINTFN(n,x)
154 #endif
155
156 /*
157 * Various supported device vendors/products.
158 */
159 Static const struct axe_type axe_devs[] = {
160 { { USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88172}, 0 },
161 { { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB2_TX }, 0},
162 { { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DUBE100}, 0 },
163 { { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_USB200M}, 0 },
164 { { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAU2KTX}, 0 },
165 { { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA120}, 0 },
166 { { USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_LN029}, 0 },
167 { { USB_VENDOR_SYSTEMTALKS, USB_PRODUCT_SYSTEMTALKS_SGCX2UL}, 0 },
168 };
169 #define axe_lookup(v, p) ((struct axe_type *)usb_lookup(axe_devs, v, p))
170
171 USB_DECLARE_DRIVER(axe);
172
173 Static int axe_tx_list_init(struct axe_softc *);
174 Static int axe_rx_list_init(struct axe_softc *);
175 Static int axe_newbuf(struct axe_softc *, struct axe_chain *, struct mbuf *);
176 Static int axe_encap(struct axe_softc *, struct mbuf *, int);
177 Static void axe_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
178 Static void axe_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status);
179 Static void axe_tick(void *);
180 Static void axe_tick_task(void *);
181 #if 0
182 Static void axe_rxstart(struct ifnet *);
183 #endif
184 Static void axe_start(struct ifnet *);
185 Static int axe_ioctl(struct ifnet *, u_long, caddr_t);
186 Static void axe_init(void *);
187 Static void axe_stop(struct axe_softc *);
188 Static void axe_watchdog(struct ifnet *);
189 Static int axe_miibus_readreg(device_ptr_t, int, int);
190 Static void axe_miibus_writereg(device_ptr_t, int, int, int);
191 Static void axe_miibus_statchg(device_ptr_t);
192 Static int axe_cmd(struct axe_softc *, int, int, int, void *);
193 Static int axe_ifmedia_upd(struct ifnet *);
194 Static void axe_ifmedia_sts(struct ifnet *, struct ifmediareq *);
195 Static void axe_reset(struct axe_softc *sc);
196
197 Static void axe_setmulti(struct axe_softc *);
198 Static void axe_lock_mii(struct axe_softc *sc);
199 Static void axe_unlock_mii(struct axe_softc *sc);
200
201 /* Get exclusive access to the MII registers */
202 Static void
203 axe_lock_mii(struct axe_softc *sc)
204 {
205 sc->axe_refcnt++;
206 usb_lockmgr(&sc->axe_mii_lock, LK_EXCLUSIVE, NULL);
207 }
208
209 Static void
210 axe_unlock_mii(struct axe_softc *sc)
211 {
212 usb_lockmgr(&sc->axe_mii_lock, LK_RELEASE, NULL);
213 if (--sc->axe_refcnt < 0)
214 usb_detach_wakeup(USBDEV(sc->axe_dev));
215 }
216
217 Static int
218 axe_cmd(struct axe_softc *sc, int cmd, int index, int val, void *buf)
219 {
220 usb_device_request_t req;
221 usbd_status err;
222
223 if (sc->axe_dying)
224 return(0);
225
226 axe_lock_mii(sc);
227 if (AXE_CMD_DIR(cmd))
228 req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
229 else
230 req.bmRequestType = UT_READ_VENDOR_DEVICE;
231 req.bRequest = AXE_CMD_CMD(cmd);
232 USETW(req.wValue, val);
233 USETW(req.wIndex, index);
234 USETW(req.wLength, AXE_CMD_LEN(cmd));
235
236 err = usbd_do_request(sc->axe_udev, &req, buf);
237 axe_unlock_mii(sc);
238
239 if (err)
240 return(-1);
241
242 return(0);
243 }
244
245 Static int
246 axe_miibus_readreg(device_ptr_t dev, int phy, int reg)
247 {
248 struct axe_softc *sc = USBGETSOFTC(dev);
249 usbd_status err;
250 u_int16_t val;
251
252 if (sc->axe_dying) {
253 DPRINTF(("axe: dying\n"));
254 return(0);
255 }
256
257 #ifdef notdef
258 /*
259 * The chip tells us the MII address of any supported
260 * PHYs attached to the chip, so only read from those.
261 */
262
263 if (sc->axe_phyaddrs[0] != AXE_NOPHY && phy != sc->axe_phyaddrs[0])
264 return (0);
265
266 if (sc->axe_phyaddrs[1] != AXE_NOPHY && phy != sc->axe_phyaddrs[1])
267 return (0);
268 #endif
269 if (sc->axe_phyaddrs[0] != 0xFF && sc->axe_phyaddrs[0] != phy)
270 return (0);
271
272
273 axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
274 err = axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, (void *)&val);
275 axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
276
277 if (err) {
278 printf("%s: read PHY failed\n", USBDEVNAME(sc->axe_dev));
279 return(-1);
280 }
281
282 if (val)
283 sc->axe_phyaddrs[0] = phy;
284
285 return (val);
286 }
287
288 Static void
289 axe_miibus_writereg(device_ptr_t dev, int phy, int reg, int val)
290 {
291 struct axe_softc *sc = USBGETSOFTC(dev);
292 usbd_status err;
293
294 if (sc->axe_dying)
295 return;
296
297 axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL);
298 err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, (void *)&val);
299 axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL);
300
301 if (err) {
302 printf("%s: write PHY failed\n", USBDEVNAME(sc->axe_dev));
303 return;
304 }
305
306 return;
307 }
308
309 Static void
310 axe_miibus_statchg(device_ptr_t dev)
311 {
312 #ifdef notdef
313 struct axe_softc *sc = USBGETSOFTC(dev);
314 struct mii_data *mii = GET_MII(sc);
315 #endif
316 /* doesn't seem to be necessary */
317 return;
318 }
319
320 /*
321 * Set media options.
322 */
323 Static int
324 axe_ifmedia_upd(struct ifnet *ifp)
325 {
326 struct axe_softc *sc = ifp->if_softc;
327 struct mii_data *mii = GET_MII(sc);
328
329 sc->axe_link = 0;
330 if (mii->mii_instance) {
331 struct mii_softc *miisc;
332 LIST_FOREACH(miisc, &mii->mii_phys, mii_list)
333 mii_phy_reset(miisc);
334 }
335 mii_mediachg(mii);
336
337 return (0);
338 }
339
340 /*
341 * Report current media status.
342 */
343 Static void
344 axe_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
345 {
346 struct axe_softc *sc = ifp->if_softc;
347 struct mii_data *mii = GET_MII(sc);
348
349 mii_pollstat(mii);
350 ifmr->ifm_active = mii->mii_media_active;
351 ifmr->ifm_status = mii->mii_media_status;
352 }
353
354 Static void
355 axe_setmulti(struct axe_softc *sc)
356 {
357 struct ifnet *ifp;
358 struct ether_multi *enm;
359 struct ether_multistep step;
360 u_int32_t h = 0;
361 u_int16_t rxmode;
362 u_int8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
363
364 if (sc->axe_dying)
365 return;
366
367 ifp = GET_IFP(sc);
368
369 axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, (void *)&rxmode);
370
371 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
372 allmulti:
373 rxmode |= AXE_RXCMD_ALLMULTI;
374 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
375 return;
376 } else
377 rxmode &= ~AXE_RXCMD_ALLMULTI;
378
379 /* now program new ones */
380 #if defined(__NetBSD__)
381 ETHER_FIRST_MULTI(step, &sc->axe_ec, enm);
382 #else
383 ETHER_FIRST_MULTI(step, &sc->arpcom, enm);
384 #endif
385 while (enm != NULL) {
386 if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
387 ETHER_ADDR_LEN) != 0)
388 goto allmulti;
389
390 h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
391 hashtbl[h / 8] |= 1 << (h % 8);
392 ETHER_NEXT_MULTI(step, enm);
393 }
394
395 ifp->if_flags &= ~IFF_ALLMULTI;
396 axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl);
397 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
398 return;
399 }
400
401 Static void
402 axe_reset(struct axe_softc *sc)
403 {
404 if (sc->axe_dying)
405 return;
406 /* XXX What to reset? */
407
408 /* Wait a little while for the chip to get its brains in order. */
409 DELAY(1000);
410 return;
411 }
412
413 /*
414 * Probe for a AX88172 chip.
415 */
416 USB_MATCH(axe)
417 {
418 USB_MATCH_START(axe, uaa);
419
420 if (!uaa->iface) {
421 return(UMATCH_NONE);
422 }
423
424 return (axe_lookup(uaa->vendor, uaa->product) != NULL ?
425 UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
426 }
427
428 /*
429 * Attach the interface. Allocate softc structures, do ifmedia
430 * setup and ethernet/BPF attach.
431 */
432 USB_ATTACH(axe)
433 {
434 USB_ATTACH_START(axe, sc, uaa);
435 usbd_device_handle dev = uaa->device;
436 usbd_status err;
437 usb_interface_descriptor_t *id;
438 usb_endpoint_descriptor_t *ed;
439 struct mii_data *mii;
440 u_char eaddr[ETHER_ADDR_LEN];
441 char devinfo[1024];
442 char *devname = USBDEVNAME(sc->axe_dev);
443 struct ifnet *ifp;
444 int i, s;
445
446 usbd_devinfo(dev, 0, devinfo, sizeof devinfo);
447 USB_ATTACH_SETUP;
448
449 err = usbd_set_config_no(dev, AXE_CONFIG_NO, 1);
450 if (err) {
451 printf("%s: getting interface handle failed\n",
452 USBDEVNAME(sc->axe_dev));
453 USB_ATTACH_ERROR_RETURN;
454 }
455
456 usb_init_task(&sc->axe_tick_task, axe_tick_task, sc);
457 lockinit(&sc->axe_mii_lock, PZERO, "axemii", 0, 0);
458 usb_init_task(&sc->axe_stop_task, (void (*)(void *))axe_stop, sc);
459
460 err = usbd_device2interface_handle(dev, AXE_IFACE_IDX, &sc->axe_iface);
461 if (err) {
462 printf("%s: getting interface handle failed\n",
463 USBDEVNAME(sc->axe_dev));
464 USB_ATTACH_ERROR_RETURN;
465 }
466
467 sc->axe_udev = dev;
468 sc->axe_product = uaa->product;
469 sc->axe_vendor = uaa->vendor;
470
471 id = usbd_get_interface_descriptor(sc->axe_iface);
472
473 printf("%s: %s\n", USBDEVNAME(sc->axe_dev), devinfo);
474
475 /* Find endpoints. */
476 for (i = 0; i < id->bNumEndpoints; i++) {
477 ed = usbd_interface2endpoint_descriptor(sc->axe_iface, i);
478 if (!ed) {
479 printf("%s: couldn't get ep %d\n",
480 USBDEVNAME(sc->axe_dev), i);
481 USB_ATTACH_ERROR_RETURN;
482 }
483 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
484 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
485 sc->axe_ed[AXE_ENDPT_RX] = ed->bEndpointAddress;
486 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
487 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
488 sc->axe_ed[AXE_ENDPT_TX] = ed->bEndpointAddress;
489 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
490 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
491 sc->axe_ed[AXE_ENDPT_INTR] = ed->bEndpointAddress;
492 }
493 }
494
495 s = splnet();
496
497 /*
498 * Get station address.
499 */
500 axe_cmd(sc, AXE_CMD_READ_NODEID, 0, 0, &eaddr);
501
502 /*
503 * Load IPG values and PHY indexes.
504 */
505 axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, (void *)&sc->axe_ipgs);
506 axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs);
507
508 /*
509 * Work around broken adapters that appear to lie about
510 * their PHY addresses.
511 */
512 sc->axe_phyaddrs[0] = sc->axe_phyaddrs[1] = 0xFF;
513
514 /*
515 * An ASIX chip was detected. Inform the world.
516 */
517 printf("%s: Ethernet address %s\n", USBDEVNAME(sc->axe_dev),
518 ether_sprintf(eaddr));
519
520 /* Initialize interface info.*/
521 ifp = GET_IFP(sc);
522 ifp->if_softc = sc;
523 strncpy(ifp->if_xname, devname, IFNAMSIZ);
524 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
525 ifp->if_ioctl = axe_ioctl;
526 ifp->if_start = axe_start;
527
528 ifp->if_watchdog = axe_watchdog;
529
530 /* ifp->if_baudrate = 10000000; */
531 /* ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;*/
532
533 IFQ_SET_READY(&ifp->if_snd);
534
535 /* Initialize MII/media info. */
536 mii = &sc->axe_mii;
537 mii->mii_ifp = ifp;
538 mii->mii_readreg = axe_miibus_readreg;
539 mii->mii_writereg = axe_miibus_writereg;
540 mii->mii_statchg = axe_miibus_statchg;
541 mii->mii_flags = MIIF_AUTOTSLEEP;
542
543 ifmedia_init(&mii->mii_media, 0, axe_ifmedia_upd, axe_ifmedia_sts);
544 mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0);
545
546 if (LIST_FIRST(&mii->mii_phys) == NULL) {
547 ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
548 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
549 } else
550 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
551
552 /* Attach the interface. */
553 if_attach(ifp);
554 Ether_ifattach(ifp, eaddr);
555 #if NRND > 0
556 rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->axe_dev),
557 RND_TYPE_NET, 0);
558 #endif
559
560 usb_callout_init(sc->axe_stat_ch);
561
562 sc->axe_attached = 1;
563 splx(s);
564
565 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->axe_udev,
566 USBDEV(sc->axe_dev));
567
568 USB_ATTACH_SUCCESS_RETURN;
569 }
570
571 USB_DETACH(axe)
572 {
573 USB_DETACH_START(axe, sc);
574 int s;
575 struct ifnet *ifp = GET_IFP(sc);
576
577 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__));
578
579 /* Detached before attached finished, so just bail out. */
580 if (!sc->axe_attached)
581 return (0);
582
583 usb_uncallout(sc->axe_stat_ch, axe_tick, sc);
584
585 sc->axe_dying = 1;
586
587 ether_ifdetach(ifp);
588
589 if (sc->axe_ep[AXE_ENDPT_TX] != NULL)
590 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
591 if (sc->axe_ep[AXE_ENDPT_RX] != NULL)
592 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]);
593 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL)
594 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
595
596 /*
597 * Remove any pending tasks. They cannot be executing because they run
598 * in the same thread as detach.
599 */
600 usb_rem_task(sc->axe_udev, &sc->axe_tick_task);
601 usb_rem_task(sc->axe_udev, &sc->axe_stop_task);
602
603 s = splusb();
604
605 if (--sc->axe_refcnt >= 0) {
606 /* Wait for processes to go away */
607 usb_detach_wait(USBDEV(sc->axe_dev));
608 }
609
610 if (ifp->if_flags & IFF_RUNNING)
611 axe_stop(sc);
612
613 #if defined(__NetBSD__)
614 #if NRND > 0
615 rnd_detach_source(&sc->rnd_source);
616 #endif
617 #endif /* __NetBSD__ */
618 mii_detach(&sc->axe_mii, MII_PHY_ANY, MII_OFFSET_ANY);
619 ifmedia_delete_instance(&sc->axe_mii.mii_media, IFM_INST_ANY);
620 ether_ifdetach(ifp);
621 if_detach(ifp);
622
623 #ifdef DIAGNOSTIC
624 if (sc->axe_ep[AXE_ENDPT_TX] != NULL ||
625 sc->axe_ep[AXE_ENDPT_RX] != NULL ||
626 sc->axe_ep[AXE_ENDPT_INTR] != NULL)
627 printf("%s: detach has active endpoints\n",
628 USBDEVNAME(sc->axe_dev));
629 #endif
630
631 sc->axe_attached = 0;
632
633 if (--sc->axe_refcnt >= 0) {
634 /* Wait for processes to go away. */
635 usb_detach_wait(USBDEV(sc->axe_dev));
636 }
637 splx(s);
638
639 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->axe_udev,
640 USBDEV(sc->axe_dev));
641
642 return (0);
643 }
644
645 int
646 axe_activate(device_ptr_t self, enum devact act)
647 {
648 struct axe_softc *sc = (struct axe_softc *)self;
649
650 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__));
651
652 switch (act) {
653 case DVACT_ACTIVATE:
654 return (EOPNOTSUPP);
655 break;
656
657 case DVACT_DEACTIVATE:
658 if_deactivate(&sc->axe_ec.ec_if);
659 sc->axe_dying = 1;
660 break;
661 }
662 return (0);
663 }
664
665 /*
666 * Initialize an RX descriptor and attach an MBUF cluster.
667 */
668 Static int
669 axe_newbuf(struct axe_softc *sc, struct axe_chain *c, struct mbuf *m)
670 {
671 struct mbuf *m_new = NULL;
672
673 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev),__func__));
674
675 if (m == NULL) {
676 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
677 if (m_new == NULL) {
678 printf("%s: no memory for rx list "
679 "-- packet dropped!\n", USBDEVNAME(sc->axe_dev));
680 return (ENOBUFS);
681 }
682
683 MCLGET(m_new, M_DONTWAIT);
684 if (!(m_new->m_flags & M_EXT)) {
685 printf("%s: no memory for rx list "
686 "-- packet dropped!\n", USBDEVNAME(sc->axe_dev));
687 m_freem(m_new);
688 return (ENOBUFS);
689 }
690 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
691 } else {
692 m_new = m;
693 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
694 m_new->m_data = m_new->m_ext.ext_buf;
695 }
696
697 m_adj(m_new, ETHER_ALIGN);
698 c->axe_mbuf = m_new;
699
700 return (0);
701 }
702
703 Static int
704 axe_rx_list_init(struct axe_softc *sc)
705 {
706 struct axe_cdata *cd;
707 struct axe_chain *c;
708 int i;
709
710 DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__));
711
712 cd = &sc->axe_cdata;
713 for (i = 0; i < AXE_RX_LIST_CNT; i++) {
714 c = &cd->axe_rx_chain[i];
715 c->axe_sc = sc;
716 c->axe_idx = i;
717 if (axe_newbuf(sc, c, NULL) == ENOBUFS)
718 return (ENOBUFS);
719 if (c->axe_xfer == NULL) {
720 c->axe_xfer = usbd_alloc_xfer(sc->axe_udev);
721 if (c->axe_xfer == NULL)
722 return (ENOBUFS);
723 c->axe_buf = usbd_alloc_buffer(c->axe_xfer, AXE_BUFSZ);
724 if (c->axe_buf == NULL) {
725 usbd_free_xfer(c->axe_xfer);
726 return (ENOBUFS);
727 }
728 }
729 }
730
731 return (0);
732 }
733
734 Static int
735 axe_tx_list_init(struct axe_softc *sc)
736 {
737 struct axe_cdata *cd;
738 struct axe_chain *c;
739 int i;
740
741 DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__));
742
743 cd = &sc->axe_cdata;
744 for (i = 0; i < AXE_TX_LIST_CNT; i++) {
745 c = &cd->axe_tx_chain[i];
746 c->axe_sc = sc;
747 c->axe_idx = i;
748 c->axe_mbuf = NULL;
749 if (c->axe_xfer == NULL) {
750 c->axe_xfer = usbd_alloc_xfer(sc->axe_udev);
751 if (c->axe_xfer == NULL)
752 return (ENOBUFS);
753 c->axe_buf = usbd_alloc_buffer(c->axe_xfer, AXE_BUFSZ);
754 if (c->axe_buf == NULL) {
755 usbd_free_xfer(c->axe_xfer);
756 return (ENOBUFS);
757 }
758 }
759 }
760
761 return (0);
762 }
763
764 #if 0
765 Static void
766 axe_rxstart(struct ifnet *ifp)
767 {
768 struct axe_softc *sc;
769 struct axe_chain *c;
770
771 sc = ifp->if_softc;
772 axe_lock_mii(sc);
773 c = &sc->axe_cdata.axe_rx_chain[sc->axe_cdata.axe_rx_prod];
774
775 if (axe_newbuf(sc, c, NULL) == ENOBUFS) {
776 ifp->if_ierrors++;
777 axe_unlock_mii(sc);
778 return;
779 }
780
781 /* Setup new transfer. */
782 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
783 c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK,
784 USBD_NO_TIMEOUT, axe_rxeof);
785 usbd_transfer(c->axe_xfer);
786 axe_unlock_mii(sc);
787
788 return;
789 }
790 #endif
791
792 /*
793 * A frame has been uploaded: pass the resulting mbuf chain up to
794 * the higher level protocols.
795 */
796 Static void
797 axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
798 {
799 struct axe_softc *sc;
800 struct axe_chain *c;
801 struct ifnet *ifp;
802 struct mbuf *m;
803 u_int32_t total_len;
804 int s;
805
806 c = priv;
807 sc = c->axe_sc;
808 ifp = GET_IFP(sc);
809
810 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev),__func__));
811
812 if (sc->axe_dying)
813 return;
814
815 if (!(ifp->if_flags & IFF_RUNNING))
816 return;
817
818 if (status != USBD_NORMAL_COMPLETION) {
819 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
820 return;
821 if (usbd_ratecheck(&sc->axe_rx_notice)) {
822 printf("%s: usb errors on rx: %s\n",
823 USBDEVNAME(sc->axe_dev), usbd_errstr(status));
824 }
825 if (status == USBD_STALLED)
826 usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_RX]);
827 goto done;
828 }
829
830 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
831
832 m = c->axe_mbuf;
833
834 if (total_len <= sizeof(struct ether_header)) {
835 ifp->if_ierrors++;
836 goto done;
837 }
838
839 ifp->if_ipackets++;
840 m->m_pkthdr.rcvif = ifp;
841 m->m_pkthdr.len = m->m_len = total_len;
842
843
844 memcpy(mtod(c->axe_mbuf, char *), c->axe_buf, total_len);
845
846 /* No errors; receive the packet. */
847 total_len -= ETHER_CRC_LEN + 4;
848
849 s = splnet();
850
851 /* XXX ugly */
852 if (axe_newbuf(sc, c, NULL) == ENOBUFS) {
853 ifp->if_ierrors++;
854 goto done1;
855 }
856
857 #if NBPFILTER > 0
858 if (ifp->if_bpf)
859 BPF_MTAP(ifp, m);
860 #endif
861
862 DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->axe_dev),
863 __func__, m->m_len));
864 IF_INPUT(ifp, m);
865 done1:
866 splx(s);
867
868 done:
869
870 /* Setup new transfer. */
871 usbd_setup_xfer(xfer, sc->axe_ep[AXE_ENDPT_RX],
872 c, c->axe_buf, AXE_BUFSZ,
873 USBD_SHORT_XFER_OK | USBD_NO_COPY,
874 USBD_NO_TIMEOUT, axe_rxeof);
875 usbd_transfer(xfer);
876
877 DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->axe_dev),
878 __func__));
879 return;
880 }
881
882 /*
883 * A frame was downloaded to the chip. It's safe for us to clean up
884 * the list buffers.
885 */
886
887 Static void
888 axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status)
889 {
890 struct axe_softc *sc;
891 struct axe_chain *c;
892 struct ifnet *ifp;
893 int s;
894
895 c = priv;
896 sc = c->axe_sc;
897 ifp = GET_IFP(sc);
898
899 if (sc->axe_dying)
900 return;
901
902 s = splnet();
903
904 if (status != USBD_NORMAL_COMPLETION) {
905 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) {
906 splx(s);
907 return;
908 }
909 ifp->if_oerrors++;
910 printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->axe_dev),
911 usbd_errstr(status));
912 if (status == USBD_STALLED)
913 usbd_clear_endpoint_stall(sc->axe_ep[AXE_ENDPT_TX]);
914 splx(s);
915 return;
916 }
917
918 ifp->if_timer = 0;
919 ifp->if_flags &= ~IFF_OACTIVE;
920
921 m_freem(c->axe_mbuf);
922 c->axe_mbuf = NULL;
923
924 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
925 axe_start(ifp);
926
927 ifp->if_opackets++;
928 splx(s);
929 return;
930 }
931
932 Static void
933 axe_tick(void *xsc)
934 {
935 struct axe_softc *sc = xsc;
936
937 if (sc == NULL)
938 return;
939
940 DPRINTFN(0xff, ("%s: %s: enter\n", USBDEVNAME(sc->axe_dev),
941 __func__));
942
943 if (sc->axe_dying)
944 return;
945
946 /* Perform periodic stuff in process context */
947 usb_add_task(sc->axe_udev, &sc->axe_tick_task);
948
949 }
950
951 Static void
952 axe_tick_task(void *xsc)
953 {
954 int s;
955 struct axe_softc *sc;
956 struct ifnet *ifp;
957 struct mii_data *mii;
958
959 sc = xsc;
960
961 if (sc == NULL)
962 return;
963
964 if (sc->axe_dying)
965 return;
966
967 ifp = GET_IFP(sc);
968 mii = GET_MII(sc);
969 if (mii == NULL)
970 return;
971
972 s = splnet();
973
974 mii_tick(mii);
975 if (!sc->axe_link) {
976 mii_pollstat(mii);
977 if (mii->mii_media_status & IFM_ACTIVE &&
978 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) {
979 DPRINTF(("%s: %s: got link\n",
980 USBDEVNAME(sc->axe_dev), __func__));
981 sc->axe_link++;
982 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)
983 axe_start(ifp);
984 }
985 }
986
987 usb_callout(sc->axe_stat_ch, hz, axe_tick, sc);
988
989 splx(s);
990 }
991
992 Static int
993 axe_encap(struct axe_softc *sc, struct mbuf *m, int idx)
994 {
995 struct axe_chain *c;
996 usbd_status err;
997
998 c = &sc->axe_cdata.axe_tx_chain[idx];
999
1000 /*
1001 * Copy the mbuf data into a contiguous buffer, leaving two
1002 * bytes at the beginning to hold the frame length.
1003 */
1004 m_copydata(m, 0, m->m_pkthdr.len, c->axe_buf);
1005 c->axe_mbuf = m;
1006
1007 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_TX],
1008 c, c->axe_buf, m->m_pkthdr.len, USBD_FORCE_SHORT_XFER, 10000,
1009 axe_txeof);
1010
1011 /* Transmit */
1012 err = usbd_transfer(c->axe_xfer);
1013 if (err != USBD_IN_PROGRESS) {
1014 axe_stop(sc);
1015 return(EIO);
1016 }
1017
1018 sc->axe_cdata.axe_tx_cnt++;
1019
1020 return(0);
1021 }
1022
1023 Static void
1024 axe_start(struct ifnet *ifp)
1025 {
1026 struct axe_softc *sc;
1027 struct mbuf *m_head = NULL;
1028
1029 sc = ifp->if_softc;
1030
1031 if (!sc->axe_link) {
1032 return;
1033 }
1034
1035 if (ifp->if_flags & IFF_OACTIVE) {
1036 return;
1037 }
1038
1039 IF_DEQUEUE(&ifp->if_snd, m_head);
1040 if (m_head == NULL) {
1041 return;
1042 }
1043
1044 if (axe_encap(sc, m_head, 0)) {
1045 IF_PREPEND(&ifp->if_snd, m_head);
1046 ifp->if_flags |= IFF_OACTIVE;
1047 return;
1048 }
1049
1050 /*
1051 * If there's a BPF listener, bounce a copy of this frame
1052 * to him.
1053 */
1054 #if NBPFILTER > 0
1055 if (ifp->if_bpf)
1056 BPF_MTAP(ifp, m_head);
1057 #endif
1058
1059 ifp->if_flags |= IFF_OACTIVE;
1060
1061 /*
1062 * Set a timeout in case the chip goes out to lunch.
1063 */
1064 ifp->if_timer = 5;
1065
1066 return;
1067 }
1068
1069 Static void
1070 axe_init(void *xsc)
1071 {
1072 struct axe_softc *sc = xsc;
1073 struct ifnet *ifp = GET_IFP(sc);
1074 struct axe_chain *c;
1075 usbd_status err;
1076 int rxmode;
1077 int i, s;
1078
1079 if (ifp->if_flags & IFF_RUNNING)
1080 return;
1081
1082 s = splnet();
1083
1084 /*
1085 * Cancel pending I/O and free all RX/TX buffers.
1086 */
1087 axe_reset(sc);
1088
1089 /* Enable RX logic. */
1090
1091 /* Init RX ring. */
1092 if (axe_rx_list_init(sc) == ENOBUFS) {
1093 printf("%s: rx list init failed\n", USBDEVNAME(sc->axe_dev));
1094 splx(s);
1095 return;
1096 }
1097
1098 /* Init TX ring. */
1099 if (axe_tx_list_init(sc) == ENOBUFS) {
1100 printf("%s: tx list init failed\n", USBDEVNAME(sc->axe_dev));
1101 splx(s);
1102 return;
1103 }
1104
1105 /* Set transmitter IPG values */
1106 axe_cmd(sc, AXE_CMD_WRITE_IPG0, 0, sc->axe_ipgs[0], NULL);
1107 axe_cmd(sc, AXE_CMD_WRITE_IPG1, 0, sc->axe_ipgs[1], NULL);
1108 axe_cmd(sc, AXE_CMD_WRITE_IPG2, 0, sc->axe_ipgs[2], NULL);
1109
1110 /* Enable receiver, set RX mode */
1111 rxmode = AXE_RXCMD_UNICAST|AXE_RXCMD_MULTICAST|AXE_RXCMD_ENABLE;
1112
1113 /* If we want promiscuous mode, set the allframes bit. */
1114 if (ifp->if_flags & IFF_PROMISC)
1115 rxmode |= AXE_RXCMD_PROMISC;
1116
1117 if (ifp->if_flags & IFF_BROADCAST)
1118 rxmode |= AXE_RXCMD_BROADCAST;
1119
1120 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
1121
1122 /* Load the multicast filter. */
1123 axe_setmulti(sc);
1124
1125 /* Open RX and TX pipes. */
1126 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_RX],
1127 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_RX]);
1128 if (err) {
1129 printf("%s: open rx pipe failed: %s\n",
1130 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1131 splx(s);
1132 return;
1133 }
1134
1135 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_TX],
1136 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_TX]);
1137 if (err) {
1138 printf("%s: open tx pipe failed: %s\n",
1139 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1140 splx(s);
1141 return;
1142 }
1143
1144 /* Start up the receive pipe. */
1145 for (i = 0; i < AXE_RX_LIST_CNT; i++) {
1146 c = &sc->axe_cdata.axe_rx_chain[i];
1147 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX],
1148 c, mtod(c->axe_mbuf, char *), AXE_BUFSZ,
1149 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, axe_rxeof);
1150 usbd_transfer(c->axe_xfer);
1151 }
1152
1153 ifp->if_flags |= IFF_RUNNING;
1154 ifp->if_flags &= ~IFF_OACTIVE;
1155
1156 splx(s);
1157
1158 usb_callout_init(sc->axe_stat_ch);
1159 usb_callout(sc->axe_stat_ch, hz, axe_tick, sc);
1160 return;
1161 }
1162
1163 Static int
1164 axe_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
1165 {
1166 struct axe_softc *sc = ifp->if_softc;
1167 struct ifreq *ifr = (struct ifreq *)data;
1168 struct ifaddr *ifa = (struct ifaddr *)data;
1169 struct mii_data *mii;
1170 u_int16_t rxmode;
1171 int error = 0;
1172
1173 switch(cmd) {
1174 case SIOCSIFADDR:
1175 ifp->if_flags |= IFF_UP;
1176 axe_init(sc);
1177
1178 switch (ifa->ifa_addr->sa_family) {
1179 #ifdef INET
1180 case AF_INET:
1181 #if defined(__NetBSD__)
1182 arp_ifinit(ifp, ifa);
1183 #else
1184 arp_ifinit(&sc->arpcom, ifa);
1185 #endif
1186 break;
1187 #endif /* INET */
1188 #ifdef NS
1189 case AF_NS:
1190 {
1191 struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
1192
1193 if (ns_nullhost(*ina))
1194 ina->x_host = *(union ns_host *)
1195 LLADDR(ifp->if_sadl);
1196 else
1197 memcpy(LLADDR(ifp->if_sadl),
1198 ina->x_host.c_host,
1199 ifp->if_addrlen);
1200 break;
1201 }
1202 #endif /* NS */
1203 }
1204 break;
1205
1206 case SIOCSIFMTU:
1207 if (ifr->ifr_mtu > ETHERMTU)
1208 error = EINVAL;
1209 else
1210 ifp->if_mtu = ifr->ifr_mtu;
1211 break;
1212
1213 case SIOCSIFFLAGS:
1214 if (ifp->if_flags & IFF_UP) {
1215 if (ifp->if_flags & IFF_RUNNING &&
1216 ifp->if_flags & IFF_PROMISC &&
1217 !(sc->axe_if_flags & IFF_PROMISC)) {
1218
1219 axe_cmd(sc, AXE_CMD_RXCTL_READ,
1220 0, 0, (void *)&rxmode);
1221 rxmode |= AXE_RXCMD_PROMISC;
1222 axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
1223 0, rxmode, NULL);
1224
1225 axe_setmulti(sc);
1226 } else if (ifp->if_flags & IFF_RUNNING &&
1227 !(ifp->if_flags & IFF_PROMISC) &&
1228 sc->axe_if_flags & IFF_PROMISC) {
1229 axe_cmd(sc, AXE_CMD_RXCTL_READ,
1230 0, 0, (void *)&rxmode);
1231 rxmode &= ~AXE_RXCMD_PROMISC;
1232 axe_cmd(sc, AXE_CMD_RXCTL_WRITE,
1233 0, rxmode, NULL);
1234 axe_setmulti(sc);
1235 } else if (!(ifp->if_flags & IFF_RUNNING))
1236 axe_init(sc);
1237 } else {
1238 if (ifp->if_flags & IFF_RUNNING)
1239 axe_stop(sc);
1240 }
1241 sc->axe_if_flags = ifp->if_flags;
1242 error = 0;
1243 break;
1244 case SIOCADDMULTI:
1245 case SIOCDELMULTI:
1246 #ifdef __NetBSD__
1247 error = (cmd == SIOCADDMULTI) ?
1248 ether_addmulti(ifr, &sc->axe_ec) :
1249 ether_delmulti(ifr, &sc->axe_ec);
1250 #else
1251 error = (cmd == SIOCADDMULTI) ?
1252 ether_addmulti(ifr, &sc->arpcom) :
1253 ether_delmulti(ifr, &sc->arpcom);
1254 #endif /* __NetBSD__ */
1255 if (error == ENETRESET) {
1256 /*
1257 * Multicast list has changed; set the hardware
1258 * filter accordingly.
1259 */
1260 axe_setmulti(sc);
1261 error = 0;
1262 }
1263 break;
1264 case SIOCGIFMEDIA:
1265 case SIOCSIFMEDIA:
1266 mii = GET_MII(sc);
1267 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, cmd);
1268 break;
1269
1270 default:
1271 error = EINVAL;
1272 break;
1273 }
1274
1275 return(error);
1276 }
1277
1278 /*
1279 * XXX
1280 * You can't call axe_txeof since the USB transfer has not
1281 * completed yet.
1282 */
1283 Static void
1284 axe_watchdog(struct ifnet *ifp)
1285 {
1286 struct axe_softc *sc;
1287 struct axe_chain *c;
1288 usbd_status stat;
1289 int s;
1290
1291 sc = ifp->if_softc;
1292
1293 ifp->if_oerrors++;
1294 printf("%s: watchdog timeout\n", USBDEVNAME(sc->axe_dev));
1295
1296 s = splusb();
1297 c = &sc->axe_cdata.axe_tx_chain[0];
1298 usbd_get_xfer_status(c->axe_xfer, NULL, NULL, NULL, &stat);
1299 axe_txeof(c->axe_xfer, c, stat);
1300
1301 if (ifp->if_snd.ifq_head != NULL)
1302 axe_start(ifp);
1303 splx(s);
1304 }
1305
1306 /*
1307 * Stop the adapter and free any mbufs allocated to the
1308 * RX and TX lists.
1309 */
1310 Static void
1311 axe_stop(struct axe_softc *sc)
1312 {
1313 usbd_status err;
1314 struct ifnet *ifp;
1315 int i;
1316
1317 axe_reset(sc);
1318
1319 ifp = GET_IFP(sc);
1320 ifp->if_timer = 0;
1321
1322 usb_uncallout(sc->axe_stat_ch, axe_tick, sc);
1323
1324 /* Stop transfers. */
1325 if (sc->axe_ep[AXE_ENDPT_RX] != NULL) {
1326 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]);
1327 if (err) {
1328 printf("%s: abort rx pipe failed: %s\n",
1329 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1330 }
1331 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_RX]);
1332 if (err) {
1333 printf("%s: close rx pipe failed: %s\n",
1334 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1335 }
1336 sc->axe_ep[AXE_ENDPT_RX] = NULL;
1337 }
1338
1339 if (sc->axe_ep[AXE_ENDPT_TX] != NULL) {
1340 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]);
1341 if (err) {
1342 printf("%s: abort tx pipe failed: %s\n",
1343 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1344 }
1345 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_TX]);
1346 if (err) {
1347 printf("%s: close tx pipe failed: %s\n",
1348 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1349 }
1350 sc->axe_ep[AXE_ENDPT_TX] = NULL;
1351 }
1352
1353 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL) {
1354 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
1355 if (err) {
1356 printf("%s: abort intr pipe failed: %s\n",
1357 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1358 }
1359 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
1360 if (err) {
1361 printf("%s: close intr pipe failed: %s\n",
1362 USBDEVNAME(sc->axe_dev), usbd_errstr(err));
1363 }
1364 sc->axe_ep[AXE_ENDPT_INTR] = NULL;
1365 }
1366
1367 /* Free RX resources. */
1368 for (i = 0; i < AXE_RX_LIST_CNT; i++) {
1369 if (sc->axe_cdata.axe_rx_chain[i].axe_mbuf != NULL) {
1370 m_freem(sc->axe_cdata.axe_rx_chain[i].axe_mbuf);
1371 sc->axe_cdata.axe_rx_chain[i].axe_mbuf = NULL;
1372 }
1373 if (sc->axe_cdata.axe_rx_chain[i].axe_xfer != NULL) {
1374 usbd_free_xfer(sc->axe_cdata.axe_rx_chain[i].axe_xfer);
1375 sc->axe_cdata.axe_rx_chain[i].axe_xfer = NULL;
1376 }
1377 }
1378
1379 /* Free TX resources. */
1380 for (i = 0; i < AXE_TX_LIST_CNT; i++) {
1381 if (sc->axe_cdata.axe_tx_chain[i].axe_mbuf != NULL) {
1382 m_freem(sc->axe_cdata.axe_tx_chain[i].axe_mbuf);
1383 sc->axe_cdata.axe_tx_chain[i].axe_mbuf = NULL;
1384 }
1385 if (sc->axe_cdata.axe_tx_chain[i].axe_xfer != NULL) {
1386 usbd_free_xfer(sc->axe_cdata.axe_tx_chain[i].axe_xfer);
1387 sc->axe_cdata.axe_tx_chain[i].axe_xfer = NULL;
1388 }
1389 }
1390
1391 sc->axe_link = 0;
1392 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
1393 }
1394
1395