Commit 5189c555 authored by David S. Miller's avatar David S. Miller

Merge branch 'r8152-minor-adjustment'

Hayes Wang says:

====================
r8152: minor adjustment

Adjust some code to make it reasonable or satisfy the suggestion from
the engineers.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a2e8bbd2 a3307f9b
......@@ -394,6 +394,7 @@
/* OCP_PHY_STATUS */
#define PHY_STAT_MASK 0x0007
#define PHY_STAT_EXT_INIT 2
#define PHY_STAT_LAN_ON 3
#define PHY_STAT_PWRDN 5
......@@ -1812,6 +1813,10 @@ static int rx_bottom(struct r8152 *tp, int budget)
unsigned int pkt_len;
struct sk_buff *skb;
/* limite the skb numbers for rx_queue */
if (unlikely(skb_queue_len(&tp->rx_queue) >= 1000))
break;
pkt_len = le32_to_cpu(rx_desc->opts1) & RX_LEN_MASK;
if (pkt_len < ETH_ZLEN)
break;
......@@ -1933,7 +1938,8 @@ static int r8152_poll(struct napi_struct *napi, int budget)
bottom_half(tp);
if (work_done < budget) {
napi_complete(napi);
if (!napi_complete_done(napi, work_done))
goto out;
if (!list_empty(&tp->rx_done))
napi_schedule(napi);
else if (!skb_queue_empty(&tp->tx_queue) &&
......@@ -1941,6 +1947,7 @@ static int r8152_poll(struct napi_struct *napi, int budget)
napi_schedule(napi);
}
out:
return work_done;
}
......@@ -2262,7 +2269,6 @@ static int rtl8153_enable(struct r8152 *tp)
if (test_bit(RTL8152_UNPLUG, &tp->flags))
return -ENODEV;
usb_disable_lpm(tp->udev);
set_tx_qlen(tp);
rtl_set_eee_plus(tp);
r8153_set_rx_early_timeout(tp);
......@@ -2428,6 +2434,29 @@ static void __rtl_set_wol(struct r8152 *tp, u32 wolopts)
device_set_wakeup_enable(&tp->udev->dev, false);
}
static void r8153_mac_clk_spd(struct r8152 *tp, bool enable)
{
/* MAC clock speed down */
if (enable) {
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL,
ALDPS_SPDWN_RATIO);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2,
EEE_SPDWN_RATIO);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3,
PKT_AVAIL_SPDWN_EN | SUSPEND_SPDWN_EN |
U1U2_SPDWN_EN | L1_SPDWN_EN);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4,
PWRSAVE_SPDWN_EN | RXDV_SPDWN_EN | TX10MIDLE_EN |
TP100_SPDWN_EN | TP500_SPDWN_EN | EEE_SPDWN_EN |
TP1000_SPDWN_EN);
} else {
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, 0);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, 0);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, 0);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, 0);
}
}
static void r8153_u1u2en(struct r8152 *tp, bool enable)
{
u8 u1u2[8];
......@@ -2445,13 +2474,35 @@ 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)
if (enable)
ocp_data |= U2P3_ENABLE;
else
ocp_data &= ~U2P3_ENABLE;
ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
}
static u16 r8153_phy_status(struct r8152 *tp, u16 desired)
{
u16 data;
int i;
for (i = 0; i < 500; i++) {
data = ocp_reg_read(tp, OCP_PHY_STATUS);
data &= PHY_STAT_MASK;
if (desired) {
if (data == desired)
break;
} else if (data == PHY_STAT_LAN_ON || data == PHY_STAT_PWRDN ||
data == PHY_STAT_EXT_INIT) {
break;
}
msleep(20);
}
return data;
}
static void r8153_power_cut_en(struct r8152 *tp, bool enable)
{
u32 ocp_data;
......@@ -2506,13 +2557,26 @@ static void rtl_runtime_suspend_enable(struct r8152 *tp, bool enable)
static void rtl8153_runtime_enable(struct r8152 *tp, bool enable)
{
rtl_runtime_suspend_enable(tp, enable);
if (enable) {
r8153_u1u2en(tp, false);
r8153_u2p3en(tp, false);
r8153_mac_clk_spd(tp, true);
rtl_runtime_suspend_enable(tp, true);
} else {
r8153_u2p3en(tp, true);
rtl_runtime_suspend_enable(tp, false);
r8153_mac_clk_spd(tp, false);
switch (tp->version) {
case RTL_VER_03:
case RTL_VER_04:
break;
case RTL_VER_05:
case RTL_VER_06:
default:
r8153_u2p3en(tp, true);
break;
}
r8153_u1u2en(tp, true);
}
}
......@@ -2778,9 +2842,15 @@ static void r8153_aldps_en(struct r8152 *tp, bool enable)
data |= EN_ALDPS;
ocp_reg_write(tp, OCP_POWER_CFG, data);
} else {
int i;
data &= ~EN_ALDPS;
ocp_reg_write(tp, OCP_POWER_CFG, data);
msleep(20);
for (i = 0; i < 20; i++) {
usleep_range(1000, 2000);
if (ocp_read_word(tp, MCU_TYPE_PLA, 0xe000) & 0x0100)
break;
}
}
}
......@@ -2851,6 +2921,17 @@ static void r8153_hw_phy_cfg(struct r8152 *tp)
r8153_aldps_en(tp, true);
r8152b_enable_fc(tp);
switch (tp->version) {
case RTL_VER_03:
case RTL_VER_04:
break;
case RTL_VER_05:
case RTL_VER_06:
default:
r8153_u2p3en(tp, true);
break;
}
set_bit(PHY_RESET, &tp->flags);
}
......@@ -2859,6 +2940,7 @@ static void r8153_first_init(struct r8152 *tp)
u32 ocp_data;
int i;
r8153_mac_clk_spd(tp, false);
rxdy_gated_en(tp, true);
r8153_teredo_off(tp);
......@@ -2913,11 +2995,6 @@ static void r8153_first_init(struct r8152 *tp)
ocp_write_word(tp, MCU_TYPE_PLA, PLA_RXFIFO_CTRL2, RXFIFO_THR3_NORMAL);
/* TX share fifo free credit full threshold */
ocp_write_dword(tp, MCU_TYPE_PLA, PLA_TXFIFO_CTRL, TXFIFO_THR_NORMAL2);
/* rx aggregation */
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
}
static void r8153_enter_oob(struct r8152 *tp)
......@@ -2925,6 +3002,8 @@ static void r8153_enter_oob(struct r8152 *tp)
u32 ocp_data;
int i;
r8153_mac_clk_spd(tp, true);
ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
ocp_data &= ~NOW_IS_OOB;
ocp_write_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL, ocp_data);
......@@ -2980,7 +3059,6 @@ static void rtl8153_disable(struct r8152 *tp)
rtl_disable(tp);
rtl_reset_bmu(tp);
r8153_aldps_en(tp, true);
usb_enable_lpm(tp->udev);
}
static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u16 speed, u8 duplex)
......@@ -3099,12 +3177,23 @@ static void rtl8153_up(struct r8152 *tp)
return;
r8153_u1u2en(tp, false);
r8153_u2p3en(tp, false);
r8153_aldps_en(tp, false);
r8153_first_init(tp);
r8153_aldps_en(tp, true);
r8153_u2p3en(tp, true);
switch (tp->version) {
case RTL_VER_03:
case RTL_VER_04:
break;
case RTL_VER_05:
case RTL_VER_06:
default:
r8153_u2p3en(tp, true);
break;
}
r8153_u1u2en(tp, true);
usb_enable_lpm(tp->udev);
}
static void rtl8153_down(struct r8152 *tp)
......@@ -3420,12 +3509,7 @@ static void r8153_init(struct r8152 *tp)
msleep(20);
}
for (i = 0; i < 500; i++) {
ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN)
break;
msleep(20);
}
data = r8153_phy_status(tp, 0);
if (tp->version == RTL_VER_03 || tp->version == RTL_VER_04 ||
tp->version == RTL_VER_05)
......@@ -3437,14 +3521,8 @@ static void r8153_init(struct r8152 *tp)
r8152_mdio_write(tp, MII_BMCR, data);
}
for (i = 0; i < 500; i++) {
ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
if (ocp_data == PHY_STAT_LAN_ON)
break;
msleep(20);
}
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);
usb_disable_lpm(tp->udev);
r8153_u2p3en(tp, false);
if (tp->version == RTL_VER_04) {
......@@ -3504,15 +3582,28 @@ static void r8153_init(struct r8152 *tp)
r8153_power_cut_en(tp, false);
r8153_u1u2en(tp, true);
r8153_mac_clk_spd(tp, false);
usb_enable_lpm(tp->udev);
/* MAC clock speed down */
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL, 0);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, 0);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, 0);
ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, 0);
/* rx aggregation */
ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
ocp_write_word(tp, MCU_TYPE_USB, USB_USB_CTRL, ocp_data);
rtl_tally_reset(tp);
r8153_u2p3en(tp, true);
switch (tp->udev->speed) {
case USB_SPEED_SUPER:
case USB_SPEED_SUPER_PLUS:
tp->coalesce = COALESCE_SUPER;
break;
case USB_SPEED_HIGH:
tp->coalesce = COALESCE_HIGH;
break;
default:
tp->coalesce = COALESCE_SLOW;
break;
}
}
static int rtl8152_pre_reset(struct usb_interface *intf)
......@@ -3697,11 +3788,8 @@ static int rtl8152_resume(struct usb_interface *intf)
mutex_lock(&tp->control);
if (!test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
tp->rtl_ops.init(tp);
queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0);
if (!test_bit(SELECTIVE_SUSPEND, &tp->flags))
netif_device_attach(netdev);
}
if (netif_running(netdev) && netdev->flags & IFF_UP) {
if (test_bit(SELECTIVE_SUSPEND, &tp->flags)) {
......@@ -3747,6 +3835,10 @@ static int rtl8152_reset_resume(struct usb_interface *intf)
struct r8152 *tp = usb_get_intfdata(intf);
clear_bit(SELECTIVE_SUSPEND, &tp->flags);
mutex_lock(&tp->control);
tp->rtl_ops.init(tp);
queue_delayed_work(system_long_wq, &tp->hw_phy_work, 0);
mutex_unlock(&tp->control);
return rtl8152_resume(intf);
}
......@@ -4458,19 +4550,6 @@ static int rtl8152_probe(struct usb_interface *intf,
tp->mii.reg_num_mask = 0x1f;
tp->mii.phy_id = R8152_PHY_ID;
switch (udev->speed) {
case USB_SPEED_SUPER:
case USB_SPEED_SUPER_PLUS:
tp->coalesce = COALESCE_SUPER;
break;
case USB_SPEED_HIGH:
tp->coalesce = COALESCE_HIGH;
break;
default:
tp->coalesce = COALESCE_SLOW;
break;
}
tp->autoneg = AUTONEG_ENABLE;
tp->speed = tp->mii.supports_gmii ? SPEED_1000 : SPEED_100;
tp->duplex = DUPLEX_FULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment