Skip to content

Commit 3d63b50

Browse files
ecsvnbd168
authored andcommitted
wifi: mt76: Fix DTS power-limits on little endian systems
The power-limits for ru and mcs and stored in the devicetree as bytewise array (often with sizes which are not a multiple of 4). These arrays have a prefix which defines for how many modes a line is applied. This prefix is also only a byte - but the code still tried to fix the endianness of this byte with a be32 operation. As result, loading was mostly failing or was sending completely unexpected values to the firmware. Since the other rates are also stored in the devicetree as bytewise arrays, just drop the u32 access + be32_to_cpu conversion and directly access them as bytes arrays. Cc: stable@vger.kernel.org Fixes: 22b980b ("mt76: add functions for parsing rate power limits from DT") Fixes: a9627d9 ("mt76: extend DT rate power limits to support 11ax devices") Signed-off-by: Sven Eckelmann (Plasma Cloud) <se@simonwunderlich.de> Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent d95279d commit 3d63b50

File tree

1 file changed

+24
-13
lines changed
  • drivers/net/wireless/mediatek/mt76

1 file changed

+24
-13
lines changed

drivers/net/wireless/mediatek/mt76/eeprom.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ mt76_get_of_array(struct device_node *np, char *name, size_t *len, int min)
253253
return prop->value;
254254
}
255255

256+
static const s8 *
257+
mt76_get_of_array_s8(struct device_node *np, char *name, size_t *len, int min)
258+
{
259+
struct property *prop = of_find_property(np, name, NULL);
260+
261+
if (!prop || !prop->value || prop->length < min)
262+
return NULL;
263+
264+
*len = prop->length;
265+
266+
return prop->value;
267+
}
268+
256269
struct device_node *
257270
mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan)
258271
{
@@ -294,7 +307,7 @@ mt76_get_txs_delta(struct device_node *np, u8 nss)
294307
}
295308

296309
static void
297-
mt76_apply_array_limit(s8 *pwr, size_t pwr_len, const __be32 *data,
310+
mt76_apply_array_limit(s8 *pwr, size_t pwr_len, const s8 *data,
298311
s8 target_power, s8 nss_delta, s8 *max_power)
299312
{
300313
int i;
@@ -303,24 +316,22 @@ mt76_apply_array_limit(s8 *pwr, size_t pwr_len, const __be32 *data,
303316
return;
304317

305318
for (i = 0; i < pwr_len; i++) {
306-
pwr[i] = min_t(s8, target_power,
307-
be32_to_cpu(data[i]) + nss_delta);
319+
pwr[i] = min_t(s8, target_power, data[i] + nss_delta);
308320
*max_power = max(*max_power, pwr[i]);
309321
}
310322
}
311323

312324
static void
313325
mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num,
314-
const __be32 *data, size_t len, s8 target_power,
326+
const s8 *data, size_t len, s8 target_power,
315327
s8 nss_delta, s8 *max_power)
316328
{
317329
int i, cur;
318330

319331
if (!data)
320332
return;
321333

322-
len /= 4;
323-
cur = be32_to_cpu(data[0]);
334+
cur = data[0];
324335
for (i = 0; i < pwr_num; i++) {
325336
if (len < pwr_len + 1)
326337
break;
@@ -335,7 +346,7 @@ mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num,
335346
if (!len)
336347
break;
337348

338-
cur = be32_to_cpu(data[0]);
349+
cur = data[0];
339350
}
340351
}
341352

@@ -346,7 +357,7 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
346357
{
347358
struct mt76_dev *dev = phy->dev;
348359
struct device_node *np;
349-
const __be32 *val;
360+
const s8 *val;
350361
char name[16];
351362
u32 mcs_rates = dev->drv->mcs_rates;
352363
u32 ru_rates = ARRAY_SIZE(dest->ru[0]);
@@ -392,21 +403,21 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
392403

393404
txs_delta = mt76_get_txs_delta(np, hweight16(phy->chainmask));
394405

395-
val = mt76_get_of_array(np, "rates-cck", &len, ARRAY_SIZE(dest->cck));
406+
val = mt76_get_of_array_s8(np, "rates-cck", &len, ARRAY_SIZE(dest->cck));
396407
mt76_apply_array_limit(dest->cck, ARRAY_SIZE(dest->cck), val,
397408
target_power, txs_delta, &max_power);
398409

399-
val = mt76_get_of_array(np, "rates-ofdm",
400-
&len, ARRAY_SIZE(dest->ofdm));
410+
val = mt76_get_of_array_s8(np, "rates-ofdm",
411+
&len, ARRAY_SIZE(dest->ofdm));
401412
mt76_apply_array_limit(dest->ofdm, ARRAY_SIZE(dest->ofdm), val,
402413
target_power, txs_delta, &max_power);
403414

404-
val = mt76_get_of_array(np, "rates-mcs", &len, mcs_rates + 1);
415+
val = mt76_get_of_array_s8(np, "rates-mcs", &len, mcs_rates + 1);
405416
mt76_apply_multi_array_limit(dest->mcs[0], ARRAY_SIZE(dest->mcs[0]),
406417
ARRAY_SIZE(dest->mcs), val, len,
407418
target_power, txs_delta, &max_power);
408419

409-
val = mt76_get_of_array(np, "rates-ru", &len, ru_rates + 1);
420+
val = mt76_get_of_array_s8(np, "rates-ru", &len, ru_rates + 1);
410421
mt76_apply_multi_array_limit(dest->ru[0], ARRAY_SIZE(dest->ru[0]),
411422
ARRAY_SIZE(dest->ru), val, len,
412423
target_power, txs_delta, &max_power);

0 commit comments

Comments
 (0)