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