From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Richard Fitzgerald <rf@opensource.cirrus.com>, vkoul@kernel.org
Cc: alsa-devel@alsa-project.org, patches@opensource.cirrus.com,
linux-kernel@vger.kernel.org, sanyog.r.kale@intel.com,
yung-chuan.liao@linux.intel.com
Subject: Re: [PATCH 3/3] soundwire: cadence: Drain the RX FIFO after an IO timeout
Date: Thu, 1 Dec 2022 12:20:06 -0600 [thread overview]
Message-ID: <0f0fa03a-b7aa-6cdb-38b8-a09bf03f9efd@linux.intel.com> (raw)
In-Reply-To: <20221201134845.4055907-4-rf@opensource.cirrus.com>
On 12/1/22 07:48, Richard Fitzgerald wrote:
> If wait_for_completion_timeout() times-out in _cdns_xfer_msg() it
> is possible that something could have been written to the RX FIFO.
> In this case, we should drain the RX FIFO so that anything in it
> doesn't carry over and mess up the next transfer.
>
> Obviously, if we got to this state something went wrong, and we
> don't really know the state of everything. The cleanup in this
> situation cannot be bullet-proof but we should attempt to avoid
> breaking future transaction, if only to reduce the amount of
> error noise when debugging the failure from a kernel log.
>
> Note that this patch only implements the draining for blocking
> (non-deferred) transfers. The deferred API doesn't have any proper
> handling of error conditions and would need some re-design before
> implementing cleanup. That is a task for a separate patch...
It's nearly impossible to deal with error conditions with deferred
transfers, specifically in the case where deferred transfers deal with
bank switches to synchronize changes across multiple links. The NAK is
visible only in the scope of a link, and it could happen that a bank
switch happens on one link and not the other. We don't have any means to
recover at this point.
That said, draining the FIFO on timeouts for regular commands is a good
idea - or it cannot hurt, so
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
>
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
> ---
> drivers/soundwire/cadence_master.c | 48 ++++++++++++++++--------------
> 1 file changed, 26 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c
> index 95c84d9f0775..6bffecf3d61a 100644
> --- a/drivers/soundwire/cadence_master.c
> +++ b/drivers/soundwire/cadence_master.c
> @@ -555,6 +555,28 @@ cdns_fill_msg_resp(struct sdw_cdns *cdns,
> return SDW_CMD_OK;
> }
>
> +static void cdns_read_response(struct sdw_cdns *cdns)
> +{
> + u32 num_resp, cmd_base;
> + int i;
> +
> + BUILD_BUG_ON(ARRAY_SIZE(cdns->response_buf) < CDNS_MCP_CMD_LEN);
> +
> + num_resp = cdns_readl(cdns, CDNS_MCP_FIFOSTAT);
> + num_resp &= CDNS_MCP_RX_FIFO_AVAIL;
> + if (num_resp > ARRAY_SIZE(cdns->response_buf)) {
> + dev_warn(cdns->dev, "RX AVAIL %d too long\n", num_resp);
> + num_resp = CDNS_MCP_CMD_LEN;
> + }
> +
> + cmd_base = CDNS_MCP_CMD_BASE;
> +
> + for (i = 0; i < num_resp; i++) {
> + cdns->response_buf[i] = cdns_readl(cdns, cmd_base);
> + cmd_base += CDNS_MCP_CMD_WORD_LEN;
> + }
> +}
> +
> static enum sdw_command_response
> _cdns_xfer_msg(struct sdw_cdns *cdns, struct sdw_msg *msg, int cmd,
> int offset, int count, bool defer)
> @@ -596,6 +618,10 @@ _cdns_xfer_msg(struct sdw_cdns *cdns, struct sdw_msg *msg, int cmd,
> dev_err(cdns->dev, "IO transfer timed out, cmd %d device %d addr %x len %d\n",
> cmd, msg->dev_num, msg->addr, msg->len);
> msg->len = 0;
> +
> + /* Drain anything in the RX_FIFO */
> + cdns_read_response(cdns);
> +
> return SDW_CMD_TIMEOUT;
> }
>
> @@ -769,28 +795,6 @@ EXPORT_SYMBOL(cdns_read_ping_status);
> * IRQ handling
> */
>
> -static void cdns_read_response(struct sdw_cdns *cdns)
> -{
> - u32 num_resp, cmd_base;
> - int i;
> -
> - BUILD_BUG_ON(ARRAY_SIZE(cdns->response_buf) < CDNS_MCP_CMD_LEN);
> -
> - num_resp = cdns_readl(cdns, CDNS_MCP_FIFOSTAT);
> - num_resp &= CDNS_MCP_RX_FIFO_AVAIL;
> - if (num_resp > ARRAY_SIZE(cdns->response_buf)) {
> - dev_warn(cdns->dev, "RX AVAIL %d too long\n", num_resp);
> - num_resp = CDNS_MCP_CMD_LEN;
> - }
> -
> - cmd_base = CDNS_MCP_CMD_BASE;
> -
> - for (i = 0; i < num_resp; i++) {
> - cdns->response_buf[i] = cdns_readl(cdns, cmd_base);
> - cmd_base += CDNS_MCP_CMD_WORD_LEN;
> - }
> -}
> -
> static int cdns_update_slave_status(struct sdw_cdns *cdns,
> u64 slave_intstat)
> {
prev parent reply other threads:[~2022-12-01 20:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 13:48 [PATCH 0/3] soundwire: cadence: Fix oversized FIFO size define Richard Fitzgerald
2022-12-01 13:48 ` [PATCH 1/3] soundwire: cadence: Don't overflow the command FIFOs Richard Fitzgerald
2022-12-01 17:49 ` Pierre-Louis Bossart
2022-12-01 13:48 ` [PATCH 2/3] soundwire: cadence: Remove wasted space in response_buf Richard Fitzgerald
2022-12-01 18:12 ` Pierre-Louis Bossart
2022-12-02 10:19 ` Richard Fitzgerald
2022-12-01 13:48 ` [PATCH 3/3] soundwire: cadence: Drain the RX FIFO after an IO timeout Richard Fitzgerald
2022-12-01 18:20 ` Pierre-Louis Bossart [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=0f0fa03a-b7aa-6cdb-38b8-a09bf03f9efd@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rf@opensource.cirrus.com \
--cc=sanyog.r.kale@intel.com \
--cc=vkoul@kernel.org \
--cc=yung-chuan.liao@linux.intel.com \
/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