blob: 032e44de75fc92493757911ba91f60048e2250ed [file] [log] [blame]
developerbf0f2d62023-11-14 17:01:47 +08001From 51e7036b3f6295eb7a8e5925dea43cb71998f0dd Mon Sep 17 00:00:00 2001
developer1d6610e2022-12-14 13:09:20 +08002From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Mon, 5 Dec 2022 18:21:51 +0800
developerbf0f2d62023-11-14 17:01:47 +08004Subject: [PATCH 1025/1042] wifi: mt76: mt7915: add bf backoff limit table
developer78848c62023-04-06 13:44:00 +08005 support
developer1d6610e2022-12-14 13:09:20 +08006
7Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
8---
developer26d6cc52023-07-31 12:27:06 +08009 debugfs.c | 2 +-
developerbf0f2d62023-11-14 17:01:47 +080010 eeprom.c | 43 ++++++++++--
developer1d6610e2022-12-14 13:09:20 +080011 mt76.h | 8 +++
developerbf0f2d62023-11-14 17:01:47 +080012 mt7915/debugfs.c | 73 ++++++++++++++++++--
13 mt7915/init.c | 7 ++
14 mt7915/main.c | 8 ++-
15 mt7915/mcu.c | 175 +++++++++++++++++++++++++++++++++++++----------
16 mt7915/mcu.h | 6 ++
17 mt7915/mt7915.h | 9 ++-
18 9 files changed, 279 insertions(+), 52 deletions(-)
developer1d6610e2022-12-14 13:09:20 +080019
developer26d6cc52023-07-31 12:27:06 +080020diff --git a/debugfs.c b/debugfs.c
developere35b8e42023-10-16 11:04:00 +080021index 1c8328d..19a835c 100644
developer26d6cc52023-07-31 12:27:06 +080022--- a/debugfs.c
23+++ b/debugfs.c
24@@ -95,7 +95,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
25 {
26 int i;
27
28- seq_printf(file, "%10s:", str);
29+ seq_printf(file, "%16s:", str);
30 for (i = 0; i < len; i++)
31 seq_printf(file, " %2d", val[i]);
32 seq_puts(file, "\n");
developer1d6610e2022-12-14 13:09:20 +080033diff --git a/eeprom.c b/eeprom.c
developerbf0f2d62023-11-14 17:01:47 +080034index eb532c7..c0536f1 100644
developer1d6610e2022-12-14 13:09:20 +080035--- a/eeprom.c
36+++ b/eeprom.c
developerbf0f2d62023-11-14 17:01:47 +080037@@ -326,9 +326,10 @@ mt76_apply_array_limit(s8 *pwr, size_t pwr_len, const __be32 *data,
38 static void
39 mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num,
40 const __be32 *data, size_t len, s8 target_power,
41- s8 nss_delta, s8 *max_power)
42+ s8 nss_delta)
43 {
44 int i, cur;
45+ s8 max_power = -128;
46
47 if (!data)
48 return;
49@@ -340,7 +341,7 @@ mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num,
50 break;
51
52 mt76_apply_array_limit(pwr + pwr_len * i, pwr_len, data + 1,
53- target_power, nss_delta, max_power);
54+ target_power, nss_delta, &max_power);
55 if (--cur > 0)
56 continue;
57
58@@ -367,12 +368,16 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
developerb2aab722023-07-10 13:49:56 +080059 char band;
60 size_t len;
developer2b96a9e2023-08-09 10:28:15 +080061 s8 max_power = -127;
developerb2aab722023-07-10 13:49:56 +080062+ s8 max_power_backoff = -127;
63 s8 txs_delta;
developer26d6cc52023-07-31 12:27:06 +080064+ int n_chains = hweight16(phy->chainmask);
developerb2aab722023-07-10 13:49:56 +080065+ s8 target_power_combine = target_power + mt76_tx_power_nss_delta(n_chains);
66
developer1d6610e2022-12-14 13:09:20 +080067 if (!mcs_rates)
68 mcs_rates = 10;
69
70- memset(dest, target_power, sizeof(*dest));
71+ memset(dest, target_power, sizeof(*dest) - sizeof(dest->path));
72+ memset(&dest->path, 0, sizeof(dest->path));
73
74 if (!IS_ENABLED(CONFIG_OF))
75 return target_power;
developerbf0f2d62023-11-14 17:01:47 +080076@@ -418,14 +423,40 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
77 val = mt76_get_of_array(np, "rates-mcs", &len, mcs_rates + 1);
78 mt76_apply_multi_array_limit(dest->mcs[0], ARRAY_SIZE(dest->mcs[0]),
79 ARRAY_SIZE(dest->mcs), val, len,
80- target_power, txs_delta, &max_power);
81+ target_power, txs_delta);
82
83 val = mt76_get_of_array(np, "rates-ru", &len, ru_rates + 1);
84 mt76_apply_multi_array_limit(dest->ru[0], ARRAY_SIZE(dest->ru[0]),
developer1d6610e2022-12-14 13:09:20 +080085 ARRAY_SIZE(dest->ru), val, len,
developerbf0f2d62023-11-14 17:01:47 +080086- target_power, txs_delta, &max_power);
87+ target_power, txs_delta);
developer1d6610e2022-12-14 13:09:20 +080088
developerb2aab722023-07-10 13:49:56 +080089- return max_power;
90+ max_power_backoff = max_power;
developer1d6610e2022-12-14 13:09:20 +080091+ val = mt76_get_of_array(np, "paths-cck", &len, ARRAY_SIZE(dest->path.cck));
92+ mt76_apply_array_limit(dest->path.cck, ARRAY_SIZE(dest->path.cck), val,
developerb2aab722023-07-10 13:49:56 +080093+ target_power_combine, txs_delta, &max_power_backoff);
developer1d6610e2022-12-14 13:09:20 +080094+
95+ val = mt76_get_of_array(np, "paths-ofdm", &len, ARRAY_SIZE(dest->path.ofdm));
96+ mt76_apply_array_limit(dest->path.ofdm, ARRAY_SIZE(dest->path.ofdm), val,
developerb2aab722023-07-10 13:49:56 +080097+ target_power_combine, txs_delta, &max_power_backoff);
developer1d6610e2022-12-14 13:09:20 +080098+
99+ val = mt76_get_of_array(np, "paths-ofdm-bf", &len, ARRAY_SIZE(dest->path.ofdm_bf));
100+ mt76_apply_array_limit(dest->path.ofdm_bf, ARRAY_SIZE(dest->path.ofdm_bf), val,
developerb2aab722023-07-10 13:49:56 +0800101+ target_power_combine, txs_delta, &max_power_backoff);
developer1d6610e2022-12-14 13:09:20 +0800102+
103+ val = mt76_get_of_array(np, "paths-ru", &len, ARRAY_SIZE(dest->path.ru[0]) + 1);
104+ mt76_apply_multi_array_limit(dest->path.ru[0], ARRAY_SIZE(dest->path.ru[0]),
105+ ARRAY_SIZE(dest->path.ru), val, len,
developerbf0f2d62023-11-14 17:01:47 +0800106+ target_power_combine, txs_delta);
developer1d6610e2022-12-14 13:09:20 +0800107+
108+ val = mt76_get_of_array(np, "paths-ru-bf", &len, ARRAY_SIZE(dest->path.ru_bf[0]) + 1);
109+ mt76_apply_multi_array_limit(dest->path.ru_bf[0], ARRAY_SIZE(dest->path.ru_bf[0]),
110+ ARRAY_SIZE(dest->path.ru_bf), val, len,
developerbf0f2d62023-11-14 17:01:47 +0800111+ target_power_combine, txs_delta);
developer1d6610e2022-12-14 13:09:20 +0800112+
developerb2aab722023-07-10 13:49:56 +0800113+ if (max_power_backoff == target_power_combine)
114+ return max_power;
115+
116+ return max_power_backoff;
developer1d6610e2022-12-14 13:09:20 +0800117 }
118 EXPORT_SYMBOL_GPL(mt76_get_rate_power_limits);
developerb2aab722023-07-10 13:49:56 +0800119
developer1d6610e2022-12-14 13:09:20 +0800120diff --git a/mt76.h b/mt76.h
developerbf0f2d62023-11-14 17:01:47 +0800121index 9673926..6ed3e1e 100644
developer1d6610e2022-12-14 13:09:20 +0800122--- a/mt76.h
123+++ b/mt76.h
developerbf0f2d62023-11-14 17:01:47 +0800124@@ -1049,6 +1049,14 @@ struct mt76_power_limits {
developer1d6610e2022-12-14 13:09:20 +0800125 s8 mcs[4][10];
126 s8 ru[7][12];
developere35b8e42023-10-16 11:04:00 +0800127 s8 eht[16][16];
developer1d6610e2022-12-14 13:09:20 +0800128+
129+ struct {
130+ s8 cck[4];
131+ s8 ofdm[4];
132+ s8 ofdm_bf[4];
133+ s8 ru[7][10];
134+ s8 ru_bf[7][10];
135+ } path;
136 };
137
138 struct mt76_ethtool_worker_info {
139diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c
developere35b8e42023-10-16 11:04:00 +0800140index f181377..19a37b5 100644
developer1d6610e2022-12-14 13:09:20 +0800141--- a/mt7915/debugfs.c
142+++ b/mt7915/debugfs.c
developer004e50c2023-06-29 20:33:22 +0800143@@ -1019,7 +1019,7 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
developer1d6610e2022-12-14 13:09:20 +0800144 if (!buf)
145 return -ENOMEM;
146
147- ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr));
148+ ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr), TX_POWER_INFO_RATE);
149 if (ret)
150 goto out;
151
developer2b96a9e2023-08-09 10:28:15 +0800152@@ -1133,7 +1133,7 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
developer1d6610e2022-12-14 13:09:20 +0800153
154 mutex_lock(&dev->mt76.mutex);
155 ret = mt7915_mcu_get_txpower_sku(phy, req.txpower_sku,
156- sizeof(req.txpower_sku));
157+ sizeof(req.txpower_sku), TX_POWER_INFO_RATE);
158 if (ret)
159 goto out;
160
developer2b96a9e2023-08-09 10:28:15 +0800161@@ -1175,7 +1175,7 @@ out:
developer1d6610e2022-12-14 13:09:20 +0800162 return ret ? ret : count;
163 }
164
165-static const struct file_operations mt7915_rate_txpower_fops = {
166+static const struct file_operations mt7915_txpower_fops = {
167 .write = mt7915_rate_txpower_set,
168 .read = mt7915_rate_txpower_get,
169 .open = simple_open,
developer2b96a9e2023-08-09 10:28:15 +0800170@@ -1183,6 +1183,69 @@ static const struct file_operations mt7915_rate_txpower_fops = {
developer1d6610e2022-12-14 13:09:20 +0800171 .llseek = default_llseek,
172 };
173
174+static int
175+mt7915_path_txpower_show(struct seq_file *file)
176+{
177+ struct mt7915_phy *phy = file->private;
178+ s8 txpower[MT7915_SKU_PATH_NUM], *buf = txpower;
179+ int ret;
180+
181+#define PATH_POWER_SHOW(_name, _len, _skip) do { \
182+ if (_skip) { \
183+ buf -= 1; \
184+ *buf = 0; \
185+ } \
186+ mt76_seq_puts_array(file, _name, buf, _len); \
187+ buf += _len; \
188+ } while(0)
189+
developer26d6cc52023-07-31 12:27:06 +0800190+ seq_printf(file, "\n%*c", 17, ' ');
developer1d6610e2022-12-14 13:09:20 +0800191+ seq_printf(file, "1T1S/2T1S/3T1S/4T1S/2T2S/3T2S/4T2S/3T3S/4T3S/4T4S\n");
192+ ret = mt7915_mcu_get_txpower_sku(phy, txpower, sizeof(txpower),
193+ TX_POWER_INFO_PATH);
194+ if (ret)
195+ return ret;
196+
197+ PATH_POWER_SHOW("CCK", 4, 0);
198+ PATH_POWER_SHOW("OFDM", 4, 0);
199+ PATH_POWER_SHOW("BF-OFDM", 4, 1);
200+
developer26d6cc52023-07-31 12:27:06 +0800201+ PATH_POWER_SHOW("HT/VHT20", 10, 0);
202+ PATH_POWER_SHOW("BF-HT/VHT20", 10, 1);
203+ PATH_POWER_SHOW("HT/VHT40", 10, 0);
204+ PATH_POWER_SHOW("BF-HT/VHT40", 10, 1);
developer1d6610e2022-12-14 13:09:20 +0800205+
developer26d6cc52023-07-31 12:27:06 +0800206+ PATH_POWER_SHOW("BW20/RU242", 10, 0);
207+ PATH_POWER_SHOW("BF-BW20/RU242", 10, 1);
208+ PATH_POWER_SHOW("BW40/RU484", 10, 0);
209+ PATH_POWER_SHOW("BF-BW40/RU484", 10, 1);
210+ PATH_POWER_SHOW("BW80/RU996", 10, 0);
211+ PATH_POWER_SHOW("BF-BW80/RU996", 10, 1);
212+ PATH_POWER_SHOW("BW160/RU2x996", 10, 0);
213+ PATH_POWER_SHOW("BF-BW160/RU2x996", 10, 1);
developer1d6610e2022-12-14 13:09:20 +0800214+ PATH_POWER_SHOW("RU26", 10, 0);
215+ PATH_POWER_SHOW("BF-RU26", 10, 0);
216+ PATH_POWER_SHOW("RU52", 10, 0);
217+ PATH_POWER_SHOW("BF-RU52", 10, 0);
218+ PATH_POWER_SHOW("RU106", 10, 0);
219+ PATH_POWER_SHOW("BF-RU106", 10, 0);
220+#undef PATH_POWER_SHOW
221+
222+ return 0;
223+}
224+
225+static int
226+mt7915_txpower_path_show(struct seq_file *file, void *data)
227+{
228+ struct mt7915_phy *phy = file->private;
229+
230+ seq_printf(file, "\nBand %d\n", phy != &phy->dev->phy);
231+
232+ return mt7915_path_txpower_show(file);
233+}
234+
235+DEFINE_SHOW_ATTRIBUTE(mt7915_txpower_path);
236+
237 static int
238 mt7915_twt_stats(struct seq_file *s, void *data)
239 {
developer2b96a9e2023-08-09 10:28:15 +0800240@@ -1269,7 +1332,9 @@ int mt7915_init_debugfs(struct mt7915_phy *phy)
developer1d6610e2022-12-14 13:09:20 +0800241 debugfs_create_file("implicit_txbf", 0600, dir, dev,
242 &fops_implicit_txbf);
243 debugfs_create_file("txpower_sku", 0400, dir, phy,
244- &mt7915_rate_txpower_fops);
245+ &mt7915_txpower_fops);
246+ debugfs_create_file("txpower_path", 0400, dir, phy,
247+ &mt7915_txpower_path_fops);
248 debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
249 mt7915_twt_stats);
250 debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval);
developerbf0f2d62023-11-14 17:01:47 +0800251diff --git a/mt7915/init.c b/mt7915/init.c
252index d908a58..b2fdd43 100644
253--- a/mt7915/init.c
254+++ b/mt7915/init.c
255@@ -284,6 +284,8 @@ void __mt7915_init_txpower(struct mt7915_phy *phy,
256 int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band);
257 struct mt76_power_limits limits;
258
259+ phy->sku_limit_en = true;
260+ phy->sku_path_en = true;
261 for (i = 0; i < sband->n_channels; i++) {
262 struct ieee80211_channel *chan = &sband->channels[i];
263 u32 target_power = 0;
264@@ -300,6 +302,11 @@ void __mt7915_init_txpower(struct mt7915_phy *phy,
265 target_power = mt76_get_rate_power_limits(phy->mt76, chan,
266 &limits,
267 target_power);
268+
269+ /* MT7915N can not enable Backoff table without setting value in dts */
270+ if (!limits.path.ofdm[0])
271+ phy->sku_path_en = false;
272+
273 target_power += nss_delta;
274 target_power = DIV_ROUND_UP(target_power, 2);
275 chan->max_power = min_t(int, chan->max_reg_power,
276diff --git a/mt7915/main.c b/mt7915/main.c
277index da9cfc6..df7aab5 100644
278--- a/mt7915/main.c
279+++ b/mt7915/main.c
280@@ -74,10 +74,12 @@ int mt7915_run(struct ieee80211_hw *hw)
281 goto out;
282
283 #ifdef MTK_DEBUG
284- ret = mt7915_mcu_set_sku_en(phy, !dev->dbg.sku_disable);
285-#else
286- ret = mt7915_mcu_set_sku_en(phy, true);
287+ if (dev->dbg.sku_disable) {
288+ phy->sku_limit_en = false;
289+ phy->sku_path_en = false;
290+ }
291 #endif
292+ ret = mt7915_mcu_set_sku_en(phy);
293 if (ret)
294 goto out;
295
developer1d6610e2022-12-14 13:09:20 +0800296diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developerbf0f2d62023-11-14 17:01:47 +0800297index 7e33386..224ce21 100644
developer1d6610e2022-12-14 13:09:20 +0800298--- a/mt7915/mcu.c
299+++ b/mt7915/mcu.c
developere35b8e42023-10-16 11:04:00 +0800300@@ -3311,7 +3311,8 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
developer1d6610e2022-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
developerbf0f2d62023-11-14 17:01:47 +0800310@@ -3351,53 +3352,139 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
311 sizeof(req), true);
312 }
developer1d6610e2022-12-14 13:09:20 +0800313
developerbf0f2d62023-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+
developer1d6610e2022-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);
developerbf0f2d62023-11-14 17:01:47 +0800366- tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
developer1d6610e2022-12-14 13:09:20 +0800367- &limits_array, tx_power);
developerbf0f2d62023-11-14 17:01:47 +0800368- mphy->txpower_cur = tx_power;
developer1d6610e2022-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;
developerbf0f2d62023-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;
developer1d6610e2022-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
developer1d6610e2022-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- }
developerbf0f2d62023-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+
developer1d6610e2022-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+ }
developerb2aab722023-07-10 13:49:56 +0800404+
developer1d6610e2022-12-14 13:09:20 +0800405+ /* he */
406+ skb_put_data(skb, &la.ru[0], sizeof(la.ru));
developer2aa1e642022-12-19 11:33:22 +0800407
developerb2aab722023-07-10 13:49:56 +0800408- for (j = 0; j < min_t(u8, mcs_num, len); j++)
409- req.txpower_sku[idx + j] = la[j];
developer1d6610e2022-12-14 13:09:20 +0800410+ ret = mt76_mcu_skb_send_msg(&dev->mt76, skb,
411+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
412+ if (ret)
413+ return ret;
developerb2aab722023-07-10 13:49:56 +0800414
415- la += mcs_num;
416- idx += len;
developerbf0f2d62023-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+
developer1d6610e2022-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;
developer2aa1e642022-12-19 11:33:22 +0800425+
developer1d6610e2022-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 */
developerb2aab722023-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);
developer1d6610e2022-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+ */
developer1d6610e2022-12-14 13:09:20 +0800442+
developerb2aab722023-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];
developer1d6610e2022-12-14 13:09:20 +0800447+ /* The non-bf fields of RU26 to RU106 are special cases */
developerb2aab722023-07-10 13:49:56 +0800448+ if (bf)
developer1d6610e2022-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);
developerb2aab722023-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+
developer1d6610e2022-12-14 13:09:20 +0800465+ return mt76_mcu_skb_send_msg(&dev->mt76, skb,
developer2aa1e642022-12-19 11:33:22 +0800466+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
developer1d6610e2022-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;
developerbf0f2d62023-11-14 17:01:47 +0800477@@ -3406,10 +3493,9 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
developer1d6610e2022-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
developerbf0f2d62023-11-14 17:01:47 +0800489@@ -3419,9 +3505,15 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
developer1d6610e2022-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
developerbf0f2d62023-11-14 17:01:47 +0800508@@ -3450,7 +3542,7 @@ int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode,
509 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 {
517@@ -3461,10 +3553,21 @@ int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable)
518 } __packed req = {
519 .format_id = TX_POWER_LIMIT_ENABLE,
developer1d6610e2022-12-14 13:09:20 +0800520 .band_idx = phy->mt76->band_idx,
developerbf0f2d62023-11-14 17:01:47 +0800521- .sku_enable = enable,
522+ .sku_enable = phy->sku_limit_en,
developer1d6610e2022-12-14 13:09:20 +0800523 };
524+ int ret;
525+
526+ ret = mt76_mcu_send_msg(&dev->mt76,
527+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
528+ sizeof(req), true);
529+ if (ret)
530+ return ret;
developerbf0f2d62023-11-14 17:01:47 +0800531+
532+ pr_info("%s: sku enable = %d, path enable = %d\n", __func__,
533+ phy->sku_limit_en, phy->sku_path_en);
developer1d6610e2022-12-14 13:09:20 +0800534
developerbf0f2d62023-11-14 17:01:47 +0800535- pr_info("%s: enable = %d\n", __func__, enable);
536+ req.sku_enable = phy->sku_path_en;
developer1d6610e2022-12-14 13:09:20 +0800537+ req.format_id = TX_POWER_LIMIT_PATH_ENABLE;
developerbf0f2d62023-11-14 17:01:47 +0800538
developer1d6610e2022-12-14 13:09:20 +0800539 return mt76_mcu_send_msg(&dev->mt76,
540 MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
developer1d6610e2022-12-14 13:09:20 +0800541diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developere35b8e42023-10-16 11:04:00 +0800542index 5fc4e2e..142bfc1 100644
developer1d6610e2022-12-14 13:09:20 +0800543--- a/mt7915/mcu.h
544+++ b/mt7915/mcu.h
developerad9333b2023-05-22 15:16:16 +0800545@@ -502,12 +502,18 @@ enum {
developer1d6610e2022-12-14 13:09:20 +0800546
547 enum {
548 TX_POWER_LIMIT_ENABLE,
549+ TX_POWER_LIMIT_PATH_ENABLE = 0x3,
550 TX_POWER_LIMIT_TABLE = 0x4,
551 TX_POWER_LIMIT_INFO = 0x7,
552 TX_POWER_LIMIT_FRAME = 0x11,
553 TX_POWER_LIMIT_FRAME_MIN = 0x12,
554 };
555
556+enum {
557+ TX_POWER_INFO_PATH = 1,
558+ TX_POWER_INFO_RATE,
559+};
560+
561 enum {
562 SPR_ENABLE = 0x1,
563 SPR_ENABLE_SD = 0x3,
564diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerbf0f2d62023-11-14 17:01:47 +0800565index 25a6815..c2fb12d 100644
developer1d6610e2022-12-14 13:09:20 +0800566--- a/mt7915/mt7915.h
567+++ b/mt7915/mt7915.h
developerad9333b2023-05-22 15:16:16 +0800568@@ -72,6 +72,7 @@
developer1d6610e2022-12-14 13:09:20 +0800569 #define MT7915_CDEV_THROTTLE_MAX 99
570
571 #define MT7915_SKU_RATE_NUM 161
572+#define MT7915_SKU_PATH_NUM 185
573
574 #define MT7915_MAX_TWT_AGRT 16
575 #define MT7915_MAX_STA_TWT_AGRT 8
developerbf0f2d62023-11-14 17:01:47 +0800576@@ -263,6 +264,9 @@ struct mt7915_phy {
577 struct list_head stats_list;
578 spinlock_t stats_lock;
579
580+ bool sku_limit_en;
581+ bool sku_path_en;
582+
583 #ifdef CONFIG_NL80211_TESTMODE
584 struct {
585 u32 *reg_backup;
586@@ -571,9 +575,10 @@ int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, bool enable,
587 int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode,
588 u8 en);
developer1d6610e2022-12-14 13:09:20 +0800589 int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band);
developerbf0f2d62023-11-14 17:01:47 +0800590-int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable);
591+int mt7915_mcu_set_sku_en(struct mt7915_phy *phy);
developer1d6610e2022-12-14 13:09:20 +0800592 int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy);
593-int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len);
594+int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,
595+ u8 category);
596 int mt7915_mcu_set_txpower_frame_min(struct mt7915_phy *phy, s8 txpower);
597 int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
598 struct ieee80211_vif *vif,
599--
developere35b8e42023-10-16 11:04:00 +08006002.18.0
developer1d6610e2022-12-14 13:09:20 +0800601