From e26e2a2bec50a85a42f81cb2fd23ec65a4f9c438 Mon Sep 17 00:00:00 2001 From: Hongquan Li Date: Sun, 3 Nov 2024 14:23:25 +0800 Subject: [PATCH] [nrf fromlist] drivers/wifi/nrfwifi: Add buffer for discard bytes Some spi drivers do not allow the send buffer and receive buffer to be empty at the same time, if this happens it will cause the spi to be unable to communicate with the nrf7002, so add the receive buffer for the discard byte in the spim_xfer_rx. Fix #80686 Upstream PR #: 80787 Signed-off-by: Hongquan Li --- drivers/wifi/nrfwifi/src/qspi/src/spi_if.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c b/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c index 2cdf3662fd5c84..4bf9f464391042 100644 --- a/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c +++ b/drivers/wifi/nrfwifi/src/qspi/src/spi_if.c @@ -58,6 +58,7 @@ static int spim_xfer_rx(unsigned int addr, void *data, unsigned int len, unsigne addr & 0xFF, 0 /* dummy byte */ }; + uint8_t discard[sizeof(hdr) + 2 * 4]; const struct spi_buf tx_buf[] = { {.buf = hdr, .len = sizeof(hdr) }, @@ -67,12 +68,17 @@ static int spim_xfer_rx(unsigned int addr, void *data, unsigned int len, unsigne const struct spi_buf_set tx = { .buffers = tx_buf, .count = 2 }; const struct spi_buf rx_buf[] = { - {.buf = NULL, .len = sizeof(hdr) + discard_bytes}, + {.buf = discard, .len = sizeof(hdr) + discard_bytes}, {.buf = data, .len = len }, }; const struct spi_buf_set rx = { .buffers = rx_buf, .count = 2 }; + if (rx_buf[0].len > sizeof(discard)) { + LOG_ERR("Discard bytes too large, please adjust buf size"); + return -EINVAL; + } + return spi_transceive_dt(&spi_spec, &tx, &rx); }