netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peng Li <lipeng321@huawei.com>
To: <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linuxarm@huawei.com>, <salil.mehta@huawei.com>,
	<lipeng321@huawei.com>
Subject: [PATCH net-next 3/5] net: hns3: add ethtool -p support for phy device
Date: Thu, 18 Jan 2018 15:13:50 +0800	[thread overview]
Message-ID: <1516259632-85088-4-git-send-email-lipeng321@huawei.com> (raw)
In-Reply-To: <1516259632-85088-1-git-send-email-lipeng321@huawei.com>

From: Jian Shen <shenjian15@huawei.com>

Add led location support for phy device. The led will keep blinking
with frequency 2HZ when locating.

Signed-off-by: Jian Shen <shenjian15@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h        |  2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 12 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c    | 88 ++++++++++++++++++++++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h    | 12 +++
 4 files changed, 114 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index d104ce5..fd06bc7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -405,6 +405,8 @@ struct hnae3_ae_ops {
 	int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
 	void (*get_flowctrl_adv)(struct hnae3_handle *handle,
 				 u32 *flowctrl_adv);
+	int (*set_led_id)(struct hnae3_handle *handle,
+			  enum ethtool_phys_id_state status);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 1c8b293..7410205 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -1084,6 +1084,17 @@ static void hns3_get_regs(struct net_device *netdev,
 	h->ae_algo->ops->get_regs(h, &cmd->version, data);
 }
 
+static int hns3_set_phys_id(struct net_device *netdev,
+			    enum ethtool_phys_id_state state)
+{
+	struct hnae3_handle *h = hns3_get_handle(netdev);
+
+	if (!h->ae_algo || !h->ae_algo->ops || !h->ae_algo->ops->set_led_id)
+		return -EOPNOTSUPP;
+
+	return h->ae_algo->ops->set_led_id(h, state);
+}
+
 static const struct ethtool_ops hns3vf_ethtool_ops = {
 	.get_drvinfo = hns3_get_drvinfo,
 	.get_ringparam = hns3_get_ringparam,
@@ -1126,6 +1137,7 @@ static const struct ethtool_ops hns3_ethtool_ops = {
 	.set_coalesce = hns3_set_coalesce,
 	.get_regs_len = hns3_get_regs_len,
 	.get_regs = hns3_get_regs,
+	.set_phys_id = hns3_set_phys_id,
 };
 
 void hns3_ethtool_set_ops(struct net_device *netdev)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 6e64bed..73caf06 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5819,6 +5819,93 @@ static void hclge_get_regs(struct hnae3_handle *handle, u32 *version,
 			"Get 64 bit register failed, ret = %d.\n", ret);
 }
 
+static int hclge_set_led_status_phy(struct phy_device *phydev, int value)
+{
+	int ret, cur_page;
+
+	mutex_lock(&phydev->lock);
+
+	ret = phy_read(phydev, HCLGE_PHY_PAGE_REG);
+	if (ret < 0)
+		goto out;
+	else
+		cur_page = ret;
+
+	ret = phy_write(phydev, HCLGE_PHY_PAGE_REG, HCLGE_PHY_PAGE_LED);
+	if (ret)
+		goto out;
+
+	ret = phy_write(phydev, HCLGE_LED_FC_REG, value);
+	if (ret)
+		goto out;
+
+	ret = phy_write(phydev, HCLGE_PHY_PAGE_REG, cur_page);
+
+out:
+	mutex_unlock(&phydev->lock);
+	return ret;
+}
+
+static int hclge_get_led_status_phy(struct phy_device *phydev, int *value)
+{
+	int ret, cur_page;
+
+	mutex_lock(&phydev->lock);
+
+	ret = phy_read(phydev, HCLGE_PHY_PAGE_REG);
+	if (ret < 0)
+		goto out;
+	else
+		cur_page = ret;
+
+	ret = phy_write(phydev, HCLGE_PHY_PAGE_REG, HCLGE_PHY_PAGE_LED);
+	if (ret)
+		goto out;
+
+	*value = phy_read(phydev, HCLGE_LED_FC_REG);
+
+	ret = phy_write(phydev, HCLGE_PHY_PAGE_REG, cur_page);
+
+out:
+	mutex_unlock(&phydev->lock);
+	return ret;
+}
+
+static int hclge_set_led_id(struct hnae3_handle *handle,
+			    enum ethtool_phys_id_state status)
+{
+#define BLINK_FREQUENCY		2
+	struct hclge_vport *vport = hclge_get_vport(handle);
+	struct hclge_dev *hdev = vport->back;
+	struct phy_device *phydev = hdev->hw.mac.phydev;
+	int ret = 0;
+
+	if (!phydev)
+		return -EOPNOTSUPP;
+
+	switch (status) {
+	case ETHTOOL_ID_ACTIVE:
+		ret = hclge_get_led_status_phy(phydev, &hdev->phy_led_val);
+		if (ret)
+			return ret;
+		return BLINK_FREQUENCY;
+	case ETHTOOL_ID_ON:
+		ret = hclge_set_led_status_phy(phydev, HCLGE_LED_FORCE_ON);
+		break;
+	case ETHTOOL_ID_OFF:
+		ret = hclge_set_led_status_phy(phydev, HCLGE_LED_FORCE_OFF);
+		break;
+	case ETHTOOL_ID_INACTIVE:
+		ret = hclge_set_led_status_phy(phydev, hdev->phy_led_val);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
 static const struct hnae3_ae_ops hclge_ops = {
 	.init_ae_dev = hclge_init_ae_dev,
 	.uninit_ae_dev = hclge_uninit_ae_dev,
@@ -5872,6 +5959,7 @@ static const struct hnae3_ae_ops hclge_ops = {
 	.get_flowctrl_adv = hclge_get_flowctrl_adv,
 	.get_regs_len = hclge_get_regs_len,
 	.get_regs = hclge_get_regs,
+	.set_led_id = hclge_set_led_id,
 };
 
 static struct hnae3_ae_algo ae_algo = {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index eeb6c8d..9969d3c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -63,6 +63,7 @@
 
 #define HCLGE_PHY_PAGE_MDIX		0
 #define HCLGE_PHY_PAGE_COPPER		0
+#define HCLGE_PHY_PAGE_LED		3
 
 /* Page Selection Reg. */
 #define HCLGE_PHY_PAGE_REG		22
@@ -73,6 +74,15 @@
 /* Copper Specific Status Register */
 #define HCLGE_PHY_CSS_REG		17
 
+/* LED Function Control Register */
+#define HCLGE_LED_FC_REG		16
+
+/* LED Polarity Control Register */
+#define HCLGE_LED_PC_REG		17
+
+#define HCLGE_LED_FORCE_ON		9
+#define HCLGE_LED_FORCE_OFF		8
+
 #define HCLGE_PHY_MDIX_CTRL_S		(5)
 #define HCLGE_PHY_MDIX_CTRL_M		GENMASK(6, 5)
 
@@ -550,6 +560,8 @@ struct hclge_dev {
 	bool accept_mta_mc; /* Whether accept mta filter multicast */
 
 	struct hclge_vlan_type_cfg vlan_type_cfg;
+
+	int phy_led_val;
 };
 
 /* VPort level vlan tag configuration for TX direction */
-- 
2.9.3

  parent reply	other threads:[~2018-01-18  7:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-18  7:13 [PATCH net-next 0/5] add some features to hns3 driver Peng Li
2018-01-18  7:13 ` [PATCH net-next 1/5] net: hns3: add support for get_regs Peng Li
2018-01-18  7:13 ` [PATCH net-next 2/5] net: hns3: add manager table initialization for hardware Peng Li
2018-01-18  7:13 ` Peng Li [this message]
2018-01-18 14:25   ` [PATCH net-next 3/5] net: hns3: add ethtool -p support for phy device Andrew Lunn
2018-01-19  2:50     ` lipeng (Y)
2018-01-18  7:13 ` [PATCH net-next 4/5] net: hns3: add ethtool -p support for fiber port Peng Li
2018-01-18  7:13 ` [PATCH net-next 5/5] net: hns3: add net status led " Peng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1516259632-85088-4-git-send-email-lipeng321@huawei.com \
    --to=lipeng321@huawei.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=salil.mehta@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).