Received: by 10.223.148.5 with SMTP id 5csp6987213wrq; Wed, 17 Jan 2018 22:46:08 -0800 (PST) X-Google-Smtp-Source: ACJfBovcso3ZJYfKqHsaYw+ywuKPDvQbrVNUiD57uLUU7R4t6PWgak4jfT7Za0jROdPDOrvyoXGK X-Received: by 10.98.254.21 with SMTP id z21mr11052119pfh.48.1516257967971; Wed, 17 Jan 2018 22:46:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516257967; cv=none; d=google.com; s=arc-20160816; b=Kx3OimZ4hyTlRpzQSK1qaou+2G97M+8h/RKzeerLi0GzADn7XEgjDLwl/w0CgsVQGR taLC/hxUva8Qug55cEw++vYtGtxHUHWnlH0VKygJWHe+hhKAyoBUiJ4rjttAkhpU2znl 4BTFXy25Z4zF+p0Lbt3dBCnASLTCkkuoPp+PYG2pmrnItUU688ehsBc1VB/82v74ONlZ Gt90eCxm4Lxvr7bpD6HS7OE7ywHRr6VrduCC/uS3RI5gKIqvRxCxgaIfTXrvybtFQ26r 0HapjdiQtjpV5oFDmj5qW0PMjy0+QuPe570FC8PygKKFbVjh8o6NtgIJLrxvxqTw3QXp D1lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=E4CulXsFjLisfx774QSct1DJbLAZDh18jbmxqCXgq6Q=; b=kPytdg9GeshMFKq8jjyFX2JGu/3qAeTNkXYFjj7p1qkfh+noARkDz5NGCHnx+1+7FT hPHvm3o36YjI6N65Val0eb4VvGO/JNyM2QZRjSZnLdxW5P3ft5cnTixltxVCeQv/FOyr SdHNtSjiqFdcMpbjDasV9anIf3Flb8Myh4G5UxLPzdHf4Z9ljAgdo3h91/6Re6k3Qksr aGabQdSxn9v10J3CTpz2XPBxlR29+vzrr9akHz2hyvr2VYCRvvjBjwSvxAdzeIzvATZf zhJtLvZoEm2TlYL5bdttWQaw88f6Cb2S7TGQPSy+BgzHdUDg0nh1I2SfeP39MlcBnx8x l6Sg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a11si6472513plt.567.2018.01.17.22.45.54; Wed, 17 Jan 2018 22:46:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754771AbeARGpI (ORCPT + 99 others); Thu, 18 Jan 2018 01:45:08 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:4253 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753011AbeARGpD (ORCPT ); Thu, 18 Jan 2018 01:45:03 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 649C0C45EBD86; Thu, 18 Jan 2018 14:44:49 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Thu, 18 Jan 2018 14:44:44 +0800 From: Peng Li To: CC: , , , , Subject: [PATCH net-next 3/5] net: hns3: add ethtool -p support for phy device Date: Thu, 18 Jan 2018 15:13:50 +0800 Message-ID: <1516259632-85088-4-git-send-email-lipeng321@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1516259632-85088-1-git-send-email-lipeng321@huawei.com> References: <1516259632-85088-1-git-send-email-lipeng321@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jian Shen Add led location support for phy device. The led will keep blinking with frequency 2HZ when locating. Signed-off-by: Jian Shen Signed-off-by: Peng Li --- 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