Skip to content

Commit

Permalink
mgmt: ec_host_cmd: save result of IN_PROGRESS command
Browse files Browse the repository at this point in the history
Add a config to save the final result of a last host command that has
sent EC_HOST_CMD_IN_PROGRESS response. To get the final result use the
ec_host_cmd_send_in_progress_status function.

Signed-off-by: Dawid Niedzwiecki <[email protected]>
  • Loading branch information
niedzwiecki-dawid authored and carlescufi committed Jul 12, 2023
1 parent 5a36d38 commit 7a479ee
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/zephyr/mgmt/ec_host_cmd/ec_host_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,31 @@ const struct ec_host_cmd *ec_host_cmd_get_hc(void);
FUNC_NORETURN void ec_host_cmd_task(void);
#endif

#ifdef CONFIG_EC_HOST_CMD_IN_PROGRESS_STATUS
/**
* @brief Check if a Host Command that sent EC_HOST_CMD_IN_PROGRESS status has ended.
*
* A Host Command that sends EC_HOST_CMD_IN_PROGRESS status doesn't send a final result.
* The final result can be get with the ec_host_cmd_send_in_progress_status function.
*
* @retval true if the Host Command endded
*/
bool ec_host_cmd_send_in_progress_ended(void);

/**
* @brief Get final result of a last Host Command that has sent EC_HOST_CMD_IN_PROGRESS status.
*
* A Host Command that sends EC_HOST_CMD_IN_PROGRESS status doesn't send a final result.
* Get the saved status with this function. The status can be get only once. Futher calls return
* EC_HOST_CMD_UNAVAILABLE.
*
* Saving status of Host Commands that send response data is not supported.
*
* @retval The final status or EC_HOST_CMD_UNAVAILABLE if not available.
*/
enum ec_host_cmd_status ec_host_cmd_send_in_progress_status(void);
#endif /* CONFIG_EC_HOST_CMD_IN_PROGRESS_STATUS */

/**
* @}
*/
Expand Down
8 changes: 8 additions & 0 deletions subsys/mgmt/ec_host_cmd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ config EC_HOST_CMD_DEDICATED_THREAD
The ec_host_cmd_init function creates a new thread dedicated for Host Command.
Otherwise the ec_host_cmd_task function has to be called within another thread.

config EC_HOST_CMD_IN_PROGRESS_STATUS
bool "Save status of last IN_PROGRESS command"
default y if EC_HOST_CMD_BACKEND_SHI
help
Enable support for saving final status of a last command that has sent
EC_HOST_CMD_IN_PROGRESS status. The saved status can be get with the
ec_host_cmd_send_in_progress_status function.

source "subsys/mgmt/ec_host_cmd/Kconfig.logging"
source "subsys/mgmt/ec_host_cmd/backends/Kconfig"

Expand Down
54 changes: 54 additions & 0 deletions subsys/mgmt/ec_host_cmd/ec_host_cmd_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ static struct ec_host_cmd ec_host_cmd = {
},
};

#ifdef CONFIG_EC_HOST_CMD_IN_PROGRESS_STATUS
/* Indicates that a command has sent EC_HOST_CMD_IN_PROGRESS but hasn't sent a final status */
static bool cmd_in_progress;

/* The final result of the last command that has sent EC_HOST_CMD_IN_PROGRESS */
static enum ec_host_cmd_status saved_status = EC_HOST_CMD_UNAVAILABLE;
#endif

static uint8_t cal_checksum(const uint8_t *const buffer, const uint16_t size)
{
uint8_t checksum = 0;
Expand All @@ -61,6 +69,22 @@ static uint8_t cal_checksum(const uint8_t *const buffer, const uint16_t size)
return (uint8_t)(-checksum);
}

#ifdef CONFIG_EC_HOST_CMD_IN_PROGRESS_STATUS
bool ec_host_cmd_send_in_progress_ended(void)
{
return !cmd_in_progress;
}

enum ec_host_cmd_status ec_host_cmd_send_in_progress_status(void)
{
enum ec_host_cmd_status ret = saved_status;

saved_status = EC_HOST_CMD_UNAVAILABLE;

return ret;
}
#endif /* CONFIG_EC_HOST_CMD_IN_PROGRESS_STATUS */

static void send_status_response(const struct ec_host_cmd_backend *backend,
struct ec_host_cmd_tx_buf *tx,
const enum ec_host_cmd_status status)
Expand Down Expand Up @@ -161,6 +185,36 @@ int ec_host_cmd_send_response(enum ec_host_cmd_status status,
struct ec_host_cmd *hc = &ec_host_cmd;
struct ec_host_cmd_tx_buf *tx = &hc->tx;

#ifdef CONFIG_EC_HOST_CMD_IN_PROGRESS_STATUS
if (cmd_in_progress) {
/* We previously got EC_HOST_CMD_IN_PROGRESS. This must be the completion
* of that command, so save the result code.
*/
LOG_INF("HC pending done, size=%d, result=%d",
args->output_buf_size, status);

/* Don't support saving response data, so mark the response as unavailable
* in that case.
*/
if (args->output_buf_size != 0) {
saved_status = EC_HOST_CMD_UNAVAILABLE;
} else {
saved_status = status;
}

/* We can't send the response back to the host now since we already sent
* the in-progress response and the host is on to other things now.
*/
cmd_in_progress = false;

return EC_HOST_CMD_SUCCESS;

} else if (status == EC_HOST_CMD_IN_PROGRESS) {
cmd_in_progress = true;
LOG_INF("HC pending");
}
#endif /* CONFIG_EC_HOST_CMD_IN_PROGRESS_STATUS */

if (status != EC_HOST_CMD_SUCCESS) {
const struct ec_host_cmd_request_header *const rx_header =
(const struct ec_host_cmd_request_header *const)hc->rx_ctx.buf;
Expand Down

0 comments on commit 7a479ee

Please sign in to comment.