xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/ath/ath10k/ce.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: ISC */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2005-2011 Atheros Communications Inc.
4*4882a593Smuzhiyun  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5*4882a593Smuzhiyun  * Copyright (c) 2018 The Linux Foundation. All rights reserved.
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef _CE_H_
9*4882a593Smuzhiyun #define _CE_H_
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include "hif.h"
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /* Descriptor rings must be aligned to this boundary */
16*4882a593Smuzhiyun #define CE_DESC_RING_ALIGN	8
17*4882a593Smuzhiyun #define CE_SEND_FLAG_GATHER	0x00010000
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun /*
20*4882a593Smuzhiyun  * Copy Engine support: low-level Target-side Copy Engine API.
21*4882a593Smuzhiyun  * This is a hardware access layer used by code that understands
22*4882a593Smuzhiyun  * how to use copy engines.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun struct ath10k_ce_pipe;
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #define CE_DESC_FLAGS_GATHER         (1 << 0)
28*4882a593Smuzhiyun #define CE_DESC_FLAGS_BYTE_SWAP      (1 << 1)
29*4882a593Smuzhiyun #define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #define CE_DESC_ADDR_MASK		GENMASK_ULL(34, 0)
32*4882a593Smuzhiyun #define CE_DESC_ADDR_HI_MASK		GENMASK(4, 0)
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* Following desc flags are used in QCA99X0 */
35*4882a593Smuzhiyun #define CE_DESC_FLAGS_HOST_INT_DIS	(1 << 2)
36*4882a593Smuzhiyun #define CE_DESC_FLAGS_TGT_INT_DIS	(1 << 3)
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
39*4882a593Smuzhiyun #define CE_DESC_FLAGS_META_DATA_LSB  ar->hw_values->ce_desc_meta_data_lsb
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #define CE_DDR_RRI_MASK			GENMASK(15, 0)
42*4882a593Smuzhiyun #define CE_DDR_DRRI_SHIFT		16
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun struct ce_desc {
45*4882a593Smuzhiyun 	__le32 addr;
46*4882a593Smuzhiyun 	__le16 nbytes;
47*4882a593Smuzhiyun 	__le16 flags; /* %CE_DESC_FLAGS_ */
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun struct ce_desc_64 {
51*4882a593Smuzhiyun 	__le64 addr;
52*4882a593Smuzhiyun 	__le16 nbytes; /* length in register map */
53*4882a593Smuzhiyun 	__le16 flags; /* fw_metadata_high */
54*4882a593Smuzhiyun 	__le32 toeplitz_hash_result;
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun #define CE_DESC_SIZE sizeof(struct ce_desc)
58*4882a593Smuzhiyun #define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun struct ath10k_ce_ring {
61*4882a593Smuzhiyun 	/* Number of entries in this ring; must be power of 2 */
62*4882a593Smuzhiyun 	unsigned int nentries;
63*4882a593Smuzhiyun 	unsigned int nentries_mask;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	/*
66*4882a593Smuzhiyun 	 * For dest ring, this is the next index to be processed
67*4882a593Smuzhiyun 	 * by software after it was/is received into.
68*4882a593Smuzhiyun 	 *
69*4882a593Smuzhiyun 	 * For src ring, this is the last descriptor that was sent
70*4882a593Smuzhiyun 	 * and completion processed by software.
71*4882a593Smuzhiyun 	 *
72*4882a593Smuzhiyun 	 * Regardless of src or dest ring, this is an invariant
73*4882a593Smuzhiyun 	 * (modulo ring size):
74*4882a593Smuzhiyun 	 *     write index >= read index >= sw_index
75*4882a593Smuzhiyun 	 */
76*4882a593Smuzhiyun 	unsigned int sw_index;
77*4882a593Smuzhiyun 	/* cached copy */
78*4882a593Smuzhiyun 	unsigned int write_index;
79*4882a593Smuzhiyun 	/*
80*4882a593Smuzhiyun 	 * For src ring, this is the next index not yet processed by HW.
81*4882a593Smuzhiyun 	 * This is a cached copy of the real HW index (read index), used
82*4882a593Smuzhiyun 	 * for avoiding reading the HW index register more often than
83*4882a593Smuzhiyun 	 * necessary.
84*4882a593Smuzhiyun 	 * This extends the invariant:
85*4882a593Smuzhiyun 	 *     write index >= read index >= hw_index >= sw_index
86*4882a593Smuzhiyun 	 *
87*4882a593Smuzhiyun 	 * For dest ring, this is currently unused.
88*4882a593Smuzhiyun 	 */
89*4882a593Smuzhiyun 	/* cached copy */
90*4882a593Smuzhiyun 	unsigned int hw_index;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 	/* Start of DMA-coherent area reserved for descriptors */
93*4882a593Smuzhiyun 	/* Host address space */
94*4882a593Smuzhiyun 	void *base_addr_owner_space_unaligned;
95*4882a593Smuzhiyun 	/* CE address space */
96*4882a593Smuzhiyun 	dma_addr_t base_addr_ce_space_unaligned;
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	/*
99*4882a593Smuzhiyun 	 * Actual start of descriptors.
100*4882a593Smuzhiyun 	 * Aligned to descriptor-size boundary.
101*4882a593Smuzhiyun 	 * Points into reserved DMA-coherent area, above.
102*4882a593Smuzhiyun 	 */
103*4882a593Smuzhiyun 	/* Host address space */
104*4882a593Smuzhiyun 	void *base_addr_owner_space;
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun 	/* CE address space */
107*4882a593Smuzhiyun 	dma_addr_t base_addr_ce_space;
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	char *shadow_base_unaligned;
110*4882a593Smuzhiyun 	struct ce_desc_64 *shadow_base;
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun 	/* keep last */
113*4882a593Smuzhiyun 	void *per_transfer_context[];
114*4882a593Smuzhiyun };
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun struct ath10k_ce_pipe {
117*4882a593Smuzhiyun 	struct ath10k *ar;
118*4882a593Smuzhiyun 	unsigned int id;
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	unsigned int attr_flags;
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	u32 ctrl_addr;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	void (*send_cb)(struct ath10k_ce_pipe *);
125*4882a593Smuzhiyun 	void (*recv_cb)(struct ath10k_ce_pipe *);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 	unsigned int src_sz_max;
128*4882a593Smuzhiyun 	struct ath10k_ce_ring *src_ring;
129*4882a593Smuzhiyun 	struct ath10k_ce_ring *dest_ring;
130*4882a593Smuzhiyun 	const struct ath10k_ce_ops *ops;
131*4882a593Smuzhiyun };
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /* Copy Engine settable attributes */
134*4882a593Smuzhiyun struct ce_attr;
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun struct ath10k_bus_ops {
137*4882a593Smuzhiyun 	u32 (*read32)(struct ath10k *ar, u32 offset);
138*4882a593Smuzhiyun 	void (*write32)(struct ath10k *ar, u32 offset, u32 value);
139*4882a593Smuzhiyun 	int (*get_num_banks)(struct ath10k *ar);
140*4882a593Smuzhiyun };
141*4882a593Smuzhiyun 
ath10k_ce_priv(struct ath10k * ar)142*4882a593Smuzhiyun static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun 	return (struct ath10k_ce *)ar->ce_priv;
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun struct ath10k_ce {
148*4882a593Smuzhiyun 	/* protects CE info */
149*4882a593Smuzhiyun 	spinlock_t ce_lock;
150*4882a593Smuzhiyun 	const struct ath10k_bus_ops *bus_ops;
151*4882a593Smuzhiyun 	struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
152*4882a593Smuzhiyun 	u32 *vaddr_rri;
153*4882a593Smuzhiyun 	dma_addr_t paddr_rri;
154*4882a593Smuzhiyun };
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun /*==================Send====================*/
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun /* ath10k_ce_send flags */
159*4882a593Smuzhiyun #define CE_SEND_FLAG_BYTE_SWAP 1
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun /*
162*4882a593Smuzhiyun  * Queue a source buffer to be sent to an anonymous destination buffer.
163*4882a593Smuzhiyun  *   ce         - which copy engine to use
164*4882a593Smuzhiyun  *   buffer          - address of buffer
165*4882a593Smuzhiyun  *   nbytes          - number of bytes to send
166*4882a593Smuzhiyun  *   transfer_id     - arbitrary ID; reflected to destination
167*4882a593Smuzhiyun  *   flags           - CE_SEND_FLAG_* values
168*4882a593Smuzhiyun  * Returns 0 on success; otherwise an error status.
169*4882a593Smuzhiyun  *
170*4882a593Smuzhiyun  * Note: If no flags are specified, use CE's default data swap mode.
171*4882a593Smuzhiyun  *
172*4882a593Smuzhiyun  * Implementation note: pushes 1 buffer to Source ring
173*4882a593Smuzhiyun  */
174*4882a593Smuzhiyun int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
175*4882a593Smuzhiyun 		   void *per_transfer_send_context,
176*4882a593Smuzhiyun 		   dma_addr_t buffer,
177*4882a593Smuzhiyun 		   unsigned int nbytes,
178*4882a593Smuzhiyun 		   /* 14 bits */
179*4882a593Smuzhiyun 		   unsigned int transfer_id,
180*4882a593Smuzhiyun 		   unsigned int flags);
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
183*4882a593Smuzhiyun 			  void *per_transfer_context,
184*4882a593Smuzhiyun 			  dma_addr_t buffer,
185*4882a593Smuzhiyun 			  unsigned int nbytes,
186*4882a593Smuzhiyun 			  unsigned int transfer_id,
187*4882a593Smuzhiyun 			  unsigned int flags);
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun /*==================Recv=======================*/
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
196*4882a593Smuzhiyun int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
197*4882a593Smuzhiyun 			  dma_addr_t paddr);
198*4882a593Smuzhiyun void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun /* recv flags */
201*4882a593Smuzhiyun /* Data is byte-swapped */
202*4882a593Smuzhiyun #define CE_RECV_FLAG_SWAPPED	1
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /*
205*4882a593Smuzhiyun  * Supply data for the next completed unprocessed receive descriptor.
206*4882a593Smuzhiyun  * Pops buffer from Dest ring.
207*4882a593Smuzhiyun  */
208*4882a593Smuzhiyun int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
209*4882a593Smuzhiyun 				  void **per_transfer_contextp,
210*4882a593Smuzhiyun 				  unsigned int *nbytesp);
211*4882a593Smuzhiyun /*
212*4882a593Smuzhiyun  * Supply data for the next completed unprocessed send descriptor.
213*4882a593Smuzhiyun  * Pops 1 completed send buffer from Source ring.
214*4882a593Smuzhiyun  */
215*4882a593Smuzhiyun int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
216*4882a593Smuzhiyun 				  void **per_transfer_contextp);
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
219*4882a593Smuzhiyun 					 void **per_transfer_contextp);
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun /*==================CE Engine Initialization=======================*/
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
224*4882a593Smuzhiyun 			const struct ce_attr *attr);
225*4882a593Smuzhiyun void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
226*4882a593Smuzhiyun int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
227*4882a593Smuzhiyun 			 const struct ce_attr *attr);
228*4882a593Smuzhiyun void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun /*==================CE Engine Shutdown=======================*/
231*4882a593Smuzhiyun /*
232*4882a593Smuzhiyun  * Support clean shutdown by allowing the caller to revoke
233*4882a593Smuzhiyun  * receive buffers.  Target DMA must be stopped before using
234*4882a593Smuzhiyun  * this API.
235*4882a593Smuzhiyun  */
236*4882a593Smuzhiyun int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
237*4882a593Smuzhiyun 			       void **per_transfer_contextp,
238*4882a593Smuzhiyun 			       dma_addr_t *bufferp);
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
241*4882a593Smuzhiyun 					 void **per_transfer_contextp,
242*4882a593Smuzhiyun 					 unsigned int *nbytesp);
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun /*
245*4882a593Smuzhiyun  * Support clean shutdown by allowing the caller to cancel
246*4882a593Smuzhiyun  * pending sends.  Target DMA must be stopped before using
247*4882a593Smuzhiyun  * this API.
248*4882a593Smuzhiyun  */
249*4882a593Smuzhiyun int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
250*4882a593Smuzhiyun 			       void **per_transfer_contextp,
251*4882a593Smuzhiyun 			       dma_addr_t *bufferp,
252*4882a593Smuzhiyun 			       unsigned int *nbytesp,
253*4882a593Smuzhiyun 			       unsigned int *transfer_idp);
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun /*==================CE Interrupt Handlers====================*/
256*4882a593Smuzhiyun void ath10k_ce_per_engine_service_any(struct ath10k *ar);
257*4882a593Smuzhiyun void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
258*4882a593Smuzhiyun void ath10k_ce_disable_interrupt(struct ath10k *ar, int ce_id);
259*4882a593Smuzhiyun void ath10k_ce_disable_interrupts(struct ath10k *ar);
260*4882a593Smuzhiyun void ath10k_ce_enable_interrupt(struct ath10k *ar, int ce_id);
261*4882a593Smuzhiyun void ath10k_ce_enable_interrupts(struct ath10k *ar);
262*4882a593Smuzhiyun void ath10k_ce_dump_registers(struct ath10k *ar,
263*4882a593Smuzhiyun 			      struct ath10k_fw_crash_data *crash_data);
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun void ath10k_ce_alloc_rri(struct ath10k *ar);
266*4882a593Smuzhiyun void ath10k_ce_free_rri(struct ath10k *ar);
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun /* ce_attr.flags values */
269*4882a593Smuzhiyun /* Use NonSnooping PCIe accesses? */
270*4882a593Smuzhiyun #define CE_ATTR_NO_SNOOP		BIT(0)
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun /* Byte swap data words */
273*4882a593Smuzhiyun #define CE_ATTR_BYTE_SWAP_DATA		BIT(1)
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /* Swizzle descriptors? */
276*4882a593Smuzhiyun #define CE_ATTR_SWIZZLE_DESCRIPTORS	BIT(2)
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun /* no interrupt on copy completion */
279*4882a593Smuzhiyun #define CE_ATTR_DIS_INTR		BIT(3)
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun /* no interrupt, only polling */
282*4882a593Smuzhiyun #define CE_ATTR_POLL			BIT(4)
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun /* Attributes of an instance of a Copy Engine */
285*4882a593Smuzhiyun struct ce_attr {
286*4882a593Smuzhiyun 	/* CE_ATTR_* values */
287*4882a593Smuzhiyun 	unsigned int flags;
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun 	/* #entries in source ring - Must be a power of 2 */
290*4882a593Smuzhiyun 	unsigned int src_nentries;
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 	/*
293*4882a593Smuzhiyun 	 * Max source send size for this CE.
294*4882a593Smuzhiyun 	 * This is also the minimum size of a destination buffer.
295*4882a593Smuzhiyun 	 */
296*4882a593Smuzhiyun 	unsigned int src_sz_max;
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 	/* #entries in destination ring - Must be a power of 2 */
299*4882a593Smuzhiyun 	unsigned int dest_nentries;
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 	void (*send_cb)(struct ath10k_ce_pipe *);
302*4882a593Smuzhiyun 	void (*recv_cb)(struct ath10k_ce_pipe *);
303*4882a593Smuzhiyun };
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun struct ath10k_ce_ops {
306*4882a593Smuzhiyun 	struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
307*4882a593Smuzhiyun 						    u32 ce_id,
308*4882a593Smuzhiyun 						    const struct ce_attr *attr);
309*4882a593Smuzhiyun 	struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
310*4882a593Smuzhiyun 						    u32 ce_id,
311*4882a593Smuzhiyun 						    const struct ce_attr *attr);
312*4882a593Smuzhiyun 	int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
313*4882a593Smuzhiyun 			      dma_addr_t paddr);
314*4882a593Smuzhiyun 	int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
315*4882a593Smuzhiyun 					     void **per_transfer_contextp,
316*4882a593Smuzhiyun 					     u32 *nbytesp);
317*4882a593Smuzhiyun 	int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
318*4882a593Smuzhiyun 				   void **per_transfer_contextp,
319*4882a593Smuzhiyun 				   dma_addr_t *nbytesp);
320*4882a593Smuzhiyun 	void (*ce_extract_desc_data)(struct ath10k *ar,
321*4882a593Smuzhiyun 				     struct ath10k_ce_ring *src_ring,
322*4882a593Smuzhiyun 				     u32 sw_index, dma_addr_t *bufferp,
323*4882a593Smuzhiyun 				     u32 *nbytesp, u32 *transfer_idp);
324*4882a593Smuzhiyun 	void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
325*4882a593Smuzhiyun 	int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
326*4882a593Smuzhiyun 			      void *per_transfer_context,
327*4882a593Smuzhiyun 			      dma_addr_t buffer, u32 nbytes,
328*4882a593Smuzhiyun 			      u32 transfer_id, u32 flags);
329*4882a593Smuzhiyun 	void (*ce_set_src_ring_base_addr_hi)(struct ath10k *ar,
330*4882a593Smuzhiyun 					     u32 ce_ctrl_addr,
331*4882a593Smuzhiyun 					     u64 addr);
332*4882a593Smuzhiyun 	void (*ce_set_dest_ring_base_addr_hi)(struct ath10k *ar,
333*4882a593Smuzhiyun 					      u32 ce_ctrl_addr,
334*4882a593Smuzhiyun 					      u64 addr);
335*4882a593Smuzhiyun 	int (*ce_completed_send_next_nolock)(struct ath10k_ce_pipe *ce_state,
336*4882a593Smuzhiyun 					     void **per_transfer_contextp);
337*4882a593Smuzhiyun };
338*4882a593Smuzhiyun 
ath10k_ce_base_address(struct ath10k * ar,unsigned int ce_id)339*4882a593Smuzhiyun static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
340*4882a593Smuzhiyun {
341*4882a593Smuzhiyun 	return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun 
344*4882a593Smuzhiyun #define COPY_ENGINE_ID(COPY_ENGINE_BASE_ADDRESS) (((COPY_ENGINE_BASE_ADDRESS) \
345*4882a593Smuzhiyun 		- CE0_BASE_ADDRESS) / (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS))
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun #define CE_SRC_RING_TO_DESC(baddr, idx) \
348*4882a593Smuzhiyun 	(&(((struct ce_desc *)baddr)[idx]))
349*4882a593Smuzhiyun 
350*4882a593Smuzhiyun #define CE_DEST_RING_TO_DESC(baddr, idx) \
351*4882a593Smuzhiyun 	(&(((struct ce_desc *)baddr)[idx]))
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun #define CE_SRC_RING_TO_DESC_64(baddr, idx) \
354*4882a593Smuzhiyun 	(&(((struct ce_desc_64 *)baddr)[idx]))
355*4882a593Smuzhiyun 
356*4882a593Smuzhiyun #define CE_DEST_RING_TO_DESC_64(baddr, idx) \
357*4882a593Smuzhiyun 	(&(((struct ce_desc_64 *)baddr)[idx]))
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun /* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
360*4882a593Smuzhiyun #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
361*4882a593Smuzhiyun 	(((int)(toidx) - (int)(fromidx)) & (nentries_mask))
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
364*4882a593Smuzhiyun #define CE_RING_IDX_ADD(nentries_mask, idx, num) \
365*4882a593Smuzhiyun 		(((idx) + (num)) & (nentries_mask))
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
368*4882a593Smuzhiyun 				ar->regs->ce_wrap_intr_sum_host_msi_lsb
369*4882a593Smuzhiyun #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
370*4882a593Smuzhiyun 				ar->regs->ce_wrap_intr_sum_host_msi_mask
371*4882a593Smuzhiyun #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
372*4882a593Smuzhiyun 	(((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
373*4882a593Smuzhiyun 		CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
374*4882a593Smuzhiyun #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS			0x0000
375*4882a593Smuzhiyun 
ath10k_ce_interrupt_summary(struct ath10k * ar)376*4882a593Smuzhiyun static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun 	struct ath10k_ce *ce = ath10k_ce_priv(ar);
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun 	return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
381*4882a593Smuzhiyun 		ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
382*4882a593Smuzhiyun 		CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun /* Host software's Copy Engine configuration. */
386*4882a593Smuzhiyun #define CE_ATTR_FLAGS 0
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun /*
389*4882a593Smuzhiyun  * Configuration information for a Copy Engine pipe.
390*4882a593Smuzhiyun  * Passed from Host to Target during startup (one per CE).
391*4882a593Smuzhiyun  *
392*4882a593Smuzhiyun  * NOTE: Structure is shared between Host software and Target firmware!
393*4882a593Smuzhiyun  */
394*4882a593Smuzhiyun struct ce_pipe_config {
395*4882a593Smuzhiyun 	__le32 pipenum;
396*4882a593Smuzhiyun 	__le32 pipedir;
397*4882a593Smuzhiyun 	__le32 nentries;
398*4882a593Smuzhiyun 	__le32 nbytes_max;
399*4882a593Smuzhiyun 	__le32 flags;
400*4882a593Smuzhiyun 	__le32 reserved;
401*4882a593Smuzhiyun };
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun /*
404*4882a593Smuzhiyun  * Directions for interconnect pipe configuration.
405*4882a593Smuzhiyun  * These definitions may be used during configuration and are shared
406*4882a593Smuzhiyun  * between Host and Target.
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  * Pipe Directions are relative to the Host, so PIPEDIR_IN means
409*4882a593Smuzhiyun  * "coming IN over air through Target to Host" as with a WiFi Rx operation.
410*4882a593Smuzhiyun  * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
411*4882a593Smuzhiyun  * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
412*4882a593Smuzhiyun  * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
413*4882a593Smuzhiyun  * over the interconnect.
414*4882a593Smuzhiyun  */
415*4882a593Smuzhiyun #define PIPEDIR_NONE    0
416*4882a593Smuzhiyun #define PIPEDIR_IN      1  /* Target-->Host, WiFi Rx direction */
417*4882a593Smuzhiyun #define PIPEDIR_OUT     2  /* Host->Target, WiFi Tx direction */
418*4882a593Smuzhiyun #define PIPEDIR_INOUT   3  /* bidirectional */
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun /* Establish a mapping between a service/direction and a pipe. */
421*4882a593Smuzhiyun struct ce_service_to_pipe {
422*4882a593Smuzhiyun 	__le32 service_id;
423*4882a593Smuzhiyun 	__le32 pipedir;
424*4882a593Smuzhiyun 	__le32 pipenum;
425*4882a593Smuzhiyun };
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun #endif /* _CE_H_ */
428