Skip to content

Commit 5f492a0

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: phylink: split out per-interface validation
Split out the internals of phylink_validate_mask() to make the code easier to read. Tested-by: Luo Jie <quic_luoj@quicinc.com> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://lore.kernel.org/r/E1r6VIB-00DDLr-7g@rmk-PC.armlinux.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 01972fa commit 5f492a0

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

drivers/net/phy/phylink.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -689,26 +689,44 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
689689
return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
690690
}
691691

692+
static void phylink_validate_one(struct phylink *pl,
693+
const unsigned long *supported,
694+
const struct phylink_link_state *state,
695+
phy_interface_t interface,
696+
unsigned long *accum_supported,
697+
unsigned long *accum_advertising)
698+
{
699+
__ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_supported);
700+
struct phylink_link_state tmp_state;
701+
702+
linkmode_copy(tmp_supported, supported);
703+
704+
tmp_state = *state;
705+
tmp_state.interface = interface;
706+
707+
if (!phylink_validate_mac_and_pcs(pl, tmp_supported, &tmp_state)) {
708+
phylink_dbg(pl, " interface %u (%s) rate match %s supports %*pbl\n",
709+
interface, phy_modes(interface),
710+
phy_rate_matching_to_str(tmp_state.rate_matching),
711+
__ETHTOOL_LINK_MODE_MASK_NBITS, tmp_supported);
712+
713+
linkmode_or(accum_supported, accum_supported, tmp_supported);
714+
linkmode_or(accum_advertising, accum_advertising,
715+
tmp_state.advertising);
716+
}
717+
}
718+
692719
static int phylink_validate_mask(struct phylink *pl, unsigned long *supported,
693720
struct phylink_link_state *state,
694721
const unsigned long *interfaces)
695722
{
696723
__ETHTOOL_DECLARE_LINK_MODE_MASK(all_adv) = { 0, };
697724
__ETHTOOL_DECLARE_LINK_MODE_MASK(all_s) = { 0, };
698-
__ETHTOOL_DECLARE_LINK_MODE_MASK(s);
699-
struct phylink_link_state t;
700725
int interface;
701726

702-
for_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX) {
703-
linkmode_copy(s, supported);
704-
705-
t = *state;
706-
t.interface = interface;
707-
if (!phylink_validate_mac_and_pcs(pl, s, &t)) {
708-
linkmode_or(all_s, all_s, s);
709-
linkmode_or(all_adv, all_adv, t.advertising);
710-
}
711-
}
727+
for_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX)
728+
phylink_validate_one(pl, supported, state, interface,
729+
all_s, all_adv);
712730

713731
linkmode_copy(supported, all_s);
714732
linkmode_copy(state->advertising, all_adv);

0 commit comments

Comments
 (0)