summaryrefslogtreecommitdiff
path: root/chip/g/usb_spi.c
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2016-10-12 13:50:47 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-13 04:32:11 -0700
commit2ddc2ae6750af478cc104342ccc355fad1046bd5 (patch)
tree084b5bb339357abfa822b3d550889e1f05305883 /chip/g/usb_spi.c
parent080c566cc86c8e73af51945afed6cecca5b789f1 (diff)
downloadchrome-ec-2ddc2ae6750af478cc104342ccc355fad1046bd5.tar.gz
g: check that the rx fifo is ready before reading from it
The USB stream should check that there are bytes in the rx fifo to read before trying to read them. This should have been in here already. Checking if rx is valid in usb-stream makes the rx_valid call in usb_spi unnecessary so that is removed. BUG=none BRANCH=none TEST=manual Test CCD functionality still works on gru and reef AP/EC consoles sudo flashrom -p raiden_debug_spi:[AP|EC] -r img.bin usb updater Change-Id: Ieb77e35cc471b1f97d540ea4560591f0f40dd600 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/397858 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'chip/g/usb_spi.c')
-rw-r--r--chip/g/usb_spi.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/chip/g/usb_spi.c b/chip/g/usb_spi.c
index bab7bae6c4..e03d2935e3 100644
--- a/chip/g/usb_spi.c
+++ b/chip/g/usb_spi.c
@@ -42,14 +42,12 @@ static void usb_spi_write_packet(struct usb_spi_config const *config,
QUEUE_ADD_UNITS(config->tx_queue, config->buffer, count);
}
-static int rx_valid(struct usb_spi_config const *config)
-{
- return (config->usb->out_desc->flags & DOEPDMA_BS_MASK) ==
- DOEPDMA_BS_DMA_DONE;
-}
-
void usb_spi_deferred(struct usb_spi_config const *config)
{
+ uint16_t count;
+ uint8_t write_count;
+ uint8_t read_count;
+ uint16_t res;
/*
* If our overall enabled state has changed we call the board specific
* enable or disable routines and save our new state.
@@ -70,34 +68,31 @@ void usb_spi_deferred(struct usb_spi_config const *config)
* And if there is a USB packet waiting we process it and generate a
* response.
*/
- if (!rx_valid(config)) {
- uint16_t count = usb_spi_read_packet(config);
- uint8_t write_count = config->buffer[0];
- uint8_t read_count = config->buffer[1];
- uint16_t res;
-
- if (!read_count && !write_count)
- return;
-
- if (!config->state->enabled) {
- res = USB_SPI_DISABLED;
- } else if (write_count > USB_SPI_MAX_WRITE_COUNT ||
- write_count != (count - HEADER_SIZE)) {
- res = USB_SPI_WRITE_COUNT_INVALID;
- } else if (read_count > USB_SPI_MAX_READ_COUNT) {
- res = USB_SPI_READ_COUNT_INVALID;
- } else {
- res = usb_spi_map_error(
- spi_transaction(SPI_FLASH_DEVICE,
- config->buffer + HEADER_SIZE,
- write_count,
- config->buffer + HEADER_SIZE,
- read_count));
- }
-
- memcpy(config->buffer, &res, HEADER_SIZE);
- usb_spi_write_packet(config, read_count + HEADER_SIZE);
+ count = usb_spi_read_packet(config);
+ write_count = config->buffer[0];
+ read_count = config->buffer[1];
+
+ if (!count || (!read_count && !write_count))
+ return;
+
+ if (!config->state->enabled) {
+ res = USB_SPI_DISABLED;
+ } else if (write_count > USB_SPI_MAX_WRITE_COUNT ||
+ write_count != (count - HEADER_SIZE)) {
+ res = USB_SPI_WRITE_COUNT_INVALID;
+ } else if (read_count > USB_SPI_MAX_READ_COUNT) {
+ res = USB_SPI_READ_COUNT_INVALID;
+ } else {
+ res = usb_spi_map_error(
+ spi_transaction(SPI_FLASH_DEVICE,
+ config->buffer + HEADER_SIZE,
+ write_count,
+ config->buffer + HEADER_SIZE,
+ read_count));
}
+
+ memcpy(config->buffer, &res, HEADER_SIZE);
+ usb_spi_write_packet(config, read_count + HEADER_SIZE);
}
static void usb_spi_written(struct consumer const *consumer, size_t count)