diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2021-06-18 13:46:56 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-18 22:47:22 +0000 |
commit | a6e62a3020e1f6d53880d91760073c4f91a63bef (patch) | |
tree | 4e79f17b97acb8477a0a826b049cb5bfecb4ac70 | |
parent | f1dad7730feb3e0a8ab37651e11fd3aad1b74938 (diff) | |
download | chrome-ec-a6e62a3020e1f6d53880d91760073c4f91a63bef.tar.gz |
usb_spi: prevent potential loss of upstream traffic
Code placing data on the upstream usb_spi queue does not check if
there is enough room on the queue, which could result in silent
dropping of data when the upstream queue is busy.
This is not a big deal with Raiden protocol V1 where USB packets to
the host are sent one at a time, but becomes a problem if the DUT
sends multiple USB packets without waiting for the host.
Adding a sleep in the loop waiting for the room in the queue to free
up seems an appropriate solution, since the AP is held in reset at
this point and there is no much activity happening on Cr50.
Experiments have shown that with 2KB PDU size the total wait time
while reading a 16M flash does not exceed 30 ms when this fix is
deployed.
BUG=b:79492818
TEST=with the rest of the patches applied observed successful flashrom
operations running Raiden protocol version V2. Without this patch
there were periodic drops of data sent by DUT.
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Change-Id: I73fdfdda09837891dc1db2453098ec1d219c4553
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2973573
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-by: Namyoon Woo <namyoon@chromium.org>
-rw-r--r-- | chip/g/usb_spi.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/chip/g/usb_spi.c b/chip/g/usb_spi.c index 54f32fd553..5d436a1b83 100644 --- a/chip/g/usb_spi.c +++ b/chip/g/usb_spi.c @@ -10,6 +10,7 @@ #include "registers.h" #include "spi.h" #include "spi_flash.h" +#include "timer.h" #include "usb_descriptor.h" #include "usb_spi.h" #include "util.h" @@ -44,6 +45,14 @@ static uint16_t usb_spi_read_packet(struct usb_spi_config const *config) static void usb_spi_write_packet(struct usb_spi_config const *config, uint8_t count) { + /* + * Experiments show that while reading a 16M flash time spent waiting + * is less than 30 ms, which is negligible in this case, as the AP is + * held in reset. + */ + while (queue_space(config->tx_queue) < count) + msleep(1); + #ifdef CONFIG_STREAM_SIGNATURE /* * This hook allows mn50 to sign SPI data read from newly |