mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-27 06:04:23 +08:00
soundwire: cadence: re-check Peripheral status with delayed_work
[ Upstream commit f8c35d61ba
]
The SoundWire peripheral enumeration is entirely based on interrupts,
more specifically sticky bits tracking state changes.
This patch adds a defensive programming check on the actual status
reported in PING frames. If for some reason an interrupt was lost or
delayed, the delayed work would detect a peripheral change of status
after the bus starts.
The 100ms defined for the delay is not completely arbitrary, if a
Peripheral didn't join the bus within that delay then probably the
hardware link is broken, and conversely if the detection didn't happen
because of software issues the 100ms is still acceptable in terms of
user experience.
The overhead of the one-shot workqueue is minimal, and the mutual
exclusion ensures that the interrupt and delayed work cannot update
the status concurrently.
Reviewed-by: Liam Girdwood <liam.r.girdwood@intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20240805114921.88007-1-yung-chuan.liao@linux.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
99002ae8a1
commit
740a6059c3
@ -891,8 +891,14 @@ static int cdns_update_slave_status(struct sdw_cdns *cdns,
|
||||
}
|
||||
}
|
||||
|
||||
if (is_slave)
|
||||
return sdw_handle_slave_status(&cdns->bus, status);
|
||||
if (is_slave) {
|
||||
int ret;
|
||||
|
||||
mutex_lock(&cdns->status_update_lock);
|
||||
ret = sdw_handle_slave_status(&cdns->bus, status);
|
||||
mutex_unlock(&cdns->status_update_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -989,6 +995,31 @@ irqreturn_t sdw_cdns_irq(int irq, void *dev_id)
|
||||
}
|
||||
EXPORT_SYMBOL(sdw_cdns_irq);
|
||||
|
||||
static void cdns_check_attached_status_dwork(struct work_struct *work)
|
||||
{
|
||||
struct sdw_cdns *cdns =
|
||||
container_of(work, struct sdw_cdns, attach_dwork.work);
|
||||
enum sdw_slave_status status[SDW_MAX_DEVICES + 1];
|
||||
u32 val;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
val = cdns_readl(cdns, CDNS_MCP_SLAVE_STAT);
|
||||
|
||||
for (i = 0; i <= SDW_MAX_DEVICES; i++) {
|
||||
status[i] = val & 0x3;
|
||||
if (status[i])
|
||||
dev_dbg(cdns->dev, "Peripheral %d status: %d\n", i, status[i]);
|
||||
val >>= 2;
|
||||
}
|
||||
|
||||
mutex_lock(&cdns->status_update_lock);
|
||||
ret = sdw_handle_slave_status(&cdns->bus, status);
|
||||
mutex_unlock(&cdns->status_update_lock);
|
||||
if (ret < 0)
|
||||
dev_err(cdns->dev, "%s: sdw_handle_slave_status failed: %d\n", __func__, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* cdns_update_slave_status_work - update slave status in a work since we will need to handle
|
||||
* other interrupts eg. CDNS_MCP_INT_RX_WL during the update slave
|
||||
@ -1745,7 +1776,11 @@ int sdw_cdns_probe(struct sdw_cdns *cdns)
|
||||
init_completion(&cdns->tx_complete);
|
||||
cdns->bus.port_ops = &cdns_port_ops;
|
||||
|
||||
mutex_init(&cdns->status_update_lock);
|
||||
|
||||
INIT_WORK(&cdns->work, cdns_update_slave_status_work);
|
||||
INIT_DELAYED_WORK(&cdns->attach_dwork, cdns_check_attached_status_dwork);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(sdw_cdns_probe);
|
||||
|
@ -117,6 +117,8 @@ struct sdw_cdns_dai_runtime {
|
||||
* @link_up: Link status
|
||||
* @msg_count: Messages sent on bus
|
||||
* @dai_runtime_array: runtime context for each allocated DAI.
|
||||
* @status_update_lock: protect concurrency between interrupt-based and delayed work
|
||||
* status update
|
||||
*/
|
||||
struct sdw_cdns {
|
||||
struct device *dev;
|
||||
@ -148,10 +150,13 @@ struct sdw_cdns {
|
||||
bool interrupt_enabled;
|
||||
|
||||
struct work_struct work;
|
||||
struct delayed_work attach_dwork;
|
||||
|
||||
struct list_head list;
|
||||
|
||||
struct sdw_cdns_dai_runtime **dai_runtime_array;
|
||||
|
||||
struct mutex status_update_lock; /* add mutual exclusion to sdw_handle_slave_status() */
|
||||
};
|
||||
|
||||
#define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
|
||||
|
@ -91,6 +91,8 @@ static inline void intel_writew(void __iomem *base, int offset, u16 value)
|
||||
|
||||
#define INTEL_MASTER_RESET_ITERATIONS 10
|
||||
|
||||
#define SDW_INTEL_DELAYED_ENUMERATION_MS 100
|
||||
|
||||
#define SDW_INTEL_CHECK_OPS(sdw, cb) ((sdw) && (sdw)->link_res && (sdw)->link_res->hw_ops && \
|
||||
(sdw)->link_res->hw_ops->cb)
|
||||
#define SDW_INTEL_OPS(sdw, cb) ((sdw)->link_res->hw_ops->cb)
|
||||
|
@ -398,6 +398,7 @@ static void intel_link_remove(struct auxiliary_device *auxdev)
|
||||
*/
|
||||
if (!bus->prop.hw_disabled) {
|
||||
sdw_intel_debugfs_exit(sdw);
|
||||
cancel_delayed_work_sync(&cdns->attach_dwork);
|
||||
sdw_cdns_enable_interrupt(cdns, false);
|
||||
}
|
||||
sdw_bus_master_delete(bus);
|
||||
|
@ -60,6 +60,9 @@ int intel_start_bus(struct sdw_intel *sdw)
|
||||
sdw_cdns_check_self_clearing_bits(cdns, __func__,
|
||||
true, INTEL_MASTER_RESET_ITERATIONS);
|
||||
|
||||
schedule_delayed_work(&cdns->attach_dwork,
|
||||
msecs_to_jiffies(SDW_INTEL_DELAYED_ENUMERATION_MS));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -151,6 +154,9 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw)
|
||||
}
|
||||
sdw_cdns_check_self_clearing_bits(cdns, __func__, true, INTEL_MASTER_RESET_ITERATIONS);
|
||||
|
||||
schedule_delayed_work(&cdns->attach_dwork,
|
||||
msecs_to_jiffies(SDW_INTEL_DELAYED_ENUMERATION_MS));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -184,6 +190,9 @@ int intel_start_bus_after_clock_stop(struct sdw_intel *sdw)
|
||||
|
||||
sdw_cdns_check_self_clearing_bits(cdns, __func__, true, INTEL_MASTER_RESET_ITERATIONS);
|
||||
|
||||
schedule_delayed_work(&cdns->attach_dwork,
|
||||
msecs_to_jiffies(SDW_INTEL_DELAYED_ENUMERATION_MS));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -194,6 +203,8 @@ int intel_stop_bus(struct sdw_intel *sdw, bool clock_stop)
|
||||
bool wake_enable = false;
|
||||
int ret;
|
||||
|
||||
cancel_delayed_work_sync(&cdns->attach_dwork);
|
||||
|
||||
if (clock_stop) {
|
||||
ret = sdw_cdns_clock_stop(cdns, true);
|
||||
if (ret < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user