blob: 949b1744870b3d2d50c17bdc5244a363b5c6ea43 [file] [log] [blame]
Kalle Valo5e3dd152013-06-12 20:52:10 +03001/*
2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _CE_H_
19#define _CE_H_
20
21#include "hif.h"
22
23
24/* Maximum number of Copy Engine's supported */
25#define CE_COUNT_MAX 8
26#define CE_HTT_H2T_MSG_SRC_NENTRIES 2048
27
28/* Descriptor rings must be aligned to this boundary */
29#define CE_DESC_RING_ALIGN 8
Kalle Valo5e3dd152013-06-12 20:52:10 +030030#define CE_SEND_FLAG_GATHER 0x00010000
31
32/*
33 * Copy Engine support: low-level Target-side Copy Engine API.
34 * This is a hardware access layer used by code that understands
35 * how to use copy engines.
36 */
37
Michal Kazior2aa39112013-08-27 13:08:02 +020038struct ath10k_ce_pipe;
Kalle Valo5e3dd152013-06-12 20:52:10 +030039
40
Kalle Valo5e3dd152013-06-12 20:52:10 +030041#define CE_DESC_FLAGS_GATHER (1 << 0)
42#define CE_DESC_FLAGS_BYTE_SWAP (1 << 1)
43#define CE_DESC_FLAGS_META_DATA_MASK 0xFFFC
44#define CE_DESC_FLAGS_META_DATA_LSB 3
45
46struct ce_desc {
47 __le32 addr;
48 __le16 nbytes;
49 __le16 flags; /* %CE_DESC_FLAGS_ */
50};
51
Michal Kaziord21fb952013-08-27 13:08:03 +020052struct ath10k_ce_ring {
Kalle Valo5e3dd152013-06-12 20:52:10 +030053 /* Number of entries in this ring; must be power of 2 */
54 unsigned int nentries;
55 unsigned int nentries_mask;
56
57 /*
58 * For dest ring, this is the next index to be processed
59 * by software after it was/is received into.
60 *
61 * For src ring, this is the last descriptor that was sent
62 * and completion processed by software.
63 *
64 * Regardless of src or dest ring, this is an invariant
65 * (modulo ring size):
66 * write index >= read index >= sw_index
67 */
68 unsigned int sw_index;
69 /* cached copy */
70 unsigned int write_index;
71 /*
72 * For src ring, this is the next index not yet processed by HW.
73 * This is a cached copy of the real HW index (read index), used
74 * for avoiding reading the HW index register more often than
75 * necessary.
76 * This extends the invariant:
77 * write index >= read index >= hw_index >= sw_index
78 *
79 * For dest ring, this is currently unused.
80 */
81 /* cached copy */
82 unsigned int hw_index;
83
84 /* Start of DMA-coherent area reserved for descriptors */
85 /* Host address space */
86 void *base_addr_owner_space_unaligned;
87 /* CE address space */
88 u32 base_addr_ce_space_unaligned;
89
90 /*
91 * Actual start of descriptors.
92 * Aligned to descriptor-size boundary.
93 * Points into reserved DMA-coherent area, above.
94 */
95 /* Host address space */
96 void *base_addr_owner_space;
97
98 /* CE address space */
99 u32 base_addr_ce_space;
100 /*
101 * Start of shadow copy of descriptors, within regular memory.
102 * Aligned to descriptor-size boundary.
103 */
104 void *shadow_base_unaligned;
105 struct ce_desc *shadow_base;
106
107 void **per_transfer_context;
108};
109
Michal Kazior2aa39112013-08-27 13:08:02 +0200110struct ath10k_ce_pipe {
Kalle Valo5e3dd152013-06-12 20:52:10 +0300111 struct ath10k *ar;
112 unsigned int id;
113
114 unsigned int attr_flags;
115
116 u32 ctrl_addr;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300117
Michal Kazior5440ce22013-09-03 15:09:58 +0200118 void (*send_cb)(struct ath10k_ce_pipe *);
119 void (*recv_cb)(struct ath10k_ce_pipe *);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300120
121 unsigned int src_sz_max;
Michal Kaziord21fb952013-08-27 13:08:03 +0200122 struct ath10k_ce_ring *src_ring;
123 struct ath10k_ce_ring *dest_ring;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300124};
125
Kalle Valo5e3dd152013-06-12 20:52:10 +0300126/* Copy Engine settable attributes */
127struct ce_attr;
128
129/*==================Send====================*/
130
131/* ath10k_ce_send flags */
132#define CE_SEND_FLAG_BYTE_SWAP 1
133
134/*
135 * Queue a source buffer to be sent to an anonymous destination buffer.
136 * ce - which copy engine to use
137 * buffer - address of buffer
138 * nbytes - number of bytes to send
139 * transfer_id - arbitrary ID; reflected to destination
140 * flags - CE_SEND_FLAG_* values
141 * Returns 0 on success; otherwise an error status.
142 *
143 * Note: If no flags are specified, use CE's default data swap mode.
144 *
145 * Implementation note: pushes 1 buffer to Source ring
146 */
Michal Kazior2aa39112013-08-27 13:08:02 +0200147int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300148 void *per_transfer_send_context,
149 u32 buffer,
150 unsigned int nbytes,
151 /* 14 bits */
152 unsigned int transfer_id,
153 unsigned int flags);
154
Michal Kazior2aa39112013-08-27 13:08:02 +0200155void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
Michal Kazior5440ce22013-09-03 15:09:58 +0200156 void (*send_cb)(struct ath10k_ce_pipe *),
Kalle Valo5e3dd152013-06-12 20:52:10 +0300157 int disable_interrupts);
158
Kalle Valo5e3dd152013-06-12 20:52:10 +0300159
160/*==================Recv=======================*/
161
162/*
163 * Make a buffer available to receive. The buffer must be at least of a
164 * minimal size appropriate for this copy engine (src_sz_max attribute).
165 * ce - which copy engine to use
166 * per_transfer_recv_context - context passed back to caller's recv_cb
167 * buffer - address of buffer in CE space
168 * Returns 0 on success; otherwise an error status.
169 *
170 * Implemenation note: Pushes a buffer to Dest ring.
171 */
Michal Kazior2aa39112013-08-27 13:08:02 +0200172int ath10k_ce_recv_buf_enqueue(struct ath10k_ce_pipe *ce_state,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300173 void *per_transfer_recv_context,
174 u32 buffer);
175
Michal Kazior2aa39112013-08-27 13:08:02 +0200176void ath10k_ce_recv_cb_register(struct ath10k_ce_pipe *ce_state,
Michal Kazior5440ce22013-09-03 15:09:58 +0200177 void (*recv_cb)(struct ath10k_ce_pipe *));
Kalle Valo5e3dd152013-06-12 20:52:10 +0300178
179/* recv flags */
180/* Data is byte-swapped */
181#define CE_RECV_FLAG_SWAPPED 1
182
183/*
184 * Supply data for the next completed unprocessed receive descriptor.
185 * Pops buffer from Dest ring.
186 */
Michal Kazior2aa39112013-08-27 13:08:02 +0200187int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300188 void **per_transfer_contextp,
189 u32 *bufferp,
190 unsigned int *nbytesp,
191 unsigned int *transfer_idp,
192 unsigned int *flagsp);
193/*
194 * Supply data for the next completed unprocessed send descriptor.
195 * Pops 1 completed send buffer from Source ring.
196 */
Michal Kazior2aa39112013-08-27 13:08:02 +0200197int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300198 void **per_transfer_contextp,
199 u32 *bufferp,
200 unsigned int *nbytesp,
201 unsigned int *transfer_idp);
202
203/*==================CE Engine Initialization=======================*/
204
205/* Initialize an instance of a CE */
Michal Kazior2aa39112013-08-27 13:08:02 +0200206struct ath10k_ce_pipe *ath10k_ce_init(struct ath10k *ar,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300207 unsigned int ce_id,
208 const struct ce_attr *attr);
209
210/*==================CE Engine Shutdown=======================*/
211/*
212 * Support clean shutdown by allowing the caller to revoke
213 * receive buffers. Target DMA must be stopped before using
214 * this API.
215 */
Michal Kazior2aa39112013-08-27 13:08:02 +0200216int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300217 void **per_transfer_contextp,
218 u32 *bufferp);
219
220/*
221 * Support clean shutdown by allowing the caller to cancel
222 * pending sends. Target DMA must be stopped before using
223 * this API.
224 */
Michal Kazior2aa39112013-08-27 13:08:02 +0200225int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
Kalle Valo5e3dd152013-06-12 20:52:10 +0300226 void **per_transfer_contextp,
227 u32 *bufferp,
228 unsigned int *nbytesp,
229 unsigned int *transfer_idp);
230
Michal Kazior2aa39112013-08-27 13:08:02 +0200231void ath10k_ce_deinit(struct ath10k_ce_pipe *ce_state);
Kalle Valo5e3dd152013-06-12 20:52:10 +0300232
233/*==================CE Interrupt Handlers====================*/
234void ath10k_ce_per_engine_service_any(struct ath10k *ar);
235void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
236void ath10k_ce_disable_interrupts(struct ath10k *ar);
237
238/* ce_attr.flags values */
239/* Use NonSnooping PCIe accesses? */
240#define CE_ATTR_NO_SNOOP 1
241
242/* Byte swap data words */
243#define CE_ATTR_BYTE_SWAP_DATA 2
244
245/* Swizzle descriptors? */
246#define CE_ATTR_SWIZZLE_DESCRIPTORS 4
247
248/* no interrupt on copy completion */
249#define CE_ATTR_DIS_INTR 8
250
251/* Attributes of an instance of a Copy Engine */
252struct ce_attr {
253 /* CE_ATTR_* values */
254 unsigned int flags;
255
Kalle Valo5e3dd152013-06-12 20:52:10 +0300256 /* #entries in source ring - Must be a power of 2 */
257 unsigned int src_nentries;
258
259 /*
260 * Max source send size for this CE.
261 * This is also the minimum size of a destination buffer.
262 */
263 unsigned int src_sz_max;
264
265 /* #entries in destination ring - Must be a power of 2 */
266 unsigned int dest_nentries;
Kalle Valo5e3dd152013-06-12 20:52:10 +0300267};
268
Kalle Valo5e3dd152013-06-12 20:52:10 +0300269#define SR_BA_ADDRESS 0x0000
270#define SR_SIZE_ADDRESS 0x0004
271#define DR_BA_ADDRESS 0x0008
272#define DR_SIZE_ADDRESS 0x000c
273#define CE_CMD_ADDRESS 0x0018
274
275#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MSB 17
276#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB 17
277#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK 0x00020000
278#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_SET(x) \
279 (((0 | (x)) << CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB) & \
280 CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK)
281
282#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MSB 16
283#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB 16
284#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK 0x00010000
285#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_GET(x) \
286 (((x) & CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK) >> \
287 CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB)
288#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_SET(x) \
289 (((0 | (x)) << CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB) & \
290 CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK)
291
292#define CE_CTRL1_DMAX_LENGTH_MSB 15
293#define CE_CTRL1_DMAX_LENGTH_LSB 0
294#define CE_CTRL1_DMAX_LENGTH_MASK 0x0000ffff
295#define CE_CTRL1_DMAX_LENGTH_GET(x) \
296 (((x) & CE_CTRL1_DMAX_LENGTH_MASK) >> CE_CTRL1_DMAX_LENGTH_LSB)
297#define CE_CTRL1_DMAX_LENGTH_SET(x) \
298 (((0 | (x)) << CE_CTRL1_DMAX_LENGTH_LSB) & CE_CTRL1_DMAX_LENGTH_MASK)
299
300#define CE_CTRL1_ADDRESS 0x0010
301#define CE_CTRL1_HW_MASK 0x0007ffff
302#define CE_CTRL1_SW_MASK 0x0007ffff
303#define CE_CTRL1_HW_WRITE_MASK 0x00000000
304#define CE_CTRL1_SW_WRITE_MASK 0x0007ffff
305#define CE_CTRL1_RSTMASK 0xffffffff
306#define CE_CTRL1_RESET 0x00000080
307
308#define CE_CMD_HALT_STATUS_MSB 3
309#define CE_CMD_HALT_STATUS_LSB 3
310#define CE_CMD_HALT_STATUS_MASK 0x00000008
311#define CE_CMD_HALT_STATUS_GET(x) \
312 (((x) & CE_CMD_HALT_STATUS_MASK) >> CE_CMD_HALT_STATUS_LSB)
313#define CE_CMD_HALT_STATUS_SET(x) \
314 (((0 | (x)) << CE_CMD_HALT_STATUS_LSB) & CE_CMD_HALT_STATUS_MASK)
315#define CE_CMD_HALT_STATUS_RESET 0
316#define CE_CMD_HALT_MSB 0
317#define CE_CMD_HALT_MASK 0x00000001
318
319#define HOST_IE_COPY_COMPLETE_MSB 0
320#define HOST_IE_COPY_COMPLETE_LSB 0
321#define HOST_IE_COPY_COMPLETE_MASK 0x00000001
322#define HOST_IE_COPY_COMPLETE_GET(x) \
323 (((x) & HOST_IE_COPY_COMPLETE_MASK) >> HOST_IE_COPY_COMPLETE_LSB)
324#define HOST_IE_COPY_COMPLETE_SET(x) \
325 (((0 | (x)) << HOST_IE_COPY_COMPLETE_LSB) & HOST_IE_COPY_COMPLETE_MASK)
326#define HOST_IE_COPY_COMPLETE_RESET 0
327#define HOST_IE_ADDRESS 0x002c
328
329#define HOST_IS_DST_RING_LOW_WATERMARK_MASK 0x00000010
330#define HOST_IS_DST_RING_HIGH_WATERMARK_MASK 0x00000008
331#define HOST_IS_SRC_RING_LOW_WATERMARK_MASK 0x00000004
332#define HOST_IS_SRC_RING_HIGH_WATERMARK_MASK 0x00000002
333#define HOST_IS_COPY_COMPLETE_MASK 0x00000001
334#define HOST_IS_ADDRESS 0x0030
335
336#define MISC_IE_ADDRESS 0x0034
337
338#define MISC_IS_AXI_ERR_MASK 0x00000400
339
340#define MISC_IS_DST_ADDR_ERR_MASK 0x00000200
341#define MISC_IS_SRC_LEN_ERR_MASK 0x00000100
342#define MISC_IS_DST_MAX_LEN_VIO_MASK 0x00000080
343#define MISC_IS_DST_RING_OVERFLOW_MASK 0x00000040
344#define MISC_IS_SRC_RING_OVERFLOW_MASK 0x00000020
345
346#define MISC_IS_ADDRESS 0x0038
347
348#define SR_WR_INDEX_ADDRESS 0x003c
349
350#define DST_WR_INDEX_ADDRESS 0x0040
351
352#define CURRENT_SRRI_ADDRESS 0x0044
353
354#define CURRENT_DRRI_ADDRESS 0x0048
355
356#define SRC_WATERMARK_LOW_MSB 31
357#define SRC_WATERMARK_LOW_LSB 16
358#define SRC_WATERMARK_LOW_MASK 0xffff0000
359#define SRC_WATERMARK_LOW_GET(x) \
360 (((x) & SRC_WATERMARK_LOW_MASK) >> SRC_WATERMARK_LOW_LSB)
361#define SRC_WATERMARK_LOW_SET(x) \
362 (((0 | (x)) << SRC_WATERMARK_LOW_LSB) & SRC_WATERMARK_LOW_MASK)
363#define SRC_WATERMARK_LOW_RESET 0
364#define SRC_WATERMARK_HIGH_MSB 15
365#define SRC_WATERMARK_HIGH_LSB 0
366#define SRC_WATERMARK_HIGH_MASK 0x0000ffff
367#define SRC_WATERMARK_HIGH_GET(x) \
368 (((x) & SRC_WATERMARK_HIGH_MASK) >> SRC_WATERMARK_HIGH_LSB)
369#define SRC_WATERMARK_HIGH_SET(x) \
370 (((0 | (x)) << SRC_WATERMARK_HIGH_LSB) & SRC_WATERMARK_HIGH_MASK)
371#define SRC_WATERMARK_HIGH_RESET 0
372#define SRC_WATERMARK_ADDRESS 0x004c
373
374#define DST_WATERMARK_LOW_LSB 16
375#define DST_WATERMARK_LOW_MASK 0xffff0000
376#define DST_WATERMARK_LOW_SET(x) \
377 (((0 | (x)) << DST_WATERMARK_LOW_LSB) & DST_WATERMARK_LOW_MASK)
378#define DST_WATERMARK_LOW_RESET 0
379#define DST_WATERMARK_HIGH_MSB 15
380#define DST_WATERMARK_HIGH_LSB 0
381#define DST_WATERMARK_HIGH_MASK 0x0000ffff
382#define DST_WATERMARK_HIGH_GET(x) \
383 (((x) & DST_WATERMARK_HIGH_MASK) >> DST_WATERMARK_HIGH_LSB)
384#define DST_WATERMARK_HIGH_SET(x) \
385 (((0 | (x)) << DST_WATERMARK_HIGH_LSB) & DST_WATERMARK_HIGH_MASK)
386#define DST_WATERMARK_HIGH_RESET 0
387#define DST_WATERMARK_ADDRESS 0x0050
388
389
390static inline u32 ath10k_ce_base_address(unsigned int ce_id)
391{
392 return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
393}
394
395#define CE_WATERMARK_MASK (HOST_IS_SRC_RING_LOW_WATERMARK_MASK | \
396 HOST_IS_SRC_RING_HIGH_WATERMARK_MASK | \
397 HOST_IS_DST_RING_LOW_WATERMARK_MASK | \
398 HOST_IS_DST_RING_HIGH_WATERMARK_MASK)
399
400#define CE_ERROR_MASK (MISC_IS_AXI_ERR_MASK | \
401 MISC_IS_DST_ADDR_ERR_MASK | \
402 MISC_IS_SRC_LEN_ERR_MASK | \
403 MISC_IS_DST_MAX_LEN_VIO_MASK | \
404 MISC_IS_DST_RING_OVERFLOW_MASK | \
405 MISC_IS_SRC_RING_OVERFLOW_MASK)
406
407#define CE_SRC_RING_TO_DESC(baddr, idx) \
408 (&(((struct ce_desc *)baddr)[idx]))
409
410#define CE_DEST_RING_TO_DESC(baddr, idx) \
411 (&(((struct ce_desc *)baddr)[idx]))
412
413/* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
414#define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
415 (((int)(toidx)-(int)(fromidx)) & (nentries_mask))
416
417#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
418
419#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB 8
420#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK 0x0000ff00
421#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
422 (((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
423 CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
424#define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS 0x0000
425
426#define CE_INTERRUPT_SUMMARY(ar) \
427 CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET( \
428 ath10k_pci_read32((ar), CE_WRAPPER_BASE_ADDRESS + \
429 CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS))
430
431#endif /* _CE_H_ */