2023-12-04 01:15:52

by Jijie Shao

[permalink] [raw]
Subject: [PATCH V2 net 2/2] net: hns: fix fake link up on xge port

From: Yonglong Liu <[email protected]>

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 <[email protected]>
Signed-off-by: Jijie Shao <[email protected]>
---
.../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


2023-12-04 10:21:12

by Wojciech Drewek

[permalink] [raw]
Subject: Re: [PATCH V2 net 2/2] net: hns: fix fake link up on xge port



On 04.12.2023 02:10, Jijie Shao wrote:
> From: Yonglong Liu <[email protected]>
>
> 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 <[email protected]>
> Signed-off-by: Jijie Shao <[email protected]>
> ---
> .../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)
> +{

It would be cleaner to return the link status than using output arg IMO

> +#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;

2023-12-04 14:44:00

by Jijie Shao

[permalink] [raw]
Subject: Re: [PATCH V2 net 2/2] net: hns: fix fake link up on xge port


on 2023/12/4 18:19, Wojciech Drewek wrote:
>
> On 04.12.2023 02:10, Jijie Shao wrote:
>>
>> +static void hns_mac_link_anti_shake(struct mac_driver *mac_ctrl_drv,
>> + u32 *link_status)
>> +{
> It would be cleaner to return the link status than using output arg IMO
>
Yes, it's a good suggestion, and this is modified in v3