Commit 2b3e48b6 authored by Heiner Kallweit's avatar Heiner Kallweit Committed by David S. Miller

r8169: improve rtl_set_coalesce

Use FIELD_PREP() to make the code better readable, and avoid the loop.
No functional change intended.
Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent bdd2be3a
...@@ -235,10 +235,8 @@ enum rtl_registers { ...@@ -235,10 +235,8 @@ enum rtl_registers {
#define RTL_COALESCE_RX_USECS GENMASK(7, 4) #define RTL_COALESCE_RX_USECS GENMASK(7, 4)
#define RTL_COALESCE_RX_FRAMES GENMASK(3, 0) #define RTL_COALESCE_RX_FRAMES GENMASK(3, 0)
#define RTL_COALESCE_MASK 0x0f #define RTL_COALESCE_T_MAX 0x0fU
#define RTL_COALESCE_SHIFT 4 #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_T_MAX * 4)
#define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK)
#define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2)
RxDescAddrLow = 0xe4, RxDescAddrLow = 0xe4,
RxDescAddrHigh = 0xe8, RxDescAddrHigh = 0xe8,
...@@ -1878,57 +1876,49 @@ static int rtl_coalesce_choose_scale(struct rtl8169_private *tp, u32 usec, ...@@ -1878,57 +1876,49 @@ static int rtl_coalesce_choose_scale(struct rtl8169_private *tp, u32 usec,
static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
{ {
struct rtl8169_private *tp = netdev_priv(dev); struct rtl8169_private *tp = netdev_priv(dev);
struct { u32 tx_fr = ec->tx_max_coalesced_frames;
u32 frames; u32 rx_fr = ec->rx_max_coalesced_frames;
u32 usecs; u32 coal_usec_max, units;
} coal_settings [] = {
{ ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs },
{ ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs }
}, *p = coal_settings;
u16 w = 0, cp01 = 0; u16 w = 0, cp01 = 0;
u32 coal_usec_max; int scale;
int scale, i;
if (rtl_is_8125(tp)) if (rtl_is_8125(tp))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (rx_fr > RTL_COALESCE_FRAME_MAX || tx_fr > RTL_COALESCE_FRAME_MAX)
return -ERANGE;
coal_usec_max = max(ec->rx_coalesce_usecs, ec->tx_coalesce_usecs); coal_usec_max = max(ec->rx_coalesce_usecs, ec->tx_coalesce_usecs);
scale = rtl_coalesce_choose_scale(tp, coal_usec_max, &cp01); scale = rtl_coalesce_choose_scale(tp, coal_usec_max, &cp01);
if (scale < 0) if (scale < 0)
return scale; return scale;
for (i = 0; i < 2; i++, p++) { /* Accept max_frames=1 we returned in rtl_get_coalesce. Accept it
u32 units; * not only when usecs=0 because of e.g. the following scenario:
*
/* * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX)
* accept max_frames=1 we returned in rtl_get_coalesce. * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1
* accept it not only when usecs=0 because of e.g. the following scenario: * - then user does `ethtool -C eth0 rx-usecs 100`
* *
* - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) * Since ethtool sends to kernel whole ethtool_coalesce settings,
* - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 * if we want to ignore rx_frames then it has to be set to 0.
* - then user does `ethtool -C eth0 rx-usecs 100` */
* if (rx_fr == 1)
* since ethtool sends to kernel whole ethtool_coalesce rx_fr = 0;
* settings, if we want to ignore rx_frames then it has if (tx_fr == 1)
* to be set to 0. tx_fr = 0;
*/
if (p->frames == 1) {
p->frames = 0;
}
units = DIV_ROUND_UP(p->usecs * 1000, scale); w |= FIELD_PREP(RTL_COALESCE_TX_FRAMES, DIV_ROUND_UP(tx_fr, 4));
if (p->frames > RTL_COALESCE_FRAME_MAX) w |= FIELD_PREP(RTL_COALESCE_RX_FRAMES, DIV_ROUND_UP(rx_fr, 4));
return -ERANGE;
w <<= RTL_COALESCE_SHIFT; units = DIV_ROUND_UP(ec->tx_coalesce_usecs * 1000U, scale);
w |= units; w |= FIELD_PREP(RTL_COALESCE_TX_USECS, units);
w <<= RTL_COALESCE_SHIFT; units = DIV_ROUND_UP(ec->rx_coalesce_usecs * 1000U, scale);
w |= DIV_ROUND_UP(p->frames, 4); w |= FIELD_PREP(RTL_COALESCE_RX_USECS, units);
}
rtl_lock_work(tp); rtl_lock_work(tp);
RTL_W16(tp, IntrMitigate, swab16(w)); RTL_W16(tp, IntrMitigate, w);
tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01; tp->cp_cmd = (tp->cp_cmd & ~INTT_MASK) | cp01;
RTL_W16(tp, CPlusCmd, tp->cp_cmd); RTL_W16(tp, CPlusCmd, tp->cp_cmd);
......
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