Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2f8225e8 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'r8152-fix-autosuspend'



Hayes Wang says:

====================
r8152: fix autosuspend issue

Avoid rx is split into two parts when runtime suspend occurs.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents dc647ec8 75dc692e
Loading
Loading
Loading
Loading
+64 −16
Original line number Original line Diff line number Diff line
@@ -3576,39 +3576,87 @@ static bool delay_autosuspend(struct r8152 *tp)
		return false;
		return false;
}
}


static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
static int rtl8152_rumtime_suspend(struct r8152 *tp)
{
{
	struct r8152 *tp = usb_get_intfdata(intf);
	struct net_device *netdev = tp->netdev;
	struct net_device *netdev = tp->netdev;
	int ret = 0;
	int ret = 0;


	mutex_lock(&tp->control);
	if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) {
		u32 rcr = 0;


	if (PMSG_IS_AUTO(message)) {
		if (delay_autosuspend(tp)) {
		if (netif_running(netdev) && delay_autosuspend(tp)) {
			ret = -EBUSY;
			ret = -EBUSY;
			goto out1;
			goto out1;
		}
		}


		if (netif_carrier_ok(netdev)) {
			u32 ocp_data;

			rcr = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
			ocp_data = rcr & ~RCR_ACPT_ALL;
			ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
			rxdy_gated_en(tp, true);
			ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA,
						 PLA_OOB_CTRL);
			if (!(ocp_data & RXFIFO_EMPTY)) {
				rxdy_gated_en(tp, false);
				ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, rcr);
				ret = -EBUSY;
				goto out1;
			}
		}

		clear_bit(WORK_ENABLE, &tp->flags);
		usb_kill_urb(tp->intr_urb);

		tp->rtl_ops.autosuspend_en(tp, true);

		if (netif_carrier_ok(netdev)) {
			napi_disable(&tp->napi);
			rtl_stop_rx(tp);
			rxdy_gated_en(tp, false);
			ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, rcr);
			napi_enable(&tp->napi);
		}
	}

	set_bit(SELECTIVE_SUSPEND, &tp->flags);
	set_bit(SELECTIVE_SUSPEND, &tp->flags);
	} else {

		netif_device_detach(netdev);
out1:
	return ret;
}
}


static int rtl8152_system_suspend(struct r8152 *tp)
{
	struct net_device *netdev = tp->netdev;
	int ret = 0;

	netif_device_detach(netdev);

	if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) {
	if (netif_running(netdev) && test_bit(WORK_ENABLE, &tp->flags)) {
		clear_bit(WORK_ENABLE, &tp->flags);
		clear_bit(WORK_ENABLE, &tp->flags);
		usb_kill_urb(tp->intr_urb);
		usb_kill_urb(tp->intr_urb);
		napi_disable(&tp->napi);
		napi_disable(&tp->napi);
		if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
			rtl_stop_rx(tp);
			tp->rtl_ops.autosuspend_en(tp, true);
		} else {
		cancel_delayed_work_sync(&tp->schedule);
		cancel_delayed_work_sync(&tp->schedule);
		tp->rtl_ops.down(tp);
		tp->rtl_ops.down(tp);
		}
		napi_enable(&tp->napi);
		napi_enable(&tp->napi);
	}
	}
out1:

	return ret;
}

static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
{
	struct r8152 *tp = usb_get_intfdata(intf);
	int ret;

	mutex_lock(&tp->control);

	if (PMSG_IS_AUTO(message))
		ret = rtl8152_rumtime_suspend(tp);
	else
		ret = rtl8152_system_suspend(tp);

	mutex_unlock(&tp->control);
	mutex_unlock(&tp->control);


	return ret;
	return ret;