linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
@ 2020-07-26 22:00 Guenter Roeck
  2020-07-26 22:00 ` [PATCH v3 1/6] iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code Guenter Roeck
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Guenter Roeck @ 2020-07-26 22:00 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Dmitry Torokhov, Thierry Reding,
	Uwe Kleine-König, Gwendal Grignou, Brian Norris, linux-iio,
	linux-kernel, linux-input, linux-pwm

The EC reports a variety of error codes. Most of those, with the exception
of EC_RES_INVALID_VERSION, are converted to -EPROTO. As result, the actual
error code gets lost. In cros_ec_cmd_xfer_status(), convert all EC errors
to Linux error codes to report a more meaningful error to the caller to aid
debugging.

To prepare for this change, handle error codes other than -EPROTO for all
callers of cros_ec_cmd_xfer_status(). Specifically, no longer assume that
-EPROTO reflects an error from the EC and all other error codes reflect a
transfer error.

v2: Add patches 1/4 to 3/4 to handle callers of cros_ec_cmd_xfer_status()
v3: Add patches 4/6 and 5/6 to handle additional callers of
	cros_ec_cmd_xfer_status()
    Use -ENOPROTOOPT for EC_RES_INVALID_VERSION
    Implement function to convert error codes

----------------------------------------------------------------
Guenter Roeck (6):
      iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code
      cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status
      platform/chrome: cros_ec_sysfs: Report range of error codes from EC
      pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status
      platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT
      platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes

 .../iio/common/cros_ec_sensors/cros_ec_sensors.c   |  2 +-
 drivers/input/keyboard/cros_ec_keyb.c              |  2 +-
 drivers/platform/chrome/cros_ec_lightbar.c         | 10 ++---
 drivers/platform/chrome/cros_ec_proto.c            | 52 +++++++++++++++++-----
 drivers/platform/chrome/cros_ec_sysfs.c            | 24 ++++------
 drivers/pwm/pwm-cros-ec.c                          | 21 ++++++---
 6 files changed, 71 insertions(+), 40 deletions(-)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3 1/6] iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code
  2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
@ 2020-07-26 22:00 ` Guenter Roeck
  2020-07-26 22:00 ` [PATCH v3 2/6] cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Guenter Roeck @ 2020-07-26 22:00 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Dmitry Torokhov, Thierry Reding,
	Uwe Kleine-König, Gwendal Grignou, Brian Norris, linux-iio,
	linux-kernel, linux-input, linux-pwm, Guenter Roeck,
	Yu-Hsuan Hsu, Prashant Malani

A follow-up patch will extend the number of errors reported by
cros_ec_cmd_xfer_status(). Specifically, the function will return
-EOPNOTSUPP if a command is not supported by the EC. Prepare for it.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3: No change
v2: No change

 drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
index a66941fdb385..e3aff95493dd 100644
--- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
+++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
@@ -73,7 +73,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
 		st->core.param.sensor_offset.flags = 0;
 
 		ret = cros_ec_motion_send_host_cmd(&st->core, 0);
-		if (ret == -EPROTO) {
+		if (ret == -EPROTO || ret == -EOPNOTSUPP) {
 			/* Reading calibscale is not supported on older EC. */
 			*val = 1;
 			*val2 = 0;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 2/6] cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status
  2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
  2020-07-26 22:00 ` [PATCH v3 1/6] iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code Guenter Roeck
@ 2020-07-26 22:00 ` Guenter Roeck
  2020-07-26 22:00 ` [PATCH v3 3/6] platform/chrome: cros_ec_sysfs: Report range of error codes from EC Guenter Roeck
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Guenter Roeck @ 2020-07-26 22:00 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Dmitry Torokhov, Thierry Reding,
	Uwe Kleine-König, Gwendal Grignou, Brian Norris, linux-iio,
	linux-kernel, linux-input, linux-pwm, Guenter Roeck,
	Yu-Hsuan Hsu, Prashant Malani

Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command
not supported") we can no longer assume that cros_ec_cmd_xfer_status()
reports -EPROTO for all errors returned by the EC itself. A follow-up
patch will change cros_ec_cmd_xfer_status() to report additional errors
reported by the EC as distinguished Linux error codes.

Handle this change by no longer assuming that -EPROTO is used to report
all errors returned by the EC itself. Since errors reported by the EC are
already reported in text form through sysfs attributes, extend this form
of error reporting to all errors reported by cros_ec_cmd_xfer_status().

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3: No change
v2: Added patch

 drivers/platform/chrome/cros_ec_lightbar.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c
index b59180bff5a3..8445cda57927 100644
--- a/drivers/platform/chrome/cros_ec_lightbar.c
+++ b/drivers/platform/chrome/cros_ec_lightbar.c
@@ -117,7 +117,7 @@ static int get_lightbar_version(struct cros_ec_dev *ec,
 	param = (struct ec_params_lightbar *)msg->data;
 	param->cmd = LIGHTBAR_CMD_VERSION;
 	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
-	if (ret < 0) {
+	if (ret < 0 && ret != -EINVAL) {
 		ret = 0;
 		goto exit;
 	}
@@ -298,11 +298,9 @@ static ssize_t sequence_show(struct device *dev,
 		goto exit;
 
 	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
-	if (ret == -EPROTO) {
-		ret = scnprintf(buf, PAGE_SIZE,
-				"ERROR: EC returned %d\n", msg->result);
-		goto exit;
-	} else if (ret < 0) {
+	if (ret < 0) {
+		ret = scnprintf(buf, PAGE_SIZE, "XFER / EC ERROR %d / %d\n",
+				ret, msg->result);
 		goto exit;
 	}
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 3/6] platform/chrome: cros_ec_sysfs: Report range of error codes from EC
  2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
  2020-07-26 22:00 ` [PATCH v3 1/6] iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code Guenter Roeck
  2020-07-26 22:00 ` [PATCH v3 2/6] cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
@ 2020-07-26 22:00 ` Guenter Roeck
  2020-07-26 22:00 ` [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Guenter Roeck @ 2020-07-26 22:00 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Dmitry Torokhov, Thierry Reding,
	Uwe Kleine-König, Gwendal Grignou, Brian Norris, linux-iio,
	linux-kernel, linux-input, linux-pwm, Guenter Roeck,
	Yu-Hsuan Hsu, Prashant Malani

Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command
not supported") we can no longer assume that cros_ec_cmd_xfer_status()
reports -EPROTO for all errors returned by the EC itself. A follow-up
patch will change cros_ec_cmd_xfer_status() to report additional errors
reported by the EC as distinguished Linux error codes.

Prepare for this change by always reporting both the Linux error code
and the EC error code in sysfs attributes.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3: No change
v2: Added patch

 drivers/platform/chrome/cros_ec_sysfs.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index d45ea5d5bfa4..9c1e0998a721 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -150,12 +150,10 @@ static ssize_t version_show(struct device *dev,
 	msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
 	msg->insize = EC_HOST_PARAM_SIZE;
 	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
-	if (ret == -EPROTO) {
-		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "Build info:    EC error %d\n", msg->result);
-	} else if (ret < 0) {
+	if (ret < 0) {
 		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "Build info:    XFER ERROR %d\n", ret);
+				   "Build info:    XFER / EC ERROR %d / %d\n",
+				   ret, msg->result);
 	} else {
 		msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
 		count += scnprintf(buf + count, PAGE_SIZE - count,
@@ -166,12 +164,10 @@ static ssize_t version_show(struct device *dev,
 	msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
 	msg->insize = sizeof(*r_chip);
 	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
-	if (ret == -EPROTO) {
-		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "Chip info:     EC error %d\n", msg->result);
-	} else if (ret < 0) {
+	if (ret < 0) {
 		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "Chip info:     XFER ERROR %d\n", ret);
+				   "Chip info:     XFER / EC ERROR %d / %d\n",
+				   ret, msg->result);
 	} else {
 		r_chip = (struct ec_response_get_chip_info *)msg->data;
 
@@ -190,12 +186,10 @@ static ssize_t version_show(struct device *dev,
 	msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset;
 	msg->insize = sizeof(*r_board);
 	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
-	if (ret == -EPROTO) {
-		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "Board version: EC error %d\n", msg->result);
-	} else if (ret < 0) {
+	if (ret < 0) {
 		count += scnprintf(buf + count, PAGE_SIZE - count,
-				   "Board version: XFER ERROR %d\n", ret);
+				   "Board version: XFER / EC ERROR %d / %d\n",
+				   ret, msg->result);
 	} else {
 		r_board = (struct ec_response_board_version *)msg->data;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status
  2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
                   ` (2 preceding siblings ...)
  2020-07-26 22:00 ` [PATCH v3 3/6] platform/chrome: cros_ec_sysfs: Report range of error codes from EC Guenter Roeck
@ 2020-07-26 22:00 ` Guenter Roeck
  2020-07-27  8:35   ` Thierry Reding
  2020-08-01  7:21   ` Uwe Kleine-König
  2020-07-26 22:01 ` [PATCH v3 5/6] platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT Guenter Roeck
                   ` (2 subsequent siblings)
  6 siblings, 2 replies; 16+ messages in thread
From: Guenter Roeck @ 2020-07-26 22:00 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Dmitry Torokhov, Thierry Reding,
	Uwe Kleine-König, Gwendal Grignou, Brian Norris, linux-iio,
	linux-kernel, linux-input, linux-pwm, Guenter Roeck,
	Yu-Hsuan Hsu, Prashant Malani

Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command
not supported") we can no longer assume that cros_ec_cmd_xfer_status()
reports -EPROTO for all errors returned by the EC itself. A follow-up
patch will change cros_ec_cmd_xfer_status() to report additional errors
reported by the EC as distinguished Linux error codes.

Handle this change by no longer assuming that only -EPROTO is used
to report all errors returned by the EC itself. Instead, support both
the old and the new error codes.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3: Added patch

 drivers/pwm/pwm-cros-ec.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
index 09c08dee099e..ef05fba1bd37 100644
--- a/drivers/pwm/pwm-cros-ec.c
+++ b/drivers/pwm/pwm-cros-ec.c
@@ -213,20 +213,27 @@ static int cros_ec_num_pwms(struct cros_ec_device *ec)
 		u32 result = 0;
 
 		ret = __cros_ec_pwm_get_duty(ec, i, &result);
-		/* We want to parse EC protocol errors */
-		if (ret < 0 && !(ret == -EPROTO && result))
-			return ret;
-
 		/*
 		 * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM
 		 * responses; everything else is treated as an error.
 		 */
-		if (result == EC_RES_INVALID_COMMAND)
+		switch (ret) {
+		case -EOPNOTSUPP:	/* invalid command */
 			return -ENODEV;
-		else if (result == EC_RES_INVALID_PARAM)
+		case -EINVAL:		/* invalid parameter */
 			return i;
-		else if (result)
+		case -EPROTO:
+			/* Old or new error return code: Handle both */
+			if (result == EC_RES_INVALID_COMMAND)
+				return -ENODEV;
+			else if (result == EC_RES_INVALID_PARAM)
+				return i;
 			return -EPROTO;
+		default:
+			if (ret < 0)
+				return ret;
+			break;
+		}
 	}
 
 	return U8_MAX;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 5/6] platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT
  2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
                   ` (3 preceding siblings ...)
  2020-07-26 22:00 ` [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
@ 2020-07-26 22:01 ` Guenter Roeck
  2020-07-30  4:53   ` Dmitry Torokhov
  2020-07-26 22:01 ` [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
  2020-07-29 22:27 ` [PATCH v3 0/6] " Brian Norris
  6 siblings, 1 reply; 16+ messages in thread
From: Guenter Roeck @ 2020-07-26 22:01 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Dmitry Torokhov, Thierry Reding,
	Uwe Kleine-König, Gwendal Grignou, Brian Norris, linux-iio,
	linux-kernel, linux-input, linux-pwm, Guenter Roeck,
	Yu-Hsuan Hsu, Prashant Malani

-ENOTSUPP is not a SUSV4 error code and should not be used. Use
-ENOPROTOOPT instead to report EC_RES_INVALID_VERSION responses
from the EC. This matches match the NFS response for unsupported
protocol versions.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3: Added patch

 drivers/input/keyboard/cros_ec_keyb.c   | 2 +-
 drivers/platform/chrome/cros_ec_proto.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index fc1793ca2f17..15d17c717081 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -348,7 +348,7 @@ static int cros_ec_keyb_info(struct cros_ec_device *ec_dev,
 	params->event_type = event_type;
 
 	ret = cros_ec_cmd_xfer_status(ec_dev, msg);
-	if (ret == -ENOTSUPP) {
+	if (ret == -ENOPROTOOPT) {
 		/* With older ECs we just return 0 for everything */
 		memset(result, 0, result_size);
 		ret = 0;
diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 3e745e0fe092..e5bbec979a2a 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -555,7 +555,7 @@ EXPORT_SYMBOL(cros_ec_cmd_xfer);
  *
  * Return:
  * >=0 - The number of bytes transferred
- * -ENOTSUPP - Operation not supported
+ * -ENOPROTOOPT - Operation not supported
  * -EPROTO - Protocol error
  */
 int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
@@ -569,7 +569,7 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
 	} else if (msg->result == EC_RES_INVALID_VERSION) {
 		dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n",
 			msg->result);
-		return -ENOTSUPP;
+		return -ENOPROTOOPT;
 	} else if (msg->result != EC_RES_SUCCESS) {
 		dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
 		return -EPROTO;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
  2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
                   ` (4 preceding siblings ...)
  2020-07-26 22:01 ` [PATCH v3 5/6] platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT Guenter Roeck
@ 2020-07-26 22:01 ` Guenter Roeck
  2020-07-29 22:21   ` Brian Norris
  2020-07-29 22:27 ` [PATCH v3 0/6] " Brian Norris
  6 siblings, 1 reply; 16+ messages in thread
From: Guenter Roeck @ 2020-07-26 22:01 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Jonathan Cameron, Benson Leung, Dmitry Torokhov, Thierry Reding,
	Uwe Kleine-König, Gwendal Grignou, Brian Norris, linux-iio,
	linux-kernel, linux-input, linux-pwm, Guenter Roeck,
	Yu-Hsuan Hsu, Prashant Malani

The EC reports a variety of error codes. Most of those, with the exception
of EC_RES_INVALID_VERSION, are converted to -EPROTO. As result, the actual
EC error code gets lost. Introduce cros_ec_map_error() to map EC error
codes to Linux error codes, and use it in cros_ec_cmd_xfer_status() to
report more meaningful errors to the caller. With this change, callers of
cros_ec_cmd_xfer_status() can implement a more distinguished action without
having to rely on the EC error code. At the same time, debugging is improved
in situations where the Linux error code is reported to userspace and/or in
the kernel log.

Cc: Gwendal Grignou <gwendal@chromium.org>
Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Cc: Prashant Malani <pmalani@chromium.org>
Cc: Brian Norris <briannorris@chromium.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v3: Use -ENOPROTOOPT for EC_RES_INVALID_VERSION
    Implement function to convert error codes
v2: No change

 drivers/platform/chrome/cros_ec_proto.c | 52 ++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index e5bbec979a2a..a081b8245682 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -15,6 +15,43 @@
 
 #define EC_COMMAND_RETRIES	50
 
+static const int cros_ec_error_map[] = {
+	[EC_RES_INVALID_COMMAND] = -EOPNOTSUPP,
+	[EC_RES_ERROR] = -EIO,
+	[EC_RES_INVALID_PARAM] = -EINVAL,
+	[EC_RES_ACCESS_DENIED] = -EACCES,
+	[EC_RES_INVALID_RESPONSE] = -EPROTO,
+	[EC_RES_INVALID_VERSION] = -ENOPROTOOPT,
+	[EC_RES_INVALID_CHECKSUM] = -EBADMSG,
+	[EC_RES_IN_PROGRESS] = -EINPROGRESS,
+	[EC_RES_UNAVAILABLE] = -ENODATA,
+	[EC_RES_TIMEOUT] = -ETIMEDOUT,
+	[EC_RES_OVERFLOW] = -EOVERFLOW,
+	[EC_RES_INVALID_HEADER] = -EBADR,
+	[EC_RES_REQUEST_TRUNCATED] = -EBADR,
+	[EC_RES_RESPONSE_TOO_BIG] = -EFBIG,
+	[EC_RES_BUS_ERROR] = -EFAULT,
+	[EC_RES_BUSY] = -EBUSY,
+	[EC_RES_INVALID_HEADER_VERSION] = -EBADMSG,
+	[EC_RES_INVALID_HEADER_CRC] = -EBADMSG,
+	[EC_RES_INVALID_DATA_CRC] = -EBADMSG,
+	[EC_RES_DUP_UNAVAILABLE] = -ENODATA,
+};
+
+static int cros_ec_map_error(uint32_t result)
+{
+	int ret = 0;
+
+	if (result != EC_RES_SUCCESS) {
+		if (result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[result])
+			ret = cros_ec_error_map[result];
+		else
+			ret = -EPROTO;
+	}
+
+	return ret;
+}
+
 static int prepare_packet(struct cros_ec_device *ec_dev,
 			  struct cros_ec_command *msg)
 {
@@ -555,8 +592,7 @@ EXPORT_SYMBOL(cros_ec_cmd_xfer);
  *
  * Return:
  * >=0 - The number of bytes transferred
- * -ENOPROTOOPT - Operation not supported
- * -EPROTO - Protocol error
+ * <0 - Linux error code
  */
 int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
 			    struct cros_ec_command *msg)
@@ -566,15 +602,11 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
 	ret = cros_ec_cmd_xfer(ec_dev, msg);
 	if (ret < 0) {
 		dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret);
-	} else if (msg->result == EC_RES_INVALID_VERSION) {
-		dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n",
-			msg->result);
-		return -ENOPROTOOPT;
-	} else if (msg->result != EC_RES_SUCCESS) {
-		dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
-		return -EPROTO;
+	} else {
+		ret = cros_ec_map_error(msg->result);
+		if (ret)
+			dev_dbg(ec_dev->dev, "Command result (err: %d [%d])\n", msg->result, ret);
 	}
-
 	return ret;
 }
 EXPORT_SYMBOL(cros_ec_cmd_xfer_status);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status
  2020-07-26 22:00 ` [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
@ 2020-07-27  8:35   ` Thierry Reding
  2020-08-01  7:21   ` Uwe Kleine-König
  1 sibling, 0 replies; 16+ messages in thread
From: Thierry Reding @ 2020-07-27  8:35 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Uwe Kleine-König, Gwendal Grignou,
	Brian Norris, linux-iio, linux-kernel, linux-input, linux-pwm,
	Yu-Hsuan Hsu, Prashant Malani

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

On Sun, Jul 26, 2020 at 03:00:59PM -0700, Guenter Roeck wrote:
> Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command
> not supported") we can no longer assume that cros_ec_cmd_xfer_status()
> reports -EPROTO for all errors returned by the EC itself. A follow-up
> patch will change cros_ec_cmd_xfer_status() to report additional errors
> reported by the EC as distinguished Linux error codes.
> 
> Handle this change by no longer assuming that only -EPROTO is used
> to report all errors returned by the EC itself. Instead, support both
> the old and the new error codes.
> 
> Cc: Gwendal Grignou <gwendal@chromium.org>
> Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
> Cc: Prashant Malani <pmalani@chromium.org>
> Cc: Brian Norris <briannorris@chromium.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v3: Added patch
> 
>  drivers/pwm/pwm-cros-ec.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)

Acked-by: Thierry Reding <thierry.reding@gmail.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
  2020-07-26 22:01 ` [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
@ 2020-07-29 22:21   ` Brian Norris
  2020-07-29 23:22     ` Guenter Roeck
  0 siblings, 1 reply; 16+ messages in thread
From: Brian Norris @ 2020-07-29 22:21 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Thierry Reding, Uwe Kleine-König,
	Gwendal Grignou, linux-iio, linux-kernel, linux-input, linux-pwm,
	Yu-Hsuan Hsu, Prashant Malani

Hi Guenter,

On Sun, Jul 26, 2020 at 03:01:01PM -0700, Guenter Roeck wrote:
> v3: Use -ENOPROTOOPT for EC_RES_INVALID_VERSION
>     Implement function to convert error codes
> v2: No change
> 
>  drivers/platform/chrome/cros_ec_proto.c | 52 ++++++++++++++++++++-----
>  1 file changed, 42 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> index e5bbec979a2a..a081b8245682 100644
> --- a/drivers/platform/chrome/cros_ec_proto.c
> +++ b/drivers/platform/chrome/cros_ec_proto.c
> @@ -15,6 +15,43 @@
>  
>  #define EC_COMMAND_RETRIES	50
>  
> +static const int cros_ec_error_map[] = {
> +	[EC_RES_INVALID_COMMAND] = -EOPNOTSUPP,
> +	[EC_RES_ERROR] = -EIO,
> +	[EC_RES_INVALID_PARAM] = -EINVAL,
> +	[EC_RES_ACCESS_DENIED] = -EACCES,
> +	[EC_RES_INVALID_RESPONSE] = -EPROTO,
> +	[EC_RES_INVALID_VERSION] = -ENOPROTOOPT,
> +	[EC_RES_INVALID_CHECKSUM] = -EBADMSG,
> +	[EC_RES_IN_PROGRESS] = -EINPROGRESS,
> +	[EC_RES_UNAVAILABLE] = -ENODATA,
> +	[EC_RES_TIMEOUT] = -ETIMEDOUT,
> +	[EC_RES_OVERFLOW] = -EOVERFLOW,
> +	[EC_RES_INVALID_HEADER] = -EBADR,
> +	[EC_RES_REQUEST_TRUNCATED] = -EBADR,
> +	[EC_RES_RESPONSE_TOO_BIG] = -EFBIG,
> +	[EC_RES_BUS_ERROR] = -EFAULT,
> +	[EC_RES_BUSY] = -EBUSY,
> +	[EC_RES_INVALID_HEADER_VERSION] = -EBADMSG,
> +	[EC_RES_INVALID_HEADER_CRC] = -EBADMSG,
> +	[EC_RES_INVALID_DATA_CRC] = -EBADMSG,
> +	[EC_RES_DUP_UNAVAILABLE] = -ENODATA,
> +};

Sorry I didn't pay attention to this earlier, but is there any
programmatic way to ensure that we don't have unexpected holes here? If
we do (e.g., we add new error codes, but they aren't contiguous for
whatever reasons), then those will get treated as "success" with your
current patch.

I say "unexpected" hole, because EC_RES_SUCCESS (0) is an expected hole.

> +
> +static int cros_ec_map_error(uint32_t result)
> +{
> +	int ret = 0;
> +
> +	if (result != EC_RES_SUCCESS) {
> +		if (result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[result])
> +			ret = cros_ec_error_map[result];

^^ Maybe we want to double check 'ret != 0'? Or maybe

			ret = cros_ec_error_map[result];
			if (!ret) {
				ret = -EPROTO;
				dev_err(..., "Unexpected EC result code %d\n", result);
			}

? Could even be WARN_ON(), since this would be an actionable programming
error, not exactly an external factor. Or maybe I'm being paranoid, and
future programmers are perfect.

Otherwise:

Reviewed-by: Brian Norris <briannorris@chromium.org>

> +		else
> +			ret = -EPROTO;
> +	}
> +
> +	return ret;
> +}
> +
>  static int prepare_packet(struct cros_ec_device *ec_dev,
>  			  struct cros_ec_command *msg)
>  {

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
  2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
                   ` (5 preceding siblings ...)
  2020-07-26 22:01 ` [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
@ 2020-07-29 22:27 ` Brian Norris
  6 siblings, 0 replies; 16+ messages in thread
From: Brian Norris @ 2020-07-29 22:27 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Thierry Reding, Uwe Kleine-König,
	Gwendal Grignou, linux-iio, linux-kernel, linux-input, linux-pwm

On Sun, Jul 26, 2020 at 03:00:55PM -0700, Guenter Roeck wrote:
> The EC reports a variety of error codes. Most of those, with the exception
> of EC_RES_INVALID_VERSION, are converted to -EPROTO. As result, the actual
> error code gets lost. In cros_ec_cmd_xfer_status(), convert all EC errors
> to Linux error codes to report a more meaningful error to the caller to aid
> debugging.
> 
> To prepare for this change, handle error codes other than -EPROTO for all
> callers of cros_ec_cmd_xfer_status(). Specifically, no longer assume that
> -EPROTO reflects an error from the EC and all other error codes reflect a
> transfer error.
> 
> v2: Add patches 1/4 to 3/4 to handle callers of cros_ec_cmd_xfer_status()
> v3: Add patches 4/6 and 5/6 to handle additional callers of
> 	cros_ec_cmd_xfer_status()
>     Use -ENOPROTOOPT for EC_RES_INVALID_VERSION
>     Implement function to convert error codes

A small potential (i.e., being paranoid about future changes) note on
patch 6, but otherwise looks fine to me:

Reviewed-by: Brian Norris <briannorris@chromium.org>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
  2020-07-29 22:21   ` Brian Norris
@ 2020-07-29 23:22     ` Guenter Roeck
  2020-07-29 23:29       ` Brian Norris
  0 siblings, 1 reply; 16+ messages in thread
From: Guenter Roeck @ 2020-07-29 23:22 UTC (permalink / raw)
  To: Brian Norris
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Thierry Reding, Uwe Kleine-König,
	Gwendal Grignou, linux-iio, linux-kernel, linux-input, linux-pwm,
	Yu-Hsuan Hsu, Prashant Malani

On 7/29/20 3:21 PM, Brian Norris wrote:
> Hi Guenter,
> 
> On Sun, Jul 26, 2020 at 03:01:01PM -0700, Guenter Roeck wrote:
>> v3: Use -ENOPROTOOPT for EC_RES_INVALID_VERSION
>>     Implement function to convert error codes
>> v2: No change
>>
>>  drivers/platform/chrome/cros_ec_proto.c | 52 ++++++++++++++++++++-----
>>  1 file changed, 42 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
>> index e5bbec979a2a..a081b8245682 100644
>> --- a/drivers/platform/chrome/cros_ec_proto.c
>> +++ b/drivers/platform/chrome/cros_ec_proto.c
>> @@ -15,6 +15,43 @@
>>  
>>  #define EC_COMMAND_RETRIES	50
>>  
>> +static const int cros_ec_error_map[] = {
>> +	[EC_RES_INVALID_COMMAND] = -EOPNOTSUPP,
>> +	[EC_RES_ERROR] = -EIO,
>> +	[EC_RES_INVALID_PARAM] = -EINVAL,
>> +	[EC_RES_ACCESS_DENIED] = -EACCES,
>> +	[EC_RES_INVALID_RESPONSE] = -EPROTO,
>> +	[EC_RES_INVALID_VERSION] = -ENOPROTOOPT,
>> +	[EC_RES_INVALID_CHECKSUM] = -EBADMSG,
>> +	[EC_RES_IN_PROGRESS] = -EINPROGRESS,
>> +	[EC_RES_UNAVAILABLE] = -ENODATA,
>> +	[EC_RES_TIMEOUT] = -ETIMEDOUT,
>> +	[EC_RES_OVERFLOW] = -EOVERFLOW,
>> +	[EC_RES_INVALID_HEADER] = -EBADR,
>> +	[EC_RES_REQUEST_TRUNCATED] = -EBADR,
>> +	[EC_RES_RESPONSE_TOO_BIG] = -EFBIG,
>> +	[EC_RES_BUS_ERROR] = -EFAULT,
>> +	[EC_RES_BUSY] = -EBUSY,
>> +	[EC_RES_INVALID_HEADER_VERSION] = -EBADMSG,
>> +	[EC_RES_INVALID_HEADER_CRC] = -EBADMSG,
>> +	[EC_RES_INVALID_DATA_CRC] = -EBADMSG,
>> +	[EC_RES_DUP_UNAVAILABLE] = -ENODATA,
>> +};
> 
> Sorry I didn't pay attention to this earlier, but is there any
> programmatic way to ensure that we don't have unexpected holes here? If
> we do (e.g., we add new error codes, but they aren't contiguous for
> whatever reasons), then those will get treated as "success" with your
> current patch.
> 
> I say "unexpected" hole, because EC_RES_SUCCESS (0) is an expected hole.
> 
>> +
>> +static int cros_ec_map_error(uint32_t result)
>> +{
>> +	int ret = 0;
>> +
>> +	if (result != EC_RES_SUCCESS) {
>> +		if (result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[result])
>> +			ret = cros_ec_error_map[result];
> 
> ^^ Maybe we want to double check 'ret != 0'? Or maybe
> 
> 			ret = cros_ec_error_map[result];
> 			if (!ret) {

'ret' won't ever be 0 here. Above:
							&& cros_ec_error_map[result]

and below:

		else
			ret = -EPROTO;

> 				ret = -EPROTO;
> 				dev_err(..., "Unexpected EC result code %d\n", result);
> 			}
> 
> ? Could even be WARN_ON(), since this would be an actionable programming
> error, not exactly an external factor. Or maybe I'm being paranoid, and
> future programmers are perfect.
> 
I think, if anything, we might consider adding the message below (result >=
ARRAY_SIZE(cros_ec_error_map) is just as bad). Not sure myself. I am
open to adding it if people think it would be useful/desirable.

Thanks,
Guenter

> Otherwise:
> 
> Reviewed-by: Brian Norris <briannorris@chromium.org>
> 
>> +		else
>> +			ret = -EPROTO;
>> +	}
>> +
>> +	return ret;
>> +}
>> +
>>  static int prepare_packet(struct cros_ec_device *ec_dev,
>>  			  struct cros_ec_command *msg)
>>  {


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
  2020-07-29 23:22     ` Guenter Roeck
@ 2020-07-29 23:29       ` Brian Norris
  0 siblings, 0 replies; 16+ messages in thread
From: Brian Norris @ 2020-07-29 23:29 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Thierry Reding, Uwe Kleine-König,
	Gwendal Grignou, linux-iio, Linux Kernel, linux-input, linux-pwm,
	Yu-Hsuan Hsu, Prashant Malani

On Wed, Jul 29, 2020 at 4:22 PM Guenter Roeck <linux@roeck-us.net> wrote:
> On 7/29/20 3:21 PM, Brian Norris wrote:
> > On Sun, Jul 26, 2020 at 03:01:01PM -0700, Guenter Roeck wrote:
> >> --- a/drivers/platform/chrome/cros_ec_proto.c
> >> +++ b/drivers/platform/chrome/cros_ec_proto.c

> > ^^ Maybe we want to double check 'ret != 0'? Or maybe
> >
> >                       ret = cros_ec_error_map[result];
> >                       if (!ret) {
>
> 'ret' won't ever be 0 here. Above:
>                                                         && cros_ec_error_map[result]
>
> and below:
>
>                 else
>                         ret = -EPROTO;

Ah, I'm reading too quickly. You're correct, sorry.

> >                               ret = -EPROTO;
> >                               dev_err(..., "Unexpected EC result code %d\n", result);
> >                       }
> >
> > ? Could even be WARN_ON(), since this would be an actionable programming
> > error, not exactly an external factor. Or maybe I'm being paranoid, and
> > future programmers are perfect.
> >
> I think, if anything, we might consider adding the message below (result >=
> ARRAY_SIZE(cros_ec_error_map) is just as bad). Not sure myself. I am
> open to adding it if people think it would be useful/desirable.

No, my primary motivation was that I thought the logic left room for
error if there were holes. I was mistaken on that point. Secondarily,
it was also potentially useful to point out when we fell into those
holes. I'm not sure logging the warning is that important. Generally,
we only care about a handful of result codes, and as long as the rest
don't end up as "success", I think we're in OK shape.

Sorry for the noise. Here's my tag (which given my misreading so far,
should probably have a heavy discount on its value):

Reviewed-by: Brian Norris <briannorris@chromium.org>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 5/6] platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT
  2020-07-26 22:01 ` [PATCH v3 5/6] platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT Guenter Roeck
@ 2020-07-30  4:53   ` Dmitry Torokhov
  0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Torokhov @ 2020-07-30  4:53 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Thierry Reding, Uwe Kleine-König, Gwendal Grignou,
	Brian Norris, linux-iio, linux-kernel, linux-input, linux-pwm,
	Yu-Hsuan Hsu, Prashant Malani

On Sun, Jul 26, 2020 at 03:01:00PM -0700, Guenter Roeck wrote:
> -ENOTSUPP is not a SUSV4 error code and should not be used. Use
> -ENOPROTOOPT instead to report EC_RES_INVALID_VERSION responses
> from the EC. This matches match the NFS response for unsupported
> protocol versions.
> 
> Cc: Gwendal Grignou <gwendal@chromium.org>
> Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
> Cc: Prashant Malani <pmalani@chromium.org>
> Cc: Brian Norris <briannorris@chromium.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

for the input bit.

> ---
> v3: Added patch
> 
>  drivers/input/keyboard/cros_ec_keyb.c   | 2 +-
>  drivers/platform/chrome/cros_ec_proto.c | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
> index fc1793ca2f17..15d17c717081 100644
> --- a/drivers/input/keyboard/cros_ec_keyb.c
> +++ b/drivers/input/keyboard/cros_ec_keyb.c
> @@ -348,7 +348,7 @@ static int cros_ec_keyb_info(struct cros_ec_device *ec_dev,
>  	params->event_type = event_type;
>  
>  	ret = cros_ec_cmd_xfer_status(ec_dev, msg);
> -	if (ret == -ENOTSUPP) {
> +	if (ret == -ENOPROTOOPT) {
>  		/* With older ECs we just return 0 for everything */
>  		memset(result, 0, result_size);
>  		ret = 0;
> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> index 3e745e0fe092..e5bbec979a2a 100644
> --- a/drivers/platform/chrome/cros_ec_proto.c
> +++ b/drivers/platform/chrome/cros_ec_proto.c
> @@ -555,7 +555,7 @@ EXPORT_SYMBOL(cros_ec_cmd_xfer);
>   *
>   * Return:
>   * >=0 - The number of bytes transferred
> - * -ENOTSUPP - Operation not supported
> + * -ENOPROTOOPT - Operation not supported
>   * -EPROTO - Protocol error
>   */
>  int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
> @@ -569,7 +569,7 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
>  	} else if (msg->result == EC_RES_INVALID_VERSION) {
>  		dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n",
>  			msg->result);
> -		return -ENOTSUPP;
> +		return -ENOPROTOOPT;
>  	} else if (msg->result != EC_RES_SUCCESS) {
>  		dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
>  		return -EPROTO;
> -- 
> 2.17.1
> 

-- 
Dmitry

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status
  2020-07-26 22:00 ` [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
  2020-07-27  8:35   ` Thierry Reding
@ 2020-08-01  7:21   ` Uwe Kleine-König
  2020-08-01 16:32     ` Guenter Roeck
  1 sibling, 1 reply; 16+ messages in thread
From: Uwe Kleine-König @ 2020-08-01  7:21 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Thierry Reding, Gwendal Grignou, Brian Norris,
	linux-iio, linux-kernel, linux-input, linux-pwm, Yu-Hsuan Hsu,
	Prashant Malani

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

On Sun, Jul 26, 2020 at 03:00:59PM -0700, Guenter Roeck wrote:
> Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command
> not supported") we can no longer assume that cros_ec_cmd_xfer_status()
> reports -EPROTO for all errors returned by the EC itself. A follow-up
> patch will change cros_ec_cmd_xfer_status() to report additional errors
> reported by the EC as distinguished Linux error codes.
> 
> Handle this change by no longer assuming that only -EPROTO is used
> to report all errors returned by the EC itself. Instead, support both
> the old and the new error codes.
> 
> Cc: Gwendal Grignou <gwendal@chromium.org>
> Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
> Cc: Prashant Malani <pmalani@chromium.org>
> Cc: Brian Norris <briannorris@chromium.org>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> v3: Added patch
> 
>  drivers/pwm/pwm-cros-ec.c | 21 ++++++++++++++-------
>  1 file changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
> index 09c08dee099e..ef05fba1bd37 100644
> --- a/drivers/pwm/pwm-cros-ec.c
> +++ b/drivers/pwm/pwm-cros-ec.c
> @@ -213,20 +213,27 @@ static int cros_ec_num_pwms(struct cros_ec_device *ec)
>  		u32 result = 0;
>  
>  		ret = __cros_ec_pwm_get_duty(ec, i, &result);
> -		/* We want to parse EC protocol errors */
> -		if (ret < 0 && !(ret == -EPROTO && result))
> -			return ret;
> -
>  		/*
>  		 * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM
>  		 * responses; everything else is treated as an error.
>  		 */

This comment is at least misleading now.

> -		if (result == EC_RES_INVALID_COMMAND)
> +		switch (ret) {
> +		case -EOPNOTSUPP:	/* invalid command */
>  			return -ENODEV;

My first reaction here was to wonder why -EOPNOTSUPP isn't passed to the
upper layer. OK, this is a loop to test the number of available devices.

> -		else if (result == EC_RES_INVALID_PARAM)
> +		case -EINVAL:		/* invalid parameter */
>  			return i;
> -		else if (result)
> +		case -EPROTO:
> +			/* Old or new error return code: Handle both */
> +			if (result == EC_RES_INVALID_COMMAND)
> +				return -ENODEV;
> +			else if (result == EC_RES_INVALID_PARAM)
> +				return i;

If I understand correctly this surprising calling convention (output
parameter is filled even though the function returned an error) is the
old one that is to be fixed.

>  			return -EPROTO;
> +		default:
> +			if (ret < 0)
> +				return ret;
> +			break;
> +		}
>  	}
>  

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status
  2020-08-01  7:21   ` Uwe Kleine-König
@ 2020-08-01 16:32     ` Guenter Roeck
  2020-08-02 20:27       ` Uwe Kleine-König
  0 siblings, 1 reply; 16+ messages in thread
From: Guenter Roeck @ 2020-08-01 16:32 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Thierry Reding, Gwendal Grignou, Brian Norris,
	linux-iio, linux-kernel, linux-input, linux-pwm, Yu-Hsuan Hsu,
	Prashant Malani

On Sat, Aug 01, 2020 at 09:21:30AM +0200, Uwe Kleine-König wrote:
> On Sun, Jul 26, 2020 at 03:00:59PM -0700, Guenter Roeck wrote:
> > Since commit c5cd2b47b203 ("platform/chrome: cros_ec_proto: Report command
> > not supported") we can no longer assume that cros_ec_cmd_xfer_status()
> > reports -EPROTO for all errors returned by the EC itself. A follow-up
> > patch will change cros_ec_cmd_xfer_status() to report additional errors
> > reported by the EC as distinguished Linux error codes.
> > 
> > Handle this change by no longer assuming that only -EPROTO is used
> > to report all errors returned by the EC itself. Instead, support both
> > the old and the new error codes.
> > 
> > Cc: Gwendal Grignou <gwendal@chromium.org>
> > Cc: Yu-Hsuan Hsu <yuhsuan@chromium.org>
> > Cc: Prashant Malani <pmalani@chromium.org>
> > Cc: Brian Norris <briannorris@chromium.org>
> > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> > ---
> > v3: Added patch
> > 
> >  drivers/pwm/pwm-cros-ec.c | 21 ++++++++++++++-------
> >  1 file changed, 14 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/pwm/pwm-cros-ec.c b/drivers/pwm/pwm-cros-ec.c
> > index 09c08dee099e..ef05fba1bd37 100644
> > --- a/drivers/pwm/pwm-cros-ec.c
> > +++ b/drivers/pwm/pwm-cros-ec.c
> > @@ -213,20 +213,27 @@ static int cros_ec_num_pwms(struct cros_ec_device *ec)
> >  		u32 result = 0;
> >  
> >  		ret = __cros_ec_pwm_get_duty(ec, i, &result);
> > -		/* We want to parse EC protocol errors */
> > -		if (ret < 0 && !(ret == -EPROTO && result))
> > -			return ret;
> > -
> >  		/*
> >  		 * We look for SUCCESS, INVALID_COMMAND, or INVALID_PARAM
> >  		 * responses; everything else is treated as an error.
> >  		 */
> 
> This comment is at least misleading now.
> 
Good point. I'll rephrase.

> > -		if (result == EC_RES_INVALID_COMMAND)
> > +		switch (ret) {
> > +		case -EOPNOTSUPP:	/* invalid command */
> >  			return -ENODEV;
> 
> My first reaction here was to wonder why -EOPNOTSUPP isn't passed to the
> upper layer. OK, this is a loop to test the number of available devices.
> 
I'll be happy to add a comment.

> > -		else if (result == EC_RES_INVALID_PARAM)
> > +		case -EINVAL:		/* invalid parameter */
> >  			return i;
> > -		else if (result)
> > +		case -EPROTO:
> > +			/* Old or new error return code: Handle both */
> > +			if (result == EC_RES_INVALID_COMMAND)
> > +				return -ENODEV;
> > +			else if (result == EC_RES_INVALID_PARAM)
> > +				return i;
> 
> If I understand correctly this surprising calling convention (output
> parameter is filled even though the function returned an error) is the
> old one that is to be fixed.
> 
Sorry, I don't get your point. This is the old convention, correct,
which we still want to support at this point. Plus, it matches the
current code, as surprosing as it may be.

Guenter

> >  			return -EPROTO;
> > +		default:
> > +			if (ret < 0)
> > +				return ret;
> > +			break;
> > +		}
> >  	}
> >  
> 
> Best regards
> Uwe
> 
> -- 
> Pengutronix e.K.                           | Uwe Kleine-König            |
> Industrial Linux Solutions                 | https://www.pengutronix.de/ |



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status
  2020-08-01 16:32     ` Guenter Roeck
@ 2020-08-02 20:27       ` Uwe Kleine-König
  0 siblings, 0 replies; 16+ messages in thread
From: Uwe Kleine-König @ 2020-08-02 20:27 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Enric Balletbo i Serra, Jonathan Cameron, Benson Leung,
	Dmitry Torokhov, Thierry Reding, Gwendal Grignou, Brian Norris,
	linux-iio, linux-kernel, linux-input, linux-pwm, Yu-Hsuan Hsu,
	Prashant Malani

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

Hello Guenter,

On Sat, Aug 01, 2020 at 09:32:19AM -0700, Guenter Roeck wrote:
> > If I understand correctly this surprising calling convention (output
> > parameter is filled even though the function returned an error) is the
> > old one that is to be fixed.
>
> Sorry, I don't get your point. This is the old convention, correct,
> which we still want to support at this point. Plus, it matches the
> current code, as surprosing as it may be.

OK, so I understood correctly and everything is fine.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-08-02 20:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-26 22:00 [PATCH v3 0/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
2020-07-26 22:00 ` [PATCH v3 1/6] iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code Guenter Roeck
2020-07-26 22:00 ` [PATCH v3 2/6] cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
2020-07-26 22:00 ` [PATCH v3 3/6] platform/chrome: cros_ec_sysfs: Report range of error codes from EC Guenter Roeck
2020-07-26 22:00 ` [PATCH v3 4/6] pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status Guenter Roeck
2020-07-27  8:35   ` Thierry Reding
2020-08-01  7:21   ` Uwe Kleine-König
2020-08-01 16:32     ` Guenter Roeck
2020-08-02 20:27       ` Uwe Kleine-König
2020-07-26 22:01 ` [PATCH v3 5/6] platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT Guenter Roeck
2020-07-30  4:53   ` Dmitry Torokhov
2020-07-26 22:01 ` [PATCH v3 6/6] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Guenter Roeck
2020-07-29 22:21   ` Brian Norris
2020-07-29 23:22     ` Guenter Roeck
2020-07-29 23:29       ` Brian Norris
2020-07-29 22:27 ` [PATCH v3 0/6] " Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).