diff mbox series

[v2,1/5] firmware: arm_scmi: reset_rx_to_maxsz during async commands

Message ID 20210601102421.26581-2-cristian.marussi@arm.com (mailing list archive)
State New, archived
Headers show
Series Review/Extend SCMI Transport Core layer | expand

Commit Message

Cristian Marussi June 1, 2021, 10:24 a.m. UTC
During an async commands execution the rx buffer len is at first set to
max_msg_sz when the synchronous part of the command is first sent; once
the synchronous part completes the transport layer waits for the delayed
response which will be processed using the same xfer descriptor initially
allocated, but synchronous response received at the end of the xfer will
have shrunk the rx buffer len to the effective payload response length.

Raise the rx buffer length again to max_msg_sz while waiting for the
delayed response, while adding an informational error message.

Fixes: 58ecdf03dbb9 ("firmware: arm_scmi: Add support for asynchronous commands and delayed response")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/driver.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Sudeep Holla June 2, 2021, 4:08 p.m. UTC | #1
On Tue, Jun 01, 2021 at 11:24:17AM +0100, Cristian Marussi wrote:
> During an async commands execution the rx buffer len is at first set to
> max_msg_sz when the synchronous part of the command is first sent; once
> the synchronous part completes the transport layer waits for the delayed
> response which will be processed using the same xfer descriptor initially
> allocated, but synchronous response received at the end of the xfer will
> have shrunk the rx buffer len to the effective payload response length.
> 
> Raise the rx buffer length again to max_msg_sz while waiting for the
> delayed response, while adding an informational error message.
> 
> Fixes: 58ecdf03dbb9 ("firmware: arm_scmi: Add support for asynchronous commands and delayed response")
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> ---
>  drivers/firmware/arm_scmi/driver.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
> index 66eb3f0e5daf..75141b90ae53 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -513,8 +513,16 @@ static int do_xfer_with_response(const struct scmi_protocol_handle *ph,
>  	xfer->async_done = &async_response;
>  
>  	ret = do_xfer(ph, xfer);
> -	if (!ret && !wait_for_completion_timeout(xfer->async_done, timeout))
> -		ret = -ETIMEDOUT;
> +	if (!ret) {
> +		/* rx.len would have been shrunk in the sync do_xfer above */
> +		reset_rx_to_maxsz(ph, xfer);

Won't this race with delayed response notification ? I think so, let me
know if not and how. Can't we have this before we fetch the response into xfer ?
diff mbox series

Patch

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 66eb3f0e5daf..75141b90ae53 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -513,8 +513,16 @@  static int do_xfer_with_response(const struct scmi_protocol_handle *ph,
 	xfer->async_done = &async_response;
 
 	ret = do_xfer(ph, xfer);
-	if (!ret && !wait_for_completion_timeout(xfer->async_done, timeout))
-		ret = -ETIMEDOUT;
+	if (!ret) {
+		/* rx.len would have been shrunk in the sync do_xfer above */
+		reset_rx_to_maxsz(ph, xfer);
+		if (!wait_for_completion_timeout(xfer->async_done, timeout)) {
+			dev_err(ph->dev,
+				"timed out in delayed resp(caller: %pS)\n",
+				(void *)_RET_IP_);
+			ret = -ETIMEDOUT;
+		}
+	}
 
 	xfer->async_done = NULL;
 	return ret;