mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
xhci: dbc: serialize enabling and disabling dbc
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> Link: https://patch.msgid.link/20260603091132.1110849-9-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
dc2ff8ba9b
commit
520058b73b
|
|
@ -661,17 +661,6 @@ static int xhci_do_dbc_start(struct xhci_dbc *dbc)
|
||||||
return 0;
|
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)
|
static int xhci_dbc_start(struct xhci_dbc *dbc)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -683,29 +672,37 @@ static int xhci_dbc_start(struct xhci_dbc *dbc)
|
||||||
|
|
||||||
spin_lock_irqsave(&dbc->lock, flags);
|
spin_lock_irqsave(&dbc->lock, flags);
|
||||||
ret = xhci_do_dbc_start(dbc);
|
ret = xhci_do_dbc_start(dbc);
|
||||||
|
if (ret)
|
||||||
|
goto err_unlock;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dbc->lock, flags);
|
spin_unlock_irqrestore(&dbc->lock, flags);
|
||||||
|
|
||||||
if (ret) {
|
mod_delayed_work(system_percpu_wq, &dbc->event_work,
|
||||||
pm_runtime_put(dbc->dev); /* note this was self.controller */
|
msecs_to_jiffies(dbc->poll_interval));
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mod_delayed_work(system_percpu_wq, &dbc->event_work,
|
return 0;
|
||||||
msecs_to_jiffies(dbc->poll_interval));
|
|
||||||
|
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)
|
static void xhci_dbc_stop(struct xhci_dbc *dbc)
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
WARN_ON(!dbc);
|
WARN_ON(!dbc);
|
||||||
|
|
||||||
|
spin_lock(&dbc->lock);
|
||||||
|
|
||||||
switch (dbc->state) {
|
switch (dbc->state) {
|
||||||
case DS_DISABLED:
|
case DS_DISABLED:
|
||||||
|
spin_unlock(&dbc->lock);
|
||||||
return;
|
return;
|
||||||
case DS_CONFIGURED:
|
case DS_CONFIGURED:
|
||||||
spin_lock(&dbc->lock);
|
|
||||||
xhci_dbc_flush_requests(dbc);
|
xhci_dbc_flush_requests(dbc);
|
||||||
spin_unlock(&dbc->lock);
|
spin_unlock(&dbc->lock);
|
||||||
|
|
||||||
|
|
@ -713,19 +710,20 @@ static void xhci_dbc_stop(struct xhci_dbc *dbc)
|
||||||
dbc->driver->disconnect(dbc);
|
dbc->driver->disconnect(dbc);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
spin_unlock(&dbc->lock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel_delayed_work_sync(&dbc->event_work);
|
cancel_delayed_work_sync(&dbc->event_work);
|
||||||
|
|
||||||
spin_lock_irqsave(&dbc->lock, flags);
|
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);
|
spin_unlock_irqrestore(&dbc->lock, flags);
|
||||||
if (ret)
|
|
||||||
return;
|
|
||||||
|
|
||||||
xhci_dbc_mem_cleanup(dbc);
|
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
|
static void
|
||||||
|
|
@ -1072,12 +1070,17 @@ static ssize_t dbc_store(struct device *dev,
|
||||||
xhci = hcd_to_xhci(dev_get_drvdata(dev));
|
xhci = hcd_to_xhci(dev_get_drvdata(dev));
|
||||||
dbc = xhci->dbc;
|
dbc = xhci->dbc;
|
||||||
|
|
||||||
if (sysfs_streq(buf, "enable"))
|
if (sysfs_streq(buf, "enable")) {
|
||||||
|
mutex_lock(&dbc->enable_mutex);
|
||||||
xhci_dbc_start(dbc);
|
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);
|
xhci_dbc_stop(dbc);
|
||||||
else
|
mutex_unlock(&dbc->enable_mutex);
|
||||||
|
} else {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return count;
|
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);
|
INIT_DELAYED_WORK(&dbc->event_work, xhci_dbc_handle_events);
|
||||||
spin_lock_init(&dbc->lock);
|
spin_lock_init(&dbc->lock);
|
||||||
|
mutex_init(&dbc->enable_mutex);
|
||||||
|
|
||||||
ret = sysfs_create_groups(&dev->kobj, dbc_dev_groups);
|
ret = sysfs_create_groups(&dev->kobj, dbc_dev_groups);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|
@ -1460,8 +1464,9 @@ void xhci_dbc_remove(struct xhci_dbc *dbc)
|
||||||
if (!dbc)
|
if (!dbc)
|
||||||
return;
|
return;
|
||||||
/* stop hw, stop wq and call dbc->ops->stop() */
|
/* stop hw, stop wq and call dbc->ops->stop() */
|
||||||
|
mutex_lock(&dbc->enable_mutex);
|
||||||
xhci_dbc_stop(dbc);
|
xhci_dbc_stop(dbc);
|
||||||
|
mutex_unlock(&dbc->enable_mutex);
|
||||||
/* remove sysfs files */
|
/* remove sysfs files */
|
||||||
sysfs_remove_groups(&dbc->dev->kobj, dbc_dev_groups);
|
sysfs_remove_groups(&dbc->dev->kobj, dbc_dev_groups);
|
||||||
|
|
||||||
|
|
@ -1514,6 +1519,8 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci)
|
||||||
if (!dbc)
|
if (!dbc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
mutex_lock(&dbc->enable_mutex);
|
||||||
|
|
||||||
switch (dbc->state) {
|
switch (dbc->state) {
|
||||||
case DS_ENABLED:
|
case DS_ENABLED:
|
||||||
case DS_CONNECTED:
|
case DS_CONNECTED:
|
||||||
|
|
@ -1525,6 +1532,7 @@ int xhci_dbc_suspend(struct xhci_hcd *xhci)
|
||||||
}
|
}
|
||||||
|
|
||||||
xhci_dbc_stop(dbc);
|
xhci_dbc_stop(dbc);
|
||||||
|
mutex_unlock(&dbc->enable_mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1537,11 +1545,15 @@ int xhci_dbc_resume(struct xhci_hcd *xhci)
|
||||||
if (!dbc)
|
if (!dbc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
mutex_lock(&dbc->enable_mutex);
|
||||||
|
|
||||||
if (dbc->resume_required) {
|
if (dbc->resume_required) {
|
||||||
dbc->resume_required = 0;
|
dbc->resume_required = 0;
|
||||||
xhci_dbc_start(dbc);
|
xhci_dbc_start(dbc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_unlock(&dbc->enable_mutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM */
|
#endif /* CONFIG_PM */
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ struct dbc_driver {
|
||||||
|
|
||||||
struct xhci_dbc {
|
struct xhci_dbc {
|
||||||
spinlock_t lock; /* device access */
|
spinlock_t lock; /* device access */
|
||||||
|
struct mutex enable_mutex;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
struct xhci_hcd *xhci;
|
struct xhci_hcd *xhci;
|
||||||
struct dbc_regs __iomem *regs;
|
struct dbc_regs __iomem *regs;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user