Patchwork [net-next,2/4] net: ethtool: add the EEE support

login
register
mail settings
Submitter Giuseppe CAVALLARO
Date March 6, 2012, 8:28 a.m.
Message ID <1331022494-12891-3-git-send-email-peppe.cavallaro@st.com>
Download mbox | patch
Permalink /patch/144864/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Giuseppe CAVALLARO - March 6, 2012, 8:28 a.m.
This patch adds two new functions to detect if Energy-Efficient
Ethernet (EEE) is supported and the way to enable/disable it.

Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
---
 include/linux/ethtool.h |    7 +++++++
 net/core/ethtool.c      |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)
Ben Hutchings - March 6, 2012, 4:56 p.m.
On Tue, 2012-03-06 at 09:28 +0100, Giuseppe CAVALLARO wrote:
> This patch adds two new functions to detect if Energy-Efficient
> Ethernet (EEE) is supported and the way to enable/disable it.
[...]

You haven't fixed any of the problems in the previous version of this
patch.

Ben.
Giuseppe CAVALLARO - March 8, 2012, 3:14 p.m.
Hello Ben

On 3/6/2012 5:56 PM, Ben Hutchings wrote:
> On Tue, 2012-03-06 at 09:28 +0100, Giuseppe CAVALLARO wrote:
>> This patch adds two new functions to detect if Energy-Efficient
>> Ethernet (EEE) is supported and the way to enable/disable it.
> [...]
> 
> You haven't fixed any of the problems in the previous version of this
> patch.

Yes you are right,  sorry :-(

Below there is what you suggested and inline my comments.

Welcome advice!

On 2/29/2012 6:00 PM, Ben Hutchings wrote:

> It is certainly necessary to distinguish:
> a. PHY is advertising EEE
> from
> b. Link partner is advertising EEE
> or
> c. EEE will be used (= a && b)

you are perfectly right and indeed I wanted to do that.

> I haven't had anything to do with PHY drivers for a while but it looks
> like you should be able to map MDIO register 3.20 to supported flags,
> 7.60 to advertising and 7.61 to lp_advertising.

I have added a function named:

    phy_check_eee

For example, the stmmac driver (only if its HW core supports the EEE
feature) calls the phy_check_eee to understand if the the points a) and
b) above are satisfied.

On the Ethtool side, within the driver the .get_eee will pass to the
user-space if the EEE is used (just point c).
The .set_eee should used to force the MAC to disable/enable the EEE (if
actually supported by MAC+PHY).
I had added this option because the Synopsys GMAC manages the TX LPI
path through a SW timer :-( that in this case can be disabled via ethtool.
Indeed, no action should be taken by the user for the PHY side.
The only thing that could be changed is the clock stop enable bit (3.0.10).

What do you think?

Peppe

>
> Even if your particular device doesn't support these MDIO registers,
> other devices will.  So I think you should define the flags and then if
> you don't have that fine control you should check in your set_settings
> implementation that the advertising value either has all the EEE mode
> flags clear or has all the modes the hardware supports set.
>
> Ben.
>




> Ben.
> 

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index e1d9e0e..8aed0dd 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -48,6 +48,7 @@  struct ethtool_cmd {
 	__u8	eth_tp_mdix;
 	__u8	reserved2;
 	__u32	lp_advertising;	/* Features the link partner advertises */
+	__u32	eee;		/* Energy-Efficient Etehrnet */
 	__u32	reserved[2];
 };
 
@@ -893,6 +894,8 @@  static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)
  * 		   and flag of the device.
  * @get_dump_data: Get dump data.
  * @set_dump: Set dump specific flags to the device.
+ * @get_eee: Get Energy-Efficient Ethernet (EEE) supported and status.
+ * @set_eee: Set EEE status (enable/disable).
  *
  * All operations are optional (i.e. the function pointer may be set
  * to %NULL) and callers must take this into account.  Callers must
@@ -956,6 +959,8 @@  struct ethtool_ops {
 				 struct ethtool_dump *, void *);
 	int	(*set_dump)(struct net_device *, struct ethtool_dump *);
 
+	int	(*get_eee) (struct net_device *, struct ethtool_value *);
+	int	(*set_eee) (struct net_device *, struct ethtool_value *);
 };
 #endif /* __KERNEL__ */
 
@@ -1029,6 +1034,8 @@  struct ethtool_ops {
 #define ETHTOOL_SET_DUMP	0x0000003e /* Set dump settings */
 #define ETHTOOL_GET_DUMP_FLAG	0x0000003f /* Get dump settings */
 #define ETHTOOL_GET_DUMP_DATA	0x00000040 /* Get dump data */
+#define ETHTOOL_GEEE		0x00000041 /* Get EEE */
+#define ETHTOOL_SEEE		0x00000042 /* Set EEE */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 6d6d7d2..f47075e 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -716,6 +716,32 @@  static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
 	return dev->ethtool_ops->set_wol(dev, &wol);
 }
 
+static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
+{
+	struct ethtool_value edata;
+
+	if (!dev->ethtool_ops->get_eee)
+		return -EOPNOTSUPP;
+
+	dev->ethtool_ops->get_eee(dev, &edata);
+
+	if (copy_to_user(useraddr, &edata, sizeof(edata)))
+		return -EFAULT;
+	return 0;
+}
+
+static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
+{
+	struct ethtool_value edata;
+
+	if (!dev->ethtool_ops->set_eee)
+		return -EOPNOTSUPP;
+
+	if (copy_from_user(&edata, useraddr, sizeof(edata)))
+		return -EFAULT;
+
+	return dev->ethtool_ops->set_eee(dev, &edata);
+}
 static int ethtool_nway_reset(struct net_device *dev)
 {
 	if (!dev->ethtool_ops->nway_reset)
@@ -1370,6 +1396,12 @@  int dev_ethtool(struct net *net, struct ifreq *ifr)
 		rc = ethtool_set_value_void(dev, useraddr,
 				       dev->ethtool_ops->set_msglevel);
 		break;
+	case ETHTOOL_GEEE:
+		rc = ethtool_get_eee(dev, useraddr);
+		break;
+	case ETHTOOL_SEEE:
+		rc = ethtool_set_eee(dev, useraddr);
+		break;
 	case ETHTOOL_NWAY_RST:
 		rc = ethtool_nway_reset(dev);
 		break;