blob: 5f25fc542e8f58d4560629045d28781f2dbef52a [file] [log] [blame]
developerd0c89452024-10-11 16:53:27 +08001From 605a40dad37c685a49f2c7985e3a05806d7ac1fc 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 +
developerd0c89452024-10-11 16:53:27 +080013 mt7915/main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++-
14 mt7915/mt7915.h | 4 ++++
15 3 files changed, 63 insertions(+), 1 deletion(-)
developerdad89a32024-04-29 14:17:17 +080016
17diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer05f3b2b2024-08-19 19:17:34 +080018index 46dcd1c..e0255a2 100644
developerdad89a32024-04-29 14:17:17 +080019--- a/mt76_connac_mcu.h
20+++ b/mt76_connac_mcu.h
developer42c7a432024-07-12 14:39:29 +080021@@ -1238,6 +1238,7 @@ enum {
developerdad89a32024-04-29 14:17:17 +080022 MCU_EXT_CMD_GROUP_PRE_CAL_INFO = 0xab,
23 MCU_EXT_CMD_DPD_PRE_CAL_INFO = 0xac,
24 MCU_EXT_CMD_PHY_STAT_INFO = 0xad,
25+ MCU_EXT_CMD_SET_QOS_MAP = 0xb4,
26 };
27
28 enum {
29diff --git a/mt7915/main.c b/mt7915/main.c
developerd0c89452024-10-11 16:53:27 +080030index f40a900..71f3ad1 100644
developerdad89a32024-04-29 14:17:17 +080031--- a/mt7915/main.c
32+++ b/mt7915/main.c
developerd0c89452024-10-11 16:53:27 +080033@@ -209,7 +209,7 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,
34 struct mt7915_phy *phy = mt7915_hw_phy(hw);
35 struct mt76_txq *mtxq;
36 bool ext_phy = phy != &dev->phy;
37- int idx, ret = 0;
38+ int idx, i, ret = 0;
39
40 mutex_lock(&dev->mt76.mutex);
41
42@@ -255,6 +255,12 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,
43 mvif->sta.wcid.tx_info |= MT_WCID_TX_INFO_SET;
44 mt76_wcid_init(&mvif->sta.wcid);
45
46+ /* init Default QoS map, defined in section 2.3 of RFC8325.
47+ * Three most significant bits of DSCP are used as UP.
48+ */
49+ for (i = 0; i < IP_DSCP_NUM; ++i)
50+ mvif->qos_map[i] = i >> 3;
51+
52 mt7915_mac_wtbl_update(dev, idx,
53 MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
54
55@@ -1619,6 +1625,56 @@ mt7915_set_frag_threshold(struct ieee80211_hw *hw, u32 val)
developer66bc8fb2024-05-06 17:14:15 +080056 return 0;
57 }
developerdad89a32024-04-29 14:17:17 +080058
developer42c7a432024-07-12 14:39:29 +080059+static int
developer05f3b2b2024-08-19 19:17:34 +080060+mt7915_set_qos_map(struct ieee80211_vif *vif, struct cfg80211_qos_map *usr_qos_map)
developerdad89a32024-04-29 14:17:17 +080061+{
developerdad89a32024-04-29 14:17:17 +080062+ struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
63+ struct {
64+ u8 bss_idx;
65+ u8 qos_map_enable;
66+ u8 __rsv[2];
67+ s8 qos_map[IP_DSCP_NUM];
68+ } __packed req = {
69+ .bss_idx = mvif->mt76.idx,
developer05f3b2b2024-08-19 19:17:34 +080070+ .qos_map_enable = usr_qos_map ? true : false,
developerdad89a32024-04-29 14:17:17 +080071+ };
developerdad89a32024-04-29 14:17:17 +080072+
developer42c7a432024-07-12 14:39:29 +080073+ /* Prevent access to members of mt7915_vif before its initialization. */
74+ if (!mvif->phy)
75+ return -EPERM;
76+
developer05f3b2b2024-08-19 19:17:34 +080077+ if (usr_qos_map) {
78+ struct cfg80211_dscp_exception *exception = usr_qos_map->dscp_exception;
79+ struct cfg80211_dscp_range *range = usr_qos_map->up;
developer42c7a432024-07-12 14:39:29 +080080+ s8 i;
81+
developer05f3b2b2024-08-19 19:17:34 +080082+ /* Default QoS map, defined in section 2.3 of RFC8325.
83+ * Three most significant bits of DSCP are used as UP.
84+ */
85+ for (i = 0; i < IP_DSCP_NUM; ++i)
86+ req.qos_map[i] = i >> 3;
87+
88+ /* User-defined QoS map */
developer42c7a432024-07-12 14:39:29 +080089+ for (i = 0; i < IEEE80211_NUM_UPS; ++i) {
90+ u8 low = range[i].low, high = range[i].high;
developerdad89a32024-04-29 14:17:17 +080091+
developer42c7a432024-07-12 14:39:29 +080092+ if (low < IP_DSCP_NUM && high < IP_DSCP_NUM && low <= high)
93+ memset(req.qos_map + low, i, high - low + 1);
94+ }
developerdad89a32024-04-29 14:17:17 +080095+
developer05f3b2b2024-08-19 19:17:34 +080096+ for (i = 0; i < usr_qos_map->num_des; ++i) {
developer42c7a432024-07-12 14:39:29 +080097+ u8 dscp = exception[i].dscp, up = exception[i].up;
developerdad89a32024-04-29 14:17:17 +080098+
developer42c7a432024-07-12 14:39:29 +080099+ if (dscp < IP_DSCP_NUM && up < IEEE80211_NUM_UPS)
100+ req.qos_map[dscp] = up;
developerdad89a32024-04-29 14:17:17 +0800101+ }
developerd0c89452024-10-11 16:53:27 +0800102+ memcpy(mvif->qos_map, req.qos_map, IP_DSCP_NUM);
developerdad89a32024-04-29 14:17:17 +0800103+ }
developerdad89a32024-04-29 14:17:17 +0800104+
developer42c7a432024-07-12 14:39:29 +0800105+ return mt76_mcu_send_msg(&mvif->phy->dev->mt76, MCU_WA_EXT_CMD(SET_QOS_MAP),
106+ &req, sizeof(req), true);
developerdad89a32024-04-29 14:17:17 +0800107+}
developer66bc8fb2024-05-06 17:14:15 +0800108+
developer42c7a432024-07-12 14:39:29 +0800109 static int
110 mt7915_set_radar_background(struct ieee80211_hw *hw,
111 struct cfg80211_chan_def *chandef)
developerd0c89452024-10-11 16:53:27 +0800112@@ -1751,6 +1807,7 @@ const struct ieee80211_ops mt7915_ops = {
developer42c7a432024-07-12 14:39:29 +0800113 .add_twt_setup = mt7915_mac_add_twt_setup,
114 .twt_teardown_request = mt7915_twt_teardown_request,
115 .set_frag_threshold = mt7915_set_frag_threshold,
116+ .set_qos_map = mt7915_set_qos_map,
117 CFG80211_TESTMODE_CMD(mt76_testmode_cmd)
118 CFG80211_TESTMODE_DUMP(mt76_testmode_dump)
119 #ifdef CONFIG_MAC80211_DEBUGFS
developerd0c89452024-10-11 16:53:27 +0800120diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
121index 74cd8ca..bfac851 100644
122--- a/mt7915/mt7915.h
123+++ b/mt7915/mt7915.h
124@@ -83,6 +83,8 @@
125 #define MT7915_CRIT_TEMP 110
126 #define MT7915_MAX_TEMP 120
127
128+#define IP_DSCP_NUM 64
129+
130 struct mt7915_vif;
131 struct mt7915_sta;
132 struct mt7915_dfs_pulse;
133@@ -175,6 +177,8 @@ struct mt7915_vif {
134
135 struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
136 struct cfg80211_bitrate_mask bitrate_mask;
137+ /* QoS map support */
138+ u8 qos_map[IP_DSCP_NUM];
139 };
140
141 /* crash-dump */
developerdad89a32024-04-29 14:17:17 +0800142--
developer05f3b2b2024-08-19 19:17:34 +08001432.45.2
developerdad89a32024-04-29 14:17:17 +0800144