[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211223011358.4031459-49-davidm@egauge.net>
Date: Thu, 23 Dec 2021 01:14:07 +0000 (UTC)
From: David Mosberger-Tang <davidm@...uge.net>
To: Ajay Singh <ajay.kathat@...rochip.com>
Cc: Claudiu Beznea <claudiu.beznea@...rochip.com>,
Kalle Valo <kvalo@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
linux-wireless@...r.kernel.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
David Mosberger-Tang <davidm@...uge.net>
Subject: [PATCH v2 48/50] wilc1000: introduce function to find and check DMA
response
Refactor DMA response checking from spi_data_rsp() into its own
function spi_data_check_rsp() as that will come in handy later.
Signed-off-by: David Mosberger-Tang <davidm@...uge.net>
---
drivers/net/wireless/microchip/wilc1000/spi.c | 52 +++++++++++--------
1 file changed, 30 insertions(+), 22 deletions(-)
diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c
index 3e2022b43ee70..8951202ed76e2 100644
--- a/drivers/net/wireless/microchip/wilc1000/spi.c
+++ b/drivers/net/wireless/microchip/wilc1000/spi.c
@@ -80,6 +80,18 @@ static int wilc_spi_reset(struct wilc *wilc);
#define PROTOCOL_REG_CRC16_MASK GENMASK(3, 3)
#define PROTOCOL_REG_CRC7_MASK GENMASK(2, 2)
+/* The response to data packets is two bytes long. For efficiency's
+ * sake, when DMAing data to WILC, we ignore the responses for all
+ * data packets except the final one. The downside of this
+ * optimization is that when the final data packet is short, we may
+ * receive (part of) the response to the second-to-last packet before
+ * the one for the final packet. To handle this, we always read 4
+ * bytes and then search for the last byte that contains the "Response
+ * Start" code (0xc in the top 4 bits). We then know that this byte
+ * is the first response byte of the final data packet.
+ */
+#define WILC_SPI_DATA_RSP_BYTES 4
+
/*
* The SPI data packet size may be any integer power of two in the
* range from 256 to 8192 bytes.
@@ -950,31 +962,13 @@ static int wilc_spi_write_reg(struct wilc *wilc, u32 addr, u32 data)
return 0;
}
-static int spi_data_rsp(struct wilc *wilc, u8 cmd)
+static int spi_data_check_rsp(struct wilc *wilc,
+ u8 rsp[WILC_SPI_DATA_RSP_BYTES])
{
struct spi_device *spi = to_spi_device(wilc->dev);
- int result, i;
- u8 rsp[4];
-
- /*
- * The response to data packets is two bytes long. For
- * efficiency's sake, wilc_spi_write() wisely ignores the
- * responses for all packets but the final one. The downside
- * of that optimization is that when the final data packet is
- * short, we may receive (part of) the response to the
- * second-to-last packet before the one for the final packet.
- * To handle this, we always read 4 bytes and then search for
- * the last byte that contains the "Response Start" code (0xc
- * in the top 4 bits). We then know that this byte is the
- * first response byte of the final data packet.
- */
- result = wilc_spi_rx(wilc, rsp, sizeof(rsp));
- if (result) {
- dev_err(&spi->dev, "Failed bus error...\n");
- return result;
- }
+ int i;
- for (i = sizeof(rsp) - 2; i >= 0; --i)
+ for (i = WILC_SPI_DATA_RSP_BYTES - 2; i >= 0; --i)
if (FIELD_GET(RSP_START_FIELD, rsp[i]) == RSP_START_TAG)
break;
@@ -996,6 +990,20 @@ static int spi_data_rsp(struct wilc *wilc, u8 cmd)
return 0;
}
+static int spi_data_rsp(struct wilc *wilc, u8 cmd)
+{
+ struct spi_device *spi = to_spi_device(wilc->dev);
+ u8 rsp[WILC_SPI_DATA_RSP_BYTES];
+ int result;
+
+ result = wilc_spi_rx(wilc, rsp, sizeof(rsp));
+ if (result) {
+ dev_err(&spi->dev, "Failed bus error...\n");
+ return result;
+ }
+ return spi_data_check_rsp(wilc, rsp);
+}
+
static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
{
struct spi_device *spi = to_spi_device(wilc->dev);
--
2.25.1
Powered by blists - more mailing lists