Fix usb_rem_task_wait API.

- Return whether it removed task from queue or not.
  . True if it was on the queue and we intercepted it before it ran.
  . False if we could not intercept it: either it wasn't queued,
    or it already ran.  (Up to caller to distinguish these cases.)
- Pass an optional interlock like callout_halt.

While here, simplify.

ok mrg@
This commit is contained in:
riastradh 2018-08-02 06:09:04 +00:00
parent b08dceaf5a
commit a1de014734
21 changed files with 125 additions and 116 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_athn_usb.c,v 1.28 2018/07/29 01:59:56 riastradh Exp $ */
/* $NetBSD: if_athn_usb.c,v 1.29 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_athn_usb.c,v 1.12 2013/01/14 09:50:31 jsing Exp $ */
/*-
@ -22,7 +22,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.28 2018/07/29 01:59:56 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_athn_usb.c,v 1.29 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -335,7 +335,8 @@ athn_usb_attach(device_t parent, device_t self, void *aux)
athn_usb_free_tx_cmd(usc);
athn_usb_free_tx_msg(usc);
athn_usb_close_pipes(usc);
usb_rem_task_wait(usc->usc_udev, &usc->usc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(usc->usc_udev, &usc->usc_task, USB_TASKQ_DRIVER,
NULL);
cv_destroy(&usc->usc_cmd_cv);
cv_destroy(&usc->usc_msg_cv);
@ -501,7 +502,8 @@ athn_usb_detach(device_t self, int flags)
athn_usb_wait_async(usc);
usb_rem_task_wait(usc->usc_udev, &usc->usc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(usc->usc_udev, &usc->usc_task, USB_TASKQ_DRIVER,
NULL);
/* Abort Tx/Rx pipes. */
athn_usb_abort_pipes(usc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_atu.c,v 1.62 2018/07/29 02:00:07 riastradh Exp $ */
/* $NetBSD: if_atu.c,v 1.63 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_atu.c,v 1.48 2004/12/30 01:53:21 dlg Exp $ */
/*
* Copyright (c) 2003, 2004
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.62 2018/07/29 02:00:07 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_atu.c,v 1.63 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -2235,7 +2235,7 @@ atu_stop(struct ifnet *ifp, int disable)
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
ifp->if_timer = 0;
usb_rem_task_wait(sc->atu_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->atu_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL);
ieee80211_new_state(ic, IEEE80211_S_INIT, -1);
/* Stop transfers. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_aue.c,v 1.144 2018/07/29 02:00:17 riastradh Exp $ */
/* $NetBSD: if_aue.c,v 1.145 2018/08/02 06:09:04 riastradh Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
@ -78,7 +78,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.144 2018/07/29 02:00:17 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_aue.c,v 1.145 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -894,8 +894,10 @@ aue_detach(device_t self, int flags)
* deactivation guaranteed to have already happened?
*/
callout_halt(&sc->aue_stat_ch, NULL);
usb_rem_task_wait(sc->aue_udev, &sc->aue_tick_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->aue_udev, &sc->aue_stop_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->aue_udev, &sc->aue_tick_task, USB_TASKQ_DRIVER,
NULL);
usb_rem_task_wait(sc->aue_udev, &sc->aue_stop_task, USB_TASKQ_DRIVER,
NULL);
sc->aue_closing = 1;
cv_signal(&sc->aue_domc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_axe.c,v 1.91 2018/07/29 02:00:27 riastradh Exp $ */
/* $NetBSD: if_axe.c,v 1.92 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
/*
@ -87,7 +87,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.91 2018/07/29 02:00:27 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.92 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -1112,7 +1112,8 @@ axe_detach(device_t self, int flags)
usbd_abort_pipe(sc->axe_ep[AXE_ENDPT_INTR]);
callout_halt(&sc->axe_stat_ch, NULL);
usb_rem_task_wait(sc->axe_udev, &sc->axe_tick_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->axe_udev, &sc->axe_tick_task, USB_TASKQ_DRIVER,
NULL);
s = splusb();

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_axen.c,v 1.15 2018/07/29 02:00:38 riastradh Exp $ */
/* $NetBSD: if_axen.c,v 1.16 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_axen.c,v 1.3 2013/10/21 10:10:22 yuo Exp $ */
/*
@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.15 2018/07/29 02:00:38 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_axen.c,v 1.16 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -829,7 +829,7 @@ axen_detach(device_t self, int flags)
callout_halt(&sc->axen_stat_ch, NULL);
usb_rem_task_wait(sc->axen_udev, &sc->axen_tick_task,
USB_TASKQ_DRIVER);
USB_TASKQ_DRIVER, NULL);
s = splusb();

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_cue.c,v 1.79 2018/07/29 02:00:48 riastradh Exp $ */
/* $NetBSD: if_cue.c,v 1.80 2018/08/02 06:09:04 riastradh Exp $ */
/*
* Copyright (c) 1997, 1998, 1999, 2000
* Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.79 2018/07/29 02:00:48 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_cue.c,v 1.80 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -579,8 +579,10 @@ cue_detach(device_t self, int flags)
* deactivation guaranteed to have already happened?
*/
callout_halt(&sc->cue_stat_ch, NULL);
usb_rem_task_wait(sc->cue_udev, &sc->cue_tick_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->cue_udev, &sc->cue_stop_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->cue_udev, &sc->cue_tick_task, USB_TASKQ_DRIVER,
NULL);
usb_rem_task_wait(sc->cue_udev, &sc->cue_stop_task, USB_TASKQ_DRIVER,
NULL);
if (!sc->cue_attached) {
/* Detached before attached finished, so just bail out. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_otus.c,v 1.34 2018/07/29 02:00:59 riastradh Exp $ */
/* $NetBSD: if_otus.c,v 1.35 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $ */
/*-
@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.34 2018/07/29 02:00:59 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.35 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -701,7 +701,7 @@ otus_detach(device_t self, int flags)
if (ifp != NULL) /* Failed to attach properly */
otus_stop(ifp);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL);
callout_destroy(&sc->sc_scan_to);
callout_destroy(&sc->sc_calib_to);

View File

@ -1,5 +1,5 @@
/* $OpenBSD: if_rum.c,v 1.40 2006/09/18 16:20:20 damien Exp $ */
/* $NetBSD: if_rum.c,v 1.62 2018/07/29 02:01:11 riastradh Exp $ */
/* $NetBSD: if_rum.c,v 1.63 2018/08/02 06:09:04 riastradh Exp $ */
/*-
* Copyright (c) 2005-2007 Damien Bergamini <damien.bergamini@free.fr>
@ -24,7 +24,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_rum.c,v 1.62 2018/07/29 02:01:11 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_rum.c,v 1.63 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -498,7 +498,7 @@ rum_detach(device_t self, int flags)
rum_stop(ifp, 1);
callout_halt(&sc->sc_scan_ch, NULL);
callout_halt(&sc->sc_amrr_ch, NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL);
bpf_detach(ifp);
ieee80211_ifdetach(ic); /* free all nodes */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_run.c,v 1.28 2018/07/29 02:01:22 riastradh Exp $ */
/* $NetBSD: if_run.c,v 1.29 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_run.c,v 1.90 2012/03/24 15:11:04 jsg Exp $ */
/*-
@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1.28 2018/07/29 02:01:22 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1.29 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -762,7 +762,8 @@ run_detach(device_t self, int flags)
run_stop(ifp, 0);
callout_halt(&sc->scan_to, NULL);
callout_halt(&sc->calib_to, NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER,
NULL);
}
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_smsc.c,v 1.35 2018/07/29 02:01:32 riastradh Exp $ */
/* $NetBSD: if_smsc.c,v 1.36 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_smsc.c,v 1.4 2012/09/27 12:38:11 jsg Exp $ */
/* $FreeBSD: src/sys/dev/usb/net/if_smsc.c,v 1.1 2012/08/15 04:03:55 gonzo Exp $ */
@ -1149,8 +1149,10 @@ smsc_detach(device_t self, int flags)
if (sc->sc_ep[SMSC_ENDPT_INTR] != NULL)
usbd_abort_pipe(sc->sc_ep[SMSC_ENDPT_INTR]);
usb_rem_task_wait(sc->sc_udev, &sc->sc_tick_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_stop_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_tick_task, USB_TASKQ_DRIVER,
NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_stop_task, USB_TASKQ_DRIVER,
NULL);
s = splusb();

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_udav.c,v 1.54 2018/07/29 02:01:43 riastradh Exp $ */
/* $NetBSD: if_udav.c,v 1.55 2018/08/02 06:09:04 riastradh Exp $ */
/* $nabe: if_udav.c,v 1.3 2003/08/21 16:57:19 nabe Exp $ */
/*
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.54 2018/07/29 02:01:43 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_udav.c,v 1.55 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -355,8 +355,10 @@ udav_detach(device_t self, int flags)
callout_halt(&sc->sc_stat_ch, NULL);
/* Remove any pending tasks */
usb_rem_task_wait(sc->sc_udev, &sc->sc_tick_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_stop_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_tick_task, USB_TASKQ_DRIVER,
NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_stop_task, USB_TASKQ_DRIVER,
NULL);
s = splusb();

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_upgt.c,v 1.21 2018/07/29 02:01:54 riastradh Exp $ */
/* $NetBSD: if_upgt.c,v 1.22 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_upgt.c,v 1.49 2010/04/20 22:05:43 tedu Exp $ */
/*
@ -18,7 +18,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.21 2018/07/29 02:01:54 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_upgt.c,v 1.22 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -506,8 +506,10 @@ upgt_detach(device_t self, int flags)
/* remove tasks and timeouts */
callout_halt(&sc->scan_to, NULL);
callout_halt(&sc->led_to, NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task_newstate, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task_tx, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task_newstate, USB_TASKQ_DRIVER,
NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task_tx, USB_TASKQ_DRIVER,
NULL);
callout_destroy(&sc->scan_to);
callout_destroy(&sc->led_to);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_ural.c,v 1.56 2018/07/29 02:02:04 riastradh Exp $ */
/* $NetBSD: if_ural.c,v 1.57 2018/08/02 06:09:04 riastradh Exp $ */
/* $FreeBSD: /repoman/r/ncvs/src/sys/dev/usb/if_ural.c,v 1.40 2006/06/02 23:14:40 sam Exp $ */
/*-
@ -24,7 +24,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.56 2018/07/29 02:02:04 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_ural.c,v 1.57 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -536,7 +536,7 @@ ural_detach(device_t self, int flags)
ural_stop(ifp, 1);
callout_halt(&sc->sc_scan_ch, NULL);
callout_halt(&sc->sc_amrr_ch, NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL);
bpf_detach(ifp);
ieee80211_ifdetach(ic);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_url.c,v 1.59 2018/07/29 02:08:17 riastradh Exp $ */
/* $NetBSD: if_url.c,v 1.60 2018/08/02 06:09:04 riastradh Exp $ */
/*
* Copyright (c) 2001, 2002
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.59 2018/07/29 02:08:17 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.60 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -356,8 +356,10 @@ url_detach(device_t self, int flags)
callout_halt(&sc->sc_stat_ch, NULL);
/* Remove any pending tasks */
usb_rem_task_wait(sc->sc_udev, &sc->sc_tick_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_stop_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_tick_task, USB_TASKQ_DRIVER,
NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_stop_task, USB_TASKQ_DRIVER,
NULL);
s = splusb();

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_urtw.c,v 1.16 2018/07/29 02:06:11 riastradh Exp $ */
/* $NetBSD: if_urtw.c,v 1.17 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_urtw.c,v 1.39 2011/07/03 15:47:17 matthew Exp $ */
/*-
@ -19,7 +19,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_urtw.c,v 1.16 2018/07/29 02:06:11 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_urtw.c,v 1.17 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -779,8 +779,9 @@ urtw_detach(device_t self, int flags)
callout_destroy(&sc->scan_to);
callout_destroy(&sc->sc_led_ch);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_ledtask, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_ledtask, USB_TASKQ_DRIVER,
NULL);
if (ifp->if_softc != NULL) {
bpf_detach(ifp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_urtwn.c,v 1.62 2018/07/30 00:17:28 jmcneill Exp $ */
/* $NetBSD: if_urtwn.c,v 1.63 2018/08/02 06:09:04 riastradh Exp $ */
/* $OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $ */
/*-
@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.62 2018/07/30 00:17:28 jmcneill Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.63 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -544,7 +544,8 @@ urtwn_detach(device_t self, int flags)
if (ISSET(sc->sc_flags, URTWN_FLAG_ATTACHED)) {
urtwn_stop(ifp, 0);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER,
NULL);
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
bpf_detach(ifp);

View File

@ -1,5 +1,5 @@
/* $OpenBSD: if_zyd.c,v 1.52 2007/02/11 00:08:04 jsg Exp $ */
/* $NetBSD: if_zyd.c,v 1.49 2018/07/29 02:07:33 riastradh Exp $ */
/* $NetBSD: if_zyd.c,v 1.50 2018/08/02 06:09:04 riastradh Exp $ */
/*-
* Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr>
@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_zyd.c,v 1.49 2018/07/29 02:07:33 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_zyd.c,v 1.50 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -468,7 +468,7 @@ zyd_detach(device_t self, int flags)
zyd_stop(ifp, 1);
callout_halt(&sc->sc_scan_ch, NULL);
callout_halt(&sc->sc_amrr_ch, NULL);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER, NULL);
/* Abort, etc. done by zyd_stop */
zyd_close_pipes(sc);

View File

@ -1,4 +1,4 @@
/* $NetBSD: uatp.c,v 1.16 2018/07/29 02:07:46 riastradh Exp $ */
/* $NetBSD: uatp.c,v 1.17 2018/08/02 06:09:04 riastradh Exp $ */
/*-
* Copyright (c) 2011-2014 The NetBSD Foundation, Inc.
@ -146,7 +146,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uatp.c,v 1.16 2018/07/29 02:07:46 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: uatp.c,v 1.17 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -1363,7 +1363,7 @@ geyser34_finalize(struct uatp_softc *sc)
DPRINTF(sc, UATP_DEBUG_MISC, ("finalizing\n"));
usb_rem_task_wait(sc->sc_hdev.sc_parent->sc_udev, &sc->sc_reset_task,
USB_TASKQ_DRIVER);
USB_TASKQ_DRIVER, NULL);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb.c,v 1.170 2018/07/29 01:59:46 riastradh Exp $ */
/* $NetBSD: usb.c,v 1.171 2018/08/02 06:09:04 riastradh Exp $ */
/*
* Copyright (c) 1998, 2002, 2008, 2012 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.170 2018/07/29 01:59:46 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: usb.c,v 1.171 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@ -458,28 +458,13 @@ usb_rem_task(struct usbd_device *dev, struct usb_task *task)
}
/*
* usb_taskq_wait(taskq, task)
*
* Wait for taskq to finish executing task, if it is executing
* task. Caller must hold the taskq lock.
*/
static void
usb_taskq_wait(struct usb_taskq *taskq, struct usb_task *task)
{
KASSERT(mutex_owned(&taskq->lock));
while (taskq->current_task == task)
cv_wait(&taskq->cv, &taskq->lock);
KASSERT(taskq->current_task != task);
}
/*
* usb_rem_task_wait(dev, task, queue)
* usb_rem_task_wait(dev, task, queue, interlock)
*
* If task is scheduled to run, remove it from the queue. If it
* may have already begun to run, wait for it to complete.
* may have already begun to run, drop interlock if not null, wait
* for it to complete, and reacquire interlock if not null.
* Return true if it successfully removed the task from the queue,
* false if not.
*
* Caller MUST guarantee that task will not be scheduled on a
* _different_ queue, at least until after this returns.
@ -490,11 +475,13 @@ usb_taskq_wait(struct usb_taskq *taskq, struct usb_task *task)
*
* May sleep.
*/
void
usb_rem_task_wait(struct usbd_device *dev, struct usb_task *task, int queue)
bool
usb_rem_task_wait(struct usbd_device *dev, struct usb_task *task, int queue,
kmutex_t *interlock)
{
struct usb_taskq *taskq;
int queue1;
bool removed;
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
ASSERT_SLEEPABLE();
@ -502,38 +489,40 @@ usb_rem_task_wait(struct usbd_device *dev, struct usb_task *task, int queue)
KASSERT(queue < USB_NUM_TASKQS);
taskq = &usb_taskq[queue];
if ((queue1 = task->queue) == USB_NUM_TASKQS) {
mutex_enter(&taskq->lock);
queue1 = task->queue;
if (queue1 == USB_NUM_TASKQS) {
/*
* It is not on the queue, but it may have already run.
* Wait for it.
* It is not on the queue. It may be about to run, or
* it may have already finished running -- there is no
* stopping it now. Wait for it if it is running.
*/
mutex_enter(&taskq->lock);
usb_taskq_wait(taskq, task);
mutex_exit(&taskq->lock);
if (interlock)
mutex_exit(interlock);
while (taskq->current_task == task)
cv_wait(&taskq->cv, &taskq->lock);
removed = false;
} else {
/*
* It may be on the queue (and not another one), but
* the state may have changed by now because we don't
* have the queue locked. Lock and reload.
* It is still on the queue. We can stop it before the
* task thread will run it.
*/
KASSERTMSG(queue1 == queue,
"task %p on q%d expected on q%d", task, queue1, queue);
mutex_enter(&taskq->lock);
queue1 = task->queue;
if (queue1 == queue) {
/* Still queued, not run. Just remove it. */
TAILQ_REMOVE(&taskq->tasks, task, next);
task->queue = USB_NUM_TASKQS;
} else {
/* Already ran. Wait for it. */
KASSERTMSG(queue1 == USB_NUM_TASKQS,
"task %p on q%d expected on q%d",
task, queue1, queue);
usb_taskq_wait(taskq, task);
}
mutex_exit(&taskq->lock);
KASSERTMSG(queue1 == queue, "task %p on q%d expected on q%d",
task, queue1, queue);
TAILQ_REMOVE(&taskq->tasks, task, next);
task->queue = USB_NUM_TASKQS;
removed = true;
}
mutex_exit(&taskq->lock);
/*
* If there's an interlock, and we dropped it to wait,
* reacquire it.
*/
if (interlock && !removed)
mutex_enter(interlock);
return removed;
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb_subr.c,v 1.225 2018/07/29 02:08:07 riastradh Exp $ */
/* $NetBSD: usb_subr.c,v 1.226 2018/08/02 06:09:04 riastradh Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
/*
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.225 2018/07/29 02:08:07 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.226 2018/08/02 06:09:04 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -823,7 +823,8 @@ usbd_kill_pipe(struct usbd_pipe *pipe)
usbd_lock_pipe(pipe);
pipe->up_methods->upm_close(pipe);
usbd_unlock_pipe(pipe);
usb_rem_task_wait(pipe->up_dev, &pipe->up_async_task, USB_TASKQ_DRIVER);
usb_rem_task_wait(pipe->up_dev, &pipe->up_async_task, USB_TASKQ_DRIVER,
NULL);
pipe->up_endpoint->ue_refcnt--;
kmem_free(pipe, pipe->up_dev->ud_bus->ub_pipesize);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbdi.h,v 1.94 2018/07/31 16:44:30 khorben Exp $ */
/* $NetBSD: usbdi.h,v 1.95 2018/08/02 06:09:04 riastradh Exp $ */
/* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */
/*
@ -221,7 +221,8 @@ struct usb_task {
void usb_add_task(struct usbd_device *, struct usb_task *, int);
void usb_rem_task(struct usbd_device *, struct usb_task *);
void usb_rem_task_wait(struct usbd_device *, struct usb_task *, int);
bool usb_rem_task_wait(struct usbd_device *, struct usb_task *, int,
kmutex_t *);
#define usb_init_task(t, f, a, fl) ((t)->fun = (f), (t)->arg = (a), (t)->queue = USB_NUM_TASKQS, (t)->flags = (fl))
struct usb_devno {