[][MAC80211][core][Fix mac80211 patch fail and update RED patch]

[Description]
Fix mac80211 patch fail and update RED patch

[Release-log]
N/A

Change-Id: I4585866092631fe2bd62d3b643000efd0abf3e36
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6987008
diff --git a/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/99902-mac80211-mtk-register-.ndo_setup_tc-to-support-wifi.patch b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/99902-mac80211-mtk-register-.ndo_setup_tc-to-support-wifi.patch
new file mode 100644
index 0000000..9be85c9
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/99902-mac80211-mtk-register-.ndo_setup_tc-to-support-wifi.patch
@@ -0,0 +1,89 @@
+From 1ca2a807a8067e585e628e6eb4721e7fee00acd6 Mon Sep 17 00:00:00 2001
+From: Sujuan Chen <sujuan.chen@mediatek.com>
+Date: Fri, 23 Dec 2022 18:12:41 +0800
+Subject: [PATCH] mac80211: mtk: register .ndo_setup_tc to support wifi2wifi
+ offload
+
+Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
+---
+ include/net/mac80211.h |  5 +++++
+ net/mac80211/iface.c   | 26 ++++++++++++++++++++++++++
+ 2 files changed, 31 insertions(+)
+
+diff --git a/include/net/mac80211.h b/include/net/mac80211.h
+index dd9e834..d98312e 100644
+--- a/include/net/mac80211.h
++++ b/include/net/mac80211.h
+@@ -4188,6 +4188,8 @@ struct ieee80211_prep_tx_info {
+  *	In fact, cannot change from having valid_links and not having them.
+  * @net_fill_receive_path: Called from .ndo_fill_receive_path in order to
+  *	get a path for hardware flow offloading
++  * @net_setup_tc: Called from .ndo_setup_tc in order to register flowblock
++ *	callback function
+  */
+ struct ieee80211_ops {
+ 	void (*tx)(struct ieee80211_hw *hw,
+@@ -4546,6 +4548,9 @@ struct ieee80211_ops {
+ 	int (*net_fill_receive_path)(struct ieee80211_hw *hw,
+ 				     struct net_device_path_ctx *ctx,
+ 				     struct net_device_path *path);
++	int (*net_setup_tc)(struct ieee80211_hw *hw,
++			    struct net_device *dev,
++			    int type, void *type_data);
+ };
+ 
+ /**
+diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
+index 6e76b23..b80fb66 100644
+--- a/net/mac80211/iface.c
++++ b/net/mac80211/iface.c
+@@ -942,6 +942,30 @@ static int ieee80211_netdev_fill_receive_path(struct net_device_path_ctx *ctx,
+ 	return ret;
+ }
+ 
++static int ieee80211_netdev_setup_tc(struct net_device *dev,
++					       enum tc_setup_type type, void *type_data)
++{
++	struct ieee80211_sub_if_data *sdata;
++	struct ieee80211_local *local;
++	int ret = -ENOENT;
++
++	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
++	local = sdata->local;
++
++	if (!local->ops->net_setup_tc)
++		return -EOPNOTSUPP;
++
++	if (!type_data)
++		return -EINVAL;
++
++	rcu_read_lock();
++
++	ret = local->ops->net_setup_tc(&local->hw, dev, (int)type, type_data);
++
++	rcu_read_unlock();
++
++	return ret;
++}
+ 
+ static const struct net_device_ops ieee80211_dataif_8023_ops = {
+ 	.ndo_open		= ieee80211_open,
+@@ -953,6 +977,7 @@ static const struct net_device_ops ieee80211_dataif_8023_ops = {
+ 	.ndo_get_stats64	= ieee80211_get_stats64,
+ 	.ndo_fill_forward_path	= ieee80211_netdev_fill_forward_path,
+ 	.ndo_fill_receive_path = ieee80211_netdev_fill_receive_path,
++	.ndo_setup_tc		= ieee80211_netdev_setup_tc,
+ };
+ 
+ static bool ieee80211_iftype_supports_hdr_offload(enum nl80211_iftype iftype)
+@@ -1482,6 +1507,7 @@ static void ieee80211_if_setup(struct net_device *dev)
+ 	ether_setup(dev);
+ 	dev->priv_flags &= ~IFF_TX_SKB_SHARING;
+ 	dev->priv_flags |= IFF_NO_QUEUE;
++	dev->features |= NETIF_F_HW_TC;
+ 	dev->netdev_ops = &ieee80211_dataif_ops;
+ 	dev->needs_free_netdev = true;
+ 	dev->priv_destructor = ieee80211_if_free;
+-- 
+2.18.0
+
diff --git a/autobuild_mac80211_release/package/kernel/mt76/patches/3006-mt76-mt7915-wed-enable-red-per-band-token-drop-for-H.patch b/autobuild_mac80211_release/package/kernel/mt76/patches/3006-mt76-mt7915-wed-enable-red-per-band-token-drop-for-H.patch
index 5eed16f..de7a3a1 100644
--- a/autobuild_mac80211_release/package/kernel/mt76/patches/3006-mt76-mt7915-wed-enable-red-per-band-token-drop-for-H.patch
+++ b/autobuild_mac80211_release/package/kernel/mt76/patches/3006-mt76-mt7915-wed-enable-red-per-band-token-drop-for-H.patch
@@ -1,8 +1,7 @@
-From f7a5428387ab23b9c9de3a67ad1ffc5921f89b72 Mon Sep 17 00:00:00 2001
+From 2f0b6e966f10cfcdb3a325238e10966c25c1ea3b Mon Sep 17 00:00:00 2001
 From: Peter Chiu <chui-hao.chiu@mediatek.com>
 Date: Fri, 2 Sep 2022 14:40:40 +0800
-Subject: [PATCH 3006/3013] mt76: mt7915: wed: enable red per-band token drop
- for HW Path
+Subject: [PATCH] mt76: mt7915: wed: enable red per-band token drop for HW Path
 
 Limit the number of token used by each band. If a band uses too many token,
 it may hurt the throughput of the other band. The SW path can solve this
@@ -10,49 +9,55 @@
 
 Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
 ---
- mt7915/mcu.c    | 56 ++++++++++++++++++++++++++++++++++++++++---------
- mt7915/mcu.h    |  1 +
- mt7915/mmio.c   |  2 +-
- mt7915/mt7915.h |  4 +++-
- 4 files changed, 51 insertions(+), 12 deletions(-)
+ mt76_connac_mcu.h |  2 +-
+ mt7915/mcu.c      | 45 ++++++++++++++++++++++++++++++++++++++-------
+ mt7915/mcu.h      |  1 +
+ mt7915/mmio.c     |  2 +-
+ mt7915/mt7915.h   |  4 +++-
+ 5 files changed, 44 insertions(+), 10 deletions(-)
 
+diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
+index 98b00747..21ea55d1 100644
+--- a/mt76_connac_mcu.h
++++ b/mt76_connac_mcu.h
+@@ -1174,13 +1174,13 @@ enum {
+ 	MCU_EXT_CMD_RXDCOC_CAL = 0x59,
+ 	MCU_EXT_CMD_GET_MIB_INFO = 0x5a,
+ #ifdef MTK_DEBUG
+-	MCU_EXT_CMD_RED_ENABLE = 0x68,
+ 	MCU_EXT_CMD_RED_SHOW_STA = 0x69,
+ 	MCU_EXT_CMD_RED_TARGET_DELAY = 0x6A,
+ 	MCU_EXT_CMD_RED_TX_RPT = 0x6B,
+ #endif
+ 	MCU_EXT_CMD_TXDPD_CAL = 0x60,
+ 	MCU_EXT_CMD_CAL_CACHE = 0x67,
++	MCU_EXT_CMD_RED_ENABLE = 0x68,
+ 	MCU_EXT_CMD_SET_RADAR_TH = 0x7c,
+ 	MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d,
+ 	MCU_EXT_CMD_MWDS_SUPPORT = 0x80,
 diff --git a/mt7915/mcu.c b/mt7915/mcu.c
-index f494d9f..5b2ae77 100644
+index f494d9f6..116a5cc9 100644
 --- a/mt7915/mcu.c
 +++ b/mt7915/mcu.c
-@@ -2374,8 +2374,17 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
- 						dev->mt76.mmio.wed.rev_id, 0);
- 		if (ret)
+@@ -2376,6 +2376,7 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
  			return ret;
-+
-+		ret = mt7915_mcu_set_red(dev, true);
-+		if (ret)
-+			return ret;
-+	} else {
-+		mt7915_mcu_set_red(dev, false);
-+		if (ret)
-+			return ret;
  	}
  
 +
  	ret = mt7915_mcu_set_mwds(dev, 1);
  	if (ret)
  		return ret;
-@@ -2385,12 +2394,7 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
+@@ -2389,8 +2390,7 @@ int mt7915_mcu_init_firmware(struct mt7915_dev *dev)
  	if (ret)
  		return ret;
  
--	ret = mt7915_mcu_init_rx_airtime(dev);
--	if (ret)
--		return ret;
--
 -	return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
 -				 MCU_WA_PARAM_RED, 0, 0);
-+	return mt7915_mcu_init_rx_airtime(dev);
++	return mt7915_mcu_set_red(dev, mtk_wed_device_active(&dev->mt76.mmio.wed));
  }
  
  int mt7915_mcu_init(struct mt7915_dev *dev)
-@@ -4533,6 +4537,34 @@ int mt7915_dbg_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a
+@@ -4533,27 +4533,58 @@ int mt7915_dbg_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a
  
  	return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), wait_resp);
  }
@@ -72,7 +77,7 @@
 +		__le16 high_mark;
 +		__le16 low_mark;
 +		u8 __rsv2[12];
-+	} req = {
++	} __packed req = {
 +		.args[0] = cpu_to_le32(MCU_WA_PARAM_RED_SETTING),
 +		.cmd = RED_GLOBAL_TOKEN_WATERMARK,
 +		.len = cpu_to_le16(sizeof(req) - 12),
@@ -87,7 +92,10 @@
  
  int mt7915_mcu_set_red(struct mt7915_dev *dev, bool enabled)
  {
-@@ -4543,17 +4575,21 @@ int mt7915_mcu_set_red(struct mt7915_dev *dev, bool enabled)
+ #define RED_DISABLE		0
+-#define RED_BY_HOST_ENABLE	1
+ #define RED_BY_WA_ENABLE	2
+ 	int ret;
  	u32 red_type = enabled > 0 ? RED_BY_WA_ENABLE : RED_DISABLE;
  	__le32 req = cpu_to_le32(red_type);
  
@@ -114,7 +122,7 @@
  int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set)
  {
 diff --git a/mt7915/mcu.h b/mt7915/mcu.h
-index f2f88cc..572cc16 100644
+index f2f88cc4..572cc16a 100644
 --- a/mt7915/mcu.h
 +++ b/mt7915/mcu.h
 @@ -285,6 +285,7 @@ enum {
@@ -126,7 +134,7 @@
  	MCU_WA_PARAM_RED_SHOW_STA = 0xf,
  	MCU_WA_PARAM_RED_TARGET_DELAY = 0x10,
 diff --git a/mt7915/mmio.c b/mt7915/mmio.c
-index e0761e8..b29fe7a 100644
+index e0761e89..b29fe7a4 100644
 --- a/mt7915/mmio.c
 +++ b/mt7915/mmio.c
 @@ -759,7 +759,7 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr,
@@ -139,7 +147,7 @@
  	wed->wlan.tx_tbit[1] = is_mt7915(&dev->mt76) ? 5 : 31;
  	wed->wlan.txfree_tbit = is_mt7986(&dev->mt76) ? 2 : 1;
 diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
-index 89c13db..2335f78 100644
+index 89c13dbe..2335f78f 100644
 --- a/mt7915/mt7915.h
 +++ b/mt7915/mt7915.h
 @@ -56,6 +56,7 @@
@@ -167,5 +175,5 @@
  int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level);
  void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len);
 -- 
-2.36.1
+2.18.0