1 /* $NetBSD: if_aue.c,v 1.91 2005/05/30 04:21:39 christos Exp $ */ 2 /* 3 * Copyright (c) 1997, 1998, 1999, 2000 4 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Bill Paul. 17 * 4. Neither the name of the author nor the names of any co-contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 * $FreeBSD: src/sys/dev/usb/if_aue.c,v 1.11 2000/01/14 01:36:14 wpaul Exp $ 34 */ 35 36 /* 37 * ADMtek AN986 Pegasus and AN8511 Pegasus II USB to ethernet driver. 38 * Datasheet is available from http://www.admtek.com.tw. 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 Pegasus chip uses four USB "endpoints" to provide 10/100 ethernet 47 * support: the control endpoint for reading/writing registers, burst 48 * read endpoint for packet reception, burst write for packet transmission 49 * and one for "interrupts." The chip uses the same RX filter scheme 50 * as the other ADMtek ethernet parts: one perfect filter entry for the 51 * the station address and a 64-bit multicast hash table. The chip supports 52 * both MII and HomePNA attachments. 53 * 54 * Since the maximum data transfer speed of USB is supposed to be 12Mbps, 55 * you're never really going to get 100Mbps speeds from this device. I 56 * think the idea is to allow the device to connect to 10 or 100Mbps 57 * networks, not necessarily to provide 100Mbps performance. Also, since 58 * the controller uses an external PHY chip, it's possible that board 59 * designers might simply choose a 10Mbps PHY. 60 * 61 * Registers are accessed using usbd_do_request(). Packet transfers are 62 * done using usbd_transfer() and friends. 63 */ 64 65 /* 66 * Ported to NetBSD and somewhat rewritten by Lennart Augustsson. 67 */ 68 69 /* 70 * TODO: 71 * better error messages from rxstat 72 * split out if_auevar.h 73 * add thread to avoid register reads from interrupt context 74 * more error checks 75 * investigate short rx problem 76 * proper cleanup on errors 77 */ 78 79 #include <sys/cdefs.h> 80 __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.91 2005/05/30 04:21:39 christos Exp $"); 81 82 #if defined(__NetBSD__) 83 #include "opt_inet.h" 84 #include "opt_ns.h" 85 #include "bpfilter.h" 86 #include "rnd.h" 87 #elif defined(__OpenBSD__) 88 #include "bpfilter.h" 89 #endif /* defined(__OpenBSD__) */ 90 91 #include <sys/param.h> 92 #include <sys/systm.h> 93 #include <sys/sockio.h> 94 #include <sys/lock.h> 95 #include <sys/mbuf.h> 96 #include <sys/malloc.h> 97 #include <sys/kernel.h> 98 #include <sys/socket.h> 99 100 #include <sys/device.h> 101 #if NRND > 0 102 #include <sys/rnd.h> 103 #endif 104 105 #include <net/if.h> 106 #if defined(__NetBSD__) 107 #include <net/if_arp.h> 108 #endif 109 #include <net/if_dl.h> 110 #include <net/if_media.h> 111 112 #define BPF_MTAP(ifp, m) bpf_mtap((ifp)->if_bpf, (m)) 113 114 #if NBPFILTER > 0 115 #include <net/bpf.h> 116 #endif 117 118 #if defined(__NetBSD__) 119 #include <net/if_ether.h> 120 #ifdef INET 121 #include <netinet/in.h> 122 #include <netinet/if_inarp.h> 123 #endif 124 #endif /* defined(__NetBSD__) */ 125 126 #if defined(__OpenBSD__) 127 #ifdef INET 128 #include <netinet/in.h> 129 #include <netinet/in_systm.h> 130 #include <netinet/in_var.h> 131 #include <netinet/ip.h> 132 #include <netinet/if_ether.h> 133 #endif 134 #endif /* defined(__OpenBSD__) */ 135 136 #ifdef NS 137 #include <netns/ns.h> 138 #include <netns/ns_if.h> 139 #endif 140 141 #include <dev/mii/mii.h> 142 #include <dev/mii/miivar.h> 143 144 #include <dev/usb/usb.h> 145 #include <dev/usb/usbdi.h> 146 #include <dev/usb/usbdi_util.h> 147 #include <dev/usb/usbdevs.h> 148 149 #include <dev/usb/if_auereg.h> 150 151 #ifdef AUE_DEBUG 152 #define DPRINTF(x) if (auedebug) logprintf x 153 #define DPRINTFN(n,x) if (auedebug >= (n)) logprintf x 154 int auedebug = 0; 155 #else 156 #define DPRINTF(x) 157 #define DPRINTFN(n,x) 158 #endif 159 160 /* 161 * Various supported device vendors/products. 162 */ 163 struct aue_type { 164 struct usb_devno aue_dev; 165 u_int16_t aue_flags; 166 #define LSYS 0x0001 /* use Linksys reset */ 167 #define PNA 0x0002 /* has Home PNA */ 168 #define PII 0x0004 /* Pegasus II chip */ 169 }; 170 171 Static const struct aue_type aue_devs[] = { 172 {{ USB_VENDOR_3COM, USB_PRODUCT_3COM_3C460B}, PII }, 173 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX1}, PNA|PII }, 174 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX2}, PII }, 175 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_UFE1000}, LSYS }, 176 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX4}, PNA }, 177 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX5}, PNA }, 178 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX6}, PII }, 179 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX7}, PII }, 180 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX8}, PII }, 181 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX9}, PNA }, 182 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_XX10}, 0 }, 183 {{ USB_VENDOR_ABOCOM, USB_PRODUCT_ABOCOM_DSB650TX_PNA}, 0 }, 184 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_USB320_EC}, 0 }, 185 {{ USB_VENDOR_ACCTON, USB_PRODUCT_ACCTON_SS1001}, PII }, 186 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUS}, PNA }, 187 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII}, PII }, 188 {{ USB_VENDOR_ADMTEK, USB_PRODUCT_ADMTEK_PEGASUSII_2}, PII }, 189 {{ USB_VENDOR_AEI, USB_PRODUCT_AEI_USBTOLAN}, PII }, 190 {{ USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_USB2LAN}, PII }, 191 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USB100}, 0 }, 192 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBLP100}, PNA }, 193 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBEL100}, 0 }, 194 {{ USB_VENDOR_BILLIONTON, USB_PRODUCT_BILLIONTON_USBE100}, PII }, 195 {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_HNE200}, PII }, 196 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TX}, 0 }, 197 {{ USB_VENDOR_COREGA, USB_PRODUCT_COREGA_FETHER_USB_TXS},PII }, 198 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX4}, LSYS|PII }, 199 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX1}, LSYS }, 200 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX}, LSYS }, 201 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX_PNA}, PNA }, 202 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX3}, LSYS|PII }, 203 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650TX2}, LSYS|PII }, 204 {{ USB_VENDOR_DLINK, USB_PRODUCT_DLINK_DSB650}, 0 }, 205 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX0}, 0 }, 206 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX1}, LSYS }, 207 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX2}, 0 }, 208 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBTX3}, LSYS }, 209 {{ USB_VENDOR_ELECOM, USB_PRODUCT_ELECOM_LDUSBLTX}, PII }, 210 {{ USB_VENDOR_ELSA, USB_PRODUCT_ELSA_USB2ETHERNET}, 0 }, 211 {{ USB_VENDOR_HAWKING, USB_PRODUCT_HAWKING_UF100}, PII }, 212 {{ USB_VENDOR_HP, USB_PRODUCT_HP_HN210E}, PII }, 213 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTX}, 0 }, 214 {{ USB_VENDOR_IODATA, USB_PRODUCT_IODATA_USBETTXS}, PII }, 215 {{ USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_KNU101TX}, 0 }, 216 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX1}, LSYS|PII }, 217 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10T}, LSYS }, 218 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100TX}, LSYS }, 219 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB100H1}, LSYS|PNA }, 220 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TA}, LSYS }, 221 {{ USB_VENDOR_LINKSYS, USB_PRODUCT_LINKSYS_USB10TX2}, LSYS|PII }, 222 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX1}, 0 }, 223 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUATX5}, 0 }, 224 {{ USB_VENDOR_MELCO, USB_PRODUCT_MELCO_LUA2TX5}, PII }, 225 {{ USB_VENDOR_MICROSOFT, USB_PRODUCT_MICROSOFT_MN110}, PII }, 226 {{ USB_VENDOR_NETGEAR, USB_PRODUCT_NETGEAR_FA101}, PII }, 227 {{ USB_VENDOR_SIEMENS, USB_PRODUCT_SIEMENS_SPEEDSTREAM}, PII }, 228 {{ USB_VENDOR_SMARTBRIDGES, USB_PRODUCT_SMARTBRIDGES_SMARTNIC},PII }, 229 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2202USB}, 0 }, 230 {{ USB_VENDOR_SMC, USB_PRODUCT_SMC_2206USB}, PII }, 231 {{ USB_VENDOR_SOHOWARE, USB_PRODUCT_SOHOWARE_NUB100}, 0 }, 232 }; 233 #define aue_lookup(v, p) ((const struct aue_type *)usb_lookup(aue_devs, v, p)) 234 235 USB_DECLARE_DRIVER(aue); 236 237 Static void aue_reset_pegasus_II(struct aue_softc *sc); 238 Static int aue_tx_list_init(struct aue_softc *); 239 Static int aue_rx_list_init(struct aue_softc *); 240 Static int aue_newbuf(struct aue_softc *, struct aue_chain *, struct mbuf *); 241 Static int aue_send(struct aue_softc *, struct mbuf *, int); 242 Static void aue_intr(usbd_xfer_handle, usbd_private_handle, usbd_status); 243 Static void aue_rxeof(usbd_xfer_handle, usbd_private_handle, usbd_status); 244 Static void aue_txeof(usbd_xfer_handle, usbd_private_handle, usbd_status); 245 Static void aue_tick(void *); 246 Static void aue_tick_task(void *); 247 Static void aue_start(struct ifnet *); 248 Static int aue_ioctl(struct ifnet *, u_long, caddr_t); 249 Static void aue_init(void *); 250 Static void aue_stop(struct aue_softc *); 251 Static void aue_watchdog(struct ifnet *); 252 Static int aue_openpipes(struct aue_softc *); 253 Static int aue_ifmedia_upd(struct ifnet *); 254 Static void aue_ifmedia_sts(struct ifnet *, struct ifmediareq *); 255 256 Static int aue_eeprom_getword(struct aue_softc *, int); 257 Static void aue_read_mac(struct aue_softc *, u_char *); 258 Static int aue_miibus_readreg(device_ptr_t, int, int); 259 Static void aue_miibus_writereg(device_ptr_t, int, int, int); 260 Static void aue_miibus_statchg(device_ptr_t); 261 262 Static void aue_lock_mii(struct aue_softc *); 263 Static void aue_unlock_mii(struct aue_softc *); 264 265 Static void aue_setmulti(struct aue_softc *); 266 Static u_int32_t aue_crc(caddr_t); 267 Static void aue_reset(struct aue_softc *); 268 269 Static int aue_csr_read_1(struct aue_softc *, int); 270 Static int aue_csr_write_1(struct aue_softc *, int, int); 271 Static int aue_csr_read_2(struct aue_softc *, int); 272 Static int aue_csr_write_2(struct aue_softc *, int, int); 273 274 #define AUE_SETBIT(sc, reg, x) \ 275 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) | (x)) 276 277 #define AUE_CLRBIT(sc, reg, x) \ 278 aue_csr_write_1(sc, reg, aue_csr_read_1(sc, reg) & ~(x)) 279 280 Static int 281 aue_csr_read_1(struct aue_softc *sc, int reg) 282 { 283 usb_device_request_t req; 284 usbd_status err; 285 uByte val = 0; 286 287 if (sc->aue_dying) 288 return (0); 289 290 req.bmRequestType = UT_READ_VENDOR_DEVICE; 291 req.bRequest = AUE_UR_READREG; 292 USETW(req.wValue, 0); 293 USETW(req.wIndex, reg); 294 USETW(req.wLength, 1); 295 296 err = usbd_do_request(sc->aue_udev, &req, &val); 297 298 if (err) { 299 DPRINTF(("%s: aue_csr_read_1: reg=0x%x err=%s\n", 300 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err))); 301 return (0); 302 } 303 304 return (val); 305 } 306 307 Static int 308 aue_csr_read_2(struct aue_softc *sc, int reg) 309 { 310 usb_device_request_t req; 311 usbd_status err; 312 uWord val; 313 314 if (sc->aue_dying) 315 return (0); 316 317 req.bmRequestType = UT_READ_VENDOR_DEVICE; 318 req.bRequest = AUE_UR_READREG; 319 USETW(req.wValue, 0); 320 USETW(req.wIndex, reg); 321 USETW(req.wLength, 2); 322 323 err = usbd_do_request(sc->aue_udev, &req, &val); 324 325 if (err) { 326 DPRINTF(("%s: aue_csr_read_2: reg=0x%x err=%s\n", 327 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err))); 328 return (0); 329 } 330 331 return (UGETW(val)); 332 } 333 334 Static int 335 aue_csr_write_1(struct aue_softc *sc, int reg, int aval) 336 { 337 usb_device_request_t req; 338 usbd_status err; 339 uByte val; 340 341 if (sc->aue_dying) 342 return (0); 343 344 val = aval; 345 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 346 req.bRequest = AUE_UR_WRITEREG; 347 USETW(req.wValue, val); 348 USETW(req.wIndex, reg); 349 USETW(req.wLength, 1); 350 351 err = usbd_do_request(sc->aue_udev, &req, &val); 352 353 if (err) { 354 DPRINTF(("%s: aue_csr_write_1: reg=0x%x err=%s\n", 355 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err))); 356 return (-1); 357 } 358 359 return (0); 360 } 361 362 Static int 363 aue_csr_write_2(struct aue_softc *sc, int reg, int aval) 364 { 365 usb_device_request_t req; 366 usbd_status err; 367 uWord val; 368 369 if (sc->aue_dying) 370 return (0); 371 372 USETW(val, aval); 373 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 374 req.bRequest = AUE_UR_WRITEREG; 375 USETW(req.wValue, aval); 376 USETW(req.wIndex, reg); 377 USETW(req.wLength, 2); 378 379 err = usbd_do_request(sc->aue_udev, &req, &val); 380 381 if (err) { 382 DPRINTF(("%s: aue_csr_write_2: reg=0x%x err=%s\n", 383 USBDEVNAME(sc->aue_dev), reg, usbd_errstr(err))); 384 return (-1); 385 } 386 387 return (0); 388 } 389 390 /* 391 * Read a word of data stored in the EEPROM at address 'addr.' 392 */ 393 Static int 394 aue_eeprom_getword(struct aue_softc *sc, int addr) 395 { 396 int i; 397 398 aue_csr_write_1(sc, AUE_EE_REG, addr); 399 aue_csr_write_1(sc, AUE_EE_CTL, AUE_EECTL_READ); 400 401 for (i = 0; i < AUE_TIMEOUT; i++) { 402 if (aue_csr_read_1(sc, AUE_EE_CTL) & AUE_EECTL_DONE) 403 break; 404 } 405 406 if (i == AUE_TIMEOUT) { 407 printf("%s: EEPROM read timed out\n", 408 USBDEVNAME(sc->aue_dev)); 409 } 410 411 return (aue_csr_read_2(sc, AUE_EE_DATA)); 412 } 413 414 /* 415 * Read the MAC from the EEPROM. It's at offset 0. 416 */ 417 Static void 418 aue_read_mac(struct aue_softc *sc, u_char *dest) 419 { 420 int i; 421 int off = 0; 422 int word; 423 424 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 425 426 for (i = 0; i < 3; i++) { 427 word = aue_eeprom_getword(sc, off + i); 428 dest[2 * i] = (u_char)word; 429 dest[2 * i + 1] = (u_char)(word >> 8); 430 } 431 } 432 433 /* Get exclusive access to the MII registers */ 434 Static void 435 aue_lock_mii(struct aue_softc *sc) 436 { 437 sc->aue_refcnt++; 438 lockmgr(&sc->aue_mii_lock, LK_EXCLUSIVE, NULL); 439 } 440 441 Static void 442 aue_unlock_mii(struct aue_softc *sc) 443 { 444 lockmgr(&sc->aue_mii_lock, LK_RELEASE, NULL); 445 if (--sc->aue_refcnt < 0) 446 usb_detach_wakeup(USBDEV(sc->aue_dev)); 447 } 448 449 Static int 450 aue_miibus_readreg(device_ptr_t dev, int phy, int reg) 451 { 452 struct aue_softc *sc = USBGETSOFTC(dev); 453 int i; 454 u_int16_t val; 455 456 if (sc->aue_dying) { 457 #ifdef DIAGNOSTIC 458 printf("%s: dying\n", USBDEVNAME(sc->aue_dev)); 459 #endif 460 return 0; 461 } 462 463 #if 0 464 /* 465 * The Am79C901 HomePNA PHY actually contains 466 * two transceivers: a 1Mbps HomePNA PHY and a 467 * 10Mbps full/half duplex ethernet PHY with 468 * NWAY autoneg. However in the ADMtek adapter, 469 * only the 1Mbps PHY is actually connected to 470 * anything, so we ignore the 10Mbps one. It 471 * happens to be configured for MII address 3, 472 * so we filter that out. 473 */ 474 if (sc->aue_vendor == USB_VENDOR_ADMTEK && 475 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { 476 if (phy == 3) 477 return (0); 478 } 479 #endif 480 481 aue_lock_mii(sc); 482 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 483 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); 484 485 for (i = 0; i < AUE_TIMEOUT; i++) { 486 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 487 break; 488 } 489 490 if (i == AUE_TIMEOUT) { 491 printf("%s: MII read timed out\n", USBDEVNAME(sc->aue_dev)); 492 } 493 494 val = aue_csr_read_2(sc, AUE_PHY_DATA); 495 496 DPRINTFN(11,("%s: %s: phy=%d reg=%d => 0x%04x\n", 497 USBDEVNAME(sc->aue_dev), __func__, phy, reg, val)); 498 499 aue_unlock_mii(sc); 500 return (val); 501 } 502 503 Static void 504 aue_miibus_writereg(device_ptr_t dev, int phy, int reg, int data) 505 { 506 struct aue_softc *sc = USBGETSOFTC(dev); 507 int i; 508 509 #if 0 510 if (sc->aue_vendor == USB_VENDOR_ADMTEK && 511 sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { 512 if (phy == 3) 513 return; 514 } 515 #endif 516 517 DPRINTFN(11,("%s: %s: phy=%d reg=%d data=0x%04x\n", 518 USBDEVNAME(sc->aue_dev), __func__, phy, reg, data)); 519 520 aue_lock_mii(sc); 521 aue_csr_write_2(sc, AUE_PHY_DATA, data); 522 aue_csr_write_1(sc, AUE_PHY_ADDR, phy); 523 aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); 524 525 for (i = 0; i < AUE_TIMEOUT; i++) { 526 if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) 527 break; 528 } 529 530 if (i == AUE_TIMEOUT) { 531 printf("%s: MII read timed out\n", 532 USBDEVNAME(sc->aue_dev)); 533 } 534 aue_unlock_mii(sc); 535 } 536 537 Static void 538 aue_miibus_statchg(device_ptr_t dev) 539 { 540 struct aue_softc *sc = USBGETSOFTC(dev); 541 struct mii_data *mii = GET_MII(sc); 542 543 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 544 545 aue_lock_mii(sc); 546 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 547 548 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_100_TX) { 549 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 550 } else { 551 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_SPEEDSEL); 552 } 553 554 if ((mii->mii_media_active & IFM_GMASK) == IFM_FDX) 555 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 556 else 557 AUE_CLRBIT(sc, AUE_CTL1, AUE_CTL1_DUPLEX); 558 559 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_RX_ENB | AUE_CTL0_TX_ENB); 560 aue_unlock_mii(sc); 561 562 /* 563 * Set the LED modes on the LinkSys adapter. 564 * This turns on the 'dual link LED' bin in the auxmode 565 * register of the Broadcom PHY. 566 */ 567 if (!sc->aue_dying && (sc->aue_flags & LSYS)) { 568 u_int16_t auxmode; 569 auxmode = aue_miibus_readreg(dev, 0, 0x1b); 570 aue_miibus_writereg(dev, 0, 0x1b, auxmode | 0x04); 571 } 572 DPRINTFN(5,("%s: %s: exit\n", USBDEVNAME(sc->aue_dev), __func__)); 573 } 574 575 #define AUE_POLY 0xEDB88320 576 #define AUE_BITS 6 577 578 Static u_int32_t 579 aue_crc(caddr_t addr) 580 { 581 u_int32_t idx, bit, data, crc; 582 583 /* Compute CRC for the address value. */ 584 crc = 0xFFFFFFFF; /* initial value */ 585 586 for (idx = 0; idx < 6; idx++) { 587 for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) 588 crc = (crc >> 1) ^ (((crc ^ data) & 1) ? AUE_POLY : 0); 589 } 590 591 return (crc & ((1 << AUE_BITS) - 1)); 592 } 593 594 Static void 595 aue_setmulti(struct aue_softc *sc) 596 { 597 struct ifnet *ifp; 598 struct ether_multi *enm; 599 struct ether_multistep step; 600 u_int32_t h = 0, i; 601 602 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 603 604 ifp = GET_IFP(sc); 605 606 if (ifp->if_flags & IFF_PROMISC) { 607 allmulti: 608 ifp->if_flags |= IFF_ALLMULTI; 609 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 610 return; 611 } 612 613 AUE_CLRBIT(sc, AUE_CTL0, AUE_CTL0_ALLMULTI); 614 615 /* first, zot all the existing hash bits */ 616 for (i = 0; i < 8; i++) 617 aue_csr_write_1(sc, AUE_MAR0 + i, 0); 618 619 /* now program new ones */ 620 #if defined(__NetBSD__) 621 ETHER_FIRST_MULTI(step, &sc->aue_ec, enm); 622 #else 623 ETHER_FIRST_MULTI(step, &sc->arpcom, enm); 624 #endif 625 while (enm != NULL) { 626 if (memcmp(enm->enm_addrlo, 627 enm->enm_addrhi, ETHER_ADDR_LEN) != 0) 628 goto allmulti; 629 630 h = aue_crc(enm->enm_addrlo); 631 AUE_SETBIT(sc, AUE_MAR + (h >> 3), 1 << (h & 0x7)); 632 ETHER_NEXT_MULTI(step, enm); 633 } 634 635 ifp->if_flags &= ~IFF_ALLMULTI; 636 } 637 638 Static void 639 aue_reset_pegasus_II(struct aue_softc *sc) 640 { 641 /* Magic constants taken from Linux driver. */ 642 aue_csr_write_1(sc, AUE_REG_1D, 0); 643 aue_csr_write_1(sc, AUE_REG_7B, 2); 644 #if 0 645 if ((sc->aue_flags & HAS_HOME_PNA) && mii_mode) 646 aue_csr_write_1(sc, AUE_REG_81, 6); 647 else 648 #endif 649 aue_csr_write_1(sc, AUE_REG_81, 2); 650 } 651 652 Static void 653 aue_reset(struct aue_softc *sc) 654 { 655 int i; 656 657 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 658 659 AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); 660 661 for (i = 0; i < AUE_TIMEOUT; i++) { 662 if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) 663 break; 664 } 665 666 if (i == AUE_TIMEOUT) 667 printf("%s: reset failed\n", USBDEVNAME(sc->aue_dev)); 668 669 #if 0 670 /* XXX what is mii_mode supposed to be */ 671 if (sc->aue_mii_mode && (sc->aue_flags & PNA)) 672 aue_csr_write_1(sc, AUE_GPIO1, 0x34); 673 else 674 aue_csr_write_1(sc, AUE_GPIO1, 0x26); 675 #endif 676 677 /* 678 * The PHY(s) attached to the Pegasus chip may be held 679 * in reset until we flip on the GPIO outputs. Make sure 680 * to set the GPIO pins high so that the PHY(s) will 681 * be enabled. 682 * 683 * Note: We force all of the GPIO pins low first, *then* 684 * enable the ones we want. 685 */ 686 if (sc->aue_flags & LSYS) { 687 /* Grrr. LinkSys has to be different from everyone else. */ 688 aue_csr_write_1(sc, AUE_GPIO0, 689 AUE_GPIO_SEL0 | AUE_GPIO_SEL1); 690 } else { 691 aue_csr_write_1(sc, AUE_GPIO0, 692 AUE_GPIO_OUT0 | AUE_GPIO_SEL0); 693 } 694 aue_csr_write_1(sc, AUE_GPIO0, 695 AUE_GPIO_OUT0 | AUE_GPIO_SEL0 | AUE_GPIO_SEL1); 696 697 if (sc->aue_flags & PII) 698 aue_reset_pegasus_II(sc); 699 700 /* Wait a little while for the chip to get its brains in order. */ 701 delay(10000); /* XXX */ 702 } 703 704 /* 705 * Probe for a Pegasus chip. 706 */ 707 USB_MATCH(aue) 708 { 709 USB_MATCH_START(aue, uaa); 710 711 if (uaa->iface != NULL) 712 return (UMATCH_NONE); 713 714 return (aue_lookup(uaa->vendor, uaa->product) != NULL ? 715 UMATCH_VENDOR_PRODUCT : UMATCH_NONE); 716 } 717 718 /* 719 * Attach the interface. Allocate softc structures, do ifmedia 720 * setup and ethernet/BPF attach. 721 */ 722 USB_ATTACH(aue) 723 { 724 USB_ATTACH_START(aue, sc, uaa); 725 char *devinfop; 726 int s; 727 u_char eaddr[ETHER_ADDR_LEN]; 728 struct ifnet *ifp; 729 struct mii_data *mii; 730 usbd_device_handle dev = uaa->device; 731 usbd_interface_handle iface; 732 usbd_status err; 733 usb_interface_descriptor_t *id; 734 usb_endpoint_descriptor_t *ed; 735 int i; 736 737 DPRINTFN(5,(" : aue_attach: sc=%p", sc)); 738 739 devinfop = usbd_devinfo_alloc(uaa->device, 0); 740 USB_ATTACH_SETUP; 741 printf("%s: %s\n", USBDEVNAME(sc->aue_dev), devinfop); 742 usbd_devinfo_free(devinfop); 743 744 err = usbd_set_config_no(dev, AUE_CONFIG_NO, 1); 745 if (err) { 746 printf("%s: setting config no failed\n", 747 USBDEVNAME(sc->aue_dev)); 748 USB_ATTACH_ERROR_RETURN; 749 } 750 751 usb_init_task(&sc->aue_tick_task, aue_tick_task, sc); 752 usb_init_task(&sc->aue_stop_task, (void (*)(void *))aue_stop, sc); 753 lockinit(&sc->aue_mii_lock, PZERO, "auemii", 0, 0); 754 755 err = usbd_device2interface_handle(dev, AUE_IFACE_IDX, &iface); 756 if (err) { 757 printf("%s: getting interface handle failed\n", 758 USBDEVNAME(sc->aue_dev)); 759 USB_ATTACH_ERROR_RETURN; 760 } 761 762 sc->aue_flags = aue_lookup(uaa->vendor, uaa->product)->aue_flags; 763 764 sc->aue_udev = dev; 765 sc->aue_iface = iface; 766 sc->aue_product = uaa->product; 767 sc->aue_vendor = uaa->vendor; 768 769 id = usbd_get_interface_descriptor(iface); 770 771 /* Find endpoints. */ 772 for (i = 0; i < id->bNumEndpoints; i++) { 773 ed = usbd_interface2endpoint_descriptor(iface, i); 774 if (ed == NULL) { 775 printf("%s: couldn't get endpoint descriptor %d\n", 776 USBDEVNAME(sc->aue_dev), i); 777 USB_ATTACH_ERROR_RETURN; 778 } 779 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 780 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 781 sc->aue_ed[AUE_ENDPT_RX] = ed->bEndpointAddress; 782 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && 783 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { 784 sc->aue_ed[AUE_ENDPT_TX] = ed->bEndpointAddress; 785 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && 786 UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { 787 sc->aue_ed[AUE_ENDPT_INTR] = ed->bEndpointAddress; 788 } 789 } 790 791 if (sc->aue_ed[AUE_ENDPT_RX] == 0 || sc->aue_ed[AUE_ENDPT_TX] == 0 || 792 sc->aue_ed[AUE_ENDPT_INTR] == 0) { 793 printf("%s: missing endpoint\n", USBDEVNAME(sc->aue_dev)); 794 USB_ATTACH_ERROR_RETURN; 795 } 796 797 798 s = splnet(); 799 800 /* Reset the adapter. */ 801 aue_reset(sc); 802 803 /* 804 * Get station address from the EEPROM. 805 */ 806 aue_read_mac(sc, eaddr); 807 808 /* 809 * A Pegasus chip was detected. Inform the world. 810 */ 811 ifp = GET_IFP(sc); 812 printf("%s: Ethernet address %s\n", USBDEVNAME(sc->aue_dev), 813 ether_sprintf(eaddr)); 814 815 /* Initialize interface info.*/ 816 ifp->if_softc = sc; 817 ifp->if_mtu = ETHERMTU; 818 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 819 ifp->if_ioctl = aue_ioctl; 820 ifp->if_start = aue_start; 821 ifp->if_watchdog = aue_watchdog; 822 #if defined(__OpenBSD__) 823 ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; 824 #endif 825 strncpy(ifp->if_xname, USBDEVNAME(sc->aue_dev), IFNAMSIZ); 826 827 IFQ_SET_READY(&ifp->if_snd); 828 829 /* Initialize MII/media info. */ 830 mii = &sc->aue_mii; 831 mii->mii_ifp = ifp; 832 mii->mii_readreg = aue_miibus_readreg; 833 mii->mii_writereg = aue_miibus_writereg; 834 mii->mii_statchg = aue_miibus_statchg; 835 mii->mii_flags = MIIF_AUTOTSLEEP; 836 ifmedia_init(&mii->mii_media, 0, aue_ifmedia_upd, aue_ifmedia_sts); 837 mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0); 838 if (LIST_FIRST(&mii->mii_phys) == NULL) { 839 ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL); 840 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE); 841 } else 842 ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); 843 844 /* Attach the interface. */ 845 if_attach(ifp); 846 Ether_ifattach(ifp, eaddr); 847 #if NRND > 0 848 rnd_attach_source(&sc->rnd_source, USBDEVNAME(sc->aue_dev), 849 RND_TYPE_NET, 0); 850 #endif 851 852 usb_callout_init(sc->aue_stat_ch); 853 854 sc->aue_attached = 1; 855 splx(s); 856 857 usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->aue_udev, 858 USBDEV(sc->aue_dev)); 859 860 USB_ATTACH_SUCCESS_RETURN; 861 } 862 863 USB_DETACH(aue) 864 { 865 USB_DETACH_START(aue, sc); 866 struct ifnet *ifp = GET_IFP(sc); 867 int s; 868 869 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 870 871 if (!sc->aue_attached) { 872 /* Detached before attached finished, so just bail out. */ 873 return (0); 874 } 875 876 usb_uncallout(sc->aue_stat_ch, aue_tick, sc); 877 /* 878 * Remove any pending tasks. They cannot be executing because they run 879 * in the same thread as detach. 880 */ 881 usb_rem_task(sc->aue_udev, &sc->aue_tick_task); 882 usb_rem_task(sc->aue_udev, &sc->aue_stop_task); 883 884 s = splusb(); 885 886 if (ifp->if_flags & IFF_RUNNING) 887 aue_stop(sc); 888 889 #if defined(__NetBSD__) 890 #if NRND > 0 891 rnd_detach_source(&sc->rnd_source); 892 #endif 893 mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY); 894 ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY); 895 ether_ifdetach(ifp); 896 #endif /* __NetBSD__ */ 897 898 if_detach(ifp); 899 900 #ifdef DIAGNOSTIC 901 if (sc->aue_ep[AUE_ENDPT_TX] != NULL || 902 sc->aue_ep[AUE_ENDPT_RX] != NULL || 903 sc->aue_ep[AUE_ENDPT_INTR] != NULL) 904 printf("%s: detach has active endpoints\n", 905 USBDEVNAME(sc->aue_dev)); 906 #endif 907 908 sc->aue_attached = 0; 909 910 if (--sc->aue_refcnt >= 0) { 911 /* Wait for processes to go away. */ 912 usb_detach_wait(USBDEV(sc->aue_dev)); 913 } 914 splx(s); 915 916 usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->aue_udev, 917 USBDEV(sc->aue_dev)); 918 919 return (0); 920 } 921 922 int 923 aue_activate(device_ptr_t self, enum devact act) 924 { 925 struct aue_softc *sc = (struct aue_softc *)self; 926 927 DPRINTFN(2,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 928 929 switch (act) { 930 case DVACT_ACTIVATE: 931 return (EOPNOTSUPP); 932 break; 933 934 case DVACT_DEACTIVATE: 935 if_deactivate(&sc->aue_ec.ec_if); 936 sc->aue_dying = 1; 937 break; 938 } 939 return (0); 940 } 941 942 /* 943 * Initialize an RX descriptor and attach an MBUF cluster. 944 */ 945 Static int 946 aue_newbuf(struct aue_softc *sc, struct aue_chain *c, struct mbuf *m) 947 { 948 struct mbuf *m_new = NULL; 949 950 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__)); 951 952 if (m == NULL) { 953 MGETHDR(m_new, M_DONTWAIT, MT_DATA); 954 if (m_new == NULL) { 955 printf("%s: no memory for rx list " 956 "-- packet dropped!\n", USBDEVNAME(sc->aue_dev)); 957 return (ENOBUFS); 958 } 959 960 MCLGET(m_new, M_DONTWAIT); 961 if (!(m_new->m_flags & M_EXT)) { 962 printf("%s: no memory for rx list " 963 "-- packet dropped!\n", USBDEVNAME(sc->aue_dev)); 964 m_freem(m_new); 965 return (ENOBUFS); 966 } 967 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 968 } else { 969 m_new = m; 970 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 971 m_new->m_data = m_new->m_ext.ext_buf; 972 } 973 974 m_adj(m_new, ETHER_ALIGN); 975 c->aue_mbuf = m_new; 976 977 return (0); 978 } 979 980 Static int 981 aue_rx_list_init(struct aue_softc *sc) 982 { 983 struct aue_cdata *cd; 984 struct aue_chain *c; 985 int i; 986 987 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 988 989 cd = &sc->aue_cdata; 990 for (i = 0; i < AUE_RX_LIST_CNT; i++) { 991 c = &cd->aue_rx_chain[i]; 992 c->aue_sc = sc; 993 c->aue_idx = i; 994 if (aue_newbuf(sc, c, NULL) == ENOBUFS) 995 return (ENOBUFS); 996 if (c->aue_xfer == NULL) { 997 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev); 998 if (c->aue_xfer == NULL) 999 return (ENOBUFS); 1000 c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ); 1001 if (c->aue_buf == NULL) 1002 return (ENOBUFS); /* XXX free xfer */ 1003 } 1004 } 1005 1006 return (0); 1007 } 1008 1009 Static int 1010 aue_tx_list_init(struct aue_softc *sc) 1011 { 1012 struct aue_cdata *cd; 1013 struct aue_chain *c; 1014 int i; 1015 1016 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 1017 1018 cd = &sc->aue_cdata; 1019 for (i = 0; i < AUE_TX_LIST_CNT; i++) { 1020 c = &cd->aue_tx_chain[i]; 1021 c->aue_sc = sc; 1022 c->aue_idx = i; 1023 c->aue_mbuf = NULL; 1024 if (c->aue_xfer == NULL) { 1025 c->aue_xfer = usbd_alloc_xfer(sc->aue_udev); 1026 if (c->aue_xfer == NULL) 1027 return (ENOBUFS); 1028 c->aue_buf = usbd_alloc_buffer(c->aue_xfer, AUE_BUFSZ); 1029 if (c->aue_buf == NULL) 1030 return (ENOBUFS); 1031 } 1032 } 1033 1034 return (0); 1035 } 1036 1037 Static void 1038 aue_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) 1039 { 1040 struct aue_softc *sc = priv; 1041 struct ifnet *ifp = GET_IFP(sc); 1042 struct aue_intrpkt *p = &sc->aue_cdata.aue_ibuf; 1043 1044 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__)); 1045 1046 if (sc->aue_dying) 1047 return; 1048 1049 if (!(ifp->if_flags & IFF_RUNNING)) 1050 return; 1051 1052 if (status != USBD_NORMAL_COMPLETION) { 1053 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { 1054 return; 1055 } 1056 sc->aue_intr_errs++; 1057 if (usbd_ratecheck(&sc->aue_rx_notice)) { 1058 printf("%s: %u usb errors on intr: %s\n", 1059 USBDEVNAME(sc->aue_dev), sc->aue_intr_errs, 1060 usbd_errstr(status)); 1061 sc->aue_intr_errs = 0; 1062 } 1063 if (status == USBD_STALLED) 1064 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]); 1065 return; 1066 } 1067 1068 if (p->aue_txstat0) 1069 ifp->if_oerrors++; 1070 1071 if (p->aue_txstat0 & (AUE_TXSTAT0_LATECOLL | AUE_TXSTAT0_EXCESSCOLL)) 1072 ifp->if_collisions++; 1073 } 1074 1075 /* 1076 * A frame has been uploaded: pass the resulting mbuf chain up to 1077 * the higher level protocols. 1078 */ 1079 Static void 1080 aue_rxeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) 1081 { 1082 struct aue_chain *c = priv; 1083 struct aue_softc *sc = c->aue_sc; 1084 struct ifnet *ifp = GET_IFP(sc); 1085 struct mbuf *m; 1086 u_int32_t total_len; 1087 struct aue_rxpkt r; 1088 int s; 1089 1090 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__)); 1091 1092 if (sc->aue_dying) 1093 return; 1094 1095 if (!(ifp->if_flags & IFF_RUNNING)) 1096 return; 1097 1098 if (status != USBD_NORMAL_COMPLETION) { 1099 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) 1100 return; 1101 sc->aue_rx_errs++; 1102 if (usbd_ratecheck(&sc->aue_rx_notice)) { 1103 printf("%s: %u usb errors on rx: %s\n", 1104 USBDEVNAME(sc->aue_dev), sc->aue_rx_errs, 1105 usbd_errstr(status)); 1106 sc->aue_rx_errs = 0; 1107 } 1108 if (status == USBD_STALLED) 1109 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_RX]); 1110 goto done; 1111 } 1112 1113 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); 1114 1115 memcpy(mtod(c->aue_mbuf, char *), c->aue_buf, total_len); 1116 1117 if (total_len <= 4 + ETHER_CRC_LEN) { 1118 ifp->if_ierrors++; 1119 goto done; 1120 } 1121 1122 memcpy(&r, c->aue_buf + total_len - 4, sizeof(r)); 1123 1124 /* Turn off all the non-error bits in the rx status word. */ 1125 r.aue_rxstat &= AUE_RXSTAT_MASK; 1126 if (r.aue_rxstat) { 1127 ifp->if_ierrors++; 1128 goto done; 1129 } 1130 1131 /* No errors; receive the packet. */ 1132 m = c->aue_mbuf; 1133 total_len -= ETHER_CRC_LEN + 4; 1134 m->m_pkthdr.len = m->m_len = total_len; 1135 ifp->if_ipackets++; 1136 1137 m->m_pkthdr.rcvif = ifp; 1138 1139 s = splnet(); 1140 1141 /* XXX ugly */ 1142 if (aue_newbuf(sc, c, NULL) == ENOBUFS) { 1143 ifp->if_ierrors++; 1144 goto done1; 1145 } 1146 1147 #if NBPFILTER > 0 1148 /* 1149 * Handle BPF listeners. Let the BPF user see the packet, but 1150 * don't pass it up to the ether_input() layer unless it's 1151 * a broadcast packet, multicast packet, matches our ethernet 1152 * address or the interface is in promiscuous mode. 1153 */ 1154 if (ifp->if_bpf) 1155 BPF_MTAP(ifp, m); 1156 #endif 1157 1158 DPRINTFN(10,("%s: %s: deliver %d\n", USBDEVNAME(sc->aue_dev), 1159 __func__, m->m_len)); 1160 IF_INPUT(ifp, m); 1161 done1: 1162 splx(s); 1163 1164 done: 1165 1166 /* Setup new transfer. */ 1167 usbd_setup_xfer(xfer, sc->aue_ep[AUE_ENDPT_RX], 1168 c, c->aue_buf, AUE_BUFSZ, 1169 USBD_SHORT_XFER_OK | USBD_NO_COPY, 1170 USBD_NO_TIMEOUT, aue_rxeof); 1171 usbd_transfer(xfer); 1172 1173 DPRINTFN(10,("%s: %s: start rx\n", USBDEVNAME(sc->aue_dev), 1174 __func__)); 1175 } 1176 1177 /* 1178 * A frame was downloaded to the chip. It's safe for us to clean up 1179 * the list buffers. 1180 */ 1181 1182 Static void 1183 aue_txeof(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) 1184 { 1185 struct aue_chain *c = priv; 1186 struct aue_softc *sc = c->aue_sc; 1187 struct ifnet *ifp = GET_IFP(sc); 1188 int s; 1189 1190 if (sc->aue_dying) 1191 return; 1192 1193 s = splnet(); 1194 1195 DPRINTFN(10,("%s: %s: enter status=%d\n", USBDEVNAME(sc->aue_dev), 1196 __func__, status)); 1197 1198 ifp->if_timer = 0; 1199 ifp->if_flags &= ~IFF_OACTIVE; 1200 1201 if (status != USBD_NORMAL_COMPLETION) { 1202 if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) { 1203 splx(s); 1204 return; 1205 } 1206 ifp->if_oerrors++; 1207 printf("%s: usb error on tx: %s\n", USBDEVNAME(sc->aue_dev), 1208 usbd_errstr(status)); 1209 if (status == USBD_STALLED) 1210 usbd_clear_endpoint_stall(sc->aue_ep[AUE_ENDPT_TX]); 1211 splx(s); 1212 return; 1213 } 1214 1215 ifp->if_opackets++; 1216 1217 m_freem(c->aue_mbuf); 1218 c->aue_mbuf = NULL; 1219 1220 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) 1221 aue_start(ifp); 1222 1223 splx(s); 1224 } 1225 1226 Static void 1227 aue_tick(void *xsc) 1228 { 1229 struct aue_softc *sc = xsc; 1230 1231 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__)); 1232 1233 if (sc == NULL) 1234 return; 1235 1236 if (sc->aue_dying) 1237 return; 1238 1239 /* Perform periodic stuff in process context. */ 1240 usb_add_task(sc->aue_udev, &sc->aue_tick_task); 1241 } 1242 1243 Static void 1244 aue_tick_task(void *xsc) 1245 { 1246 struct aue_softc *sc = xsc; 1247 struct ifnet *ifp; 1248 struct mii_data *mii; 1249 int s; 1250 1251 DPRINTFN(15,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__)); 1252 1253 if (sc->aue_dying) 1254 return; 1255 1256 ifp = GET_IFP(sc); 1257 mii = GET_MII(sc); 1258 if (mii == NULL) 1259 return; 1260 1261 s = splnet(); 1262 1263 mii_tick(mii); 1264 if (!sc->aue_link) { 1265 mii_pollstat(mii); /* XXX FreeBSD has removed this call */ 1266 if (mii->mii_media_status & IFM_ACTIVE && 1267 IFM_SUBTYPE(mii->mii_media_active) != IFM_NONE) { 1268 DPRINTFN(2,("%s: %s: got link\n", 1269 USBDEVNAME(sc->aue_dev),__func__)); 1270 sc->aue_link++; 1271 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) 1272 aue_start(ifp); 1273 } 1274 } 1275 1276 usb_callout(sc->aue_stat_ch, hz, aue_tick, sc); 1277 1278 splx(s); 1279 } 1280 1281 Static int 1282 aue_send(struct aue_softc *sc, struct mbuf *m, int idx) 1283 { 1284 int total_len; 1285 struct aue_chain *c; 1286 usbd_status err; 1287 1288 DPRINTFN(10,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev),__func__)); 1289 1290 c = &sc->aue_cdata.aue_tx_chain[idx]; 1291 1292 /* 1293 * Copy the mbuf data into a contiguous buffer, leaving two 1294 * bytes at the beginning to hold the frame length. 1295 */ 1296 m_copydata(m, 0, m->m_pkthdr.len, c->aue_buf + 2); 1297 c->aue_mbuf = m; 1298 1299 /* 1300 * The ADMtek documentation says that the packet length is 1301 * supposed to be specified in the first two bytes of the 1302 * transfer, however it actually seems to ignore this info 1303 * and base the frame size on the bulk transfer length. 1304 */ 1305 c->aue_buf[0] = (u_int8_t)m->m_pkthdr.len; 1306 c->aue_buf[1] = (u_int8_t)(m->m_pkthdr.len >> 8); 1307 total_len = m->m_pkthdr.len + 2; 1308 1309 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_TX], 1310 c, c->aue_buf, total_len, USBD_FORCE_SHORT_XFER | USBD_NO_COPY, 1311 AUE_TX_TIMEOUT, aue_txeof); 1312 1313 /* Transmit */ 1314 err = usbd_transfer(c->aue_xfer); 1315 if (err != USBD_IN_PROGRESS) { 1316 printf("%s: aue_send error=%s\n", USBDEVNAME(sc->aue_dev), 1317 usbd_errstr(err)); 1318 /* Stop the interface from process context. */ 1319 usb_add_task(sc->aue_udev, &sc->aue_stop_task); 1320 return (EIO); 1321 } 1322 DPRINTFN(5,("%s: %s: send %d bytes\n", USBDEVNAME(sc->aue_dev), 1323 __func__, total_len)); 1324 1325 sc->aue_cdata.aue_tx_cnt++; 1326 1327 return (0); 1328 } 1329 1330 Static void 1331 aue_start(struct ifnet *ifp) 1332 { 1333 struct aue_softc *sc = ifp->if_softc; 1334 struct mbuf *m_head = NULL; 1335 1336 DPRINTFN(5,("%s: %s: enter, link=%d\n", USBDEVNAME(sc->aue_dev), 1337 __func__, sc->aue_link)); 1338 1339 if (sc->aue_dying) 1340 return; 1341 1342 if (!sc->aue_link) 1343 return; 1344 1345 if (ifp->if_flags & IFF_OACTIVE) 1346 return; 1347 1348 IFQ_POLL(&ifp->if_snd, m_head); 1349 if (m_head == NULL) 1350 return; 1351 1352 if (aue_send(sc, m_head, 0)) { 1353 ifp->if_flags |= IFF_OACTIVE; 1354 return; 1355 } 1356 1357 IFQ_DEQUEUE(&ifp->if_snd, m_head); 1358 1359 #if NBPFILTER > 0 1360 /* 1361 * If there's a BPF listener, bounce a copy of this frame 1362 * to him. 1363 */ 1364 if (ifp->if_bpf) 1365 BPF_MTAP(ifp, m_head); 1366 #endif 1367 1368 ifp->if_flags |= IFF_OACTIVE; 1369 1370 /* 1371 * Set a timeout in case the chip goes out to lunch. 1372 */ 1373 ifp->if_timer = 5; 1374 } 1375 1376 Static void 1377 aue_init(void *xsc) 1378 { 1379 struct aue_softc *sc = xsc; 1380 struct ifnet *ifp = GET_IFP(sc); 1381 struct mii_data *mii = GET_MII(sc); 1382 int i, s; 1383 u_char *eaddr; 1384 1385 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 1386 1387 if (sc->aue_dying) 1388 return; 1389 1390 if (ifp->if_flags & IFF_RUNNING) 1391 return; 1392 1393 s = splnet(); 1394 1395 /* 1396 * Cancel pending I/O and free all RX/TX buffers. 1397 */ 1398 aue_reset(sc); 1399 1400 #if defined(__OpenBSD__) 1401 eaddr = sc->arpcom.ac_enaddr; 1402 #elif defined(__NetBSD__) 1403 eaddr = LLADDR(ifp->if_sadl); 1404 #endif /* defined(__NetBSD__) */ 1405 for (i = 0; i < ETHER_ADDR_LEN; i++) 1406 aue_csr_write_1(sc, AUE_PAR0 + i, eaddr[i]); 1407 1408 /* If we want promiscuous mode, set the allframes bit. */ 1409 if (ifp->if_flags & IFF_PROMISC) 1410 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 1411 else 1412 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 1413 1414 /* Init TX ring. */ 1415 if (aue_tx_list_init(sc) == ENOBUFS) { 1416 printf("%s: tx list init failed\n", USBDEVNAME(sc->aue_dev)); 1417 splx(s); 1418 return; 1419 } 1420 1421 /* Init RX ring. */ 1422 if (aue_rx_list_init(sc) == ENOBUFS) { 1423 printf("%s: rx list init failed\n", USBDEVNAME(sc->aue_dev)); 1424 splx(s); 1425 return; 1426 } 1427 1428 /* Load the multicast filter. */ 1429 aue_setmulti(sc); 1430 1431 /* Enable RX and TX */ 1432 aue_csr_write_1(sc, AUE_CTL0, AUE_CTL0_RXSTAT_APPEND | AUE_CTL0_RX_ENB); 1433 AUE_SETBIT(sc, AUE_CTL0, AUE_CTL0_TX_ENB); 1434 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_EP3_CLR); 1435 1436 mii_mediachg(mii); 1437 1438 if (sc->aue_ep[AUE_ENDPT_RX] == NULL) { 1439 if (aue_openpipes(sc)) { 1440 splx(s); 1441 return; 1442 } 1443 } 1444 1445 ifp->if_flags |= IFF_RUNNING; 1446 ifp->if_flags &= ~IFF_OACTIVE; 1447 1448 splx(s); 1449 1450 usb_callout(sc->aue_stat_ch, hz, aue_tick, sc); 1451 } 1452 1453 Static int 1454 aue_openpipes(struct aue_softc *sc) 1455 { 1456 struct aue_chain *c; 1457 usbd_status err; 1458 int i; 1459 1460 /* Open RX and TX pipes. */ 1461 err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_RX], 1462 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_RX]); 1463 if (err) { 1464 printf("%s: open rx pipe failed: %s\n", 1465 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1466 return (EIO); 1467 } 1468 err = usbd_open_pipe(sc->aue_iface, sc->aue_ed[AUE_ENDPT_TX], 1469 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_TX]); 1470 if (err) { 1471 printf("%s: open tx pipe failed: %s\n", 1472 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1473 return (EIO); 1474 } 1475 err = usbd_open_pipe_intr(sc->aue_iface, sc->aue_ed[AUE_ENDPT_INTR], 1476 USBD_EXCLUSIVE_USE, &sc->aue_ep[AUE_ENDPT_INTR], sc, 1477 &sc->aue_cdata.aue_ibuf, AUE_INTR_PKTLEN, aue_intr, 1478 AUE_INTR_INTERVAL); 1479 if (err) { 1480 printf("%s: open intr pipe failed: %s\n", 1481 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1482 return (EIO); 1483 } 1484 1485 /* Start up the receive pipe. */ 1486 for (i = 0; i < AUE_RX_LIST_CNT; i++) { 1487 c = &sc->aue_cdata.aue_rx_chain[i]; 1488 usbd_setup_xfer(c->aue_xfer, sc->aue_ep[AUE_ENDPT_RX], 1489 c, c->aue_buf, AUE_BUFSZ, 1490 USBD_SHORT_XFER_OK | USBD_NO_COPY, USBD_NO_TIMEOUT, 1491 aue_rxeof); 1492 (void)usbd_transfer(c->aue_xfer); /* XXX */ 1493 DPRINTFN(5,("%s: %s: start read\n", USBDEVNAME(sc->aue_dev), 1494 __func__)); 1495 1496 } 1497 return (0); 1498 } 1499 1500 /* 1501 * Set media options. 1502 */ 1503 Static int 1504 aue_ifmedia_upd(struct ifnet *ifp) 1505 { 1506 struct aue_softc *sc = ifp->if_softc; 1507 struct mii_data *mii = GET_MII(sc); 1508 1509 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 1510 1511 if (sc->aue_dying) 1512 return (0); 1513 1514 sc->aue_link = 0; 1515 if (mii->mii_instance) { 1516 struct mii_softc *miisc; 1517 for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL; 1518 miisc = LIST_NEXT(miisc, mii_list)) 1519 mii_phy_reset(miisc); 1520 } 1521 mii_mediachg(mii); 1522 1523 return (0); 1524 } 1525 1526 /* 1527 * Report current media status. 1528 */ 1529 Static void 1530 aue_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr) 1531 { 1532 struct aue_softc *sc = ifp->if_softc; 1533 struct mii_data *mii = GET_MII(sc); 1534 1535 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 1536 1537 mii_pollstat(mii); 1538 ifmr->ifm_active = mii->mii_media_active; 1539 ifmr->ifm_status = mii->mii_media_status; 1540 } 1541 1542 Static int 1543 aue_ioctl(struct ifnet *ifp, u_long command, caddr_t data) 1544 { 1545 struct aue_softc *sc = ifp->if_softc; 1546 struct ifaddr *ifa = (struct ifaddr *)data; 1547 struct ifreq *ifr = (struct ifreq *)data; 1548 struct mii_data *mii; 1549 int s, error = 0; 1550 1551 if (sc->aue_dying) 1552 return (EIO); 1553 1554 s = splnet(); 1555 1556 switch(command) { 1557 case SIOCSIFADDR: 1558 ifp->if_flags |= IFF_UP; 1559 aue_init(sc); 1560 1561 switch (ifa->ifa_addr->sa_family) { 1562 #ifdef INET 1563 case AF_INET: 1564 #if defined(__NetBSD__) 1565 arp_ifinit(ifp, ifa); 1566 #else 1567 arp_ifinit(&sc->arpcom, ifa); 1568 #endif 1569 break; 1570 #endif /* INET */ 1571 #ifdef NS 1572 case AF_NS: 1573 { 1574 struct ns_addr *ina = &IA_SNS(ifa)->sns_addr; 1575 1576 if (ns_nullhost(*ina)) 1577 ina->x_host = *(union ns_host *) 1578 LLADDR(ifp->if_sadl); 1579 else 1580 memcpy(LLADDR(ifp->if_sadl), 1581 ina->x_host.c_host, 1582 ifp->if_addrlen); 1583 break; 1584 } 1585 #endif /* NS */ 1586 } 1587 break; 1588 1589 case SIOCSIFMTU: 1590 if (ifr->ifr_mtu > ETHERMTU) 1591 error = EINVAL; 1592 else 1593 ifp->if_mtu = ifr->ifr_mtu; 1594 break; 1595 1596 case SIOCSIFFLAGS: 1597 if (ifp->if_flags & IFF_UP) { 1598 if (ifp->if_flags & IFF_RUNNING && 1599 ifp->if_flags & IFF_PROMISC && 1600 !(sc->aue_if_flags & IFF_PROMISC)) { 1601 AUE_SETBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 1602 } else if (ifp->if_flags & IFF_RUNNING && 1603 !(ifp->if_flags & IFF_PROMISC) && 1604 sc->aue_if_flags & IFF_PROMISC) { 1605 AUE_CLRBIT(sc, AUE_CTL2, AUE_CTL2_RX_PROMISC); 1606 } else if (!(ifp->if_flags & IFF_RUNNING)) 1607 aue_init(sc); 1608 } else { 1609 if (ifp->if_flags & IFF_RUNNING) 1610 aue_stop(sc); 1611 } 1612 sc->aue_if_flags = ifp->if_flags; 1613 error = 0; 1614 break; 1615 case SIOCADDMULTI: 1616 case SIOCDELMULTI: 1617 error = (command == SIOCADDMULTI) ? 1618 ether_addmulti(ifr, &sc->aue_ec) : 1619 ether_delmulti(ifr, &sc->aue_ec); 1620 if (error == ENETRESET) { 1621 if (ifp->if_flags & IFF_RUNNING) { 1622 aue_init(sc); 1623 aue_setmulti(sc); 1624 } 1625 error = 0; 1626 } 1627 break; 1628 case SIOCGIFMEDIA: 1629 case SIOCSIFMEDIA: 1630 mii = GET_MII(sc); 1631 error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command); 1632 break; 1633 default: 1634 error = EINVAL; 1635 break; 1636 } 1637 1638 splx(s); 1639 1640 return (error); 1641 } 1642 1643 Static void 1644 aue_watchdog(struct ifnet *ifp) 1645 { 1646 struct aue_softc *sc = ifp->if_softc; 1647 struct aue_chain *c; 1648 usbd_status stat; 1649 int s; 1650 1651 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 1652 1653 ifp->if_oerrors++; 1654 printf("%s: watchdog timeout\n", USBDEVNAME(sc->aue_dev)); 1655 1656 s = splusb(); 1657 c = &sc->aue_cdata.aue_tx_chain[0]; 1658 usbd_get_xfer_status(c->aue_xfer, NULL, NULL, NULL, &stat); 1659 aue_txeof(c->aue_xfer, c, stat); 1660 1661 if (IFQ_IS_EMPTY(&ifp->if_snd) == 0) 1662 aue_start(ifp); 1663 splx(s); 1664 } 1665 1666 /* 1667 * Stop the adapter and free any mbufs allocated to the 1668 * RX and TX lists. 1669 */ 1670 Static void 1671 aue_stop(struct aue_softc *sc) 1672 { 1673 usbd_status err; 1674 struct ifnet *ifp; 1675 int i; 1676 1677 DPRINTFN(5,("%s: %s: enter\n", USBDEVNAME(sc->aue_dev), __func__)); 1678 1679 ifp = GET_IFP(sc); 1680 ifp->if_timer = 0; 1681 1682 aue_csr_write_1(sc, AUE_CTL0, 0); 1683 aue_csr_write_1(sc, AUE_CTL1, 0); 1684 aue_reset(sc); 1685 usb_uncallout(sc->aue_stat_ch, aue_tick, sc); 1686 1687 /* Stop transfers. */ 1688 if (sc->aue_ep[AUE_ENDPT_RX] != NULL) { 1689 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_RX]); 1690 if (err) { 1691 printf("%s: abort rx pipe failed: %s\n", 1692 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1693 } 1694 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_RX]); 1695 if (err) { 1696 printf("%s: close rx pipe failed: %s\n", 1697 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1698 } 1699 sc->aue_ep[AUE_ENDPT_RX] = NULL; 1700 } 1701 1702 if (sc->aue_ep[AUE_ENDPT_TX] != NULL) { 1703 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_TX]); 1704 if (err) { 1705 printf("%s: abort tx pipe failed: %s\n", 1706 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1707 } 1708 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_TX]); 1709 if (err) { 1710 printf("%s: close tx pipe failed: %s\n", 1711 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1712 } 1713 sc->aue_ep[AUE_ENDPT_TX] = NULL; 1714 } 1715 1716 if (sc->aue_ep[AUE_ENDPT_INTR] != NULL) { 1717 err = usbd_abort_pipe(sc->aue_ep[AUE_ENDPT_INTR]); 1718 if (err) { 1719 printf("%s: abort intr pipe failed: %s\n", 1720 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1721 } 1722 err = usbd_close_pipe(sc->aue_ep[AUE_ENDPT_INTR]); 1723 if (err) { 1724 printf("%s: close intr pipe failed: %s\n", 1725 USBDEVNAME(sc->aue_dev), usbd_errstr(err)); 1726 } 1727 sc->aue_ep[AUE_ENDPT_INTR] = NULL; 1728 } 1729 1730 /* Free RX resources. */ 1731 for (i = 0; i < AUE_RX_LIST_CNT; i++) { 1732 if (sc->aue_cdata.aue_rx_chain[i].aue_mbuf != NULL) { 1733 m_freem(sc->aue_cdata.aue_rx_chain[i].aue_mbuf); 1734 sc->aue_cdata.aue_rx_chain[i].aue_mbuf = NULL; 1735 } 1736 if (sc->aue_cdata.aue_rx_chain[i].aue_xfer != NULL) { 1737 usbd_free_xfer(sc->aue_cdata.aue_rx_chain[i].aue_xfer); 1738 sc->aue_cdata.aue_rx_chain[i].aue_xfer = NULL; 1739 } 1740 } 1741 1742 /* Free TX resources. */ 1743 for (i = 0; i < AUE_TX_LIST_CNT; i++) { 1744 if (sc->aue_cdata.aue_tx_chain[i].aue_mbuf != NULL) { 1745 m_freem(sc->aue_cdata.aue_tx_chain[i].aue_mbuf); 1746 sc->aue_cdata.aue_tx_chain[i].aue_mbuf = NULL; 1747 } 1748 if (sc->aue_cdata.aue_tx_chain[i].aue_xfer != NULL) { 1749 usbd_free_xfer(sc->aue_cdata.aue_tx_chain[i].aue_xfer); 1750 sc->aue_cdata.aue_tx_chain[i].aue_xfer = NULL; 1751 } 1752 } 1753 1754 sc->aue_link = 0; 1755 1756 ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); 1757 } 1758