Received: by 10.223.148.5 with SMTP id 5csp6986824wrq; Wed, 17 Jan 2018 22:45:51 -0800 (PST) X-Google-Smtp-Source: ACJfBouq/eNZbeK3qsVfTXHCl79rEsLwu1zwmbsQ4EDZ5kmQnsTrAi7jQfy3zK8hrr9iqnE64MuU X-Received: by 10.99.114.23 with SMTP id n23mr29026430pgc.407.1516257950991; Wed, 17 Jan 2018 22:45:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516257950; cv=none; d=google.com; s=arc-20160816; b=dm/zaHSDRCohJ6MN+cKYlFDNmowUr3ouIvwKex9uAytlW+FvbzPsDChnXHxxWTP2m5 XMzfdG31PjGRsfhhmqnuSn0Q3gNpT2N+ziE7tQgf+tdg16CN5bTzk4uAysZ+GuOWoDiW CuyWvjzyWk9KGG5nKPVQc8dwluoFQYaxtVmD8d0cC1baOCvKrcuvleXR5cbL66Zy9GOs xcb7jf7sR+JmUCQM2rMOWAvu+baWROPUDrhkrz8DrjcZ80SwiGDb2undSQ++O0NXvvdI dsmacfTWUZ09Ya5vLnmSDbAWqKBMAo04kLgzC9f7yMj5eW0+yPHcg7rR5lCPSmYNWkmN nzqw== 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=fyuGLfMGf8K+HOFTXNfsEgvHZl9QnD8Hkeetch2fegk=; b=LvFzijcXAowzMqqDmlo9jPjKSteiLCate/2czsFD4IXgk+kNbmWuAZ0YujlYWIjDgg 1UnmiZmvRRCsntC9CiwzeYy/NP456ak7t/CqbzJtYzQrTd1yrFCHr4gogw9XaoS/109J e4nvCW/6q/wbpv+FBu57lUvkzHBCFMRdXIxMIK/5BGjZRgk0VdGdukz7HRQYo7YTYMZZ Ya/3fpPpX851BJa5olxELT7SaWjfXWZmeH9Mz66R+kupmp2/iLNVsb8BCEJg5XblJVDy /tCAjwy7qpD99VaQ0qXvlf7nd73Q6Yumw0izdbV7C54q+Nnv1UaBvyyc2icOB1AF8/0v RPuw== 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 z17si6087075plo.794.2018.01.17.22.45.35; Wed, 17 Jan 2018 22:45:50 -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 S1754793AbeARGpJ (ORCPT + 99 others); Thu, 18 Jan 2018 01:45:09 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:4251 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753433AbeARGpE (ORCPT ); Thu, 18 Jan 2018 01:45:04 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 465678537CBEF; 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 4/5] net: hns3: add ethtool -p support for fiber port Date: Thu, 18 Jan 2018 15:13:51 +0800 Message-ID: <1516259632-85088-5-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 fiber port. The led will keep blinking when locating. Signed-off-by: Jian Shen Signed-off-by: Peng Li --- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 20 ++++ .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 101 ++++++++++++++++----- 2 files changed, 100 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h index 1cd28e0..122f862 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h @@ -227,6 +227,9 @@ enum hclge_opcode_type { /* Mailbox cmd */ HCLGEVF_OPC_MBX_PF_TO_VF = 0x2000, + + /* Led command */ + HCLGE_OPC_LED_STATUS_CFG = 0xB000, }; #define HCLGE_TQP_REG_OFFSET 0x80000 @@ -807,6 +810,23 @@ struct hclge_reset_cmd { #define HCLGE_NIC_CMQ_DESC_NUM 1024 #define HCLGE_NIC_CMQ_DESC_NUM_S 3 +#define HCLGE_LED_PORT_SPEED_STATE_S 0 +#define HCLGE_LED_PORT_SPEED_STATE_M GENMASK(5, 0) +#define HCLGE_LED_ACTIVITY_STATE_S 0 +#define HCLGE_LED_ACTIVITY_STATE_M GENMASK(1, 0) +#define HCLGE_LED_LINK_STATE_S 0 +#define HCLGE_LED_LINK_STATE_M GENMASK(1, 0) +#define HCLGE_LED_LOCATE_STATE_S 0 +#define HCLGE_LED_LOCATE_STATE_M GENMASK(1, 0) + +struct hclge_set_led_state_cmd { + u8 port_speed_led_config; + u8 link_led_config; + u8 activity_led_config; + u8 locate_led_config; + u8 rsv[20]; +}; + int hclge_cmd_init(struct hclge_dev *hdev); static inline void hclge_write_reg(void __iomem *base, u32 reg, u32 value) { diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index 73caf06..039c90b 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -5819,6 +5819,34 @@ 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_sfp(struct hclge_dev *hdev, u8 speed_led_status, + u8 act_led_status, u8 link_led_status, + u8 locate_led_status) +{ + struct hclge_set_led_state_cmd *req; + struct hclge_desc desc; + int ret; + + hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_LED_STATUS_CFG, false); + + req = (struct hclge_set_led_state_cmd *)desc.data; + hnae_set_field(req->port_speed_led_config, HCLGE_LED_PORT_SPEED_STATE_M, + HCLGE_LED_PORT_SPEED_STATE_S, speed_led_status); + hnae_set_field(req->link_led_config, HCLGE_LED_ACTIVITY_STATE_M, + HCLGE_LED_ACTIVITY_STATE_S, act_led_status); + hnae_set_field(req->activity_led_config, HCLGE_LED_LINK_STATE_M, + HCLGE_LED_LINK_STATE_S, link_led_status); + hnae_set_field(req->locate_led_config, HCLGE_LED_LOCATE_STATE_M, + HCLGE_LED_LOCATE_STATE_S, locate_led_status); + + ret = hclge_cmd_send(&hdev->hw, &desc, 1); + if (ret) + dev_err(&hdev->pdev->dev, + "Send set led state cmd error, ret =%d\n", ret); + + return ret; +} + static int hclge_set_led_status_phy(struct phy_device *phydev, int value) { int ret, cur_page; @@ -5871,6 +5899,12 @@ static int hclge_get_led_status_phy(struct phy_device *phydev, int *value) return ret; } +enum hclge_led_status { + HCLGE_LED_OFF, + HCLGE_LED_ON, + HCLGE_LED_NO_CHANGE = 0xFF, +}; + static int hclge_set_led_id(struct hnae3_handle *handle, enum ethtool_phys_id_state status) { @@ -5880,27 +5914,52 @@ static int hclge_set_led_id(struct hnae3_handle *handle, 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; + if (phydev) { + 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; + } + } else if (hdev->hw.mac.media_type == HNAE3_MEDIA_TYPE_FIBER) { + switch (status) { + case ETHTOOL_ID_ACTIVE: + ret = hclge_set_led_status_sfp(hdev, + HCLGE_LED_NO_CHANGE, + HCLGE_LED_NO_CHANGE, + HCLGE_LED_NO_CHANGE, + HCLGE_LED_ON); + break; + case ETHTOOL_ID_INACTIVE: + ret = hclge_set_led_status_sfp(hdev, + HCLGE_LED_NO_CHANGE, + HCLGE_LED_NO_CHANGE, + HCLGE_LED_NO_CHANGE, + HCLGE_LED_OFF); + break; + default: + ret = -EINVAL; + break; + } + } else { + ret = -EOPNOTSUPP; } return ret; -- 2.9.3