Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2748394rdb; Mon, 4 Dec 2023 06:36:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1Kvz17TzlxlIZ+FrKooNkU5jD3vuYmHiSpVcOexLfB2qF3Y502yqJD/A1TVp+Q6AI/lCF X-Received: by 2002:a17:903:264e:b0:1d0:6ffd:6e7f with SMTP id je14-20020a170903264e00b001d06ffd6e7fmr2032390plb.119.1701700614243; Mon, 04 Dec 2023 06:36:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701700614; cv=none; d=google.com; s=arc-20160816; b=ZBQGMQ+V2lTl8JAblWvjqZtP38POn8ye3xcg8lNzYclO0MiJpwXlCeMNdYKTZFMMyh WZePAOPbEKhhvfgtl4vEg1UFh3/vybVAoext2BAnXJOaw2Ij3zczz/xWGYXyCJ/uLklk bKaJvUHa+6LEIkEPo27nAviNlNmRY86f6kY0D5V/bjNgzNQsZqknr6koLFgk0AV7jACf dGmvTf/uDo92MWRAiXF50FbmQaiouxKIJu5EszeQ/QcoWYx5FhQ8THhwaeEJz2hLDh23 KAABIWynqHtKZImkCQLTD4EHO1Bggqp1bZqxzRl7+bemoxcm0itxc9pprqvRA0cp/4/O uUrA== 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=ctRsQnVjrxUNUv6UXhgWAcMeTAJcjJ/T13ocReXc9m0=; fh=UwvcjOZShzHbyqxIj2eSq71qrgSTFMSQaAeIwfPfKHA=; b=S9HXn7jTMAzEDzbrTarRV44PEjrwxWrWYy1AORXY/37JV18SQYXusn5JlgBjugpXs+ S55IZX/j5/bMHZJ4pbb8shitJJpcZt3LL1iAx07Ecvu4muLZ4kjsegqY9HGpvKsyOoGG wQd/FLTqZSUQWkni8Ao6urQOFVfieT5fHHUpwqSw8tHf7DKJR0kuFqZurfnuChL5mOgQ latcy+uPPqTuVa30+mi9Gxn+GSbxzCm9lZchQh2lZlgz06Oa94UQm+z5Cc3+NHQGrwmR 3PsiFK5rR77SHKDNm2jRTlS7XsIKm/M5dEKYQ+AeUk48/RL4kOpAzYK5FTV6yoW7O35R 85qA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id j3-20020a170902da8300b001d0029879dcsi5229614plx.213.2023.12.04.06.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 06:36:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 D357780A918E; Mon, 4 Dec 2023 06:36:52 -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 S1345347AbjLDOgk (ORCPT + 99 others); Mon, 4 Dec 2023 09:36:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235879AbjLDOge (ORCPT ); Mon, 4 Dec 2023 09:36:34 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAFEE129; Mon, 4 Dec 2023 06:36:40 -0800 (PST) Received: from kwepemm000007.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SkR1n60Y9z14L9f; Mon, 4 Dec 2023 22:31:41 +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 22:36:37 +0800 From: Jijie Shao To: , , , , , , CC: , , , , , Subject: [PATCH V3 net 2/2] net: hns: fix fake link up on xge port Date: Mon, 4 Dec 2023 22:32:32 +0800 Message-ID: <20231204143232.3221542-3-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231204143232.3221542-1-shaojijie@huawei.com> References: <20231204143232.3221542-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: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm000007.china.huawei.com (7.193.23.189) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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]); Mon, 04 Dec 2023 06:36:52 -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..f75668c47935 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 u32 hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv) +{ +#define HNS_MAC_LINK_WAIT_TIME 5 +#define HNS_MAC_LINK_WAIT_CNT 40 + + u32 link_status = 0; + int i; + + if (!mac_ctrl_drv->get_link_status) + return link_status; + + 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; + } + + return link_status; +} + 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) + *link_status = hns_mac_link_anti_shake(mac_ctrl_drv); } mac_cb->link = *link_status; -- 2.30.0