Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3140343ybt; Sat, 4 Jul 2020 07:27:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOP1fLNg/nv5lLnZ9m1ZiEKK/xcindoZCxa14XpUVG23QYO5j7ZZGoFSHExRbv/SD7Gh1J X-Received: by 2002:aa7:d0d1:: with SMTP id u17mr45759234edo.13.1593872838883; Sat, 04 Jul 2020 07:27:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593872838; cv=none; d=google.com; s=arc-20160816; b=ZI50VARE58FufdjJQ5a9r4Y0/xFMd55wzYzfOyYxZUAk2LqlVnsInm0bKOS1qAHGEP Wlhpk9rWSJLe+x7gQJJI4TvIMvTWt7EzalOjEjaB00c++wOYQ+2WtttHEM3wfAr3P4Vr NUtD5KZb9RICuLpi9FuyWaz3a2FGiPyON6duO/x6HQ3nzMUGrkVdDmSYxu4o9Irbhyf3 MupceczBZL8G3PzYC91mHFGy0R6TnrqX3uO9A2ZbmktIMi9JoAGv3XVUuvdD2Bf90flP 8m1Xc/NVVwwm38pHQvCvVtDYxzcibjc2uKg98bUlvX4AxmX7rMP+kWCTVSOUdU6bIey3 OJFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=sJThXt18vj76dxg1XcYlMwFo2sABsgrySSJXPsuoOYY=; b=SwyhLK8mg5KrI05Px9JQLsJeSaijP/hMPeXkM06u/J5zhztQR7QG8/AOMrRaD6PHHd gEkF9xNlK3AnBOI8kduvfoGbod2KWGvH7CfwNQlLV4jqTy4HjJeAL3MEzCv/l7OuVJbo E0wt8PQc6iKetOnLJf39Z072zPSemBa9zsjhD+rjGhJeVdg6qtfrCiLtEJZdv9B1xENI T7HfOHoXsjjFYp3BnZcgzhpJIzcSso2mAQexTXtmXJR1kH8IypBoPBAcOT0h/8zqemR8 ZyK6+r+fMCXfSdRThcDDinXdqhduKFnXqn8vitnVfYZ4BJ4yz5mwMtEvVlctJcFbofbj 5XmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=maMritpN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si10336929edv.318.2020.07.04.07.26.56; Sat, 04 Jul 2020 07:27:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=maMritpN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726831AbgGDO0L (ORCPT + 99 others); Sat, 4 Jul 2020 10:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbgGDO0K (ORCPT ); Sat, 4 Jul 2020 10:26:10 -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 ABB70C061794 for ; Sat, 4 Jul 2020 07:26:10 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id t15so727452pjq.5 for ; Sat, 04 Jul 2020 07:26:10 -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; bh=sJThXt18vj76dxg1XcYlMwFo2sABsgrySSJXPsuoOYY=; b=maMritpNagy30HECmq6aoOT2GspL3it8/9m5yAxAVDOG8QZocql/yeZ2/WNGd8lUVa u+XXqRTIpdF1HoajLLLk1rm8R5FfBBKc3CEbM7KZVIlwXJeT2RshCn5nNRj+jZpc52vQ Zt3FPqA7ZNPpXTXgVPyVgrBFG2YdMcAXW/i3XQlOWprHufsPXXk9WVCqBgxwYFiqfNhE ro6chsTbVP1hAThtuXxCOLjGmt2KnV5NHsC1MGE9HWyTNrEH4ZJALLEtYlyL2ksrQyGV UTvNpeOxkd0DZSsxohxpcbTuaW/PMuWiciJUl3QtiBRJUjOrEbQKJfiOuzG4a2pFCzhO Ip4Q== 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; bh=sJThXt18vj76dxg1XcYlMwFo2sABsgrySSJXPsuoOYY=; b=ItZXbhnNpJ9nuXjXDXZmpIZJ2l6PGqoIi86aInmuipEGN1fPiQ67h2JZCqx8NV0+Ji tmvj3nOpPsZPi6Dp6+IjVl40DHrnqAkFN9HOLEfWHCdj9Ra4swcXHtgWAhlBdJmtcZsD TQm7jhdHrulX3ag7D0bQunsGCX4nztlb+7Szax2ESCjgxdWAgEUajpXsQEPM/BNXq+L6 rkabFPv40S/WTjWVacZ7ukKPDbnDKw5xq5En1YObsMsizxRvCMe8cXQTn8dDZu97PM7v zfaNX8Hco9wQzXvEPZieQnxcs7QacMe5W3zdmRvoRW8DRA/Ia9+kv4jr5lSn0fh7iv2H joxQ== X-Gm-Message-State: AOAM533yhufdIVOIru6oQSc79p71JMoNkAcIZYwQryjOncPrQ5SYs5OC 5Rbuwf5hcx65xuqJZXDc1Kw= X-Received: by 2002:a17:902:d896:: with SMTP id b22mr35085917plz.87.1593872770214; Sat, 04 Jul 2020 07:26:10 -0700 (PDT) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id t1sm15022776pgq.66.2020.07.04.07.26.08 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 04 Jul 2020 07:26:09 -0700 (PDT) From: Guenter Roeck To: Enric Balletbo i Serra Cc: Benson Leung , linux-kernel@vger.kernel.org, Guenter Roeck , Yu-Hsuan Hsu , Prashant Malani Subject: [PATCH] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes Date: Sat, 4 Jul 2020 07:26:07 -0700 Message-Id: <20200704142607.171400-1-linux@roeck-us.net> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. 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 --- 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; -- 2.17.1