From d69d00cd4a0835230c6504019a2497cdcd81e8e8 Mon Sep 17 00:00:00 2001 From: Dawid Niedzwiecki Date: Tue, 13 Jun 2023 10:37:46 +0000 Subject: [PATCH] mgmt: ec_host_cmd: verify a command before passing it to handler Verify validity of a received command before passing it to the general handler. It allows performing some actions, right after receiving the command. The context switch is not needed. Such feature may be needed for overloaded system, where instant reboot is required. Signed-off-by: Dawid Niedzwiecki --- include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h | 2 ++ subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h b/include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h index 0d167a11b2bb2ce..11566b4faccd80c 100644 --- a/include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h +++ b/include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h @@ -29,6 +29,8 @@ struct ec_host_cmd { * when data in rx_ctx are ready. The handler takes rx_ready to read data in rx_ctx. */ struct k_sem rx_ready; + /** Status of the rx data checked in the ec_host_cmd_send_received function. */ + enum ec_host_cmd_status rx_status; #ifdef CONFIG_EC_HOST_CMD_DEDICATED_THREAD struct k_thread thread; #endif /* CONFIG_EC_HOST_CMD_DEDICATED_THREAD */ diff --git a/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c b/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c index 45be56d183a6c52..ca430eaa16d8b8c 100644 --- a/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c +++ b/subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c @@ -242,6 +242,9 @@ int ec_host_cmd_send_response(enum ec_host_cmd_status status, void ec_host_cmd_rx_notify(void) { struct ec_host_cmd *hc = &ec_host_cmd; + struct ec_host_cmd_rx_ctx *rx = &hc->rx_ctx; + + hc->rx_status = verify_rx(rx); k_sem_give(&hc->rx_ready); } @@ -304,9 +307,12 @@ FUNC_NORETURN static void ec_host_cmd_thread(void *hc_handle, void *arg2, void * k_sem_take(&hc->rx_ready, K_FOREVER); ec_host_cmd_log_request(rx->buf); - status = verify_rx(rx); - if (status != EC_HOST_CMD_SUCCESS) { - ec_host_cmd_send_response(status, &args); + + /* Check status of the rx data, that has been verified in + * ec_host_cmd_send_received. + */ + if (hc->rx_status != EC_HOST_CMD_SUCCESS) { + ec_host_cmd_send_response(hc->rx_status, &args); continue; }