Linux-ACPI Archive on lore.kernel.org
 help / color / Atom feed
* [net-next PATCH v6 0/6]  ACPI support for dpaa2 MAC driver.
@ 2020-07-11  6:55 Calvin Johnson
  2020-07-11  6:55 ` [net-next PATCH v6 1/6] Documentation: ACPI: DSD: Document MDIO PHY Calvin Johnson
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Calvin Johnson @ 2020-07-11  6:55 UTC (permalink / raw)
  To: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Florian Fainelli, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi, Calvin Johnson

 This patch series provides ACPI support for dpaa2 MAC driver.
 This also introduces ACPI mechanism to get PHYs registered on a
 MDIO bus and provide them to be connected to MAC.

 This patchset is dependent on the review patches available on:
https://git.kernel.org/pub/scm/linux/kernel/git/lpieralisi/linux.git/log/?h=for-review/acpi-iort-id-rework

 Device Tree can be tested with the below change which is also available in
the above referenced review patches:

--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -931,6 +931,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
        if (error < 0)
                goto error_cleanup_mc_io;

+       mc_bus_dev->dev.fwnode = pdev->dev.fwnode;
        mc->root_mc_bus_dev = mc_bus_dev;
        return 0;


Changes in v6:
- change device_mdiobus_register() parameter position
- improve documentation
- change device_mdiobus_register() parameter position
- clean up phylink_fwnode_phy_connect()

Changes in v5:
- add description
- clean up if else
- rename phy_find_by_fwnode() to phy_find_by_mdio_handle()
- add docment for phy_find_by_mdio_handle()
- error out DT in phy_find_by_mdio_handle()
- clean up err return
- return -EINVAL for invalid fwnode

Changes in v4:
- release fwnode_mdio after use
- return ERR_PTR instead of NULL
- introduce device_mdiobus_register()

Changes in v3:
- cleanup based on v2 comments
- Added description for more properties
- Added MDIO node DSDT entry
- introduce fwnode_mdio_find_bus()
- renamed and improved phy_find_by_fwnode()
- cleanup based on v2 comments
- move code into phylink_fwnode_phy_connect()

Changes in v2:
- clean up dpaa2_mac_get_node()
- introduce find_phy_device()
- use acpi_find_child_device()

Calvin Johnson (6):
  Documentation: ACPI: DSD: Document MDIO PHY
  net: phy: introduce device_mdiobus_register()
  net/fsl: use device_mdiobus_register()
  net: phy: introduce phy_find_by_mdio_handle()
  phylink: introduce phylink_fwnode_phy_connect()
  net: dpaa2-mac: Add ACPI support for DPAA2 MAC driver

 Documentation/firmware-guide/acpi/dsd/phy.rst | 90 +++++++++++++++++++
 .../net/ethernet/freescale/dpaa2/dpaa2-mac.c  | 70 ++++++++-------
 drivers/net/ethernet/freescale/xgmac_mdio.c   |  3 +-
 drivers/net/phy/mdio_bus.c                    | 51 +++++++++++
 drivers/net/phy/phy_device.c                  | 40 +++++++++
 drivers/net/phy/phylink.c                     | 31 +++++++
 include/linux/mdio.h                          |  1 +
 include/linux/phy.h                           |  2 +
 include/linux/phylink.h                       |  3 +
 9 files changed, 259 insertions(+), 32 deletions(-)
 create mode 100644 Documentation/firmware-guide/acpi/dsd/phy.rst

-- 
2.17.1


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

* [net-next PATCH v6 1/6] Documentation: ACPI: DSD: Document MDIO PHY
  2020-07-11  6:55 [net-next PATCH v6 0/6] ACPI support for dpaa2 MAC driver Calvin Johnson
@ 2020-07-11  6:55 ` Calvin Johnson
  2020-07-11  6:55 ` [net-next PATCH v6 2/6] net: phy: introduce device_mdiobus_register() Calvin Johnson
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Calvin Johnson @ 2020-07-11  6:55 UTC (permalink / raw)
  To: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Florian Fainelli, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi, Calvin Johnson

Introduce ACPI mechanism to get PHYs registered on a MDIO bus and
provide them to be connected to MAC.

An ACPI node property "mdio-handle" is introduced to reference the
MDIO bus on which PHYs are registered with autoprobing method used
by mdiobus_register().

Describe properties "phy-channel" and "phy-mode"

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3:
- cleanup based on v2 comments
- Added description for more properties
- Added MDIO node DSDT entry

Changes in v2: None

 Documentation/firmware-guide/acpi/dsd/phy.rst | 90 +++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100644 Documentation/firmware-guide/acpi/dsd/phy.rst

diff --git a/Documentation/firmware-guide/acpi/dsd/phy.rst b/Documentation/firmware-guide/acpi/dsd/phy.rst
new file mode 100644
index 000000000000..0132fee10b45
--- /dev/null
+++ b/Documentation/firmware-guide/acpi/dsd/phy.rst
@@ -0,0 +1,90 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+=========================
+MDIO bus and PHYs in ACPI
+=========================
+
+The PHYs on an mdiobus are probed and registered using mdiobus_register().
+Later, for connecting these PHYs to MAC, the PHYs registered on the
+mdiobus have to be referenced.
+
+mdio-handle
+-----------
+For each MAC node, a property "mdio-handle" is used to reference the
+MDIO bus on which the PHYs are registered. On getting hold of the MDIO
+bus, use find_phy_device() to get the PHY connected to the MAC.
+
+phy-channel
+-----------
+Property "phy-channel" defines the address of the PHY on the mdiobus.
+
+phy-mode
+--------
+Property "phy-mode" defines the type of PHY interface.
+
+An example of this is shown below::
+
+DSDT entry for MAC where MDIO node is referenced
+------------------------------------------------
+	Scope(\_SB.MCE0.PR17) // 1G
+	{
+	  Name (_DSD, Package () {
+	     ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+		 Package () {
+		     Package () {"phy-channel", 1},
+		     Package () {"phy-mode", "rgmii-id"},
+		     Package () {"mdio-handle", Package (){\_SB.MDI0}}
+	      }
+	   })
+	}
+
+	Scope(\_SB.MCE0.PR18) // 1G
+	{
+	  Name (_DSD, Package () {
+	    ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+		Package () {
+		    Package () {"phy-channel", 2},
+		    Package () {"phy-mode", "rgmii-id"},
+		    Package () {"mdio-handle", Package (){\_SB.MDI0}}
+	    }
+	  })
+	}
+
+DSDT entry for MDIO node
+------------------------
+a) Silicon Component
+--------------------
+	Scope(_SB)
+	{
+	  Device(MDI0) {
+	    Name(_HID, "NXP0006")
+	    Name(_CCA, 1)
+	    Name(_UID, 0)
+	    Name(_CRS, ResourceTemplate() {
+	      Memory32Fixed(ReadWrite, MDI0_BASE, MDI_LEN)
+	      Interrupt(ResourceConsumer, Level, ActiveHigh, Shared)
+	       {
+		 MDI0_IT
+	       }
+	    }) // end of _CRS for MDI0
+	    Name (_DSD, Package () {
+	      ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
+	      Package () {
+		 Package () {"little-endian", 1},
+	      }
+	    })
+	  } // end of MDI0
+	}
+
+b) Platform Component
+---------------------
+	Scope(\_SB.MDI0)
+	{
+	  Device(PHY1) {
+	    Name (_ADR, 0x1)
+	  } // end of PHY1
+
+	  Device(PHY2) {
+	    Name (_ADR, 0x2)
+	  } // end of PHY2
+	}
-- 
2.17.1


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

* [net-next PATCH v6 2/6] net: phy: introduce device_mdiobus_register()
  2020-07-11  6:55 [net-next PATCH v6 0/6] ACPI support for dpaa2 MAC driver Calvin Johnson
  2020-07-11  6:55 ` [net-next PATCH v6 1/6] Documentation: ACPI: DSD: Document MDIO PHY Calvin Johnson
@ 2020-07-11  6:55 ` Calvin Johnson
  2020-07-11 21:36   ` Florian Fainelli
  2020-07-11  6:55 ` [net-next PATCH v6 3/6] net/fsl: use device_mdiobus_register() Calvin Johnson
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Calvin Johnson @ 2020-07-11  6:55 UTC (permalink / raw)
  To: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Florian Fainelli, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi, Calvin Johnson

Introduce device_mdiobus_register() to register mdiobus
in cases of either DT or ACPI.

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>

---

Changes in v6:
- change device_mdiobus_register() parameter position
- improve documentation

Changes in v5:
- add description
- clean up if else

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/net/phy/mdio_bus.c | 26 ++++++++++++++++++++++++++
 include/linux/mdio.h       |  1 +
 2 files changed, 27 insertions(+)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 46b33701ad4b..8610f938f81f 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -501,6 +501,32 @@ static int mdiobus_create_device(struct mii_bus *bus,
 	return ret;
 }
 
+/**
+ * device_mdiobus_register - register mdiobus for either DT or ACPI
+ * @bus: target mii_bus
+ * @dev: given MDIO device
+ *
+ * Description: Given an MDIO device and target mii bus, this function
+ * calls of_mdiobus_register() for DT node and mdiobus_register() in
+ * case of ACPI.
+ *
+ * Returns 0 on success or negative error code on failure.
+ */
+int device_mdiobus_register(struct device *dev,
+			    struct mii_bus *bus)
+{
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+
+	if (is_of_node(fwnode))
+		return of_mdiobus_register(bus, to_of_node(fwnode));
+	if (fwnode) {
+		bus->dev.fwnode = fwnode;
+		return mdiobus_register(bus);
+	}
+	return -ENODEV;
+}
+EXPORT_SYMBOL(device_mdiobus_register);
+
 /**
  * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
  * @bus: target mii_bus
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 898cbf00332a..f454c5435101 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -358,6 +358,7 @@ static inline int mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
 	return mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
 }
 
+int device_mdiobus_register(struct device *dev, struct mii_bus *bus);
 int mdiobus_register_device(struct mdio_device *mdiodev);
 int mdiobus_unregister_device(struct mdio_device *mdiodev);
 bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
-- 
2.17.1


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

* [net-next PATCH v6 3/6] net/fsl: use device_mdiobus_register()
  2020-07-11  6:55 [net-next PATCH v6 0/6] ACPI support for dpaa2 MAC driver Calvin Johnson
  2020-07-11  6:55 ` [net-next PATCH v6 1/6] Documentation: ACPI: DSD: Document MDIO PHY Calvin Johnson
  2020-07-11  6:55 ` [net-next PATCH v6 2/6] net: phy: introduce device_mdiobus_register() Calvin Johnson
@ 2020-07-11  6:55 ` Calvin Johnson
  2020-07-11  6:55 ` [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle() Calvin Johnson
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Calvin Johnson @ 2020-07-11  6:55 UTC (permalink / raw)
  To: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Florian Fainelli, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi, Calvin Johnson

Replace of_mdiobus_register() with device_mdiobus_register()
to take care of both DT and ACPI mdiobus_register.

Remove unused device_node pointer.

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>

---

Changes in v6:
- change device_mdiobus_register() parameter position

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/net/ethernet/freescale/xgmac_mdio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/xgmac_mdio.c b/drivers/net/ethernet/freescale/xgmac_mdio.c
index 98be51d8b08c..704f2b166d0a 100644
--- a/drivers/net/ethernet/freescale/xgmac_mdio.c
+++ b/drivers/net/ethernet/freescale/xgmac_mdio.c
@@ -243,7 +243,6 @@ static int xgmac_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
 
 static int xgmac_mdio_probe(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
 	struct mii_bus *bus;
 	struct resource *res;
 	struct mdio_fsl_priv *priv;
@@ -285,7 +284,7 @@ static int xgmac_mdio_probe(struct platform_device *pdev)
 	priv->has_a011043 = device_property_read_bool(&pdev->dev,
 						      "fsl,erratum-a011043");
 
-	ret = of_mdiobus_register(bus, np);
+	ret = device_mdiobus_register(&pdev->dev, bus);
 	if (ret) {
 		dev_err(&pdev->dev, "cannot register MDIO bus\n");
 		goto err_registration;
-- 
2.17.1


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

* [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle()
  2020-07-11  6:55 [net-next PATCH v6 0/6] ACPI support for dpaa2 MAC driver Calvin Johnson
                   ` (2 preceding siblings ...)
  2020-07-11  6:55 ` [net-next PATCH v6 3/6] net/fsl: use device_mdiobus_register() Calvin Johnson
@ 2020-07-11  6:55 ` Calvin Johnson
  2020-07-11 21:41   ` Florian Fainelli
  2020-07-11  6:55 ` [net-next PATCH v6 5/6] phylink: introduce phylink_fwnode_phy_connect() Calvin Johnson
  2020-07-11  6:56 ` [net-next PATCH v6 6/6] net: dpaa2-mac: Add ACPI support for DPAA2 MAC driver Calvin Johnson
  5 siblings, 1 reply; 13+ messages in thread
From: Calvin Johnson @ 2020-07-11  6:55 UTC (permalink / raw)
  To: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Florian Fainelli, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi, Calvin Johnson

The PHYs on an mdiobus are probed and registered using mdiobus_register().
Later, for connecting these PHYs to MAC, the PHYs registered on the
mdiobus have to be referenced.

For each MAC node, a property "mdio-handle" is used to reference the
MDIO bus on which the PHYs are registered. On getting hold of the MDIO
bus, use phy_find_by_fwnode() to get the PHY connected to the MAC.

Introduce fwnode_mdio_find_bus() to find the mii_bus that corresponds
to given mii_bus fwnode.

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>

---

Changes in v6: None
Changes in v5:
- rename phy_find_by_fwnode() to phy_find_by_mdio_handle()
- add docment for phy_find_by_mdio_handle()
- error out DT in phy_find_by_mdio_handle()
- clean up err return

Changes in v4:
- release fwnode_mdio after use
- return ERR_PTR instead of NULL

Changes in v3:
- introduce fwnode_mdio_find_bus()
- renamed and improved phy_find_by_fwnode()

Changes in v2: None

 drivers/net/phy/mdio_bus.c   | 25 ++++++++++++++++++++++
 drivers/net/phy/phy_device.c | 40 ++++++++++++++++++++++++++++++++++++
 include/linux/phy.h          |  2 ++
 3 files changed, 67 insertions(+)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 8610f938f81f..d9597c5b55ae 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -435,6 +435,31 @@ struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
 }
 EXPORT_SYMBOL(of_mdio_find_bus);
 
+/**
+ * fwnode_mdio_find_bus - Given an mii_bus fwnode, find the mii_bus.
+ * @mdio_bus_fwnode: fwnode of the mii_bus.
+ *
+ * Returns a reference to the mii_bus, or NULL if none found.  The
+ * embedded struct device will have its reference count incremented,
+ * and this must be put once the bus is finished with.
+ *
+ * Because the association of a fwnode and mii_bus is made via
+ * mdiobus_register(), the mii_bus cannot be found before it is
+ * registered with mdiobus_register().
+ *
+ */
+struct mii_bus *fwnode_mdio_find_bus(struct fwnode_handle *mdio_bus_fwnode)
+{
+	struct device *d;
+
+	if (!mdio_bus_fwnode)
+		return NULL;
+
+	d = class_find_device_by_fwnode(&mdio_bus_class, mdio_bus_fwnode);
+	return d ? to_mii_bus(d) : NULL;
+}
+EXPORT_SYMBOL(fwnode_mdio_find_bus);
+
 /* Walk the list of subnodes of a mdio bus and look for a node that
  * matches the mdio device's address with its 'reg' property. If
  * found, set the of_node pointer for the mdio device. This allows
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 7cda95330aea..00b2ade9714f 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -23,8 +23,10 @@
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
+#include <linux/of.h>
 #include <linux/phy.h>
 #include <linux/phy_led_triggers.h>
+#include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/sfp.h>
 #include <linux/skbuff.h>
@@ -964,6 +966,44 @@ struct phy_device *phy_find_first(struct mii_bus *bus)
 }
 EXPORT_SYMBOL(phy_find_first);
 
+/**
+ * phy_find_by_mdio_handle - get phy device from mdio-handle and phy-channel
+ * @fwnode: a pointer to a &struct fwnode_handle  to get mdio-handle and
+ * phy-channel
+ *
+ * Find fwnode_mdio using mdio-handle reference. Using fwnode_mdio get the
+ * mdio bus. Property phy-channel provides the phy address on the mdio bus.
+ * Pass mdio bus and phy address to mdiobus_get_phy() and get corresponding
+ * phy_device. This method is used for ACPI and not for DT.
+ *
+ * Returns pointer to the phy device on success, else ERR_PTR.
+ */
+struct phy_device *phy_find_by_mdio_handle(struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *fwnode_mdio;
+	struct mii_bus *mdio;
+	int addr;
+	int err;
+
+	if (is_of_node(fwnode))
+		return ERR_PTR(-EINVAL);
+
+	fwnode_mdio = fwnode_find_reference(fwnode, "mdio-handle", 0);
+	mdio = fwnode_mdio_find_bus(fwnode_mdio);
+	fwnode_handle_put(fwnode_mdio);
+	if (!mdio)
+		return ERR_PTR(-ENODEV);
+
+	err = fwnode_property_read_u32(fwnode, "phy-channel", &addr);
+	if (err)
+		return ERR_PTR(err);
+	if (addr < 0 || addr >= PHY_MAX_ADDR)
+		return ERR_PTR(-EINVAL);
+
+	return mdiobus_get_phy(mdio, addr);
+}
+EXPORT_SYMBOL(phy_find_by_mdio_handle);
+
 static void phy_link_change(struct phy_device *phydev, bool up)
 {
 	struct net_device *netdev = phydev->attached_dev;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 0403eb799913..fd383a22eb61 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -334,6 +334,7 @@ static inline struct mii_bus *devm_mdiobus_alloc(struct device *dev)
 }
 
 struct mii_bus *mdio_find_bus(const char *mdio_name);
+struct mii_bus *fwnode_mdio_find_bus(struct fwnode_handle *mdio_bus_fwnode);
 struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr);
 
 #define PHY_INTERRUPT_DISABLED	false
@@ -1245,6 +1246,7 @@ int phy_sfp_probe(struct phy_device *phydev,
 struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
 			      phy_interface_t interface);
 struct phy_device *phy_find_first(struct mii_bus *bus);
+struct phy_device *phy_find_by_mdio_handle(struct fwnode_handle *fwnode);
 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 		      u32 flags, phy_interface_t interface);
 int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
-- 
2.17.1


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

* [net-next PATCH v6 5/6] phylink: introduce phylink_fwnode_phy_connect()
  2020-07-11  6:55 [net-next PATCH v6 0/6] ACPI support for dpaa2 MAC driver Calvin Johnson
                   ` (3 preceding siblings ...)
  2020-07-11  6:55 ` [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle() Calvin Johnson
@ 2020-07-11  6:55 ` Calvin Johnson
  2020-07-11 21:37   ` Florian Fainelli
  2020-07-11  6:56 ` [net-next PATCH v6 6/6] net: dpaa2-mac: Add ACPI support for DPAA2 MAC driver Calvin Johnson
  5 siblings, 1 reply; 13+ messages in thread
From: Calvin Johnson @ 2020-07-11  6:55 UTC (permalink / raw)
  To: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Florian Fainelli, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi, Calvin Johnson

Define phylink_fwnode_phy_connect() to connect phy specified by
a fwnode to a phylink instance.

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>

---

Changes in v6:
- clean up phylink_fwnode_phy_connect()

Changes in v5:
- return -EINVAL for invalid fwnode

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/net/phy/phylink.c | 31 +++++++++++++++++++++++++++++++
 include/linux/phylink.h   |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index dae6c8b51d7f..c59a0b8ff349 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -5,6 +5,7 @@
  *
  * Copyright (C) 2015 Russell King
  */
+#include <linux/acpi.h>
 #include <linux/ethtool.h>
 #include <linux/export.h>
 #include <linux/gpio/consumer.h>
@@ -1017,6 +1018,36 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn,
 }
 EXPORT_SYMBOL_GPL(phylink_of_phy_connect);
 
+/**
+ * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode.
+ * @pl: a pointer to a &struct phylink returned from phylink_create()
+ * @fwnode: a pointer to a &struct fwnode_handle.
+ * @flags: PHY-specific flags to communicate to the PHY device driver
+ *
+ * Connect the phy specified @fwnode to the phylink instance specified
+ * by @pl. Actions specified in phylink_connect_phy() will be
+ * performed.
+ *
+ * Returns 0 on success or a negative errno.
+ */
+int phylink_fwnode_phy_connect(struct phylink *pl,
+			       struct fwnode_handle *fwnode,
+			       u32 flags)
+{
+	struct phy_device *phy_dev;
+
+	if (is_of_node(fwnode))
+		return phylink_of_phy_connect(pl, to_of_node(fwnode), flags);
+	if (is_acpi_device_node(fwnode)) {
+		phy_dev = phy_find_by_mdio_handle(fwnode);
+		if (!phy_dev)
+			return -ENODEV;
+		return phylink_connect_phy(pl, phy_dev);
+	}
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(phylink_fwnode_phy_connect);
+
 /**
  * phylink_disconnect_phy() - disconnect any PHY attached to the phylink
  *   instance.
diff --git a/include/linux/phylink.h b/include/linux/phylink.h
index b32b8b45421b..b27eed5e49a9 100644
--- a/include/linux/phylink.h
+++ b/include/linux/phylink.h
@@ -368,6 +368,9 @@ void phylink_destroy(struct phylink *);
 
 int phylink_connect_phy(struct phylink *, struct phy_device *);
 int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags);
+int phylink_fwnode_phy_connect(struct phylink *pl,
+			       struct fwnode_handle *fwnode,
+			       u32 flags);
 void phylink_disconnect_phy(struct phylink *);
 
 void phylink_mac_change(struct phylink *, bool up);
-- 
2.17.1


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

* [net-next PATCH v6 6/6] net: dpaa2-mac: Add ACPI support for DPAA2 MAC driver
  2020-07-11  6:55 [net-next PATCH v6 0/6] ACPI support for dpaa2 MAC driver Calvin Johnson
                   ` (4 preceding siblings ...)
  2020-07-11  6:55 ` [net-next PATCH v6 5/6] phylink: introduce phylink_fwnode_phy_connect() Calvin Johnson
@ 2020-07-11  6:56 ` Calvin Johnson
  5 siblings, 0 replies; 13+ messages in thread
From: Calvin Johnson @ 2020-07-11  6:56 UTC (permalink / raw)
  To: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Florian Fainelli, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi, Calvin Johnson

Modify dpaa2_mac_connect() to support ACPI along with DT.
Modify dpaa2_mac_get_node() to get the dpmac fwnode from either
DT or ACPI.
Replace of_get_phy_mode with fwnode_get_phy_mode to get
phy-mode for a dpmac_node.
Define and use helper function find_phy_device() to find phy_dev
that is later connected to mac->phylink.

Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>

---

Changes in v6: None
Changes in v5: None
Changes in v4:
- introduce device_mdiobus_register()

Changes in v3:
- cleanup based on v2 comments
- move code into phylink_fwnode_phy_connect()

Changes in v2:
- clean up dpaa2_mac_get_node()
- introduce find_phy_device()
- use acpi_find_child_device()

 .../net/ethernet/freescale/dpaa2/dpaa2-mac.c  | 70 +++++++++++--------
 1 file changed, 40 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
index 3ee236c5fc37..297d2dab9e97 100644
--- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
+++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
@@ -1,6 +1,9 @@
 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
 /* Copyright 2019 NXP */
 
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
 #include "dpaa2-eth.h"
 #include "dpaa2-mac.h"
 
@@ -23,38 +26,46 @@ static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
 }
 
 /* Caller must call of_node_put on the returned value */
-static struct device_node *dpaa2_mac_get_node(u16 dpmac_id)
+static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev,
+						u16 dpmac_id)
 {
-	struct device_node *dpmacs, *dpmac = NULL;
-	u32 id;
+	struct fwnode_handle *fsl_mc_fwnode = dev_fwnode(dev->parent->parent);
+	struct fwnode_handle *dpmacs, *dpmac = NULL;
+	struct acpi_device *adev;
 	int err;
+	u32 id;
 
-	dpmacs = of_find_node_by_name(NULL, "dpmacs");
-	if (!dpmacs)
-		return NULL;
-
-	while ((dpmac = of_get_next_child(dpmacs, dpmac)) != NULL) {
-		err = of_property_read_u32(dpmac, "reg", &id);
-		if (err)
-			continue;
-		if (id == dpmac_id)
-			break;
+	if (is_of_node(fsl_mc_fwnode)) {
+		dpmacs = fwnode_get_named_child_node(fsl_mc_fwnode, "dpmacs");
+		if (!dpmacs)
+			return NULL;
+
+		while ((dpmac = fwnode_get_next_child_node(dpmacs, dpmac))) {
+			err = fwnode_property_read_u32(dpmac, "reg", &id);
+			if (err)
+				continue;
+			if (id == dpmac_id)
+				return dpmac;
+		}
+		fwnode_handle_put(dpmacs);
+	} else if (is_acpi_device_node(fsl_mc_fwnode)) {
+		adev = acpi_find_child_device(ACPI_COMPANION(dev->parent),
+					      dpmac_id, false);
+		if (adev)
+			return acpi_fwnode_handle(adev);
 	}
-
-	of_node_put(dpmacs);
-
-	return dpmac;
+	return NULL;
 }
 
-static int dpaa2_mac_get_if_mode(struct device_node *node,
+static int dpaa2_mac_get_if_mode(struct fwnode_handle *dpmac_node,
 				 struct dpmac_attr attr)
 {
 	phy_interface_t if_mode;
 	int err;
 
-	err = of_get_phy_mode(node, &if_mode);
-	if (!err)
-		return if_mode;
+	err = fwnode_get_phy_mode(dpmac_node);
+	if (err > 0)
+		return err;
 
 	err = phy_mode(attr.eth_if, &if_mode);
 	if (!err)
@@ -231,7 +242,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
 {
 	struct fsl_mc_device *dpmac_dev = mac->mc_dev;
 	struct net_device *net_dev = mac->net_dev;
-	struct device_node *dpmac_node;
+	struct fwnode_handle *dpmac_node = NULL;
 	struct phylink *phylink;
 	struct dpmac_attr attr;
 	int err;
@@ -251,7 +262,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
 
 	mac->if_link_type = attr.link_type;
 
-	dpmac_node = dpaa2_mac_get_node(attr.id);
+	dpmac_node = dpaa2_mac_get_node(&dpmac_dev->dev, attr.id);
 	if (!dpmac_node) {
 		netdev_err(net_dev, "No dpmac@%d node found.\n", attr.id);
 		err = -ENODEV;
@@ -269,7 +280,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
 	 * error out if the interface mode requests them and there is no PHY
 	 * to act upon them
 	 */
-	if (of_phy_is_fixed_link(dpmac_node) &&
+	if (of_phy_is_fixed_link(to_of_node(dpmac_node)) &&
 	    (mac->if_mode == PHY_INTERFACE_MODE_RGMII_ID ||
 	     mac->if_mode == PHY_INTERFACE_MODE_RGMII_RXID ||
 	     mac->if_mode == PHY_INTERFACE_MODE_RGMII_TXID)) {
@@ -282,7 +293,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
 	mac->phylink_config.type = PHYLINK_NETDEV;
 
 	phylink = phylink_create(&mac->phylink_config,
-				 of_fwnode_handle(dpmac_node), mac->if_mode,
+				 dpmac_node, mac->if_mode,
 				 &dpaa2_mac_phylink_ops);
 	if (IS_ERR(phylink)) {
 		err = PTR_ERR(phylink);
@@ -290,20 +301,19 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac)
 	}
 	mac->phylink = phylink;
 
-	err = phylink_of_phy_connect(mac->phylink, dpmac_node, 0);
+	err = phylink_fwnode_phy_connect(mac->phylink, dpmac_node, 0);
 	if (err) {
-		netdev_err(net_dev, "phylink_of_phy_connect() = %d\n", err);
+		netdev_err(net_dev, "phylink_fwnode_phy_connect() = %d\n", err);
 		goto err_phylink_destroy;
 	}
 
-	of_node_put(dpmac_node);
-
+	fwnode_handle_put(dpmac_node);
 	return 0;
 
 err_phylink_destroy:
 	phylink_destroy(mac->phylink);
 err_put_node:
-	of_node_put(dpmac_node);
+	fwnode_handle_put(dpmac_node);
 err_close_dpmac:
 	dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle);
 	return err;
-- 
2.17.1


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

* Re: [net-next PATCH v6 2/6] net: phy: introduce device_mdiobus_register()
  2020-07-11  6:55 ` [net-next PATCH v6 2/6] net: phy: introduce device_mdiobus_register() Calvin Johnson
@ 2020-07-11 21:36   ` Florian Fainelli
  2020-07-13  5:56     ` Calvin Johnson
  0 siblings, 1 reply; 13+ messages in thread
From: Florian Fainelli @ 2020-07-11 21:36 UTC (permalink / raw)
  To: Calvin Johnson, Jeremy Linton, Russell King - ARM Linux admin,
	Jon, Cristi Sovaiala, Ioana Ciornei, Andrew Lunn,
	Andy Shevchenko, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi



On 7/10/2020 11:55 PM, Calvin Johnson wrote:
> Introduce device_mdiobus_register() to register mdiobus
> in cases of either DT or ACPI.
> 
> Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
> 
> ---
> 
> Changes in v6:
> - change device_mdiobus_register() parameter position
> - improve documentation
> 
> Changes in v5:
> - add description
> - clean up if else
> 
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
> 
>  drivers/net/phy/mdio_bus.c | 26 ++++++++++++++++++++++++++
>  include/linux/mdio.h       |  1 +
>  2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 46b33701ad4b..8610f938f81f 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -501,6 +501,32 @@ static int mdiobus_create_device(struct mii_bus *bus,
>  	return ret;
>  }
>  
> +/**
> + * device_mdiobus_register - register mdiobus for either DT or ACPI
> + * @bus: target mii_bus
> + * @dev: given MDIO device
> + *
> + * Description: Given an MDIO device and target mii bus, this function
> + * calls of_mdiobus_register() for DT node and mdiobus_register() in
> + * case of ACPI.
> + *
> + * Returns 0 on success or negative error code on failure.
> + */
> +int device_mdiobus_register(struct device *dev,
> +			    struct mii_bus *bus)
> +{
> +	struct fwnode_handle *fwnode = dev_fwnode(dev);
> +
> +	if (is_of_node(fwnode))
> +		return of_mdiobus_register(bus, to_of_node(fwnode));
> +	if (fwnode) {
> +		bus->dev.fwnode = fwnode;
> +		return mdiobus_register(bus);
> +	}
> +	return -ENODEV;
> +}
> +EXPORT_SYMBOL(device_mdiobus_register);
> +
>  /**
>   * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
>   * @bus: target mii_bus
> diff --git a/include/linux/mdio.h b/include/linux/mdio.h
> index 898cbf00332a..f454c5435101 100644
> --- a/include/linux/mdio.h
> +++ b/include/linux/mdio.h
> @@ -358,6 +358,7 @@ static inline int mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
>  	return mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
>  }
>  
> +int device_mdiobus_register(struct device *dev, struct mii_bus *bus);

Humm, this header file does not have any of the mii_bus registration
functions declared, and it typically pertains to mdio_device instances
which are devices *on* the mii_bus. phy.h may be more appropriate here
until we break it up into phy_device proper, mii_bus, etc.

>  int mdiobus_register_device(struct mdio_device *mdiodev);
>  int mdiobus_unregister_device(struct mdio_device *mdiodev);
>  bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
> 

-- 
Florian

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

* Re: [net-next PATCH v6 5/6] phylink: introduce phylink_fwnode_phy_connect()
  2020-07-11  6:55 ` [net-next PATCH v6 5/6] phylink: introduce phylink_fwnode_phy_connect() Calvin Johnson
@ 2020-07-11 21:37   ` Florian Fainelli
  0 siblings, 0 replies; 13+ messages in thread
From: Florian Fainelli @ 2020-07-11 21:37 UTC (permalink / raw)
  To: Calvin Johnson, Jeremy Linton, Russell King - ARM Linux admin,
	Jon, Cristi Sovaiala, Ioana Ciornei, Andrew Lunn,
	Andy Shevchenko, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi



On 7/10/2020 11:55 PM, Calvin Johnson wrote:
> Define phylink_fwnode_phy_connect() to connect phy specified by
> a fwnode to a phylink instance.
> 
> Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
> 
> ---

[snip]

> +int phylink_fwnode_phy_connect(struct phylink *pl,
> +			       struct fwnode_handle *fwnode,
> +			       u32 flags)
> +{
> +	struct phy_device *phy_dev;
> +
> +	if (is_of_node(fwnode))
> +		return phylink_of_phy_connect(pl, to_of_node(fwnode), flags);
> +	if (is_acpi_device_node(fwnode)) {
> +		phy_dev = phy_find_by_mdio_handle(fwnode);
> +		if (!phy_dev)
> +			return -ENODEV;

Please also assign dev_flags to the phy_dev for symmetry with the
phylink_of_phy_connect() function:

		phy_dev->dev_flags |= flags;

With that fixed:

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

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

* Re: [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle()
  2020-07-11  6:55 ` [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle() Calvin Johnson
@ 2020-07-11 21:41   ` Florian Fainelli
  2020-07-13  6:04     ` Calvin Johnson
  0 siblings, 1 reply; 13+ messages in thread
From: Florian Fainelli @ 2020-07-11 21:41 UTC (permalink / raw)
  To: Calvin Johnson, Jeremy Linton, Russell King - ARM Linux admin,
	Jon, Cristi Sovaiala, Ioana Ciornei, Andrew Lunn,
	Andy Shevchenko, Madalin Bucur
  Cc: netdev, linux.cj, linux-acpi



On 7/10/2020 11:55 PM, Calvin Johnson wrote:
> The PHYs on an mdiobus are probed and registered using mdiobus_register().
> Later, for connecting these PHYs to MAC, the PHYs registered on the
> mdiobus have to be referenced.
> 
> For each MAC node, a property "mdio-handle" is used to reference the
> MDIO bus on which the PHYs are registered. On getting hold of the MDIO
> bus, use phy_find_by_fwnode() to get the PHY connected to the MAC.
> 
> Introduce fwnode_mdio_find_bus() to find the mii_bus that corresponds
> to given mii_bus fwnode.
> 
> Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
> 
> ---
> 
> Changes in v6: None
> Changes in v5:
> - rename phy_find_by_fwnode() to phy_find_by_mdio_handle()
> - add docment for phy_find_by_mdio_handle()
> - error out DT in phy_find_by_mdio_handle()
> - clean up err return
> 
> Changes in v4:
> - release fwnode_mdio after use
> - return ERR_PTR instead of NULL
> 
> Changes in v3:
> - introduce fwnode_mdio_find_bus()
> - renamed and improved phy_find_by_fwnode()
> 
> Changes in v2: None
> 
>  drivers/net/phy/mdio_bus.c   | 25 ++++++++++++++++++++++
>  drivers/net/phy/phy_device.c | 40 ++++++++++++++++++++++++++++++++++++
>  include/linux/phy.h          |  2 ++
>  3 files changed, 67 insertions(+)
> 
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 8610f938f81f..d9597c5b55ae 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -435,6 +435,31 @@ struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
>  }
>  EXPORT_SYMBOL(of_mdio_find_bus);
>  
> +/**
> + * fwnode_mdio_find_bus - Given an mii_bus fwnode, find the mii_bus.
> + * @mdio_bus_fwnode: fwnode of the mii_bus.
> + *
> + * Returns a reference to the mii_bus, or NULL if none found.  The
> + * embedded struct device will have its reference count incremented,
> + * and this must be put once the bus is finished with.
> + *
> + * Because the association of a fwnode and mii_bus is made via
> + * mdiobus_register(), the mii_bus cannot be found before it is
> + * registered with mdiobus_register().
> + *
> + */
> +struct mii_bus *fwnode_mdio_find_bus(struct fwnode_handle *mdio_bus_fwnode)
> +{
> +	struct device *d;
> +
> +	if (!mdio_bus_fwnode)
> +		return NULL;
> +
> +	d = class_find_device_by_fwnode(&mdio_bus_class, mdio_bus_fwnode);
> +	return d ? to_mii_bus(d) : NULL;
> +}
> +EXPORT_SYMBOL(fwnode_mdio_find_bus);
> +
>  /* Walk the list of subnodes of a mdio bus and look for a node that
>   * matches the mdio device's address with its 'reg' property. If
>   * found, set the of_node pointer for the mdio device. This allows
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 7cda95330aea..00b2ade9714f 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -23,8 +23,10 @@
>  #include <linux/mm.h>
>  #include <linux/module.h>
>  #include <linux/netdevice.h>
> +#include <linux/of.h>
>  #include <linux/phy.h>
>  #include <linux/phy_led_triggers.h>
> +#include <linux/platform_device.h>
>  #include <linux/property.h>
>  #include <linux/sfp.h>
>  #include <linux/skbuff.h>
> @@ -964,6 +966,44 @@ struct phy_device *phy_find_first(struct mii_bus *bus)
>  }
>  EXPORT_SYMBOL(phy_find_first);
>  
> +/**
> + * phy_find_by_mdio_handle - get phy device from mdio-handle and phy-channel
> + * @fwnode: a pointer to a &struct fwnode_handle  to get mdio-handle and
> + * phy-channel
> + *
> + * Find fwnode_mdio using mdio-handle reference. Using fwnode_mdio get the
> + * mdio bus. Property phy-channel provides the phy address on the mdio bus.
> + * Pass mdio bus and phy address to mdiobus_get_phy() and get corresponding
> + * phy_device. This method is used for ACPI and not for DT.
> + *
> + * Returns pointer to the phy device on success, else ERR_PTR.
> + */
> +struct phy_device *phy_find_by_mdio_handle(struct fwnode_handle *fwnode)
> +{
> +	struct fwnode_handle *fwnode_mdio;
> +	struct mii_bus *mdio;
> +	int addr;
> +	int err;
> +
> +	if (is_of_node(fwnode))
> +		return ERR_PTR(-EINVAL);
> +
> +	fwnode_mdio = fwnode_find_reference(fwnode, "mdio-handle", 0);

I would export the positional argument here to phy_find_by_mdio_handle()
but have no strong opinion if this is not done right now and punted to
when another users comes in.

> +	mdio = fwnode_mdio_find_bus(fwnode_mdio);
> +	fwnode_handle_put(fwnode_mdio);
> +	if (!mdio)
> +		return ERR_PTR(-ENODEV);
> +
> +	err = fwnode_property_read_u32(fwnode, "phy-channel", &addr);
> +	if (err)
> +		return ERR_PTR(err);
> +	if (addr < 0 || addr >= PHY_MAX_ADDR)

Can an u32 ever be < 0?
-- 
Florian

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

* Re: [net-next PATCH v6 2/6] net: phy: introduce device_mdiobus_register()
  2020-07-11 21:36   ` Florian Fainelli
@ 2020-07-13  5:56     ` Calvin Johnson
  0 siblings, 0 replies; 13+ messages in thread
From: Calvin Johnson @ 2020-07-13  5:56 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Madalin Bucur, netdev, linux.cj, linux-acpi

On Sat, Jul 11, 2020 at 02:36:20PM -0700, Florian Fainelli wrote:
> 
> 
> On 7/10/2020 11:55 PM, Calvin Johnson wrote:
> > Introduce device_mdiobus_register() to register mdiobus
> > in cases of either DT or ACPI.
> > 
> > Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
> > 
> > ---
> > 
> > Changes in v6:
> > - change device_mdiobus_register() parameter position
> > - improve documentation
> > 
> > Changes in v5:
> > - add description
> > - clean up if else
> > 
> > Changes in v4: None
> > Changes in v3: None
> > Changes in v2: None
> > 
> >  drivers/net/phy/mdio_bus.c | 26 ++++++++++++++++++++++++++
> >  include/linux/mdio.h       |  1 +
> >  2 files changed, 27 insertions(+)
> > 
> > diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> > index 46b33701ad4b..8610f938f81f 100644
> > --- a/drivers/net/phy/mdio_bus.c
> > +++ b/drivers/net/phy/mdio_bus.c
> > @@ -501,6 +501,32 @@ static int mdiobus_create_device(struct mii_bus *bus,
> >  	return ret;
> >  }
> >  
> > +/**
> > + * device_mdiobus_register - register mdiobus for either DT or ACPI
> > + * @bus: target mii_bus
> > + * @dev: given MDIO device
> > + *
> > + * Description: Given an MDIO device and target mii bus, this function
> > + * calls of_mdiobus_register() for DT node and mdiobus_register() in
> > + * case of ACPI.
> > + *
> > + * Returns 0 on success or negative error code on failure.
> > + */
> > +int device_mdiobus_register(struct device *dev,
> > +			    struct mii_bus *bus)
> > +{
> > +	struct fwnode_handle *fwnode = dev_fwnode(dev);
> > +
> > +	if (is_of_node(fwnode))
> > +		return of_mdiobus_register(bus, to_of_node(fwnode));
> > +	if (fwnode) {
> > +		bus->dev.fwnode = fwnode;
> > +		return mdiobus_register(bus);
> > +	}
> > +	return -ENODEV;
> > +}
> > +EXPORT_SYMBOL(device_mdiobus_register);
> > +
> >  /**
> >   * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
> >   * @bus: target mii_bus
> > diff --git a/include/linux/mdio.h b/include/linux/mdio.h
> > index 898cbf00332a..f454c5435101 100644
> > --- a/include/linux/mdio.h
> > +++ b/include/linux/mdio.h
> > @@ -358,6 +358,7 @@ static inline int mdiobus_c45_read(struct mii_bus *bus, int prtad, int devad,
> >  	return mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum));
> >  }
> >  
> > +int device_mdiobus_register(struct device *dev, struct mii_bus *bus);
> 
> Humm, this header file does not have any of the mii_bus registration
> functions declared, and it typically pertains to mdio_device instances
> which are devices *on* the mii_bus. phy.h may be more appropriate here
> until we break it up into phy_device proper, mii_bus, etc.
> 
> >  int mdiobus_register_device(struct mdio_device *mdiodev);
> >  int mdiobus_unregister_device(struct mdio_device *mdiodev);
> >  bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);

Although some mii_bus registration functions are declared in phy.h, IMO, it
doesn't seem to be the right place. If we look plainly, phy related things
would be expected in phy.h and mdio related in mdio.h. Maybe as you said
we should consider breaking into phy_device proper, mii_bus, etc. We can take it
up later.

Please let me know if you still want device_mdiobus_register() in phy.h.

Thanks
Calvin


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

* Re: [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle()
  2020-07-11 21:41   ` Florian Fainelli
@ 2020-07-13  6:04     ` Calvin Johnson
  2020-07-13 11:04       ` Andy Shevchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Calvin Johnson @ 2020-07-13  6:04 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Jeremy Linton, Russell King - ARM Linux admin, Jon,
	Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Andy Shevchenko,
	Madalin Bucur, netdev, linux.cj, linux-acpi

On Sat, Jul 11, 2020 at 02:41:12PM -0700, Florian Fainelli wrote:
> 
> 
> On 7/10/2020 11:55 PM, Calvin Johnson wrote:
> > The PHYs on an mdiobus are probed and registered using mdiobus_register().
> > Later, for connecting these PHYs to MAC, the PHYs registered on the
> > mdiobus have to be referenced.
> > 
> > For each MAC node, a property "mdio-handle" is used to reference the
> > MDIO bus on which the PHYs are registered. On getting hold of the MDIO
> > bus, use phy_find_by_fwnode() to get the PHY connected to the MAC.
> > 
> > Introduce fwnode_mdio_find_bus() to find the mii_bus that corresponds
> > to given mii_bus fwnode.
> > 
> > Signed-off-by: Calvin Johnson <calvin.johnson@oss.nxp.com>
> > 
> > ---
> > 
> > Changes in v6: None
> > Changes in v5:
> > - rename phy_find_by_fwnode() to phy_find_by_mdio_handle()
> > - add docment for phy_find_by_mdio_handle()
> > - error out DT in phy_find_by_mdio_handle()
> > - clean up err return
> > 
> > Changes in v4:
> > - release fwnode_mdio after use
> > - return ERR_PTR instead of NULL
> > 
> > Changes in v3:
> > - introduce fwnode_mdio_find_bus()
> > - renamed and improved phy_find_by_fwnode()
> > 
> > Changes in v2: None
> > 
> >  drivers/net/phy/mdio_bus.c   | 25 ++++++++++++++++++++++
> >  drivers/net/phy/phy_device.c | 40 ++++++++++++++++++++++++++++++++++++
> >  include/linux/phy.h          |  2 ++
> >  3 files changed, 67 insertions(+)
> > 
> > diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> > index 8610f938f81f..d9597c5b55ae 100644
> > --- a/drivers/net/phy/mdio_bus.c
> > +++ b/drivers/net/phy/mdio_bus.c
> > @@ -435,6 +435,31 @@ struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
> >  }
> >  EXPORT_SYMBOL(of_mdio_find_bus);
> >  
> > +/**
> > + * fwnode_mdio_find_bus - Given an mii_bus fwnode, find the mii_bus.
> > + * @mdio_bus_fwnode: fwnode of the mii_bus.
> > + *
> > + * Returns a reference to the mii_bus, or NULL if none found.  The
> > + * embedded struct device will have its reference count incremented,
> > + * and this must be put once the bus is finished with.
> > + *
> > + * Because the association of a fwnode and mii_bus is made via
> > + * mdiobus_register(), the mii_bus cannot be found before it is
> > + * registered with mdiobus_register().
> > + *
> > + */
> > +struct mii_bus *fwnode_mdio_find_bus(struct fwnode_handle *mdio_bus_fwnode)
> > +{
> > +	struct device *d;
> > +
> > +	if (!mdio_bus_fwnode)
> > +		return NULL;
> > +
> > +	d = class_find_device_by_fwnode(&mdio_bus_class, mdio_bus_fwnode);
> > +	return d ? to_mii_bus(d) : NULL;
> > +}
> > +EXPORT_SYMBOL(fwnode_mdio_find_bus);
> > +
> >  /* Walk the list of subnodes of a mdio bus and look for a node that
> >   * matches the mdio device's address with its 'reg' property. If
> >   * found, set the of_node pointer for the mdio device. This allows
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 7cda95330aea..00b2ade9714f 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -23,8 +23,10 @@
> >  #include <linux/mm.h>
> >  #include <linux/module.h>
> >  #include <linux/netdevice.h>
> > +#include <linux/of.h>
> >  #include <linux/phy.h>
> >  #include <linux/phy_led_triggers.h>
> > +#include <linux/platform_device.h>
> >  #include <linux/property.h>
> >  #include <linux/sfp.h>
> >  #include <linux/skbuff.h>
> > @@ -964,6 +966,44 @@ struct phy_device *phy_find_first(struct mii_bus *bus)
> >  }
> >  EXPORT_SYMBOL(phy_find_first);
> >  
> > +/**
> > + * phy_find_by_mdio_handle - get phy device from mdio-handle and phy-channel
> > + * @fwnode: a pointer to a &struct fwnode_handle  to get mdio-handle and
> > + * phy-channel
> > + *
> > + * Find fwnode_mdio using mdio-handle reference. Using fwnode_mdio get the
> > + * mdio bus. Property phy-channel provides the phy address on the mdio bus.
> > + * Pass mdio bus and phy address to mdiobus_get_phy() and get corresponding
> > + * phy_device. This method is used for ACPI and not for DT.
> > + *
> > + * Returns pointer to the phy device on success, else ERR_PTR.
> > + */
> > +struct phy_device *phy_find_by_mdio_handle(struct fwnode_handle *fwnode)
> > +{
> > +	struct fwnode_handle *fwnode_mdio;
> > +	struct mii_bus *mdio;
> > +	int addr;
> > +	int err;
> > +
> > +	if (is_of_node(fwnode))
> > +		return ERR_PTR(-EINVAL);
> > +
> > +	fwnode_mdio = fwnode_find_reference(fwnode, "mdio-handle", 0);
> 
> I would export the positional argument here to phy_find_by_mdio_handle()
> but have no strong opinion if this is not done right now and punted to
> when another users comes in.

Sorry, I didn't get you. Can you please elaborate?

> 
> > +	mdio = fwnode_mdio_find_bus(fwnode_mdio);
> > +	fwnode_handle_put(fwnode_mdio);
> > +	if (!mdio)
> > +		return ERR_PTR(-ENODEV);
> > +
> > +	err = fwnode_property_read_u32(fwnode, "phy-channel", &addr);
> > +	if (err)
> > +		return ERR_PTR(err);
> > +	if (addr < 0 || addr >= PHY_MAX_ADDR)
> 
> Can an u32 ever be < 0?

Will remove it.

Thanks
Calvin

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

* Re: [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle()
  2020-07-13  6:04     ` Calvin Johnson
@ 2020-07-13 11:04       ` Andy Shevchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2020-07-13 11:04 UTC (permalink / raw)
  To: Calvin Johnson
  Cc: Florian Fainelli, Jeremy Linton, Russell King - ARM Linux admin,
	Jon, Cristi Sovaiala, Ioana Ciornei, Andrew Lunn, Madalin Bucur,
	netdev, linux.cj, ACPI Devel Maling List

On Mon, Jul 13, 2020 at 9:04 AM Calvin Johnson
<calvin.johnson@oss.nxp.com> wrote:
> On Sat, Jul 11, 2020 at 02:41:12PM -0700, Florian Fainelli wrote:
> > On 7/10/2020 11:55 PM, Calvin Johnson wrote:

...

> > > +   err = fwnode_property_read_u32(fwnode, "phy-channel", &addr);
> > > +   if (err)
> > > +           return ERR_PTR(err);
> > > +   if (addr < 0 || addr >= PHY_MAX_ADDR)
> >
> > Can an u32 ever be < 0?
>
> Will remove it.

Since it's harmless and we have a fix to shut the compiler up on this
kind of checks and Linus actually in favour of _seeing_ range checks
explicitly I think no need to drop, but it's up to you.


-- 
With Best Regards,
Andy Shevchenko

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

end of thread, back to index

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-11  6:55 [net-next PATCH v6 0/6] ACPI support for dpaa2 MAC driver Calvin Johnson
2020-07-11  6:55 ` [net-next PATCH v6 1/6] Documentation: ACPI: DSD: Document MDIO PHY Calvin Johnson
2020-07-11  6:55 ` [net-next PATCH v6 2/6] net: phy: introduce device_mdiobus_register() Calvin Johnson
2020-07-11 21:36   ` Florian Fainelli
2020-07-13  5:56     ` Calvin Johnson
2020-07-11  6:55 ` [net-next PATCH v6 3/6] net/fsl: use device_mdiobus_register() Calvin Johnson
2020-07-11  6:55 ` [net-next PATCH v6 4/6] net: phy: introduce phy_find_by_mdio_handle() Calvin Johnson
2020-07-11 21:41   ` Florian Fainelli
2020-07-13  6:04     ` Calvin Johnson
2020-07-13 11:04       ` Andy Shevchenko
2020-07-11  6:55 ` [net-next PATCH v6 5/6] phylink: introduce phylink_fwnode_phy_connect() Calvin Johnson
2020-07-11 21:37   ` Florian Fainelli
2020-07-11  6:56 ` [net-next PATCH v6 6/6] net: dpaa2-mac: Add ACPI support for DPAA2 MAC driver Calvin Johnson

Linux-ACPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \
		linux-acpi@vger.kernel.org
	public-inbox-index linux-acpi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git