Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2431498rdb; Sun, 3 Dec 2023 17:15:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeiFwNs05ayFsqFjrf24fEH+eEgeQVLCOdC24SBHMfpFf1g3ABnz1nWVwp1I79GemRcMsa X-Received: by 2002:a05:6a00:4214:b0:6ce:2731:47b4 with SMTP id cd20-20020a056a00421400b006ce273147b4mr3778268pfb.20.1701652552437; Sun, 03 Dec 2023 17:15:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701652552; cv=none; d=google.com; s=arc-20160816; b=eQJ5R6m/Oivd7KyB4uUo69vnqHXh+sexF+Wpfp0tPy4ZvBzR4QOSXHPnojDVfCjJQK JFNdJc3wT0ka+lTdyowLiXMUIEC9VVjYAGqSUtJvdMmxqoj64MovYPGXCH5oRud5ZWW2 0NN5A2Hu/DnTF+mm2FXthRsE0Yqxy0cMH07iokrGBUytB4xGwRgMPfKTLK05SEKS73I0 eHGDG/Gq8LD2fxJMb2CxtBZUzSRHbtXxYeyMNu4S0TzbeU0UK9KQTkbSOo3TvR393okH 10t+kuLHPI3tq2N2bG9izaqsJc02YrPnlHXO+iJOOiHmxhpowQOv8qwJHkJ15DAxUKHZ 5O2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=81C1g+GVqGyeMvhxxqqVlkAr0TL9uiNcMw1RgQk2VqI=; fh=28Gsh8p/Rrgoh0ZJgxMb30MiNZzzGa/AucmCEg5DMJI=; b=XS6Aa8jWGLPPW/b0VAL9GOpJji5X0gfD34xfPBRySNjXbfL2HN4aSzmfQKhAWlBFye 2ie8BUX1XzsHAZtNsTO/QHlLwbDhzgmhLcJeBrtlhtyqgQx2pdr4h03tUWC4KhT6PtS1 Qk9gGv2FjMlt+Msu26sPz2xwgf17HvvhoYM1NJvmOcWVgoUKv5RrJ69TbYZ993PLs/GU Qs18YVu3PEBEoTNpRQBdCNqzL19YcNyDlf86SgWrdf7rBjYikGd1keSgZNp4oI/89ZHK j8M02gGAlqGpdfGAqlNgP/XONw9zMNT2HwMxRwDeJSSXLt9X6XUs74Nl3IveTx/Nljv7 hY2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n30-20020a056a000d5e00b006ce44b51172si1580326pfv.351.2023.12.03.17.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 17:15:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7D33380657F2; Sun, 3 Dec 2023 17:15:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234213AbjLDBPe (ORCPT + 99 others); Sun, 3 Dec 2023 20:15:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234198AbjLDBPb (ORCPT ); Sun, 3 Dec 2023 20:15:31 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 167FEEB; Sun, 3 Dec 2023 17:15:37 -0800 (PST) Received: from kwepemm000007.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Sk5GB2WZpzShbw; Mon, 4 Dec 2023 09:11:14 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemm000007.china.huawei.com (7.193.23.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 4 Dec 2023 09:15:34 +0800 From: Jijie Shao To: , , , , , CC: , , , , , Subject: [PATCH V2 net 2/2] net: hns: fix fake link up on xge port Date: Mon, 4 Dec 2023 09:10:51 +0800 Message-ID: <20231204011051.4055031-3-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231204011051.4055031-1-shaojijie@huawei.com> References: <20231204011051.4055031-1-shaojijie@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm000007.china.huawei.com (7.193.23.189) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 03 Dec 2023 17:15:51 -0800 (PST) From: Yonglong Liu If a xge port just connect with an optical module and no fiber, it may have a fake link up because there may be interference on the hardware. This patch adds an anti-shake to avoid the problem. And the time of anti-shake is base on tests. Fixes: b917078c1c10 ("net: hns: Add ACPI support to check SFP present") Signed-off-by: Yonglong Liu Signed-off-by: Jijie Shao --- .../net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c index 928d934cb21a..c3abb14edd51 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c @@ -66,6 +66,27 @@ static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb) } } +static void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, + u32 *link_status) +{ +#define HNS_MAC_LINK_WAIT_TIME 5 +#define HNS_MAC_LINK_WAIT_CNT 40 + + int i; + + if (!mac_ctrl_drv->get_link_status) { + *link_status = 0; + return; + } + + for (i = 0; i < HNS_MAC_LINK_WAIT_CNT; i++) { + msleep(HNS_MAC_LINK_WAIT_TIME); + mac_ctrl_drv->get_link_status(mac_ctrl_drv, link_status); + if (!*link_status) + break; + } +} + void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status) { struct mac_driver *mac_ctrl_drv; @@ -83,6 +104,14 @@ void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status) &sfp_prsnt); if (!ret) *link_status = *link_status && sfp_prsnt; + + /* for FIBER port, it may have a fake link up. + * when the link status changes from down to up, we need to do + * anti-shake. the anti-shake time is base on tests. + * only FIBER port need to do this. + */ + if (*link_status && !mac_cb->link) + hns_mac_link_anti_shake(mac_ctrl_drv, link_status); } mac_cb->link = *link_status; -- 2.30.0