Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'ravb-rutime-PM-support'

Claudiu Beznea says:

====================
net: ravb: Add runtime PM support (part 2)

Series adds runtime PM support for the ravb driver. This is a continuation
of [1].

There are 5 more preparation patches (patches 1-5) and patch 6
adds runtime PM support.

Patches in this series were part of [2].

Changes in v4:
- remove unnecessary code from patch 4/6
- improve the code in patch 5/6

Changes in v3:
- fixed typos
- added patch "net: ravb: Move the update of ndev->features to
ravb_set_features()"
- changes title of patch "net: ravb: Do not apply RX checksum
settings to hardware if the interface is down" from v2 into
"net: ravb: Do not apply features to hardware if the interface
is down", changed patch description and updated the patch
- collected tags

Changes in v2:
- address review comments
- in patch 4/5 take into account the latest changes introduced
in ravb_set_features_gbeth()

Changes since [2]:
- patch 1/5 is new
- use pm_runtime_get_noresume() and pm_runtime_active() in patches
3/5, 4/5
- fixed higlighted typos in patch 4/5

[1] https://lore.kernel.org/all/20240202084136.3426492-1-claudiu.beznea.uj@bp.renesas.com/
[2] https://lore.kernel.org/all/20240105082339.1468817-1-claudiu.beznea.uj@bp.renesas.com/
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+103 -29
+103 -29
drivers/net/ethernet/renesas/ravb_main.c
··· 1935 1935 { 1936 1936 struct ravb_private *priv = netdev_priv(ndev); 1937 1937 const struct ravb_hw_info *info = priv->info; 1938 + struct device *dev = &priv->pdev->dev; 1938 1939 int error; 1939 1940 1940 1941 napi_enable(&priv->napi[RAVB_BE]); 1941 1942 if (info->nc_queues) 1942 1943 napi_enable(&priv->napi[RAVB_NC]); 1943 1944 1945 + error = pm_runtime_resume_and_get(dev); 1946 + if (error < 0) 1947 + goto out_napi_off; 1948 + 1944 1949 /* Set AVB config mode */ 1945 1950 error = ravb_set_config_mode(ndev); 1946 1951 if (error) 1947 - goto out_napi_off; 1952 + goto out_rpm_put; 1948 1953 1949 1954 ravb_set_delay_mode(ndev); 1950 1955 ravb_write(ndev, priv->desc_bat_dma, DBAT); ··· 1983 1978 ravb_stop_dma(ndev); 1984 1979 out_set_reset: 1985 1980 ravb_set_opmode(ndev, CCC_OPC_RESET); 1981 + out_rpm_put: 1982 + pm_runtime_mark_last_busy(dev); 1983 + pm_runtime_put_autosuspend(dev); 1986 1984 out_napi_off: 1987 1985 if (info->nc_queues) 1988 1986 napi_disable(&priv->napi[RAVB_NC]); ··· 2252 2244 struct ravb_private *priv = netdev_priv(ndev); 2253 2245 const struct ravb_hw_info *info = priv->info; 2254 2246 struct net_device_stats *nstats, *stats0, *stats1; 2247 + struct device *dev = &priv->pdev->dev; 2255 2248 2256 2249 nstats = &ndev->stats; 2250 + 2251 + pm_runtime_get_noresume(dev); 2252 + 2253 + if (!pm_runtime_active(dev)) 2254 + goto out_rpm_put; 2255 + 2257 2256 stats0 = &priv->stats[RAVB_BE]; 2258 2257 2259 2258 if (info->tx_counters) { ··· 2302 2287 nstats->rx_over_errors += stats1->rx_over_errors; 2303 2288 } 2304 2289 2290 + out_rpm_put: 2291 + pm_runtime_put_noidle(dev); 2305 2292 return nstats; 2306 2293 } 2307 2294 ··· 2326 2309 struct ravb_private *priv = netdev_priv(ndev); 2327 2310 const struct ravb_hw_info *info = priv->info; 2328 2311 struct ravb_tstamp_skb *ts_skb, *ts_skb2; 2312 + struct device *dev = &priv->pdev->dev; 2313 + int error; 2329 2314 2330 2315 netif_tx_stop_all_queues(ndev); 2331 2316 ··· 2335 2316 ravb_write(ndev, 0, RIC0); 2336 2317 ravb_write(ndev, 0, RIC2); 2337 2318 ravb_write(ndev, 0, TIC); 2319 + 2320 + /* PHY disconnect */ 2321 + if (ndev->phydev) { 2322 + phy_stop(ndev->phydev); 2323 + phy_disconnect(ndev->phydev); 2324 + if (of_phy_is_fixed_link(np)) 2325 + of_phy_deregister_fixed_link(np); 2326 + } 2338 2327 2339 2328 /* Stop PTP Clock driver */ 2340 2329 if (info->gptp || info->ccc_gac) ··· 2362 2335 } 2363 2336 } 2364 2337 2365 - /* PHY disconnect */ 2366 - if (ndev->phydev) { 2367 - phy_stop(ndev->phydev); 2368 - phy_disconnect(ndev->phydev); 2369 - if (of_phy_is_fixed_link(np)) 2370 - of_phy_deregister_fixed_link(np); 2371 - } 2372 - 2373 2338 cancel_work_sync(&priv->work); 2374 2339 2375 2340 if (info->nc_queues) ··· 2373 2354 if (info->nc_queues) 2374 2355 ravb_ring_free(ndev, RAVB_NC); 2375 2356 2357 + /* Update statistics. */ 2358 + ravb_get_stats(ndev); 2359 + 2376 2360 /* Set reset mode. */ 2377 - return ravb_set_opmode(ndev, CCC_OPC_RESET); 2361 + error = ravb_set_opmode(ndev, CCC_OPC_RESET); 2362 + if (error) 2363 + return error; 2364 + 2365 + pm_runtime_mark_last_busy(dev); 2366 + pm_runtime_put_autosuspend(dev); 2367 + 2368 + return 0; 2378 2369 } 2379 2370 2380 2371 static int ravb_hwtstamp_get(struct net_device *ndev, struct ifreq *req) ··· 2555 2526 goto done; 2556 2527 } 2557 2528 2558 - ndev->features = features; 2559 2529 done: 2560 2530 spin_unlock_irqrestore(&priv->lock, flags); 2561 2531 ··· 2569 2541 if (changed & NETIF_F_RXCSUM) 2570 2542 ravb_set_rx_csum(ndev, features & NETIF_F_RXCSUM); 2571 2543 2572 - ndev->features = features; 2573 - 2574 2544 return 0; 2575 2545 } 2576 2546 ··· 2577 2551 { 2578 2552 struct ravb_private *priv = netdev_priv(ndev); 2579 2553 const struct ravb_hw_info *info = priv->info; 2554 + struct device *dev = &priv->pdev->dev; 2555 + int ret; 2580 2556 2581 - return info->set_feature(ndev, features); 2557 + pm_runtime_get_noresume(dev); 2558 + 2559 + if (pm_runtime_active(dev)) 2560 + ret = info->set_feature(ndev, features); 2561 + else 2562 + ret = 0; 2563 + 2564 + pm_runtime_put_noidle(dev); 2565 + 2566 + if (ret) 2567 + return ret; 2568 + 2569 + ndev->features = features; 2570 + 2571 + return 0; 2582 2572 } 2583 2573 2584 2574 static const struct net_device_ops ravb_netdev_ops = { ··· 2785 2743 struct device *dev = &pdev->dev; 2786 2744 const char *dev_name; 2787 2745 unsigned long flags; 2788 - int error; 2746 + int error, irq_num; 2789 2747 2790 2748 if (irq_name) { 2791 2749 dev_name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s", ndev->name, ch); 2792 2750 if (!dev_name) 2793 2751 return -ENOMEM; 2794 2752 2795 - *irq = platform_get_irq_byname(pdev, irq_name); 2753 + irq_num = platform_get_irq_byname(pdev, irq_name); 2796 2754 flags = 0; 2797 2755 } else { 2798 2756 dev_name = ndev->name; 2799 - *irq = platform_get_irq(pdev, 0); 2757 + irq_num = platform_get_irq(pdev, 0); 2800 2758 flags = IRQF_SHARED; 2801 2759 } 2802 - if (*irq < 0) 2803 - return *irq; 2760 + if (irq_num < 0) 2761 + return irq_num; 2804 2762 2805 - error = devm_request_irq(dev, *irq, handler, flags, dev_name, ndev); 2763 + if (irq) 2764 + *irq = irq_num; 2765 + 2766 + error = devm_request_irq(dev, irq_num, handler, flags, dev_name, ndev); 2806 2767 if (error) 2807 2768 netdev_err(ndev, "cannot request IRQ %s\n", dev_name); 2808 2769 ··· 2817 2772 const struct ravb_hw_info *info = priv->info; 2818 2773 struct net_device *ndev = priv->ndev; 2819 2774 const char *irq_name, *emac_irq_name; 2820 - int error, irq; 2775 + int error; 2821 2776 2822 2777 if (!info->multi_irqs) 2823 2778 return ravb_setup_irq(priv, NULL, NULL, &ndev->irq, ravb_interrupt); ··· 2840 2795 return error; 2841 2796 2842 2797 if (info->err_mgmt_irqs) { 2843 - error = ravb_setup_irq(priv, "err_a", "err_a", &irq, ravb_multi_interrupt); 2798 + error = ravb_setup_irq(priv, "err_a", "err_a", NULL, ravb_multi_interrupt); 2844 2799 if (error) 2845 2800 return error; 2846 2801 2847 - error = ravb_setup_irq(priv, "mgmt_a", "mgmt_a", &irq, ravb_multi_interrupt); 2802 + error = ravb_setup_irq(priv, "mgmt_a", "mgmt_a", NULL, ravb_multi_interrupt); 2848 2803 if (error) 2849 2804 return error; 2850 2805 } 2851 2806 2852 - error = ravb_setup_irq(priv, "ch0", "ch0:rx_be", &irq, ravb_be_interrupt); 2807 + error = ravb_setup_irq(priv, "ch0", "ch0:rx_be", NULL, ravb_be_interrupt); 2853 2808 if (error) 2854 2809 return error; 2855 2810 2856 - error = ravb_setup_irq(priv, "ch1", "ch1:rx_nc", &irq, ravb_nc_interrupt); 2811 + error = ravb_setup_irq(priv, "ch1", "ch1:rx_nc", NULL, ravb_nc_interrupt); 2857 2812 if (error) 2858 2813 return error; 2859 2814 2860 - error = ravb_setup_irq(priv, "ch18", "ch18:tx_be", &irq, ravb_be_interrupt); 2815 + error = ravb_setup_irq(priv, "ch18", "ch18:tx_be", NULL, ravb_be_interrupt); 2861 2816 if (error) 2862 2817 return error; 2863 2818 2864 - return ravb_setup_irq(priv, "ch19", "ch19:tx_nc", &irq, ravb_nc_interrupt); 2819 + return ravb_setup_irq(priv, "ch19", "ch19:tx_nc", NULL, ravb_nc_interrupt); 2865 2820 } 2866 2821 2867 2822 static int ravb_probe(struct platform_device *pdev) ··· 2939 2894 clk_prepare(priv->refclk); 2940 2895 2941 2896 platform_set_drvdata(pdev, ndev); 2897 + pm_runtime_set_autosuspend_delay(&pdev->dev, 100); 2898 + pm_runtime_use_autosuspend(&pdev->dev); 2942 2899 pm_runtime_enable(&pdev->dev); 2943 2900 error = pm_runtime_resume_and_get(&pdev->dev); 2944 2901 if (error < 0) ··· 3046 2999 netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n", 3047 3000 (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); 3048 3001 3002 + pm_runtime_mark_last_busy(&pdev->dev); 3003 + pm_runtime_put_autosuspend(&pdev->dev); 3004 + 3049 3005 return 0; 3050 3006 3051 3007 out_napi_del: ··· 3066 3016 pm_runtime_put(&pdev->dev); 3067 3017 out_rpm_disable: 3068 3018 pm_runtime_disable(&pdev->dev); 3019 + pm_runtime_dont_use_autosuspend(&pdev->dev); 3069 3020 clk_unprepare(priv->refclk); 3070 3021 out_reset_assert: 3071 3022 reset_control_assert(rstc); ··· 3080 3029 struct net_device *ndev = platform_get_drvdata(pdev); 3081 3030 struct ravb_private *priv = netdev_priv(ndev); 3082 3031 const struct ravb_hw_info *info = priv->info; 3032 + struct device *dev = &priv->pdev->dev; 3033 + int error; 3034 + 3035 + error = pm_runtime_resume_and_get(dev); 3036 + if (error < 0) 3037 + return; 3083 3038 3084 3039 unregister_netdev(ndev); 3085 3040 if (info->nc_queues) ··· 3097 3040 dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat, 3098 3041 priv->desc_bat_dma); 3099 3042 3100 - pm_runtime_put_sync(&pdev->dev); 3043 + pm_runtime_put_sync_suspend(&pdev->dev); 3101 3044 pm_runtime_disable(&pdev->dev); 3045 + pm_runtime_dont_use_autosuspend(dev); 3102 3046 clk_unprepare(priv->refclk); 3103 3047 reset_control_assert(priv->rstc); 3104 3048 free_netdev(ndev); ··· 3181 3123 if (ret) 3182 3124 return ret; 3183 3125 3126 + ret = pm_runtime_force_suspend(&priv->pdev->dev); 3127 + if (ret) 3128 + return ret; 3129 + 3184 3130 reset_assert: 3185 3131 return reset_control_assert(priv->rstc); 3186 3132 } ··· 3207 3145 ret = ravb_wol_restore(ndev); 3208 3146 if (ret) 3209 3147 return ret; 3148 + } else { 3149 + ret = pm_runtime_force_resume(dev); 3150 + if (ret) 3151 + return ret; 3210 3152 } 3211 3153 3212 3154 /* Reopening the interface will restore the device to the working state. */ 3213 3155 ret = ravb_open(ndev); 3214 3156 if (ret < 0) 3215 - return ret; 3157 + goto out_rpm_put; 3216 3158 3217 3159 ravb_set_rx_mode(ndev); 3218 3160 netif_device_attach(ndev); 3161 + 3162 + return 0; 3163 + 3164 + out_rpm_put: 3165 + if (!priv->wol_enabled) { 3166 + pm_runtime_mark_last_busy(dev); 3167 + pm_runtime_put_autosuspend(dev); 3168 + } 3219 3169 3220 3170 return ret; 3221 3171 }