Skip to contentSkip to conversation

Ethernet support for QEMU sifive_u machine

PATCH Superseded Anup Patel 1 participant 7 messages Dec 19, 2018 – Dec 20, 2018

Subsystems (2)
lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v2 cover Ethernet support for QEMU sifive_u machine

This patchset enables Cadance MACB ethernet driver for QEMU sifive_u machine. The Cadance MACB ethernet driver works fine for QEMU sifive_u machince in both M-mode and S-mode with some minor fixes.

The patches are based upon latest RISC-V U-Boot tree
(git://git.denx.de/u-boot-riscv.git) at commit id 9deb8d2fcd13d4a40a4e63c396fe4376af46efac

To try on QEMU, please ensure following patches are applied to QEMU sources:
https://patchwork.kernel.org/patch/10729579/
https://patchwork.kernel.org/patch/10729581/

Changes since v1:
- Minor nit changes in PATCH1

Anup Patel (3):
riscv: Add asm/dma-mapping.h for DMA mappings
net: macb: Fix clk API usage for RISC-V systems
riscv: qemu: Imply MACB ethernet for emulation

 arch/riscv/include/asm/dma-mapping.h | 38 ++++++++++++++++++++++++++++
 board/emulation/qemu-riscv/Kconfig   |  4 +++
 drivers/net/macb.c                   |  4 ++-
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/include/asm/dma-mapping.h
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/3 riscv: Add asm/dma-mapping.h for DMA mappings

From: Anup Patel <[email protected]>

This patch adds asm/dma-mapping.h for Linux-like DMA mappings APIs required by some of the drivers (such as, Cadance MACB Ethernet driver).

---
 arch/riscv/include/asm/dma-mapping.h | 38 ++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 arch/riscv/include/asm/dma-mapping.h
arch/riscv/include/asm/dma-mapping.h new file +38 -0
new file mode 100644
index 0000000000..3d930c90ec
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2018 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __ASM_RISCV_DMA_MAPPING_H
+#define __ASM_RISCV_DMA_MAPPING_H
+
+#include <linux/dma-direction.h>
+
+#define dma_mapping_error(x, y)	0
+
+static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
+{
+	*handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len);
+	return (void *)*handle;
+}
+
+static inline void dma_free_coherent(void *addr)
+{
+	free(addr);
+}
+
+static inline unsigned long dma_map_single(volatile void *vaddr, size_t len,
+					   enum dma_data_direction dir)
+{
+	return (unsigned long)vaddr;
+}
+
+static inline void dma_unmap_single(volatile void *vaddr, size_t len,
+				    unsigned long paddr)
+{
+}
+
+#endif /* __ASM_RISCV_DMA_MAPPING_H */
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/3 net: macb: Fix clk API usage for RISC-V systems

In reply to Anup Patel

From: Anup Patel <[email protected]>

This patch does following fixes in MACB ethernet driver for using it on RISC-V systems (particularly QEMU sifive_u machine):
1. asm/arch/clk.h is not available on RISC-V port so include it only for non-RISC-V systems.
2. Don't fail in macb_enable_clk() if clk_enable() returns -ENOSYS because we get -ENOSYS for fixed-rate clocks.

---
 drivers/net/macb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/macb.c +3 -1
index 94c89c762b..9a06b523cc 100644
@@ -38,7 +38,9 @@
 #include <linux/mii.h>
 #include <asm/io.h>
 #include <asm/dma-mapping.h>
+#ifndef CONFIG_RISCV
 #include <asm/arch/clk.h>
+#endif
 #include <linux/errno.h>
 
 #include "macb.h"
@@ -1066,7 +1068,7 @@ static int macb_enable_clk(struct udevice *dev)
 	 */
 #ifndef CONFIG_MACB_ZYNQ
 	ret = clk_enable(&clk);
-	if (ret)
+	if (ret && ret != -ENOSYS)
 		return ret;
 #endif
 
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH v2 2/3 net: macb: Fix clk API usage for RISC-V systems

+Michal

Quoted 43 lines · Anup Patel

From: Anup Patel <[email protected]>

This patch does following fixes in MACB ethernet driver for using it on RISC-V systems (particularly QEMU sifive_u machine):
1. asm/arch/clk.h is not available on RISC-V port so include it only for non-RISC-V systems.
2. Don't fail in macb_enable_clk() if clk_enable() returns -ENOSYS because we get -ENOSYS for fixed-rate clocks.

---
 drivers/net/macb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/macb.c +3 -2
index 94c89c762b..9a06b523cc 100644
@@ -38,7 +38,9 @@
 #include <linux/mii.h>
 #include <asm/io.h>
 #include <asm/dma-mapping.h>
+#ifndef CONFIG_RISCV
 #include <asm/arch/clk.h>
+#endif
 #include <linux/errno.h>
 
 #include "macb.h"
@@ -1066,7 +1068,7 @@ static int macb_enable_clk(struct udevice *dev)
         */
 #ifndef CONFIG_MACB_ZYNQ
        ret = clk_enable(&clk);
-       if (ret)
+       if (ret && ret != -ENOSYS)
                return ret;
 #endif
 
--

2.17.1

author
#4 lore raw

PATCH v2 3/3 riscv: qemu: Imply MACB ethernet for emulation

In reply to Anup Patel

From: Anup Patel <[email protected]>

This patch enables Cadence MACB ethernet driver for QEMU RISC-V emulation by implying MACB, MII, RGMII and NET_RANDOM_ETHADDR on BOARD_SPECIFIC_OPTIONS.

---
 board/emulation/qemu-riscv/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
board/emulation/qemu-riscv/Kconfig +4 -0
index 0d865acf10..5d9611bdc7 100644
@@ -34,5 +34,9 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	imply BOARD_LATE_INIT
 	imply OF_BOARD_SETUP
 	imply SIFIVE_SERIAL
+	imply MACB
+	imply RGMII
+	imply MII
+	imply NET_RANDOM_ETHADDR
 
 endif
Signature · 1 line
2.17.1
author
#5 lore raw

PATCH v2 3/3 riscv: qemu: Imply MACB ethernet for emulation

+Michal

Quoted 30 lines · Anup Patel

From: Anup Patel <[email protected]>

This patch enables Cadence MACB ethernet driver for QEMU RISC-V emulation by implying MACB, MII, RGMII and NET_RANDOM_ETHADDR on BOARD_SPECIFIC_OPTIONS.

---
 board/emulation/qemu-riscv/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)
board/emulation/qemu-riscv/Kconfig +4 -1
index 0d865acf10..5d9611bdc7 100644
@@ -34,5 +34,9 @@ config BOARD_SPECIFIC_OPTIONS # dummy
        imply BOARD_LATE_INIT
        imply OF_BOARD_SETUP
        imply SIFIVE_SERIAL
+       imply MACB
+       imply RGMII
+       imply MII
+       imply NET_RANDOM_ETHADDR
 
 endif
--

2.17.1

author
#6 lore raw

v2 cover Ethernet support for QEMU sifive_u machine

In reply to Anup Patel

+Michal

Quoted 32 lines · Anup Patel

This patchset enables Cadance MACB ethernet driver for QEMU sifive_u machine. The Cadance MACB ethernet driver works fine for QEMU sifive_u machince in both M-mode and S-mode with some minor fixes.

The patches are based upon latest RISC-V U-Boot tree
(git://git.denx.de/u-boot-riscv.git) at commit id 9deb8d2fcd13d4a40a4e63c396fe4376af46efac

To try on QEMU, please ensure following patches are applied to QEMU sources:
https://patchwork.kernel.org/patch/10729579/
https://patchwork.kernel.org/patch/10729581/

Changes since v1:
- Minor nit changes in PATCH1

Anup Patel (3):
riscv: Add asm/dma-mapping.h for DMA mappings
net: macb: Fix clk API usage for RISC-V systems
riscv: qemu: Imply MACB ethernet for emulation

 arch/riscv/include/asm/dma-mapping.h | 38 ++++++++++++++++++++++++++++
 board/emulation/qemu-riscv/Kconfig   |  4 +++
 drivers/net/macb.c                   |  4 ++-
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/include/asm/dma-mapping.h

--
2.17.1