162306a36Sopenharmony_ci/* SPDX-License-Identifier: ISC */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2005-2011 Atheros Communications Inc.
462306a36Sopenharmony_ci * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
562306a36Sopenharmony_ci * Copyright (c) 2018 The Linux Foundation. All rights reserved.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _CE_H_
962306a36Sopenharmony_ci#define _CE_H_
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "hif.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/* Descriptor rings must be aligned to this boundary */
1662306a36Sopenharmony_ci#define CE_DESC_RING_ALIGN	8
1762306a36Sopenharmony_ci#define CE_SEND_FLAG_GATHER	0x00010000
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/*
2062306a36Sopenharmony_ci * Copy Engine support: low-level Target-side Copy Engine API.
2162306a36Sopenharmony_ci * This is a hardware access layer used by code that understands
2262306a36Sopenharmony_ci * how to use copy engines.
2362306a36Sopenharmony_ci */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_cistruct ath10k_ce_pipe;
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#define CE_DESC_FLAGS_GATHER         (1 << 0)
2862306a36Sopenharmony_ci#define CE_DESC_FLAGS_BYTE_SWAP      (1 << 1)
2962306a36Sopenharmony_ci#define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define CE_DESC_ADDR_MASK		GENMASK_ULL(34, 0)
3262306a36Sopenharmony_ci#define CE_DESC_ADDR_HI_MASK		GENMASK(4, 0)
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* Following desc flags are used in QCA99X0 */
3562306a36Sopenharmony_ci#define CE_DESC_FLAGS_HOST_INT_DIS	(1 << 2)
3662306a36Sopenharmony_ci#define CE_DESC_FLAGS_TGT_INT_DIS	(1 << 3)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
3962306a36Sopenharmony_ci#define CE_DESC_FLAGS_META_DATA_LSB  ar->hw_values->ce_desc_meta_data_lsb
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define CE_DDR_RRI_MASK			GENMASK(15, 0)
4262306a36Sopenharmony_ci#define CE_DDR_DRRI_SHIFT		16
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cistruct ce_desc {
4562306a36Sopenharmony_ci	__le32 addr;
4662306a36Sopenharmony_ci	__le16 nbytes;
4762306a36Sopenharmony_ci	__le16 flags; /* %CE_DESC_FLAGS_ */
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cistruct ce_desc_64 {
5162306a36Sopenharmony_ci	__le64 addr;
5262306a36Sopenharmony_ci	__le16 nbytes; /* length in register map */
5362306a36Sopenharmony_ci	__le16 flags; /* fw_metadata_high */
5462306a36Sopenharmony_ci	__le32 toeplitz_hash_result;
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define CE_DESC_SIZE sizeof(struct ce_desc)
5862306a36Sopenharmony_ci#define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct ath10k_ce_ring {
6162306a36Sopenharmony_ci	/* Number of entries in this ring; must be power of 2 */
6262306a36Sopenharmony_ci	unsigned int nentries;
6362306a36Sopenharmony_ci	unsigned int nentries_mask;
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci	/*
6662306a36Sopenharmony_ci	 * For dest ring, this is the next index to be processed
6762306a36Sopenharmony_ci	 * by software after it was/is received into.
6862306a36Sopenharmony_ci	 *
6962306a36Sopenharmony_ci	 * For src ring, this is the last descriptor that was sent
7062306a36Sopenharmony_ci	 * and completion processed by software.
7162306a36Sopenharmony_ci	 *
7262306a36Sopenharmony_ci	 * Regardless of src or dest ring, this is an invariant
7362306a36Sopenharmony_ci	 * (modulo ring size):
7462306a36Sopenharmony_ci	 *     write index >= read index >= sw_index
7562306a36Sopenharmony_ci	 */
7662306a36Sopenharmony_ci	unsigned int sw_index;
7762306a36Sopenharmony_ci	/* cached copy */
7862306a36Sopenharmony_ci	unsigned int write_index;
7962306a36Sopenharmony_ci	/*
8062306a36Sopenharmony_ci	 * For src ring, this is the next index not yet processed by HW.
8162306a36Sopenharmony_ci	 * This is a cached copy of the real HW index (read index), used
8262306a36Sopenharmony_ci	 * for avoiding reading the HW index register more often than
8362306a36Sopenharmony_ci	 * necessary.
8462306a36Sopenharmony_ci	 * This extends the invariant:
8562306a36Sopenharmony_ci	 *     write index >= read index >= hw_index >= sw_index
8662306a36Sopenharmony_ci	 *
8762306a36Sopenharmony_ci	 * For dest ring, this is currently unused.
8862306a36Sopenharmony_ci	 */
8962306a36Sopenharmony_ci	/* cached copy */
9062306a36Sopenharmony_ci	unsigned int hw_index;
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci	/* Start of DMA-coherent area reserved for descriptors */
9362306a36Sopenharmony_ci	/* Host address space */
9462306a36Sopenharmony_ci	void *base_addr_owner_space_unaligned;
9562306a36Sopenharmony_ci	/* CE address space */
9662306a36Sopenharmony_ci	dma_addr_t base_addr_ce_space_unaligned;
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci	/*
9962306a36Sopenharmony_ci	 * Actual start of descriptors.
10062306a36Sopenharmony_ci	 * Aligned to descriptor-size boundary.
10162306a36Sopenharmony_ci	 * Points into reserved DMA-coherent area, above.
10262306a36Sopenharmony_ci	 */
10362306a36Sopenharmony_ci	/* Host address space */
10462306a36Sopenharmony_ci	void *base_addr_owner_space;
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci	/* CE address space */
10762306a36Sopenharmony_ci	dma_addr_t base_addr_ce_space;
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	char *shadow_base_unaligned;
11062306a36Sopenharmony_ci	struct ce_desc_64 *shadow_base;
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci	/* keep last */
11362306a36Sopenharmony_ci	void *per_transfer_context[];
11462306a36Sopenharmony_ci};
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_cistruct ath10k_ce_pipe {
11762306a36Sopenharmony_ci	struct ath10k *ar;
11862306a36Sopenharmony_ci	unsigned int id;
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	unsigned int attr_flags;
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci	u32 ctrl_addr;
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	void (*send_cb)(struct ath10k_ce_pipe *);
12562306a36Sopenharmony_ci	void (*recv_cb)(struct ath10k_ce_pipe *);
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci	unsigned int src_sz_max;
12862306a36Sopenharmony_ci	struct ath10k_ce_ring *src_ring;
12962306a36Sopenharmony_ci	struct ath10k_ce_ring *dest_ring;
13062306a36Sopenharmony_ci	const struct ath10k_ce_ops *ops;
13162306a36Sopenharmony_ci};
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci/* Copy Engine settable attributes */
13462306a36Sopenharmony_cistruct ce_attr;
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_cistruct ath10k_bus_ops {
13762306a36Sopenharmony_ci	u32 (*read32)(struct ath10k *ar, u32 offset);
13862306a36Sopenharmony_ci	void (*write32)(struct ath10k *ar, u32 offset, u32 value);
13962306a36Sopenharmony_ci	int (*get_num_banks)(struct ath10k *ar);
14062306a36Sopenharmony_ci};
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_cistatic inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
14362306a36Sopenharmony_ci{
14462306a36Sopenharmony_ci	return (struct ath10k_ce *)ar->ce_priv;
14562306a36Sopenharmony_ci}
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_cistruct ath10k_ce {
14862306a36Sopenharmony_ci	/* protects CE info */
14962306a36Sopenharmony_ci	spinlock_t ce_lock;
15062306a36Sopenharmony_ci	const struct ath10k_bus_ops *bus_ops;
15162306a36Sopenharmony_ci	struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
15262306a36Sopenharmony_ci	u32 *vaddr_rri;
15362306a36Sopenharmony_ci	dma_addr_t paddr_rri;
15462306a36Sopenharmony_ci};
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci/*==================Send====================*/
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci/* ath10k_ce_send flags */
15962306a36Sopenharmony_ci#define CE_SEND_FLAG_BYTE_SWAP 1
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci/*
16262306a36Sopenharmony_ci * Queue a source buffer to be sent to an anonymous destination buffer.
16362306a36Sopenharmony_ci *   ce         - which copy engine to use
16462306a36Sopenharmony_ci *   buffer          - address of buffer
16562306a36Sopenharmony_ci *   nbytes          - number of bytes to send
16662306a36Sopenharmony_ci *   transfer_id     - arbitrary ID; reflected to destination
16762306a36Sopenharmony_ci *   flags           - CE_SEND_FLAG_* values
16862306a36Sopenharmony_ci * Returns 0 on success; otherwise an error status.
16962306a36Sopenharmony_ci *
17062306a36Sopenharmony_ci * Note: If no flags are specified, use CE's default data swap mode.
17162306a36Sopenharmony_ci *
17262306a36Sopenharmony_ci * Implementation note: pushes 1 buffer to Source ring
17362306a36Sopenharmony_ci */
17462306a36Sopenharmony_ciint ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
17562306a36Sopenharmony_ci		   void *per_transfer_send_context,
17662306a36Sopenharmony_ci		   dma_addr_t buffer,
17762306a36Sopenharmony_ci		   unsigned int nbytes,
17862306a36Sopenharmony_ci		   /* 14 bits */
17962306a36Sopenharmony_ci		   unsigned int transfer_id,
18062306a36Sopenharmony_ci		   unsigned int flags);
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ciint ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
18362306a36Sopenharmony_ci			  void *per_transfer_context,
18462306a36Sopenharmony_ci			  dma_addr_t buffer,
18562306a36Sopenharmony_ci			  unsigned int nbytes,
18662306a36Sopenharmony_ci			  unsigned int transfer_id,
18762306a36Sopenharmony_ci			  unsigned int flags);
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_civoid __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ciint ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/*==================Recv=======================*/
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ciint __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
19662306a36Sopenharmony_ciint ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
19762306a36Sopenharmony_ci			  dma_addr_t paddr);
19862306a36Sopenharmony_civoid ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci/* recv flags */
20162306a36Sopenharmony_ci/* Data is byte-swapped */
20262306a36Sopenharmony_ci#define CE_RECV_FLAG_SWAPPED	1
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci/*
20562306a36Sopenharmony_ci * Supply data for the next completed unprocessed receive descriptor.
20662306a36Sopenharmony_ci * Pops buffer from Dest ring.
20762306a36Sopenharmony_ci */
20862306a36Sopenharmony_ciint ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
20962306a36Sopenharmony_ci				  void **per_transfer_contextp,
21062306a36Sopenharmony_ci				  unsigned int *nbytesp);
21162306a36Sopenharmony_ci/*
21262306a36Sopenharmony_ci * Supply data for the next completed unprocessed send descriptor.
21362306a36Sopenharmony_ci * Pops 1 completed send buffer from Source ring.
21462306a36Sopenharmony_ci */
21562306a36Sopenharmony_ciint ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
21662306a36Sopenharmony_ci				  void **per_transfer_contextp);
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ciint ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
21962306a36Sopenharmony_ci					 void **per_transfer_contextp);
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci/*==================CE Engine Initialization=======================*/
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ciint ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
22462306a36Sopenharmony_ci			const struct ce_attr *attr);
22562306a36Sopenharmony_civoid ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
22662306a36Sopenharmony_ciint ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
22762306a36Sopenharmony_ci			 const struct ce_attr *attr);
22862306a36Sopenharmony_civoid ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci/*==================CE Engine Shutdown=======================*/
23162306a36Sopenharmony_ci/*
23262306a36Sopenharmony_ci * Support clean shutdown by allowing the caller to revoke
23362306a36Sopenharmony_ci * receive buffers.  Target DMA must be stopped before using
23462306a36Sopenharmony_ci * this API.
23562306a36Sopenharmony_ci */
23662306a36Sopenharmony_ciint ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
23762306a36Sopenharmony_ci			       void **per_transfer_contextp,
23862306a36Sopenharmony_ci			       dma_addr_t *bufferp);
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ciint ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
24162306a36Sopenharmony_ci					 void **per_transfer_contextp,
24262306a36Sopenharmony_ci					 unsigned int *nbytesp);
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci/*
24562306a36Sopenharmony_ci * Support clean shutdown by allowing the caller to cancel
24662306a36Sopenharmony_ci * pending sends.  Target DMA must be stopped before using
24762306a36Sopenharmony_ci * this API.
24862306a36Sopenharmony_ci */
24962306a36Sopenharmony_ciint ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
25062306a36Sopenharmony_ci			       void **per_transfer_contextp,
25162306a36Sopenharmony_ci			       dma_addr_t *bufferp,
25262306a36Sopenharmony_ci			       unsigned int *nbytesp,
25362306a36Sopenharmony_ci			       unsigned int *transfer_idp);
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci/*==================CE Interrupt Handlers====================*/
25662306a36Sopenharmony_civoid ath10k_ce_per_engine_service_any(struct ath10k *ar);
25762306a36Sopenharmony_civoid ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
25862306a36Sopenharmony_civoid ath10k_ce_disable_interrupt(struct ath10k *ar, int ce_id);
25962306a36Sopenharmony_civoid ath10k_ce_disable_interrupts(struct ath10k *ar);
26062306a36Sopenharmony_civoid ath10k_ce_enable_interrupt(struct ath10k *ar, int ce_id);
26162306a36Sopenharmony_civoid ath10k_ce_enable_interrupts(struct ath10k *ar);
26262306a36Sopenharmony_civoid ath10k_ce_dump_registers(struct ath10k *ar,
26362306a36Sopenharmony_ci			      struct ath10k_fw_crash_data *crash_data);
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_civoid ath10k_ce_alloc_rri(struct ath10k *ar);
26662306a36Sopenharmony_civoid ath10k_ce_free_rri(struct ath10k *ar);
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci/* ce_attr.flags values */
26962306a36Sopenharmony_ci/* Use NonSnooping PCIe accesses? */
27062306a36Sopenharmony_ci#define CE_ATTR_NO_SNOOP		BIT(0)
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ci/* Byte swap data words */
27362306a36Sopenharmony_ci#define CE_ATTR_BYTE_SWAP_DATA		BIT(1)
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci/* Swizzle descriptors? */
27662306a36Sopenharmony_ci#define CE_ATTR_SWIZZLE_DESCRIPTORS	BIT(2)
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci/* no interrupt on copy completion */
27962306a36Sopenharmony_ci#define CE_ATTR_DIS_INTR		BIT(3)
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci/* no interrupt, only polling */
28262306a36Sopenharmony_ci#define CE_ATTR_POLL			BIT(4)
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci/* Attributes of an instance of a Copy Engine */
28562306a36Sopenharmony_cistruct ce_attr {
28662306a36Sopenharmony_ci	/* CE_ATTR_* values */
28762306a36Sopenharmony_ci	unsigned int flags;
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci	/* #entries in source ring - Must be a power of 2 */
29062306a36Sopenharmony_ci	unsigned int src_nentries;
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci	/*
29362306a36Sopenharmony_ci	 * Max source send size for this CE.
29462306a36Sopenharmony_ci	 * This is also the minimum size of a destination buffer.
29562306a36Sopenharmony_ci	 */
29662306a36Sopenharmony_ci	unsigned int src_sz_max;
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci	/* #entries in destination ring - Must be a power of 2 */
29962306a36Sopenharmony_ci	unsigned int dest_nentries;
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci	void (*send_cb)(struct ath10k_ce_pipe *);
30262306a36Sopenharmony_ci	void (*recv_cb)(struct ath10k_ce_pipe *);
30362306a36Sopenharmony_ci};
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_cistruct ath10k_ce_ops {
30662306a36Sopenharmony_ci	struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
30762306a36Sopenharmony_ci						    u32 ce_id,
30862306a36Sopenharmony_ci						    const struct ce_attr *attr);
30962306a36Sopenharmony_ci	struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
31062306a36Sopenharmony_ci						    u32 ce_id,
31162306a36Sopenharmony_ci						    const struct ce_attr *attr);
31262306a36Sopenharmony_ci	int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
31362306a36Sopenharmony_ci			      dma_addr_t paddr);
31462306a36Sopenharmony_ci	int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
31562306a36Sopenharmony_ci					     void **per_transfer_contextp,
31662306a36Sopenharmony_ci					     u32 *nbytesp);
31762306a36Sopenharmony_ci	int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
31862306a36Sopenharmony_ci				   void **per_transfer_contextp,
31962306a36Sopenharmony_ci				   dma_addr_t *nbytesp);
32062306a36Sopenharmony_ci	void (*ce_extract_desc_data)(struct ath10k *ar,
32162306a36Sopenharmony_ci				     struct ath10k_ce_ring *src_ring,
32262306a36Sopenharmony_ci				     u32 sw_index, dma_addr_t *bufferp,
32362306a36Sopenharmony_ci				     u32 *nbytesp, u32 *transfer_idp);
32462306a36Sopenharmony_ci	void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
32562306a36Sopenharmony_ci	int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
32662306a36Sopenharmony_ci			      void *per_transfer_context,
32762306a36Sopenharmony_ci			      dma_addr_t buffer, u32 nbytes,
32862306a36Sopenharmony_ci			      u32 transfer_id, u32 flags);
32962306a36Sopenharmony_ci	void (*ce_set_src_ring_base_addr_hi)(struct ath10k *ar,
33062306a36Sopenharmony_ci					     u32 ce_ctrl_addr,
33162306a36Sopenharmony_ci					     u64 addr);
33262306a36Sopenharmony_ci	void (*ce_set_dest_ring_base_addr_hi)(struct ath10k *ar,
33362306a36Sopenharmony_ci					      u32 ce_ctrl_addr,
33462306a36Sopenharmony_ci					      u64 addr);
33562306a36Sopenharmony_ci	int (*ce_completed_send_next_nolock)(struct ath10k_ce_pipe *ce_state,
33662306a36Sopenharmony_ci					     void **per_transfer_contextp);
33762306a36Sopenharmony_ci};
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_cistatic inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
34062306a36Sopenharmony_ci{
34162306a36Sopenharmony_ci	return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
34262306a36Sopenharmony_ci}
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci#define COPY_ENGINE_ID(COPY_ENGINE_BASE_ADDRESS) (((COPY_ENGINE_BASE_ADDRESS) \
34562306a36Sopenharmony_ci		- CE0_BASE_ADDRESS) / (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS))
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci#define CE_SRC_RING_TO_DESC(baddr, idx) \
34862306a36Sopenharmony_ci	(&(((struct ce_desc *)baddr)[idx]))
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci#define CE_DEST_RING_TO_DESC(baddr, idx) \
35162306a36Sopenharmony_ci	(&(((struct ce_desc *)baddr)[idx]))
35262306a36Sopenharmony_ci
35362306a36Sopenharmony_ci#define CE_SRC_RING_TO_DESC_64(baddr, idx) \
35462306a36Sopenharmony_ci	(&(((struct ce_desc_64 *)baddr)[idx]))
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ci#define CE_DEST_RING_TO_DESC_64(baddr, idx) \
35762306a36Sopenharmony_ci	(&(((struct ce_desc_64 *)baddr)[idx]))
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci/* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
36062306a36Sopenharmony_ci#define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
36162306a36Sopenharmony_ci	(((int)(toidx) - (int)(fromidx)) & (nentries_mask))
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
36462306a36Sopenharmony_ci#define CE_RING_IDX_ADD(nentries_mask, idx, num) \
36562306a36Sopenharmony_ci		(((idx) + (num)) & (nentries_mask))
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
36862306a36Sopenharmony_ci				ar->regs->ce_wrap_intr_sum_host_msi_lsb
36962306a36Sopenharmony_ci#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
37062306a36Sopenharmony_ci				ar->regs->ce_wrap_intr_sum_host_msi_mask
37162306a36Sopenharmony_ci#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
37262306a36Sopenharmony_ci	(((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
37362306a36Sopenharmony_ci		CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
37462306a36Sopenharmony_ci#define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS			0x0000
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_cistatic inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
37762306a36Sopenharmony_ci{
37862306a36Sopenharmony_ci	struct ath10k_ce *ce = ath10k_ce_priv(ar);
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ci	return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
38162306a36Sopenharmony_ci		ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
38262306a36Sopenharmony_ci		CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
38362306a36Sopenharmony_ci}
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci/* Host software's Copy Engine configuration. */
38662306a36Sopenharmony_ci#define CE_ATTR_FLAGS 0
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci/*
38962306a36Sopenharmony_ci * Configuration information for a Copy Engine pipe.
39062306a36Sopenharmony_ci * Passed from Host to Target during startup (one per CE).
39162306a36Sopenharmony_ci *
39262306a36Sopenharmony_ci * NOTE: Structure is shared between Host software and Target firmware!
39362306a36Sopenharmony_ci */
39462306a36Sopenharmony_cistruct ce_pipe_config {
39562306a36Sopenharmony_ci	__le32 pipenum;
39662306a36Sopenharmony_ci	__le32 pipedir;
39762306a36Sopenharmony_ci	__le32 nentries;
39862306a36Sopenharmony_ci	__le32 nbytes_max;
39962306a36Sopenharmony_ci	__le32 flags;
40062306a36Sopenharmony_ci	__le32 reserved;
40162306a36Sopenharmony_ci};
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci/*
40462306a36Sopenharmony_ci * Directions for interconnect pipe configuration.
40562306a36Sopenharmony_ci * These definitions may be used during configuration and are shared
40662306a36Sopenharmony_ci * between Host and Target.
40762306a36Sopenharmony_ci *
40862306a36Sopenharmony_ci * Pipe Directions are relative to the Host, so PIPEDIR_IN means
40962306a36Sopenharmony_ci * "coming IN over air through Target to Host" as with a WiFi Rx operation.
41062306a36Sopenharmony_ci * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
41162306a36Sopenharmony_ci * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
41262306a36Sopenharmony_ci * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
41362306a36Sopenharmony_ci * over the interconnect.
41462306a36Sopenharmony_ci */
41562306a36Sopenharmony_ci#define PIPEDIR_NONE    0
41662306a36Sopenharmony_ci#define PIPEDIR_IN      1  /* Target-->Host, WiFi Rx direction */
41762306a36Sopenharmony_ci#define PIPEDIR_OUT     2  /* Host->Target, WiFi Tx direction */
41862306a36Sopenharmony_ci#define PIPEDIR_INOUT   3  /* bidirectional */
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_ci/* Establish a mapping between a service/direction and a pipe. */
42162306a36Sopenharmony_cistruct ce_service_to_pipe {
42262306a36Sopenharmony_ci	__le32 service_id;
42362306a36Sopenharmony_ci	__le32 pipedir;
42462306a36Sopenharmony_ci	__le32 pipenum;
42562306a36Sopenharmony_ci};
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci#endif /* _CE_H_ */
428