ce.h 11.2 KB
Newer Older
1 2
/*
 * Copyright (c) 2005-2011 Atheros Communications Inc.
K
Kalle Valo 已提交
3
 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _CE_H_
#define _CE_H_

#include "hif.h"

M
Michal Kazior 已提交
23
#define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
24 25 26 27 28 29 30 31 32 33 34

/* Descriptor rings must be aligned to this boundary */
#define CE_DESC_RING_ALIGN	8
#define CE_SEND_FLAG_GATHER	0x00010000

/*
 * Copy Engine support: low-level Target-side Copy Engine API.
 * This is a hardware access layer used by code that understands
 * how to use copy engines.
 */

35
struct ath10k_ce_pipe;
36 37 38

#define CE_DESC_FLAGS_GATHER         (1 << 0)
#define CE_DESC_FLAGS_BYTE_SWAP      (1 << 1)
39 40 41 42
#define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)

#define CE_DESC_FLAGS_GET_MASK		GENMASK(4, 0)
#define CE_DESC_37BIT_ADDR_MASK		GENMASK_ULL(37, 0)
43 44 45 46 47 48 49

/* Following desc flags are used in QCA99X0 */
#define CE_DESC_FLAGS_HOST_INT_DIS	(1 << 2)
#define CE_DESC_FLAGS_TGT_INT_DIS	(1 << 3)

#define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
#define CE_DESC_FLAGS_META_DATA_LSB  ar->hw_values->ce_desc_meta_data_lsb
50 51 52 53 54 55 56

struct ce_desc {
	__le32 addr;
	__le16 nbytes;
	__le16 flags; /* %CE_DESC_FLAGS_ */
};

57 58 59 60 61 62 63 64 65 66
struct ce_desc_64 {
	__le64 addr;
	__le16 nbytes; /* length in register map */
	__le16 flags; /* fw_metadata_high */
	__le32 toeplitz_hash_result;
};

#define CE_DESC_SIZE sizeof(struct ce_desc)
#define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)

67
struct ath10k_ce_ring {
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	/* Number of entries in this ring; must be power of 2 */
	unsigned int nentries;
	unsigned int nentries_mask;

	/*
	 * For dest ring, this is the next index to be processed
	 * by software after it was/is received into.
	 *
	 * For src ring, this is the last descriptor that was sent
	 * and completion processed by software.
	 *
	 * Regardless of src or dest ring, this is an invariant
	 * (modulo ring size):
	 *     write index >= read index >= sw_index
	 */
	unsigned int sw_index;
	/* cached copy */
	unsigned int write_index;
	/*
	 * For src ring, this is the next index not yet processed by HW.
	 * This is a cached copy of the real HW index (read index), used
	 * for avoiding reading the HW index register more often than
	 * necessary.
	 * This extends the invariant:
	 *     write index >= read index >= hw_index >= sw_index
	 *
	 * For dest ring, this is currently unused.
	 */
	/* cached copy */
	unsigned int hw_index;

	/* Start of DMA-coherent area reserved for descriptors */
	/* Host address space */
	void *base_addr_owner_space_unaligned;
	/* CE address space */
	u32 base_addr_ce_space_unaligned;

	/*
	 * Actual start of descriptors.
	 * Aligned to descriptor-size boundary.
	 * Points into reserved DMA-coherent area, above.
	 */
	/* Host address space */
	void *base_addr_owner_space;

	/* CE address space */
	u32 base_addr_ce_space;

116 117
	/* keep last */
	void *per_transfer_context[0];
118 119
};

120
struct ath10k_ce_pipe {
121 122 123 124 125 126 127
	struct ath10k *ar;
	unsigned int id;

	unsigned int attr_flags;

	u32 ctrl_addr;

128 129
	void (*send_cb)(struct ath10k_ce_pipe *);
	void (*recv_cb)(struct ath10k_ce_pipe *);
130 131

	unsigned int src_sz_max;
132 133
	struct ath10k_ce_ring *src_ring;
	struct ath10k_ce_ring *dest_ring;
134
	const struct ath10k_ce_ops *ops;
135 136 137 138 139
};

/* Copy Engine settable attributes */
struct ce_attr;

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
struct ath10k_bus_ops {
	u32 (*read32)(struct ath10k *ar, u32 offset);
	void (*write32)(struct ath10k *ar, u32 offset, u32 value);
	int (*get_num_banks)(struct ath10k *ar);
};

static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
{
	return (struct ath10k_ce *)ar->ce_priv;
}

struct ath10k_ce {
	/* protects CE info */
	spinlock_t ce_lock;
	const struct ath10k_bus_ops *bus_ops;
	struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
};

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
/*==================Send====================*/

/* ath10k_ce_send flags */
#define CE_SEND_FLAG_BYTE_SWAP 1

/*
 * Queue a source buffer to be sent to an anonymous destination buffer.
 *   ce         - which copy engine to use
 *   buffer          - address of buffer
 *   nbytes          - number of bytes to send
 *   transfer_id     - arbitrary ID; reflected to destination
 *   flags           - CE_SEND_FLAG_* values
 * Returns 0 on success; otherwise an error status.
 *
 * Note: If no flags are specified, use CE's default data swap mode.
 *
 * Implementation note: pushes 1 buffer to Source ring
 */
176
int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
177
		   void *per_transfer_send_context,
178
		   dma_addr_t buffer,
179 180 181 182 183
		   unsigned int nbytes,
		   /* 14 bits */
		   unsigned int transfer_id,
		   unsigned int flags);

184 185
int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
			  void *per_transfer_context,
186
			  dma_addr_t buffer,
187 188 189 190
			  unsigned int nbytes,
			  unsigned int transfer_id,
			  unsigned int flags);

191 192
void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);

M
Michal Kazior 已提交
193
int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
194 195 196

/*==================Recv=======================*/

197
int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
198 199
int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
			  dma_addr_t paddr);
200
void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
201 202 203 204 205 206 207 208 209

/* recv flags */
/* Data is byte-swapped */
#define CE_RECV_FLAG_SWAPPED	1

/*
 * Supply data for the next completed unprocessed receive descriptor.
 * Pops buffer from Dest ring.
 */
210
int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
211
				  void **per_transfer_contextp,
212
				  unsigned int *nbytesp);
213 214 215 216
/*
 * Supply data for the next completed unprocessed send descriptor.
 * Pops 1 completed send buffer from Source ring.
 */
217
int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
218
				  void **per_transfer_contextp);
219

K
Kalle Valo 已提交
220
int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
221
					 void **per_transfer_contextp);
K
Kalle Valo 已提交
222

223 224
/*==================CE Engine Initialization=======================*/

225
int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
226
			const struct ce_attr *attr);
227 228
void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
229
			 const struct ce_attr *attr);
230
void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
231 232 233 234 235 236 237

/*==================CE Engine Shutdown=======================*/
/*
 * Support clean shutdown by allowing the caller to revoke
 * receive buffers.  Target DMA must be stopped before using
 * this API.
 */
238
int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
239
			       void **per_transfer_contextp,
240
			       dma_addr_t *bufferp);
241

K
Kalle Valo 已提交
242 243
int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
					 void **per_transfer_contextp,
244
					 unsigned int *nbytesp);
K
Kalle Valo 已提交
245

246 247 248 249 250
/*
 * Support clean shutdown by allowing the caller to cancel
 * pending sends.  Target DMA must be stopped before using
 * this API.
 */
251
int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
252
			       void **per_transfer_contextp,
253
			       dma_addr_t *bufferp,
254 255 256 257 258 259
			       unsigned int *nbytesp,
			       unsigned int *transfer_idp);

/*==================CE Interrupt Handlers====================*/
void ath10k_ce_per_engine_service_any(struct ath10k *ar);
void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
260
int ath10k_ce_disable_interrupts(struct ath10k *ar);
261
void ath10k_ce_enable_interrupts(struct ath10k *ar);
262 263
void ath10k_ce_dump_registers(struct ath10k *ar,
			      struct ath10k_fw_crash_data *crash_data);
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293

/* ce_attr.flags values */
/* Use NonSnooping PCIe accesses? */
#define CE_ATTR_NO_SNOOP		1

/* Byte swap data words */
#define CE_ATTR_BYTE_SWAP_DATA		2

/* Swizzle descriptors? */
#define CE_ATTR_SWIZZLE_DESCRIPTORS	4

/* no interrupt on copy completion */
#define CE_ATTR_DIS_INTR		8

/* Attributes of an instance of a Copy Engine */
struct ce_attr {
	/* CE_ATTR_* values */
	unsigned int flags;

	/* #entries in source ring - Must be a power of 2 */
	unsigned int src_nentries;

	/*
	 * Max source send size for this CE.
	 * This is also the minimum size of a destination buffer.
	 */
	unsigned int src_sz_max;

	/* #entries in destination ring - Must be a power of 2 */
	unsigned int dest_nentries;
294 295

	void (*send_cb)(struct ath10k_ce_pipe *);
296
	void (*recv_cb)(struct ath10k_ce_pipe *);
297 298
};

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
struct ath10k_ce_ops {
	struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
						    u32 ce_id,
						    const struct ce_attr *attr);
	struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
						    u32 ce_id,
						    const struct ce_attr *attr);
	int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
			      dma_addr_t paddr);
	int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
					     void **per_transfer_contextp,
					     u32 *nbytesp);
	int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
				   void **per_transfer_contextp,
				   dma_addr_t *nbytesp);
	void (*ce_extract_desc_data)(struct ath10k *ar,
				     struct ath10k_ce_ring *src_ring,
				     u32 sw_index, dma_addr_t *bufferp,
				     u32 *nbytesp, u32 *transfer_idp);
	void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
	int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
			      void *per_transfer_context,
			      dma_addr_t buffer, u32 nbytes,
			      u32 transfer_id, u32 flags);
};
324

M
Michal Kazior 已提交
325
static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
326 327 328 329 330 331 332 333 334 335
{
	return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
}

#define CE_SRC_RING_TO_DESC(baddr, idx) \
	(&(((struct ce_desc *)baddr)[idx]))

#define CE_DEST_RING_TO_DESC(baddr, idx) \
	(&(((struct ce_desc *)baddr)[idx]))

336 337 338 339 340 341
#define CE_SRC_RING_TO_DESC_64(baddr, idx) \
	(&(((struct ce_desc_64 *)baddr)[idx]))

#define CE_DEST_RING_TO_DESC_64(baddr, idx) \
	(&(((struct ce_desc_64 *)baddr)[idx]))

342 343
/* Ring arithmetic (modulus number of entries in ring, which is a pwr of 2). */
#define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
344
	(((int)(toidx) - (int)(fromidx)) & (nentries_mask))
345 346

#define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
347 348
#define CE_RING_IDX_ADD(nentries_mask, idx, num) \
		(((idx) + (num)) & (nentries_mask))
349

350 351 352 353
#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
				ar->regs->ce_wrap_intr_sum_host_msi_lsb
#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
				ar->regs->ce_wrap_intr_sum_host_msi_mask
354 355 356 357 358
#define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
	(((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
		CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
#define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS			0x0000

359 360 361 362 363 364 365 366
static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
{
	struct ath10k_ce *ce = ath10k_ce_priv(ar);

	return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
		ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
		CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
}
367 368

#endif /* _CE_H_ */