2015-04-10 09:47:24

by Shengzhou Liu

[permalink] [raw]
Subject: [PATCH] net/phy: tune get_phy_c45_ids to support more c45 phy

As some C45 10G PHYs(e.g. Cortina CS4315/CS4340 PHY) have
zero Devices In package, current driver can't get correct
devices_in_package value by non-zero Devices In package.
so let's probe more with zero Devices In package to support
more C45 PHYs.

Signed-off-by: Shengzhou Liu <[email protected]>
---
drivers/net/phy/phy_device.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index bdfe51f..07cf455 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -242,12 +242,29 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, u32 *phy_id,
return -EIO;
c45_ids->devices_in_package |= (phy_reg & 0xffff);

- /* If mostly Fs, there is no device there,
- * let's get out of here.
+ /* If mostly Fs, let's continue to probe more
+ * as some c45 PHYs have zero Devices In package,
+ * e.g. Cortina CS4315/CS4340 PHY.
*/
if ((c45_ids->devices_in_package & 0x1fffffff) == 0x1fffffff) {
- *phy_id = 0xffffffff;
- return 0;
+ reg_addr = MII_ADDR_C45 | 0 << 16 | 6;
+ phy_reg = mdiobus_read(bus, addr, reg_addr);
+ if (phy_reg < 0)
+ return -EIO;
+ c45_ids->devices_in_package = (phy_reg & 0xffff) << 16;
+ reg_addr = MII_ADDR_C45 | 0 << 16 | 5;
+ phy_reg = mdiobus_read(bus, addr, reg_addr);
+ if (phy_reg < 0)
+ return -EIO;
+ c45_ids->devices_in_package |= (phy_reg & 0xffff);
+ /* If mostly Fs, there is no device there,
+ * let's get out of here.
+ */
+ if ((c45_ids->devices_in_package & 0x1fffffff) ==
+ 0x1fffffff) {
+ *phy_id = 0xffffffff;
+ return 0;
+ }
}
}

--
2.1.0.27.g96db324


2015-04-13 00:42:06

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net/phy: tune get_phy_c45_ids to support more c45 phy

From: Shengzhou Liu <[email protected]>
Date: Fri, 10 Apr 2015 17:10:20 +0800

> if ((c45_ids->devices_in_package & 0x1fffffff) == 0x1fffffff) {
> - *phy_id = 0xffffffff;
> - return 0;
> + reg_addr = MII_ADDR_C45 | 0 << 16 | 6;
> + phy_reg = mdiobus_read(bus, addr, reg_addr);
> + if (phy_reg < 0)
> + return -EIO;

Why are you reading this same register again, and why are you doing
it with the magic constant "6". That's not '6', it's 'MDIO_DEVS2'.

The first loop executed here should have read from this address, and
placed the value into the ->devices_in_package.

> + c45_ids->devices_in_package = (phy_reg & 0xffff) << 16;
> + reg_addr = MII_ADDR_C45 | 0 << 16 | 5;

Again, this isn't '5', it's 'MDIO_DEVS1'.

This looks really like a hack. You're reading again the same registers,
by hand, that the loop should already be reading properly.

Why not restructure the loop to actually probe naturally for the
presence bits in a way that works on the chip you are trying to make
work?

2015-04-13 07:14:23

by Shengzhou Liu

[permalink] [raw]
Subject: RE: [PATCH] net/phy: tune get_phy_c45_ids to support more c45 phy



> -----Original Message-----
> From: David Miller [mailto:[email protected]]
> Sent: Monday, April 13, 2015 8:42 AM
> To: Liu Shengzhou-B36685
> Cc: [email protected]; [email protected];
> [email protected]
> Subject: Re: [PATCH] net/phy: tune get_phy_c45_ids to support more c45 phy
>
> From: Shengzhou Liu <[email protected]>
> Date: Fri, 10 Apr 2015 17:10:20 +0800
>
> > if ((c45_ids->devices_in_package & 0x1fffffff) == 0x1fffffff) {
> > - *phy_id = 0xffffffff;
> > - return 0;
> > + reg_addr = MII_ADDR_C45 | 0 << 16 | 6;
> > + phy_reg = mdiobus_read(bus, addr, reg_addr);
> > + if (phy_reg < 0)
> > + return -EIO;
>
> Why are you reading this same register again, and why are you doing it with
> the magic constant "6". That's not '6', it's 'MDIO_DEVS2'.
>
> The first loop executed here should have read from this address, and placed
> the value into the ->devices_in_package.
>
> This looks really like a hack. You're reading again the same registers, by
> hand, that the loop should already be reading properly.
>
> Why not restructure the loop to actually probe naturally for the presence
> bits in a way that works on the chip you are trying to make work?

Some PHYs(e.g. Cortina CS4315/CS4340) have zero Devices In package,
If we first probe zero Devices In package by loop for(i = 0; i < num_ids && c45_ids->devices_in_package == 0; i++),
it will cause the probe fail on those C45 PHYs with non-zero Devices In package.
So we must first probe non-zero Devices In package in the loop, if the return value
of c45_ids->devices_in_package is 0x1fffffff, then try to probe zero Devices In package.
Yes, will use MDIO_DEVS1 and MDIO_DEVS2 instead of constant '6', '5' in next version.