/* SPDX-License-Identifier: BSD-3-Clause-Clear */1/*2* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.3* Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.4*/56#ifndef ATH11K_CE_H7#define ATH11K_CE_H89#define CE_COUNT_MAX 121011/* 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#ifdef __BIG_ENDIAN19#define CE_ATTR_FLAGS CE_ATTR_BYTE_SWAP_DATA20#else21#define CE_ATTR_FLAGS 022#endif2324/* Threshold to poll for tx completion in case of Interrupt disabled CE's */25#define ATH11K_CE_USAGE_THRESHOLD 322627void ath11k_ce_byte_swap(void *mem, u32 len);2829/*30* Directions for interconnect pipe configuration.31* These definitions may be used during configuration and are shared32* between Host and Target.33*34* Pipe Directions are relative to the Host, so PIPEDIR_IN means35* "coming IN over air through Target to Host" as with a WiFi Rx operation.36* Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"37* as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"38* Target since things that are "PIPEDIR_OUT" are coming IN to the Target39* over the interconnect.40*/41#define PIPEDIR_NONE 042#define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */43#define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */44#define PIPEDIR_INOUT 3 /* bidirectional */45#define PIPEDIR_INOUT_H2H 4 /* bidirectional, host to host */4647/* CE address/mask */48#define CE_HOST_IE_ADDRESS 0x00A1803C49#define CE_HOST_IE_2_ADDRESS 0x00A1804050#define CE_HOST_IE_3_ADDRESS CE_HOST_IE_ADDRESS5152/* CE IE registers are different for IPQ5018 */53#define CE_HOST_IPQ5018_IE_ADDRESS 0x0841804C54#define CE_HOST_IPQ5018_IE_2_ADDRESS 0x0841805055#define CE_HOST_IPQ5018_IE_3_ADDRESS CE_HOST_IPQ5018_IE_ADDRESS5657#define CE_HOST_IE_3_SHIFT 0xC5859#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))6061#define ATH11K_CE_RX_POST_RETRY_JIFFIES 506263struct ath11k_base;6465/*66* Establish a mapping between a service/direction and a pipe.67* Configuration information for a Copy Engine pipe and services.68* Passed from Host to Target through QMI message and must be in69* little endian format.70*/71struct service_to_pipe {72__le32 service_id;73__le32 pipedir;74__le32 pipenum;75};7677/*78* Configuration information for a Copy Engine pipe.79* Passed from Host to Target through QMI message during startup (one per CE).80*81* NOTE: Structure is shared between Host software and Target firmware!82*/83struct ce_pipe_config {84__le32 pipenum;85__le32 pipedir;86__le32 nentries;87__le32 nbytes_max;88__le32 flags;89__le32 reserved;90};9192struct ce_ie_addr {93u32 ie1_reg_addr;94u32 ie2_reg_addr;95u32 ie3_reg_addr;96};9798struct ce_remap {99u32 base;100u32 size;101};102103struct ce_attr {104/* CE_ATTR_* values */105unsigned int flags;106107/* #entries in source ring - Must be a power of 2 */108unsigned int src_nentries;109110/*111* Max source send size for this CE.112* This is also the minimum size of a destination buffer.113*/114unsigned int src_sz_max;115116/* #entries in destination ring - Must be a power of 2 */117unsigned int dest_nentries;118119void (*recv_cb)(struct ath11k_base *, struct sk_buff *);120void (*send_cb)(struct ath11k_base *, struct sk_buff *);121};122123#define CE_DESC_RING_ALIGN 8124125struct ath11k_ce_ring {126/* Number of entries in this ring; must be power of 2 */127unsigned int nentries;128unsigned int nentries_mask;129130/* For dest ring, this is the next index to be processed131* by software after it was/is received into.132*133* For src ring, this is the last descriptor that was sent134* and completion processed by software.135*136* Regardless of src or dest ring, this is an invariant137* (modulo ring size):138* write index >= read index >= sw_index139*/140unsigned int sw_index;141/* cached copy */142unsigned int write_index;143144/* Start of DMA-coherent area reserved for descriptors */145/* Host address space */146void *base_addr_owner_space_unaligned;147/* CE address space */148dma_addr_t base_addr_ce_space_unaligned;149150/* Actual start of descriptors.151* Aligned to descriptor-size boundary.152* Points into reserved DMA-coherent area, above.153*/154/* Host address space */155void *base_addr_owner_space;156157/* CE address space */158dma_addr_t base_addr_ce_space;159160/* HAL ring id */161u32 hal_ring_id;162163/* keep last */164struct sk_buff *skb[];165};166167struct ath11k_ce_pipe {168struct ath11k_base *ab;169u16 pipe_num;170unsigned int attr_flags;171unsigned int buf_sz;172unsigned int rx_buf_needed;173174void (*send_cb)(struct ath11k_base *, struct sk_buff *);175void (*recv_cb)(struct ath11k_base *, struct sk_buff *);176177struct tasklet_struct intr_tq;178struct ath11k_ce_ring *src_ring;179struct ath11k_ce_ring *dest_ring;180struct ath11k_ce_ring *status_ring;181u64 timestamp;182};183184struct ath11k_ce {185struct ath11k_ce_pipe ce_pipe[CE_COUNT_MAX];186/* Protects rings of all ce pipes */187spinlock_t ce_lock;188struct ath11k_hp_update_timer hp_timer[CE_COUNT_MAX];189};190191extern const struct ce_attr ath11k_host_ce_config_ipq8074[];192extern const struct ce_attr ath11k_host_ce_config_qca6390[];193extern const struct ce_attr ath11k_host_ce_config_qcn9074[];194195void ath11k_ce_cleanup_pipes(struct ath11k_base *ab);196void ath11k_ce_rx_replenish_retry(struct timer_list *t);197void ath11k_ce_per_engine_service(struct ath11k_base *ab, u16 ce_id);198int ath11k_ce_send(struct ath11k_base *ab, struct sk_buff *skb, u8 pipe_id,199u16 transfer_id);200void ath11k_ce_rx_post_buf(struct ath11k_base *ab);201int ath11k_ce_init_pipes(struct ath11k_base *ab);202int ath11k_ce_alloc_pipes(struct ath11k_base *ab);203void ath11k_ce_free_pipes(struct ath11k_base *ab);204int ath11k_ce_get_attr_flags(struct ath11k_base *ab, int ce_id);205void ath11k_ce_poll_send_completed(struct ath11k_base *ab, u8 pipe_id);206void ath11k_ce_get_shadow_config(struct ath11k_base *ab,207u32 **shadow_cfg, u32 *shadow_cfg_len);208void ath11k_ce_stop_shadow_timers(struct ath11k_base *ab);209210#endif211212213