developer | 43a264f | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 1 | From 8871427856374447f4275cde02936e73e452c080 Mon Sep 17 00:00:00 2001 |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 2 | From: Benjamin Lin <benjamin-jw.lin@mediatek.com> |
| 3 | Date: Thu, 4 Jan 2024 09:47:00 +0800 |
developer | ebda901 | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 4 | Subject: [PATCH 2021/2032] mtk: wifi: mt76: mt7996: add support for WMM PBC |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 5 | configuration |
| 6 | |
| 7 | Query per-AC-queue packet statistics from WA, and determine if multi-AC transmission is ongoing. |
| 8 | If it is, enable WMM mode in WA. Otherwise, disable WMM mode. |
| 9 | |
| 10 | Signed-off-by: Benjamin Lin <benjamin-jw.lin@mediatek.com> |
| 11 | --- |
| 12 | mt76_connac_mcu.h | 2 ++ |
| 13 | mt7996/init.c | 2 ++ |
| 14 | mt7996/mac.c | 4 +++ |
| 15 | mt7996/mcu.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ |
| 16 | mt7996/mcu.h | 15 +++++++++ |
| 17 | mt7996/mt7996.h | 4 +++ |
| 18 | 6 files changed, 105 insertions(+) |
| 19 | |
| 20 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
developer | ebda901 | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 21 | index 4f4b7b4f..b2b8f2a2 100644 |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 22 | --- a/mt76_connac_mcu.h |
| 23 | +++ b/mt76_connac_mcu.h |
developer | ebda901 | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 24 | @@ -1026,6 +1026,7 @@ enum { |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 25 | MCU_EXT_EVENT_ASSERT_DUMP = 0x23, |
| 26 | MCU_EXT_EVENT_RDD_REPORT = 0x3a, |
| 27 | MCU_EXT_EVENT_CSA_NOTIFY = 0x4f, |
| 28 | + MCU_EXT_EVENT_BSS_ACQ_PKT_CNT = 0x52, |
| 29 | MCU_EXT_EVENT_WA_TX_STAT = 0x74, |
| 30 | MCU_EXT_EVENT_BCC_NOTIFY = 0x75, |
| 31 | MCU_EXT_EVENT_MURU_CTRL = 0x9f, |
developer | ebda901 | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 32 | @@ -1224,6 +1225,7 @@ enum { |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 33 | MCU_EXT_CMD_TXDPD_CAL = 0x60, |
| 34 | MCU_EXT_CMD_CAL_CACHE = 0x67, |
| 35 | MCU_EXT_CMD_RED_ENABLE = 0x68, |
| 36 | + MCU_EXT_CMD_PKT_BUDGET_CTRL = 0x6c, |
| 37 | MCU_EXT_CMD_SET_RADAR_TH = 0x7c, |
| 38 | MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d, |
| 39 | MCU_EXT_CMD_MWDS_SUPPORT = 0x80, |
| 40 | diff --git a/mt7996/init.c b/mt7996/init.c |
developer | ebda901 | 2024-02-22 13:42:45 +0800 | [diff] [blame] | 41 | index 7a9b9749..90f3a417 100644 |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 42 | --- a/mt7996/init.c |
| 43 | +++ b/mt7996/init.c |
| 44 | @@ -1493,6 +1493,8 @@ int mt7996_register_device(struct mt7996_dev *dev) |
| 45 | INIT_WORK(&dev->dump_work, mt7996_mac_dump_work); |
| 46 | mutex_init(&dev->dump_mutex); |
| 47 | |
| 48 | + INIT_WORK(&dev->wmm_pbc_work, mt7996_mcu_wmm_pbc_work); |
| 49 | + |
| 50 | ret = mt7996_init_hardware(dev); |
| 51 | if (ret) |
| 52 | return ret; |
| 53 | diff --git a/mt7996/mac.c b/mt7996/mac.c |
developer | 43a264f | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 54 | index 901c2036..88e1fd14 100644 |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 55 | --- a/mt7996/mac.c |
| 56 | +++ b/mt7996/mac.c |
developer | 43a264f | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 57 | @@ -2302,6 +2302,10 @@ void mt7996_mac_work(struct work_struct *work) |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 58 | mt7996_mcu_get_all_sta_info(mdev, UNI_ALL_STA_TXRX_ADM_STAT); |
| 59 | mt7996_mcu_get_all_sta_info(mdev, UNI_ALL_STA_TXRX_MSDU_COUNT); |
| 60 | } |
| 61 | + |
| 62 | + if (mt7996_mcu_wa_cmd(phy->dev, MCU_WA_PARAM_CMD(QUERY), MCU_WA_PARAM_BSS_ACQ_PKT_CNT, |
| 63 | + BSS_ACQ_PKT_CNT_BSS_BITMAP_ALL | BSS_ACQ_PKT_CNT_READ_CLR, 0)) |
| 64 | + dev_err(mdev->dev, "Failed to query per-AC-queue packet counts.\n"); |
| 65 | } else if (mt7996_band_valid(phy->dev, i) && |
| 66 | test_bit(MT76_STATE_RUNNING, &mdev->phys[i]->state)) |
| 67 | break; |
| 68 | diff --git a/mt7996/mcu.c b/mt7996/mcu.c |
developer | 43a264f | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 69 | index 4907f729..6405c2fa 100644 |
developer | 8935fc1 | 2024-01-11 14:08:37 +0800 | [diff] [blame] | 70 | --- a/mt7996/mcu.c |
| 71 | +++ b/mt7996/mcu.c |
| 72 | @@ -666,6 +666,82 @@ mt7996_mcu_rx_thermal_notify(struct mt7996_dev *dev, struct sk_buff *skb) |
| 73 | phy->throttle_state = n->duty_percent; |
| 74 | } |
| 75 | |
| 76 | +void mt7996_mcu_wmm_pbc_work(struct work_struct *work) |
| 77 | +{ |
| 78 | +#define WMM_PBC_QUEUE_NUM 5 |
| 79 | +#define WMM_PBC_BSS_ALL 0xff |
| 80 | +#define WMM_PBC_WLAN_IDX_ALL 0xffff |
| 81 | +#define WMM_PBC_BOUND_DEFAULT 0xffff |
| 82 | +#define WMM_PBC_LOW_BOUND_VO 1900 |
| 83 | +#define WMM_PBC_LOW_BOUND_VI 1900 |
| 84 | +#define WMM_PBC_LOW_BOUND_BE 1500 |
| 85 | +#define WMM_PBC_LOW_BOUND_BK 900 |
| 86 | +#define WMM_PBC_LOW_BOUND_MGMT 32 |
| 87 | + struct mt7996_dev *dev = container_of(work, struct mt7996_dev, wmm_pbc_work); |
| 88 | + struct { |
| 89 | + u8 bss_idx; |
| 90 | + u8 queue_num; |
| 91 | + __le16 wlan_idx; |
| 92 | + u8 band_idx; |
| 93 | + u8 __rsv[3]; |
| 94 | + struct { |
| 95 | + __le16 low; |
| 96 | + __le16 up; |
| 97 | + } __packed bound[WMM_PBC_QUEUE_NUM]; |
| 98 | + } __packed req = { |
| 99 | + .bss_idx = WMM_PBC_BSS_ALL, |
| 100 | + .queue_num = WMM_PBC_QUEUE_NUM, |
| 101 | + .wlan_idx = cpu_to_le16(WMM_PBC_WLAN_IDX_ALL), |
| 102 | + .band_idx = dev->mphy.band_idx, |
| 103 | + }; |
| 104 | + int i, ret; |
| 105 | + |
| 106 | +#define pbc_acq_low_bound_config(_ac, _bound) \ |
| 107 | + req.bound[mt76_connac_lmac_mapping(_ac)].low = dev->wmm_pbc_enable ? cpu_to_le16(_bound) : 0 |
| 108 | + pbc_acq_low_bound_config(IEEE80211_AC_VO, WMM_PBC_LOW_BOUND_VO); |
| 109 | + pbc_acq_low_bound_config(IEEE80211_AC_VI, WMM_PBC_LOW_BOUND_VI); |
| 110 | + pbc_acq_low_bound_config(IEEE80211_AC_BE, WMM_PBC_LOW_BOUND_BE); |
| 111 | + pbc_acq_low_bound_config(IEEE80211_AC_BK, WMM_PBC_LOW_BOUND_BK); |
| 112 | + req.bound[4].low = dev->wmm_pbc_enable |
| 113 | + ? cpu_to_le16(WMM_PBC_LOW_BOUND_MGMT) : 0; |
| 114 | + |
| 115 | + for (i = 0; i < WMM_PBC_QUEUE_NUM; ++i) |
| 116 | + req.bound[i].up = cpu_to_le16(WMM_PBC_BOUND_DEFAULT); |
| 117 | + |
| 118 | + ret = mt76_mcu_send_msg(&dev->mt76, MCU_WA_EXT_CMD(PKT_BUDGET_CTRL), |
| 119 | + &req, sizeof(req), true); |
| 120 | + if (ret) |
| 121 | + dev_err(dev->mt76.dev, "Failed to configure WMM PBC.\n"); |
| 122 | +} |
| 123 | + |
| 124 | +static void |
| 125 | +mt7996_mcu_rx_bss_acq_pkt_cnt(struct mt7996_dev *dev, struct sk_buff *skb) |
| 126 | +{ |
| 127 | + struct mt7996_mcu_bss_acq_pkt_cnt_event *event = (struct mt7996_mcu_bss_acq_pkt_cnt_event *)skb->data; |
| 128 | + u32 bitmap = le32_to_cpu(event->bss_bitmap); |
| 129 | + u64 sum[IEEE80211_NUM_ACS] = {0}; |
| 130 | + u8 ac_cnt = 0; |
| 131 | + int i, j; |
| 132 | + |
| 133 | + for (i = 0; (i < BSS_ACQ_PKT_CNT_BSS_NUM) && (bitmap & (1 << i)); ++i) { |
| 134 | + for (j = IEEE80211_AC_VO; j < IEEE80211_NUM_ACS; ++j) |
| 135 | + sum[j] += le32_to_cpu(event->bss[i].cnt[mt76_connac_lmac_mapping(j)]); |
| 136 | + } |
| 137 | + |
| 138 | + for (i = IEEE80211_AC_VO; i < IEEE80211_NUM_ACS; ++i) { |
| 139 | + if (sum[i] > WMM_PKT_THRESHOLD) |
| 140 | + ++ac_cnt; |
| 141 | + } |
| 142 | + |
| 143 | + if (ac_cnt > 1 && !dev->wmm_pbc_enable) { |
| 144 | + dev->wmm_pbc_enable = true; |
| 145 | + queue_work(dev->mt76.wq, &dev->wmm_pbc_work); |
| 146 | + } else if (ac_cnt <= 1 && dev->wmm_pbc_enable) { |
| 147 | + dev->wmm_pbc_enable = false; |
| 148 | + queue_work(dev->mt76.wq, &dev->wmm_pbc_work); |
| 149 | + } |
| 150 | +} |
| 151 | + |
| 152 | static void |
| 153 | mt7996_mcu_rx_ext_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| 154 | { |
| 155 | @@ -675,6 +751,8 @@ mt7996_mcu_rx_ext_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| 156 | case MCU_EXT_EVENT_FW_LOG_2_HOST: |
| 157 | mt7996_mcu_rx_log_message(dev, skb); |
| 158 | break; |
| 159 | + case MCU_EXT_EVENT_BSS_ACQ_PKT_CNT: |
| 160 | + mt7996_mcu_rx_bss_acq_pkt_cnt(dev, skb); |
| 161 | default: |
| 162 | break; |
| 163 | } |
| 164 | diff --git a/mt7996/mcu.h b/mt7996/mcu.h |
| 165 | index cd327451..9dc7946b 100644 |
| 166 | --- a/mt7996/mcu.h |
| 167 | +++ b/mt7996/mcu.h |
| 168 | @@ -375,10 +375,25 @@ enum { |
| 169 | MCU_WA_PARAM_CMD_DEBUG, |
| 170 | }; |
| 171 | |
| 172 | +#define BSS_ACQ_PKT_CNT_BSS_NUM 24 |
| 173 | +#define BSS_ACQ_PKT_CNT_BSS_BITMAP_ALL 0x00ffffff |
| 174 | +#define BSS_ACQ_PKT_CNT_READ_CLR BIT(31) |
| 175 | +#define WMM_PKT_THRESHOLD 100 |
| 176 | + |
| 177 | +struct mt7996_mcu_bss_acq_pkt_cnt_event { |
| 178 | + struct mt7996_mcu_rxd rxd; |
| 179 | + |
| 180 | + __le32 bss_bitmap; |
| 181 | + struct { |
| 182 | + __le32 cnt[IEEE80211_NUM_ACS]; |
| 183 | + } __packed bss[BSS_ACQ_PKT_CNT_BSS_NUM]; |
| 184 | +} __packed; |
| 185 | + |
| 186 | enum { |
| 187 | MCU_WA_PARAM_PDMA_RX = 0x04, |
| 188 | MCU_WA_PARAM_CPU_UTIL = 0x0b, |
| 189 | MCU_WA_PARAM_RED_EN = 0x0e, |
| 190 | + MCU_WA_PARAM_BSS_ACQ_PKT_CNT = 0x12, |
| 191 | MCU_WA_PARAM_HW_PATH_HIF_VER = 0x2f, |
| 192 | MCU_WA_PARAM_RED_CONFIG = 0x40, |
| 193 | }; |
| 194 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
| 195 | index c5b83648..6ea024ef 100644 |
| 196 | --- a/mt7996/mt7996.h |
| 197 | +++ b/mt7996/mt7996.h |
| 198 | @@ -601,6 +601,9 @@ struct mt7996_dev { |
| 199 | u8 wtbl_size_group; |
| 200 | |
| 201 | struct mt7996_vow_ctrl vow; |
| 202 | + |
| 203 | + bool wmm_pbc_enable; |
| 204 | + struct work_struct wmm_pbc_work; |
| 205 | #ifdef CONFIG_MTK_DEBUG |
| 206 | u16 wlan_idx; |
| 207 | struct { |
| 208 | @@ -852,6 +855,7 @@ int mt7996_mcu_set_band_confg(struct mt7996_phy *phy, u16 option, bool enable); |
| 209 | int mt7996_mcu_set_vow_drr_ctrl(struct mt7996_phy *phy, struct mt7996_sta *msta, |
| 210 | enum vow_drr_ctrl_id id); |
| 211 | int mt7996_mcu_set_vow_feature_ctrl(struct mt7996_phy *phy); |
| 212 | +void mt7996_mcu_wmm_pbc_work(struct work_struct *work); |
| 213 | |
| 214 | static inline u8 mt7996_max_interface_num(struct mt7996_dev *dev) |
| 215 | { |
| 216 | -- |
| 217 | 2.18.0 |
| 218 | |