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