18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause-Clear */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef ATH11K_CE_H 78c2ecf20Sopenharmony_ci#define ATH11K_CE_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define CE_COUNT_MAX 12 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* Byte swap data words */ 128c2ecf20Sopenharmony_ci#define CE_ATTR_BYTE_SWAP_DATA 2 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* no interrupt on copy completion */ 158c2ecf20Sopenharmony_ci#define CE_ATTR_DIS_INTR 8 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* Host software's Copy Engine configuration. */ 188c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN 198c2ecf20Sopenharmony_ci#define CE_ATTR_FLAGS CE_ATTR_BYTE_SWAP_DATA 208c2ecf20Sopenharmony_ci#else 218c2ecf20Sopenharmony_ci#define CE_ATTR_FLAGS 0 228c2ecf20Sopenharmony_ci#endif 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Threshold to poll for tx completion in case of Interrupt disabled CE's */ 258c2ecf20Sopenharmony_ci#define ATH11K_CE_USAGE_THRESHOLD 32 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_civoid ath11k_ce_byte_swap(void *mem, u32 len); 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* 308c2ecf20Sopenharmony_ci * Directions for interconnect pipe configuration. 318c2ecf20Sopenharmony_ci * These definitions may be used during configuration and are shared 328c2ecf20Sopenharmony_ci * between Host and Target. 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * Pipe Directions are relative to the Host, so PIPEDIR_IN means 358c2ecf20Sopenharmony_ci * "coming IN over air through Target to Host" as with a WiFi Rx operation. 368c2ecf20Sopenharmony_ci * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air" 378c2ecf20Sopenharmony_ci * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man" 388c2ecf20Sopenharmony_ci * Target since things that are "PIPEDIR_OUT" are coming IN to the Target 398c2ecf20Sopenharmony_ci * over the interconnect. 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_ci#define PIPEDIR_NONE 0 428c2ecf20Sopenharmony_ci#define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */ 438c2ecf20Sopenharmony_ci#define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */ 448c2ecf20Sopenharmony_ci#define PIPEDIR_INOUT 3 /* bidirectional */ 458c2ecf20Sopenharmony_ci#define PIPEDIR_INOUT_H2H 4 /* bidirectional, host to host */ 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* CE address/mask */ 488c2ecf20Sopenharmony_ci#define CE_HOST_IE_ADDRESS 0x00A1803C 498c2ecf20Sopenharmony_ci#define CE_HOST_IE_2_ADDRESS 0x00A18040 508c2ecf20Sopenharmony_ci#define CE_HOST_IE_3_ADDRESS CE_HOST_IE_ADDRESS 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define CE_HOST_IE_3_SHIFT 0xC 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask)) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define ATH11K_CE_RX_POST_RETRY_JIFFIES 50 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistruct ath11k_base; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * Establish a mapping between a service/direction and a pipe. 628c2ecf20Sopenharmony_ci * Configuration information for a Copy Engine pipe and services. 638c2ecf20Sopenharmony_ci * Passed from Host to Target through QMI message and must be in 648c2ecf20Sopenharmony_ci * little endian format. 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_cistruct service_to_pipe { 678c2ecf20Sopenharmony_ci __le32 service_id; 688c2ecf20Sopenharmony_ci __le32 pipedir; 698c2ecf20Sopenharmony_ci __le32 pipenum; 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* 738c2ecf20Sopenharmony_ci * Configuration information for a Copy Engine pipe. 748c2ecf20Sopenharmony_ci * Passed from Host to Target through QMI message during startup (one per CE). 758c2ecf20Sopenharmony_ci * 768c2ecf20Sopenharmony_ci * NOTE: Structure is shared between Host software and Target firmware! 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_cistruct ce_pipe_config { 798c2ecf20Sopenharmony_ci __le32 pipenum; 808c2ecf20Sopenharmony_ci __le32 pipedir; 818c2ecf20Sopenharmony_ci __le32 nentries; 828c2ecf20Sopenharmony_ci __le32 nbytes_max; 838c2ecf20Sopenharmony_ci __le32 flags; 848c2ecf20Sopenharmony_ci __le32 reserved; 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cistruct ce_attr { 888c2ecf20Sopenharmony_ci /* CE_ATTR_* values */ 898c2ecf20Sopenharmony_ci unsigned int flags; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci /* #entries in source ring - Must be a power of 2 */ 928c2ecf20Sopenharmony_ci unsigned int src_nentries; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci /* 958c2ecf20Sopenharmony_ci * Max source send size for this CE. 968c2ecf20Sopenharmony_ci * This is also the minimum size of a destination buffer. 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_ci unsigned int src_sz_max; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci /* #entries in destination ring - Must be a power of 2 */ 1018c2ecf20Sopenharmony_ci unsigned int dest_nentries; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci void (*recv_cb)(struct ath11k_base *, struct sk_buff *); 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define CE_DESC_RING_ALIGN 8 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistruct ath11k_ce_ring { 1098c2ecf20Sopenharmony_ci /* Number of entries in this ring; must be power of 2 */ 1108c2ecf20Sopenharmony_ci unsigned int nentries; 1118c2ecf20Sopenharmony_ci unsigned int nentries_mask; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci /* For dest ring, this is the next index to be processed 1148c2ecf20Sopenharmony_ci * by software after it was/is received into. 1158c2ecf20Sopenharmony_ci * 1168c2ecf20Sopenharmony_ci * For src ring, this is the last descriptor that was sent 1178c2ecf20Sopenharmony_ci * and completion processed by software. 1188c2ecf20Sopenharmony_ci * 1198c2ecf20Sopenharmony_ci * Regardless of src or dest ring, this is an invariant 1208c2ecf20Sopenharmony_ci * (modulo ring size): 1218c2ecf20Sopenharmony_ci * write index >= read index >= sw_index 1228c2ecf20Sopenharmony_ci */ 1238c2ecf20Sopenharmony_ci unsigned int sw_index; 1248c2ecf20Sopenharmony_ci /* cached copy */ 1258c2ecf20Sopenharmony_ci unsigned int write_index; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci /* Start of DMA-coherent area reserved for descriptors */ 1288c2ecf20Sopenharmony_ci /* Host address space */ 1298c2ecf20Sopenharmony_ci void *base_addr_owner_space_unaligned; 1308c2ecf20Sopenharmony_ci /* CE address space */ 1318c2ecf20Sopenharmony_ci u32 base_addr_ce_space_unaligned; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* Actual start of descriptors. 1348c2ecf20Sopenharmony_ci * Aligned to descriptor-size boundary. 1358c2ecf20Sopenharmony_ci * Points into reserved DMA-coherent area, above. 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ci /* Host address space */ 1388c2ecf20Sopenharmony_ci void *base_addr_owner_space; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* CE address space */ 1418c2ecf20Sopenharmony_ci u32 base_addr_ce_space; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci /* HAL ring id */ 1448c2ecf20Sopenharmony_ci u32 hal_ring_id; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci /* keep last */ 1478c2ecf20Sopenharmony_ci struct sk_buff *skb[0]; 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistruct ath11k_ce_pipe { 1518c2ecf20Sopenharmony_ci struct ath11k_base *ab; 1528c2ecf20Sopenharmony_ci u16 pipe_num; 1538c2ecf20Sopenharmony_ci unsigned int attr_flags; 1548c2ecf20Sopenharmony_ci unsigned int buf_sz; 1558c2ecf20Sopenharmony_ci unsigned int rx_buf_needed; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci void (*send_cb)(struct ath11k_ce_pipe *); 1588c2ecf20Sopenharmony_ci void (*recv_cb)(struct ath11k_base *, struct sk_buff *); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci struct tasklet_struct intr_tq; 1618c2ecf20Sopenharmony_ci struct ath11k_ce_ring *src_ring; 1628c2ecf20Sopenharmony_ci struct ath11k_ce_ring *dest_ring; 1638c2ecf20Sopenharmony_ci struct ath11k_ce_ring *status_ring; 1648c2ecf20Sopenharmony_ci u64 timestamp; 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistruct ath11k_ce { 1688c2ecf20Sopenharmony_ci struct ath11k_ce_pipe ce_pipe[CE_COUNT_MAX]; 1698c2ecf20Sopenharmony_ci /* Protects rings of all ce pipes */ 1708c2ecf20Sopenharmony_ci spinlock_t ce_lock; 1718c2ecf20Sopenharmony_ci struct ath11k_hp_update_timer hp_timer[CE_COUNT_MAX]; 1728c2ecf20Sopenharmony_ci}; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ciextern const struct ce_attr ath11k_host_ce_config_ipq8074[]; 1758c2ecf20Sopenharmony_ciextern const struct ce_attr ath11k_host_ce_config_qca6390[]; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_civoid ath11k_ce_cleanup_pipes(struct ath11k_base *ab); 1788c2ecf20Sopenharmony_civoid ath11k_ce_rx_replenish_retry(struct timer_list *t); 1798c2ecf20Sopenharmony_civoid ath11k_ce_per_engine_service(struct ath11k_base *ab, u16 ce_id); 1808c2ecf20Sopenharmony_ciint ath11k_ce_send(struct ath11k_base *ab, struct sk_buff *skb, u8 pipe_id, 1818c2ecf20Sopenharmony_ci u16 transfer_id); 1828c2ecf20Sopenharmony_civoid ath11k_ce_rx_post_buf(struct ath11k_base *ab); 1838c2ecf20Sopenharmony_ciint ath11k_ce_init_pipes(struct ath11k_base *ab); 1848c2ecf20Sopenharmony_ciint ath11k_ce_alloc_pipes(struct ath11k_base *ab); 1858c2ecf20Sopenharmony_civoid ath11k_ce_free_pipes(struct ath11k_base *ab); 1868c2ecf20Sopenharmony_ciint ath11k_ce_get_attr_flags(struct ath11k_base *ab, int ce_id); 1878c2ecf20Sopenharmony_civoid ath11k_ce_poll_send_completed(struct ath11k_base *ab, u8 pipe_id); 1888c2ecf20Sopenharmony_ciint ath11k_ce_map_service_to_pipe(struct ath11k_base *ab, u16 service_id, 1898c2ecf20Sopenharmony_ci u8 *ul_pipe, u8 *dl_pipe); 1908c2ecf20Sopenharmony_ciint ath11k_ce_attr_attach(struct ath11k_base *ab); 1918c2ecf20Sopenharmony_civoid ath11k_ce_get_shadow_config(struct ath11k_base *ab, 1928c2ecf20Sopenharmony_ci u32 **shadow_cfg, u32 *shadow_cfg_len); 1938c2ecf20Sopenharmony_ci#endif 194