Commit Graph
49 Commits
Author SHA1 Message Date
Felix Fietkau 71e08471ab mt76: eeprom: fix return code on corrected bit-flips
Ensure that the return code is 0 when data was read successfully

Signed-off-by: Felix Fietkau <[email protected]>
2021-12-02 17:21:47 +01:00
Daniel GolleandFelix Fietkau 25237b19bc mt76: eeprom: tolerate corrected bit-flips
mtd_read() returns -EUCLEAN in case of corrected bit-flips.
As data was read, don't error out in this case.

Signed-off-by: Daniel Golle <[email protected]>
Acked-by: Hauke Mehrtens <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2021-11-28 22:20:34 +01:00
Hauke MehrtensandFelix Fietkau f81f42fe87 mt76: Print error message when reading EEPROM from mtd failed
When the EEPROM data is stored on a MTD partition print an error message
when reading this MTD partition failed. This is currently happening
often in OpenWrt because the initial data was written with using a flash
driver which ignores the error detection data and now OpenWrt uses a
driver which checks it.

With this patch a better error message is shown:
[    8.986988] mt7915e 0000:01:00.0: WA Firmware Version: DEV_000000, Build Time: 20201105222323
[    9.100508] mt7915e 0000:01:00.0: reading EEPROM from mtd factory failed: -117
[    9.144289] mt7915e: probe of 0000:01:00.0 failed with error -22

mt7915 does not work without an EEPROM, MT7922 still works.

Signed-off-by: Hauke Mehrtens <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2021-10-23 07:27:31 +02:00
Daniel GolleandFelix Fietkau 03a9926453 mt76: support reading EEPROM data embedded in fdt
Some platforms boot from SD card and don't come with calibration data
stored anywhere on the board.
As EEPROM data is rather small it can be embedded into the device tree
to be loaded from there by the mt76.

Signed-off-by: Daniel Golle <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2021-10-11 09:27:12 +02:00
Lorenzo BianconiandFelix Fietkau a6ab81c210 mt76: connac: set 6G phymode in single-sku support
Configure tx rate power for 6GHz channels. This is a preliminary patch
to enable 6GHz band for mt7921 devices.

Tested-by: Deren Wu <[email protected]>
Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2021-10-11 08:11:21 +02:00
Michael WalleandFelix Fietkau 4932c5d801 of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.

There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.

Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().

Usually the code looks like:

  const char *addr;
  addr = of_get_mac_address(np);
  if (!IS_ERR(addr))
    ether_addr_copy(ndev->dev_addr, addr);

This can then be simply rewritten as:

  of_get_mac_address(np, ndev->dev_addr);

Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.

The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!

<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
  <...
- ether_addr_copy(z, x);
  ...>

@@
identifier a.x;
@@
- if (<+... x ...+>) {}

@@
identifier a.x;
@@
  if (<+... x ...+>) {
      ...
  }
- else {}

@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
-     {}
- else
+ if (!(e))
      {...}

@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
  ... when != x
</spml>

All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.

Suggested-by: Andrew Lunn <[email protected]>
Signed-off-by: Michael Walle <[email protected]>
Reviewed-by: Andrew Lunn <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
2021-08-09 15:01:14 +02:00
Felix Fietkau 28b162366d mt76: fix calling mt76_get_of_eeprom with an offset for pre-cal data
The device tree partition offset needs to be added to the function argument,
instead of overwriting it.
Fixes an issue where wrong EEPROM data was sent to the firmware as
pre-calibration data on MT7915.

Fixes: 495184ac91bb ("mt76: mt7915: add support for applying pre-calibration data")
Signed-off-by: Felix Fietkau <[email protected]>
2021-05-15 08:07:54 +02:00
Ryder LeeandFelix Fietkau cf0e406af8 mt76: mt7915: add support for applying pre-calibration data
When the EEPROM data is read from flash, it can contain pre-calibration
data, which can save calibration time.

Note that group_cal can save 30% bootup calibration time, and dpd_cal can
save 75% channel switching time.

Tested-by: Bo Jiao <[email protected]>
Signed-off-by: Ryder Lee <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2021-04-17 11:19:58 +02:00
Felix Fietkau c71f609b39 mt76: sync with upstream changes
Signed-off-by: Felix Fietkau <[email protected]>
2021-04-14 09:12:11 +02:00
Shayne ChenandFelix Fietkau b44472e998 mt76: testmode: move mtd part to mt76_dev
Move testmode mtd variables to mt76_dev, since they are the same on
each phy.

Signed-off-by: Shayne Chen <[email protected]>
Acked-by: Ryder Lee <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2021-01-04 18:30:34 +01:00
Shayne ChenandFelix Fietkau a897a69769 mt76: testmode: introduce dbdc support
Add testmode support for DBDC NICs (both MT7615D and MT7915D work).
Testmode data and parameters are moved from per-dev to per-phy
for maintaining the value of each band.

Signed-off-by: Shayne Chen <[email protected]>
Acked-by: Ryder Lee <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2021-01-04 18:30:34 +01:00
Lorenzo BianconiandFelix Fietkau 8aa24c91b1 mt76: move hw mac_addr in mt76_phy
This is a preliminary patch to properly support mt7915 dbdc

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2020-11-13 11:19:13 +01:00
Felix Fietkau 4d019c9672 sync with upstream changes
Signed-off-by: Felix Fietkau <[email protected]>
2020-10-23 11:38:05 +02:00
Felix Fietkau 3a1ea7287e mt76: add API for testmode support
This can be used for calibration in the manufacturing process.
It supports sending a configurable number of packets with a specific rate
and configurable tx power levels / antenna settings.
It also supports receiving packets and showing some statistics, including
packet counters and detailed RSSI information.
It will only be compiled in if CONFIG_NL80211_TESTMODE is enabled

Signed-off-by: Felix Fietkau <[email protected]>
2020-06-22 21:31:02 +02:00
Shayne ChenandFelix Fietkau 1d2aedb248 mt76: extend DT rate power limits to support 11ax devices
Enable parsing per-rate txpower limits from DT for 11ax chipsets.

Co-developed-by: Felix Fietkau <[email protected]>
Tested-by: Evelyn Tsai <[email protected]>
Signed-off-by: Shayne Chen <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2020-06-16 22:04:15 +02:00
Felix Fietkau 769b030de6 mt76: add functions for parsing rate power limits from DT
This subnode can be used to set per-rate tx power limits either per
country code / regdomain or globally.
These limits are typically provided by the device manufacturers and are
used to limit sideband emissions and stay within regulatory limits

Signed-off-by: Felix Fietkau <[email protected]>
2020-06-16 22:04:15 +02:00
Lorenzo BianconiandFelix Fietkau 1c8e76f4de mt76: fix compilation warning in mt76_eeprom_override()
Fix the following compilation warning in mt76_eeprom_override routine
when CONFIG_OF is not set and label 'out' is not actually used

drivers/net/wireless/mediatek/mt76/eeprom.c: In function ‘mt76_eeprom_override’:
drivers/net/wireless/mediatek/mt76/eeprom.c:100:1: warning: label ‘out’ defined but not used [-Wunused-label]

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2019-12-22 16:11:10 +01:00
Lorenzo BianconiandFelix Fietkau 812692db17 mt76: eeprom: add support for big endian eeprom partition
mt76x0e users reported some devices (e.g TP-Link Archer VR200v) have
been flashed with big endian radio partition. Add the possibility to
specify eeprom endianness using big-endian dts property and in case
covert eeprom data in little endian

Tested-by: Kevin Schmidt <[email protected]>
Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2019-12-13 23:16:32 +01:00
Shayne ChenandFelix Fietkau a116b0a6af mt76: fix possible undetected invalid MAC address
Make sure the MAC address is checked before function returns.

If CONFIG_OF is set and the device node is null, the function will
return directly, and an invalid MAC address will not be checked.

Signed-off-by: Shayne Chen <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2019-12-13 22:43:10 +01:00
Wen YangandFelix Fietkau 0e3baf0213 mt76: fix a leaked reference by adding a missing of_node_put
The call to of_find_node_by_phandle returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./drivers/net/wireless/mediatek/mt76/eeprom.c:58:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 48, but without a corresponding object release within this function.
./drivers/net/wireless/mediatek/mt76/eeprom.c:61:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 48, but without a corresponding object release within this function.
./drivers/net/wireless/mediatek/mt76/eeprom.c:67:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 48, but without a corresponding object release within this function.
./drivers/net/wireless/mediatek/mt76/eeprom.c:70:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 48, but without a corresponding object release within this function.
./drivers/net/wireless/mediatek/mt76/eeprom.c:72:1-7: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 48, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <[email protected]>
Cc: Felix Fietkau <[email protected]>
Cc: Lorenzo Bianconi <[email protected]>
Cc: Kalle Valo <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Matthias Brugger <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Kalle Valo <[email protected]>
2019-08-22 09:26:30 +02:00
Ryder LeeandFelix Fietkau f625afcedc mt76: switch to SPDX tag instead of verbose boilerplate text
No functional change intended.

Add SPDX identifiers to all remaining files in /mt76.

Signed-off-by: Ryder Lee <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2019-08-20 15:22:20 +02:00
Felix Fietkau 3245ca8b8a mt76: check of_get_mac_address for NULL as well to restore old kernel compat
Signed-off-by: Felix Fietkau <[email protected]>
2019-08-12 20:26:55 +02:00
Petr Štetiar 75656a4590 net: wireless: support of_get_mac_address new ERR_PTR error
commit d31a36b5f407d796d121af745730712337cd32a1 upstream.

There was NVMEM support added to of_get_mac_address, so it could now return
ERR_PTR encoded error values, so we need to adjust all current users of
of_get_mac_address to this new fact.

Signed-off-by: Petr Štetiar <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
2019-07-22 22:27:46 +02:00
Felix Fietkau a5eaeb27d6 revert mt76_eeprom_override call reordering
This call order is necessary for handling the device MAC address

Signed-off-by: Felix Fietkau <[email protected]>
2017-02-03 14:25:08 +01:00
Felix Fietkau 184e068b6f use wiphy_read_of_freq_limits to parse band capability overrides
Signed-off-by: Felix Fietkau <[email protected]>
2017-02-01 16:11:35 +01:00
Felix Fietkau a39d4b7bf9 eeprom: add missing ifdef for MTD support
Signed-off-by: Felix Fietkau <[email protected]>
2016-12-15 13:00:03 +01:00
Felix Fietkau b18d66f749 core: fix checkpatch errors
Signed-off-by: Felix Fietkau <[email protected]>
2016-09-05 11:12:19 +02:00
Felix Fietkau 53c1b7f6ac update my email address
Signed-off-by: Felix Fietkau <[email protected]>
2016-09-04 17:33:28 +02:00
Felix Fietkau ced81a3458 relicense to ISC (except for util.h which is based on GPL'd kernel code
Signed-off-by: Felix Fietkau <[email protected]>
2016-07-12 08:38:46 +02:00
Felix Fietkau 079ad90fe2 update copyright lines
Signed-off-by: Felix Fietkau <[email protected]>
2016-02-25 18:09:13 +01:00
Felix Fietkau d8d9600e12 eeprom: add support for overriding the mac address via OF
Signed-off-by: Felix Fietkau <[email protected]>
2016-01-01 19:40:30 +01:00
Felix Fietkau 6ca2852f65 move mac address validation to core
Signed-off-by: Felix Fietkau <[email protected]>
2016-01-01 19:38:59 +01:00
Felix Fietkau 239b67204c move eeprom related code to common
Signed-off-by: Felix Fietkau <[email protected]>
2015-12-16 02:09:26 +01:00
Felix Fietkau a0ee20716f add a mt76x2_ prefix to all files
Signed-off-by: Felix Fietkau <[email protected]>
2015-12-06 16:54:53 +01:00
Felix Fietkau 31c11fdb05 replace mt76 prefix with mt76x2 in preparation for splitting the driver for more chipset support
Signed-off-by: Felix Fietkau <[email protected]>
2015-12-06 16:54:53 +01:00
Felix Fietkau ffdfbb745b mt76: apply OTP tx power overrides for 2.4 GHz
Signed-off-by: Felix Fietkau <[email protected]>
2015-09-26 01:22:38 +02:00
Felix Fietkau d99eddbdee mt76: fix OTP based tx power data override for group 0
Signed-off-by: Felix Fietkau <[email protected]>
2015-09-26 01:09:16 +02:00
Felix Fietkau a1767ddf64 eeprom: add support for dumping otp data separately via debugfs
Signed-off-by: Felix Fietkau <[email protected]>
2015-09-26 00:59:16 +02:00
Felix Fietkau 58a24ef247 eeprom: fix swapped 2g/5g power for OFDM rates
Signed-off-by: Felix Fietkau <[email protected]>
2015-08-28 08:53:49 +02:00
Felix Fietkau ebe9aebc92 eeprom: apply cal free data
Signed-off-by: Felix Fietkau <[email protected]>
2015-07-30 18:29:31 +02:00
Felix Fietkau b0c1bbb8bc phy: fix tx power delta parsing for 2.4 GHz as well
Signed-off-by: Felix Fietkau <[email protected]>
2015-07-29 17:57:30 +02:00
Felix Fietkau b960a4f0c5 eeprom: move OF specific functions to of.c
Signed-off-by: Felix Fietkau <[email protected]>
2015-07-29 17:04:58 +02:00
Felix Fietkau a5bdc19797 phy: fix tx power delta parsing
Signed-off-by: Felix Fietkau <[email protected]>
2015-07-29 13:50:48 +02:00
Felix Fietkau 902757f059 phy: store rate tx power individually
Signed-off-by: Felix Fietkau <[email protected]>
2015-07-28 15:01:48 +02:00
Felix Fietkau ec91841868 eeprom: wrap mt76_check_eeprom in #ifdef CONFIG_OF for now
Signed-off-by: Felix Fietkau <[email protected]>
2015-06-15 23:10:41 +02:00
Felix Fietkau c772c3bc89 eeprom: validate flash data before using it
Signed-off-by: Felix Fietkau <[email protected]>
2015-06-13 10:32:46 +02:00
Jakub Kicinski bd45637645 correct number of efuse registers read
mt76_efuse_read() is supposed to read out 16 bytes of data
that is 4x4B data registers.  Correct the loop bounds.

Signed-off-by: Jakub Kicinski <[email protected]>
2015-02-01 10:53:57 +01:00
Felix Fietkau eca052894b eeprom.c: fix retlen type
Signed-off-by: Felix Fietkau <[email protected]>
2014-12-10 21:48:24 +01:00
Felix Fietkau 9e7049b1d1 Initial import
Signed-off-by: Felix Fietkau <[email protected]>
2014-11-20 21:21:19 +01:00