[][kernel][common][eth][Fix the ethX transmit timeout issue caused by the NETSYS SER]

[Description]
Fix the ethX transmit timeout issue caused by the NETSYS SER.

In the previous change 9787474, we added a new NETSYS SER design to
prevent resetting GMAC when GMAC is not hung. However, this design
introduced a 'ethX: transmit timed out' issue when the Ethernet port
is not connected to the link partner.
Therefore, we added a check to avoid mistakenly calling
netif_carrier_on().

Without this patch, the kernel will encounter an 'ethX: transmit timed
out' issue after NETSYS SER.

[Release-log]
N/A


Change-Id: I5360d4fa985a2890373c438c8938c50ba05ae0bf
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9821872
diff --git a/21.02/files/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/21.02/files/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 6ad4ece..6967dbf 100644
--- a/21.02/files/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/21.02/files/target/linux/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -1301,7 +1301,8 @@
 	mtk_pse_set_mac_port_link(mac, true, interface);
 }
 
-void mtk_mac_fe_reset_complete(struct mtk_eth *eth, unsigned long restart)
+void mtk_mac_fe_reset_complete(struct mtk_eth *eth, unsigned long restart,
+			       unsigned long restart_carrier)
 {
 	struct phylink_link_state state;
 	struct mtk_mac *mac;
@@ -1329,7 +1330,8 @@
 				mac->interface, mac->speed, mac->duplex,
 				mac->tx_pause, mac->rx_pause);
 
-		netif_carrier_on(eth->netdev[i]);
+		if (test_bit(i, &restart_carrier))
+			netif_carrier_on(eth->netdev[i]);
 	}
 }
 
@@ -5162,7 +5164,7 @@
 	return 0;
 }
 
-static void mtk_prepare_reset_fe(struct mtk_eth *eth)
+static void mtk_prepare_reset_fe(struct mtk_eth *eth, unsigned long *restart_carrier)
 {
 	struct mtk_mac *mac;
 	u32 i = 0, val = 0;
@@ -5177,6 +5179,9 @@
 		if (!eth->netdev[i])
 			continue;
 
+		if (netif_carrier_ok(eth->netdev[i]))
+			__set_bit(i, restart_carrier);
+
 		/* call carrier off first to avoid false dev_watchdog timeouts */
 		netif_carrier_off(eth->netdev[i]);
 		netif_tx_disable(eth->netdev[i]);
@@ -5217,7 +5222,7 @@
 static void mtk_pending_work(struct work_struct *work)
 {
 	struct mtk_eth *eth = container_of(work, struct mtk_eth, pending_work);
-	unsigned long restart = 0;
+	unsigned long restart = 0, restart_carrier = 0;
 	u32 val;
 	int i;
 
@@ -5251,7 +5256,7 @@
 		mtk_prepare_reset_ppe(eth, 2);
 
 	/* Adjust FE configurations to prepare for reset */
-	mtk_prepare_reset_fe(eth);
+	mtk_prepare_reset_fe(eth, &restart_carrier);
 
 	/* Trigger Wifi SER reset */
 	for (i = 0; i < MTK_MAC_COUNT; i++) {
@@ -5349,7 +5354,7 @@
 		break;
 	}
 
-	mtk_mac_fe_reset_complete(eth, restart);
+	mtk_mac_fe_reset_complete(eth, restart, restart_carrier);
 
 	/* Restore QDMA configurations */
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))