[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191114181702.22254-15-pierre-louis.bossart@linux.intel.com>
Date: Thu, 14 Nov 2019 12:16:54 -0600
From: Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>
To: alsa-devel@...a-project.org
Cc: linux-kernel@...r.kernel.org, tiwai@...e.de, broonie@...nel.org,
vkoul@...nel.org, gregkh@...uxfoundation.org, jank@...ence.com,
srinivas.kandagatla@...aro.org, slawomir.blauciak@...el.com,
Bard liao <yung-chuan.liao@...ux.intel.com>,
Rander Wang <rander.wang@...ux.intel.com>,
Ranjani Sridharan <ranjani.sridharan@...ux.intel.com>,
Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>,
Sanyog Kale <sanyog.r.kale@...el.com>
Subject: [PATCH v3 14/22] soundwire: bus: fix race condition by tracking UNATTACHED transition
In previous patches, we added enumeration_ and initialization_complete
fields to avoid race conditions. When streaming restarts, the Master
first resumes, then requests all Slaves to renumerate/reinitialized,
and then the Slave devices resume.
Intel validation exposed a corner case where the Slave device may
transition to D3 when streaming stops, but streaming restarts before
the Master transitions to D3. In that case, the Slave status was not
cleared as UNATTACHED, and the wait_for_completion will time out.
The proposed solution is that when the Master clears the Slave(s)
status, the reason for the Slave(s) becoming unattached is
memorized. When the slave resumes, it can check if a Master-initiated
re-enumeration and initialization takes place and skip the
wait_for_completion() if there is no reason to wait.
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>
---
drivers/soundwire/bus.c | 5 ++++-
drivers/soundwire/bus.h | 8 +++++++-
drivers/soundwire/intel.c | 16 ++++++++++++----
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 329f35a40649..ddc3042e15e0 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -1154,7 +1154,7 @@ int sdw_handle_slave_status(struct sdw_bus *bus,
}
EXPORT_SYMBOL(sdw_handle_slave_status);
-void sdw_clear_slave_status(struct sdw_bus *bus)
+void sdw_clear_slave_status(struct sdw_bus *bus, u32 request)
{
struct sdw_slave *slave;
int i;
@@ -1174,6 +1174,9 @@ void sdw_clear_slave_status(struct sdw_bus *bus)
if (slave->status != SDW_SLAVE_UNATTACHED)
sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED);
+
+ /* keep track of request, used in pm_runtime resume */
+ slave->unattach_request = request;
}
}
EXPORT_SYMBOL(sdw_clear_slave_status);
diff --git a/drivers/soundwire/bus.h b/drivers/soundwire/bus.h
index 4e6fb5d2f5cc..ee362472003a 100644
--- a/drivers/soundwire/bus.h
+++ b/drivers/soundwire/bus.h
@@ -167,6 +167,12 @@ sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)
return sdw_write(slave, addr, tmp);
}
-void sdw_clear_slave_status(struct sdw_bus *bus);
+/*
+ * At the moment we only track Master-initiated hw_reset.
+ * Additional fields can be added as needed
+ */
+#define SDW_UNATTACH_REQUEST_MASTER_RESET BIT(0)
+
+void sdw_clear_slave_status(struct sdw_bus *bus, u32 request);
#endif /* __SDW_BUS_H */
diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c
index e3741c3afe1c..69b0c8f65ad8 100644
--- a/drivers/soundwire/intel.c
+++ b/drivers/soundwire/intel.c
@@ -1402,8 +1402,12 @@ static int intel_resume(struct device *dev)
return ret;
}
- /* make sure all Slaves are tagged as UNATTACHED */
- sdw_clear_slave_status(&sdw->cdns.bus);
+ /*
+ * make sure all Slaves are tagged as UNATTACHED and provide
+ * reason for reinitialization
+ */
+ sdw_clear_slave_status(&sdw->cdns.bus,
+ SDW_UNATTACH_REQUEST_MASTER_RESET);
ret = sdw_cdns_enable_interrupt(cdns, true);
if (ret < 0) {
@@ -1438,8 +1442,12 @@ static int intel_resume_runtime(struct device *dev)
return ret;
}
- /* make sure all Slaves are tagged as UNATTACHED */
- sdw_clear_slave_status(&sdw->cdns.bus);
+ /*
+ * make sure all Slaves are tagged as UNATTACHED and provide
+ * reason for reinitialization
+ */
+ sdw_clear_slave_status(&sdw->cdns.bus,
+ SDW_UNATTACH_REQUEST_MASTER_RESET);
ret = sdw_cdns_enable_interrupt(cdns, true);
if (ret < 0) {
--
2.20.1
Powered by blists - more mailing lists