Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp905667ybt; Tue, 7 Jul 2020 03:13:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyankrxabGywJUs5fcT4fpreaU/wH9Vfx7ACdLCimjC/AkH3Qxb4cU4HjG17LQzj25f0fjE X-Received: by 2002:a17:906:191a:: with SMTP id a26mr48776882eje.315.1594116819446; Tue, 07 Jul 2020 03:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594116819; cv=none; d=google.com; s=arc-20160816; b=pgbiiJ+yx98sE0QIon2+a/6n/L2T4hAaFzBW2C5Ek5m/OknDs6tO7+c7U7zq6JJ3+7 YFpZa8nCB1hZOJ0fuV2xb0ZmeHjwxzKjO26X81osrF6q1mh65PbfhW+02aQs6mP/iy8z FyceGNuoOSBnXibBByYNzQsGLexGma06Z+N8A6XG39+M6/whnU1A9JDbwei5P0OSXzSs yeyKErU9MTK/6Pos8kmYhrTfFvtCqcTBp+1N6UBdtXSd8EfqUbE3sfxOlWbEhiN7Vgc6 URPeMK8/22UlmEboiMuWPYQQQsqCwuy0IVzqom7XzK4Y/VV0s+5F95hA3vQK5ljGZcv0 iT0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=1MgrNoeiTMBXORKer/yOfGylDU6Np5T1leDURVvvqMg=; b=FbZewRJRZCGMM0p7aKETmeKQsGytiwlbSOui7PcMmzQYYFu+N3zQQmd/Y3SXmk4bET CG9yv7vDx/+ol5qtvsMtr5FLVNSqeAVcmRCUda7hv/MCeDD0UR7uTrd7yrrQa/jpLyPJ LRKg5us1oCjfAxGb0DOyiHhL07UnuQ/Vshf5Dt8r4sN2y5JrbgH185u/z+9V1KSW61hf PG7zVBKkuySMPhQSVNiYsy9ZtjkAH08gyuVsCXQ0FIKlZTE/7XbYXjIBkzLPm3dzOWeA csgPgRbBBXVYBXan4OGQjrWAjjes8KiJMxiytLnzaSNbFK2FAdgDgCy4MXVP7fh0H6c0 LHLg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y17si14437527edw.91.2020.07.07.03.13.16; Tue, 07 Jul 2020 03:13:39 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728061AbgGGKK6 (ORCPT + 99 others); Tue, 7 Jul 2020 06:10:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725941AbgGGKK6 (ORCPT ); Tue, 7 Jul 2020 06:10:58 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2ED3C061755 for ; Tue, 7 Jul 2020 03:10:57 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 87E242A5112 Subject: Re: [PATCH] platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes To: Guenter Roeck Cc: Benson Leung , linux-kernel@vger.kernel.org, Yu-Hsuan Hsu , Prashant Malani References: <20200704142607.171400-1-linux@roeck-us.net> From: Enric Balletbo i Serra Message-ID: <7fd5528a-017e-d706-8092-8e1d6b187243@collabora.com> Date: Tue, 7 Jul 2020 12:10:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200704142607.171400-1-linux@roeck-us.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Prashant and Guenter, Thank you to spend your time on look at this. On 4/7/20 16:26, 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. 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 > --- For me the patch looks good as is. Said that, I'd like to discuss a bit more (but not too much) about it :-). My "concerns" are: - It is not clear to me if some EC errors match directly to a linux kernel error codes, the importance of them, and which action should be taken in that case or if just reporting is enough. - The EC result can be obtained, either, enabling more debug traces or using the linux kernel tracing tools. So, IMO mapping _all_ the errors has very little value. Right now, the policy I followed is return -EPROTO for all EC errors and introduce/match a new error when someone (another kernel driver or userspace needs to know about it, i.e [1], where some EC drivers do different actions if -ENOTSUPP is returned). We introduced that error because we had a use case for it. The future, I'd like to maintain this policy if it makes sense to you. And introduce a new error when we have a use case for it. I.e if at some point a kernel driver needs to know when the EC is busy (-EBUSY) because the driver waits and retries again, I'll be fine to introduce this new error/match code. Otherwise, I feel that has no really value. Said that, if you still feel, that this will help you for debugging purposes, I am completely fine to pick the patch. Thoughts? Thanks, Enric [1] commit c5cd2b47b203f63682778c2a1783198e6b644294 Author: Enric Balletbo i Serra Date: Thu Feb 20 16:58:52 2020 +0100 platform/chrome: cros_ec_proto: Report command not supported In practice most drivers that use the EC protocol what really care is if the result was successful or not, hence, we introduced a cros_ec_cmd_xfer_status() function that converts EC errors to standard Linux error codes. On some few cases, though, we are interested on know if the command is supported or not, and in such cases, just ignore the error. To achieve this, return a -ENOTSUPP error when the command is not supported. > 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; >