1 // SPDX-License-Identifier: ISC
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.
13 * Support for Copy Engine hardware, which is mainly used for
14 * communication between Host and Target over a PCIe interconnect.
18 * A single CopyEngine (CE) comprises two "rings":
22 * Each ring consists of a number of descriptors which specify
23 * an address, length, and meta-data.
25 * Typically, one side of the PCIe/AHB/SNOC interconnect (Host or Target)
26 * controls one ring and the other side controls the other ring.
27 * The source side chooses when to initiate a transfer and it
28 * chooses what to send (buffer address, length). The destination
29 * side keeps a supply of "anonymous receive buffers" available and
30 * it handles incoming data as it arrives (when the destination
31 * receives an interrupt).
33 * The sender may send a simple buffer (address/length) or it may
34 * send a small list of buffers. When a small list is sent, hardware
35 * "gathers" these and they end up in a single destination buffer
36 * with a single interrupt.
38 * There are several "contexts" managed by this layer -- more, it
39 * may seem -- than should be needed. These are provided mainly for
40 * maximum flexibility and especially to facilitate a simpler HIF
41 * implementation. There are per-CopyEngine recv, send, and watermark
42 * contexts. These are supplied by the caller when a recv, send,
43 * or watermark handler is established and they are echoed back to
44 * the caller when the respective callbacks are invoked. There is
45 * also a per-transfer context supplied by the caller when a buffer
46 * (or sendlist) is sent and when a buffer is enqueued for recv.
47 * These per-transfer contexts are echoed back to the caller when
48 * the buffer is sent/received.
51 static inline u32
shadow_sr_wr_ind_addr(struct ath10k
*ar
,
52 struct ath10k_ce_pipe
*ce_state
)
54 u32 ce_id
= ce_state
->id
;
74 ath10k_warn(ar
, "invalid CE id: %d", ce_id
);
80 static inline u32
shadow_dst_wr_ind_addr(struct ath10k
*ar
,
81 struct ath10k_ce_pipe
*ce_state
)
83 u32 ce_id
= ce_state
->id
;
112 ath10k_warn(ar
, "invalid CE id: %d", ce_id
);
119 static inline unsigned int
120 ath10k_set_ring_byte(unsigned int offset
,
121 struct ath10k_hw_ce_regs_addr_map
*addr_map
)
123 return ((offset
<< addr_map
->lsb
) & addr_map
->mask
);
126 static inline unsigned int
127 ath10k_get_ring_byte(unsigned int offset
,
128 struct ath10k_hw_ce_regs_addr_map
*addr_map
)
130 return ((offset
& addr_map
->mask
) >> (addr_map
->lsb
));
133 static inline u32
ath10k_ce_read32(struct ath10k
*ar
, u32 offset
)
135 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
137 return ce
->bus_ops
->read32(ar
, offset
);
140 static inline void ath10k_ce_write32(struct ath10k
*ar
, u32 offset
, u32 value
)
142 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
144 ce
->bus_ops
->write32(ar
, offset
, value
);
147 static inline void ath10k_ce_dest_ring_write_index_set(struct ath10k
*ar
,
151 ath10k_ce_write32(ar
, ce_ctrl_addr
+
152 ar
->hw_ce_regs
->dst_wr_index_addr
, n
);
155 static inline u32
ath10k_ce_dest_ring_write_index_get(struct ath10k
*ar
,
158 return ath10k_ce_read32(ar
, ce_ctrl_addr
+
159 ar
->hw_ce_regs
->dst_wr_index_addr
);
162 static inline void ath10k_ce_src_ring_write_index_set(struct ath10k
*ar
,
166 ath10k_ce_write32(ar
, ce_ctrl_addr
+
167 ar
->hw_ce_regs
->sr_wr_index_addr
, n
);
170 static inline u32
ath10k_ce_src_ring_write_index_get(struct ath10k
*ar
,
173 return ath10k_ce_read32(ar
, ce_ctrl_addr
+
174 ar
->hw_ce_regs
->sr_wr_index_addr
);
177 static inline u32
ath10k_ce_src_ring_read_index_from_ddr(struct ath10k
*ar
,
180 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
182 return ce
->vaddr_rri
[ce_id
] & CE_DDR_RRI_MASK
;
185 static inline u32
ath10k_ce_src_ring_read_index_get(struct ath10k
*ar
,
188 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
189 u32 ce_id
= COPY_ENGINE_ID(ce_ctrl_addr
);
190 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
193 if (ar
->hw_params
.rri_on_ddr
&&
194 (ce_state
->attr_flags
& CE_ATTR_DIS_INTR
))
195 index
= ath10k_ce_src_ring_read_index_from_ddr(ar
, ce_id
);
197 index
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
198 ar
->hw_ce_regs
->current_srri_addr
);
204 ath10k_ce_shadow_src_ring_write_index_set(struct ath10k
*ar
,
205 struct ath10k_ce_pipe
*ce_state
,
208 ath10k_ce_write32(ar
, shadow_sr_wr_ind_addr(ar
, ce_state
), value
);
212 ath10k_ce_shadow_dest_ring_write_index_set(struct ath10k
*ar
,
213 struct ath10k_ce_pipe
*ce_state
,
216 ath10k_ce_write32(ar
, shadow_dst_wr_ind_addr(ar
, ce_state
), value
);
219 static inline void ath10k_ce_src_ring_base_addr_set(struct ath10k
*ar
,
223 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
224 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
225 u32 ce_ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
226 u32 addr_lo
= lower_32_bits(addr
);
228 ath10k_ce_write32(ar
, ce_ctrl_addr
+
229 ar
->hw_ce_regs
->sr_base_addr_lo
, addr_lo
);
231 if (ce_state
->ops
->ce_set_src_ring_base_addr_hi
) {
232 ce_state
->ops
->ce_set_src_ring_base_addr_hi(ar
, ce_ctrl_addr
,
237 static void ath10k_ce_set_src_ring_base_addr_hi(struct ath10k
*ar
,
241 u32 addr_hi
= upper_32_bits(addr
) & CE_DESC_ADDR_HI_MASK
;
243 ath10k_ce_write32(ar
, ce_ctrl_addr
+
244 ar
->hw_ce_regs
->sr_base_addr_hi
, addr_hi
);
247 static inline void ath10k_ce_src_ring_size_set(struct ath10k
*ar
,
251 ath10k_ce_write32(ar
, ce_ctrl_addr
+
252 ar
->hw_ce_regs
->sr_size_addr
, n
);
255 static inline void ath10k_ce_src_ring_dmax_set(struct ath10k
*ar
,
259 struct ath10k_hw_ce_ctrl1
*ctrl_regs
= ar
->hw_ce_regs
->ctrl1_regs
;
261 u32 ctrl1_addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
264 ath10k_ce_write32(ar
, ce_ctrl_addr
+ ctrl_regs
->addr
,
265 (ctrl1_addr
& ~(ctrl_regs
->dmax
->mask
)) |
266 ath10k_set_ring_byte(n
, ctrl_regs
->dmax
));
269 static inline void ath10k_ce_src_ring_byte_swap_set(struct ath10k
*ar
,
273 struct ath10k_hw_ce_ctrl1
*ctrl_regs
= ar
->hw_ce_regs
->ctrl1_regs
;
275 u32 ctrl1_addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
278 ath10k_ce_write32(ar
, ce_ctrl_addr
+ ctrl_regs
->addr
,
279 (ctrl1_addr
& ~(ctrl_regs
->src_ring
->mask
)) |
280 ath10k_set_ring_byte(n
, ctrl_regs
->src_ring
));
283 static inline void ath10k_ce_dest_ring_byte_swap_set(struct ath10k
*ar
,
287 struct ath10k_hw_ce_ctrl1
*ctrl_regs
= ar
->hw_ce_regs
->ctrl1_regs
;
289 u32 ctrl1_addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
292 ath10k_ce_write32(ar
, ce_ctrl_addr
+ ctrl_regs
->addr
,
293 (ctrl1_addr
& ~(ctrl_regs
->dst_ring
->mask
)) |
294 ath10k_set_ring_byte(n
, ctrl_regs
->dst_ring
));
298 u32
ath10k_ce_dest_ring_read_index_from_ddr(struct ath10k
*ar
, u32 ce_id
)
300 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
302 return (ce
->vaddr_rri
[ce_id
] >> CE_DDR_DRRI_SHIFT
) &
306 static inline u32
ath10k_ce_dest_ring_read_index_get(struct ath10k
*ar
,
309 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
310 u32 ce_id
= COPY_ENGINE_ID(ce_ctrl_addr
);
311 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
314 if (ar
->hw_params
.rri_on_ddr
&&
315 (ce_state
->attr_flags
& CE_ATTR_DIS_INTR
))
316 index
= ath10k_ce_dest_ring_read_index_from_ddr(ar
, ce_id
);
318 index
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
319 ar
->hw_ce_regs
->current_drri_addr
);
324 static inline void ath10k_ce_dest_ring_base_addr_set(struct ath10k
*ar
,
328 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
329 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
330 u32 ce_ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
331 u32 addr_lo
= lower_32_bits(addr
);
333 ath10k_ce_write32(ar
, ce_ctrl_addr
+
334 ar
->hw_ce_regs
->dr_base_addr_lo
, addr_lo
);
336 if (ce_state
->ops
->ce_set_dest_ring_base_addr_hi
) {
337 ce_state
->ops
->ce_set_dest_ring_base_addr_hi(ar
, ce_ctrl_addr
,
342 static void ath10k_ce_set_dest_ring_base_addr_hi(struct ath10k
*ar
,
346 u32 addr_hi
= upper_32_bits(addr
) & CE_DESC_ADDR_HI_MASK
;
349 reg_value
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
350 ar
->hw_ce_regs
->dr_base_addr_hi
);
351 reg_value
&= ~CE_DESC_ADDR_HI_MASK
;
352 reg_value
|= addr_hi
;
353 ath10k_ce_write32(ar
, ce_ctrl_addr
+
354 ar
->hw_ce_regs
->dr_base_addr_hi
, reg_value
);
357 static inline void ath10k_ce_dest_ring_size_set(struct ath10k
*ar
,
361 ath10k_ce_write32(ar
, ce_ctrl_addr
+
362 ar
->hw_ce_regs
->dr_size_addr
, n
);
365 static inline void ath10k_ce_src_ring_highmark_set(struct ath10k
*ar
,
369 struct ath10k_hw_ce_dst_src_wm_regs
*srcr_wm
= ar
->hw_ce_regs
->wm_srcr
;
370 u32 addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+ srcr_wm
->addr
);
372 ath10k_ce_write32(ar
, ce_ctrl_addr
+ srcr_wm
->addr
,
373 (addr
& ~(srcr_wm
->wm_high
->mask
)) |
374 (ath10k_set_ring_byte(n
, srcr_wm
->wm_high
)));
377 static inline void ath10k_ce_src_ring_lowmark_set(struct ath10k
*ar
,
381 struct ath10k_hw_ce_dst_src_wm_regs
*srcr_wm
= ar
->hw_ce_regs
->wm_srcr
;
382 u32 addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+ srcr_wm
->addr
);
384 ath10k_ce_write32(ar
, ce_ctrl_addr
+ srcr_wm
->addr
,
385 (addr
& ~(srcr_wm
->wm_low
->mask
)) |
386 (ath10k_set_ring_byte(n
, srcr_wm
->wm_low
)));
389 static inline void ath10k_ce_dest_ring_highmark_set(struct ath10k
*ar
,
393 struct ath10k_hw_ce_dst_src_wm_regs
*dstr_wm
= ar
->hw_ce_regs
->wm_dstr
;
394 u32 addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+ dstr_wm
->addr
);
396 ath10k_ce_write32(ar
, ce_ctrl_addr
+ dstr_wm
->addr
,
397 (addr
& ~(dstr_wm
->wm_high
->mask
)) |
398 (ath10k_set_ring_byte(n
, dstr_wm
->wm_high
)));
401 static inline void ath10k_ce_dest_ring_lowmark_set(struct ath10k
*ar
,
405 struct ath10k_hw_ce_dst_src_wm_regs
*dstr_wm
= ar
->hw_ce_regs
->wm_dstr
;
406 u32 addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+ dstr_wm
->addr
);
408 ath10k_ce_write32(ar
, ce_ctrl_addr
+ dstr_wm
->addr
,
409 (addr
& ~(dstr_wm
->wm_low
->mask
)) |
410 (ath10k_set_ring_byte(n
, dstr_wm
->wm_low
)));
413 static inline void ath10k_ce_copy_complete_inter_enable(struct ath10k
*ar
,
416 struct ath10k_hw_ce_host_ie
*host_ie
= ar
->hw_ce_regs
->host_ie
;
418 u32 host_ie_addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
419 ar
->hw_ce_regs
->host_ie_addr
);
421 ath10k_ce_write32(ar
, ce_ctrl_addr
+ ar
->hw_ce_regs
->host_ie_addr
,
422 host_ie_addr
| host_ie
->copy_complete
->mask
);
425 static inline void ath10k_ce_copy_complete_intr_disable(struct ath10k
*ar
,
428 struct ath10k_hw_ce_host_ie
*host_ie
= ar
->hw_ce_regs
->host_ie
;
430 u32 host_ie_addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
431 ar
->hw_ce_regs
->host_ie_addr
);
433 ath10k_ce_write32(ar
, ce_ctrl_addr
+ ar
->hw_ce_regs
->host_ie_addr
,
434 host_ie_addr
& ~(host_ie
->copy_complete
->mask
));
437 static inline void ath10k_ce_watermark_intr_disable(struct ath10k
*ar
,
440 struct ath10k_hw_ce_host_wm_regs
*wm_regs
= ar
->hw_ce_regs
->wm_regs
;
442 u32 host_ie_addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
443 ar
->hw_ce_regs
->host_ie_addr
);
445 ath10k_ce_write32(ar
, ce_ctrl_addr
+ ar
->hw_ce_regs
->host_ie_addr
,
446 host_ie_addr
& ~(wm_regs
->wm_mask
));
449 static inline void ath10k_ce_error_intr_enable(struct ath10k
*ar
,
452 struct ath10k_hw_ce_misc_regs
*misc_regs
= ar
->hw_ce_regs
->misc_regs
;
454 u32 misc_ie_addr
= ath10k_ce_read32(ar
, ce_ctrl_addr
+
455 ar
->hw_ce_regs
->misc_ie_addr
);
457 ath10k_ce_write32(ar
,
458 ce_ctrl_addr
+ ar
->hw_ce_regs
->misc_ie_addr
,
459 misc_ie_addr
| misc_regs
->err_mask
);
462 static inline void ath10k_ce_error_intr_disable(struct ath10k
*ar
,
465 struct ath10k_hw_ce_misc_regs
*misc_regs
= ar
->hw_ce_regs
->misc_regs
;
467 u32 misc_ie_addr
= ath10k_ce_read32(ar
,
468 ce_ctrl_addr
+ ar
->hw_ce_regs
->misc_ie_addr
);
470 ath10k_ce_write32(ar
,
471 ce_ctrl_addr
+ ar
->hw_ce_regs
->misc_ie_addr
,
472 misc_ie_addr
& ~(misc_regs
->err_mask
));
475 static inline void ath10k_ce_engine_int_status_clear(struct ath10k
*ar
,
479 struct ath10k_hw_ce_host_wm_regs
*wm_regs
= ar
->hw_ce_regs
->wm_regs
;
481 ath10k_ce_write32(ar
, ce_ctrl_addr
+ wm_regs
->addr
, mask
);
485 * Guts of ath10k_ce_send.
486 * The caller takes responsibility for any needed locking.
488 static int _ath10k_ce_send_nolock(struct ath10k_ce_pipe
*ce_state
,
489 void *per_transfer_context
,
492 unsigned int transfer_id
,
495 struct ath10k
*ar
= ce_state
->ar
;
496 struct ath10k_ce_ring
*src_ring
= ce_state
->src_ring
;
497 struct ce_desc
*desc
, sdesc
;
498 unsigned int nentries_mask
= src_ring
->nentries_mask
;
499 unsigned int sw_index
= src_ring
->sw_index
;
500 unsigned int write_index
= src_ring
->write_index
;
501 u32 ctrl_addr
= ce_state
->ctrl_addr
;
505 if (nbytes
> ce_state
->src_sz_max
)
506 ath10k_warn(ar
, "%s: send more we can (nbytes: %d, max: %d)\n",
507 __func__
, nbytes
, ce_state
->src_sz_max
);
509 if (unlikely(CE_RING_DELTA(nentries_mask
,
510 write_index
, sw_index
- 1) <= 0)) {
515 desc
= CE_SRC_RING_TO_DESC(src_ring
->base_addr_owner_space
,
518 desc_flags
|= SM(transfer_id
, CE_DESC_FLAGS_META_DATA
);
520 if (flags
& CE_SEND_FLAG_GATHER
)
521 desc_flags
|= CE_DESC_FLAGS_GATHER
;
522 if (flags
& CE_SEND_FLAG_BYTE_SWAP
)
523 desc_flags
|= CE_DESC_FLAGS_BYTE_SWAP
;
525 sdesc
.addr
= __cpu_to_le32(buffer
);
526 sdesc
.nbytes
= __cpu_to_le16(nbytes
);
527 sdesc
.flags
= __cpu_to_le16(desc_flags
);
531 src_ring
->per_transfer_context
[write_index
] = per_transfer_context
;
533 /* Update Source Ring Write Index */
534 write_index
= CE_RING_IDX_INCR(nentries_mask
, write_index
);
537 if (!(flags
& CE_SEND_FLAG_GATHER
))
538 ath10k_ce_src_ring_write_index_set(ar
, ctrl_addr
, write_index
);
540 src_ring
->write_index
= write_index
;
545 static int _ath10k_ce_send_nolock_64(struct ath10k_ce_pipe
*ce_state
,
546 void *per_transfer_context
,
549 unsigned int transfer_id
,
552 struct ath10k
*ar
= ce_state
->ar
;
553 struct ath10k_ce_ring
*src_ring
= ce_state
->src_ring
;
554 struct ce_desc_64
*desc
, sdesc
;
555 unsigned int nentries_mask
= src_ring
->nentries_mask
;
556 unsigned int sw_index
;
557 unsigned int write_index
= src_ring
->write_index
;
558 u32 ctrl_addr
= ce_state
->ctrl_addr
;
563 if (test_bit(ATH10K_FLAG_CRASH_FLUSH
, &ar
->dev_flags
))
566 if (nbytes
> ce_state
->src_sz_max
)
567 ath10k_warn(ar
, "%s: send more we can (nbytes: %d, max: %d)\n",
568 __func__
, nbytes
, ce_state
->src_sz_max
);
570 if (ar
->hw_params
.rri_on_ddr
)
571 sw_index
= ath10k_ce_src_ring_read_index_from_ddr(ar
, ce_state
->id
);
573 sw_index
= src_ring
->sw_index
;
575 if (unlikely(CE_RING_DELTA(nentries_mask
,
576 write_index
, sw_index
- 1) <= 0)) {
581 desc
= CE_SRC_RING_TO_DESC_64(src_ring
->base_addr_owner_space
,
584 desc_flags
|= SM(transfer_id
, CE_DESC_FLAGS_META_DATA
);
586 if (flags
& CE_SEND_FLAG_GATHER
)
587 desc_flags
|= CE_DESC_FLAGS_GATHER
;
589 if (flags
& CE_SEND_FLAG_BYTE_SWAP
)
590 desc_flags
|= CE_DESC_FLAGS_BYTE_SWAP
;
592 addr
= (__le32
*)&sdesc
.addr
;
594 flags
|= upper_32_bits(buffer
) & CE_DESC_ADDR_HI_MASK
;
595 addr
[0] = __cpu_to_le32(buffer
);
596 addr
[1] = __cpu_to_le32(flags
);
597 if (flags
& CE_SEND_FLAG_GATHER
)
598 addr
[1] |= __cpu_to_le32(CE_WCN3990_DESC_FLAGS_GATHER
);
600 addr
[1] &= ~(__cpu_to_le32(CE_WCN3990_DESC_FLAGS_GATHER
));
602 sdesc
.nbytes
= __cpu_to_le16(nbytes
);
603 sdesc
.flags
= __cpu_to_le16(desc_flags
);
607 src_ring
->per_transfer_context
[write_index
] = per_transfer_context
;
609 /* Update Source Ring Write Index */
610 write_index
= CE_RING_IDX_INCR(nentries_mask
, write_index
);
612 if (!(flags
& CE_SEND_FLAG_GATHER
)) {
613 if (ar
->hw_params
.shadow_reg_support
)
614 ath10k_ce_shadow_src_ring_write_index_set(ar
, ce_state
,
617 ath10k_ce_src_ring_write_index_set(ar
, ctrl_addr
,
621 src_ring
->write_index
= write_index
;
626 int ath10k_ce_send_nolock(struct ath10k_ce_pipe
*ce_state
,
627 void *per_transfer_context
,
630 unsigned int transfer_id
,
633 return ce_state
->ops
->ce_send_nolock(ce_state
, per_transfer_context
,
634 buffer
, nbytes
, transfer_id
, flags
);
636 EXPORT_SYMBOL(ath10k_ce_send_nolock
);
638 void __ath10k_ce_send_revert(struct ath10k_ce_pipe
*pipe
)
640 struct ath10k
*ar
= pipe
->ar
;
641 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
642 struct ath10k_ce_ring
*src_ring
= pipe
->src_ring
;
643 u32 ctrl_addr
= pipe
->ctrl_addr
;
645 lockdep_assert_held(&ce
->ce_lock
);
648 * This function must be called only if there is an incomplete
649 * scatter-gather transfer (before index register is updated)
650 * that needs to be cleaned up.
652 if (WARN_ON_ONCE(src_ring
->write_index
== src_ring
->sw_index
))
655 if (WARN_ON_ONCE(src_ring
->write_index
==
656 ath10k_ce_src_ring_write_index_get(ar
, ctrl_addr
)))
659 src_ring
->write_index
--;
660 src_ring
->write_index
&= src_ring
->nentries_mask
;
662 src_ring
->per_transfer_context
[src_ring
->write_index
] = NULL
;
664 EXPORT_SYMBOL(__ath10k_ce_send_revert
);
666 int ath10k_ce_send(struct ath10k_ce_pipe
*ce_state
,
667 void *per_transfer_context
,
670 unsigned int transfer_id
,
673 struct ath10k
*ar
= ce_state
->ar
;
674 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
677 spin_lock_bh(&ce
->ce_lock
);
678 ret
= ath10k_ce_send_nolock(ce_state
, per_transfer_context
,
679 buffer
, nbytes
, transfer_id
, flags
);
680 spin_unlock_bh(&ce
->ce_lock
);
684 EXPORT_SYMBOL(ath10k_ce_send
);
686 int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe
*pipe
)
688 struct ath10k
*ar
= pipe
->ar
;
689 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
692 spin_lock_bh(&ce
->ce_lock
);
693 delta
= CE_RING_DELTA(pipe
->src_ring
->nentries_mask
,
694 pipe
->src_ring
->write_index
,
695 pipe
->src_ring
->sw_index
- 1);
696 spin_unlock_bh(&ce
->ce_lock
);
700 EXPORT_SYMBOL(ath10k_ce_num_free_src_entries
);
702 int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe
*pipe
)
704 struct ath10k
*ar
= pipe
->ar
;
705 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
706 struct ath10k_ce_ring
*dest_ring
= pipe
->dest_ring
;
707 unsigned int nentries_mask
= dest_ring
->nentries_mask
;
708 unsigned int write_index
= dest_ring
->write_index
;
709 unsigned int sw_index
= dest_ring
->sw_index
;
711 lockdep_assert_held(&ce
->ce_lock
);
713 return CE_RING_DELTA(nentries_mask
, write_index
, sw_index
- 1);
715 EXPORT_SYMBOL(__ath10k_ce_rx_num_free_bufs
);
717 static int __ath10k_ce_rx_post_buf(struct ath10k_ce_pipe
*pipe
, void *ctx
,
720 struct ath10k
*ar
= pipe
->ar
;
721 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
722 struct ath10k_ce_ring
*dest_ring
= pipe
->dest_ring
;
723 unsigned int nentries_mask
= dest_ring
->nentries_mask
;
724 unsigned int write_index
= dest_ring
->write_index
;
725 unsigned int sw_index
= dest_ring
->sw_index
;
726 struct ce_desc
*base
= dest_ring
->base_addr_owner_space
;
727 struct ce_desc
*desc
= CE_DEST_RING_TO_DESC(base
, write_index
);
728 u32 ctrl_addr
= pipe
->ctrl_addr
;
730 lockdep_assert_held(&ce
->ce_lock
);
732 if ((pipe
->id
!= 5) &&
733 CE_RING_DELTA(nentries_mask
, write_index
, sw_index
- 1) == 0)
736 desc
->addr
= __cpu_to_le32(paddr
);
739 dest_ring
->per_transfer_context
[write_index
] = ctx
;
740 write_index
= CE_RING_IDX_INCR(nentries_mask
, write_index
);
741 ath10k_ce_dest_ring_write_index_set(ar
, ctrl_addr
, write_index
);
742 dest_ring
->write_index
= write_index
;
747 static int __ath10k_ce_rx_post_buf_64(struct ath10k_ce_pipe
*pipe
,
751 struct ath10k
*ar
= pipe
->ar
;
752 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
753 struct ath10k_ce_ring
*dest_ring
= pipe
->dest_ring
;
754 unsigned int nentries_mask
= dest_ring
->nentries_mask
;
755 unsigned int write_index
= dest_ring
->write_index
;
756 unsigned int sw_index
= dest_ring
->sw_index
;
757 struct ce_desc_64
*base
= dest_ring
->base_addr_owner_space
;
758 struct ce_desc_64
*desc
=
759 CE_DEST_RING_TO_DESC_64(base
, write_index
);
760 u32 ctrl_addr
= pipe
->ctrl_addr
;
762 lockdep_assert_held(&ce
->ce_lock
);
764 if (CE_RING_DELTA(nentries_mask
, write_index
, sw_index
- 1) == 0)
767 desc
->addr
= __cpu_to_le64(paddr
);
768 desc
->addr
&= __cpu_to_le64(CE_DESC_ADDR_MASK
);
772 dest_ring
->per_transfer_context
[write_index
] = ctx
;
773 write_index
= CE_RING_IDX_INCR(nentries_mask
, write_index
);
774 ath10k_ce_dest_ring_write_index_set(ar
, ctrl_addr
, write_index
);
775 dest_ring
->write_index
= write_index
;
780 void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe
*pipe
, u32 nentries
)
782 struct ath10k
*ar
= pipe
->ar
;
783 struct ath10k_ce_ring
*dest_ring
= pipe
->dest_ring
;
784 unsigned int nentries_mask
= dest_ring
->nentries_mask
;
785 unsigned int write_index
= dest_ring
->write_index
;
786 u32 ctrl_addr
= pipe
->ctrl_addr
;
787 u32 cur_write_idx
= ath10k_ce_dest_ring_write_index_get(ar
, ctrl_addr
);
789 /* Prevent CE ring stuck issue that will occur when ring is full.
790 * Make sure that write index is 1 less than read index.
792 if (((cur_write_idx
+ nentries
) & nentries_mask
) == dest_ring
->sw_index
)
795 write_index
= CE_RING_IDX_ADD(nentries_mask
, write_index
, nentries
);
796 ath10k_ce_dest_ring_write_index_set(ar
, ctrl_addr
, write_index
);
797 dest_ring
->write_index
= write_index
;
799 EXPORT_SYMBOL(ath10k_ce_rx_update_write_idx
);
801 int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe
*pipe
, void *ctx
,
804 struct ath10k
*ar
= pipe
->ar
;
805 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
808 spin_lock_bh(&ce
->ce_lock
);
809 ret
= pipe
->ops
->ce_rx_post_buf(pipe
, ctx
, paddr
);
810 spin_unlock_bh(&ce
->ce_lock
);
814 EXPORT_SYMBOL(ath10k_ce_rx_post_buf
);
817 * Guts of ath10k_ce_completed_recv_next.
818 * The caller takes responsibility for any necessary locking.
821 _ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe
*ce_state
,
822 void **per_transfer_contextp
,
823 unsigned int *nbytesp
)
825 struct ath10k_ce_ring
*dest_ring
= ce_state
->dest_ring
;
826 unsigned int nentries_mask
= dest_ring
->nentries_mask
;
827 unsigned int sw_index
= dest_ring
->sw_index
;
829 struct ce_desc
*base
= dest_ring
->base_addr_owner_space
;
830 struct ce_desc
*desc
= CE_DEST_RING_TO_DESC(base
, sw_index
);
831 struct ce_desc sdesc
;
834 /* Copy in one go for performance reasons */
837 nbytes
= __le16_to_cpu(sdesc
.nbytes
);
840 * This closes a relatively unusual race where the Host
841 * sees the updated DRRI before the update to the
842 * corresponding descriptor has completed. We treat this
843 * as a descriptor that is not yet done.
850 /* Return data from completed destination descriptor */
853 if (per_transfer_contextp
)
854 *per_transfer_contextp
=
855 dest_ring
->per_transfer_context
[sw_index
];
857 /* Copy engine 5 (HTT Rx) will reuse the same transfer context.
858 * So update transfer context all CEs except CE5.
860 if (ce_state
->id
!= 5)
861 dest_ring
->per_transfer_context
[sw_index
] = NULL
;
863 /* Update sw_index */
864 sw_index
= CE_RING_IDX_INCR(nentries_mask
, sw_index
);
865 dest_ring
->sw_index
= sw_index
;
871 _ath10k_ce_completed_recv_next_nolock_64(struct ath10k_ce_pipe
*ce_state
,
872 void **per_transfer_contextp
,
873 unsigned int *nbytesp
)
875 struct ath10k_ce_ring
*dest_ring
= ce_state
->dest_ring
;
876 unsigned int nentries_mask
= dest_ring
->nentries_mask
;
877 unsigned int sw_index
= dest_ring
->sw_index
;
878 struct ce_desc_64
*base
= dest_ring
->base_addr_owner_space
;
879 struct ce_desc_64
*desc
=
880 CE_DEST_RING_TO_DESC_64(base
, sw_index
);
881 struct ce_desc_64 sdesc
;
884 /* Copy in one go for performance reasons */
887 nbytes
= __le16_to_cpu(sdesc
.nbytes
);
889 /* This closes a relatively unusual race where the Host
890 * sees the updated DRRI before the update to the
891 * corresponding descriptor has completed. We treat this
892 * as a descriptor that is not yet done.
899 /* Return data from completed destination descriptor */
902 if (per_transfer_contextp
)
903 *per_transfer_contextp
=
904 dest_ring
->per_transfer_context
[sw_index
];
906 /* Copy engine 5 (HTT Rx) will reuse the same transfer context.
907 * So update transfer context all CEs except CE5.
909 if (ce_state
->id
!= 5)
910 dest_ring
->per_transfer_context
[sw_index
] = NULL
;
912 /* Update sw_index */
913 sw_index
= CE_RING_IDX_INCR(nentries_mask
, sw_index
);
914 dest_ring
->sw_index
= sw_index
;
919 int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe
*ce_state
,
920 void **per_transfer_ctx
,
921 unsigned int *nbytesp
)
923 return ce_state
->ops
->ce_completed_recv_next_nolock(ce_state
,
927 EXPORT_SYMBOL(ath10k_ce_completed_recv_next_nolock
);
929 int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe
*ce_state
,
930 void **per_transfer_contextp
,
931 unsigned int *nbytesp
)
933 struct ath10k
*ar
= ce_state
->ar
;
934 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
937 spin_lock_bh(&ce
->ce_lock
);
938 ret
= ce_state
->ops
->ce_completed_recv_next_nolock(ce_state
,
939 per_transfer_contextp
,
942 spin_unlock_bh(&ce
->ce_lock
);
946 EXPORT_SYMBOL(ath10k_ce_completed_recv_next
);
948 static int _ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe
*ce_state
,
949 void **per_transfer_contextp
,
952 struct ath10k_ce_ring
*dest_ring
;
953 unsigned int nentries_mask
;
954 unsigned int sw_index
;
955 unsigned int write_index
;
958 struct ath10k_ce
*ce
;
960 dest_ring
= ce_state
->dest_ring
;
966 ce
= ath10k_ce_priv(ar
);
968 spin_lock_bh(&ce
->ce_lock
);
970 nentries_mask
= dest_ring
->nentries_mask
;
971 sw_index
= dest_ring
->sw_index
;
972 write_index
= dest_ring
->write_index
;
973 if (write_index
!= sw_index
) {
974 struct ce_desc
*base
= dest_ring
->base_addr_owner_space
;
975 struct ce_desc
*desc
= CE_DEST_RING_TO_DESC(base
, sw_index
);
977 /* Return data from completed destination descriptor */
978 *bufferp
= __le32_to_cpu(desc
->addr
);
980 if (per_transfer_contextp
)
981 *per_transfer_contextp
=
982 dest_ring
->per_transfer_context
[sw_index
];
985 dest_ring
->per_transfer_context
[sw_index
] = NULL
;
988 /* Update sw_index */
989 sw_index
= CE_RING_IDX_INCR(nentries_mask
, sw_index
);
990 dest_ring
->sw_index
= sw_index
;
996 spin_unlock_bh(&ce
->ce_lock
);
1001 static int _ath10k_ce_revoke_recv_next_64(struct ath10k_ce_pipe
*ce_state
,
1002 void **per_transfer_contextp
,
1003 dma_addr_t
*bufferp
)
1005 struct ath10k_ce_ring
*dest_ring
;
1006 unsigned int nentries_mask
;
1007 unsigned int sw_index
;
1008 unsigned int write_index
;
1011 struct ath10k_ce
*ce
;
1013 dest_ring
= ce_state
->dest_ring
;
1019 ce
= ath10k_ce_priv(ar
);
1021 spin_lock_bh(&ce
->ce_lock
);
1023 nentries_mask
= dest_ring
->nentries_mask
;
1024 sw_index
= dest_ring
->sw_index
;
1025 write_index
= dest_ring
->write_index
;
1026 if (write_index
!= sw_index
) {
1027 struct ce_desc_64
*base
= dest_ring
->base_addr_owner_space
;
1028 struct ce_desc_64
*desc
=
1029 CE_DEST_RING_TO_DESC_64(base
, sw_index
);
1031 /* Return data from completed destination descriptor */
1032 *bufferp
= __le64_to_cpu(desc
->addr
);
1034 if (per_transfer_contextp
)
1035 *per_transfer_contextp
=
1036 dest_ring
->per_transfer_context
[sw_index
];
1039 dest_ring
->per_transfer_context
[sw_index
] = NULL
;
1042 /* Update sw_index */
1043 sw_index
= CE_RING_IDX_INCR(nentries_mask
, sw_index
);
1044 dest_ring
->sw_index
= sw_index
;
1050 spin_unlock_bh(&ce
->ce_lock
);
1055 int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe
*ce_state
,
1056 void **per_transfer_contextp
,
1057 dma_addr_t
*bufferp
)
1059 return ce_state
->ops
->ce_revoke_recv_next(ce_state
,
1060 per_transfer_contextp
,
1063 EXPORT_SYMBOL(ath10k_ce_revoke_recv_next
);
1066 * Guts of ath10k_ce_completed_send_next.
1067 * The caller takes responsibility for any necessary locking.
1069 static int _ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe
*ce_state
,
1070 void **per_transfer_contextp
)
1072 struct ath10k_ce_ring
*src_ring
= ce_state
->src_ring
;
1073 u32 ctrl_addr
= ce_state
->ctrl_addr
;
1074 struct ath10k
*ar
= ce_state
->ar
;
1075 unsigned int nentries_mask
= src_ring
->nentries_mask
;
1076 unsigned int sw_index
= src_ring
->sw_index
;
1077 unsigned int read_index
;
1078 struct ce_desc
*desc
;
1080 if (src_ring
->hw_index
== sw_index
) {
1082 * The SW completion index has caught up with the cached
1083 * version of the HW completion index.
1084 * Update the cached HW completion index to see whether
1085 * the SW has really caught up to the HW, or if the cached
1086 * value of the HW index has become stale.
1089 read_index
= ath10k_ce_src_ring_read_index_get(ar
, ctrl_addr
);
1090 if (read_index
== 0xffffffff)
1093 read_index
&= nentries_mask
;
1094 src_ring
->hw_index
= read_index
;
1097 if (ar
->hw_params
.rri_on_ddr
)
1098 read_index
= ath10k_ce_src_ring_read_index_get(ar
, ctrl_addr
);
1100 read_index
= src_ring
->hw_index
;
1102 if (read_index
== sw_index
)
1105 if (per_transfer_contextp
)
1106 *per_transfer_contextp
=
1107 src_ring
->per_transfer_context
[sw_index
];
1110 src_ring
->per_transfer_context
[sw_index
] = NULL
;
1111 desc
= CE_SRC_RING_TO_DESC(src_ring
->base_addr_owner_space
,
1115 /* Update sw_index */
1116 sw_index
= CE_RING_IDX_INCR(nentries_mask
, sw_index
);
1117 src_ring
->sw_index
= sw_index
;
1122 static int _ath10k_ce_completed_send_next_nolock_64(struct ath10k_ce_pipe
*ce_state
,
1123 void **per_transfer_contextp
)
1125 struct ath10k_ce_ring
*src_ring
= ce_state
->src_ring
;
1126 u32 ctrl_addr
= ce_state
->ctrl_addr
;
1127 struct ath10k
*ar
= ce_state
->ar
;
1128 unsigned int nentries_mask
= src_ring
->nentries_mask
;
1129 unsigned int sw_index
= src_ring
->sw_index
;
1130 unsigned int read_index
;
1131 struct ce_desc_64
*desc
;
1133 if (src_ring
->hw_index
== sw_index
) {
1135 * The SW completion index has caught up with the cached
1136 * version of the HW completion index.
1137 * Update the cached HW completion index to see whether
1138 * the SW has really caught up to the HW, or if the cached
1139 * value of the HW index has become stale.
1142 read_index
= ath10k_ce_src_ring_read_index_get(ar
, ctrl_addr
);
1143 if (read_index
== 0xffffffff)
1146 read_index
&= nentries_mask
;
1147 src_ring
->hw_index
= read_index
;
1150 if (ar
->hw_params
.rri_on_ddr
)
1151 read_index
= ath10k_ce_src_ring_read_index_get(ar
, ctrl_addr
);
1153 read_index
= src_ring
->hw_index
;
1155 if (read_index
== sw_index
)
1158 if (per_transfer_contextp
)
1159 *per_transfer_contextp
=
1160 src_ring
->per_transfer_context
[sw_index
];
1163 src_ring
->per_transfer_context
[sw_index
] = NULL
;
1164 desc
= CE_SRC_RING_TO_DESC_64(src_ring
->base_addr_owner_space
,
1168 /* Update sw_index */
1169 sw_index
= CE_RING_IDX_INCR(nentries_mask
, sw_index
);
1170 src_ring
->sw_index
= sw_index
;
1175 int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe
*ce_state
,
1176 void **per_transfer_contextp
)
1178 return ce_state
->ops
->ce_completed_send_next_nolock(ce_state
,
1179 per_transfer_contextp
);
1181 EXPORT_SYMBOL(ath10k_ce_completed_send_next_nolock
);
1183 static void ath10k_ce_extract_desc_data(struct ath10k
*ar
,
1184 struct ath10k_ce_ring
*src_ring
,
1186 dma_addr_t
*bufferp
,
1190 struct ce_desc
*base
= src_ring
->base_addr_owner_space
;
1191 struct ce_desc
*desc
= CE_SRC_RING_TO_DESC(base
, sw_index
);
1193 /* Return data from completed source descriptor */
1194 *bufferp
= __le32_to_cpu(desc
->addr
);
1195 *nbytesp
= __le16_to_cpu(desc
->nbytes
);
1196 *transfer_idp
= MS(__le16_to_cpu(desc
->flags
),
1197 CE_DESC_FLAGS_META_DATA
);
1200 static void ath10k_ce_extract_desc_data_64(struct ath10k
*ar
,
1201 struct ath10k_ce_ring
*src_ring
,
1203 dma_addr_t
*bufferp
,
1207 struct ce_desc_64
*base
= src_ring
->base_addr_owner_space
;
1208 struct ce_desc_64
*desc
=
1209 CE_SRC_RING_TO_DESC_64(base
, sw_index
);
1211 /* Return data from completed source descriptor */
1212 *bufferp
= __le64_to_cpu(desc
->addr
);
1213 *nbytesp
= __le16_to_cpu(desc
->nbytes
);
1214 *transfer_idp
= MS(__le16_to_cpu(desc
->flags
),
1215 CE_DESC_FLAGS_META_DATA
);
1218 /* NB: Modeled after ath10k_ce_completed_send_next */
1219 int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe
*ce_state
,
1220 void **per_transfer_contextp
,
1221 dma_addr_t
*bufferp
,
1222 unsigned int *nbytesp
,
1223 unsigned int *transfer_idp
)
1225 struct ath10k_ce_ring
*src_ring
;
1226 unsigned int nentries_mask
;
1227 unsigned int sw_index
;
1228 unsigned int write_index
;
1231 struct ath10k_ce
*ce
;
1233 src_ring
= ce_state
->src_ring
;
1239 ce
= ath10k_ce_priv(ar
);
1241 spin_lock_bh(&ce
->ce_lock
);
1243 nentries_mask
= src_ring
->nentries_mask
;
1244 sw_index
= src_ring
->sw_index
;
1245 write_index
= src_ring
->write_index
;
1247 if (write_index
!= sw_index
) {
1248 ce_state
->ops
->ce_extract_desc_data(ar
, src_ring
, sw_index
,
1252 if (per_transfer_contextp
)
1253 *per_transfer_contextp
=
1254 src_ring
->per_transfer_context
[sw_index
];
1257 src_ring
->per_transfer_context
[sw_index
] = NULL
;
1259 /* Update sw_index */
1260 sw_index
= CE_RING_IDX_INCR(nentries_mask
, sw_index
);
1261 src_ring
->sw_index
= sw_index
;
1267 spin_unlock_bh(&ce
->ce_lock
);
1271 EXPORT_SYMBOL(ath10k_ce_cancel_send_next
);
1273 int ath10k_ce_completed_send_next(struct ath10k_ce_pipe
*ce_state
,
1274 void **per_transfer_contextp
)
1276 struct ath10k
*ar
= ce_state
->ar
;
1277 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1280 spin_lock_bh(&ce
->ce_lock
);
1281 ret
= ath10k_ce_completed_send_next_nolock(ce_state
,
1282 per_transfer_contextp
);
1283 spin_unlock_bh(&ce
->ce_lock
);
1287 EXPORT_SYMBOL(ath10k_ce_completed_send_next
);
1290 * Guts of interrupt handler for per-engine interrupts on a particular CE.
1292 * Invokes registered callbacks for recv_complete,
1293 * send_complete, and watermarks.
1295 void ath10k_ce_per_engine_service(struct ath10k
*ar
, unsigned int ce_id
)
1297 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1298 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
1299 struct ath10k_hw_ce_host_wm_regs
*wm_regs
= ar
->hw_ce_regs
->wm_regs
;
1300 u32 ctrl_addr
= ce_state
->ctrl_addr
;
1302 spin_lock_bh(&ce
->ce_lock
);
1304 /* Clear the copy-complete interrupts that will be handled here. */
1305 ath10k_ce_engine_int_status_clear(ar
, ctrl_addr
,
1308 spin_unlock_bh(&ce
->ce_lock
);
1310 if (ce_state
->recv_cb
)
1311 ce_state
->recv_cb(ce_state
);
1313 if (ce_state
->send_cb
)
1314 ce_state
->send_cb(ce_state
);
1316 spin_lock_bh(&ce
->ce_lock
);
1319 * Misc CE interrupts are not being handled, but still need
1322 ath10k_ce_engine_int_status_clear(ar
, ctrl_addr
, wm_regs
->wm_mask
);
1324 spin_unlock_bh(&ce
->ce_lock
);
1326 EXPORT_SYMBOL(ath10k_ce_per_engine_service
);
1329 * Handler for per-engine interrupts on ALL active CEs.
1330 * This is used in cases where the system is sharing a
1331 * single interrput for all CEs
1334 void ath10k_ce_per_engine_service_any(struct ath10k
*ar
)
1339 intr_summary
= ath10k_ce_interrupt_summary(ar
);
1341 for (ce_id
= 0; intr_summary
&& (ce_id
< CE_COUNT
); ce_id
++) {
1342 if (intr_summary
& (1 << ce_id
))
1343 intr_summary
&= ~(1 << ce_id
);
1345 /* no intr pending on this CE */
1348 ath10k_ce_per_engine_service(ar
, ce_id
);
1351 EXPORT_SYMBOL(ath10k_ce_per_engine_service_any
);
1354 * Adjust interrupts for the copy complete handler.
1355 * If it's needed for either send or recv, then unmask
1356 * this interrupt; otherwise, mask it.
1358 * Called with ce_lock held.
1360 static void ath10k_ce_per_engine_handler_adjust(struct ath10k_ce_pipe
*ce_state
)
1362 u32 ctrl_addr
= ce_state
->ctrl_addr
;
1363 struct ath10k
*ar
= ce_state
->ar
;
1364 bool disable_copy_compl_intr
= ce_state
->attr_flags
& CE_ATTR_DIS_INTR
;
1366 if ((!disable_copy_compl_intr
) &&
1367 (ce_state
->send_cb
|| ce_state
->recv_cb
))
1368 ath10k_ce_copy_complete_inter_enable(ar
, ctrl_addr
);
1370 ath10k_ce_copy_complete_intr_disable(ar
, ctrl_addr
);
1372 ath10k_ce_watermark_intr_disable(ar
, ctrl_addr
);
1375 int ath10k_ce_disable_interrupts(struct ath10k
*ar
)
1377 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1378 struct ath10k_ce_pipe
*ce_state
;
1382 for (ce_id
= 0; ce_id
< CE_COUNT
; ce_id
++) {
1383 ce_state
= &ce
->ce_states
[ce_id
];
1384 if (ce_state
->attr_flags
& CE_ATTR_POLL
)
1387 ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
1389 ath10k_ce_copy_complete_intr_disable(ar
, ctrl_addr
);
1390 ath10k_ce_error_intr_disable(ar
, ctrl_addr
);
1391 ath10k_ce_watermark_intr_disable(ar
, ctrl_addr
);
1396 EXPORT_SYMBOL(ath10k_ce_disable_interrupts
);
1398 void ath10k_ce_enable_interrupts(struct ath10k
*ar
)
1400 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1402 struct ath10k_ce_pipe
*ce_state
;
1404 /* Enable interrupts for copy engine that
1405 * are not using polling mode.
1407 for (ce_id
= 0; ce_id
< CE_COUNT
; ce_id
++) {
1408 ce_state
= &ce
->ce_states
[ce_id
];
1409 if (ce_state
->attr_flags
& CE_ATTR_POLL
)
1412 ath10k_ce_per_engine_handler_adjust(ce_state
);
1415 EXPORT_SYMBOL(ath10k_ce_enable_interrupts
);
1417 static int ath10k_ce_init_src_ring(struct ath10k
*ar
,
1419 const struct ce_attr
*attr
)
1421 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1422 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
1423 struct ath10k_ce_ring
*src_ring
= ce_state
->src_ring
;
1424 u32 nentries
, ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
1426 nentries
= roundup_pow_of_two(attr
->src_nentries
);
1428 if (ar
->hw_params
.target_64bit
)
1429 memset(src_ring
->base_addr_owner_space
, 0,
1430 nentries
* sizeof(struct ce_desc_64
));
1432 memset(src_ring
->base_addr_owner_space
, 0,
1433 nentries
* sizeof(struct ce_desc
));
1435 src_ring
->sw_index
= ath10k_ce_src_ring_read_index_get(ar
, ctrl_addr
);
1436 src_ring
->sw_index
&= src_ring
->nentries_mask
;
1437 src_ring
->hw_index
= src_ring
->sw_index
;
1439 src_ring
->write_index
=
1440 ath10k_ce_src_ring_write_index_get(ar
, ctrl_addr
);
1441 src_ring
->write_index
&= src_ring
->nentries_mask
;
1443 ath10k_ce_src_ring_base_addr_set(ar
, ce_id
,
1444 src_ring
->base_addr_ce_space
);
1445 ath10k_ce_src_ring_size_set(ar
, ctrl_addr
, nentries
);
1446 ath10k_ce_src_ring_dmax_set(ar
, ctrl_addr
, attr
->src_sz_max
);
1447 ath10k_ce_src_ring_byte_swap_set(ar
, ctrl_addr
, 0);
1448 ath10k_ce_src_ring_lowmark_set(ar
, ctrl_addr
, 0);
1449 ath10k_ce_src_ring_highmark_set(ar
, ctrl_addr
, nentries
);
1451 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1452 "boot init ce src ring id %d entries %d base_addr %pK\n",
1453 ce_id
, nentries
, src_ring
->base_addr_owner_space
);
1458 static int ath10k_ce_init_dest_ring(struct ath10k
*ar
,
1460 const struct ce_attr
*attr
)
1462 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1463 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
1464 struct ath10k_ce_ring
*dest_ring
= ce_state
->dest_ring
;
1465 u32 nentries
, ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
1467 nentries
= roundup_pow_of_two(attr
->dest_nentries
);
1469 if (ar
->hw_params
.target_64bit
)
1470 memset(dest_ring
->base_addr_owner_space
, 0,
1471 nentries
* sizeof(struct ce_desc_64
));
1473 memset(dest_ring
->base_addr_owner_space
, 0,
1474 nentries
* sizeof(struct ce_desc
));
1476 dest_ring
->sw_index
= ath10k_ce_dest_ring_read_index_get(ar
, ctrl_addr
);
1477 dest_ring
->sw_index
&= dest_ring
->nentries_mask
;
1478 dest_ring
->write_index
=
1479 ath10k_ce_dest_ring_write_index_get(ar
, ctrl_addr
);
1480 dest_ring
->write_index
&= dest_ring
->nentries_mask
;
1482 ath10k_ce_dest_ring_base_addr_set(ar
, ce_id
,
1483 dest_ring
->base_addr_ce_space
);
1484 ath10k_ce_dest_ring_size_set(ar
, ctrl_addr
, nentries
);
1485 ath10k_ce_dest_ring_byte_swap_set(ar
, ctrl_addr
, 0);
1486 ath10k_ce_dest_ring_lowmark_set(ar
, ctrl_addr
, 0);
1487 ath10k_ce_dest_ring_highmark_set(ar
, ctrl_addr
, nentries
);
1489 ath10k_dbg(ar
, ATH10K_DBG_BOOT
,
1490 "boot ce dest ring id %d entries %d base_addr %pK\n",
1491 ce_id
, nentries
, dest_ring
->base_addr_owner_space
);
1496 static int ath10k_ce_alloc_shadow_base(struct ath10k
*ar
,
1497 struct ath10k_ce_ring
*src_ring
,
1500 src_ring
->shadow_base_unaligned
= kcalloc(nentries
,
1501 sizeof(struct ce_desc_64
),
1503 if (!src_ring
->shadow_base_unaligned
)
1506 src_ring
->shadow_base
= (struct ce_desc_64
*)
1507 PTR_ALIGN(src_ring
->shadow_base_unaligned
,
1508 CE_DESC_RING_ALIGN
);
1512 static struct ath10k_ce_ring
*
1513 ath10k_ce_alloc_src_ring(struct ath10k
*ar
, unsigned int ce_id
,
1514 const struct ce_attr
*attr
)
1516 struct ath10k_ce_ring
*src_ring
;
1517 u32 nentries
= attr
->src_nentries
;
1518 dma_addr_t base_addr
;
1521 nentries
= roundup_pow_of_two(nentries
);
1523 src_ring
= kzalloc(struct_size(src_ring
, per_transfer_context
,
1524 nentries
), GFP_KERNEL
);
1525 if (src_ring
== NULL
)
1526 return ERR_PTR(-ENOMEM
);
1528 src_ring
->nentries
= nentries
;
1529 src_ring
->nentries_mask
= nentries
- 1;
1532 * Legacy platforms that do not support cache
1533 * coherent DMA are unsupported
1535 src_ring
->base_addr_owner_space_unaligned
=
1536 dma_alloc_coherent(ar
->dev
,
1537 (nentries
* sizeof(struct ce_desc
) +
1538 CE_DESC_RING_ALIGN
),
1539 &base_addr
, GFP_KERNEL
);
1540 if (!src_ring
->base_addr_owner_space_unaligned
) {
1542 return ERR_PTR(-ENOMEM
);
1545 src_ring
->base_addr_ce_space_unaligned
= base_addr
;
1547 src_ring
->base_addr_owner_space
=
1548 PTR_ALIGN(src_ring
->base_addr_owner_space_unaligned
,
1549 CE_DESC_RING_ALIGN
);
1550 src_ring
->base_addr_ce_space
=
1551 ALIGN(src_ring
->base_addr_ce_space_unaligned
,
1552 CE_DESC_RING_ALIGN
);
1554 if (ar
->hw_params
.shadow_reg_support
) {
1555 ret
= ath10k_ce_alloc_shadow_base(ar
, src_ring
, nentries
);
1557 dma_free_coherent(ar
->dev
,
1558 (nentries
* sizeof(struct ce_desc_64
) +
1559 CE_DESC_RING_ALIGN
),
1560 src_ring
->base_addr_owner_space_unaligned
,
1563 return ERR_PTR(ret
);
1570 static struct ath10k_ce_ring
*
1571 ath10k_ce_alloc_src_ring_64(struct ath10k
*ar
, unsigned int ce_id
,
1572 const struct ce_attr
*attr
)
1574 struct ath10k_ce_ring
*src_ring
;
1575 u32 nentries
= attr
->src_nentries
;
1576 dma_addr_t base_addr
;
1579 nentries
= roundup_pow_of_two(nentries
);
1581 src_ring
= kzalloc(struct_size(src_ring
, per_transfer_context
,
1582 nentries
), GFP_KERNEL
);
1584 return ERR_PTR(-ENOMEM
);
1586 src_ring
->nentries
= nentries
;
1587 src_ring
->nentries_mask
= nentries
- 1;
1589 /* Legacy platforms that do not support cache
1590 * coherent DMA are unsupported
1592 src_ring
->base_addr_owner_space_unaligned
=
1593 dma_alloc_coherent(ar
->dev
,
1594 (nentries
* sizeof(struct ce_desc_64
) +
1595 CE_DESC_RING_ALIGN
),
1596 &base_addr
, GFP_KERNEL
);
1597 if (!src_ring
->base_addr_owner_space_unaligned
) {
1599 return ERR_PTR(-ENOMEM
);
1602 src_ring
->base_addr_ce_space_unaligned
= base_addr
;
1604 src_ring
->base_addr_owner_space
=
1605 PTR_ALIGN(src_ring
->base_addr_owner_space_unaligned
,
1606 CE_DESC_RING_ALIGN
);
1607 src_ring
->base_addr_ce_space
=
1608 ALIGN(src_ring
->base_addr_ce_space_unaligned
,
1609 CE_DESC_RING_ALIGN
);
1611 if (ar
->hw_params
.shadow_reg_support
) {
1612 ret
= ath10k_ce_alloc_shadow_base(ar
, src_ring
, nentries
);
1614 dma_free_coherent(ar
->dev
,
1615 (nentries
* sizeof(struct ce_desc_64
) +
1616 CE_DESC_RING_ALIGN
),
1617 src_ring
->base_addr_owner_space_unaligned
,
1620 return ERR_PTR(ret
);
1627 static struct ath10k_ce_ring
*
1628 ath10k_ce_alloc_dest_ring(struct ath10k
*ar
, unsigned int ce_id
,
1629 const struct ce_attr
*attr
)
1631 struct ath10k_ce_ring
*dest_ring
;
1633 dma_addr_t base_addr
;
1635 nentries
= roundup_pow_of_two(attr
->dest_nentries
);
1637 dest_ring
= kzalloc(struct_size(dest_ring
, per_transfer_context
,
1638 nentries
), GFP_KERNEL
);
1639 if (dest_ring
== NULL
)
1640 return ERR_PTR(-ENOMEM
);
1642 dest_ring
->nentries
= nentries
;
1643 dest_ring
->nentries_mask
= nentries
- 1;
1646 * Legacy platforms that do not support cache
1647 * coherent DMA are unsupported
1649 dest_ring
->base_addr_owner_space_unaligned
=
1650 dma_alloc_coherent(ar
->dev
,
1651 (nentries
* sizeof(struct ce_desc
) +
1652 CE_DESC_RING_ALIGN
),
1653 &base_addr
, GFP_KERNEL
);
1654 if (!dest_ring
->base_addr_owner_space_unaligned
) {
1656 return ERR_PTR(-ENOMEM
);
1659 dest_ring
->base_addr_ce_space_unaligned
= base_addr
;
1661 dest_ring
->base_addr_owner_space
=
1662 PTR_ALIGN(dest_ring
->base_addr_owner_space_unaligned
,
1663 CE_DESC_RING_ALIGN
);
1664 dest_ring
->base_addr_ce_space
=
1665 ALIGN(dest_ring
->base_addr_ce_space_unaligned
,
1666 CE_DESC_RING_ALIGN
);
1671 static struct ath10k_ce_ring
*
1672 ath10k_ce_alloc_dest_ring_64(struct ath10k
*ar
, unsigned int ce_id
,
1673 const struct ce_attr
*attr
)
1675 struct ath10k_ce_ring
*dest_ring
;
1677 dma_addr_t base_addr
;
1679 nentries
= roundup_pow_of_two(attr
->dest_nentries
);
1681 dest_ring
= kzalloc(struct_size(dest_ring
, per_transfer_context
,
1682 nentries
), GFP_KERNEL
);
1684 return ERR_PTR(-ENOMEM
);
1686 dest_ring
->nentries
= nentries
;
1687 dest_ring
->nentries_mask
= nentries
- 1;
1689 /* Legacy platforms that do not support cache
1690 * coherent DMA are unsupported
1692 dest_ring
->base_addr_owner_space_unaligned
=
1693 dma_alloc_coherent(ar
->dev
,
1694 (nentries
* sizeof(struct ce_desc_64
) +
1695 CE_DESC_RING_ALIGN
),
1696 &base_addr
, GFP_KERNEL
);
1697 if (!dest_ring
->base_addr_owner_space_unaligned
) {
1699 return ERR_PTR(-ENOMEM
);
1702 dest_ring
->base_addr_ce_space_unaligned
= base_addr
;
1704 /* Correctly initialize memory to 0 to prevent garbage
1705 * data crashing system when download firmware
1707 dest_ring
->base_addr_owner_space
=
1708 PTR_ALIGN(dest_ring
->base_addr_owner_space_unaligned
,
1709 CE_DESC_RING_ALIGN
);
1710 dest_ring
->base_addr_ce_space
=
1711 ALIGN(dest_ring
->base_addr_ce_space_unaligned
,
1712 CE_DESC_RING_ALIGN
);
1718 * Initialize a Copy Engine based on caller-supplied attributes.
1719 * This may be called once to initialize both source and destination
1720 * rings or it may be called twice for separate source and destination
1721 * initialization. It may be that only one side or the other is
1722 * initialized by software/firmware.
1724 int ath10k_ce_init_pipe(struct ath10k
*ar
, unsigned int ce_id
,
1725 const struct ce_attr
*attr
)
1729 if (attr
->src_nentries
) {
1730 ret
= ath10k_ce_init_src_ring(ar
, ce_id
, attr
);
1732 ath10k_err(ar
, "Failed to initialize CE src ring for ID: %d (%d)\n",
1738 if (attr
->dest_nentries
) {
1739 ret
= ath10k_ce_init_dest_ring(ar
, ce_id
, attr
);
1741 ath10k_err(ar
, "Failed to initialize CE dest ring for ID: %d (%d)\n",
1749 EXPORT_SYMBOL(ath10k_ce_init_pipe
);
1751 static void ath10k_ce_deinit_src_ring(struct ath10k
*ar
, unsigned int ce_id
)
1753 u32 ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
1755 ath10k_ce_src_ring_base_addr_set(ar
, ce_id
, 0);
1756 ath10k_ce_src_ring_size_set(ar
, ctrl_addr
, 0);
1757 ath10k_ce_src_ring_dmax_set(ar
, ctrl_addr
, 0);
1758 ath10k_ce_src_ring_highmark_set(ar
, ctrl_addr
, 0);
1761 static void ath10k_ce_deinit_dest_ring(struct ath10k
*ar
, unsigned int ce_id
)
1763 u32 ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
1765 ath10k_ce_dest_ring_base_addr_set(ar
, ce_id
, 0);
1766 ath10k_ce_dest_ring_size_set(ar
, ctrl_addr
, 0);
1767 ath10k_ce_dest_ring_highmark_set(ar
, ctrl_addr
, 0);
1770 void ath10k_ce_deinit_pipe(struct ath10k
*ar
, unsigned int ce_id
)
1772 ath10k_ce_deinit_src_ring(ar
, ce_id
);
1773 ath10k_ce_deinit_dest_ring(ar
, ce_id
);
1775 EXPORT_SYMBOL(ath10k_ce_deinit_pipe
);
1777 static void _ath10k_ce_free_pipe(struct ath10k
*ar
, int ce_id
)
1779 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1780 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
1782 if (ce_state
->src_ring
) {
1783 if (ar
->hw_params
.shadow_reg_support
)
1784 kfree(ce_state
->src_ring
->shadow_base_unaligned
);
1785 dma_free_coherent(ar
->dev
,
1786 (ce_state
->src_ring
->nentries
*
1787 sizeof(struct ce_desc
) +
1788 CE_DESC_RING_ALIGN
),
1789 ce_state
->src_ring
->base_addr_owner_space
,
1790 ce_state
->src_ring
->base_addr_ce_space
);
1791 kfree(ce_state
->src_ring
);
1794 if (ce_state
->dest_ring
) {
1795 dma_free_coherent(ar
->dev
,
1796 (ce_state
->dest_ring
->nentries
*
1797 sizeof(struct ce_desc
) +
1798 CE_DESC_RING_ALIGN
),
1799 ce_state
->dest_ring
->base_addr_owner_space
,
1800 ce_state
->dest_ring
->base_addr_ce_space
);
1801 kfree(ce_state
->dest_ring
);
1804 ce_state
->src_ring
= NULL
;
1805 ce_state
->dest_ring
= NULL
;
1808 static void _ath10k_ce_free_pipe_64(struct ath10k
*ar
, int ce_id
)
1810 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1811 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
1813 if (ce_state
->src_ring
) {
1814 if (ar
->hw_params
.shadow_reg_support
)
1815 kfree(ce_state
->src_ring
->shadow_base_unaligned
);
1816 dma_free_coherent(ar
->dev
,
1817 (ce_state
->src_ring
->nentries
*
1818 sizeof(struct ce_desc_64
) +
1819 CE_DESC_RING_ALIGN
),
1820 ce_state
->src_ring
->base_addr_owner_space
,
1821 ce_state
->src_ring
->base_addr_ce_space
);
1822 kfree(ce_state
->src_ring
);
1825 if (ce_state
->dest_ring
) {
1826 dma_free_coherent(ar
->dev
,
1827 (ce_state
->dest_ring
->nentries
*
1828 sizeof(struct ce_desc_64
) +
1829 CE_DESC_RING_ALIGN
),
1830 ce_state
->dest_ring
->base_addr_owner_space
,
1831 ce_state
->dest_ring
->base_addr_ce_space
);
1832 kfree(ce_state
->dest_ring
);
1835 ce_state
->src_ring
= NULL
;
1836 ce_state
->dest_ring
= NULL
;
1839 void ath10k_ce_free_pipe(struct ath10k
*ar
, int ce_id
)
1841 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1842 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
1844 ce_state
->ops
->ce_free_pipe(ar
, ce_id
);
1846 EXPORT_SYMBOL(ath10k_ce_free_pipe
);
1848 void ath10k_ce_dump_registers(struct ath10k
*ar
,
1849 struct ath10k_fw_crash_data
*crash_data
)
1851 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1852 struct ath10k_ce_crash_data ce_data
;
1855 lockdep_assert_held(&ar
->dump_mutex
);
1857 ath10k_err(ar
, "Copy Engine register dump:\n");
1859 spin_lock_bh(&ce
->ce_lock
);
1860 for (id
= 0; id
< CE_COUNT
; id
++) {
1861 addr
= ath10k_ce_base_address(ar
, id
);
1862 ce_data
.base_addr
= cpu_to_le32(addr
);
1864 ce_data
.src_wr_idx
=
1865 cpu_to_le32(ath10k_ce_src_ring_write_index_get(ar
, addr
));
1867 cpu_to_le32(ath10k_ce_src_ring_read_index_get(ar
, addr
));
1868 ce_data
.dst_wr_idx
=
1869 cpu_to_le32(ath10k_ce_dest_ring_write_index_get(ar
, addr
));
1871 cpu_to_le32(ath10k_ce_dest_ring_read_index_get(ar
, addr
));
1874 crash_data
->ce_crash_data
[id
] = ce_data
;
1876 ath10k_err(ar
, "[%02d]: 0x%08x %3u %3u %3u %3u", id
,
1877 le32_to_cpu(ce_data
.base_addr
),
1878 le32_to_cpu(ce_data
.src_wr_idx
),
1879 le32_to_cpu(ce_data
.src_r_idx
),
1880 le32_to_cpu(ce_data
.dst_wr_idx
),
1881 le32_to_cpu(ce_data
.dst_r_idx
));
1884 spin_unlock_bh(&ce
->ce_lock
);
1886 EXPORT_SYMBOL(ath10k_ce_dump_registers
);
1888 static const struct ath10k_ce_ops ce_ops
= {
1889 .ce_alloc_src_ring
= ath10k_ce_alloc_src_ring
,
1890 .ce_alloc_dst_ring
= ath10k_ce_alloc_dest_ring
,
1891 .ce_rx_post_buf
= __ath10k_ce_rx_post_buf
,
1892 .ce_completed_recv_next_nolock
= _ath10k_ce_completed_recv_next_nolock
,
1893 .ce_revoke_recv_next
= _ath10k_ce_revoke_recv_next
,
1894 .ce_extract_desc_data
= ath10k_ce_extract_desc_data
,
1895 .ce_free_pipe
= _ath10k_ce_free_pipe
,
1896 .ce_send_nolock
= _ath10k_ce_send_nolock
,
1897 .ce_set_src_ring_base_addr_hi
= NULL
,
1898 .ce_set_dest_ring_base_addr_hi
= NULL
,
1899 .ce_completed_send_next_nolock
= _ath10k_ce_completed_send_next_nolock
,
1902 static const struct ath10k_ce_ops ce_64_ops
= {
1903 .ce_alloc_src_ring
= ath10k_ce_alloc_src_ring_64
,
1904 .ce_alloc_dst_ring
= ath10k_ce_alloc_dest_ring_64
,
1905 .ce_rx_post_buf
= __ath10k_ce_rx_post_buf_64
,
1906 .ce_completed_recv_next_nolock
=
1907 _ath10k_ce_completed_recv_next_nolock_64
,
1908 .ce_revoke_recv_next
= _ath10k_ce_revoke_recv_next_64
,
1909 .ce_extract_desc_data
= ath10k_ce_extract_desc_data_64
,
1910 .ce_free_pipe
= _ath10k_ce_free_pipe_64
,
1911 .ce_send_nolock
= _ath10k_ce_send_nolock_64
,
1912 .ce_set_src_ring_base_addr_hi
= ath10k_ce_set_src_ring_base_addr_hi
,
1913 .ce_set_dest_ring_base_addr_hi
= ath10k_ce_set_dest_ring_base_addr_hi
,
1914 .ce_completed_send_next_nolock
= _ath10k_ce_completed_send_next_nolock_64
,
1917 static void ath10k_ce_set_ops(struct ath10k
*ar
,
1918 struct ath10k_ce_pipe
*ce_state
)
1920 switch (ar
->hw_rev
) {
1921 case ATH10K_HW_WCN3990
:
1922 ce_state
->ops
= &ce_64_ops
;
1925 ce_state
->ops
= &ce_ops
;
1930 int ath10k_ce_alloc_pipe(struct ath10k
*ar
, int ce_id
,
1931 const struct ce_attr
*attr
)
1933 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1934 struct ath10k_ce_pipe
*ce_state
= &ce
->ce_states
[ce_id
];
1937 ath10k_ce_set_ops(ar
, ce_state
);
1938 /* Make sure there's enough CE ringbuffer entries for HTT TX to avoid
1939 * additional TX locking checks.
1941 * For the lack of a better place do the check here.
1943 BUILD_BUG_ON(2 * TARGET_NUM_MSDU_DESC
>
1944 (CE_HTT_H2T_MSG_SRC_NENTRIES
- 1));
1945 BUILD_BUG_ON(2 * TARGET_10_4_NUM_MSDU_DESC_PFC
>
1946 (CE_HTT_H2T_MSG_SRC_NENTRIES
- 1));
1947 BUILD_BUG_ON(2 * TARGET_TLV_NUM_MSDU_DESC
>
1948 (CE_HTT_H2T_MSG_SRC_NENTRIES
- 1));
1951 ce_state
->id
= ce_id
;
1952 ce_state
->ctrl_addr
= ath10k_ce_base_address(ar
, ce_id
);
1953 ce_state
->attr_flags
= attr
->flags
;
1954 ce_state
->src_sz_max
= attr
->src_sz_max
;
1956 if (attr
->src_nentries
)
1957 ce_state
->send_cb
= attr
->send_cb
;
1959 if (attr
->dest_nentries
)
1960 ce_state
->recv_cb
= attr
->recv_cb
;
1962 if (attr
->src_nentries
) {
1963 ce_state
->src_ring
=
1964 ce_state
->ops
->ce_alloc_src_ring(ar
, ce_id
, attr
);
1965 if (IS_ERR(ce_state
->src_ring
)) {
1966 ret
= PTR_ERR(ce_state
->src_ring
);
1967 ath10k_err(ar
, "failed to alloc CE src ring %d: %d\n",
1969 ce_state
->src_ring
= NULL
;
1974 if (attr
->dest_nentries
) {
1975 ce_state
->dest_ring
= ce_state
->ops
->ce_alloc_dst_ring(ar
,
1978 if (IS_ERR(ce_state
->dest_ring
)) {
1979 ret
= PTR_ERR(ce_state
->dest_ring
);
1980 ath10k_err(ar
, "failed to alloc CE dest ring %d: %d\n",
1982 ce_state
->dest_ring
= NULL
;
1989 EXPORT_SYMBOL(ath10k_ce_alloc_pipe
);
1991 void ath10k_ce_alloc_rri(struct ath10k
*ar
)
1997 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
1999 ce
->vaddr_rri
= dma_alloc_coherent(ar
->dev
,
2000 (CE_COUNT
* sizeof(u32
)),
2001 &ce
->paddr_rri
, GFP_KERNEL
);
2006 ath10k_ce_write32(ar
, ar
->hw_ce_regs
->ce_rri_low
,
2007 lower_32_bits(ce
->paddr_rri
));
2008 ath10k_ce_write32(ar
, ar
->hw_ce_regs
->ce_rri_high
,
2009 (upper_32_bits(ce
->paddr_rri
) &
2010 CE_DESC_ADDR_HI_MASK
));
2012 for (i
= 0; i
< CE_COUNT
; i
++) {
2013 ctrl1_regs
= ar
->hw_ce_regs
->ctrl1_regs
->addr
;
2014 ce_base_addr
= ath10k_ce_base_address(ar
, i
);
2015 value
= ath10k_ce_read32(ar
, ce_base_addr
+ ctrl1_regs
);
2016 value
|= ar
->hw_ce_regs
->upd
->mask
;
2017 ath10k_ce_write32(ar
, ce_base_addr
+ ctrl1_regs
, value
);
2020 EXPORT_SYMBOL(ath10k_ce_alloc_rri
);
2022 void ath10k_ce_free_rri(struct ath10k
*ar
)
2024 struct ath10k_ce
*ce
= ath10k_ce_priv(ar
);
2026 dma_free_coherent(ar
->dev
, (CE_COUNT
* sizeof(u32
)),
2030 EXPORT_SYMBOL(ath10k_ce_free_rri
);