From: sudeep.holla@arm.com (Sudeep Holla)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH v2 1/2] firmware: arm_scpi: zero RX buffer before requesting data from the mbox
Date: Wed, 7 Dec 2016 18:17:20 +0000 [thread overview]
Message-ID: <f544a379-a6a0-7839-85c3-a22449fecc46@arm.com> (raw)
In-Reply-To: <20161125005432.1205-2-martin.blumenstingl@googlemail.com>
On 25/11/16 00:54, Martin Blumenstingl wrote:
> The original code was relying on the fact that the SCPI firmware
> responds with the same number of bytes (or more, all extra data would be
> ignored in that case) as requested.
> However, we have some pre-v1.0 SCPI firmwares which are responding with
> less data for some commands (sensor_value.hi_val did not exist in the
> old implementation). This means that some data from the previous
> command's RX buffer was leaked into the current command (as the RX
> buffer is re-used for all commands on the same channel). Clearing the
> RX buffer before (re-) using it ensures we get a consistent result, even
> if the SCPI firmware returns less bytes than requested.
>
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> ---
> drivers/firmware/arm_scpi.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
> index 70e1323..8c183d8 100644
> --- a/drivers/firmware/arm_scpi.c
> +++ b/drivers/firmware/arm_scpi.c
> @@ -259,6 +259,7 @@ struct scpi_chan {
> struct mbox_chan *chan;
> void __iomem *tx_payload;
> void __iomem *rx_payload;
> + resource_size_t max_payload_len;
> struct list_head rx_pending;
> struct list_head xfers_list;
> struct scpi_xfer *xfers;
> @@ -470,6 +471,20 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg)
> if (t->rx_buf) {
> if (!(++ch->token))
> ++ch->token;
> +
> + /* clear the RX buffer as it is shared across all commands on
> + * the same channel (to make sure we're not leaking data from
> + * the previous response into the current command if the SCPI
> + * firmware writes less data than requested).
> + * This is especially important for pre-v1.0 SCPI firmwares
> + * where some fields in the responses do not exist (while they
> + * exist but are optional in newer versions). One example for
> + * this problem is sensor_value.hi_val, which would contain
> + * ("leak") the second 4 bytes of the RX buffer from the
> + * previous command.
> + */
> + memset_io(ch->rx_payload, 0, ch->max_payload_len);
> +
This looks like a overkill to me. I prefer your first approach over
this, if it's only this command that's affected. I am still not sure
why Neil Armstrong mentioned that it worked for him with 64-bit read.
--
Regards,
Sudeep
next prev parent reply other threads:[~2016-12-07 18:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-24 0:18 [PATCH] SCPI (pre-v1.0): fix reading sensor value Martin Blumenstingl
2016-11-24 0:18 ` [PATCH] firmware: arm_scpi: fix reading sensor values on pre-1.0 SCPI firmwares Martin Blumenstingl
2016-12-07 18:44 ` Sudeep Holla
2016-12-11 21:16 ` Martin Blumenstingl
2016-11-24 10:47 ` [PATCH] SCPI (pre-v1.0): fix reading sensor value Sudeep Holla
2016-11-24 11:15 ` Martin Blumenstingl
2016-11-25 0:56 ` Martin Blumenstingl
2016-12-02 22:54 ` Martin Blumenstingl
2016-12-06 11:38 ` Sudeep Holla
2016-11-25 0:54 ` [PATCH v2 0/2] " Martin Blumenstingl
2016-11-25 0:54 ` [PATCH v2 1/2] firmware: arm_scpi: zero RX buffer before requesting data from the mbox Martin Blumenstingl
2016-12-07 18:17 ` Sudeep Holla [this message]
2016-12-09 20:23 ` Martin Blumenstingl
2016-12-09 10:16 ` Jon Medhurst (Tixy)
2016-11-25 0:54 ` [PATCH v2 2/2] firmware: arm_scpi: check the payload length in scpi_send_message Martin Blumenstingl
2016-12-09 9:57 ` Jon Medhurst (Tixy)
2016-12-11 21:14 ` [PATCH v3] SCPI (pre-v1.0): fix reading sensor value Martin Blumenstingl
2016-12-11 21:14 ` [PATCH v3] firmware: arm_scpi: fix reading sensor values on pre-1.0 SCPI firmwares Martin Blumenstingl
2016-12-13 14:09 ` Sudeep Holla
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=f544a379-a6a0-7839-85c3-a22449fecc46@arm.com \
--to=sudeep.holla@arm.com \
--cc=linus-amlogic@lists.infradead.org \
/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
all inboxes | Powered by JetHome®