Thu Mar 3 05:54:52 2022 UTC ()
usbnet: Delete the core lock from the API.

Init/stop and ioctl happen under IFNET_LOCK.  Multicast updates only
happen after init and before stop.  Core lock is no longer a relevant
part of the API.  Internally, it serves essentially just to lock out
asynchronous mii activity during init/stop.


(riastradh)
diff -r1.83 -r1.84 src/sys/dev/usb/usbnet.c
diff -r1.27 -r1.28 src/sys/dev/usb/usbnet.h

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

--- src/sys/dev/usb/usbnet.c 2022/03/03 05:54:28 1.83
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:54:52 1.84
@@ -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
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;
@@ -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
100volatile unsigned usbnet_number; 100volatile unsigned usbnet_number;
101 101
102static void usbnet_isowned_rx(struct usbnet *); 102static void usbnet_isowned_rx(struct usbnet *);
103static void usbnet_isowned_tx(struct usbnet *); 103static void usbnet_isowned_tx(struct usbnet *);
104 104
 105static kmutex_t *
 106usbnet_mutex_core(struct usbnet *un)
 107{
 108 return &un->un_pri->unp_core_lock;
 109}
 110
 111static __inline__ void
 112usbnet_isowned_core(struct usbnet *un)
 113{
 114 KASSERT(mutex_owned(usbnet_mutex_core(un)));
 115}
 116
105static int usbnet_modcmd(modcmd_t, void *); 117static 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
111static int usbnetdebug = 0; 123static int usbnetdebug = 0;
112 124
113SYSCTL_SETUP(sysctl_hw_usbnet_setup, "sysctl hw.usbnet setup") 125SYSCTL_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
1306bool 1318bool
1307usbnet_isdying(struct usbnet *un) 1319usbnet_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
1315void 
1316usbnet_lock_core(struct usbnet *un) 
1317{ 
1318 mutex_enter(&un->un_pri->unp_core_lock); 
1319} 
1320 
1321void 
1322usbnet_unlock_core(struct usbnet *un) 
1323{ 
1324 mutex_exit(&un->un_pri->unp_core_lock); 
1325} 
1326 
1327kmutex_t* 
1328usbnet_mutex_core(struct usbnet *un) 
1329{ 
1330 return &un->un_pri->unp_core_lock; 
1331} 
1332 
1333static void 1327static void
1334usbnet_isowned_rx(struct usbnet *un) 1328usbnet_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
1339static void 1333static void
1340usbnet_isowned_tx(struct usbnet *un) 1334usbnet_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. */

cvs diff -r1.27 -r1.28 src/sys/dev/usb/usbnet.h (expand / switch to unified diff)

--- src/sys/dev/usb/usbnet.h 2022/03/03 05:54:28 1.27
+++ src/sys/dev/usb/usbnet.h 2022/03/03 05:54:52 1.28
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.h,v 1.27 2022/03/03 05:54:28 riastradh Exp $ */ 1/* $NetBSD: usbnet.h,v 1.28 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.
@@ -287,40 +287,26 @@ struct usbnet { @@ -287,40 +287,26 @@ struct usbnet {
287/* Various accessors. */ 287/* Various accessors. */
288 288
289void usbnet_set_link(struct usbnet *, bool); 289void usbnet_set_link(struct usbnet *, bool);
290 290
291struct ifnet *usbnet_ifp(struct usbnet *); 291struct ifnet *usbnet_ifp(struct usbnet *);
292struct ethercom *usbnet_ec(struct usbnet *); 292struct ethercom *usbnet_ec(struct usbnet *);
293struct mii_data *usbnet_mii(struct usbnet *); 293struct mii_data *usbnet_mii(struct usbnet *);
294krndsource_t *usbnet_rndsrc(struct usbnet *); 294krndsource_t *usbnet_rndsrc(struct usbnet *);
295void *usbnet_softc(struct usbnet *); 295void *usbnet_softc(struct usbnet *);
296 296
297bool usbnet_havelink(struct usbnet *); 297bool usbnet_havelink(struct usbnet *);
298bool usbnet_isdying(struct usbnet *); 298bool usbnet_isdying(struct usbnet *);
299 299
300 
301/* 
302 * Locking. Note that the isowned() are implemented here so that 
303 * empty-KASSERT() causes them to be elided for non-DIAG builds. 
304 */ 
305void usbnet_lock_core(struct usbnet *); 
306void usbnet_unlock_core(struct usbnet *); 
307kmutex_t *usbnet_mutex_core(struct usbnet *); 
308static __inline__ void 
309usbnet_isowned_core(struct usbnet *un) 
310{ 
311 KASSERT(mutex_owned(usbnet_mutex_core(un))); 
312} 
313 
314/* 300/*
315 * Endpoint / rx/tx chain management: 301 * Endpoint / rx/tx chain management:
316 * 302 *
317 * usbnet_attach() initialises usbnet and allocates rx and tx chains 303 * usbnet_attach() initialises usbnet and allocates rx and tx chains
318 * usbnet_init_rx_tx() open pipes, initialises the rx/tx chains for use 304 * usbnet_init_rx_tx() open pipes, initialises the rx/tx chains for use
319 * usbnet_stop() stops pipes, cleans (not frees) rx/tx chains, locked 305 * usbnet_stop() stops pipes, cleans (not frees) rx/tx chains, locked
320 * version assumes un_lock is held 306 * version assumes un_lock is held
321 * usbnet_detach() frees the rx/tx chains 307 * usbnet_detach() frees the rx/tx chains
322 * 308 *
323 * Setup un_ed[] with valid end points before calling usbnet_attach(). 309 * Setup un_ed[] with valid end points before calling usbnet_attach().
324 * Call usbnet_init_rx_tx() to initialise pipes, which will be open 310 * Call usbnet_init_rx_tx() to initialise pipes, which will be open
325 * upon success. 311 * upon success.
326 */ 312 */