]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: dsa: microchip: wrap the MAC configuration checks in a function
authorBastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
Mon, 8 Jun 2026 14:10:07 +0000 (16:10 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 13 Jun 2026 01:08:07 +0000 (18:08 -0700)
The common .mac_config() implementation checks some conditions before
doing any register access. As this common implementation is about to be
split in the upcoming patch, these checks would lead to code
duplication.

Wrap all the checks in a need_config() function that returns true when
the driver really need to access the switch registers to configure the
MAC.

Signed-off-by: Bastien Curutchet (Schneider Electric) <bastien.curutchet@bootlin.com>
Link: https://patch.msgid.link/20260608-clean-ksz-3rd-v2-4-6e61b7be23c4@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/microchip/ksz_common.c
drivers/net/dsa/microchip/ksz_common.h

index 5fb151fbf4f306f3119398c1da64f4f4667c5cec..f2928792284327d3712d35da96950803ce7ef5f6 100644 (file)
@@ -3211,9 +3211,8 @@ phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit)
        return interface;
 }
 
-void ksz_phylink_mac_config(struct phylink_config *config,
-                           unsigned int mode,
-                           const struct phylink_link_state *state)
+bool ksz_phylink_need_config(struct phylink_config *config,
+                            unsigned int mode)
 {
        struct dsa_port *dp = dsa_phylink_to_port(config);
        struct ksz_device *dev = dp->ds->priv;
@@ -3221,21 +3220,34 @@ void ksz_phylink_mac_config(struct phylink_config *config,
 
        /* Internal PHYs */
        if (dev->info->internal_phy[port])
-               return;
+               return false;
 
        /* No need to configure XMII control register when using SGMII. */
        if (ksz_is_sgmii_port(dev, port))
-               return;
+               return false;
 
        if (phylink_autoneg_inband(mode)) {
                dev_err(dev->dev, "In-band AN not supported!\n");
-               return;
+               return false;
        }
 
-       ksz_set_xmii(dev, port, state->interface);
+       return true;
+}
 
-       if (dev->dev_ops->setup_rgmii_delay)
-               dev->dev_ops->setup_rgmii_delay(dev, port);
+void ksz_phylink_mac_config(struct phylink_config *config,
+                           unsigned int mode,
+                           const struct phylink_link_state *state)
+{
+       struct dsa_port *dp = dsa_phylink_to_port(config);
+       struct ksz_device *dev = dp->ds->priv;
+       int port = dp->index;
+
+       if (ksz_phylink_need_config(config, mode)) {
+               ksz_set_xmii(dev, port, state->interface);
+
+               if (dev->dev_ops->setup_rgmii_delay)
+                       dev->dev_ops->setup_rgmii_delay(dev, port);
+       }
 }
 
 bool ksz_get_gbit(struct ksz_device *dev, int port)
index de47498db483c01b4885605532605032195fe774..51d424233b29419e2d33173928aaf9fdabc98856 100644 (file)
@@ -472,6 +472,7 @@ void ksz_phylink_get_caps(struct dsa_switch *ds, int port,
 void ksz_phylink_mac_disable_tx_lpi(struct phylink_config *config);
 int ksz_phylink_mac_enable_tx_lpi(struct phylink_config *config,
                                  u32 timer, bool tx_clock_stop);
+bool ksz_phylink_need_config(struct phylink_config *config, unsigned int mode);
 void ksz_phylink_mac_config(struct phylink_config *config,
                            unsigned int mode,
                            const struct phylink_link_state *state);