[PATCH] staging: axis-fifo: use stream accessors for FIFO data transfers

Pramod Maurya posted 1 patch 22 hours ago
drivers/staging/axis-fifo/axis-fifo.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
[PATCH] staging: axis-fifo: use stream accessors for FIFO data transfers
Posted by Pramod Maurya 22 hours ago
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jacob Feder <jacobsfeder@gmail.com>
Cc: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Cc: Gustavo Piaz da Silva <gustavopiazdasilva2102@gmail.com>
Cc: linux-staging@lists.linux.dev
Cc: linux-kernel@vger.kernel.org

The driver uses iowrite32()/ioread32() to transfer payload data to and
from the transmit (XLLF_TDFD_OFFSET) and receive (XLLF_RDFD_OFFSET)
data FIFOs. On big-endian architectures iowrite32() maps to writel()
and ioread32() maps to readl(), both of which perform CPU-to-device
byte-swapping. For AXI-Stream FIFOs, which carry opaque byte streams,
this byte-swapping silently corrupts the payload.

Replace the per-word iowrite32()/ioread32() loops with writesl()/readsl(),
which transfer data without byte-swapping, preserving memory byte order
as required by AXI-Stream FIFO semantics.

Also convert the err_flush_rx drain loop to use batched readsl() with
min_t(unsigned int, ...) to match the types of words_available and
READ_BUF_SIZE, reusing the existing local variable copy.

Fixes: 4a965c5f89de ("staging: add driver for Xilinx AXI-Stream FIFO v4.1 IP core")
Signed-off-by: Pramod Maurya <pramod.nexgen@gmail.com>
---
 drivers/staging/axis-fifo/axis-fifo.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/axis-fifo/axis-fifo.c b/drivers/staging/axis-fifo/axis-fifo.c
index 1c34de020cf8..38e4a691b6dc 100644
--- a/drivers/staging/axis-fifo/axis-fifo.c
+++ b/drivers/staging/axis-fifo/axis-fifo.c
@@ -125,7 +125,6 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
 	unsigned int words_available;
 	unsigned int copied;
 	unsigned int copy;
-	unsigned int i;
 	int ret;
 	u32 tmp_buf[READ_BUF_SIZE];
 
@@ -167,10 +166,7 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
 	while (words_available > 0) {
 		copy = min(words_available, READ_BUF_SIZE);
 
-		for (i = 0; i < copy; i++) {
-			tmp_buf[i] = ioread32(fifo->base_addr +
-					      XLLF_RDFD_OFFSET);
-		}
+		readsl(fifo->base_addr + XLLF_RDFD_OFFSET, tmp_buf, copy);
 		words_available -= copy;
 
 		if (copy_to_user(buf + copied * sizeof(u32), tmp_buf,
@@ -186,8 +182,11 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
 	return bytes_available;
 
 err_flush_rx:
-	while (words_available--)
-		ioread32(fifo->base_addr + XLLF_RDFD_OFFSET);
+	while (words_available > 0) {
+		copy = min_t(unsigned int, words_available, READ_BUF_SIZE);
+		readsl(fifo->base_addr + XLLF_RDFD_OFFSET, tmp_buf, copy);
+		words_available -= copy;
+	}
 
 end_unlock:
 	mutex_unlock(&fifo->read_lock);
@@ -258,8 +257,7 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
 		goto end_unlock;
 	}
 
-	for (int i = 0; i < words_to_write; ++i)
-		iowrite32(txbuf[i], fifo->base_addr + XLLF_TDFD_OFFSET);
+	writesl(fifo->base_addr + XLLF_TDFD_OFFSET, txbuf, words_to_write);
 
 	iowrite32(len, fifo->base_addr + XLLF_TLR_OFFSET);
 
-- 
2.52.0