net: dsa: microchip: wrap the MAC configuration checks in a function

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>
This commit is contained in:
Bastien Curutchet (Schneider Electric) 2026-06-08 16:10:07 +02:00 committed by Jakub Kicinski
parent 4d574a5cfa
commit c90e80103b
2 changed files with 28 additions and 15 deletions

View File

@ -3211,6 +3211,29 @@ phy_interface_t ksz_get_xmii(struct ksz_device *dev, int port, bool gbit)
return interface;
}
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;
int port = dp->index;
/* Internal PHYs */
if (dev->info->internal_phy[port])
return false;
/* No need to configure XMII control register when using SGMII. */
if (ksz_is_sgmii_port(dev, port))
return false;
if (phylink_autoneg_inband(mode)) {
dev_err(dev->dev, "In-band AN not supported!\n");
return false;
}
return true;
}
void ksz_phylink_mac_config(struct phylink_config *config,
unsigned int mode,
const struct phylink_link_state *state)
@ -3219,23 +3242,12 @@ void ksz_phylink_mac_config(struct phylink_config *config,
struct ksz_device *dev = dp->ds->priv;
int port = dp->index;
/* Internal PHYs */
if (dev->info->internal_phy[port])
return;
if (ksz_phylink_need_config(config, mode)) {
ksz_set_xmii(dev, port, state->interface);
/* No need to configure XMII control register when using SGMII. */
if (ksz_is_sgmii_port(dev, port))
return;
if (phylink_autoneg_inband(mode)) {
dev_err(dev->dev, "In-band AN not supported!\n");
return;
if (dev->dev_ops->setup_rgmii_delay)
dev->dev_ops->setup_rgmii_delay(dev, port);
}
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)

View 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);