Commit graph

125 commits

Author SHA1 Message Date
Lorenzo Bianconi d704d16f20 mt76: usb: do not use sg buffers for mcu messages
Do not use scatter-gather buffers for mcu commands.
Introduce mt76u_buf_alloc and mt76u_buf_alloc_sg routines.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:55:53 +01:00
Lorenzo Bianconi 63a7de5dfb mt76: usb: move mt76u_check_sg in usb.c
Move mt76u_check_sg routine in usb.c and introduce sg_en variable
in mt76_usb in order to check if scatter-gather is supported by
mt76u layer

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:55:52 +01:00
Stanislaw Gruszka 5de4db8fcb mt76x02u: use usb_bulk_msg to upload firmware
We don't need to send firmware data asynchronously, much simpler is just
use synchronous usb_bulk_msg().

Tested-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:54:34 +01:00
Lorenzo Bianconi c0f7b25ab8 mt76: move alloc_device common code in mt76_alloc_device
Move mt76x{0,2} alloc_device common code in mt76_alloc_device and
remove duplicated code

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:54:34 +01:00
Lorenzo Bianconi e6287c337c mt76: remove add_buf pointer in mt76_queue_ops
Remove add_buf function pointer in mt76_queue_ops data structure since
it is no longer used

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:54:33 +01:00
Lorenzo Bianconi 5ed3112878 mt76: move mt76_dma_tx_queue_skb_raw in mt76-core module
Move mt76_dma_tx_queue_skb_raw routine in dma.c and add the
corresponding entry in mt76_queue_ops data structure.
mt76_dma_tx_queue_skb_raw  will be reused adding support for
mt7603 driver

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:54:33 +01:00
Lorenzo Bianconi c07a49d475 mt76: move mt76_mcu_rx_event in mt76-core
Move mt76_mcu_rx_event i mt76-core module and remove duplicated code.
mt76_mcu_rx_event will be reused adding support for mt7603 driver

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:54:33 +01:00
Lorenzo Bianconi 680abb25f7 mt76: move mt76_mcu_get_response in mt76-core
Move mt76_mcu_get_response in mt76-core module and remove duplicated
code. mt76_mcu_get_response will be reused adding support for mt7603
driver

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:54:33 +01:00
Lorenzo Bianconi 9df0fab9d1 mt76: move mt76_mcu_msg_alloc in mt76-core
Move mt76_mcu_msg_alloc in mt76-core module and remove duplicated code.
mt76_mcu_msg_alloc will be reused adding support for mt7603 driver

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-02-18 19:54:33 +01:00
Felix Fietkau e7173858c7 mt76: add channel switch announcement support
Use the appropriate mac80211 callbacks after beacon transmission

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-01-17 14:50:15 +01:00
Felix Fietkau 9cf67ec7fd mt76: fix signedness of rx status signal field
It is usually negative, so it needs to be signed.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-01-17 14:50:15 +01:00
Felix Fietkau ef13edc007 mt76: move mt76x02_phy_get_min_avg_rssi to mt76 core
This will be used by mt7603 as well

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-01-17 14:50:15 +01:00
Felix Fietkau 9313faacbb mt76: move mt76x02_get_txpower to mt76 core
It will be reused by mt7603 later

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-01-17 14:50:15 +01:00
Felix Fietkau 013b2dff81 mt76: fix tx status reporting for non-probing frames
On MT76x2, the hardware does not report tx status in the FIFO register,
if the packet id is 0.
Change the allocation of packet IDs to use 0 for no-ack packets, 1 for
non-probing packets and 2-255 for packets with tx status requested.
Fixes rate control issues

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-01-17 14:44:57 +01:00
Lorenzo Bianconi c1e0d2be0a mt76: mmio: introduce mt76x02_check_tx_hang watchdog
Port mt76x02_check_tx_hang watchdog from vendor driver in order to
perform a device reset when tx mac/dma logic hangs. Tx mac/dma stuck
has been observed when the device is heavy loaded or in a noisy
environment. Moreover introduce wdt delayed work in order to run
tx_hang watchdog. For the moment run mt76x02_check_tx_hang watchdog
just on mt76x2 devices since the issue has not been observed on mt76x0
driver yet

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2019-01-11 15:10:19 +01:00
Felix Fietkau e28487ea84 mt76: replace sta_add/remove ops with common sta_state function
Allows adding unassociated stations from mac80211

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
2018-11-30 12:30:37 +01:00
Felix Fietkau 723b90dc7d mt76: add mt76_sta_remove helper
This allows station removal code to be used by mt7603 later

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-11-30 12:29:35 +01:00
Felix Fietkau 79d1c94c9c mt76: avoid queue/status spinlocks while passing tx status to mac80211
There is some code in the mac80211 tx status processing code that could
potentially call back into the tx codepath.
To avoid deadlocks, make sure that no tx related spinlocks are taken
during the ieee80211_tx_status call.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-11-30 12:29:32 +01:00
Stanislaw Gruszka a74d633609 mt76: remove mcu_msg_alloc
We almost always use patter like this:

       skb = mt76_mcu_msg_alloc(dev, &msg, sizeof(msg));
       return mt76_mcu_send_msg(dev, skb, CMD_FUN_SET_OP, wait_resp);

This is not needed, we can allocate skb in mcu_send_msg routine.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-11-30 12:21:43 +01:00
Felix Fietkau 88046b2c9f mt76: add support for reporting tx status with skb
MT76x2/MT76x0 has somewhat unreliable tx status reporting, and for that
reason the driver currently does not report per-skb tx ack status at all.
This breaks things like client idle polling, which relies on the tx ack
status of a transmitted nullfunc frame.

This patch adds code to report skb-attached tx status if requested by
mac80211 or the rate control module. Since tx status is polled from a
simple FIFO register, the code needs to account for the possibility of
tx status events getting lost.

The code keeps a list of skbs for which tx status is required and passes
them to mac80211 once tx status has been filled in and the DMA queue is
done with it.
If a tx status event is not received after one second, the status rates
are cleared, and a succesful ACK is indicated to avoid spurious disassoc
during assoc or client polling.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-11-30 12:21:42 +01:00
Felix Fietkau 5567b37359 mt76: clean up unused leftover EXPORT_SYMBOLs
Make previously exported functions static where possible

Acked-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-11-30 12:21:40 +01:00
Stanislaw Gruszka c50479fa7a mt76: allow to identify bus
Add helpers to identify bus type.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-13 17:39:11 +02:00
Lorenzo Bianconi a23fde09c2 mt76: use mt76x02_dev instead of mt76_dev in mt76x02_mmio.c
Use mt76x02_dev data structure as reference in mt76x02_mmio.c
instead of mt76_dev

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-05 20:05:46 +02:00
Lorenzo Bianconi 1ea0a1b12a mt76: move tpc routines in mt76x02-lib module
Move mt76x02_tx_get_txpwr_adj and mt76x02_tx_set_txpwr_auto routines
in mt76x02-lib module since they are shared between mt76x0 and mt76x2
drivers. Moreover remove get_txpwr_adj function pointer

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-05 20:05:46 +02:00
Lorenzo Bianconi 1ef3aa8893 mt76: add get_tx_txpwr_adj function pointer to mt76_driver_ops
Add get_tx_txpwr_adj function pointer to mt76_driver_ops data structure
as a preliminary patch to unify txwi configuration between mt76x0 and
mt76x2 drivers since tpc is currently supported just by mt76x2 driver

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-05 20:05:44 +02:00
Lorenzo Bianconi d697b00b15 mt76: move mt76x02_tx_get_max_txpwr_adj in mt76x02_util.c
Move mt76x02_tx_get_max_txpwr_adj routine in mt76x02-lib module
since now both mt76x0 and mt76x2 drivers read rate tx power gain from
rate_power data structure. Moreover remove get_max_txpwr_adj function
pointer from mt76_driver_ops data structure

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-05 20:05:44 +02:00
Lorenzo Bianconi 6034b2b07a 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 <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-01 12:34:39 +02:00
Lorenzo Bianconi b2eabd4c32 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 <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-01 12:34:22 +02:00
Lorenzo Bianconi 957068c23f 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 <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-01 12:34:21 +02:00
Lorenzo Bianconi 481bb04324 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: c12128ce44 ("mt76: use a per rx queue page fragment cache")
Reported-by: Stanislaw Gruszka <sgruszka@redhat.com>
Tested-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-01 12:34:12 +02:00
Lorenzo Bianconi b6862effdc mt76: move mt76_rate_power in mt76_dev
Move mt76_rate_power data structure from mt76x2_dev to mt76_dev in order
to share it with mt76x0 driver. Moreover move txpower_conf and
txpower_cur in mt76_dev

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-01 12:34:00 +02:00
Felix Fietkau 7c4b446c59 mt76: add stbc entries to mt76_rate_power
Add stbc tx power eeprom parsing support for mt76x2 driver.
When writing power entries, make a distinction between rates that are
read from the same EEPROM value, but have separate register entries.

No effect on runtime behavior, but preparation for unification with mt76x0
and for placing restrictions on individual rate power limits

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-01 12:33:40 +02:00
Lorenzo Bianconi 8f410a8bfd mt76: move seq_put_array in mt76-core module
Move seq_put_array utility routine in mt76-core module
in order to be reused in mt76x0 driver

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-10-01 12:33:38 +02:00
Felix Fietkau c12128ce44 mt76: use a per rx queue page fragment cache
Using the NAPI or netdev frag cache along with other drivers can lead to
32 KiB pages being held for a long time, despite only being used for
very few page fragments.

This can happen if the driver grabs one or two fragments for rx ring
refill, while other drivers use (and free up) the remaining fragments.
The 32 KiB higher-order page can only be freed once all users have freed
their fragments.

Depending on the traffic patterns, this can waste a lot of memory and
look a lot like a memory leak.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:44 +02:00
Lorenzo Bianconi 27db1ad10f mt76: move __iomem regs in mt76_mmio
Move __iomem regs pointer in mt76_mmio data structure

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:34 +02:00
Lorenzo Bianconi f7bbb80f22 mt76: introduce mmio data structure in mt76_dev
Introduce mt76_mmio data structure in mt76_dev and
move mt76x2_mcu in mt76_mmio. This is a preliminary
patch to unify mcu code between mt76x02{e,u} drivers

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:33 +02:00
Lorenzo Bianconi c2db13ac7b mt76: usb: move mt76u_skb_dma_info in mt76x02_usb_core.c
Move mt76u_skb_dma_info routine in mt76x02-usb module and rename it in
mt76x02u_skb_dma_info. Moreover move mt76x02u_set_txinfo in
mt76x02_usb_core.c. This is a preliminary patch to move MT_TXD_INFO,
MT_MCU_MSG and MT_RX_FCE_INFO defs in mt76x02-lib module since other
chipsets (e.g. mt7603) use different dma definitions

Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:24 +02:00
Lorenzo Bianconi 905db74701 mt76: usb: move mt76x02 mcu code in mt76x02-usb module
Introduce mt76x02_usb_mcu.c in order to contain mt76x02u mcu related
code. Add mt76x02-usb module as a container for mt76x02 usb code.
This is a preliminary patch to move MT_TXD_INFO, MT_MCU_MSG and
MT_RX_FCE_INFO defs in mt76x02-lib module since other chipsets (e.g.
mt7603) use different dma definitions

Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:23 +02:00
Lorenzo Bianconi 1750715726 mt76: usb: use common helpers for mcu_alloc_msg()/mcu_send_msg()
Use mcu common helpers instead of usb specific routines.
Add static qualifier to the following functions:
- mt76u_mcu_msg_alloc
- __mt76u_mcu_send_msg
- mt76u_mcu_send_msg
- mt76u_mcu_wr_rp
- mt76u_mcu_rd_rp
- mt76u_wr_rp
- mt76u_rd_rp
This is a preliminary patch to move mt76x02 usb mcu code in
mt76x02-usb module

Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:21 +02:00
Stanislaw Gruszka 6da5a29116 mt76: add rd_rp and wr_rp to bus_ops/mcu_ops
Add callbacks for reading and writing reg pairs tables.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:20 +02:00
Stanislaw Gruszka f1638c7cd6 mt76: add usb implementation of {wr,rd}_rp
Add USB implementation for read and write reg pair routines.
The actual implementation can use mcu related routines according to
MCU state

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:19 +02:00
Lorenzo Bianconi db0f04f324 mt76: add mt76_mcu_ops data structure for mcu related pointers
Introduce mt76_mcu_ops data structure to contain mcu related function
pointers. This is a preliminary patch to move mt76x02 usb mcu code in
mt76x02-usb module

Acked-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:31:18 +02:00
Lorenzo Bianconi 23ea0e7efb mt76: remove unused MT76_MORE_STATS state
Remove no longer used hw state

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:30:59 +02:00
Stanislaw Gruszka 82e1dd0f39 mt76: use mt76_rx_status in mt76x0
Make rx status processing similar to mt76x2.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:29:20 +02:00
Stanislaw Gruszka 5327b5ea13 mt76: unify sta_rate_tbl_update and related helpers
Use common sta_rate_tbl_update on mt76x0 and mt76x2.
mt76x0 do not have support TPC (transmision power control) implmented,
msta->wcid.max_txpwr_adj is only set for mt76x2.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:29:16 +02:00
Stanislaw Gruszka 1d0496c63f mt76: unify AC to hw queue mapping
Use the same AC to hardware queue mappings for all subdrivers.
Note: this change BK and BE mappings for USB drivers.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:29:10 +02:00
Stanislaw Gruszka 22c575c4f1 mt76: unify ampdu_action
Use mt76x2_ampdu_action as common function, mt76x0 ampdu_action was
diffrent, but mt76x2 version should work for this driver as well.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:29:07 +02:00
Stanislaw Gruszka 36404c065a mt76: move wcid fields to common mt76_dev struct
All current MT devices including new MT7603 type chips support 128
WCIDs, we can unify wcid data in common mt76_dev structure.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-09-19 12:28:45 +02:00
Lorenzo Bianconi 851ab66e29 mt76: add multiple regs read support to usb_mcu layer
Introduce multiple regs read support to mcu layer in mt76-usb module.
Multiple regs read will be reused by mt76x0 driver in usb mcu layer
unification between mt76x0 and mt76x2u drivers

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-09-04 11:08:49 +03:00
Lorenzo Bianconi 288d600a88 mt76: move mt76x2u_mcu_deinit routine in mt76-usb module
Move mt76x2u_mcu_deinit routine in usb_mcu layer in order to
be reused by mt76x0 driver in usb mcu layer unification between
mt76x0 and mt76x2u drivers

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-09-04 11:08:46 +03:00
Lorenzo Bianconi 4c89ff2c74 mt76: split __mt76u_mcu_send_msg and mt76u_mcu_send_msg routines
Split __mt76u_mcu_send_msg and mt76u_mcu_send_msg in order to be reused
by mt76x0 driver in usb mcu layer unification between mt76x0 and
mt76x2u drivers

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-09-04 11:08:42 +03:00
Lorenzo Bianconi 5090efa4a2 mt76: move mt76_reg_pair definition in mt76.h
Move common definition of mt76_reg_pair in mt76.h
and remove duplicated code in mt76x2_init_common.c

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-09-04 11:08:40 +03:00
Stanislaw Gruszka 46436b5ef9 mt76: unify mac_wcid_set_key
Merge mt76x{0,2}_mac_wcid_set_key into common code.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-09-04 11:02:57 +03:00
Stanislaw Gruszka d413127359 mt76: add helpers for register access with mt76_dev struct
Add helpers for register access from common code.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-09-04 11:02:53 +03:00
Stanislaw Gruszka 108a4861ef mt76: create new mt76x02-lib module for common mt76x{0,2} code
Move rxfilter and mutex to common structure. Create mt76x02-lib.ko
for mt76x0 and mt76x2 common functions and create new unified
mt76x02_configure_filter() function there.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-09-04 11:02:47 +03:00
Stanislaw Gruszka 87e022de33 mt76: add more states
Add states needed for mt76x0 driver.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-08-02 21:51:01 +03:00
Lorenzo Bianconi b40b15e152 mt76: add usb support to mt76 layer
This will be used by drivers for MT76x2u based devices

Tested-by: <cug_yangyuancong@hotmail.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-08-02 21:48:16 +03:00
Lorenzo Bianconi 469d481886 mt76: introduce tx_queue_skb function pointer in mt76_bus_ops
Add tx_queue_skb function pointer in mt76_bus_ops since mt76x2u based
devices do not map mt76x2_txwi on dma buffers and it is not possible
to reuse mt76_dma_tx_queue_skb() routine to enqueue tx frames to
hw buffers

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-08-02 21:48:02 +03:00
Lorenzo Bianconi fcdd99ce72 mt76: rename mt76_tx_queue_skb in mt76_dma_tx_queue_skb
Move mt76_dma_tx_queue_skb routine in dma.c.
Remove static qualifier from mt76_get_txwi definition

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-08-02 21:48:01 +03:00
Lorenzo Bianconi 81e850ef26 mt76x2: add napi struct to mt76_rx_poll_complete/mt76_rx_complete signatures
in order to reuse mt76_rx_complete routine supporting mt76x2u based
devices add napi struct to mt76_rx_poll_complete and mt76_rx_complete
routine signatures and do not fetch it according to the rx queue index

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-08-02 21:47:57 +03:00
Lorenzo Bianconi ee8aa945e4 mt76: introduce mt76_{incr,decr} utility routines
Add mt76_{incr,decr} utility routines to increment/decrement a value
with wrap-around (they will be used by mt76x2 DFS sw detector)

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-07-04 18:15:57 +03:00
Felix Fietkau 26e40d4c0b mt76: wait for pending tx to complete before switching channel
Reduces interruption caused by scanning

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-05-23 10:58:14 +03:00
Felix Fietkau a85b590cf5 mt76: move ieee80211_hw allocation to common core
Allows it to be shared between different drivers and locks to be
initialized earlier

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-05-23 10:58:13 +03:00
Felix Fietkau 89bc67e3a9 mt76: only stop tx queues on offchannel, not during the entire scan
During scans, mac80211 frequently switches back to the home channel to
minimize interruption of ongoing traffic. Keep regular tx queues active
during that time.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-05-23 10:58:09 +03:00
Felix Fietkau c3d7c82a8b mt76: fix concurrent rx calls on A-MPDU release
Add a spinlock in mt76_rx_complete. Without this, multiple stats updates
could happen in parallel, which can lead to deadlocks. There are
probably more corner cases fixed by this change.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-04-30 13:21:27 +03:00
Lorenzo Bianconi 5ebdc3e069 mt76x2: add mac80211 {set,get}_antenna callbacks
Add capability to select tx/rx antennas. Possible values are:
 - 1: to use only the first antenna
 - 2: to use only the second antenna
 - 3: to use both of them

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-03-13 18:32:01 +02:00
Lorenzo Bianconi 24114a5f94 mt76: initialize available_antennas_{tx,rx} info
Initialize available_antennas related info in wiphy data structure
according to antenna_mask field; antenna_mask info is initialized
in device specific code and will be used in mac80211 {set,get}_antenna
callbacks

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-03-13 18:32:00 +02:00
Felix Fietkau d71ef28636 mt76: implement AP_LINK_PS
With software A-MPDU reordering in place, frames that notify mac80211 of
powersave changes are reordered as well, which can cause connection
stalls. Fix this by implementing powersave state processing in the
driver.

Fixes: aee5b8cf24 ("mt76: implement A-MPDU rx reordering in the driver code")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-02-01 10:43:57 +02:00
Felix Fietkau 30ce7f4456 mt76: validate rx CCMP PN
Apparently hardware does not perform CCMP PN validation in hardware, so
we need to take care of this in the driver. This is important for
protecting against replay attacks.

Since validation of fragmented frames is more complex, the CCMP header
for those is preserved. To keep the counter in sync, the first fragment
is verified by both mt76 and mac80211, and all other fragments only by
mac80211.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-01-26 11:20:52 +02:00
Felix Fietkau 9d9d738b4b mt76: split mt76_rx_complete
Add a separate function for processing frames after A-MPDU reordering,
reduce code duplication

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-01-26 11:18:43 +02:00
Felix Fietkau aee5b8cf24 mt76: implement A-MPDU rx reordering in the driver code
This is required for performing CCMP PN validation in software

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-01-26 11:18:39 +02:00
Felix Fietkau 9c68a57bc2 mt76: get station pointer by wcid and pass it to mac80211
Avoids the rhashtable lookup based on the MAC address inside mac80211

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-01-26 11:18:34 +02:00
Felix Fietkau 4e34249e95 mt76: add an intermediate struct for rx status information
Preparation for passing in more internal rx data via skb->cb

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-01-26 11:18:32 +02:00
Felix Fietkau 2340523646 mt76: fix transmission of encrypted management frames
Hardware encryption seems to break encrypted unicast mgmt tx.
Unfortunately the hardware TXWI header does not have a bit to indicate
that a frame is software encrypted, so sw-encrypted frames need to use a
different WCID. For that to work, the CCMP PN needs to be generated in
software, which makes things a bit slower, so only do it for keys that
also need to tx management frames.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2018-01-24 17:12:40 +02:00
Felix Fietkau 17f1de56df mt76: add common code shared between multiple chipsets
This will be used by drivers for MT76x2e, MT7603e and MT7628

Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
2017-12-07 15:35:55 +02:00