staging: axis-fifo: use stream accessors for FIFO data transfers
PATCH 1/1 staging: axis-fifo: use stream accessors for FIFO data transfers
To: Greg Kroah-Hartman <[email protected]>
Cc: Jacob Feder <[email protected]>
Cc: Ovidiu Panait <[email protected]>
Cc: Gustavo Piaz da Silva <[email protected]>
Cc: [email protected]
Cc: [email protected]
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.
--- drivers/staging/axis-fifo/axis-fifo.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/staging/axis-fifo/axis-fifo.c +7 -9
@@ -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 );
Signature · 1 line
2.52.0
Greg KH
maintainerQuoted 6 lines · Pramod Maurya
To: Greg Kroah-Hartman <[email protected]>
Cc: Jacob Feder <[email protected]>
Cc: Ovidiu Panait <[email protected]>
Cc: Gustavo Piaz da Silva <[email protected]>
Cc: [email protected]
Cc: [email protected]
Again, why is this here?
Quoted 8 lines
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 architecturesiowrite32()maps towritel()andioread32()maps toreadl(), 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.
Quoted 7 lines
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_rxdrain loop to use batchedreadsl()withmin_t(unsigned int, ...)to match the types ofwords_availableandREAD_BUF_SIZE, reusing the existing local variable copy.
When you have to say "also", that's a huge hint this should be split up into multiple changes. Please do that here.
thanks,
greg k-h