Skip to content

Commit 48f894a

Browse files
claudiubezneadavem330
authored andcommitted
net: ravb: Add runtime PM support
Add runtime PM support for the ravb driver. As the driver is used by different IP variants, with different behaviors, to be able to have the runtime PM support available for all devices, the preparatory commits moved all the resources parsing and allocations in the driver's probe function and kept the settings for ravb_open(). This is due to the fact that on some IP variants-platforms tuples disabling/enabling the clocks will switch the IP to the reset operation mode where register contents is lost and reconfiguration needs to be done. For this the rabv_open() function enables the clocks, switches the IP to configuration mode, applies all the register settings and switches the IP to the operational mode. At the end of ravb_open() IP is ready to send/receive data. In ravb_close() necessary reverts are done (compared with ravb_open()), the IP is switched to reset mode and clocks are disabled. The ethtool APIs or IOCTLs that might execute while the interface is down are either cached (and applied in ravb_open()) or rejected (as at that time the IP is in reset mode). Keeping the IP in the reset mode also increases the power saved (according to the hardware manual). Signed-off-by: Claudiu Beznea <[email protected]> Reviewed-by: Sergey Shtylyov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a71a50e commit 48f894a

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

drivers/net/ethernet/renesas/ravb_main.c

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,16 +1935,21 @@ static int ravb_open(struct net_device *ndev)
19351935
{
19361936
struct ravb_private *priv = netdev_priv(ndev);
19371937
const struct ravb_hw_info *info = priv->info;
1938+
struct device *dev = &priv->pdev->dev;
19381939
int error;
19391940

19401941
napi_enable(&priv->napi[RAVB_BE]);
19411942
if (info->nc_queues)
19421943
napi_enable(&priv->napi[RAVB_NC]);
19431944

1945+
error = pm_runtime_resume_and_get(dev);
1946+
if (error < 0)
1947+
goto out_napi_off;
1948+
19441949
/* Set AVB config mode */
19451950
error = ravb_set_config_mode(ndev);
19461951
if (error)
1947-
goto out_napi_off;
1952+
goto out_rpm_put;
19481953

19491954
ravb_set_delay_mode(ndev);
19501955
ravb_write(ndev, priv->desc_bat_dma, DBAT);
@@ -1978,6 +1983,9 @@ static int ravb_open(struct net_device *ndev)
19781983
ravb_stop_dma(ndev);
19791984
out_set_reset:
19801985
ravb_set_opmode(ndev, CCC_OPC_RESET);
1986+
out_rpm_put:
1987+
pm_runtime_mark_last_busy(dev);
1988+
pm_runtime_put_autosuspend(dev);
19811989
out_napi_off:
19821990
if (info->nc_queues)
19831991
napi_disable(&priv->napi[RAVB_NC]);
@@ -2318,6 +2326,8 @@ static int ravb_close(struct net_device *ndev)
23182326
struct ravb_private *priv = netdev_priv(ndev);
23192327
const struct ravb_hw_info *info = priv->info;
23202328
struct ravb_tstamp_skb *ts_skb, *ts_skb2;
2329+
struct device *dev = &priv->pdev->dev;
2330+
int error;
23212331

23222332
netif_tx_stop_all_queues(ndev);
23232333

@@ -2367,7 +2377,14 @@ static int ravb_close(struct net_device *ndev)
23672377
ravb_get_stats(ndev);
23682378

23692379
/* Set reset mode. */
2370-
return ravb_set_opmode(ndev, CCC_OPC_RESET);
2380+
error = ravb_set_opmode(ndev, CCC_OPC_RESET);
2381+
if (error)
2382+
return error;
2383+
2384+
pm_runtime_mark_last_busy(dev);
2385+
pm_runtime_put_autosuspend(dev);
2386+
2387+
return 0;
23712388
}
23722389

23732390
static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req)
@@ -2922,6 +2939,8 @@ static int ravb_probe(struct platform_device *pdev)
29222939
clk_prepare(priv->refclk);
29232940

29242941
platform_set_drvdata(pdev, ndev);
2942+
pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
2943+
pm_runtime_use_autosuspend(&pdev->dev);
29252944
pm_runtime_enable(&pdev->dev);
29262945
error = pm_runtime_resume_and_get(&pdev->dev);
29272946
if (error < 0)
@@ -3027,6 +3046,9 @@ static int ravb_probe(struct platform_device *pdev)
30273046
netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n",
30283047
(u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
30293048

3049+
pm_runtime_mark_last_busy(&pdev->dev);
3050+
pm_runtime_put_autosuspend(&pdev->dev);
3051+
30303052
return 0;
30313053

30323054
out_napi_del:
@@ -3044,6 +3066,7 @@ static int ravb_probe(struct platform_device *pdev)
30443066
pm_runtime_put(&pdev->dev);
30453067
out_rpm_disable:
30463068
pm_runtime_disable(&pdev->dev);
3069+
pm_runtime_dont_use_autosuspend(&pdev->dev);
30473070
clk_unprepare(priv->refclk);
30483071
out_reset_assert:
30493072
reset_control_assert(rstc);
@@ -3057,6 +3080,12 @@ static void ravb_remove(struct platform_device *pdev)
30573080
struct net_device *ndev = platform_get_drvdata(pdev);
30583081
struct ravb_private *priv = netdev_priv(ndev);
30593082
const struct ravb_hw_info *info = priv->info;
3083+
struct device *dev = &priv->pdev->dev;
3084+
int error;
3085+
3086+
error = pm_runtime_resume_and_get(dev);
3087+
if (error < 0)
3088+
return;
30603089

30613090
unregister_netdev(ndev);
30623091
if (info->nc_queues)
@@ -3068,8 +3097,9 @@ static void ravb_remove(struct platform_device *pdev)
30683097
dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
30693098
priv->desc_bat_dma);
30703099

3071-
pm_runtime_put_sync(&pdev->dev);
3100+
pm_runtime_put_sync_suspend(&pdev->dev);
30723101
pm_runtime_disable(&pdev->dev);
3102+
pm_runtime_dont_use_autosuspend(dev);
30733103
clk_unprepare(priv->refclk);
30743104
reset_control_assert(priv->rstc);
30753105
free_netdev(ndev);
@@ -3151,6 +3181,10 @@ static int ravb_suspend(struct device *dev)
31513181
if (ret)
31523182
return ret;
31533183

3184+
ret = pm_runtime_force_suspend(&priv->pdev->dev);
3185+
if (ret)
3186+
return ret;
3187+
31543188
reset_assert:
31553189
return reset_control_assert(priv->rstc);
31563190
}
@@ -3173,16 +3207,28 @@ static int ravb_resume(struct device *dev)
31733207
ret = ravb_wol_restore(ndev);
31743208
if (ret)
31753209
return ret;
3210+
} else {
3211+
ret = pm_runtime_force_resume(dev);
3212+
if (ret)
3213+
return ret;
31763214
}
31773215

31783216
/* Reopening the interface will restore the device to the working state. */
31793217
ret = ravb_open(ndev);
31803218
if (ret < 0)
3181-
return ret;
3219+
goto out_rpm_put;
31823220

31833221
ravb_set_rx_mode(ndev);
31843222
netif_device_attach(ndev);
31853223

3224+
return 0;
3225+
3226+
out_rpm_put:
3227+
if (!priv->wol_enabled) {
3228+
pm_runtime_mark_last_busy(dev);
3229+
pm_runtime_put_autosuspend(dev);
3230+
}
3231+
31863232
return ret;
31873233
}
31883234

0 commit comments

Comments
 (0)