platform/kernel/linux-rpi.git
3 years agomt76: mt7921: fix a precision vs width bug in printk
Dan Carpenter [Wed, 21 Apr 2021 13:16:06 +0000 (16:16 +0300)]
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>
3 years agomt76: mt7915: fix a precision vs width bug in printk
Dan Carpenter [Wed, 21 Apr 2021 13:40:40 +0000 (16:40 +0300)]
mt76: mt7915: fix a precision vs width bug in printk

Precision %.*s was intended instead of width %*s.  The original code
will still print unintended data from beyond the end of skb->data.

Fixes: 665b2c780d63 ("mt76: mt7915: limit firmware log message printk to buffer length")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: fix a precision vs width bug in printk
Dan Carpenter [Wed, 21 Apr 2021 13:14:40 +0000 (16:14 +0300)]
mt76: mt7615: fix a precision vs width bug in printk

Precision "%.*s" was intended instead of width "%*s".  The original code
will print garbage from beyond the end of the skb->data.

Fixes: d76d6c3ba2b0 ("mt76: mt7615: limit firmware log message printk to buffer length")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: debugfs: introduce napi_threaded node
Lorenzo Bianconi [Mon, 15 Mar 2021 21:49:15 +0000 (22:49 +0100)]
mt76: debugfs: introduce napi_threaded node

Introduce napi_threaded debugfs knob in order to enable/disable NAPI
threaded support

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: introduce mt7921_mcu_sta_add routine
Lorenzo Bianconi [Mon, 19 Apr 2021 12:03:00 +0000 (14:03 +0200)]
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>
3 years agomt76: mt7921: mt7921_stop should put device in fw_own state
Sean Wang [Wed, 21 Apr 2021 10:43:51 +0000 (12:43 +0200)]
mt76: mt7921: mt7921_stop should put device in fw_own state

mt7921_stop should put device in fw_own state to reduce
power consumption.

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>
3 years agomt76: connac: unschedule mac_work before going to sleep
Lorenzo Bianconi [Wed, 21 Apr 2021 10:43:50 +0000 (12:43 +0200)]
mt76: connac: unschedule mac_work before going to sleep

In order to wake the device less frequently and so reduce power
consumpation, unschedule mac_work before going to sleep

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7663: add awake and doze time accounting
Lorenzo Bianconi [Wed, 21 Apr 2021 10:43:49 +0000 (12:43 +0200)]
mt76: mt7663: add awake and doze time accounting

Similar to mt7921, 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>
3 years agomt76: mt7921: improve doze opportunity
Lorenzo Bianconi [Wed, 21 Apr 2021 10:43:48 +0000 (12:43 +0200)]
mt76: mt7921: improve doze opportunity

Increase mt7921 mac work timeout in oder to have move sleep
opportunities

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: get rid of mcu_reset function pointer
Lorenzo Bianconi [Wed, 21 Apr 2021 10:28:33 +0000 (12:28 +0200)]
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>
3 years agomt76: mt7915: do not read rf value from efuse in flash mode
Shayne Chen [Wed, 21 Apr 2021 08:39:45 +0000 (16:39 +0800)]
mt76: mt7915: do not read rf value from efuse in flash mode

Do not read rf value from efuse when driver is configured to
use flash mode.

Tested-by: Bruce Chuang <bruce-ss.chuang@mediatek.com>
Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: move token utilities in mt76 common module
Lorenzo Bianconi [Tue, 20 Apr 2021 21:05:32 +0000 (23:05 +0200)]
mt76: move token utilities in mt76 common module

Move token management in mt76 common module since it is shared between
mt7615, mt7915 and mt7921 drivers

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: move token_lock, token and token_count in mt76_dev
Lorenzo Bianconi [Tue, 20 Apr 2021 21:05:31 +0000 (23:05 +0200)]
mt76: move token_lock, token and token_count in mt76_dev

Move token_lock, token and token_count data structures in mt76_dev.
This is a preliminary patch to move token management in mt76 common
module since it is shared by mt7615, mt7915 and mt7921 drivers.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: fix possible invalid register access
Sean Wang [Mon, 19 Apr 2021 15:58:05 +0000 (23:58 +0800)]
mt76: mt7921: fix possible invalid register access

Disable the interrupt and synchronze for the pending irq handlers to ensure
the irq tasklet is not being scheduled after the suspend to avoid the
possible invalid register access acts when the host pcie controller is
suspended.

[17932.910534] mt7921e 0000:01:00.0: pci_pm_suspend+0x0/0x22c returned 0 after 21375 usecs
[17932.910590] pcieport 0000:00:00.0: calling pci_pm_suspend+0x0/0x22c @ 18565, parent: pci0000:00
[17932.910602] pcieport 0000:00:00.0: pci_pm_suspend+0x0/0x22c returned 0 after 8 usecs
[17932.910671] mtk-pcie 11230000.pcie: calling platform_pm_suspend+0x0/0x60 @ 22783, parent: soc
[17932.910674] mtk-pcie 11230000.pcie: platform_pm_suspend+0x0/0x60 returned 0 after 0 usecs

...

17933.615352] x1 : 00000000000d4200 x0 : ffffff8269ca2300
[17933.620666] Call trace:
[17933.623127]  mt76_mmio_rr+0x28/0xf0 [mt76]
[17933.627234]  mt7921_rr+0x38/0x44 [mt7921e]
[17933.631339]  mt7921_irq_tasklet+0x54/0x1d8 [mt7921e]
[17933.636309]  tasklet_action_common+0x12c/0x16c
[17933.640754]  tasklet_action+0x24/0x2c
[17933.644418]  __do_softirq+0x16c/0x344
[17933.648082]  irq_exit+0xa8/0xac
[17933.651224]  scheduler_ipi+0xd4/0x148
[17933.654890]  handle_IPI+0x164/0x2d4
[17933.658379]  gic_handle_irq+0x140/0x178
[17933.662216]  el1_irq+0xb8/0x180
[17933.665361]  cpuidle_enter_state+0xf8/0x204
[17933.669544]  cpuidle_enter+0x38/0x4c
[17933.673122]  do_idle+0x1a4/0x2a8
[17933.676352]  cpu_startup_entry+0x24/0x28
[17933.680276]  rest_init+0xd4/0xe0
[17933.683508]  arch_call_rest_init+0x10/0x18
[17933.687606]  start_kernel+0x340/0x3b4
[17933.691279] Code: aa0003f5 d503201f f953eaa8 8b344108 (b9400113)
[17933.697373] ---[ end trace a24b8e26ffbda3c5 ]---
[17933.767846] Kernel panic - not syncing: Fatal exception in interrupt

Fixes: ffa1bf97425b ("mt76: mt7921: introduce PM support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: enable deep sleep when the device suspends
Sean Wang [Mon, 19 Apr 2021 14:20:59 +0000 (22:20 +0800)]
mt76: mt7921: enable deep sleep when the device suspends

Enable the deep sleep mode in suspend handler to reduce the power
consumption further.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: introduce mt76_connac_mcu_set_deep_sleep utility
Sean Wang [Mon, 19 Apr 2021 14:20:58 +0000 (22:20 +0800)]
mt76: connac: introduce mt76_connac_mcu_set_deep_sleep utility

Introduce mt76_connac_mcu_set_deep_sleep to enable deep sleep mode
and will be activated immediately when the host returns the ownership
to the device.

Co-developed-by: Leon Yen <leon.yen@mediatek.com>
Signed-off-by: Leon Yen <leon.yen@mediatek.com>
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>
3 years agomt76: mt7921: introduce mt7921_wpdma_reinit_cond utility routine
Lorenzo Bianconi [Mon, 19 Apr 2021 14:20:57 +0000 (22:20 +0800)]
mt76: mt7921: introduce mt7921_wpdma_reinit_cond utility routine

Add mt7921_wpdma_reinit_cond to check dummy reg if driver needs to
reinitialized WPDMA after driver_own operation

Co-developed-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Co-developed-by: Leon Yen <leon.yen@mediatek.com>
Signed-off-by: Leon Yen <leon.yen@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: introduce mt7921_dma_{enable,disable} utilities
Lorenzo Bianconi [Mon, 19 Apr 2021 14:20:56 +0000 (22:20 +0800)]
mt76: mt7921: introduce mt7921_dma_{enable,disable} utilities

Introduce mt7921_dma_enable and mt7921_dma_disable utilities routine in
order for code reusing between mt7921_dma_reset and mt7921_dma_init.
This is a preliminary patch to reset dma during device driver_own
request.

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>
3 years agomt76: mt7921: introduce mt7921_wpdma_reset utility routine
Lorenzo Bianconi [Mon, 19 Apr 2021 14:20:55 +0000 (22:20 +0800)]
mt76: mt7921: introduce mt7921_wpdma_reset utility routine

Introduce mt7921_wpdma_reset routine to reset wpdma during chip reset
or driver_own request.

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>
3 years agomt76: mt7921: move mt7921_dma_reset in dma.c
Lorenzo Bianconi [Mon, 19 Apr 2021 14:20:54 +0000 (22:20 +0800)]
mt76: mt7921: move mt7921_dma_reset in dma.c

Move mt7921_dma_reset routine in dma.c and make mt7921_dma_prefetch
static. Moreover add force parameter to mt7921_dma_reset signature.
This is a preliminary patch to reset dma mt7921_mcu_drv_pmctrl.

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>
3 years agomt76: mt7615: Fix a dereference of pointer sta before it is null checked
Colin Ian King [Mon, 19 Apr 2021 13:20:32 +0000 (14:20 +0100)]
mt76: mt7615: Fix a dereference of pointer sta before it is null checked

Currently the assignment of idx dereferences pointer sta before
sta is null checked, leading to a potential null pointer dereference.
Fix this by assigning idx when it is required after the null check on
pointer sta.

Addresses-Coverity: ("Dereference before null check")
Fixes: a4a5a430b076 ("mt76: mt7615: fix TSF configuration")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: enable sw interrupts
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:45 +0000 (18:45 +0200)]
mt76: mt7921: enable sw interrupts

Enable sw interrupts in order to wake the device from deep sleep
receiving packets

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: add awake and doze time accounting
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:44 +0000 (18:45 +0200)]
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>
3 years agomt76: remove MT76_STATE_PM in tx path
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:43 +0000 (18:45 +0200)]
mt76: remove MT76_STATE_PM in tx path

since tx/rx path is now relying pm ref counting, get rid of MT76_STATE_PM
check in the tx path

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: use waitqueue for runtime-pm
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:42 +0000 (18:45 +0200)]
mt76: connac: use waitqueue for runtime-pm

Simplify the code using a wait_queue_head_t instead of a completion to
wait the chip is fully awake in mt76_connac_pm_wake routine

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: do not run mt76_txq_schedule_all directly
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:41 +0000 (18:45 +0200)]
mt76: connac: do not run mt76_txq_schedule_all directly

In order to not break runtime-pm, do run mt76_txq_schedule_all in
mt7615_set_channel/mt7921_set_channel but rely on mt76_worker_schedule

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: rely on pm refcounting in mt7615_led_set_config
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:40 +0000 (18:45 +0200)]
mt76: mt7615: rely on pm refcounting in mt7615_led_set_config

Rely on mt76_connac_pm_ref/mt76_connac_pm_unref utility routines in
mt7615_led_set_config

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: alaways wake the device before scanning
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:39 +0000 (18:45 +0200)]
mt76: connac: alaways wake the device before scanning

move scanning check from mt76_connac_power_save_sched routine
to mt7921_pm_power_save_work/mt7615_pm_power_save_work ones

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: get rid of useless MT76_STATE_PM in mt7921_mac_work
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:38 +0000 (18:45 +0200)]
mt76: mt7921: get rid of useless MT76_STATE_PM in mt7921_mac_work

Remove useless MT76_STATE_PM check in mt7921_mac_work since
mt7921_mutex_acquire will wake up the device if necessary

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: remove MT76_STATE_PM in mac_tx_free
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:37 +0000 (18:45 +0200)]
mt76: connac: remove MT76_STATE_PM in mac_tx_free

Get rid of MT76_STATE_PM chec in mt7615_mac_tx_free and
mt7921_mac_tx_free since we already rely on mt76_connac_pm_unref in the
NAPI callback.
Remove mt76_connac_power_save_sched calls in mt7615_mac_tx_free and
mt7921_mac_tx_free

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: check wake refcount in mcu_fw_pmctrl
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:36 +0000 (18:45 +0200)]
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>
3 years agomt76: connac: unschedule ps_work in mt76_connac_pm_wake
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:35 +0000 (18:45 +0200)]
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>
3 years agomt76: mt7663: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx/rx napi
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:34 +0000 (18:45 +0200)]
mt76: mt7663: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx/rx napi

Introduce mt7615_poll_rx rx napi callback for mt7663.
Do not access device registers in tx/rx napi if the device is not awake.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx/rx napi
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:33 +0000 (18:45 +0200)]
mt76: mt7921: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx/rx napi

Introduce mt7921_poll_rx rx napi callback for mt7921.
Do not access device registers in tx/rx napi if the device is not awake.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: dma: add the capability to define a custom rx napi poll routine
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:32 +0000 (18:45 +0200)]
mt76: dma: add the capability to define a custom rx napi poll routine

Add the capability to define a custom rx napi callback for each driver.
This is a preliminary patch to properly support runtime-pm on rx side

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7663: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx path
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:31 +0000 (18:45 +0200)]
mt76: mt7663: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx path

Introduce mt7615_tx_worker routine as mt76 tx worker callback for
mt7663.
Rely on mt76_connac_pm_ref/mt76_connac_pm_unref to check PM state and
increment/decrement wake counter

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx path
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:30 +0000 (18:45 +0200)]
mt76: mt7921: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx path

Introduce mt7921_tx_worker routine as mt76 tx worker callback for
mt7921.
Rely on mt76_connac_pm_ref/mt76_connac_pm_unref to check PM state and
increment/decrement wake counter

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: introduce wake counter for fw_pmctrl synchronization
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:29 +0000 (18:45 +0200)]
mt76: connac: introduce wake counter for fw_pmctrl synchronization

Introduce wake counter and related spinlock in order to synchronize
tx/rx path and fw_pmctrl request.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7663: fix a race between mt7615_mcu_drv_pmctrl and mt7615_mcu_fw_pmctrl
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:28 +0000 (18:45 +0200)]
mt76: mt7663: fix a race between mt7615_mcu_drv_pmctrl and mt7615_mcu_fw_pmctrl

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

Fixes: 1f549009b5b2 ("mt76: mt7615: do not request {driver,fw}_own if already granted")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: fix a race between mt7921_mcu_drv_pmctrl and mt7921_mcu_fw_pmctrl
Lorenzo Bianconi [Sun, 18 Apr 2021 16:45:27 +0000 (18:45 +0200)]
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>
3 years agomt76: mt7921: remove leftover function declaration
Lorenzo Bianconi [Sat, 17 Apr 2021 16:51:37 +0000 (18:51 +0200)]
mt76: mt7921: remove leftover function declaration

Get rid of leftover mt7921_mcu_add_bss_info routine declaration

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: connac: move mcu_update_arp_filter in mt76_connac module
Lorenzo Bianconi [Sat, 17 Apr 2021 10:28:49 +0000 (12:28 +0200)]
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>
3 years agomt76: mt7921: do not use 0 as NULL pointer
Lorenzo Bianconi [Sat, 17 Apr 2021 10:27:06 +0000 (12:27 +0200)]
mt76: mt7921: do not use 0 as NULL pointer

Fix the following sparse warning:
drivers/net/wireless/mediatek/mt76/mt7921/mac.c:1425:70:
  warning: Using plain integer as NULL pointer

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: directly read per-rate tx power from registers
Shayne Chen [Fri, 16 Apr 2021 22:16:19 +0000 (06:16 +0800)]
mt76: mt7915: directly read per-rate tx power from registers

Since driver no longer handler per-rate tx power setting, we need to
read the power values directly from registers.

Tested-by: Evelyn Tsai <evelyn.tsai@mediatek.com>
Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: rework the flow of txpower setting
Shayne Chen [Fri, 16 Apr 2021 22:16:18 +0000 (06:16 +0800)]
mt76: mt7915: rework the flow of txpower setting

Clean up the flow of per-rate txpower limit setting to get rid of
duplicate work since it has already been handled by firmware, and set
proper max_power based on different channels and regdomains.

Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: add support for DT rate power limits
Shayne Chen [Fri, 16 Apr 2021 22:16:17 +0000 (06:16 +0800)]
mt76: mt7915: add support for DT rate power limits

Enable to limit per-rate max txpower from DT.

Tested-by: Evelyn Tsai <evelyn.tsai@mediatek.com>
Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: abort uncompleted scan by wifi reset
Sean Wang [Fri, 16 Apr 2021 15:30:36 +0000 (23:30 +0800)]
mt76: mt7921: abort uncompleted scan by wifi reset

Scan abort should be required for the uncompleted hardware scan
interrupted by wifi reset. Otherwise, it is possible that the scan
request after wifi reset gets error code -EBUSY from mac80211 and
then blocks the reconnectting to the access point.

Fixes: 0c1ce9884607 ("mt76: mt7921: add wifi reset support")
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: add wifisys reset support in debugfs
Sean Wang [Fri, 16 Apr 2021 15:30:35 +0000 (23:30 +0800)]
mt76: mt7921: add wifisys reset support in debugfs

Introduce chip_reset knob in mt7921 debugfs to export a way to users
able to trigger wifi reset, and group the similar operations
previously defined in chip_config in the same knob.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: run mt7921_mcu_fw_log_2_host holding mt76 mutex
Lorenzo Bianconi [Thu, 15 Apr 2021 22:21:54 +0000 (00:21 +0200)]
mt76: mt7921: run mt7921_mcu_fw_log_2_host holding mt76 mutex

Wake the chip before configuring the mcu log level

Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: improve mcu error logging
Lorenzo Bianconi [Thu, 15 Apr 2021 15:50:02 +0000 (17:50 +0200)]
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>
3 years agomt76: mt7921: move hw configuration in mt7921_register_device
Lorenzo Bianconi [Thu, 15 Apr 2021 09:03:58 +0000 (11:03 +0200)]
mt76: mt7921: move hw configuration in mt7921_register_device

Get rid of init work since firmware loading is already performed in
mt7921_init_hardware

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: add support for applying pre-calibration data
Ryder Lee [Wed, 14 Apr 2021 16:45:49 +0000 (00:45 +0800)]
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 <bo.jiao@mediatek.com>
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: load ROM patch before checking patch semaphore status
Felix Fietkau [Fri, 16 Apr 2021 08:24:46 +0000 (10:24 +0200)]
mt76: mt7615: load ROM patch before checking patch semaphore status

For MT7663, the availability of the patch files is used to detect, which
corresponding firmware is going to be used (AP firmware or STA offload
firmware). If the ROM patch was already applied, it could attempt to
load the wrong firmware (without considering the alternative).

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: fix entering driver-own state on mt7663
Felix Fietkau [Thu, 15 Apr 2021 19:07:53 +0000 (21:07 +0200)]
mt76: mt7615: fix entering driver-own state on mt7663

Fixes hardware wakeup issues

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: fix hardware error recovery for mt7663
Felix Fietkau [Thu, 15 Apr 2021 18:57:42 +0000 (20:57 +0200)]
mt76: mt7615: fix hardware error recovery for mt7663

MT7663 uses different bits for communicating reset commands/status between MCU
and host. Also add an extra initial reset command.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: add dumping Tx power table
Sean Wang [Tue, 13 Apr 2021 09:08:41 +0000 (11:08 +0200)]
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>
3 years agomt76: introduce single-sku support for mt7663/mt7921
Lorenzo Bianconi [Tue, 13 Apr 2021 09:08:40 +0000 (11:08 +0200)]
mt76: introduce single-sku support for mt7663/mt7921

Introduce support for rate-txpower compensation for mt7663/mt7921 chipsets.
Rate-txpower limit is specified through dts

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: do not use mt7615 single-sku values for mt7663
Lorenzo Bianconi [Tue, 13 Apr 2021 09:08:39 +0000 (11:08 +0200)]
mt76: mt7615: do not use mt7615 single-sku values for mt7663

mt7663 mcu relies on different APIs to configure APIs per-rate power limit
respect to mt7615 driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: implement support for using DT rate power limits
Felix Fietkau [Tue, 13 Apr 2021 09:08:38 +0000 (11:08 +0200)]
mt76: mt7615: implement support for using DT rate power limits

Limits are used to update the channel max_power settings and also passed
to the firmware on channel changes

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: extend DT rate power limits to support 11ax devices
Shayne Chen [Tue, 13 Apr 2021 09:08:37 +0000 (11:08 +0200)]
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 <nbd@nbd.name>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Tested-by: Evelyn Tsai <evelyn.tsai@mediatek.com>
Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: add functions for parsing rate power limits from DT
Felix Fietkau [Tue, 13 Apr 2021 09:08:36 +0000 (11:08 +0200)]
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 <nbd@nbd.name>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agodt-bindings:net:wireless:mediatek,mt76: introduce power-limits node
Lorenzo Bianconi [Tue, 13 Apr 2021 09:08:35 +0000 (11:08 +0200)]
dt-bindings:net:wireless:mediatek,mt76: introduce power-limits node

Introduce power-limits node in mt76 binding in order to specify
per-rate power limit values for each 802.11n/802.11ac rate

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: flush tx status queue on DMA reset
Felix Fietkau [Tue, 13 Apr 2021 18:09:33 +0000 (20:09 +0200)]
mt76: flush tx status queue on DMA reset

After DMA reset, tx status information for queued frames will never arrive.
Flush the queue to free skbs immediately instead of waiting for a timeout

Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7921: add mt7921_dma_cleanup in mt7921_unregister_device
Lorenzo Bianconi [Tue, 13 Apr 2021 12:13:54 +0000 (14:13 +0200)]
mt76: mt7921: add mt7921_dma_cleanup in mt7921_unregister_device

In order to avoid memory leaks, clean the dma engine unloading the
module

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: use ieee80211_free_txskb() in mt7615_tx_token_put()
Ryder Lee [Tue, 13 Apr 2021 08:00:07 +0000 (16:00 +0800)]
mt76: mt7615: use ieee80211_free_txskb() in mt7615_tx_token_put()

We should use ieee80211_free_txskb() to report skb status avoid wrong
aql accounting after reset.

Cc: stable@vger.kernel.org
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: only free skbs after mt7615_dma_reset() when reset happens
Ryder Lee [Tue, 13 Apr 2021 08:00:06 +0000 (16:00 +0800)]
mt76: mt7615: only free skbs after mt7615_dma_reset() when reset happens

In mt7615_mac_reset_work(), make sure freeing skbs after mt7615_dma_reset().

Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: only free skbs after mt7915_dma_reset() when reset happens
Ryder Lee [Tue, 13 Apr 2021 07:26:20 +0000 (15:26 +0800)]
mt76: mt7915: only free skbs after mt7915_dma_reset() when reset happens

In mt7915_mac_reset_work(), make sure freeing skbs after mt7915_dma_reset().

Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: fix memleak when mt7915_unregister_device()
Ryder Lee [Tue, 13 Apr 2021 05:34:57 +0000 (13:34 +0800)]
mt76: mt7915: fix memleak when mt7915_unregister_device()

mt7915_tx_token_put() should get call before mt76_free_pending_txwi().

Fixes: f285dfb98562 ("mt76: mt7915: reset token when mac_reset happens")
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7615: fix memleak when mt7615_unregister_device()
Ryder Lee [Tue, 13 Apr 2021 05:34:56 +0000 (13:34 +0800)]
mt76: mt7615: fix memleak when mt7615_unregister_device()

mt7615_tx_token_put() should get call before mt76_free_pending_txwi().

Fixes: a6275e934605 ("mt76: mt7615: reset token when mac_reset happens")
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: fix rate setting of tx descriptor in testmode
Shayne Chen [Mon, 12 Apr 2021 05:39:54 +0000 (13:39 +0800)]
mt76: mt7915: fix rate setting of tx descriptor in testmode

Fix ofdm rate index and ldpc setting in rate setting field of tx
descriptor.

Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: mt7915: rework mt7915_tm_set_tx_len()
Shayne Chen [Mon, 12 Apr 2021 05:39:53 +0000 (13:39 +0800)]
mt76: mt7915: rework mt7915_tm_set_tx_len()

Rework mt7915_tm_set_tx_len() with mt76_testmode_alloc_skb() to support
larger packet based on a longer tx_time.

Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agomt76: testmode: add support to send larger packet
Shayne Chen [Mon, 12 Apr 2021 05:39:52 +0000 (13:39 +0800)]
mt76: testmode: add support to send larger packet

Add support to send larger packet in testmode to meet requirements
of some test cases.
The limit of max packet size is determined based on tx rate mode setting.

Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
3 years agortlwifi: implement set_tim by update beacon content
Ping-Ke Shih [Mon, 19 Apr 2021 06:59:56 +0000 (14:59 +0800)]
rtlwifi: implement set_tim by update beacon content

Once beacon content is changed, we update the content to wifi card by
send_beacon_frame(). Then, STA with PS can wake up properly to receive its
packets.

Since we update beacon content to PCI wifi devices every beacon interval,
the only one usb device, 8192CU, needs to update beacon content when
mac80211 calling set_tim.

Reported-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Tested-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210419065956.6085-1-pkshih@realtek.com
3 years agolibertas_tf: Remove duplicate struct declaration
Wan Jiabing [Wed, 31 Mar 2021 02:35:52 +0000 (10:35 +0800)]
libertas_tf: Remove duplicate struct declaration

struct lbtf_private is declared twice. One has been declared
at 157th line. Remove the duplicate.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210331023557.2804128-4-wanjiabing@vivo.com
3 years agortw88: refine napi deinit flow
Po-Hao Huang [Thu, 15 Apr 2021 08:47:03 +0000 (16:47 +0800)]
rtw88: refine napi deinit flow

We used to stop napi before disabling irqs. And it turns out
to cause some problem when we try to stop device while interrupt arrives.

To safely stop pci, we do three steps:
1. disable interrupt
2. synchronize_irq
3. stop_napi
Since step 2 and 3 may not finish as expected when interrupt is enabled,
use rtwpci->running to decide whether interrupt should be re-enabled at
the time.

Fixes: 9e2fd29864c5 ("rtw88: add napi support")
Signed-off-by: Po-Hao Huang <phhuang@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210415084703.27255-4-pkshih@realtek.com
3 years agortw88: Fix potential unrecoverable tx queue stop
Yu-Yen Ting [Thu, 15 Apr 2021 08:47:02 +0000 (16:47 +0800)]
rtw88: Fix potential unrecoverable tx queue stop

If there are lots of packets to be transmitted, the driver would check
whether the available descriptors are sufficient according the read/write
point of tx queue. Once the available descriptor is not enough,
ieee80211_stop_queue is called.

TX ISR, meanwhile, is releasing the tx resources after the packets are
transmitted. This routine may call ieee80211_wake_queue by checking the
available descriptor.

The potential queue stop problem would occur when the tx queue is
stopped due to the heavy traffic. Then thare is no chance to wake the
queue up because the read point is not updated immediately, as a result,
no more packets coulde be transmitted in this queue.

This patch makes sure the ieee80211_wake_queue could be called properly
and avoids the race condition when ring->r.rp, ring->queue_stopped are
updated.

Signed-off-by: Yu-Yen Ting <steventing@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210415084703.27255-3-pkshih@realtek.com
3 years agortw88: 8821c: Don't set RX_FLAG_DECRYPTED if packet has no encryption
Guo-Feng Fan [Thu, 15 Apr 2021 08:47:01 +0000 (16:47 +0800)]
rtw88: 8821c: Don't set RX_FLAG_DECRYPTED if packet has no encryption

The value of GET_RX_DESC_SWDEC() indicates that if this RX
packet requires software decryption or not. And software
decryption is required when the packet was encrypted and the
hardware failed to decrypt it.

So, GET_RX_DESC_SWDEC() is negative does not mean that this
packet is decrypted, it might just have no encryption at all.
To actually see if the packet is decrypted, driver needs to
further check if the hardware has successfully decrypted it,
with a specific type of encryption algorithm.

Signed-off-by: Guo-Feng Fan <vincent_fann@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210415084703.27255-2-pkshih@realtek.com
3 years agortw88: 8822c: debug: allow debugfs to enable/disable TXGAPK
Guo-Feng Fan [Mon, 19 Apr 2021 00:37:48 +0000 (08:37 +0800)]
rtw88: 8822c: debug: allow debugfs to enable/disable TXGAPK

Use "cat dm_cap" to show all features; where, prefix +/- means feature is
enabled/disabled:

$ cat dm_cap
DM capability 0x00000002
( 1) +TXGAPK

To control dm_cap:
use "echo +1 > dm_cap" to enable TXGAPK
use "echo -1 > dm_cap" to disable TXGAPK

Below is an example to disable TXGAPK.

$ echo -1 > dm_cap
$ cat dm_cap
DM capability 0x00000000
( 1) -TXGAPK

Below is an example to show TXGAPK status
$ echo 1 > dm_cap; cat dm_cap

( 1) +TXGAPK

path 0:
0x56 = 0x88c89
[TXGAPK] offset 1 0
[TXGAPK] offset 1 1
[TXGAPK] offset 1 2
[TXGAPK] offset 1 3
[TXGAPK] offset 0 4
[TXGAPK] offset 0 5
[TXGAPK] offset 0 6
[TXGAPK] offset 0 7
[TXGAPK] offset 0 8
[TXGAPK] offset 0 9

path 1:
0x56 = 0x89c89
[TXGAPK] offset 1 0
[TXGAPK] offset 1 1
[TXGAPK] offset 1 2
[TXGAPK] offset 1 3
[TXGAPK] offset 0 4
[TXGAPK] offset 0 5
[TXGAPK] offset 0 6
[TXGAPK] offset 0 7
[TXGAPK] offset 0 8
[TXGAPK] offset 0 9

Signed-off-by: Guo-Feng Fan <vincent_fann@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210419003748.3224-4-pkshih@realtek.com
3 years agortw88: 8822c: Add gap-k calibration to improve long range performance
Guo-Feng Fan [Mon, 19 Apr 2021 00:37:47 +0000 (08:37 +0800)]
rtw88: 8822c: Add gap-k calibration to improve long range performance

gap-k is a calibration mechanism to eliminate power gaps between
two nearly rate groups.

This mechanism improves performance in long range test by applying
proper power value to those rate groups which have nonlinear power gap.

Signed-off-by: Guo-Feng Fan <vincent_fann@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210419003748.3224-3-pkshih@realtek.com
3 years agortw88: 8822c: reorder macro position according to the register number
Guo-Feng Fan [Mon, 19 Apr 2021 00:37:46 +0000 (08:37 +0800)]
rtw88: 8822c: reorder macro position according to the register number

This patch doesn't change logic at all, just a refactor patch.

1. Move BIT MASK and BIT definition along with the register definition
2. Remove redundant definition
3. Align macros with Tab key

Signed-off-by: Guo-Feng Fan <vincent_fann@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210419003748.3224-2-pkshih@realtek.com
3 years agonet: wwan: mhi_wwan_ctrl: Fix RX buffer starvation
Loic Poulain [Tue, 20 Apr 2021 09:36:22 +0000 (11:36 +0200)]
net: wwan: mhi_wwan_ctrl: Fix RX buffer starvation

The mhi_wwan_rx_budget_dec function is supposed to return true if
RX buffer budget has been successfully decremented, allowing to queue
a new RX buffer for transfer. However the current implementation is
broken when RX budget is '1', in which case budget is decremented but
false is returned, preventing to requeue one buffer, and leading to
RX buffer starvation.

Fixes: fa588eba632d ("net: Add Qcom WWAN control driver")
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: phy: at803x: fix probe error if copper page is selected
Michael Walle [Tue, 20 Apr 2021 10:29:29 +0000 (12:29 +0200)]
net: phy: at803x: fix probe error if copper page is selected

The commit c329e5afb42f ("net: phy: at803x: select correct page on
config init") selects the copper page during probe. This fails if the
copper page was already selected. In this case, the value of the copper
page (which is 1) is propagated through phy_restore_page() and is
finally returned for at803x_probe(). Fix it, by just using the
at803x_page_write() directly.

Also in case of an error, the regulator is not disabled and leads to a
WARN_ON() when the probe fails. This couldn't happen before, because
at803x_parse_dt() was the last call in at803x_probe(). It is hard to
see, that the parse_dt() actually enables the regulator. Thus move the
regulator_enable() to the probe function and undo it in case of an
error.

Fixes: c329e5afb42f ("net: phy: at803x: select correct page on config init")
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: David Bauer <mail@david-bauer.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: mana: remove redundant initialization of variable err
Colin Ian King [Tue, 20 Apr 2021 12:27:30 +0000 (13:27 +0100)]
net: mana: remove redundant initialization of variable err

The variable err is being initialized with a value that is
never read and it is being updated later with a new value.  The
initialization is redundant and can be removed

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agovirtio-net: fix use-after-free in page_to_skb()
Eric Dumazet [Tue, 20 Apr 2021 09:43:41 +0000 (02:43 -0700)]
virtio-net: fix use-after-free in page_to_skb()

KASAN/syzbot had 4 reports, one of them being:

BUG: KASAN: slab-out-of-bounds in memcpy include/linux/fortify-string.h:191 [inline]
BUG: KASAN: slab-out-of-bounds in page_to_skb+0x5cf/0xb70 drivers/net/virtio_net.c:480
Read of size 12 at addr ffff888014a5f800 by task systemd-udevd/8445

CPU: 0 PID: 8445 Comm: systemd-udevd Not tainted 5.12.0-rc8-next-20210419-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 <IRQ>
 __dump_stack lib/dump_stack.c:79 [inline]
 dump_stack+0x141/0x1d7 lib/dump_stack.c:120
 print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:233
 __kasan_report mm/kasan/report.c:419 [inline]
 kasan_report.cold+0x7c/0xd8 mm/kasan/report.c:436
 check_region_inline mm/kasan/generic.c:180 [inline]
 kasan_check_range+0x13d/0x180 mm/kasan/generic.c:186
 memcpy+0x20/0x60 mm/kasan/shadow.c:65
 memcpy include/linux/fortify-string.h:191 [inline]
 page_to_skb+0x5cf/0xb70 drivers/net/virtio_net.c:480
 receive_mergeable drivers/net/virtio_net.c:1009 [inline]
 receive_buf+0x2bc0/0x6250 drivers/net/virtio_net.c:1119
 virtnet_receive drivers/net/virtio_net.c:1411 [inline]
 virtnet_poll+0x568/0x10b0 drivers/net/virtio_net.c:1516
 __napi_poll+0xaf/0x440 net/core/dev.c:6962
 napi_poll net/core/dev.c:7029 [inline]
 net_rx_action+0x801/0xb40 net/core/dev.c:7116
 __do_softirq+0x29b/0x9fe kernel/softirq.c:559
 invoke_softirq kernel/softirq.c:433 [inline]
 __irq_exit_rcu+0x136/0x200 kernel/softirq.c:637
 irq_exit_rcu+0x5/0x20 kernel/softirq.c:649
 common_interrupt+0xa4/0xd0 arch/x86/kernel/irq.c:240

Fixes: fb32856b16ad ("virtio-net: page_to_skb() use build_skb when there's sufficient tailroom")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Reported-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agophy: nxp-c45-tja11xx: fix phase offset calculation
Radu Pirea (NXP OSS) [Tue, 20 Apr 2021 13:11:33 +0000 (16:11 +0300)]
phy: nxp-c45-tja11xx: fix phase offset calculation

Fix phase offset calculation.

Signed-off-by: Radu Pirea (NXP OSS) <radu-nicolae.pirea@oss.nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: enetc: automatically select IERB module
Michael Walle [Tue, 20 Apr 2021 14:28:21 +0000 (16:28 +0200)]
net: enetc: automatically select IERB module

Now that enetc supports flow control we have to make sure the settings in
the IERB are correct. Therefore, we actually depend on the enetc-ierb
module. Previously it was possible that this module was disabled while the
enetc was enabled. Fix it by automatically select the enetc-ierb module.

Fixes: e7d48e5fbf30 ("net: enetc: add a mini driver for the Integrated Endpoint Register Block")
Signed-off-by: Michael Walle <michael@walle.cc>
Acked-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agovirtio-net: restrict build_skb() use to some arches
Eric Dumazet [Tue, 20 Apr 2021 20:01:44 +0000 (13:01 -0700)]
virtio-net: restrict build_skb() use to some arches

build_skb() is supposed to be followed by
skb_reserve(skb, NET_IP_ALIGN), so that IP headers are word-aligned.
(Best practice is to reserve NET_IP_ALIGN+NET_SKB_PAD, but the NET_SKB_PAD
part is only a performance optimization if tunnel encaps are added.)

Unfortunately virtio_net has not provisioned this reserve.
We can only use build_skb() for arches where NET_IP_ALIGN == 0

We might refine this later, with enough testing.

Fixes: fb32856b16ad ("virtio-net: page_to_skb() use build_skb when there's sufficient tailroom")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: wwan: Fix bit ops double shift
Loic Poulain [Tue, 20 Apr 2021 19:09:57 +0000 (21:09 +0200)]
net: wwan: Fix bit ops double shift

bit operation helpers such as test_bit, clear_bit, etc take bit
position as parameter and not value. Current usage causes double
shift => BIT(BIT(0)). Fix that in wwan_core and mhi_wwan_ctrl.

Fixes: 9a44c1cc6388 ("net: Add a WWAN subsystem")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agoMerge branch 'dsa-tag-override'
David S. Miller [Tue, 20 Apr 2021 23:51:20 +0000 (16:51 -0700)]
Merge branch 'dsa-tag-override'

Tobias Waldekranz says:

====================
net: dsa: Allow default tag protocol to be overridden from DT

This is a continuation of the work started in this patch:
https://lore.kernel.org/netdev/20210323102326.3677940-1-tobias@waldekranz.com/

In addition to the mv88e6xxx support to dynamically change the
protocol, it is now possible to override the protocol from the device
tree. This means that when a board vendor finds an incompatibility,
they can specify a working protocol in the DT, and users will not have
to worry about it.

Some background information:

In a system using an NXP T1023 SoC connected to a 6390X switch, we
noticed that TO_CPU frames where not reaching the CPU. This only
happened on hardware port 8. Looking at the DSA master interface
(dpaa-ethernet) we could see that an Rx error counter was bumped at
the same rate. The logs indicated a parser error.

It just so happens that a TO_CPU coming in on device 0, port 8, will
result in the first two bytes of the DSA tag being one of:

00 40
00 44
00 46

My guess was that since these values looked like 802.3 length fields,
the controller's parser would signal an error if the frame length did
not match what was in the header.

This was later confirmed using two different workarounds provided by
Vladimir. Unfortunately these either bypass or ignore the hardware
parser and thus robs working combinations of the ability to do RSS and
other nifty things. It was therefore decided to go with the option of
a DT override.

v1 -> v2:
  - Fail if the device does not support changing protocols instead of
    falling back to the default. (Andrew)
  - Only call change_tag_protocol on CPU ports. (Andrew/Vladimir)
  - Only allow changing the protocol on chips that have at least
    "undocumented" level of support for EDSA. (Andrew).
  - List the supported protocols in the binding documentation. I opted
    for only listing the protocols that I have tested. As more people
    test their drivers, they can add them. (Rob)

v2 -> v3:
  - Rename "dsa,tag-protocol" -> "dsa-tag-protocol". (Rob)
  - Some cleanups to 4/5. (Vladimir)
  - Add a comment detailing how tree/driver agreement on the tag
    protocol is enforced. (Vladimir).
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agodt-bindings: net: dsa: Document dsa-tag-protocol property
Tobias Waldekranz [Tue, 20 Apr 2021 18:53:11 +0000 (20:53 +0200)]
dt-bindings: net: dsa: Document dsa-tag-protocol property

The 'dsa-tag-protocol' is used to force a switch tree to use a
particular tag protocol, typically because the Ethernet controller
that it is connected to is not compatible with the default one.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: dsa: Allow default tag protocol to be overridden from DT
Tobias Waldekranz [Tue, 20 Apr 2021 18:53:10 +0000 (20:53 +0200)]
net: dsa: Allow default tag protocol to be overridden from DT

Some combinations of tag protocols and Ethernet controllers are
incompatible, and it is hard for the driver to keep track of these.

Therefore, allow the device tree author (typically the board vendor)
to inform the driver of this fact by selecting an alternate protocol
that is known to work.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: dsa: Only notify CPU ports of changes to the tag protocol
Tobias Waldekranz [Tue, 20 Apr 2021 18:53:09 +0000 (20:53 +0200)]
net: dsa: Only notify CPU ports of changes to the tag protocol

Previously DSA ports were also included, on the assumption that the
protocol used by the CPU port had to the matched throughout the entire
tree.

As there is not yet any consumer in need of this, drop the call.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: dsa: mv88e6xxx: Allow dynamic reconfiguration of tag protocol
Tobias Waldekranz [Tue, 20 Apr 2021 18:53:08 +0000 (20:53 +0200)]
net: dsa: mv88e6xxx: Allow dynamic reconfiguration of tag protocol

For devices that supports both regular and Ethertyped DSA tags, allow
the user to change the protocol.

Additionally, because there are ethernet controllers that do not
handle regular DSA tags in all cases, also allow the protocol to be
changed on devices with undocumented support for EDSA. But, in those
cases, make sure to log the fact that an undocumented feature has been
enabled.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agonet: dsa: mv88e6xxx: Mark chips with undocumented EDSA tag support
Tobias Waldekranz [Tue, 20 Apr 2021 18:53:07 +0000 (20:53 +0200)]
net: dsa: mv88e6xxx: Mark chips with undocumented EDSA tag support

All devices are capable of using regular DSA tags. Support for
Ethertyped DSA tags sort into three categories:

1. No support. Older chips fall into this category.

2. Full support. Datasheet explicitly supports configuring the CPU
   port to receive FORWARDs with a DSA tag.

3. Undocumented support. Datasheet lists the configuration from
   category 2 as "reserved for future use", but does empirically
   behave like a category 2 device.

So, instead of listing the one true protocol that should be used by a
particular chip, specify the level of support for EDSA (support for
regular DSA is implicit on all chips). As before, we use EDSA for all
chips that fully supports it.

In upcoming changes, we will use this information to support
dynamically changing the tag protocol.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agoMerge tag 'mac80211-next-for-net-next-2021-04-20' of git://git.kernel.org/pub/scm...
David S. Miller [Tue, 20 Apr 2021 23:44:04 +0000 (16:44 -0700)]
Merge tag 'mac80211-next-for-net-next-2021-04-20' of git://git./linux/kernel/git/jberg/mac80211-next

Johannes Berg says:

====================
Another set of updates, all over the map:
 * set sk_pacing_shift for 802.3->802.11 encap offload
 * some monitor support for 802.11->802.3 decap offload
 * HE (802.11ax) spec updates
 * userspace API for TDLS HE support
 * along with various other small features, cleanups and
   fixups
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agoMerge branch 'mlxsw-refactor-qdisc-offload'
David S. Miller [Tue, 20 Apr 2021 23:43:13 +0000 (16:43 -0700)]
Merge branch 'mlxsw-refactor-qdisc-offload'

Petr Machata says:

====================
mlxsw: Refactor qdisc offload

Currently, mlxsw admits for offload a suitable root qdisc, and its
children. Thus up to two levels of hierarchy are offloaded. Often, this is
enough: one can configure TCs with RED and TCs with a shaper, and can even
see counters for each TC by looking at a qdisc at a sufficiently shallow
position.

While simple, the system has obvious shortcomings. It is not possible to
configure both RED and shaping on one TC. It is not possible to place a
PRIO below root TBF, which would then be offloaded as port shaper. FIFOs
are only offloaded at root or directly below, which is confusing to users,
because RED and TBF of course have their own FIFO.

This patchset is a step towards the end goal of allowing more comprehensive
qdisc tree offload and cleans up the qdisc offload code.

- Patches #1-#4 contain small cleanups.

- Up until now, since mlxsw offloaded only a very simple qdisc
  configurations, basically all bookkeeping was done using one container
  for the root qdisc, and 8 containers for its children. Patches #5, #6, #8
  and #9 gradually introduce a more dynamic structure, where parent-child
  relationships are tracked directly at qdiscs, instead of being implicit.

- This tree management assumes only one qdisc is created at a time. In FIFO
  handlers, this condition was enforced simply by asserting RTNL lock. But
  instead of furthering this RTNL dependence, patch #7 converts the whole
  qdisc offload logic to a per-port mutex.

- Patch #10 adds a selftest.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agoselftests: mlxsw: sch_red_ets: Test proper counter cleaning in ETS
Petr Machata [Tue, 20 Apr 2021 14:53:48 +0000 (16:53 +0200)]
selftests: mlxsw: sch_red_ets: Test proper counter cleaning in ETS

There was a bug introduced during the rework which cause non-zero backlog
being stuck at ETS. Introduce a selftest that would have caught the issue
earlier.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agomlxsw: spectrum_qdisc: Index future FIFOs by band number
Petr Machata [Tue, 20 Apr 2021 14:53:47 +0000 (16:53 +0200)]
mlxsw: spectrum_qdisc: Index future FIFOs by band number

mlxsw used to hold an array of qdiscs indexed by the TC number. In the
previous patch, it was changed to allocate child qdiscs dynamically, and
they are now indexed by band number. Follow suit with the array of future
FIFOs.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agomlxsw: spectrum_qdisc: Allocate child qdiscs dynamically
Petr Machata [Tue, 20 Apr 2021 14:53:46 +0000 (16:53 +0200)]
mlxsw: spectrum_qdisc: Allocate child qdiscs dynamically

Instead of keeping qdiscs in globally-preallocated arrays, introduce a
per-qdisc-kind value num_classes, and then allocate the necessary child
qdiscs (if any) based on that value. Since now dynamic allocation is
involved, mlxsw_sp_qdisc_replace() gets messy enough that it is worth it to
split it to two cases: a new qdisc allocation and a change of existing
qdisc. (Note that the change also includes what TC formally calls replace,
if the qdisc kind is the same.)

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
3 years agomlxsw: spectrum_qdisc: Guard all qdisc accesses with a lock
Petr Machata [Tue, 20 Apr 2021 14:53:45 +0000 (16:53 +0200)]
mlxsw: spectrum_qdisc: Guard all qdisc accesses with a lock

The FIFO handler currently guards accesses to the future FIFO tracking by
asserting RTNL. In the future, the changes to the qdisc state will be more
thorough, so other qdiscs will need this guarding is as well. In order
to not further the RTNL infestation, instead convert to a custom lock that
will guard accesses to the qdisc state.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>