From: sashiko-bot@kernel.org
To: "Ajay Kumar Nandam" <ajay.nandam@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe
Date: Thu, 03 Dec 2026 08:08:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-247338@kernel.org> (raw)
In-Reply-To: <20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-4-046ce68c8b0e@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] soundwire: qcom: swrm_reconcile_slaves() clobbers
ctrl->slave_status
- [High] soundwire: qcom: missing clock_stop_not_supported update on
reconcile
- [Medium] soundwire: qcom: swrm_reconcile_slaves() skips alerting
peripherals
- [Medium] soundwire: qcom: swrm_reconcile_slaves() may assign duplicate
dev_num
- [Low] soundwire: qcom: redundant reads and checks in
swrm_reconcile_slaves()
- [Low] soundwire: qcom: missing break on FIFO read error in
swrm_reconcile_slaves()
- [Low] soundwire: qcom: swrm_reconcile_slaves() reads DevIDs of
already-bound slaves
--
commit b4c7c081a46d27523980bc34cc988e2f4829cddd
Author: Ajay Kumar Nandam <ajay.nandam@oss.qualcomm.com>
soundwire: qcom: reconcile a retained peripheral after controller re-probe
This commit adds swrm_reconcile_slaves() to scan attached device-number
slots after the enumeration wait in qcom_swrm_probe() and bind any
uniquely matching unbound peripheral that retained its device number
across a controller re-probe. It disables ctrl->irq while reconciling
slot state.
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index b1656412ffab1..95d3e4ecd2a9c 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -772,6 +772,73 @@ static int qcom_swrm_enumerate(struct sdw_bus *bus)
> return 0;
> }
>
> +/* Caller must disable the status IRQ while updating slot state. */
> +static void swrm_reconcile_slaves(struct qcom_swrm_ctrl *ctrl)
> +{
> + struct sdw_bus *bus = &ctrl->bus;
> + u32 slv_status_raw = 0;
> + int i;
> +
> + ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &slv_status_raw);
> +
> + for (i = 1; i <= SDW_MAX_DEVICES; i++) {
> + u32 slot_status = (slv_status_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) &
> + SWRM_MCP_SLV_STATUS_MASK;
> + u8 buf[SDW_NUM_DEV_ID_REGISTERS] = {0};
> + struct sdw_slave *slave, *match = NULL;
> + struct sdw_slave_id id;
> + int nmatch = 0, n, all_ok = 1;
> + u32 recheck_raw = 0, recheck_slot;
> + u64 addr;
> +
> + if (slot_status != SDW_SLAVE_ATTACHED)
> + continue;
[Severity: Medium]
Can a retained peripheral reporting SDW_SLAVE_ALERT be skipped here and
left permanently unbound?
Unlike a freshly reset peripheral, one that stayed attached across a
controller re-probe keeps its previously programmed SDW_SCP_INTMASK1
(for example bus clash and parity enabled by wsa881x_probe()). If an
interrupt latches during an ADSP restart, SWRM_MCP_SLV_STATUS reports
SDW_SLAVE_ALERT instead of SDW_SLAVE_ATTACHED, so this check, the
recheck below, and qcom_swrm_set_slave_dev_num() all skip it.
Once enable_irq() runs, sdw_handle_slave_status() ignores unassigned
slots, so the alert is never cleared and the peripheral never returns
to SDW_SLAVE_ATTACHED.
> +
> + mutex_lock(&bus->msg_lock);
> + for (n = 0; n < SDW_NUM_DEV_ID_REGISTERS; n++) {
> + if (qcom_swrm_cmd_fifo_rd_cmd(ctrl, i, SDW_SCP_DEVID_0 + n,
> + 1, &buf[n]) != SDW_CMD_OK)
> + all_ok = 0;
> + }
> + mutex_unlock(&bus->msg_lock);
> + if (!all_ok)
> + continue;
[Severity: Low]
Does this execute six sleeping FIFO reads for every already-bound
peripheral on normal boots?
Each qcom_swrm_cmd_fifo_rd_cmd() sleeps at least 350 us via
usleep_range(), adding over 2 ms per already-bound peripheral across
synchronous controller probes while ctrl->irq is disabled, only to
discard the result below. Checking up front whether bus->slaves has
any unbound entry, and skipping slots already owned by a slave's
dev_num, would avoid this bus I/O when enumeration already succeeded.
[Severity: Low]
Should this loop break on the first qcom_swrm_cmd_fifo_rd_cmd() failure?
Because !all_ok discards buf[] right after unlocking bus->msg_lock,
continuing issues up to five extra failing reads. On a read FIFO
underflow, swrm_wait_for_rd_fifo_avail() sleeps ~15.5 ms per call,
turning one timeout into ~95 ms per failing slot with ctrl->irq
disabled.
[ ... ]
> + if (!(match->dev_num == 0 && match->status == SDW_SLAVE_UNATTACHED))
> + continue;
> +
> + /* Re-check the slot after the SCP reads. */
> + ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &recheck_raw);
> + recheck_slot = (recheck_raw >> (i * SWRM_MCP_SLV_STATUS_SZ)) &
> + SWRM_MCP_SLV_STATUS_MASK;
> + if (recheck_slot != SDW_SLAVE_ATTACHED ||
> + match->dev_num != 0 ||
> + match->status != SDW_SLAVE_UNATTACHED)
> + continue;
[Severity: Low]
Are the match->dev_num and match->status checks here redundant?
The same condition was just verified above with only ctrl->reg_read()
in between while ctrl->irq is disabled, so nothing can mutate those
fields here. Skipping already-bound slots before the FIFO reads and
breaking on the first read error would also avoid redundant bus traffic
and repeated error logs.
> +
> + qcom_swrm_set_slave_dev_num(bus, match, i);
[Severity: Medium]
Can this assign a duplicate dev_num if another slave in bus->slaves
already owns slot i?
When a peripheral detaches, sdw_modify_slave_status() marks it
SDW_SLAVE_UNATTACHED without clearing its dev_num. If slave A attached
on slot i during the enumeration wait, detached, and hardware
auto-enumeration reused slot i for unbound slave B before
reconciliation, this assigns dev_num = i to slave B as well.
Because sdw_get_slave() returns the first matching entry in
bus->slaves, subsequent status transitions, alerts, and initialization
for slot i are misdirected to slave A while slave B remains stuck
unattached. Checking whether any slave in bus->slaves already has
dev_num == i before binding would prevent this.
[Severity: High]
Does binding match here miss updating ctrl->clock_stop_not_supported?
In qcom_swrm_enumerate(), binding a slave with prop.clk_stop_mode1 set
(such as wsa881x_probe()) sets ctrl->clock_stop_not_supported = true.
Leaving it false here causes swrm_runtime_suspend() and
swrm_runtime_resume() to run SoundWire clock-stop sequences instead of
performing SWRM_COMP_SW_RESET and re-initializing the controller when
the 3-second autosuspend timer fires.
> + qcom_swrm_get_device_status(ctrl);
> + sdw_handle_slave_status(&ctrl->bus, ctrl->status);
[Severity: High]
Can calling qcom_swrm_get_device_status() here clobber
ctrl->slave_status and drop attach events for other peripherals on the
bus?
swrm_reconcile_slaves() snapshots SWRM_MCP_SLV_STATUS once before the
loop and runs with ctrl->irq disabled, so another peripheral on slot j
can finish attaching during the SCP DevID reads:
CPU0 (probe) Hardware / IRQ
qcom_swrm_probe()
disable_irq(ctrl->irq)
swrm_reconcile_slaves()
read SWRM_MCP_SLV_STATUS
(slot i attached,
slot j unattached)
SCP DevID reads on slot i
slot j attaches, IRQ pending
qcom_swrm_set_slave_dev_num(match, i)
qcom_swrm_get_device_status()
ctrl->slave_status = live <-- absorbs slot j = ATTACHED
sdw_handle_slave_status() <-- skips unassigned slot j
enable_irq(ctrl->irq)
qcom_swrm_irq_handler()
ctrl->slave_status == live
skips qcom_swrm_enumerate()
When enable_irq() delivers the pending attach interrupt,
qcom_swrm_irq_handler() sees ctrl->slave_status == slave_status, skips
qcom_swrm_enumerate(), and leaves peripheral j permanently unbound.
Calling sdw_handle_slave_status() inside the loop also re-invokes
sdw_update_slave_status() on every already-attached slave for each
reconciled slot.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-ak-gt-soundwire-qcom-mmrole-rework-v1-0-046ce68c8b0e@oss.qualcomm.com?part=4
prev parent reply other threads:[~2026-12-03 8:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 7:41 [PATCH 0/4] soundwire: qcom: controller lifecycle fixes on unbind/reprobe Ajay Kumar Nandam
2026-12-03 7:41 ` [PATCH 1/4] soundwire: qcom: don't touch registers when the iface clock is not live Ajay Kumar Nandam
2026-12-03 8:09 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 2/4] soundwire: qcom: disable runtime PM on controller unbind Ajay Kumar Nandam
2026-12-03 8:08 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 3/4] soundwire: qcom: dispose IRQ mappings " Ajay Kumar Nandam
2026-12-03 7:55 ` sashiko-bot
2026-12-03 7:41 ` [PATCH 4/4] soundwire: qcom: reconcile a retained peripheral after controller re-probe Ajay Kumar Nandam
2026-12-03 8:08 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-247338@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ajay.nandam@oss.qualcomm.com \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox