| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: usbnet.c,v 1.64 2022/03/03 05:49:22 riastradh Exp $ */ | | 1 | /* $NetBSD: usbnet.c,v 1.65 2022/03/03 05:49:29 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.64 2022/03/03 05:49:22 riastradh Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.65 2022/03/03 05:49:29 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 | |
45 | struct usbnet_cdata { | | 45 | struct 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; |
| @@ -1229,63 +1229,50 @@ usbnet_watchdog(struct ifnet *ifp) | | | @@ -1229,63 +1229,50 @@ usbnet_watchdog(struct ifnet *ifp) |
1229 | DPRINTF("uncd_tx_cnt now %ju", cd->uncd_tx_cnt, 0, 0, 0); | | 1229 | DPRINTF("uncd_tx_cnt now %ju", cd->uncd_tx_cnt, 0, 0, 0); |
1230 | } | | 1230 | } |
1231 | | | 1231 | |
1232 | if (!IFQ_IS_EMPTY(&ifp->if_snd)) | | 1232 | if (!IFQ_IS_EMPTY(&ifp->if_snd)) |
1233 | (*ifp->if_start)(ifp); | | 1233 | (*ifp->if_start)(ifp); |
1234 | } | | 1234 | } |
1235 | | | 1235 | |
1236 | static void | | 1236 | static void |
1237 | usbnet_tick_task(void *arg) | | 1237 | usbnet_tick_task(void *arg) |
1238 | { | | 1238 | { |
1239 | USBNETHIST_FUNC(); | | 1239 | USBNETHIST_FUNC(); |
1240 | struct usbnet * const un = arg; | | 1240 | struct usbnet * const un = arg; |
1241 | struct usbnet_private * const unp = un->un_pri; | | 1241 | struct usbnet_private * const unp = un->un_pri; |
1242 | | | | |
1243 | USBNETHIST_CALLARGSN(8, "%jd: enter", unp->unp_number, 0, 0, 0); | | | |
1244 | | | | |
1245 | mutex_enter(&unp->unp_core_lock); | | | |
1246 | if (unp->unp_stopping || unp->unp_dying) { | | | |
1247 | mutex_exit(&unp->unp_core_lock); | | | |
1248 | return; | | | |
1249 | } | | | |
1250 | | | | |
1251 | struct ifnet * const ifp = usbnet_ifp(un); | | 1242 | struct ifnet * const ifp = usbnet_ifp(un); |
1252 | struct mii_data * const mii = usbnet_mii(un); | | 1243 | struct mii_data * const mii = usbnet_mii(un); |
1253 | | | 1244 | |
1254 | KASSERT(ifp != NULL); /* embedded member */ | | 1245 | USBNETHIST_CALLARGSN(8, "%jd: enter", unp->unp_number, 0, 0, 0); |
1255 | | | | |
1256 | usbnet_busy(un); | | | |
1257 | mutex_exit(&unp->unp_core_lock); | | | |
1258 | | | 1246 | |
1259 | mutex_enter(&unp->unp_txlock); | | 1247 | mutex_enter(&unp->unp_txlock); |
1260 | const bool timeout = unp->unp_timer != 0 && --unp->unp_timer == 0; | | 1248 | const bool timeout = unp->unp_timer != 0 && --unp->unp_timer == 0; |
1261 | mutex_exit(&unp->unp_txlock); | | 1249 | mutex_exit(&unp->unp_txlock); |
1262 | if (timeout) | | 1250 | if (timeout) |
1263 | usbnet_watchdog(ifp); | | 1251 | usbnet_watchdog(ifp); |
1264 | | | 1252 | |
1265 | DPRINTFN(8, "mii %#jx ifp %#jx", (uintptr_t)mii, (uintptr_t)ifp, 0, 0); | | 1253 | DPRINTFN(8, "mii %#jx ifp %#jx", (uintptr_t)mii, (uintptr_t)ifp, 0, 0); |
1266 | if (mii) { | | 1254 | if (mii) { |
1267 | mutex_enter(&unp->unp_core_lock); | | 1255 | mutex_enter(&unp->unp_core_lock); |
1268 | mii_tick(mii); | | 1256 | mii_tick(mii); |
1269 | if (!unp->unp_link) | | 1257 | if (!unp->unp_link) |
1270 | (*mii->mii_statchg)(ifp); | | 1258 | (*mii->mii_statchg)(ifp); |
1271 | mutex_exit(&unp->unp_core_lock); | | 1259 | mutex_exit(&unp->unp_core_lock); |
1272 | } | | 1260 | } |
1273 | | | 1261 | |
1274 | /* Call driver if requested. */ | | 1262 | /* Call driver if requested. */ |
1275 | uno_tick(un); | | 1263 | uno_tick(un); |
1276 | | | 1264 | |
1277 | mutex_enter(&unp->unp_core_lock); | | 1265 | mutex_enter(&unp->unp_core_lock); |
1278 | usbnet_unbusy(un); | | | |
1279 | if (!unp->unp_stopping && !unp->unp_dying) | | 1266 | if (!unp->unp_stopping && !unp->unp_dying) |
1280 | callout_schedule(&unp->unp_stat_ch, hz); | | 1267 | callout_schedule(&unp->unp_stat_ch, hz); |
1281 | mutex_exit(&unp->unp_core_lock); | | 1268 | mutex_exit(&unp->unp_core_lock); |
1282 | } | | 1269 | } |
1283 | | | 1270 | |
1284 | static int | | 1271 | static int |
1285 | usbnet_if_init(struct ifnet *ifp) | | 1272 | usbnet_if_init(struct ifnet *ifp) |
1286 | { | | 1273 | { |
1287 | USBNETHIST_FUNC(); USBNETHIST_CALLED(); | | 1274 | USBNETHIST_FUNC(); USBNETHIST_CALLED(); |
1288 | struct usbnet * const un = ifp->if_softc; | | 1275 | struct usbnet * const un = ifp->if_softc; |
1289 | bool dying; | | 1276 | bool dying; |
1290 | | | 1277 | |
1291 | KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname); | | 1278 | KASSERTMSG(IFNET_LOCKED(ifp), "%s", ifp->if_xname); |