Skip to contentSkip to conversation

net: stmmac: loongson1: cleanups

PATCH Applied Russell King (Oracle) 6 participants 10 messages Jun 18, 2025 – Jun 19, 2025

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover net: stmmac: loongson1: cleanups

Hi,

A couple of patches to cleanup loongson1. First, introducing a match data struct to allow the per-match data to be extended beyond the init function pointer, and then adding a setup method to allow the resource base address to be translated to the MAC index at probe time rather than repeatedly in the setup function.

 .../net/ethernet/stmicro/stmmac/dwmac-loongson1.c  | 73 ++++++++++++++++------
 1 file changed, 55 insertions(+), 18 deletions(-)
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!
#1 lore raw

PATCH 1/2 net: stmmac: loongson1: provide match data struct

Provide a structure for match data rather than using the function pointer as match data. This allows stronger type-checking for the function itself, and allows extensions to the match data.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson1.c | 24 ++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c +18 -6
index 3e86810717d3..78d9540be10c 100644
@@ -46,6 +46,10 @@ struct ls1x_dwmac {
 	struct regmap *regmap;
 };
 
+struct ls1x_data {
+	int (*init)(struct platform_device *pdev, void *bsp_priv);
+};
+
 static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
 {
 	struct ls1x_dwmac *dwmac = priv;
@@ -143,9 +147,9 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
 {
 	struct plat_stmmacenet_data *plat_dat;
 	struct stmmac_resources stmmac_res;
+	const struct ls1x_data *data;
 	struct regmap *regmap;
 	struct ls1x_dwmac *dwmac;
-	int (*init)(struct platform_device *pdev, void *priv);
 	int ret;
 
 	ret = stmmac_get_platform_resources(pdev, &stmmac_res);
@@ -159,8 +163,8 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, PTR_ERR(regmap),
 				     "Unable to find syscon\n");
 
-	init = of_device_get_match_data(&pdev->dev);
-	if (!init) {
+	data = of_device_get_match_data(&pdev->dev);
+	if (!data) {
 		dev_err(&pdev->dev, "No of match data provided\n");
 		return -EINVAL;
 	}
@@ -175,21 +179,29 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
 				     "dt configuration failed\n");
 
 	plat_dat->bsp_priv = dwmac;
-	plat_dat->init = init;
+	plat_dat->init = data->init;
 	dwmac->plat_dat = plat_dat;
 	dwmac->regmap = regmap;
 
 	return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
 }
 
+static const struct ls1x_data ls1b_dwmac_data = {
+	.init = ls1b_dwmac_syscon_init,
+};
+
+static const struct ls1x_data ls1c_dwmac_data = {
+	.init = ls1c_dwmac_syscon_init,
+};
+
 static const struct of_device_id ls1x_dwmac_match[] = {
 	{
 		.compatible = "loongson,ls1b-gmac",
-		.data = &ls1b_dwmac_syscon_init,
+		.data = &ls1b_dwmac_data,
 	},
 	{
 		.compatible = "loongson,ls1c-emac",
-		.data = &ls1c_dwmac_syscon_init,
+		.data = &ls1c_dwmac_data,
 	},
 	{ }
 };
Signature · 1 line
2.30.2
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH net-next 1/2] net: stmmac: loongson1: provide match data struct

Quoted 5 lines · Russell King (Oracle)

Provide a structure for match data rather than using the function pointer as match data. This allows stronger type-checking for the function itself, and allows extensions to the match data.

maintainer Reviewed-by Tested-by
#3 lore raw

Re: [PATCH net-next 1/2] net: stmmac: loongson1: provide match data struct

Quoted 9 lines · Simon Horman
Quoted 5 lines · Russell King (Oracle)

Provide a structure for match data rather than using the function pointer as match data. This allows stronger type-checking for the function itself, and allows extensions to the match data.

Signature · 3 lines
Best regards,

Keguang Zhang
Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH net-next 1/2] net: stmmac: loongson1: provide match data struct

In reply to Russell King (Oracle)
Quoted 5 lines · Russell King (Oracle)

Provide a structure for match data rather than using the function pointer as match data. This allows stronger type-checking for the function itself, and allows extensions to the match data.

Andrew

maintainer Reviewed-by Tested-by on v1 1/2
#5 lore raw

Re: [PATCH net-next 1/2] net: stmmac: loongson1: provide match data struct

In reply to Russell King (Oracle)
Quoted 83 lines · Russell King (Oracle)

Provide a structure for match data rather than using the function pointer as match data. This allows stronger type-checking for the function itself, and allows extensions to the match data.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson1.c | 24 ++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c +18 -7
index 3e86810717d3..78d9540be10c 100644
@@ -46,6 +46,10 @@ struct ls1x_dwmac {
        struct regmap *regmap;
 };
 
+struct ls1x_data {
+       int (*init)(struct platform_device *pdev, void *bsp_priv);
+};
+
 static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
 {
        struct ls1x_dwmac *dwmac = priv;
@@ -143,9 +147,9 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
 {
        struct plat_stmmacenet_data *plat_dat;
        struct stmmac_resources stmmac_res;
+       const struct ls1x_data *data;
        struct regmap *regmap;
        struct ls1x_dwmac *dwmac;
-       int (*init)(struct platform_device *pdev, void *priv);
        int ret;
 
        ret = stmmac_get_platform_resources(pdev, &stmmac_res);
@@ -159,8 +163,8 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
                return dev_err_probe(&pdev->dev, PTR_ERR(regmap),
                                     "Unable to find syscon\n");
 
-       init = of_device_get_match_data(&pdev->dev);
-       if (!init) {
+       data = of_device_get_match_data(&pdev->dev);
+       if (!data) {
                dev_err(&pdev->dev, "No of match data provided\n");
                return -EINVAL;
        }
@@ -175,21 +179,29 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
                                     "dt configuration failed\n");
 
        plat_dat->bsp_priv = dwmac;
-       plat_dat->init = init;
+       plat_dat->init = data->init;
        dwmac->plat_dat = plat_dat;
        dwmac->regmap = regmap;
 
        return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
 }
 
+static const struct ls1x_data ls1b_dwmac_data = {
+       .init = ls1b_dwmac_syscon_init,
+};
+
+static const struct ls1x_data ls1c_dwmac_data = {
+       .init = ls1c_dwmac_syscon_init,
+};
+
 static const struct of_device_id ls1x_dwmac_match[] = {
        {
                .compatible = "loongson,ls1b-gmac",
-               .data = &ls1b_dwmac_syscon_init,
+               .data = &ls1b_dwmac_data,
        },
        {
                .compatible = "loongson,ls1c-emac",
-               .data = &ls1c_dwmac_syscon_init,
+               .data = &ls1c_dwmac_data,
        },
        { }
 };
--

2.30.2

Signature · 3 lines
Best regards,

Keguang Zhang
#6 lore raw

PATCH 2/2 net: stmmac: loongson1: get ls1b resource only once

In reply to Russell King (Oracle)

ls1b_dwmac_syscon_init() was getting the stmmac iomem resource to detect which GMAC block is being used. Move this to a separate setup() function that only runs at probe time, so it can sensibly behave with an unrecognised resource adress. Use this to set a MAC index (id) which is then used in place of testing the base address.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson1.c | 49 ++++++++++++++-----
 1 file changed, 37 insertions(+), 12 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c +37 -12
index 78d9540be10c..32b5d1492e2e 100644
@@ -44,28 +44,50 @@
 struct ls1x_dwmac {
 	struct plat_stmmacenet_data *plat_dat;
 	struct regmap *regmap;
+	unsigned int id;
 };
 
 struct ls1x_data {
+	int (*setup)(struct platform_device *pdev,
+		     struct plat_stmmacenet_data *plat_dat);
 	int (*init)(struct platform_device *pdev, void *bsp_priv);
 };
 
-static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
+static int ls1b_dwmac_setup(struct platform_device *pdev,
+			    struct plat_stmmacenet_data *plat_dat)
 {
-	struct ls1x_dwmac *dwmac = priv;
-	struct plat_stmmacenet_data *plat = dwmac->plat_dat;
-	struct regmap *regmap = dwmac->regmap;
+	struct ls1x_dwmac *dwmac = plat_dat->bsp_priv;
 	struct resource *res;
-	unsigned long reg_base;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
+		/* This shouldn't fail - stmmac_get_platform_resources()
+		 * already mapped this resource.
+		 */
 		dev_err(&pdev->dev, "Could not get IO_MEM resources\n");
 		return -EINVAL;
 	}
-	reg_base = (unsigned long)res->start;
 
-	if (reg_base == LS1B_GMAC0_BASE) {
+	if (res->start == LS1B_GMAC0_BASE) {
+		dwmac->id = 0;
+	} else if (res->start == LS1B_GMAC1_BASE) {
+		dwmac->id = 1;
+	} else {
+		dev_err(&pdev->dev, "Invalid Ethernet MAC base address %pR",
+			res);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
+{
+	struct ls1x_dwmac *dwmac = priv;
+	struct plat_stmmacenet_data *plat = dwmac->plat_dat;
+	struct regmap *regmap = dwmac->regmap;
+
+	if (dwmac->id == 0) {
 		switch (plat->phy_interface) {
 		case PHY_INTERFACE_MODE_RGMII_ID:
 			regmap_update_bits(regmap, LS1X_SYSCON0,
@@ -84,7 +106,7 @@ static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
 		}
 
 		regmap_update_bits(regmap, LS1X_SYSCON0, GMAC0_SHUT, 0);
-	} else if (reg_base == LS1B_GMAC1_BASE) {
+	} else if (dwmac->id == 1) {
 		regmap_update_bits(regmap, LS1X_SYSCON0,
 				   GMAC1_USE_UART1 | GMAC1_USE_UART0,
 				   GMAC1_USE_UART1 | GMAC1_USE_UART0);
@@ -108,10 +130,6 @@ static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
 		}
 
 		regmap_update_bits(regmap, LS1X_SYSCON1, GMAC1_SHUT, 0);
-	} else {
-		dev_err(&pdev->dev, "Invalid Ethernet MAC base address %lx",
-			reg_base);
-		return -EINVAL;
 	}
 
 	return 0;
@@ -183,10 +201,17 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
 	dwmac->plat_dat = plat_dat;
 	dwmac->regmap = regmap;
 
+	if (data->setup) {
+		ret = data->setup(pdev, plat_dat);
+		if (ret)
+			return ret;
+	}
+
 	return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
 }
 
 static const struct ls1x_data ls1b_dwmac_data = {
+	.setup = ls1b_dwmac_setup,
 	.init = ls1b_dwmac_syscon_init,
 };
 
Signature · 1 line
2.30.2
reviewer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH net-next 2/2] net: stmmac: loongson1: get ls1b resource only once

Quoted 7 lines · Russell King (Oracle)

ls1b_dwmac_syscon_init() was getting the stmmac iomem resource to detect which GMAC block is being used. Move this to a separate setup() function that only runs at probe time, so it can sensibly behave with an unrecognised resource adress. Use this to set a MAC index (id) which is then used in place of testing the base address.

maintainer Reviewed-by Tested-by on v1 2/2
#8 lore raw

Re: [PATCH net-next 2/2] net: stmmac: loongson1: get ls1b resource only once

In reply to Russell King (Oracle)
Quoted 115 lines · Russell King (Oracle)

ls1b_dwmac_syscon_init() was getting the stmmac iomem resource to detect which GMAC block is being used. Move this to a separate setup() function that only runs at probe time, so it can sensibly behave with an unrecognised resource adress. Use this to set a MAC index (id) which is then used in place of testing the base address.

---
 .../ethernet/stmicro/stmmac/dwmac-loongson1.c | 49 ++++++++++++++-----
 1 file changed, 37 insertions(+), 12 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c +37 -13
index 78d9540be10c..32b5d1492e2e 100644
@@ -44,28 +44,50 @@
 struct ls1x_dwmac {
        struct plat_stmmacenet_data *plat_dat;
        struct regmap *regmap;
+       unsigned int id;
 };
 
 struct ls1x_data {
+       int (*setup)(struct platform_device *pdev,
+                    struct plat_stmmacenet_data *plat_dat);
        int (*init)(struct platform_device *pdev, void *bsp_priv);
 };
 
-static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
+static int ls1b_dwmac_setup(struct platform_device *pdev,
+                           struct plat_stmmacenet_data *plat_dat)
 {
-       struct ls1x_dwmac *dwmac = priv;
-       struct plat_stmmacenet_data *plat = dwmac->plat_dat;
-       struct regmap *regmap = dwmac->regmap;
+       struct ls1x_dwmac *dwmac = plat_dat->bsp_priv;
        struct resource *res;
-       unsigned long reg_base;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
+               /* This shouldn't fail - stmmac_get_platform_resources()
+                * already mapped this resource.
+                */
                dev_err(&pdev->dev, "Could not get IO_MEM resources\n");
                return -EINVAL;
        }
-       reg_base = (unsigned long)res->start;
 
-       if (reg_base == LS1B_GMAC0_BASE) {
+       if (res->start == LS1B_GMAC0_BASE) {
+               dwmac->id = 0;
+       } else if (res->start == LS1B_GMAC1_BASE) {
+               dwmac->id = 1;
+       } else {
+               dev_err(&pdev->dev, "Invalid Ethernet MAC base address %pR",
+                       res);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
+{
+       struct ls1x_dwmac *dwmac = priv;
+       struct plat_stmmacenet_data *plat = dwmac->plat_dat;
+       struct regmap *regmap = dwmac->regmap;
+
+       if (dwmac->id == 0) {
                switch (plat->phy_interface) {
                case PHY_INTERFACE_MODE_RGMII_ID:
                        regmap_update_bits(regmap, LS1X_SYSCON0,
@@ -84,7 +106,7 @@ static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
                }
 
                regmap_update_bits(regmap, LS1X_SYSCON0, GMAC0_SHUT, 0);
-       } else if (reg_base == LS1B_GMAC1_BASE) {
+       } else if (dwmac->id == 1) {
                regmap_update_bits(regmap, LS1X_SYSCON0,
                                   GMAC1_USE_UART1 | GMAC1_USE_UART0,
                                   GMAC1_USE_UART1 | GMAC1_USE_UART0);
@@ -108,10 +130,6 @@ static int ls1b_dwmac_syscon_init(struct platform_device *pdev, void *priv)
                }
 
                regmap_update_bits(regmap, LS1X_SYSCON1, GMAC1_SHUT, 0);
-       } else {
-               dev_err(&pdev->dev, "Invalid Ethernet MAC base address %lx",
-                       reg_base);
-               return -EINVAL;
        }
 
        return 0;
@@ -183,10 +201,17 @@ static int ls1x_dwmac_probe(struct platform_device *pdev)
        dwmac->plat_dat = plat_dat;
        dwmac->regmap = regmap;
 
+       if (data->setup) {
+               ret = data->setup(pdev, plat_dat);
+               if (ret)
+                       return ret;
+       }
+
        return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
 }
 
 static const struct ls1x_data ls1b_dwmac_data = {
+       .setup = ls1b_dwmac_setup,
        .init = ls1b_dwmac_syscon_init,
 };
 
--

2.30.2

Signature · 3 lines
Best regards,

Keguang Zhang
#9 lore raw
In reply to Russell King (Oracle)
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 9 lines · On Wed, 18 Jun 2025 11:41:18 +0100 you wrote:

Hi,

A couple of patches to cleanup loongson1. First, introducing a match data struct to allow the per-match data to be extended beyond the init function pointer, and then adding a setup method to allow the resource base address to be translated to the MAC index at probe time rather than repeatedly in the setup function.

[...]

Here is the summary with links:
- [net-next,1/2] net: stmmac: loongson1: provide match data struct

    https://git.kernel.org/netdev/net-next/c/b1cffac4792b
  - [net-next,2/2] net: stmmac: loongson1: get ls1b resource only once
    https://git.kernel.org/netdev/net-next/c/e3527bf4dc33

You are awesome, thank you!

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