netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ftgmac100: Get link speed and duplex for NC-SI
@ 2024-08-02  8:33 Jacky Chou
  2024-08-02 15:48 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Jacky Chou @ 2024-08-02  8:33 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, jacky_chou, u.kleine-koenig,
	netdev, linux-kernel

The ethtool of this driver uses the phy API of ethtool
to get the link information from PHY driver.
Because the NC-SI is forced on 100Mbps and full duplex,
the driver connects a fixed-link phy driver for NC-SI.
The ethtool will get the link information from the
fixed-link phy driver.

Signed-off-by: Jacky Chou <jacky_chou@aspeedtech.com>
---
 drivers/net/ethernet/faraday/ftgmac100.c | 37 ++++++++++++++----------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index fddfd1dd5070..0c820997ef88 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -26,6 +26,7 @@
 #include <linux/of_net.h>
 #include <net/ip.h>
 #include <net/ncsi.h>
+#include <linux/phy_fixed.h>
 
 #include "ftgmac100.h"
 
@@ -50,6 +51,15 @@
 #define FTGMAC_100MHZ		100000000
 #define FTGMAC_25MHZ		25000000
 
+/* For NC-SI to register a fixed-link phy device */
+struct fixed_phy_status ncsi_phy_status = {
+	.link = 1,
+	.speed = SPEED_100,
+	.duplex = DUPLEX_FULL,
+	.pause = 0,
+	.asym_pause = 0
+};
+
 struct ftgmac100 {
 	/* Registers */
 	struct resource *res;
@@ -1492,19 +1502,8 @@ static int ftgmac100_open(struct net_device *netdev)
 		return err;
 	}
 
-	/* When using NC-SI we force the speed to 100Mbit/s full duplex,
-	 *
-	 * Otherwise we leave it set to 0 (no link), the link
-	 * message from the PHY layer will handle setting it up to
-	 * something else if needed.
-	 */
-	if (priv->use_ncsi) {
-		priv->cur_duplex = DUPLEX_FULL;
-		priv->cur_speed = SPEED_100;
-	} else {
-		priv->cur_duplex = 0;
-		priv->cur_speed = 0;
-	}
+	priv->cur_duplex = 0;
+	priv->cur_speed = 0;
 
 	/* Reset the hardware */
 	err = ftgmac100_reset_and_config_mac(priv);
@@ -1532,9 +1531,6 @@ static int ftgmac100_open(struct net_device *netdev)
 		/* If we have a PHY, start polling */
 		phy_start(netdev->phydev);
 	} else if (priv->use_ncsi) {
-		/* If using NC-SI, set our carrier on and start the stack */
-		netif_carrier_on(netdev);
-
 		/* Start the NCSI device */
 		err = ncsi_start_dev(priv->ndev);
 		if (err)
@@ -1794,6 +1790,7 @@ static int ftgmac100_probe(struct platform_device *pdev)
 	struct net_device *netdev;
 	struct ftgmac100 *priv;
 	struct device_node *np;
+	struct phy_device *phydev;
 	int err = 0;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1879,6 +1876,14 @@ static int ftgmac100_probe(struct platform_device *pdev)
 			err = -EINVAL;
 			goto err_phy_connect;
 		}
+
+		phydev = fixed_phy_register(PHY_POLL, &ncsi_phy_status, NULL);
+		err = phy_connect_direct(netdev, phydev, ftgmac100_adjust_link,
+					 PHY_INTERFACE_MODE_MII);
+		if (err) {
+			dev_err(&pdev->dev, "Connecting PHY failed\n");
+			goto err_phy_connect;
+		}
 	} else if (np && of_phy_is_fixed_link(np)) {
 		struct phy_device *phy;
 
-- 
2.25.1


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

* Re: [PATCH] net: ftgmac100: Get link speed and duplex for NC-SI
  2024-08-02  8:33 [PATCH] net: ftgmac100: Get link speed and duplex for NC-SI Jacky Chou
@ 2024-08-02 15:48 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2024-08-02 15:48 UTC (permalink / raw)
  To: Jacky Chou
  Cc: davem, edumazet, kuba, pabeni, u.kleine-koenig, netdev,
	linux-kernel

On Fri, Aug 02, 2024 at 04:33:32PM +0800, Jacky Chou wrote:
> The ethtool of this driver uses the phy API of ethtool
> to get the link information from PHY driver.
> Because the NC-SI is forced on 100Mbps and full duplex,
> the driver connects a fixed-link phy driver for NC-SI.
> The ethtool will get the link information from the
> fixed-link phy driver.
> 
> Signed-off-by: Jacky Chou <jacky_chou@aspeedtech.com>
> ---
>  drivers/net/ethernet/faraday/ftgmac100.c | 37 ++++++++++++++----------
>  1 file changed, 21 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
> index fddfd1dd5070..0c820997ef88 100644
> --- a/drivers/net/ethernet/faraday/ftgmac100.c
> +++ b/drivers/net/ethernet/faraday/ftgmac100.c
> @@ -26,6 +26,7 @@
>  #include <linux/of_net.h>
>  #include <net/ip.h>
>  #include <net/ncsi.h>
> +#include <linux/phy_fixed.h>
>  
>  #include "ftgmac100.h"
>  
> @@ -50,6 +51,15 @@
>  #define FTGMAC_100MHZ		100000000
>  #define FTGMAC_25MHZ		25000000
>  
> +/* For NC-SI to register a fixed-link phy device */
> +struct fixed_phy_status ncsi_phy_status = {
> +	.link = 1,
> +	.speed = SPEED_100,
> +	.duplex = DUPLEX_FULL,
> +	.pause = 0,
> +	.asym_pause = 0
> +};

nit: This structure is only used in this file, so it should be static

> +
>  struct ftgmac100 {
>  	/* Registers */
>  	struct resource *res;

-- 
pw-bot: cr

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

end of thread, other threads:[~2024-08-02 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02  8:33 [PATCH] net: ftgmac100: Get link speed and duplex for NC-SI Jacky Chou
2024-08-02 15:48 ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).