From 31553ea700b0e66a3d02b523bc09c6e722d8a044 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Mon, 30 Nov 2026 15:57:47 +0100 Subject: [PATCH 1/3] soundwire: intel_bus_common: error handling on cdns_init() For some reason only one of the two calls of cdns_init() is error-checked, align error handling for consistency. Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/intel_bus_common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/soundwire/intel_bus_common.c b/drivers/soundwire/intel_bus_common.c index fa35eb2fc76328..5f629c593bb6b1 100644 --- a/drivers/soundwire/intel_bus_common.c +++ b/drivers/soundwire/intel_bus_common.c @@ -110,8 +110,11 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw) /* * Re-initialize the IP since it was powered-off */ - sdw_cdns_init(&sdw->cdns); - + ret = sdw_cdns_init(&sdw->cdns); + if (ret < 0) { + dev_err(dev, "%s: unable to initialize Cadence IP: %d\n", __func__, ret); + return ret; + } } else { ret = sdw_cdns_enable_interrupt(cdns, true); if (ret < 0) { From bb0f6f84a11e73a34975e06d2539d51494bc6f55 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Mon, 30 Nov 2026 16:01:43 +0100 Subject: [PATCH 2/3] soundwire: intel: add sync_arm_unlocked() helper AI models report a possible race condition when starting multiple links. Add new helper to take lock at a higher level, following the example of sync_go_unlocked. Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/intel.c | 12 +++++++++--- drivers/soundwire/intel.h | 6 ++++++ drivers/soundwire/intel_ace2x.c | 10 ++++++++-- include/linux/soundwire/sdw_intel.h | 3 +++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index af65214836b4d0..bde06d0232c7e0 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -497,17 +497,22 @@ static int intel_link_power_down(struct sdw_intel *sdw) return ret; } -static void intel_shim_sync_arm(struct sdw_intel *sdw) +static void intel_shim_sync_arm_unlocked(struct sdw_intel *sdw) { void __iomem *shim = sdw->link_res->shim; u32 sync_reg; - mutex_lock(sdw->link_res->shim_lock); - /* update SYNC register */ sync_reg = intel_readl(shim, SDW_SHIM_SYNC); sync_reg |= (SDW_SHIM_SYNC_CMDSYNC << sdw->instance); intel_writel(shim, SDW_SHIM_SYNC, sync_reg); +} + +static void intel_shim_sync_arm(struct sdw_intel *sdw) +{ + mutex_lock(sdw->link_res->shim_lock); + + intel_shim_sync_arm_unlocked(sdw); mutex_unlock(sdw->link_res->shim_lock); } @@ -1088,6 +1093,7 @@ const struct sdw_intel_hw_ops sdw_intel_cnl_hw_ops = { .pre_bank_switch = intel_pre_bank_switch, .post_bank_switch = intel_post_bank_switch, + .sync_arm_unlocked = intel_shim_sync_arm_unlocked, .sync_arm = intel_shim_sync_arm, .sync_go_unlocked = intel_shim_sync_go_unlocked, .sync_go = intel_shim_sync_go, diff --git a/drivers/soundwire/intel.h b/drivers/soundwire/intel.h index 7a2e7e73ad632a..0e8c93e223c802 100644 --- a/drivers/soundwire/intel.h +++ b/drivers/soundwire/intel.h @@ -222,6 +222,12 @@ static inline void sdw_intel_shim_wake(struct sdw_intel *sdw, bool wake_enable) SDW_INTEL_OPS(sdw, shim_wake)(sdw, wake_enable); } +static inline void sdw_intel_sync_arm_unlocked(struct sdw_intel *sdw) +{ + if (SDW_INTEL_CHECK_OPS(sdw, sync_arm_unlocked)) + SDW_INTEL_OPS(sdw, sync_arm_unlocked)(sdw); +} + static inline void sdw_intel_sync_arm(struct sdw_intel *sdw) { if (SDW_INTEL_CHECK_OPS(sdw, sync_arm)) diff --git a/drivers/soundwire/intel_ace2x.c b/drivers/soundwire/intel_ace2x.c index 642b33ab552606..eebb4d44b6de4a 100644 --- a/drivers/soundwire/intel_ace2x.c +++ b/drivers/soundwire/intel_ace2x.c @@ -631,13 +631,18 @@ static int intel_link_power_down(struct sdw_intel *sdw) return ret; } -static void intel_sync_arm(struct sdw_intel *sdw) +static void intel_sync_arm_unlocked(struct sdw_intel *sdw) { unsigned int link_id = sdw->instance; + hdac_bus_eml_sdw_sync_arm_unlocked(sdw->link_res->hbus, link_id); +} + +static void intel_sync_arm(struct sdw_intel *sdw) +{ mutex_lock(sdw->link_res->shim_lock); - hdac_bus_eml_sdw_sync_arm_unlocked(sdw->link_res->hbus, link_id); + intel_sync_arm_unlocked(sdw); mutex_unlock(sdw->link_res->shim_lock); } @@ -1166,6 +1171,7 @@ const struct sdw_intel_hw_ops sdw_intel_lnl_hw_ops = { .pre_bank_switch = intel_pre_bank_switch, .post_bank_switch = intel_post_bank_switch, + .sync_arm_unlocked = intel_sync_arm_unlocked, .sync_arm = intel_sync_arm, .sync_go_unlocked = intel_sync_go_unlocked, .sync_go = intel_sync_go, diff --git a/include/linux/soundwire/sdw_intel.h b/include/linux/soundwire/sdw_intel.h index 9710f2dc04e298..1d10183566aa23 100644 --- a/include/linux/soundwire/sdw_intel.h +++ b/include/linux/soundwire/sdw_intel.h @@ -404,6 +404,8 @@ struct sdw_intel; * @shim_wake: enable/disable in-band wake management * @pre_bank_switch: helper for bus management * @post_bank_switch: helper for bus management + * @sync_arm_unlocked: helper for multi-link synchronization - + * shim_lock is assumed to be locked at higher level * @sync_arm: helper for multi-link synchronization * @sync_go_unlocked: helper for multi-link synchronization - * shim_lock is assumed to be locked at higher level @@ -435,6 +437,7 @@ struct sdw_intel_hw_ops { int (*pre_bank_switch)(struct sdw_intel *sdw); int (*post_bank_switch)(struct sdw_intel *sdw); + void (*sync_arm_unlocked)(struct sdw_intel *sdw); void (*sync_arm)(struct sdw_intel *sdw); int (*sync_go_unlocked)(struct sdw_intel *sdw); int (*sync_go)(struct sdw_intel *sdw); From 6225763e4c0d610b467b76b6197f718e5bcb442a Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Mon, 30 Nov 2026 16:13:16 +0100 Subject: [PATCH 3/3] soundwire: intel_bus_common: use shim_lock for sync_arm/go sequence AI models expose a possible race condition when starting multiple links in parallel. Link A: Link B: sync_arm sync_arm config_update ... sync_go ... config_update sync_go The sync_go on Link A would clear the CMDSYNC bit for link B, but the config_update has not taken place just yet and the second sync_go would be a no-op - Link B would not start. The suggested fix is to rely on the shim_lock to start each link in a more atomic way. Note that this race condition does not happen during a regular bank switch where the Cadence IP does not need to be configured. It's the sync_arm+config_update that's problematic only on startup/resume. Link: https://lore.kernel.org/linux-sound/0ece6c88-9e3d-4d30-9027-21722bea8754@linux.dev/T/#m74e6c505170df142d8015c93fef1f881e0f5d394 Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/intel_bus_common.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/soundwire/intel_bus_common.c b/drivers/soundwire/intel_bus_common.c index 5f629c593bb6b1..61e0f99669ef4d 100644 --- a/drivers/soundwire/intel_bus_common.c +++ b/drivers/soundwire/intel_bus_common.c @@ -26,11 +26,15 @@ int intel_start_bus(struct sdw_intel *sdw) * follow recommended programming flows to avoid timeouts when * gsync is enabled */ - if (bus->multi_link) - sdw_intel_sync_arm(sdw); + if (bus->multi_link) { + mutex_lock(sdw->link_res->shim_lock); + sdw_intel_sync_arm_unlocked(sdw); + } ret = sdw_cdns_init(cdns); if (ret < 0) { + if (bus->multi_link) + mutex_unlock(sdw->link_res->shim_lock); dev_err(dev, "%s: unable to initialize Cadence IP: %d\n", __func__, ret); return ret; } @@ -38,7 +42,8 @@ int intel_start_bus(struct sdw_intel *sdw) sdw_cdns_config_update(cdns); if (bus->multi_link) { - ret = sdw_intel_sync_go(sdw); + ret = sdw_intel_sync_go_unlocked(sdw); + mutex_unlock(sdw->link_res->shim_lock); if (ret < 0) { dev_err(dev, "%s: sync go failed: %d\n", __func__, ret); return ret; @@ -104,14 +109,18 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw) * follow recommended programming flows to avoid * timeouts when gsync is enabled */ - if (bus->multi_link) - sdw_intel_sync_arm(sdw); + if (bus->multi_link) { + mutex_lock(sdw->link_res->shim_lock); + sdw_intel_sync_arm_unlocked(sdw); + } /* * Re-initialize the IP since it was powered-off */ ret = sdw_cdns_init(&sdw->cdns); if (ret < 0) { + if (bus->multi_link) + mutex_unlock(sdw->link_res->shim_lock); dev_err(dev, "%s: unable to initialize Cadence IP: %d\n", __func__, ret); return ret; } @@ -126,8 +135,11 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw) ret = sdw_cdns_clock_restart(cdns, !clock_stop0); if (ret < 0) { dev_err(dev, "unable to restart clock during resume\n"); - if (!clock_stop0) + if (!clock_stop0) { sdw_cdns_enable_interrupt(cdns, false); + if (bus->multi_link) + mutex_unlock(sdw->link_res->shim_lock); + } return ret; } @@ -135,7 +147,8 @@ int intel_start_bus_after_reset(struct sdw_intel *sdw) sdw_cdns_config_update(cdns); if (bus->multi_link) { - ret = sdw_intel_sync_go(sdw); + ret = sdw_intel_sync_go_unlocked(sdw); + mutex_unlock(sdw->link_res->shim_lock); if (ret < 0) { dev_err(sdw->cdns.dev, "sync go failed during resume\n"); return ret;