xref: /linux/include/linux/soc/mediatek/mtk_wed.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1 #ifndef __MTK_WED_H
2 #define __MTK_WED_H
3 
4 #include <linux/kernel.h>
5 #include <linux/rcupdate.h>
6 #include <linux/regmap.h>
7 #include <linux/pci.h>
8 #include <linux/skbuff.h>
9 #include <linux/netdevice.h>
10 
11 #define MTK_WED_TX_QUEUES		2
12 #define MTK_WED_RX_QUEUES		2
13 #define MTK_WED_RX_PAGE_QUEUES		3
14 
15 #define WED_WO_STA_REC			0x6
16 
17 struct mtk_wed_hw;
18 struct mtk_wdma_desc;
19 
20 enum mtk_wed_wo_cmd {
21 	MTK_WED_WO_CMD_WED_CFG,
22 	MTK_WED_WO_CMD_WED_RX_STAT,
23 	MTK_WED_WO_CMD_RRO_SER,
24 	MTK_WED_WO_CMD_DBG_INFO,
25 	MTK_WED_WO_CMD_DEV_INFO,
26 	MTK_WED_WO_CMD_BSS_INFO,
27 	MTK_WED_WO_CMD_STA_REC,
28 	MTK_WED_WO_CMD_DEV_INFO_DUMP,
29 	MTK_WED_WO_CMD_BSS_INFO_DUMP,
30 	MTK_WED_WO_CMD_STA_REC_DUMP,
31 	MTK_WED_WO_CMD_BA_INFO_DUMP,
32 	MTK_WED_WO_CMD_FBCMD_Q_DUMP,
33 	MTK_WED_WO_CMD_FW_LOG_CTRL,
34 	MTK_WED_WO_CMD_LOG_FLUSH,
35 	MTK_WED_WO_CMD_CHANGE_STATE,
36 	MTK_WED_WO_CMD_CPU_STATS_ENABLE,
37 	MTK_WED_WO_CMD_CPU_STATS_DUMP,
38 	MTK_WED_WO_CMD_EXCEPTION_INIT,
39 	MTK_WED_WO_CMD_PROF_CTRL,
40 	MTK_WED_WO_CMD_STA_BA_DUMP,
41 	MTK_WED_WO_CMD_BA_CTRL_DUMP,
42 	MTK_WED_WO_CMD_RXCNT_CTRL,
43 	MTK_WED_WO_CMD_RXCNT_INFO,
44 	MTK_WED_WO_CMD_SET_CAP,
45 	MTK_WED_WO_CMD_CCIF_RING_DUMP,
46 	MTK_WED_WO_CMD_WED_END
47 };
48 
49 struct mtk_wed_bm_desc {
50 	__le32 buf0;
51 	__le32 token;
52 } __packed __aligned(4);
53 
54 enum mtk_wed_bus_tye {
55 	MTK_WED_BUS_PCIE,
56 	MTK_WED_BUS_AXI,
57 };
58 
59 #define MTK_WED_RING_CONFIGURED		BIT(0)
60 struct mtk_wed_ring {
61 	struct mtk_wdma_desc *desc;
62 	dma_addr_t desc_phys;
63 	u32 desc_size;
64 	int size;
65 	u32 flags;
66 
67 	u32 reg_base;
68 	void __iomem *wpdma;
69 };
70 
71 struct mtk_wed_wo_rx_stats {
72 	__le16 wlan_idx;
73 	__le16 tid;
74 	__le32 rx_pkt_cnt;
75 	__le32 rx_byte_cnt;
76 	__le32 rx_err_cnt;
77 	__le32 rx_drop_cnt;
78 };
79 
80 struct mtk_wed_buf {
81 	void *p;
82 	dma_addr_t phy_addr;
83 };
84 
85 struct mtk_wed_device {
86 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
87 	const struct mtk_wed_ops *ops;
88 	struct device *dev;
89 	struct mtk_wed_hw *hw;
90 	bool init_done, running;
91 	int wdma_idx;
92 	int irq;
93 	u8 version;
94 
95 	/* used by wlan driver */
96 	u32 rev_id;
97 
98 	struct mtk_wed_ring tx_ring[MTK_WED_TX_QUEUES];
99 	struct mtk_wed_ring rx_ring[MTK_WED_RX_QUEUES];
100 	struct mtk_wed_ring txfree_ring;
101 	struct mtk_wed_ring tx_wdma[MTK_WED_TX_QUEUES];
102 	struct mtk_wed_ring rx_wdma[MTK_WED_RX_QUEUES];
103 	struct mtk_wed_ring rx_rro_ring[MTK_WED_RX_QUEUES];
104 	struct mtk_wed_ring rx_page_ring[MTK_WED_RX_PAGE_QUEUES];
105 	struct mtk_wed_ring ind_cmd_ring;
106 
107 	struct {
108 		int size;
109 		struct mtk_wed_buf *pages;
110 		struct mtk_wdma_desc *desc;
111 		dma_addr_t desc_phys;
112 	} tx_buf_ring;
113 
114 	struct {
115 		int size;
116 		struct mtk_wed_bm_desc *desc;
117 		dma_addr_t desc_phys;
118 	} rx_buf_ring;
119 
120 	struct {
121 		struct mtk_wed_ring ring;
122 		dma_addr_t miod_phys;
123 		dma_addr_t fdbk_phys;
124 	} rro;
125 
126 	struct {
127 		int size;
128 		struct mtk_wed_buf *pages;
129 		struct mtk_wed_bm_desc *desc;
130 		dma_addr_t desc_phys;
131 	} hw_rro;
132 
133 	/* filled by driver: */
134 	struct {
135 		union {
136 			struct platform_device *platform_dev;
137 			struct pci_dev *pci_dev;
138 		};
139 		enum mtk_wed_bus_tye bus_type;
140 		void __iomem *base;
141 		u32 phy_base;
142 		u32 id;
143 
144 		u32 wpdma_phys;
145 		u32 wpdma_int;
146 		u32 wpdma_mask;
147 		u32 wpdma_tx;
148 		u32 wpdma_txfree;
149 		u32 wpdma_rx_glo;
150 		u32 wpdma_rx;
151 		u32 wpdma_rx_rro[MTK_WED_RX_QUEUES];
152 		u32 wpdma_rx_pg;
153 
154 		bool wcid_512;
155 		bool hw_rro;
156 		bool msi;
157 
158 		u16 token_start;
159 		unsigned int nbuf;
160 		unsigned int rx_nbuf;
161 		unsigned int rx_npkt;
162 		unsigned int rx_size;
163 		unsigned int amsdu_max_len;
164 
165 		u8 tx_tbit[MTK_WED_TX_QUEUES];
166 		u8 rx_tbit[MTK_WED_RX_QUEUES];
167 		u8 rro_rx_tbit[MTK_WED_RX_QUEUES];
168 		u8 rx_pg_tbit[MTK_WED_RX_PAGE_QUEUES];
169 		u8 txfree_tbit;
170 		u8 amsdu_max_subframes;
171 
172 		struct {
173 			u8 se_group_nums;
174 			u16 win_size;
175 			u16 particular_sid;
176 			u32 ack_sn_addr;
177 			dma_addr_t particular_se_phys;
178 			dma_addr_t addr_elem_phys[1024];
179 		} ind_cmd;
180 
181 		u32 (*init_buf)(void *ptr, dma_addr_t phys, int token_id);
182 		int (*offload_enable)(struct mtk_wed_device *wed);
183 		void (*offload_disable)(struct mtk_wed_device *wed);
184 		u32 (*init_rx_buf)(struct mtk_wed_device *wed, int size);
185 		void (*release_rx_buf)(struct mtk_wed_device *wed);
186 		void (*update_wo_rx_stats)(struct mtk_wed_device *wed,
187 					   struct mtk_wed_wo_rx_stats *stats);
188 		int (*reset)(struct mtk_wed_device *wed);
189 		void (*reset_complete)(struct mtk_wed_device *wed);
190 	} wlan;
191 #endif
192 };
193 
194 struct mtk_wed_ops {
195 	int (*attach)(struct mtk_wed_device *dev);
196 	int (*tx_ring_setup)(struct mtk_wed_device *dev, int ring,
197 			     void __iomem *regs, bool reset);
198 	int (*rx_ring_setup)(struct mtk_wed_device *dev, int ring,
199 			     void __iomem *regs, bool reset);
200 	int (*txfree_ring_setup)(struct mtk_wed_device *dev,
201 				 void __iomem *regs);
202 	int (*msg_update)(struct mtk_wed_device *dev, int cmd_id,
203 			  void *data, int len);
204 	void (*detach)(struct mtk_wed_device *dev);
205 	void (*ppe_check)(struct mtk_wed_device *dev, struct sk_buff *skb,
206 			  u32 reason, u32 hash);
207 
208 	void (*stop)(struct mtk_wed_device *dev);
209 	void (*start)(struct mtk_wed_device *dev, u32 irq_mask);
210 	void (*reset_dma)(struct mtk_wed_device *dev);
211 
212 	u32 (*reg_read)(struct mtk_wed_device *dev, u32 reg);
213 	void (*reg_write)(struct mtk_wed_device *dev, u32 reg, u32 val);
214 
215 	u32 (*irq_get)(struct mtk_wed_device *dev, u32 mask);
216 	void (*irq_set_mask)(struct mtk_wed_device *dev, u32 mask);
217 	int (*setup_tc)(struct mtk_wed_device *wed, struct net_device *dev,
218 			enum tc_setup_type type, void *type_data);
219 	void (*start_hw_rro)(struct mtk_wed_device *dev, u32 irq_mask,
220 			     bool reset);
221 	void (*rro_rx_ring_setup)(struct mtk_wed_device *dev, int ring,
222 				  void __iomem *regs);
223 	void (*msdu_pg_rx_ring_setup)(struct mtk_wed_device *dev, int ring,
224 				      void __iomem *regs);
225 	int (*ind_rx_ring_setup)(struct mtk_wed_device *dev,
226 				 void __iomem *regs);
227 };
228 
229 extern const struct mtk_wed_ops __rcu *mtk_soc_wed_ops;
230 
231 static inline int
mtk_wed_device_attach(struct mtk_wed_device * dev)232 mtk_wed_device_attach(struct mtk_wed_device *dev)
233 {
234 	int ret = -ENODEV;
235 
236 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
237 	rcu_read_lock();
238 	dev->ops = rcu_dereference(mtk_soc_wed_ops);
239 	if (dev->ops)
240 		ret = dev->ops->attach(dev);
241 	else
242 		rcu_read_unlock();
243 
244 	if (ret)
245 		dev->ops = NULL;
246 #endif
247 
248 	return ret;
249 }
250 
mtk_wed_get_rx_capa(struct mtk_wed_device * dev)251 static inline bool mtk_wed_get_rx_capa(struct mtk_wed_device *dev)
252 {
253 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
254 	if (dev->version == 3)
255 		return dev->wlan.hw_rro;
256 
257 	return dev->version != 1;
258 #else
259 	return false;
260 #endif
261 }
262 
mtk_wed_is_amsdu_supported(struct mtk_wed_device * dev)263 static inline bool mtk_wed_is_amsdu_supported(struct mtk_wed_device *dev)
264 {
265 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
266 	return dev->version == 3;
267 #else
268 	return false;
269 #endif
270 }
271 
272 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
273 #define mtk_wed_device_active(_dev) !!(_dev)->ops
274 #define mtk_wed_device_detach(_dev) (_dev)->ops->detach(_dev)
275 #define mtk_wed_device_start(_dev, _mask) (_dev)->ops->start(_dev, _mask)
276 #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) \
277 	(_dev)->ops->tx_ring_setup(_dev, _ring, _regs, _reset)
278 #define mtk_wed_device_txfree_ring_setup(_dev, _regs) \
279 	(_dev)->ops->txfree_ring_setup(_dev, _regs)
280 #define mtk_wed_device_reg_read(_dev, _reg) \
281 	(_dev)->ops->reg_read(_dev, _reg)
282 #define mtk_wed_device_reg_write(_dev, _reg, _val) \
283 	(_dev)->ops->reg_write(_dev, _reg, _val)
284 #define mtk_wed_device_irq_get(_dev, _mask) \
285 	(_dev)->ops->irq_get(_dev, _mask)
286 #define mtk_wed_device_irq_set_mask(_dev, _mask) \
287 	(_dev)->ops->irq_set_mask(_dev, _mask)
288 #define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs, _reset) \
289 	(_dev)->ops->rx_ring_setup(_dev, _ring, _regs, _reset)
290 #define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash) \
291 	(_dev)->ops->ppe_check(_dev, _skb, _reason, _hash)
292 #define mtk_wed_device_update_msg(_dev, _id, _msg, _len) \
293 	(_dev)->ops->msg_update(_dev, _id, _msg, _len)
294 #define mtk_wed_device_stop(_dev) (_dev)->ops->stop(_dev)
295 #define mtk_wed_device_dma_reset(_dev) (_dev)->ops->reset_dma(_dev)
296 #define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) \
297 	(_dev)->ops->setup_tc(_dev, _netdev, _type, _type_data)
298 #define mtk_wed_device_start_hw_rro(_dev, _mask, _reset) \
299 	(_dev)->ops->start_hw_rro(_dev, _mask, _reset)
300 #define mtk_wed_device_rro_rx_ring_setup(_dev, _ring, _regs) \
301 	(_dev)->ops->rro_rx_ring_setup(_dev, _ring, _regs)
302 #define mtk_wed_device_msdu_pg_rx_ring_setup(_dev, _ring, _regs) \
303 	(_dev)->ops->msdu_pg_rx_ring_setup(_dev, _ring, _regs)
304 #define mtk_wed_device_ind_rx_ring_setup(_dev, _regs) \
305 	(_dev)->ops->ind_rx_ring_setup(_dev, _regs)
306 
307 #else
mtk_wed_device_active(struct mtk_wed_device * dev)308 static inline bool mtk_wed_device_active(struct mtk_wed_device *dev)
309 {
310 	return false;
311 }
312 #define mtk_wed_device_detach(_dev) do {} while (0)
313 #define mtk_wed_device_start(_dev, _mask) do {} while (0)
314 #define mtk_wed_device_tx_ring_setup(_dev, _ring, _regs, _reset) -ENODEV
315 #define mtk_wed_device_txfree_ring_setup(_dev, _ring, _regs) -ENODEV
316 #define mtk_wed_device_reg_read(_dev, _reg) 0
317 #define mtk_wed_device_reg_write(_dev, _reg, _val) do {} while (0)
318 #define mtk_wed_device_irq_get(_dev, _mask) 0
319 #define mtk_wed_device_irq_set_mask(_dev, _mask) do {} while (0)
320 #define mtk_wed_device_rx_ring_setup(_dev, _ring, _regs, _reset) -ENODEV
321 #define mtk_wed_device_ppe_check(_dev, _skb, _reason, _hash)  do {} while (0)
322 #define mtk_wed_device_update_msg(_dev, _id, _msg, _len) -ENODEV
323 #define mtk_wed_device_stop(_dev) do {} while (0)
324 #define mtk_wed_device_dma_reset(_dev) do {} while (0)
325 #define mtk_wed_device_setup_tc(_dev, _netdev, _type, _type_data) -EOPNOTSUPP
326 #define mtk_wed_device_start_hw_rro(_dev, _mask, _reset) do {} while (0)
327 #define mtk_wed_device_rro_rx_ring_setup(_dev, _ring, _regs) -ENODEV
328 #define mtk_wed_device_msdu_pg_rx_ring_setup(_dev, _ring, _regs) -ENODEV
329 #define mtk_wed_device_ind_rx_ring_setup(_dev, _regs) -ENODEV
330 #endif
331 
332 #endif
333