1 /* $OpenBSD: if_kue.c,v 1.12 2001/07/08 23:38:08 fgsch Exp $ */ 2 /* $NetBSD: if_kue.c,v 1.40 2001/04/08 02:10:57 augustss Exp $ */ 3 /* 4 * Copyright (c) 1997, 1998, 1999, 2000 5 * Bill Paul <wpaul@ee.columbia.edu>. 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 * $FreeBSD: src/sys/dev/usb/if_kue.c,v 1.14 2000/01/14 01:36:15 wpaul Exp $ 35 */ 36 37 /* 38 * Kawasaki LSI KL5KUSB101B USB to ethernet adapter driver. 39 * 40 * Written by Bill Paul <wpaul@ee.columbia.edu> 41 * Electrical Engineering Department 42 * Columbia University, New York City 43 */ 44 45 /* 46 * The KLSI USB to ethernet adapter chip contains an USB serial interface, 47 * ethernet MAC and embedded microcontroller (called the QT Engine). 48 * The chip must have firmware loaded into it before it will operate. 49 * Packets are passed between the chip and host via bulk transfers. 50 * There is an interrupt endpoint mentioned in the software spec, however 51 * it's currently unused. This device is 10Mbps half-duplex only, hence 52 * there is no media selection logic. The MAC supports a 128 entry 53 * multicast filter, though the exact size of the filter can depend 54 * on the firmware. Curiously, while the software spec describes various 55 * ethernet statistics counters, my sample adapter and firmware combination 56 * claims not to support any statistics counters at all. 57 * 58 * Note that once we load the firmware in the device, we have to be 59 * careful not to load it again: if you restart your computer but 60 * leave the adapter attached to the USB controller, it may remain 61 * powered on and retain its firmware. In this case, we don't need 62 * to load the firmware a second time. 63 * 64 * Special thanks to Rob Furr for providing an ADS Technologies 65 * adapter for development and testing. No monkeys were harmed during 66 * the development of this driver. 67 */ 68 69 /* 70 * Ported to NetBSD and somewhat rewritten by Lennart Augustsson. 71 */ 72 73 #if defined(__NetBSD__) 74 #include "opt_inet.h" 75 #include "opt_ns.h" 76 #include "bpfilter.h" 77 #include "rnd.h" 78 #elif defined(__OpenBSD__) 79 #include "bpfilter.h" 80 #endif 81 82 #include <sys/param.h> 83 #include <sys/systm.h> 84 #include <sys/sockio.h> 85 #include <sys/mbuf.h> 86 #include <sys/malloc.h> 87 #include <sys/kernel.h> 88 #include <sys/socket.h> 89 #include <sys/device.h> 90 #include <sys/proc.h> 91 92 #include <sys/device.h> 93 #if NRND > 0 94 #include <sys/rnd.h> 95 #endif 96 97 #include <net/if.h> 98 #if defined(__NetBSD__) 99 #include <net/if_arp.h> 100 #endif 101 #include <net/if_dl.h> 102 103 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m)) 104 105 #if NBPFILTER > 0 106 #include <net/bpf.h> 107 #endif 108 109 #if defined(__NetBSD__) 110 #include <net/if_ether.h> 111 #ifdef INET 112 #include <netinet/in.h> 113 #include <netinet/if_inarp.h> 114 #endif 115 #endif /* defined (__NetBSD__) */ 116 117 #if defined(__OpenBSD__) 118 #ifdef INET 119 #include <netinet/in.h> 120 #include <netinet/in_systm.h> 121 #include <netinet/in_var.h> 122 #include <netinet/ip.h> 123 #include <netinet/if_ether.h> 124 #endif 125 #endif /* defined (__OpenBSD__) */ 126 127 #ifdef NS 128 #include <netns/ns.h> 129 #include <netns/ns_if.h> 130 #endif 131 132 #include <dev/usb/usb.h> 133 #include <dev/usb/usbdi.h> 134 #include <dev/usb/usbdi_util.h> 135 #include <dev/usb/usbdevs.h> 136 137 #include <dev/usb/if_kuereg.h> 138 #include <dev/usb/kue_fw.h> 139 140 #ifdef KUE_DEBUG 141 #define DPRINTF(x) if (kuedebug) logprintf x 142 #define DPRINTFN(n,x) if (kuedebug >= (n)) logprintf x 143 int kuedebug = 0; 144 #else 145 #define DPRINTF(x) 146 #define DPRINTFN(n,x) 147 #endif 148 149 /* 150 * Various supported device vendors/products. 151 */ 152 Static const struct kue_type kue_devs[] = { 153 { USB_VENDOR_AOX, USB_PRODUCT_AOX_USB101 }, 154 { USB_VENDOR_ADS, USB_PRODUCT_ADS_UBS10BT }, 155 { USB_VENDOR_ATEN, USB_PRODUCT_ATEN_UC10T }, 156 { USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_EA101 }, 157 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET }, 158 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET2 }, 159 { USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_ENET3 }, 160 { USB_VENDOR_ENTREGA, USB_PRODUCT_ENTREGA_E45 }, 161 { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C19250 }, 162 { USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460 }, 163 { USB_VENDOR_COREGA, USB_PRODUCT_COREGA_ETHER_USB_T }, 164 { USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650C }, 165 { USB_VENDOR_SMC, USB_PRODUCT_SMC_2102USB }, 166 { USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T }, 167 { USB_VENDOR_KLSI, USB_PRODUCT_KLSI_DUH3E10BT }, 168 { USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETT }, 169 { USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_URE450 }, 170 { 0, 0 } 171 }; 172 173 USB_DECLARE_DRIVER(kue); 174 175 Static int kue_tx_list_init(struct kue_softc *); 176 Static int kue_rx_list_init(struct kue_softc *); 177 Static int kue_newbuf(struct kue_softc *, struct kue_chain *,struct mbuf *); 178 Static int kue_send(struct kue_softc *, struct mbuf *, int); 179 Static int kue_open_pipes(struct kue_softc *); 180 Static void kue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status); 181 Static void kue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status); 182 Static void kue_start(struct ifnet *); 183 Static int kue_ioctl(struct ifnet *, u_long, caddr_t); 184 Static void kue_init(void *); 185 Static void kue_stop(struct kue_softc *); 186 Static void kue_watchdog(struct ifnet *); 187 188 Static void kue_setmulti(struct kue_softc *); 189 Static void kue_reset(struct kue_softc *); 190 191 Static usbd_status kue_ctl(struct kue_softc *, int, u_int8_t, 192 u_int16_t, void *, u_int32_t); 193 Static usbd_status kue_setword(struct kue_softc *, u_int8_t, u_int16_t); 194 Static int kue_load_fw(struct kue_softc *); 195 196 Static usbd_status 197 kue_setword(struct kue_softc *sc, u_int8_t breq, u_int16_t word) 198 { 199 usb_device_request_t req; 200 201 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 202 203 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 204 req.bRequest = breq; 205 USETW(req.wValue, word); 206 USETW(req.wIndex, 0); 207 USETW(req.wLength, 0); 208 209 return (usbd_do_request(sc->kue_udev, &req, NULL)); 210 } 211 212 Static usbd_status 213 kue_ctl(struct kue_softc *sc, int rw, u_int8_t breq, u_int16_t val, 214 void *data, u_int32_t len) 215 { 216 usb_device_request_t req; 217 218 DPRINTFN(10,("%s: %s: enter, len=%d\n", USBDEVNAME(sc->kue_dev), 219 __FUNCTION__, len)); 220 221 if (rw == KUE_CTL_WRITE) 222 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 223 else 224 req.bmRequestType = UT_READ_VENDOR_DEVICE; 225 226 req.bRequest = breq; 227 USETW(req.wValue, val); 228 USETW(req.wIndex, 0); 229 USETW(req.wLength, len); 230 231 return (usbd_do_request(sc->kue_udev, &req, data)); 232 } 233 234 Static int 235 kue_load_fw(struct kue_softc *sc) 236 { 237 usb_device_descriptor_t dd; 238 usbd_status err; 239 240 DPRINTFN(1,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __FUNCTION__)); 241 242 /* 243 * First, check if we even need to load the firmware. 244 * If the device was still attached when the system was 245 * rebooted, it may already have firmware loaded in it. 246 * If this is the case, we don't need to do it again. 247 * And in fact, if we try to load it again, we'll hang, 248 * so we have to avoid this condition if we don't want 249 * to look stupid. 250 * 251 * We can test this quickly by checking the bcdRevision 252 * code. The NIC will return a different revision code if 253 * it's probed while the firmware is still loaded and 254 * running. 255 */ 256 if (usbd_get_device_desc(sc->kue_udev, &dd)) 257 return (EIO); 258 if (UGETW(dd.bcdDevice) == KUE_WARM_REV) { 259 printf("%s: warm boot, no firmware download\n", 260 USBDEVNAME(sc->kue_dev)); 261 return (0); 262 } 263 264 printf("%s: cold boot, downloading firmware\n", 265 USBDEVNAME(sc->kue_dev)); 266 267 /* Load code segment */ 268 DPRINTFN(1,("%s: kue_load_fw: download code_seg\n", 269 USBDEVNAME(sc->kue_dev))); 270 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, 271 0, (void *)kue_code_seg, sizeof(kue_code_seg)); 272 if (err) { 273 printf("%s: failed to load code segment: %s\n", 274 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 275 return (EIO); 276 } 277 278 /* Load fixup segment */ 279 DPRINTFN(1,("%s: kue_load_fw: download fix_seg\n", 280 USBDEVNAME(sc->kue_dev))); 281 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, 282 0, (void *)kue_fix_seg, sizeof(kue_fix_seg)); 283 if (err) { 284 printf("%s: failed to load fixup segment: %s\n", 285 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 286 return (EIO); 287 } 288 289 /* Send trigger command. */ 290 DPRINTFN(1,("%s: kue_load_fw: download trig_seg\n", 291 USBDEVNAME(sc->kue_dev))); 292 err = kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SEND_SCAN, 293 0, (void *)kue_trig_seg, sizeof(kue_trig_seg)); 294 if (err) { 295 printf("%s: failed to load trigger segment: %s\n", 296 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 297 return (EIO); 298 } 299 300 usbd_delay_ms(sc->kue_udev, 10); 301 302 /* 303 * Reload device descriptor. 304 * Why? The chip without the firmware loaded returns 305 * one revision code. The chip with the firmware 306 * loaded and running returns a *different* revision 307 * code. This confuses the quirk mechanism, which is 308 * dependent on the revision data. 309 */ 310 (void)usbd_reload_device_desc(sc->kue_udev); 311 312 DPRINTFN(1,("%s: %s: done\n", USBDEVNAME(sc->kue_dev), __FUNCTION__)); 313 314 /* Reset the adapter. */ 315 kue_reset(sc); 316 317 return (0); 318 } 319 320 Static void 321 kue_setmulti(struct kue_softc *sc) 322 { 323 struct ifnet *ifp = GET_IFP(sc); 324 struct ether_multi *enm; 325 struct ether_multistep step; 326 int i; 327 328 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __FUNCTION__)); 329 330 if (ifp->if_flags & IFF_PROMISC) { 331 allmulti: 332 ifp->if_flags |= IFF_ALLMULTI; 333 sc->kue_rxfilt |= KUE_RXFILT_ALLMULTI; 334 sc->kue_rxfilt &= ~KUE_RXFILT_MULTICAST; 335 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); 336 return; 337 } 338 339 sc->kue_rxfilt &= ~KUE_RXFILT_ALLMULTI; 340 341 i = 0; 342 #if defined (__NetBSD__) 343 ETHER_FIRST_MULTI(step, &sc->kue_ec, enm); 344 #else 345 ETHER_FIRST_MULTI(step, &sc->arpcom, enm); 346 #endif 347 while (enm != NULL) { 348 if (i == KUE_MCFILTCNT(sc) || 349 memcmp(enm->enm_addrlo, enm->enm_addrhi, 350 ETHER_ADDR_LEN) != 0) 351 goto allmulti; 352 353 memcpy(KUE_MCFILT(sc, i), enm->enm_addrlo, ETHER_ADDR_LEN); 354 ETHER_NEXT_MULTI(step, enm); 355 i++; 356 } 357 358 ifp->if_flags &= ~IFF_ALLMULTI; 359 360 sc->kue_rxfilt |= KUE_RXFILT_MULTICAST; 361 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MCAST_FILTERS, 362 i, sc->kue_mcfilters, i * ETHER_ADDR_LEN); 363 364 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); 365 } 366 367 /* 368 * Issue a SET_CONFIGURATION command to reset the MAC. This should be 369 * done after the firmware is loaded into the adapter in order to 370 * bring it into proper operation. 371 */ 372 Static void 373 kue_reset(struct kue_softc *sc) 374 { 375 usbd_status err; 376 377 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __FUNCTION__)); 378 379 err = usbd_set_config_no(sc->kue_udev, KUE_CONFIG_NO, 1); 380 if (err) 381 printf("%s: reset failed\n", USBDEVNAME(sc->kue_dev)); 382 383 /* Wait a little while for the chip to get its brains in order. */ 384 usbd_delay_ms(sc->kue_udev, 10); 385 } 386 387 /* 388 * Probe for a KLSI chip. 389 */ 390 USB_MATCH(kue) 391 { 392 USB_MATCH_START(kue, uaa); 393 const struct kue_type *t; 394 395 DPRINTFN(25,("kue_match: enter\n")); 396 397 if (uaa->iface != NULL) 398 return (UMATCH_NONE); 399 400 for (t = kue_devs; t->kue_vid != 0; t++) 401 if (uaa->vendor == t->kue_vid && uaa->product == t->kue_did) 402 return (UMATCH_VENDOR_PRODUCT); 403 404 return (UMATCH_NONE); 405 } 406 407 /* 408 * Attach the interface. Allocate softc structures, do 409 * setup and ethernet/BPF attach. 410 */ 411 USB_ATTACH(kue) 412 { 413 USB_ATTACH_START(kue, sc, uaa); 414 char devinfo[1024]; 415 int s; 416 struct ifnet *ifp; 417 usbd_device_handle dev = uaa->device; 418 usbd_interface_handle iface; 419 usbd_status err; 420 usb_interface_descriptor_t *id; 421 usb_endpoint_descriptor_t *ed; 422 int i; 423 424 DPRINTFN(5,(" : kue_attach: sc=%p, dev=%p", sc, dev)); 425 426 usbd_devinfo(dev, 0, devinfo); 427 USB_ATTACH_SETUP; 428 printf("%s: %s\n", USBDEVNAME(sc->kue_dev), devinfo); 429 430 err = usbd_set_config_no(dev, KUE_CONFIG_NO, 1); 431 if (err) { 432 printf("%s: setting config no failed\n", 433 USBDEVNAME(sc->kue_dev)); 434 USB_ATTACH_ERROR_RETURN; 435 } 436 437 sc->kue_udev = dev; 438 sc->kue_product = uaa->product; 439 sc->kue_vendor = uaa->vendor; 440 441 /* Load the firmware into the NIC. */ 442 if (kue_load_fw(sc)) { 443 printf("%s: loading firmware failed\n", 444 USBDEVNAME(sc->kue_dev)); 445 USB_ATTACH_ERROR_RETURN; 446 } 447 448 err = usbd_device2interface_handle(dev, KUE_IFACE_IDX, &iface); 449 if (err) { 450 printf("%s: getting interface handle failed\n", 451 USBDEVNAME(sc->kue_dev)); 452 USB_ATTACH_ERROR_RETURN; 453 } 454 455 sc->kue_iface = iface; 456 id = usbd_get_interface_descriptor(iface); 457 458 /* Find endpoints. */ 459 for (i = 0; i < id->bNumEndpoints; i++) { 460 ed = usbd_interface2endpoint_descriptor(iface, i); 461 if (ed == NULL) { 462 printf("%s: couldn't get ep %d\n", 463 USBDEVNAME(sc->kue_dev), i); 464 USB_ATTACH_ERROR_RETURN; 465 } 466 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 467 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 468 sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress; 469 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 470 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 471 sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress; 472 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 473 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { 474 sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress; 475 } 476 } 477 478 if (sc->kue_ed[KUE_ENDPT_RX] == 0 || sc->kue_ed[KUE_ENDPT_TX] == 0) { 479 printf("%s: missing endpoint\n", USBDEVNAME(sc->kue_dev)); 480 USB_ATTACH_ERROR_RETURN; 481 } 482 483 /* Read ethernet descriptor */ 484 err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR, 485 0, &sc->kue_desc, sizeof(sc->kue_desc)); 486 if (err) { 487 printf("%s: could not read Ethernet descriptor\n", 488 USBDEVNAME(sc->kue_dev)); 489 USB_ATTACH_ERROR_RETURN; 490 } 491 492 sc->kue_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN, 493 M_USBDEV, M_NOWAIT); 494 if (sc->kue_mcfilters == NULL) { 495 printf("%s: no memory for multicast filter buffer\n", 496 USBDEVNAME(sc->kue_dev)); 497 USB_ATTACH_ERROR_RETURN; 498 } 499 500 s = splnet(); 501 502 /* 503 * A KLSI chip was detected. Inform the world. 504 */ 505 printf("%s: Ethernet address %s\n", USBDEVNAME(sc->kue_dev), 506 ether_sprintf(sc->kue_desc.kue_macaddr)); 507 508 #if defined(__OpenBSD__) 509 bcopy(sc->kue_desc.kue_macaddr, 510 (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN); 511 #endif 512 513 /* Initialize interface info.*/ 514 ifp = GET_IFP(sc); 515 ifp->if_softc = sc; 516 ifp->if_mtu = ETHERMTU; 517 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 518 ifp->if_ioctl = kue_ioctl; 519 ifp->if_start = kue_start; 520 ifp->if_watchdog = kue_watchdog; 521 IFQ_SET_READY(&ifp->if_snd); 522 strncpy(ifp->if_xname, USBDEVNAME(sc->kue_dev), IFNAMSIZ); 523 524 /* Attach the interface. */ 525 if_attach(ifp); 526 Ether_ifattach(ifp, sc->kue_desc.kue_macaddr); 527 #if NRND > 0 528 rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->kue_dev), 529 RND_TYPE_NET, 0); 530 #endif 531 532 sc->kue_attached = 1; 533 splx(s); 534 535 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->kue_udev, 536 USBDEV(sc->kue_dev)); 537 538 USB_ATTACH_SUCCESS_RETURN; 539 } 540 541 USB_DETACH(kue) 542 { 543 USB_DETACH_START(kue, sc); 544 struct ifnet *ifp = GET_IFP(sc); 545 int s; 546 547 s = splusb(); /* XXX why? */ 548 549 if (sc->kue_mcfilters != NULL) { 550 free(sc->kue_mcfilters, M_USBDEV); 551 sc->kue_mcfilters = NULL; 552 } 553 554 if (!sc->kue_attached) { 555 /* Detached before attached finished, so just bail out. */ 556 splx(s); 557 return (0); 558 } 559 560 if (ifp->if_flags & IFF_RUNNING) 561 kue_stop(sc); 562 563 #if defined(__NetBSD__) 564 #if NRND > 0 565 rnd_detach_source(&sc->rnd_source); 566 #endif 567 #if NBPFILTER > 0 568 bpfdetach(ifp); 569 #endif 570 #endif /* __NetBSD__ */ 571 ether_ifdetach(ifp); 572 573 if_detach(ifp); 574 575 #ifdef DIAGNOSTIC 576 if (sc->kue_ep[KUE_ENDPT_TX] != NULL || 577 sc->kue_ep[KUE_ENDPT_RX] != NULL || 578 sc->kue_ep[KUE_ENDPT_INTR] != NULL) 579 printf("%s: detach has active endpoints\n", 580 USBDEVNAME(sc->kue_dev)); 581 #endif 582 583 sc->kue_attached = 0; 584 splx(s); 585 586 return (0); 587 } 588 589 int 590 kue_activate(device_ptr_t self, enum devact act) 591 { 592 struct kue_softc *sc = (struct kue_softc *)self; 593 594 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __FUNCTION__)); 595 596 switch (act) { 597 case DVACT_ACTIVATE: 598 return (EOPNOTSUPP); 599 break; 600 601 case DVACT_DEACTIVATE: 602 #if defined(__NetBSD__) 603 /* Deactivate the interface. */ 604 if_deactivate(&sc->kue_ec.ec_if); 605 #endif 606 sc->kue_dying = 1; 607 break; 608 } 609 return (0); 610 } 611 612 /* 613 * Initialize an RX descriptor and attach an MBUF cluster. 614 */ 615 Static int 616 kue_newbuf(struct kue_softc *sc, struct kue_chain *c, struct mbuf *m) 617 { 618 struct mbuf *m_new = NULL; 619 620 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 621 622 if (m == NULL) { 623 MGETHDR(m_new, M_DONTWAIT, MT_DATA); 624 if (m_new == NULL) { 625 printf("%s: no memory for rx list " 626 "-- packet dropped!\n", USBDEVNAME(sc->kue_dev)); 627 return (ENOBUFS); 628 } 629 630 MCLGET(m_new, M_DONTWAIT); 631 if (!(m_new->m_flags & M_EXT)) { 632 printf("%s: no memory for rx list " 633 "-- packet dropped!\n", USBDEVNAME(sc->kue_dev)); 634 m_freem(m_new); 635 return (ENOBUFS); 636 } 637 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 638 } else { 639 m_new = m; 640 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 641 m_new->m_data = m_new->m_ext.ext_buf; 642 } 643 644 c->kue_mbuf = m_new; 645 646 return (0); 647 } 648 649 Static int 650 kue_rx_list_init(struct kue_softc *sc) 651 { 652 struct kue_cdata *cd; 653 struct kue_chain *c; 654 int i; 655 656 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __FUNCTION__)); 657 658 cd = &sc->kue_cdata; 659 for (i = 0; i < KUE_RX_LIST_CNT; i++) { 660 c = &cd->kue_rx_chain[i]; 661 c->kue_sc = sc; 662 c->kue_idx = i; 663 if (kue_newbuf(sc, c, NULL) == ENOBUFS) 664 return (ENOBUFS); 665 if (c->kue_xfer == NULL) { 666 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev); 667 if (c->kue_xfer == NULL) 668 return (ENOBUFS); 669 c->kue_buf = usbd_alloc_buffer(c->kue_xfer, KUE_BUFSZ); 670 if (c->kue_buf == NULL) 671 return (ENOBUFS); /* XXX free xfer */ 672 } 673 } 674 675 return (0); 676 } 677 678 Static int 679 kue_tx_list_init(struct kue_softc *sc) 680 { 681 struct kue_cdata *cd; 682 struct kue_chain *c; 683 int i; 684 685 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev), __FUNCTION__)); 686 687 cd = &sc->kue_cdata; 688 for (i = 0; i < KUE_TX_LIST_CNT; i++) { 689 c = &cd->kue_tx_chain[i]; 690 c->kue_sc = sc; 691 c->kue_idx = i; 692 c->kue_mbuf = NULL; 693 if (c->kue_xfer == NULL) { 694 c->kue_xfer = usbd_alloc_xfer(sc->kue_udev); 695 if (c->kue_xfer == NULL) 696 return (ENOBUFS); 697 c->kue_buf = usbd_alloc_buffer(c->kue_xfer, KUE_BUFSZ); 698 if (c->kue_buf == NULL) 699 return (ENOBUFS); 700 } 701 } 702 703 return (0); 704 } 705 706 /* 707 * A frame has been uploaded: pass the resulting mbuf chain up to 708 * the higher level protocols. 709 */ 710 Static void 711 kue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) 712 { 713 struct kue_chain *c = priv; 714 struct kue_softc *sc = c->kue_sc; 715 struct ifnet *ifp = GET_IFP(sc); 716 struct mbuf *m; 717 int total_len = 0; 718 int s; 719 720 DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->kue_dev), 721 __FUNCTION__, status)); 722 723 if (sc->kue_dying) 724 return; 725 726 if (!(ifp->if_flags & IFF_RUNNING)) 727 return; 728 729 if (status != USBD_NORMAL_COMPLETION) { 730 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) 731 return; 732 sc->kue_rx_errs++; 733 if (usbd_ratecheck(&sc->kue_rx_notice)) { 734 printf("%s: %u usb errors on rx: %s\n", 735 USBDEVNAME(sc->kue_dev), sc->kue_rx_errs, 736 usbd_errstr(status)); 737 sc->kue_rx_errs = 0; 738 } 739 if (status == USBD_STALLED) 740 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_RX]); 741 goto done; 742 } 743 744 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); 745 746 DPRINTFN(10,("%s: %s: total_len=%d len=%d\n", USBDEVNAME(sc->kue_dev), 747 __FUNCTION__, total_len, 748 UGETW(mtod(c->kue_mbuf, u_int8_t *)))); 749 750 if (total_len <= 1) 751 goto done; 752 753 m = c->kue_mbuf; 754 /* copy data to mbuf */ 755 memcpy(mtod(m, char*), c->kue_buf, total_len); 756 757 /* No errors; receive the packet. */ 758 total_len = UGETW(mtod(m, u_int8_t *)); 759 m_adj(m, sizeof(u_int16_t)); 760 761 if (total_len < sizeof(struct ether_header)) { 762 ifp->if_ierrors++; 763 goto done; 764 } 765 766 ifp->if_ipackets++; 767 m->m_pkthdr.len = m->m_len = total_len; 768 769 m->m_pkthdr.rcvif = ifp; 770 771 s = splnet(); 772 773 /* XXX ugly */ 774 if (kue_newbuf(sc, c, NULL) == ENOBUFS) { 775 ifp->if_ierrors++; 776 goto done1; 777 } 778 779 #if NBPFILTER > 0 780 /* 781 * Handle BPF listeners. Let the BPF user see the packet, but 782 * don't pass it up to the ether_input() layer unless it's 783 * a broadcast packet, multicast packet, matches our ethernet 784 * address or the interface is in promiscuous mode. 785 */ 786 if (ifp->if_bpf) 787 BPF_MTAP(ifp, m); 788 #endif 789 790 DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->kue_dev), 791 __FUNCTION__, m->m_len)); 792 IF_INPUT(ifp, m); 793 done1: 794 splx(s); 795 796 done: 797 798 /* Setup new transfer. */ 799 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX], 800 c, c->kue_buf, KUE_BUFSZ, USBD_SHORT_XFER_OK | USBD_NO_COPY, 801 USBD_NO_TIMEOUT, kue_rxeof); 802 usbd_transfer(c->kue_xfer); 803 804 DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->kue_dev), 805 __FUNCTION__)); 806 } 807 808 /* 809 * A frame was downloaded to the chip. It's safe for us to clean up 810 * the list buffers. 811 */ 812 813 Static void 814 kue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) 815 { 816 struct kue_chain *c = priv; 817 struct kue_softc *sc = c->kue_sc; 818 struct ifnet *ifp = GET_IFP(sc); 819 int s; 820 821 if (sc->kue_dying) 822 return; 823 824 s = splnet(); 825 826 DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->kue_dev), 827 __FUNCTION__, status)); 828 829 ifp->if_timer = 0; 830 ifp->if_flags &= ~IFF_OACTIVE; 831 832 if (status != USBD_NORMAL_COMPLETION) { 833 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { 834 splx(s); 835 return; 836 } 837 ifp->if_oerrors++; 838 printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->kue_dev), 839 usbd_errstr(status)); 840 if (status == USBD_STALLED) 841 usbd_clear_endpoint_stall(sc->kue_ep[KUE_ENDPT_TX]); 842 splx(s); 843 return; 844 } 845 846 ifp->if_opackets++; 847 848 m_freem(c->kue_mbuf); 849 c->kue_mbuf = NULL; 850 851 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) 852 kue_start(ifp); 853 854 splx(s); 855 } 856 857 Static int 858 kue_send(struct kue_softc *sc, struct mbuf *m, int idx) 859 { 860 int total_len; 861 struct kue_chain *c; 862 usbd_status err; 863 864 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 865 866 c = &sc->kue_cdata.kue_tx_chain[idx]; 867 868 /* 869 * Copy the mbuf data into a contiguous buffer, leaving two 870 * bytes at the beginning to hold the frame length. 871 */ 872 m_copydata(m, 0, m->m_pkthdr.len, c->kue_buf + 2); 873 c->kue_mbuf = m; 874 875 total_len = m->m_pkthdr.len + 2; 876 /* XXX what's this? */ 877 total_len += 64 - (total_len % 64); 878 879 /* Frame length is specified in the first 2 bytes of the buffer. */ 880 c->kue_buf[0] = (u_int8_t)m->m_pkthdr.len; 881 c->kue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8); 882 883 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_TX], 884 c, c->kue_buf, total_len, USBD_NO_COPY, USBD_DEFAULT_TIMEOUT, 885 kue_txeof); 886 887 /* Transmit */ 888 err = usbd_transfer(c->kue_xfer); 889 if (err != USBD_IN_PROGRESS) { 890 printf("%s: kue_send error=%s\n", USBDEVNAME(sc->kue_dev), 891 usbd_errstr(err)); 892 kue_stop(sc); 893 return (EIO); 894 } 895 896 sc->kue_cdata.kue_tx_cnt++; 897 898 return (0); 899 } 900 901 Static void 902 kue_start(struct ifnet *ifp) 903 { 904 struct kue_softc *sc = ifp->if_softc; 905 struct mbuf *m_head = NULL; 906 907 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 908 909 if (sc->kue_dying) 910 return; 911 912 if (ifp->if_flags & IFF_OACTIVE) 913 return; 914 915 IFQ_POLL(&ifp->if_snd, m_head); 916 if (m_head == NULL) 917 return; 918 919 if (kue_send(sc, m_head, 0)) { 920 ifp->if_flags |= IFF_OACTIVE; 921 return; 922 } 923 924 IFQ_DEQUEUE(&ifp->if_snd, m_head); 925 926 #if NBPFILTER > 0 927 /* 928 * If there's a BPF listener, bounce a copy of this frame 929 * to him. 930 */ 931 if (ifp->if_bpf) 932 BPF_MTAP(ifp, m_head); 933 #endif 934 935 ifp->if_flags |= IFF_OACTIVE; 936 937 /* 938 * Set a timeout in case the chip goes out to lunch. 939 */ 940 ifp->if_timer = 6; 941 } 942 943 Static void 944 kue_init(void *xsc) 945 { 946 struct kue_softc *sc = xsc; 947 struct ifnet *ifp = GET_IFP(sc); 948 int s; 949 u_char *eaddr; 950 951 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 952 953 if (ifp->if_flags & IFF_RUNNING) 954 return; 955 956 s = splnet(); 957 958 #if defined(__NetBSD__) 959 eaddr = LLADDR(ifp->if_sadl); 960 #else 961 eaddr = sc->arpcom.ac_enaddr; 962 #endif /* defined(__NetBSD__) */ 963 /* Set MAC address */ 964 kue_ctl(sc, KUE_CTL_WRITE, KUE_CMD_SET_MAC, 0, eaddr, ETHER_ADDR_LEN); 965 966 sc->kue_rxfilt = KUE_RXFILT_UNICAST | KUE_RXFILT_BROADCAST; 967 968 /* If we want promiscuous mode, set the allframes bit. */ 969 if (ifp->if_flags & IFF_PROMISC) 970 sc->kue_rxfilt |= KUE_RXFILT_PROMISC; 971 972 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, sc->kue_rxfilt); 973 974 /* I'm not sure how to tune these. */ 975 #if 0 976 /* 977 * Leave this one alone for now; setting it 978 * wrong causes lockups on some machines/controllers. 979 */ 980 kue_setword(sc, KUE_CMD_SET_SOFS, 1); 981 #endif 982 kue_setword(sc, KUE_CMD_SET_URB_SIZE, 64); 983 984 /* Init TX ring. */ 985 if (kue_tx_list_init(sc) == ENOBUFS) { 986 printf("%s: tx list init failed\n", USBDEVNAME(sc->kue_dev)); 987 splx(s); 988 return; 989 } 990 991 /* Init RX ring. */ 992 if (kue_rx_list_init(sc) == ENOBUFS) { 993 printf("%s: rx list init failed\n", USBDEVNAME(sc->kue_dev)); 994 splx(s); 995 return; 996 } 997 998 /* Load the multicast filter. */ 999 kue_setmulti(sc); 1000 1001 if (sc->kue_ep[KUE_ENDPT_RX] == NULL) { 1002 if (kue_open_pipes(sc)) { 1003 splx(s); 1004 return; 1005 } 1006 } 1007 1008 ifp->if_flags |= IFF_RUNNING; 1009 ifp->if_flags &= ~IFF_OACTIVE; 1010 1011 splx(s); 1012 } 1013 1014 Static int 1015 kue_open_pipes(struct kue_softc *sc) 1016 { 1017 usbd_status err; 1018 struct kue_chain *c; 1019 int i; 1020 1021 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 1022 1023 /* Open RX and TX pipes. */ 1024 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_RX], 1025 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_RX]); 1026 if (err) { 1027 printf("%s: open rx pipe failed: %s\n", 1028 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1029 return (EIO); 1030 } 1031 1032 err = usbd_open_pipe(sc->kue_iface, sc->kue_ed[KUE_ENDPT_TX], 1033 USBD_EXCLUSIVE_USE, &sc->kue_ep[KUE_ENDPT_TX]); 1034 if (err) { 1035 printf("%s: open tx pipe failed: %s\n", 1036 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1037 return (EIO); 1038 } 1039 1040 /* Start up the receive pipe. */ 1041 for (i = 0; i < KUE_RX_LIST_CNT; i++) { 1042 c = &sc->kue_cdata.kue_rx_chain[i]; 1043 usbd_setup_xfer(c->kue_xfer, sc->kue_ep[KUE_ENDPT_RX], 1044 c, c->kue_buf, KUE_BUFSZ, 1045 USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT, 1046 kue_rxeof); 1047 DPRINTFN(5,("%s: %s: start read\n", USBDEVNAME(sc->kue_dev), 1048 __FUNCTION__)); 1049 usbd_transfer(c->kue_xfer); 1050 } 1051 1052 return (0); 1053 } 1054 1055 Static int 1056 kue_ioctl(struct ifnet *ifp, u_long command, caddr_t data) 1057 { 1058 struct kue_softc *sc = ifp->if_softc; 1059 struct ifaddr *ifa = (struct ifaddr *)data; 1060 struct ifreq *ifr = (struct ifreq *)data; 1061 int s, error = 0; 1062 1063 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 1064 1065 if (sc->kue_dying) 1066 return (EIO); 1067 1068 #ifdef DIAGNOSTIC 1069 if (!curproc) { 1070 printf("%s: no proc!!\n", USBDEVNAME(sc->kue_dev)); 1071 return EIO; 1072 } 1073 #endif 1074 1075 s = splnet(); 1076 1077 switch(command) { 1078 case SIOCSIFADDR: 1079 ifp->if_flags |= IFF_UP; 1080 kue_init(sc); 1081 1082 switch (ifa->ifa_addr->sa_family) { 1083 #ifdef INET 1084 case AF_INET: 1085 #if defined(__NetBSD__) 1086 arp_ifinit(ifp, ifa); 1087 #else 1088 arp_ifinit(&sc->arpcom, ifa); 1089 #endif 1090 break; 1091 #endif /* INET */ 1092 #ifdef NS 1093 case AF_NS: 1094 { 1095 struct ns_addr *ina = &IA_SNS(ifa)->sns_addr; 1096 1097 if (ns_nullhost(*ina)) 1098 ina->x_host = *(union ns_host *) 1099 LLADDR(ifp->if_sadl); 1100 else 1101 memcpy(LLADDR(ifp->if_sadl), 1102 ina->x_host.c_host, 1103 ifp->if_addrlen); 1104 break; 1105 } 1106 #endif /* NS */ 1107 } 1108 break; 1109 1110 case SIOCSIFMTU: 1111 if (ifr->ifr_mtu > ETHERMTU) 1112 error = EINVAL; 1113 else 1114 ifp->if_mtu = ifr->ifr_mtu; 1115 break; 1116 1117 case SIOCSIFFLAGS: 1118 if (ifp->if_flags & IFF_UP) { 1119 if (ifp->if_flags & IFF_RUNNING && 1120 ifp->if_flags & IFF_PROMISC && 1121 !(sc->kue_if_flags & IFF_PROMISC)) { 1122 sc->kue_rxfilt |= KUE_RXFILT_PROMISC; 1123 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, 1124 sc->kue_rxfilt); 1125 } else if (ifp->if_flags & IFF_RUNNING && 1126 !(ifp->if_flags & IFF_PROMISC) && 1127 sc->kue_if_flags & IFF_PROMISC) { 1128 sc->kue_rxfilt &= ~KUE_RXFILT_PROMISC; 1129 kue_setword(sc, KUE_CMD_SET_PKT_FILTER, 1130 sc->kue_rxfilt); 1131 } else if (!(ifp->if_flags & IFF_RUNNING)) 1132 kue_init(sc); 1133 } else { 1134 if (ifp->if_flags & IFF_RUNNING) 1135 kue_stop(sc); 1136 } 1137 sc->kue_if_flags = ifp->if_flags; 1138 error = 0; 1139 break; 1140 case SIOCADDMULTI: 1141 case SIOCDELMULTI: 1142 kue_setmulti(sc); 1143 error = 0; 1144 break; 1145 default: 1146 error = EINVAL; 1147 break; 1148 } 1149 1150 splx(s); 1151 1152 return (error); 1153 } 1154 1155 Static void 1156 kue_watchdog(struct ifnet *ifp) 1157 { 1158 struct kue_softc *sc = ifp->if_softc; 1159 struct kue_chain *c; 1160 usbd_status stat; 1161 int s; 1162 1163 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 1164 1165 if (sc->kue_dying) 1166 return; 1167 1168 ifp->if_oerrors++; 1169 printf("%s: watchdog timeout\n", USBDEVNAME(sc->kue_dev)); 1170 1171 s = splusb(); 1172 c = &sc->kue_cdata.kue_tx_chain[0]; 1173 usbd_get_xfer_status(c->kue_xfer, NULL, NULL, NULL, &stat); 1174 kue_txeof(c->kue_xfer, c, stat); 1175 1176 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) 1177 kue_start(ifp); 1178 splx(s); 1179 } 1180 1181 /* 1182 * Stop the adapter and free any mbufs allocated to the 1183 * RX and TX lists. 1184 */ 1185 Static void 1186 kue_stop(struct kue_softc *sc) 1187 { 1188 usbd_status err; 1189 struct ifnet *ifp; 1190 int i; 1191 1192 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->kue_dev),__FUNCTION__)); 1193 1194 ifp = GET_IFP(sc); 1195 ifp->if_timer = 0; 1196 1197 /* Stop transfers. */ 1198 if (sc->kue_ep[KUE_ENDPT_RX] != NULL) { 1199 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_RX]); 1200 if (err) { 1201 printf("%s: abort rx pipe failed: %s\n", 1202 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1203 } 1204 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_RX]); 1205 if (err) { 1206 printf("%s: close rx pipe failed: %s\n", 1207 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1208 } 1209 sc->kue_ep[KUE_ENDPT_RX] = NULL; 1210 } 1211 1212 if (sc->kue_ep[KUE_ENDPT_TX] != NULL) { 1213 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_TX]); 1214 if (err) { 1215 printf("%s: abort tx pipe failed: %s\n", 1216 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1217 } 1218 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_TX]); 1219 if (err) { 1220 printf("%s: close tx pipe failed: %s\n", 1221 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1222 } 1223 sc->kue_ep[KUE_ENDPT_TX] = NULL; 1224 } 1225 1226 if (sc->kue_ep[KUE_ENDPT_INTR] != NULL) { 1227 err = usbd_abort_pipe(sc->kue_ep[KUE_ENDPT_INTR]); 1228 if (err) { 1229 printf("%s: abort intr pipe failed: %s\n", 1230 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1231 } 1232 err = usbd_close_pipe(sc->kue_ep[KUE_ENDPT_INTR]); 1233 if (err) { 1234 printf("%s: close intr pipe failed: %s\n", 1235 USBDEVNAME(sc->kue_dev), usbd_errstr(err)); 1236 } 1237 sc->kue_ep[KUE_ENDPT_INTR] = NULL; 1238 } 1239 1240 /* Free RX resources. */ 1241 for (i = 0; i < KUE_RX_LIST_CNT; i++) { 1242 if (sc->kue_cdata.kue_rx_chain[i].kue_mbuf != NULL) { 1243 m_freem(sc->kue_cdata.kue_rx_chain[i].kue_mbuf); 1244 sc->kue_cdata.kue_rx_chain[i].kue_mbuf = NULL; 1245 } 1246 if (sc->kue_cdata.kue_rx_chain[i].kue_xfer != NULL) { 1247 usbd_free_xfer(sc->kue_cdata.kue_rx_chain[i].kue_xfer); 1248 sc->kue_cdata.kue_rx_chain[i].kue_xfer = NULL; 1249 } 1250 } 1251 1252 /* Free TX resources. */ 1253 for (i = 0; i < KUE_TX_LIST_CNT; i++) { 1254 if (sc->kue_cdata.kue_tx_chain[i].kue_mbuf != NULL) { 1255 m_freem(sc->kue_cdata.kue_tx_chain[i].kue_mbuf); 1256 sc->kue_cdata.kue_tx_chain[i].kue_mbuf = NULL; 1257 } 1258 if (sc->kue_cdata.kue_tx_chain[i].kue_xfer != NULL) { 1259 usbd_free_xfer(sc->kue_cdata.kue_tx_chain[i].kue_xfer); 1260 sc->kue_cdata.kue_tx_chain[i].kue_xfer = NULL; 1261 } 1262 } 1263 1264 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 1265 } 1266