linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] net: phy: Enable C45 vendor specific MDIO register addr space
@ 2018-04-17  9:02 Vicentiu Galanopulo
  2018-04-17  9:02 ` [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space Vicentiu Galanopulo
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Vicentiu Galanopulo @ 2018-04-17  9:02 UTC (permalink / raw)
  To: andrew, robh, netdev, linux-kernel, mark.rutland, davem, marcel,
	devicetree
  Cc: alexandru.marginean, madalin.bucur, vicentiu.galanopulo

Enabling the discovery on the MDIO bus of PHYs which
have a vendor specific address space for accessing the C45 MDIO registers.

Vicentiu Galanopulo (3):
  net: phy: Add binding for vendor specific C45 MDIO address space
  net: phy: Change the array size to 32 for device_ids
  net: phy: Enable C45 PHYs with vendor specific address space

 Documentation/devicetree/bindings/net/phy.txt |   6 ++
 drivers/net/phy/phy_device.c                  |  49 ++++++++++-
 drivers/of/of_mdio.c                          | 113 +++++++++++++++++++++++++-
 include/linux/phy.h                           |  16 +++-
 4 files changed, 176 insertions(+), 8 deletions(-)

-- 
2.7.4

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

* [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space
  2018-04-17  9:02 [PATCH net-next 0/3] net: phy: Enable C45 vendor specific MDIO register addr space Vicentiu Galanopulo
@ 2018-04-17  9:02 ` Vicentiu Galanopulo
  2018-04-17 12:53   ` Andrew Lunn
  2018-04-17 18:18   ` Florian Fainelli
  2018-04-17  9:02 ` [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids Vicentiu Galanopulo
  2018-04-17  9:02 ` [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space Vicentiu Galanopulo
  2 siblings, 2 replies; 16+ messages in thread
From: Vicentiu Galanopulo @ 2018-04-17  9:02 UTC (permalink / raw)
  To: andrew, robh, netdev, linux-kernel, mark.rutland, davem, marcel,
	devicetree
  Cc: alexandru.marginean, madalin.bucur, vicentiu.galanopulo

The extra property enables the discovery on the MDIO bus
of the PHYs which have a vendor specific address space
for accessing the C45 MDIO registers.

Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
---
 Documentation/devicetree/bindings/net/phy.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/phy.txt b/Documentation/devicetree/bindings/net/phy.txt
index d2169a5..82692e2 100644
--- a/Documentation/devicetree/bindings/net/phy.txt
+++ b/Documentation/devicetree/bindings/net/phy.txt
@@ -61,6 +61,11 @@ Optional Properties:
 - reset-deassert-us: Delay after the reset was deasserted in microseconds.
   If this property is missing the delay will be skipped.
 
+- dev-addr: If set, it indicates the device address of the PHY to be used
+  when accessing the C45 PHY registers over MDIO. It is used for vendor specific
+  register space addresses that do no conform to standard address for the MDIO
+  registers (e.g. MMD30)
+
 Example:
 
 ethernet-phy@0 {
@@ -72,4 +77,5 @@ ethernet-phy@0 {
 	reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
 	reset-assert-us = <1000>;
 	reset-deassert-us = <2000>;
+	dev-addr = <0x1e>;
 };
-- 
2.7.4

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

* [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids
  2018-04-17  9:02 [PATCH net-next 0/3] net: phy: Enable C45 vendor specific MDIO register addr space Vicentiu Galanopulo
  2018-04-17  9:02 ` [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space Vicentiu Galanopulo
@ 2018-04-17  9:02 ` Vicentiu Galanopulo
  2018-04-17 12:54   ` Andrew Lunn
  2018-04-17 18:18   ` Florian Fainelli
  2018-04-17  9:02 ` [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space Vicentiu Galanopulo
  2 siblings, 2 replies; 16+ messages in thread
From: Vicentiu Galanopulo @ 2018-04-17  9:02 UTC (permalink / raw)
  To: andrew, robh, netdev, linux-kernel, mark.rutland, davem, marcel,
	devicetree
  Cc: alexandru.marginean, madalin.bucur, vicentiu.galanopulo

In the context of enabling the discovery of the PHYs
which have the C45 MDIO address space in a non-standard
address:  num_ids in get_phy_c45_ids, has the
value 8 (ARRAY_SIZE(c45_ids->device_ids)), but the
u32 *devs can store 32 devices in the bitfield.

If a device is stored in *devs, in bits 32 to 9
(bit counting in lookup loop starts from 1), it will
not be found.

Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
---
 include/linux/phy.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/phy.h b/include/linux/phy.h
index f0b5870..26aa320 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -360,7 +360,7 @@ enum phy_state {
  */
 struct phy_c45_device_ids {
 	u32 devices_in_package;
-	u32 device_ids[8];
+	u32 device_ids[32];
 };
 
 /* phy_device: An instance of a PHY
-- 
2.7.4

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

* [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space
  2018-04-17  9:02 [PATCH net-next 0/3] net: phy: Enable C45 vendor specific MDIO register addr space Vicentiu Galanopulo
  2018-04-17  9:02 ` [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space Vicentiu Galanopulo
  2018-04-17  9:02 ` [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids Vicentiu Galanopulo
@ 2018-04-17  9:02 ` Vicentiu Galanopulo
  2018-04-17 12:56   ` Andrew Lunn
                     ` (2 more replies)
  2 siblings, 3 replies; 16+ messages in thread
From: Vicentiu Galanopulo @ 2018-04-17  9:02 UTC (permalink / raw)
  To: andrew, robh, netdev, linux-kernel, mark.rutland, davem, marcel,
	devicetree
  Cc: alexandru.marginean, madalin.bucur, vicentiu.galanopulo

A search of the dev-addr property is done in of_mdiobus_register.
If the property is found in the PHY node, of_mdiobus_register_vend_spec_phy()
is called. This is a wrapper function for of_mdiobus_register_phy()
which finds the device in package based on dev-addr, and fills
devices_addrs, which is a new field added to phy_c45_device_ids.
This new field will store the dev-addr property on the same index
where the device in package has been found.

The of_mdiobus_register_phy() now contains an extra parameter,
which is struct phy_c45_device_ids *c45_ids.
If c45_ids is not NULL, get_vend_spec_addr_phy_device() is called
and c45_ids are propagated all the way to get_phy_c45_ids().

Having dev-addr stored in devices_addrs, in get_phy_c45_ids(),
when probing the identifiers, dev-addr can be extracted from
devices_addrs and probed if devices_addrs[current_identifier] is not 0.

Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
---
 drivers/net/phy/phy_device.c |  49 +++++++++++++++++--
 drivers/of/of_mdio.c         | 113 +++++++++++++++++++++++++++++++++++++++++--
 include/linux/phy.h          |  14 ++++++
 3 files changed, 169 insertions(+), 7 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index ac23322..5c79fd8 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -457,7 +457,7 @@ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr,
 static int get_phy_c45_ids(struct mii_bus *bus, int addr, u32 *phy_id,
 			   struct phy_c45_device_ids *c45_ids) {
 	int phy_reg;
-	int i, reg_addr;
+	int i, reg_addr, dev_addr;
 	const int num_ids = ARRAY_SIZE(c45_ids->device_ids);
 	u32 *devs = &c45_ids->devices_in_package;
 
@@ -493,13 +493,23 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, u32 *phy_id,
 		if (!(c45_ids->devices_in_package & (1 << i)))
 			continue;
 
-		reg_addr = MII_ADDR_C45 | i << 16 | MII_PHYSID1;
+		/* if c45_ids->devices_addrs for the current id is not 0,
+		 * then dev-addr was defined in the PHY device tree node,
+		 * and the PHY has been seen as a valid device, and added
+		 * in the package. In this case we can use the
+		 * dev-addr(c45_ids->devices_addrs[i]) to do the MDIO
+		 * reading of the PHY ID.
+		 */
+		dev_addr = !!c45_ids->devices_addrs[i] ?
+					c45_ids->devices_addrs[i] : i;
+
+		reg_addr = MII_ADDR_C45 | dev_addr << 16 | MII_PHYSID1;
 		phy_reg = mdiobus_read(bus, addr, reg_addr);
 		if (phy_reg < 0)
 			return -EIO;
 		c45_ids->device_ids[i] = (phy_reg & 0xffff) << 16;
 
-		reg_addr = MII_ADDR_C45 | i << 16 | MII_PHYSID2;
+		reg_addr = MII_ADDR_C45 | dev_addr << 16 | MII_PHYSID2;
 		phy_reg = mdiobus_read(bus, addr, reg_addr);
 		if (phy_reg < 0)
 			return -EIO;
@@ -551,6 +561,39 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id,
 }
 
 /**
+ * get_vend_spec_addr_phy_device - reads the specified PHY device
+ *				   and returns its @phy_device struct
+ * @bus: the target MII bus
+ * @addr: PHY address on the MII bus
+ * @is_c45: If true the PHY uses the 802.3 clause 45 protocol
+ * @c45_ids: Query the c45_ids to see if a PHY with a vendor specific
+ *           register address space was defined in the PHY device tree
+ *           node by adding the "dev-addr" property to the node.
+ *           Store the c45 ID information about the rest of the PHYs
+ *           found PHYs on the MDIO bus during probing.
+ *
+ * Description: Reads the ID registers of the PHY at @addr on the
+ *   @bus, then allocates and returns the phy_device to represent it.
+ */
+struct phy_device *get_vend_spec_addr_phy_device(struct mii_bus *bus,
+						 int addr, bool is_c45,
+						 struct phy_c45_device_ids *c45_ids)
+{
+	u32 phy_id = 0;
+	int r;
+
+	r = get_phy_id(bus, addr, &phy_id, is_c45, c45_ids);
+	if (r)
+		return ERR_PTR(r);
+
+	/* If the phy_id is mostly Fs, there is no device there */
+	if ((phy_id & 0x1fffffff) == 0x1fffffff)
+		return ERR_PTR(-ENODEV);
+
+	return phy_device_create(bus, addr, phy_id, is_c45, c45_ids);
+}
+
+/**
  * get_phy_device - reads the specified PHY device and returns its @phy_device
  *		    struct
  * @bus: the target MII bus
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 8c0c927..52e8bfb 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -45,7 +45,8 @@ static int of_get_phy_id(struct device_node *device, u32 *phy_id)
 }
 
 static int of_mdiobus_register_phy(struct mii_bus *mdio,
-				    struct device_node *child, u32 addr)
+				   struct device_node *child, u32 addr,
+				   struct phy_c45_device_ids *c45_ids)
 {
 	struct phy_device *phy;
 	bool is_c45;
@@ -58,7 +59,12 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
 	if (!is_c45 && !of_get_phy_id(child, &phy_id))
 		phy = phy_device_create(mdio, addr, phy_id, 0, NULL);
 	else
-		phy = get_phy_device(mdio, addr, is_c45);
+		if (c45_ids)
+			phy = get_vend_spec_addr_phy_device(mdio,
+							    addr, is_c45,
+							    c45_ids);
+		else
+			phy = get_phy_device(mdio, addr, is_c45);
 	if (IS_ERR(phy))
 		return PTR_ERR(phy);
 
@@ -190,6 +196,72 @@ static bool of_mdiobus_child_is_phy(struct device_node *child)
 	return false;
 }
 
+static void of_fill_c45_devices_addrs(u32 dev_addr,
+				      struct phy_c45_device_ids *c45_ids)
+{
+	int i;
+	const int num_ids = ARRAY_SIZE(c45_ids->device_ids);
+
+	/* Search through all Device Identifiers
+	 * and set dev_addr in c45_ids->devices_addrs,
+	 * if the device bit is set in
+	 * c45_ids->devices_in_package
+	 */
+	for (i = 1; i < num_ids; i++) {
+		if (!(c45_ids->devices_in_package & (1 << i)))
+			continue;
+
+		c45_ids->devices_addrs[i] = dev_addr;
+	}
+}
+
+static int of_find_devaddr_in_pkg(struct mii_bus *bus, u32 addr, u32 dev_addr,
+				  struct phy_c45_device_ids *c45_ids)
+{
+	u32 *devs = &c45_ids->devices_in_package;
+	int phy_reg, reg_addr;
+
+	reg_addr = MII_ADDR_C45 | dev_addr << 16 | MDIO_DEVS2;
+	phy_reg = mdiobus_read(bus, addr, reg_addr);
+	if (phy_reg < 0)
+		return -EIO;
+
+	*devs = (phy_reg & 0xffff) << 16;
+
+	reg_addr = MII_ADDR_C45 | dev_addr << 16 | MDIO_DEVS1;
+	phy_reg = mdiobus_read(bus, addr, reg_addr);
+	if (phy_reg < 0)
+		return -EIO;
+
+	*devs |= (phy_reg & 0xffff);
+
+	return 0;
+}
+
+/*
+ * Finds the device in package and populates the c45_ids
+ * if any device is found at dev_addr address. After this
+ * the PHY is registered
+ */
+static int of_mdiobus_register_vend_spec_phy(struct mii_bus *mdio,
+					     struct device_node *child,
+					     u32 addr, u32 dev_addr)
+{
+	struct phy_c45_device_ids c45_ids = {0};
+	int dev_err = 0;
+
+	if (!dev_addr)
+		goto register_phy;
+
+	dev_err = of_find_devaddr_in_pkg(mdio, addr, dev_addr, &c45_ids);
+
+	if (!dev_err)
+		of_fill_c45_devices_addrs(dev_addr, &c45_ids);
+
+register_phy:
+	return of_mdiobus_register_phy(mdio, child, addr, &c45_ids);
+}
+
 /**
  * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
  * @mdio: pointer to mii_bus structure
@@ -202,7 +274,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 {
 	struct device_node *child;
 	bool scanphys = false;
+	bool dev_addr_found = true;
 	int addr, rc;
+	int dev_addr = 0;
+	int ret;
 
 	/* Do not continue if the node is disabled */
 	if (!of_device_is_available(np))
@@ -226,6 +301,14 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 
 	/* Loop over the child nodes and register a phy_device for each phy */
 	for_each_available_child_of_node(np, child) {
+		/* Check if dev-addr is set in the PHY node */
+		ret = of_property_read_u32(child, "dev-addr", &dev_addr);
+
+		if (ret < 0) {
+			/* either not set or invalid */
+			dev_addr_found = false;
+		}
+
 		addr = of_mdio_parse_addr(&mdio->dev, child);
 		if (addr < 0) {
 			scanphys = true;
@@ -233,7 +316,14 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 		}
 
 		if (of_mdiobus_child_is_phy(child))
-			rc = of_mdiobus_register_phy(mdio, child, addr);
+			if (dev_addr_found)
+				rc = of_mdiobus_register_vend_spec_phy(mdio,
+								       child,
+								       addr,
+								       dev_addr);
+			else
+				rc = of_mdiobus_register_phy(mdio, child,
+							     addr, NULL);
 		else
 			rc = of_mdiobus_register_device(mdio, child, addr);
 
@@ -248,8 +338,16 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 	if (!scanphys)
 		return 0;
 
+	/* reset device found variable */
+	dev_addr_found = true;
+
 	/* auto scan for PHYs with empty reg property */
 	for_each_available_child_of_node(np, child) {
+		/* Check if dev-addr is set in the PHY node,
+		 * for PHYs which don't have reg property set
+		 */
+		ret = of_property_read_u32(child, "dev-addr", &dev_addr);
+
 		/* Skip PHYs with reg property set */
 		if (of_find_property(child, "reg", NULL))
 			continue;
@@ -264,7 +362,14 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 				 child->name, addr);
 
 			if (of_mdiobus_child_is_phy(child)) {
-				rc = of_mdiobus_register_phy(mdio, child, addr);
+				if (dev_addr_found)
+					rc = of_mdiobus_register_vend_spec_phy(mdio,
+									       child,
+									       addr,
+									       dev_addr);
+				else
+					rc = of_mdiobus_register_phy(mdio, child,
+								     addr, NULL);
 				if (rc && rc != -ENODEV)
 					goto unregister;
 			}
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 26aa320..889d85e 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -357,10 +357,13 @@ enum phy_state {
  * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
  * @devices_in_package: Bit vector of devices present.
  * @device_ids: The device identifer for each present device.
+ * @devices_addrs: The devices addresses from the device tree
+ *		   for each present device.
  */
 struct phy_c45_device_ids {
 	u32 devices_in_package;
 	u32 device_ids[32];
+	u32 devices_addrs[32];
 };
 
 /* phy_device: An instance of a PHY
@@ -904,6 +907,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
 				     struct phy_c45_device_ids *c45_ids);
 #if IS_ENABLED(CONFIG_PHYLIB)
 struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
+struct phy_device *get_vend_spec_addr_phy_device(struct mii_bus *bus, int addr,
+						 bool is_c45,
+						 struct phy_c45_device_ids *c45_ids);
 int phy_device_register(struct phy_device *phy);
 void phy_device_free(struct phy_device *phydev);
 #else
@@ -913,6 +919,14 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
 	return NULL;
 }
 
+static inline
+struct phy_device *get_vend_spec_addr_phy_device(struct mii_bus *bus, int addr,
+						 bool is_c45,
+						 struct phy_c45_device_ids *c45_ids)
+{
+	return NULL;
+}
+
 static inline int phy_device_register(struct phy_device *phy)
 {
 	return 0;
-- 
2.7.4

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

* Re: [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space
  2018-04-17  9:02 ` [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space Vicentiu Galanopulo
@ 2018-04-17 12:53   ` Andrew Lunn
  2018-04-17 18:18   ` Florian Fainelli
  1 sibling, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2018-04-17 12:53 UTC (permalink / raw)
  To: Vicentiu Galanopulo
  Cc: robh, netdev, linux-kernel, mark.rutland, davem, marcel,
	devicetree, alexandru.marginean, madalin.bucur

On Tue, Apr 17, 2018 at 04:02:31AM -0500, Vicentiu Galanopulo wrote:
> The extra property enables the discovery on the MDIO bus
> of the PHYs which have a vendor specific address space
> for accessing the C45 MDIO registers.
> 
> Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>

Hi Vicentiu

I think binding is O.K, but the implementation needs work. So 

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids
  2018-04-17  9:02 ` [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids Vicentiu Galanopulo
@ 2018-04-17 12:54   ` Andrew Lunn
  2018-04-17 18:18   ` Florian Fainelli
  1 sibling, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2018-04-17 12:54 UTC (permalink / raw)
  To: Vicentiu Galanopulo
  Cc: robh, netdev, linux-kernel, mark.rutland, davem, marcel,
	devicetree, alexandru.marginean, madalin.bucur

On Tue, Apr 17, 2018 at 04:02:32AM -0500, Vicentiu Galanopulo wrote:
> In the context of enabling the discovery of the PHYs
> which have the C45 MDIO address space in a non-standard
> address:  num_ids in get_phy_c45_ids, has the
> value 8 (ARRAY_SIZE(c45_ids->device_ids)), but the
> u32 *devs can store 32 devices in the bitfield.
> 
> If a device is stored in *devs, in bits 32 to 9
> (bit counting in lookup loop starts from 1), it will
> not be found.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space
  2018-04-17  9:02 ` [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space Vicentiu Galanopulo
@ 2018-04-17 12:56   ` Andrew Lunn
  2018-04-17 18:27   ` Florian Fainelli
  2018-04-25 22:46   ` kbuild test robot
  2 siblings, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2018-04-17 12:56 UTC (permalink / raw)
  To: Vicentiu Galanopulo
  Cc: robh, netdev, linux-kernel, mark.rutland, davem, marcel,
	devicetree, alexandru.marginean, madalin.bucur

On Tue, Apr 17, 2018 at 04:02:33AM -0500, Vicentiu Galanopulo wrote:
> A search of the dev-addr property is done in of_mdiobus_register.
> If the property is found in the PHY node, of_mdiobus_register_vend_spec_phy()
> is called. This is a wrapper function for of_mdiobus_register_phy()
> which finds the device in package based on dev-addr, and fills
> devices_addrs, which is a new field added to phy_c45_device_ids.
> This new field will store the dev-addr property on the same index
> where the device in package has been found.
> 
> The of_mdiobus_register_phy() now contains an extra parameter,
> which is struct phy_c45_device_ids *c45_ids.
> If c45_ids is not NULL, get_vend_spec_addr_phy_device() is called
> and c45_ids are propagated all the way to get_phy_c45_ids().
> 
> Having dev-addr stored in devices_addrs, in get_phy_c45_ids(),
> when probing the identifiers, dev-addr can be extracted from
> devices_addrs and probed if devices_addrs[current_identifier] is not 0.

This still needs work. But i don't want David to see the two
Reviewed-by and think the series is O.K. So lets make it clear

NACK

More comments to follow.

    Andrew

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

* Re: [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space
  2018-04-17  9:02 ` [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space Vicentiu Galanopulo
  2018-04-17 12:53   ` Andrew Lunn
@ 2018-04-17 18:18   ` Florian Fainelli
  2018-04-17 18:27     ` Andrew Lunn
  1 sibling, 1 reply; 16+ messages in thread
From: Florian Fainelli @ 2018-04-17 18:18 UTC (permalink / raw)
  To: vicentiu.galanopulo, andrew, robh, netdev, linux-kernel,
	mark.rutland, davem, marcel, devicetree
  Cc: alexandru.marginean, madalin.bucur

On 04/17/2018 02:02 AM, Vicentiu Galanopulo wrote:
> The extra property enables the discovery on the MDIO bus
> of the PHYs which have a vendor specific address space
> for accessing the C45 MDIO registers.
> 
> Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
> ---
>  Documentation/devicetree/bindings/net/phy.txt | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/net/phy.txt b/Documentation/devicetree/bindings/net/phy.txt
> index d2169a5..82692e2 100644
> --- a/Documentation/devicetree/bindings/net/phy.txt
> +++ b/Documentation/devicetree/bindings/net/phy.txt
> @@ -61,6 +61,11 @@ Optional Properties:
>  - reset-deassert-us: Delay after the reset was deasserted in microseconds.
>    If this property is missing the delay will be skipped.
>  
> +- dev-addr: If set, it indicates the device address of the PHY to be used
> +  when accessing the C45 PHY registers over MDIO. It is used for vendor specific
> +  register space addresses that do no conform to standard address for the MDIO
> +  registers (e.g. MMD30)

Rob made that comment earlier, and I have to ask again now, why don't we
have the Clause 45 PHY binding be modified such that you have a reg
property that has #address-size = 2? This should be entirely backwards
compatible, but it would allow you to specify that device address in a
more traditional way.

> +
>  Example:
>  
>  ethernet-phy@0 {
> @@ -72,4 +77,5 @@ ethernet-phy@0 {
>  	reset-gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
>  	reset-assert-us = <1000>;
>  	reset-deassert-us = <2000>;
> +	dev-addr = <0x1e>;
>  };
> 


-- 
Florian

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

* Re: [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids
  2018-04-17  9:02 ` [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids Vicentiu Galanopulo
  2018-04-17 12:54   ` Andrew Lunn
@ 2018-04-17 18:18   ` Florian Fainelli
  1 sibling, 0 replies; 16+ messages in thread
From: Florian Fainelli @ 2018-04-17 18:18 UTC (permalink / raw)
  To: vicentiu.galanopulo, andrew, robh, netdev, linux-kernel,
	mark.rutland, davem, marcel, devicetree
  Cc: alexandru.marginean, madalin.bucur

On 04/17/2018 02:02 AM, Vicentiu Galanopulo wrote:
> In the context of enabling the discovery of the PHYs
> which have the C45 MDIO address space in a non-standard
> address:  num_ids in get_phy_c45_ids, has the
> value 8 (ARRAY_SIZE(c45_ids->device_ids)), but the
> u32 *devs can store 32 devices in the bitfield.
> 
> If a device is stored in *devs, in bits 32 to 9
> (bit counting in lookup loop starts from 1), it will
> not be found.
> 
> Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>

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

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

* Re: [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space
  2018-04-17  9:02 ` [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space Vicentiu Galanopulo
  2018-04-17 12:56   ` Andrew Lunn
@ 2018-04-17 18:27   ` Florian Fainelli
  2018-04-18  9:38     ` Vicenţiu Galanopulo
  2018-04-25 22:46   ` kbuild test robot
  2 siblings, 1 reply; 16+ messages in thread
From: Florian Fainelli @ 2018-04-17 18:27 UTC (permalink / raw)
  To: vicentiu.galanopulo, andrew, robh, netdev, linux-kernel,
	mark.rutland, davem, marcel, devicetree
  Cc: alexandru.marginean, madalin.bucur

On 04/17/2018 02:02 AM, Vicentiu Galanopulo wrote:
> A search of the dev-addr property is done in of_mdiobus_register.
> If the property is found in the PHY node, of_mdiobus_register_vend_spec_phy()
> is called. This is a wrapper function for of_mdiobus_register_phy()
> which finds the device in package based on dev-addr, and fills
> devices_addrs, which is a new field added to phy_c45_device_ids.
> This new field will store the dev-addr property on the same index
> where the device in package has been found.
> 
> The of_mdiobus_register_phy() now contains an extra parameter,
> which is struct phy_c45_device_ids *c45_ids.
> If c45_ids is not NULL, get_vend_spec_addr_phy_device() is called
> and c45_ids are propagated all the way to get_phy_c45_ids().
> 
> Having dev-addr stored in devices_addrs, in get_phy_c45_ids(),
> when probing the identifiers, dev-addr can be extracted from
> devices_addrs and probed if devices_addrs[current_identifier] is not 0.

I must clearly be missing something, but why are you introducing all
these conditionals instead of updating the existing code to be able to
operate against an arbitrary dev-addr value, and then just making sure
the first thing you do is fetch that property from Device Tree? There is
no way someone is going to be testing with your specific use case in the
future (except yourselves) so unless you make supporting an arbitrary
"dev-addr" value become part of how the code works, this is going to be
breaking badly.

And please, can you keep me copied for next submissions?

> 
> Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
> ---
>  drivers/net/phy/phy_device.c |  49 +++++++++++++++++--
>  drivers/of/of_mdio.c         | 113 +++++++++++++++++++++++++++++++++++++++++--
>  include/linux/phy.h          |  14 ++++++
>  3 files changed, 169 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index ac23322..5c79fd8 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -457,7 +457,7 @@ static int get_phy_c45_devs_in_pkg(struct mii_bus *bus, int addr, int dev_addr,
>  static int get_phy_c45_ids(struct mii_bus *bus, int addr, u32 *phy_id,
>  			   struct phy_c45_device_ids *c45_ids) {
>  	int phy_reg;
> -	int i, reg_addr;
> +	int i, reg_addr, dev_addr;
>  	const int num_ids = ARRAY_SIZE(c45_ids->device_ids);
>  	u32 *devs = &c45_ids->devices_in_package;
>  
> @@ -493,13 +493,23 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, u32 *phy_id,
>  		if (!(c45_ids->devices_in_package & (1 << i)))
>  			continue;
>  
> -		reg_addr = MII_ADDR_C45 | i << 16 | MII_PHYSID1;
> +		/* if c45_ids->devices_addrs for the current id is not 0,
> +		 * then dev-addr was defined in the PHY device tree node,
> +		 * and the PHY has been seen as a valid device, and added
> +		 * in the package. In this case we can use the
> +		 * dev-addr(c45_ids->devices_addrs[i]) to do the MDIO
> +		 * reading of the PHY ID.
> +		 */
> +		dev_addr = !!c45_ids->devices_addrs[i] ?
> +					c45_ids->devices_addrs[i] : i;
> +
> +		reg_addr = MII_ADDR_C45 | dev_addr << 16 | MII_PHYSID1;
>  		phy_reg = mdiobus_read(bus, addr, reg_addr);
>  		if (phy_reg < 0)
>  			return -EIO;
>  		c45_ids->device_ids[i] = (phy_reg & 0xffff) << 16;
>  
> -		reg_addr = MII_ADDR_C45 | i << 16 | MII_PHYSID2;
> +		reg_addr = MII_ADDR_C45 | dev_addr << 16 | MII_PHYSID2;
>  		phy_reg = mdiobus_read(bus, addr, reg_addr);
>  		if (phy_reg < 0)
>  			return -EIO;
> @@ -551,6 +561,39 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id,
>  }
>  
>  /**
> + * get_vend_spec_addr_phy_device - reads the specified PHY device
> + *				   and returns its @phy_device struct
> + * @bus: the target MII bus
> + * @addr: PHY address on the MII bus
> + * @is_c45: If true the PHY uses the 802.3 clause 45 protocol
> + * @c45_ids: Query the c45_ids to see if a PHY with a vendor specific
> + *           register address space was defined in the PHY device tree
> + *           node by adding the "dev-addr" property to the node.
> + *           Store the c45 ID information about the rest of the PHYs
> + *           found PHYs on the MDIO bus during probing.
> + *
> + * Description: Reads the ID registers of the PHY at @addr on the
> + *   @bus, then allocates and returns the phy_device to represent it.
> + */
> +struct phy_device *get_vend_spec_addr_phy_device(struct mii_bus *bus,
> +						 int addr, bool is_c45,
> +						 struct phy_c45_device_ids *c45_ids)
> +{
> +	u32 phy_id = 0;
> +	int r;
> +
> +	r = get_phy_id(bus, addr, &phy_id, is_c45, c45_ids);
> +	if (r)
> +		return ERR_PTR(r);
> +
> +	/* If the phy_id is mostly Fs, there is no device there */
> +	if ((phy_id & 0x1fffffff) == 0x1fffffff)
> +		return ERR_PTR(-ENODEV);
> +
> +	return phy_device_create(bus, addr, phy_id, is_c45, c45_ids);
> +}
> +
> +/**
>   * get_phy_device - reads the specified PHY device and returns its @phy_device
>   *		    struct
>   * @bus: the target MII bus
> diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
> index 8c0c927..52e8bfb 100644
> --- a/drivers/of/of_mdio.c
> +++ b/drivers/of/of_mdio.c
> @@ -45,7 +45,8 @@ static int of_get_phy_id(struct device_node *device, u32 *phy_id)
>  }
>  
>  static int of_mdiobus_register_phy(struct mii_bus *mdio,
> -				    struct device_node *child, u32 addr)
> +				   struct device_node *child, u32 addr,
> +				   struct phy_c45_device_ids *c45_ids)
>  {
>  	struct phy_device *phy;
>  	bool is_c45;
> @@ -58,7 +59,12 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio,
>  	if (!is_c45 && !of_get_phy_id(child, &phy_id))
>  		phy = phy_device_create(mdio, addr, phy_id, 0, NULL);
>  	else
> -		phy = get_phy_device(mdio, addr, is_c45);
> +		if (c45_ids)
> +			phy = get_vend_spec_addr_phy_device(mdio,
> +							    addr, is_c45,
> +							    c45_ids);
> +		else
> +			phy = get_phy_device(mdio, addr, is_c45);
>  	if (IS_ERR(phy))
>  		return PTR_ERR(phy);
>  
> @@ -190,6 +196,72 @@ static bool of_mdiobus_child_is_phy(struct device_node *child)
>  	return false;
>  }
>  
> +static void of_fill_c45_devices_addrs(u32 dev_addr,
> +				      struct phy_c45_device_ids *c45_ids)
> +{
> +	int i;
> +	const int num_ids = ARRAY_SIZE(c45_ids->device_ids);
> +
> +	/* Search through all Device Identifiers
> +	 * and set dev_addr in c45_ids->devices_addrs,
> +	 * if the device bit is set in
> +	 * c45_ids->devices_in_package
> +	 */
> +	for (i = 1; i < num_ids; i++) {
> +		if (!(c45_ids->devices_in_package & (1 << i)))
> +			continue;
> +
> +		c45_ids->devices_addrs[i] = dev_addr;
> +	}
> +}
> +
> +static int of_find_devaddr_in_pkg(struct mii_bus *bus, u32 addr, u32 dev_addr,
> +				  struct phy_c45_device_ids *c45_ids)
> +{
> +	u32 *devs = &c45_ids->devices_in_package;
> +	int phy_reg, reg_addr;
> +
> +	reg_addr = MII_ADDR_C45 | dev_addr << 16 | MDIO_DEVS2;
> +	phy_reg = mdiobus_read(bus, addr, reg_addr);
> +	if (phy_reg < 0)
> +		return -EIO;
> +
> +	*devs = (phy_reg & 0xffff) << 16;
> +
> +	reg_addr = MII_ADDR_C45 | dev_addr << 16 | MDIO_DEVS1;
> +	phy_reg = mdiobus_read(bus, addr, reg_addr);
> +	if (phy_reg < 0)
> +		return -EIO;
> +
> +	*devs |= (phy_reg & 0xffff);
> +
> +	return 0;
> +}
> +
> +/*
> + * Finds the device in package and populates the c45_ids
> + * if any device is found at dev_addr address. After this
> + * the PHY is registered
> + */
> +static int of_mdiobus_register_vend_spec_phy(struct mii_bus *mdio,
> +					     struct device_node *child,
> +					     u32 addr, u32 dev_addr)
> +{
> +	struct phy_c45_device_ids c45_ids = {0};
> +	int dev_err = 0;
> +
> +	if (!dev_addr)
> +		goto register_phy;
> +
> +	dev_err = of_find_devaddr_in_pkg(mdio, addr, dev_addr, &c45_ids);
> +
> +	if (!dev_err)
> +		of_fill_c45_devices_addrs(dev_addr, &c45_ids);
> +
> +register_phy:
> +	return of_mdiobus_register_phy(mdio, child, addr, &c45_ids);
> +}
> +
>  /**
>   * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
>   * @mdio: pointer to mii_bus structure
> @@ -202,7 +274,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  {
>  	struct device_node *child;
>  	bool scanphys = false;
> +	bool dev_addr_found = true;
>  	int addr, rc;
> +	int dev_addr = 0;
> +	int ret;
>  
>  	/* Do not continue if the node is disabled */
>  	if (!of_device_is_available(np))
> @@ -226,6 +301,14 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  
>  	/* Loop over the child nodes and register a phy_device for each phy */
>  	for_each_available_child_of_node(np, child) {
> +		/* Check if dev-addr is set in the PHY node */
> +		ret = of_property_read_u32(child, "dev-addr", &dev_addr);
> +
> +		if (ret < 0) {
> +			/* either not set or invalid */
> +			dev_addr_found = false;
> +		}
> +
>  		addr = of_mdio_parse_addr(&mdio->dev, child);
>  		if (addr < 0) {
>  			scanphys = true;
> @@ -233,7 +316,14 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  		}
>  
>  		if (of_mdiobus_child_is_phy(child))
> -			rc = of_mdiobus_register_phy(mdio, child, addr);
> +			if (dev_addr_found)
> +				rc = of_mdiobus_register_vend_spec_phy(mdio,
> +								       child,
> +								       addr,
> +								       dev_addr);
> +			else
> +				rc = of_mdiobus_register_phy(mdio, child,
> +							     addr, NULL);
>  		else
>  			rc = of_mdiobus_register_device(mdio, child, addr);
>  
> @@ -248,8 +338,16 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  	if (!scanphys)
>  		return 0;
>  
> +	/* reset device found variable */
> +	dev_addr_found = true;
> +
>  	/* auto scan for PHYs with empty reg property */
>  	for_each_available_child_of_node(np, child) {
> +		/* Check if dev-addr is set in the PHY node,
> +		 * for PHYs which don't have reg property set
> +		 */
> +		ret = of_property_read_u32(child, "dev-addr", &dev_addr);
> +
>  		/* Skip PHYs with reg property set */
>  		if (of_find_property(child, "reg", NULL))
>  			continue;
> @@ -264,7 +362,14 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
>  				 child->name, addr);
>  
>  			if (of_mdiobus_child_is_phy(child)) {
> -				rc = of_mdiobus_register_phy(mdio, child, addr);
> +				if (dev_addr_found)
> +					rc = of_mdiobus_register_vend_spec_phy(mdio,
> +									       child,
> +									       addr,
> +									       dev_addr);
> +				else
> +					rc = of_mdiobus_register_phy(mdio, child,
> +								     addr, NULL);
>  				if (rc && rc != -ENODEV)
>  					goto unregister;
>  			}
> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index 26aa320..889d85e 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -357,10 +357,13 @@ enum phy_state {
>   * struct phy_c45_device_ids - 802.3-c45 Device Identifiers
>   * @devices_in_package: Bit vector of devices present.
>   * @device_ids: The device identifer for each present device.
> + * @devices_addrs: The devices addresses from the device tree
> + *		   for each present device.
>   */
>  struct phy_c45_device_ids {
>  	u32 devices_in_package;
>  	u32 device_ids[32];
> +	u32 devices_addrs[32];
>  };
>  
>  /* phy_device: An instance of a PHY
> @@ -904,6 +907,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
>  				     struct phy_c45_device_ids *c45_ids);
>  #if IS_ENABLED(CONFIG_PHYLIB)
>  struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
> +struct phy_device *get_vend_spec_addr_phy_device(struct mii_bus *bus, int addr,
> +						 bool is_c45,
> +						 struct phy_c45_device_ids *c45_ids);
>  int phy_device_register(struct phy_device *phy);
>  void phy_device_free(struct phy_device *phydev);
>  #else
> @@ -913,6 +919,14 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
>  	return NULL;
>  }
>  
> +static inline
> +struct phy_device *get_vend_spec_addr_phy_device(struct mii_bus *bus, int addr,
> +						 bool is_c45,
> +						 struct phy_c45_device_ids *c45_ids)
> +{
> +	return NULL;
> +}
> +
>  static inline int phy_device_register(struct phy_device *phy)
>  {
>  	return 0;
> 


-- 
Florian

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

* Re: [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space
  2018-04-17 18:18   ` Florian Fainelli
@ 2018-04-17 18:27     ` Andrew Lunn
  2018-04-17 18:29       ` Florian Fainelli
  0 siblings, 1 reply; 16+ messages in thread
From: Andrew Lunn @ 2018-04-17 18:27 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: vicentiu.galanopulo, robh, netdev, linux-kernel, mark.rutland,
	davem, marcel, devicetree, alexandru.marginean, madalin.bucur

On Tue, Apr 17, 2018 at 11:18:20AM -0700, Florian Fainelli wrote:
> On 04/17/2018 02:02 AM, Vicentiu Galanopulo wrote:
> > The extra property enables the discovery on the MDIO bus
> > of the PHYs which have a vendor specific address space
> > for accessing the C45 MDIO registers.
> > 
> > Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
> > ---
> >  Documentation/devicetree/bindings/net/phy.txt | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/Documentation/devicetree/bindings/net/phy.txt b/Documentation/devicetree/bindings/net/phy.txt
> > index d2169a5..82692e2 100644
> > --- a/Documentation/devicetree/bindings/net/phy.txt
> > +++ b/Documentation/devicetree/bindings/net/phy.txt
> > @@ -61,6 +61,11 @@ Optional Properties:
> >  - reset-deassert-us: Delay after the reset was deasserted in microseconds.
> >    If this property is missing the delay will be skipped.
> >  
> > +- dev-addr: If set, it indicates the device address of the PHY to be used
> > +  when accessing the C45 PHY registers over MDIO. It is used for vendor specific
> > +  register space addresses that do no conform to standard address for the MDIO
> > +  registers (e.g. MMD30)
> 
> Rob made that comment earlier, and I have to ask again now, why don't we
> have the Clause 45 PHY binding be modified such that you have a reg
> property that has #address-size = 2? This should be entirely backwards
> compatible, but it would allow you to specify that device address in a
> more traditional way.

Hi Florian

I think we might get into trouble when we have both c22 and c45 on the
same bus. Two different reg formats. I would have to try it and see to
be sure.

     Andrew

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

* Re: [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space
  2018-04-17 18:27     ` Andrew Lunn
@ 2018-04-17 18:29       ` Florian Fainelli
  2018-04-24 13:14         ` Rob Herring
  0 siblings, 1 reply; 16+ messages in thread
From: Florian Fainelli @ 2018-04-17 18:29 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: vicentiu.galanopulo, robh, netdev, linux-kernel, mark.rutland,
	davem, marcel, devicetree, alexandru.marginean, madalin.bucur

On 04/17/2018 11:27 AM, Andrew Lunn wrote:
> On Tue, Apr 17, 2018 at 11:18:20AM -0700, Florian Fainelli wrote:
>> On 04/17/2018 02:02 AM, Vicentiu Galanopulo wrote:
>>> The extra property enables the discovery on the MDIO bus
>>> of the PHYs which have a vendor specific address space
>>> for accessing the C45 MDIO registers.
>>>
>>> Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
>>> ---
>>>  Documentation/devicetree/bindings/net/phy.txt | 6 ++++++
>>>  1 file changed, 6 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/net/phy.txt b/Documentation/devicetree/bindings/net/phy.txt
>>> index d2169a5..82692e2 100644
>>> --- a/Documentation/devicetree/bindings/net/phy.txt
>>> +++ b/Documentation/devicetree/bindings/net/phy.txt
>>> @@ -61,6 +61,11 @@ Optional Properties:
>>>  - reset-deassert-us: Delay after the reset was deasserted in microseconds.
>>>    If this property is missing the delay will be skipped.
>>>  
>>> +- dev-addr: If set, it indicates the device address of the PHY to be used
>>> +  when accessing the C45 PHY registers over MDIO. It is used for vendor specific
>>> +  register space addresses that do no conform to standard address for the MDIO
>>> +  registers (e.g. MMD30)
>>
>> Rob made that comment earlier, and I have to ask again now, why don't we
>> have the Clause 45 PHY binding be modified such that you have a reg
>> property that has #address-size = 2? This should be entirely backwards
>> compatible, but it would allow you to specify that device address in a
>> more traditional way.
> 
> Hi Florian
> 
> I think we might get into trouble when we have both c22 and c45 on the
> same bus. Two different reg formats. I would have to try it and see to
> be sure.

Hum indeed, we would no longer be able to mix and match on the same MDIO
bus, unless we give C22 PHYs a "fake" second cell. Disregard that idea
then, and let's stick with 'dev-addr'.
-- 
Florian

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

* RE: [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space
  2018-04-17 18:27   ` Florian Fainelli
@ 2018-04-18  9:38     ` Vicenţiu Galanopulo
  2018-04-18 12:27       ` Andrew Lunn
  0 siblings, 1 reply; 16+ messages in thread
From: Vicenţiu Galanopulo @ 2018-04-18  9:38 UTC (permalink / raw)
  To: Florian Fainelli, andrew, robh, netdev, linux-kernel,
	mark.rutland, davem, marcel, devicetree
  Cc: Alexandru Marginean, Madalin-cristian Bucur



> > Having dev-addr stored in devices_addrs, in get_phy_c45_ids(), when
> > probing the identifiers, dev-addr can be extracted from devices_addrs
> > and probed if devices_addrs[current_identifier] is not 0.
> 
> I must clearly be missing something, but why are you introducing all these
> conditionals instead of updating the existing code to be able to operate against
> an arbitrary dev-addr value, and then just making sure the first thing you do is
> fetch that property from Device Tree? There is no way someone is going to be
> testing with your specific use case in the future (except yourselves) so unless you
> make supporting an arbitrary "dev-addr" value become part of how the code
> works, this is going to be breaking badly.
>

Hi Florian,

My intention was to have this patch as "plugin" and modify the existing kernel API little to none. I was thinking that with a #ifdef, ideally,  all changes could be part of a CONFIG kernel option.
Updating the existing code, instead of the conditionals, might run into just that, and the change could propagate across multiple modules. This is from my first RFC patch, review by Andrew:
        of_mdiobus_register(), when it loops over the children, looks for 
        the new property. If found, it passed dev-id to of_mdiobus_register_phy().
        That passes it to get_phy_device(). I think get_phy_device() can 
        then set the ID in c45_ids, before passing it to get_phy_id().
        get_phy_c45_ids() will first look at devices in package and can add 
        further devices to c45_ids. It will then probe both those found, and 
        the static
        one you added.
                                                                                              Andrew

        [Vicenţiu Galanopulo]
        Just to make sure I understand. Do you want me to change the signature 
        of all of_mdiobus_register_phy(), get_phy_device(), get_phy_id() and
        get_phy_c45_ids() and include the dev_addr parameter obtained from the 
        device tree?  (a propagation of this parameter across all functions 
        all the way to
        get_phy_c45_devs_in_pkg?) This will impact xgbe-mdio.c, fixed_phy.c 
        because get_phy_device() is used in these files. 

 
 The "catch" is to transport the dev-addr value from of_mdio.c (location of the  loop of the PHY device tree node which reads all PHY node properties) to phy_device.c (this is where you can get the PHY ID).
My understanding from Andrew's comment is that the key here is the c45_ids, and that these could be filled in of_mdio.c, first, with the IDs from dev-addr (he called them "static" as they are queried directly by using the value of dev-addr) and afterwards, in phy_device.c (following the lookup loop - in a "dynamic" way).
There's nothing more to this patch than some functionality from phy_device.c ported to of_mdio.c, to enable the extraction of the PHY IDs. 
I guess the code redundancy could be reduced (between of_mdio.c and phy_device.c) and maybe you or Andrew could comment on this if you would like to go with this patch approach.

Not sure I understand your comment about the specific use case and the breaking badly part.  
Right now I'm able to test because I have access to a PHY with dev-addr = 0x1e. 
But the whole mechanism in this patch starts to work the moment you set <dev-addr> in the device tree. If you don't set that, nothing happens. If you set it to a bogus value, no PHY ID will be found at that address. Besides that, the PHY ID extraction code is the same as what is currently working in phy_device.c. 
80-90% of the patch is based on what already exists in phy_device.c and of_mdio.c. Where is the breaking badly part supposed to happen? 

> And please, can you keep me copied for next submissions?
Yes, the "to" list was pretty long and I somehow missed you. Sorry.
 
Vicentiu

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

* Re: [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space
  2018-04-18  9:38     ` Vicenţiu Galanopulo
@ 2018-04-18 12:27       ` Andrew Lunn
  0 siblings, 0 replies; 16+ messages in thread
From: Andrew Lunn @ 2018-04-18 12:27 UTC (permalink / raw)
  To: Vicenţiu Galanopulo
  Cc: Florian Fainelli, robh, netdev, linux-kernel, mark.rutland,
	davem, marcel, devicetree, Alexandru Marginean,
	Madalin-cristian Bucur

On Wed, Apr 18, 2018 at 09:38:47AM +0000, Vicenţiu Galanopulo wrote:
> 
> 
> > > Having dev-addr stored in devices_addrs, in get_phy_c45_ids(), when
> > > probing the identifiers, dev-addr can be extracted from devices_addrs
> > > and probed if devices_addrs[current_identifier] is not 0.
> > 
> > I must clearly be missing something, but why are you introducing all these
> > conditionals instead of updating the existing code to be able to operate against
> > an arbitrary dev-addr value, and then just making sure the first thing you do is
> > fetch that property from Device Tree? There is no way someone is going to be
> > testing with your specific use case in the future (except yourselves) so unless you
> > make supporting an arbitrary "dev-addr" value become part of how the code
> > works, this is going to be breaking badly.
> >
> 
> Hi Florian,
> 
> My intention was to have this patch as "plugin" and modify the existing kernel API little to none.

Hi Vicenţiu

In Linux, kernel APIs are not sacred. If you need to change them, do
so.

We want a clear, well integrated solution, with minimal
duplication.

	Andrew

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

* Re: [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space
  2018-04-17 18:29       ` Florian Fainelli
@ 2018-04-24 13:14         ` Rob Herring
  0 siblings, 0 replies; 16+ messages in thread
From: Rob Herring @ 2018-04-24 13:14 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Andrew Lunn, vicentiu.galanopulo, netdev, linux-kernel,
	mark.rutland, davem, marcel, devicetree, alexandru.marginean,
	madalin.bucur

On Tue, Apr 17, 2018 at 11:29:27AM -0700, Florian Fainelli wrote:
> On 04/17/2018 11:27 AM, Andrew Lunn wrote:
> > On Tue, Apr 17, 2018 at 11:18:20AM -0700, Florian Fainelli wrote:
> >> On 04/17/2018 02:02 AM, Vicentiu Galanopulo wrote:
> >>> The extra property enables the discovery on the MDIO bus
> >>> of the PHYs which have a vendor specific address space
> >>> for accessing the C45 MDIO registers.
> >>>
> >>> Signed-off-by: Vicentiu Galanopulo <vicentiu.galanopulo@nxp.com>
> >>> ---
> >>>  Documentation/devicetree/bindings/net/phy.txt | 6 ++++++
> >>>  1 file changed, 6 insertions(+)
> >>>
> >>> diff --git a/Documentation/devicetree/bindings/net/phy.txt b/Documentation/devicetree/bindings/net/phy.txt
> >>> index d2169a5..82692e2 100644
> >>> --- a/Documentation/devicetree/bindings/net/phy.txt
> >>> +++ b/Documentation/devicetree/bindings/net/phy.txt
> >>> @@ -61,6 +61,11 @@ Optional Properties:
> >>>  - reset-deassert-us: Delay after the reset was deasserted in microseconds.
> >>>    If this property is missing the delay will be skipped.
> >>>  
> >>> +- dev-addr: If set, it indicates the device address of the PHY to be used
> >>> +  when accessing the C45 PHY registers over MDIO. It is used for vendor specific
> >>> +  register space addresses that do no conform to standard address for the MDIO
> >>> +  registers (e.g. MMD30)
> >>
> >> Rob made that comment earlier, and I have to ask again now, why don't we
> >> have the Clause 45 PHY binding be modified such that you have a reg
> >> property that has #address-size = 2? This should be entirely backwards
> >> compatible, but it would allow you to specify that device address in a
> >> more traditional way.

#address-size is not a valid property. I think #address-cells is what 
was meant here. However, the statement is still not right either. The 
number of cells is how many cells to encode an address, not how many 
addresses you have.

> > 
> > Hi Florian
> > 
> > I think we might get into trouble when we have both c22 and c45 on the
> > same bus. Two different reg formats. I would have to try it and see to
> > be sure.
>
> Hum indeed, we would no longer be able to mix and match on the same MDIO
> bus, unless we give C22 PHYs a "fake" second cell. Disregard that idea
> then, and let's stick with 'dev-addr'.

The format would be the same (1 cell for an address), you'd just have 1 
address for c22 and 2 addresses for c45 devices which is perfectly fine.

However, as I mentioned on the previous version, I'm okay with dev-addr 
given it seems to be a quirk that isn't always needed.

Rob

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

* Re: [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space
  2018-04-17  9:02 ` [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space Vicentiu Galanopulo
  2018-04-17 12:56   ` Andrew Lunn
  2018-04-17 18:27   ` Florian Fainelli
@ 2018-04-25 22:46   ` kbuild test robot
  2 siblings, 0 replies; 16+ messages in thread
From: kbuild test robot @ 2018-04-25 22:46 UTC (permalink / raw)
  To: Vicentiu Galanopulo
  Cc: kbuild-all, andrew, robh, netdev, linux-kernel, mark.rutland,
	davem, marcel, devicetree, alexandru.marginean, madalin.bucur,
	vicentiu.galanopulo

[-- Attachment #1: Type: text/plain, Size: 726 bytes --]

Hi Vicentiu,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Vicentiu-Galanopulo/net-phy-Enable-C45-vendor-specific-MDIO-register-addr-space/20180418-014927
config: x86_64-randconfig-b0-04260315 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

>> ERROR: "get_vend_spec_addr_phy_device" [drivers/of/of_mdio.ko] undefined!

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 25865 bytes --]

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

end of thread, other threads:[~2018-04-25 22:46 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-17  9:02 [PATCH net-next 0/3] net: phy: Enable C45 vendor specific MDIO register addr space Vicentiu Galanopulo
2018-04-17  9:02 ` [PATCH net-next 1/3] net: phy: Add binding for vendor specific C45 MDIO address space Vicentiu Galanopulo
2018-04-17 12:53   ` Andrew Lunn
2018-04-17 18:18   ` Florian Fainelli
2018-04-17 18:27     ` Andrew Lunn
2018-04-17 18:29       ` Florian Fainelli
2018-04-24 13:14         ` Rob Herring
2018-04-17  9:02 ` [PATCH net-next 2/3] net: phy: Change the array size to 32 for device_ids Vicentiu Galanopulo
2018-04-17 12:54   ` Andrew Lunn
2018-04-17 18:18   ` Florian Fainelli
2018-04-17  9:02 ` [PATCH net-next 3/3] net: phy: Enable C45 PHYs with vendor specific address space Vicentiu Galanopulo
2018-04-17 12:56   ` Andrew Lunn
2018-04-17 18:27   ` Florian Fainelli
2018-04-18  9:38     ` Vicenţiu Galanopulo
2018-04-18 12:27       ` Andrew Lunn
2018-04-25 22:46   ` kbuild test robot

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).