@@ -3446,39 +3446,87 @@ static bool delay_autosuspend(struct r8152 *tp)
34463446 return false;
34473447}
34483448
3449- static int rtl8152_suspend (struct usb_interface * intf , pm_message_t message )
3449+ static int rtl8152_rumtime_suspend (struct r8152 * tp )
34503450{
3451- struct r8152 * tp = usb_get_intfdata (intf );
34523451 struct net_device * netdev = tp -> netdev ;
34533452 int ret = 0 ;
34543453
3455- mutex_lock (& tp -> control );
3454+ if (netif_running (netdev ) && test_bit (WORK_ENABLE , & tp -> flags )) {
3455+ u32 rcr = 0 ;
34563456
3457- if (PMSG_IS_AUTO (message )) {
3458- if (netif_running (netdev ) && delay_autosuspend (tp )) {
3457+ if (delay_autosuspend (tp )) {
34593458 ret = - EBUSY ;
34603459 goto out1 ;
34613460 }
34623461
3463- set_bit (SELECTIVE_SUSPEND , & tp -> flags );
3464- } else {
3465- netif_device_detach (netdev );
3462+ if (netif_carrier_ok (netdev )) {
3463+ u32 ocp_data ;
3464+
3465+ rcr = ocp_read_dword (tp , MCU_TYPE_PLA , PLA_RCR );
3466+ ocp_data = rcr & ~RCR_ACPT_ALL ;
3467+ ocp_write_dword (tp , MCU_TYPE_PLA , PLA_RCR , ocp_data );
3468+ rxdy_gated_en (tp , true);
3469+ ocp_data = ocp_read_byte (tp , MCU_TYPE_PLA ,
3470+ PLA_OOB_CTRL );
3471+ if (!(ocp_data & RXFIFO_EMPTY )) {
3472+ rxdy_gated_en (tp , false);
3473+ ocp_write_dword (tp , MCU_TYPE_PLA , PLA_RCR , rcr );
3474+ ret = - EBUSY ;
3475+ goto out1 ;
3476+ }
3477+ }
3478+
3479+ clear_bit (WORK_ENABLE , & tp -> flags );
3480+ usb_kill_urb (tp -> intr_urb );
3481+
3482+ rtl_runtime_suspend_enable (tp , true);
3483+
3484+ if (netif_carrier_ok (netdev )) {
3485+ napi_disable (& tp -> napi );
3486+ rtl_stop_rx (tp );
3487+ rxdy_gated_en (tp , false);
3488+ ocp_write_dword (tp , MCU_TYPE_PLA , PLA_RCR , rcr );
3489+ napi_enable (& tp -> napi );
3490+ }
34663491 }
34673492
3493+ set_bit (SELECTIVE_SUSPEND , & tp -> flags );
3494+
3495+ out1 :
3496+ return ret ;
3497+ }
3498+
3499+ static int rtl8152_system_suspend (struct r8152 * tp )
3500+ {
3501+ struct net_device * netdev = tp -> netdev ;
3502+ int ret = 0 ;
3503+
3504+ netif_device_detach (netdev );
3505+
34683506 if (netif_running (netdev ) && test_bit (WORK_ENABLE , & tp -> flags )) {
34693507 clear_bit (WORK_ENABLE , & tp -> flags );
34703508 usb_kill_urb (tp -> intr_urb );
34713509 napi_disable (& tp -> napi );
3472- if (test_bit (SELECTIVE_SUSPEND , & tp -> flags )) {
3473- rtl_stop_rx (tp );
3474- rtl_runtime_suspend_enable (tp , true);
3475- } else {
3476- cancel_delayed_work_sync (& tp -> schedule );
3477- tp -> rtl_ops .down (tp );
3478- }
3510+ cancel_delayed_work_sync (& tp -> schedule );
3511+ tp -> rtl_ops .down (tp );
34793512 napi_enable (& tp -> napi );
34803513 }
3481- out1 :
3514+
3515+ return ret ;
3516+ }
3517+
3518+ static int rtl8152_suspend (struct usb_interface * intf , pm_message_t message )
3519+ {
3520+ struct r8152 * tp = usb_get_intfdata (intf );
3521+ int ret ;
3522+
3523+ mutex_lock (& tp -> control );
3524+
3525+ if (PMSG_IS_AUTO (message ))
3526+ ret = rtl8152_rumtime_suspend (tp );
3527+ else
3528+ ret = rtl8152_system_suspend (tp );
3529+
34823530 mutex_unlock (& tp -> control );
34833531
34843532 return ret ;
0 commit comments