@@ -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 );
19791984out_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 );
19811989out_napi_off :
19821990 if (info -> nc_queues )
19831991 napi_disable (& priv -> napi [RAVB_NC ]);
@@ -2244,8 +2252,15 @@ static struct net_device_stats *ravb_get_stats(struct net_device *ndev)
22442252 struct ravb_private * priv = netdev_priv (ndev );
22452253 const struct ravb_hw_info * info = priv -> info ;
22462254 struct net_device_stats * nstats , * stats0 , * stats1 ;
2255+ struct device * dev = & priv -> pdev -> dev ;
22472256
22482257 nstats = & ndev -> stats ;
2258+
2259+ pm_runtime_get_noresume (dev );
2260+
2261+ if (!pm_runtime_active (dev ))
2262+ goto out_rpm_put ;
2263+
22492264 stats0 = & priv -> stats [RAVB_BE ];
22502265
22512266 if (info -> tx_counters ) {
@@ -2287,6 +2302,8 @@ static struct net_device_stats *ravb_get_stats(struct net_device *ndev)
22872302 nstats -> rx_over_errors += stats1 -> rx_over_errors ;
22882303 }
22892304
2305+ out_rpm_put :
2306+ pm_runtime_put_noidle (dev );
22902307 return nstats ;
22912308}
22922309
@@ -2309,6 +2326,8 @@ static int ravb_close(struct net_device *ndev)
23092326 struct ravb_private * priv = netdev_priv (ndev );
23102327 const struct ravb_hw_info * info = priv -> info ;
23112328 struct ravb_tstamp_skb * ts_skb , * ts_skb2 ;
2329+ struct device * dev = & priv -> pdev -> dev ;
2330+ int error ;
23122331
23132332 netif_tx_stop_all_queues (ndev );
23142333
@@ -2317,6 +2336,14 @@ static int ravb_close(struct net_device *ndev)
23172336 ravb_write (ndev , 0 , RIC2 );
23182337 ravb_write (ndev , 0 , TIC );
23192338
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+
23202347 /* Stop PTP Clock driver */
23212348 if (info -> gptp || info -> ccc_gac )
23222349 ravb_ptp_stop (ndev );
@@ -2335,14 +2362,6 @@ static int ravb_close(struct net_device *ndev)
23352362 }
23362363 }
23372364
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-
23462365 cancel_work_sync (& priv -> work );
23472366
23482367 if (info -> nc_queues )
@@ -2354,8 +2373,18 @@ static int ravb_close(struct net_device *ndev)
23542373 if (info -> nc_queues )
23552374 ravb_ring_free (ndev , RAVB_NC );
23562375
2376+ /* Update statistics. */
2377+ ravb_get_stats (ndev );
2378+
23572379 /* 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 ;
23592388}
23602389
23612390static 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,
25262555 goto done ;
25272556 }
25282557
2529- ndev -> features = features ;
25302558done :
25312559 spin_unlock_irqrestore (& priv -> lock , flags );
25322560
@@ -2541,8 +2569,6 @@ static int ravb_set_features_rcar(struct net_device *ndev,
25412569 if (changed & NETIF_F_RXCSUM )
25422570 ravb_set_rx_csum (ndev , features & NETIF_F_RXCSUM );
25432571
2544- ndev -> features = features ;
2545-
25462572 return 0 ;
25472573}
25482574
@@ -2551,8 +2577,24 @@ static int ravb_set_features(struct net_device *ndev,
25512577{
25522578 struct ravb_private * priv = netdev_priv (ndev );
25532579 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 ;
25542596
2555- return info -> set_feature ( ndev , features ) ;
2597+ return 0 ;
25562598}
25572599
25582600static 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,
27432785 struct device * dev = & pdev -> dev ;
27442786 const char * dev_name ;
27452787 unsigned long flags ;
2746- int error ;
2788+ int error , irq_num ;
27472789
27482790 if (irq_name ) {
27492791 dev_name = devm_kasprintf (dev , GFP_KERNEL , "%s:%s" , ndev -> name , ch );
27502792 if (!dev_name )
27512793 return - ENOMEM ;
27522794
2753- * irq = platform_get_irq_byname (pdev , irq_name );
2795+ irq_num = platform_get_irq_byname (pdev , irq_name );
27542796 flags = 0 ;
27552797 } else {
27562798 dev_name = ndev -> name ;
2757- * irq = platform_get_irq (pdev , 0 );
2799+ irq_num = platform_get_irq (pdev , 0 );
27582800 flags = IRQF_SHARED ;
27592801 }
2760- if (* irq < 0 )
2761- return * irq ;
2802+ if (irq_num < 0 )
2803+ return irq_num ;
27622804
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 );
27642809 if (error )
27652810 netdev_err (ndev , "cannot request IRQ %s\n" , dev_name );
27662811
@@ -2772,7 +2817,7 @@ static int ravb_setup_irqs(struct ravb_private *priv)
27722817 const struct ravb_hw_info * info = priv -> info ;
27732818 struct net_device * ndev = priv -> ndev ;
27742819 const char * irq_name , * emac_irq_name ;
2775- int error , irq ;
2820+ int error ;
27762821
27772822 if (!info -> multi_irqs )
27782823 return ravb_setup_irq (priv , NULL , NULL , & ndev -> irq , ravb_interrupt );
@@ -2795,28 +2840,28 @@ static int ravb_setup_irqs(struct ravb_private *priv)
27952840 return error ;
27962841
27972842 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 );
27992844 if (error )
28002845 return error ;
28012846
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 );
28032848 if (error )
28042849 return error ;
28052850 }
28062851
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 );
28082853 if (error )
28092854 return error ;
28102855
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 );
28122857 if (error )
28132858 return error ;
28142859
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 );
28162861 if (error )
28172862 return error ;
28182863
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 );
28202865}
28212866
28222867static int ravb_probe (struct platform_device * pdev )
@@ -2894,6 +2939,8 @@ static int ravb_probe(struct platform_device *pdev)
28942939 clk_prepare (priv -> refclk );
28952940
28962941 platform_set_drvdata (pdev , ndev );
2942+ pm_runtime_set_autosuspend_delay (& pdev -> dev , 100 );
2943+ pm_runtime_use_autosuspend (& pdev -> dev );
28972944 pm_runtime_enable (& pdev -> dev );
28982945 error = pm_runtime_resume_and_get (& pdev -> dev );
28992946 if (error < 0 )
@@ -2999,6 +3046,9 @@ static int ravb_probe(struct platform_device *pdev)
29993046 netdev_info (ndev , "Base address at %#x, %pM, IRQ %d.\n" ,
30003047 (u32 )ndev -> base_addr , ndev -> dev_addr , ndev -> irq );
30013048
3049+ pm_runtime_mark_last_busy (& pdev -> dev );
3050+ pm_runtime_put_autosuspend (& pdev -> dev );
3051+
30023052 return 0 ;
30033053
30043054out_napi_del :
@@ -3016,6 +3066,7 @@ static int ravb_probe(struct platform_device *pdev)
30163066 pm_runtime_put (& pdev -> dev );
30173067out_rpm_disable :
30183068 pm_runtime_disable (& pdev -> dev );
3069+ pm_runtime_dont_use_autosuspend (& pdev -> dev );
30193070 clk_unprepare (priv -> refclk );
30203071out_reset_assert :
30213072 reset_control_assert (rstc );
@@ -3029,6 +3080,12 @@ static void ravb_remove(struct platform_device *pdev)
30293080 struct net_device * ndev = platform_get_drvdata (pdev );
30303081 struct ravb_private * priv = netdev_priv (ndev );
30313082 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 ;
30323089
30333090 unregister_netdev (ndev );
30343091 if (info -> nc_queues )
@@ -3040,8 +3097,9 @@ static void ravb_remove(struct platform_device *pdev)
30403097 dma_free_coherent (ndev -> dev .parent , priv -> desc_bat_size , priv -> desc_bat ,
30413098 priv -> desc_bat_dma );
30423099
3043- pm_runtime_put_sync (& pdev -> dev );
3100+ pm_runtime_put_sync_suspend (& pdev -> dev );
30443101 pm_runtime_disable (& pdev -> dev );
3102+ pm_runtime_dont_use_autosuspend (dev );
30453103 clk_unprepare (priv -> refclk );
30463104 reset_control_assert (priv -> rstc );
30473105 free_netdev (ndev );
@@ -3123,6 +3181,10 @@ static int ravb_suspend(struct device *dev)
31233181 if (ret )
31243182 return ret ;
31253183
3184+ ret = pm_runtime_force_suspend (& priv -> pdev -> dev );
3185+ if (ret )
3186+ return ret ;
3187+
31263188reset_assert :
31273189 return reset_control_assert (priv -> rstc );
31283190}
@@ -3145,16 +3207,28 @@ static int ravb_resume(struct device *dev)
31453207 ret = ravb_wol_restore (ndev );
31463208 if (ret )
31473209 return ret ;
3210+ } else {
3211+ ret = pm_runtime_force_resume (dev );
3212+ if (ret )
3213+ return ret ;
31483214 }
31493215
31503216 /* Reopening the interface will restore the device to the working state. */
31513217 ret = ravb_open (ndev );
31523218 if (ret < 0 )
3153- return ret ;
3219+ goto out_rpm_put ;
31543220
31553221 ravb_set_rx_mode (ndev );
31563222 netif_device_attach (ndev );
31573223
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+
31583232 return ret ;
31593233}
31603234
0 commit comments