Debian Codegraph @

drivers/net/wireless/ath/ath12k/ce.h

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