Skip to content

Commit 1fdf2b5

Browse files
committed
wifi: mt76: fix queue reg access when building WED and NPU together
Move the offload specific parts of Q_READ/Q_WRITE into mt76_dma_handle_read/write, which return false to fall back to readl/writel. The WED and NPU #ifdefs now live inside those helpers instead of selecting between mutually exclusive macro definitions, so a kernel with both enabled supports both at runtime. Also fixes the NPU path dereferencing a hardcoded q instead of the macro argument. Link: https://patch.msgid.link/20260724124813.3961474-20-nbd@nbd.name Signed-off-by: Felix Fietkau <nbd@nbd.name>
1 parent 6f8d8c4 commit 1fdf2b5

1 file changed

Lines changed: 55 additions & 51 deletions

File tree

  • drivers/net/wireless/mediatek/mt76

drivers/net/wireless/mediatek/mt76/dma.h

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef __MT76_DMA_H
66
#define __MT76_DMA_H
77

8+
#include <linux/regmap.h>
9+
810
#define DMA_DUMMY_DATA ((void *)~0)
911

1012
#define MT_RING_SIZE 0x10
@@ -46,73 +48,75 @@
4648
#define MT_FCE_INFO_LEN 4
4749
#define MT_RX_RXWI_LEN 32
4850

51+
static inline bool
52+
mt76_dma_handle_read(struct mt76_queue *q, u32 offset, u32 *val)
53+
{
4954
#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
55+
if (q->flags & MT_QFLAG_WED) {
56+
*val = mtk_wed_device_reg_read(q->wed, q->wed_regs + offset);
5057

51-
#define Q_READ(_q, _field) ({ \
52-
u32 _offset = offsetof(struct mt76_queue_regs, _field); \
53-
u32 _val; \
54-
if ((_q)->flags & MT_QFLAG_WED) \
55-
_val = mtk_wed_device_reg_read((_q)->wed, \
56-
((_q)->wed_regs + \
57-
_offset)); \
58-
else \
59-
_val = readl(&(_q)->regs->_field); \
60-
_val; \
61-
})
58+
return true;
59+
}
60+
#endif
61+
#if IS_ENABLED(CONFIG_MT76_NPU)
62+
if (q->flags & MT_QFLAG_NPU) {
63+
struct airoha_npu *npu;
64+
65+
*val = 0;
66+
rcu_read_lock();
67+
npu = rcu_dereference(q->dev->mmio.npu);
68+
if (npu)
69+
regmap_read(npu->regmap, q->wed_regs + offset, val);
70+
rcu_read_unlock();
71+
72+
return true;
73+
}
74+
#endif
6275

63-
#define Q_WRITE(_q, _field, _val) do { \
64-
u32 _offset = offsetof(struct mt76_queue_regs, _field); \
65-
if ((_q)->flags & MT_QFLAG_WED) \
66-
mtk_wed_device_reg_write((_q)->wed, \
67-
((_q)->wed_regs + _offset), \
68-
_val); \
69-
else \
70-
writel(_val, &(_q)->regs->_field); \
71-
} while (0)
76+
return false;
77+
}
7278

73-
#elif IS_ENABLED(CONFIG_MT76_NPU)
79+
static inline bool
80+
mt76_dma_handle_write(struct mt76_queue *q, u32 offset, u32 val)
81+
{
82+
#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
83+
if (q->flags & MT_QFLAG_WED) {
84+
mtk_wed_device_reg_write(q->wed, q->wed_regs + offset, val);
85+
86+
return true;
87+
}
88+
#endif
89+
#if IS_ENABLED(CONFIG_MT76_NPU)
90+
if (q->flags & MT_QFLAG_NPU) {
91+
struct airoha_npu *npu;
92+
93+
rcu_read_lock();
94+
npu = rcu_dereference(q->dev->mmio.npu);
95+
if (npu)
96+
regmap_write(npu->regmap, q->wed_regs + offset, val);
97+
rcu_read_unlock();
98+
99+
return true;
100+
}
101+
#endif
102+
103+
return false;
104+
}
74105

75106
#define Q_READ(_q, _field) ({ \
76107
u32 _offset = offsetof(struct mt76_queue_regs, _field); \
77-
u32 _val = 0; \
78-
if ((_q)->flags & MT_QFLAG_NPU) { \
79-
struct airoha_npu *npu; \
80-
\
81-
rcu_read_lock(); \
82-
npu = rcu_dereference(q->dev->mmio.npu); \
83-
if (npu) \
84-
regmap_read(npu->regmap, \
85-
((_q)->wed_regs + _offset), &_val); \
86-
rcu_read_unlock(); \
87-
} else { \
108+
u32 _val; \
109+
if (!mt76_dma_handle_read(_q, _offset, &_val)) \
88110
_val = readl(&(_q)->regs->_field); \
89-
} \
90111
_val; \
91112
})
92113

93114
#define Q_WRITE(_q, _field, _val) do { \
94115
u32 _offset = offsetof(struct mt76_queue_regs, _field); \
95-
if ((_q)->flags & MT_QFLAG_NPU) { \
96-
struct airoha_npu *npu; \
97-
\
98-
rcu_read_lock(); \
99-
npu = rcu_dereference(q->dev->mmio.npu); \
100-
if (npu) \
101-
regmap_write(npu->regmap, \
102-
((_q)->wed_regs + _offset), _val); \
103-
rcu_read_unlock(); \
104-
} else { \
116+
if (!mt76_dma_handle_write(_q, _offset, _val)) \
105117
writel(_val, &(_q)->regs->_field); \
106-
} \
107118
} while (0)
108119

109-
#else
110-
111-
#define Q_READ(_q, _field) readl(&(_q)->regs->_field)
112-
#define Q_WRITE(_q, _field, _val) writel(_val, &(_q)->regs->_field)
113-
114-
#endif
115-
116120
struct mt76_desc {
117121
__le32 buf0;
118122
__le32 ctrl;

0 commit comments

Comments
 (0)