[PATCH v3 1/3] net: emaclite: enable for more architectures

From: Samuel Obuch samuel.obuch@codasip.com
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 RISC-V.
Use ioremap function instead of ioremap_nocache, and include linux/io.h instead of asm/io.h, so that ioremap function is automatically created, if not defined by the architecture. We can switch to the ioremap function, as Microblaze's ioremap_nocache is just empty and in MIPS implementations of ioremap_nocache and ioremap are the same.
Signed-off-by: Samuel Obuch samuel.obuch@codasip.com ---
v3: Fix commit message, remove addtional asm/io.h include.
v2: Use ioremap instead of ioremap_nocache, switch to linux/io.h.
v1: Do not use ioremap_nocache for archs other than MIPS and Microblaze.
drivers/net/xilinx_emaclite.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index 6c9f1f7c27..29e8271c63 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -14,14 +14,13 @@ #include <console.h> #include <malloc.h> #include <asm/global_data.h> -#include <asm/io.h> #include <phy.h> #include <miiphy.h> #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 +614,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;

From: Samuel Obuch samuel.obuch@codasip.com
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 samuel.obuch@codasip.com --- drivers/net/xilinx_emaclite.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index 29e8271c63..a4851ad36f 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -112,12 +112,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++) @@ -135,8 +135,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; }
@@ -147,7 +146,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,

From: Samuel Obuch samuel.obuch@codasip.com
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.
Signed-off-by: Samuel Obuch samuel.obuch@codasip.com --- drivers/net/xilinx_emaclite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index a4851ad36f..16ba915fba 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -517,6 +517,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"); @@ -525,7 +527,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);

On 9/27/22 13:21, samuel.obuch@codasip.com wrote:
From: Samuel Obuch samuel.obuch@codasip.com
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 RISC-V.
Use ioremap function instead of ioremap_nocache, and include linux/io.h instead of asm/io.h, so that ioremap function is automatically created, if not defined by the architecture. We can switch to the ioremap function, as Microblaze's ioremap_nocache is just empty and in MIPS implementations of ioremap_nocache and ioremap are the same.
Signed-off-by: Samuel Obuch samuel.obuch@codasip.com
v3: Fix commit message, remove addtional asm/io.h include.
v2: Use ioremap instead of ioremap_nocache, switch to linux/io.h.
v1: Do not use ioremap_nocache for archs other than MIPS and Microblaze.
drivers/net/xilinx_emaclite.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index 6c9f1f7c27..29e8271c63 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -14,14 +14,13 @@ #include <console.h> #include <malloc.h> #include <asm/global_data.h> -#include <asm/io.h> #include <phy.h> #include <miiphy.h> #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 +614,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;
Applied all.
Thanks, Michal
participants (2)
-
Michal Simek
-
samuel.obuch@codasip.com