All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy
@ 2015-04-14 10:09 Shengzhou Liu
  2015-04-14 17:45 ` Florian Fainelli
  0 siblings, 1 reply; 5+ messages in thread
From: Shengzhou Liu @ 2015-04-14 10:09 UTC (permalink / raw)
  To: netdev, davem; +Cc: linux-kernel, Shengzhou Liu

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 <Shengzhou.Liu@freescale.com>
---
v2: use MDIO_DEVS1 and MDIO_DEVS2 instead of constant '6', '5'

 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..c4f836f 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 | MDIO_DEVS2;
+			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 | MDIO_DEVS1;
+			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


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

* Re: [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy
  2015-04-14 10:09 [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy Shengzhou Liu
@ 2015-04-14 17:45 ` Florian Fainelli
  2015-04-15  8:27     ` Shengzhou.Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Fainelli @ 2015-04-14 17:45 UTC (permalink / raw)
  To: Shengzhou Liu, netdev, davem; +Cc: linux-kernel

On 14/04/15 03:09, Shengzhou Liu wrote:
> 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.

I cannot remember exactly how many times this patch has been posted, but
it still is not clear to me what you are doing here is helping with
these Cortina PHYs.

Could you post a dump of the mdiobus_read() arguments and values for the
old code and the new code you are proposing? That way it might be
clearer what is the goal here?

> 
> Signed-off-by: Shengzhou Liu <Shengzhou.Liu@freescale.com>
> ---
> v2: use MDIO_DEVS1 and MDIO_DEVS2 instead of constant '6', '5'
> 
>  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..c4f836f 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 | MDIO_DEVS2;
> +			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 | MDIO_DEVS1;
> +			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;
> +			}

Could not we somehow be a bit more clever and utilize the loop, with an
adjusted i = 0 during this condition? Some something like this (untested):


diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index bdfe51fc3a65..4bb3d3084db1 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -230,6 +230,7 @@ static int get_phy_c45_ids(struct mii_bus *bus, int
addr, u32 *phy_id,
        for (i = 1;
             i < num_ids && c45_ids->devices_in_package == 0;
             i++) {
+again:
                reg_addr = MII_ADDR_C45 | i << 16 | MDIO_DEVS2;
                phy_reg = mdiobus_read(bus, addr, reg_addr);
                if (phy_reg < 0)
@@ -246,6 +247,11 @@ static int get_phy_c45_ids(struct mii_bus *bus, int
addr, u32 *phy_id,
                 * let's get out of here.
                 */
                if ((c45_ids->devices_in_package & 0x1fffffff) ==
0x1fffffff) {
+                       if (i == num_ids) {
+                               i = 0;
+                               goto again;
+                       }
+
                        *phy_id = 0xffffffff;
                        return 0;
                }
-- 
Florian

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

* RE: [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy
  2015-04-14 17:45 ` Florian Fainelli
@ 2015-04-15  8:27     ` Shengzhou.Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Shengzhou.Liu @ 2015-04-15  8:27 UTC (permalink / raw)
  To: Florian Fainelli, netdev, davem; +Cc: linux-kernel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3873 bytes --]

> -----Original Message-----
> From: Florian Fainelli [mailto:f.fainelli@gmail.com]
> Sent: Wednesday, April 15, 2015 1:45 AM
> To: Liu Shengzhou-B36685; netdev@vger.kernel.org; davem@davemloft.net
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy
> 
> On 14/04/15 03:09, Shengzhou Liu wrote:
> > 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.
> 
> I cannot remember exactly how many times this patch has been posted, but it
> still is not clear to me what you are doing here is helping with these
> Cortina PHYs.
> 
> Could you post a dump of the mdiobus_read() arguments and values for the old
> code and the new code you are proposing? That way it might be clearer what is
> the goal here?
> 
The key point is that standard C45 PHYs use non-zero Devices in package i(reg_addr = MII_ADDR_C45 | i << 16 | MDIO_DEVS) to read  devices_in_package, device zero is reserved, but Cortina CS4315/CS4340 PHY use zero Devices in package(reg_addr = MII_ADDR_C45 | 0 << 16 | MDIO_DEVS) to read devices_in_package. 

This is caused by Cortina non-standard PHY, e.g. standard PHY has MII_PHYSID1=0x02, MII_PHYSID2=0x03, but CS4315/CS4340 PHY has non-standard offset of PHY ID registers(MII_PHYSID1=0x00, MII_PHYSID2=0x01).
  
> >
> > Signed-off-by: Shengzhou Liu <Shengzhou.Liu@freescale.com>
> > ---
> > v2: use MDIO_DEVS1 and MDIO_DEVS2 instead of constant '6', '5'
> >
> >  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..c4f836f 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 | MDIO_DEVS2;
> > +			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 | MDIO_DEVS1;
> > +			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;
> > +			}
> 
> Could not we somehow be a bit more clever and utilize the loop, with an
> adjusted i = 0 during this condition? Some something like this (untested):
> 
> Florian

I had done it to utilize the loop with i = 0 as your thought, but David Miller said that the way of utilizing the loop makes no sense to test 'i' for zero vs. non-zero until the looping construct it is contained within can actually hit a zero value, adding such a check here makes the code confusing.
So I dropped the way of utilizing the loop to make code readable.

ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

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

* RE: [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy
@ 2015-04-15  8:27     ` Shengzhou.Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Shengzhou.Liu @ 2015-04-15  8:27 UTC (permalink / raw)
  To: Florian Fainelli, netdev, davem; +Cc: linux-kernel

> -----Original Message-----
> From: Florian Fainelli [mailto:f.fainelli@gmail.com]
> Sent: Wednesday, April 15, 2015 1:45 AM
> To: Liu Shengzhou-B36685; netdev@vger.kernel.org; davem@davemloft.net
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy
> 
> On 14/04/15 03:09, Shengzhou Liu wrote:
> > 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.
> 
> I cannot remember exactly how many times this patch has been posted, but it
> still is not clear to me what you are doing here is helping with these
> Cortina PHYs.
> 
> Could you post a dump of the mdiobus_read() arguments and values for the old
> code and the new code you are proposing? That way it might be clearer what is
> the goal here?
> 
The key point is that standard C45 PHYs use non-zero Devices in package i(reg_addr = MII_ADDR_C45 | i << 16 | MDIO_DEVS) to read  devices_in_package, device zero is reserved, but Cortina CS4315/CS4340 PHY use zero Devices in package(reg_addr = MII_ADDR_C45 | 0 << 16 | MDIO_DEVS) to read devices_in_package. 

This is caused by Cortina non-standard PHY, e.g. standard PHY has MII_PHYSID1=0x02, MII_PHYSID2=0x03, but CS4315/CS4340 PHY has non-standard offset of PHY ID registers(MII_PHYSID1=0x00, MII_PHYSID2=0x01).
  
> >
> > Signed-off-by: Shengzhou Liu <Shengzhou.Liu@freescale.com>
> > ---
> > v2: use MDIO_DEVS1 and MDIO_DEVS2 instead of constant '6', '5'
> >
> >  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..c4f836f 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 | MDIO_DEVS2;
> > +			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 | MDIO_DEVS1;
> > +			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;
> > +			}
> 
> Could not we somehow be a bit more clever and utilize the loop, with an
> adjusted i = 0 during this condition? Some something like this (untested):
> 
> Florian

I had done it to utilize the loop with i = 0 as your thought, but David Miller said that the way of utilizing the loop makes no sense to test 'i' for zero vs. non-zero until the looping construct it is contained within can actually hit a zero value, adding such a check here makes the code confusing.
So I dropped the way of utilizing the loop to make code readable.


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

* [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy
@ 2014-04-24  8:22 Shengzhou Liu
  0 siblings, 0 replies; 5+ messages in thread
From: Shengzhou Liu @ 2014-04-24  8:22 UTC (permalink / raw)
  To: netdev; +Cc: scottwood, Shengzhou Liu

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 which have zero Devices In package.

Signed-off-by: Shengzhou Liu <Shengzhou.Liu@freescale.com>
---
v2: refined to reuse code.

 drivers/net/phy/phy_device.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index cfb5110..4f5d518 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -232,7 +232,7 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, u32 *phy_id,
 	for (i = 1;
 	     i < num_ids && c45_ids->devices_in_package == 0;
 	     i++) {
-		reg_addr = MII_ADDR_C45 | i << 16 | 6;
+retry:		reg_addr = MII_ADDR_C45 | i << 16 | 6;
 		phy_reg = mdiobus_read(bus, addr, reg_addr);
 		if (phy_reg < 0)
 			return -EIO;
@@ -244,12 +244,20 @@ 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 ((c45_ids->devices_in_package & 0x1fffffff) == 0x1fffffff) {
-			*phy_id = 0xffffffff;
-			return 0;
+			if (i) {
+				/*  If mostly Fs, there is no device there,
+				 *  then let's continue to probe more, as some
+				 *  10G PHYs have zero Devices In package,
+				 *  e.g. Cortina CS4315/CS4340 PHY.
+				 */
+				i = 0;
+				goto retry;
+			} else {
+				/* no device there, let's get out of here */
+				*phy_id = 0xffffffff;
+				return 0;
+			}
 		}
 	}
 
-- 
1.8.0

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

end of thread, other threads:[~2015-04-15  8:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-14 10:09 [PATCH v2] net/phy: tune get_phy_c45_ids to support more c45 phy Shengzhou Liu
2015-04-14 17:45 ` Florian Fainelli
2015-04-15  8:27   ` Shengzhou.Liu
2015-04-15  8:27     ` Shengzhou.Liu
  -- strict thread matches above, loose matches on Subject: below --
2014-04-24  8:22 Shengzhou Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.