[][MAC80211][wed][add dma mask limitation for the board w/ >= 4GB dram]

[Description]
Add dma mask limitation and add GFP_DMA32 flag when alloc memory for the board w/ >= 4GB dram

[Release-log]
N/A


Change-Id: I5c594b7187118d95547fc989a767f72a11bf8a51
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7882515
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/target/linux/mediatek/patches-5.4/999-3023-mtk-wed-add-dma-mask-limitation-and-GFP_DMA32-for-bo.patch b/autobuild_mac80211_release/mt7988_mt7996_mac80211/target/linux/mediatek/patches-5.4/999-3023-mtk-wed-add-dma-mask-limitation-and-GFP_DMA32-for-bo.patch
new file mode 100644
index 0000000..e27c903
--- /dev/null
+++ b/autobuild_mac80211_release/mt7988_mt7996_mac80211/target/linux/mediatek/patches-5.4/999-3023-mtk-wed-add-dma-mask-limitation-and-GFP_DMA32-for-bo.patch
@@ -0,0 +1,106 @@
+From 57294c4562d1f93ee2deaef67a2ad15fb925c288 Mon Sep 17 00:00:00 2001
+From: "sujuan.chen" <sujuan.chen@mediatek.com>
+Date: Wed, 19 Jul 2023 17:22:59 +0800
+Subject: [PATCH] mtk: wed: add dma mask limitation and GFP_DMA32 for board w/
+ >= 4GB dram
+
+Signed-off-by: sujuan.chen <sujuan.chen@mediatek.com>
+---
+ drivers/net/ethernet/mediatek/mtk_wed.c     | 8 ++++++--
+ drivers/net/ethernet/mediatek/mtk_wed_mcu.c | 4 ++--
+ drivers/net/ethernet/mediatek/mtk_wed_wo.c  | 4 ++--
+ drivers/net/ethernet/mediatek/mtk_wed_wo.h  | 1 +
+ 4 files changed, 11 insertions(+), 6 deletions(-)
+
+diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
+index 45dfa0c..d4d8658 100644
+--- a/drivers/net/ethernet/mediatek/mtk_wed.c
++++ b/drivers/net/ethernet/mediatek/mtk_wed.c
+@@ -472,7 +472,7 @@ mtk_wed_tx_buffer_alloc(struct mtk_wed_device *dev)
+ 		void *buf;
+ 		int s;
+ 
+-		page = __dev_alloc_pages(GFP_KERNEL, 0);
++		page = __dev_alloc_pages(GFP_KERNEL | GFP_DMA32, 0);
+ 		if (!page)
+ 			return -ENOMEM;
+ 
+@@ -636,7 +636,7 @@ mtk_wed_rx_page_buffer_alloc(struct mtk_wed_device *dev)
+ 		void *buf;
+ 		int s;
+ 
+-		page = __dev_alloc_pages(GFP_KERNEL, 0);
++		page = __dev_alloc_pages(GFP_KERNEL | GFP_DMA32, 0);
+ 		if (!page)
+ 			return -ENOMEM;
+ 
+@@ -2239,6 +2239,10 @@ mtk_wed_attach(struct mtk_wed_device *dev)
+ 	dev->wdma_idx = hw->index;
+ 	dev->ver = hw->version;
+ 
++	ret = dma_set_mask_and_coherent(hw->dev, DMA_BIT_MASK(32));
++	if (ret)
++		return ret;
++
+ 	if (dev->hw->version == 3)
+ 		dev->hw->pci_base = mtk_wed_get_pci_base(dev);
+ 
+diff --git a/drivers/net/ethernet/mediatek/mtk_wed_mcu.c b/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
+index 055594d..4ed1548 100644
+--- a/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
++++ b/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
+@@ -131,7 +131,7 @@ int mtk_wed_exception_init(struct mtk_wed_wo *wo)
+ 	}req;
+ 
+ 	exp->log_size = EXCEPTION_LOG_SIZE;
+-	exp->log = kmalloc(exp->log_size, GFP_ATOMIC);
++	exp->log = page_frag_alloc(&wo->page, exp->log_size, GFP_ATOMIC | GFP_DMA32);
+ 	if (!exp->log)
+ 		return -ENOMEM;
+ 
+@@ -151,7 +151,7 @@ int mtk_wed_exception_init(struct mtk_wed_wo *wo)
+ 				    &req, sizeof(req), false);
+ 
+ free:
+-	kfree(exp->log);
++	skb_free_frag(exp->log);
+ 	return -ENOMEM;
+ }
+ 
+diff --git a/drivers/net/ethernet/mediatek/mtk_wed_wo.c b/drivers/net/ethernet/mediatek/mtk_wed_wo.c
+index 54b7787..e991d20 100644
+--- a/drivers/net/ethernet/mediatek/mtk_wed_wo.c
++++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.c
+@@ -88,7 +88,7 @@ woif_q_rx_fill(struct mtk_wed_wo *wo, struct wed_wo_queue *q, bool rx)
+ 		page = &q->rx_page;
+ 
+ 	while (q->queued < q->ndesc) {
+-		buf = page_frag_alloc(page, len, GFP_ATOMIC);
++		buf = page_frag_alloc(page, len, GFP_ATOMIC | GFP_DMA32);
+ 		if (!buf)
+ 			break;
+ 
+@@ -555,7 +555,7 @@ void mtk_wed_wo_exit(struct mtk_wed_hw *hw)
+ 
+ 	if (wo->exp.log) {
+ 		dma_unmap_single(wo->hw->dev, wo->exp.phys, wo->exp.log_size, DMA_FROM_DEVICE);
+-		kfree(wo->exp.log);
++		skb_free_frag(wo->exp.log);
+ 	}
+ 
+ 	wo->hw = NULL;
+diff --git a/drivers/net/ethernet/mediatek/mtk_wed_wo.h b/drivers/net/ethernet/mediatek/mtk_wed_wo.h
+index 548b38e..3fd1f3f 100644
+--- a/drivers/net/ethernet/mediatek/mtk_wed_wo.h
++++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.h
+@@ -193,6 +193,7 @@ struct mtk_wed_wo {
+ 	const struct wed_wo_drv_ops *drv_ops;
+ 	const struct wed_wo_mcu_ops *mcu_ops;
+ 	const struct wed_wo_queue_ops *queue_ops;
++	struct page_frag_cache page;
+ 
+ 	struct net_device napi_dev;
+ 	spinlock_t rx_lock;
+-- 
+2.18.0
+