xref: /linux/drivers/net/wireless/ath/ath12k/ce.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1d8899132SKalle Valo /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2d8899132SKalle Valo /*
3d8899132SKalle Valo  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
4*0ae57070SBaochen Qiang  * Copyright (c) 2021-2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
5d8899132SKalle Valo  */
6d8899132SKalle Valo 
7d8899132SKalle Valo #ifndef ATH12K_CE_H
8d8899132SKalle Valo #define ATH12K_CE_H
9d8899132SKalle Valo 
10d8899132SKalle Valo #define CE_COUNT_MAX 16
11d8899132SKalle Valo 
12d8899132SKalle Valo /* Byte swap data words */
13d8899132SKalle Valo #define CE_ATTR_BYTE_SWAP_DATA 2
14d8899132SKalle Valo 
15d8899132SKalle Valo /* no interrupt on copy completion */
16d8899132SKalle Valo #define CE_ATTR_DIS_INTR		8
17d8899132SKalle Valo 
18d8899132SKalle Valo /* Host software's Copy Engine configuration. */
19d8899132SKalle Valo #define CE_ATTR_FLAGS 0
20d8899132SKalle Valo 
21d8899132SKalle Valo /* Threshold to poll for tx completion in case of Interrupt disabled CE's */
22d8899132SKalle Valo #define ATH12K_CE_USAGE_THRESHOLD 32
23d8899132SKalle Valo 
24d8899132SKalle Valo /* Directions for interconnect pipe configuration.
25d8899132SKalle Valo  * These definitions may be used during configuration and are shared
26d8899132SKalle Valo  * between Host and Target.
27d8899132SKalle Valo  *
28d8899132SKalle Valo  * Pipe Directions are relative to the Host, so PIPEDIR_IN means
29d8899132SKalle Valo  * "coming IN over air through Target to Host" as with a WiFi Rx operation.
30d8899132SKalle Valo  * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
31d8899132SKalle Valo  * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
32d8899132SKalle Valo  * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
33d8899132SKalle Valo  * over the interconnect.
34d8899132SKalle Valo  */
35d8899132SKalle Valo #define PIPEDIR_NONE		0
36d8899132SKalle Valo #define PIPEDIR_IN		1 /* Target-->Host, WiFi Rx direction */
37d8899132SKalle Valo #define PIPEDIR_OUT		2 /* Host->Target, WiFi Tx direction */
38d8899132SKalle Valo #define PIPEDIR_INOUT		3 /* bidirectional */
39d8899132SKalle Valo #define PIPEDIR_INOUT_H2H	4 /* bidirectional, host to host */
40d8899132SKalle Valo 
41d8899132SKalle Valo /* CE address/mask */
42d8899132SKalle Valo #define CE_HOST_IE_ADDRESS	0x00A1803C
43d8899132SKalle Valo #define CE_HOST_IE_2_ADDRESS	0x00A18040
44d8899132SKalle Valo #define CE_HOST_IE_3_ADDRESS	CE_HOST_IE_ADDRESS
45d8899132SKalle Valo 
46d8899132SKalle Valo #define CE_HOST_IE_3_SHIFT	0xC
47d8899132SKalle Valo 
48d8899132SKalle Valo #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
49d8899132SKalle Valo 
50d8899132SKalle Valo #define ATH12K_CE_RX_POST_RETRY_JIFFIES 50
51d8899132SKalle Valo 
52d8899132SKalle Valo struct ath12k_base;
53d8899132SKalle Valo 
54d8899132SKalle Valo /* Establish a mapping between a service/direction and a pipe.
55d8899132SKalle Valo  * Configuration information for a Copy Engine pipe and services.
56d8899132SKalle Valo  * Passed from Host to Target through QMI message and must be in
57d8899132SKalle Valo  * little endian format.
58d8899132SKalle Valo  */
59d8899132SKalle Valo struct service_to_pipe {
60d8899132SKalle Valo 	__le32 service_id;
61d8899132SKalle Valo 	__le32 pipedir;
62d8899132SKalle Valo 	__le32 pipenum;
63d8899132SKalle Valo };
64d8899132SKalle Valo 
65d8899132SKalle Valo /* Configuration information for a Copy Engine pipe.
66d8899132SKalle Valo  * Passed from Host to Target through QMI message during startup (one per CE).
67d8899132SKalle Valo  *
68d8899132SKalle Valo  * NOTE: Structure is shared between Host software and Target firmware!
69d8899132SKalle Valo  */
70d8899132SKalle Valo struct ce_pipe_config {
71d8899132SKalle Valo 	__le32 pipenum;
72d8899132SKalle Valo 	__le32 pipedir;
73d8899132SKalle Valo 	__le32 nentries;
74d8899132SKalle Valo 	__le32 nbytes_max;
75d8899132SKalle Valo 	__le32 flags;
76d8899132SKalle Valo 	__le32 reserved;
77d8899132SKalle Valo };
78d8899132SKalle Valo 
79d8899132SKalle Valo struct ce_attr {
80d8899132SKalle Valo 	/* CE_ATTR_* values */
81d8899132SKalle Valo 	unsigned int flags;
82d8899132SKalle Valo 
83d8899132SKalle Valo 	/* #entries in source ring - Must be a power of 2 */
84d8899132SKalle Valo 	unsigned int src_nentries;
85d8899132SKalle Valo 
86d8899132SKalle Valo 	/* Max source send size for this CE.
87d8899132SKalle Valo 	 * This is also the minimum size of a destination buffer.
88d8899132SKalle Valo 	 */
89d8899132SKalle Valo 	unsigned int src_sz_max;
90d8899132SKalle Valo 
91d8899132SKalle Valo 	/* #entries in destination ring - Must be a power of 2 */
92d8899132SKalle Valo 	unsigned int dest_nentries;
93d8899132SKalle Valo 
94d8899132SKalle Valo 	void (*recv_cb)(struct ath12k_base *ab, struct sk_buff *skb);
95d8899132SKalle Valo };
96d8899132SKalle Valo 
97d8899132SKalle Valo #define CE_DESC_RING_ALIGN 8
98d8899132SKalle Valo 
99d8899132SKalle Valo struct ath12k_ce_ring {
100d8899132SKalle Valo 	/* Number of entries in this ring; must be power of 2 */
101d8899132SKalle Valo 	unsigned int nentries;
102d8899132SKalle Valo 	unsigned int nentries_mask;
103d8899132SKalle Valo 
104d8899132SKalle Valo 	/* For dest ring, this is the next index to be processed
105d8899132SKalle Valo 	 * by software after it was/is received into.
106d8899132SKalle Valo 	 *
107d8899132SKalle Valo 	 * For src ring, this is the last descriptor that was sent
108d8899132SKalle Valo 	 * and completion processed by software.
109d8899132SKalle Valo 	 *
110d8899132SKalle Valo 	 * Regardless of src or dest ring, this is an invariant
111d8899132SKalle Valo 	 * (modulo ring size):
112d8899132SKalle Valo 	 *     write index >= read index >= sw_index
113d8899132SKalle Valo 	 */
114d8899132SKalle Valo 	unsigned int sw_index;
115d8899132SKalle Valo 	/* cached copy */
116d8899132SKalle Valo 	unsigned int write_index;
117d8899132SKalle Valo 
118d8899132SKalle Valo 	/* Start of DMA-coherent area reserved for descriptors */
119d8899132SKalle Valo 	/* Host address space */
120d8899132SKalle Valo 	void *base_addr_owner_space_unaligned;
121d8899132SKalle Valo 	/* CE address space */
122*0ae57070SBaochen Qiang 	dma_addr_t base_addr_ce_space_unaligned;
123d8899132SKalle Valo 
124d8899132SKalle Valo 	/* Actual start of descriptors.
125d8899132SKalle Valo 	 * Aligned to descriptor-size boundary.
126d8899132SKalle Valo 	 * Points into reserved DMA-coherent area, above.
127d8899132SKalle Valo 	 */
128d8899132SKalle Valo 	/* Host address space */
129d8899132SKalle Valo 	void *base_addr_owner_space;
130d8899132SKalle Valo 
131d8899132SKalle Valo 	/* CE address space */
132*0ae57070SBaochen Qiang 	dma_addr_t base_addr_ce_space;
133d8899132SKalle Valo 
134d8899132SKalle Valo 	/* HAL ring id */
135d8899132SKalle Valo 	u32 hal_ring_id;
136d8899132SKalle Valo 
137d8899132SKalle Valo 	/* keep last */
138d8899132SKalle Valo 	struct sk_buff *skb[];
139d8899132SKalle Valo };
140d8899132SKalle Valo 
141d8899132SKalle Valo struct ath12k_ce_pipe {
142d8899132SKalle Valo 	struct ath12k_base *ab;
143d8899132SKalle Valo 	u16 pipe_num;
144d8899132SKalle Valo 	unsigned int attr_flags;
145d8899132SKalle Valo 	unsigned int buf_sz;
146d8899132SKalle Valo 	unsigned int rx_buf_needed;
147d8899132SKalle Valo 
148d8899132SKalle Valo 	void (*send_cb)(struct ath12k_ce_pipe *pipe);
149d8899132SKalle Valo 	void (*recv_cb)(struct ath12k_base *ab, struct sk_buff *skb);
150d8899132SKalle Valo 
151d8899132SKalle Valo 	struct tasklet_struct intr_tq;
152d8899132SKalle Valo 	struct ath12k_ce_ring *src_ring;
153d8899132SKalle Valo 	struct ath12k_ce_ring *dest_ring;
154d8899132SKalle Valo 	struct ath12k_ce_ring *status_ring;
155d8899132SKalle Valo 	u64 timestamp;
156d8899132SKalle Valo };
157d8899132SKalle Valo 
158d8899132SKalle Valo struct ath12k_ce {
159d8899132SKalle Valo 	struct ath12k_ce_pipe ce_pipe[CE_COUNT_MAX];
160d8899132SKalle Valo 	/* Protects rings of all ce pipes */
161d8899132SKalle Valo 	spinlock_t ce_lock;
162d8899132SKalle Valo 	struct ath12k_hp_update_timer hp_timer[CE_COUNT_MAX];
163d8899132SKalle Valo };
164d8899132SKalle Valo 
165d8899132SKalle Valo extern const struct ce_attr ath12k_host_ce_config_qcn9274[];
166d8899132SKalle Valo extern const struct ce_attr ath12k_host_ce_config_wcn7850[];
167d8899132SKalle Valo 
168d8899132SKalle Valo void ath12k_ce_cleanup_pipes(struct ath12k_base *ab);
169d8899132SKalle Valo void ath12k_ce_rx_replenish_retry(struct timer_list *t);
170d8899132SKalle Valo void ath12k_ce_per_engine_service(struct ath12k_base *ab, u16 ce_id);
171d8899132SKalle Valo int ath12k_ce_send(struct ath12k_base *ab, struct sk_buff *skb, u8 pipe_id,
172d8899132SKalle Valo 		   u16 transfer_id);
173d8899132SKalle Valo void ath12k_ce_rx_post_buf(struct ath12k_base *ab);
174d8899132SKalle Valo int ath12k_ce_init_pipes(struct ath12k_base *ab);
175d8899132SKalle Valo int ath12k_ce_alloc_pipes(struct ath12k_base *ab);
176d8899132SKalle Valo void ath12k_ce_free_pipes(struct ath12k_base *ab);
177d8899132SKalle Valo int ath12k_ce_get_attr_flags(struct ath12k_base *ab, int ce_id);
178d8899132SKalle Valo void ath12k_ce_poll_send_completed(struct ath12k_base *ab, u8 pipe_id);
179d8899132SKalle Valo void ath12k_ce_get_shadow_config(struct ath12k_base *ab,
180d8899132SKalle Valo 				 u32 **shadow_cfg, u32 *shadow_cfg_len);
181d8899132SKalle Valo #endif
182