[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1465798076-176393-3-git-send-email-lidongpo@hisilicon.com>
Date: Mon, 13 Jun 2016 14:07:55 +0800
From: Dongpo Li <lidongpo@...ilicon.com>
To: <f.fainelli@...il.com>, <robh+dt@...nel.org>,
<mark.rutland@....com>, <davem@...emloft.net>
CC: <xuejiancheng@...ilicon.com>, <netdev@...r.kernel.org>,
<devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
Dongpo Li <lidongpo@...ilicon.com>
Subject: [PATCH 2/3] ethtool: Add common functions for get and set settings
Currently, most drivers only support get and set PHY settings
by PHY ethtool API. For those drivers, it's better to
supply common functions for get_settings and set_settings.
This patch adds common functions implementation.
Reviewed-by: Jiancheng Xue <xuejiancheng@...ilicon.com>
Signed-off-by: Dongpo Li <lidongpo@...ilicon.com>
---
include/linux/ethtool.h | 2 ++
net/core/ethtool.c | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 9ded8c6..e114db9 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -82,6 +82,8 @@ struct net_device;
/* Some generic methods drivers may use in their ethtool_ops */
u32 ethtool_op_get_link(struct net_device *dev);
int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *eti);
+int ethtool_op_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
+int ethtool_op_set_settings(struct net_device *dev, struct ethtool_cmd *cmd);
/**
* ethtool_rxfh_indir_default - get default value for RX flow hash indirection
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index f403481..270b6d1 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -50,6 +50,27 @@ int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
}
EXPORT_SYMBOL(ethtool_op_get_ts_info);
+int ethtool_op_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+ if (!dev->phydev)
+ return -ENODEV;
+
+ return phy_ethtool_gset(dev->phydev, cmd);
+}
+EXPORT_SYMBOL(ethtool_op_get_settings);
+
+int ethtool_op_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+ if (!capable(CAP_NET_ADMIN))
+ return -EPERM;
+
+ if (!dev->phydev)
+ return -ENODEV;
+
+ return phy_ethtool_sset(dev->phydev, cmd);
+}
+EXPORT_SYMBOL(ethtool_op_set_settings);
+
/* Handlers for each ethtool command */
#define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
--
2.8.2
Powered by blists - more mailing lists