/* SPDX-License-Identifier: BSD-3-Clause-Clear */1/*2* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.3* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.4*/56#ifndef ATH12K_CE_H7#define ATH12K_CE_H89#define CE_COUNT_MAX 161011/* Byte swap data words */12#define CE_ATTR_BYTE_SWAP_DATA 21314/* no interrupt on copy completion */15#define CE_ATTR_DIS_INTR 81617/* Host software's Copy Engine configuration. */18#define CE_ATTR_FLAGS 01920/* Threshold to poll for tx completion in case of Interrupt disabled CE's */21#define ATH12K_CE_USAGE_THRESHOLD 322223/* Directions for interconnect pipe configuration.24* These definitions may be used during configuration and are shared25* between Host and Target.26*27* Pipe Directions are relative to the Host, so PIPEDIR_IN means28* "coming IN over air through Target to Host" as with a WiFi Rx operation.29* Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"30* as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"31* Target since things that are "PIPEDIR_OUT" are coming IN to the Target32* over the interconnect.33*/34#define PIPEDIR_NONE 035#define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */36#define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */37#define PIPEDIR_INOUT 3 /* bidirectional */38#define PIPEDIR_INOUT_H2H 4 /* bidirectional, host to host */3940/* CE address/mask */41#define CE_HOST_IE_ADDRESS 0x00A1803C42#define CE_HOST_IE_2_ADDRESS 0x00A1804043#define CE_HOST_IE_3_ADDRESS CE_HOST_IE_ADDRESS4445#define CE_HOST_IE_3_SHIFT 0xC4647#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))4849#define ATH12K_CE_RX_POST_RETRY_JIFFIES 505051struct ath12k_base;5253/* Establish a mapping between a service/direction and a pipe.54* Configuration information for a Copy Engine pipe and services.55* Passed from Host to Target through QMI message and must be in56* little endian format.57*/58struct service_to_pipe {59__le32 service_id;60__le32 pipedir;61__le32 pipenum;62};6364/* Configuration information for a Copy Engine pipe.65* Passed from Host to Target through QMI message during startup (one per CE).66*67* NOTE: Structure is shared between Host software and Target firmware!68*/69struct ce_pipe_config {70__le32 pipenum;71__le32 pipedir;72__le32 nentries;73__le32 nbytes_max;74__le32 flags;75__le32 reserved;76};7778struct ce_attr {79/* CE_ATTR_* values */80unsigned int flags;8182/* #entries in source ring - Must be a power of 2 */83unsigned int src_nentries;8485/* Max source send size for this CE.86* This is also the minimum size of a destination buffer.87*/88unsigned int src_sz_max;8990/* #entries in destination ring - Must be a power of 2 */91unsigned int dest_nentries;9293void (*recv_cb)(struct ath12k_base *ab, struct sk_buff *skb);94};9596#define CE_DESC_RING_ALIGN 89798struct ath12k_ce_ring {99/* Number of entries in this ring; must be power of 2 */100unsigned int nentries;101unsigned int nentries_mask;102103/* For dest ring, this is the next index to be processed104* by software after it was/is received into.105*106* For src ring, this is the last descriptor that was sent107* and completion processed by software.108*109* Regardless of src or dest ring, this is an invariant110* (modulo ring size):111* write index >= read index >= sw_index112*/113unsigned int sw_index;114/* cached copy */115unsigned int write_index;116117/* Start of DMA-coherent area reserved for descriptors */118/* Host address space */119void *base_addr_owner_space_unaligned;120/* CE address space */121u32 base_addr_ce_space_unaligned;122123/* Actual start of descriptors.124* Aligned to descriptor-size boundary.125* Points into reserved DMA-coherent area, above.126*/127/* Host address space */128void *base_addr_owner_space;129130/* CE address space */131u32 base_addr_ce_space;132133/* HAL ring id */134u32 hal_ring_id;135136/* keep last */137struct sk_buff *skb[];138};139140struct ath12k_ce_pipe {141struct ath12k_base *ab;142u16 pipe_num;143unsigned int attr_flags;144unsigned int buf_sz;145unsigned int rx_buf_needed;146147void (*send_cb)(struct ath12k_ce_pipe *pipe);148void (*recv_cb)(struct ath12k_base *ab, struct sk_buff *skb);149150struct tasklet_struct intr_tq;151struct ath12k_ce_ring *src_ring;152struct ath12k_ce_ring *dest_ring;153struct ath12k_ce_ring *status_ring;154u64 timestamp;155};156157struct ath12k_ce {158struct ath12k_ce_pipe ce_pipe[CE_COUNT_MAX];159/* Protects rings of all ce pipes */160spinlock_t ce_lock;161struct ath12k_hp_update_timer hp_timer[CE_COUNT_MAX];162};163164extern const struct ce_attr ath12k_host_ce_config_qcn9274[];165extern const struct ce_attr ath12k_host_ce_config_wcn7850[];166167void ath12k_ce_cleanup_pipes(struct ath12k_base *ab);168void ath12k_ce_rx_replenish_retry(struct timer_list *t);169void ath12k_ce_per_engine_service(struct ath12k_base *ab, u16 ce_id);170int ath12k_ce_send(struct ath12k_base *ab, struct sk_buff *skb, u8 pipe_id,171u16 transfer_id);172void ath12k_ce_rx_post_buf(struct ath12k_base *ab);173int ath12k_ce_init_pipes(struct ath12k_base *ab);174int ath12k_ce_alloc_pipes(struct ath12k_base *ab);175void ath12k_ce_free_pipes(struct ath12k_base *ab);176int ath12k_ce_get_attr_flags(struct ath12k_base *ab, int ce_id);177void ath12k_ce_poll_send_completed(struct ath12k_base *ab, u8 pipe_id);178int ath12k_ce_map_service_to_pipe(struct ath12k_base *ab, u16 service_id,179u8 *ul_pipe, u8 *dl_pipe);180int ath12k_ce_attr_attach(struct ath12k_base *ab);181void ath12k_ce_get_shadow_config(struct ath12k_base *ab,182u32 **shadow_cfg, u32 *shadow_cfg_len);183#endif184185186