Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp932196rdb; Fri, 1 Dec 2023 02:31:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfoCo5lYmTunINwl1iP0W6+7OKgjZLih4ZKU7HX2ZV6DnoMxge0YM+rhWI9Nx1icguFF9+ X-Received: by 2002:a05:6a20:d704:b0:189:c0e1:4979 with SMTP id iz4-20020a056a20d70400b00189c0e14979mr31660788pzb.29.1701426674036; Fri, 01 Dec 2023 02:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701426673; cv=none; d=google.com; s=arc-20160816; b=Qjm69I5Kwrx3UZn/1IRLzRGi2azWd3UtkXL54/nGx9V7PUHPSLmCxeuKRXpTnCnKcQ PGE3zImB+sx94WFUN4yhxTVKX2cf6tspano8N9Ozv0yDuhaLpxGOIqsDBF99bVNDmN9v ad8Ds388FCEn+uLjIR0JjyjOxgf/wsTjmZ5M29O38uYU4lXtbfIjGnml5gk+MwO2JSOM xB0nL6JDuj7+kvyZ9MDMLY65oYBM2mOCocUC6Fwwp6HSvObHBGS0C/tdmpWLvh+DDVLA Ma0+W3TJdEt5eqBb2HcnSGnQUuDFjSyPY9XH+S9G3ABLha1c3VN77lmUrsYDYzsfVzy8 S8tg== 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=G7qmSL5N5PWDCLfy13GOBPAyC3KTscB+VWz2+F9vdwg=; fh=28Gsh8p/Rrgoh0ZJgxMb30MiNZzzGa/AucmCEg5DMJI=; b=Mfx1/1xWfDNfP9x+ct88XRtOHhdYeZfqlgxCoiMsr0OV5BJtttLgVzXql/AjY3hPVt /Flw3Gc/mS+mrv6z3wo3de3GyxdqeIcgglaGTSYEuRlL/lvQAMPDyq9sdFzGY2EZdKXV GnN2e/S4yvJ39v7qU/yrqaQaLR3fdfshrWcaIpQmyZD4ay1+DAyNxTPczpCvnJtNkV6E CqNMcmnBrYNvP3f00g2XBEw09YA5l1OaCgY+IZg71DiAC1fV4wE9RW+KG+QByQQLN0PX npn58o28v7OQMuYrLOCytSSnpGZQzTpZj7xMw5UWx9v1kMNu92Y6WVlmn2eFC30G5iK6 YbzA== 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:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x129-20020a636387000000b005be327e08afsi3265511pgb.224.2023.12.01.02.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 02:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 1DCC881603A4; Fri, 1 Dec 2023 02:31:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378273AbjLAKaw (ORCPT + 99 others); Fri, 1 Dec 2023 05:30:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378239AbjLAKat (ORCPT ); Fri, 1 Dec 2023 05:30:49 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C572F1; Fri, 1 Dec 2023 02:30:54 -0800 (PST) Received: from kwepemm000007.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4ShTpf6jrszvRN7; Fri, 1 Dec 2023 18:30:18 +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; Fri, 1 Dec 2023 18:30:52 +0800 From: Jijie Shao To: , , , , , CC: , , , , , Subject: [PATCH net 2/2] net: hns: fix fake link up on xge port Date: Fri, 1 Dec 2023 18:27:03 +0800 Message-ID: <20231201102703.4134592-3-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231201102703.4134592-1-shaojijie@huawei.com> References: <20231201102703.4134592-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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Fri, 01 Dec 2023 02:31:11 -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 | 28 +++++++++++++++++++ 1 file changed, 28 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..3d923756e439 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c @@ -66,6 +66,26 @@ static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb) } } +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 +103,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