Skip to content

ASoC/soundwire: Intel: avoid transfer timed out in module unload - #4833

Closed
bardliao wants to merge 2 commits into
thesofproject:topic/sof-devfrom
bardliao:fix-remove-issue
Closed

bardliao wants to merge 2 commits into
thesofproject:topic/sof-devfrom
bardliao:fix-remove-issue

Conversation

@bardliao

Copy link
Copy Markdown
Collaborator

SOF runtime resume will resume the sdw link if a wake is detected by the codec. And we simply assume there is wakes when we check HDadio WAKEEN/WAKESTS. It is harmless. But we will get sdw transfer timed out if the SOF runtime resume is triggered by module unload. That is because codecs will be attached when the sdw link is powered up, and the sdw link will no longer work after the link device is unloaded.
The PR disable the sdw interrupt after sdw_intel_exit() to allow codec driver initialize the codec in the attached state. Also, disable Peripherals' runtime PM to prevent Peripherals from being resume in the link device unregistering process.

Fixes: #4809

Codecs may need to access sdw registers via sdw bus in the exit process.
Disabling sdw interrupt will block sdw IO transfer.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Peripherals are not able to access the sdw link after the link device
is unregistered. Disable pm runtime to precent the peripheral from
being resume.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really getting the suggested fixes @bardliao

Comment thread sound/soc/sof/intel/hda.c
sdw_intel_exit(hdev->sdw);
hdev->sdw = NULL;

hda_sdw_int_enable(sdev, false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we give an example of when "Codecs may need to access sdw registers via sdw bus in the exit process".

I don't fully buy the argument. IIRC the initial code was intentional so that we wouldn't have ANY interrupts while removing the devices.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we give an example of when "Codecs may need to access sdw registers via sdw bus in the exit process".

When we run sudo modprobe -r snd_sof_pci_intel_lnl, snd_sof_runtime_resume will be trigger first. And hda_sdw_process_wakeen will be called when dsp boot. Due to intel_shim_check_wake return 1 unconditionally, soundwire_intel.links will be powered up. And the codecs will be attached.
SCP Msg trf timed out will happen if hda_sdw_exit is called before codec is initialized, and SDW interrupt is disabled.

Please see the log in detail.
lnl_remove.txt

I don't fully buy the argument. IIRC the initial code was intentional so that we wouldn't have ANY interrupts while removing the devices.

I agree that we don't want any interrupts while removing the devices. However, the interrupts are also used in sdw commend transfer. Can we cancel the sdw commend transfer before disabling SDW interrupt?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart Alternative solution #4838. Instead of canceling the sdw commend, #4838 wait for them be finished.

*/
list_for_each_entry(slave, &ldev->link_res.cdns->bus.slaves, node)
pm_runtime_disable(&slave->dev);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really needed? We already disable pm_runtime in codec drivers, e.g.

static int rt711_sdca_sdw_remove(struct sdw_slave *slave)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really needed? We already disable pm_runtime in codec drivers, e.g.

static int rt711_sdca_sdw_remove(struct sdw_slave *slave)

The resume runtime is called before codec drivers being removed. So, disabling it in the .remove function is too late.

@plbossart plbossart Feb 24, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bardliao alternatively you could do something like we do in the .prepare step:

ret = device_for_each_child(bus->dev, NULL, intel_resume_child_device);

But we would need a pm_runtime_resume() which would wait for the devices to be fully resumed (I don't recall why we didn't do this for .prepare).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bardliao alternatively you could do something like we do in the .prepare step:

ret = device_for_each_child(bus->dev, NULL, intel_resume_child_device);

But we would need a pm_runtime_resume() which would wait for the devices to be fully resumed (I don't recall why we didn't do this for .prepare).

Let me study this.

@plbossart

Copy link
Copy Markdown
Member

"
When we run sudo modprobe -r snd_sof_pci_intel_lnl, snd_sof_runtime_resume will be trigger first. And hda_sdw_process_wakeen will be called when dsp boot. Due to intel_shim_check_wake return 1 unconditionally, soundwire_intel.links will be powered up. And the codecs will be attached.
"

ok, so now I am starting to get the issue. But I guess we already had the issue before the change to power-up the links unconditionally. If a device has a wake event just during the remove we could also hit the same issue.

@bardliao

Copy link
Copy Markdown
Collaborator Author

" When we run sudo modprobe -r snd_sof_pci_intel_lnl, snd_sof_runtime_resume will be trigger first. And hda_sdw_process_wakeen will be called when dsp boot. Due to intel_shim_check_wake return 1 unconditionally, soundwire_intel.links will be powered up. And the codecs will be attached. "

ok, so now I am starting to get the issue. But I guess we already had the issue before the change to power-up the links unconditionally. If a device has a wake event just during the remove we could also hit the same issue.

Exactly, we will get the issue if a device happen to has a wake event during the remove .

@bardliao

Copy link
Copy Markdown
Collaborator Author

replaced by #4838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SoundWire: transfer timed out in suspend-resume-without-audio

2 participants