* [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions
@ 2024-05-29 9:41 Oleksij Rempel
2024-05-29 9:41 ` [PATCH v1 2/2] net: sja1105: add function to configure CPU port Oleksij Rempel
2024-05-30 13:25 ` [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-05-29 9:41 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel
Refactor sja1105_adjust_link by moving RGMII delay and speed settings
into separate functions: sja1105_set_rgmii_delay() and
sja1105_set_speed().
This restructuring makes the code more modular and reusable, preparing
for the next patch where the CPU port configuration will be handled in
a separate function.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/sja1105.c | 89 ++++++++++++++++++++++++++-----------------
1 file changed, 53 insertions(+), 36 deletions(-)
diff --git a/drivers/net/sja1105.c b/drivers/net/sja1105.c
index d88a5e2fcf..c759c40b36 100644
--- a/drivers/net/sja1105.c
+++ b/drivers/net/sja1105.c
@@ -2713,6 +2713,55 @@ static int sja1105_port_set_mode(struct dsa_port *dp, int port,
return 0;
}
+static int sja1105_set_rgmii_delay(struct sja1105_private *priv, int port,
+ phy_interface_t phy_mode)
+{
+ if (phy_mode == PHY_INTERFACE_MODE_RGMII_RXID ||
+ phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
+ priv->rgmii_rx_delay[port] = true;
+
+ if (phy_mode == PHY_INTERFACE_MODE_RGMII_TXID ||
+ phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
+ priv->rgmii_tx_delay[port] = true;
+
+ if ((priv->rgmii_rx_delay[port] ||
+ priv->rgmii_tx_delay[port]) &&
+ !priv->dcfg->setup_rgmii_delay) {
+ dev_err(priv->dev, "Chip does not support internal RGMII delays\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static void sja1105_set_speed(struct dsa_port *dp, int port, int speed)
+{
+ struct device *dev = dp->ds->dev;
+ struct sja1105_private *priv = dev_get_priv(dev);
+ struct sja1105_xmii_params_entry *mii;
+ struct sja1105_mac_config_entry *mac;
+
+ mii = priv->static_config.tables[BLK_IDX_XMII_PARAMS].entries;
+ mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
+
+ if (mii->xmii_mode[port] == XMII_MODE_SGMII) {
+ mac[port].speed =
+ priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
+ priv->xpcs_cfg[port].speed = speed;
+ } else if (speed == SPEED_1000) {
+ mac[port].speed =
+ priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
+ } else if (speed == SPEED_100) {
+ mac[port].speed =
+ priv->dcfg->port_speed[SJA1105_SPEED_100MBPS];
+ } else if (speed == SPEED_10) {
+ mac[port].speed =
+ priv->dcfg->port_speed[SJA1105_SPEED_10MBPS];
+ } else {
+ mac[port].speed = priv->dcfg->port_speed[SJA1105_SPEED_AUTO];
+ }
+}
+
static int sja1105_port_pre_enable(struct dsa_port *dp, int port,
phy_interface_t phy_mode)
{
@@ -2734,13 +2783,10 @@ static void sja1105_adjust_link(struct eth_device *edev)
struct sja1105_private *priv = dev_get_priv(dev);
struct phy_device *phy = dp->edev.phydev;
phy_interface_t phy_mode = phy->interface;
- struct sja1105_xmii_params_entry *mii;
- struct sja1105_mac_config_entry *mac;
int port = dp->index;
int ret;
- mii = priv->static_config.tables[BLK_IDX_XMII_PARAMS].entries;
- mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG].entries;
+ sja1105_set_speed(dp, port, phy->speed);
ret = sja1105_port_set_mode(dp, port, phy_mode);
if (ret)
@@ -2748,38 +2794,9 @@ static void sja1105_adjust_link(struct eth_device *edev)
/* Let the PHY handle the RGMII delays, if present. */
if (phy->phy_id == 0) {
- if (phy_mode == PHY_INTERFACE_MODE_RGMII_RXID ||
- phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
- priv->rgmii_rx_delay[port] = true;
-
- if (phy_mode == PHY_INTERFACE_MODE_RGMII_TXID ||
- phy_mode == PHY_INTERFACE_MODE_RGMII_ID)
- priv->rgmii_tx_delay[port] = true;
-
- if ((priv->rgmii_rx_delay[port] ||
- priv->rgmii_tx_delay[port]) &&
- !priv->dcfg->setup_rgmii_delay) {
- dev_err(priv->dev, "Chip does not support internal RGMII delays\n");
- return;
- }
- }
-
- if (mii->xmii_mode[port] == XMII_MODE_SGMII) {
- mac[port].speed =
- priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
- priv->xpcs_cfg[port].speed = phy->speed;
- } else if (phy->speed == SPEED_1000) {
- mac[port].speed =
- priv->dcfg->port_speed[SJA1105_SPEED_1000MBPS];
- } else if (phy->speed == SPEED_100) {
- mac[port].speed =
- priv->dcfg->port_speed[SJA1105_SPEED_100MBPS];
- } else if (phy->speed == SPEED_10) {
- mac[port].speed =
- priv->dcfg->port_speed[SJA1105_SPEED_10MBPS];
- } else {
- mac[port].speed = priv->dcfg->port_speed[SJA1105_SPEED_AUTO];
- return;
+ ret = sja1105_set_rgmii_delay(priv, port, phy_mode);
+ if (ret)
+ goto error;
}
ret = sja1105_static_config_reload(priv);
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v1 2/2] net: sja1105: add function to configure CPU port
2024-05-29 9:41 [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions Oleksij Rempel
@ 2024-05-29 9:41 ` Oleksij Rempel
2024-05-30 13:25 ` [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-05-29 9:41 UTC (permalink / raw)
To: barebox; +Cc: Oleksij Rempel
Introduce sja1105_cpu_port_enable() to configure the CPU port.
Typically, dedicated Ethernet devices attach to a PHY with an adjust
link function for the networking framework to handle link adjustments.
However, for the CPU port, we face a unique scenario where the device
tree defines two Ethernet devices each with a fixed link: CPU == fixed
link and fixed link == Switch.
This function reflects the model where fixed link driver extracts all
needed information from the device tree, but we do not create an
Ethernet device for the fixed link == Switch bundle, only for the
CPU == fixed link part. Thus, instead of adding adjust link support for
non-dedicated Ethernet devices or making them official Ethernet devices,
we opt to use a port_enable call in the DSA framework.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/sja1105.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/drivers/net/sja1105.c b/drivers/net/sja1105.c
index c759c40b36..4ef30b8c81 100644
--- a/drivers/net/sja1105.c
+++ b/drivers/net/sja1105.c
@@ -2840,8 +2840,35 @@ static int sja1105_rcv(struct dsa_switch *ds, int *port, void *packet,
return 0;
}
+static int sja1105_cpu_port_enable(struct dsa_port *dp, int port,
+ struct phy_device *phy)
+{
+ struct device *dev = dp->ds->dev;
+ struct sja1105_private *priv = dev_get_priv(dev);
+ phy_interface_t phy_mode = phy->interface;
+ struct dsa_switch *ds = &priv->ds;
+ int cpu = ds->cpu_port;
+ int ret;
+
+ if (port != cpu)
+ return 0;
+
+ sja1105_set_speed(dp, port, phy->speed);
+
+ ret = sja1105_port_set_mode(dp, port, phy_mode);
+ if (ret)
+ return ret;
+
+ ret = sja1105_set_rgmii_delay(priv, port, phy_mode);
+ if (ret)
+ return ret;
+
+ return sja1105_static_config_reload(priv);
+}
+
static const struct dsa_switch_ops sja1105_dsa_ops = {
.port_pre_enable = sja1105_port_pre_enable,
+ .port_enable = sja1105_cpu_port_enable,
.adjust_link = sja1105_adjust_link,
.xmit = sja1105_xmit,
.rcv = sja1105_rcv,
--
2.39.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions
2024-05-29 9:41 [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions Oleksij Rempel
2024-05-29 9:41 ` [PATCH v1 2/2] net: sja1105: add function to configure CPU port Oleksij Rempel
@ 2024-05-30 13:25 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2024-05-30 13:25 UTC (permalink / raw)
To: barebox, Oleksij Rempel
On Wed, 29 May 2024 11:41:23 +0200, Oleksij Rempel wrote:
> Refactor sja1105_adjust_link by moving RGMII delay and speed settings
> into separate functions: sja1105_set_rgmii_delay() and
> sja1105_set_speed().
> This restructuring makes the code more modular and reusable, preparing
> for the next patch where the CPU port configuration will be handled in
> a separate function.
>
> [...]
Applied, thanks!
[1/2] net: sja1105: split adjust_link into reusable functions
https://git.pengutronix.de/cgit/barebox/commit/?id=7eb2939bc051 (link may not be stable)
[2/2] net: sja1105: add function to configure CPU port
https://git.pengutronix.de/cgit/barebox/commit/?id=9cce2d64ba7d (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-30 13:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-29 9:41 [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions Oleksij Rempel
2024-05-29 9:41 ` [PATCH v1 2/2] net: sja1105: add function to configure CPU port Oleksij Rempel
2024-05-30 13:25 ` [PATCH v1 1/2] net: sja1105: split adjust_link into reusable functions Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox