Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4878375pjb; Mon, 27 Jul 2020 07:26:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKSljdZcHoz6heLPqgpAs1iZBsN+iDC5TQk+w+K4aL2M4LbVQrPDZFzg6hskWg9ZSboj1a X-Received: by 2002:a17:906:4a4e:: with SMTP id a14mr9532947ejv.450.1595859960674; Mon, 27 Jul 2020 07:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859960; cv=none; d=google.com; s=arc-20160816; b=sKOK6TzjLE/NKaga0zg/tZyghTqAbfHotu+bt8gyD2aP6w666gr58LU8IroXQoc1bQ iWyD8ybUtpsHobESQCHMUBK/eM3Ml85J6zefJxz9IVI9KWIP9S06HV3SaeuTYDzI3Uy7 B8nBydEP5M6TwX8M5R+KZ+87kYA0BBRSe/QN4L7CVaLDbeVoW2lpECbwSNPVwER6UFgh nrz6DF0j8o9+ieogTsrBnQedL7YTz6+gFOYyM5UqP2tVOgXb/3uhtObvZbzjHC1AJ8br D/J7kfJLteZJ6eb8trCSRKaWYIYY5O454p5hwRZjOe3T1SRph5Qln4fgYxN4NU9Su/7C QzAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BdZB/B34pz2LtC/MqxtIJ4VawN96aIDyCPHHR5QW8Fs=; b=hxLmLxX9F8jHpUmroZe4SeODxXIG6DuYo5ss3KXV3sRSwUcQHJfYLNWX1otM81Xncn RDNUpzNFIKxAgedy97o//O6RoW1FSXIGNRYLX0wOUbKyaZ4Tp8U3yEE5jI9VwkPSvXgw 43ojylSeLK4GBvqnqjnrpdNrl4+k9u02vdFFmOFJxcRp15BPbaXP1rZU7oggOdK9V4BN IapKKVGKr93QHSOAKhS4Cubf+5a05HjdZ7qILMX9g22CPQ6hGli5vCuc6NwwUt/ONQAM isvPfWVr1+SOxqq4x9Hk84srPDp6SpK45EY8+g50EkL/JdZB32WY/w530tnnrQek7ca4 AFiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cjKy1Way; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b13si1937353edy.593.2020.07.27.07.25.34; Mon, 27 Jul 2020 07:26:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cjKy1Way; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731844AbgG0OWL (ORCPT + 99 others); Mon, 27 Jul 2020 10:22:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:51012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731296AbgG0OWI (ORCPT ); Mon, 27 Jul 2020 10:22:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 029182173E; Mon, 27 Jul 2020 14:22:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859727; bh=gyQdnrPqdFImMtpb8jo3c1WTMauHr62tKoWb/8+nMWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cjKy1Way9fgeXeKnJRuyWef+5e3i04mg4T4fVe5dcDuAgAKYgp8VhdHSXGjklk2pL dTbXs1/Ms7MxL71sPLZHYLrhlCNCHsr/26YcGjrnY4Q4ROGkXKbij1Lf8byxX+Wo5I NKwqGi0GLCHC7LKYUXJtoMI04ViUGz4sQ5Itc7wI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jian Shen , Huazhong tan , "David S. Miller" , Sasha Levin Subject: [PATCH 5.7 080/179] net: hns3: fix return value error when query MAC link status fail Date: Mon, 27 Jul 2020 16:04:15 +0200 Message-Id: <20200727134936.580410663@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jian Shen [ Upstream commit fac24df7b9a6d9363abdff0e351ade041dd16daa ] Currently, PF queries the MAC link status per second by calling function hclge_get_mac_link_status(). It return the error code when failed to send cmdq command to firmware. It's incorrect, because this return value is used as the MAC link status, which 0 means link down, and none-zero means link up. So fixes it. Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer Support") Signed-off-by: Jian Shen Signed-off-by: Huazhong tan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- .../hisilicon/hns3/hns3pf/hclge_main.c | 49 +++++++++---------- .../hisilicon/hns3/hns3pf/hclge_main.h | 3 ++ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index 4de268a879582..b66b93f320b42 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -2680,11 +2680,10 @@ void hclge_task_schedule(struct hclge_dev *hdev, unsigned long delay_time) delay_time); } -static int hclge_get_mac_link_status(struct hclge_dev *hdev) +static int hclge_get_mac_link_status(struct hclge_dev *hdev, int *link_status) { struct hclge_link_status_cmd *req; struct hclge_desc desc; - int link_status; int ret; hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_LINK_STATUS, true); @@ -2696,33 +2695,25 @@ static int hclge_get_mac_link_status(struct hclge_dev *hdev) } req = (struct hclge_link_status_cmd *)desc.data; - link_status = req->status & HCLGE_LINK_STATUS_UP_M; + *link_status = (req->status & HCLGE_LINK_STATUS_UP_M) > 0 ? + HCLGE_LINK_STATUS_UP : HCLGE_LINK_STATUS_DOWN; - return !!link_status; + return 0; } -static int hclge_get_mac_phy_link(struct hclge_dev *hdev) +static int hclge_get_mac_phy_link(struct hclge_dev *hdev, int *link_status) { - unsigned int mac_state; - int link_stat; + struct phy_device *phydev = hdev->hw.mac.phydev; + + *link_status = HCLGE_LINK_STATUS_DOWN; if (test_bit(HCLGE_STATE_DOWN, &hdev->state)) return 0; - mac_state = hclge_get_mac_link_status(hdev); - - if (hdev->hw.mac.phydev) { - if (hdev->hw.mac.phydev->state == PHY_RUNNING) - link_stat = mac_state & - hdev->hw.mac.phydev->link; - else - link_stat = 0; - - } else { - link_stat = mac_state; - } + if (phydev && (phydev->state != PHY_RUNNING || !phydev->link)) + return 0; - return !!link_stat; + return hclge_get_mac_link_status(hdev, link_status); } static void hclge_update_link_status(struct hclge_dev *hdev) @@ -2732,6 +2723,7 @@ static void hclge_update_link_status(struct hclge_dev *hdev) struct hnae3_handle *rhandle; struct hnae3_handle *handle; int state; + int ret; int i; if (!client) @@ -2740,7 +2732,12 @@ static void hclge_update_link_status(struct hclge_dev *hdev) if (test_and_set_bit(HCLGE_STATE_LINK_UPDATING, &hdev->state)) return; - state = hclge_get_mac_phy_link(hdev); + ret = hclge_get_mac_phy_link(hdev, &state); + if (ret) { + clear_bit(HCLGE_STATE_LINK_UPDATING, &hdev->state); + return; + } + if (state != hdev->hw.mac.link) { for (i = 0; i < hdev->num_vmdq_vport + 1; i++) { handle = &hdev->vport[i].nic; @@ -6435,14 +6432,15 @@ static int hclge_mac_link_status_wait(struct hclge_dev *hdev, int link_ret) { #define HCLGE_MAC_LINK_STATUS_NUM 100 + int link_status; int i = 0; int ret; do { - ret = hclge_get_mac_link_status(hdev); - if (ret < 0) + ret = hclge_get_mac_link_status(hdev, &link_status); + if (ret) return ret; - else if (ret == link_ret) + if (link_status == link_ret) return 0; msleep(HCLGE_LINK_STATUS_MS); @@ -6453,9 +6451,6 @@ static int hclge_mac_link_status_wait(struct hclge_dev *hdev, int link_ret) static int hclge_mac_phy_link_status_wait(struct hclge_dev *hdev, bool en, bool is_phy) { -#define HCLGE_LINK_STATUS_DOWN 0 -#define HCLGE_LINK_STATUS_UP 1 - int link_ret; link_ret = en ? HCLGE_LINK_STATUS_UP : HCLGE_LINK_STATUS_DOWN; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h index 71df23d5f1b4d..8784168f8f6f7 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h @@ -316,6 +316,9 @@ enum hclge_link_fail_code { HCLGE_LF_XSFP_ABSENT, }; +#define HCLGE_LINK_STATUS_DOWN 0 +#define HCLGE_LINK_STATUS_UP 1 + #define HCLGE_PG_NUM 4 #define HCLGE_SCH_MODE_SP 0 #define HCLGE_SCH_MODE_DWRR 1 -- 2.25.1