[][kernel][mt7988][eth][Fix DMA init timeout in network-restart stress test]

[Description]
Fix DMA init timeout in network-restart stress test :
1. Turn on the gmac forwarding when mkt_open is only halfway initialized
or  start deinit in mtk_close without forbid forwarding in gmac, this
can lead to unknown exceptions.
2. Update the init/deinit order in mtk_open/mtk_close.
3. Move the configure of gdm from mtk_mac_config to mtk_hw_init, avoid
asynchronous operations on gdm config.
4. Update related patches.

[Release-log]
N/A


Change-Id: I80f594948b0c0ddc7eb34bb47e78e2ff74229f6a
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6728789
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/9993-add-wed.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/9993-add-wed.patch
index 7aabbeb..baa88ef 100755
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/9993-add-wed.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/9993-add-wed.patch
@@ -146,8 +146,7 @@
  #include <linux/mfd/syscon.h>
  #include <linux/regmap.h>
  #include <linux/clk.h>
-@@ -19,13 +20,15 @@
- #include <linux/interrupt.h>
+@@ -20,12 +21,14 @@
  #include <linux/pinctrl/devinfo.h>
  #include <linux/phylink.h>
  #include <linux/gpio/consumer.h>
@@ -162,7 +161,7 @@
  
  #if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
  #include "mtk_hnat/nf_hnat_mtk.h"
-@@ -850,7 +853,7 @@ static int mtk_init_fq_dma(struct mtk_eth *eth)
+@@ -1116,7 +1119,7 @@ static int mtk_init_fq_dma(struct mtk_et
  	int i;
  
  	if (!eth->soc->has_sram) {
@@ -170,8 +169,8 @@
 +		eth->scratch_ring = dma_alloc_coherent(eth->dma_dev,
  					       cnt * soc->txrx.txd_size,
  					       &eth->phy_scratch_ring,
- 					       GFP_ATOMIC);
-@@ -866,10 +869,10 @@ static int mtk_init_fq_dma(struct mtk_eth *eth)
+ 					       GFP_KERNEL);
+@@ -1134,10 +1137,10 @@ static int mtk_init_fq_dma(struct mtk_et
  	if (unlikely(!eth->scratch_head))
  		return -ENOMEM;
  
@@ -184,7 +183,7 @@
  		return -ENOMEM;
  
  	phy_ring_tail = eth->phy_scratch_ring +
-@@ -933,26 +936,26 @@ static void mtk_tx_unmap(struct mtk_eth *eth, struct mtk_tx_buf *tx_buf,
+@@ -1201,26 +1204,26 @@ static void mtk_tx_unmap(struct mtk_eth
  {
  	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
  		if (tx_buf->flags & MTK_TX_FLAGS_SINGLE0) {
@@ -215,8 +214,8 @@
  				       dma_unmap_addr(tx_buf, dma_addr1),
  				       dma_unmap_len(tx_buf, dma_len1),
  				       DMA_TO_DEVICE);
-@@ -1017,9 +1020,9 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
- 	itx_buf = mtk_desc_to_tx_buf(ring, itxd);
+@@ -1454,9 +1457,9 @@ static int mtk_tx_map(struct sk_buff *sk
+ 	itx_buf = mtk_desc_to_tx_buf(ring, itxd, soc->txrx.txd_size);
  	memset(itx_buf, 0, sizeof(*itx_buf));
  
 -	txd_info.addr = dma_map_single(eth->dev, skb->data, txd_info.size,
@@ -226,8 +225,8 @@
 +	if (unlikely(dma_mapping_error(eth->dma_dev, txd_info.addr)))
  		return -ENOMEM;
  
- 	WRITE_ONCE(itxd->txd1, mapped_addr);
-@@ -1114,10 +1117,10 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
+ 	mtk_tx_set_dma_desc(skb, dev, itxd, &txd_info);
+@@ -1497,10 +1500,10 @@ static int mtk_tx_map(struct sk_buff *sk
  			txd_info.qid = skb->mark & MTK_QDMA_TX_MASK;
  			txd_info.last = i == skb_shinfo(skb)->nr_frags - 1 &&
  					!(frag_size - txd_info.size);
@@ -240,15 +239,15 @@
   				goto err_dma;
  
  			mtk_tx_set_dma_desc(skb, dev, txd, &txd_info);
-@@ -1384,6 +1387,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
- 		struct net_device *netdev;
+@@ -1737,6 +1740,7 @@ static int mtk_poll_rx(struct napi_struc
+ 		struct net_device *netdev = NULL;
  		unsigned int pktlen;
  		dma_addr_t dma_addr = 0;
 +		u32 hash, reason;
  		int mac = 0;
  
  		if (eth->hwlro)
-@@ -1427,22 +1431,22 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
+@@ -1787,12 +1791,12 @@ static int mtk_poll_rx(struct napi_struc
  			netdev->stats.rx_dropped++;
  			goto release_desc;
  		}
@@ -263,8 +262,7 @@
  			skb_free_frag(new_data);
  			netdev->stats.rx_dropped++;
  			goto release_desc;
- 		}
- 
+@@ -1801,7 +1805,7 @@ static int mtk_poll_rx(struct napi_struc
  		addr64 = (MTK_HAS_CAPS(eth->soc->caps, MTK_8GB_ADDRESSING)) ?
  			  ((u64)(trxd.rxd2 & 0xf)) << 32 : 0;
  
@@ -273,8 +271,7 @@
  				 (u64)(trxd.rxd1 | addr64),
  				 ring->buf_size, DMA_FROM_DEVICE);
  
- 		/* receive data */
-@@ -1463,6 +1467,17 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
+@@ -1827,6 +1831,17 @@ static int mtk_poll_rx(struct napi_struc
  			skb_checksum_none_assert(skb);
  		skb->protocol = eth_type_trans(skb, netdev);
  
@@ -290,9 +287,9 @@
 +					  trxd.rxd4 & MTK_RXD4_FOE_ENTRY);
 +
  		if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
- 			if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
- 				if (trxd.rxd3 & RX_DMA_VTAG_V2)
-@@ -1748,7 +1763,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
+ 			if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ||
+ 			    MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
+@@ -2120,7 +2135,7 @@ static int mtk_tx_alloc(struct mtk_eth *
  		goto no_tx_mem;
  
  	if (!eth->soc->has_sram)
@@ -300,8 +297,8 @@
 +		ring->dma = dma_alloc_coherent(eth->dma_dev, MTK_DMA_SIZE * sz,
  					       &ring->phys, GFP_KERNEL);
  	else {
- 		ring->dma =  eth->scratch_ring + MTK_DMA_SIZE;
-@@ -1780,6 +1795,6 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
+ 		ring->dma =  eth->scratch_ring + MTK_DMA_SIZE * sz;
+@@ -2154,7 +2169,7 @@ static int mtk_tx_alloc(struct mtk_eth *
  	 * descriptors in ring->dma_pdma.
  	 */
  	if (!MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
@@ -309,7 +306,8 @@
 +		ring->dma_pdma = dma_alloc_coherent(eth->dma_dev, MTK_DMA_SIZE * sz,
  						    &ring->phys_pdma, GFP_KERNEL);
  		if (!ring->dma_pdma)
-@@ -1839,6 +1854,6 @@ static void mtk_tx_clean(struct mtk_eth *eth)
+ 			goto no_tx_mem;
+@@ -2215,14 +2230,14 @@ static void mtk_tx_clean(struct mtk_eth
  	}
  
  	if (!eth->soc->has_sram && ring->dma) {
@@ -317,7 +315,7 @@
 +		dma_free_coherent(eth->dma_dev,
  				  MTK_DMA_SIZE * soc->txrx.txd_size,
  				  ring->dma, ring->phys);
-@@ -1847,6 +1862,6 @@ static void mtk_tx_clean(struct mtk_eth *eth)
+ 		ring->dma = NULL;
  	}
  
  	if (ring->dma_pdma) {
@@ -325,7 +323,8 @@
 +		dma_free_coherent(eth->dma_dev,
  				  MTK_DMA_SIZE * soc->txrx.txd_size,
  				  ring->dma_pdma, ring->phys_pdma);
-@@ -1892,7 +1907,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
+ 		ring->dma_pdma = NULL;
+@@ -2267,7 +2282,7 @@ static int mtk_rx_alloc(struct mtk_eth *
  
  	if ((!eth->soc->has_sram) || (eth->soc->has_sram
  				&& (rx_flag != MTK_RX_FLAGS_NORMAL)))
@@ -334,12 +333,10 @@
  					       rx_dma_size * eth->soc->txrx.rxd_size,
  					       &ring->phys, GFP_KERNEL);
  	else {
-@@ -1907,13 +1922,13 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
- 		return -ENOMEM;
- 
+@@ -2284,11 +2299,11 @@ static int mtk_rx_alloc(struct mtk_eth *
  	for (i = 0; i < rx_dma_size; i++) {
  		struct mtk_rx_dma_v2 *rxd;
-
+ 
 -		dma_addr_t dma_addr = dma_map_single(eth->dev,
 +		dma_addr_t dma_addr = dma_map_single(eth->dma_dev,
  				ring->data[i] + NET_SKB_PAD + eth->ip_align,
@@ -348,9 +345,9 @@
 -		if (unlikely(dma_mapping_error(eth->dev, dma_addr)))
 +		if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
  			return -ENOMEM;
-
+ 
  		rxd = ring->dma + i * eth->soc->txrx.rxd_size;
-@@ -1968,7 +1983,7 @@ static void mtk_rx_clean(struct mtk_eth *eth, struct mtk_rx_ring *ring, int in_s
+@@ -2360,7 +2375,7 @@ static void mtk_rx_clean(struct mtk_eth
  					       MTK_8GB_ADDRESSING)) ?
  				  ((u64)(rxd->rxd2 & 0xf)) << 32 : 0;
  
@@ -359,7 +356,7 @@
  					 (u64)(rxd->rxd1 | addr64),
  					 ring->buf_size,
  					 DMA_FROM_DEVICE);
-@@ -1982,7 +1997,7 @@ static void mtk_rx_clean(struct mtk_eth *eth, struct mtk_rx_ring *ring, int in_s
+@@ -2374,7 +2389,7 @@ static void mtk_rx_clean(struct mtk_eth
  		return;
  
  	if (ring->dma) {
@@ -368,7 +365,7 @@
  				  ring->dma_size * eth->soc->txrx.rxd_size,
  				  ring->dma,
  				  ring->phys);
-@@ -2462,6 +2477,6 @@ static void mtk_dma_free(struct mtk_eth *eth)
+@@ -2861,7 +2876,7 @@ static void mtk_dma_free(struct mtk_eth
  		if (eth->netdev[i])
  			netdev_reset_queue(eth->netdev[i]);
  	if ( !eth->soc->has_sram && eth->scratch_ring) {
@@ -376,16 +373,8 @@
 +		dma_free_coherent(eth->dma_dev,
  				  MTK_DMA_SIZE * soc->txrx.txd_size,
  				  eth->scratch_ring, eth->phy_scratch_ring);
-@@ -2661,7 +2676,7 @@ static int mtk_open(struct net_device *dev)
- 		if (err)
- 			return err;
- 
--		if (eth->soc->offload_version && mtk_ppe_start(&eth->ppe) == 0)
-+		if (eth->soc->offload_version && mtk_ppe_start(eth->ppe) == 0)
- 			gdm_config = MTK_GDMA_TO_PPE;
- 
- 		mtk_gdm_config(eth, gdm_config);
-@@ -2778,7 +2793,7 @@ static int mtk_stop(struct net_device *dev)
+ 		eth->scratch_ring = NULL;
+@@ -3243,7 +3258,7 @@ static int mtk_stop(struct net_device *d
  	mtk_dma_free(eth);
  
  	if (eth->soc->offload_version)
@@ -394,16 +383,16 @@
  
  	return 0;
  }
-@@ -2855,6 +2870,8 @@ static int mtk_napi_init(struct mtk_eth *eth)
+@@ -3320,6 +3335,8 @@ static int mtk_napi_init(struct mtk_eth
  
  static int mtk_hw_init(struct mtk_eth *eth, u32 type)
  {
 +	u32 dma_mask = ETHSYS_DMA_AG_MAP_PDMA | ETHSYS_DMA_AG_MAP_QDMA |
 +		       ETHSYS_DMA_AG_MAP_PPE;
  	int i, ret = 0;
+ 	u32 val;
  
- 	pr_info("[%s] reset_lock:%d, force:%d\n", __func__,
-@@ -2872,6 +2889,10 @@ static int mtk_hw_init(struct mtk_eth *eth, u32 type)
+@@ -3338,6 +3355,10 @@ static int mtk_hw_init(struct mtk_eth *e
  			goto err_disable_pm;
  	}
  
@@ -414,7 +403,7 @@
  	if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
  		ret = device_reset(eth->dev);
  		if (ret) {
-@@ -3501,6 +3522,35 @@ free_netdev:
+@@ -4091,6 +4112,35 @@ free_netdev:
  	return err;
  }
  
@@ -450,7 +439,7 @@
  static int mtk_probe(struct platform_device *pdev)
  {
  	struct device_node *mac_np;
-@@ -3514,6 +3564,7 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -4104,6 +4154,7 @@ static int mtk_probe(struct platform_dev
  	eth->soc = of_device_get_match_data(&pdev->dev);
  
  	eth->dev = &pdev->dev;
@@ -458,7 +447,7 @@
  	eth->base = devm_platform_ioremap_resource(pdev, 0);
  	if (IS_ERR(eth->base))
  		return PTR_ERR(eth->base);
-@@ -3567,6 +3618,16 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -4176,6 +4227,16 @@ static int mtk_probe(struct platform_dev
  		}
  	}
  
@@ -473,9 +462,9 @@
 +	}
 +
  	if (MTK_HAS_CAPS(eth->soc->caps, MTK_SGMII)) {
- 		eth->sgmii = devm_kzalloc(eth->dev, sizeof(*eth->sgmii),
+ 		eth->xgmii = devm_kzalloc(eth->dev, sizeof(*eth->xgmii),
  					  GFP_KERNEL);
-@@ -3589,6 +3650,22 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -4217,6 +4278,22 @@ static int mtk_probe(struct platform_dev
  		}
  	}
  
@@ -498,7 +487,7 @@
  	for (i = 0; i < MTK_MAX_IRQ_NUM; i++) {
  		if (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_INT) && i > 0)
  			eth->irq[i] = eth->irq[0];
-@@ -3692,10 +3769,11 @@ static int mtk_probe(struct platform_device *pdev)
+@@ -4320,10 +4397,11 @@ static int mtk_probe(struct platform_dev
  	}
  
  	if (eth->soc->offload_version) {
@@ -519,9 +508,9 @@
 index 349f98503..b52378bd6
 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
-@@ -517,6 +517,9 @@
+@@ -549,6 +549,9 @@
  #define RX_DMA_SPORT_MASK       0x7
- #endif
+ #define RX_DMA_SPORT_MASK_V2    0xf
  
 +#define MTK_WDMA0_BASE		0x2800
 +#define MTK_WDMA1_BASE		0x2c00
@@ -529,7 +518,7 @@
  /* QDMA descriptor txd4 */
  #define TX_DMA_CHKSUM		(0x7 << 29)
  #define TX_DMA_TSO		BIT(28)
-@@ -704,6 +707,12 @@
+@@ -773,6 +776,12 @@
  #define ETHSYS_FE_RST_CHK_IDLE_EN 	0x28
  
  
@@ -542,7 +531,7 @@
  /* SGMII subsystem config registers */
  /* Register to auto-negotiation restart */
  #define SGMSYS_PCS_CONTROL_1	0x0
-@@ -1209,6 +1218,7 @@ struct mtk_reset_event {
+@@ -1520,6 +1529,7 @@ struct mtk_phylink_priv {
  /* struct mtk_eth -	This is the main datasructure for holding the state
   *			of the driver
   * @dev:		The device pointer
@@ -550,15 +539,15 @@
   * @base:		The mapped register i/o base
   * @page_lock:		Make sure that register operations are atomic
   * @tx_irq__lock:	Make sure that IRQ register operations are atomic
-@@ -1243,6 +1253,7 @@ struct mtk_reset_event {
+@@ -1554,6 +1564,7 @@ struct mtk_phylink_priv {
  
  struct mtk_eth {
  	struct device			*dev;
 +	struct device			*dma_dev;
  	void __iomem			*base;
+ 	void __iomem			*sram_base;
  	spinlock_t			page_lock;
- 	spinlock_t			tx_irq_lock;
-@@ -1283,7 +1294,7 @@ struct mtk_eth {
+@@ -1596,7 +1607,7 @@ struct mtk_eth {
  	spinlock_t			syscfg0_lock;
  	struct timer_list		mtk_dma_monitor_timer;
  
@@ -567,13 +556,15 @@
  	struct rhashtable		flow_table;
  };
  
-@@ -1336,5 +1347,6 @@ void ethsys_reset(struct mtk_eth *eth, u32 reset_bits);
+@@ -1655,6 +1666,7 @@ void ethsys_reset(struct mtk_eth *eth, u
  int mtk_eth_offload_init(struct mtk_eth *eth);
  int mtk_eth_setup_tc(struct net_device *dev, enum tc_setup_type type,
  		     void *type_data);
 +void mtk_eth_set_dma_device(struct mtk_eth *eth, struct device *dma_dev);
  
- #endif /* MTK_ETH_H */
+ int mtk_mac2xgmii_id(struct mtk_eth *eth, int mac_id);
+ int mtk_usxgmii_init(struct mtk_xgmii *ss, struct device_node *r);
+
 diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
 old mode 100644
 new mode 100755