Skip to content

Commit 5f61f03

Browse files
hkallweitopsiff
authored andcommitted
r8169: improve __rtl8169_set_wol
mainline inclusion from mainline-v6.13-rc1 category: other Add helper r8169_mod_reg8_cond() what allows to significantly simplify __rtl8169_set_wol(). Signed-off-by: Heiner Kallweit <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit c507e96) Signed-off-by: Wentao Guan <[email protected]>
1 parent d773d53 commit 5f61f03

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

drivers/net/ethernet/realtek/r8169_main.c

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,20 @@ static void rtl_mod_config5(struct rtl8169_private *tp, u8 clear, u8 set)
748748
RTL_W8(tp, Config5, (val & ~clear) | set);
749749
}
750750

751+
static void r8169_mod_reg8_cond(struct rtl8169_private *tp, int reg,
752+
u8 bits, bool cond)
753+
{
754+
u8 val, old_val;
755+
756+
old_val = RTL_R8(tp, reg);
757+
if (cond)
758+
val = old_val | bits;
759+
else
760+
val = old_val & ~bits;
761+
if (val != old_val)
762+
RTL_W8(tp, reg, val);
763+
}
764+
751765
static bool rtl_is_8125(struct rtl8169_private *tp)
752766
{
753767
return tp->mac_version >= RTL_GIGA_MAC_VER_61;
@@ -1538,58 +1552,37 @@ static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
15381552

15391553
static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts)
15401554
{
1541-
static const struct {
1542-
u32 opt;
1543-
u16 reg;
1544-
u8 mask;
1545-
} cfg[] = {
1546-
{ WAKE_PHY, Config3, LinkUp },
1547-
{ WAKE_UCAST, Config5, UWF },
1548-
{ WAKE_BCAST, Config5, BWF },
1549-
{ WAKE_MCAST, Config5, MWF },
1550-
{ WAKE_ANY, Config5, LanWake },
1551-
{ WAKE_MAGIC, Config3, MagicPacket }
1552-
};
1553-
unsigned int i, tmp = ARRAY_SIZE(cfg);
1554-
u8 options;
1555-
15561555
rtl_unlock_config_regs(tp);
15571556

15581557
if (rtl_is_8168evl_up(tp)) {
1559-
tmp--;
15601558
if (wolopts & WAKE_MAGIC)
15611559
rtl_eri_set_bits(tp, 0x0dc, MagicPacket_v2);
15621560
else
15631561
rtl_eri_clear_bits(tp, 0x0dc, MagicPacket_v2);
15641562
} else if (rtl_is_8125(tp)) {
1565-
tmp--;
15661563
if (wolopts & WAKE_MAGIC)
15671564
r8168_mac_ocp_modify(tp, 0xc0b6, 0, BIT(0));
15681565
else
15691566
r8168_mac_ocp_modify(tp, 0xc0b6, BIT(0), 0);
1567+
} else {
1568+
r8169_mod_reg8_cond(tp, Config3, MagicPacket,
1569+
wolopts & WAKE_MAGIC);
15701570
}
15711571

1572-
for (i = 0; i < tmp; i++) {
1573-
options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask;
1574-
if (wolopts & cfg[i].opt)
1575-
options |= cfg[i].mask;
1576-
RTL_W8(tp, cfg[i].reg, options);
1577-
}
1572+
r8169_mod_reg8_cond(tp, Config3, LinkUp, wolopts & WAKE_PHY);
1573+
r8169_mod_reg8_cond(tp, Config5, UWF, wolopts & WAKE_UCAST);
1574+
r8169_mod_reg8_cond(tp, Config5, BWF, wolopts & WAKE_BCAST);
1575+
r8169_mod_reg8_cond(tp, Config5, MWF, wolopts & WAKE_MCAST);
1576+
r8169_mod_reg8_cond(tp, Config5, LanWake, wolopts);
15781577

15791578
switch (tp->mac_version) {
15801579
case RTL_GIGA_MAC_VER_02 ... RTL_GIGA_MAC_VER_06:
1581-
options = RTL_R8(tp, Config1) & ~PMEnable;
1582-
if (wolopts)
1583-
options |= PMEnable;
1584-
RTL_W8(tp, Config1, options);
1580+
r8169_mod_reg8_cond(tp, Config1, PMEnable, wolopts);
15851581
break;
15861582
case RTL_GIGA_MAC_VER_34:
15871583
case RTL_GIGA_MAC_VER_37:
15881584
case RTL_GIGA_MAC_VER_39 ... RTL_GIGA_MAC_VER_66:
1589-
if (wolopts)
1590-
rtl_mod_config2(tp, 0, PME_SIGNAL);
1591-
else
1592-
rtl_mod_config2(tp, PME_SIGNAL, 0);
1585+
r8169_mod_reg8_cond(tp, Config2, PME_SIGNAL, wolopts);
15931586
break;
15941587
default:
15951588
break;

0 commit comments

Comments
 (0)