Skip to contentSkip to conversation

net: npcm: Support for fixed PHYs

PATCH In review William A. Kennington III 3 participants 3 messages Mar 27, 2021 – Mar 31, 2021 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: npcm: Support for fixed PHYs

Most of our machines don't have PHYs between the NIC and the BMC over their NC-SI port. We don't want to use the kernel NC-SI machinery, but we do want phyless support.

---
 drivers/net/ethernet/nuvoton/npcm7xx_emc.c | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/ethernet/nuvoton/npcm7xx_emc.c +30 -1
index f07449e2f68d..1dc871a72180 100644
@@ -26,6 +26,7 @@
 #include <linux/of.h>
 #include <linux/of_net.h>
 #include <linux/of_device.h>
+#include <linux/of_mdio.h>
 #include <linux/dma-mapping.h>
 
 #include <linux/regmap.h>
@@ -242,6 +243,7 @@ struct  npcm7xx_ether {
 	struct net_device *ndev;
 	struct resource *res;
 	unsigned int msg_enable;
+	struct device_node *phy_dn;
 	struct mii_bus *mii_bus;
 	struct phy_device *phy_dev;
 	struct napi_struct napi;
@@ -1774,6 +1776,17 @@ static int npcm7xx_mii_setup(struct net_device *dev)
 
 	pdev = ether->pdev;
 
+	if (ether->phy_dn) {
+		ether->phy_dev = of_phy_connect(dev, ether->phy_dn,
+					&adjust_link, 0, 0);
+		if (!ether->phy_dn) {
+			dev_err(&dev->dev, "could not connect to phy %pOF\n",
+				ether->phy_dn);
+			return -ENODEV;
+		}
+		return 0;
+	}
+
 	ether->mii_bus = mdiobus_alloc();
 	if (!ether->mii_bus) {
 		err = -ENOMEM;
@@ -2011,6 +2024,15 @@ static int npcm7xx_ether_probe(struct platform_device *pdev)
 		}
 	} else {
 		ether->use_ncsi = false;
+
+		ether->phy_dn = of_parse_phandle(np, "phy-handle", 0);
+		if (!ether->phy_dn && of_phy_is_fixed_link(np)) {
+			error = of_phy_register_fixed_link(np);
+			if (error < 0)
+				goto failed_free_napi;
+			ether->phy_dn = of_node_get(np);
+		}
+
 	error = npcm7xx_mii_setup(dev);
 	if (error < 0) {
 		dev_err(&pdev->dev, "npcm7xx_mii_setup err\n");
@@ -2032,6 +2054,9 @@ static int npcm7xx_ether_probe(struct platform_device *pdev)
 	return 0;
 
 failed_free_napi:
+	of_node_put(ether->phy_dn);
+	if (of_phy_is_fixed_link(np))
+		of_phy_deregister_fixed_link(np);
 	netif_napi_del(&ether->napi);
 	platform_set_drvdata(pdev, NULL);
 failed_free_io:
@@ -2048,13 +2073,17 @@ static int npcm7xx_ether_remove(struct platform_device *pdev)
 {
 	struct net_device *dev = platform_get_drvdata(pdev);
 	struct npcm7xx_ether *ether = netdev_priv(dev);
+	struct device_node *np = pdev->dev.of_node;
 
 #ifdef CONFIG_DEBUG_FS
 	debugfs_remove_recursive(ether->dbgfs_dir);
 #endif
-
 	unregister_netdev(dev);
 
+	of_node_put(ether->phy_dn);
+	if (of_phy_is_fixed_link(np))
+		of_phy_deregister_fixed_link(np);
+
 	free_irq(ether->txirq, dev);
 	free_irq(ether->rxirq, dev);
 
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · William A. Kennington III

Most of our machines don't have PHYs between the NIC and the BMC over their NC-SI port. We don't want to use the kernel NC-SI machinery, but we do want phyless support.

This looks fine to me. Tomer, Avi, can I please get a review from someone at Nuvoton?

It would be great to see this driver submitted upstream too!

Quoted 90 lines
---
 drivers/net/ethernet/nuvoton/npcm7xx_emc.c | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/ethernet/nuvoton/npcm7xx_emc.c +30 -2
index f07449e2f68d..1dc871a72180 100644
@@ -26,6 +26,7 @@
 #include <linux/of.h>
 #include <linux/of_net.h>
 #include <linux/of_device.h>
+#include <linux/of_mdio.h>
 #include <linux/dma-mapping.h>
 
 #include <linux/regmap.h>
@@ -242,6 +243,7 @@ struct  npcm7xx_ether {
        struct net_device *ndev;
        struct resource *res;
        unsigned int msg_enable;
+       struct device_node *phy_dn;
        struct mii_bus *mii_bus;
        struct phy_device *phy_dev;
        struct napi_struct napi;
@@ -1774,6 +1776,17 @@ static int npcm7xx_mii_setup(struct net_device *dev)
 
        pdev = ether->pdev;
 
+       if (ether->phy_dn) {
+               ether->phy_dev = of_phy_connect(dev, ether->phy_dn,
+                                       &adjust_link, 0, 0);
+               if (!ether->phy_dn) {
+                       dev_err(&dev->dev, "could not connect to phy %pOF\n",
+                               ether->phy_dn);
+                       return -ENODEV;
+               }
+               return 0;
+       }
+
        ether->mii_bus = mdiobus_alloc();
        if (!ether->mii_bus) {
                err = -ENOMEM;
@@ -2011,6 +2024,15 @@ static int npcm7xx_ether_probe(struct platform_device *pdev)
                }
        } else {
                ether->use_ncsi = false;
+
+               ether->phy_dn = of_parse_phandle(np, "phy-handle", 0);
+               if (!ether->phy_dn && of_phy_is_fixed_link(np)) {
+                       error = of_phy_register_fixed_link(np);
+                       if (error < 0)
+                               goto failed_free_napi;
+                       ether->phy_dn = of_node_get(np);
+               }
+
        error = npcm7xx_mii_setup(dev);
        if (error < 0) {
                dev_err(&pdev->dev, "npcm7xx_mii_setup err\n");
@@ -2032,6 +2054,9 @@ static int npcm7xx_ether_probe(struct platform_device *pdev)
        return 0;
 
 failed_free_napi:
+       of_node_put(ether->phy_dn);
+       if (of_phy_is_fixed_link(np))
+               of_phy_deregister_fixed_link(np);
        netif_napi_del(&ether->napi);
        platform_set_drvdata(pdev, NULL);
 failed_free_io:
@@ -2048,13 +2073,17 @@ static int npcm7xx_ether_remove(struct platform_device *pdev)
 {
        struct net_device *dev = platform_get_drvdata(pdev);
        struct npcm7xx_ether *ether = netdev_priv(dev);
+       struct device_node *np = pdev->dev.of_node;
 
 #ifdef CONFIG_DEBUG_FS
        debugfs_remove_recursive(ether->dbgfs_dir);
 #endif
-
        unregister_netdev(dev);
 
+       of_node_put(ether->phy_dn);
+       if (of_phy_is_fixed_link(np))
+               of_phy_deregister_fixed_link(np);
+
        free_irq(ether->txirq, dev);
        free_irq(ether->rxirq, dev);
 
--

2.31.0.291.g576ba9dcdaf-goog

Reviewed-by
#2 lore raw

Looks fine to me,

cheers,

Tomer

Quoted 115 lines · Joel Stanley
Quoted 6 lines · William A. Kennington III

Most of our machines don't have PHYs between the NIC and the BMC over their NC-SI port. We don't want to use the kernel NC-SI machinery, but we do want phyless support.

This looks fine to me. Tomer, Avi, can I please get a review from someone at Nuvoton?

It would be great to see this driver submitted upstream too!

---

Review

Quoted 4 lines
 drivers/net/ethernet/nuvoton/npcm7xx_emc.c | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/nuvoton/npcm7xx_emc.c

drivers/net/ethernet/nuvoton/npcm7xx_emc.c static int npcm7xx_mii_setup(struct net_device

Quoted 20 lines

index f07449e2f68d..1dc871a72180 100644

drivers/net/ethernet/nuvoton/npcm7xx_emc.c +2 -0
@@ -26,6 +26,7 @@
 #include <linux/of.h>
 #include <linux/of_net.h>
 #include <linux/of_device.h>
+#include <linux/of_mdio.h>
 #include <linux/dma-mapping.h>
 
 #include <linux/regmap.h>
@@ -242,6 +243,7 @@ struct  npcm7xx_ether {
        struct net_device *ndev;
        struct resource *res;
        unsigned int msg_enable;
+       struct device_node *phy_dn;
        struct mii_bus *mii_bus;
        struct phy_device *phy_dev;
        struct napi_struct napi;
@@ -1774,6 +1776,17 @@ static int npcm7xx_mii_setup(struct net_device

*dev)

drivers/net/ethernet/nuvoton/npcm7xx_emc.c static int npcm7xx_mii_setup(struct net_device *dev)

Quoted 8 lines
drivers/net/ethernet/nuvoton/npcm7xx_emc.c +5 -0
        pdev = ether->pdev;
 
+       if (ether->phy_dn) {
+               ether->phy_dev = of_phy_connect(dev, ether->phy_dn,
+                                       &adjust_link, 0, 0);
+               if (!ether->phy_dn) {
+                       dev_err(&dev->dev, "could not connect to phy

%pOF\n",

drivers/net/ethernet/nuvoton/npcm7xx_emc.c static int npcm7xx_ether_probe(struct

Quoted 10 lines
drivers/net/ethernet/nuvoton/npcm7xx_emc.c +6 -0
+                               ether->phy_dn);
+                       return -ENODEV;
+               }
+               return 0;
+       }
+
        ether->mii_bus = mdiobus_alloc();
        if (!ether->mii_bus) {
                err = -ENOMEM;
@@ -2011,6 +2024,15 @@ static int npcm7xx_ether_probe(struct

platform_device *pdev)

drivers/net/ethernet/nuvoton/npcm7xx_emc.c static int npcm7xx_ether_probe(struct

Quoted 16 lines
drivers/net/ethernet/nuvoton/npcm7xx_emc.c +9 -0
                }
        } else {
                ether->use_ncsi = false;
+
+               ether->phy_dn = of_parse_phandle(np, "phy-handle", 0);
+               if (!ether->phy_dn && of_phy_is_fixed_link(np)) {
+                       error = of_phy_register_fixed_link(np);
+                       if (error < 0)
+                               goto failed_free_napi;
+                       ether->phy_dn = of_node_get(np);
+               }
+
        error = npcm7xx_mii_setup(dev);
        if (error < 0) {
                dev_err(&pdev->dev, "npcm7xx_mii_setup err\n");
@@ -2032,6 +2054,9 @@ static int npcm7xx_ether_probe(struct

platform_device *pdev)

drivers/net/ethernet/nuvoton/npcm7xx_emc.c static int npcm7xx_ether_remove(struct

Quoted 10 lines
drivers/net/ethernet/nuvoton/npcm7xx_emc.c +3 -0
        return 0;
 
 failed_free_napi:
+       of_node_put(ether->phy_dn);
+       if (of_phy_is_fixed_link(np))
+               of_phy_deregister_fixed_link(np);
        netif_napi_del(&ether->napi);
        platform_set_drvdata(pdev, NULL);
 failed_free_io:
@@ -2048,13 +2073,17 @@ static int npcm7xx_ether_remove(struct

platform_device *pdev)

Quoted 21 lines
drivers/net/ethernet/nuvoton/npcm7xx_emc.c +5 -2
 {
        struct net_device *dev = platform_get_drvdata(pdev);
        struct npcm7xx_ether *ether = netdev_priv(dev);
+       struct device_node *np = pdev->dev.of_node;
 
 #ifdef CONFIG_DEBUG_FS
        debugfs_remove_recursive(ether->dbgfs_dir);
 #endif
-
        unregister_netdev(dev);
 
+       of_node_put(ether->phy_dn);
+       if (of_phy_is_fixed_link(np))
+               of_phy_deregister_fixed_link(np);
+
        free_irq(ether->txirq, dev);
        free_irq(ether->rxirq, dev);
 
--

2.31.0.291.g576ba9dcdaf-goog