1 /* $NetBSD: if_axe.c,v 1.29 2009/09/23 19:07:19 plunky Exp $ */ 2 3 /* 4 * Copyright (c) 1997, 1998, 1999, 2000-2003 5 * Bill Paul <wpaul@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@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@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.29 2009/09/23 19:07:19 plunky 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/mutex.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 141 #include <dev/usb/if_axereg.h> 142 143 #ifdef AXE_DEBUG 144 #define DPRINTF(x) do { if (axedebug) logprintf x; } while (0) 145 #define DPRINTFN(n,x) do { if (axedebug >= (n)) logprintf x; } while (0) 146 int axedebug = 0; 147 #else 148 #define DPRINTF(x) 149 #define DPRINTFN(n,x) 150 #endif 151 152 /* 153 * Various supported device vendors/products. 154 */ 155 Static const struct axe_type axe_devs[] = { 156 { { USB_VENDOR_ASIX, USB_PRODUCT_ASIX_AX88172}, 0 }, 157 { { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB2_TX }, 0}, 158 { { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DUBE100}, 0 }, 159 { { USB_VENDOR_LINKSYS2, USB_PRODUCT_LINKSYS2_USB200M}, 0 }, 160 { { USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUAU2KTX}, 0 }, 161 { { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA120}, 0 }, 162 { { USB_VENDOR_SITECOM, USB_PRODUCT_SITECOM_LN029}, 0 }, 163 { { USB_VENDOR_SYSTEMTALKS, USB_PRODUCT_SYSTEMTALKS_SGCX2UL}, 0 }, 164 }; 165 #define axe_lookup(v, p) ((const struct axe_type *)usb_lookup(axe_devs, v, p)) 166 167 int axe_match(device_t, cfdata_t, void *); 168 void axe_attach(device_t, device_t, void *); 169 int axe_detach(device_t, int); 170 int axe_activate(device_t, enum devact); 171 extern struct cfdriver axe_cd; 172 CFATTACH_DECL_NEW(axe, sizeof(struct axe_softc), axe_match, axe_attach, 173 axe_detach, axe_activate); 174 175 Static int axe_tx_list_init(struct axe_softc *); 176 Static int axe_rx_list_init(struct axe_softc *); 177 Static int axe_newbuf(struct axe_softc *, struct axe_chain *, struct mbuf *); 178 Static int axe_encap(struct axe_softc *, struct mbuf *, int); 179 Static void axe_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status); 180 Static void axe_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status); 181 Static void axe_tick(void *); 182 Static void axe_tick_task(void *); 183 #if 0 184 Static void axe_rxstart(struct ifnet *); 185 #endif 186 Static void axe_start(struct ifnet *); 187 Static int axe_ioctl(struct ifnet *, u_long, void *); 188 Static void axe_init(void *); 189 Static void axe_stop(struct axe_softc *); 190 Static void axe_watchdog(struct ifnet *); 191 Static int axe_miibus_readreg(device_t, int, int); 192 Static void axe_miibus_writereg(device_t, int, int, int); 193 Static void axe_miibus_statchg(device_t); 194 Static int axe_cmd(struct axe_softc *, int, int, int, void *); 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 mutex_enter(&sc->axe_mii_lock); 207 } 208 209 Static void 210 axe_unlock_mii(struct axe_softc *sc) 211 { 212 mutex_exit(&sc->axe_mii_lock); 213 if (--sc->axe_refcnt < 0) 214 usb_detach_wakeup((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 KASSERT(mutex_owned(&sc->axe_mii_lock)); 224 225 if (sc->axe_dying) 226 return(0); 227 228 if (AXE_CMD_DIR(cmd)) 229 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 230 else 231 req.bmRequestType = UT_READ_VENDOR_DEVICE; 232 req.bRequest = AXE_CMD_CMD(cmd); 233 USETW(req.wValue, val); 234 USETW(req.wIndex, index); 235 USETW(req.wLength, AXE_CMD_LEN(cmd)); 236 237 err = usbd_do_request(sc->axe_udev, &req, buf); 238 239 if (err) 240 return(-1); 241 242 return(0); 243 } 244 245 Static int 246 axe_miibus_readreg(device_t dev, int phy, int reg) 247 { 248 struct axe_softc *sc = device_private(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 val = 0; 273 274 axe_lock_mii(sc); 275 axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL); 276 err = axe_cmd(sc, AXE_CMD_MII_READ_REG, reg, phy, (void *)&val); 277 axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL); 278 axe_unlock_mii(sc); 279 280 if (err) { 281 aprint_error_dev(sc->axe_dev, "read PHY failed\n"); 282 return(-1); 283 } 284 285 if (val) 286 sc->axe_phyaddrs[0] = phy; 287 288 return (le16toh(val)); 289 } 290 291 Static void 292 axe_miibus_writereg(device_t dev, int phy, int reg, int aval) 293 { 294 struct axe_softc *sc = device_private(dev); 295 usbd_status err; 296 u_int16_t val; 297 298 if (sc->axe_dying) 299 return; 300 301 val = htole16(aval); 302 axe_lock_mii(sc); 303 axe_cmd(sc, AXE_CMD_MII_OPMODE_SW, 0, 0, NULL); 304 err = axe_cmd(sc, AXE_CMD_MII_WRITE_REG, reg, phy, (void *)&val); 305 axe_cmd(sc, AXE_CMD_MII_OPMODE_HW, 0, 0, NULL); 306 axe_unlock_mii(sc); 307 308 if (err) { 309 aprint_error_dev(sc->axe_dev, "write PHY failed\n"); 310 return; 311 } 312 } 313 314 Static void 315 axe_miibus_statchg(device_t dev) 316 { 317 struct axe_softc *sc = device_private(dev); 318 struct mii_data *mii = GET_MII(sc); 319 int val, err; 320 321 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) 322 val = AXE_MEDIA_FULL_DUPLEX; 323 else 324 val = 0; 325 DPRINTF(("axe_miibus_statchg: val=0x%x\n", val)); 326 axe_lock_mii(sc); 327 err = axe_cmd(sc, AXE_CMD_WRITE_MEDIA, 0, val, NULL); 328 axe_unlock_mii(sc); 329 if (err) { 330 aprint_error_dev(sc->axe_dev, "media change failed\n"); 331 return; 332 } 333 } 334 335 Static void 336 axe_setmulti(struct axe_softc *sc) 337 { 338 struct ifnet *ifp; 339 struct ether_multi *enm; 340 struct ether_multistep step; 341 u_int32_t h = 0; 342 u_int16_t rxmode; 343 u_int8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; 344 345 if (sc->axe_dying) 346 return; 347 348 ifp = GET_IFP(sc); 349 350 axe_lock_mii(sc); 351 axe_cmd(sc, AXE_CMD_RXCTL_READ, 0, 0, (void *)&rxmode); 352 rxmode = le16toh(rxmode); 353 354 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) { 355 allmulti: 356 rxmode |= AXE_RXCMD_ALLMULTI; 357 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); 358 return; 359 } else 360 rxmode &= ~AXE_RXCMD_ALLMULTI; 361 362 /* now program new ones */ 363 #if defined(__NetBSD__) 364 ETHER_FIRST_MULTI(step, &sc->axe_ec, enm); 365 #else 366 ETHER_FIRST_MULTI(step, &sc->arpcom, enm); 367 #endif 368 while (enm != NULL) { 369 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 370 ETHER_ADDR_LEN) != 0) 371 goto allmulti; 372 373 h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26; 374 hashtbl[h / 8] |= 1 << (h % 8); 375 ETHER_NEXT_MULTI(step, enm); 376 } 377 378 ifp->if_flags &= ~IFF_ALLMULTI; 379 axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, (void *)&hashtbl); 380 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); 381 axe_unlock_mii(sc); 382 return; 383 } 384 385 Static void 386 axe_reset(struct axe_softc *sc) 387 { 388 if (sc->axe_dying) 389 return; 390 /* XXX What to reset? */ 391 392 /* Wait a little while for the chip to get its brains in order. */ 393 DELAY(1000); 394 return; 395 } 396 397 /* 398 * Probe for a AX88172 chip. 399 */ 400 int 401 axe_match(device_t parent, cfdata_t match, void *aux) 402 { 403 struct usb_attach_arg *uaa = aux; 404 405 return (axe_lookup(uaa->vendor, uaa->product) != NULL ? 406 UMATCH_VENDOR_PRODUCT : UMATCH_NONE); 407 } 408 409 /* 410 * Attach the interface. Allocate softc structures, do ifmedia 411 * setup and ethernet/BPF attach. 412 */ 413 void 414 axe_attach(device_t parent, device_t self, void *aux) 415 { 416 struct axe_softc *sc = device_private(self); 417 struct usb_attach_arg *uaa = aux; 418 usbd_device_handle dev = uaa->device; 419 usbd_status err; 420 usb_interface_descriptor_t *id; 421 usb_endpoint_descriptor_t *ed; 422 struct mii_data *mii; 423 u_char eaddr[ETHER_ADDR_LEN]; 424 char *devinfop; 425 const char *devname = device_xname(self); 426 struct ifnet *ifp; 427 int i, s; 428 429 sc->axe_dev = self; 430 431 aprint_naive("\n"); 432 aprint_normal("\n"); 433 434 devinfop = usbd_devinfo_alloc(dev, 0); 435 aprint_normal_dev(self, "%s\n", devinfop); 436 usbd_devinfo_free(devinfop); 437 438 err = usbd_set_config_no(dev, AXE_CONFIG_NO, 1); 439 if (err) { 440 aprint_error_dev(self, "getting interface handle failed\n"); 441 return; 442 } 443 444 usb_init_task(&sc->axe_tick_task, axe_tick_task, sc); 445 mutex_init(&sc->axe_mii_lock, MUTEX_DEFAULT, IPL_NONE); 446 usb_init_task(&sc->axe_stop_task, (void (*)(void *))axe_stop, sc); 447 448 err = usbd_device2interface_handle(dev, AXE_IFACE_IDX, &sc->axe_iface); 449 if (err) { 450 aprint_error_dev(self, "getting interface handle failed\n"); 451 return; 452 } 453 454 sc->axe_udev = dev; 455 sc->axe_product = uaa->product; 456 sc->axe_vendor = uaa->vendor; 457 458 id = usbd_get_interface_descriptor(sc->axe_iface); 459 460 /* Find endpoints. */ 461 for (i = 0; i < id->bNumEndpoints; i++) { 462 ed = usbd_interface2endpoint_descriptor(sc->axe_iface, i); 463 if (!ed) { 464 aprint_error_dev(self, "couldn't get ep %d\n", i); 465 return; 466 } 467 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 468 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 469 sc->axe_ed[AXE_ENDPT_RX] = ed->bEndpointAddress; 470 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 471 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 472 sc->axe_ed[AXE_ENDPT_TX] = ed->bEndpointAddress; 473 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 474 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { 475 sc->axe_ed[AXE_ENDPT_INTR] = ed->bEndpointAddress; 476 } 477 } 478 479 s = splnet(); 480 481 /* 482 * Get station address. 483 */ 484 axe_lock_mii(sc); 485 axe_cmd(sc, AXE_CMD_READ_NODEID, 0, 0, &eaddr); 486 487 /* 488 * Load IPG values and PHY indexes. 489 */ 490 axe_cmd(sc, AXE_CMD_READ_IPG012, 0, 0, (void *)&sc->axe_ipgs); 491 axe_cmd(sc, AXE_CMD_READ_PHYID, 0, 0, (void *)&sc->axe_phyaddrs); 492 axe_unlock_mii(sc); 493 494 /* 495 * Work around broken adapters that appear to lie about 496 * their PHY addresses. 497 */ 498 sc->axe_phyaddrs[0] = sc->axe_phyaddrs[1] = 0xFF; 499 500 /* 501 * An ASIX chip was detected. Inform the world. 502 */ 503 aprint_normal_dev(self, "Ethernet address %s\n", 504 ether_sprintf(eaddr)); 505 506 /* Initialize interface info.*/ 507 ifp = GET_IFP(sc); 508 ifp->if_softc = sc; 509 strncpy(ifp->if_xname, devname, IFNAMSIZ); 510 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 511 ifp->if_ioctl = axe_ioctl; 512 ifp->if_start = axe_start; 513 514 ifp->if_watchdog = axe_watchdog; 515 516 /* ifp->if_baudrate = 10000000; */ 517 /* ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;*/ 518 519 IFQ_SET_READY(&ifp->if_snd); 520 521 /* Initialize MII/media info. */ 522 mii = &sc->axe_mii; 523 mii->mii_ifp = ifp; 524 mii->mii_readreg = axe_miibus_readreg; 525 mii->mii_writereg = axe_miibus_writereg; 526 mii->mii_statchg = axe_miibus_statchg; 527 mii->mii_flags = MIIF_AUTOTSLEEP; 528 529 sc->axe_ec.ec_mii = mii; 530 ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus); 531 mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0); 532 533 if (LIST_EMPTY(&mii->mii_phys)) { 534 ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL); 535 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE); 536 } else 537 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); 538 539 /* Attach the interface. */ 540 if_attach(ifp); 541 ether_ifattach(ifp, eaddr); 542 #if NRND > 0 543 rnd_attach_source(&sc->rnd_source, device_xname(sc->axe_dev), 544 RND_TYPE_NET, 0); 545 #endif 546 547 callout_init(&(sc->axe_stat_ch), 0); 548 549 sc->axe_attached = 1; 550 splx(s); 551 552 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->axe_udev, sc->axe_dev); 553 554 return; 555 } 556 557 int 558 axe_detach(device_t self, int flags) 559 { 560 struct axe_softc *sc = device_private(self); 561 int s; 562 struct ifnet *ifp = GET_IFP(sc); 563 564 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__)); 565 566 /* Detached before attached finished, so just bail out. */ 567 if (!sc->axe_attached) 568 return (0); 569 570 callout_stop(&(sc->axe_stat_ch)); 571 572 sc->axe_dying = 1; 573 574 ether_ifdetach(ifp); 575 576 if (sc->axe_ep[AXE_ENDPT_TX] != NULL) 577 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]); 578 if (sc->axe_ep[AXE_ENDPT_RX] != NULL) 579 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]); 580 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL) 581 usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]); 582 583 /* 584 * Remove any pending tasks. They cannot be executing because they run 585 * in the same thread as detach. 586 */ 587 usb_rem_task(sc->axe_udev, &sc->axe_tick_task); 588 usb_rem_task(sc->axe_udev, &sc->axe_stop_task); 589 590 s = splusb(); 591 592 if (--sc->axe_refcnt >= 0) { 593 /* Wait for processes to go away */ 594 usb_detach_wait((sc->axe_dev)); 595 } 596 597 if (ifp->if_flags & IFF_RUNNING) 598 axe_stop(sc); 599 600 #if defined(__NetBSD__) 601 #if NRND > 0 602 rnd_detach_source(&sc->rnd_source); 603 #endif 604 #endif /* __NetBSD__ */ 605 mii_detach(&sc->axe_mii, MII_PHY_ANY, MII_OFFSET_ANY); 606 ifmedia_delete_instance(&sc->axe_mii.mii_media, IFM_INST_ANY); 607 ether_ifdetach(ifp); 608 if_detach(ifp); 609 610 #ifdef DIAGNOSTIC 611 if (sc->axe_ep[AXE_ENDPT_TX] != NULL || 612 sc->axe_ep[AXE_ENDPT_RX] != NULL || 613 sc->axe_ep[AXE_ENDPT_INTR] != NULL) 614 aprint_debug_dev(self, "detach has active endpoints\n"); 615 #endif 616 617 sc->axe_attached = 0; 618 619 if (--sc->axe_refcnt >= 0) { 620 /* Wait for processes to go away. */ 621 usb_detach_wait((sc->axe_dev)); 622 } 623 splx(s); 624 625 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->axe_udev, sc->axe_dev); 626 627 return (0); 628 } 629 630 int 631 axe_activate(device_t self, enum devact act) 632 { 633 struct axe_softc *sc = device_private(self); 634 635 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__)); 636 637 switch (act) { 638 case DVACT_ACTIVATE: 639 return (EOPNOTSUPP); 640 break; 641 642 case DVACT_DEACTIVATE: 643 if_deactivate(&sc->axe_ec.ec_if); 644 sc->axe_dying = 1; 645 break; 646 } 647 return (0); 648 } 649 650 /* 651 * Initialize an RX descriptor and attach an MBUF cluster. 652 */ 653 Static int 654 axe_newbuf(struct axe_softc *sc, struct axe_chain *c, struct mbuf *m) 655 { 656 struct mbuf *m_new = NULL; 657 658 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev),__func__)); 659 660 if (m == NULL) { 661 MGETHDR(m_new, M_DONTWAIT, MT_DATA); 662 if (m_new == NULL) { 663 aprint_error_dev(sc->axe_dev, "no memory for rx list " 664 "-- packet dropped!\n"); 665 return (ENOBUFS); 666 } 667 668 MCLGET(m_new, M_DONTWAIT); 669 if (!(m_new->m_flags & M_EXT)) { 670 aprint_error_dev(sc->axe_dev, "no memory for rx list " 671 "-- packet dropped!\n"); 672 m_freem(m_new); 673 return (ENOBUFS); 674 } 675 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 676 } else { 677 m_new = m; 678 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 679 m_new->m_data = m_new->m_ext.ext_buf; 680 } 681 682 m_adj(m_new, ETHER_ALIGN); 683 c->axe_mbuf = m_new; 684 685 return (0); 686 } 687 688 Static int 689 axe_rx_list_init(struct axe_softc *sc) 690 { 691 struct axe_cdata *cd; 692 struct axe_chain *c; 693 int i; 694 695 DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__)); 696 697 cd = &sc->axe_cdata; 698 for (i = 0; i < AXE_RX_LIST_CNT; i++) { 699 c = &cd->axe_rx_chain[i]; 700 c->axe_sc = sc; 701 c->axe_idx = i; 702 if (axe_newbuf(sc, c, NULL) == ENOBUFS) 703 return (ENOBUFS); 704 if (c->axe_xfer == NULL) { 705 c->axe_xfer = usbd_alloc_xfer(sc->axe_udev); 706 if (c->axe_xfer == NULL) 707 return (ENOBUFS); 708 c->axe_buf = usbd_alloc_buffer(c->axe_xfer, AXE_BUFSZ); 709 if (c->axe_buf == NULL) { 710 usbd_free_xfer(c->axe_xfer); 711 return (ENOBUFS); 712 } 713 } 714 } 715 716 return (0); 717 } 718 719 Static int 720 axe_tx_list_init(struct axe_softc *sc) 721 { 722 struct axe_cdata *cd; 723 struct axe_chain *c; 724 int i; 725 726 DPRINTF(("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), __func__)); 727 728 cd = &sc->axe_cdata; 729 for (i = 0; i < AXE_TX_LIST_CNT; i++) { 730 c = &cd->axe_tx_chain[i]; 731 c->axe_sc = sc; 732 c->axe_idx = i; 733 c->axe_mbuf = NULL; 734 if (c->axe_xfer == NULL) { 735 c->axe_xfer = usbd_alloc_xfer(sc->axe_udev); 736 if (c->axe_xfer == NULL) 737 return (ENOBUFS); 738 c->axe_buf = usbd_alloc_buffer(c->axe_xfer, AXE_BUFSZ); 739 if (c->axe_buf == NULL) { 740 usbd_free_xfer(c->axe_xfer); 741 return (ENOBUFS); 742 } 743 } 744 } 745 746 return (0); 747 } 748 749 #if 0 750 Static void 751 axe_rxstart(struct ifnet *ifp) 752 { 753 struct axe_softc *sc; 754 struct axe_chain *c; 755 756 sc = ifp->if_softc; 757 axe_lock_mii(sc); 758 c = &sc->axe_cdata.axe_rx_chain[sc->axe_cdata.axe_rx_prod]; 759 760 if (axe_newbuf(sc, c, NULL) == ENOBUFS) { 761 ifp->if_ierrors++; 762 axe_unlock_mii(sc); 763 return; 764 } 765 766 /* Setup new transfer. */ 767 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX], 768 c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, USBD_SHORT_XFER_OK, 769 USBD_NO_TIMEOUT, axe_rxeof); 770 usbd_transfer(c->axe_xfer); 771 axe_unlock_mii(sc); 772 773 return; 774 } 775 #endif 776 777 /* 778 * A frame has been uploaded: pass the resulting mbuf chain up to 779 * the higher level protocols. 780 */ 781 Static void 782 axe_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) 783 { 784 struct axe_softc *sc; 785 struct axe_chain *c; 786 struct ifnet *ifp; 787 struct mbuf *m; 788 u_int32_t total_len; 789 int s; 790 791 c = priv; 792 sc = c->axe_sc; 793 ifp = GET_IFP(sc); 794 795 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->axe_dev),__func__)); 796 797 if (sc->axe_dying) 798 return; 799 800 if (!(ifp->if_flags & IFF_RUNNING)) 801 return; 802 803 if (status != USBD_NORMAL_COMPLETION) { 804 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) 805 return; 806 if (usbd_ratecheck(&sc->axe_rx_notice)) { 807 printf("%s: usb errors on rx: %s\n", 808 device_xname(sc->axe_dev), usbd_errstr(status)); 809 } 810 if (status == USBD_STALLED) 811 usbd_clear_endpoint_stall_async(sc->axe_ep[AXE_ENDPT_RX]); 812 goto done; 813 } 814 815 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); 816 817 m = c->axe_mbuf; 818 819 if (total_len <= sizeof(struct ether_header)) { 820 ifp->if_ierrors++; 821 goto done; 822 } 823 824 ifp->if_ipackets++; 825 m->m_pkthdr.rcvif = ifp; 826 m->m_pkthdr.len = m->m_len = total_len; 827 828 829 memcpy(mtod(c->axe_mbuf, char *), c->axe_buf, total_len); 830 831 /* No errors; receive the packet. */ 832 total_len -= ETHER_CRC_LEN + 4; 833 834 s = splnet(); 835 836 /* XXX ugly */ 837 if (axe_newbuf(sc, c, NULL) == ENOBUFS) { 838 ifp->if_ierrors++; 839 goto done1; 840 } 841 842 #if NBPFILTER > 0 843 if (ifp->if_bpf) 844 BPF_MTAP(ifp, m); 845 #endif 846 847 DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->axe_dev), 848 __func__, m->m_len)); 849 (*(ifp)->if_input)((ifp), (m)); 850 done1: 851 splx(s); 852 853 done: 854 855 /* Setup new transfer. */ 856 usbd_setup_xfer(xfer, sc->axe_ep[AXE_ENDPT_RX], 857 c, c->axe_buf, AXE_BUFSZ, 858 USBD_SHORT_XFER_OK | USBD_NO_COPY, 859 USBD_NO_TIMEOUT, axe_rxeof); 860 usbd_transfer(xfer); 861 862 DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->axe_dev), 863 __func__)); 864 return; 865 } 866 867 /* 868 * A frame was downloaded to the chip. It's safe for us to clean up 869 * the list buffers. 870 */ 871 872 Static void 873 axe_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, 874 usbd_status status) 875 { 876 struct axe_softc *sc; 877 struct axe_chain *c; 878 struct ifnet *ifp; 879 int s; 880 881 c = priv; 882 sc = c->axe_sc; 883 ifp = GET_IFP(sc); 884 885 if (sc->axe_dying) 886 return; 887 888 s = splnet(); 889 890 if (status != USBD_NORMAL_COMPLETION) { 891 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { 892 splx(s); 893 return; 894 } 895 ifp->if_oerrors++; 896 printf("%s: usb error on tx: %s\n", device_xname(sc->axe_dev), 897 usbd_errstr(status)); 898 if (status == USBD_STALLED) 899 usbd_clear_endpoint_stall_async(sc->axe_ep[AXE_ENDPT_TX]); 900 splx(s); 901 return; 902 } 903 904 ifp->if_timer = 0; 905 ifp->if_flags &= ~IFF_OACTIVE; 906 907 m_freem(c->axe_mbuf); 908 c->axe_mbuf = NULL; 909 910 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) 911 axe_start(ifp); 912 913 ifp->if_opackets++; 914 splx(s); 915 return; 916 } 917 918 Static void 919 axe_tick(void *xsc) 920 { 921 struct axe_softc *sc = xsc; 922 923 if (sc == NULL) 924 return; 925 926 DPRINTFN(0xff, ("%s: %s: enter\n", USBDEVNAME(sc->axe_dev), 927 __func__)); 928 929 if (sc->axe_dying) 930 return; 931 932 /* Perform periodic stuff in process context */ 933 usb_add_task(sc->axe_udev, &sc->axe_tick_task, USB_TASKQ_DRIVER); 934 935 } 936 937 Static void 938 axe_tick_task(void *xsc) 939 { 940 int s; 941 struct axe_softc *sc; 942 struct ifnet *ifp; 943 struct mii_data *mii; 944 945 sc = xsc; 946 947 if (sc == NULL) 948 return; 949 950 if (sc->axe_dying) 951 return; 952 953 ifp = GET_IFP(sc); 954 mii = GET_MII(sc); 955 if (mii == NULL) 956 return; 957 958 s = splnet(); 959 960 mii_tick(mii); 961 962 callout_reset(&(sc->axe_stat_ch), (hz), (axe_tick), (sc)); 963 964 splx(s); 965 } 966 967 Static int 968 axe_encap(struct axe_softc *sc, struct mbuf *m, int idx) 969 { 970 struct axe_chain *c; 971 usbd_status err; 972 973 c = &sc->axe_cdata.axe_tx_chain[idx]; 974 975 /* 976 * Copy the mbuf data into a contiguous buffer, leaving two 977 * bytes at the beginning to hold the frame length. 978 */ 979 m_copydata(m, 0, m->m_pkthdr.len, c->axe_buf); 980 c->axe_mbuf = m; 981 982 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_TX], 983 c, c->axe_buf, m->m_pkthdr.len, USBD_FORCE_SHORT_XFER, 10000, 984 axe_txeof); 985 986 /* Transmit */ 987 err = usbd_transfer(c->axe_xfer); 988 if (err != USBD_IN_PROGRESS) { 989 axe_stop(sc); 990 return(EIO); 991 } 992 993 sc->axe_cdata.axe_tx_cnt++; 994 995 return(0); 996 } 997 998 Static void 999 axe_start(struct ifnet *ifp) 1000 { 1001 struct axe_softc *sc; 1002 struct mbuf *m_head = NULL; 1003 1004 sc = ifp->if_softc; 1005 1006 if ((ifp->if_flags & (IFF_OACTIVE|IFF_RUNNING)) != IFF_RUNNING) 1007 return; 1008 1009 IF_DEQUEUE(&ifp->if_snd, m_head); 1010 if (m_head == NULL) { 1011 return; 1012 } 1013 1014 if (axe_encap(sc, m_head, 0)) { 1015 IF_PREPEND(&ifp->if_snd, m_head); 1016 ifp->if_flags |= IFF_OACTIVE; 1017 return; 1018 } 1019 1020 /* 1021 * If there's a BPF listener, bounce a copy of this frame 1022 * to him. 1023 */ 1024 #if NBPFILTER > 0 1025 if (ifp->if_bpf) 1026 BPF_MTAP(ifp, m_head); 1027 #endif 1028 1029 ifp->if_flags |= IFF_OACTIVE; 1030 1031 /* 1032 * Set a timeout in case the chip goes out to lunch. 1033 */ 1034 ifp->if_timer = 5; 1035 1036 return; 1037 } 1038 1039 Static void 1040 axe_init(void *xsc) 1041 { 1042 struct axe_softc *sc = xsc; 1043 struct ifnet *ifp = GET_IFP(sc); 1044 struct axe_chain *c; 1045 usbd_status err; 1046 int rxmode; 1047 int i, s; 1048 1049 if (ifp->if_flags & IFF_RUNNING) 1050 return; 1051 1052 s = splnet(); 1053 1054 /* 1055 * Cancel pending I/O and free all RX/TX buffers. 1056 */ 1057 axe_reset(sc); 1058 1059 /* Enable RX logic. */ 1060 1061 /* Init RX ring. */ 1062 if (axe_rx_list_init(sc) == ENOBUFS) { 1063 printf("%s: rx list init failed\n", device_xname(sc->axe_dev)); 1064 splx(s); 1065 return; 1066 } 1067 1068 /* Init TX ring. */ 1069 if (axe_tx_list_init(sc) == ENOBUFS) { 1070 printf("%s: tx list init failed\n", device_xname(sc->axe_dev)); 1071 splx(s); 1072 return; 1073 } 1074 1075 /* Set transmitter IPG values */ 1076 axe_lock_mii(sc); 1077 axe_cmd(sc, AXE_CMD_WRITE_IPG0, 0, sc->axe_ipgs[0], NULL); 1078 axe_cmd(sc, AXE_CMD_WRITE_IPG1, 0, sc->axe_ipgs[1], NULL); 1079 axe_cmd(sc, AXE_CMD_WRITE_IPG2, 0, sc->axe_ipgs[2], NULL); 1080 1081 /* Enable receiver, set RX mode */ 1082 rxmode = AXE_RXCMD_UNICAST|AXE_RXCMD_MULTICAST|AXE_RXCMD_ENABLE; 1083 1084 /* If we want promiscuous mode, set the allframes bit. */ 1085 if (ifp->if_flags & IFF_PROMISC) 1086 rxmode |= AXE_RXCMD_PROMISC; 1087 1088 if (ifp->if_flags & IFF_BROADCAST) 1089 rxmode |= AXE_RXCMD_BROADCAST; 1090 1091 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL); 1092 axe_unlock_mii(sc); 1093 1094 /* Load the multicast filter. */ 1095 axe_setmulti(sc); 1096 1097 /* Open RX and TX pipes. */ 1098 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_RX], 1099 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_RX]); 1100 if (err) { 1101 printf("%s: open rx pipe failed: %s\n", 1102 device_xname(sc->axe_dev), usbd_errstr(err)); 1103 splx(s); 1104 return; 1105 } 1106 1107 err = usbd_open_pipe(sc->axe_iface, sc->axe_ed[AXE_ENDPT_TX], 1108 USBD_EXCLUSIVE_USE, &sc->axe_ep[AXE_ENDPT_TX]); 1109 if (err) { 1110 printf("%s: open tx pipe failed: %s\n", 1111 device_xname(sc->axe_dev), usbd_errstr(err)); 1112 splx(s); 1113 return; 1114 } 1115 1116 /* Start up the receive pipe. */ 1117 for (i = 0; i < AXE_RX_LIST_CNT; i++) { 1118 c = &sc->axe_cdata.axe_rx_chain[i]; 1119 usbd_setup_xfer(c->axe_xfer, sc->axe_ep[AXE_ENDPT_RX], 1120 c, mtod(c->axe_mbuf, char *), AXE_BUFSZ, 1121 USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, axe_rxeof); 1122 usbd_transfer(c->axe_xfer); 1123 } 1124 1125 ifp->if_flags |= IFF_RUNNING; 1126 ifp->if_flags &= ~IFF_OACTIVE; 1127 1128 splx(s); 1129 1130 callout_init(&(sc->axe_stat_ch), 0); 1131 callout_reset(&(sc->axe_stat_ch), (hz), (axe_tick), (sc)); 1132 return; 1133 } 1134 1135 Static int 1136 axe_ioctl(struct ifnet *ifp, u_long cmd, void *data) 1137 { 1138 struct axe_softc *sc = ifp->if_softc; 1139 struct ifreq *ifr = (struct ifreq *)data; 1140 struct ifaddr *ifa = (struct ifaddr *)data; 1141 u_int16_t rxmode; 1142 int error = 0; 1143 1144 switch(cmd) { 1145 case SIOCINITIFADDR: 1146 ifp->if_flags |= IFF_UP; 1147 axe_init(sc); 1148 1149 switch (ifa->ifa_addr->sa_family) { 1150 #ifdef INET 1151 case AF_INET: 1152 #if defined(__NetBSD__) 1153 arp_ifinit(ifp, ifa); 1154 #else 1155 arp_ifinit(&sc->arpcom, ifa); 1156 #endif 1157 break; 1158 #endif /* INET */ 1159 } 1160 break; 1161 1162 case SIOCSIFMTU: 1163 if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > ETHERMTU) 1164 error = EINVAL; 1165 else if ((error = ifioctl_common(ifp, cmd, data)) == ENETRESET) 1166 error = 0; 1167 break; 1168 1169 case SIOCSIFFLAGS: 1170 if ((error = ifioctl_common(ifp, cmd, data)) != 0) 1171 break; 1172 if (ifp->if_flags & IFF_UP) { 1173 if (ifp->if_flags & IFF_RUNNING && 1174 ifp->if_flags & IFF_PROMISC && 1175 !(sc->axe_if_flags & IFF_PROMISC)) { 1176 1177 axe_lock_mii(sc); 1178 axe_cmd(sc, AXE_CMD_RXCTL_READ, 1179 0, 0, (void *)&rxmode); 1180 rxmode = le16toh(rxmode) | AXE_RXCMD_PROMISC; 1181 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 1182 0, rxmode, NULL); 1183 axe_unlock_mii(sc); 1184 1185 axe_setmulti(sc); 1186 } else if (ifp->if_flags & IFF_RUNNING && 1187 !(ifp->if_flags & IFF_PROMISC) && 1188 sc->axe_if_flags & IFF_PROMISC) { 1189 axe_lock_mii(sc); 1190 axe_cmd(sc, AXE_CMD_RXCTL_READ, 1191 0, 0, (void *)&rxmode); 1192 rxmode = le16toh(rxmode) & ~AXE_RXCMD_PROMISC; 1193 axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 1194 0, rxmode, NULL); 1195 axe_unlock_mii(sc); 1196 axe_setmulti(sc); 1197 } else if (!(ifp->if_flags & IFF_RUNNING)) 1198 axe_init(sc); 1199 } else { 1200 if (ifp->if_flags & IFF_RUNNING) 1201 axe_stop(sc); 1202 } 1203 sc->axe_if_flags = ifp->if_flags; 1204 error = 0; 1205 break; 1206 case SIOCADDMULTI: 1207 case SIOCDELMULTI: 1208 case SIOCGIFMEDIA: 1209 case SIOCSIFMEDIA: 1210 error = ether_ioctl(ifp, cmd, data); 1211 if (error == ENETRESET) { 1212 /* 1213 * Multicast list has changed; set the hardware 1214 * filter accordingly. 1215 */ 1216 if (ifp->if_flags & IFF_RUNNING) 1217 axe_setmulti(sc); 1218 error = 0; 1219 } 1220 break; 1221 default: 1222 error = ether_ioctl(ifp, cmd, data); 1223 break; 1224 } 1225 1226 return(error); 1227 } 1228 1229 /* 1230 * XXX 1231 * You can't call axe_txeof since the USB transfer has not 1232 * completed yet. 1233 */ 1234 Static void 1235 axe_watchdog(struct ifnet *ifp) 1236 { 1237 struct axe_softc *sc; 1238 struct axe_chain *c; 1239 usbd_status stat; 1240 int s; 1241 1242 sc = ifp->if_softc; 1243 1244 ifp->if_oerrors++; 1245 printf("%s: watchdog timeout\n", device_xname(sc->axe_dev)); 1246 1247 s = splusb(); 1248 c = &sc->axe_cdata.axe_tx_chain[0]; 1249 usbd_get_xfer_status(c->axe_xfer, NULL, NULL, NULL, &stat); 1250 axe_txeof(c->axe_xfer, c, stat); 1251 1252 if (ifp->if_snd.ifq_head != NULL) 1253 axe_start(ifp); 1254 splx(s); 1255 } 1256 1257 /* 1258 * Stop the adapter and free any mbufs allocated to the 1259 * RX and TX lists. 1260 */ 1261 Static void 1262 axe_stop(struct axe_softc *sc) 1263 { 1264 usbd_status err; 1265 struct ifnet *ifp; 1266 int i; 1267 1268 axe_reset(sc); 1269 1270 ifp = GET_IFP(sc); 1271 ifp->if_timer = 0; 1272 1273 callout_stop(&(sc->axe_stat_ch)); 1274 1275 /* Stop transfers. */ 1276 if (sc->axe_ep[AXE_ENDPT_RX] != NULL) { 1277 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_RX]); 1278 if (err) { 1279 printf("%s: abort rx pipe failed: %s\n", 1280 device_xname(sc->axe_dev), usbd_errstr(err)); 1281 } 1282 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_RX]); 1283 if (err) { 1284 printf("%s: close rx pipe failed: %s\n", 1285 device_xname(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_abort_pipe(sc->axe_ep[AXE_ENDPT_TX]); 1292 if (err) { 1293 printf("%s: abort tx pipe failed: %s\n", 1294 device_xname(sc->axe_dev), usbd_errstr(err)); 1295 } 1296 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_TX]); 1297 if (err) { 1298 printf("%s: close tx pipe failed: %s\n", 1299 device_xname(sc->axe_dev), usbd_errstr(err)); 1300 } 1301 sc->axe_ep[AXE_ENDPT_TX] = NULL; 1302 } 1303 1304 if (sc->axe_ep[AXE_ENDPT_INTR] != NULL) { 1305 err = usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]); 1306 if (err) { 1307 printf("%s: abort intr pipe failed: %s\n", 1308 device_xname(sc->axe_dev), usbd_errstr(err)); 1309 } 1310 err = usbd_close_pipe(sc->axe_ep[AXE_ENDPT_INTR]); 1311 if (err) { 1312 printf("%s: close intr pipe failed: %s\n", 1313 device_xname(sc->axe_dev), usbd_errstr(err)); 1314 } 1315 sc->axe_ep[AXE_ENDPT_INTR] = NULL; 1316 } 1317 1318 /* Free RX resources. */ 1319 for (i = 0; i < AXE_RX_LIST_CNT; i++) { 1320 if (sc->axe_cdata.axe_rx_chain[i].axe_mbuf != NULL) { 1321 m_freem(sc->axe_cdata.axe_rx_chain[i].axe_mbuf); 1322 sc->axe_cdata.axe_rx_chain[i].axe_mbuf = NULL; 1323 } 1324 if (sc->axe_cdata.axe_rx_chain[i].axe_xfer != NULL) { 1325 usbd_free_xfer(sc->axe_cdata.axe_rx_chain[i].axe_xfer); 1326 sc->axe_cdata.axe_rx_chain[i].axe_xfer = NULL; 1327 } 1328 } 1329 1330 /* Free TX resources. */ 1331 for (i = 0; i < AXE_TX_LIST_CNT; i++) { 1332 if (sc->axe_cdata.axe_tx_chain[i].axe_mbuf != NULL) { 1333 m_freem(sc->axe_cdata.axe_tx_chain[i].axe_mbuf); 1334 sc->axe_cdata.axe_tx_chain[i].axe_mbuf = NULL; 1335 } 1336 if (sc->axe_cdata.axe_tx_chain[i].axe_xfer != NULL) { 1337 usbd_free_xfer(sc->axe_cdata.axe_tx_chain[i].axe_xfer); 1338 sc->axe_cdata.axe_tx_chain[i].axe_xfer = NULL; 1339 } 1340 } 1341 1342 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 1343 } 1344 1345