Thu Mar 3 05:46:58 2022 UTC ()
usbnet: Set and clear IFF_RUNNING slightly earlier and later.

- Set IFF_RUNNING before any calls to usbnet_rxeof are possible.
- Don't clear IFF_RUNNING until all transfers have been aborted.


(riastradh)
diff -r1.45 -r1.46 src/sys/dev/usb/usbnet.c

cvs diff -r1.45 -r1.46 src/sys/dev/usb/usbnet.c (expand / switch to context diff)
--- src/sys/dev/usb/usbnet.c 2022/03/03 05:46:50 1.45
+++ src/sys/dev/usb/usbnet.c 2022/03/03 05:46:58 1.46
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbnet.c,v 1.45 2022/03/03 05:46:50 riastradh Exp $	*/
+/*	$NetBSD: usbnet.c,v 1.46 2022/03/03 05:46:58 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 Matthew R. Green
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.45 2022/03/03 05:46:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbnet.c,v 1.46 2022/03/03 05:46:58 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -850,9 +850,6 @@
 		goto out;
 	}
 
-	/* Start up the receive pipe(s). */
-	usbnet_rx_start_pipes(un);
-
 	/* Indicate we are up and running. */
 #if 0
 	/* XXX if_mcast_op() can call this without ifnet locked */
@@ -860,6 +857,9 @@
 #endif
 	ifp->if_flags |= IFF_RUNNING;
 
+	/* Start up the receive pipe(s). */
+	usbnet_rx_start_pipes(un);
+
 	callout_schedule(&unp->unp_stat_ch, hz);
 
 out:
@@ -1126,14 +1126,6 @@
 
 	uno_stop(un, ifp, disable);
 
-	/*
-	 * XXXSMP Would like to
-	 *	KASSERT(IFNET_LOCKED(ifp))
-	 * here but the locking order is:
-	 *	ifnet -> core_lock -> rxlock -> txlock
-	 * and core_lock is already held.
-	 */
-	ifp->if_flags &= ~IFF_RUNNING;
 	unp->unp_timer = 0;
 
 	callout_halt(&unp->unp_stat_ch, &unp->unp_core_lock);
@@ -1149,6 +1141,15 @@
 
 	/* Close pipes. */
 	usbnet_ep_close_pipes(un);
+
+	/*
+	 * XXXSMP Would like to
+	 *	KASSERT(IFNET_LOCKED(ifp))
+	 * here but the locking order is:
+	 *	ifnet -> core_lock -> rxlock -> txlock
+	 * and core_lock is already held.
+	 */
+	ifp->if_flags &= ~IFF_RUNNING;
 
 	usbnet_unbusy(un);
 }