Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: dma: dma_dw_common: Disable channel even if draining times out #68621

Conversation

ujfalusi
Copy link
Collaborator

@ujfalusi ujfalusi commented Feb 6, 2024

If the channel suspend with draining fails on stop because of reasons outside of the scope of the DMA driver (the peripheral is powered off before trying to drain for example) we must continue and disable the channel.

The channel can be released by the client despite of it remained enabled. A new DMA channel request can pick the channel (as it is released) but re-configuration is going to be skipped and the use of the channel is going to fail. Then we will see the same drain timeout on channel stop again since the channel retained the configuration which resulted the first timeout.

The drain timeout was made fatal by an earlier commit which fixed the WAIT_FOR return value handling.

At the same time improve the warning and error prints for drain and disable timeout by including the DMA device name.

Fixes: 6226f9e ("dma: dw: fix the return value check")

@zephyrbot zephyrbot added the area: DMA Direct Memory Access label Feb 6, 2024
@zephyrbot zephyrbot requested a review from teburd February 6, 2024 11:51
@teburd
Copy link
Collaborator

teburd commented Feb 6, 2024

If we're powering off the peripheral before suspending the DMA channel, isn't that a bug that should be fixed seemingly? The rest makes good sense.

teburd
teburd previously approved these changes Feb 6, 2024
@ujfalusi
Copy link
Collaborator Author

ujfalusi commented Feb 6, 2024

If we're powering off the peripheral before suspending the DMA channel, isn't that a bug that should be fixed seemingly? The rest makes good sense.

If the peripheral is stopped later then there is a chance of underrun/overrun (tx/rx) since the DMA is not servicing the peripheral.
The underrun is more problematic in TX case as it is implementation specific what the hardware will do, it might keep sending the last word or sends all zero/one.
The stop really have only effect on streaming (audio) and if we want to stop it does not really matter what is not sent out from the FIFO of the DMA.

I would debate the existence of the drain instead ;)

@teburd
Copy link
Collaborator

teburd commented Feb 6, 2024

If we're powering off the peripheral before suspending the DMA channel, isn't that a bug that should be fixed seemingly? The rest makes good sense.

If the peripheral is stopped later then there is a chance of underrun/overrun (tx/rx) since the DMA is not servicing the peripheral. The underrun is more problematic in TX case as it is implementation specific what the hardware will do, it might keep sending the last word or sends all zero/one. The stop really have only effect on streaming (audio) and if we want to stop it does not really matter what is not sent out from the FIFO of the DMA.

I would debate the existence of the drain instead ;)

That’s a fair point! That behavior isn’t likely consistent across dmacs either I’d assume?

Copy link
Collaborator

@plbossart plbossart left a comment

Choose a reason for hiding this comment

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

nit-pick on logs below

return -ETIMEDOUT;
}
if (!fifo_empty)
LOG_WRN("%s channel %d drain time out", dev->name, channel);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Either you change the format of all logs or you follow the existing convention.

I see e.g. no reason why the logs on line 577 remain the same, that should be a separate patch anyways IMHO.

Copy link
Collaborator Author

@ujfalusi ujfalusi Feb 6, 2024

Choose a reason for hiding this comment

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

@plbossart, I have a separate patch for changing log prints, I did not want to include unrelated patches or changes in this PR.
I have changed these as these prints are for error and now warning and the original ones did not provided clue on the DMA from where the channel was used.
Like:
<inf> dma_dw_common: dw_dma_stop: dw_dma_stop: dma 0 channel drain time out
you would not have guessed which one would it be:
<inf> dma_dw_common: dw_dma_stop: dma@7c000 channel 0 drain time out
<inf> dma_dw_common: dw_dma_stop: dma@7d000 channel 0 drain time out

And for the line 577, I would convert that to LOG_INF(), add similar one to dw_dma_start().

Copy link
Collaborator

Choose a reason for hiding this comment

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

if there's a separate patch for logs, then let's move the format change in there. This patch should only deal with the subject, i.e. "Disable channel even if draining times out"

@teburd teburd added the bug The issue is a bug, or the PR is fixing a bug label Feb 6, 2024
@teburd teburd added this to the v3.6.0 milestone Feb 6, 2024
@ujfalusi ujfalusi force-pushed the peter/pr/dw_dma_disable_on_drain_timeout_01 branch from 7773c26 to e048f43 Compare February 7, 2024 06:51
@ujfalusi
Copy link
Collaborator Author

ujfalusi commented Feb 7, 2024

Changes since v1:

  • kept the uninformative log prints fro drain timeout and channel disable as requested by @plbossart

plbossart
plbossart previously approved these changes Feb 7, 2024
Copy link
Collaborator

@plbossart plbossart left a comment

Choose a reason for hiding this comment

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

Thanks @ujfalusi

LOG_ERR("%s: dma %d channel drain time out", __func__, channel);
return -ETIMEDOUT;
}
if (!fifo_empty)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this needs brackets in zephyr

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I always forget this, sorry.

@ujfalusi ujfalusi force-pushed the peter/pr/dw_dma_disable_on_drain_timeout_01 branch from e048f43 to f364cf4 Compare February 8, 2024 06:34
@ujfalusi
Copy link
Collaborator Author

ujfalusi commented Feb 8, 2024

Changes since v2:

  • Keep brackets around the if statement.
  • v2.1: (and keep the printed string intact)

@ujfalusi ujfalusi force-pushed the peter/pr/dw_dma_disable_on_drain_timeout_01 branch from f364cf4 to 893ba33 Compare February 8, 2024 06:38
If the channel suspend with draining fails on stop because of reasons
outside of the scope of the DMA driver (the peripheral is powered off
before trying to drain for example) we must continue and disable the
channel.

The channel can be released by the client despite of it remained enabled.
A new DMA channel request can pick the channel (as it is released) but
re-configuration is going to be skipped and the use of the channel is going
to fail. Then we will see the same drain timeout on channel stop again
since the channel retained the configuration which resulted the first
timeout.

The drain timeout was made fatal by an earlier commit which fixed the
WAIT_FOR return value handling.

Fixes: 6226f9e ("dma: dw: fix the return value check")
Signed-off-by: Peter Ujfalusi <[email protected]>
@kv2019i kv2019i added the platform: Intel ADSP Intel Audio platforms label Feb 8, 2024
@plbossart plbossart requested a review from teburd February 8, 2024 14:39
@henrikbrixandersen henrikbrixandersen merged commit 84631ce into zephyrproject-rtos:main Feb 8, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DMA Direct Memory Access bug The issue is a bug, or the PR is fixing a bug platform: Intel ADSP Intel Audio platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants