Skip to content

Commit 0aad9af

Browse files
author
Tzung-Bi Shih
committed
platform/chrome: cros_ec_proto: separate cros_ec_wait_until_complete()
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 <tzungbi@kernel.org> Reviewed-by: Guenter Roeck <groeck@chromium.org> Link: https://lore.kernel.org/r/20220718050914.2267370-7-tzungbi@kernel.org
1 parent 810be30 commit 0aad9af

1 file changed

Lines changed: 35 additions & 39 deletions

File tree

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -134,56 +134,52 @@ static int cros_ec_xfer_command(struct cros_ec_device *ec_dev, struct cros_ec_co
134134
return ret;
135135
}
136136

137-
static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
137+
static int cros_ec_wait_until_complete(struct cros_ec_device *ec_dev, uint32_t *result)
138138
{
139-
int ret = cros_ec_xfer_command(ec_dev, msg);
139+
struct {
140+
struct cros_ec_command msg;
141+
struct ec_response_get_comms_status status;
142+
} __packed buf;
143+
struct cros_ec_command *msg = &buf.msg;
144+
struct ec_response_get_comms_status *status = &buf.status;
145+
int ret = 0, i;
140146

141-
if (msg->result == EC_RES_IN_PROGRESS) {
142-
int i;
143-
struct cros_ec_command *status_msg;
144-
struct ec_response_get_comms_status *status;
147+
msg->version = 0;
148+
msg->command = EC_CMD_GET_COMMS_STATUS;
149+
msg->insize = sizeof(*status);
150+
msg->outsize = 0;
145151

146-
status_msg = kmalloc(sizeof(*status_msg) + sizeof(*status),
147-
GFP_KERNEL);
148-
if (!status_msg)
149-
return -ENOMEM;
152+
/* Query the EC's status until it's no longer busy or we encounter an error. */
153+
for (i = 0; i < EC_COMMAND_RETRIES; ++i) {
154+
usleep_range(10000, 11000);
150155

151-
status_msg->version = 0;
152-
status_msg->command = EC_CMD_GET_COMMS_STATUS;
153-
status_msg->insize = sizeof(*status);
154-
status_msg->outsize = 0;
156+
ret = cros_ec_xfer_command(ec_dev, msg);
157+
if (ret == -EAGAIN)
158+
continue;
159+
if (ret < 0)
160+
return ret;
155161

156-
/*
157-
* Query the EC's status until it's no longer busy or
158-
* we encounter an error.
159-
*/
160-
for (i = 0; i < EC_COMMAND_RETRIES; i++) {
161-
usleep_range(10000, 11000);
162-
163-
trace_cros_ec_request_start(status_msg);
164-
ret = (*xfer_fxn)(ec_dev, status_msg);
165-
trace_cros_ec_request_done(status_msg, ret);
166-
if (ret == -EAGAIN)
167-
continue;
168-
if (ret < 0)
169-
break;
170-
171-
msg->result = status_msg->result;
172-
if (status_msg->result != EC_RES_SUCCESS)
173-
break;
174-
175-
status = (struct ec_response_get_comms_status *)
176-
status_msg->data;
177-
if (!(status->flags & EC_COMMS_STATUS_PROCESSING))
178-
break;
179-
}
162+
*result = msg->result;
163+
if (msg->result != EC_RES_SUCCESS)
164+
return ret;
180165

181-
kfree(status_msg);
166+
if (!(status->flags & EC_COMMS_STATUS_PROCESSING))
167+
return ret;
182168
}
183169

184170
return ret;
185171
}
186172

173+
static int cros_ec_send_command(struct cros_ec_device *ec_dev, struct cros_ec_command *msg)
174+
{
175+
int ret = cros_ec_xfer_command(ec_dev, msg);
176+
177+
if (msg->result == EC_RES_IN_PROGRESS)
178+
ret = cros_ec_wait_until_complete(ec_dev, &msg->result);
179+
180+
return ret;
181+
}
182+
187183
/**
188184
* cros_ec_prepare_tx() - Prepare an outgoing message in the output buffer.
189185
* @ec_dev: Device to register.

0 commit comments

Comments
 (0)