@@ -1935,16 +1935,21 @@ static int ravb_open(struct net_device *ndev)
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 );
@@ -1978,6 +1983,9 @@ static int ravb_open(struct net_device *ndev)
1978
1983
ravb_stop_dma (ndev );
1979
1984
out_set_reset :
1980
1985
ravb_set_opmode (ndev , CCC_OPC_RESET );
1986
+ out_rpm_put :
1987
+ pm_runtime_mark_last_busy (dev );
1988
+ pm_runtime_put_autosuspend (dev );
1981
1989
out_napi_off :
1982
1990
if (info -> nc_queues )
1983
1991
napi_disable (& priv -> napi [RAVB_NC ]);
@@ -2244,8 +2252,15 @@ static struct net_device_stats *ravb_get_stats(struct net_device *ndev)
2244
2252
struct ravb_private * priv = netdev_priv (ndev );
2245
2253
const struct ravb_hw_info * info = priv -> info ;
2246
2254
struct net_device_stats * nstats , * stats0 , * stats1 ;
2255
+ struct device * dev = & priv -> pdev -> dev ;
2247
2256
2248
2257
nstats = & ndev -> stats ;
2258
+
2259
+ pm_runtime_get_noresume (dev );
2260
+
2261
+ if (!pm_runtime_active (dev ))
2262
+ goto out_rpm_put ;
2263
+
2249
2264
stats0 = & priv -> stats [RAVB_BE ];
2250
2265
2251
2266
if (info -> tx_counters ) {
@@ -2287,6 +2302,8 @@ static struct net_device_stats *ravb_get_stats(struct net_device *ndev)
2287
2302
nstats -> rx_over_errors += stats1 -> rx_over_errors ;
2288
2303
}
2289
2304
2305
+ out_rpm_put :
2306
+ pm_runtime_put_noidle (dev );
2290
2307
return nstats ;
2291
2308
}
2292
2309
@@ -2309,6 +2326,8 @@ static int ravb_close(struct net_device *ndev)
2309
2326
struct ravb_private * priv = netdev_priv (ndev );
2310
2327
const struct ravb_hw_info * info = priv -> info ;
2311
2328
struct ravb_tstamp_skb * ts_skb , * ts_skb2 ;
2329
+ struct device * dev = & priv -> pdev -> dev ;
2330
+ int error ;
2312
2331
2313
2332
netif_tx_stop_all_queues (ndev );
2314
2333
@@ -2317,6 +2336,14 @@ static int ravb_close(struct net_device *ndev)
2317
2336
ravb_write (ndev , 0 , RIC2 );
2318
2337
ravb_write (ndev , 0 , TIC );
2319
2338
2339
+ /* PHY disconnect */
2340
+ if (ndev -> phydev ) {
2341
+ phy_stop (ndev -> phydev );
2342
+ phy_disconnect (ndev -> phydev );
2343
+ if (of_phy_is_fixed_link (np ))
2344
+ of_phy_deregister_fixed_link (np );
2345
+ }
2346
+
2320
2347
/* Stop PTP Clock driver */
2321
2348
if (info -> gptp || info -> ccc_gac )
2322
2349
ravb_ptp_stop (ndev );
@@ -2335,14 +2362,6 @@ static int ravb_close(struct net_device *ndev)
2335
2362
}
2336
2363
}
2337
2364
2338
- /* PHY disconnect */
2339
- if (ndev -> phydev ) {
2340
- phy_stop (ndev -> phydev );
2341
- phy_disconnect (ndev -> phydev );
2342
- if (of_phy_is_fixed_link (np ))
2343
- of_phy_deregister_fixed_link (np );
2344
- }
2345
-
2346
2365
cancel_work_sync (& priv -> work );
2347
2366
2348
2367
if (info -> nc_queues )
@@ -2354,8 +2373,18 @@ static int ravb_close(struct net_device *ndev)
2354
2373
if (info -> nc_queues )
2355
2374
ravb_ring_free (ndev , RAVB_NC );
2356
2375
2376
+ /* Update statistics. */
2377
+ ravb_get_stats (ndev );
2378
+
2357
2379
/* Set reset mode. */
2358
- 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 ;
2359
2388
}
2360
2389
2361
2390
static int ravb_hwtstamp_get (struct net_device * ndev , struct ifreq * req )
@@ -2526,7 +2555,6 @@ static int ravb_set_features_gbeth(struct net_device *ndev,
2526
2555
goto done ;
2527
2556
}
2528
2557
2529
- ndev -> features = features ;
2530
2558
done :
2531
2559
spin_unlock_irqrestore (& priv -> lock , flags );
2532
2560
@@ -2541,8 +2569,6 @@ static int ravb_set_features_rcar(struct net_device *ndev,
2541
2569
if (changed & NETIF_F_RXCSUM )
2542
2570
ravb_set_rx_csum (ndev , features & NETIF_F_RXCSUM );
2543
2571
2544
- ndev -> features = features ;
2545
-
2546
2572
return 0 ;
2547
2573
}
2548
2574
@@ -2551,8 +2577,24 @@ static int ravb_set_features(struct net_device *ndev,
2551
2577
{
2552
2578
struct ravb_private * priv = netdev_priv (ndev );
2553
2579
const struct ravb_hw_info * info = priv -> info ;
2580
+ struct device * dev = & priv -> pdev -> dev ;
2581
+ int ret ;
2582
+
2583
+ pm_runtime_get_noresume (dev );
2584
+
2585
+ if (pm_runtime_active (dev ))
2586
+ ret = info -> set_feature (ndev , features );
2587
+ else
2588
+ ret = 0 ;
2589
+
2590
+ pm_runtime_put_noidle (dev );
2591
+
2592
+ if (ret )
2593
+ return ret ;
2594
+
2595
+ ndev -> features = features ;
2554
2596
2555
- return info -> set_feature ( ndev , features ) ;
2597
+ return 0 ;
2556
2598
}
2557
2599
2558
2600
static const struct net_device_ops ravb_netdev_ops = {
@@ -2743,24 +2785,27 @@ static int ravb_setup_irq(struct ravb_private *priv, const char *irq_name,
2743
2785
struct device * dev = & pdev -> dev ;
2744
2786
const char * dev_name ;
2745
2787
unsigned long flags ;
2746
- int error ;
2788
+ int error , irq_num ;
2747
2789
2748
2790
if (irq_name ) {
2749
2791
dev_name = devm_kasprintf (dev , GFP_KERNEL , "%s:%s" , ndev -> name , ch );
2750
2792
if (!dev_name )
2751
2793
return - ENOMEM ;
2752
2794
2753
- * irq = platform_get_irq_byname (pdev , irq_name );
2795
+ irq_num = platform_get_irq_byname (pdev , irq_name );
2754
2796
flags = 0 ;
2755
2797
} else {
2756
2798
dev_name = ndev -> name ;
2757
- * irq = platform_get_irq (pdev , 0 );
2799
+ irq_num = platform_get_irq (pdev , 0 );
2758
2800
flags = IRQF_SHARED ;
2759
2801
}
2760
- if (* irq < 0 )
2761
- return * irq ;
2802
+ if (irq_num < 0 )
2803
+ return irq_num ;
2762
2804
2763
- error = devm_request_irq (dev , * irq , handler , flags , dev_name , ndev );
2805
+ if (irq )
2806
+ * irq = irq_num ;
2807
+
2808
+ error = devm_request_irq (dev , irq_num , handler , flags , dev_name , ndev );
2764
2809
if (error )
2765
2810
netdev_err (ndev , "cannot request IRQ %s\n" , dev_name );
2766
2811
@@ -2772,7 +2817,7 @@ static int ravb_setup_irqs(struct ravb_private *priv)
2772
2817
const struct ravb_hw_info * info = priv -> info ;
2773
2818
struct net_device * ndev = priv -> ndev ;
2774
2819
const char * irq_name , * emac_irq_name ;
2775
- int error , irq ;
2820
+ int error ;
2776
2821
2777
2822
if (!info -> multi_irqs )
2778
2823
return ravb_setup_irq (priv , NULL , NULL , & ndev -> irq , ravb_interrupt );
@@ -2795,28 +2840,28 @@ static int ravb_setup_irqs(struct ravb_private *priv)
2795
2840
return error ;
2796
2841
2797
2842
if (info -> err_mgmt_irqs ) {
2798
- error = ravb_setup_irq (priv , "err_a" , "err_a" , & irq , ravb_multi_interrupt );
2843
+ error = ravb_setup_irq (priv , "err_a" , "err_a" , NULL , ravb_multi_interrupt );
2799
2844
if (error )
2800
2845
return error ;
2801
2846
2802
- error = ravb_setup_irq (priv , "mgmt_a" , "mgmt_a" , & irq , ravb_multi_interrupt );
2847
+ error = ravb_setup_irq (priv , "mgmt_a" , "mgmt_a" , NULL , ravb_multi_interrupt );
2803
2848
if (error )
2804
2849
return error ;
2805
2850
}
2806
2851
2807
- error = ravb_setup_irq (priv , "ch0" , "ch0:rx_be" , & irq , ravb_be_interrupt );
2852
+ error = ravb_setup_irq (priv , "ch0" , "ch0:rx_be" , NULL , ravb_be_interrupt );
2808
2853
if (error )
2809
2854
return error ;
2810
2855
2811
- error = ravb_setup_irq (priv , "ch1" , "ch1:rx_nc" , & irq , ravb_nc_interrupt );
2856
+ error = ravb_setup_irq (priv , "ch1" , "ch1:rx_nc" , NULL , ravb_nc_interrupt );
2812
2857
if (error )
2813
2858
return error ;
2814
2859
2815
- error = ravb_setup_irq (priv , "ch18" , "ch18:tx_be" , & irq , ravb_be_interrupt );
2860
+ error = ravb_setup_irq (priv , "ch18" , "ch18:tx_be" , NULL , ravb_be_interrupt );
2816
2861
if (error )
2817
2862
return error ;
2818
2863
2819
- return ravb_setup_irq (priv , "ch19" , "ch19:tx_nc" , & irq , ravb_nc_interrupt );
2864
+ return ravb_setup_irq (priv , "ch19" , "ch19:tx_nc" , NULL , ravb_nc_interrupt );
2820
2865
}
2821
2866
2822
2867
static int ravb_probe (struct platform_device * pdev )
@@ -2894,6 +2939,8 @@ static int ravb_probe(struct platform_device *pdev)
2894
2939
clk_prepare (priv -> refclk );
2895
2940
2896
2941
platform_set_drvdata (pdev , ndev );
2942
+ pm_runtime_set_autosuspend_delay (& pdev -> dev , 100 );
2943
+ pm_runtime_use_autosuspend (& pdev -> dev );
2897
2944
pm_runtime_enable (& pdev -> dev );
2898
2945
error = pm_runtime_resume_and_get (& pdev -> dev );
2899
2946
if (error < 0 )
@@ -2999,6 +3046,9 @@ static int ravb_probe(struct platform_device *pdev)
2999
3046
netdev_info (ndev , "Base address at %#x, %pM, IRQ %d.\n" ,
3000
3047
(u32 )ndev -> base_addr , ndev -> dev_addr , ndev -> irq );
3001
3048
3049
+ pm_runtime_mark_last_busy (& pdev -> dev );
3050
+ pm_runtime_put_autosuspend (& pdev -> dev );
3051
+
3002
3052
return 0 ;
3003
3053
3004
3054
out_napi_del :
@@ -3016,6 +3066,7 @@ static int ravb_probe(struct platform_device *pdev)
3016
3066
pm_runtime_put (& pdev -> dev );
3017
3067
out_rpm_disable :
3018
3068
pm_runtime_disable (& pdev -> dev );
3069
+ pm_runtime_dont_use_autosuspend (& pdev -> dev );
3019
3070
clk_unprepare (priv -> refclk );
3020
3071
out_reset_assert :
3021
3072
reset_control_assert (rstc );
@@ -3029,6 +3080,12 @@ static void ravb_remove(struct platform_device *pdev)
3029
3080
struct net_device * ndev = platform_get_drvdata (pdev );
3030
3081
struct ravb_private * priv = netdev_priv (ndev );
3031
3082
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 ;
3032
3089
3033
3090
unregister_netdev (ndev );
3034
3091
if (info -> nc_queues )
@@ -3040,8 +3097,9 @@ static void ravb_remove(struct platform_device *pdev)
3040
3097
dma_free_coherent (ndev -> dev .parent , priv -> desc_bat_size , priv -> desc_bat ,
3041
3098
priv -> desc_bat_dma );
3042
3099
3043
- pm_runtime_put_sync (& pdev -> dev );
3100
+ pm_runtime_put_sync_suspend (& pdev -> dev );
3044
3101
pm_runtime_disable (& pdev -> dev );
3102
+ pm_runtime_dont_use_autosuspend (dev );
3045
3103
clk_unprepare (priv -> refclk );
3046
3104
reset_control_assert (priv -> rstc );
3047
3105
free_netdev (ndev );
@@ -3123,6 +3181,10 @@ static int ravb_suspend(struct device *dev)
3123
3181
if (ret )
3124
3182
return ret ;
3125
3183
3184
+ ret = pm_runtime_force_suspend (& priv -> pdev -> dev );
3185
+ if (ret )
3186
+ return ret ;
3187
+
3126
3188
reset_assert :
3127
3189
return reset_control_assert (priv -> rstc );
3128
3190
}
@@ -3145,16 +3207,28 @@ static int ravb_resume(struct device *dev)
3145
3207
ret = ravb_wol_restore (ndev );
3146
3208
if (ret )
3147
3209
return ret ;
3210
+ } else {
3211
+ ret = pm_runtime_force_resume (dev );
3212
+ if (ret )
3213
+ return ret ;
3148
3214
}
3149
3215
3150
3216
/* Reopening the interface will restore the device to the working state. */
3151
3217
ret = ravb_open (ndev );
3152
3218
if (ret < 0 )
3153
- return ret ;
3219
+ goto out_rpm_put ;
3154
3220
3155
3221
ravb_set_rx_mode (ndev );
3156
3222
netif_device_attach (ndev );
3157
3223
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
+
3158
3232
return ret ;
3159
3233
}
3160
3234
0 commit comments