Skip to contentSkip to conversation

fec.c: several cleanups and bugfixes

PATCH Superseded Lothar Waßmann 3 participants 12 messages Dec 7, 2011 – Dec 8, 2011

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover fec.c: several cleanups and bugfixes

The following set of patches provides some cleanup and bugfixes for drivers/net/ethernet/freescale/fec.c and makes the driver buildable as a module.

Changes wrt v1:
- more appropriate subject lines
- fix a messup in patch 7: mii_cnt must be a driver global variable

Lothar Waßmann (8):
misc cleanups
set con_id in clk_get() call to NULL
prevent dobule restart of interface on FDX/HDX change don't request invalid IRQ
don't munge MAC address from platform data preserve MII/RMII setting in fec_stop()
fix the .remove code
make FEC driver buildable as module

 drivers/net/ethernet/freescale/Kconfig |    2 +-
 drivers/net/ethernet/freescale/fec.c   |   63 ++++++++++++++++++++++----------
 2 files changed, 44 insertions(+), 21 deletions(-)
#1 lore raw

PATCH v2 1/8 fec.c: misc cleanups

- remove some bogus whitespace
- remove line wraps from printk messages

---
 drivers/net/ethernet/freescale/fec.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/freescale/fec.c +8 -6
index 1124ce0..f224e58 100644
@@ -99,7 +99,7 @@ static struct platform_device_id fec_devtype[] = {
 MODULE_DEVICE_TABLE(platform, fec_devtype);
 
 enum imx_fec_type {
-	IMX25_FEC = 1, 	/* runs on i.mx25/50/53 */
+	IMX25_FEC = 1,	/* runs on i.mx25/50/53 */
 	IMX27_FEC,	/* runs on i.mx27/35/51 */
 	IMX28_FEC,
 	IMX6Q_FEC,
@@ -132,7 +132,7 @@ MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address");
 #elif defined (CONFIG_M5272C3)
 #define	FEC_FLASHMAC	(0xffe04000 + 4)
 #elif defined(CONFIG_MOD5272)
-#define FEC_FLASHMAC 	0xffc0406b
+#define FEC_FLASHMAC	0xffc0406b
 #else
 #define	FEC_FLASHMAC	0
 #endif
@@ -972,8 +972,9 @@ static int fec_enet_mii_probe(struct net_device *ndev)
 	}
 
 	if (phy_id >= PHY_MAX_ADDR) {
-		printk(KERN_INFO "%s: no PHY, assuming direct connection "
-			"to switch\n", ndev->name);
+		printk(KERN_INFO
+			"%s: no PHY, assuming direct connection to switch\n",
+			ndev->name);
 		strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE);
 		phy_id = 0;
 	}
@@ -998,8 +999,9 @@ static int fec_enet_mii_probe(struct net_device *ndev)
 	fep->link = 0;
 	fep->full_duplex = 0;
 
-	printk(KERN_INFO "%s: Freescale FEC PHY driver [%s] "
-		"(mii_bus:phy_addr=%s, irq=%d)\n", ndev->name,
+	printk(KERN_INFO
+		"%s: Freescale FEC PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
+		ndev->name,
 		fep->phy_dev->drv->name, dev_name(&fep->phy_dev->dev),
 		fep->phy_dev->irq);
 
Signature · 1 line
1.5.6.5
#2 lore raw

PATCH v2 2/8 fec.c: set con_id in clk_get() call to NULL

The con_id is actually not needed for clk_get().

---
 drivers/net/ethernet/freescale/fec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/freescale/fec.c +1 -1
index f224e58..65ee506 100644
@@ -1585,7 +1585,7 @@ fec_probe(struct platform_device *pdev)
 		}
 	}
 
-	fep->clk = clk_get(&pdev->dev, "fec_clk");
+	fep->clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(fep->clk)) {
 		ret = PTR_ERR(fep->clk);
 		goto failed_clk;
Signature · 1 line
1.5.6.5
#3 lore raw

PATCH v2 3/8 fec.c: prevent dobule restart of interface on FDX/HDX change

Upon detection of a FDX/HDX change the interface is restarted twice.

---
 drivers/net/ethernet/freescale/fec.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/net/ethernet/freescale/fec.c +2 -0
index 65ee506..7ef408f 100644
@@ -865,6 +865,8 @@ static void fec_enet_adjust_link(struct net_device *ndev)
 	if (phy_dev->link) {
 		if (fep->full_duplex != phy_dev->duplex) {
 			fec_restart(ndev, phy_dev->duplex);
+			/* prevent unnecessary second fec_restart() below */
+			fep->link = phy_dev->link;
 			status_change = 1;
 		}
 	}
Signature · 1 line
1.5.6.5
#4 lore raw

PATCH v2 4/8 fec.c: don't request invalid IRQ

prevent calling request_irq() with a known invalid IRQ number and preserve the return value of the platform_get_irq() function

---
 drivers/net/ethernet/freescale/fec.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/freescale/fec.c +6 -2
index 7ef408f..e2b5ce6 100644
@@ -1575,8 +1575,12 @@ fec_probe(struct platform_device *pdev)
 
 	for (i = 0; i < FEC_IRQ_NUM; i++) {
 		irq = platform_get_irq(pdev, i);
-		if (i && irq < 0)
-			break;
+		if (irq < 0) {
+			if (i)
+				break;
+			ret = irq;
+			goto failed_irq;
+		}
 		ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
 		if (ret) {
 			while (--i >= 0) {
Signature · 1 line
1.5.6.5
#5 lore raw

PATCH v2 5/8 fec.c: don't munge MAC address from platform data

When the MAC address is supplied via platform_data it should be OK as it is and should not be modified in case of a dual FEC setup. Also copying the MAC from platform_data to the single 'macaddr' variable will overwrite the MAC for the first interface in case of a dual FEC setup.

---
 drivers/net/ethernet/freescale/fec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/freescale/fec.c +1 -1
index e2b5ce6..11534b9 100644
@@ -818,7 +818,7 @@ static void __inline__ fec_get_mac(struct net_device *ndev)
 			iap = (unsigned char *)FEC_FLASHMAC;
 #else
 		if (pdata)
-			memcpy(iap, pdata->mac, ETH_ALEN);
+			iap = (unsigned char *)&pdata->mac;
 #endif
 	}
 
Signature · 1 line
1.5.6.5
#6 lore raw

PATCH v2 6/8 fec.c: preserve MII/RMII setting in fec_stop()

Additionally to setting the ETHER_EN bit in FEC_ECNTRL the MII/RMII setting in FEC_R_CNTRL needs to be preserved to keep the MII interface functional.

---
 drivers/net/ethernet/freescale/fec.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/net/ethernet/freescale/fec.c +4 -1
index 11534b9..ab0afb5 100644
@@ -515,6 +515,7 @@ fec_stop(struct net_device *ndev)
 	struct fec_enet_private *fep = netdev_priv(ndev);
 	const struct platform_device_id *id_entry =
 				platform_get_device_id(fep->pdev);
+	u32 rmii_mode = readl(fep->hwp + FEC_R_CNTRL) & (1 << 8);
 
 	/* We cannot expect a graceful transmit stop without link !!! */
 	if (fep->link) {
@@ -531,8 +532,10 @@ fec_stop(struct net_device *ndev)
 	writel(FEC_DEFAULT_IMASK, fep->hwp + FEC_IMASK);
 
 	/* We have to keep ENET enabled to have MII interrupt stay working */
-	if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
+	if (id_entry->driver_data & FEC_QUIRK_ENET_MAC) {
 		writel(2, fep->hwp + FEC_ECNTRL);
+		writel(rmii_mode, fep->hwp + FEC_R_CNTRL);
+	}
 }
 
 
Signature · 1 line
1.5.6.5
#7 lore raw

PATCH v2 7/8 fec.c: fix the .remove code

The .remove code is broken in several ways.
- mdiobus_unregister() is called twice for the same object in case of dual FEC
- phy_disconnect() is being called when the PHY is already disconnected
- the requested IRQ(s) are not freed
- fec_stop() is being called with the inteface already stopped

All of those lead to kernel crashes if the remove function is actually used.

---
 drivers/net/ethernet/freescale/fec.c |   31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)
drivers/net/ethernet/freescale/fec.c +22 -9
index ab0afb5..01ee9cc 100644
@@ -259,6 +259,8 @@ struct fec_enet_private {
 /* Transmitter timeout */
 #define TX_TIMEOUT (2 * HZ)
 
+static int mii_cnt;
+
 static void *swap_buffer(void *bufaddr, int len)
 {
 	int i;
@@ -1040,8 +1042,12 @@ static int fec_enet_mii_init(struct platform_device *pdev)
 	 */
 	if ((id_entry->driver_data & FEC_QUIRK_ENET_MAC) && pdev->id > 0) {
 		/* fec1 uses fec0 mii_bus */
-		fep->mii_bus = fec0_mii_bus;
-		return 0;
+		if (mii_cnt && fec0_mii_bus) {
+			fep->mii_bus = fec0_mii_bus;
+			mii_cnt++;
+			return 0;
+		}
+		return -ENOENT;
 	}
 
 	fep->mii_timeout = 0;
@@ -1086,6 +1092,8 @@ static int fec_enet_mii_init(struct platform_device *pdev)
 	if (mdiobus_register(fep->mii_bus))
 		goto err_out_free_mdio_irq;
 
+	mii_cnt++;
+
 	/* save fec0 mii_bus */
 	if (id_entry->driver_data & FEC_QUIRK_ENET_MAC)
 		fec0_mii_bus = fep->mii_bus;
@@ -1102,11 +1110,11 @@ err_out:
 
 static void fec_enet_mii_remove(struct fec_enet_private *fep)
 {
-	if (fep->phy_dev)
-		phy_disconnect(fep->phy_dev);
-	mdiobus_unregister(fep->mii_bus);
-	kfree(fep->mii_bus->irq);
-	mdiobus_free(fep->mii_bus);
+	if (--mii_cnt == 0) {
+		mdiobus_unregister(fep->mii_bus);
+		kfree(fep->mii_bus->irq);
+		mdiobus_free(fep->mii_bus);
+	}
 }
 
 static int fec_enet_get_settings(struct net_device *ndev,
@@ -1646,13 +1654,18 @@ fec_drv_remove(struct platform_device *pdev)
 	struct net_device *ndev = platform_get_drvdata(pdev);
 	struct fec_enet_private *fep = netdev_priv(ndev);
 	struct resource *r;
+	int i;
 
-	fec_stop(ndev);
+	unregister_netdev(ndev);
 	fec_enet_mii_remove(fep);
+	for (i = 0; i < FEC_IRQ_NUM; i++) {
+		int irq = platform_get_irq(pdev, i);
+		if (irq > 0)
+			free_irq(irq, ndev);
+	}
 	clk_disable(fep->clk);
 	clk_put(fep->clk);
 	iounmap(fep->hwp);
-	unregister_netdev(ndev);
 	free_netdev(ndev);
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Signature · 1 line
1.5.6.5
#8 lore raw

PATCH v2 8/8 fec.c: make FEC driver buildable as module

---
 drivers/net/ethernet/freescale/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/freescale/Kconfig +1 -1
index c520cfd..b02e315 100644
@@ -21,7 +21,7 @@ config NET_VENDOR_FREESCALE
 if NET_VENDOR_FREESCALE
 
 config FEC
-	bool "FEC ethernet controller (of ColdFire and some i.MX CPUs)"
+	tristate "FEC ethernet controller (of ColdFire and some i.MX CPUs)"
 	depends on (M523x || M527x || M5272 || M528x || M520x || M532x || \
 		   ARCH_MXC || ARCH_MXS)
 	select PHYLIB
Signature · 1 line
1.5.6.5
maintainer
#9 lore raw
In reply to Lothar Waßmann

From: Lothar Waßmann <[email protected]>
Date: Wed, 7 Dec 2011 14:37:12 +0100

Quoted 3 lines

The following set of patches provides some cleanup and bugfixes for drivers/net/ethernet/freescale/fec.c and makes the driver buildable as a module.

1) I said to use a subject prefix of "fec: " not "fec.c: "

2) You did not integrate Shawn's "Acked-by: " tags, I'm not going to go sifting through the previous patch postings to collect them up, that's your job.

#10 lore raw

Hi,

Quoted 9 lines · David Miller

From: Lothar Waßmann <[email protected]>
Date: Wed, 7 Dec 2011 14:37:12 +0100

Quoted 3 lines

The following set of patches provides some cleanup and bugfixes for drivers/net/ethernet/freescale/fec.c and makes the driver buildable as a module.

1) I said to use a subject prefix of "fec: " not "fec.c: "

OK.

Quoted 4 lines

2) You did not integrate Shawn's "Acked-by: " tags, I'm not going to go sifting through the previous patch postings to collect them up, that's your job.

I still got no Ack from Shawn for patches 3 and 5 and only Tested-by for patches 6 thru 8. Should I wait for Shawn's Ack for those patches too, or should I resent now?

Lothar Waßmann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________
Acked-by
#11 lore raw
Quoted 6 lines · Lothar Waßmann

Hi,

Quoted 3 lines · David Miller

From: Lothar Waßmann <[email protected]>
Date: Wed,  7 Dec 2011 14:37:12 +0100

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

The following set of patches provides some cleanup and bugfixes for drivers/net/ethernet/freescale/fec.c and makes the driver buildable as a module.

1) I said to use a subject prefix of "fec: " not "fec.c: "

OK.

To be consistent with existing commits, I would suggest use "net/fec:
" as the subject prefix.

Quoted 9 lines
Quoted 5 lines

2) You did not integrate Shawn's "Acked-by: " tags, I'm not going to go sifting through the previous patch postings to collect them up, that's your job.

I still got no Ack from Shawn for patches 3 and 5 and only Tested-by for patches 6 thru 8. Should I wait for Shawn's Ack for those patches too, or should I resent now?

For the whole series,

Signature · 2 lines
Regards,
Shawn