| From edbe4cad5b63d80c10ac7ae14010e7018e6b351a Mon Sep 17 00:00:00 2001 |
| From: Benjamin Lin <benjamin-jw.lin@mediatek.com> |
| Date: Thu, 4 Jan 2024 09:47:00 +0800 |
| Subject: [PATCH 2021/2028] mtk: wifi: mt76: mt7996: add support for WMM PBC |
| configuration |
| |
| Query per-AC-queue packet statistics from WA, and determine if multi-AC transmission is ongoing. |
| If it is, enable WMM mode in WA. Otherwise, disable WMM mode. |
| |
| Signed-off-by: Benjamin Lin <benjamin-jw.lin@mediatek.com> |
| --- |
| mt76_connac_mcu.h | 2 ++ |
| mt7996/init.c | 2 ++ |
| mt7996/mac.c | 4 +++ |
| mt7996/mcu.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ |
| mt7996/mcu.h | 15 +++++++++ |
| mt7996/mt7996.h | 4 +++ |
| 6 files changed, 105 insertions(+) |
| |
| diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
| index 77c5b62f..7b4548dd 100644 |
| --- a/mt76_connac_mcu.h |
| +++ b/mt76_connac_mcu.h |
| @@ -1022,6 +1022,7 @@ enum { |
| MCU_EXT_EVENT_ASSERT_DUMP = 0x23, |
| MCU_EXT_EVENT_RDD_REPORT = 0x3a, |
| MCU_EXT_EVENT_CSA_NOTIFY = 0x4f, |
| + MCU_EXT_EVENT_BSS_ACQ_PKT_CNT = 0x52, |
| MCU_EXT_EVENT_WA_TX_STAT = 0x74, |
| MCU_EXT_EVENT_BCC_NOTIFY = 0x75, |
| MCU_EXT_EVENT_MURU_CTRL = 0x9f, |
| @@ -1220,6 +1221,7 @@ enum { |
| MCU_EXT_CMD_TXDPD_CAL = 0x60, |
| MCU_EXT_CMD_CAL_CACHE = 0x67, |
| MCU_EXT_CMD_RED_ENABLE = 0x68, |
| + MCU_EXT_CMD_PKT_BUDGET_CTRL = 0x6c, |
| MCU_EXT_CMD_SET_RADAR_TH = 0x7c, |
| MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d, |
| MCU_EXT_CMD_MWDS_SUPPORT = 0x80, |
| diff --git a/mt7996/init.c b/mt7996/init.c |
| index 12682c9b..193904bc 100644 |
| --- a/mt7996/init.c |
| +++ b/mt7996/init.c |
| @@ -1493,6 +1493,8 @@ int mt7996_register_device(struct mt7996_dev *dev) |
| INIT_WORK(&dev->dump_work, mt7996_mac_dump_work); |
| mutex_init(&dev->dump_mutex); |
| |
| + INIT_WORK(&dev->wmm_pbc_work, mt7996_mcu_wmm_pbc_work); |
| + |
| ret = mt7996_init_hardware(dev); |
| if (ret) |
| return ret; |
| diff --git a/mt7996/mac.c b/mt7996/mac.c |
| index bdf808fc..94c0cfab 100644 |
| --- a/mt7996/mac.c |
| +++ b/mt7996/mac.c |
| @@ -2288,6 +2288,10 @@ void mt7996_mac_work(struct work_struct *work) |
| mt7996_mcu_get_all_sta_info(mdev, UNI_ALL_STA_TXRX_ADM_STAT); |
| mt7996_mcu_get_all_sta_info(mdev, UNI_ALL_STA_TXRX_MSDU_COUNT); |
| } |
| + |
| + if (mt7996_mcu_wa_cmd(phy->dev, MCU_WA_PARAM_CMD(QUERY), MCU_WA_PARAM_BSS_ACQ_PKT_CNT, |
| + BSS_ACQ_PKT_CNT_BSS_BITMAP_ALL | BSS_ACQ_PKT_CNT_READ_CLR, 0)) |
| + dev_err(mdev->dev, "Failed to query per-AC-queue packet counts.\n"); |
| } else if (mt7996_band_valid(phy->dev, i) && |
| test_bit(MT76_STATE_RUNNING, &mdev->phys[i]->state)) |
| break; |
| diff --git a/mt7996/mcu.c b/mt7996/mcu.c |
| index 62c073bd..85d04525 100644 |
| --- a/mt7996/mcu.c |
| +++ b/mt7996/mcu.c |
| @@ -666,6 +666,82 @@ mt7996_mcu_rx_thermal_notify(struct mt7996_dev *dev, struct sk_buff *skb) |
| phy->throttle_state = n->duty_percent; |
| } |
| |
| +void mt7996_mcu_wmm_pbc_work(struct work_struct *work) |
| +{ |
| +#define WMM_PBC_QUEUE_NUM 5 |
| +#define WMM_PBC_BSS_ALL 0xff |
| +#define WMM_PBC_WLAN_IDX_ALL 0xffff |
| +#define WMM_PBC_BOUND_DEFAULT 0xffff |
| +#define WMM_PBC_LOW_BOUND_VO 1900 |
| +#define WMM_PBC_LOW_BOUND_VI 1900 |
| +#define WMM_PBC_LOW_BOUND_BE 1500 |
| +#define WMM_PBC_LOW_BOUND_BK 900 |
| +#define WMM_PBC_LOW_BOUND_MGMT 32 |
| + struct mt7996_dev *dev = container_of(work, struct mt7996_dev, wmm_pbc_work); |
| + struct { |
| + u8 bss_idx; |
| + u8 queue_num; |
| + __le16 wlan_idx; |
| + u8 band_idx; |
| + u8 __rsv[3]; |
| + struct { |
| + __le16 low; |
| + __le16 up; |
| + } __packed bound[WMM_PBC_QUEUE_NUM]; |
| + } __packed req = { |
| + .bss_idx = WMM_PBC_BSS_ALL, |
| + .queue_num = WMM_PBC_QUEUE_NUM, |
| + .wlan_idx = cpu_to_le16(WMM_PBC_WLAN_IDX_ALL), |
| + .band_idx = dev->mphy.band_idx, |
| + }; |
| + int i, ret; |
| + |
| +#define pbc_acq_low_bound_config(_ac, _bound) \ |
| + req.bound[mt76_connac_lmac_mapping(_ac)].low = dev->wmm_pbc_enable ? cpu_to_le16(_bound) : 0 |
| + pbc_acq_low_bound_config(IEEE80211_AC_VO, WMM_PBC_LOW_BOUND_VO); |
| + pbc_acq_low_bound_config(IEEE80211_AC_VI, WMM_PBC_LOW_BOUND_VI); |
| + pbc_acq_low_bound_config(IEEE80211_AC_BE, WMM_PBC_LOW_BOUND_BE); |
| + pbc_acq_low_bound_config(IEEE80211_AC_BK, WMM_PBC_LOW_BOUND_BK); |
| + req.bound[4].low = dev->wmm_pbc_enable |
| + ? cpu_to_le16(WMM_PBC_LOW_BOUND_MGMT) : 0; |
| + |
| + for (i = 0; i < WMM_PBC_QUEUE_NUM; ++i) |
| + req.bound[i].up = cpu_to_le16(WMM_PBC_BOUND_DEFAULT); |
| + |
| + ret = mt76_mcu_send_msg(&dev->mt76, MCU_WA_EXT_CMD(PKT_BUDGET_CTRL), |
| + &req, sizeof(req), true); |
| + if (ret) |
| + dev_err(dev->mt76.dev, "Failed to configure WMM PBC.\n"); |
| +} |
| + |
| +static void |
| +mt7996_mcu_rx_bss_acq_pkt_cnt(struct mt7996_dev *dev, struct sk_buff *skb) |
| +{ |
| + struct mt7996_mcu_bss_acq_pkt_cnt_event *event = (struct mt7996_mcu_bss_acq_pkt_cnt_event *)skb->data; |
| + u32 bitmap = le32_to_cpu(event->bss_bitmap); |
| + u64 sum[IEEE80211_NUM_ACS] = {0}; |
| + u8 ac_cnt = 0; |
| + int i, j; |
| + |
| + for (i = 0; (i < BSS_ACQ_PKT_CNT_BSS_NUM) && (bitmap & (1 << i)); ++i) { |
| + for (j = IEEE80211_AC_VO; j < IEEE80211_NUM_ACS; ++j) |
| + sum[j] += le32_to_cpu(event->bss[i].cnt[mt76_connac_lmac_mapping(j)]); |
| + } |
| + |
| + for (i = IEEE80211_AC_VO; i < IEEE80211_NUM_ACS; ++i) { |
| + if (sum[i] > WMM_PKT_THRESHOLD) |
| + ++ac_cnt; |
| + } |
| + |
| + if (ac_cnt > 1 && !dev->wmm_pbc_enable) { |
| + dev->wmm_pbc_enable = true; |
| + queue_work(dev->mt76.wq, &dev->wmm_pbc_work); |
| + } else if (ac_cnt <= 1 && dev->wmm_pbc_enable) { |
| + dev->wmm_pbc_enable = false; |
| + queue_work(dev->mt76.wq, &dev->wmm_pbc_work); |
| + } |
| +} |
| + |
| static void |
| mt7996_mcu_rx_ext_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| { |
| @@ -675,6 +751,8 @@ mt7996_mcu_rx_ext_event(struct mt7996_dev *dev, struct sk_buff *skb) |
| case MCU_EXT_EVENT_FW_LOG_2_HOST: |
| mt7996_mcu_rx_log_message(dev, skb); |
| break; |
| + case MCU_EXT_EVENT_BSS_ACQ_PKT_CNT: |
| + mt7996_mcu_rx_bss_acq_pkt_cnt(dev, skb); |
| default: |
| break; |
| } |
| diff --git a/mt7996/mcu.h b/mt7996/mcu.h |
| index cd327451..9dc7946b 100644 |
| --- a/mt7996/mcu.h |
| +++ b/mt7996/mcu.h |
| @@ -375,10 +375,25 @@ enum { |
| MCU_WA_PARAM_CMD_DEBUG, |
| }; |
| |
| +#define BSS_ACQ_PKT_CNT_BSS_NUM 24 |
| +#define BSS_ACQ_PKT_CNT_BSS_BITMAP_ALL 0x00ffffff |
| +#define BSS_ACQ_PKT_CNT_READ_CLR BIT(31) |
| +#define WMM_PKT_THRESHOLD 100 |
| + |
| +struct mt7996_mcu_bss_acq_pkt_cnt_event { |
| + struct mt7996_mcu_rxd rxd; |
| + |
| + __le32 bss_bitmap; |
| + struct { |
| + __le32 cnt[IEEE80211_NUM_ACS]; |
| + } __packed bss[BSS_ACQ_PKT_CNT_BSS_NUM]; |
| +} __packed; |
| + |
| enum { |
| MCU_WA_PARAM_PDMA_RX = 0x04, |
| MCU_WA_PARAM_CPU_UTIL = 0x0b, |
| MCU_WA_PARAM_RED_EN = 0x0e, |
| + MCU_WA_PARAM_BSS_ACQ_PKT_CNT = 0x12, |
| MCU_WA_PARAM_HW_PATH_HIF_VER = 0x2f, |
| MCU_WA_PARAM_RED_CONFIG = 0x40, |
| }; |
| diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
| index c5b83648..6ea024ef 100644 |
| --- a/mt7996/mt7996.h |
| +++ b/mt7996/mt7996.h |
| @@ -601,6 +601,9 @@ struct mt7996_dev { |
| u8 wtbl_size_group; |
| |
| struct mt7996_vow_ctrl vow; |
| + |
| + bool wmm_pbc_enable; |
| + struct work_struct wmm_pbc_work; |
| #ifdef CONFIG_MTK_DEBUG |
| u16 wlan_idx; |
| struct { |
| @@ -852,6 +855,7 @@ int mt7996_mcu_set_band_confg(struct mt7996_phy *phy, u16 option, bool enable); |
| int mt7996_mcu_set_vow_drr_ctrl(struct mt7996_phy *phy, struct mt7996_sta *msta, |
| enum vow_drr_ctrl_id id); |
| int mt7996_mcu_set_vow_feature_ctrl(struct mt7996_phy *phy); |
| +void mt7996_mcu_wmm_pbc_work(struct work_struct *work); |
| |
| static inline u8 mt7996_max_interface_num(struct mt7996_dev *dev) |
| { |
| -- |
| 2.18.0 |
| |