Thu Mar 3 05:47:43 2022 UTC ()
usbnet: Don't check if_flags for IFF_RUNNING in usbnet_rxeof.

This can only run after we start the pipes in usbnet_init_rx_tx, and
before we abort the pipes in usbnet_stop, during which time if_flags
& IFF_RUNNING is stably set.


(riastradh)
diff -r1.51 -r1.52 src/sys/dev/usb/usbnet.c

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

--- src/sys/dev/usb/usbnet.c 2022/03/03 05:47:36 1.51
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:47:43 1.52
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usbnet.c,v 1.51 2022/03/03 05:47:36 riastradh Exp $ */ 1/* $NetBSD: usbnet.c,v 1.52 2022/03/03 05:47:43 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.51 2022/03/03 05:47:36 riastradh Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.52 2022/03/03 05:47:43 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;
@@ -327,37 +327,36 @@ usbnet_input(struct usbnet * const un, u @@ -327,37 +327,36 @@ usbnet_input(struct usbnet * const un, u
327} 327}
328 328
329/* 329/*
330 * A frame has been uploaded: pass the resulting mbuf chain up to 330 * A frame has been uploaded: pass the resulting mbuf chain up to
331 * the higher level protocols. 331 * the higher level protocols.
332 */ 332 */
333static void 333static void
334usbnet_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status) 334usbnet_rxeof(struct usbd_xfer *xfer, void *priv, usbd_status status)
335{ 335{
336 USBNETHIST_FUNC(); 336 USBNETHIST_FUNC();
337 struct usbnet_chain * const c = priv; 337 struct usbnet_chain * const c = priv;
338 struct usbnet * const un = c->unc_un; 338 struct usbnet * const un = c->unc_un;
339 struct usbnet_private * const unp = un->un_pri; 339 struct usbnet_private * const unp = un->un_pri;
340 struct ifnet * const ifp = usbnet_ifp(un); 
341 uint32_t total_len; 340 uint32_t total_len;
342 341
343 USBNETHIST_CALLARGSN(5, "%jd: enter: status %#jx xfer %#jx", 342 USBNETHIST_CALLARGSN(5, "%jd: enter: status %#jx xfer %#jx",
344 unp->unp_number, status, (uintptr_t)xfer, 0); 343 unp->unp_number, status, (uintptr_t)xfer, 0);
345 344
346 mutex_enter(&unp->unp_rxlock); 345 mutex_enter(&unp->unp_rxlock);
347 346
348 if (unp->unp_dying || unp->unp_stopping || 347 if (unp->unp_dying || unp->unp_stopping ||
349 status == USBD_INVAL || status == USBD_NOT_STARTED || 348 status == USBD_INVAL || status == USBD_NOT_STARTED ||
350 status == USBD_CANCELLED || !(ifp->if_flags & IFF_RUNNING)) 349 status == USBD_CANCELLED)
351 goto out; 350 goto out;
352 351
353 if (status != USBD_NORMAL_COMPLETION) { 352 if (status != USBD_NORMAL_COMPLETION) {
354 if (usbd_ratecheck(&unp->unp_rx_notice)) 353 if (usbd_ratecheck(&unp->unp_rx_notice))
355 device_printf(un->un_dev, "usb errors on rx: %s\n", 354 device_printf(un->un_dev, "usb errors on rx: %s\n",
356 usbd_errstr(status)); 355 usbd_errstr(status));
357 if (status == USBD_STALLED) 356 if (status == USBD_STALLED)
358 usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_RX]); 357 usbd_clear_endpoint_stall_async(unp->unp_ep[USBNET_ENDPT_RX]);
359 goto done; 358 goto done;
360 } 359 }
361 360
362 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL); 361 usbd_get_xfer_status(xfer, NULL, NULL, &total_len, NULL);
363 362