// Copyright (c) 2024 Hisilicon Limited.
 
 #include <linux/phy.h>
+#include <linux/rtnetlink.h>
 #include "hbg_common.h"
 #include "hbg_hw.h"
 #include "hbg_mdio.h"
 {
        struct device *dev = &priv->pdev->dev;
 
+       rtnl_lock();
+
        if (priv->stats.np_link_fail_cnt >= HBG_NP_LINK_FAIL_RETRY_TIMES) {
                dev_err(dev, "failed to fix the MAC link status\n");
                priv->stats.np_link_fail_cnt = 0;
-               return;
+               goto unlock;
        }
 
+       if (!priv->mac.phydev->link)
+               goto unlock;
+
        priv->stats.np_link_fail_cnt++;
        dev_err(dev, "failed to link between MAC and PHY, try to fix...\n");
 
         */
        hbg_phy_stop(priv);
        hbg_phy_start(priv);
+
+unlock:
+       rtnl_unlock();
 }
 
 static void hbg_phy_adjust_link(struct net_device *netdev)