usbnet drivers: Stop timeout loops early if device is detaching.diff -r1.172 -r1.173 src/sys/dev/usb/if_aue.c
(riastradh)
--- src/sys/dev/usb/if_aue.c 2022/03/03 05:50:22 1.172
+++ src/sys/dev/usb/if_aue.c 2022/03/03 05:50:57 1.173
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_aue.c,v 1.172 2022/03/03 05:50:22 riastradh Exp $ */ | 1 | /* $NetBSD: if_aue.c,v 1.173 2022/03/03 05:50:57 riastradh Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1997, 1998, 1999, 2000 | 4 | * Copyright (c) 1997, 1998, 1999, 2000 | |
5 | * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. | 5 | * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -66,27 +66,27 @@ | @@ -66,27 +66,27 @@ | |||
66 | /* | 66 | /* | |
67 | * Ported to NetBSD and somewhat rewritten by Lennart Augustsson. | 67 | * Ported to NetBSD and somewhat rewritten by Lennart Augustsson. | |
68 | */ | 68 | */ | |
69 | 69 | |||
70 | /* | 70 | /* | |
71 | * TODO: | 71 | * TODO: | |
72 | * better error messages from rxstat | 72 | * better error messages from rxstat | |
73 | * more error checks | 73 | * more error checks | |
74 | * investigate short rx problem | 74 | * investigate short rx problem | |
75 | * proper cleanup on errors | 75 | * proper cleanup on errors | |
76 | */ | 76 | */ | |
77 | 77 | |||
78 | #include <sys/cdefs.h> | 78 | #include <sys/cdefs.h> | |
79 | __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.172 2022/03/03 05:50:22 riastradh Exp $"); | 79 | __KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.173 2022/03/03 05:50:57 riastradh Exp $"); | |
80 | 80 | |||
81 | #ifdef _KERNEL_OPT | 81 | #ifdef _KERNEL_OPT | |
82 | #include "opt_usb.h" | 82 | #include "opt_usb.h" | |
83 | #include "opt_inet.h" | 83 | #include "opt_inet.h" | |
84 | #endif | 84 | #endif | |
85 | 85 | |||
86 | #include <sys/param.h> | 86 | #include <sys/param.h> | |
87 | 87 | |||
88 | #include <dev/usb/usbnet.h> | 88 | #include <dev/usb/usbnet.h> | |
89 | #include <dev/usb/usbhist.h> | 89 | #include <dev/usb/usbhist.h> | |
90 | #include <dev/usb/if_auereg.h> | 90 | #include <dev/usb/if_auereg.h> | |
91 | 91 | |||
92 | #ifdef INET | 92 | #ifdef INET | |
@@ -473,26 +473,28 @@ aue_uno_mii_read_reg(struct usbnet *un, | @@ -473,26 +473,28 @@ aue_uno_mii_read_reg(struct usbnet *un, | |||
473 | * so we filter that out. | 473 | * so we filter that out. | |
474 | */ | 474 | */ | |
475 | if (sc->aue_vendor == USB_VENDOR_ADMTEK && | 475 | if (sc->aue_vendor == USB_VENDOR_ADMTEK && | |
476 | sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { | 476 | sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { | |
477 | if (phy == 3) | 477 | if (phy == 3) | |
478 | return EINVAL; | 478 | return EINVAL; | |
479 | } | 479 | } | |
480 | #endif | 480 | #endif | |
481 | 481 | |||
482 | aue_csr_write_1(sc, AUE_PHY_ADDR, phy); | 482 | aue_csr_write_1(sc, AUE_PHY_ADDR, phy); | |
483 | aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); | 483 | aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_READ); | |
484 | 484 | |||
485 | for (i = 0; i < AUE_TIMEOUT; i++) { | 485 | for (i = 0; i < AUE_TIMEOUT; i++) { | |
486 | if (usbnet_isdying(un)) | |||
487 | return ENXIO; | |||
486 | if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) | 488 | if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) | |
487 | break; | 489 | break; | |
488 | } | 490 | } | |
489 | 491 | |||
490 | if (i == AUE_TIMEOUT) { | 492 | if (i == AUE_TIMEOUT) { | |
491 | AUEHIST_CALLARGS("aue%jd: phy=%#jx reg=%#jx read timed out", | 493 | AUEHIST_CALLARGS("aue%jd: phy=%#jx reg=%#jx read timed out", | |
492 | device_unit(un->un_dev), phy, reg, 0); | 494 | device_unit(un->un_dev), phy, reg, 0); | |
493 | return ETIMEDOUT; | 495 | return ETIMEDOUT; | |
494 | } | 496 | } | |
495 | 497 | |||
496 | *val = aue_csr_read_2(sc, AUE_PHY_DATA); | 498 | *val = aue_csr_read_2(sc, AUE_PHY_DATA); | |
497 | 499 | |||
498 | AUEHIST_CALLARGSN(11, "aue%jd: phy=%#jx reg=%#jx => 0x%04jx", | 500 | AUEHIST_CALLARGSN(11, "aue%jd: phy=%#jx reg=%#jx => 0x%04jx", | |
@@ -514,26 +516,28 @@ aue_uno_mii_write_reg(struct usbnet *un, | @@ -514,26 +516,28 @@ aue_uno_mii_write_reg(struct usbnet *un, | |||
514 | #if 0 | 516 | #if 0 | |
515 | if (sc->aue_vendor == USB_VENDOR_ADMTEK && | 517 | if (sc->aue_vendor == USB_VENDOR_ADMTEK && | |
516 | sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { | 518 | sc->aue_product == USB_PRODUCT_ADMTEK_PEGASUS) { | |
517 | if (phy == 3) | 519 | if (phy == 3) | |
518 | return EINVAL; | 520 | return EINVAL; | |
519 | } | 521 | } | |
520 | #endif | 522 | #endif | |
521 | 523 | |||
522 | aue_csr_write_2(sc, AUE_PHY_DATA, val); | 524 | aue_csr_write_2(sc, AUE_PHY_DATA, val); | |
523 | aue_csr_write_1(sc, AUE_PHY_ADDR, phy); | 525 | aue_csr_write_1(sc, AUE_PHY_ADDR, phy); | |
524 | aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); | 526 | aue_csr_write_1(sc, AUE_PHY_CTL, reg | AUE_PHYCTL_WRITE); | |
525 | 527 | |||
526 | for (i = 0; i < AUE_TIMEOUT; i++) { | 528 | for (i = 0; i < AUE_TIMEOUT; i++) { | |
529 | if (usbnet_isdying(un)) | |||
530 | return ENXIO; | |||
527 | if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) | 531 | if (aue_csr_read_1(sc, AUE_PHY_CTL) & AUE_PHYCTL_DONE) | |
528 | break; | 532 | break; | |
529 | } | 533 | } | |
530 | 534 | |||
531 | if (i == AUE_TIMEOUT) { | 535 | if (i == AUE_TIMEOUT) { | |
532 | DPRINTF("aue%jd: phy=%#jx reg=%#jx val=%#jx write timed out", | 536 | DPRINTF("aue%jd: phy=%#jx reg=%#jx val=%#jx write timed out", | |
533 | device_unit(un->un_dev), phy, reg, val); | 537 | device_unit(un->un_dev), phy, reg, val); | |
534 | return ETIMEDOUT; | 538 | return ETIMEDOUT; | |
535 | } | 539 | } | |
536 | 540 | |||
537 | return 0; | 541 | return 0; | |
538 | } | 542 | } | |
539 | 543 | |||
@@ -670,26 +674,28 @@ aue_reset_pegasus_II(struct aue_softc *s | @@ -670,26 +674,28 @@ aue_reset_pegasus_II(struct aue_softc *s | |||
670 | 674 | |||
671 | static void | 675 | static void | |
672 | aue_reset(struct aue_softc *sc) | 676 | aue_reset(struct aue_softc *sc) | |
673 | { | 677 | { | |
674 | struct usbnet * const un = &sc->aue_un; | 678 | struct usbnet * const un = &sc->aue_un; | |
675 | int i; | 679 | int i; | |
676 | 680 | |||
677 | AUEHIST_FUNC(); | 681 | AUEHIST_FUNC(); | |
678 | AUEHIST_CALLARGSN(2, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); | 682 | AUEHIST_CALLARGSN(2, "aue%jd: enter", device_unit(un->un_dev), 0, 0, 0); | |
679 | 683 | |||
680 | AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); | 684 | AUE_SETBIT(sc, AUE_CTL1, AUE_CTL1_RESETMAC); | |
681 | 685 | |||
682 | for (i = 0; i < AUE_TIMEOUT; i++) { | 686 | for (i = 0; i < AUE_TIMEOUT; i++) { | |
687 | if (usbnet_isdying(un)) | |||
688 | return; | |||
683 | if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) | 689 | if (!(aue_csr_read_1(sc, AUE_CTL1) & AUE_CTL1_RESETMAC)) | |
684 | break; | 690 | break; | |
685 | } | 691 | } | |
686 | 692 | |||
687 | if (i == AUE_TIMEOUT) | 693 | if (i == AUE_TIMEOUT) | |
688 | printf("%s: reset failed\n", device_xname(un->un_dev)); | 694 | printf("%s: reset failed\n", device_xname(un->un_dev)); | |
689 | 695 | |||
690 | #if 0 | 696 | #if 0 | |
691 | /* XXX what is mii_mode supposed to be */ | 697 | /* XXX what is mii_mode supposed to be */ | |
692 | if (sc->sc_mii_mode && (un->un_flags & PNA)) | 698 | if (sc->sc_mii_mode && (un->un_flags & PNA)) | |
693 | aue_csr_write_1(sc, AUE_GPIO1, 0x34); | 699 | aue_csr_write_1(sc, AUE_GPIO1, 0x34); | |
694 | else | 700 | else | |
695 | aue_csr_write_1(sc, AUE_GPIO1, 0x26); | 701 | aue_csr_write_1(sc, AUE_GPIO1, 0x26); |
--- src/sys/dev/usb/if_mos.c 2022/03/03 05:50:22 1.8
+++ src/sys/dev/usb/if_mos.c 2022/03/03 05:50:57 1.9
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_mos.c,v 1.8 2022/03/03 05:50:22 riastradh Exp $ */ | 1 | /* $NetBSD: if_mos.c,v 1.9 2022/03/03 05:50:57 riastradh Exp $ */ | |
2 | /* $OpenBSD: if_mos.c,v 1.40 2019/07/07 06:40:10 kevlo Exp $ */ | 2 | /* $OpenBSD: if_mos.c,v 1.40 2019/07/07 06:40:10 kevlo Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2008 Johann Christian Rode <jcrode@gmx.net> | 5 | * Copyright (c) 2008 Johann Christian Rode <jcrode@gmx.net> | |
6 | * | 6 | * | |
7 | * Permission to use, copy, modify, and distribute this software for any | 7 | * Permission to use, copy, modify, and distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | 8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice appear in all copies. | 9 | * copyright notice and this permission notice appear in all copies. | |
10 | * | 10 | * | |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
@@ -62,27 +62,27 @@ | @@ -62,27 +62,27 @@ | |||
62 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 62 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
63 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 63 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
64 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 64 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
65 | * THE POSSIBILITY OF SUCH DAMAGE. | 65 | * THE POSSIBILITY OF SUCH DAMAGE. | |
66 | */ | 66 | */ | |
67 | 67 | |||
68 | /* | 68 | /* | |
69 | * Moschip MCS7730/MCS7830/MCS7832 USB to Ethernet controller | 69 | * Moschip MCS7730/MCS7830/MCS7832 USB to Ethernet controller | |
70 | * The datasheet is available at the following URL: | 70 | * The datasheet is available at the following URL: | |
71 | * http://www.moschip.com/data/products/MCS7830/Data%20Sheet_7830.pdf | 71 | * http://www.moschip.com/data/products/MCS7830/Data%20Sheet_7830.pdf | |
72 | */ | 72 | */ | |
73 | 73 | |||
74 | #include <sys/cdefs.h> | 74 | #include <sys/cdefs.h> | |
75 | __KERNEL_RCSID(0, "$NetBSD: if_mos.c,v 1.8 2022/03/03 05:50:22 riastradh Exp $"); | 75 | __KERNEL_RCSID(0, "$NetBSD: if_mos.c,v 1.9 2022/03/03 05:50:57 riastradh Exp $"); | |
76 | 76 | |||
77 | #include <sys/param.h> | 77 | #include <sys/param.h> | |
78 | 78 | |||
79 | #include <dev/usb/usbnet.h> | 79 | #include <dev/usb/usbnet.h> | |
80 | #include <dev/usb/if_mosreg.h> | 80 | #include <dev/usb/if_mosreg.h> | |
81 | 81 | |||
82 | #define MOS_PAUSE_REWRITES 3 | 82 | #define MOS_PAUSE_REWRITES 3 | |
83 | 83 | |||
84 | #define MOS_TIMEOUT 1000 | 84 | #define MOS_TIMEOUT 1000 | |
85 | 85 | |||
86 | #define MOS_RX_LIST_CNT 1 | 86 | #define MOS_RX_LIST_CNT 1 | |
87 | #define MOS_TX_LIST_CNT 1 | 87 | #define MOS_TX_LIST_CNT 1 | |
88 | 88 | |||
@@ -354,26 +354,28 @@ mos_write_mcast(struct usbnet *un, uint8 | @@ -354,26 +354,28 @@ mos_write_mcast(struct usbnet *un, uint8 | |||
354 | 354 | |||
355 | static int | 355 | static int | |
356 | mos_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val) | 356 | mos_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val) | |
357 | { | 357 | { | |
358 | int i, res; | 358 | int i, res; | |
359 | 359 | |||
360 | mos_reg_write_2(un, MOS_PHY_DATA, 0); | 360 | mos_reg_write_2(un, MOS_PHY_DATA, 0); | |
361 | mos_reg_write_1(un, MOS_PHY_CTL, (phy & MOS_PHYCTL_PHYADDR) | | 361 | mos_reg_write_1(un, MOS_PHY_CTL, (phy & MOS_PHYCTL_PHYADDR) | | |
362 | MOS_PHYCTL_READ); | 362 | MOS_PHYCTL_READ); | |
363 | mos_reg_write_1(un, MOS_PHY_STS, (reg & MOS_PHYSTS_PHYREG) | | 363 | mos_reg_write_1(un, MOS_PHY_STS, (reg & MOS_PHYSTS_PHYREG) | | |
364 | MOS_PHYSTS_PENDING); | 364 | MOS_PHYSTS_PENDING); | |
365 | 365 | |||
366 | for (i = 0; i < MOS_TIMEOUT; i++) { | 366 | for (i = 0; i < MOS_TIMEOUT; i++) { | |
367 | if (usbnet_isdying(un)) | |||
368 | return ENXIO; | |||
367 | if (mos_reg_read_1(un, MOS_PHY_STS) & MOS_PHYSTS_READY) | 369 | if (mos_reg_read_1(un, MOS_PHY_STS) & MOS_PHYSTS_READY) | |
368 | break; | 370 | break; | |
369 | } | 371 | } | |
370 | if (i == MOS_TIMEOUT) { | 372 | if (i == MOS_TIMEOUT) { | |
371 | aprint_error_dev(un->un_dev, "read PHY failed\n"); | 373 | aprint_error_dev(un->un_dev, "read PHY failed\n"); | |
372 | return EIO; | 374 | return EIO; | |
373 | } | 375 | } | |
374 | 376 | |||
375 | res = mos_reg_read_2(un, MOS_PHY_DATA); | 377 | res = mos_reg_read_2(un, MOS_PHY_DATA); | |
376 | *val = res; | 378 | *val = res; | |
377 | 379 | |||
378 | DPRINTFN(10,("%s: %s: phy %d reg %d val %u\n", | 380 | DPRINTFN(10,("%s: %s: phy %d reg %d val %u\n", | |
379 | device_xname(un->un_dev), __func__, phy, reg, res)); | 381 | device_xname(un->un_dev), __func__, phy, reg, res)); | |
@@ -386,26 +388,28 @@ mos_uno_mii_write_reg(struct usbnet *un, | @@ -386,26 +388,28 @@ mos_uno_mii_write_reg(struct usbnet *un, | |||
386 | { | 388 | { | |
387 | int i; | 389 | int i; | |
388 | 390 | |||
389 | DPRINTFN(10,("%s: %s: phy %d reg %d val %u\n", | 391 | DPRINTFN(10,("%s: %s: phy %d reg %d val %u\n", | |
390 | device_xname(un->un_dev), __func__, phy, reg, val)); | 392 | device_xname(un->un_dev), __func__, phy, reg, val)); | |
391 | 393 | |||
392 | mos_reg_write_2(un, MOS_PHY_DATA, val); | 394 | mos_reg_write_2(un, MOS_PHY_DATA, val); | |
393 | mos_reg_write_1(un, MOS_PHY_CTL, (phy & MOS_PHYCTL_PHYADDR) | | 395 | mos_reg_write_1(un, MOS_PHY_CTL, (phy & MOS_PHYCTL_PHYADDR) | | |
394 | MOS_PHYCTL_WRITE); | 396 | MOS_PHYCTL_WRITE); | |
395 | mos_reg_write_1(un, MOS_PHY_STS, (reg & MOS_PHYSTS_PHYREG) | | 397 | mos_reg_write_1(un, MOS_PHY_STS, (reg & MOS_PHYSTS_PHYREG) | | |
396 | MOS_PHYSTS_PENDING); | 398 | MOS_PHYSTS_PENDING); | |
397 | 399 | |||
398 | for (i = 0; i < MOS_TIMEOUT; i++) { | 400 | for (i = 0; i < MOS_TIMEOUT; i++) { | |
401 | if (usbnet_isdying(un)) | |||
402 | return ENXIO; | |||
399 | if (mos_reg_read_1(un, MOS_PHY_STS) & MOS_PHYSTS_READY) | 403 | if (mos_reg_read_1(un, MOS_PHY_STS) & MOS_PHYSTS_READY) | |
400 | break; | 404 | break; | |
401 | } | 405 | } | |
402 | if (i == MOS_TIMEOUT) { | 406 | if (i == MOS_TIMEOUT) { | |
403 | aprint_error_dev(un->un_dev, "write PHY failed\n"); | 407 | aprint_error_dev(un->un_dev, "write PHY failed\n"); | |
404 | return EIO; | 408 | return EIO; | |
405 | } | 409 | } | |
406 | 410 | |||
407 | return 0; | 411 | return 0; | |
408 | } | 412 | } | |
409 | 413 | |||
410 | void | 414 | void | |
411 | mos_uno_mii_statchg(struct ifnet *ifp) | 415 | mos_uno_mii_statchg(struct ifnet *ifp) |
--- src/sys/dev/usb/if_mue.c 2022/03/03 05:50:22 1.64
+++ src/sys/dev/usb/if_mue.c 2022/03/03 05:50:57 1.65
@@ -1,36 +1,36 @@ | @@ -1,36 +1,36 @@ | |||
1 | /* $NetBSD: if_mue.c,v 1.64 2022/03/03 05:50:22 riastradh Exp $ */ | 1 | /* $NetBSD: if_mue.c,v 1.65 2022/03/03 05:50:57 riastradh Exp $ */ | |
2 | /* $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $ */ | 2 | /* $OpenBSD: if_mue.c,v 1.3 2018/08/04 16:42:46 jsg Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2018 Kevin Lo <kevlo@openbsd.org> | 5 | * Copyright (c) 2018 Kevin Lo <kevlo@openbsd.org> | |
6 | * | 6 | * | |
7 | * Permission to use, copy, modify, and distribute this software for any | 7 | * Permission to use, copy, modify, and distribute this software for any | |
8 | * purpose with or without fee is hereby granted, provided that the above | 8 | * purpose with or without fee is hereby granted, provided that the above | |
9 | * copyright notice and this permission notice appear in all copies. | 9 | * copyright notice and this permission notice appear in all copies. | |
10 | * | 10 | * | |
11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
18 | */ | 18 | */ | |
19 | 19 | |||
20 | /* Driver for Microchip LAN7500/LAN7800 chipsets. */ | 20 | /* Driver for Microchip LAN7500/LAN7800 chipsets. */ | |
21 | 21 | |||
22 | #include <sys/cdefs.h> | 22 | #include <sys/cdefs.h> | |
23 | __KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.64 2022/03/03 05:50:22 riastradh Exp $"); | 23 | __KERNEL_RCSID(0, "$NetBSD: if_mue.c,v 1.65 2022/03/03 05:50:57 riastradh Exp $"); | |
24 | 24 | |||
25 | #ifdef _KERNEL_OPT | 25 | #ifdef _KERNEL_OPT | |
26 | #include "opt_usb.h" | 26 | #include "opt_usb.h" | |
27 | #include "opt_inet.h" | 27 | #include "opt_inet.h" | |
28 | #endif | 28 | #endif | |
29 | 29 | |||
30 | #include <sys/param.h> | 30 | #include <sys/param.h> | |
31 | 31 | |||
32 | #include <dev/usb/usbnet.h> | 32 | #include <dev/usb/usbnet.h> | |
33 | 33 | |||
34 | #include <dev/usb/if_muereg.h> | 34 | #include <dev/usb/if_muereg.h> | |
35 | #include <dev/usb/if_muevar.h> | 35 | #include <dev/usb/if_muevar.h> | |
36 | 36 | |||
@@ -190,26 +190,28 @@ mue_csr_write(struct usbnet *un, uint32_ | @@ -190,26 +190,28 @@ mue_csr_write(struct usbnet *un, uint32_ | |||
190 | } | 190 | } | |
191 | 191 | |||
192 | return 0; | 192 | return 0; | |
193 | } | 193 | } | |
194 | 194 | |||
195 | static int | 195 | static int | |
196 | mue_wait_for_bits(struct usbnet *un, uint32_t reg, | 196 | mue_wait_for_bits(struct usbnet *un, uint32_t reg, | |
197 | uint32_t set, uint32_t clear, uint32_t fail) | 197 | uint32_t set, uint32_t clear, uint32_t fail) | |
198 | { | 198 | { | |
199 | uint32_t val; | 199 | uint32_t val; | |
200 | int ntries; | 200 | int ntries; | |
201 | 201 | |||
202 | for (ntries = 0; ntries < 1000; ntries++) { | 202 | for (ntries = 0; ntries < 1000; ntries++) { | |
203 | if (usbnet_isdying(un)) | |||
204 | return 1; | |||
203 | val = mue_csr_read(un, reg); | 205 | val = mue_csr_read(un, reg); | |
204 | if ((val & set) || !(val & clear)) | 206 | if ((val & set) || !(val & clear)) | |
205 | return 0; | 207 | return 0; | |
206 | if (val & fail) | 208 | if (val & fail) | |
207 | return 1; | 209 | return 1; | |
208 | usbd_delay_ms(un->un_udev, 1); | 210 | usbd_delay_ms(un->un_udev, 1); | |
209 | } | 211 | } | |
210 | 212 | |||
211 | return 1; | 213 | return 1; | |
212 | } | 214 | } | |
213 | 215 | |||
214 | static int | 216 | static int | |
215 | mue_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val) | 217 | mue_uno_mii_read_reg(struct usbnet *un, int phy, int reg, uint16_t *val) |
--- src/sys/dev/usb/if_smsc.c 2022/03/03 05:50:22 1.72
+++ src/sys/dev/usb/if_smsc.c 2022/03/03 05:50:57 1.73
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_smsc.c,v 1.72 2022/03/03 05:50:22 riastradh Exp $ */ | 1 | /* $NetBSD: if_smsc.c,v 1.73 2022/03/03 05:50:57 riastradh Exp $ */ | |
2 | 2 | |||
3 | /* $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */ | 3 | /* $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */ | |
4 | /* $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */ | 4 | /* $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */ | |
5 | /*- | 5 | /*- | |
6 | * Copyright (c) 2012 | 6 | * Copyright (c) 2012 | |
7 | * Ben Gray <bgray@freebsd.org>. | 7 | * Ben Gray <bgray@freebsd.org>. | |
8 | * All rights reserved. | 8 | * All rights reserved. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -51,27 +51,27 @@ | @@ -51,27 +51,27 @@ | |||
51 | * the H/W checksum will be incorrect, however the rx code compensates for this. | 51 | * the H/W checksum will be incorrect, however the rx code compensates for this. | |
52 | * | 52 | * | |
53 | * TX checksuming is more complicated, the device requires a special header to | 53 | * TX checksuming is more complicated, the device requires a special header to | |
54 | * be prefixed onto the start of the frame which indicates the start and end | 54 | * be prefixed onto the start of the frame which indicates the start and end | |
55 | * positions of the UDP or TCP frame. This requires the driver to manually | 55 | * positions of the UDP or TCP frame. This requires the driver to manually | |
56 | * go through the packet data and decode the headers prior to sending. | 56 | * go through the packet data and decode the headers prior to sending. | |
57 | * On Linux they generally provide cues to the location of the csum and the | 57 | * On Linux they generally provide cues to the location of the csum and the | |
58 | * area to calculate it over, on FreeBSD we seem to have to do it all ourselves, | 58 | * area to calculate it over, on FreeBSD we seem to have to do it all ourselves, | |
59 | * hence this is not as optimal and therefore h/w TX checksum is currently not | 59 | * hence this is not as optimal and therefore h/w TX checksum is currently not | |
60 | * implemented. | 60 | * implemented. | |
61 | */ | 61 | */ | |
62 | 62 | |||
63 | #include <sys/cdefs.h> | 63 | #include <sys/cdefs.h> | |
64 | __KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.72 2022/03/03 05:50:22 riastradh Exp $"); | 64 | __KERNEL_RCSID(0, "$NetBSD: if_smsc.c,v 1.73 2022/03/03 05:50:57 riastradh Exp $"); | |
65 | 65 | |||
66 | #ifdef _KERNEL_OPT | 66 | #ifdef _KERNEL_OPT | |
67 | #include "opt_usb.h" | 67 | #include "opt_usb.h" | |
68 | #endif | 68 | #endif | |
69 | 69 | |||
70 | #include <sys/param.h> | 70 | #include <sys/param.h> | |
71 | 71 | |||
72 | #include <dev/usb/usbnet.h> | 72 | #include <dev/usb/usbnet.h> | |
73 | #include <dev/usb/usbhist.h> | 73 | #include <dev/usb/usbhist.h> | |
74 | 74 | |||
75 | #include <dev/usb/if_smscreg.h> | 75 | #include <dev/usb/if_smscreg.h> | |
76 | 76 | |||
77 | #include "ioconf.h" | 77 | #include "ioconf.h" | |
@@ -254,26 +254,28 @@ smsc_writereg(struct usbnet *un, uint32_ | @@ -254,26 +254,28 @@ smsc_writereg(struct usbnet *un, uint32_ | |||
254 | if (err != 0) | 254 | if (err != 0) | |
255 | smsc_warn_printf(un, "Failed to write register 0x%0x\n", off); | 255 | smsc_warn_printf(un, "Failed to write register 0x%0x\n", off); | |
256 | 256 | |||
257 | return err; | 257 | return err; | |
258 | } | 258 | } | |
259 | 259 | |||
260 | static int | 260 | static int | |
261 | smsc_wait_for_bits(struct usbnet *un, uint32_t reg, uint32_t bits) | 261 | smsc_wait_for_bits(struct usbnet *un, uint32_t reg, uint32_t bits) | |
262 | { | 262 | { | |
263 | uint32_t val; | 263 | uint32_t val; | |
264 | int err, i; | 264 | int err, i; | |
265 | 265 | |||
266 | for (i = 0; i < 100; i++) { | 266 | for (i = 0; i < 100; i++) { | |
267 | if (usbnet_isdying(un)) | |||
268 | return ENXIO; | |||
267 | if ((err = smsc_readreg(un, reg, &val)) != 0) | 269 | if ((err = smsc_readreg(un, reg, &val)) != 0) | |
268 | return err; | 270 | return err; | |
269 | if (!(val & bits)) | 271 | if (!(val & bits)) | |
270 | return 0; | 272 | return 0; | |
271 | DELAY(5); | 273 | DELAY(5); | |
272 | } | 274 | } | |
273 | 275 | |||
274 | return 1; | 276 | return 1; | |
275 | } | 277 | } | |
276 | 278 | |||
277 | static int | 279 | static int | |
278 | smsc_uno_miibus_readreg(struct usbnet *un, int phy, int reg, uint16_t *val) | 280 | smsc_uno_miibus_readreg(struct usbnet *un, int phy, int reg, uint16_t *val) | |
279 | { | 281 | { |
--- src/sys/dev/usb/if_udav.c 2022/03/03 05:50:22 1.79
+++ src/sys/dev/usb/if_udav.c 2022/03/03 05:50:57 1.80
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_udav.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $ */ | 1 | /* $NetBSD: if_udav.c,v 1.80 2022/03/03 05:50:57 riastradh Exp $ */ | |
2 | /* $nabe: if_udav.c,v 1.3 2003/08/21 16:57:19 nabe Exp $ */ | 2 | /* $nabe: if_udav.c,v 1.3 2003/08/21 16:57:19 nabe Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2003 | 5 | * Copyright (c) 2003 | |
6 | * Shingo WATANABE <nabe@nabechan.org>. All rights reserved. | 6 | * Shingo WATANABE <nabe@nabechan.org>. All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -35,27 +35,27 @@ | @@ -35,27 +35,27 @@ | |||
35 | * DM9601(DAVICOM USB to Ethernet MAC Controller with Integrated 10/100 PHY) | 35 | * DM9601(DAVICOM USB to Ethernet MAC Controller with Integrated 10/100 PHY) | |
36 | * The spec can be found at the following url. | 36 | * The spec can be found at the following url. | |
37 | * http://www.davicom.com.tw/big5/download/Data%20Sheet/DM9601-DS-F01-062202s.pdf | 37 | * http://www.davicom.com.tw/big5/download/Data%20Sheet/DM9601-DS-F01-062202s.pdf | |
38 | */ | 38 | */ | |
39 | 39 | |||
40 | /* | 40 | /* | |
41 | * TODO: | 41 | * TODO: | |
42 | * Interrupt Endpoint support | 42 | * Interrupt Endpoint support | |
43 | * External PHYs | 43 | * External PHYs | |
44 | * powerhook() support? | 44 | * powerhook() support? | |
45 | */ | 45 | */ | |
46 | 46 | |||
47 | #include <sys/cdefs.h> | 47 | #include <sys/cdefs.h> | |
48 | __KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $"); | 48 | __KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.80 2022/03/03 05:50:57 riastradh Exp $"); | |
49 | 49 | |||
50 | #ifdef _KERNEL_OPT | 50 | #ifdef _KERNEL_OPT | |
51 | #include "opt_usb.h" | 51 | #include "opt_usb.h" | |
52 | #endif | 52 | #endif | |
53 | 53 | |||
54 | #include <sys/param.h> | 54 | #include <sys/param.h> | |
55 | 55 | |||
56 | #include <dev/usb/usbnet.h> | 56 | #include <dev/usb/usbnet.h> | |
57 | #include <dev/usb/if_udavreg.h> | 57 | #include <dev/usb/if_udavreg.h> | |
58 | 58 | |||
59 | /* Function declarations */ | 59 | /* Function declarations */ | |
60 | static int udav_match(device_t, cfdata_t, void *); | 60 | static int udav_match(device_t, cfdata_t, void *); | |
61 | static void udav_attach(device_t, device_t, void *); | 61 | static void udav_attach(device_t, device_t, void *); | |
@@ -558,26 +558,28 @@ udav_chip_init(struct usbnet *un) | @@ -558,26 +558,28 @@ udav_chip_init(struct usbnet *un) | |||
558 | */ | 558 | */ | |
559 | UDAV_CLRBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY); | 559 | UDAV_CLRBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY); | |
560 | #else | 560 | #else | |
561 | if (un->un_flags & UDAV_EXT_PHY) { | 561 | if (un->un_flags & UDAV_EXT_PHY) { | |
562 | UDAV_SETBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY); | 562 | UDAV_SETBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY); | |
563 | } else { | 563 | } else { | |
564 | UDAV_CLRBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY); | 564 | UDAV_CLRBIT(un, UDAV_NCR, UDAV_NCR_EXT_PHY); | |
565 | } | 565 | } | |
566 | #endif | 566 | #endif | |
567 | 567 | |||
568 | UDAV_SETBIT(un, UDAV_NCR, UDAV_NCR_RST); | 568 | UDAV_SETBIT(un, UDAV_NCR, UDAV_NCR_RST); | |
569 | 569 | |||
570 | for (int i = 0; i < UDAV_TX_TIMEOUT; i++) { | 570 | for (int i = 0; i < UDAV_TX_TIMEOUT; i++) { | |
571 | if (usbnet_isdying(un)) | |||
572 | return; | |||
571 | if (!(udav_csr_read1(un, UDAV_NCR) & UDAV_NCR_RST)) | 573 | if (!(udav_csr_read1(un, UDAV_NCR) & UDAV_NCR_RST)) | |
572 | break; | 574 | break; | |
573 | delay(10); /* XXX */ | 575 | delay(10); /* XXX */ | |
574 | } | 576 | } | |
575 | delay(10000); /* XXX */ | 577 | delay(10000); /* XXX */ | |
576 | } | 578 | } | |
577 | 579 | |||
578 | #define UDAV_BITS 6 | 580 | #define UDAV_BITS 6 | |
579 | 581 | |||
580 | #define UDAV_CALCHASH(addr) \ | 582 | #define UDAV_CALCHASH(addr) \ | |
581 | (ether_crc32_le((addr), ETHER_ADDR_LEN) & ((1 << UDAV_BITS) - 1)) | 583 | (ether_crc32_le((addr), ETHER_ADDR_LEN) & ((1 << UDAV_BITS) - 1)) | |
582 | 584 | |||
583 | static void | 585 | static void |
--- src/sys/dev/usb/if_url.c 2022/03/03 05:50:22 1.79
+++ src/sys/dev/usb/if_url.c 2022/03/03 05:50:57 1.80
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_url.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $ */ | 1 | /* $NetBSD: if_url.c,v 1.80 2022/03/03 05:50:57 riastradh Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001, 2002 | 4 | * Copyright (c) 2001, 2002 | |
5 | * Shingo WATANABE <nabe@nabechan.org>. All rights reserved. | 5 | * Shingo WATANABE <nabe@nabechan.org>. All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -34,27 +34,27 @@ | @@ -34,27 +34,27 @@ | |||
34 | * The RTL8150L(Realtek USB to fast ethernet controller) spec can be found at | 34 | * The RTL8150L(Realtek USB to fast ethernet controller) spec can be found at | |
35 | * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/8150v14.pdf | 35 | * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/8150v14.pdf | |
36 | * ftp://152.104.125.40/lancard/data_sheet/8150/8150v14.pdf | 36 | * ftp://152.104.125.40/lancard/data_sheet/8150/8150v14.pdf | |
37 | */ | 37 | */ | |
38 | 38 | |||
39 | /* | 39 | /* | |
40 | * TODO: | 40 | * TODO: | |
41 | * Interrupt Endpoint support | 41 | * Interrupt Endpoint support | |
42 | * External PHYs | 42 | * External PHYs | |
43 | * powerhook() support? | 43 | * powerhook() support? | |
44 | */ | 44 | */ | |
45 | 45 | |||
46 | #include <sys/cdefs.h> | 46 | #include <sys/cdefs.h> | |
47 | __KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.79 2022/03/03 05:50:22 riastradh Exp $"); | 47 | __KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.80 2022/03/03 05:50:57 riastradh Exp $"); | |
48 | 48 | |||
49 | #ifdef _KERNEL_OPT | 49 | #ifdef _KERNEL_OPT | |
50 | #include "opt_inet.h" | 50 | #include "opt_inet.h" | |
51 | #include "opt_usb.h" | 51 | #include "opt_usb.h" | |
52 | #endif | 52 | #endif | |
53 | 53 | |||
54 | #include <sys/param.h> | 54 | #include <sys/param.h> | |
55 | 55 | |||
56 | #include <net/if_ether.h> | 56 | #include <net/if_ether.h> | |
57 | #ifdef INET | 57 | #ifdef INET | |
58 | #include <netinet/in.h> | 58 | #include <netinet/in.h> | |
59 | #include <netinet/if_inarp.h> | 59 | #include <netinet/if_inarp.h> | |
60 | #endif | 60 | #endif | |
@@ -418,26 +418,28 @@ url_uno_init(struct ifnet *ifp) | @@ -418,26 +418,28 @@ url_uno_init(struct ifnet *ifp) | |||
418 | static void | 418 | static void | |
419 | url_reset(struct usbnet *un) | 419 | url_reset(struct usbnet *un) | |
420 | { | 420 | { | |
421 | int i; | 421 | int i; | |
422 | 422 | |||
423 | DPRINTF(("%s: %s: enter\n", device_xname(un->un_dev), __func__)); | 423 | DPRINTF(("%s: %s: enter\n", device_xname(un->un_dev), __func__)); | |
424 | 424 | |||
425 | if (usbnet_isdying(un)) | 425 | if (usbnet_isdying(un)) | |
426 | return; | 426 | return; | |
427 | 427 | |||
428 | URL_SETBIT(un, URL_CR, URL_CR_SOFT_RST); | 428 | URL_SETBIT(un, URL_CR, URL_CR_SOFT_RST); | |
429 | 429 | |||
430 | for (i = 0; i < URL_TX_TIMEOUT; i++) { | 430 | for (i = 0; i < URL_TX_TIMEOUT; i++) { | |
431 | if (usbnet_isdying(un)) | |||
432 | return; | |||
431 | if (!(url_csr_read_1(un, URL_CR) & URL_CR_SOFT_RST)) | 433 | if (!(url_csr_read_1(un, URL_CR) & URL_CR_SOFT_RST)) | |
432 | break; | 434 | break; | |
433 | delay(10); /* XXX */ | 435 | delay(10); /* XXX */ | |
434 | } | 436 | } | |
435 | 437 | |||
436 | delay(10000); /* XXX */ | 438 | delay(10000); /* XXX */ | |
437 | } | 439 | } | |
438 | 440 | |||
439 | static void | 441 | static void | |
440 | url_rcvfilt_locked(struct usbnet *un) | 442 | url_rcvfilt_locked(struct usbnet *un) | |
441 | { | 443 | { | |
442 | struct ifnet * const ifp = usbnet_ifp(un); | 444 | struct ifnet * const ifp = usbnet_ifp(un); | |
443 | struct ethercom *ec = usbnet_ec(un); | 445 | struct ethercom *ec = usbnet_ec(un); |
--- src/sys/dev/usb/if_ure.c 2022/03/03 05:50:22 1.41
+++ src/sys/dev/usb/if_ure.c 2022/03/03 05:50:57 1.42
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if_ure.c,v 1.41 2022/03/03 05:50:22 riastradh Exp $ */ | 1 | /* $NetBSD: if_ure.c,v 1.42 2022/03/03 05:50:57 riastradh Exp $ */ | |
2 | /* $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */ | 2 | /* $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */ | |
3 | 3 | |||
4 | /*- | 4 | /*- | |
5 | * Copyright (c) 2015-2016 Kevin Lo <kevlo@FreeBSD.org> | 5 | * Copyright (c) 2015-2016 Kevin Lo <kevlo@FreeBSD.org> | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 | * SUCH DAMAGE. | 27 | * SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | /* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */ | 30 | /* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.41 2022/03/03 05:50:22 riastradh Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.42 2022/03/03 05:50:57 riastradh Exp $"); | |
34 | 34 | |||
35 | #ifdef _KERNEL_OPT | 35 | #ifdef _KERNEL_OPT | |
36 | #include "opt_usb.h" | 36 | #include "opt_usb.h" | |
37 | #include "opt_inet.h" | 37 | #include "opt_inet.h" | |
38 | #endif | 38 | #endif | |
39 | 39 | |||
40 | #include <sys/param.h> | 40 | #include <sys/param.h> | |
41 | #include <sys/cprng.h> | 41 | #include <sys/cprng.h> | |
42 | 42 | |||
43 | #include <net/route.h> | 43 | #include <net/route.h> | |
44 | 44 | |||
45 | #include <dev/usb/usbnet.h> | 45 | #include <dev/usb/usbnet.h> | |
46 | 46 | |||
@@ -386,26 +386,28 @@ ure_rcvfilt_locked(struct usbnet *un) | @@ -386,26 +386,28 @@ ure_rcvfilt_locked(struct usbnet *un) | |||
386 | ure_write_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA, rxmode); | 386 | ure_write_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA, rxmode); | |
387 | } | 387 | } | |
388 | 388 | |||
389 | static void | 389 | static void | |
390 | ure_reset(struct usbnet *un) | 390 | ure_reset(struct usbnet *un) | |
391 | { | 391 | { | |
392 | int i; | 392 | int i; | |
393 | 393 | |||
394 | usbnet_isowned_core(un); | 394 | usbnet_isowned_core(un); | |
395 | 395 | |||
396 | ure_write_1(un, URE_PLA_CR, URE_MCU_TYPE_PLA, URE_CR_RST); | 396 | ure_write_1(un, URE_PLA_CR, URE_MCU_TYPE_PLA, URE_CR_RST); | |
397 | 397 | |||
398 | for (i = 0; i < URE_TIMEOUT; i++) { | 398 | for (i = 0; i < URE_TIMEOUT; i++) { | |
399 | if (usbnet_isdying(un)) | |||
400 | return; | |||
399 | if (!(ure_read_1(un, URE_PLA_CR, URE_MCU_TYPE_PLA) & | 401 | if (!(ure_read_1(un, URE_PLA_CR, URE_MCU_TYPE_PLA) & | |
400 | URE_CR_RST)) | 402 | URE_CR_RST)) | |
401 | break; | 403 | break; | |
402 | usbd_delay_ms(un->un_udev, 10); | 404 | usbd_delay_ms(un->un_udev, 10); | |
403 | } | 405 | } | |
404 | if (i == URE_TIMEOUT) | 406 | if (i == URE_TIMEOUT) | |
405 | URE_PRINTF(un, "reset never completed\n"); | 407 | URE_PRINTF(un, "reset never completed\n"); | |
406 | } | 408 | } | |
407 | 409 | |||
408 | static int | 410 | static int | |
409 | ure_init_locked(struct ifnet *ifp) | 411 | ure_init_locked(struct ifnet *ifp) | |
410 | { | 412 | { | |
411 | struct usbnet * const un = ifp->if_softc; | 413 | struct usbnet * const un = ifp->if_softc; | |
@@ -531,35 +533,39 @@ ure_rtl8153_init(struct usbnet *un) | @@ -531,35 +533,39 @@ ure_rtl8153_init(struct usbnet *un) | |||
531 | uint8_t u1u2[8]; | 533 | uint8_t u1u2[8]; | |
532 | int i; | 534 | int i; | |
533 | 535 | |||
534 | /* Disable ALDPS. */ | 536 | /* Disable ALDPS. */ | |
535 | ure_ocp_reg_write(un, URE_OCP_POWER_CFG, | 537 | ure_ocp_reg_write(un, URE_OCP_POWER_CFG, | |
536 | ure_ocp_reg_read(un, URE_OCP_POWER_CFG) & ~URE_EN_ALDPS); | 538 | ure_ocp_reg_read(un, URE_OCP_POWER_CFG) & ~URE_EN_ALDPS); | |
537 | usbd_delay_ms(un->un_udev, 20); | 539 | usbd_delay_ms(un->un_udev, 20); | |
538 | 540 | |||
539 | memset(u1u2, 0x00, sizeof(u1u2)); | 541 | memset(u1u2, 0x00, sizeof(u1u2)); | |
540 | ure_write_mem(un, URE_USB_TOLERANCE, | 542 | ure_write_mem(un, URE_USB_TOLERANCE, | |
541 | URE_MCU_TYPE_USB | URE_BYTE_EN_SIX_BYTES, u1u2, sizeof(u1u2)); | 543 | URE_MCU_TYPE_USB | URE_BYTE_EN_SIX_BYTES, u1u2, sizeof(u1u2)); | |
542 | 544 | |||
543 | for (i = 0; i < URE_TIMEOUT; i++) { | 545 | for (i = 0; i < URE_TIMEOUT; i++) { | |
546 | if (usbnet_isdying(un)) | |||
547 | return; | |||
544 | if (ure_read_2(un, URE_PLA_BOOT_CTRL, URE_MCU_TYPE_PLA) & | 548 | if (ure_read_2(un, URE_PLA_BOOT_CTRL, URE_MCU_TYPE_PLA) & | |
545 | URE_AUTOLOAD_DONE) | 549 | URE_AUTOLOAD_DONE) | |
546 | break; | 550 | break; | |
547 | usbd_delay_ms(un->un_udev, 10); | 551 | usbd_delay_ms(un->un_udev, 10); | |
548 | } | 552 | } | |
549 | if (i == URE_TIMEOUT) | 553 | if (i == URE_TIMEOUT) | |
550 | URE_PRINTF(un, "timeout waiting for chip autoload\n"); | 554 | URE_PRINTF(un, "timeout waiting for chip autoload\n"); | |
551 | 555 | |||
552 | for (i = 0; i < URE_TIMEOUT; i++) { | 556 | for (i = 0; i < URE_TIMEOUT; i++) { | |
557 | if (usbnet_isdying(un)) | |||
558 | return; | |||
553 | val = ure_ocp_reg_read(un, URE_OCP_PHY_STATUS) & | 559 | val = ure_ocp_reg_read(un, URE_OCP_PHY_STATUS) & | |
554 | URE_PHY_STAT_MASK; | 560 | URE_PHY_STAT_MASK; | |
555 | if (val == URE_PHY_STAT_LAN_ON || val == URE_PHY_STAT_PWRDN) | 561 | if (val == URE_PHY_STAT_LAN_ON || val == URE_PHY_STAT_PWRDN) | |
556 | break; | 562 | break; | |
557 | usbd_delay_ms(un->un_udev, 10); | 563 | usbd_delay_ms(un->un_udev, 10); | |
558 | } | 564 | } | |
559 | if (i == URE_TIMEOUT) | 565 | if (i == URE_TIMEOUT) | |
560 | URE_PRINTF(un, "timeout waiting for phy to stabilize\n"); | 566 | URE_PRINTF(un, "timeout waiting for phy to stabilize\n"); | |
561 | 567 | |||
562 | ure_write_2(un, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB, | 568 | ure_write_2(un, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB, | |
563 | ure_read_2(un, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB) & | 569 | ure_read_2(un, URE_USB_U2P3_CTRL, URE_MCU_TYPE_USB) & | |
564 | ~URE_U2P3_ENABLE); | 570 | ~URE_U2P3_ENABLE); | |
565 | 571 | |||
@@ -738,37 +744,41 @@ ure_init_fifo(struct usbnet *un) | @@ -738,37 +744,41 @@ ure_init_fifo(struct usbnet *un) | |||
738 | 744 | |||
739 | ure_reset(un); | 745 | ure_reset(un); | |
740 | 746 | |||
741 | ure_write_1(un, URE_PLA_CR, URE_MCU_TYPE_PLA, 0); | 747 | ure_write_1(un, URE_PLA_CR, URE_MCU_TYPE_PLA, 0); | |
742 | 748 | |||
743 | ure_write_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA, | 749 | ure_write_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA, | |
744 | ure_read_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & | 750 | ure_read_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & | |
745 | ~URE_NOW_IS_OOB); | 751 | ~URE_NOW_IS_OOB); | |
746 | 752 | |||
747 | ure_write_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA, | 753 | ure_write_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA, | |
748 | ure_read_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA) & | 754 | ure_read_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA) & | |
749 | ~URE_MCU_BORW_EN); | 755 | ~URE_MCU_BORW_EN); | |
750 | for (i = 0; i < URE_TIMEOUT; i++) { | 756 | for (i = 0; i < URE_TIMEOUT; i++) { | |
757 | if (usbnet_isdying(un)) | |||
758 | return; | |||
751 | if (ure_read_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & | 759 | if (ure_read_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & | |
752 | URE_LINK_LIST_READY) | 760 | URE_LINK_LIST_READY) | |
753 | break; | 761 | break; | |
754 | usbd_delay_ms(un->un_udev, 10); | 762 | usbd_delay_ms(un->un_udev, 10); | |
755 | } | 763 | } | |
756 | if (i == URE_TIMEOUT) | 764 | if (i == URE_TIMEOUT) | |
757 | URE_PRINTF(un, "timeout waiting for OOB control\n"); | 765 | URE_PRINTF(un, "timeout waiting for OOB control\n"); | |
758 | ure_write_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA, | 766 | ure_write_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA, | |
759 | ure_read_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA) | | 767 | ure_read_2(un, URE_PLA_SFF_STS_7, URE_MCU_TYPE_PLA) | | |
760 | URE_RE_INIT_LL); | 768 | URE_RE_INIT_LL); | |
761 | for (i = 0; i < URE_TIMEOUT; i++) { | 769 | for (i = 0; i < URE_TIMEOUT; i++) { | |
770 | if (usbnet_isdying(un)) | |||
771 | return; | |||
762 | if (ure_read_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & | 772 | if (ure_read_1(un, URE_PLA_OOB_CTRL, URE_MCU_TYPE_PLA) & | |
763 | URE_LINK_LIST_READY) | 773 | URE_LINK_LIST_READY) | |
764 | break; | 774 | break; | |
765 | usbd_delay_ms(un->un_udev, 10); | 775 | usbd_delay_ms(un->un_udev, 10); | |
766 | } | 776 | } | |
767 | if (i == URE_TIMEOUT) | 777 | if (i == URE_TIMEOUT) | |
768 | URE_PRINTF(un, "timeout waiting for OOB control\n"); | 778 | URE_PRINTF(un, "timeout waiting for OOB control\n"); | |
769 | 779 | |||
770 | ure_write_2(un, URE_PLA_CPCR, URE_MCU_TYPE_PLA, | 780 | ure_write_2(un, URE_PLA_CPCR, URE_MCU_TYPE_PLA, | |
771 | ure_read_2(un, URE_PLA_CPCR, URE_MCU_TYPE_PLA) & | 781 | ure_read_2(un, URE_PLA_CPCR, URE_MCU_TYPE_PLA) & | |
772 | ~URE_CPCR_RX_VLAN); | 782 | ~URE_CPCR_RX_VLAN); | |
773 | ure_write_2(un, URE_PLA_TCR0, URE_MCU_TYPE_PLA, | 783 | ure_write_2(un, URE_PLA_TCR0, URE_MCU_TYPE_PLA, | |
774 | ure_read_2(un, URE_PLA_TCR0, URE_MCU_TYPE_PLA) | | 784 | ure_read_2(un, URE_PLA_TCR0, URE_MCU_TYPE_PLA) | |