Skip to contentSkip to conversation

net: ethernet: ti: cpsw: Fix suspend/resume break

PATCH Superseded Keerthy 2 participants 2 messages Jun 22, 2019 – Jun 23, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Keerthy

author
#0 lore raw

PATCH 1/1 net: ethernet: ti: cpsw: Fix suspend/resume break

Commit bfe59032bd6127ee190edb30be9381a01765b958 ("net: ethernet:
ti: cpsw: use cpsw as drv data")changes
the driver data to struct cpsw_common *cpsw. This is done only in probe/remove but the suspend/resume functions are still left with struct net_device *ndev. Hence fix both suspend & resume also to fetch the updated driver data.

Fixes bfe59032bd6127ee1 ("net: ethernet: ti: cpsw: use cpsw as drv data")
---
 drivers/net/ethernet/ti/cpsw.c | 36 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 25 deletions(-)
drivers/net/ethernet/ti/cpsw.c +11 -25
index 7bdd287074fc..2aeaad15e20e 100644
@@ -2590,20 +2590,12 @@ static int cpsw_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int cpsw_suspend(struct device *dev)
 {
-	struct net_device	*ndev = dev_get_drvdata(dev);
-	struct cpsw_common	*cpsw = ndev_to_cpsw(ndev);
-
-	if (cpsw->data.dual_emac) {
-		int i;
+	struct cpsw_common *cpsw = dev_get_drvdata(dev);
+	int i;
 
-		for (i = 0; i < cpsw->data.slaves; i++) {
-			if (netif_running(cpsw->slaves[i].ndev))
-				cpsw_ndo_stop(cpsw->slaves[i].ndev);
-		}
-	} else {
-		if (netif_running(ndev))
-			cpsw_ndo_stop(ndev);
-	}
+	for (i = 0; i < cpsw->data.slaves; i++)
+		if (netif_running(cpsw->slaves[i].ndev))
+			cpsw_ndo_stop(cpsw->slaves[i].ndev);
 
 	/* Select sleep pin state */
 	pinctrl_pm_select_sleep_state(dev);
@@ -2613,25 +2605,19 @@ static int cpsw_suspend(struct device *dev)
 
 static int cpsw_resume(struct device *dev)
 {
-	struct net_device	*ndev = dev_get_drvdata(dev);
-	struct cpsw_common	*cpsw = ndev_to_cpsw(ndev);
+	struct cpsw_common *cpsw = dev_get_drvdata(dev);
+	int i;
 
 	/* Select default pin state */
 	pinctrl_pm_select_default_state(dev);
 
 	/* shut up ASSERT_RTNL() warning in netif_set_real_num_tx/rx_queues */
 	rtnl_lock();
-	if (cpsw->data.dual_emac) {
-		int i;
 
-		for (i = 0; i < cpsw->data.slaves; i++) {
-			if (netif_running(cpsw->slaves[i].ndev))
-				cpsw_ndo_open(cpsw->slaves[i].ndev);
-		}
-	} else {
-		if (netif_running(ndev))
-			cpsw_ndo_open(ndev);
-	}
+	for (i = 0; i < cpsw->data.slaves; i++)
+		if (netif_running(cpsw->slaves[i].ndev))
+			cpsw_ndo_open(cpsw->slaves[i].ndev);
+
 	rtnl_unlock();
 
 	return 0;
Signature · 1 line
2.17.1
#1 lore raw

On Sat, Jun 22, 2019 at 04:01:40PM +0530, Keerthy wrote:

Hi Keerty,

Quoted 29 lines

Commit bfe59032bd6127ee190edb30be9381a01765b958 ("net: ethernet:
ti: cpsw: use cpsw as drv data")changes
the driver data to struct cpsw_common *cpsw. This is done only in probe/remove but the suspend/resume functions are still left with struct net_device *ndev. Hence fix both suspend & resume also to fetch the updated driver data.

Fixes bfe59032bd6127ee1 ("net: ethernet: ti: cpsw: use cpsw as drv data")

---
drivers/net/ethernet/ti/cpsw.c | 36 +++++++++++-----------------------

1 file changed, 11 insertions(+), 25 deletions(-)
drivers/net/ethernet/ti/cpsw.c +2 -5
index 7bdd287074fc..2aeaad15e20e 100644
@@ -2590,20 +2590,12 @@ static int cpsw_remove(struct platform_device *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int cpsw_suspend(struct device *dev)
 {
-	struct net_device	*ndev = dev_get_drvdata(dev);
-	struct cpsw_common	*cpsw = ndev_to_cpsw(ndev);
-
-	if (cpsw->data.dual_emac) {
-		int i;
+	struct cpsw_common *cpsw = dev_get_drvdata(dev);
+	int i;
 

drivers/net/ethernet/ti/cpsw.c static int cpsw_remove(struct platform_device *pdev) · line 2597

Quoted 10 lines
drivers/net/ethernet/ti/cpsw.c +2 -8
-		for (i = 0; i < cpsw->data.slaves; i++) {
-			if (netif_running(cpsw->slaves[i].ndev))
-				cpsw_ndo_stop(cpsw->slaves[i].ndev);
-		}
-	} else {
-		if (netif_running(ndev))
-			cpsw_ndo_stop(ndev);
-	}
+	for (i = 0; i < cpsw->data.slaves; i++)
+		if (netif_running(cpsw->slaves[i].ndev))

Seems I've missed to add this, but in your fix potential issue in switch mode. ndev is not necessarily present for slave, you need to check on ndev != null before using it, if you still remove cpsw->data.dual_emac ofc.

Thanks.

Quoted 23 lines
drivers/net/ethernet/ti/cpsw.c +3 -6
+			cpsw_ndo_stop(cpsw->slaves[i].ndev);
 
 	/* Select sleep pin state */
 	pinctrl_pm_select_sleep_state(dev);
@@ -2613,25 +2605,19 @@ static int cpsw_suspend(struct device *dev)
 
 static int cpsw_resume(struct device *dev)
 {
-	struct net_device	*ndev = dev_get_drvdata(dev);
-	struct cpsw_common	*cpsw = ndev_to_cpsw(ndev);
+	struct cpsw_common *cpsw = dev_get_drvdata(dev);
+	int i;
 
 	/* Select default pin state */
 	pinctrl_pm_select_default_state(dev);
 
 	/* shut up ASSERT_RTNL() warning in netif_set_real_num_tx/rx_queues */
 	rtnl_lock();
-	if (cpsw->data.dual_emac) {
-		int i;
 
-		for (i = 0; i < cpsw->data.slaves; i++) {
-			if (netif_running(cpsw->slaves[i].ndev))

drivers/net/ethernet/ti/cpsw.c static int cpsw_suspend(struct device *dev) · line 2620

Quoted 10 lines
drivers/net/ethernet/ti/cpsw.c +4 -6
-				cpsw_ndo_open(cpsw->slaves[i].ndev);
-		}
-	} else {
-		if (netif_running(ndev))
-			cpsw_ndo_open(ndev);
-	}
+	for (i = 0; i < cpsw->data.slaves; i++)
+		if (netif_running(cpsw->slaves[i].ndev))
+			cpsw_ndo_open(cpsw->slaves[i].ndev);
+

same here

Quoted 6 lines
drivers/net/ethernet/ti/cpsw.c +0 -0
 	rtnl_unlock();
 
 	return 0;
Signature · 1 line
2.17.1
Signature · 2 lines
Regards,
Ivan Khoronzhuk