aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhayeswang <hayeswang@realtek.com>2017-01-10 04:04:06 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-10 11:46:46 -0500
commit8fb280616878b81c0790a0c33acbeec59c5711f4 (patch)
tree1a3ca3ca379e295002c65f4b62740c9623b55d93
parentdc647ec88e029307e60e6bf9988056605f11051a (diff)
r8152: split rtl8152_suspend function
Split rtl8152_suspend() into rtl8152_system_suspend() and rtl8152_rumtime_suspend(). Signed-off-by: Hayes Wang <hayeswang@realtek.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/usb/r8152.c57
1 files changed, 40 insertions, 17 deletions
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 7dc61228c55b..c5e6d88de4e4 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -3576,39 +3576,62 @@ static bool delay_autosuspend(struct r8152 *tp)
3576 return false; 3576 return false;
3577} 3577}
3578 3578
3579static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message) 3579static int rtl8152_rumtime_suspend(struct r8152 *tp)
3580{ 3580{
3581 struct r8152 *tp = usb_get_intfdata(intf);
3582 struct net_device *netdev = tp->netdev; 3581 struct net_device *netdev = tp->netdev;
3583 int ret = 0; 3582 int ret = 0;
3584 3583
3585 mutex_lock(&tp->control); 3584 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) {
3586 3585 if (delay_autosuspend(tp)) {
3587 if (PMSG_IS_AUTO(message)) {
3588 if (netif_running(netdev) && delay_autosuspend(tp)) {
3589 ret = -EBUSY; 3586 ret = -EBUSY;
3590 goto out1; 3587 goto out1;
3591 } 3588 }
3592 3589
3593 set_bit(SELECTIVE_SUSPEND, &tp->flags); 3590 clear_bit(WORK_ENABLE, &tp->flags);
3594 } else { 3591 usb_kill_urb(tp->intr_urb);
3595 netif_device_detach(netdev); 3592 napi_disable(&tp->napi);
3593 rtl_stop_rx(tp);
3594 tp->rtl_ops.autosuspend_en(tp, true);
3595 napi_enable(&tp->napi);
3596 } 3596 }
3597 3597
3598 set_bit(SELECTIVE_SUSPEND, &tp->flags);
3599
3600out1:
3601 return ret;
3602}
3603
3604static int rtl8152_system_suspend(struct r8152 *tp)
3605{
3606 struct net_device *netdev = tp->netdev;
3607 int ret = 0;
3608
3609 netif_device_detach(netdev);
3610
3598 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) { 3611 if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) {
3599 clear_bit(WORK_ENABLE, &tp->flags); 3612 clear_bit(WORK_ENABLE, &tp->flags);
3600 usb_kill_urb(tp->intr_urb); 3613 usb_kill_urb(tp->intr_urb);
3601 napi_disable(&tp->napi); 3614 napi_disable(&tp->napi);
3602 if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { 3615 cancel_delayed_work_sync(&tp->schedule);
3603 rtl_stop_rx(tp); 3616 tp->rtl_ops.down(tp);
3604 tp->rtl_ops.autosuspend_en(tp, true);
3605 } else {
3606 cancel_delayed_work_sync(&tp->schedule);
3607 tp->rtl_ops.down(tp);
3608 }
3609 napi_enable(&tp->napi); 3617 napi_enable(&tp->napi);
3610 } 3618 }
3611out1: 3619
3620 return ret;
3621}
3622
3623static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
3624{
3625 struct r8152 *tp = usb_get_intfdata(intf);
3626 int ret;
3627
3628 mutex_lock(&tp->control);
3629
3630 if (PMSG_IS_AUTO(message))
3631 ret = rtl8152_rumtime_suspend(tp);
3632 else
3633 ret = rtl8152_system_suspend(tp);
3634
3612 mutex_unlock(&tp->control); 3635 mutex_unlock(&tp->control);
3613 3636
3614 return ret; 3637 return ret;