mirror of
https://github.com/outbackdingo/mt76.git
synced 2026-10-24 21:36:52 +00:00
In mt76_wed_init_rx_buf, it's hardcoded to use MT_RXQ_MAIN. But for non-DBDC MT7986 MT_RXQ_BAND1 is used for RX data queue which leads to kernel panic when attaching WED. Use the correct RX queue by checking WED version and band_idx. v2 and band 1 -> MT_RXQ_BAND1 Others -> MT_RXQ_MAIN Kernel panic: Unable to handle kernel access to user memory outside uaccess routines at virtual address 0000000000000000 Mem abort info: ESR = 0x0000000096000005 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 FSC = 0x05: level 1 translation fault Data abort info: ISV = 0, ISS = 0x00000005, ISS2 = 0x00000000 CM = 0, WnR = 0, TnD = 0, TagAccess = 0 GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 Internal error: Oops: 0000000096000005 [#1] SMP CPU: 1 UID: 0 PID: 925 Comm: kmodloader Tainted: G O 6.18.26 #0 NONE Tainted: [O]=OOT_MODULE Hardware name: Acer Connect Vero W6m (DT) pstate: 40400005 (nZcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : page_pool_alloc_frag_netmem+0x1c/0x1bc lr : page_pool_alloc_frag+0xc/0x34 sp : ffffffc081dab660 x29: ffffffc081dab660 x28: ffffffc081dabc60 x27: ffffff80091af040 x26: 0000008000000000 x25: ffffff80091a8898 x24: ffffff80091a5440 x23: 0000000000001000 x22: 0000000140000000 x21: ffffff80091a2040 x20: ffffff8003f1d780 x19: 0000000000000000 x18: 0000000000000020 x17: ffffffbfbf0ac000 x16: ffffffc080ee0000 x15: ffffff80049d47ca x14: 000000000000037b x13: 000000000000037b x12: 0000000000000001 x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000 x8 : ffffff8003f1d7c0 x7 : 0000000000000000 x6 : ffffff8003f1d780 x5 : 0000000000000680 x4 : 0000000000000000 x3 : 0000000000002824 x2 : 0000000000000000 x1 : ffffffc081dab71c x0 : 0000000000000000 Call trace: page_pool_alloc_frag_netmem+0x1c/0x1bc (P) page_pool_alloc_frag+0xc/0x34 mt76_wed_init_rx_buf+0xf8/0x2ac [mt76] mtk_wed_start+0x79c/0x12ac mt7915_dma_start+0x274/0x63c [mt7915e] mt7915_dma_start+0x5b4/0x63c [mt7915e] mt7915_dma_init+0x49c/0x81c [mt7915e] mt7915_register_device+0x24c/0x530 [mt7915e] mt7915_mmio_probe+0x91c/0x1980 [mt7915e] platform_probe+0x58/0xa0 really_probe+0xb8/0x2a8 __driver_probe_device+0x74/0x118 driver_probe_device+0x3c/0xe0 __driver_attach+0x88/0x154 bus_for_each_dev+0x60/0xb0 driver_attach+0x20/0x28 bus_add_driver+0xdc/0x200 driver_register+0x64/0x118 __platform_driver_register+0x20/0x30 init_module+0x74/0x1000 [mt7915e] do_one_initcall+0x4c/0x1f8 do_init_module+0x50/0x210 load_module+0x15f8/0x1b10 __do_sys_init_module+0x1a8/0x260 __arm64_sys_init_module+0x18/0x20 invoke_syscall.constprop.0+0x4c/0xd0 do_el0_svc+0x3c/0xd0 el0_svc+0x18/0x60 el0t_64_sync_handler+0x98/0xdc el0t_64_sync+0x158/0x15c Code: aa0003f3 a9025bf5 a90363f7 d2820017 (b9400000) Signed-off-by: Zhi-Jun You <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Felix Fietkau <[email protected]>
215 lines
5.0 KiB
C
215 lines
5.0 KiB
C
// SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
/*
|
|
* Copyright (C) 2023 Lorenzo Bianconi <[email protected]>
|
|
*/
|
|
|
|
#include "mt76.h"
|
|
#include "dma.h"
|
|
|
|
void mt76_wed_release_rx_buf(struct mtk_wed_device *wed)
|
|
{
|
|
struct mt76_dev *dev = mt76_wed_to_dev(wed);
|
|
int i;
|
|
|
|
for (i = 0; i < dev->rx_token_size; i++) {
|
|
struct mt76_txwi_cache *t;
|
|
|
|
t = mt76_rx_token_release(dev, i);
|
|
if (!t || !t->ptr)
|
|
continue;
|
|
|
|
mt76_put_page_pool_buf(t->ptr, false);
|
|
t->ptr = NULL;
|
|
|
|
mt76_put_rxwi(dev, t);
|
|
}
|
|
|
|
mt76_free_pending_rxwi(dev);
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_release_rx_buf);
|
|
|
|
#ifdef CONFIG_NET_MEDIATEK_SOC_WED
|
|
u32 mt76_wed_init_rx_buf(struct mtk_wed_device *wed, int size)
|
|
{
|
|
struct mtk_wed_bm_desc *desc = wed->rx_buf_ring.desc;
|
|
struct mt76_dev *dev = mt76_wed_to_dev(wed);
|
|
struct mt76_txwi_cache *t = NULL;
|
|
struct mt76_queue *q;
|
|
int i;
|
|
|
|
if (wed->version == 2 && dev->phy.band_idx)
|
|
q = &dev->q_rx[MT_RXQ_BAND1];
|
|
else
|
|
q = &dev->q_rx[MT_RXQ_MAIN];
|
|
|
|
for (i = 0; i < size; i++) {
|
|
dma_addr_t addr;
|
|
u32 offset;
|
|
int token;
|
|
void *buf;
|
|
|
|
t = mt76_get_rxwi(dev);
|
|
if (!t)
|
|
goto unmap;
|
|
|
|
buf = mt76_get_page_pool_buf(q, &offset, q->buf_size);
|
|
if (!buf)
|
|
goto unmap;
|
|
|
|
addr = page_pool_get_dma_addr(virt_to_head_page(buf)) + offset;
|
|
desc->buf0 = cpu_to_le32(addr);
|
|
token = mt76_rx_token_consume(dev, buf, t, addr);
|
|
if (token < 0) {
|
|
mt76_put_page_pool_buf(buf, false);
|
|
goto unmap;
|
|
}
|
|
|
|
token = FIELD_PREP(MT_DMA_CTL_TOKEN, token);
|
|
#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
|
|
token |= FIELD_PREP(MT_DMA_CTL_SDP0_H, addr >> 32);
|
|
#endif
|
|
desc->token |= cpu_to_le32(token);
|
|
desc++;
|
|
}
|
|
|
|
return 0;
|
|
|
|
unmap:
|
|
if (t)
|
|
mt76_put_rxwi(dev, t);
|
|
mt76_wed_release_rx_buf(wed);
|
|
|
|
return -ENOMEM;
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_init_rx_buf);
|
|
|
|
int mt76_wed_offload_enable(struct mtk_wed_device *wed)
|
|
{
|
|
struct mt76_dev *dev = mt76_wed_to_dev(wed);
|
|
|
|
spin_lock_bh(&dev->token_lock);
|
|
dev->token_size = wed->wlan.token_start;
|
|
spin_unlock_bh(&dev->token_lock);
|
|
|
|
return !wait_event_timeout(dev->tx_wait, !dev->wed_token_count, HZ);
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_offload_enable);
|
|
|
|
int mt76_wed_dma_setup(struct mt76_dev *dev, struct mt76_queue *q, bool reset)
|
|
{
|
|
int ret = 0, type, ring;
|
|
u16 flags;
|
|
|
|
if (!q || !q->ndesc)
|
|
return -EINVAL;
|
|
|
|
flags = q->flags;
|
|
if (!q->wed || !mtk_wed_device_active(q->wed))
|
|
q->flags &= ~MT_QFLAG_WED;
|
|
|
|
if (!(q->flags & MT_QFLAG_WED))
|
|
return 0;
|
|
|
|
type = FIELD_GET(MT_QFLAG_WED_TYPE, q->flags);
|
|
ring = FIELD_GET(MT_QFLAG_WED_RING, q->flags);
|
|
|
|
switch (type) {
|
|
case MT76_WED_Q_TX:
|
|
ret = mtk_wed_device_tx_ring_setup(q->wed, ring, q->regs,
|
|
reset);
|
|
if (!ret)
|
|
q->wed_regs = q->wed->tx_ring[ring].reg_base;
|
|
break;
|
|
case MT76_WED_Q_TXFREE:
|
|
/* WED txfree queue needs ring to be initialized before setup */
|
|
q->flags = 0;
|
|
mt76_dma_queue_reset(dev, q, true);
|
|
mt76_dma_rx_fill(dev, q, false);
|
|
|
|
ret = mtk_wed_device_txfree_ring_setup(q->wed, q->regs);
|
|
if (!ret)
|
|
q->wed_regs = q->wed->txfree_ring.reg_base;
|
|
break;
|
|
case MT76_WED_Q_RX:
|
|
ret = mtk_wed_device_rx_ring_setup(q->wed, ring, q->regs,
|
|
reset);
|
|
if (!ret)
|
|
q->wed_regs = q->wed->rx_ring[ring].reg_base;
|
|
break;
|
|
case MT76_WED_RRO_Q_DATA:
|
|
q->flags &= ~MT_QFLAG_WED;
|
|
mt76_dma_queue_reset(dev, q, false);
|
|
mtk_wed_device_rro_rx_ring_setup(q->wed, ring, q->regs);
|
|
q->head = q->ndesc - 1;
|
|
q->queued = q->head;
|
|
break;
|
|
case MT76_WED_RRO_Q_MSDU_PG:
|
|
q->flags &= ~MT_QFLAG_WED;
|
|
mt76_dma_queue_reset(dev, q, false);
|
|
mtk_wed_device_msdu_pg_rx_ring_setup(q->wed, ring, q->regs);
|
|
q->head = q->ndesc - 1;
|
|
q->queued = q->head;
|
|
break;
|
|
case MT76_WED_RRO_Q_IND:
|
|
q->flags &= ~MT_QFLAG_WED;
|
|
mt76_dma_queue_reset(dev, q, true);
|
|
mt76_dma_rx_fill(dev, q, false);
|
|
mtk_wed_device_ind_rx_ring_setup(q->wed, q->regs);
|
|
break;
|
|
default:
|
|
ret = -EINVAL;
|
|
break;
|
|
}
|
|
q->flags = flags;
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_dma_setup);
|
|
#endif /*CONFIG_NET_MEDIATEK_SOC_WED */
|
|
|
|
void mt76_wed_offload_disable(struct mtk_wed_device *wed)
|
|
{
|
|
struct mt76_dev *dev = mt76_wed_to_dev(wed);
|
|
|
|
spin_lock_bh(&dev->token_lock);
|
|
dev->token_size = dev->drv->token_size;
|
|
spin_unlock_bh(&dev->token_lock);
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_offload_disable);
|
|
|
|
void mt76_wed_reset_complete(struct mtk_wed_device *wed)
|
|
{
|
|
struct mt76_dev *dev = mt76_wed_to_dev(wed);
|
|
|
|
complete(&dev->mmio.wed_reset_complete);
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_reset_complete);
|
|
|
|
int mt76_wed_net_setup_tc(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
|
|
struct net_device *netdev, enum tc_setup_type type,
|
|
void *type_data)
|
|
{
|
|
struct mt76_phy *phy = hw->priv;
|
|
struct mtk_wed_device *wed = &phy->dev->mmio.wed;
|
|
|
|
if (!mtk_wed_device_active(wed))
|
|
return -EOPNOTSUPP;
|
|
|
|
return mtk_wed_device_setup_tc(wed, netdev, type, type_data);
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_net_setup_tc);
|
|
|
|
void mt76_wed_dma_reset(struct mt76_dev *dev)
|
|
{
|
|
struct mt76_mmio *mmio = &dev->mmio;
|
|
|
|
if (!test_bit(MT76_STATE_WED_RESET, &dev->phy.state))
|
|
return;
|
|
|
|
complete(&mmio->wed_reset);
|
|
|
|
if (!wait_for_completion_timeout(&mmio->wed_reset_complete, 3 * HZ))
|
|
dev_err(dev->dev, "wed reset complete timeout\n");
|
|
}
|
|
EXPORT_SYMBOL_GPL(mt76_wed_dma_reset);
|