Thu Mar 3 05:49:58 2022 UTC ()
usbnet: Don't waste time calling uno_stop if device is detaching.

The hardware is most likely gone, so trying to write to its registers
(and, in some cases, wait until a timeout for a device to reset) is a
waste of time.  Even if it was detached only in software with drvctl,
reattaching it will reset the device anyway.


(riastradh)
diff -r1.67 -r1.68 src/sys/dev/usb/usbnet.c

cvs diff -r1.67 -r1.68 src/sys/dev/usb/usbnet.c (expand / switch to unified diff)

--- src/sys/dev/usb/usbnet.c 2022/03/03 05:49:44 1.67
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:49:58 1.68
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.c,v 1.67 2022/03/03 05:49:44 riastradh Exp $ */ 1/* $NetBSD: usbnet.c,v 1.68 2022/03/03 05:49:58 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2019 Matthew R. Green 4 * Copyright (c) 2019 Matthew R. Green
5 * All rights reserved. 5 * 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.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Common code shared between USB network drivers. 30 * Common code shared between USB network drivers.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.67 2022/03/03 05:49:44 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.68 2022/03/03 05:49:58 riastradh Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/kmem.h> 38#include <sys/kmem.h>
39#include <sys/module.h> 39#include <sys/module.h>
40#include <sys/atomic.h> 40#include <sys/atomic.h>
41 41
42#include <dev/usb/usbnet.h> 42#include <dev/usb/usbnet.h>
43#include <dev/usb/usbhist.h> 43#include <dev/usb/usbhist.h>
44 44
45struct usbnet_cdata { 45struct usbnet_cdata {
46 struct usbnet_chain *uncd_tx_chain; 46 struct usbnet_chain *uncd_tx_chain;
47 struct usbnet_chain *uncd_rx_chain; 47 struct usbnet_chain *uncd_rx_chain;
@@ -1144,28 +1144,33 @@ usbnet_stop(struct usbnet *un, struct if @@ -1144,28 +1144,33 @@ usbnet_stop(struct usbnet *un, struct if
1144 * already firing, we stop the task or wait for it complete 1144 * already firing, we stop the task or wait for it complete
1145 * only after if last fired. Setting unp_stopping prevents the 1145 * only after if last fired. Setting unp_stopping prevents the
1146 * timer task from being scheduled again. 1146 * timer task from being scheduled again.
1147 */ 1147 */
1148 callout_halt(&unp->unp_stat_ch, &unp->unp_core_lock); 1148 callout_halt(&unp->unp_stat_ch, &unp->unp_core_lock);
1149 usb_rem_task_wait(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER, 1149 usb_rem_task_wait(un->un_udev, &unp->unp_ticktask, USB_TASKQ_DRIVER,
1150 &unp->unp_core_lock); 1150 &unp->unp_core_lock);
1151 1151
1152 /* 1152 /*
1153 * Now that the software is quiescent, ask the driver to stop 1153 * Now that the software is quiescent, ask the driver to stop
1154 * the hardware. The driver's uno_stop routine now has 1154 * the hardware. The driver's uno_stop routine now has
1155 * exclusive access to any registers that might previously have 1155 * exclusive access to any registers that might previously have
1156 * been used by to ifmedia, mii, or ioctl callbacks. 1156 * been used by to ifmedia, mii, or ioctl callbacks.
 1157 *
 1158 * Don't bother if the device is being detached, though -- if
 1159 * it's been unplugged then there's no point in trying to touch
 1160 * the registers.
1157 */ 1161 */
1158 uno_stop(un, ifp, disable); 1162 if (!unp->unp_dying)
 1163 uno_stop(un, ifp, disable);
1159 1164
1160 /* Stop transfers. */ 1165 /* Stop transfers. */
1161 usbnet_ep_stop_pipes(un); 1166 usbnet_ep_stop_pipes(un);
1162 1167
1163 /* Free RX/TX resources. */ 1168 /* Free RX/TX resources. */
1164 usbnet_rx_list_fini(un); 1169 usbnet_rx_list_fini(un);
1165 usbnet_tx_list_fini(un); 1170 usbnet_tx_list_fini(un);
1166 1171
1167 /* Close pipes. */ 1172 /* Close pipes. */
1168 usbnet_ep_close_pipes(un); 1173 usbnet_ep_close_pipes(un);
1169 1174
1170 /* Everything is quesced now. */ 1175 /* Everything is quesced now. */
1171 KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp), 1176 KASSERTMSG(!unp->unp_ifp_attached || IFNET_LOCKED(ifp),