From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 08/15] xhci: dbc: serialize enabling and disabling dbc
Date: Wed, 3 Jun 2026 12:11:25 +0300 [thread overview]
Message-ID: <20260603091132.1110849-9-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20260603091132.1110849-1-mathias.nyman@linux.intel.com>
DbC can be enabled and disabled via sysfs, serialize those
with a mutex to make sure everything is done in the correct
order.
remove xhci_do_dbc_stop() and integrate the register write and
dbc->state setting into xhci_do_stop()
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-dbgcap.c | 66 ++++++++++++++++++++--------------
drivers/usb/host/xhci-dbgcap.h | 1 +
2 files changed, 40 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 6a9f73fecb73..49ae546c4103 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -661,17 +661,6 @@ static int xhci_do_dbc_start(struct xhci_dbc *dbc)
return 0;
}
-static int xhci_do_dbc_stop(struct xhci_dbc *dbc)
-{
- if (dbc->state == DS_DISABLED)
- return -EINVAL;
-
- writel(0, &dbc->regs->control);
- dbc->state = DS_DISABLED;
-
- return 0;
-}
-
static int xhci_dbc_start(struct xhci_dbc *dbc)
{
int ret;
@@ -683,29 +672,37 @@ static int xhci_dbc_start(struct xhci_dbc *dbc)
spin_lock_irqsave(&dbc->lock, flags);
ret = xhci_do_dbc_start(dbc);
+ if (ret)
+ goto err_unlock;
+
spin_unlock_irqrestore(&dbc->lock, flags);
- if (ret) {
- pm_runtime_put(dbc->dev); /* note this was self.controller */
- return ret;
- }
+ mod_delayed_work(system_percpu_wq, &dbc->event_work,
+ msecs_to_jiffies(dbc->poll_interval));
- return mod_delayed_work(system_percpu_wq, &dbc->event_work,
- msecs_to_jiffies(dbc->poll_interval));
+ return 0;
+
+err_unlock:
+
+ spin_unlock_irqrestore(&dbc->lock, flags);
+ pm_runtime_put(dbc->dev); /* note this was self.controller */
+
+ return ret;
}
static void xhci_dbc_stop(struct xhci_dbc *dbc)
{
- int ret;
unsigned long flags;
WARN_ON(!dbc);
+ spin_lock(&dbc->lock);
+
switch (dbc->state) {
case DS_DISABLED:
+ spin_unlock(&dbc->lock);
return;
case DS_CONFIGURED:
- spin_lock(&dbc->lock);
xhci_dbc_flush_requests(dbc);
spin_unlock(&dbc->lock);
@@ -713,19 +710,20 @@ static void xhci_dbc_stop(struct xhci_dbc *dbc)
dbc->driver->disconnect(dbc);
break;
default:
+ spin_unlock(&dbc->lock);
break;
}
cancel_delayed_work_sync(&dbc->event_work);
spin_lock_irqsave(&dbc->lock, flags);
- ret = xhci_do_dbc_stop(dbc);
+ writel(0, &dbc->regs->control);
+ dbc->state = DS_DISABLED;
spin_unlock_irqrestore(&dbc->lock, flags);
- if (ret)
- return;
xhci_dbc_mem_cleanup(dbc);
- pm_runtime_put_sync(dbc->dev); /* note, was self.controller */
+
+ pm_runtime_put(dbc->dev); /* note, was self.controller */
}
static void
@@ -1072,12 +1070,17 @@ static ssize_t dbc_store(struct device *dev,
xhci = hcd_to_xhci(dev_get_drvdata(dev));
dbc = xhci->dbc;
- if (sysfs_streq(buf, "enable"))
+ if (sysfs_streq(buf, "enable")) {
+ mutex_lock(&dbc->enable_mutex);
xhci_dbc_start(dbc);
- else if (sysfs_streq(buf, "disable"))
+ mutex_unlock(&dbc->enable_mutex);
+ } else if (sysfs_streq(buf, "disable")) {
+ mutex_lock(&dbc->enable_mutex);
xhci_dbc_stop(dbc);
- else
+ mutex_unlock(&dbc->enable_mutex);
+ } else {
return -EINVAL;
+ }
return count;
}
@@ -1443,6 +1446,7 @@ xhci_alloc_dbc(struct device *dev, void __iomem *base, const struct dbc_driver *
INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
spin_lock_init(&dbc->lock);
+ mutex_init(&dbc->enable_mutex);
ret = sysfs_create_groups(&dev->kobj, dbc_dev_groups);
if (ret)
@@ -1460,8 +1464,9 @@ void xhci_dbc_remove(struct xhci_dbc *dbc)
if (!dbc)
return;
/* stop hw, stop wq and call dbc->ops->stop() */
+ mutex_lock(&dbc->enable_mutex);
xhci_dbc_stop(dbc);
-
+ mutex_unlock(&dbc->enable_mutex);
/* remove sysfs files */
sysfs_remove_groups(&dbc->dev->kobj, dbc_dev_groups);
@@ -1514,6 +1519,8 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci)
if (!dbc)
return 0;
+ mutex_lock(&dbc->enable_mutex);
+
switch (dbc->state) {
case DS_ENABLED:
case DS_CONNECTED:
@@ -1525,6 +1532,7 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci)
}
xhci_dbc_stop(dbc);
+ mutex_unlock(&dbc->enable_mutex);
return 0;
}
@@ -1537,11 +1545,15 @@ int xhci_dbc_resume(struct xhci_hcd *xhci)
if (!dbc)
return 0;
+ mutex_lock(&dbc->enable_mutex);
+
if (dbc->resume_required) {
dbc->resume_required = 0;
xhci_dbc_start(dbc);
}
+ mutex_unlock(&dbc->enable_mutex);
+
return ret;
}
#endif /* CONFIG_PM */
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index 20ae4e7617f2..f4c0169a1b4d 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -140,6 +140,7 @@ struct dbc_driver {
struct xhci_dbc {
spinlock_t lock; /* device access */
+ struct mutex enable_mutex;
struct device *dev;
struct xhci_hcd *xhci;
struct dbc_regs __iomem *regs;
--
2.43.0
next prev parent reply other threads:[~2026-06-03 9:12 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 9:11 [PATCH 00/15] xhci features for usb-next Mathias Nyman
2026-06-03 9:11 ` [PATCH 01/15] usb: xhci: fix typo in xhci_set_port_power() comment Mathias Nyman
2026-06-03 9:11 ` [PATCH 02/15] usb: xhci: remove legacy 'num_trbs_free' tracking Mathias Nyman
2026-06-03 9:11 ` [PATCH 03/15] usb: xhci: Simplify xhci_quiesce() Mathias Nyman
2026-06-03 9:11 ` [PATCH 04/15] usb: xhci: Remove skip_isoc_td() Mathias Nyman
2026-06-03 9:11 ` [PATCH 05/15] usb: xhci: Remove isochronous URB_SHORT_NOT_OK handling Mathias Nyman
2026-06-03 9:11 ` [PATCH 06/15] usb: xhci: Improve Soft Retries after short transfers Mathias Nyman
2026-06-03 9:11 ` [PATCH 07/15] xhci: dbc: Fix sysfs ABI Documentation for xhci dbc states Mathias Nyman
2026-06-03 9:11 ` Mathias Nyman [this message]
2026-06-15 6:11 ` [PATCH 08/15] xhci: dbc: serialize enabling and disabling dbc Borah, Chaitanya Kumar
2026-06-15 8:47 ` Mathias Nyman
2026-06-15 8:55 ` [RFT PATCH] xhci: dbc: support runtime suspend while DbC is in enabled state Mathias Nyman
2026-06-15 12:14 ` Borah, Chaitanya Kumar
2026-06-03 9:11 ` [PATCH 09/15] xhci: dbc: add helper to set and clear DbC DCE enable bit Mathias Nyman
2026-06-03 9:11 ` [PATCH 10/15] xhci: dbc: add timestamps to DbC state changes in a new helper Mathias Nyman
2026-06-03 9:11 ` [PATCH 11/15] xhci: dbc: detect and recover hung DbC during enumeraton Mathias Nyman
2026-06-03 9:11 ` [PATCH 12/15] xhci: Prevent queuing new commands if xhci is inaccessible Mathias Nyman
2026-06-03 9:11 ` [PATCH 13/15] usb: xhci: refactor DCBAA struct Mathias Nyman
2026-06-03 9:11 ` [PATCH 14/15] usb: xhci: allocate DCBAA based on host controller max slots Mathias Nyman
2026-06-03 9:11 ` [PATCH 15/15] usb: xhci: allocate internal DCBAA mirror dynamically Mathias Nyman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260603091132.1110849-9-mathias.nyman@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox