All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benson Leung <bleung@google.com>
To: Shawn Nematbakhsh <shawnn@chromium.org>
Cc: linux-kernel@vger.kernel.org, lee.jones@linaro.org,
	jonathanh@nvidia.com, briannorris@chromium.org,
	bleung@google.com, bleung@chromium.org
Subject: Re: [PATCH] mfd: cros ec: spi: Fix "in progress" error signaling
Date: Tue, 21 Nov 2017 19:54:08 -0800	[thread overview]
Message-ID: <20171122035408.GA121077@decatoncale.mtv.corp.google.com> (raw)
In-Reply-To: <20170927213527.31416-1-shawnn@chromium.org>

[-- Attachment #1: Type: text/plain, Size: 3999 bytes --]

Hi Shawn,

On Wed, Sep 27, 2017 at 02:35:27PM -0700, Shawn Nematbakhsh wrote:
> For host commands that take a long time to process, cros ec can return
> early by signaling a EC_RES_IN_PROGRESS result. The host must then poll
> status with EC_CMD_GET_COMMS_STATUS until completion of the command.
> 
> None of the above applies when data link errors are encountered. When
> errors such as EC_SPI_PAST_END are encountered during command
> transmission, it usually means the command was not received by the EC.
> Treating such errors as if they were 'EC_RES_IN_PROGRESS' results is
> almost always the wrong decision, and can result in host commands
> silently being lost.
> 
> Reported-and-tested-by: Jon Hunter <jonathanh@nvidia.com>
> Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>

Acked-by: Benson Leung <bleung@chromium.org>

> ---
>  drivers/mfd/cros_ec_spi.c | 52 ++++++++++++++++++++++-------------------------
>  1 file changed, 24 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c
> index c9714072e224..d019b5b00b67 100644
> --- a/drivers/mfd/cros_ec_spi.c
> +++ b/drivers/mfd/cros_ec_spi.c
> @@ -377,6 +377,7 @@ static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev,
>  	u8 *ptr;
>  	u8 *rx_buf;
>  	u8 sum;
> +	u8 rx_byte;
>  	int ret = 0, final_ret;
>  
>  	len = cros_ec_prepare_tx(ec_dev, ec_msg);
> @@ -421,25 +422,22 @@ static int cros_ec_pkt_xfer_spi(struct cros_ec_device *ec_dev,
>  	if (!ret) {
>  		/* Verify that EC can process command */
>  		for (i = 0; i < len; i++) {
> -			switch (rx_buf[i]) {
> -			case EC_SPI_PAST_END:
> -			case EC_SPI_RX_BAD_DATA:
> -			case EC_SPI_NOT_READY:
> -				ret = -EAGAIN;
> -				ec_msg->result = EC_RES_IN_PROGRESS;
> -			default:
> +			rx_byte = rx_buf[i];
> +			if (rx_byte == EC_SPI_PAST_END  ||
> +			    rx_byte == EC_SPI_RX_BAD_DATA ||
> +			    rx_byte == EC_SPI_NOT_READY) {
> +				ret = -EREMOTEIO;
>  				break;
>  			}
> -			if (ret)
> -				break;
>  		}
> -		if (!ret)
> -			ret = cros_ec_spi_receive_packet(ec_dev,
> -					ec_msg->insize + sizeof(*response));
> -	} else {
> -		dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
>  	}
>  
> +	if (!ret)
> +		ret = cros_ec_spi_receive_packet(ec_dev,
> +				ec_msg->insize + sizeof(*response));
> +	else
> +		dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
> +
>  	final_ret = terminate_request(ec_dev);
>  
>  	spi_bus_unlock(ec_spi->spi->master);
> @@ -508,6 +506,7 @@ static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev,
>  	int i, len;
>  	u8 *ptr;
>  	u8 *rx_buf;
> +	u8 rx_byte;
>  	int sum;
>  	int ret = 0, final_ret;
>  
> @@ -544,25 +543,22 @@ static int cros_ec_cmd_xfer_spi(struct cros_ec_device *ec_dev,
>  	if (!ret) {
>  		/* Verify that EC can process command */
>  		for (i = 0; i < len; i++) {
> -			switch (rx_buf[i]) {
> -			case EC_SPI_PAST_END:
> -			case EC_SPI_RX_BAD_DATA:
> -			case EC_SPI_NOT_READY:
> -				ret = -EAGAIN;
> -				ec_msg->result = EC_RES_IN_PROGRESS;
> -			default:
> +			rx_byte = rx_buf[i];
> +			if (rx_byte == EC_SPI_PAST_END  ||
> +			    rx_byte == EC_SPI_RX_BAD_DATA ||
> +			    rx_byte == EC_SPI_NOT_READY) {
> +				ret = -EREMOTEIO;
>  				break;
>  			}
> -			if (ret)
> -				break;
>  		}
> -		if (!ret)
> -			ret = cros_ec_spi_receive_response(ec_dev,
> -					ec_msg->insize + EC_MSG_TX_PROTO_BYTES);
> -	} else {
> -		dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
>  	}
>  
> +	if (!ret)
> +		ret = cros_ec_spi_receive_response(ec_dev,
> +				ec_msg->insize + EC_MSG_TX_PROTO_BYTES);
> +	else
> +		dev_err(ec_dev->dev, "spi transfer failed: %d\n", ret);
> +
>  	final_ret = terminate_request(ec_dev);
>  
>  	spi_bus_unlock(ec_spi->spi->master);
> -- 
> 2.12.2
> 

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2017-11-22  3:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-27 21:35 [PATCH] mfd: cros ec: spi: Fix "in progress" error signaling Shawn Nematbakhsh
2017-09-27 22:19 ` Brian Norris
2017-11-14 17:00   ` Shawn N
2017-11-29 11:50     ` Jon Hunter
2017-11-22  3:54 ` Benson Leung [this message]
2017-11-29 12:11 ` Lee Jones
2018-03-26 16:48   ` Enric Balletbo Serra
2018-03-26 17:26     ` Alexandru M Stan
2018-03-27 10:49       ` Enric Balletbo Serra
2018-03-29 22:08         ` Alexandru M Stan

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=20171122035408.GA121077@decatoncale.mtv.corp.google.com \
    --to=bleung@google.com \
    --cc=bleung@chromium.org \
    --cc=briannorris@chromium.org \
    --cc=jonathanh@nvidia.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shawnn@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.