]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: airoha: npu: Add wlan_{send,get}_msg NPU callbacks
authorLorenzo Bianconi <lorenzo@kernel.org>
Mon, 11 Aug 2025 15:31:38 +0000 (17:31 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 13 Aug 2025 01:58:32 +0000 (18:58 -0700)
Introduce wlan_send_msg() and wlan_get_msg() NPU wlan callbacks used
by the wlan driver (MT76) to initialize NPU module registers in order to
offload wireless-wired traffic.
This is a preliminary patch to enable wlan flowtable offload for EN7581
SoC with MT76 driver.

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://patch.msgid.link/20250811-airoha-en7581-wlan-offlaod-v7-3-58823603bb4e@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/airoha/airoha_npu.c
drivers/net/ethernet/airoha/airoha_npu.h

index 731e0119d988cf1e1663f376ce6fc9971f79f4a9..2a337f00386f3d1a35b964331f3b09d3db4634f6 100644 (file)
 #define REG_CR_MBQ8_CTRL(_n)           (NPU_MBOX_BASE_ADDR + 0x0b0 + ((_n) << 2))
 #define REG_CR_NPU_MIB(_n)             (NPU_MBOX_BASE_ADDR + 0x140 + ((_n) << 2))
 
+#define NPU_WLAN_BASE_ADDR             0x30d000
+
+#define REG_IRQ_STATUS                 (NPU_WLAN_BASE_ADDR + 0x030)
+#define REG_IRQ_RXDONE(_n)             (NPU_WLAN_BASE_ADDR + ((_n) << 2) + 0x034)
+#define NPU_IRQ_RX_MASK(_n)            ((_n) == 1 ? BIT(17) : BIT(16))
+
+#define REG_TX_BASE(_n)                        (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x080)
+#define REG_TX_DSCP_NUM(_n)            (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x084)
+#define REG_TX_CPU_IDX(_n)             (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x088)
+#define REG_TX_DMA_IDX(_n)             (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x08c)
+
+#define REG_RX_BASE(_n)                        (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x180)
+#define REG_RX_DSCP_NUM(_n)            (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x184)
+#define REG_RX_CPU_IDX(_n)             (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x188)
+#define REG_RX_DMA_IDX(_n)             (NPU_WLAN_BASE_ADDR + ((_n) << 4) + 0x18c)
+
 #define NPU_TIMER_BASE_ADDR            0x310100
 #define REG_WDT_TIMER_CTRL(_n)         (NPU_TIMER_BASE_ADDR + ((_n) * 0x100))
 #define WDT_EN_MASK                    BIT(25)
@@ -420,6 +436,30 @@ static int airoha_npu_wlan_msg_send(struct airoha_npu *npu, int ifindex,
        return err;
 }
 
+static int airoha_npu_wlan_msg_get(struct airoha_npu *npu, int ifindex,
+                                  enum airoha_npu_wlan_get_cmd func_id,
+                                  void *data, int data_len, gfp_t gfp)
+{
+       struct wlan_mbox_data *wlan_data;
+       int err, len;
+
+       len = sizeof(*wlan_data) + data_len;
+       wlan_data = kzalloc(len, gfp);
+       if (!wlan_data)
+               return -ENOMEM;
+
+       wlan_data->ifindex = ifindex;
+       wlan_data->func_type = NPU_OP_GET;
+       wlan_data->func_id = func_id;
+
+       err = airoha_npu_send_msg(npu, NPU_FUNC_WIFI, wlan_data, len);
+       if (!err)
+               memcpy(data, wlan_data->d, data_len);
+       kfree(wlan_data);
+
+       return err;
+}
+
 static int
 airoha_npu_wlan_set_reserved_memory(struct airoha_npu *npu,
                                    int ifindex, const char *name,
@@ -471,6 +511,15 @@ static int airoha_npu_wlan_init_memory(struct airoha_npu *npu)
                                        GFP_KERNEL);
 }
 
+static u32 airoha_npu_wlan_queue_addr_get(struct airoha_npu *npu, int qid,
+                                         bool xmit)
+{
+       if (xmit)
+               return REG_TX_BASE(qid + 2);
+
+       return REG_RX_BASE(qid);
+}
+
 struct airoha_npu *airoha_npu_get(struct device *dev, dma_addr_t *stats_addr)
 {
        struct platform_device *pdev;
@@ -575,6 +624,9 @@ static int airoha_npu_probe(struct platform_device *pdev)
        npu->ops.ppe_flush_sram_entries = airoha_npu_ppe_flush_sram_entries;
        npu->ops.ppe_foe_commit_entry = airoha_npu_foe_commit_entry;
        npu->ops.wlan_init_reserved_memory = airoha_npu_wlan_init_memory;
+       npu->ops.wlan_send_msg = airoha_npu_wlan_msg_send;
+       npu->ops.wlan_get_msg = airoha_npu_wlan_msg_get;
+       npu->ops.wlan_get_queue_addr = airoha_npu_wlan_queue_addr_get;
 
        npu->regmap = devm_regmap_init_mmio(dev, base, &regmap_config);
        if (IS_ERR(npu->regmap))
index 0cb5356b00e90fd45cde90b92d9125d49e51e5e5..7b9ff370c879333397214401b22157832b656e47 100644 (file)
@@ -43,6 +43,20 @@ enum airoha_npu_wlan_set_cmd {
        WLAN_FUNC_SET_WAIT_TOKEN_ID_SIZE,
 };
 
+enum airoha_npu_wlan_get_cmd {
+       WLAN_FUNC_GET_WAIT_NPU_INFO,
+       WLAN_FUNC_GET_WAIT_LAST_RATE,
+       WLAN_FUNC_GET_WAIT_COUNTER,
+       WLAN_FUNC_GET_WAIT_DBG_COUNTER,
+       WLAN_FUNC_GET_WAIT_RXDESC_BASE,
+       WLAN_FUNC_GET_WAIT_WCID_DBG_COUNTER,
+       WLAN_FUNC_GET_WAIT_DMA_ADDR,
+       WLAN_FUNC_GET_WAIT_RING_SIZE,
+       WLAN_FUNC_GET_WAIT_NPU_SUPPORT_MAP,
+       WLAN_FUNC_GET_WAIT_MDC_LOCK_ADDRESS,
+       WLAN_FUNC_GET_WAIT_NPU_VERSION,
+};
+
 struct airoha_npu {
        struct device *dev;
        struct regmap *regmap;
@@ -67,6 +81,14 @@ struct airoha_npu {
                                            u32 entry_size, u32 hash,
                                            bool ppe2);
                int (*wlan_init_reserved_memory)(struct airoha_npu *npu);
+               int (*wlan_send_msg)(struct airoha_npu *npu, int ifindex,
+                                    enum airoha_npu_wlan_set_cmd func_id,
+                                    void *data, int data_len, gfp_t gfp);
+               int (*wlan_get_msg)(struct airoha_npu *npu, int ifindex,
+                                   enum airoha_npu_wlan_get_cmd func_id,
+                                   void *data, int data_len, gfp_t gfp);
+               u32 (*wlan_get_queue_addr)(struct airoha_npu *npu, int qid,
+                                          bool xmit);
        } ops;
 };