From patchwork Wed Jun 15 05:12:38 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: 12881822 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 37E027C for ; Wed, 15 Jun 2022 05:13:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D40DC3411B; Wed, 15 Jun 2022 05:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269984; bh=78h/xWejmUYXqnLJGctnzKO4vmtanAQy4FkFlDYdQXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pn5PpbZi4XEf/wyObY4kB4cFox427EPVYZYDHUKgtUbgUB0+4Ql4qHwGqqE7WIxLK D1aTYve/bijW8MA27yC5JkkDqDC8A3gDm1U0ZqZZc1aNd7SHh3FPlfOr9otypfKoxo HhZ7sRNUyLYajtLhI24YiUCFnJqW7Cho+PgVFjS61bX3uRWecwHU0Wf/CramhwV5wN cYamb0C9UO8A4IspFmwX6GW/WmDPLJukZ7/Hd4uz2sS9T/fN0ie4SIHOTnA+hFj0FX SGMjq02rIGbPivyYshDrywaPlCcQaIBOrH+nhv3RY7h/bWEm94bP3Eevv89IP/JFOU 0b0ReWw69TgnQ== 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 01/11] platform/chrome: cros_ec_proto: add "cros_ec_" prefix to send_command() Date: Wed, 15 Jun 2022 05:12:38 +0000 Message-Id: <20220615051248.1628156-2-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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(). Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck --- 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 Wed Jun 15 05:12:39 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: 12881823 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 5B3527C for ; Wed, 15 Jun 2022 05:13:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 482A9C341C8; Wed, 15 Jun 2022 05:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269986; bh=HzxmI06J0+gbvIw8Mk49vLYOJ5K4ttyGawmN3HAEkAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xv9vBWL8n9SKqDL5XgA7+/RWxjV1Fgc5qrjmUlBMVNaEQT9xEUXPu/Z6e3S6m16sT vbpmeTbwjo3ZvEMJPbIJvs1Qrwq3a9IdS5BaXbACx4m8fNkN/qLx4umd+cquOh5xpz Bd/i4sWRPzBfS75nd4V+5cG3qXizlscGiavOoHXHfLPEesvn6mDVTBL3hVZ7u7Fpgj TtrgO/jYOjG+BtFTn1tT2mX7iGfcjSrOzwBQO36u7S4xsTEzKU1IX9rEVnBon2VD15 TVtfGFqLn4K2BREBjCGSVsGCeQaCXwXZ2HOqg4C/BONWnn0ppOto5wGtaQflelkosH 9n9LeF4ZvuHtQ== 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 02/11] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_cmd_xfer() Date: Wed, 15 Jun 2022 05:12:39 +0000 Message-Id: <20220615051248.1628156-3-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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(). Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck --- 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 Wed Jun 15 05:12:40 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: 12881824 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 913D87C for ; Wed, 15 Jun 2022 05:13:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83AB7C3411B; Wed, 15 Jun 2022 05:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269987; bh=ZNPEv167URz6WTK9s6ICZv11yZTOdgPUlR8S5bdtLm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=owSQTeJsI+CF7/aM4z2eR3Wn65AbfYmGOuNUeqhcdyQ/LaZCwq57+tIq0Q8O8Zws/ ILfAVs++70aRdsKXh6+Ds2KJsAw//DkFEJ6yYgGGsv7WjjdZF9kkjy/na+HtkRMNfb mlWE2SsH5bGbTEIqiMb91fBY6NDfnYyRHJZuwgRYAIcWUsAofkTuPbwzFAoQavjlfI 0Am0Pd7QHG4FA7ioxl7lmlYk5y76i7jMFeiGTD2REkQulB48WC7DYkLOEDRbwYH0bR YhwHSQKhK8Vpw14OUkrWjbEPPdXrZjiNZ4y6hn7NDws5+SMqeseq88ZojNQXBbGhah As5134fy/8xXA== 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 03/11] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_send_command() Date: Wed, 15 Jun 2022 05:12:40 +0000 Message-Id: <20220615051248.1628156-4-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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(). Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck --- 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 e031777dea87..3ede971e82ee 100644 --- a/drivers/platform/chrome/cros_kunit_util.c +++ b/drivers/platform/chrome/cros_kunit_util.c @@ -15,6 +15,10 @@ 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; @@ -46,6 +50,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); @@ -90,6 +108,8 @@ EXPORT_SYMBOL_GPL(cros_kunit_ec_xfer_mock_next); void cros_kunit_mock_reset(void) { 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 79c4525f873c..ae4080cb13f1 100644 --- a/drivers/platform/chrome/cros_kunit_util.h +++ b/drivers/platform/chrome/cros_kunit_util.h @@ -24,8 +24,12 @@ struct ec_xfer_mock { }; 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 Wed Jun 15 05:12:41 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: 12881825 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 CF1BC7C for ; Wed, 15 Jun 2022 05:13:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF3B3C341C8; Wed, 15 Jun 2022 05:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269988; bh=eh0wHoBVv18wEv+R8ggGvnitBSyOqK/G5EAzt9lOmDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yt6hKy+q5jlj//QHdEMotgEX4SCsX6VksZfcJLmvBrSCgEjbj1WPuLitNbK9+X6sC HYBF2o6ffImHUQ2HHDHjFOHSrscqV/kzcG4U0eLMZcQJOGaD8jTfGUX7KzhUygvD5I jFkfGtRWO8Gpu3tYP1cuiwEUaYcpsOAcfiCsk5GcmXBEajxrKNg/VGsz9K7ZS3ov8N 1WW/4os/TJQbny/tyt6s9C0VANaH0P2QC/WEWDX5xujWxF2/62C+2CpBwHJ6AIqs8h 7v+c5kYRWNMFlTFv2ED0reJHkgDyeSyTWm/6HGlL2riJjJ0Wgao2NgWWGXPLLmsBjn OkE4OrWNIRcJg== 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 04/11] platform/chrome: cros_ec_proto: separate cros_ec_xfer_command() Date: Wed, 15 Jun 2022 05:12:41 +0000 Message-Id: <20220615051248.1628156-5-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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. Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck --- 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 Wed Jun 15 05:12:42 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: 12881826 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 147A87C for ; Wed, 15 Jun 2022 05:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 065DBC3411F; Wed, 15 Jun 2022 05:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269989; bh=6ItXxr6KZikq3OhN5ZSu919u0fACp3SvOrk9yJh74MM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p/Rvr6IR2IPAJA5zET142LmUmNMUvwbnc4EmpAY+aFT5a2fibq7A64h6g/9VcOswK SDEOv2pPH9XfBybKBpA/GNT0tW9smc+tfwzCRkCgKLaesrMIPfiVLjAp/lYW36S/t1 doWGQuCfvF4hxIVmazElk87Obn+1BZMxQ5sSOsvo4K8KM4IuKGrSM0agRTtTXccTx6 6d2CN9e0wrHLS0M/UBNvZDskXxRkUF78bURVE9w2YcLokNEKgE0/j7QGR7m2SScs91 ZlPQuhskbI7r6Q6OoX5vvjeTX4sXVNOix/x6IZIFr/C/KkaGa7XdrJyI50ERZg1KG/ NvxZWx9djnxVA== 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 05/11] platform/chrome: cros_ec_proto: separate cros_ec_wait_until_complete() Date: Wed, 15 Jun 2022 05:12:42 +0000 Message-Id: <20220615051248.1628156-6-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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 --- drivers/platform/chrome/cros_ec_proto.c | 75 ++++++++++++------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 0cec013be3d3..466ecb063bd6 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -134,53 +134,50 @@ 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 cros_ec_command *msg; + struct ec_response_get_comms_status *status; + int ret = 0, i; + + msg = kzalloc(sizeof(*msg) + sizeof(*status), GFP_KERNEL); + if (!msg) + return -ENOMEM; - if (msg->result == EC_RES_IN_PROGRESS) { - int i; - struct cros_ec_command *status_msg; - struct ec_response_get_comms_status *status; + msg->command = EC_CMD_GET_COMMS_STATUS; + msg->insize = sizeof(*status); - status_msg = kmalloc(sizeof(*status_msg) + sizeof(*status), - GFP_KERNEL); - if (!status_msg) - return -ENOMEM; + status = (struct ec_response_get_comms_status *)msg->data; - status_msg->version = 0; - status_msg->command = EC_CMD_GET_COMMS_STATUS; - status_msg->insize = sizeof(*status); - status_msg->outsize = 0; + /* 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); - /* - * 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; - } + ret = cros_ec_xfer_command(ec_dev, msg); + if (ret == -EAGAIN) + continue; + if (ret < 0) + break; + + *result = msg->result; + if (msg->result != EC_RES_SUCCESS) + break; - kfree(status_msg); + if (!(status->flags & EC_COMMS_STATUS_PROCESSING)) + break; } + kfree(msg); + 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; } From patchwork Wed Jun 15 05:12:43 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: 12881827 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 4FEE17C for ; Wed, 15 Jun 2022 05:13:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 424DDC3411B; Wed, 15 Jun 2022 05:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269991; bh=5SLS/K/WO5NPoG6nosQIx5zbsicGDMXiC+LrsQiUdaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f5sOmv6FSap7n32AGDTO3VcIvuGYBym1VQoFHYYEymvyDUZcEuoWozMtlHsxNhvQD TFAYl9kmtOsBiBeRS6quY6woXPiFPrrrs45zEYpVlqdYI8KeCrCkeyUxbUiCVvePzn IrO/9psvEMHZJmzpNAEwGG04INLPyAlBZPbOOdTROG4ZNgaDOt1r9+PiI+YZca+mlS eL+g8emG9HtHD/YKONkbQSrl5bRWF70qD3m6AHhQr/VXOtdEjLFfWYyx2S24gEeI7n 9OvLw0YxluuK5cvfasF2dDzI7KnSos6vlHTCsPDLt/tshK8f3eIt66R8nq9QFAxLA8 r/7rddHzXC0Gw== 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 06/11] platform/chrome: cros_ec_proto: change Kunit expectation when timed out Date: Wed, 15 Jun 2022 05:12:43 +0000 Message-Id: <20220615051248.1628156-7-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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. Signed-off-by: Tzung-Bi Shih --- 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 Wed Jun 15 05:12:44 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: 12881828 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 8A7947C for ; Wed, 15 Jun 2022 05:13:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D4A4C34115; Wed, 15 Jun 2022 05:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269992; bh=1Ziar4/L2yYTjXxZ9eePmtAtdMdL2lsbb8Bw9TmQToM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdnTk7gYSmjQxxysxldnd/wF83UM/qfSHCYgSTCoCc5JzgqyXiXzYbsW7vi8uvyX0 WeFNf/DdKmngt3KkjrPHI1BSAnrJD1Lw/Ry7E7Yo9pkmcne2ImOZsXttF7ANG/rONq nRl00diCDDt3sM2yGN6jVDlcWGq5pPuseprUYDVDSkNBmUVOfhHHEoGtf22/pEfu81 XOIzg8Jgwdr+KlaTFUd+FbUgcgwCQ5KQFAdEAeCMSocNJz+yfa+xhPTYJcBFx4kuFB JDj3hX0I6+sKR1sQ0Cc7I4vtm7BEYDobjSatrfYtUNcmdyAf6J2jxEqdCS7kewdQls pjq+IO3NY0nJw== 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 07/11] platform/chrome: cros_ec_proto: return -EAGAIN when retries timed out Date: Wed, 15 Jun 2022 05:12:44 +0000 Message-Id: <20220615051248.1628156-8-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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 --- 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 466ecb063bd6..49772a4c5353 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 * break; } + if (i >= EC_COMMAND_RETRIES) + ret = -EAGAIN; + kfree(msg); return ret; } From patchwork Wed Jun 15 05:12:45 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: 12881829 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 CCB127C for ; Wed, 15 Jun 2022 05:13:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B919EC341C0; Wed, 15 Jun 2022 05:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269993; bh=ouMi+OrOc1vdWAJZIxurgSh0grbjdWfmqXvHpzaOysA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mdBgEqbehzX3muATuka1QXahgd/QR7A/6g84zTd6wEpvPjeWadHV7XbFKzdVxH1tQ R/RneL0rTryU1we8pa2Z5MrNRDLCrCxCxPX7E49bycU1J1EzOE4/E2tXdwj4Ohzh31 mBomMgFuUTGjPjoJpfGF+Q/Egjg3m4Jbon6VIYxKaznBxkHQsF6h+XyoMXgHscf+xH oW+hpXnY4VdifBa+iXbTyTMjLJDRfHXjXplz+6aeYZX/5nGawuMQD0QRosIYVieSjD 74ZLSaQ/6zVoJISaWfNHonppDJRsh0Aw4ahb3SOxGFzfUWkZBp3GrIRxiBrzppiTvy beaC7kUh+OmKg== 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 08/11] platform/chrome: cros_ec_proto: change Kunit expectation for EC errors Date: Wed, 15 Jun 2022 05:12:45 +0000 Message-Id: <20220615051248.1628156-9-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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() checks `msg->result` for EC_CMD_GET_COMMS_STATUS. However, it doesn't return standard error codes like most of others. Change the Kunit test expectation to align them. Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_proto_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index fbb872040711..2a6b099fbfd9 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -1927,7 +1927,7 @@ static void cros_ec_proto_test_cmd_xfer_in_progress_return_error(struct kunit *t } ret = cros_ec_cmd_xfer(ec_dev, &msg); - KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, ret, -EOPNOTSUPP); KUNIT_EXPECT_EQ(test, msg.result, EC_RES_INVALID_COMMAND); From patchwork Wed Jun 15 05:12:46 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: 12881830 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 0FFB87C for ; Wed, 15 Jun 2022 05:13:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00E4FC3411F; Wed, 15 Jun 2022 05:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269994; bh=pMu/iPTPt+7snGnGf7n7Le6i011YyhLzHZlK+Kum9iQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZO+PAazBmnEIlX9gNI2US1eLAX8sqXpT/ZmgnrbiUqf1/pyOYuMI6je9Do44OAJvl hGpQjFUkew4YHj1PLHCpjzfQ7/QM+hBJCqulx8xQZAkoMPgVK7d/eKizqyqZMFGAiN NvnPtg8lCpESXJM+Q7gXjmJ3WTAS35imI3vhlQOz/NuT1AaIZuiBgTaGB7wdjTylQf gF1J+RJ+DjMgDCHYMAAEf097ZkqHAD8oE2y0GV9Q4u+UE/8buMj814xlGYVu7CD3oo sAcL10+o8t1VxmZx3/6/5AoQ7Pq6J702HGi0Z1J7imfSZ80Rx0leQaw2Sfn15XfcIl iMLhWcdV//tIA== 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 09/11] platform/chrome: cros_ec_proto: return standard error codes for EC errors Date: Wed, 15 Jun 2022 05:12:46 +0000 Message-Id: <20220615051248.1628156-10-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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() checks `msg->result` for EC_CMD_GET_COMMS_STATUS. However, it doesn't return standard error codes like most of others. Use cros_ec_map_error() to align them. Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_proto.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index 49772a4c5353..5323edddb540 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -138,7 +138,7 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t * { struct cros_ec_command *msg; struct ec_response_get_comms_status *status; - int ret = 0, i; + int ret = 0, i, mapped; msg = kzalloc(sizeof(*msg) + sizeof(*status), GFP_KERNEL); if (!msg) @@ -160,8 +160,11 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t * break; *result = msg->result; - if (msg->result != EC_RES_SUCCESS) + mapped = cros_ec_map_error(msg->result); + if (mapped) { + ret = mapped; break; + } if (!(status->flags & EC_COMMS_STATUS_PROCESSING)) break; From patchwork Wed Jun 15 05:12:47 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: 12881831 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 488807C for ; Wed, 15 Jun 2022 05:13:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B805C34115; Wed, 15 Jun 2022 05:13:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269996; bh=i5w06+KIfprfZwCkANiW0+X0QAOeYszoT4dilim9fog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DybqA0Q1enn3Y1tSudMj/BYzmP+bjyjVHRZvu1POpFKmPqGKOrRbg3KowDHPkSpEK aKXeEV1o6foB+kdGXLJ/u2PrRHdvbXm7qz7TSic0tfpGvCSF8/2/87NVGHArV6wilL JR4XONlDiClP6iy9vrdhQ6jUjTkS+o0ejEeh5q/O2cfvC/AxIku8UYhrZ4n/rZ3tXv ZJS5SjY3/ATLYJBMpU7rplFbthYpSZkYNO26TUYLx3Nxg0h++1pfYn2hXFsP22yt2j 5hcvDxBYVjp/93LXre9FoM/lv3QstxTKusFfXA87ZXd32vMrv8/tc08DWo7kb/ALT5 PeiuiK0oCOSqw== 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 10/11] platform/chrome: cros_ec_proto: add Kunit test for empty payload Date: Wed, 15 Jun 2022 05:12:47 +0000 Message-Id: <20220615051248.1628156-11-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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 --- 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 2a6b099fbfd9..7d45e5022221 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 Wed Jun 15 05:12:48 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: 12881832 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 84A217C for ; Wed, 15 Jun 2022 05:13:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 768DAC3411B; Wed, 15 Jun 2022 05:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655269997; bh=+DHhSqosE4XJOM/fy6PqZfeINZkN9gw6GDOPcgfkxIM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DmmvWJt7/KEN9iqPCpXt88y5IrUee/OKe2tBCoTg3FcnO70ioMynPNBJO6Q7JAlY8 YKeUotl/SH/UKARFt0EP54uKJEhE/KEmj9mH8G+AxuSuGBbIMF+DcDvmQ6huckjAaK EcLPp+QKdf3XlliPYuFHTueqtTL3stU0/p766OIpNj3iLVYcRzWLpBBlXXbim3LqDb rQi6VQDdXb2YrsbBZpUYiIgyHotRwxq72P+tBApldM/76xjyZ7CvRhKr2Zw+B/w/FU mXYZSzpvVk6heS50n2wfGMtO0TOpxAO1sdjF9nPAPHS30Y8t4La3N3PqH79KvD1HGe dZJhPMHGnVVAQ== 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 11/11] platform/chrome: cros_ec_proto: return -EPROTO if empty payload Date: Wed, 15 Jun 2022 05:12:48 +0000 Message-Id: <20220615051248.1628156-12-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615051248.1628156-1-tzungbi@kernel.org> References: <20220615051248.1628156-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. Signed-off-by: Tzung-Bi Shih --- 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 5323edddb540..0c7042aa2640 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -166,6 +166,11 @@ static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t * break; } + if (ret == 0) { + ret = -EPROTO; + break; + } + if (!(status->flags & EC_COMMS_STATUS_PROCESSING)) break; }