diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-06-25 21:06:22 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-02 09:32:52 -0700 |
commit | 0ee2689ee9efc71df37e620b2ecef3c0ec635216 (patch) | |
tree | 200a7de48ae16230b2f406f216a9d2c1e09d54fa | |
parent | c830c036dcf18b230de81b800ce9e9fd8b3dc19e (diff) | |
download | chrome-ec-0ee2689ee9efc71df37e620b2ecef3c0ec635216.tar.gz |
Add get-protocol-information command
This is necessary to support larger packet sizes for host protocol
ver.3. The host previously didn't have any way to know how big a
packet the EC could accept / respond with (except on LPC, where the
size is determined by the I/O window).
BUG=chrome-os-partner:20257
BRANCH=none
TEST='ectool protoinfo' returns good info; on link,
Protocol info:
protocol versions: 2 3
max request: 256 bytes
max response: 256 bytes
flags: 0x00000000
and on pit,
Protocol info:
protocol versions: 2 3
max request: 544 bytes
max response: 544 bytes
flags: 0x00000001
Change-Id: Ic1e3831d9b4a96ffbf365c0d09b6023472de39a9
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/60703
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r-- | chip/lm4/lpc.c | 21 | ||||
-rw-r--r-- | chip/stm32/spi.c | 53 | ||||
-rw-r--r-- | include/ec_commands.h | 23 | ||||
-rw-r--r-- | util/ectool.c | 33 |
4 files changed, 118 insertions, 12 deletions
diff --git a/chip/lm4/lpc.c b/chip/lm4/lpc.c index 8e2102b403..6648a56dad 100644 --- a/chip/lm4/lpc.c +++ b/chip/lm4/lpc.c @@ -849,3 +849,24 @@ static void lpc_tick(void) task_trigger_irq(LM4_IRQ_LPC); } DECLARE_HOOK(HOOK_TICK, lpc_tick, HOOK_PRIO_DEFAULT); + +/** + * Get protocol information + */ +static int lpc_get_protocol_info(struct host_cmd_handler_args *args) +{ + struct ec_response_get_protocol_info *r = args->response; + + memset(r, 0, sizeof(*r)); + r->protocol_versions = (1 << 2) | (1 << 3); + r->max_request_packet_size = EC_LPC_HOST_PACKET_SIZE; + r->max_response_packet_size = EC_LPC_HOST_PACKET_SIZE; + r->flags = 0; + + args->response_size = sizeof(*r); + + return EC_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, + lpc_get_protocol_info, + EC_VER_MASK(0)); diff --git a/chip/stm32/spi.c b/chip/stm32/spi.c index c2a6044da8..4f65820d9a 100644 --- a/chip/stm32/spi.c +++ b/chip/stm32/spi.c @@ -63,18 +63,15 @@ enum { * for a 1MHz clock which is as slow as we would reasonably want it. */ SPI_CMD_RX_TIMEOUT_US = 8192, -}; -/* - * Our input and output buffers. These must be large enough for our largest - * message, including protocol overhead. - */ -static uint8_t out_msg[EC_HOST_PARAM_SIZE + SPI_MSG_PROTO_LEN]; -static uint8_t in_msg[EC_HOST_PARAM_SIZE + SPI_MSG_PROTO_LEN]; -static uint8_t active; -static uint8_t enabled; -static struct host_cmd_handler_args args; -static struct host_packet spi_packet; + /* + * Max data size for request/response packet. This is big enough + * to handle a request/respose header, flash write offset/size, and + * 512 bytes of flash data. + */ + SPI_MAX_REQUEST_SIZE = 0x220, + SPI_MAX_RESPONSE_SIZE = 0x220, +}; /* * The AP blindly clocks back bytes over the SPI interface looking for the @@ -93,6 +90,17 @@ static const uint8_t out_preamble[4] = { SPI_MSG_HEADER_BYTE2, /* This is the byte which matters */ }; +/* + * Our input and output buffers. These must be large enough for our largest + * message, including protocol overhead. + */ +static uint8_t out_msg[SPI_MAX_RESPONSE_SIZE + sizeof(out_preamble)]; +static uint8_t in_msg[SPI_MAX_REQUEST_SIZE]; +static uint8_t active; +static uint8_t enabled; +static struct host_cmd_handler_args args; +static struct host_packet spi_packet; + /** * Wait until we have received a certain number of bytes * @@ -228,7 +236,7 @@ static void setup_for_transaction(void) } /** - * Called to indicate that a command has completed + * Called for V2 protocol to indicate that a command has completed * * Some commands can continue for a while. This function is called by * host_command when it completes. @@ -450,3 +458,24 @@ static void spi_chipset_shutdown(void) } DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, spi_chipset_shutdown, HOOK_PRIO_DEFAULT); DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, spi_chipset_shutdown, HOOK_PRIO_DEFAULT); + +/** + * Get protocol information + */ +static int spi_get_protocol_info(struct host_cmd_handler_args *args) +{ + struct ec_response_get_protocol_info *r = args->response; + + memset(r, 0, sizeof(*r)); + r->protocol_versions = (1 << 2) | (1 << 3); + r->max_request_packet_size = SPI_MAX_REQUEST_SIZE; + r->max_response_packet_size = SPI_MAX_RESPONSE_SIZE; + r->flags = EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED; + + args->response_size = sizeof(*r); + + return EC_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_GET_PROTOCOL_INFO, + spi_get_protocol_info, + EC_VER_MASK(0)); diff --git a/include/ec_commands.h b/include/ec_commands.h index 2eb0b7159c..0359bb1270 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -502,6 +502,29 @@ struct ec_response_test_protocol { uint8_t buf[32]; } __packed; +/* Get prococol information */ +#define EC_CMD_GET_PROTOCOL_INFO 0x0b + +/* Flags for ec_response_get_protocol_info.flags */ +/* EC_RES_IN_PROGRESS may be returned if a command is slow */ +#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0) + +struct ec_response_get_protocol_info { + /* Fields which exist if at least protocol version 3 supported */ + + /* Bitmask of protocol versions supported (1 << n means version n)*/ + uint32_t protocol_versions; + + /* Maximum request packet size, in bytes */ + uint16_t max_request_packet_size; + + /* Maximum response packet size, in bytes */ + uint16_t max_response_packet_size; + + /* Flags; see EC_PROTOCOL_INFO_* */ + uint32_t flags; +} __packed; + /*****************************************************************************/ /* Flash commands */ diff --git a/util/ectool.c b/util/ectool.c index 953b5b9a6d..39e49d16f5 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -108,6 +108,8 @@ const char help_str[] = " Rapidly write bytes to port 80\n" " powerinfo\n" " Prints power-related information\n" + " protoinfo\n" + " Prints EC host protocol information\n" " pstoreinfo\n" " Prints information on the EC host persistent storage\n" " pstoreread <offset> <size> <outfile>\n" @@ -2561,6 +2563,36 @@ int cmd_chipinfo(int argc, char *argv[]) return 0; } +int cmd_proto_info(int argc, char *argv[]) +{ + struct ec_response_get_protocol_info info; + int rv; + int i; + + printf("Protocol info:\n"); + + rv = ec_command(EC_CMD_GET_PROTOCOL_INFO, 0, NULL, 0, + &info, sizeof(info)); + if (rv < 0) { + fprintf(stderr, "Protocol info unavailable. EC probably only " + "supports protocol version 2.\n"); + return rv; + } + + printf(" protocol versions:"); + for (i = 0; i < 32; i++) { + if (info.protocol_versions & (1 << i)) + printf(" %d", i); + } + printf("\n"); + + printf(" max request: %4d bytes\n", info.max_request_packet_size); + printf(" max response: %4d bytes\n", info.max_response_packet_size); + printf(" flags: 0x%08x\n", info.flags); + if (info.flags & EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED) + printf(" EC_RES_IN_PROGRESS supported\n"); + return 0; +} static int ec_hash_help(const char *cmd) { @@ -3049,6 +3081,7 @@ const struct command commands[] = { {"keyscan", cmd_keyscan}, {"panicinfo", cmd_panic_info}, {"powerinfo", cmd_power_info}, + {"protoinfo", cmd_proto_info}, {"pstoreinfo", cmd_pstore_info}, {"pstoreread", cmd_pstore_read}, {"pstorewrite", cmd_pstore_write}, |