* [PATCH 0/2] soundwire: qcom: fix WCD AHB serialization and wr_fifo_depth init order
@ 2026-11-24 22:46 Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 1/2] soundwire: qcom: serialize WCD AHB bridge transactions Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 2/2] soundwire: qcom: populate wr_fifo_depth before enabling interrupts Robert Ijtsma via B4 Relay
0 siblings, 2 replies; 4+ messages in thread
From: Robert Ijtsma via B4 Relay @ 2026-11-24 22:46 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Robert Ijtsma
Fix two race conditions observed on WCD934x-hosted Qualcomm SoundWire
controllers (such as on Microsoft Surface Pro X / SC8180X):
1. Serialize each two-step WCD AHB bridge register access (RD_ADDR +
RD_DATA or WR_DATA + WR_ADDR) with a controller mutex so concurrent
IRQ and init/bus accesses cannot interleave on the shared bridge
registers.
2. Read and validate SWRM_COMP_PARAMS write FIFO depth before
registering the threaded IRQ in probe and before enabling CPU
interrupts in qcom_swrm_init(), avoiding false write-FIFO overflow
errors while wr_fifo_depth is still zero.
Tested on Microsoft Surface Pro X SQ2 (SC8180X, WCD934x + WSA881x).
Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
---
Robert Ijtsma (2):
soundwire: qcom: serialize WCD AHB bridge transactions
soundwire: qcom: populate wr_fifo_depth before enabling interrupts
drivers/soundwire/qcom.c | 57 ++++++++++++++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 19 deletions(-)
---
base-commit: 4843f6873f7c4835e62f2c73ba0fd538e57a2f22
change-id: 20261124-qcom-soundwire-fixes-9d31c8dc5303
Best regards,
--
Robert Ijtsma <robertijtsma@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] soundwire: qcom: serialize WCD AHB bridge transactions
2026-11-24 22:46 [PATCH 0/2] soundwire: qcom: fix WCD AHB serialization and wr_fifo_depth init order Robert Ijtsma via B4 Relay
@ 2026-11-24 22:46 ` Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 2/2] soundwire: qcom: populate wr_fifo_depth before enabling interrupts Robert Ijtsma via B4 Relay
1 sibling, 0 replies; 4+ messages in thread
From: Robert Ijtsma via B4 Relay @ 2026-11-24 22:46 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Robert Ijtsma
From: Robert Ijtsma <robertijtsma@gmail.com>
On SLIMbus-hosted WCD934x Qualcomm SoundWire controllers, each AHB
bridge register access spans two separate regmap_bulk_*() transfers
(SWRM_AHB_BRIDGE_RD_ADDR_0 followed by SWRM_AHB_BRIDGE_RD_DATA_0, or
SWRM_AHB_BRIDGE_WR_DATA_0 followed by SWRM_AHB_BRIDGE_WR_ADDR_0).
Without controller-level serialization across each pair, concurrent
accesses from the threaded IRQ handler and bus/init callers can
interleave on the shared AHB bridge registers and corrupt reads or
writes.
Add ahb_lock to struct qcom_swrm_ctrl to serialize each two-step AHB
bridge register transaction.
Fixes: 02efb49aa805 ("soundwire: qcom: add support for SoundWire controller")
Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
---
drivers/soundwire/qcom.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index c31d921..368f511 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -202,6 +202,8 @@ struct qcom_swrm_ctrl {
struct completion enumeration;
/* Port alloc/free lock */
struct mutex port_lock;
+ /* Serialize two-step WCD AHB bridge address/data accesses */
+ struct mutex ahb_lock;
struct clk *hclk;
int irq;
u32 ee;
@@ -388,18 +390,18 @@ static int qcom_swrm_ahb_reg_read(struct qcom_swrm_ctrl *ctrl, int reg,
struct regmap *wcd_regmap = ctrl->regmap;
int ret;
+ mutex_lock(&ctrl->ahb_lock);
/* pg register + offset */
ret = regmap_bulk_write(wcd_regmap, SWRM_AHB_BRIDGE_RD_ADDR_0,
- (u8 *)®, 4);
+ (u8 *)®, 4);
if (ret < 0)
- return SDW_CMD_FAIL;
+ goto out;
ret = regmap_bulk_read(wcd_regmap, SWRM_AHB_BRIDGE_RD_DATA_0,
val, 4);
- if (ret < 0)
- return SDW_CMD_FAIL;
-
- return SDW_CMD_OK;
+out:
+ mutex_unlock(&ctrl->ahb_lock);
+ return ret < 0 ? SDW_CMD_FAIL : SDW_CMD_OK;
}
static int qcom_swrm_ahb_reg_write(struct qcom_swrm_ctrl *ctrl,
@@ -407,19 +409,20 @@ static int qcom_swrm_ahb_reg_write(struct qcom_swrm_ctrl *ctrl,
{
struct regmap *wcd_regmap = ctrl->regmap;
int ret;
+
+ mutex_lock(&ctrl->ahb_lock);
/* pg register + offset */
ret = regmap_bulk_write(wcd_regmap, SWRM_AHB_BRIDGE_WR_DATA_0,
- (u8 *)&val, 4);
+ (u8 *)&val, 4);
if (ret)
- return SDW_CMD_FAIL;
+ goto out;
/* write address register */
ret = regmap_bulk_write(wcd_regmap, SWRM_AHB_BRIDGE_WR_ADDR_0,
- (u8 *)®, 4);
- if (ret)
- return SDW_CMD_FAIL;
-
- return SDW_CMD_OK;
+ (u8 *)®, 4);
+out:
+ mutex_unlock(&ctrl->ahb_lock);
+ return ret ? SDW_CMD_FAIL : SDW_CMD_OK;
}
static int qcom_swrm_cpu_reg_read(struct qcom_swrm_ctrl *ctrl, int reg,
@@ -1680,6 +1683,7 @@ static int qcom_swrm_probe(struct platform_device *pdev)
ctrl->dev = dev;
dev_set_drvdata(&pdev->dev, ctrl);
mutex_init(&ctrl->port_lock);
+ mutex_init(&ctrl->ahb_lock);
init_completion(&ctrl->broadcast);
init_completion(&ctrl->enumeration);
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] soundwire: qcom: populate wr_fifo_depth before enabling interrupts
2026-11-24 22:46 [PATCH 0/2] soundwire: qcom: fix WCD AHB serialization and wr_fifo_depth init order Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 1/2] soundwire: qcom: serialize WCD AHB bridge transactions Robert Ijtsma via B4 Relay
@ 2026-11-24 22:46 ` Robert Ijtsma via B4 Relay
2026-11-24 22:54 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Robert Ijtsma via B4 Relay @ 2026-11-24 22:46 UTC (permalink / raw)
To: Srinivas Kandagatla, Vinod Koul, Bard Liao, Pierre-Louis Bossart
Cc: linux-arm-msm, linux-sound, Robert Ijtsma
From: Robert Ijtsma <robertijtsma@gmail.com>
ctrl->wr_fifo_depth is currently populated at the end of
qcom_swrm_init(), after devm_request_threaded_irq() in qcom_swrm_probe()
and after enabling CPU interrupts in qcom_swrm_init().
If a SoundWire interrupt fires before SWRM_COMP_PARAMS has been read,
qcom_swrm_cmd_fifo_wr_cmd() observes ctrl->wr_fifo_depth == 0 and fails
with -EIO ("err write overflow").
Read and validate SWRM_COMP_PARAMS in qcom_swrm_probe() prior to
requesting the threaded IRQ, and read SWRM_COMP_PARAMS before enabling
CPU interrupts in qcom_swrm_init().
Fixes: 02efb49aa805 ("soundwire: qcom: add support for SoundWire controller")
Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
---
drivers/soundwire/qcom.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index 368f511..3a42ab8 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -997,6 +997,12 @@ static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl)
ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CLEAR],
0xFFFFFFFF);
+ ctrl->reg_read(ctrl, SWRM_COMP_PARAMS, &val);
+ if (ctrl->version >= SWRM_VERSION_3_1_0)
+ ctrl->wr_fifo_depth = FIELD_GET(SWRM_V3_COMP_PARAMS_WR_FIFO_DEPTH, val);
+ else
+ ctrl->wr_fifo_depth = FIELD_GET(SWRM_COMP_PARAMS_WR_FIFO_DEPTH, val);
+
/* enable CPU IRQs for the selected EE window */
ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CPU_EN],
SWRM_INTERRUPT_STATUS_RMSK);
@@ -1008,12 +1014,6 @@ static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl)
swrm_wait_for_frame_gen_enabled(ctrl);
ctrl->slave_status = 0;
- ctrl->reg_read(ctrl, SWRM_COMP_PARAMS, &val);
-
- if (ctrl->version >= SWRM_VERSION_3_1_0)
- ctrl->wr_fifo_depth = FIELD_GET(SWRM_V3_COMP_PARAMS_WR_FIFO_DEPTH, val);
- else
- ctrl->wr_fifo_depth = FIELD_GET(SWRM_COMP_PARAMS_WR_FIFO_DEPTH, val);
return 0;
}
@@ -1717,6 +1717,21 @@ static int qcom_swrm_probe(struct platform_device *pdev)
ctrl->reg_read(ctrl, SWRM_COMP_HW_VERSION, &ctrl->version);
qcom_swrm_set_ee_register_layout(ctrl, data);
+ ret = ctrl->reg_read(ctrl, SWRM_COMP_PARAMS, &val);
+ if (ret != SDW_CMD_OK) {
+ ret = -EIO;
+ goto err_clk;
+ }
+ if (ctrl->version >= SWRM_VERSION_3_1_0)
+ ctrl->wr_fifo_depth = FIELD_GET(SWRM_V3_COMP_PARAMS_WR_FIFO_DEPTH, val);
+ else
+ ctrl->wr_fifo_depth = FIELD_GET(SWRM_COMP_PARAMS_WR_FIFO_DEPTH, val);
+ if (!ctrl->wr_fifo_depth) {
+ dev_err(dev, "Invalid write FIFO depth in SWRM_COMP_PARAMS: %#x\n", val);
+ ret = -EINVAL;
+ goto err_clk;
+ }
+
ret = devm_request_threaded_irq(dev, ctrl->irq, NULL,
qcom_swrm_irq_handler,
IRQF_TRIGGER_RISING |
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] soundwire: qcom: populate wr_fifo_depth before enabling interrupts
2026-11-24 22:46 ` [PATCH 2/2] soundwire: qcom: populate wr_fifo_depth before enabling interrupts Robert Ijtsma via B4 Relay
@ 2026-11-24 22:54 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-24 22:54 UTC (permalink / raw)
To: Robert Ijtsma; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] soundwire: qcom: Fixes trailer cites 02efb49aa805 instead of
a661308c34de
- [Low] soundwire: qcom: redundant unchecked SWRM_COMP_PARAMS read in
qcom_swrm_init()
--
commit 6cb5da021ef8535ab5b5f9bfc4e8100a46f9d35b
Author: Robert Ijtsma <robertijtsma@gmail.com>
> soundwire: qcom: populate wr_fifo_depth before enabling interrupts
>
> ctrl->wr_fifo_depth is currently populated at the end of
> qcom_swrm_init(), after devm_request_threaded_irq() in qcom_swrm_probe()
> and after enabling CPU interrupts in qcom_swrm_init().
>
> If a SoundWire interrupt fires before SWRM_COMP_PARAMS has been read,
> qcom_swrm_cmd_fifo_wr_cmd() observes ctrl->wr_fifo_depth == 0 and fails
> with -EIO ("err write overflow").
>
> Read and validate SWRM_COMP_PARAMS in qcom_swrm_probe() prior to
> requesting the threaded IRQ, and read SWRM_COMP_PARAMS before enabling
> CPU interrupts in qcom_swrm_init().
>
> Fixes: 02efb49aa805 ("soundwire: qcom: add support for SoundWire controller")
> Signed-off-by: Robert Ijtsma <robertijtsma@gmail.com>
[Severity: Low]
Should the Fixes: tag point to a661308c34de ("soundwire: qcom: wait for
fifo space to be available before read/write") instead of 02efb49aa805
("soundwire: qcom: add support for SoundWire controller")?
Commit a661308c34de ("soundwire: qcom: wait for fifo space to be available
before read/write") introduced ctrl->wr_fifo_depth, the SWRM_COMP_PARAMS
read at the end of qcom_swrm_init(), and swrm_wait_for_wr_fifo_avail() in
qcom_swrm_cmd_fifo_wr_cmd().
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index 368f511867835..3a42ab85be7c6 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -997,6 +997,12 @@ static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl)
> ctrl->reg_write(ctrl, ctrl->reg_layout[SWRM_REG_INTERRUPT_CLEAR],
> 0xFFFFFFFF);
>
> + ctrl->reg_read(ctrl, SWRM_COMP_PARAMS, &val);
> + if (ctrl->version >= SWRM_VERSION_3_1_0)
> + ctrl->wr_fifo_depth = FIELD_GET(SWRM_V3_COMP_PARAMS_WR_FIFO_DEPTH, val);
> + else
> + ctrl->wr_fifo_depth = FIELD_GET(SWRM_COMP_PARAMS_WR_FIFO_DEPTH, val);
> +
[Severity: Low]
Is re-reading SWRM_COMP_PARAMS in qcom_swrm_init() needed now that
qcom_swrm_probe() reads and validates ctrl->wr_fifo_depth before requesting
the IRQ or calling qcom_swrm_init()?
SWRM_COMP_PARAMS is a static capability register, and this second read does
not check the return status of ctrl->reg_read(). If a transient regmap
read error occurs during controller initialization or runtime resume, val
retains the value previously read from SWRM_MCP_CFG_ADDR and overwrites the
validated ctrl->wr_fifo_depth with 0, causing later command FIFO writes to
fail with -EIO.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-qcom-soundwire-fixes-v1-0-8ca94d60ddd6@gmail.com?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 22:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 22:46 [PATCH 0/2] soundwire: qcom: fix WCD AHB serialization and wr_fifo_depth init order Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 1/2] soundwire: qcom: serialize WCD AHB bridge transactions Robert Ijtsma via B4 Relay
2026-11-24 22:46 ` [PATCH 2/2] soundwire: qcom: populate wr_fifo_depth before enabling interrupts Robert Ijtsma via B4 Relay
2026-11-24 22:54 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox