]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: phylink: add ability to validate a set of interface modes
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Fri, 30 Sep 2022 14:20:59 +0000 (16:20 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Oct 2022 10:08:32 +0000 (11:08 +0100)
Rather than having the ability to validate all supported interface
modes or a single interface mode, introduce the ability to validate
a subset of supported modes.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
[ rebased on current net-next ]
Signed-off-by: Marek BehĂșn <kabel@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phylink.c

index d0af026c9afae182535f5171e3acb66573474528..2cf388fad1be2d2df1e61b5e3e4aaa34aa2b2b64 100644 (file)
@@ -637,8 +637,9 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
        return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
 }
 
-static int phylink_validate_any(struct phylink *pl, unsigned long *supported,
-                               struct phylink_link_state *state)
+static int phylink_validate_mask(struct phylink *pl, unsigned long *supported,
+                                struct phylink_link_state *state,
+                                const unsigned long *interfaces)
 {
        __ETHTOOL_DECLARE_LINK_MODE_MASK(all_adv) = { 0, };
        __ETHTOOL_DECLARE_LINK_MODE_MASK(all_s) = { 0, };
@@ -647,7 +648,7 @@ static int phylink_validate_any(struct phylink *pl, unsigned long *supported,
        int intf;
 
        for (intf = 0; intf < PHY_INTERFACE_MODE_MAX; intf++) {
-               if (test_bit(intf, pl->config->supported_interfaces)) {
+               if (test_bit(intf, interfaces)) {
                        linkmode_copy(s, supported);
 
                        t = *state;
@@ -668,12 +669,14 @@ static int phylink_validate_any(struct phylink *pl, unsigned long *supported,
 static int phylink_validate(struct phylink *pl, unsigned long *supported,
                            struct phylink_link_state *state)
 {
-       if (!phy_interface_empty(pl->config->supported_interfaces)) {
+       const unsigned long *interfaces = pl->config->supported_interfaces;
+
+       if (!phy_interface_empty(interfaces)) {
                if (state->interface == PHY_INTERFACE_MODE_NA)
-                       return phylink_validate_any(pl, supported, state);
+                       return phylink_validate_mask(pl, supported, state,
+                                                    interfaces);
 
-               if (!test_bit(state->interface,
-                             pl->config->supported_interfaces))
+               if (!test_bit(state->interface, interfaces))
                        return -EINVAL;
        }