]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/net/wireless/ath/ath10k/ce.h
ath10k: add support for shadow register for WNC3990
[linux.git] / drivers / net / wireless / ath / ath10k / ce.h
1 /*
2  * Copyright (c) 2005-2011 Atheros Communications Inc.
3  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
4  * Copyright (c) 2018 The Linux Foundation. All rights reserved.
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 #ifndef _CE_H_
20 #define _CE_H_
21
22 #include "hif.h"
23
24 #define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
25
26 /* Descriptor rings must be aligned to this boundary */
27 #define CE_DESC_RING_ALIGN      8
28 #define CE_SEND_FLAG_GATHER     0x00010000
29
30 /*
31  * Copy Engine support: low-level Target-side Copy Engine API.
32  * This is a hardware access layer used by code that understands
33  * how to use copy engines.
34  */
35
36 struct ath10k_ce_pipe;
37
38 #define CE_DESC_FLAGS_GATHER         (1 << 0)
39 #define CE_DESC_FLAGS_BYTE_SWAP      (1 << 1)
40 #define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)
41
42 #define CE_DESC_FLAGS_GET_MASK          GENMASK(4, 0)
43 #define CE_DESC_37BIT_ADDR_MASK         GENMASK_ULL(37, 0)
44
45 /* Following desc flags are used in QCA99X0 */
46 #define CE_DESC_FLAGS_HOST_INT_DIS      (1 << 2)
47 #define CE_DESC_FLAGS_TGT_INT_DIS       (1 << 3)
48
49 #define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
50 #define CE_DESC_FLAGS_META_DATA_LSB  ar->hw_values->ce_desc_meta_data_lsb
51
52 struct ce_desc {
53         __le32 addr;
54         __le16 nbytes;
55         __le16 flags; /* %CE_DESC_FLAGS_ */
56 };
57
58 struct ce_desc_64 {
59         __le64 addr;
60         __le16 nbytes; /* length in register map */
61         __le16 flags; /* fw_metadata_high */
62         __le32 toeplitz_hash_result;
63 };
64
65 #define CE_DESC_SIZE sizeof(struct ce_desc)
66 #define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)
67
68 struct ath10k_ce_ring {
69         /* Number of entries in this ring; must be power of 2 */
70         unsigned int nentries;
71         unsigned int nentries_mask;
72
73         /*
74          * For dest ring, this is the next index to be processed
75          * by software after it was/is received into.
76          *
77          * For src ring, this is the last descriptor that was sent
78          * and completion processed by software.
79          *
80          * Regardless of src or dest ring, this is an invariant
81          * (modulo ring size):
82          *     write index >= read index >= sw_index
83          */
84         unsigned int sw_index;
85         /* cached copy */
86         unsigned int write_index;
87         /*
88          * For src ring, this is the next index not yet processed by HW.
89          * This is a cached copy of the real HW index (read index), used
90          * for avoiding reading the HW index register more often than
91          * necessary.
92          * This extends the invariant:
93          *     write index >= read index >= hw_index >= sw_index
94          *
95          * For dest ring, this is currently unused.
96          */
97         /* cached copy */
98         unsigned int hw_index;
99
100         /* Start of DMA-coherent area reserved for descriptors */
101         /* Host address space */
102         void *base_addr_owner_space_unaligned;
103         /* CE address space */
104         u32 base_addr_ce_space_unaligned;
105
106         /*
107          * Actual start of descriptors.
108          * Aligned to descriptor-size boundary.
109          * Points into reserved DMA-coherent area, above.
110          */
111         /* Host address space */
112         void *base_addr_owner_space;
113
114         /* CE address space */
115         u32 base_addr_ce_space;
116
117         char *shadow_base_unaligned;
118         struct ce_desc *shadow_base;
119
120         /* keep last */
121         void *per_transfer_context[0];
122 };
123
124 struct ath10k_ce_pipe {
125         struct ath10k *ar;
126         unsigned int id;
127
128         unsigned int attr_flags;
129
130         u32 ctrl_addr;
131
132         void (*send_cb)(struct ath10k_ce_pipe *);
133         void (*recv_cb)(struct ath10k_ce_pipe *);
134
135         unsigned int src_sz_max;
136         struct ath10k_ce_ring *src_ring;
137         struct ath10k_ce_ring *dest_ring;
138         const struct ath10k_ce_ops *ops;
139 };
140
141 /* Copy Engine settable attributes */
142 struct ce_attr;
143
144 struct ath10k_bus_ops {
145         u32 (*read32)(struct ath10k *ar, u32 offset);
146         void (*write32)(struct ath10k *ar, u32 offset, u32 value);
147         int (*get_num_banks)(struct ath10k *ar);
148 };
149
150 static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
151 {
152         return (struct ath10k_ce *)ar->ce_priv;
153 }
154
155 struct ath10k_ce {
156         /* protects CE info */
157         spinlock_t ce_lock;
158         const struct ath10k_bus_ops *bus_ops;
159         struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
160 };
161
162 /*==================Send====================*/
163
164 /* ath10k_ce_send flags */
165 #define CE_SEND_FLAG_BYTE_SWAP 1
166
167 /*
168  * Queue a source buffer to be sent to an anonymous destination buffer.
169  *   ce         - which copy engine to use
170  *   buffer          - address of buffer
171  *   nbytes          - number of bytes to send
172  *   transfer_id     - arbitrary ID; reflected to destination
173  *   flags           - CE_SEND_FLAG_* values
174  * Returns 0 on success; otherwise an error status.
175  *
176  * Note: If no flags are specified, use CE's default data swap mode.
177  *
178  * Implementation note: pushes 1 buffer to Source ring
179  */
180 int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
181                    void *per_transfer_send_context,
182                    dma_addr_t buffer,
183                    unsigned int nbytes,
184                    /* 14 bits */
185                    unsigned int transfer_id,
186                    unsigned int flags);
187
188 int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
189                           void *per_transfer_context,
190                           dma_addr_t buffer,
191                           unsigned int nbytes,
192                           unsigned int transfer_id,
193                           unsigned int flags);
194
195 void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
196
197 int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
198
199 /*==================Recv=======================*/
200
201 int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
202 int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
203                           dma_addr_t paddr);
204 void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
205
206 /* recv flags */
207 /* Data is byte-swapped */
208 #define CE_RECV_FLAG_SWAPPED    1
209
210 /*
211  * Supply data for the next completed unprocessed receive descriptor.
212  * Pops buffer from Dest ring.
213  */
214 int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
215                                   void **per_transfer_contextp,
216                                   unsigned int *nbytesp);
217 /*
218  * Supply data for the next completed unprocessed send descriptor.
219  * Pops 1 completed send buffer from Source ring.
220  */
221 int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
222                                   void **per_transfer_contextp);
223
224 int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
225                                          void **per_transfer_contextp);
226
227 /*==================CE Engine Initialization=======================*/
228
229 int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
230                         const struct ce_attr *attr);
231 void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
232 int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
233                          const struct ce_attr *attr);
234 void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
235
236 /*==================CE Engine Shutdown=======================*/
237 /*
238  * Support clean shutdown by allowing the caller to revoke
239  * receive buffers.  Target DMA must be stopped before using
240  * this API.
241  */
242 int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
243                                void **per_transfer_contextp,
244                                dma_addr_t *bufferp);
245
246 int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
247                                          void **per_transfer_contextp,
248                                          unsigned int *nbytesp);
249
250 /*
251  * Support clean shutdown by allowing the caller to cancel
252  * pending sends.  Target DMA must be stopped before using
253  * this API.
254  */
255 int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
256                                void **per_transfer_contextp,
257                                dma_addr_t *bufferp,
258                                unsigned int *nbytesp,
259                                unsigned int *transfer_idp);
260
261 /*==================CE Interrupt Handlers====================*/
262 void ath10k_ce_per_engine_service_any(struct ath10k *ar);
263 void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
264 int ath10k_ce_disable_interrupts(struct ath10k *ar);
265 void ath10k_ce_enable_interrupts(struct ath10k *ar);
266 void ath10k_ce_dump_registers(struct ath10k *ar,
267                               struct ath10k_fw_crash_data *crash_data);
268
269 /* ce_attr.flags values */
270 /* Use NonSnooping PCIe accesses? */
271 #define CE_ATTR_NO_SNOOP                1
272
273 /* Byte swap data words */
274 #define CE_ATTR_BYTE_SWAP_DATA          2
275
276 /* Swizzle descriptors? */
277 #define CE_ATTR_SWIZZLE_DESCRIPTORS     4
278
279 /* no interrupt on copy completion */
280 #define CE_ATTR_DIS_INTR                8
281
282 /* Attributes of an instance of a Copy Engine */
283 struct ce_attr {
284         /* CE_ATTR_* values */
285         unsigned int flags;
286
287         /* #entries in source ring - Must be a power of 2 */
288         unsigned int src_nentries;
289
290         /*
291          * Max source send size for this CE.
292          * This is also the minimum size of a destination buffer.
293          */
294         unsigned int src_sz_max;
295
296         /* #entries in destination ring - Must be a power of 2 */
297         unsigned int dest_nentries;
298
299         void (*send_cb)(struct ath10k_ce_pipe *);
300         void (*recv_cb)(struct ath10k_ce_pipe *);
301 };
302
303 struct ath10k_ce_ops {
304         struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
305                                                     u32 ce_id,
306                                                     const struct ce_attr *attr);
307         struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
308                                                     u32 ce_id,
309                                                     const struct ce_attr *attr);
310         int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
311                               dma_addr_t paddr);
312         int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
313                                              void **per_transfer_contextp,
314                                              u32 *nbytesp);
315         int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
316                                    void **per_transfer_contextp,
317                                    dma_addr_t *nbytesp);
318         void (*ce_extract_desc_data)(struct ath10k *ar,
319                                      struct ath10k_ce_ring *src_ring,
320                                      u32 sw_index, dma_addr_t *bufferp,
321                                      u32 *nbytesp, u32 *transfer_idp);
322         void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
323         int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
324                               void *per_transfer_context,
325                               dma_addr_t buffer, u32 nbytes,
326                               u32 transfer_id, u32 flags);
327 };
328
329 static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
330 {
331         return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
332 }
333
334 #define CE_SRC_RING_TO_DESC(baddr, idx) \
335         (&(((struct ce_desc *)baddr)[idx]))
336
337 #define CE_DEST_RING_TO_DESC(baddr, idx) \
338         (&(((struct ce_desc *)baddr)[idx]))
339
340 #define CE_SRC_RING_TO_DESC_64(baddr, idx) \
341         (&(((struct ce_desc_64 *)baddr)[idx]))
342
343 #define CE_DEST_RING_TO_DESC_64(baddr, idx) \
344         (&(((struct ce_desc_64 *)baddr)[idx]))
345
346 /* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
347 #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
348         (((int)(toidx) - (int)(fromidx)) & (nentries_mask))
349
350 #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
351 #define CE_RING_IDX_ADD(nentries_mask, idx, num) \
352                 (((idx) + (num)) & (nentries_mask))
353
354 #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
355                                 ar->regs->ce_wrap_intr_sum_host_msi_lsb
356 #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
357                                 ar->regs->ce_wrap_intr_sum_host_msi_mask
358 #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
359         (((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
360                 CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
361 #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS                    0x0000
362 #define CE_INTERRUPT_SUMMARY            (GENMASK(CE_COUNT_MAX - 1, 0))
363
364 static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
365 {
366         struct ath10k_ce *ce = ath10k_ce_priv(ar);
367
368         if (!ar->hw_params.per_ce_irq)
369                 return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
370                         ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
371                         CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
372         else
373                 return CE_INTERRUPT_SUMMARY;
374 }
375
376 #endif /* _CE_H_ */