From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 20/29] wifi: mt76: fix queue reg access when building WED and NPU together
Date: Fri, 24 Jul 2026 12:48:04 +0000 [thread overview]
Message-ID: <20260724124813.3961474-20-nbd@nbd.name> (raw)
In-Reply-To: <20260724124813.3961474-1-nbd@nbd.name>
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.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
drivers/net/wireless/mediatek/mt76/dma.h | 110 ++++++++++++-----------
1 file changed, 57 insertions(+), 53 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/dma.h b/drivers/net/wireless/mediatek/mt76/dma.h
index a2cf82cfdaaa..7694764febe7 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.h
+++ b/drivers/net/wireless/mediatek/mt76/dma.h
@@ -5,6 +5,8 @@
#ifndef __MT76_DMA_H
#define __MT76_DMA_H
+#include <linux/regmap.h>
+
#define DMA_DUMMY_DATA ((void *)~0)
#define MT_RING_SIZE 0x10
@@ -46,73 +48,75 @@
#define MT_FCE_INFO_LEN 4
#define MT_RX_RXWI_LEN 32
+static inline bool
+mt76_dma_handle_read(struct mt76_queue *q, u32 offset, u32 *val)
+{
#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
+ if (q->flags & MT_QFLAG_WED) {
+ *val = mtk_wed_device_reg_read(q->wed, q->wed_regs + offset);
+
+ return true;
+ }
+#endif
+#if IS_ENABLED(CONFIG_MT76_NPU)
+ if (q->flags & MT_QFLAG_NPU) {
+ struct airoha_npu *npu;
+
+ *val = 0;
+ rcu_read_lock();
+ npu = rcu_dereference(q->dev->mmio.npu);
+ if (npu)
+ regmap_read(npu->regmap, q->wed_regs + offset, val);
+ rcu_read_unlock();
+
+ return true;
+ }
+#endif
+
+ return false;
+}
+
+static inline bool
+mt76_dma_handle_write(struct mt76_queue *q, u32 offset, u32 val)
+{
+#if IS_ENABLED(CONFIG_NET_MEDIATEK_SOC_WED)
+ if (q->flags & MT_QFLAG_WED) {
+ mtk_wed_device_reg_write(q->wed, q->wed_regs + offset, val);
+
+ return true;
+ }
+#endif
+#if IS_ENABLED(CONFIG_MT76_NPU)
+ if (q->flags & MT_QFLAG_NPU) {
+ struct airoha_npu *npu;
+
+ rcu_read_lock();
+ npu = rcu_dereference(q->dev->mmio.npu);
+ if (npu)
+ regmap_write(npu->regmap, q->wed_regs + offset, val);
+ rcu_read_unlock();
+
+ return true;
+ }
+#endif
+
+ return false;
+}
#define Q_READ(_q, _field) ({ \
u32 _offset = offsetof(struct mt76_queue_regs, _field); \
u32 _val; \
- if ((_q)->flags & MT_QFLAG_WED) \
- _val = mtk_wed_device_reg_read((_q)->wed, \
- ((_q)->wed_regs + \
- _offset)); \
- else \
+ if (!mt76_dma_handle_read(_q, _offset, &_val)) \
_val = readl(&(_q)->regs->_field); \
_val; \
})
#define Q_WRITE(_q, _field, _val) do { \
u32 _offset = offsetof(struct mt76_queue_regs, _field); \
- if ((_q)->flags & MT_QFLAG_WED) \
- mtk_wed_device_reg_write((_q)->wed, \
- ((_q)->wed_regs + _offset), \
- _val); \
- else \
+ if (!mt76_dma_handle_write(_q, _offset, _val)) \
writel(_val, &(_q)->regs->_field); \
} while (0)
-#elif IS_ENABLED(CONFIG_MT76_NPU)
-
-#define Q_READ(_q, _field) ({ \
- u32 _offset = offsetof(struct mt76_queue_regs, _field); \
- u32 _val = 0; \
- if ((_q)->flags & MT_QFLAG_NPU) { \
- struct airoha_npu *npu; \
- \
- rcu_read_lock(); \
- npu = rcu_dereference(q->dev->mmio.npu); \
- if (npu) \
- regmap_read(npu->regmap, \
- ((_q)->wed_regs + _offset), &_val); \
- rcu_read_unlock(); \
- } else { \
- _val = readl(&(_q)->regs->_field); \
- } \
- _val; \
-})
-
-#define Q_WRITE(_q, _field, _val) do { \
- u32 _offset = offsetof(struct mt76_queue_regs, _field); \
- if ((_q)->flags & MT_QFLAG_NPU) { \
- struct airoha_npu *npu; \
- \
- rcu_read_lock(); \
- npu = rcu_dereference(q->dev->mmio.npu); \
- if (npu) \
- regmap_write(npu->regmap, \
- ((_q)->wed_regs + _offset), _val); \
- rcu_read_unlock(); \
- } else { \
- writel(_val, &(_q)->regs->_field); \
- } \
-} while (0)
-
-#else
-
-#define Q_READ(_q, _field) readl(&(_q)->regs->_field)
-#define Q_WRITE(_q, _field, _val) writel(_val, &(_q)->regs->_field)
-
-#endif
-
struct mt76_desc {
__le32 buf0;
__le32 ctrl;
--
2.53.0
next prev parent reply other threads:[~2026-07-24 12:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 12:47 [PATCH mt76-next 01/29] wifi: mt76: fix HE DCM max-RU capability encoding Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 02/29] wifi: mt76: mt7996: bound TLV walk in mt7996_mcu_get_chip_config Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 03/29] wifi: mt76: fix out-of-bounds access in mmio copy helpers Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 04/29] wifi: mt76: mt7915: unwind state on add_interface failure Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 05/29] wifi: mt76: mt7996: hold dev->mt76.mutex while disabling tx worker in SER Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 06/29] wifi: mt76: decode the full VHT Rx STBC capability field Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 07/29] wifi: mt76: fix ER-SU 106-tone RU check in RX rate decode Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 08/29] wifi: mt76: mt7996: reserve space for the CSA-abort countdown TLV Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 09/29] wifi: mt76: mt7996: don't leak MLD group index on remap alloc failure Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 10/29] wifi: mt76: cancel reset and rc work on device unregister Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 11/29] wifi: mt76: report data NSS for STBC frames in RX rate decode Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 12/29] wifi: mt76: mt7915: use little-endian for bss_info_ra wire fields Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 13/29] wifi: mt76: mt7996: add missing rdd_idx check when enabling background radar Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 14/29] wifi: mt76: only consume the WO drop bit on WED v2 devices Felix Fietkau
2026-07-24 12:47 ` [PATCH mt76-next 15/29] wifi: mt76: mt7996: add mcu command to set bssid mapping address Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 16/29] wifi: mt76: mt7996: leave PS when a 4-address connection is established Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 17/29] wifi: mt76: mt7915: unlink TWT flow if the MCU rejects the agreement Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 18/29] wifi: mt76: mt7996: skip key upload when adding an offchannel link Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 19/29] wifi: mt76: mt7996: wake MCU waiters before aborting scan in L1 SER Felix Fietkau
2026-07-24 12:48 ` Felix Fietkau [this message]
2026-07-24 12:48 ` [PATCH mt76-next 21/29] wifi: mt76: mt7996: select net_setup_tc handler at runtime Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 22/29] wifi: mt76: fix stuck TX queues after SER with no active interfaces Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 23/29] wifi: mt76: mt7615: fix NULL deref in mt7615_mac_set_rates Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 24/29] mt76: mt7915: trigger L1 SER on PLE MDP RIOC hang Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 25/29] wifi: mt76: mt7996: free vif links after clearing wcid entries on full reset Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 26/29] wifi: mt76: mt7996: clear stale link state " Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 27/29] wifi: mt76: set MT76_SCANNING when starting a hw scan Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 28/29] wifi: mt76: serialize scan-link teardown with dev->mutex Felix Fietkau
2026-07-24 12:48 ` [PATCH mt76-next 29/29] wifi: mt76: mt7996: hold dev->mutex in remove_interface teardown Felix Fietkau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260724124813.3961474-20-nbd@nbd.name \
--to=nbd@nbd.name \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox