Skip to contentSkip to conversation

riscv: spacemit: Add ethernet support for K3

PATCH Superseded Inochi Amaoto 2 participants 9 messages Mar 9

Subsystems (8)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Inochi Amaoto

author maintainer
#0 lore raw

v8 cover riscv: spacemit: Add ethernet support for K3

Add initial support for ethernet controller of the Spacemit K3 SoC. This ethernet controller is almost a standard Synopsys DesignWare MAC (version 5.40a). This controller require a syscon device to configure some basic features, like interface type and internal delay.

Change from v7:
- https://lore.kernel.org/netdev/[email protected]
patch 3:
1. Remove unused parameter in spacemit_dwmac_fix_delay().

Change from v6:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. Drop the extra blank line at the last

Change from v5:
- https://lore.kernel.org/netdev/[email protected]
patch 3:
1. fix error from checkpatch

Change from v4:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1 Apply Rob's tag.
2 Adjust clock description according to Russell's suggestion. patch 3:
1. Add set_phy_intf_sel() and get_interfaces() hook, suggested by Russell.

Change from v3:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. fix the uncorrect compatible string postion
patch 3:
1. add "CTRL_" prefix to all ctrl register definition
2. only use delay config 0 to calculate delay code.
3. fix typo in the comment

Change from v2:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. remove not needed compatible for select
2. drop empty line in "spacemit,apmu" properties
3. add spacemit,apmu properties to required.
patch 3:
1. remove misused phy_fix_phy_mode_for_mac_delays.
2. use local tx clock instead of the clk_tx_i in the dwmac.

Change from v1:
- https://lore.kernel.org/netdev/[email protected]
patch 1:
1. remove phy clock
patch 3:
1. improve comment and include something special about Spacmit K3 dwmac
2. reorder the included file
3. fix wrong delay macro used in spacemit_dwmac_set_delay.
4. add check for maximum supported delay.
5. use DIV_ROUND_CLOSEST to calculate best delay configuration.
6. use assign for the ctrl register initial value.
7. fix input when calling of_property_read_u32().

Inochi Amaoto (3):
dt-bindings: net: Add support for Spacemit K3 dwmac
net: stmmac: platform: Add snps,dwmac-5.40a IP compatible string
net: stmmac: Add glue layer for Spacemit K3 SoC

 .../devicetree/bindings/net/snps,dwmac.yaml   |   2 +
 .../bindings/net/spacemit,k3-dwmac.yaml       | 102 ++++++++
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-spacemit.c  | 227 ++++++++++++++++++
 .../ethernet/stmicro/stmmac/stmmac_platform.c |   1 +
 6 files changed, 345 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c

--
2.53.0

author maintainer
#1 lore raw

PATCH v8 1/3 dt-bindings: net: Add support for Spacemit K3 dwmac

The GMAC IP on Spacemit K3 is almost a standard Synopsys DesignWare MAC (version 5.40a) with some extra clock.

Add necessary compatible string for this device.

---
 .../devicetree/bindings/net/snps,dwmac.yaml   |   2 +
 .../bindings/net/spacemit,k3-dwmac.yaml       | 102 ++++++++++++++++++
 2 files changed, 104 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml
Documentation/devicetree/bindings/net/snps,dwmac.yaml +2 -0
index 38bc34dc4f09..98ebb6276bc6 100644
@@ -109,6 +109,7 @@ properties:
         - snps,dwmac-5.10a
         - snps,dwmac-5.20
         - snps,dwmac-5.30a
+        - snps,dwmac-5.40a
         - snps,dwxgmac
         - snps,dwxgmac-2.10
         - sophgo,sg2042-dwmac
@@ -656,6 +657,7 @@ allOf:
                 - snps,dwmac-5.10a
                 - snps,dwmac-5.20
                 - snps,dwmac-5.30a
+                - snps,dwmac-5.40a
                 - snps,dwxgmac
                 - snps,dwxgmac-2.10
                 - st,spear600-gmac
Documentation/devicetree/bindings/net/spacemit,k3-dwmac.yaml new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH v8 2/3 net: stmmac: platform: Add snps,dwmac-5.40a IP compatible string

In reply to Inochi Amaoto

Add compatible string for 5.40a version that can avoid to define some platform data in the glue layer.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +1 -0
index 5c9fd91a1db9..02303a808fb5 100644
@@ -396,6 +396,7 @@ static const char * const stmmac_gmac4_compats[] = {
 	"snps,dwmac-5.10a",
 	"snps,dwmac-5.20",
 	"snps,dwmac-5.30a",
+	"snps,dwmac-5.40a",
 	NULL
 };
 
Signature · 1 line
2.53.0
Reviewed-by on v8 2/3
#3 lore raw

Re: [PATCH net-next v8 2/3] net: stmmac: platform: Add snps,dwmac-5.40a IP compatible string

Quoted 4 lines · Inochi Amaoto

Add compatible string for 5.40a version that can avoid to define some platform data in the glue layer.

Thanks!

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author maintainer
#4 lore raw

PATCH v8 3/3 net: stmmac: Add glue layer for Spacemit K3 SoC

In reply to Inochi Amaoto

The ethernet controller on Spacemit K3 SoC is Synopsys DesignWare MAC (version 5.40a), with the following special points:
1. The rate of the tx clock line is auto changed when the mac speed rate is changed, and no need for changing the input tx clock.
2. This controller require a extra syscon device to configure the interface type, enable wake up interrupt and delay configuration if needed.

Add Spacemit dwmac driver support on the Spacemit K3 SoC.

---
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-spacemit.c  | 227 ++++++++++++++++++
 3 files changed, 240 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c
drivers/net/ethernet/stmicro/stmmac/Kconfig +12 -0
index 07088d03dbab..d3a6ab7383fc 100644
@@ -216,6 +216,18 @@ config DWMAC_SOPHGO
 	  for the stmmac device driver. This driver is used for the
 	  ethernet controllers on various Sophgo SoCs.
 
+config DWMAC_SPACEMIT
+	tristate "Spacemit dwmac support"
+	depends on OF && (ARCH_SPACEMIT || COMPILE_TEST)
+	select MFD_SYSCON
+	default m if ARCH_SPACEMIT
+	help
+	  Support for ethernet controllers on Spacemit RISC-V SoCs
+
+	  This selects the Spacemit platform specific glue layer support
+	  for the stmmac device driver. This driver is used for the
+	  Spacemit K3 ethernet controllers.
+
 config DWMAC_STARFIVE
 	tristate "StarFive dwmac support"
 	depends on OF && (ARCH_STARFIVE || COMPILE_TEST)
drivers/net/ethernet/stmicro/stmmac/Makefile +1 -0
index c9263987ef8d..945c5354eced 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_DWMAC_RZN1)	+= dwmac-rzn1.o
 obj-$(CONFIG_DWMAC_S32)		+= dwmac-s32.o
 obj-$(CONFIG_DWMAC_SOCFPGA)	+= dwmac-altr-socfpga.o
 obj-$(CONFIG_DWMAC_SOPHGO)	+= dwmac-sophgo.o
+obj-$(CONFIG_DWMAC_SPACEMIT)	+= dwmac-spacemit.o
 obj-$(CONFIG_DWMAC_STARFIVE)	+= dwmac-starfive.o
 obj-$(CONFIG_DWMAC_STI)		+= dwmac-sti.o
 obj-$(CONFIG_DWMAC_STM32)	+= dwmac-stm32.o
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
2.53.0
Reviewed-by on v8 3/3
#5 lore raw

Re: [PATCH net-next v8 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC

drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 105

Quoted 5 lines · Inochi Amaoto
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +5 -0
+static int spacemit_dwmac_update_irq_config(struct spacmit_dwmac *dwmac,
+					    struct stmmac_resources *stmmac_res)
+{
+	unsigned int mask = CTRL_WAKE_IRQ_EN;
+	unsigned int val = stmmac_res->wol_irq >= 0 ? CTRL_WAKE_IRQ_EN : 0;

This looks like the last thing I can spot that needs to be addressed. netdev wants to see "reverse christmas tree" local variable declarations.

Please reverse the order of these two declarations to achieve that.

With that fixed:

Thanks!

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author maintainer
#6 lore raw

Re: [PATCH net-next v8 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC

Quoted 11 lines · Russell King (Oracle)

drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c line 105

Quoted 5 lines · Inochi Amaoto
drivers/net/ethernet/stmicro/stmmac/dwmac-spacemit.c new file +5 -0
+static int spacemit_dwmac_update_irq_config(struct spacmit_dwmac *dwmac,
+					    struct stmmac_resources *stmmac_res)
+{
+	unsigned int mask = CTRL_WAKE_IRQ_EN;
+	unsigned int val = stmmac_res->wol_irq >= 0 ? CTRL_WAKE_IRQ_EN : 0;

This looks like the last thing I can spot that needs to be addressed. netdev wants to see "reverse christmas tree" local variable declarations.

Quoted 8 lines

Please reverse the order of these two declarations to achieve that.

With that fixed:

Thanks!

Great, after some lookup, I find the variables in function spacemit_set_phy_intf_sel() are also needed to reversed. I will also fix this in the next version.

Regards,
Inochi

#7 lore raw

Re: [PATCH net-next v8 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC

In reply to Inochi Amaoto
Quoted 3 lines
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-spacemit.c  | 227 ++++++++++++++++++

One last point, please add another patch which adds a MAINTAINERS entry for this file, so you can be Cc'd with future stmmac developments.

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author maintainer
#8 lore raw

Re: [PATCH net-next v8 3/3] net: stmmac: Add glue layer for Spacemit K3 SoC

Quoted 9 lines · Russell King (Oracle)
Quoted 3 lines
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  12 +
 drivers/net/ethernet/stmicro/stmmac/Makefile  |   1 +
 .../ethernet/stmicro/stmmac/dwmac-spacemit.c  | 227 ++++++++++++++++++

One last point, please add another patch which adds a MAINTAINERS entry for this file, so you can be Cc'd with future stmmac developments.

Thanks.

OK, I will add a MAINTAINERS entry for both this file and binding file.

Regards,
Inochi