0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _CE_H_
0009 #define _CE_H_
0010
0011 #include "hif.h"
0012
0013 #define CE_HTT_H2T_MSG_SRC_NENTRIES 8192
0014
0015
0016 #define CE_DESC_RING_ALIGN 8
0017 #define CE_SEND_FLAG_GATHER 0x00010000
0018
0019
0020
0021
0022
0023
0024
0025 struct ath10k_ce_pipe;
0026
0027 #define CE_DESC_FLAGS_GATHER (1 << 0)
0028 #define CE_DESC_FLAGS_BYTE_SWAP (1 << 1)
0029 #define CE_WCN3990_DESC_FLAGS_GATHER BIT(31)
0030
0031 #define CE_DESC_ADDR_MASK GENMASK_ULL(34, 0)
0032 #define CE_DESC_ADDR_HI_MASK GENMASK(4, 0)
0033
0034
0035 #define CE_DESC_FLAGS_HOST_INT_DIS (1 << 2)
0036 #define CE_DESC_FLAGS_TGT_INT_DIS (1 << 3)
0037
0038 #define CE_DESC_FLAGS_META_DATA_MASK ar->hw_values->ce_desc_meta_data_mask
0039 #define CE_DESC_FLAGS_META_DATA_LSB ar->hw_values->ce_desc_meta_data_lsb
0040
0041 #define CE_DDR_RRI_MASK GENMASK(15, 0)
0042 #define CE_DDR_DRRI_SHIFT 16
0043
0044 struct ce_desc {
0045 __le32 addr;
0046 __le16 nbytes;
0047 __le16 flags;
0048 };
0049
0050 struct ce_desc_64 {
0051 __le64 addr;
0052 __le16 nbytes;
0053 __le16 flags;
0054 __le32 toeplitz_hash_result;
0055 };
0056
0057 #define CE_DESC_SIZE sizeof(struct ce_desc)
0058 #define CE_DESC_SIZE_64 sizeof(struct ce_desc_64)
0059
0060 struct ath10k_ce_ring {
0061
0062 unsigned int nentries;
0063 unsigned int nentries_mask;
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 unsigned int sw_index;
0077
0078 unsigned int write_index;
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 unsigned int hw_index;
0091
0092
0093
0094 void *base_addr_owner_space_unaligned;
0095
0096 dma_addr_t base_addr_ce_space_unaligned;
0097
0098
0099
0100
0101
0102
0103
0104 void *base_addr_owner_space;
0105
0106
0107 dma_addr_t base_addr_ce_space;
0108
0109 char *shadow_base_unaligned;
0110 struct ce_desc_64 *shadow_base;
0111
0112
0113 void *per_transfer_context[];
0114 };
0115
0116 struct ath10k_ce_pipe {
0117 struct ath10k *ar;
0118 unsigned int id;
0119
0120 unsigned int attr_flags;
0121
0122 u32 ctrl_addr;
0123
0124 void (*send_cb)(struct ath10k_ce_pipe *);
0125 void (*recv_cb)(struct ath10k_ce_pipe *);
0126
0127 unsigned int src_sz_max;
0128 struct ath10k_ce_ring *src_ring;
0129 struct ath10k_ce_ring *dest_ring;
0130 const struct ath10k_ce_ops *ops;
0131 };
0132
0133
0134 struct ce_attr;
0135
0136 struct ath10k_bus_ops {
0137 u32 (*read32)(struct ath10k *ar, u32 offset);
0138 void (*write32)(struct ath10k *ar, u32 offset, u32 value);
0139 int (*get_num_banks)(struct ath10k *ar);
0140 };
0141
0142 static inline struct ath10k_ce *ath10k_ce_priv(struct ath10k *ar)
0143 {
0144 return (struct ath10k_ce *)ar->ce_priv;
0145 }
0146
0147 struct ath10k_ce {
0148
0149 spinlock_t ce_lock;
0150 const struct ath10k_bus_ops *bus_ops;
0151 struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
0152 u32 *vaddr_rri;
0153 dma_addr_t paddr_rri;
0154 };
0155
0156
0157
0158
0159 #define CE_SEND_FLAG_BYTE_SWAP 1
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
0175 void *per_transfer_send_context,
0176 dma_addr_t buffer,
0177 unsigned int nbytes,
0178
0179 unsigned int transfer_id,
0180 unsigned int flags);
0181
0182 int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
0183 void *per_transfer_context,
0184 dma_addr_t buffer,
0185 unsigned int nbytes,
0186 unsigned int transfer_id,
0187 unsigned int flags);
0188
0189 void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
0190
0191 int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe);
0192
0193
0194
0195 int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe);
0196 int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
0197 dma_addr_t paddr);
0198 void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries);
0199
0200
0201
0202 #define CE_RECV_FLAG_SWAPPED 1
0203
0204
0205
0206
0207
0208 int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
0209 void **per_transfer_contextp,
0210 unsigned int *nbytesp);
0211
0212
0213
0214
0215 int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
0216 void **per_transfer_contextp);
0217
0218 int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
0219 void **per_transfer_contextp);
0220
0221
0222
0223 int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
0224 const struct ce_attr *attr);
0225 void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id);
0226 int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
0227 const struct ce_attr *attr);
0228 void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id);
0229
0230
0231
0232
0233
0234
0235
0236 int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
0237 void **per_transfer_contextp,
0238 dma_addr_t *bufferp);
0239
0240 int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
0241 void **per_transfer_contextp,
0242 unsigned int *nbytesp);
0243
0244
0245
0246
0247
0248
0249 int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
0250 void **per_transfer_contextp,
0251 dma_addr_t *bufferp,
0252 unsigned int *nbytesp,
0253 unsigned int *transfer_idp);
0254
0255
0256 void ath10k_ce_per_engine_service_any(struct ath10k *ar);
0257 void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id);
0258 void ath10k_ce_disable_interrupt(struct ath10k *ar, int ce_id);
0259 void ath10k_ce_disable_interrupts(struct ath10k *ar);
0260 void ath10k_ce_enable_interrupt(struct ath10k *ar, int ce_id);
0261 void ath10k_ce_enable_interrupts(struct ath10k *ar);
0262 void ath10k_ce_dump_registers(struct ath10k *ar,
0263 struct ath10k_fw_crash_data *crash_data);
0264
0265 void ath10k_ce_alloc_rri(struct ath10k *ar);
0266 void ath10k_ce_free_rri(struct ath10k *ar);
0267
0268
0269
0270 #define CE_ATTR_NO_SNOOP BIT(0)
0271
0272
0273 #define CE_ATTR_BYTE_SWAP_DATA BIT(1)
0274
0275
0276 #define CE_ATTR_SWIZZLE_DESCRIPTORS BIT(2)
0277
0278
0279 #define CE_ATTR_DIS_INTR BIT(3)
0280
0281
0282 #define CE_ATTR_POLL BIT(4)
0283
0284
0285 struct ce_attr {
0286
0287 unsigned int flags;
0288
0289
0290 unsigned int src_nentries;
0291
0292
0293
0294
0295
0296 unsigned int src_sz_max;
0297
0298
0299 unsigned int dest_nentries;
0300
0301 void (*send_cb)(struct ath10k_ce_pipe *);
0302 void (*recv_cb)(struct ath10k_ce_pipe *);
0303 };
0304
0305 struct ath10k_ce_ops {
0306 struct ath10k_ce_ring *(*ce_alloc_src_ring)(struct ath10k *ar,
0307 u32 ce_id,
0308 const struct ce_attr *attr);
0309 struct ath10k_ce_ring *(*ce_alloc_dst_ring)(struct ath10k *ar,
0310 u32 ce_id,
0311 const struct ce_attr *attr);
0312 int (*ce_rx_post_buf)(struct ath10k_ce_pipe *pipe, void *ctx,
0313 dma_addr_t paddr);
0314 int (*ce_completed_recv_next_nolock)(struct ath10k_ce_pipe *ce_state,
0315 void **per_transfer_contextp,
0316 u32 *nbytesp);
0317 int (*ce_revoke_recv_next)(struct ath10k_ce_pipe *ce_state,
0318 void **per_transfer_contextp,
0319 dma_addr_t *nbytesp);
0320 void (*ce_extract_desc_data)(struct ath10k *ar,
0321 struct ath10k_ce_ring *src_ring,
0322 u32 sw_index, dma_addr_t *bufferp,
0323 u32 *nbytesp, u32 *transfer_idp);
0324 void (*ce_free_pipe)(struct ath10k *ar, int ce_id);
0325 int (*ce_send_nolock)(struct ath10k_ce_pipe *pipe,
0326 void *per_transfer_context,
0327 dma_addr_t buffer, u32 nbytes,
0328 u32 transfer_id, u32 flags);
0329 void (*ce_set_src_ring_base_addr_hi)(struct ath10k *ar,
0330 u32 ce_ctrl_addr,
0331 u64 addr);
0332 void (*ce_set_dest_ring_base_addr_hi)(struct ath10k *ar,
0333 u32 ce_ctrl_addr,
0334 u64 addr);
0335 int (*ce_completed_send_next_nolock)(struct ath10k_ce_pipe *ce_state,
0336 void **per_transfer_contextp);
0337 };
0338
0339 static inline u32 ath10k_ce_base_address(struct ath10k *ar, unsigned int ce_id)
0340 {
0341 return CE0_BASE_ADDRESS + (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS) * ce_id;
0342 }
0343
0344 #define COPY_ENGINE_ID(COPY_ENGINE_BASE_ADDRESS) (((COPY_ENGINE_BASE_ADDRESS) \
0345 - CE0_BASE_ADDRESS) / (CE1_BASE_ADDRESS - CE0_BASE_ADDRESS))
0346
0347 #define CE_SRC_RING_TO_DESC(baddr, idx) \
0348 (&(((struct ce_desc *)baddr)[idx]))
0349
0350 #define CE_DEST_RING_TO_DESC(baddr, idx) \
0351 (&(((struct ce_desc *)baddr)[idx]))
0352
0353 #define CE_SRC_RING_TO_DESC_64(baddr, idx) \
0354 (&(((struct ce_desc_64 *)baddr)[idx]))
0355
0356 #define CE_DEST_RING_TO_DESC_64(baddr, idx) \
0357 (&(((struct ce_desc_64 *)baddr)[idx]))
0358
0359
0360 #define CE_RING_DELTA(nentries_mask, fromidx, toidx) \
0361 (((int)(toidx) - (int)(fromidx)) & (nentries_mask))
0362
0363 #define CE_RING_IDX_INCR(nentries_mask, idx) (((idx) + 1) & (nentries_mask))
0364 #define CE_RING_IDX_ADD(nentries_mask, idx, num) \
0365 (((idx) + (num)) & (nentries_mask))
0366
0367 #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB \
0368 ar->regs->ce_wrap_intr_sum_host_msi_lsb
0369 #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK \
0370 ar->regs->ce_wrap_intr_sum_host_msi_mask
0371 #define CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(x) \
0372 (((x) & CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_MASK) >> \
0373 CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_LSB)
0374 #define CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS 0x0000
0375
0376 static inline u32 ath10k_ce_interrupt_summary(struct ath10k *ar)
0377 {
0378 struct ath10k_ce *ce = ath10k_ce_priv(ar);
0379
0380 return CE_WRAPPER_INTERRUPT_SUMMARY_HOST_MSI_GET(
0381 ce->bus_ops->read32((ar), CE_WRAPPER_BASE_ADDRESS +
0382 CE_WRAPPER_INTERRUPT_SUMMARY_ADDRESS));
0383 }
0384
0385
0386 #define CE_ATTR_FLAGS 0
0387
0388
0389
0390
0391
0392
0393
0394 struct ce_pipe_config {
0395 __le32 pipenum;
0396 __le32 pipedir;
0397 __le32 nentries;
0398 __le32 nbytes_max;
0399 __le32 flags;
0400 __le32 reserved;
0401 };
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415 #define PIPEDIR_NONE 0
0416 #define PIPEDIR_IN 1
0417 #define PIPEDIR_OUT 2
0418 #define PIPEDIR_INOUT 3
0419
0420
0421 struct ce_service_to_pipe {
0422 __le32 service_id;
0423 __le32 pipedir;
0424 __le32 pipenum;
0425 };
0426
0427 #endif