r8169: improve rtl_jumbo_config
authorHeiner Kallweit <hkallweit1@gmail.com>
Sat, 15 Feb 2020 13:52:58 +0000 (14:52 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 17 Feb 2020 03:36:06 +0000 (19:36 -0800)
Merge enabling and disabling jumbo packets to one function to make
the code a little simpler.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/realtek/r8169_main.c

index 25b0cae735798137383b6f39b8fbd5cb81b2577d..ce4cb7d7be712c0cca5c059f3f39dea2d4a0ffd3 100644 (file)
@@ -2472,66 +2472,52 @@ static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp)
        RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0));
 }
 
-static void rtl_hw_jumbo_enable(struct rtl8169_private *tp)
+static void rtl_jumbo_config(struct rtl8169_private *tp)
 {
-       rtl_unlock_config_regs(tp);
-       switch (tp->mac_version) {
-       case RTL_GIGA_MAC_VER_12:
-       case RTL_GIGA_MAC_VER_17:
-               pcie_set_readrq(tp->pci_dev, 512);
-               r8168b_1_hw_jumbo_enable(tp);
-               break;
-       case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_26:
-               pcie_set_readrq(tp->pci_dev, 512);
-               r8168c_hw_jumbo_enable(tp);
-               break;
-       case RTL_GIGA_MAC_VER_27 ... RTL_GIGA_MAC_VER_28:
-               r8168dp_hw_jumbo_enable(tp);
-               break;
-       case RTL_GIGA_MAC_VER_31 ... RTL_GIGA_MAC_VER_33:
-               pcie_set_readrq(tp->pci_dev, 512);
-               r8168e_hw_jumbo_enable(tp);
-               break;
-       default:
-               break;
-       }
-       rtl_lock_config_regs(tp);
-}
+       bool jumbo = tp->dev->mtu > ETH_DATA_LEN;
 
-static void rtl_hw_jumbo_disable(struct rtl8169_private *tp)
-{
        rtl_unlock_config_regs(tp);
        switch (tp->mac_version) {
        case RTL_GIGA_MAC_VER_12:
        case RTL_GIGA_MAC_VER_17:
-               r8168b_1_hw_jumbo_disable(tp);
+               if (jumbo) {
+                       pcie_set_readrq(tp->pci_dev, 512);
+                       r8168b_1_hw_jumbo_enable(tp);
+               } else {
+                       r8168b_1_hw_jumbo_disable(tp);
+               }
                break;
        case RTL_GIGA_MAC_VER_18 ... RTL_GIGA_MAC_VER_26:
-               r8168c_hw_jumbo_disable(tp);
+               if (jumbo) {
+                       pcie_set_readrq(tp->pci_dev, 512);
+                       r8168c_hw_jumbo_enable(tp);
+               } else {
+                       r8168c_hw_jumbo_disable(tp);
+               }
                break;
        case RTL_GIGA_MAC_VER_27 ... RTL_GIGA_MAC_VER_28:
-               r8168dp_hw_jumbo_disable(tp);
+               if (jumbo)
+                       r8168dp_hw_jumbo_enable(tp);
+               else
+                       r8168dp_hw_jumbo_disable(tp);
                break;
        case RTL_GIGA_MAC_VER_31 ... RTL_GIGA_MAC_VER_33:
-               r8168e_hw_jumbo_disable(tp);
+               if (jumbo) {
+                       pcie_set_readrq(tp->pci_dev, 512);
+                       r8168e_hw_jumbo_enable(tp);
+               } else {
+                       r8168e_hw_jumbo_disable(tp);
+               }
                break;
        default:
                break;
        }
        rtl_lock_config_regs(tp);
 
-       if (pci_is_pcie(tp->pci_dev) && tp->supports_gmii)
+       if (!jumbo && pci_is_pcie(tp->pci_dev) && tp->supports_gmii)
                pcie_set_readrq(tp->pci_dev, 4096);
 }
 
-static void rtl_jumbo_config(struct rtl8169_private *tp, int mtu)
-{
-       if (mtu > ETH_DATA_LEN)
-               rtl_hw_jumbo_enable(tp);
-       else
-               rtl_hw_jumbo_disable(tp);
-}
-
 DECLARE_RTL_COND(rtl_chipcmd_cond)
 {
        return RTL_R8(tp, ChipCmd) & CmdReset;
@@ -3875,7 +3861,7 @@ static void rtl_hw_start(struct  rtl8169_private *tp)
        rtl_set_rx_tx_desc_registers(tp);
        rtl_lock_config_regs(tp);
 
-       rtl_jumbo_config(tp, tp->dev->mtu);
+       rtl_jumbo_config(tp);
 
        /* Initially a 10 us delay. Turned it into a PCI commit. - FR */
        rtl_pci_commit(tp);
@@ -3891,10 +3877,9 @@ static int rtl8169_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct rtl8169_private *tp = netdev_priv(dev);
 
-       rtl_jumbo_config(tp, new_mtu);
-
        dev->mtu = new_mtu;
        netdev_update_features(dev);
+       rtl_jumbo_config(tp);
 
        return 0;
 }