net: emaclite: fix broken build
Subsystems (2)
PATCH v2 1/3 net: emaclite: fix broken build
From: Samuel Obuch <[email protected]>
Function ioremap_nocache seems to be defined only for mips and microblaze architectures. Therefore, the function call in the emaclite driver causes this driver to be unusable with other architectures, for example riscv.
v2: Use ioremap function instead of ioremap_nocache. Switch to linux/io.h which automatically creates ioremap if not defined by the architecture.
--- drivers/net/xilinx_emaclite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/xilinx_emaclite.c +3 -3
@@ -20,8 +20,8 @@#include <fdtdec.h> #include <linux/delay.h> #include <linux/errno.h> +#include <linux/io.h> #include <linux/kernel.h> -#include <asm/io.h> #include <eth_phy.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -615,8 +615,8 @@ static int emaclite_of_to_plat(struct udevice *dev)int offset =0 ; pdata->iobase =dev_read_addr (dev); - emaclite->regs = (struct emaclite_regs *)ioremap_nocache (pdata->iobase, -0x10000 ); + emaclite->regs = (struct emaclite_regs *)ioremap (pdata->iobase, +0x10000 ); emaclite->phyaddr =-1 ;
Signature · 1 line
2.31.1
PATCH v2 2/3 net: emaclite: fix xemaclite_alignedread/write functions
From: Samuel Obuch <[email protected]>
Use __raw_read* and __raw_write* functions to ensure read/write is passed to the memory-mapped regions, as non-volatile accesses may get optimised out.
--- drivers/net/xilinx_emaclite.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/xilinx_emaclite.c +4 -5
@@ -113,12 +113,12 @@ static void xemaclite_alignedread(u32 *srcptr, void *destptr, u32 bytecount)/* Word aligned buffer, no correction needed. */ to32ptr = (u32 *) destptr;while (bytecount >3 ) { - *to32ptr++ = *from32ptr++; + *to32ptr++ =__raw_readl (from32ptr++); bytecount -=4 ; } to8ptr = (u8 *) to32ptr; - alignbuffer = *from32ptr++; + alignbuffer =__raw_readl (from32ptr++); from8ptr = (u8 *) &alignbuffer;for (i =0 ; i < bytecount; i++)
@@ -136,8 +136,7 @@ static void xemaclite_alignedwrite(void *srcptr, u32 *destptr, u32 bytecount) from32ptr = (u32 *) srcptr;while (bytecount >3 ) { - - *to32ptr++ = *from32ptr++; +__raw_writel (*from32ptr++, to32ptr++); bytecount -=4 ; }
@@ -148,7 +147,7 @@ static void xemaclite_alignedwrite(void *srcptr, u32 *destptr, u32 bytecount)for (i =0 ; i < bytecount; i++) *to8ptr++ = *from8ptr++; - *to32ptr++ = alignbuffer; +__raw_writel (alignbuffer, to32ptr++); } static int wait_for_bit(const char *func, u32 *reg, const u32 mask,
Signature · 1 line
2.31.1
Re: [PATCH v2 2/3] net: emaclite: fix xemaclite_alignedread/write functions
Quoted 51 lines · On Fri, Sep 23, 2022 at 3:31 PM <[email protected]> wrote:
From: Samuel Obuch <[email protected]>
Use __raw_read* and __raw_write* functions to ensure read/write is passed to the memory-mapped regions, as non-volatile accesses may get optimised out.
Signed-off-by Samuel Obuch <[email protected]>--- drivers/net/xilinx_emaclite.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/net/xilinx_emaclite.c +4
-6@@ -113,12 +113,12 @@ static void xemaclite_alignedread(u32 *srcptr, void *destptr, u32 bytecount)/* Word aligned buffer, no correction needed. */ to32ptr = (u32 *) destptr;while (bytecount >3 ) { - *to32ptr++ = *from32ptr++; + *to32ptr++ =__raw_readl (from32ptr++); bytecount -=4 ; } to8ptr = (u8 *) to32ptr; - alignbuffer = *from32ptr++; + alignbuffer =__raw_readl (from32ptr++); from8ptr = (u8 *) &alignbuffer;for (i =0 ; i < bytecount; i++)@@ -136,8 +136,7 @@ static void xemaclite_alignedwrite(void *srcptr, u32 *destptr, u32 bytecount) from32ptr = (u32 *) srcptr;while (bytecount >3 ) { - - *to32ptr++ = *from32ptr++; +__raw_writel (*from32ptr++, to32ptr++); bytecount -=4 ; }@@ -148,7 +147,7 @@ static void xemaclite_alignedwrite(void *srcptr, u32 *destptr, u32 bytecount)for (i =0 ; i < bytecount; i++) *to8ptr++ = *from8ptr++; - *to32ptr++ = alignbuffer; +__raw_writel (alignbuffer, to32ptr++); } static int wait_for_bit(const char *func, u32 *reg, const u32 mask, --
Quoted 2 lines
2.31.1
PATCH v2 3/3 net: emaclite: fix handling for IP packets with specific lengths
In reply to [email protected]From: Samuel Obuch <[email protected]>
The maximum length is capped similarly to the emaclite_send function. Avoid integer underflow for values of ip->ip_len < 30, the minimum length of an IP packet is 21 bytes.
--- drivers/net/xilinx_emaclite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/xilinx_emaclite.c +3 -1
@@ -518,6 +518,8 @@ try_again: length =ntohs (ip->ip_len); length +=ETHER_HDR_SIZE +ETH_FCS_LEN ;debug ("IP Packet %x\n" , length); +if (length >PKTSIZE ) + length =PKTSIZE ;break ;default :debug ("Other Packet\n" );
@@ -526,7 +528,7 @@ try_again: }/* Read the rest of the packet which is longer then first read */ -if (length != first_read) +if (length > first_read)xemaclite_alignedread (addr + first_read, etherrxbuff + first_read, length - first_read);
Signature · 1 line
2.31.1
Re: [PATCH v2 3/3] net: emaclite: fix handling for IP packets with specific lengths
Quoted 35 lines · On Fri, Sep 23, 2022 at 3:31 PM <[email protected]> wrote:
From: Samuel Obuch <[email protected]>
The maximum length is capped similarly to the
emaclite_sendfunction. Avoid integer underflow for values ofip->ip_len< 30, the minimum length of an IP packet is 21 bytes.Signed-off-by Samuel Obuch <[email protected]>--- drivers/net/xilinx_emaclite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/xilinx_emaclite.c +3
-2@@ -518,6 +518,8 @@ try_again: length =ntohs (ip->ip_len); length +=ETHER_HDR_SIZE +ETH_FCS_LEN ;debug ("IP Packet %x\n" , length); +if (length >PKTSIZE ) + length =PKTSIZE ;break ;default :debug ("Other Packet\n" );@@ -526,7 +528,7 @@ try_again: }/* Read the rest of the packet which is longer then first read */ -if (length != first_read) +if (length > first_read)xemaclite_alignedread (addr + first_read, etherrxbuff + first_read, length - first_read); --
Quoted 2 lines
2.31.1
Michal Simek
maintainerHi,
can you please update subject line?
Currently this driver is enabled by microblaze and mips which means there are not broken builds that's why subject is not correct.
Quoted 3 lines · On 9/23/22 14:31, [email protected] wrote:
From: Samuel Obuch <[email protected]>
Function
ioremap_nocacheseems to be defined only for mips and microblaze
nit: MIPS and Microblaze
Quoted 2 lines
architectures. Therefore, the function call in the emaclite driver causes this driver to be unusable with other architectures, for example riscv.
RISC-V
Quoted 3 lines
v2: Use ioremap function instead of
ioremap_nocache. Switch tolinux/io.hwhich automatically creates ioremap if not defined by the architecture.
This should go out of commit message below ---.
Quoted 11 lines
Signed-off-by Samuel Obuch <[email protected]>--- drivers/net/xilinx_emaclite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/net/xilinx_emaclite.c +0
-0
drivers/net/xilinx_emaclite.c line 24
Quoted 6 lines
drivers/net/xilinx_emaclite.c +1
-1@@ -20,8 +20,8 @@#include <fdtdec.h> #include <linux/delay.h> #include <linux/errno.h> +#include <linux/io.h> #include <linux/kernel.h> -#include <asm/io.h>
There is actually one more asm/io.h in this file. Please also remove it.
drivers/net/xilinx_emaclite.c static int emaclite_of_to_plat(struct udevice *dev) · line 619
Quoted 11 lines
drivers/net/xilinx_emaclite.c +2
-2#include <eth_phy.h> DECLARE_GLOBAL_DATA_PTR ;@@ -615,8 +615,8 @@ static int emaclite_of_to_plat(struct udevice *dev)int offset =0 ; pdata->iobase =dev_read_addr (dev); - emaclite->regs = (struct emaclite_regs *)ioremap_nocache (pdata->iobase, -0x10000 ); + emaclite->regs = (struct emaclite_regs *)ioremap (pdata->iobase, +0x10000 );
Above you are not saying why you are doing it. It would be good to say in commit message that Microblaze ioremap_nocache is just empty and in MIPS ioremap_nocache implementation is the same with ioremap.
And also that Linux kernel doesn't use any ioremap_nocache function that's why this function shouldn't be used because simple ioremap is uncached already.
drivers/net/xilinx_emaclite.c static int emaclite_of_to_plat(struct udevice *dev) · line 622
Quoted 3 lines
drivers/net/xilinx_emaclite.c +0
-0emaclite->phyaddr =-1 ;
Thanks,
Michal