From patchwork Mon Jul 18 05:09:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920720 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97837A47 for ; Mon, 18 Jul 2022 05:10:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6133CC341CA; Mon, 18 Jul 2022 05:10:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121008; bh=pVG8rW+S0oNjgp6FHgiutzZNiAPcjJzWkFPlQQkw1WQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RDQ8O8553aGFHHHoPoseAb6SH31h8CPVPrz+K61bBSYWrAAejRB/0bQ0+q2CMlQi+ LWS59Bm315fRZcZP6u1Th1xEcAoNT+Ur9y7Nm7t+t1IevDGVT3FoqdJ/LVBNTI2lVK wbDbUxnAtDUOYcdenlR1lCiEkl6YN7JLgk3s/TOB/Nz7DMNnksom61tfPwol9ylICu OqPMnfvZDD96k8tHj/bx1rNWs04rHrrULBu3BC/YrHJW7E9i0N0yOef24pSEgIa07t 04BElEBkPHdlV336XXNtCqNrWfpd1cY2tMtr7JBCe96fOdnp60Z3WyD9d/OUlJoSVy 5SD0FE4nvlNQQ== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/10] platform/chrome: cros_kunit_util: add default value for `msg->result` Date: Mon, 18 Jul 2022 05:09:05 +0000 Message-Id: <20220718050914.2267370-2-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add default value for `msg->result` so that it won't be garbage bytes when the mock list is empty. Signed-off-by: Tzung-Bi Shih --- No v1. New in the series. drivers/platform/chrome/cros_kunit_util.c | 7 ++++++- drivers/platform/chrome/cros_kunit_util.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_kunit_util.c b/drivers/platform/chrome/cros_kunit_util.c index e031777dea87..6810d558d462 100644 --- a/drivers/platform/chrome/cros_kunit_util.c +++ b/drivers/platform/chrome/cros_kunit_util.c @@ -13,6 +13,8 @@ #include "cros_ec.h" #include "cros_kunit_util.h" +int cros_kunit_ec_xfer_mock_default_result; +EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_default_result); int cros_kunit_ec_xfer_mock_default_ret; EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_default_ret); @@ -24,8 +26,10 @@ int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_comman struct ec_xfer_mock *mock; mock = list_first_entry_or_null(&cros_kunit_ec_xfer_mock_in, struct ec_xfer_mock, list); - if (!mock) + if (!mock) { + msg->result = cros_kunit_ec_xfer_mock_default_result; return cros_kunit_ec_xfer_mock_default_ret; + } list_del(&mock->list); @@ -89,6 +93,7 @@ EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_next); void cros_kunit_mock_reset(void) { + cros_kunit_ec_xfer_mock_default_result = 0; cros_kunit_ec_xfer_mock_default_ret = 0; INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in); INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out); diff --git a/drivers/platform/chrome/cros_kunit_util.h b/drivers/platform/chrome/cros_kunit_util.h index 79c4525f873c..79c4f259f2bb 100644 --- a/drivers/platform/chrome/cros_kunit_util.h +++ b/drivers/platform/chrome/cros_kunit_util.h @@ -23,6 +23,7 @@ struct ec_xfer_mock { u32 o_data_len; }; +extern int cros_kunit_ec_xfer_mock_default_result; extern int cros_kunit_ec_xfer_mock_default_ret; int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); From patchwork Mon Jul 18 05:09:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920721 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3E4CA47 for ; Mon, 18 Jul 2022 05:10:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B18AC341CE; Mon, 18 Jul 2022 05:10:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121009; bh=fkd2e0BODvoo+pEM/gTsjyNgH9JMUx2Ptnib31kv7Xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ey1hG32SqY4uQjvaRSjPGz1NNHTyCtqEdsl/8I2Xaq+DSmmCKOOZQHVD+aEqAwrHY uKx/iQdbUH38tlhHan+zYxgp/6TT9ZtmwALNVPLrFJq+zQTKq9Oq8QJCm1vQVjcqFN FjUx36he4LLgfDOhT6MwMp28Aq4dONQ/kHKfQnjn1de05Wwyd8LcXaqLTuQZ+Ox03L 1aQLCwHLuGSgQWxF8HQcflxv8LnGXDe0NETemUO8vSaVuBmfBrT68nNpjmGK+InTD8 g1JAcAlSuEvRiUsURO+cD0lqAuRjLB4aNokdumxRYClNpMpaOTn/IHI+6TleLEPF0t FfEUsC7WnuGTA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/10] platform/chrome: cros_ec_proto: add "cros_ec_" prefix to send_command() Date: Mon, 18 Jul 2022 05:09:06 +0000 Message-Id: <20220718050914.2267370-3-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To be neat, add "cros_ec_" prefix to static function send_command(). Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v1: - Add R-b tag. drivers/platform/chrome/cros_ec_proto.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 6923ea4401e5..b02fd1414e52 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -107,8 +107,7 @@ static int prepare_tx_legacy(struct cros_ec_device *ec_dev, return EC_MSG_TX_PROTO_BYTES + msg->outsize; } -static int send_command(struct cros_ec_device *ec_dev, - struct cros_ec_command *msg) +static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) { int ret; int (*xfer_fxn)(struct cros_ec_device *ec, struct cros_ec_command *msg); @@ -255,7 +254,7 @@ static int cros_ec_get_host_event_wake_mask(struct cros_ec_device *ec_dev, uint3 msg->command = EC_CMD_HOST_EVENT_GET_WAKE_MASK; msg->insize = sizeof(*r); - ret = send_command(ec_dev, msg); + ret = cros_ec_send_command(ec_dev, msg); if (ret < 0) goto exit; @@ -295,7 +294,7 @@ static int cros_ec_get_proto_info(struct cros_ec_device *ec_dev, int devidx) msg->command = EC_CMD_PASSTHRU_OFFSET(devidx) | EC_CMD_GET_PROTOCOL_INFO; msg->insize = sizeof(*info); - ret = send_command(ec_dev, msg); + ret = cros_ec_send_command(ec_dev, msg); /* * Send command once again when timeout occurred. * Fingerprint MCU (FPMCU) is restarted during system boot which @@ -304,7 +303,7 @@ static int cros_ec_get_proto_info(struct cros_ec_device *ec_dev, int devidx) * attempt because we waited at least EC_MSG_DEADLINE_MS. */ if (ret == -ETIMEDOUT) - ret = send_command(ec_dev, msg); + ret = cros_ec_send_command(ec_dev, msg); if (ret < 0) { dev_dbg(ec_dev->dev, @@ -376,7 +375,7 @@ static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev) params = (struct ec_params_hello *)msg->data; params->in_data = 0xa0b0c0d0; - ret = send_command(ec_dev, msg); + ret = cros_ec_send_command(ec_dev, msg); if (ret < 0) { dev_dbg(ec_dev->dev, "EC failed to respond to v2 hello: %d\n", ret); goto exit; @@ -453,7 +452,7 @@ static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev, pver = (struct ec_params_get_cmd_versions *)msg->data; pver->cmd = cmd; - ret = send_command(ec_dev, msg); + ret = cros_ec_send_command(ec_dev, msg); if (ret < 0) goto exit; @@ -634,7 +633,7 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) } } - ret = send_command(ec_dev, msg); + ret = cros_ec_send_command(ec_dev, msg); mutex_unlock(&ec_dev->lock); return ret; From patchwork Mon Jul 18 05:09:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920722 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4546A46 for ; Mon, 18 Jul 2022 05:10:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4FD0C341C0; Mon, 18 Jul 2022 05:10:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121010; bh=IUxdR7ZbjimWcL8ZjQCwdKb2eqDx6YCX80muuZ1SjjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SilUXi3XfsrVylqz1R9LBFutwRFoQEdKX9DC2quQPcSXdFAoPq2iPapJxz32zklvI HORu9XO8c+yn1MmV2t3ig4P3m5hdkBkETfU+Eloi2SA2swQ7xfO8JsnXrN1AJ3ea/Z 5v5Rg8trDPzyrdJb6NGP/yqFzgSo5cbkQTs8C515kwPk2WKj1H+UjfL2XFEnfK7+Vp iZ0GWKvY6ZDrHzjLRHw9QkGkAJppo3mLoFRfQ7BqHBVLFtjdoVFdR6GhGEUaaWGc5I xcj77cVoZ+9HahvhuKaR2SY9nIR3UKZIE5ozQtelGoJgNfYpW9dc/QoY5hMm8K9SHe OBw0kjJRgAhQA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/10] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_cmd_xfer() Date: Mon, 18 Jul 2022 05:09:07 +0000 Message-Id: <20220718050914.2267370-4-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cros_ec_cmd_xfer() transfers the given command and data if any. It performs some sanity checks and calls cros_ec_send_command(). Add Kunit tests for cros_ec_cmd_xfer(). Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v1: - Add R-b tag. drivers/platform/chrome/cros_ec_proto_test.c | 149 +++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index 1e2a1522c288..33721607a5b9 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -1535,6 +1535,151 @@ static void cros_ec_proto_test_query_all_default_wake_mask_return0(struct kunit } } +static void cros_ec_proto_test_cmd_xfer_normal(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct { + struct cros_ec_command msg; + u8 data[0x100]; + } __packed buf; + + ec_dev->max_request = 0xff; + ec_dev->max_response = 0xee; + ec_dev->max_passthru = 0xdd; + + buf.msg.version = 0; + buf.msg.command = EC_CMD_HELLO; + buf.msg.insize = 4; + buf.msg.outsize = 2; + buf.data[0] = 0x55; + buf.data[1] = 0xaa; + + { + u8 *data; + + mock = cros_kunit_ec_xfer_mock_add(test, 4); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + + data = (u8 *)mock->o_data; + data[0] = 0xaa; + data[1] = 0x55; + data[2] = 0xcc; + data[3] = 0x33; + } + + ret = cros_ec_cmd_xfer(ec_dev, &buf.msg); + KUNIT_EXPECT_EQ(test, ret, 4); + + { + u8 *data; + + mock = cros_kunit_ec_xfer_mock_next(); + KUNIT_EXPECT_PTR_NE(test, mock, NULL); + + KUNIT_EXPECT_EQ(test, mock->msg.version, 0); + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_HELLO); + KUNIT_EXPECT_EQ(test, mock->msg.insize, 4); + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 2); + + data = (u8 *)mock->i_data; + KUNIT_EXPECT_EQ(test, data[0], 0x55); + KUNIT_EXPECT_EQ(test, data[1], 0xaa); + + KUNIT_EXPECT_EQ(test, buf.data[0], 0xaa); + KUNIT_EXPECT_EQ(test, buf.data[1], 0x55); + KUNIT_EXPECT_EQ(test, buf.data[2], 0xcc); + KUNIT_EXPECT_EQ(test, buf.data[3], 0x33); + } +} + +static void cros_ec_proto_test_cmd_xfer_excess_msg_insize(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct { + struct cros_ec_command msg; + u8 data[0x100]; + } __packed buf; + + ec_dev->max_request = 0xff; + ec_dev->max_response = 0xee; + ec_dev->max_passthru = 0xdd; + + buf.msg.version = 0; + buf.msg.command = EC_CMD_HELLO; + buf.msg.insize = 0xee + 1; + buf.msg.outsize = 2; + + { + mock = cros_kunit_ec_xfer_mock_add(test, 0xcc); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + ret = cros_ec_cmd_xfer(ec_dev, &buf.msg); + KUNIT_EXPECT_EQ(test, ret, 0xcc); + + { + mock = cros_kunit_ec_xfer_mock_next(); + KUNIT_EXPECT_PTR_NE(test, mock, NULL); + + KUNIT_EXPECT_EQ(test, mock->msg.version, 0); + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_HELLO); + KUNIT_EXPECT_EQ(test, mock->msg.insize, 0xee); + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 2); + } +} + +static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_without_passthru(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + int ret; + struct { + struct cros_ec_command msg; + u8 data[0x100]; + } __packed buf; + + ec_dev->max_request = 0xff; + ec_dev->max_response = 0xee; + ec_dev->max_passthru = 0xdd; + + buf.msg.version = 0; + buf.msg.command = EC_CMD_HELLO; + buf.msg.insize = 4; + buf.msg.outsize = 0xff + 1; + + ret = cros_ec_cmd_xfer(ec_dev, &buf.msg); + KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE); +} + +static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthru(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + int ret; + struct { + struct cros_ec_command msg; + u8 data[0x100]; + } __packed buf; + + ec_dev->max_request = 0xff; + ec_dev->max_response = 0xee; + ec_dev->max_passthru = 0xdd; + + buf.msg.version = 0; + buf.msg.command = EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) + EC_CMD_HELLO; + buf.msg.insize = 4; + buf.msg.outsize = 0xdd + 1; + + ret = cros_ec_cmd_xfer(ec_dev, &buf.msg); + KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE); +} + static void cros_ec_proto_test_release(struct device *dev) { } @@ -1601,6 +1746,10 @@ static struct kunit_case cros_ec_proto_test_cases[] = { KUNIT_CASE(cros_ec_proto_test_query_all_no_host_sleep_return0), KUNIT_CASE(cros_ec_proto_test_query_all_default_wake_mask_return_error), KUNIT_CASE(cros_ec_proto_test_query_all_default_wake_mask_return0), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_normal), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_excess_msg_insize), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_excess_msg_outsize_without_passthru), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthru), {} }; From patchwork Mon Jul 18 05:09:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920723 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 288ECA46 for ; Mon, 18 Jul 2022 05:10:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AA06C341CD; Mon, 18 Jul 2022 05:10:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121012; bh=OFNFUOfkUXPHHG9R19TPDPEei1yRlrQ1+RSXitJR40U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KyZ6zFte/VR8ooqF1VBwHoM7aGjvmzQt9c1z/w6hZoIQosIu6pPz/RxF7CWwx2ENV si4wOvjgeOvDCSBSfjVPKOOPy6DNkH+qkiedFg0doc3RtZO/1ChACPEbMkKjfEl6wK kArRg8h3+jIxIlkn2s1PXijAd3WPBtvyh2rPosHc+aVG+qE3aZVLHWzU0JvP64s3QM it/0Owxl4wgAV9bWBVkH7DkUz9+4Nwo3oBTzWjXw1Ze8Rv18diQEsktI+9AdfK/4+3 3Smi0Cz2WFeOVMiVvD9uLc54CyZJEdj/QR4av7xrxwKoElUZQkRm74Re95l5QxymXP KBhWE6qU5gQJQ== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/10] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_send_command() Date: Mon, 18 Jul 2022 05:09:08 +0000 Message-Id: <20220718050914.2267370-5-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cros_ec_cmd_xfer() is the only exported function that calls static function cros_ec_send_command(). Add Kunit tests for cros_ec_send_command() through calling cros_ec_cmd_xfer(). Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v1: - Add R-b tag. drivers/platform/chrome/cros_ec_proto_test.c | 265 +++++++++++++++++++ drivers/platform/chrome/cros_kunit_util.c | 20 ++ drivers/platform/chrome/cros_kunit_util.h | 4 + 3 files changed, 289 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index 33721607a5b9..64100fd81c6a 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -1680,6 +1680,262 @@ static void cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthru(struct KUNIT_EXPECT_EQ(test, ret, -EMSGSIZE); } +static void cros_ec_proto_test_cmd_xfer_protocol_v3_normal(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->proto_version = 3; + ec_dev->cmd_xfer = cros_kunit_ec_cmd_xfer_mock; + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, cros_kunit_ec_cmd_xfer_mock_called, 0); + KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 1); +} + +static void cros_ec_proto_test_cmd_xfer_protocol_v3_no_op(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->proto_version = 3; + ec_dev->cmd_xfer = cros_kunit_ec_cmd_xfer_mock; + ec_dev->pkt_xfer = NULL; + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, -EIO); +} + +static void cros_ec_proto_test_cmd_xfer_protocol_v2_normal(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->proto_version = 2; + ec_dev->cmd_xfer = cros_kunit_ec_cmd_xfer_mock; + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, cros_kunit_ec_cmd_xfer_mock_called, 1); + KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 0); +} + +static void cros_ec_proto_test_cmd_xfer_protocol_v2_no_op(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->proto_version = 2; + ec_dev->cmd_xfer = NULL; + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, -EIO); +} + +static void cros_ec_proto_test_cmd_xfer_in_progress_normal(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + /* For the first host command to return EC_RES_IN_PROGRESS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, 0, EC_RES_IN_PROGRESS, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + /* For EC_CMD_GET_COMMS_STATUS. */ + { + struct ec_response_get_comms_status *data; + + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data)); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + + data = (struct ec_response_get_comms_status *)mock->o_data; + data->flags = 0; + } + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_comms_status)); + + KUNIT_EXPECT_EQ(test, msg.result, EC_RES_SUCCESS); + + /* For the first host command to return EC_RES_IN_PROGRESS. */ + { + mock = cros_kunit_ec_xfer_mock_next(); + KUNIT_EXPECT_PTR_NE(test, mock, NULL); + } + + /* For EC_CMD_GET_COMMS_STATUS. */ + { + mock = cros_kunit_ec_xfer_mock_next(); + KUNIT_EXPECT_PTR_NE(test, mock, NULL); + + KUNIT_EXPECT_EQ(test, mock->msg.version, 0); + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_COMMS_STATUS); + KUNIT_EXPECT_EQ(test, mock->msg.insize, + sizeof(struct ec_response_get_comms_status)); + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0); + } + + KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 2); +} + +static void cros_ec_proto_test_cmd_xfer_in_progress_retries_eagain(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + /* For the first host command to return EC_RES_IN_PROGRESS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, 0, EC_RES_IN_PROGRESS, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + /* For EC_CMD_GET_COMMS_STATUS EC_COMMAND_RETRIES times. */ + cros_kunit_ec_xfer_mock_default_ret = -EAGAIN; + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, -EAGAIN); + + /* For EC_CMD_GET_COMMS_STATUS EC_COMMAND_RETRIES times. */ + KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 51); +} + +static void cros_ec_proto_test_cmd_xfer_in_progress_retries_status_processing(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + /* For the first host command to return EC_RES_IN_PROGRESS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, 0, EC_RES_IN_PROGRESS, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + /* For EC_CMD_GET_COMMS_STATUS EC_COMMAND_RETRIES times. */ + { + struct ec_response_get_comms_status *data; + int i; + + for (i = 0; i < 50; ++i) { + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data)); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + + data = (struct ec_response_get_comms_status *)mock->o_data; + data->flags |= EC_COMMS_STATUS_PROCESSING; + } + } + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_comms_status)); + + KUNIT_EXPECT_EQ(test, msg.result, EC_RES_SUCCESS); + + /* For EC_CMD_GET_COMMS_STATUS EC_COMMAND_RETRIES times. */ + KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 51); +} + +static void cros_ec_proto_test_cmd_xfer_in_progress_xfer_error(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + /* For the first host command to return EC_RES_IN_PROGRESS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, 0, EC_RES_IN_PROGRESS, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + /* For EC_CMD_GET_COMMS_STATUS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, -EIO, EC_RES_SUCCESS, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, -EIO); +} + +static void cros_ec_proto_test_cmd_xfer_in_progress_return_error(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + /* For the first host command to return EC_RES_IN_PROGRESS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, 0, EC_RES_IN_PROGRESS, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + /* For EC_CMD_GET_COMMS_STATUS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, 0, EC_RES_INVALID_COMMAND, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, msg.result, EC_RES_INVALID_COMMAND); + + KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 2); +} + static void cros_ec_proto_test_release(struct device *dev) { } @@ -1750,6 +2006,15 @@ static struct kunit_case cros_ec_proto_test_cases[] = { KUNIT_CASE(cros_ec_proto_test_cmd_xfer_excess_msg_insize), KUNIT_CASE(cros_ec_proto_test_cmd_xfer_excess_msg_outsize_without_passthru), KUNIT_CASE(cros_ec_proto_test_cmd_xfer_excess_msg_outsize_with_passthru), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_protocol_v3_normal), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_protocol_v3_no_op), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_protocol_v2_normal), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_protocol_v2_no_op), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_normal), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_retries_eagain), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_retries_status_processing), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_xfer_error), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return_error), {} }; diff --git a/drivers/platform/chrome/cros_kunit_util.c b/drivers/platform/chrome/cros_kunit_util.c index 6810d558d462..e6a0a1b4ed4b 100644 --- a/drivers/platform/chrome/cros_kunit_util.c +++ b/drivers/platform/chrome/cros_kunit_util.c @@ -17,6 +17,10 @@ int cros_kunit_ec_xfer_mock_default_result; EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_default_result); int cros_kunit_ec_xfer_mock_default_ret; EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_default_ret); +int cros_kunit_ec_cmd_xfer_mock_called; +EXPORT_SYMBOL_GPL(cros_kunit_ec_cmd_xfer_mock_called); +int cros_kunit_ec_pkt_xfer_mock_called; +EXPORT_SYMBOL_GPL(cros_kunit_ec_pkt_xfer_mock_called); static struct list_head cros_kunit_ec_xfer_mock_in; static struct list_head cros_kunit_ec_xfer_mock_out; @@ -50,6 +54,20 @@ int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_comman } EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock); +int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +{ + ++cros_kunit_ec_cmd_xfer_mock_called; + return cros_kunit_ec_xfer_mock(ec_dev, msg); +} +EXPORT_SYMBOL_GPL(cros_kunit_ec_cmd_xfer_mock); + +int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +{ + ++cros_kunit_ec_pkt_xfer_mock_called; + return cros_kunit_ec_xfer_mock(ec_dev, msg); +} +EXPORT_SYMBOL_GPL(cros_kunit_ec_pkt_xfer_mock); + struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size) { return cros_kunit_ec_xfer_mock_addx(test, size, EC_RES_SUCCESS, size); @@ -95,6 +113,8 @@ void cros_kunit_mock_reset(void) { cros_kunit_ec_xfer_mock_default_result = 0; cros_kunit_ec_xfer_mock_default_ret = 0; + cros_kunit_ec_cmd_xfer_mock_called = 0; + cros_kunit_ec_pkt_xfer_mock_called = 0; INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_in); INIT_LIST_HEAD(&cros_kunit_ec_xfer_mock_out); } diff --git a/drivers/platform/chrome/cros_kunit_util.h b/drivers/platform/chrome/cros_kunit_util.h index 79c4f259f2bb..85e2974fd048 100644 --- a/drivers/platform/chrome/cros_kunit_util.h +++ b/drivers/platform/chrome/cros_kunit_util.h @@ -25,8 +25,12 @@ struct ec_xfer_mock { extern int cros_kunit_ec_xfer_mock_default_result; extern int cros_kunit_ec_xfer_mock_default_ret; +extern int cros_kunit_ec_cmd_xfer_mock_called; +extern int cros_kunit_ec_pkt_xfer_mock_called; int cros_kunit_ec_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); +int cros_kunit_ec_cmd_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); +int cros_kunit_ec_pkt_xfer_mock(struct cros_ec_device *ec_dev, struct cros_ec_command *msg); struct ec_xfer_mock *cros_kunit_ec_xfer_mock_add(struct kunit *test, size_t size); struct ec_xfer_mock *cros_kunit_ec_xfer_mock_addx(struct kunit *test, int ret, int result, size_t size); From patchwork Mon Jul 18 05:09:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920724 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 781D5A48 for ; Mon, 18 Jul 2022 05:10:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54BC1C341C0; Mon, 18 Jul 2022 05:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121013; bh=2AJY7UOnSKuVvqFNVT9weNxjX2Q/FUV/Ywaba8qJwe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gi9NsWl51RzQUiOJkTIXynCcezX0o2fvnsGpgqsFQiz1Ce7V4boJJmzU1RpHsjyHK Y92DRFJ1H4EtqRFMtV2NTrSzNbq/bV20Yc5AvkOPwRoXu1xeQVyHbpnnh3TdeNe+bd 7DY0d9dPcxSGjzSsaeZqcTU159t7hXSpMSarG+GqwC8YmBy3dMjsH1KZ6P83C59jQ6 /XepllLVo5AI66Sywu51H0AbWfjoVczutp1OCCLuchoUJce1NIHaHlz2G4EtSOA/lk en5eyUswjtGg5sqeUK87C7UU+HWr3rz2MEvsjvmNnJc743RupLrnHu8sROI7ZIGqPe LsJMejJWt9+fQ== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/10] platform/chrome: cros_ec_proto: separate cros_ec_xfer_command() Date: Mon, 18 Jul 2022 05:09:09 +0000 Message-Id: <20220718050914.2267370-6-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cros_ec_send_command() has extra logic to handle EC_RES_IN_PROGRESS. Separate the command transfer part into cros_ec_xfer_command() so that other functions can re-use it. Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v1: - Add R-b tag. drivers/platform/chrome/cros_ec_proto.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index b02fd1414e52..0cec013be3d3 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -107,7 +107,7 @@ static int prepare_tx_legacy(struct cros_ec_device *ec_dev, return EC_MSG_TX_PROTO_BYTES + msg->outsize; } -static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +static int cros_ec_xfer_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) { int ret; int (*xfer_fxn)(struct cros_ec_device *ec, struct cros_ec_command *msg); @@ -123,14 +123,21 @@ static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_co * the EC is trying to use protocol v2, on an underlying * communication mechanism that does not support v2. */ - dev_err_once(ec_dev->dev, - "missing EC transfer API, cannot send command\n"); + dev_err_once(ec_dev->dev, "missing EC transfer API, cannot send command\n"); return -EIO; } trace_cros_ec_request_start(msg); ret = (*xfer_fxn)(ec_dev, msg); trace_cros_ec_request_done(msg, ret); + + return ret; +} + +static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +{ + int ret = cros_ec_xfer_command(ec_dev, msg); + if (msg->result == EC_RES_IN_PROGRESS) { int i; struct cros_ec_command *status_msg; From patchwork Mon Jul 18 05:09:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920725 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EBE7A47 for ; Mon, 18 Jul 2022 05:10:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EE1AC341CA; Mon, 18 Jul 2022 05:10:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121014; bh=O6BmjsqSJ+Huo3HjurXfnhr+k1oxAIxru4gq3B0ygJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HlnGHh1dyoOsNJ8jabgwfEh5st3eqslRLD8gYT+5/gL0SUlD1/EdKaNNyGENcwsT2 iaIH8QXPRuz+38hfjVcjHTKdf5kcHzeaDc43brPoyE84v7FzCl84Nbv5zxj1Idm16b n/oqw8vhptjXEzgIkDX169v5nfdPeDyj2/9yBsqZ24d2l5cXXBwp+0mFpDdHo+codl iu32AxaeAqIds9sn6cAfGz4vOw84t0tOUQQswp0Ooc1wgimwLj9VwT51vchdamrxew h02z3FvDT+v3QuR89CiQre5tyFxLwO1Gw6AKdhafK/Xy5rvf8gYhLroAwu/Vt/N7uy SS1H/Q/UU/5uw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/10] platform/chrome: cros_ec_proto: separate cros_ec_wait_until_complete() Date: Mon, 18 Jul 2022 05:09:10 +0000 Message-Id: <20220718050914.2267370-7-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 EC returns EC_RES_IN_PROGRESS if the host command needs more time to complete. Whenever receives the return code, cros_ec_send_command() sends EC_CMD_GET_COMMS_STATUS to query the command status. Separate cros_ec_wait_until_complete() from cros_ec_send_command(). It sends EC_CMD_GET_COMMS_STATUS and waits until the previous command was completed, or encountered error, or timed out. Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck --- Changes from v1: - Allocate buffer in cros_ec_wait_until_complete() statically. - Use `return ret` instead of `break` to make the intent explicit. drivers/platform/chrome/cros_ec_proto.c | 74 ++++++++++++------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 0cec013be3d3..a6ad7f7956e6 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -134,56 +134,52 @@ static int cros_ec_xfer_command(struct cros_ec_device *ec_dev, struct cros_ec_co return ret; } -static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *result) { - int ret = cros_ec_xfer_command(ec_dev, msg); + struct { + struct cros_ec_command msg; + struct ec_response_get_comms_status status; + } __packed buf; + struct cros_ec_command *msg = &buf.msg; + struct ec_response_get_comms_status *status = &buf.status; + int ret = 0, i; - if (msg->result == EC_RES_IN_PROGRESS) { - int i; - struct cros_ec_command *status_msg; - struct ec_response_get_comms_status *status; + msg->version = 0; + msg->command = EC_CMD_GET_COMMS_STATUS; + msg->insize = sizeof(*status); + msg->outsize = 0; - status_msg = kmalloc(sizeof(*status_msg) + sizeof(*status), - GFP_KERNEL); - if (!status_msg) - return -ENOMEM; + /* Query the EC's status until it's no longer busy or we encounter an error. */ + for (i = 0; i < EC_COMMAND_RETRIES; ++i) { + usleep_range(10000, 11000); - status_msg->version = 0; - status_msg->command = EC_CMD_GET_COMMS_STATUS; - status_msg->insize = sizeof(*status); - status_msg->outsize = 0; + ret = cros_ec_xfer_command(ec_dev, msg); + if (ret == -EAGAIN) + continue; + if (ret < 0) + return ret; - /* - * Query the EC's status until it's no longer busy or - * we encounter an error. - */ - for (i = 0; i < EC_COMMAND_RETRIES; i++) { - usleep_range(10000, 11000); - - trace_cros_ec_request_start(status_msg); - ret = (*xfer_fxn)(ec_dev, status_msg); - trace_cros_ec_request_done(status_msg, ret); - if (ret == -EAGAIN) - continue; - if (ret < 0) - break; - - msg->result = status_msg->result; - if (status_msg->result != EC_RES_SUCCESS) - break; - - status = (struct ec_response_get_comms_status *) - status_msg->data; - if (!(status->flags & EC_COMMS_STATUS_PROCESSING)) - break; - } + *result = msg->result; + if (msg->result != EC_RES_SUCCESS) + return ret; - kfree(status_msg); + if (!(status->flags & EC_COMMS_STATUS_PROCESSING)) + return ret; } return ret; } +static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg) +{ + int ret = cros_ec_xfer_command(ec_dev, msg); + + if (msg->result == EC_RES_IN_PROGRESS) + ret = cros_ec_wait_until_complete(ec_dev, &msg->result); + + return ret; +} + /** * cros_ec_prepare_tx() - Prepare an outgoing message in the output buffer. * @ec_dev: Device to register. From patchwork Mon Jul 18 05:09:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920726 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D47ADA47 for ; Mon, 18 Jul 2022 05:10:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C98B8C341D0; Mon, 18 Jul 2022 05:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121015; bh=AiSiBQ+ZaUZkBmavl4dmYj+PPOpZmD0zS6L5wecAMb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dl6hlM84u/rIJC03z6Acjppsw5YvKJqmX/f4eXYe8cxJtRQ9a83UHYRO06bf44hSq lg95VYqHbnPrkCPsH0qb3SOGOnCJ7Aye5lI9pLx6gVK1RRtUmUeCnxS9hIJ10pS8F/ jYSlK2O3j6z4/9vCZhaI6FGbQzG8wuSBidQmiUtpAOzg8zLeZNfqr0Tg/jefx8Jo6M nQ02D8lHWq27Eoqj9S/QiTmzoNU0NztX5WDKSlwn+zF3eFiLTLtDTS1Fuqj/f6mRXh I95bHfEm2UBS//PzDg5K0IyB4CS2hZ5Tpab5ZSRreJwO0LT+aLX3XIuR2On3Q8o8Rn DZCIP6gDPk2UA== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/10] platform/chrome: cros_ec_proto: change Kunit expectation when timed out Date: Mon, 18 Jul 2022 05:09:11 +0000 Message-Id: <20220718050914.2267370-8-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While EC_COMMS_STATUS_PROCESSING flag is still on after it tries EC_COMMAND_RETRIES times for sending EC_CMD_GET_COMMS_STATUS, cros_ec_wait_until_complete() doesn't return an error code. Change the expectation to an error code. Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v1: - Add R-b tag. drivers/platform/chrome/cros_ec_proto_test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index 64100fd81c6a..fbb872040711 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -1870,9 +1870,7 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_retries_status_processing(st } ret = cros_ec_cmd_xfer(ec_dev, &msg); - KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_comms_status)); - - KUNIT_EXPECT_EQ(test, msg.result, EC_RES_SUCCESS); + KUNIT_EXPECT_EQ(test, ret, -EAGAIN); /* For EC_CMD_GET_COMMS_STATUS EC_COMMAND_RETRIES times. */ KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 51); From patchwork Mon Jul 18 05:09:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920727 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BFCCA47 for ; Mon, 18 Jul 2022 05:10:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0ED59C341C8; Mon, 18 Jul 2022 05:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121016; bh=qZEfQmPuzobblfAILf3AUWXcuMaT0V6hEOUvHUNl8Wg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T9D2Uwy5Q9lasElEuSApy6N0MnUxH+mHQhsf1FmV3W1fqzsRDG9gIjgJFtRm3X7uy Kqrsth9rh+JoQ/g7RQicEjrvHB0xzTExvIKrJ91qRYi7aHZQ2z9+sEX71aGhub4VI7 jt89FUWYEsSQu2K01OWtXkSNi5I5+h+cPC0tA644n4H4zpnakVVPL6Js4/RbeXB9pA 5rElaI0ZfxT3GpNc4Rep6j6NBFlW45TliPKWfza/6CnGVAwvFu/8Yl1xKzKtSwuepL E2+BLj2I++0b1rMIEyKmO5qnl3DZlVsSFUiEy3bWNAb5rS4vlgbYw4BGHePnMtOW/A AB3ZX+PrTggAw== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/10] platform/chrome: cros_ec_proto: return -EAGAIN when retries timed out Date: Mon, 18 Jul 2022 05:09:12 +0000 Message-Id: <20220718050914.2267370-9-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While EC_COMMS_STATUS_PROCESSING flag is still on after it tries EC_COMMAND_RETRIES times for sending EC_CMD_GET_COMMS_STATUS, cros_ec_wait_until_complete() doesn't return an error code. Return -EAGAIN in the case instead. Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck --- No changes from v1. drivers/platform/chrome/cros_ec_proto.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index a6ad7f7956e6..9dec475edc84 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -167,6 +167,9 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t * return ret; } + if (i >= EC_COMMAND_RETRIES) + ret = -EAGAIN; + return ret; } From patchwork Mon Jul 18 05:09:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920728 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59A94A47 for ; Mon, 18 Jul 2022 05:10:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48F18C341D1; Mon, 18 Jul 2022 05:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121018; bh=nL2IFLAzOr5cOIj07ugBl3ewpUMw1jlbJK1RtoAjFDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lktgRo7eQNyC4UwmJk5XSoMvnxr7xre/aGqRb7+a/s5yY9DXhwARmCr7k2ws8B3Xx D2y2ZNm5o+gu8VUJ43FNZCP3Ant0KW07e9hbJjzQWQc2sx7Zg7MyUQN+5pijJbCsHt t/C1v6hbMH8KNJwhiCiaBUkmf4y7CCk2e/WFEnEwkceniDgZC6V2PZjBY0+z9OWNZG 8pWaPBk+WQtoKVyPhyWq5ValdZf50v+23AjQeYMzemyVzFtNoDhgQF8md6CgdlalC3 P8nGf/G3exGA12CrOPGoeY1lRSg1FjAEy/30wO7xfPJnsmsPoWmDsicsx0XPE/JOZk X0PdazoAcBY1Q== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/10] platform/chrome: cros_ec_proto: add Kunit test for empty payload Date: Mon, 18 Jul 2022 05:09:13 +0000 Message-Id: <20220718050914.2267370-10-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cros_ec_wait_until_complete() sends EC_CMD_GET_COMMS_STATUS which expects to receive sizeof(struct ec_response_get_comms_status) from cros_ec_xfer_command(). Add Kunit test and expect to receive an error code when cros_ec_xfer_command() returns 0. Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck --- No changes from v1. drivers/platform/chrome/cros_ec_proto_test.c | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index fbb872040711..d76e09b8a36a 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -1934,6 +1934,36 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_return_error(struct kunit *t KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 2); } +static void cros_ec_proto_test_cmd_xfer_in_progress_return0(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct ec_xfer_mock *mock; + int ret; + struct cros_ec_command msg; + + memset(&msg, 0, sizeof(msg)); + + ec_dev->pkt_xfer = cros_kunit_ec_pkt_xfer_mock; + + /* For the first host command to return EC_RES_IN_PROGRESS. */ + { + mock = cros_kunit_ec_xfer_mock_addx(test, 0, EC_RES_IN_PROGRESS, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + /* For EC_CMD_GET_COMMS_STATUS. */ + { + mock = cros_kunit_ec_xfer_mock_add(test, 0); + KUNIT_ASSERT_PTR_NE(test, mock, NULL); + } + + ret = cros_ec_cmd_xfer(ec_dev, &msg); + KUNIT_EXPECT_EQ(test, ret, -EPROTO); + + KUNIT_EXPECT_EQ(test, cros_kunit_ec_pkt_xfer_mock_called, 2); +} + static void cros_ec_proto_test_release(struct device *dev) { } @@ -2013,6 +2043,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = { KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_retries_status_processing), KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_xfer_error), KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return_error), + KUNIT_CASE(cros_ec_proto_test_cmd_xfer_in_progress_return0), {} }; From patchwork Mon Jul 18 05:09:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 12920729 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93004A47 for ; Mon, 18 Jul 2022 05:10:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86003C341C8; Mon, 18 Jul 2022 05:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658121019; bh=gbnWF/H385ErUCktkchjx9qWigCWiBQBmE32idRb2bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oEL0daO+4CLKjDbZlMyzc113plobNi/RfQML86pWpFHiRo8Lm687f90tgMwzqEZVu 8HeKG68CsSLHXwI334xKu9zh2TCqhPUbrFgfvgrQLzfRToMsXh59/lO6sGR59sDHNu Ev3MR5KPNiXVfOv2FZg+dtm0INVB/FaSgIUvhhRCqBnxYybFCA26L+z3KH1sUGhl7p 9DBCQO/x1JNWSSYr+XMyPkrKXH1O3CgIZu37CsSsq+oJON3UMxn5m+lmbKh3XPRcMC mTyMFvcyvSVQWF/Wkq/JFYe8Kth29wZqqZTG90Cx37v8eK1ToOekfycKDJcXFQqZWB ho8YuJHG1ycDg== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, tzungbi@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/10] platform/chrome: cros_ec_proto: return -EPROTO if empty payload Date: Mon, 18 Jul 2022 05:09:14 +0000 Message-Id: <20220718050914.2267370-11-tzungbi@kernel.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220718050914.2267370-1-tzungbi@kernel.org> References: <20220718050914.2267370-1-tzungbi@kernel.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 cros_ec_wait_until_complete() sends EC_CMD_GET_COMMS_STATUS which expects to receive sizeof(struct ec_response_get_comms_status) from cros_ec_xfer_command(). Return -EPROTO if cros_ec_xfer_command() returns 0. Reviewed-by: Guenter Roeck Signed-off-by: Tzung-Bi Shih --- Changes from v1: - Add R-b tag. drivers/platform/chrome/cros_ec_proto.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 9dec475edc84..05d2e8765a66 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -163,6 +163,11 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t * if (msg->result != EC_RES_SUCCESS) return ret; + if (ret == 0) { + ret = -EPROTO; + break; + } + if (!(status->flags & EC_COMMS_STATUS_PROCESSING)) return ret; }