Skip to contentSkip to conversation

FEC: Do not pass unaligned buffer to network stack

PATCH New Marek Vasut 3 participants 5 messages Aug 26, 2012 – Sep 28, 2012 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 FEC: Do not pass unaligned buffer to network stack

Do not pass unaligned RX buffer to the upper layers. The upper layer, especially in the ARP case, recycles the buffer and passes it back into the FEC, into it's TX path. With caches enabled, the FEC hangs on this from time to time.

Cc Benoit Thebaudeau <benoit.thebaudeau@advans>
Cc Eric Nelson <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Joe Hershberger <[email protected]>
---
 drivers/net/fec_mxc.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/fec_mxc.c +2 -1
index fbfc842..7b6a997 100644
@@ -31,6 +31,7 @@
 #include <asm/arch/imx-regs.h>
 #include <asm/io.h>
 #include <asm/errno.h>
+#include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -791,7 +792,7 @@ static int fec_recv(struct eth_device *dev)
 	uint16_t bd_status;
 	uint32_t addr, size;
 	int i;
-	uchar buff[FEC_MAX_PKT_SIZE];
+	uchar buff[FEC_MAX_PKT_SIZE] __aligned(ARCH_DMA_MINALIGN);
 
 	/*
 	 * Check if any critical events have happened
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 FEC: Properly align address over the buffers for cache ops

Align the address that's to be invalidated/flushed properly.

Cc Benoit Thebaudeau <benoit.thebaudeau@advans>
Cc Eric Nelson <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Joe Hershberger <[email protected]>
---
 drivers/net/fec_mxc.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/fec_mxc.c +8 -6
index 7b6a997..bc44d38 100644
@@ -695,7 +695,7 @@ static void fec_halt(struct eth_device *dev)
 static int fec_send(struct eth_device *dev, void *packet, int length)
 {
 	unsigned int status;
-	uint32_t size;
+	uint32_t size, end;
 	uint32_t addr;
 
 	/*
@@ -722,8 +722,9 @@ static int fec_send(struct eth_device *dev, void *packet, int length)
 #endif
 
 	addr = (uint32_t)packet;
-	size = roundup(length, ARCH_DMA_MINALIGN);
-	flush_dcache_range(addr, addr + size);
+	end = roundup(addr + length, ARCH_DMA_MINALIGN);
+	addr &= ~(ARCH_DMA_MINALIGN - 1);
+	flush_dcache_range(addr, end);
 
 	writew(length, &fec->tbd_base[fec->tbd_index].data_length);
 	writel(addr, &fec->tbd_base[fec->tbd_index].data_pointer);
@@ -790,7 +791,7 @@ static int fec_recv(struct eth_device *dev)
 	int frame_length, len = 0;
 	struct nbuf *frame;
 	uint16_t bd_status;
-	uint32_t addr, size;
+	uint32_t addr, size, end;
 	int i;
 	uchar buff[FEC_MAX_PKT_SIZE] __aligned(ARCH_DMA_MINALIGN);
 
@@ -854,8 +855,9 @@ static int fec_recv(struct eth_device *dev)
 			 * Invalidate data cache over the buffer
 			 */
 			addr = (uint32_t)frame;
-			size = roundup(frame_length, ARCH_DMA_MINALIGN);
-			invalidate_dcache_range(addr, addr + size);
+			end = roundup(addr + frame_length, ARCH_DMA_MINALIGN);
+			addr &= ~(ARCH_DMA_MINALIGN - 1);
+			invalidate_dcache_range(addr, end);
 
 			/*
 			 *  Fill the buffer and pass it to upper layers
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 1/2 FEC: Do not pass unaligned buffer to network stack

In reply to Marek Vasut
Quoted 4 lines · Marek Vasut

Do not pass unaligned RX buffer to the upper layers. The upper layer, especially in the ARP case, recycles the buffer and passes it back into the FEC, into it's TX path. With caches enabled, the FEC hangs on this from time to time.

Nice fix, thanks. TFTP does not hang now after applying this series of patches.

On a mx28evk:

#4 lore raw

PATCH 1/2 FEC: Do not pass unaligned buffer to network stack

In reply to Marek Vasut

Hi Marek,

Quoted 11 lines · Marek Vasut

Do not pass unaligned RX buffer to the upper layers. The upper layer, especially in the ARP case, recycles the buffer and passes it back into the FEC, into it's TX path. With caches enabled, the FEC hangs on this from time to time.

Cc Benoit Thebaudeau <benoit.thebaudeau@advans>
Cc Eric Nelson <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Joe Hershberger <[email protected]>

---

Applied, thanks.

-Joe