[PATCH net-next v3 10/11] net: mdio: add C45-over-C22 fallback to fwnode_mdiobus_register_phy()

Michael Walle posted 11 patches 2 years, 7 months ago
[PATCH net-next v3 10/11] net: mdio: add C45-over-C22 fallback to fwnode_mdiobus_register_phy()
Posted by Michael Walle 2 years, 7 months ago
If trying to register a C45 PHY on an MDIO bus which isn't capable of
C45 (either because the MDIO controller doesn't support it or because
C45 accesses are prohibited due to faulty C22 PHYs) we can fall back to
the new C45-over-C22 access method.

Signed-off-by: Michael Walle <mwalle@kernel.org>
---
Please note, that both with the old and the new code compatible =
"ethernet-phy-idNNNN.NNNN" only works for the C22 case. I'm wondering if
compatible = "ethernet-phy-idNNNN.NNNN", "ethernet-phy-ieee802.3-c45
even makes sense because there might be multiple C45 ids. At least it is
an allowed pattern according to the device tree bindings. But with the
current code, the ethernet-phy-idNNNN.NNNN is ignored in the c45 case.
---
 drivers/net/mdio/fwnode_mdio.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c
index 972c8932c2fe..fed056d82b4e 100644
--- a/drivers/net/mdio/fwnode_mdio.c
+++ b/drivers/net/mdio/fwnode_mdio.c
@@ -115,7 +115,6 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 	struct mii_timestamper *mii_ts = NULL;
 	struct pse_control *psec = NULL;
 	struct phy_device *phy;
-	bool is_c45;
 	u32 phy_id;
 	int rc;
 
@@ -129,13 +128,19 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus,
 		goto clean_pse;
 	}
 
-	is_c45 = fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45");
-	if (is_c45 || fwnode_get_phy_id(child, &phy_id))
-		phy = get_phy_device(bus, addr,
-				     is_c45 ? PHY_ACCESS_C45 : PHY_ACCESS_C22);
-	else
+	if (fwnode_device_is_compatible(child, "ethernet-phy-ieee802.3-c45")) {
+		if (mdiobus_supports_c45(bus))
+			phy = get_phy_device(bus, addr, PHY_ACCESS_C45);
+		else
+			phy = get_phy_device(bus, addr,
+					     PHY_ACCESS_C45_OVER_C22);
+	} else if (fwnode_get_phy_id(child, &phy_id) == 0) {
 		phy = phy_device_create(bus, addr, phy_id, PHY_ACCESS_C22,
 					NULL);
+	} else {
+		phy = get_phy_device(bus, addr, PHY_ACCESS_C22);
+	}
+
 	if (IS_ERR(phy)) {
 		rc = PTR_ERR(phy);
 		goto clean_mii_ts;

-- 
2.39.2
Re: [PATCH net-next v3 10/11] net: mdio: add C45-over-C22 fallback to fwnode_mdiobus_register_phy()
Posted by Andrew Lunn 2 years, 6 months ago
> Please note, that both with the old and the new code compatible =
> "ethernet-phy-idNNNN.NNNN" only works for the C22 case. I'm wondering if
> compatible = "ethernet-phy-idNNNN.NNNN", "ethernet-phy-ieee802.3-c45
> even makes sense because there might be multiple C45 ids. At least it is
> an allowed pattern according to the device tree bindings. But with the
> current code, the ethernet-phy-idNNNN.NNNN is ignored in the c45 case.

I think these two should be orthogonal.

ethernet-phy-idNNNN.NNNN should be used to load the driver. The driver
has a list of IDs it can drive, and we want the module loading
machinery to load a module which can driver this ID.

"ethernet-phy-ieee802.3-c45" should be about how to read the ID
registers, if ethernet-phy-idNNNN.NNNN is not present.

	Andrew
Re: [PATCH net-next v3 10/11] net: mdio: add C45-over-C22 fallback to fwnode_mdiobus_register_phy()
Posted by Michael Walle 2 years, 6 months ago
Am 2023-07-19 02:03, schrieb Andrew Lunn:
>> Please note, that both with the old and the new code compatible =
>> "ethernet-phy-idNNNN.NNNN" only works for the C22 case. I'm wondering 
>> if
>> compatible = "ethernet-phy-idNNNN.NNNN", "ethernet-phy-ieee802.3-c45
>> even makes sense because there might be multiple C45 ids. At least it 
>> is
>> an allowed pattern according to the device tree bindings. But with the
>> current code, the ethernet-phy-idNNNN.NNNN is ignored in the c45 case.
> 
> I think these two should be orthogonal.
> 
> ethernet-phy-idNNNN.NNNN should be used to load the driver. The driver
> has a list of IDs it can drive, and we want the module loading
> machinery to load a module which can driver this ID.

See [1]. It is used to overwrite the PHY ID. Which I think works
in the c22 case.

> "ethernet-phy-ieee802.3-c45" should be about how to read the ID
> registers, if ethernet-phy-idNNNN.NNNN is not present.

And if it's present? See [2].

-michael

[1] 
https://elixir.bootlin.com/linux/v6.4.3/source/Documentation/devicetree/bindings/net/ethernet-phy.yaml#L38
[2] 
https://elixir.bootlin.com/linux/v6.4.3/source/Documentation/devicetree/bindings/net/ethernet-phy.yaml#L50