diff mbox series

[net,2/2] net: hns: fix fake link up on xge port

Message ID 20231201102703.4134592-3-shaojijie@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series There are some bugfix for the HNS ethernet driver | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 1115 this patch: 1117
netdev/cc_maintainers success CCed 8 of 9 maintainers
netdev/build_clang fail Errors and warnings before: 1142 this patch: 1144
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn fail Errors and warnings before: 1142 this patch: 1144
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 40 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jijie Shao Dec. 1, 2023, 10:27 a.m. UTC
From: Yonglong Liu <liuyonglong@huawei.com>

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 <liuyonglong@huawei.com>
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
---
 .../net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Jakub Kicinski Dec. 2, 2023, 5:19 a.m. UTC | #1
On Fri, 1 Dec 2023 18:27:03 +0800 Jijie Shao wrote:
> +void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, u32 *link_status)

drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:69:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   69 | void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, u32 *link_status)
      | ^
      | static
Jijie Shao Dec. 4, 2023, 1:20 a.m. UTC | #2
on 2023/12/2 13:19, Jakub Kicinski wrote:
> On Fri, 1 Dec 2023 18:27:03 +0800 Jijie Shao wrote:
>> +void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, u32 *link_status)
> drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:69:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
>     69 | void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, u32 *link_status)
>        | ^
>        | static

Thanks,
   v2 patch is sent to fix it.
kernel test robot Dec. 6, 2023, 1:21 a.m. UTC | #3
Hi Jijie,

kernel test robot noticed the following build warnings:

[auto build test WARNING on net/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Jijie-Shao/net-hns-fix-wrong-head-when-modify-the-tx-feature-when-sending-packets/20231201-183325
base:   net/main
patch link:    https://lore.kernel.org/r/20231201102703.4134592-3-shaojijie%40huawei.com
patch subject: [PATCH net 2/2] net: hns: fix fake link up on xge port
config: i386-buildonly-randconfig-001-20231202 (https://download.01.org/0day-ci/archive/20231206/202312060909.F00QN1zB-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/202312060909.F00QN1zB-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312060909.F00QN1zB-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:69:6: warning: no previous prototype for function 'hns_mac_link_anti_shake' [-Wmissing-prototypes]
   void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, u32 *link_status)
        ^
   drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c:69:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, u32 *link_status)
   ^
   static 
   1 warning generated.


vim +/hns_mac_link_anti_shake +69 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c

    68	
  > 69	void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv, u32 *link_status)
    70	{
    71	#define HNS_MAC_LINK_WAIT_TIME 5
    72	#define HNS_MAC_LINK_WAIT_CNT 40
    73	
    74		int i;
    75	
    76		if (!mac_ctrl_drv->get_link_status) {
    77			*link_status = 0;
    78			return;
    79		}
    80	
    81		for (i = 0; i < HNS_MAC_LINK_WAIT_CNT; i++) {
    82			msleep(HNS_MAC_LINK_WAIT_TIME);
    83			mac_ctrl_drv->get_link_status(mac_ctrl_drv, link_status);
    84			if (!*link_status)
    85				break;
    86		}
    87	}
    88
diff mbox series

Patch

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;