soundwire: amd: SoundWire manager driver bug fixes
v9 cover soundwire: amd: SoundWire manager driver bug fixes
This series collects bug fixes for the AMD SoundWire manager driver (ACP6.3/7.0/7.1/7.2). The patches address correctness issues across six areas. Patches 9, 12, 13, 15, 20, and 21 fix issues reported by Lee Jones <[email protected]>.
Wake interrupt handling (patches 1-8): fixes reported on OEM platforms running ACP6.3/7.0/7.1/7.2. Consolidate pad register macros into amd_init.h, add correct SCHMEN/OE programming for ACP 7.0/7.1/7.2, introduce D0/D3 PM pad helpers, track full pad teardown across suspend/resume, fix missing wake interrupt and group wake-arming calls in runtime suspend, fix the IRQ thread dropping STATUS_0TO7 on simultaneous wake and state-change events, remove the spurious STATUS_8TO11 clear in amd_sdw_process_wake_event(), and fix a missing wake interrupt for ACP6.3 in POWER_OFF suspend.
Command response handling (patches 9-11): fix silent widening of -ETIMEDOUT to u64 (reported by Lee Jones), cache the last successful PING result to avoid spurious disconnect warnings on transient timeouts, and add lockdep_assert_held() to enforce the msg_lock contract.
Work-queue and driver lifecycle (patches 12-16): fix drain ordering in the remove path and defer dev_set_drvdata() until after INIT_WORK() to close a concurrent-remove window (both reported by Lee Jones), guard pm_runtime_disable() against unpaired calls, guard IRQ work execution with the interrupt_enabled flag using WRITE_ONCE/READ_ONCE, clear stale ACP_SW_STATE_CHANGE_STATUS registers before re-enabling interrupt delivery, and add explanatory comments in amd_disable_sdw_interrupts() and amd_sdw_irq_thread() (reported by Lee Jones), and fix *sdw_ctx leak when sdw_amd_startup() fails. Companion NULL-check patches are already merged in Mark Brown's ASoC tree:
34ea81a7f284 ("ASoC: SOF: amd: guard adata->sdw dereferences with
NULL check in IRQ handler")
41e06aaef9c0 ("ASoC: amd: ps: guard adata->sdw dereferences with
NULL check in IRQ handler")
Power management (patches 17-20): propagate amd_init_sdw_manager() errors on POWER_OFF resume, drop amd_deinit_sdw_manager() in POWER_OFF suspend, replace the open-coded >= ACP70 comparison with an explicit switch/case, and fix interrupt-gate and work-drain ordering in PM ops (reported by Lee Jones).
Drvdata and register safety (patches 21-23): add a NULL drvdata guard in sdw_amd_startup() (reported by Lee Jones), and fix shared-register read-modify-write races in amd_sdw_set_device_state() and amd_sdw_host_wake_enable() by holding acp_sdw_lock.
Generic bus fix (patch 24): fix deadlock in sdw_handle_slave_alerts() when the parent manager is in RPM_SUSPENDING. The manager's runtime_suspend callback blocks in cancel_work_sync() waiting for the alert work to complete, while the alert work blocks waiting for the manager to complete its suspend. The fix checks the manager PM state directly via slave->bus->dev->parent using pm_runtime_get_if_active(); if the manager is not RPM_ACTIVE, return early to defer the alert, avoiding dropped alerts when the slave is RPM_SUSPENDED but the manager is still active. If the manager is active, use pm_runtime_resume_and_get() for the slave for correct error-path PM reference accounting.
Changes since v8:
- Patch 24: correct Fixes tag to commit aa79293517b3 ("soundwire: bus:
fix io error when processing alert event"), which introduced pm_runtime_get_sync() into sdw_handle_slave_alerts(); rework deadlock condition to check manager PM state via pm_runtime_get_if_active(slave->bus->dev->parent) instead of slave
state: if manager is not RPM_ACTIVE return early to defer the alert, avoiding dropped alerts when slave is RPM_SUSPENDED but manager is active; replace pm_runtime_get_sync() with pm_runtime_resume_and_get() for correct error-path PM reference accounting; add have_mgr_ref boolean and mgr_put: label to track and release the manager reference.
- Link to v8:
https://lore.kernel.org/linux-sound/[email protected]
Changes since v7:
- Patch 15: expand beyond the interrupt_enabled guard to also clear stale ACP_SW_STATE_CHANGE_STATUS_0TO7 and _8TO11 registers in amd_enable_sdw_interrupts() before re-enabling interrupt delivery, add STATUS clears in the ACP6.3 POWER_OFF_MODE wake-re-enable block in amd_suspend_runtime(), and add explanatory comments in amd_disable_sdw_interrupts() and amd_sdw_irq_thread(). Rename to "guard IRQ work with interrupt_enabled and clear STATUS".
- Add patch 24: fix deadlock in sdw_handle_slave_alerts() caused by pm_runtime_get_sync() blocking when the parent manager is in RPM_SUSPENDING; replace with pm_runtime_get_if_active() conditioned on pm_runtime_status_suspended().
- Link to v7:
https://lore.kernel.org/linux-sound/[email protected]
Changes since v6:
- Patch 7: drop Fixes tag; the STATUS_8TO11 double-clear is an irq-thread logic bug not attributable to a single introducing commit.
- Patch 16: change approach to publish *sdw_ctx = ctx before sdw_amd_startup() and reset *sdw_ctx = NULL on startup failure before calling sdw_amd_exit(); update commit description to match. With this ordering *sdw_ctx is visible before amd_enable_sdw_interrupts() so the IRQ handler window between interrupt enable and ctx publication is closed.
- Link to v6:
https://lore.kernel.org/linux-sound/[email protected]
Changes since v5:
- Drop patch 10 (return response on IMM status cleanup timeout) and patch 11 (clarify bad-state guard poll omission in IMM_RES_VALID path): dropped after review feedback.
- Patch 2: rename disable_oe to needs_schmen_oe for clarity; update Fixes tags to cite ACP 7.x introduction commits instead of the
ACP 6.3-only refactor commit:
commit 2c0ae8ef1e5e ("soundwire: amd: add support for ACP7.0 & ACP7.1 platforms") commit 34b1cb4ec286 ("soundwire: amd: Add support for acp7.2 platform")
- Patch 4: use "POWER_OFF_MODE runtime suspend" instead of
"wake-armed runtime suspend" for precision.
- Patch 5: add commit description explaining why the early return before wake-arming is correct when amd_deinit_sdw_manager() fails; update Fixes tag to commit dcc48a73eae7 ("soundwire: amd: change the soundwire wake enable/disable sequence").
- Patch 8: update Fixes tag to correct commit SHA.
- Patch 9: drop dev_err_ratelimited() calls for ping status timeout; the error is already tracked via the cache introduced in patch 10.
- Patch 14: update Fixes tag to commit ed5e8741b8db ("soundwire: amd:
refactor amd soundwire manager device node creation"), which introduced the partial-init startup sequence that makes the unconditional pm_runtime_disable() incorrect.
- Patch 15: add WRITE_ONCE() for all stores to interrupt_enabled and READ_ONCE() for the load in amd_sdw_irq_thread(); restore interrupt_enabled in the ACP6.3-specific wake-re-enable block in amd_suspend_runtime() POWER_OFF_MODE; guard IRQ work execution instead of scheduling.
- Patch 16: simplify to single-problem description (ctx leak on startup failure); remove the concurrent IRQ handler race rationale. Two ASoC companion patches addressing the IRQ handler NULL dereference window (adata->sdw dereferenced without NULL check between amd_enable_sdw_interrupts() and *sdw_ctx assignment) have been posted and merged in Mark Brown's ASoC tree:
34ea81a7f284 ("ASoC: SOF: amd: guard adata->sdw dereferences with
NULL check in IRQ handler")
41e06aaef9c0 ("ASoC: amd: ps: guard adata->sdw dereferences with
NULL check in IRQ handler")
- Patch 19: add WRITE_ONCE(interrupt_enabled, true) in the ACP6.3 wake-re-enable block in amd_suspend_runtime() POWER_OFF_MODE.
- Patch 20: expand description to explain the redundant amd_sdw_wake_enable(false) calls and clarify CLK_STOP_MODE
interrupt handling through D3.
- Link to v5:
https://lore.kernel.org/linux-sound/[email protected]/
Changes since v4:
- Add patches 1-8 (OEM-reported wake interrupt fixes for ACP6.3/7.0/7.1/7.2): pad register macro consolidation, SCHMEN/OE programming for ACP 7.0/7.1/7.2, D0/D3 PM helpers, pad teardown tracking, missing wake interrupt in runtime suspend, STATUS_0TO7 race fix (promoted from patch 12/13 in v4), STATUS_8TO11 fix reworked to a targeted removal of the clear in amd_sdw_process_wake_event(), and ACP6.3 POWER_OFF wake fix.
- Add patch 11: clarify bad-state guard poll omission in IMM_RES_VALID path.
- Add patch 15: defer dev_set_drvdata() until after INIT_WORK().
- Add patches 17-18: guard IRQ work with interrupt_enabled flag; delay *sdw_ctx publication until after startup succeeds (supersedes v4 patch 7 ctx-leak fix with a more robust approach).
- Add patches 23-25: NULL drvdata guard in sdw_amd_startup(), and shared-register RMW races in amd_sdw_set_device_state() and amd_sdw_host_wake_enable().
- Drop v4 patch 7 (fix ctx leak when sdw_amd_startup() fails):
superseded by patch 18.
- Link to v4:
https://lore.kernel.org/all/[email protected]/
Changes since v3:
- Add patch 12/13 to fix IRQ thread dropping STATUS_0TO7 when a wake event and a device-state change arrive simultaneously.
- Add patch 13/13 to fix STATUS_8TO11 double-clear race in the wake handler introduced by the simultaneous-wake fix.
- Add lockdep_assert_held() to amd_sdw_read_ping_status() (patch 4/13) to enforce the msg_lock contract machine-checkably.
- Add return response on IMM status cleanup timeout (patch 2/13).
- Update patch 11/13 (fix interrupt gate and work drain ordering in PM ops) to also fix amd_sdw_wake_enable() ordering in both CLK_STOP_MODE
paths: move the call to after amd_enable_sdw_interrupts() so the unconditional interrupt mask write does not clobber the wake bit.
Changes since v2:
- Update comment for ping_slave_stat variable description in patch 3/13.
- Split the remove path work drain and pm ops guard patch into separate patches (patches 5/13 and 6/13) to improve clarity and maintainability.
Changes since v1:
- Rework patch 1 to fix the u64 return type properly via out-parameter.
Vijendar Mukunda (24):
soundwire: amd: consolidate pad register macros into amd_init.h
soundwire: amd: program pad SCHMEN and OE control for ACP 7.0/7.1/7.2
soundwire: amd: add pad ctrl helpers for D0/D3 PM transitions
soundwire: amd: track full pad teardown across suspend/resume
soundwire: amd: fix missing wake interrupt and group wake-arming calls
in runtime suspend
soundwire: amd: fix IRQ thread dropping STATUS_0TO7 on simultaneous
wake
soundwire: amd: remove STATUS_8TO11 clear from
amd_sdw_process_wake_event()
soundwire: amd: fix missing wake interrupt for ACP6.3 in POWER_OFF
suspend
soundwire: amd: fix SDW command timeout return value handling
soundwire: amd: cache ping slave status to avoid spurious disconnect
on timeout
soundwire: amd: assert msg_lock is held in amd_sdw_read_ping_status()
soundwire: amd: fix work drain ordering in remove path
soundwire: amd: defer dev_set_drvdata() until after INIT_WORK()
soundwire: amd: pm_runtime guard in remove path
soundwire: amd: guard IRQ work with interrupt_enabled and clear STATUS
soundwire: amd: fix *sdw_ctx leak when sdw_amd_startup() fails
soundwire: amd: propagate amd_init_sdw_manager() error on resume
soundwire: amd: drop amd_deinit_sdw_manager() in POWER_OFF suspend
soundwire: amd: replace >= ACP70 with explicit switch/case in PM paths
soundwire: amd: fix interrupt gate and work drain ordering in PM ops
soundwire: amd: check for NULL manager drvdata in sdw_amd_startup()
soundwire: amd: fix shared-register RMW race in
amd_sdw_set_device_state()
soundwire: amd: fix shared-register RMW race in
amd_sdw_host_wake_enable()
soundwire: bus: use pm_runtime_get_if_active() in
sdw_handle_slave_alerts()
drivers/soundwire/amd_init.c | 76 ++++-- drivers/soundwire/amd_init.h | 18 ++ drivers/soundwire/amd_manager.c | 372 ++++++++++++++++++++++++------ drivers/soundwire/amd_manager.h | 10 - drivers/soundwire/bus.c | 52 ++++- include/linux/soundwire/sdw_amd.h | 15 ++ 6 files changed, 434 insertions(+), 109 deletions(-)
Signature · 1 line
2.53.0
PATCH v9 1/24 soundwire: amd: consolidate pad register macros into amd_init.h
Move ACP_PAD_PULLDOWN_CTRL and ACP_SW_PAD_KEEPER_EN from their duplicate definitions in amd_init.c and amd_manager.h into amd_init.h, so a single canonical definition is shared by both translation units.
Drop the eight stale AMD_SDW{0,1}_PAD_*_{ENABLE,DISABLE}_MASK definitions from amd_manager.h; they are no longer referenced anywhere.
No functional change.
--- drivers/soundwire/amd_init.c | 2 -- drivers/soundwire/amd_init.h | 3 +++ drivers/soundwire/amd_manager.h | 10 ---------- 3 files changed, 3 insertions(+), 12 deletions(-)
drivers/soundwire/amd_init.c +0 -2
@@ -16,8 +16,6 @@#include "amd_init.h" -#define ACP_PAD_PULLDOWN_CTRL 0x0001448 -#define ACP_SW_PAD_KEEPER_EN 0x0001454#define AMD_SDW0_PAD_CTRL_MASK 0x60#define AMD_SDW1_PAD_CTRL_MASK 5#define AMD_SDW_PAD_CTRL_MASK (AMD_SDW0_PAD_CTRL_MASK | AMD_SDW1_PAD_CTRL_MASK)
drivers/soundwire/amd_init.h +3 -0
@@ -8,6 +8,9 @@#include <linux/soundwire/sdw_amd.h> +#define ACP_PAD_PULLDOWN_CTRL 0x0001448 +#define ACP_SW_PAD_KEEPER_EN 0x0001454 +int amd_sdw_manager_start (struct amd_sdw_manager *amd_manager);static inline void amd_updatel (void __iomem *mmio,int offset,u32 mask,u32 val)
drivers/soundwire/amd_manager.h +0 -10
@@ -11,8 +11,6 @@#define SDW_MANAGER_REG_OFFSET 0xc00#define AMD_SDW_DEFAULT_ROWS 50#define AMD_SDW_DEFAULT_COLUMNS 10 -#define ACP_PAD_PULLDOWN_CTRL 0x0001448 -#define ACP_SW_PAD_KEEPER_EN 0x0001454#define ACP_SW0_WAKE_EN 0x0001458#define ACP_EXTERNAL_INTR_CNTL0 0x0001a04#define ACP_EXTERNAL_INTR_STAT0 0x0001a0c
@@ -180,14 +178,6 @@#define AMD_DPN_CH_EN_LCTRL GENMASK(2, 0)#define AMD_DPN_CH_EN_CHMASK GENMASK(10, 3)#define AMD_SDW_STAT_MAX_RETRY_COUNT 100 -#define AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK 0x7f9f -#define AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK 0x7ffa -#define AMD_SDW0_PAD_PULLDOWN_CTRL_DISABLE_MASK 0x60 -#define AMD_SDW1_PAD_PULLDOWN_CTRL_DISABLE_MASK 5 -#define AMD_SDW0_PAD_KEEPER_EN_MASK 1 -#define AMD_SDW1_PAD_KEEPER_EN_MASK 0x10 -#define AMD_SDW0_PAD_KEEPER_DISABLE_MASK 0x1e -#define AMD_SDW1_PAD_KEEPER_DISABLE_MASK 0xf#define AMD_SDW_PREQ_INTR_STAT BIT(19)#define AMD_SDW_CLK_STOP_DONE 1#define AMD_SDW_CLK_RESUME_REQ 2
Signature · 1 line
2.53.0
PATCH v9 2/24 soundwire: amd: program pad SCHMEN and OE control for ACP 7.0/7.1/7.2
In reply to Vijendar MukundaACP 7.0/7.1/7.2 hardware requires SCHMEN control and output-enable (OE) registers to be programmed as part of the pad enable sequence, in addition to the existing keeper and pulldown writes.
Update amd_enable_sdw_pads() to program ACP_PAD_SCHMEN_CTRL and ACP_PAD_DISABLE_OE_CTRL for active pads. Pass acp_rev to amd_enable_sdw_pads() and restrict these writes to ACP 7.0/7.1/7.2; ACP 6.3 is unaffected.
Define per-register masks in amd_init.h replacing generic local defines in amd_init.c.
amd_enable_sdw_pads() targets ACP6.3/7.0/7.1/7.2 only. The default -EINVAL prevents applying this pad sequence to unsupported ACP revisions.
--- drivers/soundwire/amd_init.c | 54 ++++++++++++++++++++++++------------ drivers/soundwire/amd_init.h | 15 ++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-)
drivers/soundwire/amd_init.c +36 -18
@@ -16,37 +16,55 @@#include "amd_init.h" -#define AMD_SDW0_PAD_CTRL_MASK 0x60 -#define AMD_SDW1_PAD_CTRL_MASK 5 -#define AMD_SDW_PAD_CTRL_MASK (AMD_SDW0_PAD_CTRL_MASK | AMD_SDW1_PAD_CTRL_MASK) -#define AMD_SDW0_PAD_EN 1 -#define AMD_SDW1_PAD_EN 0x10 -#define AMD_SDW_PAD_EN (AMD_SDW0_PAD_EN | AMD_SDW1_PAD_EN) - -static int amd_enable_sdw_pads (void __iomem *mmio,u32 link_mask,struct device *dev) +static int amd_enable_sdw_pads (void __iomem *mmio,u32 link_mask,u32 acp_rev,struct device *dev) { -u32 pad_keeper_en, pad_pulldown_ctrl_mask; +u32 pad_keeper_mask, pad_pulldown_mask, pad_schmen_mask, pad_oe_mask; +bool needs_schmen_oe; + +switch (acp_rev) { +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : + needs_schmen_oe = true; +break ; +case ACP63_PCI_REV_ID : + needs_schmen_oe = false; +break ; +default : +dev_err (dev,"unsupported ACP revision 0x%x\n" , acp_rev); +return -EINVAL ; + }switch (link_mask) {case 1 : - pad_keeper_en =AMD_SDW0_PAD_EN ; - pad_pulldown_ctrl_mask =AMD_SDW0_PAD_CTRL_MASK ; + pad_keeper_mask =AMD_SDW0_PAD_KEEPER_EN_MASK ; + pad_pulldown_mask =AMD_SDW0_PAD_PULLDOWN_MASK ; + pad_schmen_mask =AMD_SDW0_PAD_SCHMEN_MASK ; + pad_oe_mask =AMD_SDW0_PAD_OE_CTRL_MASK ;break ;case 2 : - pad_keeper_en =AMD_SDW1_PAD_EN ; - pad_pulldown_ctrl_mask =AMD_SDW1_PAD_CTRL_MASK ; + pad_keeper_mask =AMD_SDW1_PAD_KEEPER_EN_MASK ; + pad_pulldown_mask =AMD_SDW1_PAD_PULLDOWN_MASK ; + pad_schmen_mask =AMD_SDW1_PAD_SCHMEN_MASK ; + pad_oe_mask =AMD_SDW1_PAD_OE_CTRL_MASK ;break ;case 3 : - pad_keeper_en =AMD_SDW_PAD_EN ; - pad_pulldown_ctrl_mask =AMD_SDW_PAD_CTRL_MASK ; + pad_keeper_mask =AMD_SDW_PAD_KEEPER_EN_MASK ; + pad_pulldown_mask =AMD_SDW_PAD_PULLDOWN_MASK ; + pad_schmen_mask =AMD_SDW_PAD_SCHMEN_MASK ; + pad_oe_mask =AMD_SDW_PAD_OE_CTRL_MASK ;break ;default :dev_err (dev,"No SDW Links are enabled\n" );return -ENODEV ; } -amd_updatel (mmio,ACP_SW_PAD_KEEPER_EN , pad_keeper_en, pad_keeper_en); -amd_updatel (mmio,ACP_PAD_PULLDOWN_CTRL , pad_pulldown_ctrl_mask,0 ); +amd_updatel (mmio,ACP_SW_PAD_KEEPER_EN , pad_keeper_mask, pad_keeper_mask); +amd_updatel (mmio,ACP_PAD_PULLDOWN_CTRL , pad_pulldown_mask,0 ); +if (needs_schmen_oe) { +amd_updatel (mmio,ACP_PAD_SCHMEN_CTRL , pad_schmen_mask, pad_schmen_mask); +amd_updatel (mmio,ACP_PAD_DISABLE_OE_CTRL , pad_oe_mask,0 ); + }return 0 ; }
@@ -86,7 +104,7 @@ static struct sdw_amd_ctx *sdw_amd_probe_controller(struct sdw_amd_res *res) count = res->count;dev_dbg (&adev->dev,"Creating %d SDW Link devices\n" , count); - ret =amd_enable_sdw_pads (res->mmio_base, res->link_mask, res->parent); + ret =amd_enable_sdw_pads (res->mmio_base, res->link_mask, res->acp_rev, res->parent);if (ret)return NULL ;
drivers/soundwire/amd_init.h +15 -0
@@ -9,7 +9,22 @@#include <linux/soundwire/sdw_amd.h> #define ACP_PAD_PULLDOWN_CTRL 0x0001448 +#define ACP_PAD_SCHMEN_CTRL 0x0001450#define ACP_SW_PAD_KEEPER_EN 0x0001454 +#define ACP_PAD_DISABLE_OE_CTRL 0x0001468 + +#define AMD_SDW0_PAD_PULLDOWN_MASK (BIT(5) | BIT(6)) +#define AMD_SDW1_PAD_PULLDOWN_MASK (BIT(0) | BIT(2)) +#define AMD_SDW_PAD_PULLDOWN_MASK (AMD_SDW0_PAD_PULLDOWN_MASK | AMD_SDW1_PAD_PULLDOWN_MASK) +#define AMD_SDW0_PAD_KEEPER_EN_MASK BIT(0) +#define AMD_SDW1_PAD_KEEPER_EN_MASK BIT(4) +#define AMD_SDW_PAD_KEEPER_EN_MASK (AMD_SDW0_PAD_KEEPER_EN_MASK | AMD_SDW1_PAD_KEEPER_EN_MASK) +#define AMD_SDW0_PAD_OE_CTRL_MASK (BIT(5) | BIT(6)) +#define AMD_SDW1_PAD_OE_CTRL_MASK (BIT(0) | BIT(2)) +#define AMD_SDW_PAD_OE_CTRL_MASK (AMD_SDW0_PAD_OE_CTRL_MASK | AMD_SDW1_PAD_OE_CTRL_MASK) +#define AMD_SDW0_PAD_SCHMEN_MASK (BIT(5) | BIT(6)) +#define AMD_SDW1_PAD_SCHMEN_MASK (BIT(0) | BIT(2)) +#define AMD_SDW_PAD_SCHMEN_MASK (AMD_SDW0_PAD_SCHMEN_MASK | AMD_SDW1_PAD_SCHMEN_MASK)int amd_sdw_manager_start (struct amd_sdw_manager *amd_manager);
Signature · 1 line
2.53.0
PATCH v9 3/24 soundwire: amd: add pad ctrl helpers for D0/D3 PM transitions
In reply to Vijendar MukundaDuring POWER_OFF_MODE clock stop the SoundWire clock is expected to transition High to Low cleanly. On some OEM platforms based on ACP 7.0/7.1/7.2, a transient High pulse is observed after the initial Low; the clock briefly follows a High -> Low -> High -> Low sequence (High lasting a few milliseconds) instead of the expected High -> Low. This spurious High edge interferes with wake interrupt detection, causing wake events to be silently missed.
Hardware team analysis identified that the pad keeper, pulldown, SCHMEN control and output-enable registers must be programmed as a coordinated sequence during D3 entry and D0 re-entry to suppress the transient bounce and restore the pads correctly on resume.
Introduce amd_sdw_pad_ctrl() to program PAD_KEEPER_EN, PAD_PULLDOWN_CTRL, PAD_SCHMEN_CTRL and PAD_DISABLE_OE_CTRL in a single call for D0 entry (enable=true) or D3 entry (enable=false). Introduce amd_sdw_oe_ctrl() as a lighter helper that only toggles OE. Introduce amd_sdw_pad_ctrl_supported() to consolidate the ACP revision check; both helpers use it in place of duplicate switch statements.
Both helpers apply only to ACP 7.0/7.1/7.2; ACP 6.3 returns without error and unknown revisions emit a dev_err and return.
Wire amd_sdw_pad_ctrl() into amd_suspend() and amd_resume_runtime(). Wire amd_sdw_oe_ctrl() into amd_suspend_runtime() to disable OE while leaving keeper and schmen enabled; pads remain capable of detecting wake events when wake is armed.
--- drivers/soundwire/amd_manager.c | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+)
drivers/soundwire/amd_manager.c +108 -0
@@ -152,6 +152,104 @@ static int amd_deinit_sdw_manager(struct amd_sdw_manager *amd_manager)return amd_disable_sdw_manager (amd_manager); } +static void __amd_sdw_oe_update (struct amd_sdw_manager *amd_manager, +u32 mask,bool enable) +{ +amd_updatel (amd_manager->acp_mmio,ACP_PAD_DISABLE_OE_CTRL , + mask, enable ?0 : mask); +} + +static bool amd_sdw_pad_ctrl_supported (struct amd_sdw_manager *amd_manager) +{ +switch (amd_manager->acp_rev) { +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : +return true; +case ACP63_PCI_REV_ID : +return false; +default : +dev_err (amd_manager->dev,"unknown ACP revision 0x%x\n" , + amd_manager->acp_rev); +return false; + } +} + +static void amd_sdw_oe_ctrl (struct amd_sdw_manager *amd_manager,bool enable) +{ +u32 mask; + +if (!amd_sdw_pad_ctrl_supported (amd_manager)) +return ; + +switch (amd_manager->instance) { +case ACP_SDW0 : + mask =AMD_SDW0_PAD_OE_CTRL_MASK ; +break ; +case ACP_SDW1 : + mask =AMD_SDW1_PAD_OE_CTRL_MASK ; +break ; +default : +dev_err (amd_manager->dev,"invalid SDW instance %d\n" , + amd_manager->instance); +return ; + } + +mutex_lock (amd_manager->acp_sdw_lock); +__amd_sdw_oe_update (amd_manager, mask, enable); +mutex_unlock (amd_manager->acp_sdw_lock); +} + +static void amd_sdw_pad_ctrl (struct amd_sdw_manager *amd_manager,bool enable) +{ +u32 keeper_mask, pulldown_mask, schmen_mask, oe_mask; + +if (!amd_sdw_pad_ctrl_supported (amd_manager)) +return ; + +switch (amd_manager->instance) { +case ACP_SDW0 : + keeper_mask =AMD_SDW0_PAD_KEEPER_EN_MASK ; + pulldown_mask =AMD_SDW0_PAD_PULLDOWN_MASK ; + schmen_mask =AMD_SDW0_PAD_SCHMEN_MASK ; + oe_mask =AMD_SDW0_PAD_OE_CTRL_MASK ; +break ; +case ACP_SDW1 : + keeper_mask =AMD_SDW1_PAD_KEEPER_EN_MASK ; + pulldown_mask =AMD_SDW1_PAD_PULLDOWN_MASK ; + schmen_mask =AMD_SDW1_PAD_SCHMEN_MASK ; + oe_mask =AMD_SDW1_PAD_OE_CTRL_MASK ; +break ; +default : +dev_err (amd_manager->dev,"invalid SDW instance %d\n" , + amd_manager->instance); +return ; + } + +mutex_lock (amd_manager->acp_sdw_lock); +if (enable) { +/* D0: set keeper, clear pulldown, set schmen */ +amd_updatel (amd_manager->acp_mmio,ACP_SW_PAD_KEEPER_EN , + keeper_mask, keeper_mask); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_PULLDOWN_CTRL , + pulldown_mask,0 ); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_SCHMEN_CTRL , + schmen_mask, schmen_mask); + }else { +/* D3: clear keeper, set pulldown, clear schmen */ +amd_updatel (amd_manager->acp_mmio,ACP_SW_PAD_KEEPER_EN , + keeper_mask,0 ); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_PULLDOWN_CTRL , + pulldown_mask, pulldown_mask); +amd_updatel (amd_manager->acp_mmio,ACP_PAD_SCHMEN_CTRL , + schmen_mask,0 ); + } + +/* enable OE on D0 (clear disable bits), disable OE on D3 (set them) */ +__amd_sdw_oe_update (amd_manager, oe_mask, enable); +mutex_unlock (amd_manager->acp_sdw_lock); +} +static void amd_sdw_set_frameshape (struct amd_sdw_manager *amd_manager) {u32 frame_size;
@@ -1319,6 +1417,8 @@ static int __maybe_unused amd_suspend(struct device *dev) ret =amd_deinit_sdw_manager (amd_manager);if (ret)return ret; +/* System suspend: tear down all pads */ +amd_sdw_pad_ctrl (amd_manager, false); }if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );
@@ -1363,6 +1463,13 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) ret =amd_deinit_sdw_manager (amd_manager);if (ret)return ret; +/* +* For ACP 7.0/7.1/7.2: disable OE only; keeper and schmen remain +* enabled unconditionally so that wake-capable devices can detect +* wake events if wake is armed. +* For ACP 6.3 this call is a no-op. +*/ +amd_sdw_oe_ctrl (amd_manager, false); }if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );
@@ -1403,6 +1510,7 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)return ret; } }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_sdw_pad_ctrl (amd_manager, true);writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance));if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_host_wake_enable (amd_manager, false);
Signature · 1 line
2.53.0
PATCH v9 4/24 soundwire: amd: track full pad teardown across suspend/resume
In reply to Vijendar Mukundaamd_sdw_pad_ctrl() performs a full pad teardown (keeper, pulldown, schmen and OE) for system suspend, while amd_sdw_oe_ctrl() disables only OE for POWER_OFF_MODE runtime suspend. amd_resume_runtime() must distinguish between these two cases to restore pads correctly: a full teardown requires amd_sdw_pad_ctrl(true) on resume; a POWER_OFF_MODE runtime suspend in which only OE was disabled requires only amd_sdw_oe_ctrl(true).
Introduce pad_fully_torn_down flag to track when a full pad teardown was performed. Set the flag after amd_sdw_pad_ctrl(false) in amd_suspend() using amd_sdw_pad_ctrl_supported() to gate the assignment to revisions that support pad control. Clear it after the full restore in amd_resume_runtime(). On resume, restore all pads if the flag is set, otherwise restore OE only; both paths delegate revision gating to the respective helpers.
--- drivers/soundwire/amd_manager.c | 12 ++++++++++-- include/linux/soundwire/sdw_amd.h | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-)
drivers/soundwire/amd_manager.c +10 -2
@@ -1418,7 +1418,10 @@ static int __maybe_unused amd_suspend(struct device *dev)if (ret)return ret;/* System suspend: tear down all pads */ -amd_sdw_pad_ctrl (amd_manager, false); +if (amd_sdw_pad_ctrl_supported (amd_manager)) { +amd_sdw_pad_ctrl (amd_manager, false); + amd_manager->pad_fully_torn_down = true; + } }if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );
@@ -1510,7 +1513,12 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)return ret; } }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { -amd_sdw_pad_ctrl (amd_manager, true); +if (amd_manager->pad_fully_torn_down) { +amd_sdw_pad_ctrl (amd_manager, true); + amd_manager->pad_fully_torn_down = false; + }else { +amd_sdw_oe_ctrl (amd_manager, true); + }writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance));if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_host_wake_enable (amd_manager, false);
include/linux/soundwire/sdw_amd.h +7 -0
@@ -75,6 +75,12 @@ struct sdw_amd_dai_runtime {* @wake_en_mask: wake enable mask per SoundWire manager * @acp_rev: acp pci device revision id * @clk_stopped: flag set to true when clock is stopped +* @pad_fully_torn_down: true when system suspend performed a full pad +* teardown (keeper, schmen and OE cleared, pulldown asserted). Cleared after +* all pads are restored in amd_resume_runtime(). False on initial probe +* (zero-initialized) and after a POWER_OFF_MODE runtime suspend in which +* only OE was disabled; in the latter case amd_resume_runtime() restores +* OE only, leaving keeper and schmen untouched. * @power_mode_mask: flag interprets amd SoundWire manager power mode * @dai_runtime_array: dai runtime array */
@@ -106,6 +112,7 @@ struct amd_sdw_manager {u32 power_mode_mask;u32 acp_rev;bool clk_stopped; +bool pad_fully_torn_down;struct sdw_amd_dai_runtime **dai_runtime_array; };
Signature · 1 line
2.53.0
PATCH v9 5/24 soundwire: amd: fix missing wake interrupt and group wake-arming calls in runtime suspend
In reply to Vijendar MukundaIn amd_suspend_runtime() POWER_OFF_MODE, amd_sdw_wake_enable() was called before amd_deinit_sdw_manager(), causing the wake IRQ mask to be silently overwritten.
amd_deinit_sdw_manager() calls amd_disable_sdw_interrupts() which writes 0x00 to ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11, wiping AMD_SDW_WAKE_INTR_MASK (BIT(16)) set by amd_sdw_wake_enable(). Move amd_sdw_wake_enable() to after amd_deinit_sdw_manager() so the wake mask is armed after the interrupt-disable sequence and cannot be clobbered.
Move amd_sdw_host_wake_enable() after amd_deinit_sdw_manager() as well, grouping both wake-arming calls together after the interrupt-disable sequence.
If amd_deinit_sdw_manager() fails (timeout waiting for ACP_SW_EN_STATUS), the hardware is in an indeterminate state and wake IRQ delivery cannot be expected to function; the early return before the wake-arming calls is correct in this case.
--- drivers/soundwire/amd_manager.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/soundwire/amd_manager.c +6 -6
@@ -1454,18 +1454,18 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)if (ret)return ret; }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { -amd_sdw_wake_enable (amd_manager, true); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, true); -if (ret) -return ret; - } ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; ret =amd_deinit_sdw_manager (amd_manager);if (ret)return ret; +amd_sdw_wake_enable (amd_manager, true); +if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { + ret =amd_sdw_host_wake_enable (amd_manager, true); +if (ret) +return ret; + }/* * For ACP 7.0/7.1/7.2: disable OE only; keeper and schmen remain * enabled unconditionally so that wake-capable devices can detect
Signature · 1 line
2.53.0
PATCH v9 6/24 soundwire: amd: fix IRQ thread dropping STATUS_0TO7 on simultaneous wake
In reply to Vijendar MukundaWhen a wake interrupt and a device-state change arrived simultaneously, amd_sdw_irq_thread() returned early after the wake path, silently discarding the STATUS_0TO7 bits.
Remove the early return and fall through to the normal slave-status processing path. Clear the wake bit from the local status_change_8to11 copy before proceeding so the remaining status checks are not confused by the wake bit.
--- drivers/soundwire/amd_manager.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/soundwire/amd_manager.c +5 -2
@@ -1110,8 +1110,11 @@ static void amd_sdw_irq_thread(struct work_struct *work)dev_dbg (amd_manager->dev,"[SDW%d] SDW INT: 0to7=0x%x, 8to11=0x%x\n" , amd_manager->instance, status_change_0to7, status_change_8to11); -if (status_change_8to11 &AMD_SDW_WAKE_STAT_MASK ) -return amd_sdw_process_wake_event (amd_manager); + +if (status_change_8to11 &AMD_SDW_WAKE_STAT_MASK ) { +amd_sdw_process_wake_event (amd_manager); + status_change_8to11 &= ~AMD_SDW_WAKE_STAT_MASK ; + }if (status_change_8to11 &AMD_SDW_PREQ_INTR_STAT ) {amd_sdw_read_and_process_ping_status (amd_manager);
Signature · 1 line
2.53.0
PATCH v9 7/24 soundwire: amd: remove STATUS_8TO11 clear from amd_sdw_process_wake_event()
In reply to Vijendar Mukundaamd_sdw_irq_thread() falls through after handling a wake event to process any coalesced PREQ or peripheral status events, rather than returning early. With the fall-through in place, both amd_sdw_process_wake_event() and the tail of amd_sdw_irq_thread() write 0x00 to ACP_SW_STATE_CHANGE_STATUS_8TO11 in the same invocation. Any status bit asserted by hardware between those two writes would be lost before the next invocation reads the register.
Remove the writel() from amd_sdw_process_wake_event() so that ACP_SW_STATE_CHANGE_STATUS_8TO11 is cleared exactly once per invocation by the tail of amd_sdw_irq_thread().
--- drivers/soundwire/amd_manager.c | 1 - 1 file changed, 1 deletion(-)
drivers/soundwire/amd_manager.c +0 -1
@@ -1093,7 +1093,6 @@ static void amd_sdw_process_wake_event(struct amd_sdw_manager *amd_manager)dev_dbg (amd_manager->dev,"SoundWire Wake event reported\n" );pm_request_resume (amd_manager->dev);writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance)); -writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); }static void amd_sdw_irq_thread (struct work_struct *work)
Signature · 1 line
2.53.0
PATCH v9 8/24 soundwire: amd: fix missing wake interrupt for ACP6.3 in POWER_OFF suspend
In reply to Vijendar MukundaOn some OEM platforms based on ACP 6.3, with a SoundWire topology where the UAJ peripheral is on one instance and the speaker peripheral is on the other, wake events from the UAJ instance are silently lost every time it enters POWER_OFF runtime suspend (D3) while speaker playback keeps ACP in D0.
On ACP6.3, unlike ACP7.0/7.1/7.2, there is no dedicated host wake interrupt path (no ACP_EXTERNAL_INTR_CNTL1 host wake mask bits and no PME wake mechanism). The wake event from a suspended SoundWire instance is delivered solely through the standard SoundWire interrupt bit in ACP_EXTERNAL_INTR_CNTL.
In the POWER_OFF_MODE runtime suspend path, amd_deinit_sdw_manager() calls amd_disable_sdw_interrupts() which clears the SoundWire instance bit in ACP_EXTERNAL_INTR_CNTL. After this, the wake interrupt has no delivery path to the CPU.
Fix this by re-enabling the SoundWire instance bit in ACP_EXTERNAL_INTR_CNTL after amd_deinit_sdw_manager() and amd_sdw_wake_enable() complete, when acp_rev is ACP63_PCI_REV_ID and wake_en_mask is set. The acp_sdw_lock mutex is held around the read-modify-write to prevent a race when both instances suspend or resume concurrently.
--- drivers/soundwire/amd_manager.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/soundwire/amd_manager.c +7 -0
@@ -1467,6 +1467,13 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) ret =amd_sdw_host_wake_enable (amd_manager, true);if (ret)return ret; + }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && + amd_manager->wake_en_mask) { +mutex_lock (amd_manager->acp_sdw_lock); + val = sdw_manager_reg_mask_array[amd_manager->instance]; +amd_updatel (amd_manager->acp_mmio, +ACP_EXTERNAL_INTR_CNTL (amd_manager->instance), val, val); +mutex_unlock (amd_manager->acp_sdw_lock); }/* * For ACP 7.0/7.1/7.2: disable OE only; keeper and schmen remain
Signature · 1 line
2.53.0
PATCH v9 9/24 soundwire: amd: fix SDW command timeout return value handling
In reply to Vijendar Mukundaamd_sdw_send_cmd_get_resp() returned u64 but was returning -ETIMEDOUT (a negative int) on readl_poll_timeout() failures, which silently widens to a large u64 value.
Change the return type to int and pass the raw u64 response through an out-parameter. Timeout is detected directly from readl_poll_timeout() return value.
Update all callers: amd_program_scp_addr(), _amd_sdw_xfer_msg(), amd_sdw_read_and_process_ping_status(), and amd_sdw_read_ping_status() to check the return value and handle timeout explicitly.
--- drivers/soundwire/amd_manager.c | 49 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 22 deletions(-)
drivers/soundwire/amd_manager.c +27 -22
@@ -348,10 +348,9 @@ static void amd_sdw_ctl_word_prep(u32 *lower_word, u32 *upper_word, struct sdw_m *lower_word = lower_data; } -static u64 amd_sdw_send_cmd_get_resp (struct amd_sdw_manager *amd_manager,u32 lower_data, -u32 upper_data) +static int amd_sdw_send_cmd_get_resp (struct amd_sdw_manager *amd_manager,u32 lower_data, +u32 upper_data,u64 *response) { -u64 resp;u32 lower_resp, upper_resp;u32 sts;int ret;
@@ -389,9 +388,8 @@ static u64 amd_sdw_send_cmd_get_resp(struct amd_sdw_manager *amd_manager, u32 lo amd_manager->instance);return ret; } - resp = upper_resp; - resp = (resp <<32 ) | lower_resp; -return resp; + *response = ((u64 )upper_resp <<32 ) | lower_resp; +return 0 ; } static enum sdw_command_response
@@ -407,19 +405,22 @@ amd_program_scp_addr(struct amd_sdw_manager *amd_manager, struct sdw_msg *msg) scp_msg.buf = &msg->addr_page1; scp_msg.flags =SDW_MSG_FLAG_WRITE ;amd_sdw_ctl_word_prep (&lower_data, &upper_data, &scp_msg,0 ); - response_buf[0 ] =amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data); +if (amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data, &response_buf[0 ])) { +dev_err_ratelimited (amd_manager->dev, +"SCP_addrpage command timeout for Slave %d\n" , msg->dev_num); +return SDW_CMD_TIMEOUT ; + } scp_msg.addr =SDW_SCP_ADDRPAGE2 ; scp_msg.buf = &msg->addr_page2;amd_sdw_ctl_word_prep (&lower_data, &upper_data, &scp_msg,0 ); - response_buf[1 ] =amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data); +if (amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data, &response_buf[1 ])) { +dev_err_ratelimited (amd_manager->dev, +"SCP_addrpage command timeout for Slave %d\n" , msg->dev_num); +return SDW_CMD_TIMEOUT ; + }for (index =0 ; index <2 ; index++) { -if (response_buf[index] == -ETIMEDOUT ) { -dev_err_ratelimited (amd_manager->dev, -"SCP_addrpage command timeout for Slave %d\n" , - msg->dev_num); -return SDW_CMD_TIMEOUT ; - }else if (!(response_buf[index] &AMD_SDW_MCP_RESP_ACK )) { +if (!(response_buf[index] &AMD_SDW_MCP_RESP_ACK )) {if (response_buf[index] &AMD_SDW_MCP_RESP_NACK ) { dev_err_ratelimited(amd_manager->dev, "SCP_addrpage NACKed for Slave %d\n",
@@ -464,11 +465,7 @@ static enum sdw_command_response amd_sdw_fill_msg_resp(struct amd_sdw_manager *aif (msg->flags ==SDW_MSG_FLAG_READ ) msg->buf[offset] =FIELD_GET (AMD_SDW_MCP_RESP_RDATA , response); }else { -if (response == -ETIMEDOUT ) { -dev_err_ratelimited (amd_manager->dev,"command timeout for Slave %d\n" , - msg->dev_num); -return SDW_CMD_TIMEOUT ; - }else if (response &AMD_SDW_MCP_RESP_NACK ) { +if (response &AMD_SDW_MCP_RESP_NACK ) {dev_err_ratelimited (amd_manager->dev,"command response NACK received for Slave %d\n" , msg->dev_num);
@@ -488,7 +485,11 @@ static unsigned int _amd_sdw_xfer_msg(struct amd_sdw_manager *amd_manager, strucu32 upper_data =0 , lower_data =0 ;amd_sdw_ctl_word_prep (&lower_data, &upper_data, msg, cmd_offset); - response =amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data); +if (amd_sdw_send_cmd_get_resp (amd_manager, lower_data, upper_data, &response)) { +dev_err_ratelimited (amd_manager->dev,"command timeout for Slave %d\n" , + msg->dev_num); +return SDW_CMD_TIMEOUT ; + }return amd_sdw_fill_msg_resp (amd_manager, msg, response, cmd_offset); }
@@ -544,7 +545,10 @@ static void amd_sdw_read_and_process_ping_status(struct amd_sdw_manager *amd_manu64 response;mutex_lock (&amd_manager->bus.msg_lock); - response =amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 ); +if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response)) { +mutex_unlock (&amd_manager->bus.msg_lock); +return ; + }mutex_unlock (&amd_manager->bus.msg_lock);amd_sdw_process_ping_status (response, amd_manager); }
@@ -555,7 +559,8 @@ static u32 amd_sdw_read_ping_status(struct sdw_bus *bus)u64 response;u32 slave_stat; - response =amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 ); +if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response)) +return 0 ;/* slave status from ping response */ slave_stat =FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_0_3 , response); slave_stat |=FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_4_11 , response) <<8 ;
Signature · 1 line
2.53.0
PATCH v9 10/24 soundwire: amd: cache ping slave status to avoid spurious disconnect on timeout
In reply to Vijendar Mukundaamd_sdw_read_ping_status() returned 0 on a PING command timeout. This was indistinguishable from a valid "no peripherals attached" response, causing sdw_show_ping_status() to log a spurious disconnect warning even when devices were actually present.
Add ping_slave_stat to struct amd_sdw_manager to cache the slave_stat from the last successful ping response. On timeout, the cached value is returned instead of 0, so sdw_show_ping_status() sees the last known good state. The timeout itself is still reported via dev_err() - the cache does not suppress the error.
ping_slave_stat is initialised to U32_MAX in probe and reset to U32_MAX under msg_lock before any failable step in the POWER_OFF_MODE resume path, so a partially-failed resume cannot leave stale pre-suspend data behind for a subsequent ping timeout to report.
--- drivers/soundwire/amd_manager.c | 18 +++++++++++++++++- include/linux/soundwire/sdw_amd.h | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +17 -1
@@ -549,6 +549,9 @@ static void amd_sdw_read_and_process_ping_status(struct amd_sdw_manager *amd_manmutex_unlock (&amd_manager->bus.msg_lock);return ; } + amd_manager->ping_slave_stat = +FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_0_3 , response) | + (FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_4_11 , response) <<8 );mutex_unlock (&amd_manager->bus.msg_lock);amd_sdw_process_ping_status (response, amd_manager); }
@@ -560,11 +563,12 @@ static u32 amd_sdw_read_ping_status(struct sdw_bus *bus)u32 slave_stat;if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response)) -return 0 ; +return amd_manager->ping_slave_stat ==U32_MAX ?0 : amd_manager->ping_slave_stat;/* slave status from ping response */ slave_stat =FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_0_3 , response); slave_stat |=FIELD_GET (AMD_SDW_MCP_SLAVE_STAT_4_11 , response) <<8 ;dev_dbg (amd_manager->dev,"slave_stat:0x%x\n" , slave_stat); + amd_manager->ping_slave_stat = slave_stat;return slave_stat; }
@@ -1182,6 +1186,7 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)dev_err (dev,"mmio not found\n" );return -ENOMEM ; } + amd_manager->ping_slave_stat =U32_MAX ; amd_manager->instance = pdata->instance; amd_manager->mmio = amd_manager->acp_mmio + (amd_manager->instance *SDW_MANAGER_REG_OFFSET );
@@ -1534,6 +1539,17 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)amd_sdw_oe_ctrl (amd_manager, true); }writel (0x00 , amd_manager->acp_mmio +ACP_SW_WAKE_EN (amd_manager->instance)); +/* +* POWER_OFF_MODE tears the bus down completely; invalidate the +* cached ping status before any failable step so that a +* partially-failed resume leaves the first post-resume ping +* timeout returning 0 rather than stale pre-suspend data. +* CLK_STOP_MODE leaves peripherals attached, so the cache +* remains valid there. +*/ +mutex_lock (&amd_manager->bus.msg_lock); + amd_manager->ping_slave_stat =U32_MAX ; +mutex_unlock (&amd_manager->bus.msg_lock);if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { ret =amd_sdw_host_wake_enable (amd_manager, false);if (ret)
include/linux/soundwire/sdw_amd.h +4 -0
@@ -82,6 +82,9 @@ struct sdw_amd_dai_runtime {* only OE was disabled; in the latter case amd_resume_runtime() restores * OE only, leaving keeper and schmen untouched. * @power_mode_mask: flag interprets amd SoundWire manager power mode +* @ping_slave_stat: cached slave status from the last ping +* transaction that returned a response; +* initialised to U32_MAX ("no valid reading yet") * @dai_runtime_array: dai runtime array */ struct amd_sdw_manager {
@@ -111,6 +114,7 @@ struct amd_sdw_manager {u32 wake_en_mask;u32 power_mode_mask;u32 acp_rev; +u32 ping_slave_stat;bool clk_stopped;bool pad_fully_torn_down;
Signature · 1 line
2.53.0
PATCH v9 11/24 soundwire: amd: assert msg_lock is held in amd_sdw_read_ping_status()
In reply to Vijendar Mukundaamd_sdw_read_ping_status() is always called from sdw_show_ping_status() which holds bus->msg_lock. Add lockdep_assert_held() to document this locking requirement and catch any future callers that omit the lock.
--- drivers/soundwire/amd_manager.c | 1 + 1 file changed, 1 insertion(+)
drivers/soundwire/amd_manager.c +1 -0
@@ -562,6 +562,7 @@ static u32 amd_sdw_read_ping_status(struct sdw_bus *bus)u64 response;u32 slave_stat; +lockdep_assert_held (&bus->msg_lock);if (amd_sdw_send_cmd_get_resp (amd_manager,0 ,0 , &response))return amd_manager->ping_slave_stat ==U32_MAX ?0 : amd_manager->ping_slave_stat;/* slave status from ping response */
Signature · 1 line
2.53.0
PATCH v9 12/24 soundwire: amd: fix work drain ordering in remove path
In reply to Vijendar Mukundaamd_sdw_manager_remove() cancelled amd_sdw_work but not amd_sdw_irq_thread. Since amd_sdw_irq_thread() calls schedule_work(&amd_sdw_work), an in-flight irq_thread item can re-queue amd_sdw_work after its cancel returns, defeating the cancellation.
Fix by calling amd_disable_sdw_interrupts() first to quiesce the hardware IRQ source, then cancel_work_sync() for amd_sdw_irq_thread, then cancel_work_sync() for amd_sdw_work. The existing cancel_work_sync(amd_sdw_work) is also moved to after amd_disable_sdw_interrupts() so that any work item queued between the old cancel position and the interrupt disable cannot escape draining.
synchronize_irq() is deliberately not used before the cancel_work_sync() calls. Once SoundWire interrupts are masked, no new IRQ deliveries can occur. An IRQ handler already in flight may still queue amd_sdw_irq_thread, so cancel_work_sync() is used to drain both amd_sdw_irq_thread and any amd_sdw_work items it may have scheduled. This fully quiesces the driver workqueues, making synchronize_irq() unnecessary.
--- drivers/soundwire/amd_manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +2 -1
@@ -1266,8 +1266,9 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)int ret;pm_runtime_disable (&pdev->dev); -cancel_work_sync (&amd_manager->amd_sdw_work);amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work);sdw_bus_master_delete (&amd_manager->bus); ret =amd_disable_sdw_manager (amd_manager);if (ret)
Signature · 1 line
2.53.0
PATCH v9 13/24 soundwire: amd: defer dev_set_drvdata() until after INIT_WORK()
In reply to Vijendar Mukundaamd_sdw_manager_probe() called dev_set_drvdata() before initialising the amd_sdw_irq_thread and amd_sdw_work structures with INIT_WORK(). An interrupt arriving in that window could call the IRQ handler which enqueues amd_sdw_irq_thread before the work struct is initialised, leading to undefined behaviour.
Move dev_set_drvdata() to after both INIT_WORK() calls to close the race window.
--- drivers/soundwire/amd_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +1 -1
@@ -1254,9 +1254,9 @@ static int amd_sdw_manager_probe(struct platform_device *pdev)sdw_bus_master_delete (&amd_manager->bus);return ret; } -dev_set_drvdata (dev, amd_manager);INIT_WORK (&amd_manager->amd_sdw_irq_thread, amd_sdw_irq_thread);INIT_WORK (&amd_manager->amd_sdw_work, amd_sdw_update_slave_status_work); +dev_set_drvdata (dev, amd_manager);return 0 ; }
Signature · 1 line
2.53.0
PATCH v9 14/24 soundwire: amd: pm_runtime guard in remove path
In reply to Vijendar MukundaGuard pm_runtime_disable() so it is only called when runtime PM was actually enabled. amd_sdw_manager_start() calls pm_runtime_enable() only at the very end, after several fallible hardware init steps. If sdw_amd_startup() fails mid-loop (one manager started, the next fails before pm_runtime_enable()), sdw_amd_exit() triggers platform_device_unregister() for all managers. Calling pm_runtime_disable() on the partially-started manager finds disable_depth already at its initial value of 1, silently increments it to 2 and returns without a warning, so a later pm_runtime_enable() would only bring it back to 1 and leave runtime PM disabled. Use pm_runtime_enabled() to skip the call when it was never paired with an enable.
--- drivers/soundwire/amd_manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +2 -1
@@ -1265,7 +1265,8 @@ static void amd_sdw_manager_remove(struct platform_device *pdev)struct amd_sdw_manager *amd_manager =dev_get_drvdata (&pdev->dev);int ret; -pm_runtime_disable (&pdev->dev); +if (pm_runtime_enabled (&pdev->dev)) +pm_runtime_disable (&pdev->dev);amd_disable_sdw_interrupts (amd_manager);cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work);
Signature · 1 line
2.53.0
PATCH v9 15/24 soundwire: amd: guard IRQ work with interrupt_enabled and clear STATUS
In reply to Vijendar MukundaAdd an interrupt_enabled boolean to struct amd_sdw_manager to prevent already-queued work from executing during the window between starting to disable interrupts and the hardware masks taking effect.
- Add interrupt_enabled to struct amd_sdw_manager.
- Clear ACP_SW_STATE_CHANGE_STATUS_8TO11 and _0TO7 at the start of amd_enable_sdw_interrupts(), before setting interrupt_enabled, so that stale pre-suspend STATUS bits do not trigger spurious processing on POWER_OFF_MODE resume. After amd_sdw_clock_stop() completes, hardware cannot assert new STATUS bits, so the clear loses no real events.
- Set interrupt_enabled to true in amd_enable_sdw_interrupts(), after clearing stale STATUS and before unmasking any hardware registers, so no IRQ can fire with the flag false.
- Clear interrupt_enabled to false at the start of amd_disable_sdw_interrupts(), before touching any hardware registers, so that queued work items that start executing after the flag is cleared will return early.
- Guard execution of amd_sdw_irq_thread() with an early-return flag check.
- Restore interrupt_enabled inside the ACP6.3-specific wake-re-enable block in amd_suspend_runtime() POWER_OFF_MODE, so that wake events are processed after hardware wake delivery is re-armed.
- Clear STATUS registers in the ACP6.3 POWER_OFF_MODE wake-re-enable block before restoring interrupt_enabled, so that a wake interrupt does not cause amd_sdw_irq_thread() to process pre-suspend state-change or PREQ bits while the manager is disabled.
- Use WRITE_ONCE() for all stores to interrupt_enabled and READ_ONCE() for the load in amd_sdw_irq_thread() to annotate the intended single-writer/single-reader cross-context access and prevent compiler caching under LKMM.
--- drivers/soundwire/amd_manager.c | 38 +++++++++++++++++++++++++++++++ include/linux/soundwire/sdw_amd.h | 4 ++++ 2 files changed, 42 insertions(+)
drivers/soundwire/amd_manager.c +38 -0
@@ -119,6 +119,9 @@ static void amd_enable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 val; +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_0TO7 ); +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance];amd_updatel (amd_manager->acp_mmio,ACP_EXTERNAL_INTR_CNTL (amd_manager->instance), val, val);
@@ -135,6 +138,26 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 irq_mask; +/* +* Clear the flag before updating hardware masks. Work items already +* queued but not yet started will see the flag false at entry and +* return early; work items already running will complete their current +* invocation. Callers that need to ensure no instance of +* amd_sdw_irq_thread() is executing on return must follow this call +* with cancel_work_sync(&amd_manager->amd_sdw_irq_thread). Once the +* mask registers are written, the ACP hardware will not assert any new +* SDW interrupt. +* +* ACP_EXTERNAL_INTR_CNTL is the top-level gate: clearing it here +* stops interrupt delivery to the CPU. An in-flight +* amd_sdw_update_slave_status_work() on the SDW_SLAVE_ATTACHED path +* may re-write ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7 and _MASK_8TO11 +* after this function returns, but that work never touches +* ACP_EXTERNAL_INTR_CNTL, so the gate remains closed and no interrupt +* can reach the CPU. +*/ +WRITE_ONCE (amd_manager->interrupt_enabled, false); +mutex_lock (amd_manager->acp_sdw_lock); irq_mask = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance),
@@ -1112,6 +1135,18 @@ static void amd_sdw_irq_thread(struct work_struct *work)u32 status_change_8to11;u32 status_change_0to7; +/* +* Interrupts are being disabled (PM suspend or driver remove). +* Stale ACP_SW_STATE_CHANGE_STATUS_0TO7 and _8TO11 bits are +* expected to be cleared before interrupt delivery is re-enabled: +* amd_enable_sdw_interrupts() clears them on POWER_OFF_MODE resume, +* and the ACP6.3 POWER_OFF_MODE wake-re-enable block in +* amd_suspend_runtime() clears them before restoring +* interrupt_enabled for wake delivery. +*/ +if (!READ_ONCE (amd_manager->interrupt_enabled)) +return ; + status_change_8to11 =readl (amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); status_change_0to7 =readl (amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_0TO7 );if (!status_change_0to7 && !status_change_8to11)
@@ -1482,6 +1517,9 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return ret; }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && amd_manager->wake_en_mask) { +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_0TO7 ); +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio,
include/linux/soundwire/sdw_amd.h +4 -0
@@ -85,6 +85,9 @@ struct sdw_amd_dai_runtime {* @ping_slave_stat: cached slave status from the last ping * transaction that returned a response; * initialised to U32_MAX ("no valid reading yet") +* @interrupt_enabled: set when hardware interrupts are enabled; cleared +* before disabling to prevent queued work from executing +* interrupt events during teardown * @dai_runtime_array: dai runtime array */ struct amd_sdw_manager {
@@ -117,6 +120,7 @@ struct amd_sdw_manager {u32 ping_slave_stat;bool clk_stopped;bool pad_fully_torn_down; +bool interrupt_enabled;struct sdw_amd_dai_runtime **dai_runtime_array; };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v9 15/24] soundwire: amd: guard IRQ work with interrupt_enabled and clear STATUS
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] soundwire: amd: race re-enabling IRQ masks in amd_disable_sdw_interrupts() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: race re-enabling IRQ masks in amd_disable_sdw_interrupts()
--
commit 4a620e80f932c593cc068162973ef08fa381e1c4
Author: Vijendar Mukunda <[email protected]>
soundwire: amd: guard IRQ work with interrupt_enabled and clear STATUS
This commit adds an interrupt_enabled flag to struct amd_sdw_manager to prevent queued IRQ work from executing while interrupts are being disabled, and clears stale status registers before enabling interrupts or re-arming ACP6.3 wake delivery.
Quoted 4 lines
drivers/soundwire/amd_manager.c +0
-0
[ ... ]
Quoted 27 lines
drivers/soundwire/amd_manager.c +20
-0@@ -135,6 +138,26 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 irq_mask; +/* +* Clear the flag before updating hardware masks. Work items already +* queued but not yet started will see the flag false at entry and +* return early; work items already running will complete their current +* invocation. Callers that need to ensure no instance of +* amd_sdw_irq_thread() is executing on return must follow this call +* with cancel_work_sync(&amd_manager->amd_sdw_irq_thread). Once the +* mask registers are written, the ACP hardware will not assert any new +* SDW interrupt. +* +* ACP_EXTERNAL_INTR_CNTL is the top-level gate: clearing it here +* stops interrupt delivery to the CPU. An in-flight +* amd_sdw_update_slave_status_work() on the SDW_SLAVE_ATTACHED path +* may re-write ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7 and _MASK_8TO11 +* after this function returns, but that work never touches +* ACP_EXTERNAL_INTR_CNTL, so the gate remains closed and no interrupt +* can reach the CPU. +*/ +WRITE_ONCE (amd_manager->interrupt_enabled, false); +mutex_lock (amd_manager->acp_sdw_lock); irq_mask = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance),
[ ... ]
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend_runtime(struct device *dev) · line 1524
Quoted 10 lines
drivers/soundwire/amd_manager.c +3
-0@@ -1481,6 +1516,9 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return ret; }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && amd_manager->wake_en_mask) { +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_0TO7 ); +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio,
[Severity: Medium]
Can an in-flight amd_sdw_update_slave_status_work() re-enable ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7 and _MASK_8TO11 right before amd_suspend_runtime() re-opens ACP_EXTERNAL_INTR_CNTL for ACP6.3 wake?
The comment in amd_disable_sdw_interrupts() notes that an in-flight amd_sdw_update_slave_status_work() on the SDW_SLAVE_ATTACHED path may overwrite ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7 and _MASK_8TO11 after amd_disable_sdw_interrupts() clears them, and relies on ACP_EXTERNAL_INTR_CNTL staying closed. However, in AMD_SDW_POWER_OFF_MODE on ACP6.3 with wake_en_mask set, amd_suspend_runtime() then preserves those mask bits and re-opens the top-level gate:
CPU0 kworkeramd_suspend_runtime()
...
amd_deinit_sdw_manager()
amd_disable_sdw_interrupts()
interrupt_enabled = false
ACP_EXTERNAL_INTR_CNTL &= ~mask
MASK_0TO7 = 0
MASK_8TO11 = 0
amd_sdw_update_slave_status_work()
MASK_0TO7 = AMD_SDW_IRQ_MASK_0TO7
MASK_8TO11 = AMD_SDW_IRQ_MASK_8TO11
amd_sdw_wake_enable(..., true)
MASK_8TO11 |= AMD_SDW_WAKE_INTR_MASK interrupt_enabled = true
ACP_EXTERNAL_INTR_CNTL |= mask <-- non-wake IRQs unmasked while suspended
Because amd_sdw_wake_enable() performs a read-modify-write on ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11, the non-wake state-change and PREQ interrupt masks written by the worker remain enabled once amd_suspend_runtime() sets interrupt_enabled back to true and re-enables ACP_EXTERNAL_INTR_CNTL, allowing amd_sdw_irq_thread() to process non-wake interrupts while the manager is disabled and clock-stopped.
Checking READ_ONCE(amd_manager->interrupt_enabled) in amd_sdw_update_slave_status_work() before unmasking, or draining amd_sdw_work before clearing the mask registers in amd_disable_sdw_interrupts(), would avoid this race.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Re: [PATCH v9 15/24] soundwire: amd: guard IRQ work with interrupt_enabled and clear STATUS
Quoted 49 lines · On 24/11/26 14:48, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: race re-enabling IRQ masks inamd_disable_sdw_interrupts()
--commit
4a620e80f932c593cc068162973ef08fa381e1c4
Author: Vijendar Mukunda <[email protected]>soundwire: amd: guard IRQ work with
interrupt_enabledand clear STATUSThis commit adds an
interrupt_enabledflag to structamd_sdw_managerto prevent queued IRQ work from executing while interrupts are being disabled, and clears stale status registers before enabling interrupts or re-arming ACP6.3 wake delivery.Quoted 4 lines
drivers/soundwire/amd_manager.c +0
-0[ ... ]
Quoted 27 lines
drivers/soundwire/amd_manager.c +20
-0@@ -135,6 +138,26 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) {u32 irq_mask; +/* +* Clear the flag before updating hardware masks. Work items already +* queued but not yet started will see the flag false at entry and +* return early; work items already running will complete their current +* invocation. Callers that need to ensure no instance of +* amd_sdw_irq_thread() is executing on return must follow this call +* with cancel_work_sync(&amd_manager->amd_sdw_irq_thread). Once the +* mask registers are written, the ACP hardware will not assert any new +* SDW interrupt. +* +* ACP_EXTERNAL_INTR_CNTL is the top-level gate: clearing it here +* stops interrupt delivery to the CPU. An in-flight +* amd_sdw_update_slave_status_work() on the SDW_SLAVE_ATTACHED path +* may re-write ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7 and _MASK_8TO11 +* after this function returns, but that work never touches +* ACP_EXTERNAL_INTR_CNTL, so the gate remains closed and no interrupt +* can reach the CPU. +*/ +WRITE_ONCE (amd_manager->interrupt_enabled, false); +mutex_lock (amd_manager->acp_sdw_lock); irq_mask = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance),[ ... ]
Quoted 14 lines
drivers/soundwire/amd_manager.c static int __maybe_unused amd_suspend_runtime(struct device *dev) · line 1524
Quoted 10 lines
drivers/soundwire/amd_manager.c +3
-0@@ -1481,6 +1516,9 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return ret; }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && amd_manager->wake_en_mask) { +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 ); +writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_0TO7 ); +WRITE_ONCE (amd_manager->interrupt_enabled, true);mutex_lock (amd_manager->acp_sdw_lock); val = sdw_manager_reg_mask_array[amd_manager->instance]; amd_updatel(amd_manager->acp_mmio,[Severity: Medium]
Can an in-flightamd_sdw_update_slave_status_work()re-enableACP_SW_STATE_CHANGE_STATUS_MASK_0TO7and_MASK_8TO11right beforeamd_suspend_runtime()re-opensACP_EXTERNAL_INTR_CNTLfor ACP6.3 wake?
No code change required; marking as false positive.
The amd_deinit_sdw_manager() call shown in the reviewer's trace is removed by patch 18 of this series ("soundwire: amd: drop amd_deinit_sdw_manager() in POWER_OFF suspend"). With the full series applied, the AMD_SDW_POWER_OFF_MODE path in amd_acp63_sdw_suspend_runtime() is:
acp_disable_sdw_interrupts(amd_manager); // close gate, MASK = 0 cancel_work_sync(&amd_manager->amd_sdw_irq_thread); // drain irq_thread cancel_work_sync(&amd_manager->amd_sdw_work); // drain sdw_work amd_sdw_clock_stop(amd_manager); // stop clock acp_disable_sdw_manager(amd_manager); acp_sdw_wake_enable(amd_manager, true); // set wake bit only
...
/* ACP6.3 wake reopen: */
writel(0x00, STATUS_8TO11);
writel(0x00, STATUS_0TO7);
WRITE_ONCE(interrupt_enabled, true);
ACP_EXTERNAL_INTR_CNTL |= mask;
cancel_work_sync(&amd_sdw_work) at line 1466 waits for any running amd_sdw_update_slave_status_work() to complete and cancels any pending instance. After it returns, no kworker can overwrite the MASK registers. The two-step drain (irq_thread first, then sdw_work) also covers the chain case where a running irq_thread schedules amd_sdw_work just before completing.
When the gate reopens, MASK_0TO7 = 0 and MASK_8TO11 = AMD_SDW_WAKE_INTR_MASK only (set by acp_sdw_wake_enable()). The clock is stopped before gate-open so no STATUS bits can be set by hardware, and STATUS registers are explicitly cleared to zero immediately before gate-open.
As additional defenses: the SoundWire clock is stopped before the gate reopens, so no PING frames are sent and STATUS bits cannot be set by hardware after gate-open; and STATUS_0TO7 and STATUS_8TO11 are explicitly cleared to zero immediately before the gate reopens, removing any stale bits from before the suspend.
Quoted 38 lines
The comment in
amd_disable_sdw_interrupts()notes that an in-flightamd_sdw_update_slave_status_work()on theSDW_SLAVE_ATTACHEDpath may overwriteACP_SW_STATE_CHANGE_STATUS_MASK_0TO7and_MASK_8TO11afteramd_disable_sdw_interrupts()clears them, and relies onACP_EXTERNAL_INTR_CNTLstaying closed. However, inAMD_SDW_POWER_OFF_MODEon ACP6.3 withwake_en_maskset,amd_suspend_runtime()then preserves those mask bits and re-opens the top-level gate:CPU0 kworker
amd_suspend_runtime()
...
amd_deinit_sdw_manager()amd_disable_sdw_interrupts() interrupt_enabled = false ACP_EXTERNAL_INTR_CNTL &= ~mask MASK_0TO7 = 0 MASK_8TO11 = 0 amd_sdw_update_slave_status_work() MASK_0TO7 = AMD_SDW_IRQ_MASK_0TO7 MASK_8TO11 = AMD_SDW_IRQ_MASK_8TO11 amd_sdw_wake_enable(..., true) MASK_8TO11 |= AMD_SDW_WAKE_INTR_MASK
interrupt_enabled= true
ACP_EXTERNAL_INTR_CNTL|= mask <-- non-wake IRQs unmasked while suspendedBecause
amd_sdw_wake_enable()performs a read-modify-write onACP_SW_STATE_CHANGE_STATUS_MASK_8TO11, the non-wake state-change and PREQ interrupt masks written by the worker remain enabled onceamd_suspend_runtime()setsinterrupt_enabledback to true and re-enablesACP_EXTERNAL_INTR_CNTL, allowingamd_sdw_irq_thread()to process non-wake interrupts while the manager is disabled and clock-stopped.Checking
READ_ONCE(amd_manager->interrupt_enabled)inamd_sdw_update_slave_status_work()before unmasking, or drainingamd_sdw_workbefore clearing the mask registers inamd_disable_sdw_interrupts(), would avoid this race.
PATCH v9 16/24 soundwire: amd: fix *sdw_ctx leak when sdw_amd_startup() fails
In reply to Vijendar Mukundasdw_amd_probe() published *sdw_ctx immediately after sdw_amd_probe_controller() returned, before sdw_amd_startup() ran. If sdw_amd_startup() failed, the error was returned directly, leaving *sdw_ctx pointing to an allocated context whose platform devices were already registered. The caller has no way to distinguish this from a genuine probe success, so the context and devices leak.
Fix this by publishing *sdw_ctx = ctx right after sdw_amd_probe_controller() succeeds, then calling sdw_amd_startup(). On failure reset *sdw_ctx = NULL and call sdw_amd_exit(ctx) before returning the error. The caller always observes *sdw_ctx as either NULL (startup did not complete) or a pointer to a fully-started, valid context.
--- drivers/soundwire/amd_init.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/soundwire/amd_init.c +13 -3
@@ -182,11 +182,21 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)int sdw_amd_probe (struct sdw_amd_res *res,struct sdw_amd_ctx **sdw_ctx) { - *sdw_ctx =sdw_amd_probe_controller (res); -if (!*sdw_ctx) +struct sdw_amd_ctx *ctx; +int ret; + + ctx =sdw_amd_probe_controller (res); +if (!ctx)return -ENODEV ; -return sdw_amd_startup (*sdw_ctx); + *sdw_ctx = ctx; + ret =sdw_amd_startup (ctx); +if (ret) { + *sdw_ctx =NULL ; +sdw_amd_exit (ctx); +return ret; + } +return 0 ; }EXPORT_SYMBOL_NS (sdw_amd_probe,"SOUNDWIRE_AMD_INIT" );
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v9 16/24] soundwire: amd: fix *sdw_ctx leak when sdw_amd_startup() fails
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] soundwire: amd: race with hardirq handlers on sdw_amd_startup() failure --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: race with hardirq handlers on sdw_amd_startup() failure
--
commit fb658db6de398fb5ff736ed8e17029fdf853a4c4
Author: Vijendar Mukunda <[email protected]>
soundwire: amd: fix *sdw_ctx leak when sdw_amd_startup() fails
This commit cleans up the allocated SoundWire context and resets *sdw_ctx to NULL if sdw_amd_startup() fails during sdw_amd_probe().
Quoted 18 lines
drivers/soundwire/amd_init.c +5
-3@@ -182,11 +182,21 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)int sdw_amd_probe (struct sdw_amd_res *res,struct sdw_amd_ctx **sdw_ctx) { - *sdw_ctx =sdw_amd_probe_controller (res); -if (!*sdw_ctx) +struct sdw_amd_ctx *ctx; +int ret; + + ctx =sdw_amd_probe_controller (res); +if (!ctx)return -ENODEV ; -return sdw_amd_startup (*sdw_ctx);
drivers/soundwire/amd_init.c static int sdw_amd_startup(struct sdw_amd_ctx *ctx) · line 201
Quoted 10 lines
drivers/soundwire/amd_init.c +8
-0+ *sdw_ctx = ctx; + ret =sdw_amd_startup (ctx); +if (ret) { + *sdw_ctx =NULL ; +sdw_amd_exit (ctx); +return ret; + } +return 0 ; }EXPORT_SYMBOL_NS (sdw_amd_probe,"SOUNDWIRE_AMD_INIT" );
[Severity: Medium]
Can clearing *sdw_ctx and tearing down ctx here race with the parent ACP hardirq handler?
The callers of sdw_amd_probe() register their PCI IRQ handler before probing SoundWire, and amd_sdw_manager_start() unmasks manager interrupts in hardware via amd_enable_sdw_interrupts() before amd_enable_sdw_manager() and before subsequent managers in sdw_amd_startup() are started. If startup fails after interrupts are unmasked on a manager, the IRQ handler can fire while sdw_amd_probe() clears *sdw_ctx (adata->sdw) and runs sdw_amd_exit():
CPU0 CPU1 (<hardirq>)sdw_amd_probe()
*sdw_ctx = ctx
sdw_amd_startup(ctx)
amd_sdw_manager_start()
amd_enable_sdw_interrupts()
/* startup fails */
acp7x_irq_handler()
if (adata->sdw)
sof_acp7x_handle_sdw_manager_irq()
snd_sof_dsp_write(...) *sdw_ctx = NULL
if (!adata->sdw->pdev[instance])
<-- NULL pointer dereference
If the hardirq handler instead loads adata->sdw->pdev[instance] right before *sdw_ctx = NULL, it runs unsynchronized with sdw_amd_exit(ctx), which unregisters the platform devices (freeing amd_manager without waiting for in-flight hardirqs) and frees ctx, allowing a use-after-free or scheduling amd_sdw_irq_thread after cancel_work_sync(). In addition, because *sdw_ctx is cleared before amd_sdw_manager_remove() calls amd_disable_sdw_interrupts(), any SoundWire interrupt arriving on ACP7x in that window sees adata->sdw == NULL and returns IRQ_NONE without acknowledging the status registers.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Re: [PATCH v9 16/24] soundwire: amd: fix *sdw_ctx leak when sdw_amd_startup() fails
Quoted 31 lines · On 24/11/26 14:41, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] soundwire: amd: race with hardirq handlers onsdw_amd_startup()failure
--commit
fb658db6de398fb5ff736ed8e17029fdf853a4c4
Author: Vijendar Mukunda <[email protected]>soundwire: amd: fix
*sdw_ctxleak whensdw_amd_startup()failsThis commit cleans up the allocated SoundWire context and resets
*sdw_ctxto NULL ifsdw_amd_startup()fails duringsdw_amd_probe().Quoted 17 lines
drivers/soundwire/amd_init.c +5
-2@@ -182,11 +182,21 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)int sdw_amd_probe (struct sdw_amd_res *res,struct sdw_amd_ctx **sdw_ctx) { - *sdw_ctx =sdw_amd_probe_controller (res); -if (!*sdw_ctx) +struct sdw_amd_ctx *ctx; +int ret; + + ctx =sdw_amd_probe_controller (res); +if (!ctx)return -ENODEV ;
Quoted 14 lines
drivers/soundwire/amd_init.c static int sdw_amd_startup(struct sdw_amd_ctx *ctx) · line 201
Quoted 11 lines
drivers/soundwire/amd_init.c +8
-1-return sdw_amd_startup (*sdw_ctx); + *sdw_ctx = ctx; + ret =sdw_amd_startup (ctx); +if (ret) { + *sdw_ctx =NULL ; +sdw_amd_exit (ctx); +return ret; + } +return 0 ; }EXPORT_SYMBOL_NS (sdw_amd_probe,"SOUNDWIRE_AMD_INIT" );[Severity: Medium]
Can clearing*sdw_ctxand tearing down ctx here race with the parent ACP hardirq handler?
No code change required; marking as false positive.
The specific NULL pointer dereference concern — acp_irq_handler() (sound/soc/sof/amd/acp.c) accessing adata->sdw->pdev[i]->dev when adata->sdw is NULL — is directly addressed by companion patches already merged in Mark Brown's ASoC tree:
34ea81a7f284 ("ASoC: SOF: amd: guard adata->sdw dereferences with NULL check in IRQ handler")
41e06aaef9c0 ("ASoC: amd: ps: guard adata->sdw dereferences with NULL check in IRQ handler")
These patches add a NULL check for adata->sdw in acp_irq_handler() before accessing ->pdev[0]->dev and ->pdev[1]->dev. The interrupt status register write (snd_sof_dsp_write() clearing ACP_SDW0_IRQ_MASK in ACP_EXTERNAL_INTR_STAT) is moved outside the guard, so the ACP interrupt bit is always acknowledged regardless of adata->sdw state. This prevents the hardware from re-asserting the interrupt when adata->sdw is NULL.
This patch sets *sdw_ctx = NULL before calling sdw_amd_exit(ctx). After *sdw_ctx = NULL, acp_irq_handler() sees adata->sdw == NULL, acknowledges the IRQ, and returns without scheduling any work. sdw_amd_exit() then frees ctx safely because no IRQ handler can access it after the NULL check.
The STATUS-register pre-clear argument applies to the sub-case where acp_enable_sdw_manager() itself fails: STATUS was cleared at gate-open, the manager hardware never started, no PING frames were sent, and no peripheral can set STATUS bits. The companion patches cover the case where manager 0 fully started before manager 1 failed.
Quoted 34 lines
The callers of
sdw_amd_probe()register their PCI IRQ handler before probing SoundWire, andamd_sdw_manager_start()unmasks manager interrupts in hardware viaamd_enable_sdw_interrupts()beforeamd_enable_sdw_manager()and before subsequent managers insdw_amd_startup()are started. If startup fails after interrupts are unmasked on a manager, the IRQ handler can fire whilesdw_amd_probe()clears*sdw_ctx(adata->sdw) and runssdw_amd_exit():CPU0 CPU1 (<hardirq>)
sdw_amd_probe()
*sdw_ctx= ctx
sdw_amd_startup(ctx)amd_sdw_manager_start() amd_enable_sdw_interrupts() /* startup fails */ acp7x_irq_handler() if (adata->sdw) sof_acp7x_handle_sdw_manager_irq() snd_sof_dsp_write(...)
*sdw_ctx= NULL
if (!adata->sdw->pdev[instance])
<-- NULL pointer dereferenceIf the hardirq handler instead loads adata->sdw->pdev[instance] right before
*sdw_ctx= NULL, it runs unsynchronized withsdw_amd_exit(ctx), which unregisters the platform devices (freeingamd_managerwithout waiting for in-flight hardirqs) and frees ctx, allowing a use-after-free or schedulingamd_sdw_irq_threadaftercancel_work_sync(). In addition, because*sdw_ctxis cleared beforeamd_sdw_manager_remove()callsamd_disable_sdw_interrupts(), any SoundWire interrupt arriving on ACP7x in that window seesadata->sdw== NULL and returnsIRQ_NONEwithout acknowledging the status registers.
PATCH v9 17/24 soundwire: amd: propagate amd_init_sdw_manager() error on resume
In reply to Vijendar MukundaIn amd_resume_runtime() POWER_OFF_MODE, amd_init_sdw_manager() was called without capturing its return value. The function performs hardware bus resets using readl_poll_timeout() and can return -ETIMEDOUT if the hardware does not respond. When that happens, execution fell through to amd_enable_sdw_interrupts() and amd_enable_sdw_manager() on hardware that may still be in a broken reset state.
Fix by capturing the return value and returning early on failure.
--- drivers/soundwire/amd_manager.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/soundwire/amd_manager.c +3 -1
@@ -1612,7 +1612,9 @@ static int __maybe_unused amd_resume_runtime(struct device *dev) ret =amd_sdw_clk_init_ctrl (amd_manager);if (ret)return ret; -amd_init_sdw_manager (amd_manager); + ret =amd_init_sdw_manager (amd_manager); +if (ret) +return ret;amd_enable_sdw_interrupts (amd_manager); ret =amd_enable_sdw_manager (amd_manager);if (ret)
Signature · 1 line
2.53.0
PATCH v9 18/24 soundwire: amd: drop amd_deinit_sdw_manager() in POWER_OFF suspend
In reply to Vijendar Mukundaamd_deinit_sdw_manager() was a small helper that bundled amd_disable_sdw_interrupts() and amd_disable_sdw_manager() together. Expand the two POWER_OFF_MODE call sites in amd_suspend() and amd_suspend_runtime() to call those two functions directly, then remove the helper. No functional change.
--- drivers/soundwire/amd_manager.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/soundwire/amd_manager.c +4 -8
@@ -169,12 +169,6 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager)writel (0x00 , amd_manager->mmio +ACP_SW_ERROR_INTR_MASK ); } -static int amd_deinit_sdw_manager (struct amd_sdw_manager *amd_manager) -{ -amd_disable_sdw_interrupts (amd_manager); -return amd_disable_sdw_manager (amd_manager); -} -static void __amd_sdw_oe_update (struct amd_sdw_manager *amd_manager,u32 mask,bool enable) {
@@ -1464,7 +1458,8 @@ static int __maybe_unused amd_suspend(struct device *dev) ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; - ret =amd_deinit_sdw_manager (amd_manager); +amd_disable_sdw_interrupts (amd_manager); + ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;/* System suspend: tear down all pads */
@@ -1507,7 +1502,8 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; - ret =amd_deinit_sdw_manager (amd_manager); +amd_disable_sdw_interrupts (amd_manager); + ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;amd_sdw_wake_enable (amd_manager, true);
Signature · 1 line
2.53.0
PATCH v9 19/24 soundwire: amd: replace >= ACP70 with explicit switch/case in PM paths
In reply to Vijendar MukundaReplace open-ended acp_rev >= ACP70_PCI_REV_ID comparisons in amd_suspend(), amd_suspend_runtime(), and amd_resume_runtime() with explicit per-revision handling enumerating ACP63, ACP70, ACP71, and ACP72, so that every supported revision is handled explicitly.
The host wake enable step is guarded by acp_rev at six PM call sites. Factor that repeated block into amd_sdw_host_wake_enable_by_rev() to avoid duplicating the switch/case at every site. The remaining device state transitions keep an inline switch/case as one of them carries additional PME handling.
An unrecognised revision cannot reach these PM callbacks because amd_sdw_manager_probe() already validates acp_rev with the same switch and fails registration for anything unknown. The switch default therefore emits dev_err() and returns -EINVAL to make the unexpected case visible while keeping the error path consistent across all PM operations.
--- drivers/soundwire/amd_manager.c | 100 +++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 34 deletions(-)
drivers/soundwire/amd_manager.c +66 -34
@@ -1420,6 +1420,23 @@ static int __maybe_unused amd_pm_prepare(struct device *dev)return 0 ; } +static int __maybe_unused amd_sdw_host_wake_enable_by_rev (struct amd_sdw_manager *amd_manager, +bool enable) +{ +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : +return amd_sdw_host_wake_enable (amd_manager, enable); +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; + } +return 0 ; +} +static int __maybe_unused amd_suspend (struct device *dev) {struct amd_sdw_manager *amd_manager =dev_get_drvdata (dev);
@@ -1435,22 +1452,18 @@ static int __maybe_unused amd_suspend(struct device *dev)if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) {cancel_work_sync (&amd_manager->amd_sdw_work);amd_sdw_wake_enable (amd_manager, false); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) {cancel_work_sync (&amd_manager->amd_sdw_work);amd_sdw_wake_enable (amd_manager, false); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret;/* * As per hardware programming sequence on AMD platforms, * clock stop should be invoked first before powering-off
@@ -1468,10 +1481,19 @@ static int __maybe_unused amd_suspend(struct device *dev) amd_manager->pad_fully_torn_down = true; } } -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );if (ret)return ret; +break ; +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; }return 0 ; }
@@ -1490,11 +1512,9 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev) }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) {amd_sdw_wake_enable (amd_manager, true); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, true); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true); +if (ret) +return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret;
@@ -1507,12 +1527,10 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)if (ret)return ret;amd_sdw_wake_enable (amd_manager, true); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, true); -if (ret) -return ret; - }else if ((amd_manager->acp_rev ==ACP63_PCI_REV_ID ) && - amd_manager->wake_en_mask) { + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true); +if (ret) +return ret; +if (amd_manager->acp_rev ==ACP63_PCI_REV_ID && amd_manager->wake_en_mask) {writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_8TO11 );writel (0x00 , amd_manager->mmio +ACP_SW_STATE_CHANGE_STATUS_0TO7 );WRITE_ONCE (amd_manager->interrupt_enabled, true);
@@ -1530,7 +1548,12 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)*/ amd_sdw_oe_ctrl (amd_manager, false); } -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D3 );if (ret)return ret;
@@ -1542,6 +1565,10 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)dev_dbg (amd_manager->dev,"ACP_PME_EN:0x%x\n" , val); } } +break ; +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; }return 0 ; }
@@ -1563,11 +1590,9 @@ static int __maybe_unused amd_resume_runtime(struct device *dev) ret =amd_sdw_clock_stop_exit (amd_manager);if (ret)return ret; -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret; }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) {if (amd_manager->pad_fully_torn_down) {amd_sdw_pad_ctrl (amd_manager, true);
@@ -1587,11 +1612,9 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)mutex_lock (&amd_manager->bus.msg_lock); amd_manager->ping_slave_stat =U32_MAX ;mutex_unlock (&amd_manager->bus.msg_lock); -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { - ret =amd_sdw_host_wake_enable (amd_manager, false); -if (ret) -return ret; - } + ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false); +if (ret) +return ret; val =readl (amd_manager->mmio +ACP_SW_CLK_RESUME_CTRL );if (val) { val |=AMD_SDW_CLK_RESUME_REQ ;
@@ -1617,10 +1640,19 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)return ret;amd_sdw_set_frameshape (amd_manager); } -if (amd_manager->acp_rev >=ACP70_PCI_REV_ID ) { +switch (amd_manager->acp_rev) { +case ACP63_PCI_REV_ID : +break ; +case ACP70_PCI_REV_ID : +case ACP71_PCI_REV_ID : +case ACP72_PCI_REV_ID : ret =amd_sdw_set_device_state (amd_manager,AMD_SDW_DEVICE_STATE_D0 );if (ret)return ret; +break ; +default : +dev_err (amd_manager->dev,"unexpected acp_rev 0x%x\n" , amd_manager->acp_rev); +return -EINVAL ; }return 0 ; }
Signature · 1 line
2.53.0
PATCH v9 20/24 soundwire: amd: fix interrupt gate and work drain ordering in PM ops
In reply to Vijendar MukundaFix ordering and sequencing bugs across the CLK_STOP_MODE and POWER_OFF_MODE suspend paths:
amd_suspend():
- CLK_STOP_MODE: cancel_work_sync(&amd_sdw_work) ran without first closing the ACP_EXTERNAL_INTR_CNTL delivery gate or draining amd_sdw_irq_thread. An ISR already in flight when the drain completed could re-queue work after cancel_work_sync() returned, racing amd_sdw_clock_stop(). amd_sdw_wake_enable(false) preceding the work drain was also redundant: amd_disable_sdw_interrupts() already masks all SDW interrupt delivery including wake. The amd_enable_sdw_interrupts() call after clock stop restores all state-change, error, and delivery masks; in CLK_STOP_MODE only the SDW clock is gated so no state-change interrupt can be asserted after clock stop. The wake bit is not part of the restored masks; wake interrupts are only asserted when the system transitions to D3. If amd_sdw_host_wake_enable_by_rev() returns -EINVAL the operation aborts; this indicates an unrecognized acp_rev, which is an unsupported configuration on this driver.
- POWER_OFF_MODE: same missing gate closure and irq_thread drain before the work drain; a redundant amd_disable_sdw_interrupts() call was placed after clock stop instead of before the drains; amd_sdw_wake_enable(false) at the top of this branch was redundant because amd_disable_sdw_interrupts() (now moved first) already zeroes ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11, which covers the wake bit.
amd_suspend_runtime():
- CLK_STOP_MODE: neither amd_sdw_irq_thread nor amd_sdw_work was drained at all before amd_sdw_clock_stop(); the interrupt delivery gate was not closed before the drains and not reopened after clock stop; amd_sdw_wake_enable(true) was placed before the drains instead of after clock stop. If amd_sdw_host_wake_enable_by_rev() returns -EINVAL the operation aborts; this indicates an unrecognized acp_rev, which is an unsupported configuration on this driver.
- POWER_OFF_MODE: missing gate closure, irq_thread drain, and work drain before clock stop; amd_disable_sdw_interrupts() was placed after clock stop instead of before.
--- drivers/soundwire/amd_manager.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/soundwire/amd_manager.c +13 -5
@@ -1450,17 +1450,20 @@ static int __maybe_unused amd_suspend(struct device *dev) }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work); -amd_sdw_wake_enable (amd_manager, false); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false);if (ret)return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager); }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread);cancel_work_sync (&amd_manager->amd_sdw_work); -amd_sdw_wake_enable (amd_manager, false); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, false);if (ret)return ret;
@@ -1471,7 +1474,6 @@ static int __maybe_unused amd_suspend(struct device *dev) ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; -amd_disable_sdw_interrupts (amd_manager); ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;
@@ -1511,18 +1513,24 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)return 0 ; }if (amd_manager->power_mode_mask &AMD_SDW_CLK_STOP_MODE ) { -amd_sdw_wake_enable (amd_manager, true); +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work); ret =amd_sdw_host_wake_enable_by_rev (amd_manager, true);if (ret)return ret; ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; +amd_enable_sdw_interrupts (amd_manager); +amd_sdw_wake_enable (amd_manager, true); }else if (amd_manager->power_mode_mask &AMD_SDW_POWER_OFF_MODE ) { +amd_disable_sdw_interrupts (amd_manager); +cancel_work_sync (&amd_manager->amd_sdw_irq_thread); +cancel_work_sync (&amd_manager->amd_sdw_work); ret =amd_sdw_clock_stop (amd_manager);if (ret)return ret; -amd_disable_sdw_interrupts (amd_manager); ret =amd_disable_sdw_manager (amd_manager);if (ret)return ret;
Signature · 1 line
2.53.0
PATCH v9 21/24 soundwire: amd: check for NULL manager drvdata in sdw_amd_startup()
In reply to Vijendar Mukundasdw_amd_startup() calls dev_get_drvdata() to retrieve the per-manager context and passes the result unconditionally to amd_sdw_manager_start(). If the platform device for a manager instance was registered successfully but its probe failed (e.g. due to ENOMEM or a deferred probe), dev_get_drvdata() returns NULL and amd_sdw_manager_start() immediately dereferences it, causing a kernel panic.
Add a NULL check after dev_get_drvdata() and return -ENODEV so that a failed manager probe surfaces as an error from sdw_amd_probe() rather than a kernel crash.
--- drivers/soundwire/amd_init.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/soundwire/amd_init.c +4 -0
@@ -172,6 +172,10 @@ static int sdw_amd_startup(struct sdw_amd_ctx *ctx)if (!(ctx->link_mask &BIT (i)))continue ; amd_manager =dev_get_drvdata (&ctx->pdev[i]->dev); +if (!amd_manager) { +dev_err (&ctx->pdev[i]->dev,"SoundWire manager not probed\n" ); +return -ENODEV ; + } ret =amd_sdw_manager_start (amd_manager);if (ret)return ret;
Signature · 1 line
2.53.0
PATCH v9 22/24 soundwire: amd: fix shared-register RMW race in amd_sdw_set_device_state()
In reply to Vijendar MukundaAMD_SDW_DEVICE_STATE packs the D0/D3 state for SDW0 (bits [1:0]) and SDW1 (bits [3:2]) in a single ACP-level register. amd_sdw_set_device_state() performed a read-modify-write sequence on this shared register without holding acp_sdw_lock, leaving it open to a lost-update race when SDW0 and SDW1 execute concurrent PM transitions.
Acquire acp_sdw_lock around the read-modify-write sequence. Unlock before returning -EINVAL from the default branch so the mutex is always released on every exit path.
--- drivers/soundwire/amd_manager.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/soundwire/amd_manager.c +3 -0
@@ -292,6 +292,7 @@ static int amd_sdw_set_device_state(struct amd_sdw_manager *amd_manager, u32 tar {u32 sdw_dev_state; +mutex_lock (amd_manager->acp_sdw_lock); sdw_dev_state =readl (amd_manager->acp_mmio +AMD_SDW_DEVICE_STATE );switch (amd_manager->instance) {case ACP_SDW0 :
@@ -303,10 +304,12 @@ static int amd_sdw_set_device_state(struct amd_sdw_manager *amd_manager, u32 tar AMD_SDW1_DEVICE_STATE_MASK);break ;default : +mutex_unlock (amd_manager->acp_sdw_lock);return -EINVAL ; }writel (sdw_dev_state, amd_manager->acp_mmio +AMD_SDW_DEVICE_STATE ); sdw_dev_state =readl (amd_manager->acp_mmio +AMD_SDW_DEVICE_STATE ); +mutex_unlock (amd_manager->acp_sdw_lock);dev_dbg (amd_manager->dev,"AMD_SDW_DEVICE_STATE:0x%x\n" , sdw_dev_state);return 0 ; }
Signature · 1 line
2.53.0
PATCH v9 23/24 soundwire: amd: fix shared-register RMW race in amd_sdw_host_wake_enable()
In reply to Vijendar MukundaACP_EXTERNAL_INTR_CNTL(ACP_SDW1) holds host-wake interrupt bits for both instances (BIT(22) for SDW0, BIT(23) for SDW1). amd_sdw_host_wake_enable() performed a read-modify-write sequence on this shared register without holding acp_sdw_lock, leaving it open to a lost-update race when SDW0 and SDW1 execute concurrent PM transitions.
Acquire acp_sdw_lock around the read-modify-write sequence.
--- drivers/soundwire/amd_manager.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/soundwire/amd_manager.c +2 -0
@@ -333,12 +333,14 @@ static int amd_sdw_host_wake_enable(struct amd_sdw_manager *amd_manager, bool enreturn -EINVAL ; } +mutex_lock (amd_manager->acp_sdw_lock); intr_cntl1 =readl (amd_manager->acp_mmio +ACP_EXTERNAL_INTR_CNTL (ACP_SDW1 ));if (enable) intr_cntl1 |= sdw_host_wake_irq_mask;else intr_cntl1 &= ~sdw_host_wake_irq_mask;writel (intr_cntl1, amd_manager->acp_mmio +ACP_EXTERNAL_INTR_CNTL (ACP_SDW1 )); +mutex_unlock (amd_manager->acp_sdw_lock);return 0 ; }
Signature · 1 line
2.53.0
PATCH v9 24/24 soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
In reply to Vijendar Mukundasdw_handle_slave_alerts() calls pm_runtime_get_sync(&slave->dev) which, when slave->dev is not in RPM_ACTIVE, calls rpm_resume() on the slave. rpm_resume() propagates synchronously up the parent chain: slave->dev -> bus->dev -> manager->dev. If manager->dev is in RPM_SUSPENDING at that point, rpm_resume() blocks on dev->power.wait_queue waiting for the suspend to complete.
This creates a deadlock: the manager's runtime_suspend callback (e.g. amd_suspend_runtime() or intel_suspend_runtime()) is blocked in cancel_work_sync() waiting for the alert work to finish, while the alert work is blocked in pm_runtime_get_sync() waiting for the manager's runtime_suspend to complete.
Fix this by first checking the manager device state using pm_runtime_get_if_active() on slave->bus->dev->parent (the physical manager device). This is an atomic check: if it returns 1 the usage counter is incremented in the same operation and the manager cannot transition to RPM_SUSPENDING while the reference is held.
- If the manager reference cannot be taken (ret == 0, manager is not RPM_ACTIVE): return early to defer the alert. By PM ordering the slave is already RPM_SUSPENDED and hardware is inaccessible. The MIPI SoundWire spec guarantees the peripheral re-asserts the alert after clock resume; when the link fully powers off the peripheral loses power and its alert state does not survive, so the early return is harmless in both cases. This also closes the race where the slave is in RPM_SUSPENDING at the check: if the slave's suspend completes before handle_nested_irq() runs and the manager enters RPM_SUSPENDING, pm_runtime_get_if_active(mgr_dev) would have returned 0 and the function would already have returned early.
- If the manager reference is taken (ret > 0, manager is RPM_ACTIVE):
proceed with pm_runtime_resume_and_get(&slave->dev) to resume the slave. Holding the manager reference prevents the manager from entering RPM_SUSPENDING while the slave resumes, closing the deadlock window for all slave PM states.
- If ret < 0 (-EINVAL, PM disabled on manager): fall through without a manager reference. PM being disabled means no suspend/resume callbacks run, so no deadlock risk. This is consistent with the original -EACCES exemption for the slave.
pm_runtime_resume_and_get() is used for the slave (instead of pm_runtime_get_sync()) because it does not increment the usage counter on error, simplifying the error-path accounting. Introduce have_pm_ref and have_mgr_ref booleans to guard the pm_runtime_put calls at io_err:
so they are only reached when a reference was actually taken. The manager reference is released at the new mgr_put: label after io_err:.
--- drivers/soundwire/bus.c | 52 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-)
drivers/soundwire/bus.c +47 -5
@@ -1667,15 +1667,52 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)u8 buf, buf2[2 ];bool parity_check;bool parity_quirk; +bool have_pm_ref = false; +bool have_mgr_ref = false; +struct device *mgr_dev = slave->bus->dev->parent;sdw_modify_slave_status (slave,SDW_SLAVE_ALERT ); - ret =pm_runtime_get_sync (&slave->dev); + ret =pm_runtime_get_if_active (mgr_dev); +if (ret ==0 ) { +/* +* Manager is not RPM_ACTIVE; slave is already RPM_SUSPENDED +* by PM ordering. Return early to avoid I/O on inaccessible +* hardware and to prevent a deadlock: if the manager is in +* RPM_SUSPENDING, its runtime_suspend callback may be blocked +* in cancel_work_sync() waiting for this work, while this work +* would block in pm_runtime_resume_and_get() waiting for the +* manager to complete its suspend. +* +* When the SoundWire link enters clock-stop mode, the MIPI +* SoundWire spec guarantees the peripheral re-asserts the +* alert after clock resume, so the interrupt is deferred +* rather than dropped. When the link fully powers off +* (e.g. D3 or equivalent), the peripheral loses power and +* its alert state does not survive; the early return is +* harmless. +*/ +dev_dbg (&slave->dev,"Alert deferred: manager not active\n" ); +return 0 ; + } +if (ret >0 ) + have_mgr_ref = true; +/* +* ret < 0 (-EINVAL): PM is disabled (CONFIG_PM=n or disable_depth > 0). +* Fall through without a manager reference. +*/ + + ret =pm_runtime_resume_and_get (&slave->dev);if (ret <0 && ret != -EACCES ) {dev_err (&slave->dev,"Failed to resume device: %d\n" , ret); -pm_runtime_put_noidle (&slave->dev); -return ret; + goto mgr_put; } +if (ret >=0 ) + have_pm_ref = true; +/* +* ret == -EACCES: PM is disabled on slave; fall through without a +* slave reference, consistent with the original -EACCES exemption. +*/ /* Read Intstat 1, Intstat 2 and Intstat 3 registers */ ret =sdw_read_no_pm (slave,SDW_SCP_INT1 );
@@ -1861,8 +1898,13 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)dev_warn (&slave->dev,"Reached MAX_RETRY on alert read\n" ); io_err: -pm_runtime_mark_last_busy (&slave->dev); -pm_runtime_put_autosuspend (&slave->dev); +if (have_pm_ref) { +pm_runtime_mark_last_busy (&slave->dev); +pm_runtime_put_autosuspend (&slave->dev); + } +mgr_put: +if (have_mgr_ref) +pm_runtime_put (mgr_dev);return ret; }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v9 24/24] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] soundwire: bus: sdw_handle_slave_alerts() drops alerts during manager resume - [Medium] soundwire…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] soundwire: bus: sdw_handle_slave_alerts() drops alerts during manager resume
- [Medium] soundwire: bus: unserviced alert in sdw_handle_slave_alerts() on suspend race
--
commit ce0ecb1363ee793ca8d8a1d1cf6efec9d612e28a
Author: Vijendar Mukunda <[email protected]>
soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
This commit uses pm_runtime_get_if_active() on the parent manager device in sdw_handle_slave_alerts() before calling pm_runtime_resume_and_get() on the slave device to avoid a runtime PM deadlock with the manager's runtime_suspend callback.
Quoted 27 lines
drivers/soundwire/bus.c +15
-1@@ -1667,15 +1667,52 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)u8 buf, buf2[2 ];bool parity_check;bool parity_quirk; +bool have_pm_ref = false; +bool have_mgr_ref = false; +struct device *mgr_dev = slave->bus->dev->parent;sdw_modify_slave_status (slave,SDW_SLAVE_ALERT ); - ret =pm_runtime_get_sync (&slave->dev); + ret =pm_runtime_get_if_active (mgr_dev); +if (ret ==0 ) { +/* +* Manager is not RPM_ACTIVE; slave is already RPM_SUSPENDED +* by PM ordering. Return early to avoid I/O on inaccessible +* hardware and to prevent a deadlock: if the manager is in +* RPM_SUSPENDING, its runtime_suspend callback may be blocked +* in cancel_work_sync() waiting for this work, while this work +* would block in pm_runtime_resume_and_get() waiting for the +* manager to complete its suspend. +* +* When the SoundWire link enters clock-stop mode, the MIPI
drivers/soundwire/bus.c static int sdw_handle_slave_alerts(struct sdw_slave *slave) · line 1697
Quoted 10 lines
drivers/soundwire/bus.c +10
-0+* SoundWire spec guarantees the peripheral re-asserts the +* alert after clock resume, so the interrupt is deferred +* rather than dropped. When the link fully powers off +* (e.g. D3 or equivalent), the peripheral loses power and +* its alert state does not survive; the early return is +* harmless. +*/ +dev_dbg (&slave->dev,"Alert deferred: manager not active\n" ); +return 0 ; + }
[Severity: High]
Can this early return drop peripheral alerts when mgr_dev is in RPM_RESUMING?
pm_runtime_get_if_active(mgr_dev) returns 0 whenever mgr_dev->power.runtime_status != RPM_ACTIVE, including when mgr_dev is in RPM_RESUMING. All in-tree manager drivers restart the SoundWire clock and enable peripheral interrupts inside their runtime_resume callbacks while mgr_dev is still in RPM_RESUMING (for example, intel_start_bus_after_clock_stop() restarts the clock, calls sdw_cdns_enable_interrupt(), and then sleeps in sdw_cdns_check_self_clearing_bits()).
CPU0 CPU1 (kworker)rpm_resume(mgr_dev)
mgr_dev->power.runtime_status = RPM_RESUMING intel_resume_runtime()
intel_start_bus_after_clock_stop()
sdw_cdns_clock_restart()
sdw_cdns_enable_interrupt()
<peripheral alert IRQ>
cdns_update_slave_status_work()
clear CDNS_MCP_SLAVE_INTSTAT0/1 sdw_handle_slave_status()
sdw_handle_slave_alerts()
pm_runtime_get_if_active(...) return 0 <-- alert not cleared
sdw_cdns_check_self_clearing_bits()
mgr_dev->power.runtime_status = RPM_ACTIVE
Similarly, in amd_sdw_irq_thread(), a wake event and a peripheral status change arriving together queue an asynchronous pm_request_resume(mgr_dev), schedule amd_sdw_work, and clear ACP_SW_STATE_CHANGE_STATUS_0TO7/8TO11 while mgr_dev is still RPM_SUSPENDED or RPM_RESUMING.
Because the manager status-change interrupt registers have already been cleared and the clock is running, returning without clearing SDW_SCP_INT1 leaves the peripheral continuously reporting SDW_SLAVE_ALERT in PING frames with no new ATTACHED-to-ALERT edge to re-trigger the manager interrupt once mgr_dev reaches RPM_ACTIVE.
[Severity: Medium]
When mgr_dev is in RPM_SUSPENDING and sdw_handle_slave_alerts() returns 0 here to avoid the cancel_work_sync() deadlock, what will resume the manager to service the deferred alert?
Without calling pm_request_resume(mgr_dev) (or pm_request_resume(&slave->dev)) before returning, mgr_dev->power.deferred_resume remains false in rpm_suspend(). Once cancel_work_sync() finishes, the manager stops the SoundWire clock and enters RPM_SUSPENDED. A peripheral can only re-assert its alert in PING frames after the clock resumes, so if nothing triggers a runtime resume (for example, on a non-wake-capable peripheral), the manager stays suspended and the alert goes unserviced; in AMD_SDW_POWER_OFF_MODE or SDW_INTEL_CLK_STOP_BUS_RESET, only the manager controller powers down while external codec peripherals remain powered, and the later bus reset on manager resume clears the peripheral's SCP interrupt state.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
Re: [PATCH v9 24/24] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts()
Quoted 50 lines · On 11/24/26 14:57, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] soundwire: bus:sdw_handle_slave_alerts()drops alerts during manager resume
- [Medium] soundwire: bus: unserviced alert insdw_handle_slave_alerts()on suspend race
--commit
ce0ecb1363ee793ca8d8a1d1cf6efec9d612e28a
Author: Vijendar Mukunda <[email protected]>soundwire: bus: use
pm_runtime_get_if_active()insdw_handle_slave_alerts()This commit uses
pm_runtime_get_if_active()on the parent manager device insdw_handle_slave_alerts()before callingpm_runtime_resume_and_get()on the slave device to avoid a runtime PM deadlock with the manager'sruntime_suspendcallback.Quoted 32 lines
drivers/soundwire/bus.c +20
-1@@ -1667,15 +1667,52 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)u8 buf, buf2[2 ];bool parity_check;bool parity_quirk; +bool have_pm_ref = false; +bool have_mgr_ref = false; +struct device *mgr_dev = slave->bus->dev->parent;sdw_modify_slave_status (slave,SDW_SLAVE_ALERT ); - ret =pm_runtime_get_sync (&slave->dev); + ret =pm_runtime_get_if_active (mgr_dev); +if (ret ==0 ) { +/* +* Manager is not RPM_ACTIVE; slave is already RPM_SUSPENDED +* by PM ordering. Return early to avoid I/O on inaccessible +* hardware and to prevent a deadlock: if the manager is in +* RPM_SUSPENDING, its runtime_suspend callback may be blocked +* in cancel_work_sync() waiting for this work, while this work +* would block in pm_runtime_resume_and_get() waiting for the +* manager to complete its suspend. +* +* When the SoundWire link enters clock-stop mode, the MIPI +* SoundWire spec guarantees the peripheral re-asserts the +* alert after clock resume, so the interrupt is deferred +* rather than dropped. When the link fully powers off +* (e.g. D3 or equivalent), the peripheral loses power and +* its alert state does not survive; the early return is
Quoted 8 lines
drivers/soundwire/bus.c static int sdw_handle_slave_alerts(struct sdw_slave *slave) · line 1697
Quoted 5 lines
drivers/soundwire/bus.c +5
-0+* harmless. +*/ +dev_dbg (&slave->dev,"Alert deferred: manager not active\n" ); +return 0 ; + }[Severity: High]
Can this early return drop peripheral alerts whenmgr_devis inRPM_RESUMING?
Agreed. The commit comment's assumption "slave is already RPM_SUSPENDED by PM ordering" does not hold when mgr_dev is in RPM_RESUMING — the manager's runtime_resume callback has already restarted the clock and enabled interrupts at that point, so the peripheral can assert an alert. The early return must be restricted to RPM_SUSPENDED and RPM_SUSPENDING only. When mgr_dev is in RPM_RESUMING the clock is running and the alert should be serviced. Will fix it and respin the series.
Quoted 38 lines
pm_runtime_get_if_active(mgr_dev)returns 0 whenevermgr_dev->power.runtime_status!=RPM_ACTIVE, including whenmgr_devis inRPM_RESUMING. All in-tree manager drivers restart the SoundWire clock and enable peripheral interrupts inside theirruntime_resumecallbacks whilemgr_devis still inRPM_RESUMING(for example,intel_start_bus_after_clock_stop()restarts the clock, callssdw_cdns_enable_interrupt(), and then sleeps insdw_cdns_check_self_clearing_bits()).CPU0 CPU1 (kworker)
rpm_resume(mgr_dev)
mgr_dev->power.runtime_status=RPM_RESUMINGintel_resume_runtime()
intel_start_bus_after_clock_stop()
sdw_cdns_clock_restart()
sdw_cdns_enable_interrupt()
<peripheral alert IRQ>
cdns_update_slave_status_work()
clear CDNS_MCP_SLAVE_INTSTAT0/1sdw_handle_slave_status()
sdw_handle_slave_alerts()
pm_runtime_get_if_active(...)return 0 <-- alert not cleared
sdw_cdns_check_self_clearing_bits()
mgr_dev->power.runtime_status=RPM_ACTIVESimilarly, in
amd_sdw_irq_thread(), a wake event and a peripheral status change arriving together queue an asynchronouspm_request_resume(mgr_dev), scheduleamd_sdw_work, and clear ACP_SW_STATE_CHANGE_STATUS_0TO7/8TO11 whilemgr_devis stillRPM_SUSPENDEDorRPM_RESUMING.Because the manager status-change interrupt registers have already been cleared and the clock is running, returning without clearing
SDW_SCP_INT1leaves the peripheral continuously reportingSDW_SLAVE_ALERTin PING frames with no new ATTACHED-to-ALERT edge to re-trigger the manager interrupt oncemgr_devreachesRPM_ACTIVE.
Quoted 4 lines
[Severity: Medium]
Whenmgr_devis inRPM_SUSPENDINGandsdw_handle_slave_alerts()returns 0 here to avoid thecancel_work_sync()deadlock, what will resume the manager to service the deferred alert?
Agreed. For CLK_STOP_MODE without bus reset the peripheral retains its SCP state across the clock stop, and without pm_request_resume(&slave->dev) a non-wake-capable peripheral has no path to trigger a resume and the deferred alert goes unserviced. Already addressed in the fixup:pm_request_resume(&slave->dev) is added before the early return. will fix it.
Quoted 12 lines
Without calling
pm_request_resume(mgr_dev)(orpm_request_resume(&slave->dev)) before returning,mgr_dev->power.deferred_resumeremains false inrpm_suspend(). Oncecancel_work_sync()finishes, the manager stops the SoundWire clock and entersRPM_SUSPENDED. A peripheral can only re-assert its alert in PING frames after the clock resumes, so if nothing triggers a runtime resume (for example, on a non-wake-capable peripheral), the manager stays suspended and the alert goes unserviced; inAMD_SDW_POWER_OFF_MODEorSDW_INTEL_CLK_STOP_BUS_RESET, only the manager controller powers down while external codec peripherals remain powered, and the later bus reset on manager resume clears the peripheral's SCP interrupt state.