mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1 1/3] net: dsa: add adjust_link support
@ 2023-03-16 13:42 Oleksij Rempel
  2023-03-16 13:42 ` [PATCH v1 2/3] net: dsa: sja1105: move port enable to adjust link code Oleksij Rempel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Oleksij Rempel @ 2023-03-16 13:42 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

The required functionality is essential for cable hot plugging or
asynchronous link detection. In its current state, DSA will only operate
if the cable was connected prior to booting.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/dsa.c | 4 ++--
 include/dsa.h     | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa.c b/drivers/net/dsa.c
index 793bbbb4f1..9c21564876 100644
--- a/drivers/net/dsa.c
+++ b/drivers/net/dsa.c
@@ -104,8 +104,8 @@ static int dsa_port_start(struct eth_device *edev)
 			return ret;
 	}
 
-	ret = phy_device_connect(edev, ds->slave_mii_bus, dp->index, NULL, 0,
-				 interface);
+	ret = phy_device_connect(edev, ds->slave_mii_bus, dp->index,
+				 ops->adjust_link, 0, interface);
 	if (ret)
 		return ret;
 
diff --git a/include/dsa.h b/include/dsa.h
index e823bac0a7..527941c269 100644
--- a/include/dsa.h
+++ b/include/dsa.h
@@ -55,6 +55,7 @@ struct dsa_switch_ops {
 
 	int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
 	int (*phy_write)(struct dsa_switch *ds, int port, int regnum, u16 val);
+	void (*adjust_link)(struct eth_device *dev);
 };
 
 struct dsa_port {
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 2/3] net: dsa: sja1105: move port enable to adjust link code.
  2023-03-16 13:42 [PATCH v1 1/3] net: dsa: add adjust_link support Oleksij Rempel
@ 2023-03-16 13:42 ` Oleksij Rempel
  2023-03-16 13:42 ` [PATCH v1 3/3] net: dsa: sja1105: fall back to default speed configuration if no link was detected Oleksij Rempel
  2023-03-21  8:09 ` [PATCH v1 1/3] net: dsa: add adjust_link support Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2023-03-16 13:42 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Execute port enable code dynamically based on link detection status.
This enables proper MAC configuration during link detection events.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/sja1105.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/net/sja1105.c b/drivers/net/sja1105.c
index b85184ed92..693730f96c 100644
--- a/drivers/net/sja1105.c
+++ b/drivers/net/sja1105.c
@@ -1432,7 +1432,7 @@ static int sja1105_init_mac_settings(struct sja1105_private *priv)
 		.top  = {0x1FF, 0, 0, 0, 0, 0, 0},
 		.base = {0x0, 0, 0, 0, 0, 0, 0, 0},
 		.enabled = {1, 0, 0, 0, 0, 0, 0, 0},
-		/* Will be overridden in sja1105_port_enable. */
+		/* Will be overridden in sja1105_adjust_link. */
 		.speed = priv->dcfg->port_speed[SJA1105_SPEED_AUTO],
 		.egress = true,
 		.ingress = true,
@@ -2727,14 +2727,16 @@ static int sja1105_port_pre_enable(struct dsa_port *dp, int port,
 	return sja1105_static_config_reload(priv);
 }
 
-static int sja1105_port_enable(struct dsa_port *dp, int port,
-			       struct phy_device *phy)
+static void sja1105_adjust_link(struct eth_device *edev)
 {
+	struct dsa_port *dp = edev->priv;
 	struct device *dev = dp->ds->dev;
 	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;
@@ -2742,7 +2744,7 @@ static int sja1105_port_enable(struct dsa_port *dp, int port,
 
 	ret = sja1105_port_set_mode(dp, port, phy_mode);
 	if (ret)
-		return ret;
+		goto error;
 
 	/* Let the PHY handle the RGMII delays, if present. */
 	if (phy->phy_id == 0) {
@@ -2758,7 +2760,7 @@ static int sja1105_port_enable(struct dsa_port *dp, int 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;
 		}
 	}
 
@@ -2778,10 +2780,18 @@ static int sja1105_port_enable(struct dsa_port *dp, int port,
 	} else {
 		dev_err(priv->dev, "Invalid PHY speed %d on port %d\n",
 			phy->speed, port);
-		return -EINVAL;
+		return;
 	}
 
-	return sja1105_static_config_reload(priv);
+	ret = sja1105_static_config_reload(priv);
+	if (ret)
+		goto error;
+
+	return;
+
+error:
+	dev_err(priv->dev, "Failed to adjust link on port %d, error %pe\n",
+		port, ERR_PTR(ret));
 }
 
 static int sja1105_xmit(struct dsa_port *dp, int port, void *packet, int length)
@@ -2816,7 +2826,7 @@ static int sja1105_rcv(struct dsa_switch *ds, int *port, void *packet,
 
 static const struct dsa_switch_ops sja1105_dsa_ops = {
 	.port_pre_enable	= sja1105_port_pre_enable,
-	.port_enable		= sja1105_port_enable,
+	.adjust_link		= sja1105_adjust_link,
 	.xmit			= sja1105_xmit,
 	.rcv			= sja1105_rcv,
 };
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 3/3] net: dsa: sja1105: fall back to default speed configuration if no link was detected
  2023-03-16 13:42 [PATCH v1 1/3] net: dsa: add adjust_link support Oleksij Rempel
  2023-03-16 13:42 ` [PATCH v1 2/3] net: dsa: sja1105: move port enable to adjust link code Oleksij Rempel
@ 2023-03-16 13:42 ` Oleksij Rempel
  2023-03-21  8:09 ` [PATCH v1 1/3] net: dsa: add adjust_link support Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2023-03-16 13:42 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Rather than generating an error, revert to the default link
configuration. Some configuration is performed during the port pre-enable
sequence.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/sja1105.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/sja1105.c b/drivers/net/sja1105.c
index 693730f96c..328e5a6369 100644
--- a/drivers/net/sja1105.c
+++ b/drivers/net/sja1105.c
@@ -2778,8 +2778,7 @@ static void sja1105_adjust_link(struct eth_device *edev)
 		mac[port].speed =
 			priv->dcfg->port_speed[SJA1105_SPEED_10MBPS];
 	} else {
-		dev_err(priv->dev, "Invalid PHY speed %d on port %d\n",
-			phy->speed, port);
+		mac[port].speed = priv->dcfg->port_speed[SJA1105_SPEED_AUTO];
 		return;
 	}
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/3] net: dsa: add adjust_link support
  2023-03-16 13:42 [PATCH v1 1/3] net: dsa: add adjust_link support Oleksij Rempel
  2023-03-16 13:42 ` [PATCH v1 2/3] net: dsa: sja1105: move port enable to adjust link code Oleksij Rempel
  2023-03-16 13:42 ` [PATCH v1 3/3] net: dsa: sja1105: fall back to default speed configuration if no link was detected Oleksij Rempel
@ 2023-03-21  8:09 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-03-21  8:09 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Thu, Mar 16, 2023 at 02:42:07PM +0100, Oleksij Rempel wrote:
> The required functionality is essential for cable hot plugging or
> asynchronous link detection. In its current state, DSA will only operate
> if the cable was connected prior to booting.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/net/dsa.c | 4 ++--
>  include/dsa.h     | 1 +
>  2 files changed, 3 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/net/dsa.c b/drivers/net/dsa.c
> index 793bbbb4f1..9c21564876 100644
> --- a/drivers/net/dsa.c
> +++ b/drivers/net/dsa.c
> @@ -104,8 +104,8 @@ static int dsa_port_start(struct eth_device *edev)
>  			return ret;
>  	}
>  
> -	ret = phy_device_connect(edev, ds->slave_mii_bus, dp->index, NULL, 0,
> -				 interface);
> +	ret = phy_device_connect(edev, ds->slave_mii_bus, dp->index,
> +				 ops->adjust_link, 0, interface);
>  	if (ret)
>  		return ret;
>  
> diff --git a/include/dsa.h b/include/dsa.h
> index e823bac0a7..527941c269 100644
> --- a/include/dsa.h
> +++ b/include/dsa.h
> @@ -55,6 +55,7 @@ struct dsa_switch_ops {
>  
>  	int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
>  	int (*phy_write)(struct dsa_switch *ds, int port, int regnum, u16 val);
> +	void (*adjust_link)(struct eth_device *dev);
>  };
>  
>  struct dsa_port {
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-21  8:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 13:42 [PATCH v1 1/3] net: dsa: add adjust_link support Oleksij Rempel
2023-03-16 13:42 ` [PATCH v1 2/3] net: dsa: sja1105: move port enable to adjust link code Oleksij Rempel
2023-03-16 13:42 ` [PATCH v1 3/3] net: dsa: sja1105: fall back to default speed configuration if no link was detected Oleksij Rempel
2023-03-21  8:09 ` [PATCH v1 1/3] net: dsa: add adjust_link support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox