xref: /linux/drivers/net/wireless/ath/ath10k/ce.h (revision a23e1966932464e1c5226cb9ac4ce1d5fc10ba22)
1f0553ca9SKalle Valo /* SPDX-License-Identifier: ISC */
25e3dd157SKalle Valo /*
35e3dd157SKalle Valo  * Copyright (c) 2005-2011 Atheros Communications Inc.
48b1083d6SKalle Valo  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5b7ba83f7SRakesh Pillai  * Copyright (c) 2018 The Linux Foundation. All rights reserved.
65e3dd157SKalle Valo  */
75e3dd157SKalle Valo 
85e3dd157SKalle Valo #ifndef _CE_H_
95e3dd157SKalle Valo #define _CE_H_
105e3dd157SKalle Valo 
115e3dd157SKalle Valo #include "hif.h"
125e3dd157SKalle Valo 
1343c9e384SMichal Kazior #define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
145e3dd157SKalle Valo 
155e3dd157SKalle Valo /* Descriptor rings must be aligned to this boundary */
165e3dd157SKalle Valo #define CE_DESC_RING_ALIGN	8
175e3dd157SKalle Valo #define CE_SEND_FLAG_GATHER	0x00010000
185e3dd157SKalle Valo 
195e3dd157SKalle Valo /*
205e3dd157SKalle Valo  * Copy Engine support: low-level Target-side Copy Engine API.
215e3dd157SKalle Valo  * This is a hardware access layer used by code that understands
225e3dd157SKalle Valo  * how to use copy engines.
235e3dd157SKalle Valo  */
245e3dd157SKalle Valo 
252aa39115SMichal Kazior struct ath10k_ce_pipe;
265e3dd157SKalle Valo 
275e3dd157SKalle Valo #define CE_DESC_FLAGS_GATHER         (1 << 0)
285e3dd157SKalle Valo #define CE_DESC_FLAGS_BYTE_SWAP      (1 << 1)
292a1e1ad3SGovind Singh #define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)
302a1e1ad3SGovind Singh 
315b9030ceSRakesh Pillai #define CE_DESC_ADDR_MASK		GENMASK_ULL(34, 0)
325b9030ceSRakesh Pillai #define CE_DESC_ADDR_HI_MASK		GENMASK(4, 0)
332adf99caSVasanthakumar Thiagarajan 
342adf99caSVasanthakumar Thiagarajan /* Following desc flags are used in QCA99X0 */
352adf99caSVasanthakumar Thiagarajan #define CE_DESC_FLAGS_HOST_INT_DIS	(1 << 2)
362adf99caSVasanthakumar Thiagarajan #define CE_DESC_FLAGS_TGT_INT_DIS	(1 << 3)
372adf99caSVasanthakumar Thiagarajan 
382adf99caSVasanthakumar Thiagarajan #define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
392adf99caSVasanthakumar Thiagarajan #define CE_DESC_FLAGS_META_DATA_LSB  ar->hw_values->ce_desc_meta_data_lsb
405e3dd157SKalle Valo 
414945af5bSGovind Singh #define CE_DDR_RRI_MASK			GENMASK(15, 0)
424945af5bSGovind Singh #define CE_DDR_DRRI_SHIFT		16
434945af5bSGovind Singh 
445e3dd157SKalle Valo struct ce_desc {
455e3dd157SKalle Valo 	__le32 addr;
465e3dd157SKalle Valo 	__le16 nbytes;
475e3dd157SKalle Valo 	__le16 flags; /* %CE_DESC_FLAGS_ */
485e3dd157SKalle Valo };
495e3dd157SKalle Valo 
502a1e1ad3SGovind Singh struct ce_desc_64 {
512a1e1ad3SGovind Singh 	__le64 addr;
522a1e1ad3SGovind Singh 	__le16 nbytes; /* length in register map */
532a1e1ad3SGovind Singh 	__le16 flags; /* fw_metadata_high */
542a1e1ad3SGovind Singh 	__le32 toeplitz_hash_result;
552a1e1ad3SGovind Singh };
562a1e1ad3SGovind Singh 
572a1e1ad3SGovind Singh #define CE_DESC_SIZE sizeof(struct ce_desc)
582a1e1ad3SGovind Singh #define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)
592a1e1ad3SGovind Singh 
60d21fb959SMichal Kazior struct ath10k_ce_ring {
615e3dd157SKalle Valo 	/* Number of entries in this ring; must be power of 2 */
625e3dd157SKalle Valo 	unsigned int nentries;
635e3dd157SKalle Valo 	unsigned int nentries_mask;
645e3dd157SKalle Valo 
655e3dd157SKalle Valo 	/*
665e3dd157SKalle Valo 	 * For dest ring, this is the next index to be processed
675e3dd157SKalle Valo 	 * by software after it was/is received into.
685e3dd157SKalle Valo 	 *
695e3dd157SKalle Valo 	 * For src ring, this is the last descriptor that was sent
705e3dd157SKalle Valo 	 * and completion processed by software.
715e3dd157SKalle Valo 	 *
725e3dd157SKalle Valo 	 * Regardless of src or dest ring, this is an invariant
735e3dd157SKalle Valo 	 * (modulo ring size):
745e3dd157SKalle Valo 	 *     write index >= read index >= sw_index
755e3dd157SKalle Valo 	 */
765e3dd157SKalle Valo 	unsigned int sw_index;
775e3dd157SKalle Valo 	/* cached copy */
785e3dd157SKalle Valo 	unsigned int write_index;
795e3dd157SKalle Valo 	/*
805e3dd157SKalle Valo 	 * For src ring, this is the next index not yet processed by HW.
815e3dd157SKalle Valo 	 * This is a cached copy of the real HW index (read index), used
825e3dd157SKalle Valo 	 * for avoiding reading the HW index register more often than
835e3dd157SKalle Valo 	 * necessary.
845e3dd157SKalle Valo 	 * This extends the invariant:
855e3dd157SKalle Valo 	 *     write index >= read index >= hw_index >= sw_index
865e3dd157SKalle Valo 	 *
875e3dd157SKalle Valo 	 * For dest ring, this is currently unused.
885e3dd157SKalle Valo 	 */
895e3dd157SKalle Valo 	/* cached copy */
905e3dd157SKalle Valo 	unsigned int hw_index;
915e3dd157SKalle Valo 
925e3dd157SKalle Valo 	/* Start of DMA-coherent area reserved for descriptors */
935e3dd157SKalle Valo 	/* Host address space */
945e3dd157SKalle Valo 	void *base_addr_owner_space_unaligned;
955e3dd157SKalle Valo 	/* CE address space */
965b9030ceSRakesh Pillai 	dma_addr_t base_addr_ce_space_unaligned;
975e3dd157SKalle Valo 
985e3dd157SKalle Valo 	/*
995e3dd157SKalle Valo 	 * Actual start of descriptors.
1005e3dd157SKalle Valo 	 * Aligned to descriptor-size boundary.
1015e3dd157SKalle Valo 	 * Points into reserved DMA-coherent area, above.
1025e3dd157SKalle Valo 	 */
1035e3dd157SKalle Valo 	/* Host address space */
1045e3dd157SKalle Valo 	void *base_addr_owner_space;
1055e3dd157SKalle Valo 
1065e3dd157SKalle Valo 	/* CE address space */
1075b9030ceSRakesh Pillai 	dma_addr_t base_addr_ce_space;
1085e3dd157SKalle Valo 
109b7ba83f7SRakesh Pillai 	char *shadow_base_unaligned;
11018630083SRakesh Pillai 	struct ce_desc_64 *shadow_base;
111b7ba83f7SRakesh Pillai 
11225d0dbcbSMichal Kazior 	/* keep last */
1133f856f29SKees Cook 	void *per_transfer_context[] __counted_by(nentries);
1145e3dd157SKalle Valo };
1155e3dd157SKalle Valo 
1162aa39115SMichal Kazior struct ath10k_ce_pipe {
1175e3dd157SKalle Valo 	struct ath10k *ar;
1185e3dd157SKalle Valo 	unsigned int id;
1195e3dd157SKalle Valo 
1205e3dd157SKalle Valo 	unsigned int attr_flags;
1215e3dd157SKalle Valo 
1225e3dd157SKalle Valo 	u32 ctrl_addr;
1235e3dd157SKalle Valo 
1245440ce25SMichal Kazior 	void (*send_cb)(struct ath10k_ce_pipe *);
1255440ce25SMichal Kazior 	void (*recv_cb)(struct ath10k_ce_pipe *);
1265e3dd157SKalle Valo 
1275e3dd157SKalle Valo 	unsigned int src_sz_max;
128d21fb959SMichal Kazior 	struct ath10k_ce_ring *src_ring;
129d21fb959SMichal Kazior 	struct ath10k_ce_ring *dest_ring;
1302a1e1ad3SGovind Singh 	const struct ath10k_ce_ops *ops;
1315e3dd157SKalle Valo };
1325e3dd157SKalle Valo 
1335e3dd157SKalle Valo /* Copy Engine settable attributes */
1345e3dd157SKalle Valo struct ce_attr;
1355e3dd157SKalle Valo 
136641fe28aSGovind Singh struct ath10k_bus_ops {
137641fe28aSGovind Singh 	u32 (*read32)(struct ath10k *ar, u32 offset);
138641fe28aSGovind Singh 	void (*write32)(struct ath10k *ar, u32 offset, u32 value);
139641fe28aSGovind Singh 	int (*get_num_banks)(struct ath10k *ar);
140641fe28aSGovind Singh };
141641fe28aSGovind Singh 
ath10k_ce_priv(struct ath10k * ar)142641fe28aSGovind Singh static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
143641fe28aSGovind Singh {
144641fe28aSGovind Singh 	return (struct ath10k_ce *)ar->ce_priv;
145641fe28aSGovind Singh }
146641fe28aSGovind Singh 
147641fe28aSGovind Singh struct ath10k_ce {
148641fe28aSGovind Singh 	/* protects CE info */
149641fe28aSGovind Singh 	spinlock_t ce_lock;
150641fe28aSGovind Singh 	const struct ath10k_bus_ops *bus_ops;
151641fe28aSGovind Singh 	struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
1524945af5bSGovind Singh 	u32 *vaddr_rri;
1534945af5bSGovind Singh 	dma_addr_t paddr_rri;
154641fe28aSGovind Singh };
155641fe28aSGovind Singh 
1565e3dd157SKalle Valo /*==================Send====================*/
1575e3dd157SKalle Valo 
1585e3dd157SKalle Valo /* ath10k_ce_send flags */
1595e3dd157SKalle Valo #define CE_SEND_FLAG_BYTE_SWAP 1
1605e3dd157SKalle Valo 
1615e3dd157SKalle Valo /*
1625e3dd157SKalle Valo  * Queue a source buffer to be sent to an anonymous destination buffer.
1635e3dd157SKalle Valo  *   ce         - which copy engine to use
1645e3dd157SKalle Valo  *   buffer          - address of buffer
1655e3dd157SKalle Valo  *   nbytes          - number of bytes to send
1665e3dd157SKalle Valo  *   transfer_id     - arbitrary ID; reflected to destination
1675e3dd157SKalle Valo  *   flags           - CE_SEND_FLAG_* values
1685e3dd157SKalle Valo  * Returns 0 on success; otherwise an error status.
1695e3dd157SKalle Valo  *
1705e3dd157SKalle Valo  * Note: If no flags are specified, use CE's default data swap mode.
1715e3dd157SKalle Valo  *
1725e3dd157SKalle Valo  * Implementation note: pushes 1 buffer to Source ring
1735e3dd157SKalle Valo  */
1742aa39115SMichal Kazior int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
1755e3dd157SKalle Valo 		   void *per_transfer_send_context,
1765dac5f37SGovind Singh 		   dma_addr_t buffer,
1775e3dd157SKalle Valo 		   unsigned int nbytes,
1785e3dd157SKalle Valo 		   /* 14 bits */
1795e3dd157SKalle Valo 		   unsigned int transfer_id,
1805e3dd157SKalle Valo 		   unsigned int flags);
1815e3dd157SKalle Valo 
182726346fcSMichal Kazior int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
183726346fcSMichal Kazior 			  void *per_transfer_context,
1845dac5f37SGovind Singh 			  dma_addr_t buffer,
185726346fcSMichal Kazior 			  unsigned int nbytes,
186726346fcSMichal Kazior 			  unsigned int transfer_id,
187726346fcSMichal Kazior 			  unsigned int flags);
188726346fcSMichal Kazior 
18908b8aa09SMichal Kazior void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
19008b8aa09SMichal Kazior 
1913efcb3b4SMichal Kazior int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
1925e3dd157SKalle Valo 
1935e3dd157SKalle Valo /*==================Recv=======================*/
1945e3dd157SKalle Valo 
195728f95eeSMichal Kazior int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
1965dac5f37SGovind Singh int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
1975dac5f37SGovind Singh 			  dma_addr_t paddr);
198128abd09SRajkumar Manoharan void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
1995e3dd157SKalle Valo 
2005e3dd157SKalle Valo /* recv flags */
2015e3dd157SKalle Valo /* Data is byte-swapped */
2025e3dd157SKalle Valo #define CE_RECV_FLAG_SWAPPED	1
2035e3dd157SKalle Valo 
2045e3dd157SKalle Valo /*
2055e3dd157SKalle Valo  * Supply data for the next completed unprocessed receive descriptor.
2065e3dd157SKalle Valo  * Pops buffer from Dest ring.
2075e3dd157SKalle Valo  */
2082aa39115SMichal Kazior int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
2095e3dd157SKalle Valo 				  void **per_transfer_contextp,
21024d9ef5eSRajkumar Manoharan 				  unsigned int *nbytesp);
2115e3dd157SKalle Valo /*
2125e3dd157SKalle Valo  * Supply data for the next completed unprocessed send descriptor.
2135e3dd157SKalle Valo  * Pops 1 completed send buffer from Source ring.
2145e3dd157SKalle Valo  */
2152aa39115SMichal Kazior int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
216765952e4SRajkumar Manoharan 				  void **per_transfer_contextp);
2175e3dd157SKalle Valo 
218eef25405SKalle Valo int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
219765952e4SRajkumar Manoharan 					 void **per_transfer_contextp);
220eef25405SKalle Valo 
2215e3dd157SKalle Valo /*==================CE Engine Initialization=======================*/
2225e3dd157SKalle Valo 
22325d0dbcbSMichal Kazior int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
22484cbf3a7SMichal Kazior 			const struct ce_attr *attr);
22584cbf3a7SMichal Kazior void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
22684cbf3a7SMichal Kazior int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
2279d9bdbb0SRajkumar Manoharan 			 const struct ce_attr *attr);
22825d0dbcbSMichal Kazior void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
2295e3dd157SKalle Valo 
2305e3dd157SKalle Valo /*==================CE Engine Shutdown=======================*/
2315e3dd157SKalle Valo /*
2325e3dd157SKalle Valo  * Support clean shutdown by allowing the caller to revoke
2335e3dd157SKalle Valo  * receive buffers.  Target DMA must be stopped before using
2345e3dd157SKalle Valo  * this API.
2355e3dd157SKalle Valo  */
2362aa39115SMichal Kazior int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
2375e3dd157SKalle Valo 			       void **per_transfer_contextp,
2385dac5f37SGovind Singh 			       dma_addr_t *bufferp);
2395e3dd157SKalle Valo 
240eef25405SKalle Valo int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
241eef25405SKalle Valo 					 void **per_transfer_contextp,
24224d9ef5eSRajkumar Manoharan 					 unsigned int *nbytesp);
243eef25405SKalle Valo 
2445e3dd157SKalle Valo /*
2455e3dd157SKalle Valo  * Support clean shutdown by allowing the caller to cancel
2465e3dd157SKalle Valo  * pending sends.  Target DMA must be stopped before using
2475e3dd157SKalle Valo  * this API.
2485e3dd157SKalle Valo  */
2492aa39115SMichal Kazior int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
2505e3dd157SKalle Valo 			       void **per_transfer_contextp,
2515dac5f37SGovind Singh 			       dma_addr_t *bufferp,
2525e3dd157SKalle Valo 			       unsigned int *nbytesp,
2535e3dd157SKalle Valo 			       unsigned int *transfer_idp);
2545e3dd157SKalle Valo 
2555e3dd157SKalle Valo /*==================CE Interrupt Handlers====================*/
2565e3dd157SKalle Valo void ath10k_ce_per_engine_service_any(struct ath10k *ar);
2575e3dd157SKalle Valo void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
258d66d24acSDouglas Anderson void ath10k_ce_disable_interrupt(struct ath10k *ar, int ce_id);
259d66d24acSDouglas Anderson void ath10k_ce_disable_interrupts(struct ath10k *ar);
260d66d24acSDouglas Anderson void ath10k_ce_enable_interrupt(struct ath10k *ar, int ce_id);
261145cc121SMichal Kazior void ath10k_ce_enable_interrupts(struct ath10k *ar);
262c75c398bSMohammed Shafi Shajakhan void ath10k_ce_dump_registers(struct ath10k *ar,
263c75c398bSMohammed Shafi Shajakhan 			      struct ath10k_fw_crash_data *crash_data);
264b92aba35SRakesh Pillai 
2654945af5bSGovind Singh void ath10k_ce_alloc_rri(struct ath10k *ar);
2664945af5bSGovind Singh void ath10k_ce_free_rri(struct ath10k *ar);
2675e3dd157SKalle Valo 
2685e3dd157SKalle Valo /* ce_attr.flags values */
2695e3dd157SKalle Valo /* Use NonSnooping PCIe accesses? */
2709abcb937SGovind Singh #define CE_ATTR_NO_SNOOP		BIT(0)
2715e3dd157SKalle Valo 
2725e3dd157SKalle Valo /* Byte swap data words */
2739abcb937SGovind Singh #define CE_ATTR_BYTE_SWAP_DATA		BIT(1)
2745e3dd157SKalle Valo 
2755e3dd157SKalle Valo /* Swizzle descriptors? */
2769abcb937SGovind Singh #define CE_ATTR_SWIZZLE_DESCRIPTORS	BIT(2)
2775e3dd157SKalle Valo 
2785e3dd157SKalle Valo /* no interrupt on copy completion */
2799abcb937SGovind Singh #define CE_ATTR_DIS_INTR		BIT(3)
2809abcb937SGovind Singh 
2819abcb937SGovind Singh /* no interrupt, only polling */
2829abcb937SGovind Singh #define CE_ATTR_POLL			BIT(4)
2835e3dd157SKalle Valo 
2845e3dd157SKalle Valo /* Attributes of an instance of a Copy Engine */
2855e3dd157SKalle Valo struct ce_attr {
2865e3dd157SKalle Valo 	/* CE_ATTR_* values */
2875e3dd157SKalle Valo 	unsigned int flags;
2885e3dd157SKalle Valo 
2895e3dd157SKalle Valo 	/* #entries in source ring - Must be a power of 2 */
2905e3dd157SKalle Valo 	unsigned int src_nentries;
2915e3dd157SKalle Valo 
2925e3dd157SKalle Valo 	/*
2935e3dd157SKalle Valo 	 * Max source send size for this CE.
2945e3dd157SKalle Valo 	 * This is also the minimum size of a destination buffer.
2955e3dd157SKalle Valo 	 */
2965e3dd157SKalle Valo 	unsigned int src_sz_max;
2975e3dd157SKalle Valo 
2985e3dd157SKalle Valo 	/* #entries in destination ring - Must be a power of 2 */
2995e3dd157SKalle Valo 	unsigned int dest_nentries;
3000e5b2950SRajkumar Manoharan 
3010e5b2950SRajkumar Manoharan 	void (*send_cb)(struct ath10k_ce_pipe *);
3029d9bdbb0SRajkumar Manoharan 	void (*recv_cb)(struct ath10k_ce_pipe *);
3035e3dd157SKalle Valo };
3045e3dd157SKalle Valo 
3052a1e1ad3SGovind Singh struct ath10k_ce_ops {
3062a1e1ad3SGovind Singh 	struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
3072a1e1ad3SGovind Singh 						    u32 ce_id,
3082a1e1ad3SGovind Singh 						    const struct ce_attr *attr);
3092a1e1ad3SGovind Singh 	struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
3102a1e1ad3SGovind Singh 						    u32 ce_id,
3112a1e1ad3SGovind Singh 						    const struct ce_attr *attr);
3122a1e1ad3SGovind Singh 	int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
3132a1e1ad3SGovind Singh 			      dma_addr_t paddr);
3142a1e1ad3SGovind Singh 	int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
3152a1e1ad3SGovind Singh 					     void **per_transfer_contextp,
3162a1e1ad3SGovind Singh 					     u32 *nbytesp);
3172a1e1ad3SGovind Singh 	int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
3182a1e1ad3SGovind Singh 				   void **per_transfer_contextp,
3192a1e1ad3SGovind Singh 				   dma_addr_t *nbytesp);
3202a1e1ad3SGovind Singh 	void (*ce_extract_desc_data)(struct ath10k *ar,
3212a1e1ad3SGovind Singh 				     struct ath10k_ce_ring *src_ring,
3222a1e1ad3SGovind Singh 				     u32 sw_index, dma_addr_t *bufferp,
3232a1e1ad3SGovind Singh 				     u32 *nbytesp, u32 *transfer_idp);
3242a1e1ad3SGovind Singh 	void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
3252a1e1ad3SGovind Singh 	int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
3262a1e1ad3SGovind Singh 			      void *per_transfer_context,
3272a1e1ad3SGovind Singh 			      dma_addr_t buffer, u32 nbytes,
3282a1e1ad3SGovind Singh 			      u32 transfer_id, u32 flags);
3295b9030ceSRakesh Pillai 	void (*ce_set_src_ring_base_addr_hi)(struct ath10k *ar,
3305b9030ceSRakesh Pillai 					     u32 ce_ctrl_addr,
3315b9030ceSRakesh Pillai 					     u64 addr);
3325b9030ceSRakesh Pillai 	void (*ce_set_dest_ring_base_addr_hi)(struct ath10k *ar,
3335b9030ceSRakesh Pillai 					      u32 ce_ctrl_addr,
3345b9030ceSRakesh Pillai 					      u64 addr);
33502f73d3aSRakesh Pillai 	int (*ce_completed_send_next_nolock)(struct ath10k_ce_pipe *ce_state,
33602f73d3aSRakesh Pillai 					     void **per_transfer_contextp);
3372a1e1ad3SGovind Singh };
338a3e712b7SKalle Valo 
ath10k_ce_base_address(struct ath10k * ar,unsigned int ce_id)339d63955b3SMichal Kazior static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
3405e3dd157SKalle Valo {
3415e3dd157SKalle Valo 	return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
3425e3dd157SKalle Valo }
3435e3dd157SKalle Valo 
3444945af5bSGovind Singh #define COPY_ENGINE_ID(COPY_ENGINE_BASE_ADDRESS) (((COPY_ENGINE_BASE_ADDRESS) \
3454945af5bSGovind Singh 		- CE0_BASE_ADDRESS) / (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS))
3464945af5bSGovind Singh 
3475e3dd157SKalle Valo #define CE_SRC_RING_TO_DESC(baddr, idx) \
3485e3dd157SKalle Valo 	(&(((struct ce_desc *)baddr)[idx]))
3495e3dd157SKalle Valo 
3505e3dd157SKalle Valo #define CE_DEST_RING_TO_DESC(baddr, idx) \
3515e3dd157SKalle Valo 	(&(((struct ce_desc *)baddr)[idx]))
3525e3dd157SKalle Valo 
3532a1e1ad3SGovind Singh #define CE_SRC_RING_TO_DESC_64(baddr, idx) \
3542a1e1ad3SGovind Singh 	(&(((struct ce_desc_64 *)baddr)[idx]))
3552a1e1ad3SGovind Singh 
3562a1e1ad3SGovind Singh #define CE_DEST_RING_TO_DESC_64(baddr, idx) \
3572a1e1ad3SGovind Singh 	(&(((struct ce_desc_64 *)baddr)[idx]))
3582a1e1ad3SGovind Singh 
3595e3dd157SKalle Valo /* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
3605e3dd157SKalle Valo #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
3615e3dd157SKalle Valo 	(((int)(toidx) - (int)(fromidx)) & (nentries_mask))
3625e3dd157SKalle Valo 
3635e3dd157SKalle Valo #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
364128abd09SRajkumar Manoharan #define CE_RING_IDX_ADD(nentries_mask, idx, num) \
365128abd09SRajkumar Manoharan 		(((idx) + (num)) & (nentries_mask))
3665e3dd157SKalle Valo 
367a521ee98SVasanthakumar Thiagarajan #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
368a521ee98SVasanthakumar Thiagarajan 				ar->regs->ce_wrap_intr_sum_host_msi_lsb
369a521ee98SVasanthakumar Thiagarajan #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
370a521ee98SVasanthakumar Thiagarajan 				ar->regs->ce_wrap_intr_sum_host_msi_mask
3715e3dd157SKalle Valo #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
3725e3dd157SKalle Valo 	(((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
3735e3dd157SKalle Valo 		CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
3745e3dd157SKalle Valo #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS			0x0000
3755e3dd157SKalle Valo 
ath10k_ce_interrupt_summary(struct ath10k * ar)376641fe28aSGovind Singh static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
377641fe28aSGovind Singh {
378641fe28aSGovind Singh 	struct ath10k_ce *ce = ath10k_ce_priv(ar);
379641fe28aSGovind Singh 
380641fe28aSGovind Singh 	return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
381641fe28aSGovind Singh 		ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
382641fe28aSGovind Singh 		CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
383641fe28aSGovind Singh }
3845e3dd157SKalle Valo 
3858ac5fe8eSBrian Norris /* Host software's Copy Engine configuration. */
3868ac5fe8eSBrian Norris #define CE_ATTR_FLAGS 0
3878ac5fe8eSBrian Norris 
3888ac5fe8eSBrian Norris /*
3898ac5fe8eSBrian Norris  * Configuration information for a Copy Engine pipe.
3908ac5fe8eSBrian Norris  * Passed from Host to Target during startup (one per CE).
3918ac5fe8eSBrian Norris  *
3928ac5fe8eSBrian Norris  * NOTE: Structure is shared between Host software and Target firmware!
3938ac5fe8eSBrian Norris  */
3948ac5fe8eSBrian Norris struct ce_pipe_config {
3958ac5fe8eSBrian Norris 	__le32 pipenum;
3968ac5fe8eSBrian Norris 	__le32 pipedir;
3978ac5fe8eSBrian Norris 	__le32 nentries;
3988ac5fe8eSBrian Norris 	__le32 nbytes_max;
3998ac5fe8eSBrian Norris 	__le32 flags;
4008ac5fe8eSBrian Norris 	__le32 reserved;
4018ac5fe8eSBrian Norris };
4028ac5fe8eSBrian Norris 
4038ac5fe8eSBrian Norris /*
4048ac5fe8eSBrian Norris  * Directions for interconnect pipe configuration.
4058ac5fe8eSBrian Norris  * These definitions may be used during configuration and are shared
4068ac5fe8eSBrian Norris  * between Host and Target.
4078ac5fe8eSBrian Norris  *
4088ac5fe8eSBrian Norris  * Pipe Directions are relative to the Host, so PIPEDIR_IN means
4098ac5fe8eSBrian Norris  * "coming IN over air through Target to Host" as with a WiFi Rx operation.
4108ac5fe8eSBrian Norris  * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
4118ac5fe8eSBrian Norris  * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
4128ac5fe8eSBrian Norris  * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
4138ac5fe8eSBrian Norris  * over the interconnect.
4148ac5fe8eSBrian Norris  */
4158ac5fe8eSBrian Norris #define PIPEDIR_NONE    0
4168ac5fe8eSBrian Norris #define PIPEDIR_IN      1  /* Target-->Host, WiFi Rx direction */
4178ac5fe8eSBrian Norris #define PIPEDIR_OUT     2  /* Host->Target, WiFi Tx direction */
4188ac5fe8eSBrian Norris #define PIPEDIR_INOUT   3  /* bidirectional */
4198ac5fe8eSBrian Norris 
4208ac5fe8eSBrian Norris /* Establish a mapping between a service/direction and a pipe. */
421521fc37bSMaharaja Kennadyrajan struct ce_service_to_pipe {
4228ac5fe8eSBrian Norris 	__le32 service_id;
4238ac5fe8eSBrian Norris 	__le32 pipedir;
4248ac5fe8eSBrian Norris 	__le32 pipenum;
4258ac5fe8eSBrian Norris };
4268ac5fe8eSBrian Norris 
4275e3dd157SKalle Valo #endif /* _CE_H_ */
428