Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: ISC */
  2/*
  3 * Copyright (c) 2005-2011 Atheros Communications Inc.
  4 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
  5 * Copyright (c) 2018 The Linux Foundation. All rights reserved.
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#ifndef _CE_H_
  9#define _CE_H_
 10
 11#include "hif.h"
 12
 13#define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
 
 
 
 14
 15/* Descriptor rings must be aligned to this boundary */
 16#define CE_DESC_RING_ALIGN	8
 17#define CE_SEND_FLAG_GATHER	0x00010000
 18
 19/*
 20 * Copy Engine support: low-level Target-side Copy Engine API.
 21 * This is a hardware access layer used by code that understands
 22 * how to use copy engines.
 23 */
 24
 25struct ath10k_ce_pipe;
 26
 
 27#define CE_DESC_FLAGS_GATHER         (1 << 0)
 28#define CE_DESC_FLAGS_BYTE_SWAP      (1 << 1)
 29#define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)
 30
 31#define CE_DESC_ADDR_MASK		GENMASK_ULL(34, 0)
 32#define CE_DESC_ADDR_HI_MASK		GENMASK(4, 0)
 33
 34/* Following desc flags are used in QCA99X0 */
 35#define CE_DESC_FLAGS_HOST_INT_DIS	(1 << 2)
 36#define CE_DESC_FLAGS_TGT_INT_DIS	(1 << 3)
 37
 38#define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
 39#define CE_DESC_FLAGS_META_DATA_LSB  ar->hw_values->ce_desc_meta_data_lsb
 40
 41#define CE_DDR_RRI_MASK			GENMASK(15, 0)
 42#define CE_DDR_DRRI_SHIFT		16
 43
 44struct ce_desc {
 45	__le32 addr;
 46	__le16 nbytes;
 47	__le16 flags; /* %CE_DESC_FLAGS_ */
 48};
 49
 50struct ce_desc_64 {
 51	__le64 addr;
 52	__le16 nbytes; /* length in register map */
 53	__le16 flags; /* fw_metadata_high */
 54	__le32 toeplitz_hash_result;
 55};
 56
 57#define CE_DESC_SIZE sizeof(struct ce_desc)
 58#define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)
 59
 60struct ath10k_ce_ring {
 61	/* Number of entries in this ring; must be power of 2 */
 62	unsigned int nentries;
 63	unsigned int nentries_mask;
 64
 65	/*
 66	 * For dest ring, this is the next index to be processed
 67	 * by software after it was/is received into.
 68	 *
 69	 * For src ring, this is the last descriptor that was sent
 70	 * and completion processed by software.
 71	 *
 72	 * Regardless of src or dest ring, this is an invariant
 73	 * (modulo ring size):
 74	 *     write index >= read index >= sw_index
 75	 */
 76	unsigned int sw_index;
 77	/* cached copy */
 78	unsigned int write_index;
 79	/*
 80	 * For src ring, this is the next index not yet processed by HW.
 81	 * This is a cached copy of the real HW index (read index), used
 82	 * for avoiding reading the HW index register more often than
 83	 * necessary.
 84	 * This extends the invariant:
 85	 *     write index >= read index >= hw_index >= sw_index
 86	 *
 87	 * For dest ring, this is currently unused.
 88	 */
 89	/* cached copy */
 90	unsigned int hw_index;
 91
 92	/* Start of DMA-coherent area reserved for descriptors */
 93	/* Host address space */
 94	void *base_addr_owner_space_unaligned;
 95	/* CE address space */
 96	dma_addr_t base_addr_ce_space_unaligned;
 97
 98	/*
 99	 * Actual start of descriptors.
100	 * Aligned to descriptor-size boundary.
101	 * Points into reserved DMA-coherent area, above.
102	 */
103	/* Host address space */
104	void *base_addr_owner_space;
105
106	/* CE address space */
107	dma_addr_t base_addr_ce_space;
108
109	char *shadow_base_unaligned;
110	struct ce_desc_64 *shadow_base;
 
 
 
111
112	/* keep last */
113	void *per_transfer_context[] __counted_by(nentries);
114};
115
116struct ath10k_ce_pipe {
117	struct ath10k *ar;
118	unsigned int id;
119
120	unsigned int attr_flags;
121
122	u32 ctrl_addr;
123
124	void (*send_cb)(struct ath10k_ce_pipe *);
125	void (*recv_cb)(struct ath10k_ce_pipe *);
126
127	unsigned int src_sz_max;
128	struct ath10k_ce_ring *src_ring;
129	struct ath10k_ce_ring *dest_ring;
130	const struct ath10k_ce_ops *ops;
131};
132
133/* Copy Engine settable attributes */
134struct ce_attr;
135
136struct ath10k_bus_ops {
137	u32 (*read32)(struct ath10k *ar, u32 offset);
138	void (*write32)(struct ath10k *ar, u32 offset, u32 value);
139	int (*get_num_banks)(struct ath10k *ar);
140};
141
142static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
143{
144	return (struct ath10k_ce *)ar->ce_priv;
145}
146
147struct ath10k_ce {
148	/* protects CE info */
149	spinlock_t ce_lock;
150	const struct ath10k_bus_ops *bus_ops;
151	struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
152	u32 *vaddr_rri;
153	dma_addr_t paddr_rri;
154};
155
156/*==================Send====================*/
157
158/* ath10k_ce_send flags */
159#define CE_SEND_FLAG_BYTE_SWAP 1
160
161/*
162 * Queue a source buffer to be sent to an anonymous destination buffer.
163 *   ce         - which copy engine to use
164 *   buffer          - address of buffer
165 *   nbytes          - number of bytes to send
166 *   transfer_id     - arbitrary ID; reflected to destination
167 *   flags           - CE_SEND_FLAG_* values
168 * Returns 0 on success; otherwise an error status.
169 *
170 * Note: If no flags are specified, use CE's default data swap mode.
171 *
172 * Implementation note: pushes 1 buffer to Source ring
173 */
174int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
175		   void *per_transfer_send_context,
176		   dma_addr_t buffer,
177		   unsigned int nbytes,
178		   /* 14 bits */
179		   unsigned int transfer_id,
180		   unsigned int flags);
181
182int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
183			  void *per_transfer_context,
184			  dma_addr_t buffer,
185			  unsigned int nbytes,
186			  unsigned int transfer_id,
187			  unsigned int flags);
188
189void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
 
 
190
191int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
192
193/*==================Recv=======================*/
194
195int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
196int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
197			  dma_addr_t paddr);
198void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
 
 
 
 
 
 
 
 
 
 
 
 
199
200/* recv flags */
201/* Data is byte-swapped */
202#define CE_RECV_FLAG_SWAPPED	1
203
204/*
205 * Supply data for the next completed unprocessed receive descriptor.
206 * Pops buffer from Dest ring.
207 */
208int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
209				  void **per_transfer_contextp,
210				  unsigned int *nbytesp);
 
 
 
211/*
212 * Supply data for the next completed unprocessed send descriptor.
213 * Pops 1 completed send buffer from Source ring.
214 */
215int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
216				  void **per_transfer_contextp);
217
218int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
219					 void **per_transfer_contextp);
220
221/*==================CE Engine Initialization=======================*/
222
223int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
224			const struct ce_attr *attr);
225void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
226int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
227			 const struct ce_attr *attr);
228void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
229
230/*==================CE Engine Shutdown=======================*/
231/*
232 * Support clean shutdown by allowing the caller to revoke
233 * receive buffers.  Target DMA must be stopped before using
234 * this API.
235 */
236int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
237			       void **per_transfer_contextp,
238			       dma_addr_t *bufferp);
239
240int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
241					 void **per_transfer_contextp,
242					 unsigned int *nbytesp);
243
244/*
245 * Support clean shutdown by allowing the caller to cancel
246 * pending sends.  Target DMA must be stopped before using
247 * this API.
248 */
249int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
250			       void **per_transfer_contextp,
251			       dma_addr_t *bufferp,
252			       unsigned int *nbytesp,
253			       unsigned int *transfer_idp);
254
 
 
255/*==================CE Interrupt Handlers====================*/
256void ath10k_ce_per_engine_service_any(struct ath10k *ar);
257void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
258void ath10k_ce_disable_interrupt(struct ath10k *ar, int ce_id);
259void ath10k_ce_disable_interrupts(struct ath10k *ar);
260void ath10k_ce_enable_interrupt(struct ath10k *ar, int ce_id);
261void ath10k_ce_enable_interrupts(struct ath10k *ar);
262void ath10k_ce_dump_registers(struct ath10k *ar,
263			      struct ath10k_fw_crash_data *crash_data);
264
265void ath10k_ce_alloc_rri(struct ath10k *ar);
266void ath10k_ce_free_rri(struct ath10k *ar);
267
268/* ce_attr.flags values */
269/* Use NonSnooping PCIe accesses? */
270#define CE_ATTR_NO_SNOOP		BIT(0)
271
272/* Byte swap data words */
273#define CE_ATTR_BYTE_SWAP_DATA		BIT(1)
274
275/* Swizzle descriptors? */
276#define CE_ATTR_SWIZZLE_DESCRIPTORS	BIT(2)
277
278/* no interrupt on copy completion */
279#define CE_ATTR_DIS_INTR		BIT(3)
280
281/* no interrupt, only polling */
282#define CE_ATTR_POLL			BIT(4)
283
284/* Attributes of an instance of a Copy Engine */
285struct ce_attr {
286	/* CE_ATTR_* values */
287	unsigned int flags;
288
289	/* #entries in source ring - Must be a power of 2 */
290	unsigned int src_nentries;
291
292	/*
293	 * Max source send size for this CE.
294	 * This is also the minimum size of a destination buffer.
295	 */
296	unsigned int src_sz_max;
297
298	/* #entries in destination ring - Must be a power of 2 */
299	unsigned int dest_nentries;
300
301	void (*send_cb)(struct ath10k_ce_pipe *);
302	void (*recv_cb)(struct ath10k_ce_pipe *);
303};
304
305struct ath10k_ce_ops {
306	struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
307						    u32 ce_id,
308						    const struct ce_attr *attr);
309	struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
310						    u32 ce_id,
311						    const struct ce_attr *attr);
312	int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
313			      dma_addr_t paddr);
314	int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
315					     void **per_transfer_contextp,
316					     u32 *nbytesp);
317	int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
318				   void **per_transfer_contextp,
319				   dma_addr_t *nbytesp);
320	void (*ce_extract_desc_data)(struct ath10k *ar,
321				     struct ath10k_ce_ring *src_ring,
322				     u32 sw_index, dma_addr_t *bufferp,
323				     u32 *nbytesp, u32 *transfer_idp);
324	void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
325	int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
326			      void *per_transfer_context,
327			      dma_addr_t buffer, u32 nbytes,
328			      u32 transfer_id, u32 flags);
329	void (*ce_set_src_ring_base_addr_hi)(struct ath10k *ar,
330					     u32 ce_ctrl_addr,
331					     u64 addr);
332	void (*ce_set_dest_ring_base_addr_hi)(struct ath10k *ar,
333					      u32 ce_ctrl_addr,
334					      u64 addr);
335	int (*ce_completed_send_next_nolock)(struct ath10k_ce_pipe *ce_state,
336					     void **per_transfer_contextp);
337};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
339static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
340{
341	return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
342}
343
344#define COPY_ENGINE_ID(COPY_ENGINE_BASE_ADDRESS) (((COPY_ENGINE_BASE_ADDRESS) \
345		- CE0_BASE_ADDRESS) / (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS))
 
 
 
 
 
 
 
 
 
346
347#define CE_SRC_RING_TO_DESC(baddr, idx) \
348	(&(((struct ce_desc *)baddr)[idx]))
349
350#define CE_DEST_RING_TO_DESC(baddr, idx) \
351	(&(((struct ce_desc *)baddr)[idx]))
352
353#define CE_SRC_RING_TO_DESC_64(baddr, idx) \
354	(&(((struct ce_desc_64 *)baddr)[idx]))
355
356#define CE_DEST_RING_TO_DESC_64(baddr, idx) \
357	(&(((struct ce_desc_64 *)baddr)[idx]))
358
359/* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
360#define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
361	(((int)(toidx) - (int)(fromidx)) & (nentries_mask))
362
363#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
364#define CE_RING_IDX_ADD(nentries_mask, idx, num) \
365		(((idx) + (num)) & (nentries_mask))
366
367#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
368				ar->regs->ce_wrap_intr_sum_host_msi_lsb
369#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
370				ar->regs->ce_wrap_intr_sum_host_msi_mask
371#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
372	(((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
373		CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
374#define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS			0x0000
375
376static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
377{
378	struct ath10k_ce *ce = ath10k_ce_priv(ar);
379
380	return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
381		ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
382		CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
383}
384
385/* Host software's Copy Engine configuration. */
386#define CE_ATTR_FLAGS 0
387
388/*
389 * Configuration information for a Copy Engine pipe.
390 * Passed from Host to Target during startup (one per CE).
391 *
392 * NOTE: Structure is shared between Host software and Target firmware!
393 */
394struct ce_pipe_config {
395	__le32 pipenum;
396	__le32 pipedir;
397	__le32 nentries;
398	__le32 nbytes_max;
399	__le32 flags;
400	__le32 reserved;
401};
402
403/*
404 * Directions for interconnect pipe configuration.
405 * These definitions may be used during configuration and are shared
406 * between Host and Target.
407 *
408 * Pipe Directions are relative to the Host, so PIPEDIR_IN means
409 * "coming IN over air through Target to Host" as with a WiFi Rx operation.
410 * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
411 * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
412 * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
413 * over the interconnect.
414 */
415#define PIPEDIR_NONE    0
416#define PIPEDIR_IN      1  /* Target-->Host, WiFi Rx direction */
417#define PIPEDIR_OUT     2  /* Host->Target, WiFi Tx direction */
418#define PIPEDIR_INOUT   3  /* bidirectional */
419
420/* Establish a mapping between a service/direction and a pipe. */
421struct ce_service_to_pipe {
422	__le32 service_id;
423	__le32 pipedir;
424	__le32 pipenum;
425};
426
427#endif /* _CE_H_ */
v3.15
 
  1/*
  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 4096
 27
 28/* Descriptor rings must be aligned to this boundary */
 29#define CE_DESC_RING_ALIGN	8
 30#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
 38struct ath10k_ce_pipe;
 39
 40
 41#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
 
 
 
 
 
 
 
 
 
 
 52struct ath10k_ce_ring {
 53	/* 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
110struct ath10k_ce_pipe {
111	struct ath10k *ar;
112	unsigned int id;
113
114	unsigned int attr_flags;
115
116	u32 ctrl_addr;
117
118	void (*send_cb)(struct ath10k_ce_pipe *);
119	void (*recv_cb)(struct ath10k_ce_pipe *);
120
121	unsigned int src_sz_max;
122	struct ath10k_ce_ring *src_ring;
123	struct ath10k_ce_ring *dest_ring;
 
124};
125
126/* 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 */
147int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
148		   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
155int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
156			  void *per_transfer_context,
157			  u32 buffer,
158			  unsigned int nbytes,
159			  unsigned int transfer_id,
160			  unsigned int flags);
161
162void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
163				void (*send_cb)(struct ath10k_ce_pipe *),
164				int disable_interrupts);
165
166int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
167
168/*==================Recv=======================*/
169
170/*
171 * Make a buffer available to receive. The buffer must be at least of a
172 * minimal size appropriate for this copy engine (src_sz_max attribute).
173 *   ce                    - which copy engine to use
174 *   per_transfer_recv_context  - context passed back to caller's recv_cb
175 *   buffer                     - address of buffer in CE space
176 * Returns 0 on success; otherwise an error status.
177 *
178 * Implemenation note: Pushes a buffer to Dest ring.
179 */
180int ath10k_ce_recv_buf_enqueue(struct ath10k_ce_pipe *ce_state,
181			       void *per_transfer_recv_context,
182			       u32 buffer);
183
184void ath10k_ce_recv_cb_register(struct ath10k_ce_pipe *ce_state,
185				void (*recv_cb)(struct ath10k_ce_pipe *));
186
187/* recv flags */
188/* Data is byte-swapped */
189#define CE_RECV_FLAG_SWAPPED	1
190
191/*
192 * Supply data for the next completed unprocessed receive descriptor.
193 * Pops buffer from Dest ring.
194 */
195int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
196				  void **per_transfer_contextp,
197				  u32 *bufferp,
198				  unsigned int *nbytesp,
199				  unsigned int *transfer_idp,
200				  unsigned int *flagsp);
201/*
202 * Supply data for the next completed unprocessed send descriptor.
203 * Pops 1 completed send buffer from Source ring.
204 */
205int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
206			   void **per_transfer_contextp,
207			   u32 *bufferp,
208			   unsigned int *nbytesp,
209			   unsigned int *transfer_idp);
210
211/*==================CE Engine Initialization=======================*/
212
213/* Initialize an instance of a CE */
214struct ath10k_ce_pipe *ath10k_ce_init(struct ath10k *ar,
215				unsigned int ce_id,
216				const struct ce_attr *attr);
 
 
217
218/*==================CE Engine Shutdown=======================*/
219/*
220 * Support clean shutdown by allowing the caller to revoke
221 * receive buffers.  Target DMA must be stopped before using
222 * this API.
223 */
224int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
225			       void **per_transfer_contextp,
226			       u32 *bufferp);
 
 
 
 
227
228/*
229 * Support clean shutdown by allowing the caller to cancel
230 * pending sends.  Target DMA must be stopped before using
231 * this API.
232 */
233int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
234			       void **per_transfer_contextp,
235			       u32 *bufferp,
236			       unsigned int *nbytesp,
237			       unsigned int *transfer_idp);
238
239void ath10k_ce_deinit(struct ath10k_ce_pipe *ce_state);
240
241/*==================CE Interrupt Handlers====================*/
242void ath10k_ce_per_engine_service_any(struct ath10k *ar);
243void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
244int ath10k_ce_disable_interrupts(struct ath10k *ar);
 
 
 
 
 
 
 
 
245
246/* ce_attr.flags values */
247/* Use NonSnooping PCIe accesses? */
248#define CE_ATTR_NO_SNOOP		1
249
250/* Byte swap data words */
251#define CE_ATTR_BYTE_SWAP_DATA		2
252
253/* Swizzle descriptors? */
254#define CE_ATTR_SWIZZLE_DESCRIPTORS	4
255
256/* no interrupt on copy completion */
257#define CE_ATTR_DIS_INTR		8
 
 
 
258
259/* Attributes of an instance of a Copy Engine */
260struct ce_attr {
261	/* CE_ATTR_* values */
262	unsigned int flags;
263
264	/* #entries in source ring - Must be a power of 2 */
265	unsigned int src_nentries;
266
267	/*
268	 * Max source send size for this CE.
269	 * This is also the minimum size of a destination buffer.
270	 */
271	unsigned int src_sz_max;
272
273	/* #entries in destination ring - Must be a power of 2 */
274	unsigned int dest_nentries;
 
 
 
275};
276
277#define SR_BA_ADDRESS		0x0000
278#define SR_SIZE_ADDRESS		0x0004
279#define DR_BA_ADDRESS		0x0008
280#define DR_SIZE_ADDRESS		0x000c
281#define CE_CMD_ADDRESS		0x0018
282
283#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MSB	17
284#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB	17
285#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK	0x00020000
286#define CE_CTRL1_DST_RING_BYTE_SWAP_EN_SET(x) \
287	(((0 | (x)) << CE_CTRL1_DST_RING_BYTE_SWAP_EN_LSB) & \
288	CE_CTRL1_DST_RING_BYTE_SWAP_EN_MASK)
289
290#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MSB	16
291#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB	16
292#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK	0x00010000
293#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_GET(x) \
294	(((x) & CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK) >> \
295	 CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB)
296#define CE_CTRL1_SRC_RING_BYTE_SWAP_EN_SET(x) \
297	(((0 | (x)) << CE_CTRL1_SRC_RING_BYTE_SWAP_EN_LSB) & \
298	 CE_CTRL1_SRC_RING_BYTE_SWAP_EN_MASK)
299
300#define CE_CTRL1_DMAX_LENGTH_MSB		15
301#define CE_CTRL1_DMAX_LENGTH_LSB		0
302#define CE_CTRL1_DMAX_LENGTH_MASK		0x0000ffff
303#define CE_CTRL1_DMAX_LENGTH_GET(x) \
304	(((x) & CE_CTRL1_DMAX_LENGTH_MASK) >> CE_CTRL1_DMAX_LENGTH_LSB)
305#define CE_CTRL1_DMAX_LENGTH_SET(x) \
306	(((0 | (x)) << CE_CTRL1_DMAX_LENGTH_LSB) & CE_CTRL1_DMAX_LENGTH_MASK)
307
308#define CE_CTRL1_ADDRESS			0x0010
309#define CE_CTRL1_HW_MASK			0x0007ffff
310#define CE_CTRL1_SW_MASK			0x0007ffff
311#define CE_CTRL1_HW_WRITE_MASK			0x00000000
312#define CE_CTRL1_SW_WRITE_MASK			0x0007ffff
313#define CE_CTRL1_RSTMASK			0xffffffff
314#define CE_CTRL1_RESET				0x00000080
315
316#define CE_CMD_HALT_STATUS_MSB			3
317#define CE_CMD_HALT_STATUS_LSB			3
318#define CE_CMD_HALT_STATUS_MASK			0x00000008
319#define CE_CMD_HALT_STATUS_GET(x) \
320	(((x) & CE_CMD_HALT_STATUS_MASK) >> CE_CMD_HALT_STATUS_LSB)
321#define CE_CMD_HALT_STATUS_SET(x) \
322	(((0 | (x)) << CE_CMD_HALT_STATUS_LSB) & CE_CMD_HALT_STATUS_MASK)
323#define CE_CMD_HALT_STATUS_RESET		0
324#define CE_CMD_HALT_MSB				0
325#define CE_CMD_HALT_MASK			0x00000001
326
327#define HOST_IE_COPY_COMPLETE_MSB		0
328#define HOST_IE_COPY_COMPLETE_LSB		0
329#define HOST_IE_COPY_COMPLETE_MASK		0x00000001
330#define HOST_IE_COPY_COMPLETE_GET(x) \
331	(((x) & HOST_IE_COPY_COMPLETE_MASK) >> HOST_IE_COPY_COMPLETE_LSB)
332#define HOST_IE_COPY_COMPLETE_SET(x) \
333	(((0 | (x)) << HOST_IE_COPY_COMPLETE_LSB) & HOST_IE_COPY_COMPLETE_MASK)
334#define HOST_IE_COPY_COMPLETE_RESET		0
335#define HOST_IE_ADDRESS				0x002c
336
337#define HOST_IS_DST_RING_LOW_WATERMARK_MASK	0x00000010
338#define HOST_IS_DST_RING_HIGH_WATERMARK_MASK	0x00000008
339#define HOST_IS_SRC_RING_LOW_WATERMARK_MASK	0x00000004
340#define HOST_IS_SRC_RING_HIGH_WATERMARK_MASK	0x00000002
341#define HOST_IS_COPY_COMPLETE_MASK		0x00000001
342#define HOST_IS_ADDRESS				0x0030
343
344#define MISC_IE_ADDRESS				0x0034
345
346#define MISC_IS_AXI_ERR_MASK			0x00000400
347
348#define MISC_IS_DST_ADDR_ERR_MASK		0x00000200
349#define MISC_IS_SRC_LEN_ERR_MASK		0x00000100
350#define MISC_IS_DST_MAX_LEN_VIO_MASK		0x00000080
351#define MISC_IS_DST_RING_OVERFLOW_MASK		0x00000040
352#define MISC_IS_SRC_RING_OVERFLOW_MASK		0x00000020
353
354#define MISC_IS_ADDRESS				0x0038
355
356#define SR_WR_INDEX_ADDRESS			0x003c
357
358#define DST_WR_INDEX_ADDRESS			0x0040
359
360#define CURRENT_SRRI_ADDRESS			0x0044
361
362#define CURRENT_DRRI_ADDRESS			0x0048
363
364#define SRC_WATERMARK_LOW_MSB			31
365#define SRC_WATERMARK_LOW_LSB			16
366#define SRC_WATERMARK_LOW_MASK			0xffff0000
367#define SRC_WATERMARK_LOW_GET(x) \
368	(((x) & SRC_WATERMARK_LOW_MASK) >> SRC_WATERMARK_LOW_LSB)
369#define SRC_WATERMARK_LOW_SET(x) \
370	(((0 | (x)) << SRC_WATERMARK_LOW_LSB) & SRC_WATERMARK_LOW_MASK)
371#define SRC_WATERMARK_LOW_RESET			0
372#define SRC_WATERMARK_HIGH_MSB			15
373#define SRC_WATERMARK_HIGH_LSB			0
374#define SRC_WATERMARK_HIGH_MASK			0x0000ffff
375#define SRC_WATERMARK_HIGH_GET(x) \
376	(((x) & SRC_WATERMARK_HIGH_MASK) >> SRC_WATERMARK_HIGH_LSB)
377#define SRC_WATERMARK_HIGH_SET(x) \
378	(((0 | (x)) << SRC_WATERMARK_HIGH_LSB) & SRC_WATERMARK_HIGH_MASK)
379#define SRC_WATERMARK_HIGH_RESET		0
380#define SRC_WATERMARK_ADDRESS			0x004c
381
382#define DST_WATERMARK_LOW_LSB			16
383#define DST_WATERMARK_LOW_MASK			0xffff0000
384#define DST_WATERMARK_LOW_SET(x) \
385	(((0 | (x)) << DST_WATERMARK_LOW_LSB) & DST_WATERMARK_LOW_MASK)
386#define DST_WATERMARK_LOW_RESET			0
387#define DST_WATERMARK_HIGH_MSB			15
388#define DST_WATERMARK_HIGH_LSB			0
389#define DST_WATERMARK_HIGH_MASK			0x0000ffff
390#define DST_WATERMARK_HIGH_GET(x) \
391	(((x) & DST_WATERMARK_HIGH_MASK) >> DST_WATERMARK_HIGH_LSB)
392#define DST_WATERMARK_HIGH_SET(x) \
393	(((0 | (x)) << DST_WATERMARK_HIGH_LSB) & DST_WATERMARK_HIGH_MASK)
394#define DST_WATERMARK_HIGH_RESET		0
395#define DST_WATERMARK_ADDRESS			0x0050
396
397
398static inline u32 ath10k_ce_base_address(unsigned int ce_id)
399{
400	return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
401}
402
403#define CE_WATERMARK_MASK (HOST_IS_SRC_RING_LOW_WATERMARK_MASK  | \
404			   HOST_IS_SRC_RING_HIGH_WATERMARK_MASK | \
405			   HOST_IS_DST_RING_LOW_WATERMARK_MASK  | \
406			   HOST_IS_DST_RING_HIGH_WATERMARK_MASK)
407
408#define CE_ERROR_MASK	(MISC_IS_AXI_ERR_MASK           | \
409			 MISC_IS_DST_ADDR_ERR_MASK      | \
410			 MISC_IS_SRC_LEN_ERR_MASK       | \
411			 MISC_IS_DST_MAX_LEN_VIO_MASK   | \
412			 MISC_IS_DST_RING_OVERFLOW_MASK | \
413			 MISC_IS_SRC_RING_OVERFLOW_MASK)
414
415#define CE_SRC_RING_TO_DESC(baddr, idx) \
416	(&(((struct ce_desc *)baddr)[idx]))
417
418#define CE_DEST_RING_TO_DESC(baddr, idx) \
419	(&(((struct ce_desc *)baddr)[idx]))
420
 
 
 
 
 
 
421/* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
422#define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
423	(((int)(toidx)-(int)(fromidx)) & (nentries_mask))
424
425#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
 
 
426
427#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB		8
428#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK		0x0000ff00
 
 
429#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
430	(((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
431		CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
432#define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS			0x0000
433
434#define CE_INTERRUPT_SUMMARY(ar) \
435	CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET( \
436		ath10k_pci_read32((ar), CE_WRAPPER_BASE_ADDRESS + \
437		CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
439#endif /* _CE_H_ */