blob: 6120b94a29229a86e3bae03e35847820c8891af1 [file] [log] [blame]
developer753619c2024-02-22 13:42:45 +08001From c9b6bb691e58656f520262ec544f37f00aaf4ec2 Mon Sep 17 00:00:00 2001
developera16be1f2022-12-14 13:09:20 +08002From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Mon, 5 Dec 2022 18:21:51 +0800
developer753619c2024-02-22 13:42:45 +08004Subject: [PATCH 1025/1048] wifi: mt76: mt7915: add bf backoff limit table
developereb155692024-01-11 14:08:37 +08005 support
developera16be1f2022-12-14 13:09:20 +08006
7Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
8---
developereb155692024-01-11 14:08:37 +08009 debugfs.c | 4 +-
developer70180b02023-11-14 17:01:47 +080010 eeprom.c | 43 ++++++++++--
developera16be1f2022-12-14 13:09:20 +080011 mt76.h | 8 +++
developereb155692024-01-11 14:08:37 +080012 mt7915/debugfs.c | 73 +++++++++++++++++--
developer70180b02023-11-14 17:01:47 +080013 mt7915/init.c | 7 ++
developereb155692024-01-11 14:08:37 +080014 mt7915/main.c | 6 +-
15 mt7915/mcu.c | 178 +++++++++++++++++++++++++++++++++++++----------
developer70180b02023-11-14 17:01:47 +080016 mt7915/mcu.h | 6 ++
17 mt7915/mt7915.h | 9 ++-
developereb155692024-01-11 14:08:37 +080018 9 files changed, 279 insertions(+), 55 deletions(-)
developera16be1f2022-12-14 13:09:20 +080019
developerf9b00212023-07-31 12:27:06 +080020diff --git a/debugfs.c b/debugfs.c
developereb155692024-01-11 14:08:37 +080021index 1c8328d..a626f7c 100644
developerf9b00212023-07-31 12:27:06 +080022--- a/debugfs.c
23+++ b/debugfs.c
developereb155692024-01-11 14:08:37 +080024@@ -95,9 +95,9 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
developerf9b00212023-07-31 12:27:06 +080025 {
26 int i;
27
28- seq_printf(file, "%10s:", str);
29+ seq_printf(file, "%16s:", str);
30 for (i = 0; i < len; i++)
developereb155692024-01-11 14:08:37 +080031- seq_printf(file, " %2d", val[i]);
32+ seq_printf(file, " %4d", val[i]);
developerf9b00212023-07-31 12:27:06 +080033 seq_puts(file, "\n");
developereb155692024-01-11 14:08:37 +080034 }
35 EXPORT_SYMBOL_GPL(mt76_seq_puts_array);
developera16be1f2022-12-14 13:09:20 +080036diff --git a/eeprom.c b/eeprom.c
developereb155692024-01-11 14:08:37 +080037index 9d029c0..4213e44 100644
developera16be1f2022-12-14 13:09:20 +080038--- a/eeprom.c
39+++ b/eeprom.c
developereb155692024-01-11 14:08:37 +080040@@ -336,9 +336,10 @@ mt76_apply_array_limit(s8 *pwr, size_t pwr_len, const __be32 *data,
developer70180b02023-11-14 17:01:47 +080041 static void
42 mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num,
43 const __be32 *data, size_t len, s8 target_power,
44- s8 nss_delta, s8 *max_power)
45+ s8 nss_delta)
46 {
47 int i, cur;
48+ s8 max_power = -128;
49
50 if (!data)
51 return;
developereb155692024-01-11 14:08:37 +080052@@ -350,7 +351,7 @@ mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num,
developer70180b02023-11-14 17:01:47 +080053 break;
54
55 mt76_apply_array_limit(pwr + pwr_len * i, pwr_len, data + 1,
56- target_power, nss_delta, max_power);
57+ target_power, nss_delta, &max_power);
58 if (--cur > 0)
59 continue;
60
developereb155692024-01-11 14:08:37 +080061@@ -377,12 +378,16 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
developer327aa322023-07-10 13:49:56 +080062 char band;
63 size_t len;
developerc8796032023-08-09 10:28:15 +080064 s8 max_power = -127;
developer327aa322023-07-10 13:49:56 +080065+ s8 max_power_backoff = -127;
66 s8 txs_delta;
developerf9b00212023-07-31 12:27:06 +080067+ int n_chains = hweight16(phy->chainmask);
developer327aa322023-07-10 13:49:56 +080068+ s8 target_power_combine = target_power + mt76_tx_power_nss_delta(n_chains);
69
developera16be1f2022-12-14 13:09:20 +080070 if (!mcs_rates)
71 mcs_rates = 10;
72
73- memset(dest, target_power, sizeof(*dest));
74+ memset(dest, target_power, sizeof(*dest) - sizeof(dest->path));
75+ memset(&dest->path, 0, sizeof(dest->path));
76
77 if (!IS_ENABLED(CONFIG_OF))
78 return target_power;
developereb155692024-01-11 14:08:37 +080079@@ -428,14 +433,40 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
developer70180b02023-11-14 17:01:47 +080080 val = mt76_get_of_array(np, "rates-mcs", &len, mcs_rates + 1);
81 mt76_apply_multi_array_limit(dest->mcs[0], ARRAY_SIZE(dest->mcs[0]),
82 ARRAY_SIZE(dest->mcs), val, len,
83- target_power, txs_delta, &max_power);
84+ target_power, txs_delta);
85
86 val = mt76_get_of_array(np, "rates-ru", &len, ru_rates + 1);
87 mt76_apply_multi_array_limit(dest->ru[0], ARRAY_SIZE(dest->ru[0]),
developera16be1f2022-12-14 13:09:20 +080088 ARRAY_SIZE(dest->ru), val, len,
developer70180b02023-11-14 17:01:47 +080089- target_power, txs_delta, &max_power);
90+ target_power, txs_delta);
developera16be1f2022-12-14 13:09:20 +080091
developer327aa322023-07-10 13:49:56 +080092- return max_power;
93+ max_power_backoff = max_power;
developera16be1f2022-12-14 13:09:20 +080094+ val = mt76_get_of_array(np, "paths-cck", &len, ARRAY_SIZE(dest->path.cck));
95+ mt76_apply_array_limit(dest->path.cck, ARRAY_SIZE(dest->path.cck), val,
developer327aa322023-07-10 13:49:56 +080096+ target_power_combine, txs_delta, &max_power_backoff);
developera16be1f2022-12-14 13:09:20 +080097+
98+ val = mt76_get_of_array(np, "paths-ofdm", &len, ARRAY_SIZE(dest->path.ofdm));
99+ mt76_apply_array_limit(dest->path.ofdm, ARRAY_SIZE(dest->path.ofdm), val,
developer327aa322023-07-10 13:49:56 +0800100+ target_power_combine, txs_delta, &max_power_backoff);
developera16be1f2022-12-14 13:09:20 +0800101+
102+ val = mt76_get_of_array(np, "paths-ofdm-bf", &len, ARRAY_SIZE(dest->path.ofdm_bf));
103+ mt76_apply_array_limit(dest->path.ofdm_bf, ARRAY_SIZE(dest->path.ofdm_bf), val,
developer327aa322023-07-10 13:49:56 +0800104+ target_power_combine, txs_delta, &max_power_backoff);
developera16be1f2022-12-14 13:09:20 +0800105+
106+ val = mt76_get_of_array(np, "paths-ru", &len, ARRAY_SIZE(dest->path.ru[0]) + 1);
107+ mt76_apply_multi_array_limit(dest->path.ru[0], ARRAY_SIZE(dest->path.ru[0]),
108+ ARRAY_SIZE(dest->path.ru), val, len,
developer70180b02023-11-14 17:01:47 +0800109+ target_power_combine, txs_delta);
developera16be1f2022-12-14 13:09:20 +0800110+
111+ val = mt76_get_of_array(np, "paths-ru-bf", &len, ARRAY_SIZE(dest->path.ru_bf[0]) + 1);
112+ mt76_apply_multi_array_limit(dest->path.ru_bf[0], ARRAY_SIZE(dest->path.ru_bf[0]),
113+ ARRAY_SIZE(dest->path.ru_bf), val, len,
developer70180b02023-11-14 17:01:47 +0800114+ target_power_combine, txs_delta);
developera16be1f2022-12-14 13:09:20 +0800115+
developer327aa322023-07-10 13:49:56 +0800116+ if (max_power_backoff == target_power_combine)
117+ return max_power;
118+
119+ return max_power_backoff;
developera16be1f2022-12-14 13:09:20 +0800120 }
121 EXPORT_SYMBOL_GPL(mt76_get_rate_power_limits);
developer327aa322023-07-10 13:49:56 +0800122
developera16be1f2022-12-14 13:09:20 +0800123diff --git a/mt76.h b/mt76.h
developer753619c2024-02-22 13:42:45 +0800124index 412ef33..781be50 100644
developera16be1f2022-12-14 13:09:20 +0800125--- a/mt76.h
126+++ b/mt76.h
developer753619c2024-02-22 13:42:45 +0800127@@ -1084,6 +1084,14 @@ struct mt76_power_limits {
developera16be1f2022-12-14 13:09:20 +0800128 s8 mcs[4][10];
129 s8 ru[7][12];
developerbd9fa1e2023-10-16 11:04:00 +0800130 s8 eht[16][16];
developera16be1f2022-12-14 13:09:20 +0800131+
132+ struct {
133+ s8 cck[4];
134+ s8 ofdm[4];
135+ s8 ofdm_bf[4];
136+ s8 ru[7][10];
137+ s8 ru_bf[7][10];
138+ } path;
139 };
140
141 struct mt76_ethtool_worker_info {
142diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c
developer753619c2024-02-22 13:42:45 +0800143index 40a126f..c7002ee 100644
developera16be1f2022-12-14 13:09:20 +0800144--- a/mt7915/debugfs.c
145+++ b/mt7915/debugfs.c
developer47efbdb2023-06-29 20:33:22 +0800146@@ -1019,7 +1019,7 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
developera16be1f2022-12-14 13:09:20 +0800147 if (!buf)
148 return -ENOMEM;
149
150- ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr));
151+ ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr), TX_POWER_INFO_RATE);
152 if (ret)
153 goto out;
154
developerc8796032023-08-09 10:28:15 +0800155@@ -1133,7 +1133,7 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
developera16be1f2022-12-14 13:09:20 +0800156
157 mutex_lock(&dev->mt76.mutex);
158 ret = mt7915_mcu_get_txpower_sku(phy, req.txpower_sku,
159- sizeof(req.txpower_sku));
160+ sizeof(req.txpower_sku), TX_POWER_INFO_RATE);
161 if (ret)
162 goto out;
163
developerc8796032023-08-09 10:28:15 +0800164@@ -1175,7 +1175,7 @@ out:
developera16be1f2022-12-14 13:09:20 +0800165 return ret ? ret : count;
166 }
167
168-static const struct file_operations mt7915_rate_txpower_fops = {
169+static const struct file_operations mt7915_txpower_fops = {
170 .write = mt7915_rate_txpower_set,
171 .read = mt7915_rate_txpower_get,
172 .open = simple_open,
developerc8796032023-08-09 10:28:15 +0800173@@ -1183,6 +1183,69 @@ static const struct file_operations mt7915_rate_txpower_fops = {
developera16be1f2022-12-14 13:09:20 +0800174 .llseek = default_llseek,
175 };
176
177+static int
178+mt7915_path_txpower_show(struct seq_file *file)
179+{
180+ struct mt7915_phy *phy = file->private;
181+ s8 txpower[MT7915_SKU_PATH_NUM], *buf = txpower;
182+ int ret;
183+
184+#define PATH_POWER_SHOW(_name, _len, _skip) do { \
185+ if (_skip) { \
186+ buf -= 1; \
187+ *buf = 0; \
188+ } \
189+ mt76_seq_puts_array(file, _name, buf, _len); \
190+ buf += _len; \
191+ } while(0)
192+
developereb155692024-01-11 14:08:37 +0800193+ seq_printf(file, "\n%*c", 18, ' ');
developera16be1f2022-12-14 13:09:20 +0800194+ seq_printf(file, "1T1S/2T1S/3T1S/4T1S/2T2S/3T2S/4T2S/3T3S/4T3S/4T4S\n");
195+ ret = mt7915_mcu_get_txpower_sku(phy, txpower, sizeof(txpower),
196+ TX_POWER_INFO_PATH);
197+ if (ret)
198+ return ret;
199+
200+ PATH_POWER_SHOW("CCK", 4, 0);
201+ PATH_POWER_SHOW("OFDM", 4, 0);
202+ PATH_POWER_SHOW("BF-OFDM", 4, 1);
203+
developerf9b00212023-07-31 12:27:06 +0800204+ PATH_POWER_SHOW("HT/VHT20", 10, 0);
205+ PATH_POWER_SHOW("BF-HT/VHT20", 10, 1);
206+ PATH_POWER_SHOW("HT/VHT40", 10, 0);
207+ PATH_POWER_SHOW("BF-HT/VHT40", 10, 1);
developera16be1f2022-12-14 13:09:20 +0800208+
developerf9b00212023-07-31 12:27:06 +0800209+ PATH_POWER_SHOW("BW20/RU242", 10, 0);
210+ PATH_POWER_SHOW("BF-BW20/RU242", 10, 1);
211+ PATH_POWER_SHOW("BW40/RU484", 10, 0);
212+ PATH_POWER_SHOW("BF-BW40/RU484", 10, 1);
213+ PATH_POWER_SHOW("BW80/RU996", 10, 0);
214+ PATH_POWER_SHOW("BF-BW80/RU996", 10, 1);
215+ PATH_POWER_SHOW("BW160/RU2x996", 10, 0);
216+ PATH_POWER_SHOW("BF-BW160/RU2x996", 10, 1);
developera16be1f2022-12-14 13:09:20 +0800217+ PATH_POWER_SHOW("RU26", 10, 0);
218+ PATH_POWER_SHOW("BF-RU26", 10, 0);
219+ PATH_POWER_SHOW("RU52", 10, 0);
220+ PATH_POWER_SHOW("BF-RU52", 10, 0);
221+ PATH_POWER_SHOW("RU106", 10, 0);
222+ PATH_POWER_SHOW("BF-RU106", 10, 0);
223+#undef PATH_POWER_SHOW
224+
225+ return 0;
226+}
227+
228+static int
229+mt7915_txpower_path_show(struct seq_file *file, void *data)
230+{
231+ struct mt7915_phy *phy = file->private;
232+
233+ seq_printf(file, "\nBand %d\n", phy != &phy->dev->phy);
234+
235+ return mt7915_path_txpower_show(file);
236+}
237+
238+DEFINE_SHOW_ATTRIBUTE(mt7915_txpower_path);
239+
240 static int
241 mt7915_twt_stats(struct seq_file *s, void *data)
242 {
developer753619c2024-02-22 13:42:45 +0800243@@ -1309,7 +1372,9 @@ int mt7915_init_debugfs(struct mt7915_phy *phy)
developera16be1f2022-12-14 13:09:20 +0800244 debugfs_create_file("implicit_txbf", 0600, dir, dev,
245 &fops_implicit_txbf);
246 debugfs_create_file("txpower_sku", 0400, dir, phy,
247- &mt7915_rate_txpower_fops);
248+ &mt7915_txpower_fops);
249+ debugfs_create_file("txpower_path", 0400, dir, phy,
250+ &mt7915_txpower_path_fops);
251 debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
252 mt7915_twt_stats);
253 debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval);
developer70180b02023-11-14 17:01:47 +0800254diff --git a/mt7915/init.c b/mt7915/init.c
developer753619c2024-02-22 13:42:45 +0800255index 9613e1d..9d05d12 100644
developer70180b02023-11-14 17:01:47 +0800256--- a/mt7915/init.c
257+++ b/mt7915/init.c
developer1a173672023-12-21 14:49:33 +0800258@@ -284,6 +284,8 @@ static void __mt7915_init_txpower(struct mt7915_phy *phy,
developer70180b02023-11-14 17:01:47 +0800259 int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band);
260 struct mt76_power_limits limits;
261
262+ phy->sku_limit_en = true;
263+ phy->sku_path_en = true;
264 for (i = 0; i < sband->n_channels; i++) {
265 struct ieee80211_channel *chan = &sband->channels[i];
266 u32 target_power = 0;
developer1a173672023-12-21 14:49:33 +0800267@@ -300,6 +302,11 @@ static void __mt7915_init_txpower(struct mt7915_phy *phy,
developer70180b02023-11-14 17:01:47 +0800268 target_power = mt76_get_rate_power_limits(phy->mt76, chan,
269 &limits,
270 target_power);
271+
272+ /* MT7915N can not enable Backoff table without setting value in dts */
273+ if (!limits.path.ofdm[0])
274+ phy->sku_path_en = false;
275+
276 target_power += nss_delta;
277 target_power = DIV_ROUND_UP(target_power, 2);
278 chan->max_power = min_t(int, chan->max_reg_power,
279diff --git a/mt7915/main.c b/mt7915/main.c
developer753619c2024-02-22 13:42:45 +0800280index 3f07183..6192c20 100644
developer70180b02023-11-14 17:01:47 +0800281--- a/mt7915/main.c
282+++ b/mt7915/main.c
developereb155692024-01-11 14:08:37 +0800283@@ -73,11 +73,7 @@ int mt7915_run(struct ieee80211_hw *hw)
284 if (ret)
developer70180b02023-11-14 17:01:47 +0800285 goto out;
286
developereb155692024-01-11 14:08:37 +0800287-#ifdef MTK_DEBUG
developer70180b02023-11-14 17:01:47 +0800288- ret = mt7915_mcu_set_sku_en(phy, !dev->dbg.sku_disable);
289-#else
290- ret = mt7915_mcu_set_sku_en(phy, true);
developereb155692024-01-11 14:08:37 +0800291-#endif
developer70180b02023-11-14 17:01:47 +0800292+ ret = mt7915_mcu_set_sku_en(phy);
293 if (ret)
294 goto out;
295
developera16be1f2022-12-14 13:09:20 +0800296diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer753619c2024-02-22 13:42:45 +0800297index 0694c9a..3e41abd 100644
developera16be1f2022-12-14 13:09:20 +0800298--- a/mt7915/mcu.c
299+++ b/mt7915/mcu.c
developer753619c2024-02-22 13:42:45 +0800300@@ -3405,7 +3405,8 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
developera16be1f2022-12-14 13:09:20 +0800301 int ret;
302 s8 txpower_sku[MT7915_SKU_RATE_NUM];
303
304- ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku));
305+ ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku),
306+ TX_POWER_INFO_RATE);
307 if (ret)
308 return ret;
309
developer753619c2024-02-22 13:42:45 +0800310@@ -3445,53 +3446,139 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
developer70180b02023-11-14 17:01:47 +0800311 sizeof(req), true);
312 }
developera16be1f2022-12-14 13:09:20 +0800313
developer70180b02023-11-14 17:01:47 +0800314+static void
315+mt7915_update_txpower(struct mt7915_phy *phy, int tx_power)
316+{
317+ struct mt76_phy *mphy = phy->mt76;
318+ struct ieee80211_channel *chan = mphy->main_chan;
319+ int chain_idx, val, e2p_power_limit = 0;
320+
321+ if (chan == NULL) {
322+ mphy->txpower_cur = tx_power;
323+ return;
324+ }
325+
326+ for (chain_idx = 0; chain_idx < hweight16(mphy->chainmask); chain_idx++) {
327+ val = mt7915_eeprom_get_target_power(phy->dev, chan, chain_idx);
328+ val += mt7915_eeprom_get_power_delta(phy->dev, chan->band);
329+
330+ e2p_power_limit = max_t(int, e2p_power_limit, val);
331+ }
332+
333+ if (phy->sku_limit_en)
334+ mphy->txpower_cur = min_t(int, e2p_power_limit, tx_power);
335+ else
336+ mphy->txpower_cur = e2p_power_limit;
337+}
338+
developera16be1f2022-12-14 13:09:20 +0800339 int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy)
340 {
341+#define TX_POWER_LIMIT_TABLE_RATE 0
342+#define TX_POWER_LIMIT_TABLE_PATH 1
343 struct mt7915_dev *dev = phy->dev;
344 struct mt76_phy *mphy = phy->mt76;
345 struct ieee80211_hw *hw = mphy->hw;
346- struct mt7915_mcu_txpower_sku req = {
347+ struct mt7915_sku_val {
348+ u8 format_id;
349+ u8 limit_type;
350+ u8 band_idx;
351+ } __packed hdr = {
352 .format_id = TX_POWER_LIMIT_TABLE,
353+ .limit_type = TX_POWER_LIMIT_TABLE_RATE,
354 .band_idx = phy->mt76->band_idx,
355 };
356- struct mt76_power_limits limits_array;
357- s8 *la = (s8 *)&limits_array;
358- int i, idx;
359- int tx_power;
360+ int i, ret, tx_power;
361+ const u8 *len = mt7915_sku_group_len;
362+ struct mt76_power_limits la = {};
363+ struct sk_buff *skb;
364
365 tx_power = mt7915_get_power_bound(phy, hw->conf.power_level);
developer70180b02023-11-14 17:01:47 +0800366- tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
developera16be1f2022-12-14 13:09:20 +0800367- &limits_array, tx_power);
developer70180b02023-11-14 17:01:47 +0800368- mphy->txpower_cur = tx_power;
developera16be1f2022-12-14 13:09:20 +0800369
370- for (i = 0, idx = 0; i < ARRAY_SIZE(mt7915_sku_group_len); i++) {
371- u8 mcs_num, len = mt7915_sku_group_len[i];
372- int j;
developer70180b02023-11-14 17:01:47 +0800373+ if (phy->sku_limit_en) {
374+ tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
375+ &la, tx_power);
376+ mt7915_update_txpower(phy, tx_power);
377+ } else {
378+ mt7915_update_txpower(phy, tx_power);
379+ return 0;
380+ }
381
382- if (i >= SKU_HT_BW20 && i <= SKU_VHT_BW160) {
383- mcs_num = 10;
developera16be1f2022-12-14 13:09:20 +0800384+ skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
385+ sizeof(hdr) + MT7915_SKU_RATE_NUM);
386+ if (!skb)
387+ return -ENOMEM;
388
developera16be1f2022-12-14 13:09:20 +0800389- if (i == SKU_HT_BW20 || i == SKU_VHT_BW20)
390- la = (s8 *)&limits_array + 12;
391- } else {
392- mcs_num = len;
393- }
developer70180b02023-11-14 17:01:47 +0800394+ skb_put_data(skb, &hdr, sizeof(hdr));
395+ skb_put_data(skb, &la.cck, len[SKU_CCK] + len[SKU_OFDM]);
396+ skb_put_data(skb, &la.mcs[0], len[SKU_HT_BW20]);
397+ skb_put_data(skb, &la.mcs[1], len[SKU_HT_BW40]);
398+
developera16be1f2022-12-14 13:09:20 +0800399+ /* vht */
400+ for (i = 0; i < 4; i++) {
401+ skb_put_data(skb, &la.mcs[i], sizeof(la.mcs[i]));
402+ skb_put_zero(skb, 2); /* padding */
403+ }
developerc5ce7502022-12-19 11:33:22 +0800404
developer327aa322023-07-10 13:49:56 +0800405- for (j = 0; j < min_t(u8, mcs_num, len); j++)
406- req.txpower_sku[idx + j] = la[j];
developereb155692024-01-11 14:08:37 +0800407+ /* he */
408+ skb_put_data(skb, &la.ru[0], sizeof(la.ru));
409
410- la += mcs_num;
411- idx += len;
developera16be1f2022-12-14 13:09:20 +0800412+ ret = mt76_mcu_skb_send_msg(&dev->mt76, skb,
413+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
414+ if (ret)
415+ return ret;
developereb155692024-01-11 14:08:37 +0800416+
developer70180b02023-11-14 17:01:47 +0800417+ /* only set per-path power table when it's configured */
418+ if (!phy->sku_path_en)
419+ return 0;
420+
developera16be1f2022-12-14 13:09:20 +0800421+ skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
422+ sizeof(hdr) + MT7915_SKU_PATH_NUM);
423+ if (!skb)
424+ return -ENOMEM;
developerc5ce7502022-12-19 11:33:22 +0800425+
developera16be1f2022-12-14 13:09:20 +0800426+ hdr.limit_type = TX_POWER_LIMIT_TABLE_PATH;
427+ skb_put_data(skb, &hdr, sizeof(hdr));
428+ skb_put_data(skb, &la.path.cck, sizeof(la.path.cck));
429+ skb_put_data(skb, &la.path.ofdm, sizeof(la.path.ofdm));
430+ skb_put_data(skb, &la.path.ofdm_bf[1], sizeof(la.path.ofdm_bf) - 1);
431+
432+ /* HT20 and HT40 */
developer327aa322023-07-10 13:49:56 +0800433+ skb_put_data(skb, &la.path.ru[3], sizeof(la.path.ru[3]));
434+ skb_put_data(skb, &la.path.ru_bf[3][1], sizeof(la.path.ru_bf[3]) - 1);
435+ skb_put_data(skb, &la.path.ru[4], sizeof(la.path.ru[4]));
436+ skb_put_data(skb, &la.path.ru_bf[4][1], sizeof(la.path.ru_bf[4]) - 1);
developera16be1f2022-12-14 13:09:20 +0800437+
438+ /* start from non-bf and bf fields of
439+ * BW20/RU242, BW40/RU484, BW80/RU996, BW160/RU2x996,
440+ * RU26, RU52, and RU106
441+ */
developera16be1f2022-12-14 13:09:20 +0800442+
developer327aa322023-07-10 13:49:56 +0800443+ for (i = 0; i < 8; i++) {
444+ bool bf = i % 2;
445+ u8 idx = (i + 6) / 2;
446+ s8 *buf = bf ? la.path.ru_bf[idx] : la.path.ru[idx];
developera16be1f2022-12-14 13:09:20 +0800447+ /* The non-bf fields of RU26 to RU106 are special cases */
developer327aa322023-07-10 13:49:56 +0800448+ if (bf)
developera16be1f2022-12-14 13:09:20 +0800449+ skb_put_data(skb, buf + 1, 9);
450+ else
451+ skb_put_data(skb, buf, 10);
452 }
453
454- return mt76_mcu_send_msg(&dev->mt76,
455- MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
456- sizeof(req), true);
developer327aa322023-07-10 13:49:56 +0800457+ for (i = 0; i < 6; i++) {
458+ bool bf = i % 2;
459+ u8 idx = i / 2;
460+ s8 *buf = bf ? la.path.ru_bf[idx] : la.path.ru[idx];
461+
462+ skb_put_data(skb, buf, 10);
463+ }
464+
developera16be1f2022-12-14 13:09:20 +0800465+ return mt76_mcu_skb_send_msg(&dev->mt76, skb,
developerc5ce7502022-12-19 11:33:22 +0800466+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
developera16be1f2022-12-14 13:09:20 +0800467 }
468
469-int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
470+int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,
471+ u8 category)
472 {
473-#define RATE_POWER_INFO 2
474 struct mt7915_dev *dev = phy->dev;
475 struct {
476 u8 format_id;
developer753619c2024-02-22 13:42:45 +0800477@@ -3500,10 +3587,9 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
developera16be1f2022-12-14 13:09:20 +0800478 u8 _rsv;
479 } __packed req = {
480 .format_id = TX_POWER_LIMIT_INFO,
481- .category = RATE_POWER_INFO,
482+ .category = category,
483 .band_idx = phy->mt76->band_idx,
484 };
485- s8 txpower_sku[MT7915_SKU_RATE_NUM][2];
486 struct sk_buff *skb;
487 int ret, i;
488
developer753619c2024-02-22 13:42:45 +0800489@@ -3513,9 +3599,15 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
developera16be1f2022-12-14 13:09:20 +0800490 if (ret)
491 return ret;
492
493- memcpy(txpower_sku, skb->data + 4, sizeof(txpower_sku));
494- for (i = 0; i < len; i++)
495- txpower[i] = txpower_sku[i][req.band_idx];
496+ if (category == TX_POWER_INFO_RATE) {
497+ s8 res[MT7915_SKU_RATE_NUM][2];
498+
499+ memcpy(res, skb->data + 4, sizeof(res));
500+ for (i = 0; i < len; i++)
501+ txpower[i] = res[i][req.band_idx];
502+ } else if (category == TX_POWER_INFO_PATH) {
503+ memcpy(txpower, skb->data + 4, len);
504+ }
505
506 dev_kfree_skb(skb);
507
developer753619c2024-02-22 13:42:45 +0800508@@ -3544,7 +3636,7 @@ int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode,
developer70180b02023-11-14 17:01:47 +0800509 sizeof(req), false);
510 }
511
512-int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable)
513+int mt7915_mcu_set_sku_en(struct mt7915_phy *phy)
514 {
515 struct mt7915_dev *dev = phy->dev;
516 struct mt7915_sku {
developer753619c2024-02-22 13:42:45 +0800517@@ -3555,10 +3647,24 @@ int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable)
developer70180b02023-11-14 17:01:47 +0800518 } __packed req = {
519 .format_id = TX_POWER_LIMIT_ENABLE,
developera16be1f2022-12-14 13:09:20 +0800520 .band_idx = phy->mt76->band_idx,
developer70180b02023-11-14 17:01:47 +0800521- .sku_enable = enable,
developera16be1f2022-12-14 13:09:20 +0800522 };
developereb155692024-01-11 14:08:37 +0800523+ int ret, sku_disable = 0;
developera16be1f2022-12-14 13:09:20 +0800524+
developereb155692024-01-11 14:08:37 +0800525+#ifdef MTK_DEBUG
526+ sku_disable = dev->dbg.sku_disable;
527+#endif
528+ req.sku_enable = sku_disable ? 0 : phy->sku_limit_en;
developera16be1f2022-12-14 13:09:20 +0800529+ ret = mt76_mcu_send_msg(&dev->mt76,
530+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
531+ sizeof(req), true);
532+ if (ret)
533+ return ret;
developer70180b02023-11-14 17:01:47 +0800534+
535+ pr_info("%s: sku enable = %d, path enable = %d\n", __func__,
developereb155692024-01-11 14:08:37 +0800536+ sku_disable ? 0 : phy->sku_limit_en, sku_disable ? 0 : phy->sku_path_en);
developera16be1f2022-12-14 13:09:20 +0800537
developer70180b02023-11-14 17:01:47 +0800538- pr_info("%s: enable = %d\n", __func__, enable);
developereb155692024-01-11 14:08:37 +0800539+ req.sku_enable = sku_disable ? 0 : phy->sku_path_en;
developera16be1f2022-12-14 13:09:20 +0800540+ req.format_id = TX_POWER_LIMIT_PATH_ENABLE;
developer70180b02023-11-14 17:01:47 +0800541
developera16be1f2022-12-14 13:09:20 +0800542 return mt76_mcu_send_msg(&dev->mt76,
543 MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
developera16be1f2022-12-14 13:09:20 +0800544diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developer753619c2024-02-22 13:42:45 +0800545index 1b0bd06..94eff26 100644
developera16be1f2022-12-14 13:09:20 +0800546--- a/mt7915/mcu.h
547+++ b/mt7915/mcu.h
developer753619c2024-02-22 13:42:45 +0800548@@ -517,12 +517,18 @@ enum {
developera16be1f2022-12-14 13:09:20 +0800549
550 enum {
551 TX_POWER_LIMIT_ENABLE,
552+ TX_POWER_LIMIT_PATH_ENABLE = 0x3,
553 TX_POWER_LIMIT_TABLE = 0x4,
554 TX_POWER_LIMIT_INFO = 0x7,
555 TX_POWER_LIMIT_FRAME = 0x11,
556 TX_POWER_LIMIT_FRAME_MIN = 0x12,
557 };
558
559+enum {
560+ TX_POWER_INFO_PATH = 1,
561+ TX_POWER_INFO_RATE,
562+};
563+
564 enum {
565 SPR_ENABLE = 0x1,
566 SPR_ENABLE_SD = 0x3,
567diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer753619c2024-02-22 13:42:45 +0800568index a74a4eb..bb4ef00 100644
developera16be1f2022-12-14 13:09:20 +0800569--- a/mt7915/mt7915.h
570+++ b/mt7915/mt7915.h
developer7af0f762023-05-22 15:16:16 +0800571@@ -72,6 +72,7 @@
developera16be1f2022-12-14 13:09:20 +0800572 #define MT7915_CDEV_THROTTLE_MAX 99
573
574 #define MT7915_SKU_RATE_NUM 161
575+#define MT7915_SKU_PATH_NUM 185
576
577 #define MT7915_MAX_TWT_AGRT 16
578 #define MT7915_MAX_STA_TWT_AGRT 8
developereb155692024-01-11 14:08:37 +0800579@@ -300,6 +301,9 @@ struct mt7915_phy {
developer70180b02023-11-14 17:01:47 +0800580 struct list_head stats_list;
581 spinlock_t stats_lock;
582
583+ bool sku_limit_en;
584+ bool sku_path_en;
585+
586 #ifdef CONFIG_NL80211_TESTMODE
587 struct {
588 u32 *reg_backup;
developer753619c2024-02-22 13:42:45 +0800589@@ -612,9 +616,10 @@ int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable,
developer70180b02023-11-14 17:01:47 +0800590 int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode,
591 u8 en);
developera16be1f2022-12-14 13:09:20 +0800592 int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band);
developer70180b02023-11-14 17:01:47 +0800593-int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable);
594+int mt7915_mcu_set_sku_en(struct mt7915_phy *phy);
developera16be1f2022-12-14 13:09:20 +0800595 int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy);
596-int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len);
597+int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,
598+ u8 category);
599 int mt7915_mcu_set_txpower_frame_min(struct mt7915_phy *phy, s8 txpower);
600 int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
601 struct ieee80211_vif *vif,
602--
developerbd9fa1e2023-10-16 11:04:00 +08006032.18.0
developera16be1f2022-12-14 13:09:20 +0800604