net: phylink: split phylink_sfp_module_insert()
authorRussell King <rmk+kernel@armlinux.org.uk>
Wed, 11 Dec 2019 10:56:40 +0000 (10:56 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 11 Dec 2019 19:53:41 +0000 (11:53 -0800)
Split out the configuration step from phylink_sfp_module_insert() so
we can re-use this later.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phylink.c

index bce530fc956d1eb4aa8ee6f585787ab81c1e4523..571521d928f25094a8d7dca3d8cdff79b384872e 100644 (file)
@@ -1684,25 +1684,21 @@ static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)
        pl->netdev->sfp_bus = NULL;
 }
 
-static int phylink_sfp_module_insert(void *upstream,
-                                    const struct sfp_eeprom_id *id)
+static int phylink_sfp_config(struct phylink *pl, u8 mode, u8 port,
+                             const unsigned long *supported,
+                             const unsigned long *advertising)
 {
-       struct phylink *pl = upstream;
-       __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
        __ETHTOOL_DECLARE_LINK_MODE_MASK(support1);
+       __ETHTOOL_DECLARE_LINK_MODE_MASK(support);
        struct phylink_link_state config;
        phy_interface_t iface;
-       int ret = 0;
        bool changed;
-       u8 port;
-
-       ASSERT_RTNL();
+       int ret;
 
-       sfp_parse_support(pl->sfp_bus, id, support);
-       port = sfp_parse_port(pl->sfp_bus, id, support);
+       linkmode_copy(support, supported);
 
        memset(&config, 0, sizeof(config));
-       linkmode_copy(config.advertising, support);
+       linkmode_copy(config.advertising, advertising);
        config.interface = PHY_INTERFACE_MODE_NA;
        config.speed = SPEED_UNKNOWN;
        config.duplex = DUPLEX_UNKNOWN;
@@ -1717,8 +1713,6 @@ static int phylink_sfp_module_insert(void *upstream,
                return ret;
        }
 
-       linkmode_copy(support1, support);
-
        iface = sfp_select_interface(pl->sfp_bus, config.advertising);
        if (iface == PHY_INTERFACE_MODE_NA) {
                phylink_err(pl,
@@ -1728,18 +1722,18 @@ static int phylink_sfp_module_insert(void *upstream,
        }
 
        config.interface = iface;
+       linkmode_copy(support1, support);
        ret = phylink_validate(pl, support1, &config);
        if (ret) {
                phylink_err(pl, "validation of %s/%s with support %*pb failed: %d\n",
-                           phylink_an_mode_str(MLO_AN_INBAND),
+                           phylink_an_mode_str(mode),
                            phy_modes(config.interface),
                            __ETHTOOL_LINK_MODE_MASK_NBITS, support, ret);
                return ret;
        }
 
        phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n",
-                   phylink_an_mode_str(MLO_AN_INBAND),
-                   phy_modes(config.interface),
+                   phylink_an_mode_str(mode), phy_modes(config.interface),
                    __ETHTOOL_LINK_MODE_MASK_NBITS, support);
 
        if (phy_interface_mode_is_8023z(iface) && pl->phydev)
@@ -1751,15 +1745,15 @@ static int phylink_sfp_module_insert(void *upstream,
                linkmode_copy(pl->link_config.advertising, config.advertising);
        }
 
-       if (pl->cur_link_an_mode != MLO_AN_INBAND ||
+       if (pl->cur_link_an_mode != mode ||
            pl->link_config.interface != config.interface) {
                pl->link_config.interface = config.interface;
-               pl->cur_link_an_mode = MLO_AN_INBAND;
+               pl->cur_link_an_mode = mode;
 
                changed = true;
 
                phylink_info(pl, "switched to %s/%s link mode\n",
-                            phylink_an_mode_str(MLO_AN_INBAND),
+                            phylink_an_mode_str(mode),
                             phy_modes(config.interface));
        }
 
@@ -1772,6 +1766,21 @@ static int phylink_sfp_module_insert(void *upstream,
        return ret;
 }
 
+static int phylink_sfp_module_insert(void *upstream,
+                                    const struct sfp_eeprom_id *id)
+{
+       struct phylink *pl = upstream;
+       __ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
+       u8 port;
+
+       ASSERT_RTNL();
+
+       sfp_parse_support(pl->sfp_bus, id, support);
+       port = sfp_parse_port(pl->sfp_bus, id, support);
+
+       return phylink_sfp_config(pl, MLO_AN_INBAND, port, support, support);
+}
+
 static int phylink_sfp_module_start(void *upstream)
 {
        struct phylink *pl = upstream;