| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: usbnet.c,v 1.83 2022/03/03 05:54:28 riastradh Exp $ */ | | 1 | /* $NetBSD: usbnet.c,v 1.84 2022/03/03 05:54:52 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.83 2022/03/03 05:54:28 riastradh Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.84 2022/03/03 05:54:52 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; |
| @@ -92,26 +92,38 @@ struct usbnet_private { | | | @@ -92,26 +92,38 @@ struct usbnet_private { |
92 | | | 92 | |
93 | struct timeval unp_rx_notice; | | 93 | struct timeval unp_rx_notice; |
94 | struct timeval unp_tx_notice; | | 94 | struct timeval unp_tx_notice; |
95 | struct timeval unp_intr_notice; | | 95 | struct timeval unp_intr_notice; |
96 | }; | | 96 | }; |
97 | | | 97 | |
98 | #define un_cdata(un) (&(un)->un_pri->unp_cdata) | | 98 | #define un_cdata(un) (&(un)->un_pri->unp_cdata) |
99 | | | 99 | |
100 | volatile unsigned usbnet_number; | | 100 | volatile unsigned usbnet_number; |
101 | | | 101 | |
102 | static void usbnet_isowned_rx(struct usbnet *); | | 102 | static void usbnet_isowned_rx(struct usbnet *); |
103 | static void usbnet_isowned_tx(struct usbnet *); | | 103 | static void usbnet_isowned_tx(struct usbnet *); |
104 | | | 104 | |
| | | 105 | static kmutex_t * |
| | | 106 | usbnet_mutex_core(struct usbnet *un) |
| | | 107 | { |
| | | 108 | return &un->un_pri->unp_core_lock; |
| | | 109 | } |
| | | 110 | |
| | | 111 | static __inline__ void |
| | | 112 | usbnet_isowned_core(struct usbnet *un) |
| | | 113 | { |
| | | 114 | KASSERT(mutex_owned(usbnet_mutex_core(un))); |
| | | 115 | } |
| | | 116 | |
105 | static int usbnet_modcmd(modcmd_t, void *); | | 117 | static int usbnet_modcmd(modcmd_t, void *); |
106 | | | 118 | |
107 | #ifdef USB_DEBUG | | 119 | #ifdef USB_DEBUG |
108 | #ifndef USBNET_DEBUG | | 120 | #ifndef USBNET_DEBUG |
109 | #define usbnetdebug 0 | | 121 | #define usbnetdebug 0 |
110 | #else | | 122 | #else |
111 | static int usbnetdebug = 0; | | 123 | static int usbnetdebug = 0; |
112 | | | 124 | |
113 | SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup") | | 125 | SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup") |
114 | { | | 126 | { |
115 | int err; | | 127 | int err; |
116 | const struct sysctlnode *rnode; | | 128 | const struct sysctlnode *rnode; |
117 | const struct sysctlnode *cnode; | | 129 | const struct sysctlnode *cnode; |
| @@ -1302,44 +1314,26 @@ usbnet_havelink(struct usbnet *un) | | | @@ -1302,44 +1314,26 @@ usbnet_havelink(struct usbnet *un) |
1302 | { | | 1314 | { |
1303 | return un->un_pri->unp_link; | | 1315 | return un->un_pri->unp_link; |
1304 | } | | 1316 | } |
1305 | | | 1317 | |
1306 | bool | | 1318 | bool |
1307 | usbnet_isdying(struct usbnet *un) | | 1319 | usbnet_isdying(struct usbnet *un) |
1308 | { | | 1320 | { |
1309 | return atomic_load_relaxed(&un->un_pri->unp_dying); | | 1321 | return atomic_load_relaxed(&un->un_pri->unp_dying); |
1310 | } | | 1322 | } |
1311 | | | 1323 | |
1312 | | | 1324 | |
1313 | /* Locking. */ | | 1325 | /* Locking. */ |
1314 | | | 1326 | |
1315 | void | | | |
1316 | usbnet_lock_core(struct usbnet *un) | | | |
1317 | { | | | |
1318 | mutex_enter(&un->un_pri->unp_core_lock); | | | |
1319 | } | | | |
1320 | | | | |
1321 | void | | | |
1322 | usbnet_unlock_core(struct usbnet *un) | | | |
1323 | { | | | |
1324 | mutex_exit(&un->un_pri->unp_core_lock); | | | |
1325 | } | | | |
1326 | | | | |
1327 | kmutex_t* | | | |
1328 | usbnet_mutex_core(struct usbnet *un) | | | |
1329 | { | | | |
1330 | return &un->un_pri->unp_core_lock; | | | |
1331 | } | | | |
1332 | | | | |
1333 | static void | | 1327 | static void |
1334 | usbnet_isowned_rx(struct usbnet *un) | | 1328 | usbnet_isowned_rx(struct usbnet *un) |
1335 | { | | 1329 | { |
1336 | KASSERT(mutex_owned(&un->un_pri->unp_rxlock)); | | 1330 | KASSERT(mutex_owned(&un->un_pri->unp_rxlock)); |
1337 | } | | 1331 | } |
1338 | | | 1332 | |
1339 | static void | | 1333 | static void |
1340 | usbnet_isowned_tx(struct usbnet *un) | | 1334 | usbnet_isowned_tx(struct usbnet *un) |
1341 | { | | 1335 | { |
1342 | KASSERT(mutex_owned(&un->un_pri->unp_txlock)); | | 1336 | KASSERT(mutex_owned(&un->un_pri->unp_txlock)); |
1343 | } | | 1337 | } |
1344 | | | 1338 | |
1345 | /* Autoconf management. */ | | 1339 | /* Autoconf management. */ |