developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 1 | From 605a40dad37c685a49f2c7985e3a05806d7ac1fc Mon Sep 17 00:00:00 2001 |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 2 | From: Benjamin Lin <benjamin-jw.lin@mediatek.com> |
| 3 | Date: Thu, 25 Apr 2024 17:17:13 +0800 |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 4 | Subject: [PATCH] wifi: mt76: mt7915: fix inconsistent QoS mapping between SW |
| 5 | and HW |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 6 | |
| 7 | The mapping from IP DSCP to IEEE 802.11 user priority may be customized. |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 8 | Therefore, 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. |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 9 | |
| 10 | Signed-off-by: Benjamin Lin <benjamin-jw.lin@mediatek.com> |
| 11 | --- |
| 12 | mt76_connac_mcu.h | 1 + |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 13 | mt7915/main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++- |
| 14 | mt7915/mt7915.h | 4 ++++ |
| 15 | 3 files changed, 63 insertions(+), 1 deletion(-) |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 16 | |
| 17 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 18 | index 46dcd1c..e0255a2 100644 |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 19 | --- a/mt76_connac_mcu.h |
| 20 | +++ b/mt76_connac_mcu.h |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 21 | @@ -1238,6 +1238,7 @@ enum { |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 22 | 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 { |
| 29 | diff --git a/mt7915/main.c b/mt7915/main.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 30 | index f40a900..71f3ad1 100644 |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 31 | --- a/mt7915/main.c |
| 32 | +++ b/mt7915/main.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 33 | @@ -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) |
developer | 66bc8fb | 2024-05-06 17:14:15 +0800 | [diff] [blame] | 56 | return 0; |
| 57 | } |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 58 | |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 59 | +static int |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 60 | +mt7915_set_qos_map(struct ieee80211_vif *vif, struct cfg80211_qos_map *usr_qos_map) |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 61 | +{ |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 62 | + 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, |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 70 | + .qos_map_enable = usr_qos_map ? true : false, |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 71 | + }; |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 72 | + |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 73 | + /* Prevent access to members of mt7915_vif before its initialization. */ |
| 74 | + if (!mvif->phy) |
| 75 | + return -EPERM; |
| 76 | + |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 77 | + 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; |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 80 | + s8 i; |
| 81 | + |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 82 | + /* 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 */ |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 89 | + for (i = 0; i < IEEE80211_NUM_UPS; ++i) { |
| 90 | + u8 low = range[i].low, high = range[i].high; |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 91 | + |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 92 | + if (low < IP_DSCP_NUM && high < IP_DSCP_NUM && low <= high) |
| 93 | + memset(req.qos_map + low, i, high - low + 1); |
| 94 | + } |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 95 | + |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 96 | + for (i = 0; i < usr_qos_map->num_des; ++i) { |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 97 | + u8 dscp = exception[i].dscp, up = exception[i].up; |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 98 | + |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 99 | + if (dscp < IP_DSCP_NUM && up < IEEE80211_NUM_UPS) |
| 100 | + req.qos_map[dscp] = up; |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 101 | + } |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 102 | + memcpy(mvif->qos_map, req.qos_map, IP_DSCP_NUM); |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 103 | + } |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 104 | + |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 105 | + return mt76_mcu_send_msg(&mvif->phy->dev->mt76, MCU_WA_EXT_CMD(SET_QOS_MAP), |
| 106 | + &req, sizeof(req), true); |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 107 | +} |
developer | 66bc8fb | 2024-05-06 17:14:15 +0800 | [diff] [blame] | 108 | + |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 109 | static int |
| 110 | mt7915_set_radar_background(struct ieee80211_hw *hw, |
| 111 | struct cfg80211_chan_def *chandef) |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 112 | @@ -1751,6 +1807,7 @@ const struct ieee80211_ops mt7915_ops = { |
developer | 42c7a43 | 2024-07-12 14:39:29 +0800 | [diff] [blame] | 113 | .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 |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 120 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| 121 | index 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 */ |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 142 | -- |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 143 | 2.45.2 |
developer | dad89a3 | 2024-04-29 14:17:17 +0800 | [diff] [blame] | 144 | |