Merge branch 'r8152-fixes'

Hayes Wang says:

====================
r8152: issues fix

v2:
Replace patch #2 with "r8152: fix wakeup settings".

v1:
These patches are used to fix issues.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2015-07-27 00:56:39 -07:00
commit 3d3af88592

View File

@ -2075,7 +2075,6 @@ static int rtl_start_rx(struct r8152 *tp)
{ {
int i, ret = 0; int i, ret = 0;
napi_disable(&tp->napi);
INIT_LIST_HEAD(&tp->rx_done); INIT_LIST_HEAD(&tp->rx_done);
for (i = 0; i < RTL8152_MAX_RX; i++) { for (i = 0; i < RTL8152_MAX_RX; i++) {
INIT_LIST_HEAD(&tp->rx_info[i].list); INIT_LIST_HEAD(&tp->rx_info[i].list);
@ -2083,7 +2082,6 @@ static int rtl_start_rx(struct r8152 *tp)
if (ret) if (ret)
break; break;
} }
napi_enable(&tp->napi);
if (ret && ++i < RTL8152_MAX_RX) { if (ret && ++i < RTL8152_MAX_RX) {
struct list_head rx_queue; struct list_head rx_queue;
@ -2166,6 +2164,7 @@ static int rtl8153_enable(struct r8152 *tp)
if (test_bit(RTL8152_UNPLUG, &tp->flags)) if (test_bit(RTL8152_UNPLUG, &tp->flags))
return -ENODEV; return -ENODEV;
usb_disable_lpm(tp->udev);
set_tx_qlen(tp); set_tx_qlen(tp);
rtl_set_eee_plus(tp); rtl_set_eee_plus(tp);
r8153_set_rx_early_timeout(tp); r8153_set_rx_early_timeout(tp);
@ -2337,11 +2336,61 @@ static void __rtl_set_wol(struct r8152 *tp, u32 wolopts)
device_set_wakeup_enable(&tp->udev->dev, false); device_set_wakeup_enable(&tp->udev->dev, false);
} }
static void r8153_u1u2en(struct r8152 *tp, bool enable)
{
u8 u1u2[8];
if (enable)
memset(u1u2, 0xff, sizeof(u1u2));
else
memset(u1u2, 0x00, sizeof(u1u2));
usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2);
}
static void r8153_u2p3en(struct r8152 *tp, bool enable)
{
u32 ocp_data;
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL);
if (enable && tp->version != RTL_VER_03 && tp->version != RTL_VER_04)
ocp_data |= U2P3_ENABLE;
else
ocp_data &= ~U2P3_ENABLE;
ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
}
static void r8153_power_cut_en(struct r8152 *tp, bool enable)
{
u32 ocp_data;
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT);
if (enable)
ocp_data |= PWR_EN | PHASE2_EN;
else
ocp_data &= ~(PWR_EN | PHASE2_EN);
ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data);
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
ocp_data &= ~PCUT_STATUS;
ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
}
static bool rtl_can_wakeup(struct r8152 *tp)
{
struct usb_device *udev = tp->udev;
return (udev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_WAKEUP);
}
static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable) static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable)
{ {
if (enable) { if (enable) {
u32 ocp_data; u32 ocp_data;
r8153_u1u2en(tp, false);
r8153_u2p3en(tp, false);
__rtl_set_wol(tp, WAKE_ANY); __rtl_set_wol(tp, WAKE_ANY);
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG); ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_CONFIG);
@ -2353,6 +2402,8 @@ static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable)
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML); ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CRWECR, CRWECR_NORAML);
} else { } else {
__rtl_set_wol(tp, tp->saved_wolopts); __rtl_set_wol(tp, tp->saved_wolopts);
r8153_u2p3en(tp, true);
r8153_u1u2en(tp, true);
} }
} }
@ -2599,46 +2650,6 @@ static void r8153_hw_phy_cfg(struct r8152 *tp)
set_bit(PHY_RESET, &tp->flags); set_bit(PHY_RESET, &tp->flags);
} }
static void r8153_u1u2en(struct r8152 *tp, bool enable)
{
u8 u1u2[8];
if (enable)
memset(u1u2, 0xff, sizeof(u1u2));
else
memset(u1u2, 0x00, sizeof(u1u2));
usb_ocp_write(tp, USB_TOLERANCE, BYTE_EN_SIX_BYTES, sizeof(u1u2), u1u2);
}
static void r8153_u2p3en(struct r8152 *tp, bool enable)
{
u32 ocp_data;
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL);
if (enable)
ocp_data |= U2P3_ENABLE;
else
ocp_data &= ~U2P3_ENABLE;
ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
}
static void r8153_power_cut_en(struct r8152 *tp, bool enable)
{
u32 ocp_data;
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_POWER_CUT);
if (enable)
ocp_data |= PWR_EN | PHASE2_EN;
else
ocp_data &= ~(PWR_EN | PHASE2_EN);
ocp_write_word(tp, MCU_TYPE_USB, USB_POWER_CUT, ocp_data);
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_MISC_0);
ocp_data &= ~PCUT_STATUS;
ocp_write_word(tp, MCU_TYPE_USB, USB_MISC_0, ocp_data);
}
static void r8153_first_init(struct r8152 *tp) static void r8153_first_init(struct r8152 *tp)
{ {
u32 ocp_data; u32 ocp_data;
@ -2781,6 +2792,7 @@ static void rtl8153_disable(struct r8152 *tp)
r8153_disable_aldps(tp); r8153_disable_aldps(tp);
rtl_disable(tp); rtl_disable(tp);
r8153_enable_aldps(tp); r8153_enable_aldps(tp);
usb_enable_lpm(tp->udev);
} }
static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex) static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
@ -2901,9 +2913,13 @@ static void rtl8153_up(struct r8152 *tp)
if (test_bit(RTL8152_UNPLUG, &tp->flags)) if (test_bit(RTL8152_UNPLUG, &tp->flags))
return; return;
r8153_u1u2en(tp, false);
r8153_disable_aldps(tp); r8153_disable_aldps(tp);
r8153_first_init(tp); r8153_first_init(tp);
r8153_enable_aldps(tp); r8153_enable_aldps(tp);
r8153_u2p3en(tp, true);
r8153_u1u2en(tp, true);
usb_enable_lpm(tp->udev);
} }
static void rtl8153_down(struct r8152 *tp) static void rtl8153_down(struct r8152 *tp)
@ -2914,6 +2930,7 @@ static void rtl8153_down(struct r8152 *tp)
} }
r8153_u1u2en(tp, false); r8153_u1u2en(tp, false);
r8153_u2p3en(tp, false);
r8153_power_cut_en(tp, false); r8153_power_cut_en(tp, false);
r8153_disable_aldps(tp); r8153_disable_aldps(tp);
r8153_enter_oob(tp); r8153_enter_oob(tp);
@ -2932,8 +2949,10 @@ static void set_carrier(struct r8152 *tp)
if (!netif_carrier_ok(netdev)) { if (!netif_carrier_ok(netdev)) {
tp->rtl_ops.enable(tp); tp->rtl_ops.enable(tp);
set_bit(RTL8152_SET_RX_MODE, &tp->flags); set_bit(RTL8152_SET_RX_MODE, &tp->flags);
napi_disable(&tp->napi);
netif_carrier_on(netdev); netif_carrier_on(netdev);
rtl_start_rx(tp); rtl_start_rx(tp);
napi_enable(&tp->napi);
} }
} else { } else {
if (netif_carrier_ok(netdev)) { if (netif_carrier_ok(netdev)) {
@ -3252,6 +3271,7 @@ static void r8153_init(struct r8152 *tp)
msleep(20); msleep(20);
} }
usb_disable_lpm(tp->udev);
r8153_u2p3en(tp, false); r8153_u2p3en(tp, false);
if (tp->version == RTL_VER_04) { if (tp->version == RTL_VER_04) {
@ -3319,6 +3339,7 @@ static void r8153_init(struct r8152 *tp)
r8153_enable_aldps(tp); r8153_enable_aldps(tp);
r8152b_enable_fc(tp); r8152b_enable_fc(tp);
rtl_tally_reset(tp); rtl_tally_reset(tp);
r8153_u2p3en(tp, true);
} }
static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message) static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
@ -3374,9 +3395,11 @@ static int rtl8152_resume(struct usb_interface *intf)
if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) { if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
rtl_runtime_suspend_enable(tp, false); rtl_runtime_suspend_enable(tp, false);
clear_bit(SELECTIVE_SUSPEND, &tp->flags); clear_bit(SELECTIVE_SUSPEND, &tp->flags);
napi_disable(&tp->napi);
set_bit(WORK_ENABLE, &tp->flags); set_bit(WORK_ENABLE, &tp->flags);
if (netif_carrier_ok(tp->netdev)) if (netif_carrier_ok(tp->netdev))
rtl_start_rx(tp); rtl_start_rx(tp);
napi_enable(&tp->napi);
} else { } else {
tp->rtl_ops.up(tp); tp->rtl_ops.up(tp);
rtl8152_set_speed(tp, AUTONEG_ENABLE, rtl8152_set_speed(tp, AUTONEG_ENABLE,
@ -3403,12 +3426,15 @@ static void rtl8152_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
if (usb_autopm_get_interface(tp->intf) < 0) if (usb_autopm_get_interface(tp->intf) < 0)
return; return;
mutex_lock(&tp->control); if (!rtl_can_wakeup(tp)) {
wol->supported = 0;
wol->supported = WAKE_ANY; wol->wolopts = 0;
wol->wolopts = __rtl_get_wol(tp); } else {
mutex_lock(&tp->control);
mutex_unlock(&tp->control); wol->supported = WAKE_ANY;
wol->wolopts = __rtl_get_wol(tp);
mutex_unlock(&tp->control);
}
usb_autopm_put_interface(tp->intf); usb_autopm_put_interface(tp->intf);
} }
@ -3418,6 +3444,9 @@ static int rtl8152_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
struct r8152 *tp = netdev_priv(dev); struct r8152 *tp = netdev_priv(dev);
int ret; int ret;
if (!rtl_can_wakeup(tp))
return -EOPNOTSUPP;
ret = usb_autopm_get_interface(tp->intf); ret = usb_autopm_get_interface(tp->intf);
if (ret < 0) if (ret < 0)
goto out_set_wol; goto out_set_wol;
@ -4059,6 +4088,9 @@ static int rtl8152_probe(struct usb_interface *intf,
goto out1; goto out1;
} }
if (!rtl_can_wakeup(tp))
__rtl_set_wol(tp, 0);
tp->saved_wolopts = __rtl_get_wol(tp); tp->saved_wolopts = __rtl_get_wol(tp);
if (tp->saved_wolopts) if (tp->saved_wolopts)
device_set_wakeup_enable(&udev->dev, true); device_set_wakeup_enable(&udev->dev, true);