Skip to contentSkip to conversation

stmmac: probe code refactoring and clean up part 1

PATCH In review Joachim Eastwood 2 participants 6 messages May 20, 2015 – May 21, 2015

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

cover stmmac: probe code refactoring and clean up part 1

This patch set refactor the code in stmmac_pci_probe and stmmac_pltfr_probe and moves the common bits into stmmac_dvr_probe. Along the way some clean- ups are applied to stmmac_pltfr_probe.

The code has been tested on the LPC18xx platform.

I am still working on more refactoring of the platform probe code, hence part 1, but I need some more time on this.

Joachim Eastwood (4):
stmmac: move driver data setting into stmmac_dvr_probe
stmmac: let stmmac_dvr_probe take a struct of resources
stmmac: change the stmmac_dvr_probe return type to int
stmmac: drop unnecessary dt checks in stmmac_probe_config_dt

 drivers/net/ethernet/stmicro/stmmac/stmmac.h       | 14 +++--
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 30 +++++++----
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c   | 19 +++----
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  | 62 +++++++---------------
 4 files changed, 54 insertions(+), 71 deletions(-)
Signature · 1 line
1.8.0
#1 lore raw

PATCH 1/4 stmmac: move driver data setting into stmmac_dvr_probe

Move setting of driver data into stmmac_dvr_probe so the other probe functions don't have to. This will help to simplify the other probe functions later.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c     | 2 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c      | 2 --
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 2 --
 3 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -0
index 05c146f718a3..fae9195c8ff7 100644
@@ -2830,6 +2830,8 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 	priv->ioaddr = addr;
 	priv->dev->base_addr = (unsigned long)addr;
 
+	dev_set_drvdata(device, priv);
+
 	/* Verify driver arguments */
 	stmmac_verify_args();
 
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +0 -2
index 3bca908716e2..4743d0017d79 100644
@@ -222,8 +222,6 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
 	priv->dev->irq = pdev->irq;
 	priv->wol_irq = pdev->irq;
 
-	pci_set_drvdata(pdev, priv->dev);
-
 	dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n");
 
 	return 0;
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +0 -2
index ffe9e820b312..6db27dee0901 100644
@@ -349,8 +349,6 @@ int stmmac_pltfr_probe(struct platform_device *pdev)
 	if (mac)
 		memcpy(priv->dev->dev_addr, mac, ETH_ALEN);
 
-	platform_set_drvdata(pdev, priv->dev);
-
 	pr_debug("STMMAC platform driver registration completed");
 
 	return 0;
Signature · 1 line
1.8.0
#2 lore raw

PATCH 2/4 stmmac: let stmmac_dvr_probe take a struct of resources

In reply to Joachim Eastwood

Creat a struct that contain all the resources that needs to be assigned to the priv struct in stmmac_dvr_probe. This makes it possible to factor out more common code from the other probe functions and also use this struct to hold the resources as they are fetched.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h       | 10 ++++-
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 15 ++++++--
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c   | 10 +++--
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  | 45 +++++++++-------------
 4 files changed, 45 insertions(+), 35 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +9 -1
index 2ac9552d1fa3..b1687adb8e02 100644
@@ -34,6 +34,14 @@
 #include <linux/ptp_clock_kernel.h>
 #include <linux/reset.h>
 
+struct stmmac_resources {
+	void __iomem *addr;
+	const char *mac;
+	int wol_irq;
+	int lpi_irq;
+	int irq;
+};
+
 struct stmmac_tx_info {
 	dma_addr_t buf;
 	bool map_as_page;
@@ -131,7 +139,7 @@ int stmmac_suspend(struct net_device *ndev);
 int stmmac_dvr_remove(struct net_device *ndev);
 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 				     struct plat_stmmacenet_data *plat_dat,
-				     void __iomem *addr);
+				     struct stmmac_resources *res);
 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
 bool stmmac_eee_init(struct stmmac_priv *priv);
 
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +11 -4
index fae9195c8ff7..e8b630a1f1ef 100644
@@ -2799,7 +2799,7 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
  * stmmac_dvr_probe
  * @device: device pointer
  * @plat_dat: platform data pointer
- * @addr: iobase memory address
+ * @res: stmmac resource pointer
  * Description: this is the main probe function used to
  * call the alloc_etherdev, allocate the priv structure.
  * Return:
@@ -2808,7 +2808,7 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
  */
 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 				     struct plat_stmmacenet_data *plat_dat,
-				     void __iomem *addr)
+				     struct stmmac_resources *res)
 {
 	int ret = 0;
 	struct net_device *ndev = NULL;
@@ -2827,8 +2827,15 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 	stmmac_set_ethtool_ops(ndev);
 	priv->pause = pause;
 	priv->plat = plat_dat;
-	priv->ioaddr = addr;
-	priv->dev->base_addr = (unsigned long)addr;
+	priv->ioaddr = res->addr;
+	priv->dev->base_addr = (unsigned long)res->addr;
+
+	priv->dev->irq = res->irq;
+	priv->wol_irq = res->wol_irq;
+	priv->lpi_irq = res->lpi_irq;
+
+	if (res->mac)
+		memcpy(priv->dev->dev_addr, res->mac, ETH_ALEN);
 
 	dev_set_drvdata(device, priv);
 
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +7 -3
index 4743d0017d79..2c663ec2dfb3 100644
@@ -163,6 +163,7 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
 {
 	struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
 	struct plat_stmmacenet_data *plat;
+	struct stmmac_resources res;
 	struct stmmac_priv *priv;
 	int i;
 	int ret;
@@ -214,13 +215,16 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
 
 	pci_enable_msi(pdev);
 
-	priv = stmmac_dvr_probe(&pdev->dev, plat, pcim_iomap_table(pdev)[i]);
+	memset(&res, 0, sizeof(res));
+	res.addr = pcim_iomap_table(pdev)[i];
+	res.wol_irq = pdev->irq;
+	res.irq = pdev->irq;
+
+	priv = stmmac_dvr_probe(&pdev->dev, plat, &res);
 	if (IS_ERR(priv)) {
 		dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__);
 		return PTR_ERR(priv);
 	}
-	priv->dev->irq = pdev->irq;
-	priv->wol_irq = pdev->irq;
 
 	dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n");
 
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +18 -27

92 lines not on this page · raw message

Signature · 1 line
1.8.0
#3 lore raw

PATCH 3/4 stmmac: change the stmmac_dvr_probe return type to int

In reply to Joachim Eastwood

Since stmmac_dvr_probe takes care of setting driver data and assign resources to the priv structure there is no need to access the priv structure from the other probe functions. This mean that this function can be changed into just return an int and thus simplifying the callers.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h          |  6 +++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c     | 15 +++++++--------
 drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c      | 11 +----------
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 11 +----------
 4 files changed, 12 insertions(+), 31 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +3 -3
index b1687adb8e02..9cbcae203597 100644
@@ -137,9 +137,9 @@ void stmmac_ptp_unregister(struct stmmac_priv *priv);
 int stmmac_resume(struct net_device *ndev);
 int stmmac_suspend(struct net_device *ndev);
 int stmmac_dvr_remove(struct net_device *ndev);
-struct stmmac_priv *stmmac_dvr_probe(struct device *device,
-				     struct plat_stmmacenet_data *plat_dat,
-				     struct stmmac_resources *res);
+int stmmac_dvr_probe(struct device *device,
+		     struct plat_stmmacenet_data *plat_dat,
+		     struct stmmac_resources *res);
 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
 bool stmmac_eee_init(struct stmmac_priv *priv);
 
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -8
index e8b630a1f1ef..538de1ae4e2d 100644
@@ -2803,12 +2803,11 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
  * Description: this is the main probe function used to
  * call the alloc_etherdev, allocate the priv structure.
  * Return:
- * on success the new private structure is returned, otherwise the error
- * pointer.
+ * returns 0 on success, otherwise errno.
  */
-struct stmmac_priv *stmmac_dvr_probe(struct device *device,
-				     struct plat_stmmacenet_data *plat_dat,
-				     struct stmmac_resources *res)
+int stmmac_dvr_probe(struct device *device,
+		     struct plat_stmmacenet_data *plat_dat,
+		     struct stmmac_resources *res)
 {
 	int ret = 0;
 	struct net_device *ndev = NULL;
@@ -2816,7 +2815,7 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 
 	ndev = alloc_etherdev(sizeof(struct stmmac_priv));
 	if (!ndev)
-		return ERR_PTR(-ENOMEM);
+		return -ENOMEM;
 
 	SET_NETDEV_DEV(ndev, device);
 
@@ -2952,7 +2951,7 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
 		}
 	}
 
-	return priv;
+	return 0;
 
 error_mdio_register:
 	unregister_netdev(ndev);
@@ -2965,7 +2964,7 @@ error_pclk_get:
 error_clk_get:
 	free_netdev(ndev);
 
-	return ERR_PTR(ret);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(stmmac_dvr_probe);
 
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +1 -10
index 2c663ec2dfb3..d71a721ea61c 100644
@@ -164,7 +164,6 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
 	struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
 	struct plat_stmmacenet_data *plat;
 	struct stmmac_resources res;
-	struct stmmac_priv *priv;
 	int i;
 	int ret;
 
@@ -220,15 +219,7 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
 	res.wol_irq = pdev->irq;
 	res.irq = pdev->irq;
 
-	priv = stmmac_dvr_probe(&pdev->dev, plat, &res);
-	if (IS_ERR(priv)) {
-		dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__);
-		return PTR_ERR(priv);
-	}
-
-	dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n");
-
-	return 0;
+	return stmmac_dvr_probe(&pdev->dev, plat, &res);
 }
 
 /**
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +1 -10
index 6b7481afbdf7..10de9351a1ec 100644
@@ -255,7 +255,6 @@ int stmmac_pltfr_probe(struct platform_device *pdev)
 	int ret = 0;
 	struct resource *res;
 	struct device *dev = &pdev->dev;
-	struct stmmac_priv *priv = NULL;
 	struct plat_stmmacenet_data *plat_dat = NULL;
 
 	memset(&stmmac_res, 0, sizeof(stmmac_res));
@@ -334,15 +333,7 @@ int stmmac_pltfr_probe(struct platform_device *pdev)
 			return ret;
 	}
 
-	priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, &stmmac_res);
-	if (IS_ERR(priv)) {
-		pr_err("%s: main driver probe failed", __func__);
-		return PTR_ERR(priv);
-	}
-
-	pr_debug("STMMAC platform driver registration completed");
-
-	return 0;
+	return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
 }
 EXPORT_SYMBOL_GPL(stmmac_pltfr_probe);
 
Signature · 1 line
1.8.0
#4 lore raw

PATCH 4/4 stmmac: drop unnecessary dt checks in stmmac_probe_config_dt

In reply to Joachim Eastwood

Since the caller already check the presence of a of_node there is no need to repeat the check in stmmac_probe_config_dt.

There is also no point in checking the return value of the of_match_device function since if there wasn't match in the first place we would never be in this function.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +0 -6
index 10de9351a1ec..d2bb7907bf61 100644
@@ -111,13 +111,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
 	const struct of_device_id *device;
 	struct device *dev = &pdev->dev;
 
-	if (!np)
-		return -ENODEV;
-
 	device = of_match_device(dev->driver->of_match_table, dev);
-	if (!device)
-		return -ENODEV;
-
 	if (device->data) {
 		const struct stmmac_of_data *data = device->data;
 		plat->has_gmac = data->has_gmac;
Signature · 1 line
1.8.0
maintainer
#5 lore raw
In reply to Joachim Eastwood

From: Joachim Eastwood <[email protected]>
Date: Wed, 20 May 2015 20:03:05 +0200

Quoted 8 lines

This patch set refactor the code in stmmac_pci_probe and stmmac_pltfr_probe and moves the common bits into stmmac_dvr_probe. Along the way some clean- ups are applied to stmmac_pltfr_probe.

The code has been tested on the LPC18xx platform.

I am still working on more refactoring of the platform probe code, hence part 1, but I need some more time on this.

Series applied, thank you.