History log of /linux-master/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c
Revision Date Author Comments
# b6351ef9 15-Jan-2024 Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

wifi: mt76: mt7921: fix incorrect type conversion for CLC command

clc->len is defined as 32 bits in length, so it must also be
operated on with 32 bits, not 16 bits.

Fixes: fa6ad88e023d ("wifi: mt76: mt7921: fix country count limitation for CLC")
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312112104.Zkc3QUHr-lkp@intel.com/
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# fa6ad88e 21-Nov-2023 Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

wifi: mt76: mt7921: fix country count limitation for CLC

Due to the increase in the number of power tables for 6Ghz on CLC,
the variable nr_country is no longer sufficient to represent the
total quantity. Therefore, we have switched to calculating the
length of clc buf to obtain the correct power table. Additionally,
the version number has been incremented to 1.

Fixes: 23bdc5d8cadf ("wifi: mt76: mt7921: introduce Country Location Control support")
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 2fac91f2 20-Oct-2023 Wu Yunchuan <yunchuan@nfschina.com>

wifi: mt76: Remove unnecessary (void*) conversions

No need cast (void *) to (struct mt7615_phy *).

Signed-off-by: Wu Yunchuan <yunchuan@nfschina.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# ce18572b 01-Oct-2023 Rong Yan <rong.yan@mediatek.com>

wifi: mt76: mt7921: support 5.9/6GHz channel config in acpi

The mtcl table, configured by platform vendor, provides regulatory
information for 5.9/6 GHz channels. mt792x should work on
corresponding channels supported by mtcl. This patch would parse
the settings in mtcl table and apply the result into chip side.

Signed-off-by: Rong Yan <rong.yan@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 7a934b5c 30-Oct-2023 Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

wifi: mt76: mt7921: fix 6GHz disabled by the missing default CLC config

No matter CLC is enabled or disabled, the driver should initialize
the default value 0xff for channel configuration of CLC. Otherwise,
the zero value would disable channels.

Reported-and-tested-by: Ben Greear <greearb@candelatech.com>
Closes: https://lore.kernel.org/all/2fb78387-d226-3193-8ca7-90040561b9ad@candelatech.com/
Fixes: 09382d8f8641 ("wifi: mt76: mt7921: update the channel usage when the regd domain changed")
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/5a976ddf1f636b5cb809373501d3cfdc6d8de3e4.1698648737.git.deren.wu@mediatek.com


# 09382d8f 29-Sep-2023 Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

wifi: mt76: mt7921: update the channel usage when the regd domain changed

The 5.9/6GHz channel license of a certain platform device has been
regulated in various countries. That may be difference with standard
Liunx regulatory domain settings. In this case, when .reg_notifier()
called for regulatory change, mt792x chipset should update the channel
usage based on clc or dts configurations.

Channel would be disabled by following cases.
* clc report the particular UNII-x is disabled.
* dts enabled and the channel is not configured.

Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 4fc8df50 29-Sep-2023 Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

wifi: mt76: mt7921: get regulatory information from the clc event

The clc event can report the radio configuration for the corresponding
country and the driver would take it as regulatory information of a
certain platform device.

This patch would change the clc commnad from no-waiting to waiting for
event. For backward compatible, we also add a new nic capability tag
to indicate the firmware did support this new clc event from now on.

Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 51ba0e3a 29-Sep-2023 Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

wifi: mt76: mt7921: add 6GHz power type support for clc

There are several power type should be supported in 6GHz band. mt7921
apply 6GHz power type from AP settings and clc will setup the
corresponding regulatory power.

Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# dab35009 29-Sep-2023 Deren Wu <deren.wu@mediatek.com>

wifi: mt76: mt7921: move connac nic capability handling to mt7921

mt76_connac_mcu_get_nic_capability() is used by mt7921 only. It
would be better to put the code in chip folder. And we can provide
more chip capability information in mt792x_phy without making
mt76_phy much bigger.

The three functions would be moved to mt7921 folder and renamed.
mt76_connac_mcu_parse_tx_resource()
mt76_connac_mcu_parse_phy_cap()
mt76_connac_mcu_get_nic_capability()

Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 7d403f3a 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt792x: move MT7921_PM_TIMEOUT and MT7921_HW_SCAN_TIMEOUT in common code

MT7921_PM_TIMEOUT is shared between mt7925 and mt7921 so move it in
mt792x module.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 583204ae 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt792x: move mt7921_load_firmware in mt792x-lib module

mt7921_load_firmware routine is shared between mt7921 and mt7925 chipset
so move it in mt792x-lib module.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 29f5a494 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: move acpi_sar code in mt792x-lib module

Move acpi_sar code in mt792x-lib module since it is shared between
mt7921 and mt7925 driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# c21a7f9f 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: move shared runtime-pm code on mt792x-lib

Moving hif_ops marcos in mt792x.h, we can move shared runtime-pm code
between mt7925 and mt7921 in mt792x-lib module.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 5c041325 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: move hif_ops macro in mt792x.h

Move the following hif_ops macro in mt792x.h:
- mt7925_init_reset
- mt7925_dev_reset
- mt7925_mcu_init
- __mt7925_mcu_drv_pmctrl
- __mt7925_mcu_fw_pmctrl

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 311f121c 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: move mac shared code in mt792x-lib module

Reduce duplicated code moving mac shared code in mt792x-lib module.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# c74df1c0 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt792x: introduce mt792x-lib module

mt792x-lib module will contain the shared code between mt7921 and new
MT79 WiFi7 chipset

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 975e122d 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: rename mt7921_dev in mt792x_dev

This is a preliminary patch to introduce WiFi7 chipset support

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 78562b2c 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: rename mt7921_phy in mt792x_phy

This is a preliminary patch to introduce WiFi7 chipset support

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# b7bfad2c 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: rename mt7921_sta in mt792x_sta

This is a preliminary patch to introduce WiFi7 chipset support

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 15ca8970 28-Jun-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: rename mt7921_vif in mt792x_vif

This is a preliminary patch to introduce WiFi7 chipset support

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 6ae39b7c 02-Jun-2023 Ben Greear <greearb@candelatech.com>

wifi: mt76: mt7921: Support temp sensor

Allow sensors tool to read radio's temperature, example:

mt7921_phy17-pci-1800
Adapter: PCI adapter
temp1: +72.0°C

Signed-off-by: Ben Greear <greearb@candelatech.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 525c469e 05-Jul-2023 Quan Zhou <quan.zhou@mediatek.com>

wifi: mt76: mt7921e: fix init command fail with enabled device

For some cases as below, we may encounter the unpreditable chip stats
in driver probe()
* The system reboot flow do not work properly, such as kernel oops while
rebooting, and then the driver do not go back to default status at
this moment.
* Similar to the flow above. If the device was enabled in BIOS or UEFI,
the system may switch to Linux without driver fully shutdown.

To avoid the problem, force push the device back to default in probe()
* mt7921e_mcu_fw_pmctrl() : return control privilege to chip side.
* mt7921_wfsys_reset() : cleanup chip config before resource init.

Error log
[59007.600714] mt7921e 0000:02:00.0: ASIC revision: 79220010
[59010.889773] mt7921e 0000:02:00.0: Message 00000010 (seq 1) timeout
[59010.889786] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59014.217839] mt7921e 0000:02:00.0: Message 00000010 (seq 2) timeout
[59014.217852] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59017.545880] mt7921e 0000:02:00.0: Message 00000010 (seq 3) timeout
[59017.545893] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59020.874086] mt7921e 0000:02:00.0: Message 00000010 (seq 4) timeout
[59020.874099] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59024.202019] mt7921e 0000:02:00.0: Message 00000010 (seq 5) timeout
[59024.202033] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59027.530082] mt7921e 0000:02:00.0: Message 00000010 (seq 6) timeout
[59027.530096] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59030.857888] mt7921e 0000:02:00.0: Message 00000010 (seq 7) timeout
[59030.857904] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59034.185946] mt7921e 0000:02:00.0: Message 00000010 (seq 8) timeout
[59034.185961] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59037.514249] mt7921e 0000:02:00.0: Message 00000010 (seq 9) timeout
[59037.514262] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59040.842362] mt7921e 0000:02:00.0: Message 00000010 (seq 10) timeout
[59040.842375] mt7921e 0000:02:00.0: Failed to get patch semaphore
[59040.923845] mt7921e 0000:02:00.0: hardware init failed

Cc: stable@vger.kernel.org
Fixes: 5c14a5f944b9 ("mt76: mt7921: introduce mt7921e support")
Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Tested-by: Juan Martinez <juan.martinez@amd.com>
Co-developed-by: Leon Yen <leon.yen@mediatek.com>
Signed-off-by: Leon Yen <leon.yen@mediatek.com>
Signed-off-by: Quan Zhou <quan.zhou@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Message-ID: <39fcb7cee08d4ab940d38d82f21897483212483f.1688569385.git.deren.wu@mediatek.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>


# 12db28c3 11-Apr-2023 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: fix kernel panic by accessing unallocated eeprom.data

The MT7921 driver no longer uses eeprom.data, but the relevant code has not
been removed completely since
commit 16d98b548365 ("mt76: mt7921: rely on mcu_get_nic_capability").
This could result in potential invalid memory access.

To fix the kernel panic issue in mt7921, it is necessary to avoid accessing
unallocated eeprom.data which can lead to invalid memory access.

Furthermore, it is possible to entirely eliminate the
mt7921_mcu_parse_eeprom function and solely depend on
mt7921_mcu_parse_response to divide the RxD header.

[2.702735] BUG: kernel NULL pointer dereference, address: 0000000000000550
[2.702740] #PF: supervisor write access in kernel mode
[2.702741] #PF: error_code(0x0002) - not-present page
[2.702743] PGD 0 P4D 0
[2.702747] Oops: 0002 [#1] PREEMPT SMP NOPTI
[2.702755] RIP: 0010:mt7921_mcu_parse_response+0x147/0x170 [mt7921_common]
[2.702758] RSP: 0018:ffffae7c00fef828 EFLAGS: 00010286
[2.702760] RAX: ffffa367f57be024 RBX: ffffa367cc7bf500 RCX: 0000000000000000
[2.702762] RDX: 0000000000000550 RSI: 0000000000000000 RDI: ffffa367cc7bf500
[2.702763] RBP: ffffae7c00fef840 R08: ffffa367cb167000 R09: 0000000000000005
[2.702764] R10: 0000000000000000 R11: ffffffffc04702e4 R12: ffffa367e8329f40
[2.702766] R13: 0000000000000000 R14: 0000000000000001 R15: ffffa367e8329f40
[2.702768] FS: 000079ee6cf20c40(0000) GS:ffffa36b2f940000(0000) knlGS:0000000000000000
[2.702769] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[2.702775] CR2: 0000000000000550 CR3: 00000001233c6004 CR4: 0000000000770ee0
[2.702776] PKRU: 55555554
[2.702777] Call Trace:
[2.702782] mt76_mcu_skb_send_and_get_msg+0xc3/0x11e [mt76 <HASH:1bc4 5>]
[2.702785] mt7921_run_firmware+0x241/0x853 [mt7921_common <HASH:6a2f 6>]
[2.702789] mt7921e_mcu_init+0x2b/0x56 [mt7921e <HASH:d290 7>]
[2.702792] mt7921_register_device+0x2eb/0x5a5 [mt7921_common <HASH:6a2f 6>]
[2.702795] ? mt7921_irq_tasklet+0x1d4/0x1d4 [mt7921e <HASH:d290 7>]
[2.702797] mt7921_pci_probe+0x2d6/0x319 [mt7921e <HASH:d290 7>]
[2.702799] pci_device_probe+0x9f/0x12a

Fixes: 16d98b548365 ("mt76: mt7921: rely on mcu_get_nic_capability")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 61d1f545 04-Apr-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: move mcu_uni_event and mcu_reg_event in common code

mcu_uni_event and mcu_reg_event structs are shared between mt7921 and
mt7615 drivers, so move them in connac lib.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 140efef3 02-Apr-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: move shared mac definitions in mt76_connac2_mac.h

Move some mac shared definitions between mt7996, mt7921 and mt7915 in
mt76_connac2_mac.h.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 50cc972d 02-Apr-2023 Lorenzo Bianconi <lorenzo@kernel.org>

wifi: mt76: mt7921: get rid of eeprom.h

eeprom.h is mostly empty for mt7921, so get rid of it.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# c222f77f 17-Jan-2023 Neil Chen <yn.chen@mediatek.com>

wifi: mt76: mt7921: fix rx filter incorrect by drv/fw inconsistent

The rx filter, in mt7921 series, may be changed in fw operation. There is
a racing problem if rx filter controlled by both driver and firmware at
the same time. To avoid this issue, let mt7921 driver set rx filter by new
command MCU_CE_CMD_SET_RX_FILTER and allow the firmware controlling it
only.

Reviewed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Neil Chen <yn.chen@mediatek.com>
Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# c36457a8 31-Dec-2022 Deren Wu <deren.wu@mediatek.com>

wifi: mt76: mt7921: fix invalid remain_on_channel duration

round_jiffies_up() may change the duration reported from chip. We should
take the real timeout for current channel privilege.

Fixes: 034ae28b56f1 ("wifi: mt76: mt7921: introduce remain_on_channel support")
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 914189af 16-Dec-2022 Deren Wu <deren.wu@mediatek.com>

wifi: mt76: mt7921: fix channel switch fail in monitor mode

When the chanctx enabled, IEEE80211_CONF_CHANGE_CHANNEL in .config()
would not be called anymore. mt76 cannot control RF channel for monitor.
Add monitor type set-channel flow in .change_chanctx().

Fixes: 41ac53c899bd ("wifi: mt76: mt7921: introduce chanctx support")
Reviewed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 7176fe65 06-Dec-2022 Quan Zhou <quan.zhou@mediatek.com>

wifi: mt76: mt7921: add support to update fw capability with MTFG table

In ACPI enabled devices, mt7921 should read MTFG table from platform
hardware. Apply necessary settings for firmware capabilities through CLC
command.

Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Quan Zhou <quan.zhou@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 034ae28b 14-Nov-2022 Sean Wang <sean.wang@mediatek.com>

wifi: mt76: mt7921: introduce remain_on_channel support

Introduce remain_on_channel support. Additionally, we add
mt7921_check_offload_capability to disable .remain_on_channel and
.cancel_remain_on_channel and related configuration because those
operations would rely on the fundamental MCU commands that will be only
supported with newer firmware.

Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 98678fc0 10-Nov-2022 Sean Wang <sean.wang@mediatek.com>

wifi: mt76: mt7921: drop ieee80211_[start, stop]_queues in driver

The firmware would be in charge of braking and continuing the traffic while
the channel contexts are switching between different BSS and HW SCAN in the
background.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 5b55b6da 10-Nov-2022 Quan Zhou <quan.zhou@mediatek.com>

wifi: mt76: mt7921: add unified ROC cmd/event support

Add unified ROC cmd/event which is only supported by the newer fw.

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Co-developed-by: Kaikai Hu <kaikai.hu@mediatek.com>
Signed-off-by: Kaikai Hu <kaikai.hu@mediatek.com>
Signed-off-by: Quan Zhou <quan.zhou@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 23bdc5d8 07-Sep-2022 Ming Yen Hsieh <mingyen.hsieh@mediatek.com>

wifi: mt76: mt7921: introduce Country Location Control support

Country Location Control (CLC) is an additional control for country rules
in firmware. We introduce this new feature to make sure mt7921 series
working properly in all region.

The addtional policies would be put into firmware based on differnt
regions. mt76 driver should be in charge of submitting per region policy.

Reviewed-by: Sean Wang <sean.wang@mediatek.com>
Tested-by: YN Chen <YN.Chen@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# a3b8008d 24-Jun-2022 Johannes Berg <johannes.berg@intel.com>

wifi: mac80211: move ps setting to vif config

This really shouldn't be in a per-link config, we don't want
to let anyone control it that way (if anything, link powersave
could be forced through APIs to activate/deactivate a link),
and we don't support powersave in software with devices that
can do MLO.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>


# 4aa8e0a4 21-Jun-2022 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: enable HW beacon filter in the initialization stage

The current driver has worked with HW beacon filter and connection
monitor all the way, here we move the enablement into the initialization
stage like other HW features being done to get rid of others are
confused why these configurations would be changed at runtime.

We still leave a way to turn off these offload features in debugfs knobs
but that is just for debugging purposes.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 1d5af0ac 02-Jul-2022 Felix Fietkau <nbd@nbd.name>

mt76: do not use skb_set_queue_mapping for internal purposes

Previously the code used skb_set_queue_mapping for management or non-bufferable
powersave frames that need to be sent to a different hardware queue.
This can confuse AQL, which expects the value to remain the same until the tx
status report.
The only place that currently uses the altered skb queue mapping is the txwi
write function. Change the code to pass the hardware queue id as a function
parameter instead.

Signed-off-by: Felix Fietkau <nbd@nbd.name>


# d2f5c8ed 20-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: move mt76_connac2_mcu_fill_message in mt76_connac module

Move mt76_connac2_mcu_fill_message routine in shared module in order to
reuse it for mt7921 and mt7915e drivers. This is a preliminary patch to
add mt7990 driver support.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# fc6ee71a 20-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: move mcu_txd/mcu_rxd structures in shared code

This is a preliminary patch to add mt7990 chipset support.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 9d958b60 08-Jun-2022 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921: fix command timeout in AP stop period

Due to AP stop improperly, mt7921 driver would face random command timeout
by chip fw problem. Migrate AP start/stop process to .start_ap/.stop_ap and
congiure BSS network settings in both hooks.

The new flow is shown below.
* AP start
.start_ap()
configure BSS network resource
set BSS to connected state
.bss_info_changed()
enable fw beacon offload

* AP stop
.bss_info_changed()
disable fw beacon offload (skip this command)
.stop_ap()
set BSS to disconnected state (beacon offload disabled automatically)
destroy BSS network resource

Fixes: 116c69603b01 ("mt76: mt7921: Add AP mode support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# c149d3a9 08-Jun-2022 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921: not support beacon offload disable command

Beacon disable flow would be handled in bss stop handler automatically.
Force return -EOPNOTSUPP in disable case.

Fixes: 116c69603b01 ("mt76: mt7921: Add AP mode support")
Reviewed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 182071cd 07-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move connac2_mac_write_txwi in mt76_connac module

mac_write_txwi code is shared between connac2 devices (mt7915 and
mt7921). Move it in connac module.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# e00b3e40 07-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: rely on mt76_dev in mt7921_mac_write_txwi signature

This is a preliminary patch to share txwi configuration code.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 28fec923 03-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mt76_connac2_load_patch in connac module

Move mt76_connac2_load_patch utility routine in mt76_connac module since
it is shared between mt7921 and mt7915. This is a preliminary patch to
support mt7902e driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# b9ec2710 03-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mt76_connac2_load_ram in connac module

Move mt76_connac2_load_ram utility routine in mt76_connac module since
it is shared between mt7921 and mt7915. This is a preliminary patch to
support mt7902e driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# c132fc7d 03-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: move fw toggle in mt7921_load_firmware

Move drv_own/fw_own toggle in mt7921_load_firmware. This change allow to
reuse connac code to load patch for mt7921 driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Tested-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 3d8c636c 03-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move shared fw structures in connac module

Move mt76_connac2 fw structures in connac module since they are shared
between mt7921 and mt7915 drivers. This is a preliminary patch to add
mt7902e support.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 56054087 03-Jun-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: get rid of mt7921_mcu_exit

Run skb_queue_purge when needed.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# a55a0c70 27-May-2022 YN Chen <yn.chen@mediatek.com>

mt76: mt7921s: fix firmware download random fail

To avoid racing problems in chip, mt7921s should reacquire drv-own after
firmware semaphore is released.

Fixes: 78b217580c509 ("mt76: mt7921s: fix bus hang with wrong privilege")
Signed-off-by: YN Chen <yn.chen@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 45b6f9cb 27-May-2022 YN Chen <yn.chen@mediatek.com>

mt76: mt7921: add PATCH_FINISH_REQ cmd response handling

add new case to fetch the return value of PATCH_FINISH_REQ

Signed-off-by: YN Chen <yn.chen@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 6e8912a5 06-Jun-2022 Shaul Triebitz <shaul.triebitz@intel.com>

wifi: mac80211: return a beacon for a specific link

Pass the link id through to the get_beacon and return
the beacon for a specific link id.

Signed-off-by: Shaul Triebitz <shaul.triebitz@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>


# f276e20b 10-May-2022 Johannes Berg <johannes.berg@intel.com>

wifi: mac80211: move interface config to new struct

We'll use bss_conf for per-link configuration later, so
move out all the non-link-specific data out into a new
struct ieee80211_vif_cfg used in the vif.

Some adjustments were done with the following spatch:

@@
expression sdata;
struct ieee80211_vif *vifp;
identifier var = { assoc, ibss_joined, aid, arp_addr_list, arp_addr_cnt, ssid, ssid_len, s1g, ibss_creator };
@@
(
-sdata->vif.bss_conf.var
+sdata->vif.cfg.var
|
-vifp->bss_conf.var
+vifp->cfg.var
)

@bss_conf@
struct ieee80211_bss_conf *bss_conf;
identifier var = { assoc, ibss_joined, aid, arp_addr_list, arp_addr_cnt, ssid, ssid_len, s1g, ibss_creator };
@@
-bss_conf->var
+vif_cfg->var

(though more manual fixups were needed, e.g. replacing
"vif_cfg->" by "vif->cfg." in many files.)

Signed-off-by: Johannes Berg <johannes.berg@intel.com>


# 5fc201aa 11-May-2022 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921: add ipv6 NS offload support

Add ipv6 NS offload for WoWLAN state.

Tested in this way:
1. Put device-A into WoW state.
2. ping6 from device-B to device-A.
3. In sniffer, see Neighbour advertisement from device-A.

Reviewed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Ming Yen Hsieh <mingyen.hsieh@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 116c6960 06-Apr-2022 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: Add AP mode support

add AP mode support to mt7921 that can work for mt7921[e,s,u]
with the common code.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Tested-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 24e69f6b 16-Mar-2022 Deren Wu <deren.wu@mediatek.com>

mt76: fix monitor rx FCS error in DFS channel

When setup monitor mode in DFS channel, mt76 send CH_SWITCH_DFS to
fw for channel config. This would cause rx performance bad while
monitoring frames. Settings CH_SWITCH_NORMAL in monitor mode would
get the same performance as normal channels.

Reviewed-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# cbaa0a40 28-Feb-2022 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: fix up the monitor mode

Properly set up the monitor mode the firmware can support to fix up
RTS/CTS and beacon frames cannot be captured and forwarded to the host.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Tested-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 00a883e6 24-Feb-2022 Felix Fietkau <nbd@nbd.name>

mt76: fix dfs state issue with 160 MHz channels

When operating on a mix of DFS and non-DFS channels, the driver only checks
the CAC status of the control channel. This causes beacons/tx to fail if the
control channel is on a non-DFS channel.
Fix this by calling cfg80211_reg_can_beacon to determine the DFS status of
all affected channels

Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 11005b18 24-Jan-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921s: fix a possible memory leak in mt7921_load_patch

Always release fw data at the end of mt7921_load_patch routine.

Fixes: 78b217580c509 ("mt76: mt7921s: fix bus hang with wrong privilege")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 4abe5b92 09-Jan-2022 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: fix endianness issues in mt7921_mcu_set_tx()

Fix the following sparse warning in mt7921_mcu_set_tx routine:

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:792:25: warning: incorrect type in assignment (different base types)
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:792:25: expected restricted __le16 [usertype] aifs
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:792:25: got unsigned char [usertype] aifs
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:798:35: warning: incorrect type in assignment (different base types)
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:798:35: expected restricted __le16 [usertype] cw_min

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 66ca1a7b 24-Dec-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: set EDCA parameters with the MCU CE command

The command MCU_EXT_CMD_EDCA_UPDATE is not fully supported by the MT7921
firmware, so we apply CE command MCU_CE_CMD_SET_EDCA_PARAMS instead which
is supported even in the oldest firmware to properly set up EDCA parameters
for each AC.

Fixes: 1c099ab44727 ("mt76: mt7921: add MCU support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 9e90c351 24-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mt76_connac_mcu_gen_dl_mode in mt76-connac module

Move mt76_connac_mcu_gen_dl_mode utility routine in mt76_connac_mcu.h
since it is shared by all drivers.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# ae90bdd6 24-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mt76_connac_mcu_restart in common module

Move mt76_connac_mcu_restart routine in mt76-connac since it is shared
between mt7921 and mt7915.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 8f4fa0f3 24-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: get rid of mt7921_mcu_get_eeprom

Remove mt7921_mcu_get_eeprom since it is no longer used.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# b5322e44 23-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7915: rely on mt76_connac_mcu_sta_ba

Rely on mt76_connac_mcu_sta_ba routine in mt7915 and remove duplicated
code.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 6683d988 19-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mt76_connac_mcu_add_key in connac module

Move key configuration code shared between mt7921 and mt7915 in
mt76-connac module and remove duplicated code.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 44c73d17 19-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mt76_connac_chan_bw in common code

Move mt76_connac_chan_bw in mt76-connac code and remove
duplicated code from mt7921 and mt7915 driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 09c874a1 19-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mt76_connac_mcu_get_cipher in common code

Move mt76_connac_mcu_get_cipher in mt76-connac code and remove
duplicated code from mt7921 and mt7915 driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 1bb42a35 15-Dec-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921s: fix suspend error with enlarging mcu timeout value

Fix the false positive suspend error that may occur on mt7921s
with enlarging mcu timeout value.

The reason why we have to enlarge mcu timeout from HZ / 3 to HZ is
we should consider the additional overhead caused by running
concurrently with btmtksdio (a MT7921 bluetooth SDIO driver) that
would compete for the same SDIO bus in process context to complete
the suspend procedure.

Fixes: 48fab5bbef40 ("mt76: mt7921: introduce mt7921s support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 3c312f43 15-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: remove dead definitions

to_wcid_lo and to_wcid_hi are no longer used in mt7921/mcu.c

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 81a88b1e 10-Dec-2021 Tzung-Bi Shih <tzungbi@google.com>

mt76: mt7921: reduce log severity levels for informative messages

"ASIC revision" and "Firmware init done" shouldn't be error messages.
Reduces the severity levels.

Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# ffc2198d 09-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: rely on MCU_CMD macro

Similar to mt7915 driver, rely on MCU_CMD macro and do not command
definitions directly

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 680a2ead 09-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: introduce MCU_CE_CMD macro

Similar to MCU_EXT_CMD, introduce MCU_CE_CMD for CE commands

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 54722402 09-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: introduce MCU_UNI_CMD macro

Similar to MCU_EXT_CMD, introduce MCU_UNI_CMD for unified commands

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 9d8d136c 09-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: align MCU_EXT definitions with 7915 driver

Align MCU_EXT and MCU_FW definitions between mt76_connac and mt7915
driver. This is a preliminary patch to reuse mt76_connac in mt7915
driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# e6d2070d 09-Dec-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: introduce MCU_EXT macros

Introduce MCU_EXT_CMD and MCU_EXT_QUERY macros in mt76_connac module.
This is a preliminary patch to reuse mt76_connac module in mt7915
driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# e0bf699a 08-Dec-2021 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921: fix network buffer leak by txs missing

TXS in mt7921 may be forwared to tx_done event. Should try to catch
TXS information in tx_done event as well.

Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 78b21758 28-Nov-2021 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921s: fix bus hang with wrong privilege

Accroding to chip hw flow, mt7921s need to re-acquire privilege
again before normal running. Otherwise, the bus may be stuck in
an abnormal status.

Tested-by: Leon Yen <Leon.Yen@mediatek.com>
Co-developed-by: Eric-SY Chang <Eric-SY.Chang@mediatek.com>
Signed-off-by: Eric-SY Chang <Eric-SY.Chang@mediatek.com>
Co-developed-by: YN Chen <YN.Chen@mediatek.com>
Signed-off-by: YN Chen <YN.Chen@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# ca74b9b9 18-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921s: add reset support

Introduce wifi chip reset support for mt7921 device to recover
mcu hangs or abnormal wifi system.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 48fab5bb 18-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: introduce mt7921s support

Introduce support for mt7921s 802.11ax (Wi-Fi 6) 2x2:2SS chipset.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# fe0195f7 18-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: refactor mt7921_mcu_send_message

This is a preliminary patch to introduce mt7921s support.

Refactor mt7921_mcu_send_message to be sharable between mt7921s and
mt7921e.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 16d98b54 18-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: rely on mcu_get_nic_capability

Rely on mcu_get_nic_capability to obtain Tx quota information
for the SDIO device, get PHY capability, MAC address and then we can
totally drop mt7921/eeprom.c and any unnecessary code.

Noting that mt76_connac_mcu_get_nic_capability should be run before set
flag MT76_STATE_MCU_RUNNING being set to setup the proper parameters
like Tx quota control before the device is started to running.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# f0ff5d3a 18-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: make all event parser reusable between mt7921s and mt7921e

The longer event such as the event for mcu_get_nic_capability would hold
the data in paged fragment skb for the SDIO device so we turn the skb to
be linearized skb before accessing it to reuse the same event parser
betweem mt7921s and mt7921e.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 8910a4e5 18-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: add MT7921_COMMON module

This is a preliminary patch to introduce mt7921s support.

MT7921_COMMON module grouping bus independent objects the both mt7921e and
mt7921s can share with and have to rely on.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# dfc7743d 18-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: refactor mcu.c to be bus independent

This is a preliminary patch to introduce mt7921s support.

Make mcu.c reusable between mt7921s and mt7921e

Tested-by: Deren Wu <deren.wu@mediatek.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# bb0ae4cf 12-Oct-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: add MU EDCA cmd support

Add MU EDCA MCU command support to update MU AC parameter record field
from the access point.

Co-developed-by: Eric-SY Chang <Eric-SY.Chang@mediatek.com>
Signed-off-by: Eric-SY Chang <Eric-SY.Chang@mediatek.com>
Tested-by: Eric-SY Chang <Eric-SY.Chang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 215a2efa 15-Sep-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: introduce __mt76_mcu_send_firmware routine

Introduce __mt76_mcu_send_firmware routine to specify mcu message max
length. This is a preliminary patch to support mt7921s driver.

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 50ac15a5 23-Aug-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: add 6GHz support

Unlock 6GHz band if supported by the device. Configure HE 6G
capabilities.

Tested-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 02d1c7d4 14-Sep-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: fix retrying release semaphore without end

We should pass the error code to the caller immediately
to avoid the possible infinite retry to release the semaphore.

Fixes: 1c099ab44727 ("mt76: mt7921: add MCU support")
Co-developed-by: YN Chen <YN.Chen@mediatek.com>
Signed-off-by: YN Chen <YN.Chen@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 8c19b3fe 03-Sep-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: remove mcu rate reporting code

Remove unused tx rate reporting through mcu tx done event since
now tx status is fully supported

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 8e695328 13-Aug-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: fix kernel warning from cfg80211_calculate_bitrate

Fix the kernel warning from cfg80211_calculate_bitrate
due to the legacy rate is not parsed well in the current driver.

Also, zeros struct rate_info before we fill it out to avoid the old value
is kept such as rate->legacy.

[ 790.921560] WARNING: CPU: 7 PID: 970 at net/wireless/util.c:1298 cfg80211_calculate_bitrate+0x354/0x35c [cfg80211]
[ 790.987738] Hardware name: MediaTek Asurada rev1 board (DT)
[ 790.993298] pstate: a0400009 (NzCv daif +PAN -UAO)
[ 790.998104] pc : cfg80211_calculate_bitrate+0x354/0x35c [cfg80211]
[ 791.004295] lr : cfg80211_calculate_bitrate+0x180/0x35c [cfg80211]
[ 791.010462] sp : ffffffc0129c3880
[ 791.013765] x29: ffffffc0129c3880 x28: ffffffd38305bea8
[ 791.019065] x27: ffffffc0129c3970 x26: 0000000000000013
[ 791.024364] x25: 00000000000003ca x24: 000000000000002f
[ 791.029664] x23: 00000000000000d0 x22: ffffff8d108bc000
[ 791.034964] x21: ffffff8d108bc0d0 x20: ffffffc0129c39a8
[ 791.040264] x19: ffffffc0129c39a8 x18: 00000000ffff0a10
[ 791.045563] x17: 0000000000000050 x16: 00000000000000ec
[ 791.050910] x15: ffffffd3f9ebed9c x14: 0000000000000006
[ 791.056211] x13: 00000000000b2eea x12: 0000000000000000
[ 791.061511] x11: 00000000ffffffff x10: 0000000000000000
[ 791.066811] x9 : 0000000000000000 x8 : 0000000000000000
[ 791.072110] x7 : 0000000000000000 x6 : ffffffd3fafa5a7b
[ 791.077409] x5 : 0000000000000000 x4 : 0000000000000000
[ 791.082708] x3 : 0000000000000000 x2 : 0000000000000000
[ 791.088008] x1 : ffffff8d3f79c918 x0 : 0000000000000000
[ 791.093308] Call trace:
[ 791.095770] cfg80211_calculate_bitrate+0x354/0x35c [cfg80211]
[ 791.101615] nl80211_put_sta_rate+0x6c/0x2c0 [cfg80211]
[ 791.106853] nl80211_send_station+0x980/0xaa4 [cfg80211]
[ 791.112178] nl80211_get_station+0xb4/0x134 [cfg80211]
[ 791.117308] genl_rcv_msg+0x3a0/0x440
[ 791.120960] netlink_rcv_skb+0xcc/0x118
[ 791.124785] genl_rcv+0x34/0x48
[ 791.127916] netlink_unicast+0x144/0x1dc

Fixes: 1c099ab44727 ("mt76: mt7921: add MCU support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 890809ca 08-Aug-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: introduce mt7921_mcu_set_beacon_filter utility routine

Introduce mt7921_mcu_set_beacon_filter utility routine in order to
remove duplicated code for hw beacon filtering.
Move mt7921_pm_interface_iter in debugfs since it is just used there.
Make the following routine static:
- mt7921_pm_interface_iter
- mt7921_mcu_uni_bss_bcnft
- mt7921_mcu_set_bss_pm

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 68808872 15-Jul-2021 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921: Add mt7922 support

Add new chip mt7922 in mt7921 module with following items
1. new chip ID / fw bin name
2. is_mt7922()
check chip type for different fw files
3. mt7921_get_data_mode()
check security type of fw (backward compatible)

Co-developed-by: Jimmy Hu <Jimmy.Hu@mediatek.com>
Signed-off-by: Jimmy Hu <Jimmy.Hu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# cd3f3873 14-Jul-2021 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921: Fix out of order process by invalid event pkt

The acceptable event report should inlcude original CMD-ID. Otherwise,
drop unexpected result from fw.

Fixes: 1c099ab44727c ("mt76: mt7921: add MCU support")
Signed-off-by: Jimmy Hu <Jimmy.Hu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# adedbc64 20-Jun-2021 Sean Wang <sean.wang@mediatek.com>

mt76: fix build error implicit enumeration conversion

drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:114:10: error: implicit
conversion from enumeration type 'enum mt76_cipher_type' to different
enumeration type 'enum mcu_cipher_type' [-Werror,-Wenum-conversion]
return MT_CIPHER_NONE;
~~~~~~ ^~~~~~~~~~~~~~

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:114:10: error: implicit
conversion from enumeration type 'enum mt76_cipher_type' to different
enumeration type 'enum mcu_cipher_type' [-Werror,-Wenum-conversion]
return MT_CIPHER_NONE;
~~~~~~ ^~~~~~~~~~~~~~

Fixes: c368362c36d3 ("mt76: fix iv and CCMP header insertion")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 30502351 19-Jun-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: avoid unnecessary spin_lock/spin_unlock in mt7921_mcu_tx_done_event

Do not grab the spinlock in mt7921_mcu_tx_done_event routine if not
necessary.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# df040215 19-Jun-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: fix endianness in mt7921_mcu_tx_done_event

Fix endianness in mt7921_mcu_tx_done_event event reported by the
firmware.

Fixes: 3cce2b98e0241 ("mt76: mt7921: introduce mac tx done handling")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# abf3d98d 21-Jul-2021 Arnd Bergmann <arnd@arndb.de>

mt76: fix enum type mismatch

There is no 'NONE' version of 'enum mcu_cipher_type', and returning
'MT_CIPHER_NONE' causes a warning:

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c: In function 'mt7921_mcu_get_cipher':
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:114:24: error: implicit conversion from 'enum mt76_cipher_type' to 'enum mcu_cipher_type' [-Werror=enum-conversion]
114 | return MT_CIPHER_NONE;
| ^~~~~~~~~~~~~~

Add the missing MCU_CIPHER_NONE defintion that fits in here with
the same value.

Fixes: c368362c36d3 ("mt76: fix iv and CCMP header insertion")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210721150745.1914829-1-arnd@kernel.org


# c3426904 08-Jul-2021 Aaron Ma <aaron.ma@canonical.com>

mt76: mt7921: continue to probe driver when fw already downloaded

When reboot system, no power cycles, firmware is already downloaded,
return -EIO will break driver as error:
mt7921e: probe of 0000:03:00.0 failed with error -5

Skip firmware download and continue to probe.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
Fixes: 1c099ab44727c ("mt76: mt7921: add MCU support")
Signed-off-by: David S. Miller <davem@davemloft.net>


# c368362c 17-Jun-2021 Ryder Lee <ryder.lee@mediatek.com>

mt76: fix iv and CCMP header insertion

The iv from RXD is only for TKIP_RSC/CCMP_PN/GCMP_PN, and it needs a
check for CCMP header insertion. Move mt76_cipher_type to mt76.h to
reduce duplicated code.

Signed-off-by: Xing Song <xing.song@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# f5056657 10-May-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: enable deep sleep at runtime

Enable the deep sleep mode with that firmware is able to trap into
the doze state at runtime to reduce the power consumption further.

The deep sleep mode is not allowed in the STA state transition with
the firmware to have the fast connection experience as we've done in
the full power mode

Reviewed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# f7d2958c 06-Jun-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: add mt76_connac_mcu_get_nic_capability utility routine

Introduce mt76_connac_mcu_get_nic_capability utility routine to poll
device capabilities returned by mcu fw for CE devices (mt7663/mt7921).
This is a preliminary patch to introduce 6GHz support.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 82453b1c 02-Jun-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: fix UC entry is being overwritten

Fix UC entry is being overwritten by BC entry

Tested-by: Deren Wu <deren.wu@mediatek.com>
Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 15539a5b 31-May-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: remove mt7921_get_wtbl_info routine

Since now the fw reports tx rate events without polling,
mt7921_get_wtbl_info and related structures are no longer used.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 3cce2b98 28-May-2021 Deren Wu <deren.wu@mediatek.com>

mt76: mt7921: introduce mac tx done handling

Instead of read tx status from mac table, add new mechanisam to hanele
tx done event for data frame, every 250ms

This event indicate the real tx status of this pkt in mac layer and
would help mac80211 correct status more frequently

Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# a2d3442e 19-May-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: enable runtime pm by default

mt7921 is mainly used in CE/IoT market so enable runtime-pm by default

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 10de032a 10-May-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: add back connection monitor support

Hw beacon cmd to the mt7921 firmware doesn't only filter out the beacon,
but also performs its own connection monitoring, including periodic
keep-alives to the AP and probing the AP on beacon loss. Will indicate
the host with the event when the firmware detects the connection is lost.

Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support")
Reviewed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: YN Chen <yn.chen@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 7bf0a71e 19-May-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: fix reset under the deep sleep is enabled

To fix possibly the race to access register between the WiFi reset
and the other context that is caused by explicitly cancelling ps_work
and wake_work to break PM_STATE consistency.

Deep sleep would cause the hardware into the inactive state,
so we forcely put device drv_own state before we start to reset.

The patch also ignore the reset request when the procedure is in
progress to avoid the consecutive WiFi resets.

localhost ~ # [ 2932.073966] SError Interrupt on CPU7, code 0xbe000011
[ 2932.073967] CPU: 7 PID: 8761 Comm: kworker/u16:2 Not tainted 5.4.112 #30
[ 2932.073968] Hardware name: MediaTek Asurada rev1 board (DT)
[ 2932.073968] Workqueue: phy0 ieee80211_reconfig_filter [mac80211]
[ 2932.073969] pstate: 80400089 (Nzcv daIf +PAN -UAO)
[ 2932.073969] pc : el1_irq+0x78/0x180
[ 2932.073970] lr : mt76_mmio_rmw+0x30/0x5c [mt76]
[ 2932.073970] sp : ffffffc01142bad0
[ 2932.073970] x29: ffffffc01142bc00 x28: ffffff8f96fb1e00
[ 2932.073971] x27: ffffffd2cdc12138 x26: ffffffd2cdaeb018
[ 2932.073972] x25: 0000000000000000 x24: ffffff8fa8e14c08
[ 2932.073973] x23: 0000000080c00009 x22: ffffffd2a5603918
[ 2932.073974] x21: ffffffc01142bc10 x20: 0000007fffffffff
[ 2932.073975] x19: 0000000000000000 x18: 0000000000000400
[ 2932.073975] x17: 0000000000000400 x16: ffffffd2cd2b87dc
[ 2932.073976] x15: 0000000000000000 x14: 0000000000000000
[ 2932.073977] x13: 0000000000000001 x12: 0000000000000001
[ 2932.073978] x11: 0000000000000001 x10: 000000000010e000
[ 2932.073978] x9 : 0000000000000000 x8 : ffffffc013921404
[ 2932.073979] x7 : 000000b2b5593519 x6 : 0000000000300000
[ 2932.073980] x5 : 0000000000000000 x4 : ffffffc01142bbc8
[ 2932.073980] x3 : 00000000000001f0 x2 : 0000000000000000
[ 2932.073981] x1 : 0000000000021404 x0 : ffffff8fa8e12300
[ 2932.073982] Kernel panic - not syncing: Asynchronous SError Interrupt
[ 2932.073983] CPU: 7 PID: 8761 Comm: kworker/u16:2 Not tainted 5.4.112 #30
[ 2932.073983] Hardware name: MediaTek Asurada rev1 board (DT)
[ 2932.073984] Workqueue: phy0 ieee80211_reconfig_filter [mac80211]
[ 2932.073984] Call trace:
[ 2932.073985] dump_backtrace+0x0/0x14c
[ 2932.073985] show_stack+0x20/0x2c
[ 2932.073985] dump_stack+0xa0/0xf8
[ 2932.073986] panic+0x154/0x360
[ 2932.073986] test_taint+0x0/0x44
[ 2932.073986] arm64_serror_panic+0x78/0x84
[ 2932.073987] do_serror+0x0/0x118
[ 2932.073987] do_serror+0xa4/0x118
[ 2932.073987] el1_error+0x84/0xf8
[ 2932.073988] el1_irq+0x78/0x180
[ 2932.073988] mt76_mmio_rr+0x30/0xf0 [mt76]
[ 2932.073988] mt76_mmio_rmw+0x30/0x5c [mt76]
[ 2932.073989] mt7921_rmw+0x4c/0x5c [mt7921e]
[ 2932.073989] mt7921_configure_filter+0x138/0x160 [mt7921e]
[ 2932.073990] ieee80211_configure_filter+0x2f0/0x3e0 [mac80211]
[ 2932.073990] ieee80211_reconfig_filter+0x1c/0x28 [mac80211]
[ 2932.073990] process_one_work+0x208/0x3c8
[ 2932.073991] worker_thread+0x23c/0x3e8
[ 2932.073991] kthread+0x140/0x17c
[ 2932.073992] ret_from_fork+0x10/0x18
[ 2932.074071] SMP: stopping secondary CPUs
[ 2932.074071] Kernel Offset: 0x12bc800000 from 0xffffffc010000000
[ 2932.074072] PHYS_OFFSET: 0xfffffff180000000
[ 2932.074072] CPU features: 0x080026,2a80aa18
[ 2932.074072] Memory Limit: none

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# d874e6c0 23-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: fix possible AOOB issue in mt7921_mcu_tx_rate_report

Fix possible array out of bound access in mt7921_mcu_tx_rate_report.
Remove unnecessary varibable in mt7921_mcu_tx_rate_report

Fixes: 1c099ab44727c ("mt76: mt7921: add MCU support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/91a1e8f6b6a3e6a929de560ed68132f6eb421720.1619187875.git.lorenzo@kernel.org


# 3df93214 21-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: reinit wpdma during drv_own if necessary

Check dummy reg to reinitialized WPDMA during driver_own operation

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 2bf301bc 21-Apr-2021 Dan Carpenter <dan.carpenter@oracle.com>

mt76: mt7921: fix a precision vs width bug in printk

Precision %.*s was intended instead of width %*s. The original code
is potentially an information leak.

Fixes: c7cc5ec57303 ("mt76: mt7921: rework mt7921_mcu_debug_msg_event routine")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 36fcc8cf 19-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: introduce mt7921_mcu_sta_add routine

mt7921_mcu_sta_add will be used to add and remove wtbl entries.
Create broadcast wtbl entry after AP association

Co-developed-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Deren Wu <deren.wu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# d43b3257 20-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: get rid of mcu_reset function pointer

since mcu_reset it used only by mt7921, move the reset callback to
mt7921_mcu_parse_response routine and get rid of the function pointer.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 36873246 18-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: add awake and doze time accounting

Introduce awake and doze time accounting for runtime pm.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# ec7bd7b4 18-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: check wake refcount in mcu_fw_pmctrl

In order to avoid synchronization races between tx and rx path, rely on
mt76_connac_skip_fw_pmctrl putting the chip in sleep mode for mt7921 and
mt7663 devices

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 4f9b3aeb 18-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: unschedule ps_work in mt76_connac_pm_wake

In order to avoid synchronization issues between wake and ps works,
cancel ps_work in mt76_connac_pm_wake routine

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# fad90e43 18-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: fix a race between mt7921_mcu_drv_pmctrl and mt7921_mcu_fw_pmctrl

Introduce a mutex in order to avoid a race between mt7921_mcu_drv_pmctrl and
mt7921_mcu_fw_pmctrl routines since they are run two independent works

Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# f4f4089e 16-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: connac: move mcu_update_arp_filter in mt76_connac module

Move mt76_connac_mcu_update_arp_filter in mt76_connac module since the
code is shared between mt7615 and mt7921

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 53d35b1a 15-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: improve mcu error logging

Dump mcu command code in hex and related prefix to help debugging

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# ea29acc9 13-Apr-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: add dumping Tx power table

Dump the tx power table saved in offload firmware.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 481fc927 12-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: add rcu section in mt7921_mcu_tx_rate_report

Introduce rcu section in mt7921_mcu_tx_rate_report before dereferencing
wcid pointer otherwise loockdep will report the following issue:

[ 115.245740] =============================
[ 115.245754] WARNING: suspicious RCU usage
[ 115.245771] 5.10.20 #0 Not tainted
[ 115.245784] -----------------------------
[ 115.245816] other info that might help us debug this:
[ 115.245830] rcu_scheduler_active = 2, debug_locks = 1
[ 115.245845] 3 locks held by kworker/u4:1/20:
[ 115.245858] #0: ffffff80065ab138 ((wq_completion)phy0){+.+.}-{0:0}, at: process_one_work+0x1f8/0x6b8
[ 115.245948] #1: ffffffc01198bdd8 ((work_completion)(&(&dev->mphy.mac_work)->work)){+.+.}-{0:0}, at: process_one_8
[ 115.246027] #2: ffffff8006543ce8 (&dev->mutex#2){+.+.}-{3:3}, at: mt7921_mac_work+0x60/0x2b0 [mt7921e]
[ 115.246125]
[ 115.246125] stack backtrace:
[ 115.246142] CPU: 1 PID: 20 Comm: kworker/u4:1 Not tainted 5.10.20 #0
[ 115.246152] Hardware name: MediaTek MT7622 RFB1 board (DT)
[ 115.246168] Workqueue: phy0 mt7921_mac_work [mt7921e]
[ 115.246188] Call trace:
[ 115.246201] dump_backtrace+0x0/0x1a8
[ 115.246213] show_stack+0x14/0x30
[ 115.246228] dump_stack+0xec/0x134
[ 115.246240] lockdep_rcu_suspicious+0xcc/0xdc
[ 115.246255] mt7921_get_wtbl_info+0x2a4/0x310 [mt7921e]
[ 115.246269] mt7921_mac_work+0x284/0x2b0 [mt7921e]
[ 115.246281] process_one_work+0x2a0/0x6b8
[ 115.246293] worker_thread+0x40/0x440
[ 115.246305] kthread+0x144/0x148
[ 115.246317] ret_from_fork+0x10/0x18

Fixes: 1c099ab44727c ("mt76: mt7921: add MCU support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 2afd17b4 11-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: introduce MCU_EVENT_LP_INFO event parsing

Report trace event related to MCU_EVENT_LP_INFO that is sent by the mcu
when it is ready to enter in deep sleep state

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 49897c52 05-Apr-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: fix the insmod hangs

Fix the second insert module causing the device hangs after remove module.

Fixes: 1c099ab44727 ("mt76: mt7921: add MCU support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 9c9d8321 05-Apr-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: fix inappropriate WoW setup with the missing ARP informaiton

Fix the Wake-on-WoWLAN failure should rely on ARP Information is being
updated in time to the firmware.

Fixes: ffa1bf97425b ("mt76: mt7921: introduce PM support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# c7cc5ec5 03-Apr-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: rework mt7921_mcu_debug_msg_event routine

Rework mt7921_mcu_debug_msg_event routing removing unnecessary
assignments and relying on wiphy_info

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 0c1ce988 07-Mar-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: add wifi reset support

Introduce wifi chip reset support for mt7921 device to recover mcu
hangs.

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# d32464e6 07-Mar-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: introduce mt7921_run_firmware utility routine.

This is a preliminary patch to introduce chip reset for mt7921 devices.

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# a2a6cd54 07-Mar-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: reduce mcu timeouts for suspend, offload and hif_ctrl msg

Reduce mcu timeout for the following uni mcu commands:
- MCU_UNI_CMD_SUSPEND
- MCU_UNI_CMD_OFFLOAD
- MCU_UNI_CMD_HIF_CTRL

This is a preliminary patch to introduce chip reset support

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 159f6dd6 19-Feb-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: switch to new api for hardware beacon filter

Current firmware only supports new api for enabling hardware beacon filter.

Fixes: 1d8efc741df80 ("mt76: mt7921: introduce Runtime PM support")
Beacon filter cmd have to rely on the associatied access point's beacon
interval and DTIM information.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# fb5fabb1 25-Feb-2021 Arnd Bergmann <arnd@arndb.de>

mt76: mt7921: remove incorrect error handling

Clang points out a mistake in the error handling in
mt7921_mcu_tx_rate_report(), which tries to dereference a pointer that
cannot be initialized because of the error that is being handled:

drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:409:3: warning: variable 'stats' is uninitialized when used here [-Wuninitialized]
stats->tx_rate = rate;
^~~~~
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c:401:32: note: initialize the variable 'stats' to silence this warning
struct mt7921_sta_stats *stats;
^
Just remove the obviously incorrect line.

Fixes: 1c099ab44727 ("mt76: mt7921: add MCU support")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210225145953.404859-2-arnd@kernel.org


# 0da3c795 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: add coredump support

Introduce coredump support to mt7921 driver.

The coredump would be produced when MCU met the fatal error or driver
sent out the specific cmd to force trigger it.

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 1d8efc74 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: introduce Runtime PM support

Introduce runtime PM to mt7921 driver

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 022159b0 27-Jan-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: rely on mt76_connac_mcu module for suspend and WoW support

Rely on mt76_connac_mcu module for suspend and WoW support and remove
duplicated code

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 80fc1e37 27-Jan-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: rely on mt76_connac_mcu module for sched_scan and hw_scan

Rely on mt76_connac_mcu module for sched_scan and hw_scan and remove
duplicated code

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 67aa2743 27-Jan-2021 Lorenzo Bianconi <lorenzo@kernel.org>

mt76: mt7921: rely on mt76_connac_mcu common library

Rely on mt76_connac_mcu common library and remove duplicated code

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# ffa1bf97 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: introduce PM support

Introduce suspend/resume and WoW (Wake-on-WoWLAN) support to mt7921
driver to allow remote wakeu-up from the suspend state.

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# b88f5c64 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: introduce beacon_loss mcu event

If device has enabled beacon hw filter rx beacons are not reported to
the host. Introduce beacon_loss mcu event to trigger mac80211 mlme
connection state machine in this configuration.
IEEE80211_VIF_BEACON_FILTER has not set in vif flags since hw beacon
filter is not enabled yet

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 4086ee28 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: introduce support for hardware beacon filter

Introduce support for hw beacon filter available in the mt7921 firmware.

According to mt7921e firmware, enabling hardware filter would rely on
mt7921_mcu_uni_bss_bcnft and disabling hardware filter still rely on legacy
mt7921_mcu_set_bss_pm.

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 56d965da 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: introduce 802.11 PS support in sta mode

Enable 802.11 power-save support available in mt7921 firmware

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 29f9d8b0 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: introduce schedule scan support

introduce schedule scan to control mt7921 firmware to do background scan in
defined plan to see if the matched SSID is available.

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>


# 1c099ab4 27-Jan-2021 Sean Wang <sean.wang@mediatek.com>

mt76: mt7921: add MCU support

MT7921 contains a microprocessor with which the host can use command/event
to communicate to implement offload features such as establish connection,
hardware scan and so on. The host has to download the ROM patch, RAM
firmware and finally activate the MCU to complete the MT7921
initialization.

Co-developed-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Co-developed-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Soul Huang <Soul.Huang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>