File Index
Files and directories
Sign in
FILE

airoha_offload.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/soc/airoha/airoha_offload.h C
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (c) 2025 AIROHA Inc
  4 * Author: Lorenzo Bianconi <lorenzo@kernel.org>
  5 */
  6#ifndef AIROHA_OFFLOAD_H
  7#define AIROHA_OFFLOAD_H
  8
  9#include <linux/skbuff.h>
 10#include <linux/spinlock.h>
 11#include <linux/workqueue.h>
 12
 13enum {
 14	PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED = 0x0f,
 15};
 16
 17struct airoha_ppe_dev {
 18	struct {
 19		int (*setup_tc_block_cb)(struct airoha_ppe_dev *dev,
 20					 void *type_data);
 21		void (*check_skb)(struct airoha_ppe_dev *dev,
 22				  struct sk_buff *skb, u16 hash,
 23				  bool rx_wlan);
 24	} ops;
 25
 26	void *priv;
 27};
 28
 29#if (IS_BUILTIN(CONFIG_NET_AIROHA) || IS_MODULE(CONFIG_NET_AIROHA))
 30struct airoha_ppe_dev *airoha_ppe_get_dev(struct device *dev);
 31void airoha_ppe_put_dev(struct airoha_ppe_dev *dev);
 32
 33static inline int airoha_ppe_dev_setup_tc_block_cb(struct airoha_ppe_dev *dev,
 34						   void *type_data)
 35{
 36	return dev->ops.setup_tc_block_cb(dev, type_data);
 37}
 38
 39static inline void airoha_ppe_dev_check_skb(struct airoha_ppe_dev *dev,
 40					    struct sk_buff *skb,
 41					    u16 hash, bool rx_wlan)
 42{
 43	dev->ops.check_skb(dev, skb, hash, rx_wlan);
 44}
 45#else
 46static inline struct airoha_ppe_dev *airoha_ppe_get_dev(struct device *dev)
 47{
 48	return NULL;
 49}
 50
 51static inline void airoha_ppe_put_dev(struct airoha_ppe_dev *dev)
 52{
 53}
 54
 55static inline int airoha_ppe_dev_setup_tc_block_cb(struct airoha_ppe_dev *dev,
 56						   void *type_data)
 57{
 58	return -EOPNOTSUPP;
 59}
 60
 61static inline void airoha_ppe_dev_check_skb(struct airoha_ppe_dev *dev,
 62					    struct sk_buff *skb, u16 hash,
 63					    bool rx_wlan)
 64{
 65}
 66#endif
 67
 68#define NPU_NUM_CORES		8
 69#define NPU_NUM_IRQ		6
 70#define NPU_RX0_DESC_NUM	512
 71#define NPU_RX1_DESC_NUM	512
 72
 73/* CTRL */
 74#define NPU_RX_DMA_DESC_LAST_MASK	BIT(27)
 75#define NPU_RX_DMA_DESC_LEN_MASK	GENMASK(26, 14)
 76#define NPU_RX_DMA_DESC_CUR_LEN_MASK	GENMASK(13, 1)
 77#define NPU_RX_DMA_DESC_DONE_MASK	BIT(0)
 78/* INFO */
 79#define NPU_RX_DMA_PKT_COUNT_MASK	GENMASK(31, 29)
 80#define NPU_RX_DMA_PKT_ID_MASK		GENMASK(28, 26)
 81#define NPU_RX_DMA_SRC_PORT_MASK	GENMASK(25, 21)
 82#define NPU_RX_DMA_CRSN_MASK		GENMASK(20, 16)
 83#define NPU_RX_DMA_FOE_ID_MASK		GENMASK(15, 0)
 84/* DATA */
 85#define NPU_RX_DMA_SID_MASK		GENMASK(31, 16)
 86#define NPU_RX_DMA_FRAG_TYPE_MASK	GENMASK(15, 14)
 87#define NPU_RX_DMA_PRIORITY_MASK	GENMASK(13, 10)
 88#define NPU_RX_DMA_RADIO_ID_MASK	GENMASK(9, 6)
 89#define NPU_RX_DMA_VAP_ID_MASK		GENMASK(5, 2)
 90#define NPU_RX_DMA_FRAME_TYPE_MASK	GENMASK(1, 0)
 91
 92struct airoha_npu_rx_dma_desc {
 93	u32 ctrl;
 94	u32 info;
 95	u32 data;
 96	u32 addr;
 97	u64 rsv;
 98} __packed;
 99
100/* CTRL */
101#define NPU_TX_DMA_DESC_SCHED_MASK	BIT(31)
102#define NPU_TX_DMA_DESC_LEN_MASK	GENMASK(30, 18)
103#define NPU_TX_DMA_DESC_VEND_LEN_MASK	GENMASK(17, 1)
104#define NPU_TX_DMA_DESC_DONE_MASK	BIT(0)
105
106#define NPU_TXWI_LEN	192
107
108struct airoha_npu_tx_dma_desc {
109	u32 ctrl;
110	u32 addr;
111	u64 rsv;
112	u8 txwi[NPU_TXWI_LEN];
113} __packed;
114
115enum airoha_npu_wlan_set_cmd {
116	WLAN_FUNC_SET_WAIT_PCIE_ADDR,
117	WLAN_FUNC_SET_WAIT_DESC,
118	WLAN_FUNC_SET_WAIT_NPU_INIT_DONE,
119	WLAN_FUNC_SET_WAIT_TRAN_TO_CPU,
120	WLAN_FUNC_SET_WAIT_BA_WIN_SIZE,
121	WLAN_FUNC_SET_WAIT_DRIVER_MODEL,
122	WLAN_FUNC_SET_WAIT_DEL_STA,
123	WLAN_FUNC_SET_WAIT_DRAM_BA_NODE_ADDR,
124	WLAN_FUNC_SET_WAIT_PKT_BUF_ADDR,
125	WLAN_FUNC_SET_WAIT_IS_TEST_NOBA,
126	WLAN_FUNC_SET_WAIT_FLUSHONE_TIMEOUT,
127	WLAN_FUNC_SET_WAIT_FLUSHALL_TIMEOUT,
128	WLAN_FUNC_SET_WAIT_IS_FORCE_TO_CPU,
129	WLAN_FUNC_SET_WAIT_PCIE_STATE,
130	WLAN_FUNC_SET_WAIT_PCIE_PORT_TYPE,
131	WLAN_FUNC_SET_WAIT_ERROR_RETRY_TIMES,
132	WLAN_FUNC_SET_WAIT_BAR_INFO,
133	WLAN_FUNC_SET_WAIT_FAST_FLAG,
134	WLAN_FUNC_SET_WAIT_NPU_BAND0_ONCPU,
135	WLAN_FUNC_SET_WAIT_TX_RING_PCIE_ADDR,
136	WLAN_FUNC_SET_WAIT_TX_DESC_HW_BASE,
137	WLAN_FUNC_SET_WAIT_TX_BUF_SPACE_HW_BASE,
138	WLAN_FUNC_SET_WAIT_RX_RING_FOR_TXDONE_HW_BASE,
139	WLAN_FUNC_SET_WAIT_TX_PKT_BUF_ADDR,
140	WLAN_FUNC_SET_WAIT_INODE_TXRX_REG_ADDR,
141	WLAN_FUNC_SET_WAIT_INODE_DEBUG_FLAG,
142	WLAN_FUNC_SET_WAIT_INODE_HW_CFG_INFO,
143	WLAN_FUNC_SET_WAIT_INODE_STOP_ACTION,
144	WLAN_FUNC_SET_WAIT_INODE_PCIE_SWAP,
145	WLAN_FUNC_SET_WAIT_RATELIMIT_CTRL,
146	WLAN_FUNC_SET_WAIT_HWNAT_INIT,
147	WLAN_FUNC_SET_WAIT_ARHT_CHIP_INFO,
148	WLAN_FUNC_SET_WAIT_TX_BUF_CHECK_ADDR,
149	WLAN_FUNC_SET_WAIT_TOKEN_ID_SIZE,
150};
151
152enum airoha_npu_wlan_get_cmd {
153	WLAN_FUNC_GET_WAIT_NPU_INFO,
154	WLAN_FUNC_GET_WAIT_LAST_RATE,
155	WLAN_FUNC_GET_WAIT_COUNTER,
156	WLAN_FUNC_GET_WAIT_DBG_COUNTER,
157	WLAN_FUNC_GET_WAIT_RXDESC_BASE,
158	WLAN_FUNC_GET_WAIT_WCID_DBG_COUNTER,
159	WLAN_FUNC_GET_WAIT_DMA_ADDR,
160	WLAN_FUNC_GET_WAIT_RING_SIZE,
161	WLAN_FUNC_GET_WAIT_NPU_SUPPORT_MAP,
162	WLAN_FUNC_GET_WAIT_MDC_LOCK_ADDRESS,
163	WLAN_FUNC_GET_WAIT_NPU_VERSION,
164};
165
166struct airoha_npu {
167#if (IS_BUILTIN(CONFIG_NET_AIROHA_NPU) || IS_MODULE(CONFIG_NET_AIROHA_NPU))
168	struct device *dev;
169	struct regmap *regmap;
170
171	struct airoha_npu_core {
172		struct airoha_npu *npu;
173		/* protect concurrent npu memory accesses */
174		spinlock_t lock;
175		struct work_struct wdt_work;
176	} cores[NPU_NUM_CORES];
177
178	int irqs[NPU_NUM_IRQ];
179
180	struct airoha_foe_stats __iomem *stats;
181
182	struct {
183		int (*ppe_init)(struct airoha_npu *npu);
184		int (*ppe_deinit)(struct airoha_npu *npu);
185		int (*ppe_init_stats)(struct airoha_npu *npu,
186				      dma_addr_t addr, u32 num_stats_entries);
187		int (*ppe_flush_sram_entries)(struct airoha_npu *npu,
188					      dma_addr_t foe_addr,
189					      int sram_num_entries);
190		int (*ppe_foe_commit_entry)(struct airoha_npu *npu,
191					    dma_addr_t foe_addr,
192					    u32 entry_size, u32 hash,
193					    bool ppe2);
194		int (*wlan_init_reserved_memory)(struct airoha_npu *npu);
195		int (*wlan_send_msg)(struct airoha_npu *npu, int ifindex,
196				     enum airoha_npu_wlan_set_cmd func_id,
197				     void *data, int data_len, gfp_t gfp);
198		int (*wlan_get_msg)(struct airoha_npu *npu, int ifindex,
199				    enum airoha_npu_wlan_get_cmd func_id,
200				    void *data, int data_len, gfp_t gfp);
201		u32 (*wlan_get_queue_addr)(struct airoha_npu *npu, int qid,
202					   bool xmit);
203		void (*wlan_set_irq_status)(struct airoha_npu *npu, u32 val);
204		u32 (*wlan_get_irq_status)(struct airoha_npu *npu, int q);
205		void (*wlan_enable_irq)(struct airoha_npu *npu, int q);
206		void (*wlan_disable_irq)(struct airoha_npu *npu, int q);
207	} ops;
208#endif
209};
210
211#if (IS_BUILTIN(CONFIG_NET_AIROHA_NPU) || IS_MODULE(CONFIG_NET_AIROHA_NPU))
212struct airoha_npu *airoha_npu_get(struct device *dev);
213void airoha_npu_put(struct airoha_npu *npu);
214
215static inline int airoha_npu_wlan_init_reserved_memory(struct airoha_npu *npu)
216{
217	return npu->ops.wlan_init_reserved_memory(npu);
218}
219
220static inline int airoha_npu_wlan_send_msg(struct airoha_npu *npu,
221					   int ifindex,
222					   enum airoha_npu_wlan_set_cmd cmd,
223					   void *data, int data_len, gfp_t gfp)
224{
225	return npu->ops.wlan_send_msg(npu, ifindex, cmd, data, data_len, gfp);
226}
227
228static inline int airoha_npu_wlan_get_msg(struct airoha_npu *npu, int ifindex,
229					  enum airoha_npu_wlan_get_cmd cmd,
230					  void *data, int data_len, gfp_t gfp)
231{
232	return npu->ops.wlan_get_msg(npu, ifindex, cmd, data, data_len, gfp);
233}
234
235static inline u32 airoha_npu_wlan_get_queue_addr(struct airoha_npu *npu,
236						 int qid, bool xmit)
237{
238	return npu->ops.wlan_get_queue_addr(npu, qid, xmit);
239}
240
241static inline void airoha_npu_wlan_set_irq_status(struct airoha_npu *npu,
242						  u32 val)
243{
244	npu->ops.wlan_set_irq_status(npu, val);
245}
246
247static inline u32 airoha_npu_wlan_get_irq_status(struct airoha_npu *npu, int q)
248{
249	return npu->ops.wlan_get_irq_status(npu, q);
250}
251
252static inline void airoha_npu_wlan_enable_irq(struct airoha_npu *npu, int q)
253{
254	npu->ops.wlan_enable_irq(npu, q);
255}
256
257static inline void airoha_npu_wlan_disable_irq(struct airoha_npu *npu, int q)
258{
259	npu->ops.wlan_disable_irq(npu, q);
260}
261#else
262static inline struct airoha_npu *airoha_npu_get(struct device *dev)
263{
264	return NULL;
265}
266
267static inline void airoha_npu_put(struct airoha_npu *npu)
268{
269}
270
271static inline int airoha_npu_wlan_init_reserved_memory(struct airoha_npu *npu)
272{
273	return -EOPNOTSUPP;
274}
275
276static inline int airoha_npu_wlan_send_msg(struct airoha_npu *npu,
277					   int ifindex,
278					   enum airoha_npu_wlan_set_cmd cmd,
279					   void *data, int data_len, gfp_t gfp)
280{
281	return -EOPNOTSUPP;
282}
283
284static inline int airoha_npu_wlan_get_msg(struct airoha_npu *npu, int ifindex,
285					  enum airoha_npu_wlan_get_cmd cmd,
286					  void *data, int data_len, gfp_t gfp)
287{
288	return -EOPNOTSUPP;
289}
290
291static inline u32 airoha_npu_wlan_get_queue_addr(struct airoha_npu *npu,
292						 int qid, bool xmit)
293{
294	return 0;
295}
296
297static inline void airoha_npu_wlan_set_irq_status(struct airoha_npu *npu,
298						  u32 val)
299{
300}
301
302static inline u32 airoha_npu_wlan_get_irq_status(struct airoha_npu *npu,
303						 int q)
304{
305	return 0;
306}
307
308static inline void airoha_npu_wlan_enable_irq(struct airoha_npu *npu, int q)
309{
310}
311
312static inline void airoha_npu_wlan_disable_irq(struct airoha_npu *npu, int q)
313{
314}
315#endif
316
317#endif /* AIROHA_OFFLOAD_H */
~/ Read-only file preview.