Commit 5c57a901 authored by Ido Yariv's avatar Ido Yariv Committed by Luciano Coelho

wl1271: Handle large SPI transfers

The HW supports up to 4095 bytes transfers via SPI. The SPI read & write
operations do not handle larger transfers, causing the HW to stall in such
cases.

Fix this by fragmenting large transfers into smaller chunks, and
transferring each one separately.
Signed-off-by: default avatarIdo Yariv <ido@wizery.com>
Tested-by: default avatarJuuso Oikarinen <juuso.oikarinen@nokia.com>
Signed-off-by: default avatarLuciano Coelho <luciano.coelho@nokia.com>
parent 65836112
...@@ -63,6 +63,11 @@ ...@@ -63,6 +63,11 @@
((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32)) ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32))
#define HW_ACCESS_WSPI_INIT_CMD_MASK 0 #define HW_ACCESS_WSPI_INIT_CMD_MASK 0
/* HW limitation: maximum possible chunk size is 4095 bytes */
#define WSPI_MAX_CHUNK_SIZE 4092
#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
static inline struct spi_device *wl_to_spi(struct wl1271 *wl) static inline struct spi_device *wl_to_spi(struct wl1271 *wl)
{ {
return wl->if_priv; return wl->if_priv;
...@@ -202,90 +207,117 @@ static int wl1271_spi_read_busy(struct wl1271 *wl) ...@@ -202,90 +207,117 @@ static int wl1271_spi_read_busy(struct wl1271 *wl)
static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
size_t len, bool fixed) size_t len, bool fixed)
{ {
struct spi_transfer t[3]; struct spi_transfer t[2];
struct spi_message m; struct spi_message m;
u32 *busy_buf; u32 *busy_buf;
u32 *cmd; u32 *cmd;
u32 chunk_len;
cmd = &wl->buffer_cmd; while (len > 0) {
busy_buf = wl->buffer_busyword; chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
*cmd = 0; cmd = &wl->buffer_cmd;
*cmd |= WSPI_CMD_READ; busy_buf = wl->buffer_busyword;
*cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
*cmd |= addr & WSPI_CMD_BYTE_ADDR;
if (fixed) *cmd = 0;
*cmd |= WSPI_CMD_FIXED; *cmd |= WSPI_CMD_READ;
*cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
WSPI_CMD_BYTE_LENGTH;
*cmd |= addr & WSPI_CMD_BYTE_ADDR;
spi_message_init(&m); if (fixed)
memset(t, 0, sizeof(t)); *cmd |= WSPI_CMD_FIXED;
t[0].tx_buf = cmd; spi_message_init(&m);
t[0].len = 4; memset(t, 0, sizeof(t));
t[0].cs_change = true;
spi_message_add_tail(&t[0], &m);
/* Busy and non busy words read */ t[0].tx_buf = cmd;
t[1].rx_buf = busy_buf; t[0].len = 4;
t[1].len = WL1271_BUSY_WORD_LEN; t[0].cs_change = true;
t[1].cs_change = true; spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
spi_sync(wl_to_spi(wl), &m); /* Busy and non busy words read */
t[1].rx_buf = busy_buf;
t[1].len = WL1271_BUSY_WORD_LEN;
t[1].cs_change = true;
spi_message_add_tail(&t[1], &m);
if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && spi_sync(wl_to_spi(wl), &m);
wl1271_spi_read_busy(wl)) {
memset(buf, 0, len);
return;
}
spi_message_init(&m); if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
memset(t, 0, sizeof(t)); wl1271_spi_read_busy(wl)) {
memset(buf, 0, chunk_len);
return;
}
t[0].rx_buf = buf; spi_message_init(&m);
t[0].len = len; memset(t, 0, sizeof(t));
t[0].cs_change = true;
spi_message_add_tail(&t[0], &m);
spi_sync(wl_to_spi(wl), &m); t[0].rx_buf = buf;
t[0].len = chunk_len;
t[0].cs_change = true;
spi_message_add_tail(&t[0], &m);
spi_sync(wl_to_spi(wl), &m);
wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd)); wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, len); wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, chunk_len);
if (!fixed)
addr += chunk_len;
buf += chunk_len;
len -= chunk_len;
}
} }
static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
size_t len, bool fixed) size_t len, bool fixed)
{ {
struct spi_transfer t[2]; struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
struct spi_message m; struct spi_message m;
u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
u32 *cmd; u32 *cmd;
u32 chunk_len;
int i;
cmd = &wl->buffer_cmd; WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
*cmd = 0;
*cmd |= WSPI_CMD_WRITE;
*cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
*cmd |= addr & WSPI_CMD_BYTE_ADDR;
if (fixed)
*cmd |= WSPI_CMD_FIXED;
spi_message_init(&m); spi_message_init(&m);
memset(t, 0, sizeof(t)); memset(t, 0, sizeof(t));
t[0].tx_buf = cmd; cmd = &commands[0];
t[0].len = sizeof(*cmd); i = 0;
spi_message_add_tail(&t[0], &m); while (len > 0) {
chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
t[1].tx_buf = buf; *cmd = 0;
t[1].len = len; *cmd |= WSPI_CMD_WRITE;
spi_message_add_tail(&t[1], &m); *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
WSPI_CMD_BYTE_LENGTH;
*cmd |= addr & WSPI_CMD_BYTE_ADDR;
spi_sync(wl_to_spi(wl), &m); if (fixed)
*cmd |= WSPI_CMD_FIXED;
t[i].tx_buf = cmd;
t[i].len = sizeof(*cmd);
spi_message_add_tail(&t[i++], &m);
t[i].tx_buf = buf;
t[i].len = chunk_len;
spi_message_add_tail(&t[i++], &m);
wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd)); wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, len); wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, chunk_len);
if (!fixed)
addr += chunk_len;
buf += chunk_len;
len -= chunk_len;
cmd++;
}
spi_sync(wl_to_spi(wl), &m);
} }
static irqreturn_t wl1271_irq(int irq, void *cookie) static irqreturn_t wl1271_irq(int irq, void *cookie)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment