All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support
@ 2015-02-23 16:26 Guenter Roeck
  2015-02-23 16:26 ` [RFT PATCH 2/2] net: dsa: mv88e6352: Add support for EEE Guenter Roeck
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Guenter Roeck @ 2015-02-23 16:26 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, linux-kernel,
	Guenter Roeck

EEE configuration is similar for the various MV88E6xxx chips.
Add generic support for it.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Applies to net-next.

The code seems to be working, at least according to ethtool, but some
more testing with other chip types would be useful. Also, I am not sure
what to do with phy_init_eee.

 drivers/net/dsa/mv88e6xxx.c | 55 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/mv88e6xxx.h |  3 +++
 2 files changed, 58 insertions(+)

diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index a83ace0..2d5306a 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -649,6 +649,61 @@ int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
 	return mv88e6xxx_phy_wait(ds);
 }
 
+int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
+{
+	int reg;
+
+	reg = mv88e6xxx_phy_read_indirect(ds, port, 16);
+	if (reg < 0)
+		return -EOPNOTSUPP;
+
+	e->eee_enabled = !!(reg & 0x0200);
+	e->tx_lpi_enabled = !!(reg & 0x0100);
+
+	reg = REG_READ(REG_PORT(port), 0);
+	e->eee_active = !!(reg & 0x0040);
+
+	return 0;
+}
+
+static int mv88e6xxx_eee_enable_set(struct dsa_switch *ds, int port,
+				    bool eee_enabled, bool tx_lpi_enabled)
+{
+	int reg, nreg;
+
+	/* Don't call phy_init_eee for now. It fails if the link is down,
+	 * but that should not really be a reason to fail configuration.
+	 */
+
+	reg = mv88e6xxx_phy_read_indirect(ds, port, 16);
+	if (reg < 0)
+		return reg;
+
+	nreg = reg & ~0x0300;
+	if (eee_enabled)
+		nreg |= 0x0200;
+	if (tx_lpi_enabled)
+		nreg |= 0x0100;
+
+	if (nreg != reg)
+		return mv88e6xxx_phy_write_indirect(ds, port, 16, nreg);
+
+	return 0;
+}
+
+int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
+		      struct phy_device *phydev, struct ethtool_eee *e)
+{
+	int ret;
+
+	ret = mv88e6xxx_eee_enable_set(ds, port, e->eee_enabled,
+				       e->tx_lpi_enabled);
+	if (ret)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
 static int __init mv88e6xxx_init(void)
 {
 #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131)
diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h
index 7294227..5fd42ce 100644
--- a/drivers/net/dsa/mv88e6xxx.h
+++ b/drivers/net/dsa/mv88e6xxx.h
@@ -88,6 +88,9 @@ int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds);
 int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum);
 int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
 				 u16 val);
+int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
+int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
+		      struct phy_device *phydev, struct ethtool_eee *e);
 
 extern struct dsa_switch_driver mv88e6131_switch_driver;
 extern struct dsa_switch_driver mv88e6123_61_65_switch_driver;
-- 
2.1.0


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

* [RFT PATCH 2/2] net: dsa: mv88e6352: Add support for EEE
  2015-02-23 16:26 [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Guenter Roeck
@ 2015-02-23 16:26 ` Guenter Roeck
  2015-02-23 17:45 ` [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Florian Fainelli
  2015-02-23 22:19 ` David Miller
  2 siblings, 0 replies; 8+ messages in thread
From: Guenter Roeck @ 2015-02-23 16:26 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Andrew Lunn, Florian Fainelli, linux-kernel,
	Guenter Roeck

Enable EEE support for MV88E6352.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Applies to net-next.

Support for other chips using the mv88e6xxx code can be added
with similar patches.

 drivers/net/dsa/mv88e6352.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/dsa/mv88e6352.c b/drivers/net/dsa/mv88e6352.c
index 1ebd8f9..7bc5998 100644
--- a/drivers/net/dsa/mv88e6352.c
+++ b/drivers/net/dsa/mv88e6352.c
@@ -717,6 +717,8 @@ struct dsa_switch_driver mv88e6352_switch_driver = {
 	.get_strings		= mv88e6352_get_strings,
 	.get_ethtool_stats	= mv88e6352_get_ethtool_stats,
 	.get_sset_count		= mv88e6352_get_sset_count,
+	.set_eee		= mv88e6xxx_set_eee,
+	.get_eee		= mv88e6xxx_get_eee,
 #ifdef CONFIG_NET_DSA_HWMON
 	.get_temp		= mv88e6352_get_temp,
 	.get_temp_limit		= mv88e6352_get_temp_limit,
-- 
2.1.0


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

* Re: [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support
  2015-02-23 16:26 [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Guenter Roeck
  2015-02-23 16:26 ` [RFT PATCH 2/2] net: dsa: mv88e6352: Add support for EEE Guenter Roeck
@ 2015-02-23 17:45 ` Florian Fainelli
  2015-02-23 18:52   ` Guenter Roeck
  2015-02-23 22:19 ` David Miller
  2 siblings, 1 reply; 8+ messages in thread
From: Florian Fainelli @ 2015-02-23 17:45 UTC (permalink / raw)
  To: Guenter Roeck, netdev; +Cc: David S. Miller, Andrew Lunn, linux-kernel

On 23/02/15 08:26, Guenter Roeck wrote:
> EEE configuration is similar for the various MV88E6xxx chips.
> Add generic support for it.
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>

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

> ---
> Applies to net-next.
> 
> The code seems to be working, at least according to ethtool, but some
> more testing with other chip types would be useful. Also, I am not sure
> what to do with phy_init_eee.

phy_init_eee() is to be used in case you have a PHY which is not managed
by the switch indirect or direct accesses, it looks like you are just
fine with the current code.

One possible improvement could be ironing out the EEE
enabling/resolution by ensuring that the link partner also supports EEE?
Not sure if there is an existing register returning that from the
switch, or if you need to do a direct read to the PHY?

> 
>  drivers/net/dsa/mv88e6xxx.c | 55 +++++++++++++++++++++++++++++++++++++++++++++
>  drivers/net/dsa/mv88e6xxx.h |  3 +++
>  2 files changed, 58 insertions(+)
> 
> diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
> index a83ace0..2d5306a 100644
> --- a/drivers/net/dsa/mv88e6xxx.c
> +++ b/drivers/net/dsa/mv88e6xxx.c
> @@ -649,6 +649,61 @@ int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
>  	return mv88e6xxx_phy_wait(ds);
>  }
>  
> +int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
> +{
> +	int reg;
> +
> +	reg = mv88e6xxx_phy_read_indirect(ds, port, 16);
> +	if (reg < 0)
> +		return -EOPNOTSUPP;
> +
> +	e->eee_enabled = !!(reg & 0x0200);
> +	e->tx_lpi_enabled = !!(reg & 0x0100);
> +
> +	reg = REG_READ(REG_PORT(port), 0);
> +	e->eee_active = !!(reg & 0x0040);
> +
> +	return 0;
> +}
> +
> +static int mv88e6xxx_eee_enable_set(struct dsa_switch *ds, int port,
> +				    bool eee_enabled, bool tx_lpi_enabled)
> +{
> +	int reg, nreg;
> +
> +	/* Don't call phy_init_eee for now. It fails if the link is down,
> +	 * but that should not really be a reason to fail configuration.
> +	 */
> +
> +	reg = mv88e6xxx_phy_read_indirect(ds, port, 16);
> +	if (reg < 0)
> +		return reg;
> +
> +	nreg = reg & ~0x0300;
> +	if (eee_enabled)
> +		nreg |= 0x0200;
> +	if (tx_lpi_enabled)
> +		nreg |= 0x0100;
> +
> +	if (nreg != reg)
> +		return mv88e6xxx_phy_write_indirect(ds, port, 16, nreg);
> +
> +	return 0;
> +}
> +
> +int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
> +		      struct phy_device *phydev, struct ethtool_eee *e)
> +{
> +	int ret;
> +
> +	ret = mv88e6xxx_eee_enable_set(ds, port, e->eee_enabled,
> +				       e->tx_lpi_enabled);
> +	if (ret)
> +		return -EOPNOTSUPP;
> +
> +	return 0;
> +}
> +
>  static int __init mv88e6xxx_init(void)
>  {
>  #if IS_ENABLED(CONFIG_NET_DSA_MV88E6131)
> diff --git a/drivers/net/dsa/mv88e6xxx.h b/drivers/net/dsa/mv88e6xxx.h
> index 7294227..5fd42ce 100644
> --- a/drivers/net/dsa/mv88e6xxx.h
> +++ b/drivers/net/dsa/mv88e6xxx.h
> @@ -88,6 +88,9 @@ int mv88e6xxx_eeprom_busy_wait(struct dsa_switch *ds);
>  int mv88e6xxx_phy_read_indirect(struct dsa_switch *ds, int addr, int regnum);
>  int mv88e6xxx_phy_write_indirect(struct dsa_switch *ds, int addr, int regnum,
>  				 u16 val);
> +int mv88e6xxx_get_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
> +int mv88e6xxx_set_eee(struct dsa_switch *ds, int port,
> +		      struct phy_device *phydev, struct ethtool_eee *e);
>  
>  extern struct dsa_switch_driver mv88e6131_switch_driver;
>  extern struct dsa_switch_driver mv88e6123_61_65_switch_driver;
> 


-- 
Florian

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

* Re: [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support
  2015-02-23 17:45 ` [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Florian Fainelli
@ 2015-02-23 18:52   ` Guenter Roeck
  2015-02-23 21:25     ` Florian Fainelli
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2015-02-23 18:52 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: netdev, David S. Miller, Andrew Lunn, linux-kernel

On Mon, Feb 23, 2015 at 09:45:01AM -0800, Florian Fainelli wrote:
> On 23/02/15 08:26, Guenter Roeck wrote:
> > EEE configuration is similar for the various MV88E6xxx chips.
> > Add generic support for it.
> > 
> > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> 
> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
> 
> > ---
> > Applies to net-next.
> > 
> > The code seems to be working, at least according to ethtool, but some
> > more testing with other chip types would be useful. Also, I am not sure
> > what to do with phy_init_eee.
> 
> phy_init_eee() is to be used in case you have a PHY which is not managed
> by the switch indirect or direct accesses, it looks like you are just
> fine with the current code.
> 
> One possible improvement could be ironing out the EEE
> enabling/resolution by ensuring that the link partner also supports EEE?
> Not sure if there is an existing register returning that from the
> switch, or if you need to do a direct read to the PHY?
> 

EEE configuration on Marvell switches is independent from link partner
capabilities. In the hardware available to me, EEE is enabled by
default with a strapping pin on the chip. Making it dependent on link
partner capabilities would be odd because it would mean that, if the
link is down or if the link partner doesn't support it, it could be
disabled, but it could no longer be re-enabled. This is what
phy_init_eee enforces today. I dropped calling it because I thought
that this behavior would be odd and inconsistent.

Question for me is if it makes sense to have phy_init_eee depend on
the link status or on link partner capabilities in the first place.
Personally I think it should only depend on local PHY capabilities,
and that it should be possible to configure EEE even if the link
is down or if the (current) link partner doesn't support it.

Consider the following: Assume both ends are configured to have EEE
disabled, even if the PHYs support it. Both ends run linux and call
phy_init_eee() to check for EEE capabilities. I have not tested it,
but I suspect that it is not currently possible to enable EEE on either
end because both ends believe that the link partner doesn't support it.
I'll test that theory once I get a system where I can control both ends.

Thanks,
Guenter

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

* Re: [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support
  2015-02-23 18:52   ` Guenter Roeck
@ 2015-02-23 21:25     ` Florian Fainelli
  0 siblings, 0 replies; 8+ messages in thread
From: Florian Fainelli @ 2015-02-23 21:25 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: netdev, David S. Miller, Andrew Lunn, linux-kernel

On 23/02/15 10:52, Guenter Roeck wrote:
> On Mon, Feb 23, 2015 at 09:45:01AM -0800, Florian Fainelli wrote:
>> On 23/02/15 08:26, Guenter Roeck wrote:
>>> EEE configuration is similar for the various MV88E6xxx chips.
>>> Add generic support for it.
>>>
>>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>>
>> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
>>
>>> ---
>>> Applies to net-next.
>>>
>>> The code seems to be working, at least according to ethtool, but some
>>> more testing with other chip types would be useful. Also, I am not sure
>>> what to do with phy_init_eee.
>>
>> phy_init_eee() is to be used in case you have a PHY which is not managed
>> by the switch indirect or direct accesses, it looks like you are just
>> fine with the current code.
>>
>> One possible improvement could be ironing out the EEE
>> enabling/resolution by ensuring that the link partner also supports EEE?
>> Not sure if there is an existing register returning that from the
>> switch, or if you need to do a direct read to the PHY?
>>
> 
> EEE configuration on Marvell switches is independent from link partner
> capabilities. In the hardware available to me, EEE is enabled by
> default with a strapping pin on the chip. Making it dependent on link
> partner capabilities would be odd because it would mean that, if the
> link is down or if the link partner doesn't support it, it could be
> disabled, but it could no longer be re-enabled. This is what
> phy_init_eee enforces today. I dropped calling it because I thought
> that this behavior would be odd and inconsistent.
> 
> Question for me is if it makes sense to have phy_init_eee depend on
> the link status or on link partner capabilities in the first place.
> Personally I think it should only depend on local PHY capabilities,
> and that it should be possible to configure EEE even if the link
> is down or if the (current) link partner doesn't support it.

Completely agree with that.

BTW, the clock stop thing is also poorly handled imho because you would
want the PHY library to tell you whether your PHY supports TX clock
stopping, and not having to discover that by doing a first call with
phy_init_eee(phydev, 1), see that it fails, retry with
phy_init_eee(phydev, 0), but that's for another series of patches:

https://github.com/ffainelli/linux/tree/phy-eee-tx-clk

> 
> Consider the following: Assume both ends are configured to have EEE
> disabled, even if the PHYs support it. Both ends run linux and call
> phy_init_eee() to check for EEE capabilities. I have not tested it,
> but I suspect that it is not currently possible to enable EEE on either
> end because both ends believe that the link partner doesn't support it.
> I'll test that theory once I get a system where I can control both ends.

Well, it will work the first time you enable EEE and all of these
conditions are met: link is negotiated, your PHY reports EEE capability,
your link partner advertises EEE, and subsequent link up/down events
should maintain EEE operation. I agree that this needs revisiting
because you would certainly want to advertise EEE all the time if you
support it and have configured it, and enable it as soon as you find a
link partner that can also support EEE.
-- 
Florian

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

* Re: [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support
  2015-02-23 16:26 [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Guenter Roeck
  2015-02-23 16:26 ` [RFT PATCH 2/2] net: dsa: mv88e6352: Add support for EEE Guenter Roeck
  2015-02-23 17:45 ` [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Florian Fainelli
@ 2015-02-23 22:19 ` David Miller
  2015-02-24  2:29   ` Guenter Roeck
  2 siblings, 1 reply; 8+ messages in thread
From: David Miller @ 2015-02-23 22:19 UTC (permalink / raw)
  To: linux; +Cc: netdev, andrew, f.fainelli, linux-kernel

From: Guenter Roeck <linux@roeck-us.net>
Date: Mon, 23 Feb 2015 08:26:09 -0800

> +	/* Don't call phy_init_eee for now. It fails if the link is down,
> +	 * but that should not really be a reason to fail configuration.
> +	 */

I think there is some confusion about phy_init_eee().

You invoke it after a link has been established.  Because programming
the MDIO registers that turn on EEE can only be done if the link
is configured in a certain way.

If you look at stmmac, it invokes phy_init_eee() via it's adjust_link
callback passed to phy_connect().  This is basically how I would
expect it to be used, in that any time a link parameter changes we
rerun phy_init_eee() to check the link partner registers, duplex
state, etc.

SXGBE on the other hand seems to not be using phy_init_eee() properly,
it only invokes it once per device open and that makes no sense at all
because then you're stuck with the eee state resulting from the link
state at open time.

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

* Re: [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support
  2015-02-23 22:19 ` David Miller
@ 2015-02-24  2:29   ` Guenter Roeck
  2015-02-24  2:34     ` Florian Fainelli
  0 siblings, 1 reply; 8+ messages in thread
From: Guenter Roeck @ 2015-02-24  2:29 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, andrew, f.fainelli, linux-kernel

On 02/23/2015 02:19 PM, David Miller wrote:
> From: Guenter Roeck <linux@roeck-us.net>
> Date: Mon, 23 Feb 2015 08:26:09 -0800
>
>> +	/* Don't call phy_init_eee for now. It fails if the link is down,
>> +	 * but that should not really be a reason to fail configuration.
>> +	 */
>
> I think there is some confusion about phy_init_eee().
>
> You invoke it after a link has been established.  Because programming
> the MDIO registers that turn on EEE can only be done if the link
> is configured in a certain way.
>
> If you look at stmmac, it invokes phy_init_eee() via it's adjust_link
> callback passed to phy_connect().  This is basically how I would
> expect it to be used, in that any time a link parameter changes we
> rerun phy_init_eee() to check the link partner registers, duplex
> state, etc.
>
> SXGBE on the other hand seems to not be using phy_init_eee() properly,
> it only invokes it once per device open and that makes no sense at all
> because then you're stuck with the eee state resulting from the link
> state at open time.
>
That explains a lot. I suspect the use in bcm_sf2 and bcmgenet is also
not as intended.

Thanks,
Guenter


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

* Re: [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support
  2015-02-24  2:29   ` Guenter Roeck
@ 2015-02-24  2:34     ` Florian Fainelli
  0 siblings, 0 replies; 8+ messages in thread
From: Florian Fainelli @ 2015-02-24  2:34 UTC (permalink / raw)
  To: Guenter Roeck, David Miller; +Cc: netdev, andrew, linux-kernel

On 23/02/15 18:29, Guenter Roeck wrote:
> On 02/23/2015 02:19 PM, David Miller wrote:
>> From: Guenter Roeck <linux@roeck-us.net>
>> Date: Mon, 23 Feb 2015 08:26:09 -0800
>>
>>> +    /* Don't call phy_init_eee for now. It fails if the link is down,
>>> +     * but that should not really be a reason to fail configuration.
>>> +     */
>>
>> I think there is some confusion about phy_init_eee().
>>
>> You invoke it after a link has been established.  Because programming
>> the MDIO registers that turn on EEE can only be done if the link
>> is configured in a certain way.
>>
>> If you look at stmmac, it invokes phy_init_eee() via it's adjust_link
>> callback passed to phy_connect().  This is basically how I would
>> expect it to be used, in that any time a link parameter changes we
>> rerun phy_init_eee() to check the link partner registers, duplex
>> state, etc.
>>
>> SXGBE on the other hand seems to not be using phy_init_eee() properly,
>> it only invokes it once per device open and that makes no sense at all
>> because then you're stuck with the eee state resulting from the link
>> state at open time.
>>
> That explains a lot. I suspect the use in bcm_sf2 and bcmgenet is also
> not as intended.

Yes, it certainly needs fixing.
-- 
Florian

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

end of thread, other threads:[~2015-02-24  2:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-23 16:26 [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Guenter Roeck
2015-02-23 16:26 ` [RFT PATCH 2/2] net: dsa: mv88e6352: Add support for EEE Guenter Roeck
2015-02-23 17:45 ` [RFT PATCH 1/2] net: dsa: mv88e6xxx: Add EEE support Florian Fainelli
2015-02-23 18:52   ` Guenter Roeck
2015-02-23 21:25     ` Florian Fainelli
2015-02-23 22:19 ` David Miller
2015-02-24  2:29   ` Guenter Roeck
2015-02-24  2:34     ` Florian Fainelli

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.