Commit Graph
945 Commits
Author SHA1 Message Date
Lorenzo BianconiandFelix Fietkau 3d43146b66 mt76x0: usb: stop cal/mac workqueues at hw stop
Stop mac and calibration work stopping the hw even if the
device has been removed

Fixes: b11e19694dc9 ("mt76x0: add ieee80211_ops ops pointer to
mt76x0_alloc_device signature")

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-10-04 12:55:58 +02:00
Lorenzo BianconiandFelix Fietkau 6856ef62bf mt76: usb: fix hw initialization sequence
mt76u_alloc_queues need to be called before mt76u_mcu_init_rx
since it initializes rx_page_lock spinlock used in mt76u_buf_alloc
routine.

Fixes: b11e19694dc9 ("mt76x0: add ieee80211_ops ops pointer to
mt76x0_alloc_device signature")

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-10-04 12:55:58 +02:00
Stanislaw GruszkaandFelix Fietkau 05c7f24bfa mt76: fix frag length allocation for usb
This is correct fix for c12128ce44b0 ("mt76: use a per rx queue page
fragment cache"). We use wrong length when we allocate segments for
MCU transmissions, which require bigger segment size than e->buf_size.

Commit 481bb0432414 ("mt76: usb: make rx page_frag_cache access atomic")
partially solved the problem or actually mask it by changing
mt76u_mcu_init_rx() and mt76u_alloc_queues() sequence, so e->buf_size
become non zero any longer, but still not big enough to handle MCU data.

Patch fixes memory corruption which can manifest itself as random,
not easy to reproduce crashes, during mt76 driver load or unload.

Fixes: c12128ce44b0 ("mt76: use a per rx queue page fragment cache")
Signed-off-by: Stanislaw Gruszka <[email protected]>
Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-10-04 12:55:58 +02:00
Colin Ian KingandFelix Fietkau 6afb1b85a4 mt76: fix header guard macro define names
The header guards that are #defined are different from those being
checked.  Fix this by #defining them to the correct name.

Fixes clang warnings:
drivers/net/wireless/mediatek/mt76/mt76x02_mcu.h:17:9:
warning: '__MT76x02_MCU_H' is used as a header guard here, followed
by #define of a different macro [-Wheader-guard]

drivers/net/wireless/mediatek/mt76/mt76x02_usb.h:17:9:
warning: '__MT76x02_USB_H' is used as a header guard here, followed
by #define of a different macro [-Wheader-guard]

Fixes: 905db7470199 ("mt76: usb: move mt76x02 mcu code in mt76x02-usb module")
Fixes: edaa580bc830 ("mt76: move shared mcu_calibrate routine in mt76x02-lib module")
Signed-off-by: Colin Ian King <[email protected]>
2018-10-01 13:56:48 +02:00
Lorenzo BianconiandFelix Fietkau c6b192623f mt76x2: move mt76x2 source files to mt76x2 folder
Move mt76x2 and mt76x2u drivers to mt76x2 subfolder and
leave just shared code in mt76 root folder

Acked-by: Stanislaw Gruszka <[email protected]>
Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-10-01 13:54:56 +02:00
Lorenzo BianconiandFelix Fietkau 053de5c432 mt76x0: pci: add mt76x0e_cleanup routine
Add mt76x0e_cleanup routine to tidy up the device
during device removal

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-10-01 13:43:30 +02:00
Felix Fietkau 94d44458f1 mt76: mt76x2: fix multi-interface beacon configuration
If the first virtual interface is a station (or an AP with beacons
temporarily disabled), the beacon of the second interface needs to
occupy hardware beacon slot 0.
For some reason the beacon index was incorrectly masked with the
virtual interface beacon mask, which prevents the secondary
interface from sending beacons unless the first one also does.

Cc: [email protected]
Signed-off-by: Felix Fietkau <[email protected]>
2018-10-01 13:25:40 +02:00
Felix Fietkau 7464cc9710 mt76: check aggregation sequence number for frames sent via drv_tx
ps-poll response frames can be sent via drv_tx. Store the frame sequence number
for such frames, in case a BlockAckReq needs to be sent

Signed-off-by: Felix Fietkau <[email protected]>
2018-09-29 13:15:33 +02:00
Felix Fietkau 542f17edfc mt76: fix handling ps-poll frames
Hardware station lookup for pspoll frames can fail, which makes the driver
ignore ps-poll frames. Fix the resulting powersave issues by looking up
the station for pspoll frames in software

Signed-off-by: Felix Fietkau <[email protected]>
2018-09-29 13:13:10 +02:00
Felix Fietkau 14f70f4d28 mt7603: fix wcid for frames sent via drv_tx
pspoll responses can be sent via drv_tx, which may need to be encrypted

Signed-off-by: Felix Fietkau <[email protected]>
2018-09-29 13:11:45 +02:00
Felix Fietkau 62ce3245da move mt7603 source files to mt7603/
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-28 18:02:01 +02:00
Lorenzo BianconiandFelix Fietkau fb5bae06ef mt76x0: usb: move mt76x0u_tx_prepare_skb in usb.c
Move mt76x0u_tx_prepare_skb routine in usb module in
order to remove leftover usb dependency from generic code

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau b50f38acb3 mt76x0: eeprom: load eeprom data from mtd by default
Read eeprom data from mtd memory by default and fall-back
to efuse if it fails

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau c240904a31 mt76x0: pci: add mt76x0e_{start/stop} callbacks
Introduce mt76x0e_start and mt76x0e_stop mac80211
callbacks to start/stop device mac opening/closing
the netdevice

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 8050d714e8 mt76x0: add ieee80211_ops ops pointer to mt76x0_alloc_device signature
Add ieee80211_ops ops pointer to mt76x0_alloc_device routine signature
in order to specify mac80211 callbacks and remove usb dependency from
mt76x0 generic code.
Move mt76x0_ops callbacks in usb module in order to remove leftover
usb dependency in mt76x0 generic code.
Introduce mt76x0e_ops mac80211 callbacks for pci code

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 5d2a331f91 mt76: move set_{tx,rx}_path routines in mt76x02-lib module
Move mt76x02_phy_set_rxpath and mt76x02_phy_tx_dac routines in
mt76x02_phy.c since they are shared between mt76x2 and mt76x0 drivers.
Moreover move chainmask variable from mt76x2/mt76x0 to mt76_dev data
structure

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 15a50e1267 mt76x0: phy: set antenna parameter according to wireless band
Move mt76x0_ant_select routine in __mt76x0_phy_set_channel in order to
configure antenna parameters according to the current wireless channel

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 22be43e70d mt76x0: pci: add hw initialization at bootstrap
Add mt76x0e_register_device routine in pci.c
to initialize the device during hw probe.

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau da982d3ce6 mt76x0: usb: move initialization code in usb.c
Move usb initialization code in mt76x0-usb module in
order to remove usb dependency from generic init code
(not completed yet). Moreover fix a memory leak in usb probe
if mt76x02_wait_for_mac fails

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau fe1379a9f0 mt76: add mt76x02_mac_start routine
Introduce mt76x02_mac_start since the mac start code is shared between
mt76x0e and mt76x2 drivers.

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 5bb8339822 mt76x0: init rx filter in mt76x0_init_hardware
Initialize rxfilter mask at bootstrap an not at mac start.
This is a preliminary patch to share mt76x2_mac_start routine
between mt76x2e and mt76x0e drivers

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 94776fe14b mt76x0: init: remove MT_PBF_SYS_CTRL configuration in mt76x0_reset_csr_bbp
Remove MT_PBF_SYS_CTRL configuration in mt76x0_reset_csr_bbp since
it is already initialized in mt76x0_init_mac_registers routine

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 005d40af4f mt76x0: init: remove duplicated initialization
Remove MT_HEADER_TRANS_CTRL_REG/MT_TSO_CTRL configuration
since they are already initialized in mt76x0_init_mac_registers
routine

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau c7b28f49a7 mt76x0: use mt76x02 utility routines in mt76x0 init code
Use mt76x02_wait_for_wpdma and mt76x02_wait_for_txrx_idle
utility routines in mt76x0_init_hardware and mt76x0_mac_start
and remove duplicated code

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 886f6fc995 mt76x0: usb: move mcu code in usb_mcu.c
Move usb mcu code in a dedicated source file in order to remove
usb dependency from generic source files and improve code
maintainability

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau e1a21793e1 mt76x0: pci: move mcu code in pci_mcu.c
Move pci mcu code in a dedicated source file in order to
improve maintainability and facilitate new device support
development

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 7cc4be790b mt76x0: update initvals to latest version of vendor driver
Update mac/rf/dcoc initial values to latest version of vendor driver.
Improve code readability

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 47eee35f01 mt76: move mt76x2_wait_for_bbp in mt76x02-lib module
Move mt76x2_wait_for_bbp utility routine in mt76x02_util.h
in order to be resued by mt76x0 driver. Morover rename it in
mt76x02_wait_for_txrx_idle

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 5f1d0ff3d0 mt76: mmio: add implementation of wr_rp and rd_rp
Introduce mmio implementation of mt76_mmio_rd_rp and
mt76_mmio_wr_rp and remove mt76x2 duplicated code.
mt76_mmio_{wr,rd}_rp allows to reuse mt76x0 init code
adding mt76x0e support

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 5a29094532 mt76: move mt76x02_beacon_offset in mt76x02_util.c
Move mt76x02_beacon_offset utility routine in mt76x02-lib module
since it is shared between mt76x0 and mt76x2 driver and remove
duplicated code. Moreover move beacon_offset data structure in
mt76x02-lib module since it is shared between mt76x0 and mt76x2
drivers

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau 11e3028287 mt76: move queue initialization in mt76x02_mmio.c
Move mt76x02_dma_init, mt76x02_init_rx_queue and mt76x02_init_tx_queue
routines in mt76x02-lib module in order to be reused by mt76x0 driver

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:47:52 +02:00
Lorenzo BianconiandFelix Fietkau a8fda4b220 mt76: move mt76x02_set_irq_mask in mt76x02_mmio.c
Move mt76x02_set_irq_mask, mt76x02_irq_enable and mt76x02_irq_disable
in mt76x02-lib module in order to be reused by mt76x0 driver.
Moreover move irq_lock and irqmask in mt76_mmio data structure

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:45:26 +02:00
Lorenzo BianconiandFelix Fietkau 0527feb6f7 mt76: add mt76x02_dma_enable/mt76x02_dma_disable utility routines
Introduce mt76x02_dma_enable and mt76x02_dma_disable utility routines
in order to be reused in mt76x0 mac configuration and remove duplicated
code

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:45:26 +02:00
Lorenzo BianconiandFelix Fietkau 3a3554ad98 mt76: move wait_for_wpdma in mt76x02_dma.h
Move wait_for_wpdma utility routine in mt76x02_dma.h
in order to be reused by mt76x0 driver. Moreover add
the possibility to specify the timeout value in
wait_for_wpdma signature

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:45:08 +02:00
Lorenzo BianconiandFelix Fietkau b95bc8a75a mt76x0: use mt76_poll in mt76x0_set_wlan_state
Use mt76_poll utility routine in mt76x0_set_wlan_state to check
if the PLL/XTAL is ready

Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-28 13:45:08 +02:00
Felix Fietkau 41c552f13a mt76x0: work around cflags issue in compat layer for trace.h
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-28 13:03:29 +02:00
Felix Fietkau 6c3ee6bbd8 mt76x2: disable WLAN core before probe
If the WLAN core is still active during initialization, it might cause
the MCU or DMA to hang. This can happen during soft reboot, so disable
the core + clock early to avoid this issue.

Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Stanislaw GruszkaandFelix Fietkau 4112e1ca30 mt76x0: add quirk to disable 2.4GHz band for Archer T1U
TP-LINK Archer T1U do not support 2.4GHz band despite EEPROM
reports that. Add quirk to mask out 2.4GHz support.

Reported-by: Sid Hayn <[email protected]>
Signed-off-by: Stanislaw Gruszka <[email protected]>
2018-09-26 22:04:27 +02:00
Hauke MehrtensandFelix Fietkau bddaa9c449 mt76: use skb_pad() instead of __skb_pad()
mt76 uses __skb_pad() with free_on_error set to true, this is the same
as calling skb_pad().
This patch does not change any functionality, but it makes it easier to
backport this driver in backports, because skb_pad() is also available
in older kernel versions.

Fixes: b40b15e1521f ("mt76: add usb support to mt76 layer")
Signed-off-by: Hauke Mehrtens <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau 06b4b36049 mt76: usb: make rx page_frag_cache access atomic
Add rx_page_lock spinlock in order to make rx page fragment access
atomic. This patch fixes the following crash that occasionally
occurs during module loading/unloading

BUG: unable to handle kernel paging request at ffff9f8322e19000
PGD 27ba01067 P4D 27ba01067 PUD 27ddba063 PMD 263b35063 PTE 8000000262e19061
Oops: 0003 [#1] SMP PTI
CPU: 2 PID: 1766 Comm: systemd-udevd Not tainted 4.19.0-rc5+ #6
Hardware name: ASUSTeK COMPUTER INC. ESC2000 G2/Z9PE-D8 WS, BIOS 0405 03/19/2012
RIP: 0010:__memcpy+0x12/0x20
RSP: 0018:ffffba13849b3ad8 EFLAGS: 00010246
RAX: ffff9f8322e17004 RBX: 00000000000038f0 RCX: 000000000000031f
RDX: 0000000000000000 RSI: ffffba13844cf058 RDI: ffff9f8322e18ffc
RBP: 0000000000010c6c R08: 0000000000000000 R09: 0000607ec0000000
R10: 0000000000000003 R11: 0000000000003e2e R12: ffff9f8324cd9540
R13: 0000000000000000 R14: ffffba13849b3b30 R15: ffff9f8322e17000
FS:  00007fadec85b880(0000) GS:ffff9f833fa80000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffff9f8322e19000 CR3: 0000000263428001 CR4: 00000000000606e0
Call Trace:
 mt76x02u_mcu_fw_send_data+0x16c/0x270 [mt76x02_usb]
 mt76x0u_probe+0x35a/0x598 [mt76x0u]
 usb_probe_interface+0x113/0x310
 really_probe+0x1c8/0x400
 driver_probe_device+0x5c/0x130
 __driver_attach+0xec/0x110
 bus_for_each_dev+0x50/0x90
 bus_add_driver+0x1c0/0x280
 driver_register+0x5b/0xe0
 usb_register_driver+0x7c/0x140
 do_one_initcall+0x44/0x19b
 do_init_module+0x5a/0x210
 load_module+0x175c/0x1bc0
 __do_sys_finit_module+0x97/0xc0
 do_syscall_64+0x3f/0xf0
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x7fadeb6f1809
RSP: 002b:00007ffe548f9f38 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
RAX: ffffffffffffffda RBX: 00007fadebdf0d89 RCX: 00007fadeb6f1809
RDX: 0000000000000000 RSI: 00007fadebdf0d89 RDI: 0000000000000006
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000006 R11: 0000000000000246 R12: 0000560b9ef58ab0
R13: 0000560b9ef29800 R14: 0000560b9ef59040 R15: 0000000000020000

Fixes: c12128ce44b0 ("mt76: use a per rx queue page fragment cache")
Reported-by: Stanislaw Gruszka <[email protected]>
Tested-by: Stanislaw Gruszka <[email protected]>
Signed-off-by: Lorenzo Bianconi <[email protected]>
2018-09-26 22:04:27 +02:00
Davide CarattiandFelix Fietkau 4f346379b3 mt76: report firmware version using ethtool
print fw_ver and build_ver members of struct mt76x02_fw_header, similarly
to what appears in the output of 'dmesg' when the MCU firmware is loaded.

Reported-by: Sid Hayn <[email protected]>
Signed-off-by: Davide Caratti <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Felix Fietkau 8cd4ecfa0e mt76: include linux/module.h in files using MODULE_*
Fix source files using MODULE_* macros without including linux/module.h

Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau ac8c1db8b0 mt76x0: phy: introduce mt76x0_phy_set_txpower routine
Add mt76x0_phy_set_txpower routine in order to configure
base and per rate tx power gain. Moreover take into account
txpower_conf in order to limit the tx power gain according to
the bound provided by mac80211

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau 82248d9cfa mt76x0: use shared debugfs implementation
Use mt76 shared debugfs implementation and remove duplicated code
in mt76x0 driver

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau 9a0cf759f9 mt76x0: remove eeprom dependency from mt76x0_get_power_info
In order to unify eeprom parsing between mt76x0 and mt76x2 drivers,
remove eeprom pointer dependency from mt76x0_get_power_info routine.
Remove mt76x0_eeprom_params since it is now an empty structure

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau a8cba4623b mt76x0: remove eeprom dependency from mt76x0_set_tx_power_per_rate
In order to unify eeprom parsing between mt76x0 and mt76x2 drivers,
remove eeprom pointer dependency from mt76x0_set_tx_power_per_rate.
Moreover use mt76_rate_power to store power vs rate calibration data.

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau d1c23bc697 mt76x0: remove mt76x0_phy_set_tx_power and mt76x0_extra_power_over_mac
Remove mt76x0_extra_power_over_mac and mt76x0_phy_set_tx_power routines
since they are not actually used and tx power handling will be unified
with mt76x2 driver

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau f70a0fc51b mt76: move mt76x02_rate_power_val in mt76x02-lib module
Move mt76x02_rate_power_val and mt76x2_sign_extend_optional utility
routines in mt76x02_eeprom.h in order to reuse them in mt76x0 eeprom
parsing

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau 2fa0efe3ea mt76: move rate_txpower handler in mt76 debugfs
Move rate_txpower handler in mt76 debugfs in order to be reused
in mt76x0 driver and remove duplicated code

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00
Lorenzo BianconiandFelix Fietkau 2214aa5a24 mt76: add mt76x02_phy_set_txpower utility routine
Add mt76x02_phy_set_txpower utility routine in mt76x02_phy.c
in order to be reused in mt76x0 tx power management code.
Moreover move following routines in mt76x02-lib module:
- mt76x02_tx_power_mask
- mt76x02_get_max_rate_power
- mt76x02_limit_rate_power
- mt76x02_add_rate_power_offset

Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
2018-09-26 22:04:27 +02:00