blob: 6eed8bd0bb32392e8539813aad6349258a34b496 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 6e6fb69bc4f57d622fae76d8d5a3102b8e98e10f Mon Sep 17 00:00:00 2001
developerdad89a32024-04-29 14:17:17 +08002From: Benjamin Lin <benjamin-jw.lin@mediatek.com>
3Date: Thu, 25 Apr 2024 17:17:13 +0800
developer42c7a432024-07-12 14:39:29 +08004Subject: [PATCH] wifi: mt76: mt7915: fix inconsistent QoS mapping between SW
5 and HW
developerdad89a32024-04-29 14:17:17 +08006
7The mapping from IP DSCP to IEEE 802.11 user priority may be customized.
developer42c7a432024-07-12 14:39:29 +08008Therefore, the mapping needs to be passed to HW, so that the QoS type of traffic can be mapped in a consistent manner for both SW and HW paths.
developerdad89a32024-04-29 14:17:17 +08009
10Signed-off-by: Benjamin Lin <benjamin-jw.lin@mediatek.com>
11---
12 mt76_connac_mcu.h | 1 +
developer05f3b2b2024-08-19 19:17:34 +080013 mt7915/main.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 52 insertions(+)
developerdad89a32024-04-29 14:17:17 +080015
16diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer05f3b2b2024-08-19 19:17:34 +080017index 46dcd1c..e0255a2 100644
developerdad89a32024-04-29 14:17:17 +080018--- a/mt76_connac_mcu.h
19+++ b/mt76_connac_mcu.h
developer42c7a432024-07-12 14:39:29 +080020@@ -1238,6 +1238,7 @@ enum {
developerdad89a32024-04-29 14:17:17 +080021 MCU_EXT_CMD_GROUP_PRE_CAL_INFO = 0xab,
22 MCU_EXT_CMD_DPD_PRE_CAL_INFO = 0xac,
23 MCU_EXT_CMD_PHY_STAT_INFO = 0xad,
24+ MCU_EXT_CMD_SET_QOS_MAP = 0xb4,
25 };
26
27 enum {
28diff --git a/mt7915/main.c b/mt7915/main.c
developer05f3b2b2024-08-19 19:17:34 +080029index f40a900..f82d0b1 100644
developerdad89a32024-04-29 14:17:17 +080030--- a/mt7915/main.c
31+++ b/mt7915/main.c
developer05f3b2b2024-08-19 19:17:34 +080032@@ -1619,6 +1619,56 @@ mt7915_set_frag_threshold(struct ieee80211_hw *hw, u32 val)
developer66bc8fb2024-05-06 17:14:15 +080033 return 0;
34 }
developerdad89a32024-04-29 14:17:17 +080035
developer42c7a432024-07-12 14:39:29 +080036+static int
developer05f3b2b2024-08-19 19:17:34 +080037+mt7915_set_qos_map(struct ieee80211_vif *vif, struct cfg80211_qos_map *usr_qos_map)
developerdad89a32024-04-29 14:17:17 +080038+{
39+#define IP_DSCP_NUM 64
40+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
41+ struct {
42+ u8 bss_idx;
43+ u8 qos_map_enable;
44+ u8 __rsv[2];
45+ s8 qos_map[IP_DSCP_NUM];
46+ } __packed req = {
47+ .bss_idx = mvif->mt76.idx,
developer05f3b2b2024-08-19 19:17:34 +080048+ .qos_map_enable = usr_qos_map ? true : false,
developerdad89a32024-04-29 14:17:17 +080049+ };
developerdad89a32024-04-29 14:17:17 +080050+
developer42c7a432024-07-12 14:39:29 +080051+ /* Prevent access to members of mt7915_vif before its initialization. */
52+ if (!mvif->phy)
53+ return -EPERM;
54+
developer05f3b2b2024-08-19 19:17:34 +080055+ if (usr_qos_map) {
56+ struct cfg80211_dscp_exception *exception = usr_qos_map->dscp_exception;
57+ struct cfg80211_dscp_range *range = usr_qos_map->up;
developer42c7a432024-07-12 14:39:29 +080058+ s8 i;
59+
developer05f3b2b2024-08-19 19:17:34 +080060+ /* Default QoS map, defined in section 2.3 of RFC8325.
61+ * Three most significant bits of DSCP are used as UP.
62+ */
63+ for (i = 0; i < IP_DSCP_NUM; ++i)
64+ req.qos_map[i] = i >> 3;
65+
66+ /* User-defined QoS map */
developer42c7a432024-07-12 14:39:29 +080067+ for (i = 0; i < IEEE80211_NUM_UPS; ++i) {
68+ u8 low = range[i].low, high = range[i].high;
developerdad89a32024-04-29 14:17:17 +080069+
developer42c7a432024-07-12 14:39:29 +080070+ if (low < IP_DSCP_NUM && high < IP_DSCP_NUM && low <= high)
71+ memset(req.qos_map + low, i, high - low + 1);
72+ }
developerdad89a32024-04-29 14:17:17 +080073+
developer05f3b2b2024-08-19 19:17:34 +080074+ for (i = 0; i < usr_qos_map->num_des; ++i) {
developer42c7a432024-07-12 14:39:29 +080075+ u8 dscp = exception[i].dscp, up = exception[i].up;
developerdad89a32024-04-29 14:17:17 +080076+
developer42c7a432024-07-12 14:39:29 +080077+ if (dscp < IP_DSCP_NUM && up < IEEE80211_NUM_UPS)
78+ req.qos_map[dscp] = up;
developerdad89a32024-04-29 14:17:17 +080079+ }
80+ }
developerdad89a32024-04-29 14:17:17 +080081+
developer42c7a432024-07-12 14:39:29 +080082+ return mt76_mcu_send_msg(&mvif->phy->dev->mt76, MCU_WA_EXT_CMD(SET_QOS_MAP),
83+ &req, sizeof(req), true);
developerdad89a32024-04-29 14:17:17 +080084+}
developer66bc8fb2024-05-06 17:14:15 +080085+
developer42c7a432024-07-12 14:39:29 +080086 static int
87 mt7915_set_radar_background(struct ieee80211_hw *hw,
88 struct cfg80211_chan_def *chandef)
developer05f3b2b2024-08-19 19:17:34 +080089@@ -1751,6 +1801,7 @@ const struct ieee80211_ops mt7915_ops = {
developer42c7a432024-07-12 14:39:29 +080090 .add_twt_setup = mt7915_mac_add_twt_setup,
91 .twt_teardown_request = mt7915_twt_teardown_request,
92 .set_frag_threshold = mt7915_set_frag_threshold,
93+ .set_qos_map = mt7915_set_qos_map,
94 CFG80211_TESTMODE_CMD(mt76_testmode_cmd)
95 CFG80211_TESTMODE_DUMP(mt76_testmode_dump)
96 #ifdef CONFIG_MAC80211_DEBUGFS
developerdad89a32024-04-29 14:17:17 +080097--
developer05f3b2b2024-08-19 19:17:34 +0800982.45.2
developerdad89a32024-04-29 14:17:17 +080099