blob: f5ef68299265dc6039a41a901ed104677dd6f4a0 [file] [log] [blame]
developer5875ff12024-01-30 17:29:50 +08001From d4a2ad918d25ac2afd8b25761b68f2fe400a5974 Mon Sep 17 00:00:00 2001
2From: Benjamin Lin <benjamin-jw.lin@mediatek.com>
3Date: Mon, 29 Jan 2024 11:28:41 +0800
4Subject: [PATCH] wifi: mt76: mt7915: add support for WMM PBC configuration
5
6---
7 mt76_connac_mcu.h | 2 ++
8 mt7915/init.c | 2 ++
9 mt7915/mac.c | 14 ++++++++
10 mt7915/mcu.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++
11 mt7915/mcu.h | 15 ++++++++
12 mt7915/mt7915.h | 4 +++
13 6 files changed, 127 insertions(+)
14
15diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
16index 84e77fa..4eb59d3 100644
17--- a/mt76_connac_mcu.h
18+++ b/mt76_connac_mcu.h
19@@ -1014,6 +1014,7 @@ enum {
20 MCU_EXT_EVENT_ASSERT_DUMP = 0x23,
21 MCU_EXT_EVENT_RDD_REPORT = 0x3a,
22 MCU_EXT_EVENT_CSA_NOTIFY = 0x4f,
23+ MCU_EXT_EVENT_BSS_ACQ_PKT_CNT = 0x52,
24 MCU_EXT_EVENT_WA_TX_STAT = 0x74,
25 MCU_EXT_EVENT_BCC_NOTIFY = 0x75,
26 MCU_EXT_EVENT_MURU_CTRL = 0x9f,
27@@ -1209,6 +1210,7 @@ enum {
28 MCU_EXT_CMD_TXDPD_CAL = 0x60,
29 MCU_EXT_CMD_CAL_CACHE = 0x67,
30 MCU_EXT_CMD_RED_ENABLE = 0x68,
31+ MCU_EXT_CMD_PKT_BUDGET_CTRL = 0x6c,
32 MCU_EXT_CMD_SET_RADAR_TH = 0x7c,
33 MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d,
34 MCU_EXT_CMD_MWDS_SUPPORT = 0x80,
35diff --git a/mt7915/init.c b/mt7915/init.c
36index d5d9cbf..2fc1f3c 100644
37--- a/mt7915/init.c
38+++ b/mt7915/init.c
39@@ -1217,6 +1217,8 @@ int mt7915_register_device(struct mt7915_dev *dev)
40 INIT_WORK(&dev->dump_work, mt7915_mac_dump_work);
41 mutex_init(&dev->dump_mutex);
42
43+ INIT_WORK(&dev->wmm_pbc_work, mt7915_mcu_wmm_pbc_work);
44+
45 dev->dbdc_support = mt7915_band_config(dev);
46
47 phy2 = mt7915_alloc_ext_phy(dev);
48diff --git a/mt7915/mac.c b/mt7915/mac.c
49index 3736853..762159b 100644
50--- a/mt7915/mac.c
51+++ b/mt7915/mac.c
52@@ -2027,6 +2027,8 @@ void mt7915_mac_work(struct work_struct *work)
53
54 mt76_update_survey(mphy);
55 if (++mphy->mac_work_count == 5) {
56+ int i;
57+
58 mphy->mac_work_count = 0;
59
60 mt7915_mac_update_stats(phy);
61@@ -2034,6 +2036,18 @@ void mt7915_mac_work(struct work_struct *work)
62
63 if (phy->dev->muru_debug)
64 mt7915_mcu_muru_debug_get(phy);
65+
66+ /* Update DEV-wise information only in
67+ * the MAC work of the first band running.
68+ */
69+ for (i = MT_BAND0; i <= mphy->band_idx; ++i) {
70+ if (i == mphy->band_idx) {
71+ if (mt7915_mcu_wa_cmd(phy->dev, MCU_WA_PARAM_CMD(QUERY), MCU_WA_PARAM_BSS_ACQ_PKT_CNT,
72+ BSS_ACQ_PKT_CNT_BSS_BITMAP_ALL | BSS_ACQ_PKT_CNT_READ_CLR, 0))
73+ dev_err(mphy->dev->dev, "Failed to query per-AC-queue packet counts.\n");
74+ } else if (test_bit(MT76_STATE_RUNNING, &mphy->dev->phys[i]->state))
75+ break;
76+ }
77 }
78
79 if (++phy->stats_work_count == 10) {
80diff --git a/mt7915/mcu.c b/mt7915/mcu.c
81index 7a2a537..d101cbf 100644
82--- a/mt7915/mcu.c
83+++ b/mt7915/mcu.c
84@@ -354,6 +354,93 @@ mt7915_mcu_rx_bcc_notify(struct mt7915_dev *dev, struct sk_buff *skb)
85 mt7915_mcu_cca_finish, mphy->hw);
86 }
87
88+void mt7915_mcu_wmm_pbc_work(struct work_struct *work)
89+{
90+#define WMM_PBC_QUEUE_NUM 5
91+#define WMM_PBC_BSS_ALL 0xff
92+#define WMM_PBC_WLAN_IDX_ALL 0xffff
93+#define WMM_PBC_BOUND_DEFAULT 0xffff
94+#define WMM_PBC_UP_BOUND_BAND0_VO 950
95+#define WMM_PBC_UP_BOUND_BAND0_VI 950
96+#define WMM_PBC_UP_BOUND_BAND0_BE 750
97+#define WMM_PBC_UP_BOUND_BAND0_BK 450
98+#define WMM_PBC_UP_BOUND_BAND1_VO 1900
99+#define WMM_PBC_UP_BOUND_BAND1_VI 1900
100+#define WMM_PBC_UP_BOUND_BAND1_BE 1500
101+#define WMM_PBC_UP_BOUND_BAND1_BK 900
102+#define WMM_PBC_UP_BOUND_MGMT 32
103+ struct mt7915_dev *dev = container_of(work, struct mt7915_dev, wmm_pbc_work);
104+ struct {
105+ u8 bss_idx;
106+ u8 queue_num;
107+ __le16 wlan_idx;
108+ u8 __rsv[4];
109+ struct {
110+ __le16 low;
111+ __le16 up;
112+ } __packed bound[WMM_PBC_QUEUE_NUM * 2];
113+ } __packed req = {
114+ .bss_idx = WMM_PBC_BSS_ALL,
115+ .queue_num = WMM_PBC_QUEUE_NUM * 2,
116+ .wlan_idx = cpu_to_le16(WMM_PBC_WLAN_IDX_ALL),
117+ };
118+ int i;
119+
120+#define pbc_acq_up_bound_config(_band, _ac, _bound) \
121+ req.bound[_band * WMM_PBC_QUEUE_NUM + mt76_connac_lmac_mapping(_ac)].up = dev->wmm_pbc_enable \
122+ ? cpu_to_le16(_bound) \
123+ : cpu_to_le16(WMM_PBC_BOUND_DEFAULT)
124+ pbc_acq_up_bound_config(MT_BAND0, IEEE80211_AC_VO, WMM_PBC_UP_BOUND_BAND0_VO);
125+ pbc_acq_up_bound_config(MT_BAND0, IEEE80211_AC_VI, WMM_PBC_UP_BOUND_BAND0_VI);
126+ pbc_acq_up_bound_config(MT_BAND0, IEEE80211_AC_BE, WMM_PBC_UP_BOUND_BAND0_BE);
127+ pbc_acq_up_bound_config(MT_BAND0, IEEE80211_AC_BK, WMM_PBC_UP_BOUND_BAND0_BK);
128+ req.bound[MT_BAND0 * WMM_PBC_QUEUE_NUM + 4].up = dev->wmm_pbc_enable
129+ ? cpu_to_le16(WMM_PBC_UP_BOUND_MGMT)
130+ : cpu_to_le16(WMM_PBC_BOUND_DEFAULT);
131+ pbc_acq_up_bound_config(MT_BAND1, IEEE80211_AC_VO, WMM_PBC_UP_BOUND_BAND1_VO);
132+ pbc_acq_up_bound_config(MT_BAND1, IEEE80211_AC_VI, WMM_PBC_UP_BOUND_BAND1_VI);
133+ pbc_acq_up_bound_config(MT_BAND1, IEEE80211_AC_BE, WMM_PBC_UP_BOUND_BAND1_BE);
134+ pbc_acq_up_bound_config(MT_BAND1, IEEE80211_AC_BK, WMM_PBC_UP_BOUND_BAND1_BK);
135+ req.bound[MT_BAND1 * WMM_PBC_QUEUE_NUM + 4].up = dev->wmm_pbc_enable
136+ ? cpu_to_le16(WMM_PBC_UP_BOUND_MGMT)
137+ : cpu_to_le16(WMM_PBC_BOUND_DEFAULT);
138+
139+ for (i = 0; i < WMM_PBC_QUEUE_NUM * 2; ++i)
140+ req.bound[i].low = cpu_to_le16(WMM_PBC_BOUND_DEFAULT);
141+
142+ if (mt76_mcu_send_msg(&dev->mt76, MCU_WA_EXT_CMD(PKT_BUDGET_CTRL),
143+ &req, sizeof(req), true))
144+ dev_err(dev->mt76.dev, "Failed to configure WMM PBC.\n");
145+}
146+
147+static void
148+mt7915_mcu_rx_bss_acq_pkt_cnt(struct mt7915_dev *dev, struct sk_buff * skb)
149+{
150+ struct mt7915_mcu_bss_acq_pkt_cnt_event *event = (struct mt7915_mcu_bss_acq_pkt_cnt_event *)skb->data;
151+ u32 bitmap = le32_to_cpu(event->bss_bitmap);
152+ u64 sum[IEEE80211_NUM_ACS] = {0};
153+ u8 ac_cnt = 0;
154+ int i, j;
155+
156+ for (i = 0; (i < BSS_ACQ_PKT_CNT_BSS_NUM) && (bitmap & (1 << i)); ++i) {
157+ for (j = IEEE80211_AC_VO; j < IEEE80211_NUM_ACS; ++j)
158+ sum[j] += le32_to_cpu(event->bss[i].cnt[mt76_connac_lmac_mapping(j)]);
159+ }
160+
161+ for (i = IEEE80211_AC_VO; i < IEEE80211_NUM_ACS; ++i) {
162+ if (sum[i] > WMM_PKT_THRESHOLD)
163+ ++ac_cnt;
164+ }
165+
166+ if (ac_cnt > 1 && !dev->wmm_pbc_enable) {
167+ dev->wmm_pbc_enable = true;
168+ queue_work(dev->mt76.wq, &dev->wmm_pbc_work);
169+ } else if (ac_cnt <= 1 && dev->wmm_pbc_enable) {
170+ dev->wmm_pbc_enable = false;
171+ queue_work(dev->mt76.wq, &dev->wmm_pbc_work);
172+ }
173+}
174+
175 static void
176 mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
177 {
178@@ -376,6 +463,9 @@ mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb)
179 case MCU_EXT_EVENT_BCC_NOTIFY:
180 mt7915_mcu_rx_bcc_notify(dev, skb);
181 break;
182+ case MCU_EXT_EVENT_BSS_ACQ_PKT_CNT:
183+ mt7915_mcu_rx_bss_acq_pkt_cnt(dev, skb);
184+ break;
185 default:
186 break;
187 }
188diff --git a/mt7915/mcu.h b/mt7915/mcu.h
189index 8f36546..fa0847d 100644
190--- a/mt7915/mcu.h
191+++ b/mt7915/mcu.h
192@@ -329,10 +329,25 @@ enum {
193 MCU_WA_PARAM_CMD_DEBUG,
194 };
195
196+#define BSS_ACQ_PKT_CNT_BSS_NUM 24
197+#define BSS_ACQ_PKT_CNT_BSS_BITMAP_ALL 0x00ffffff
198+#define BSS_ACQ_PKT_CNT_READ_CLR BIT(31)
199+#define WMM_PKT_THRESHOLD 50
200+
201+struct mt7915_mcu_bss_acq_pkt_cnt_event {
202+ struct mt76_connac2_mcu_rxd rxd;
203+
204+ __le32 bss_bitmap;
205+ struct {
206+ __le32 cnt[IEEE80211_NUM_ACS];
207+ } __packed bss[BSS_ACQ_PKT_CNT_BSS_NUM];
208+} __packed;
209+
210 enum {
211 MCU_WA_PARAM_PDMA_RX = 0x04,
212 MCU_WA_PARAM_CPU_UTIL = 0x0b,
213 MCU_WA_PARAM_RED = 0x0e,
214+ MCU_WA_PARAM_BSS_ACQ_PKT_CNT = 0x12,
215 MCU_WA_PARAM_RED_SETTING = 0x40,
216 };
217
218diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
219index 1b79733..874d531 100644
220--- a/mt7915/mt7915.h
221+++ b/mt7915/mt7915.h
222@@ -322,6 +322,9 @@ struct mt7915_dev {
223 struct reset_control *rstc;
224 void __iomem *dcm;
225 void __iomem *sku;
226+
227+ bool wmm_pbc_enable;
228+ struct work_struct wmm_pbc_work;
229 };
230
231 enum {
232@@ -512,6 +515,7 @@ int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl);
233 int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level);
234 void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb);
235 void mt7915_mcu_exit(struct mt7915_dev *dev);
236+void mt7915_mcu_wmm_pbc_work(struct work_struct *work);
237
238 static inline u16 mt7915_wtbl_size(struct mt7915_dev *dev)
239 {
240--
2412.18.0
242