Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[platform/kernel/linux-rpi.git] / drivers / net / usb / r8152.c
index cee9fef..54a83f7 100644 (file)
@@ -736,16 +736,16 @@ struct r8152 {
        struct tasklet_struct tx_tl;
 
        struct rtl_ops {
-               void (*init)(struct r8152 *);
-               int (*enable)(struct r8152 *);
-               void (*disable)(struct r8152 *);
-               void (*up)(struct r8152 *);
-               void (*down)(struct r8152 *);
-               void (*unload)(struct r8152 *);
-               int (*eee_get)(struct r8152 *, struct ethtool_eee *);
-               int (*eee_set)(struct r8152 *, struct ethtool_eee *);
-               bool (*in_nway)(struct r8152 *);
-               void (*hw_phy_cfg)(struct r8152 *);
+               void (*init)(struct r8152 *tp);
+               int (*enable)(struct r8152 *tp);
+               void (*disable)(struct r8152 *tp);
+               void (*up)(struct r8152 *tp);
+               void (*down)(struct r8152 *tp);
+               void (*unload)(struct r8152 *tp);
+               int (*eee_get)(struct r8152 *tp, struct ethtool_eee *eee);
+               int (*eee_set)(struct r8152 *tp, struct ethtool_eee *eee);
+               bool (*in_nway)(struct r8152 *tp);
+               void (*hw_phy_cfg)(struct r8152 *tp);
                void (*autosuspend_en)(struct r8152 *tp, bool enable);
        } rtl_ops;
 
@@ -1688,7 +1688,7 @@ static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
 }
 
 /* r8152_csum_workaround()
- * The hw limites the value the transport offset. When the offset is out of the
+ * The hw limits the value of the transport offset. When the offset is out of
  * range, calculate the checksum by sw.
  */
 static void r8152_csum_workaround(struct r8152 *tp, struct sk_buff *skb,
@@ -2178,6 +2178,7 @@ static void tx_bottom(struct r8152 *tp)
        int res;
 
        do {
+               struct net_device *netdev = tp->netdev;
                struct tx_agg *agg;
 
                if (skb_queue_empty(&tp->tx_queue))
@@ -2188,24 +2189,23 @@ static void tx_bottom(struct r8152 *tp)
                        break;
 
                res = r8152_tx_agg_fill(tp, agg);
-               if (res) {
-                       struct net_device *netdev = tp->netdev;
+               if (!res)
+                       continue;
 
-                       if (res == -ENODEV) {
-                               rtl_set_unplug(tp);
-                               netif_device_detach(netdev);
-                       } else {
-                               struct net_device_stats *stats = &netdev->stats;
-                               unsigned long flags;
+               if (res == -ENODEV) {
+                       rtl_set_unplug(tp);
+                       netif_device_detach(netdev);
+               } else {
+                       struct net_device_stats *stats = &netdev->stats;
+                       unsigned long flags;
 
-                               netif_warn(tp, tx_err, netdev,
-                                          "failed tx_urb %d\n", res);
-                               stats->tx_dropped += agg->skb_num;
+                       netif_warn(tp, tx_err, netdev,
+                                  "failed tx_urb %d\n", res);
+                       stats->tx_dropped += agg->skb_num;
 
-                               spin_lock_irqsave(&tp->tx_lock, flags);
-                               list_add_tail(&agg->list, &tp->tx_free);
-                               spin_unlock_irqrestore(&tp->tx_lock, flags);
-                       }
+                       spin_lock_irqsave(&tp->tx_lock, flags);
+                       list_add_tail(&agg->list, &tp->tx_free);
+                       spin_unlock_irqrestore(&tp->tx_lock, flags);
                }
        } while (res == 0);
 }
@@ -3377,11 +3377,23 @@ static void r8152b_hw_phy_cfg(struct r8152 *tp)
        set_bit(PHY_RESET, &tp->flags);
 }
 
-static void r8152b_exit_oob(struct r8152 *tp)
+static void wait_oob_link_list_ready(struct r8152 *tp)
 {
        u32 ocp_data;
        int i;
 
+       for (i = 0; i < 1000; i++) {
+               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
+               if (ocp_data & LINK_LIST_READY)
+                       break;
+               usleep_range(1000, 2000);
+       }
+}
+
+static void r8152b_exit_oob(struct r8152 *tp)
+{
+       u32 ocp_data;
+
        ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
        ocp_data &= ~RCR_ACPT_ALL;
        ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
@@ -3399,23 +3411,13 @@ static void r8152b_exit_oob(struct r8152 *tp)
        ocp_data &= ~MCU_BORW_EN;
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
        ocp_data |= RE_INIT_LL;
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        rtl8152_nic_reset(tp);
 
@@ -3457,7 +3459,6 @@ static void r8152b_exit_oob(struct r8152 *tp)
 static void r8152b_enter_oob(struct r8152 *tp)
 {
        u32 ocp_data;
-       int i;
 
        ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
        ocp_data &= ~NOW_IS_OOB;
@@ -3469,23 +3470,13 @@ static void r8152b_enter_oob(struct r8152 *tp)
 
        rtl_disable(tp);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
        ocp_data |= RE_INIT_LL;
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, RTL8152_RMS);
 
@@ -3711,7 +3702,6 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
 static void r8153_first_init(struct r8152 *tp)
 {
        u32 ocp_data;
-       int i;
 
        r8153_mac_clk_spd(tp, false);
        rxdy_gated_en(tp, true);
@@ -3732,23 +3722,13 @@ static void r8153_first_init(struct r8152 *tp)
        ocp_data &= ~MCU_BORW_EN;
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
        ocp_data |= RE_INIT_LL;
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX);
 
@@ -3773,7 +3753,6 @@ static void r8153_first_init(struct r8152 *tp)
 static void r8153_enter_oob(struct r8152 *tp)
 {
        u32 ocp_data;
-       int i;
 
        r8153_mac_clk_spd(tp, true);
 
@@ -3784,23 +3763,13 @@ static void r8153_enter_oob(struct r8152 *tp)
        rtl_disable(tp);
        rtl_reset_bmu(tp);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7);
        ocp_data |= RE_INIT_LL;
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_SFF_STS_7, ocp_data);
 
-       for (i = 0; i < 1000; i++) {
-               ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_OOB_CTRL);
-               if (ocp_data & LINK_LIST_READY)
-                       break;
-               usleep_range(1000, 2000);
-       }
+       wait_oob_link_list_ready(tp);
 
        ocp_data = tp->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
        ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, ocp_data);
@@ -5633,7 +5602,8 @@ static int rtl8152_probe(struct usb_interface *intf,
        }
 
        if (le16_to_cpu(udev->descriptor.bcdDevice) == 0x3011 && udev->serial &&
-           (!strcmp(udev->serial, "000001000000") || !strcmp(udev->serial, "000002000000"))) {
+           (!strcmp(udev->serial, "000001000000") ||
+            !strcmp(udev->serial, "000002000000"))) {
                dev_info(&udev->dev, "Dell TB16 Dock, disable RX aggregation");
                set_bit(DELL_TB_RX_AGG_BUG, &tp->flags);
        }