Wed Feb 12 16:00:17 2020 UTC ()
New xfer state variables ux_timeout_set and ux_timeout_reset.

These are needed because:

- The host controller interrupt cannot wait for the callout or task
  to finish running.

- Nothing in the USBD API as is waits for the callout or task to
  finish running.

- Callers expect to be able to resubmit USB xfers from xfer callbacks
  without waiting for anything to finish running.

The variable ux_timeout_set can be used by a host controller to
decide on submission whether to schedule the callout or to ask an
already-scheduled callout or already-queued task to reschedule the
callout, by setting the variable ux_timeout_reset to true.

When the callout or task runs and sees that ux_timeout_reset is true,
rather than queue the task or abort the xfer, it can instead just
schedule the callout anew.


(riastradh)
diff -r1.190 -r1.191 src/sys/dev/usb/usbdi.c
diff -r1.120 -r1.121 src/sys/dev/usb/usbdivar.h

cvs diff -r1.190 -r1.191 src/sys/dev/usb/usbdi.c (expand / switch to context diff)
--- src/sys/dev/usb/usbdi.c 2020/02/12 15:59:59 1.190
+++ src/sys/dev/usb/usbdi.c 2020/02/12 16:00:17 1.191
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdi.c,v 1.190 2020/02/12 15:59:59 riastradh Exp $	*/
+/*	$NetBSD: usbdi.c,v 1.191 2020/02/12 16:00:17 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.190 2020/02/12 15:59:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.191 2020/02/12 16:00:17 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -494,6 +494,7 @@
 
 	/* Wait for any straggling timeout to complete. */
 	mutex_enter(xfer->ux_bus->ub_lock);
+	xfer->ux_timeout_reset = false; /* do not resuscitate */
 	callout_halt(&xfer->ux_callout, xfer->ux_bus->ub_lock);
 	usb_rem_task_wait(xfer->ux_pipe->up_dev, &xfer->ux_aborttask,
 	    USB_TASKQ_HC, xfer->ux_bus->ub_lock);

cvs diff -r1.120 -r1.121 src/sys/dev/usb/usbdivar.h (expand / switch to context diff)
--- src/sys/dev/usb/usbdivar.h 2020/02/08 08:47:27 1.120
+++ src/sys/dev/usb/usbdivar.h 2020/02/12 16:00:17 1.121
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbdivar.h,v 1.120 2020/02/08 08:47:27 maxv Exp $	*/
+/*	$NetBSD: usbdivar.h,v 1.121 2020/02/12 16:00:17 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -288,6 +288,19 @@
 
 	struct usb_task		ux_aborttask;
 	struct callout		ux_callout;
+
+	/*
+	 * Protected by bus lock.
+	 *
+	 * - ux_timeout_set: The timeout is scheduled as a callout or
+	 *   usb task, and has not yet acquired the bus lock.
+	 *
+	 * - ux_timeout_reset: The xfer completed, and was resubmitted
+	 *   before the callout or task was able to acquire the bus
+	 *   lock, so one or the other needs to schedule a new callout.
+	 */
+	bool			ux_timeout_set;
+	bool			ux_timeout_reset;
 };
 
 void usbd_init(void);