From patchwork Mon Jul 20 20:22:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11674541 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70FB5138A for ; Mon, 20 Jul 2020 20:22:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A030207DF for ; Mon, 20 Jul 2020 20:22:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YQ1fimAk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729893AbgGTUWv (ORCPT ); Mon, 20 Jul 2020 16:22:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731219AbgGTUWu (ORCPT ); Mon, 20 Jul 2020 16:22:50 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8925DC061794; Mon, 20 Jul 2020 13:22:50 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id k1so424914pjt.5; Mon, 20 Jul 2020 13:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=KRP2YYdI7T0EhHxiCZP03QeZpOTCB3357aMOLsKRCT8=; b=YQ1fimAkktpJg8SdUGFqufOAvdTM8lkuxH89v+ZkBZk7Ll/7dK8KevMeDNByIXJNc8 i/Qp+1Y8Yn1WkhDxCb+6SnHYYdj+OrEURiHJHVEMc5ZY8vmBZBOJSSXmFSsxY/pDtJlP USqP6DQ8bDYlHJBvbWIcs9IBNXd/jlcapQMAjQYXNGSWvVDrbCHreYlfjbASS8SRQoh/ Mgj68oJqSpKf0UyzjCISIVHEL0TCfwVQVinZfr2Hf3xtHfBOoU61OEkWAyIpJJEVvYe7 0i91/h3ePuyyLxXBPEOmx5AuIVsHeiezOugmWc1MEvXqvdkMy7PiujcT/2yA8wqarNDf xL7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=KRP2YYdI7T0EhHxiCZP03QeZpOTCB3357aMOLsKRCT8=; b=eMgYeeLxHbzB8Qr6KFF9a7KwqV1FgzPDgn88Ei0orCH2TGoTf5K+SHUWvkUUXtQQSB tJ/nI4mg/Hy2NMjYR20zkIYaDzA94OiblsOVzvy3iQTTVoQ9e6Zz8R6WD/snTbkfgqxS usIgA/kbvODB4RtQS78JIcQsmNRhClLVgJ7xq4AIFkn6BHgMw2fiT7c/P7/RaBqiG0Mx D+R2Jz4j/dhpwT2qxOrav+j0nb7aBVmkJmH2Py/erFXxyWxRirDrKUoI7xsvDBHt5/lF SPgcIU0h9qkemFgvkUlIOi6nopfAtZOOPDpyxSZ63osH5iOsWTcirSEilJ33+5iDBRHC NG9Q== X-Gm-Message-State: AOAM530ezYjuGHAkuVClpeNmhls8LR/1IQdGY1SYdvs3f8vSDtqlN1nO +FB7ZQbIWzec0RnjQfZdWEE= X-Google-Smtp-Source: ABdhPJyx1Ai0r+hOFgm8OQmv/zGlCKrZorLSQ6321OwETwHtfNvMLw2Jnve2BSJLd3oy/UV7pjlCzA== X-Received: by 2002:a17:90a:ad8e:: with SMTP id s14mr1192363pjq.36.1595276570174; Mon, 20 Jul 2020 13:22:50 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 2sm18216769pfa.110.2020.07.20.13.22.49 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Jul 2020 13:22:49 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Benson Leung , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Yu-Hsuan Hsu , Prashant Malani , Guenter Roeck Subject: [PATCH v2 1/4] iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code Date: Mon, 20 Jul 2020 13:22:40 -0700 Message-Id: <20200720202243.180230-2-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200720202243.180230-1-linux@roeck-us.net> References: <20200720202243.180230-1-linux@roeck-us.net> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: Yu-Hsuan Hsu Cc: Prashant Malani Signed-off-by: Guenter Roeck Acked-by: Jonathan Cameron --- v2: Added patch 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; From patchwork Mon Jul 20 20:22:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11674543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D86DD138A for ; Mon, 20 Jul 2020 20:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1A9322BF5 for ; Mon, 20 Jul 2020 20:22:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PpL6hp0K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731238AbgGTUWx (ORCPT ); Mon, 20 Jul 2020 16:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731224AbgGTUWw (ORCPT ); Mon, 20 Jul 2020 16:22:52 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1861C061794; Mon, 20 Jul 2020 13:22:51 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id j19so10832618pgm.11; Mon, 20 Jul 2020 13:22:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=QJTwvF7OVB9geqL6s9YWUDhdihHDDKb0TP4SnK0503g=; b=PpL6hp0Kyy5Vti3RFDIa1oZdaF+I53/ZZ9MaDLCCbdadzd1CniORHUgk/yx/tK65gS EkKChg1g3psz9xvjN4sDrwuNEXR5qWjA5aVRl8hiOeJWJXt897hGgyBeVXMDK2QJYoLZ uTiBq3UQ5g7XK7RNp6BCFID5+HE204X5VrhtNY/5SNFwebeybOrq7SBpJUsQkfeHFMQ7 n1xAINvOgS644K43yp3Vq4HHrK8JsR+E8wSs9TV4gvAHAQg6qY/26AWoNUE7/KHHfJwA LmBVGFNBKLUhaddjfSP9BJhGWu/gmoWRfae7V3VHlQa7IfPKmN45DzlBHA++17XYNGI7 l9Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=QJTwvF7OVB9geqL6s9YWUDhdihHDDKb0TP4SnK0503g=; b=nzQZLAmhNDN61uUYG5nLT/H92lN/2MzDVJ9hlHqzIMeAxHC+4J0NjOMs1NnLweg/dz npruW0DIpnASC8oxuEjefh85ldqoPxCt0TX9kiwbUtsdBF5z5MEf/lt+JAGP07l19jkX LojIrTsu8iSnzPwKEmRH/hilR+5T9Bjj1BK8z3opU/ljBnyL9RyVa7k5sOOfSAB4oMq/ oqXBBwOr+1h8kQq152x2mEQyJI6JsxOzK3rrYENfdivSPTTHeEpxX04pCFOgAbEda1p6 NCEzES4B+xS8QxqHiED/VChPRzUST/3490gVEvUiOEnmMf4EZVmMgo3yrZnt76UPum9W ccEg== X-Gm-Message-State: AOAM530JECLaM5vJ+Hd8/FtgMQ9u0VhoZkNu1MnH4ZbkNNv1s5G3Jjxu 4fFLt+G25yvzmVRTmtgKMbU= X-Google-Smtp-Source: ABdhPJwJ/gJfWCV56yGpwx0FqjO9lqx+TL2whMK/Zd7R9FKJ8oiIsg0Q0R2go1M6gCLsc94/DVjDOQ== X-Received: by 2002:a63:e00c:: with SMTP id e12mr20034050pgh.413.1595276571505; Mon, 20 Jul 2020 13:22:51 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id g18sm17302459pfi.141.2020.07.20.13.22.50 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Jul 2020 13:22:51 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Benson Leung , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Yu-Hsuan Hsu , Prashant Malani , Guenter Roeck Subject: [PATCH v2 2/4] cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status Date: Mon, 20 Jul 2020 13:22:41 -0700 Message-Id: <20200720202243.180230-3-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200720202243.180230-1-linux@roeck-us.net> References: <20200720202243.180230-1-linux@roeck-us.net> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: Yu-Hsuan Hsu Cc: Prashant Malani Signed-off-by: Guenter Roeck --- 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; } From patchwork Mon Jul 20 20:22:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11674545 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6720138A for ; Mon, 20 Jul 2020 20:23:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC8A122B4E for ; Mon, 20 Jul 2020 20:23:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gOztGMeW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731270AbgGTUW5 (ORCPT ); Mon, 20 Jul 2020 16:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731247AbgGTUWy (ORCPT ); Mon, 20 Jul 2020 16:22:54 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07EF6C061794; Mon, 20 Jul 2020 13:22:54 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id j19so10832669pgm.11; Mon, 20 Jul 2020 13:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Vb/s6eaRVOOXS2bQDo6HvuZPYU7xzzm5Qvi0rhYOi/A=; b=gOztGMeWodtIMuhefmbncov8BWaUFxhuOUu7ct4pkkZvSUgOk86YslH2wWoh5boGqe s91zbVBgl4K0h2fTdeb4Vn5mYPB9f1PxT7re09ZsAzFv1OPhyLmvp1T+AQaHlsNsPv76 C5U4I8RUxXRjcskoQw9sOGJKZsPZtD4remMJ2DnRPBufe6txu/PHKHGIrrkklWcpfkD0 a0fMFt5MMbYpcg57yAD6kr9iAktN+9fj+S3tDTtPzl22/qKNzAQNNK2PtEv/jpSbvx5G Mkc4XE2RyiWaFYQqheko5pJZL6wQtF8bM00HJxxZKcxswuPhKOP059rBnNYPoy1tNqma Lexw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Vb/s6eaRVOOXS2bQDo6HvuZPYU7xzzm5Qvi0rhYOi/A=; b=ElPhaYhKwNGpOv2EaGhzzzAR7+CkOPiAvEJgQiLB22+12H05tQHpL9JzsoeNrMHe2X ft0Iq5+tngNgw1BIS+HEECKnESqB2q8frE0gkeWq8sqbxNq0z+fCSEZakTuNgiqYxuUB cH/kMtpqZxnPzfikl3azgl9uB++udB1M2dPjC6TuDqP1ukTcqgry/ooCOkHAnziQjFKE 6BBq77TcNId+0LeykVWFPZ9vDgzE9MAg/FyCoE6LuA/HezHFcbjmTSwYbVLWk2/YBuQx OG3SrtKSOYo15D5D76PgAGD6NkFj7rjwJnGW6npEubPO9JxK4d1gPmO1DVBZbsLPC43d wjpQ== X-Gm-Message-State: AOAM533HscMnNTlVAehccCrjXNINa+78Zpp3CLiLKEQyUG924O36swnK iuL5xw70ErqQmWbnETLSha0= X-Google-Smtp-Source: ABdhPJzbGnL6J+t8kzDZtYPnexg7+vQHnuw9hhvFAa96MmipGdPcB6fbjyeV88GHNEhP2zP6VAmbbg== X-Received: by 2002:a63:1c23:: with SMTP id c35mr19358566pgc.91.1595276573598; Mon, 20 Jul 2020 13:22:53 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id j5sm17353700pfa.5.2020.07.20.13.22.52 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Jul 2020 13:22:53 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Benson Leung , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Yu-Hsuan Hsu , Prashant Malani , Guenter Roeck Subject: [PATCH v2 3/4] platform/chrome: cros_ec_sysfs: Report range of error codes from EC Date: Mon, 20 Jul 2020 13:22:42 -0700 Message-Id: <20200720202243.180230-4-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200720202243.180230-1-linux@roeck-us.net> References: <20200720202243.180230-1-linux@roeck-us.net> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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: Yu-Hsuan Hsu Cc: Prashant Malani Signed-off-by: Guenter Roeck --- 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; From patchwork Mon Jul 20 20:22:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 11674547 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6046213B6 for ; Mon, 20 Jul 2020 20:23:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A87422B4E for ; Mon, 20 Jul 2020 20:23:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QkKkAZeh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730614AbgGTUXA (ORCPT ); Mon, 20 Jul 2020 16:23:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731224AbgGTUW4 (ORCPT ); Mon, 20 Jul 2020 16:22:56 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47330C0619D2; Mon, 20 Jul 2020 13:22:56 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id w2so10837845pgg.10; Mon, 20 Jul 2020 13:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=w+TorV6mA7rqY5GL2y/dxljOSmTJZvSpfXkQ2KHgU20=; b=QkKkAZeh/YLKhEcBiQ0hP9C1kiZimO2XCXZrKaFRwnG9cmuXG5afpjy1umjjc3G7sr bMR+JqyHma3BjXy6f7liB0y69JtB/3OfSRYqWEc450AEt8XHIgkb7oeoQdi5OeoJAJzw HDMWBTfpFyXgHyso9hFO2X1dsyqYGw2rM6JGoTP/JDDrfHkx8NaG9JdY6izoqN6OJQX8 zAeCp7BvmPRv/0yQOztWmm60JPV2jgqiFN+WRVhywvNDZw+qkj+Qe18JfPbI4GR0KX8h KBIPu9gC/nnZjkIwO4SPJha4mcrdG+gGn/rm/L4jA3/9uuU6vl4NurT1AWU/ubmrCufY bcCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=w+TorV6mA7rqY5GL2y/dxljOSmTJZvSpfXkQ2KHgU20=; b=hZsUStVVm1bg+I5bCZWwufyPUzudGGt6K+WAvPertSXfG1yZJyehetMWD2XfJmrkN7 y8l6PSL9dSo0PHbeMzf/wcq3MZ7sf0ZabAX3MdDVqrc8b+ZBbt1+HpVO8Sn6S0GtQZTX skuWRjGRQqbKJLsHpZIdtCc/aIrIubQTWRayk7NPBB8yWf9Tsp7f/3CdV5i4poBkDVPa GKo7qd4L5V1kaAh9ovrj1LGopeLOXZPde4oSkituGtUOlSad1wnBqLPfYc3DirEs8aIA DLY5CiRIa91Sv57/+7jwlfLIIzMiPFlXzu2DKyf3UW9C8M0PLGORf1XaOaqnPn7cd8BP ktLg== X-Gm-Message-State: AOAM530GSdbfnlpwzT7ti/ksW/hxwhIkmdVMrEWK6UqXeSyLt5OK0FWA WhW2mLTcZzcHbSrIcCOLS169qlmz X-Google-Smtp-Source: ABdhPJxydgttZ8N8g+ET44350AvzkjYSZVQMiq06EJiaZfRwS+0ODGTp+WU3KLLSu6ZlrOXRKsSqqQ== X-Received: by 2002:a63:3c2:: with SMTP id 185mr20442576pgd.46.1595276575799; Mon, 20 Jul 2020 13:22:55 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id a68sm429122pje.35.2020.07.20.13.22.54 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Jul 2020 13:22:55 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Benson Leung , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Yu-Hsuan Hsu , Prashant Malani , Guenter Roeck Subject: [PATCH v2 4/4] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Date: Mon, 20 Jul 2020 13:22:43 -0700 Message-Id: <20200720202243.180230-5-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200720202243.180230-1-linux@roeck-us.net> References: <20200720202243.180230-1-linux@roeck-us.net> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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. Cc: Yu-Hsuan Hsu Cc: Prashant Malani Signed-off-by: Guenter Roeck --- v2: No change Notes: I would welcome feedback on the error code translations. Can we do better ? -ENOTSUPP is not a recommended error code, and checkpatch complains about it. It is used in existing code, so I did not change it, but it might be worthwhile exploring if we can find a better error code to report "version not supported". Possible candidates might be EPROTOTYPE, ENOPROTOOPT, EPROTONOSUPPORT, EPFNOSUPPORT, or EAFNOSUPPORT. I don't see a direct match, but NFS reports -EPROTONOSUPPORT for unsupported protocol versions. drivers/platform/chrome/cros_ec_proto.c | 37 +++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 3e745e0fe092..10aa9e483d35 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -543,6 +543,29 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, } EXPORT_SYMBOL(cros_ec_cmd_xfer); +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] = -ENOTSUPP, + [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, +}; + /** * cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC. * @ec_dev: EC device. @@ -555,8 +578,7 @@ EXPORT_SYMBOL(cros_ec_cmd_xfer); * * Return: * >=0 - The number of bytes transferred - * -ENOTSUPP - 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,13 +588,12 @@ 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 -ENOTSUPP; } else if (msg->result != EC_RES_SUCCESS) { - dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result); - return -EPROTO; + if (msg->result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[msg->result]) + ret = cros_ec_error_map[msg->result]; + else + ret = -EPROTO; + dev_dbg(ec_dev->dev, "Command result (err: %d [%d])\n", msg->result, ret); } return ret;