Skip to contentSkip to conversation

net: stmmac: dwmac-socfpga: Cleanup .fix_mac_speed

PATCH Applied Maxime Chevallier 3 participants 12 messages Mar 24 – Mar 27

Subsystems (5)
lore
Share & tools
lore

Maxime Chevallier

author maintainer
#0 lore raw

cover net: stmmac: dwmac-socfpga: Cleanup .fix_mac_speed

Hi everyone,

This small series does a bit of cleanup in the dwmad-socfpga glue driver, especially around the .fix_mac_speed() operation.

It's mostly about re-using existing helpers from the glue driver, as well as reorganizing the code to make the local private structures a little bit smaller.

No functionnal changes are intended, this was tested on cyclone V.

Maxime Chevallier (5):
net: stmmac: dwmac-socfpga: Move internal helpers
net: stmmac: dwmac-socfpga: Use the socfpga_sgmii_config() helper
net: stmmac: dwmac-socfpga: Use the correct type for interface modes
net: stmmac: dwmac-socfpga: get the phy_mode with the dedicated helper
net: stmmac: dwmac-sofcpga: Drop the struct device reference

 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   | 58 +++++++++----------
 1 file changed, 28 insertions(+), 30 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/5 net: stmmac: dwmac-socfpga: Move internal helpers

This is preparatory work to allow reusing the SGMII configuration helper and the wrapper to get the interface in the fix_mac_speed() callback.

---
 .../ethernet/stmicro/stmmac/dwmac-socfpga.c   | 24 +++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +12 -12
index 5f89fd968ae9..42da73b92ceb 100644
@@ -72,6 +72,18 @@ struct socfpga_dwmac {
 	const struct socfpga_dwmac_ops *ops;
 };
 
+static int socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac)
+{
+	return dwmac->plat_dat->phy_interface;
+}
+
+static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
+{
+	u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE;
+
+	writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
+}
+
 static void socfpga_dwmac_fix_mac_speed(void *bsp_priv,
 					phy_interface_t interface, int speed,
 					unsigned int mode)
@@ -244,18 +256,6 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *
 	return ret;
 }
 
-static int socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac)
-{
-	return dwmac->plat_dat->phy_interface;
-}
-
-static void socfpga_sgmii_config(struct socfpga_dwmac *dwmac, bool enable)
-{
-	u16 val = enable ? SGMII_ADAPTER_ENABLE : SGMII_ADAPTER_DISABLE;
-
-	writew(val, dwmac->sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
-}
-
 static int socfpga_set_phy_mode_common(int phymode, u32 *val)
 {
 	switch (phymode) {
Signature · 1 line
2.49.0
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH net-next 1/5] net: stmmac: dwmac-socfpga: Move internal helpers

Quoted 4 lines · Maxime Chevallier

This is preparatory work to allow reusing the SGMII configuration helper and the wrapper to get the interface in the fix_mac_speed() callback.

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
#3 lore raw

PATCH 2/5 net: stmmac: dwmac-socfpga: Use the socfpga_sgmii_config() helper

In reply to Maxime Chevallier

Use the existing socfpga_sgmii_config() helper in socfpga_dwmac_fix_mac_speed(), instead of re-coding the register access.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +2 -4
index 42da73b92ceb..ed6448c0ad2a 100644
@@ -95,8 +95,7 @@ static void socfpga_dwmac_fix_mac_speed(void *bsp_priv,
 	u32 val;
 
 	if (sgmii_adapter_base)
-		writew(SGMII_ADAPTER_DISABLE,
-		       sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
+		socfpga_sgmii_config(dwmac, false);
 
 	if (splitter_base) {
 		val = readl(splitter_base + EMAC_SPLITTER_CTRL_REG);
@@ -121,8 +120,7 @@ static void socfpga_dwmac_fix_mac_speed(void *bsp_priv,
 	if ((priv->plat->phy_interface == PHY_INTERFACE_MODE_SGMII ||
 	     priv->plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) &&
 	     sgmii_adapter_base)
-		writew(SGMII_ADAPTER_ENABLE,
-		       sgmii_adapter_base + SGMII_ADAPTER_CTRL_REG);
+		socfpga_sgmii_config(dwmac, true);
 }
 
 static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *dev)
Signature · 1 line
2.49.0
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH net-next 2/5] net: stmmac: dwmac-socfpga: Use the socfpga_sgmii_config() helper

Quoted 4 lines · Maxime Chevallier

Use the existing socfpga_sgmii_config() helper in socfpga_dwmac_fix_mac_speed(), instead of re-coding the register access.

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
#5 lore raw

PATCH 3/5 net: stmmac: dwmac-socfpga: Use the correct type for interface modes

In reply to Maxime Chevallier

The internal helper socfpga_get_plat_phymode() returns an int where we actually return a PHY_INTERFACE_MODE_xxx, use the correct type for this.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +3 -3
index ed6448c0ad2a..629074dbbc15 100644
@@ -72,7 +72,7 @@ struct socfpga_dwmac {
 	const struct socfpga_dwmac_ops *ops;
 };
 
-static int socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac)
+static phy_interface_t socfpga_get_plat_phymode(struct socfpga_dwmac *dwmac)
 {
 	return dwmac->plat_dat->phy_interface;
 }
@@ -386,7 +386,7 @@ static int smtg_crosststamp(ktime_t *device, struct system_counterval_t *system,
 static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac)
 {
 	struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr;
-	int phymode = socfpga_get_plat_phymode(dwmac);
+	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
 	u32 reg_offset = dwmac->reg_offset;
 	u32 reg_shift = dwmac->reg_shift;
 	u32 ctrl, val, module;
@@ -444,7 +444,7 @@ static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac)
 static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac)
 {
 	struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr;
-	int phymode = socfpga_get_plat_phymode(dwmac);
+	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
 	u32 reg_offset = dwmac->reg_offset;
 	u32 reg_shift = dwmac->reg_shift;
 	u32 ctrl, val, module;
Signature · 1 line
2.49.0
Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH net-next 3/5] net: stmmac: dwmac-socfpga: Use the correct type for interface modes

Quoted 4 lines · Maxime Chevallier

The internal helper socfpga_get_plat_phymode() returns an int where we actually return a PHY_INTERFACE_MODE_xxx, use the correct type for this.

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
#7 lore raw

PATCH 4/5 net: stmmac: dwmac-socfpga: get the phy_mode with the dedicated helper

In reply to Maxime Chevallier

We enable/disable the sgmii_adapter in the .fix_mac_speed() ops based on the phy_mode used in the plat_data. We currently get it with :

socfpga_dwmac
->dev

    ->drv_data
      ->netdev
        ->priv
	  ->stmmac_priv
	    ->plat
	      ->phy_interface

where we can get it with :

socfpga_dwmac
->plat_data

    ->phy_interface (done by socfpga_get_plat_phymode)

Use that helper here.

Note that we are also being passed a phy_interface_t from the .fix_mac_speed() callback, provided by phylink.

We can handle that in the future when dynamic interface selection is supported. We'd need to guarantee that we have a Lynx PCS to handle it.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +4 -5
index 629074dbbc15..ae40de2ed8eb 100644
@@ -89,9 +89,9 @@ static void socfpga_dwmac_fix_mac_speed(void *bsp_priv,
 					unsigned int mode)
 {
 	struct socfpga_dwmac *dwmac = (struct socfpga_dwmac *)bsp_priv;
-	struct stmmac_priv *priv = netdev_priv(dev_get_drvdata(dwmac->dev));
-	void __iomem *splitter_base = dwmac->splitter_base;
 	void __iomem *sgmii_adapter_base = dwmac->sgmii_adapter_base;
+	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
+	void __iomem *splitter_base = dwmac->splitter_base;
 	u32 val;
 
 	if (sgmii_adapter_base)
@@ -117,9 +117,8 @@ static void socfpga_dwmac_fix_mac_speed(void *bsp_priv,
 		writel(val, splitter_base + EMAC_SPLITTER_CTRL_REG);
 	}
 
-	if ((priv->plat->phy_interface == PHY_INTERFACE_MODE_SGMII ||
-	     priv->plat->phy_interface == PHY_INTERFACE_MODE_1000BASEX) &&
-	     sgmii_adapter_base)
+	if ((phymode == PHY_INTERFACE_MODE_SGMII ||
+	     phymode == PHY_INTERFACE_MODE_1000BASEX) && sgmii_adapter_base)
 		socfpga_sgmii_config(dwmac, true);
 }
 
Signature · 1 line
2.49.0
Reviewed-by on v1 4/5
#8 lore raw

Re: [PATCH net-next 4/5] net: stmmac: dwmac-socfpga: get the phy_mode with the dedicated helper

Quoted 20 lines · Maxime Chevallier

We enable/disable the sgmii_adapter in the .fix_mac_speed() ops based on the phy_mode used in the plat_data. We currently get it with :

socfpga_dwmac
->dev

    ->drv_data
      ->netdev
        ->priv
	  ->stmmac_priv
	    ->plat
	      ->phy_interface

where we can get it with :

socfpga_dwmac
->plat_data

    ->phy_interface (done by socfpga_get_plat_phymode)

Use that helper here.

Quoted 7 lines

Note that we are also being passed a phy_interface_t from the .fix_mac_speed() callback, provided by phylink.

We can handle that in the future when dynamic interface selection is supported. We'd need to guarantee that we have a Lynx PCS to handle it.

Nice cleanup!

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
#9 lore raw

PATCH 5/5 net: stmmac: dwmac-sofcpga: Drop the struct device reference

In reply to Maxime Chevallier

We keep a reference to our the struct device in the socfpga_dwmac priv structure, but now it's only ever used to produce logs in the .set_phy_mode() ops, that are specific to this driver.

When we call that ops, we always have a ref to the struct device around, so let's pass it to .set_phy_mode(). We can now discard that reference from struct socfpga_dwmac.

---
 .../net/ethernet/stmicro/stmmac/dwmac-socfpga.c   | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +8 -7
index ae40de2ed8eb..1d7f0a57d288 100644
@@ -53,14 +53,14 @@
 
 struct socfpga_dwmac;
 struct socfpga_dwmac_ops {
-	int (*set_phy_mode)(struct socfpga_dwmac *dwmac_priv);
+	int (*set_phy_mode)(struct socfpga_dwmac *dwmac_priv,
+			    struct device *dev);
 	void (*setup_plat_dat)(struct socfpga_dwmac *dwmac_priv);
 };
 
 struct socfpga_dwmac {
 	u32	reg_offset;
 	u32	reg_shift;
-	struct	device *dev;
 	struct plat_stmmacenet_data *plat_dat;
 	struct regmap *sys_mgr_base_addr;
 	struct reset_control *stmmac_rst;
@@ -243,7 +243,6 @@ static int socfpga_dwmac_parse_data(struct socfpga_dwmac *dwmac, struct device *
 	dwmac->reg_offset = reg_offset;
 	dwmac->reg_shift = reg_shift;
 	dwmac->sys_mgr_base_addr = sys_mgr_base_addr;
-	dwmac->dev = dev;
 	of_node_put(np_sgmii_adapter);
 
 	return 0;
@@ -382,7 +381,8 @@ static int smtg_crosststamp(ktime_t *device, struct system_counterval_t *system,
 	return 0;
 }
 
-static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac)
+static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac,
+				     struct device *dev)
 {
 	struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr;
 	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
@@ -391,7 +391,7 @@ static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac)
 	u32 ctrl, val, module;
 
 	if (socfpga_set_phy_mode_common(phymode, &val)) {
-		dev_err(dwmac->dev, "bad phy mode %d\n", phymode);
+		dev_err(dev, "bad phy mode %d\n", phymode);
 		return -EINVAL;
 	}
 
@@ -440,7 +440,8 @@ static int socfpga_gen5_set_phy_mode(struct socfpga_dwmac *dwmac)
 	return 0;
 }
 
-static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac)
+static int socfpga_gen10_set_phy_mode(struct socfpga_dwmac *dwmac,
+				      struct device *dev)
 {
 	struct regmap *sys_mgr_base_addr = dwmac->sys_mgr_base_addr;
 	phy_interface_t phymode = socfpga_get_plat_phymode(dwmac);
@@ -552,7 +553,7 @@ static int socfpga_dwmac_init(struct device *dev, void *bsp_priv)
 {
 	struct socfpga_dwmac *dwmac = bsp_priv;
 
-	return dwmac->ops->set_phy_mode(dwmac);
+	return dwmac->ops->set_phy_mode(dwmac, dev);
 }
 
 static void socfpga_gen5_setup_plat_dat(struct socfpga_dwmac *dwmac)
Signature · 1 line
2.49.0
Reviewed-by on v1 5/5
#10 lore raw

Re: [PATCH net-next 5/5] net: stmmac: dwmac-sofcpga: Drop the struct device reference

Quoted 18 lines · Maxime Chevallier

We keep a reference to our the struct device in the socfpga_dwmac priv structure, but now it's only ever used to produce logs in the .set_phy_mode() ops, that are specific to this driver.

When we call that ops, we always have a ref to the struct device around, so let's pass it to .set_phy_mode(). We can now discard that reference from struct socfpga_dwmac.

---
 .../net/ethernet/stmicro/stmmac/dwmac-socfpga.c   | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +0 -0
index ae40de2ed8eb..1d7f0a57d288 100644

drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c line 57

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +2 -1
@@ -53,14 +53,14 @@
 
 struct socfpga_dwmac;
 struct socfpga_dwmac_ops {
-	int (*set_phy_mode)(struct socfpga_dwmac *dwmac_priv);
+	int (*set_phy_mode)(struct socfpga_dwmac *dwmac_priv,
+			    struct device *dev);

As you're changing the signature of this method, would it be more sensible to put "struct device *dev" as the first arg, rather than swapping the order below:

drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c static int socfpga_dwmac_init(struct device *dev, void *bsp_priv) · line 556

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +1 -1
@@ -552,7 +553,7 @@ static int socfpga_dwmac_init(struct device *dev, void *bsp_priv)
 {
 	struct socfpga_dwmac *dwmac = bsp_priv;
 
-	return dwmac->ops->set_phy_mode(dwmac);
+	return dwmac->ops->set_phy_mode(dwmac, dev);

?

In either case:

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!
#11 lore raw
In reply to Maxime Chevallier
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Tue, 24 Mar 2026 10:20:55 +0100 you wrote:

Hi everyone,

This small series does a bit of cleanup in the dwmad-socfpga glue driver, especially around the .fix_mac_speed() operation.

It's mostly about re-using existing helpers from the glue driver, as well as reorganizing the code to make the local private structures a little bit smaller.

[...]

Here is the summary with links:
- [net-next,1/5] net: stmmac: dwmac-socfpga: Move internal helpers

    https://git.kernel.org/netdev/net-next/c/845a04411118
  - [net-next,2/5] net: stmmac: dwmac-socfpga: Use the socfpga_sgmii_config() helper
    https://git.kernel.org/netdev/net-next/c/a7be7cc12442
  - [net-next,3/5] net: stmmac: dwmac-socfpga: Use the correct type for interface modes
    https://git.kernel.org/netdev/net-next/c/9b04ecdfb876
  - [net-next,4/5] net: stmmac: dwmac-socfpga: get the phy_mode with the dedicated helper
    https://git.kernel.org/netdev/net-next/c/adf1536f79a5
  - [net-next,5/5] net: stmmac: dwmac-sofcpga: Drop the struct device reference
    https://git.kernel.org/netdev/net-next/c/9bd1af853750

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html