Message ID | 20231204143232.3221542-3-shaojijie@huawei.com (mailing list archive) |
---|---|
State | Accepted |
Commit | f708aba40f9c1eeb9c7e93ed4863b5f85b09b288 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | There are some bugfix for the HNS ethernet driver | expand |
On 04.12.2023 15:32, Jijie Shao wrote: > 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> > --- Thanks! Reviewed-by: Wojciech Drewek <wojciech.drewek@intel.com> > .../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;
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;