1*4882a593Smuzhiyun // SPDX-License-Identifier: ISC
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2005-2011 Atheros Communications Inc.
4*4882a593Smuzhiyun * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5*4882a593Smuzhiyun * Copyright (c) 2018 The Linux Foundation. All rights reserved.
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include "hif.h"
9*4882a593Smuzhiyun #include "ce.h"
10*4882a593Smuzhiyun #include "debug.h"
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun /*
13*4882a593Smuzhiyun * Support for Copy Engine hardware, which is mainly used for
14*4882a593Smuzhiyun * communication between Host and Target over a PCIe interconnect.
15*4882a593Smuzhiyun */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun * A single CopyEngine (CE) comprises two "rings":
19*4882a593Smuzhiyun * a source ring
20*4882a593Smuzhiyun * a destination ring
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * Each ring consists of a number of descriptors which specify
23*4882a593Smuzhiyun * an address, length, and meta-data.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * Typically, one side of the PCIe/AHB/SNOC interconnect (Host or Target)
26*4882a593Smuzhiyun * controls one ring and the other side controls the other ring.
27*4882a593Smuzhiyun * The source side chooses when to initiate a transfer and it
28*4882a593Smuzhiyun * chooses what to send (buffer address, length). The destination
29*4882a593Smuzhiyun * side keeps a supply of "anonymous receive buffers" available and
30*4882a593Smuzhiyun * it handles incoming data as it arrives (when the destination
31*4882a593Smuzhiyun * receives an interrupt).
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun * The sender may send a simple buffer (address/length) or it may
34*4882a593Smuzhiyun * send a small list of buffers. When a small list is sent, hardware
35*4882a593Smuzhiyun * "gathers" these and they end up in a single destination buffer
36*4882a593Smuzhiyun * with a single interrupt.
37*4882a593Smuzhiyun *
38*4882a593Smuzhiyun * There are several "contexts" managed by this layer -- more, it
39*4882a593Smuzhiyun * may seem -- than should be needed. These are provided mainly for
40*4882a593Smuzhiyun * maximum flexibility and especially to facilitate a simpler HIF
41*4882a593Smuzhiyun * implementation. There are per-CopyEngine recv, send, and watermark
42*4882a593Smuzhiyun * contexts. These are supplied by the caller when a recv, send,
43*4882a593Smuzhiyun * or watermark handler is established and they are echoed back to
44*4882a593Smuzhiyun * the caller when the respective callbacks are invoked. There is
45*4882a593Smuzhiyun * also a per-transfer context supplied by the caller when a buffer
46*4882a593Smuzhiyun * (or sendlist) is sent and when a buffer is enqueued for recv.
47*4882a593Smuzhiyun * These per-transfer contexts are echoed back to the caller when
48*4882a593Smuzhiyun * the buffer is sent/received.
49*4882a593Smuzhiyun */
50*4882a593Smuzhiyun
shadow_sr_wr_ind_addr(struct ath10k * ar,struct ath10k_ce_pipe * ce_state)51*4882a593Smuzhiyun static inline u32 shadow_sr_wr_ind_addr(struct ath10k *ar,
52*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun u32 ce_id = ce_state->id;
55*4882a593Smuzhiyun u32 addr = 0;
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun switch (ce_id) {
58*4882a593Smuzhiyun case 0:
59*4882a593Smuzhiyun addr = 0x00032000;
60*4882a593Smuzhiyun break;
61*4882a593Smuzhiyun case 3:
62*4882a593Smuzhiyun addr = 0x0003200C;
63*4882a593Smuzhiyun break;
64*4882a593Smuzhiyun case 4:
65*4882a593Smuzhiyun addr = 0x00032010;
66*4882a593Smuzhiyun break;
67*4882a593Smuzhiyun case 5:
68*4882a593Smuzhiyun addr = 0x00032014;
69*4882a593Smuzhiyun break;
70*4882a593Smuzhiyun case 7:
71*4882a593Smuzhiyun addr = 0x0003201C;
72*4882a593Smuzhiyun break;
73*4882a593Smuzhiyun default:
74*4882a593Smuzhiyun ath10k_warn(ar, "invalid CE id: %d", ce_id);
75*4882a593Smuzhiyun break;
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun return addr;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun
shadow_dst_wr_ind_addr(struct ath10k * ar,struct ath10k_ce_pipe * ce_state)80*4882a593Smuzhiyun static inline u32 shadow_dst_wr_ind_addr(struct ath10k *ar,
81*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state)
82*4882a593Smuzhiyun {
83*4882a593Smuzhiyun u32 ce_id = ce_state->id;
84*4882a593Smuzhiyun u32 addr = 0;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun switch (ce_id) {
87*4882a593Smuzhiyun case 1:
88*4882a593Smuzhiyun addr = 0x00032034;
89*4882a593Smuzhiyun break;
90*4882a593Smuzhiyun case 2:
91*4882a593Smuzhiyun addr = 0x00032038;
92*4882a593Smuzhiyun break;
93*4882a593Smuzhiyun case 5:
94*4882a593Smuzhiyun addr = 0x00032044;
95*4882a593Smuzhiyun break;
96*4882a593Smuzhiyun case 7:
97*4882a593Smuzhiyun addr = 0x0003204C;
98*4882a593Smuzhiyun break;
99*4882a593Smuzhiyun case 8:
100*4882a593Smuzhiyun addr = 0x00032050;
101*4882a593Smuzhiyun break;
102*4882a593Smuzhiyun case 9:
103*4882a593Smuzhiyun addr = 0x00032054;
104*4882a593Smuzhiyun break;
105*4882a593Smuzhiyun case 10:
106*4882a593Smuzhiyun addr = 0x00032058;
107*4882a593Smuzhiyun break;
108*4882a593Smuzhiyun case 11:
109*4882a593Smuzhiyun addr = 0x0003205C;
110*4882a593Smuzhiyun break;
111*4882a593Smuzhiyun default:
112*4882a593Smuzhiyun ath10k_warn(ar, "invalid CE id: %d", ce_id);
113*4882a593Smuzhiyun break;
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun return addr;
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun static inline unsigned int
ath10k_set_ring_byte(unsigned int offset,struct ath10k_hw_ce_regs_addr_map * addr_map)120*4882a593Smuzhiyun ath10k_set_ring_byte(unsigned int offset,
121*4882a593Smuzhiyun struct ath10k_hw_ce_regs_addr_map *addr_map)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun return ((offset << addr_map->lsb) & addr_map->mask);
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun static inline unsigned int
ath10k_get_ring_byte(unsigned int offset,struct ath10k_hw_ce_regs_addr_map * addr_map)127*4882a593Smuzhiyun ath10k_get_ring_byte(unsigned int offset,
128*4882a593Smuzhiyun struct ath10k_hw_ce_regs_addr_map *addr_map)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun return ((offset & addr_map->mask) >> (addr_map->lsb));
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun
ath10k_ce_read32(struct ath10k * ar,u32 offset)133*4882a593Smuzhiyun static inline u32 ath10k_ce_read32(struct ath10k *ar, u32 offset)
134*4882a593Smuzhiyun {
135*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun return ce->bus_ops->read32(ar, offset);
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun
ath10k_ce_write32(struct ath10k * ar,u32 offset,u32 value)140*4882a593Smuzhiyun static inline void ath10k_ce_write32(struct ath10k *ar, u32 offset, u32 value)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun ce->bus_ops->write32(ar, offset, value);
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun
ath10k_ce_dest_ring_write_index_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)147*4882a593Smuzhiyun static inline void ath10k_ce_dest_ring_write_index_set(struct ath10k *ar,
148*4882a593Smuzhiyun u32 ce_ctrl_addr,
149*4882a593Smuzhiyun unsigned int n)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
152*4882a593Smuzhiyun ar->hw_ce_regs->dst_wr_index_addr, n);
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun
ath10k_ce_dest_ring_write_index_get(struct ath10k * ar,u32 ce_ctrl_addr)155*4882a593Smuzhiyun static inline u32 ath10k_ce_dest_ring_write_index_get(struct ath10k *ar,
156*4882a593Smuzhiyun u32 ce_ctrl_addr)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun return ath10k_ce_read32(ar, ce_ctrl_addr +
159*4882a593Smuzhiyun ar->hw_ce_regs->dst_wr_index_addr);
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun
ath10k_ce_src_ring_write_index_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)162*4882a593Smuzhiyun static inline void ath10k_ce_src_ring_write_index_set(struct ath10k *ar,
163*4882a593Smuzhiyun u32 ce_ctrl_addr,
164*4882a593Smuzhiyun unsigned int n)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
167*4882a593Smuzhiyun ar->hw_ce_regs->sr_wr_index_addr, n);
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
ath10k_ce_src_ring_write_index_get(struct ath10k * ar,u32 ce_ctrl_addr)170*4882a593Smuzhiyun static inline u32 ath10k_ce_src_ring_write_index_get(struct ath10k *ar,
171*4882a593Smuzhiyun u32 ce_ctrl_addr)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun return ath10k_ce_read32(ar, ce_ctrl_addr +
174*4882a593Smuzhiyun ar->hw_ce_regs->sr_wr_index_addr);
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun
ath10k_ce_src_ring_read_index_from_ddr(struct ath10k * ar,u32 ce_id)177*4882a593Smuzhiyun static inline u32 ath10k_ce_src_ring_read_index_from_ddr(struct ath10k *ar,
178*4882a593Smuzhiyun u32 ce_id)
179*4882a593Smuzhiyun {
180*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun return ce->vaddr_rri[ce_id] & CE_DDR_RRI_MASK;
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
ath10k_ce_src_ring_read_index_get(struct ath10k * ar,u32 ce_ctrl_addr)185*4882a593Smuzhiyun static inline u32 ath10k_ce_src_ring_read_index_get(struct ath10k *ar,
186*4882a593Smuzhiyun u32 ce_ctrl_addr)
187*4882a593Smuzhiyun {
188*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
189*4882a593Smuzhiyun u32 ce_id = COPY_ENGINE_ID(ce_ctrl_addr);
190*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
191*4882a593Smuzhiyun u32 index;
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun if (ar->hw_params.rri_on_ddr &&
194*4882a593Smuzhiyun (ce_state->attr_flags & CE_ATTR_DIS_INTR))
195*4882a593Smuzhiyun index = ath10k_ce_src_ring_read_index_from_ddr(ar, ce_id);
196*4882a593Smuzhiyun else
197*4882a593Smuzhiyun index = ath10k_ce_read32(ar, ce_ctrl_addr +
198*4882a593Smuzhiyun ar->hw_ce_regs->current_srri_addr);
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun return index;
201*4882a593Smuzhiyun }
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun static inline void
ath10k_ce_shadow_src_ring_write_index_set(struct ath10k * ar,struct ath10k_ce_pipe * ce_state,unsigned int value)204*4882a593Smuzhiyun ath10k_ce_shadow_src_ring_write_index_set(struct ath10k *ar,
205*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state,
206*4882a593Smuzhiyun unsigned int value)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun ath10k_ce_write32(ar, shadow_sr_wr_ind_addr(ar, ce_state), value);
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun static inline void
ath10k_ce_shadow_dest_ring_write_index_set(struct ath10k * ar,struct ath10k_ce_pipe * ce_state,unsigned int value)212*4882a593Smuzhiyun ath10k_ce_shadow_dest_ring_write_index_set(struct ath10k *ar,
213*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state,
214*4882a593Smuzhiyun unsigned int value)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun ath10k_ce_write32(ar, shadow_dst_wr_ind_addr(ar, ce_state), value);
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun
ath10k_ce_src_ring_base_addr_set(struct ath10k * ar,u32 ce_id,u64 addr)219*4882a593Smuzhiyun static inline void ath10k_ce_src_ring_base_addr_set(struct ath10k *ar,
220*4882a593Smuzhiyun u32 ce_id,
221*4882a593Smuzhiyun u64 addr)
222*4882a593Smuzhiyun {
223*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
224*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
225*4882a593Smuzhiyun u32 ce_ctrl_addr = ath10k_ce_base_address(ar, ce_id);
226*4882a593Smuzhiyun u32 addr_lo = lower_32_bits(addr);
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
229*4882a593Smuzhiyun ar->hw_ce_regs->sr_base_addr_lo, addr_lo);
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun if (ce_state->ops->ce_set_src_ring_base_addr_hi) {
232*4882a593Smuzhiyun ce_state->ops->ce_set_src_ring_base_addr_hi(ar, ce_ctrl_addr,
233*4882a593Smuzhiyun addr);
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
ath10k_ce_set_src_ring_base_addr_hi(struct ath10k * ar,u32 ce_ctrl_addr,u64 addr)237*4882a593Smuzhiyun static void ath10k_ce_set_src_ring_base_addr_hi(struct ath10k *ar,
238*4882a593Smuzhiyun u32 ce_ctrl_addr,
239*4882a593Smuzhiyun u64 addr)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun u32 addr_hi = upper_32_bits(addr) & CE_DESC_ADDR_HI_MASK;
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
244*4882a593Smuzhiyun ar->hw_ce_regs->sr_base_addr_hi, addr_hi);
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun
ath10k_ce_src_ring_size_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)247*4882a593Smuzhiyun static inline void ath10k_ce_src_ring_size_set(struct ath10k *ar,
248*4882a593Smuzhiyun u32 ce_ctrl_addr,
249*4882a593Smuzhiyun unsigned int n)
250*4882a593Smuzhiyun {
251*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
252*4882a593Smuzhiyun ar->hw_ce_regs->sr_size_addr, n);
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
ath10k_ce_src_ring_dmax_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)255*4882a593Smuzhiyun static inline void ath10k_ce_src_ring_dmax_set(struct ath10k *ar,
256*4882a593Smuzhiyun u32 ce_ctrl_addr,
257*4882a593Smuzhiyun unsigned int n)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun struct ath10k_hw_ce_ctrl1 *ctrl_regs = ar->hw_ce_regs->ctrl1_regs;
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun u32 ctrl1_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
262*4882a593Smuzhiyun ctrl_regs->addr);
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + ctrl_regs->addr,
265*4882a593Smuzhiyun (ctrl1_addr & ~(ctrl_regs->dmax->mask)) |
266*4882a593Smuzhiyun ath10k_set_ring_byte(n, ctrl_regs->dmax));
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun
ath10k_ce_src_ring_byte_swap_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)269*4882a593Smuzhiyun static inline void ath10k_ce_src_ring_byte_swap_set(struct ath10k *ar,
270*4882a593Smuzhiyun u32 ce_ctrl_addr,
271*4882a593Smuzhiyun unsigned int n)
272*4882a593Smuzhiyun {
273*4882a593Smuzhiyun struct ath10k_hw_ce_ctrl1 *ctrl_regs = ar->hw_ce_regs->ctrl1_regs;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun u32 ctrl1_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
276*4882a593Smuzhiyun ctrl_regs->addr);
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + ctrl_regs->addr,
279*4882a593Smuzhiyun (ctrl1_addr & ~(ctrl_regs->src_ring->mask)) |
280*4882a593Smuzhiyun ath10k_set_ring_byte(n, ctrl_regs->src_ring));
281*4882a593Smuzhiyun }
282*4882a593Smuzhiyun
ath10k_ce_dest_ring_byte_swap_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)283*4882a593Smuzhiyun static inline void ath10k_ce_dest_ring_byte_swap_set(struct ath10k *ar,
284*4882a593Smuzhiyun u32 ce_ctrl_addr,
285*4882a593Smuzhiyun unsigned int n)
286*4882a593Smuzhiyun {
287*4882a593Smuzhiyun struct ath10k_hw_ce_ctrl1 *ctrl_regs = ar->hw_ce_regs->ctrl1_regs;
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun u32 ctrl1_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
290*4882a593Smuzhiyun ctrl_regs->addr);
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + ctrl_regs->addr,
293*4882a593Smuzhiyun (ctrl1_addr & ~(ctrl_regs->dst_ring->mask)) |
294*4882a593Smuzhiyun ath10k_set_ring_byte(n, ctrl_regs->dst_ring));
295*4882a593Smuzhiyun }
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun static inline
ath10k_ce_dest_ring_read_index_from_ddr(struct ath10k * ar,u32 ce_id)298*4882a593Smuzhiyun u32 ath10k_ce_dest_ring_read_index_from_ddr(struct ath10k *ar, u32 ce_id)
299*4882a593Smuzhiyun {
300*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun return (ce->vaddr_rri[ce_id] >> CE_DDR_DRRI_SHIFT) &
303*4882a593Smuzhiyun CE_DDR_RRI_MASK;
304*4882a593Smuzhiyun }
305*4882a593Smuzhiyun
ath10k_ce_dest_ring_read_index_get(struct ath10k * ar,u32 ce_ctrl_addr)306*4882a593Smuzhiyun static inline u32 ath10k_ce_dest_ring_read_index_get(struct ath10k *ar,
307*4882a593Smuzhiyun u32 ce_ctrl_addr)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
310*4882a593Smuzhiyun u32 ce_id = COPY_ENGINE_ID(ce_ctrl_addr);
311*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
312*4882a593Smuzhiyun u32 index;
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun if (ar->hw_params.rri_on_ddr &&
315*4882a593Smuzhiyun (ce_state->attr_flags & CE_ATTR_DIS_INTR))
316*4882a593Smuzhiyun index = ath10k_ce_dest_ring_read_index_from_ddr(ar, ce_id);
317*4882a593Smuzhiyun else
318*4882a593Smuzhiyun index = ath10k_ce_read32(ar, ce_ctrl_addr +
319*4882a593Smuzhiyun ar->hw_ce_regs->current_drri_addr);
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun return index;
322*4882a593Smuzhiyun }
323*4882a593Smuzhiyun
ath10k_ce_dest_ring_base_addr_set(struct ath10k * ar,u32 ce_id,u64 addr)324*4882a593Smuzhiyun static inline void ath10k_ce_dest_ring_base_addr_set(struct ath10k *ar,
325*4882a593Smuzhiyun u32 ce_id,
326*4882a593Smuzhiyun u64 addr)
327*4882a593Smuzhiyun {
328*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
329*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
330*4882a593Smuzhiyun u32 ce_ctrl_addr = ath10k_ce_base_address(ar, ce_id);
331*4882a593Smuzhiyun u32 addr_lo = lower_32_bits(addr);
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
334*4882a593Smuzhiyun ar->hw_ce_regs->dr_base_addr_lo, addr_lo);
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun if (ce_state->ops->ce_set_dest_ring_base_addr_hi) {
337*4882a593Smuzhiyun ce_state->ops->ce_set_dest_ring_base_addr_hi(ar, ce_ctrl_addr,
338*4882a593Smuzhiyun addr);
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
ath10k_ce_set_dest_ring_base_addr_hi(struct ath10k * ar,u32 ce_ctrl_addr,u64 addr)342*4882a593Smuzhiyun static void ath10k_ce_set_dest_ring_base_addr_hi(struct ath10k *ar,
343*4882a593Smuzhiyun u32 ce_ctrl_addr,
344*4882a593Smuzhiyun u64 addr)
345*4882a593Smuzhiyun {
346*4882a593Smuzhiyun u32 addr_hi = upper_32_bits(addr) & CE_DESC_ADDR_HI_MASK;
347*4882a593Smuzhiyun u32 reg_value;
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun reg_value = ath10k_ce_read32(ar, ce_ctrl_addr +
350*4882a593Smuzhiyun ar->hw_ce_regs->dr_base_addr_hi);
351*4882a593Smuzhiyun reg_value &= ~CE_DESC_ADDR_HI_MASK;
352*4882a593Smuzhiyun reg_value |= addr_hi;
353*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
354*4882a593Smuzhiyun ar->hw_ce_regs->dr_base_addr_hi, reg_value);
355*4882a593Smuzhiyun }
356*4882a593Smuzhiyun
ath10k_ce_dest_ring_size_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)357*4882a593Smuzhiyun static inline void ath10k_ce_dest_ring_size_set(struct ath10k *ar,
358*4882a593Smuzhiyun u32 ce_ctrl_addr,
359*4882a593Smuzhiyun unsigned int n)
360*4882a593Smuzhiyun {
361*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr +
362*4882a593Smuzhiyun ar->hw_ce_regs->dr_size_addr, n);
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun
ath10k_ce_src_ring_highmark_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)365*4882a593Smuzhiyun static inline void ath10k_ce_src_ring_highmark_set(struct ath10k *ar,
366*4882a593Smuzhiyun u32 ce_ctrl_addr,
367*4882a593Smuzhiyun unsigned int n)
368*4882a593Smuzhiyun {
369*4882a593Smuzhiyun struct ath10k_hw_ce_dst_src_wm_regs *srcr_wm = ar->hw_ce_regs->wm_srcr;
370*4882a593Smuzhiyun u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + srcr_wm->addr);
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + srcr_wm->addr,
373*4882a593Smuzhiyun (addr & ~(srcr_wm->wm_high->mask)) |
374*4882a593Smuzhiyun (ath10k_set_ring_byte(n, srcr_wm->wm_high)));
375*4882a593Smuzhiyun }
376*4882a593Smuzhiyun
ath10k_ce_src_ring_lowmark_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)377*4882a593Smuzhiyun static inline void ath10k_ce_src_ring_lowmark_set(struct ath10k *ar,
378*4882a593Smuzhiyun u32 ce_ctrl_addr,
379*4882a593Smuzhiyun unsigned int n)
380*4882a593Smuzhiyun {
381*4882a593Smuzhiyun struct ath10k_hw_ce_dst_src_wm_regs *srcr_wm = ar->hw_ce_regs->wm_srcr;
382*4882a593Smuzhiyun u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + srcr_wm->addr);
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + srcr_wm->addr,
385*4882a593Smuzhiyun (addr & ~(srcr_wm->wm_low->mask)) |
386*4882a593Smuzhiyun (ath10k_set_ring_byte(n, srcr_wm->wm_low)));
387*4882a593Smuzhiyun }
388*4882a593Smuzhiyun
ath10k_ce_dest_ring_highmark_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)389*4882a593Smuzhiyun static inline void ath10k_ce_dest_ring_highmark_set(struct ath10k *ar,
390*4882a593Smuzhiyun u32 ce_ctrl_addr,
391*4882a593Smuzhiyun unsigned int n)
392*4882a593Smuzhiyun {
393*4882a593Smuzhiyun struct ath10k_hw_ce_dst_src_wm_regs *dstr_wm = ar->hw_ce_regs->wm_dstr;
394*4882a593Smuzhiyun u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + dstr_wm->addr);
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + dstr_wm->addr,
397*4882a593Smuzhiyun (addr & ~(dstr_wm->wm_high->mask)) |
398*4882a593Smuzhiyun (ath10k_set_ring_byte(n, dstr_wm->wm_high)));
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun
ath10k_ce_dest_ring_lowmark_set(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int n)401*4882a593Smuzhiyun static inline void ath10k_ce_dest_ring_lowmark_set(struct ath10k *ar,
402*4882a593Smuzhiyun u32 ce_ctrl_addr,
403*4882a593Smuzhiyun unsigned int n)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun struct ath10k_hw_ce_dst_src_wm_regs *dstr_wm = ar->hw_ce_regs->wm_dstr;
406*4882a593Smuzhiyun u32 addr = ath10k_ce_read32(ar, ce_ctrl_addr + dstr_wm->addr);
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + dstr_wm->addr,
409*4882a593Smuzhiyun (addr & ~(dstr_wm->wm_low->mask)) |
410*4882a593Smuzhiyun (ath10k_set_ring_byte(n, dstr_wm->wm_low)));
411*4882a593Smuzhiyun }
412*4882a593Smuzhiyun
ath10k_ce_copy_complete_inter_enable(struct ath10k * ar,u32 ce_ctrl_addr)413*4882a593Smuzhiyun static inline void ath10k_ce_copy_complete_inter_enable(struct ath10k *ar,
414*4882a593Smuzhiyun u32 ce_ctrl_addr)
415*4882a593Smuzhiyun {
416*4882a593Smuzhiyun struct ath10k_hw_ce_host_ie *host_ie = ar->hw_ce_regs->host_ie;
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun u32 host_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
419*4882a593Smuzhiyun ar->hw_ce_regs->host_ie_addr);
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + ar->hw_ce_regs->host_ie_addr,
422*4882a593Smuzhiyun host_ie_addr | host_ie->copy_complete->mask);
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun
ath10k_ce_copy_complete_intr_disable(struct ath10k * ar,u32 ce_ctrl_addr)425*4882a593Smuzhiyun static inline void ath10k_ce_copy_complete_intr_disable(struct ath10k *ar,
426*4882a593Smuzhiyun u32 ce_ctrl_addr)
427*4882a593Smuzhiyun {
428*4882a593Smuzhiyun struct ath10k_hw_ce_host_ie *host_ie = ar->hw_ce_regs->host_ie;
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun u32 host_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
431*4882a593Smuzhiyun ar->hw_ce_regs->host_ie_addr);
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + ar->hw_ce_regs->host_ie_addr,
434*4882a593Smuzhiyun host_ie_addr & ~(host_ie->copy_complete->mask));
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun
ath10k_ce_watermark_intr_disable(struct ath10k * ar,u32 ce_ctrl_addr)437*4882a593Smuzhiyun static inline void ath10k_ce_watermark_intr_disable(struct ath10k *ar,
438*4882a593Smuzhiyun u32 ce_ctrl_addr)
439*4882a593Smuzhiyun {
440*4882a593Smuzhiyun struct ath10k_hw_ce_host_wm_regs *wm_regs = ar->hw_ce_regs->wm_regs;
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun u32 host_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
443*4882a593Smuzhiyun ar->hw_ce_regs->host_ie_addr);
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + ar->hw_ce_regs->host_ie_addr,
446*4882a593Smuzhiyun host_ie_addr & ~(wm_regs->wm_mask));
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun
ath10k_ce_error_intr_enable(struct ath10k * ar,u32 ce_ctrl_addr)449*4882a593Smuzhiyun static inline void ath10k_ce_error_intr_enable(struct ath10k *ar,
450*4882a593Smuzhiyun u32 ce_ctrl_addr)
451*4882a593Smuzhiyun {
452*4882a593Smuzhiyun struct ath10k_hw_ce_misc_regs *misc_regs = ar->hw_ce_regs->misc_regs;
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun u32 misc_ie_addr = ath10k_ce_read32(ar, ce_ctrl_addr +
455*4882a593Smuzhiyun ar->hw_ce_regs->misc_ie_addr);
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun ath10k_ce_write32(ar,
458*4882a593Smuzhiyun ce_ctrl_addr + ar->hw_ce_regs->misc_ie_addr,
459*4882a593Smuzhiyun misc_ie_addr | misc_regs->err_mask);
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
ath10k_ce_error_intr_disable(struct ath10k * ar,u32 ce_ctrl_addr)462*4882a593Smuzhiyun static inline void ath10k_ce_error_intr_disable(struct ath10k *ar,
463*4882a593Smuzhiyun u32 ce_ctrl_addr)
464*4882a593Smuzhiyun {
465*4882a593Smuzhiyun struct ath10k_hw_ce_misc_regs *misc_regs = ar->hw_ce_regs->misc_regs;
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun u32 misc_ie_addr = ath10k_ce_read32(ar,
468*4882a593Smuzhiyun ce_ctrl_addr + ar->hw_ce_regs->misc_ie_addr);
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun ath10k_ce_write32(ar,
471*4882a593Smuzhiyun ce_ctrl_addr + ar->hw_ce_regs->misc_ie_addr,
472*4882a593Smuzhiyun misc_ie_addr & ~(misc_regs->err_mask));
473*4882a593Smuzhiyun }
474*4882a593Smuzhiyun
ath10k_ce_engine_int_status_clear(struct ath10k * ar,u32 ce_ctrl_addr,unsigned int mask)475*4882a593Smuzhiyun static inline void ath10k_ce_engine_int_status_clear(struct ath10k *ar,
476*4882a593Smuzhiyun u32 ce_ctrl_addr,
477*4882a593Smuzhiyun unsigned int mask)
478*4882a593Smuzhiyun {
479*4882a593Smuzhiyun struct ath10k_hw_ce_host_wm_regs *wm_regs = ar->hw_ce_regs->wm_regs;
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_ctrl_addr + wm_regs->addr, mask);
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun /*
485*4882a593Smuzhiyun * Guts of ath10k_ce_send.
486*4882a593Smuzhiyun * The caller takes responsibility for any needed locking.
487*4882a593Smuzhiyun */
_ath10k_ce_send_nolock(struct ath10k_ce_pipe * ce_state,void * per_transfer_context,dma_addr_t buffer,unsigned int nbytes,unsigned int transfer_id,unsigned int flags)488*4882a593Smuzhiyun static int _ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
489*4882a593Smuzhiyun void *per_transfer_context,
490*4882a593Smuzhiyun dma_addr_t buffer,
491*4882a593Smuzhiyun unsigned int nbytes,
492*4882a593Smuzhiyun unsigned int transfer_id,
493*4882a593Smuzhiyun unsigned int flags)
494*4882a593Smuzhiyun {
495*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
496*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring = ce_state->src_ring;
497*4882a593Smuzhiyun struct ce_desc *desc, sdesc;
498*4882a593Smuzhiyun unsigned int nentries_mask = src_ring->nentries_mask;
499*4882a593Smuzhiyun unsigned int sw_index = src_ring->sw_index;
500*4882a593Smuzhiyun unsigned int write_index = src_ring->write_index;
501*4882a593Smuzhiyun u32 ctrl_addr = ce_state->ctrl_addr;
502*4882a593Smuzhiyun u32 desc_flags = 0;
503*4882a593Smuzhiyun int ret = 0;
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun if (nbytes > ce_state->src_sz_max)
506*4882a593Smuzhiyun ath10k_warn(ar, "%s: send more we can (nbytes: %d, max: %d)\n",
507*4882a593Smuzhiyun __func__, nbytes, ce_state->src_sz_max);
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun if (unlikely(CE_RING_DELTA(nentries_mask,
510*4882a593Smuzhiyun write_index, sw_index - 1) <= 0)) {
511*4882a593Smuzhiyun ret = -ENOSR;
512*4882a593Smuzhiyun goto exit;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun desc = CE_SRC_RING_TO_DESC(src_ring->base_addr_owner_space,
516*4882a593Smuzhiyun write_index);
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun desc_flags |= SM(transfer_id, CE_DESC_FLAGS_META_DATA);
519*4882a593Smuzhiyun
520*4882a593Smuzhiyun if (flags & CE_SEND_FLAG_GATHER)
521*4882a593Smuzhiyun desc_flags |= CE_DESC_FLAGS_GATHER;
522*4882a593Smuzhiyun if (flags & CE_SEND_FLAG_BYTE_SWAP)
523*4882a593Smuzhiyun desc_flags |= CE_DESC_FLAGS_BYTE_SWAP;
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun sdesc.addr = __cpu_to_le32(buffer);
526*4882a593Smuzhiyun sdesc.nbytes = __cpu_to_le16(nbytes);
527*4882a593Smuzhiyun sdesc.flags = __cpu_to_le16(desc_flags);
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun *desc = sdesc;
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun src_ring->per_transfer_context[write_index] = per_transfer_context;
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun /* Update Source Ring Write Index */
534*4882a593Smuzhiyun write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun /* WORKAROUND */
537*4882a593Smuzhiyun if (!(flags & CE_SEND_FLAG_GATHER))
538*4882a593Smuzhiyun ath10k_ce_src_ring_write_index_set(ar, ctrl_addr, write_index);
539*4882a593Smuzhiyun
540*4882a593Smuzhiyun src_ring->write_index = write_index;
541*4882a593Smuzhiyun exit:
542*4882a593Smuzhiyun return ret;
543*4882a593Smuzhiyun }
544*4882a593Smuzhiyun
_ath10k_ce_send_nolock_64(struct ath10k_ce_pipe * ce_state,void * per_transfer_context,dma_addr_t buffer,unsigned int nbytes,unsigned int transfer_id,unsigned int flags)545*4882a593Smuzhiyun static int _ath10k_ce_send_nolock_64(struct ath10k_ce_pipe *ce_state,
546*4882a593Smuzhiyun void *per_transfer_context,
547*4882a593Smuzhiyun dma_addr_t buffer,
548*4882a593Smuzhiyun unsigned int nbytes,
549*4882a593Smuzhiyun unsigned int transfer_id,
550*4882a593Smuzhiyun unsigned int flags)
551*4882a593Smuzhiyun {
552*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
553*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring = ce_state->src_ring;
554*4882a593Smuzhiyun struct ce_desc_64 *desc, sdesc;
555*4882a593Smuzhiyun unsigned int nentries_mask = src_ring->nentries_mask;
556*4882a593Smuzhiyun unsigned int sw_index;
557*4882a593Smuzhiyun unsigned int write_index = src_ring->write_index;
558*4882a593Smuzhiyun u32 ctrl_addr = ce_state->ctrl_addr;
559*4882a593Smuzhiyun __le32 *addr;
560*4882a593Smuzhiyun u32 desc_flags = 0;
561*4882a593Smuzhiyun int ret = 0;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
564*4882a593Smuzhiyun return -ESHUTDOWN;
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun if (nbytes > ce_state->src_sz_max)
567*4882a593Smuzhiyun ath10k_warn(ar, "%s: send more we can (nbytes: %d, max: %d)\n",
568*4882a593Smuzhiyun __func__, nbytes, ce_state->src_sz_max);
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun if (ar->hw_params.rri_on_ddr)
571*4882a593Smuzhiyun sw_index = ath10k_ce_src_ring_read_index_from_ddr(ar, ce_state->id);
572*4882a593Smuzhiyun else
573*4882a593Smuzhiyun sw_index = src_ring->sw_index;
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun if (unlikely(CE_RING_DELTA(nentries_mask,
576*4882a593Smuzhiyun write_index, sw_index - 1) <= 0)) {
577*4882a593Smuzhiyun ret = -ENOSR;
578*4882a593Smuzhiyun goto exit;
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun desc = CE_SRC_RING_TO_DESC_64(src_ring->base_addr_owner_space,
582*4882a593Smuzhiyun write_index);
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun desc_flags |= SM(transfer_id, CE_DESC_FLAGS_META_DATA);
585*4882a593Smuzhiyun
586*4882a593Smuzhiyun if (flags & CE_SEND_FLAG_GATHER)
587*4882a593Smuzhiyun desc_flags |= CE_DESC_FLAGS_GATHER;
588*4882a593Smuzhiyun
589*4882a593Smuzhiyun if (flags & CE_SEND_FLAG_BYTE_SWAP)
590*4882a593Smuzhiyun desc_flags |= CE_DESC_FLAGS_BYTE_SWAP;
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun addr = (__le32 *)&sdesc.addr;
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun flags |= upper_32_bits(buffer) & CE_DESC_ADDR_HI_MASK;
595*4882a593Smuzhiyun addr[0] = __cpu_to_le32(buffer);
596*4882a593Smuzhiyun addr[1] = __cpu_to_le32(flags);
597*4882a593Smuzhiyun if (flags & CE_SEND_FLAG_GATHER)
598*4882a593Smuzhiyun addr[1] |= __cpu_to_le32(CE_WCN3990_DESC_FLAGS_GATHER);
599*4882a593Smuzhiyun else
600*4882a593Smuzhiyun addr[1] &= ~(__cpu_to_le32(CE_WCN3990_DESC_FLAGS_GATHER));
601*4882a593Smuzhiyun
602*4882a593Smuzhiyun sdesc.nbytes = __cpu_to_le16(nbytes);
603*4882a593Smuzhiyun sdesc.flags = __cpu_to_le16(desc_flags);
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun *desc = sdesc;
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun src_ring->per_transfer_context[write_index] = per_transfer_context;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun /* Update Source Ring Write Index */
610*4882a593Smuzhiyun write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun if (!(flags & CE_SEND_FLAG_GATHER)) {
613*4882a593Smuzhiyun if (ar->hw_params.shadow_reg_support)
614*4882a593Smuzhiyun ath10k_ce_shadow_src_ring_write_index_set(ar, ce_state,
615*4882a593Smuzhiyun write_index);
616*4882a593Smuzhiyun else
617*4882a593Smuzhiyun ath10k_ce_src_ring_write_index_set(ar, ctrl_addr,
618*4882a593Smuzhiyun write_index);
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun src_ring->write_index = write_index;
622*4882a593Smuzhiyun exit:
623*4882a593Smuzhiyun return ret;
624*4882a593Smuzhiyun }
625*4882a593Smuzhiyun
ath10k_ce_send_nolock(struct ath10k_ce_pipe * ce_state,void * per_transfer_context,dma_addr_t buffer,unsigned int nbytes,unsigned int transfer_id,unsigned int flags)626*4882a593Smuzhiyun int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
627*4882a593Smuzhiyun void *per_transfer_context,
628*4882a593Smuzhiyun dma_addr_t buffer,
629*4882a593Smuzhiyun unsigned int nbytes,
630*4882a593Smuzhiyun unsigned int transfer_id,
631*4882a593Smuzhiyun unsigned int flags)
632*4882a593Smuzhiyun {
633*4882a593Smuzhiyun return ce_state->ops->ce_send_nolock(ce_state, per_transfer_context,
634*4882a593Smuzhiyun buffer, nbytes, transfer_id, flags);
635*4882a593Smuzhiyun }
636*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_send_nolock);
637*4882a593Smuzhiyun
__ath10k_ce_send_revert(struct ath10k_ce_pipe * pipe)638*4882a593Smuzhiyun void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe)
639*4882a593Smuzhiyun {
640*4882a593Smuzhiyun struct ath10k *ar = pipe->ar;
641*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
642*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring = pipe->src_ring;
643*4882a593Smuzhiyun u32 ctrl_addr = pipe->ctrl_addr;
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun lockdep_assert_held(&ce->ce_lock);
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun /*
648*4882a593Smuzhiyun * This function must be called only if there is an incomplete
649*4882a593Smuzhiyun * scatter-gather transfer (before index register is updated)
650*4882a593Smuzhiyun * that needs to be cleaned up.
651*4882a593Smuzhiyun */
652*4882a593Smuzhiyun if (WARN_ON_ONCE(src_ring->write_index == src_ring->sw_index))
653*4882a593Smuzhiyun return;
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun if (WARN_ON_ONCE(src_ring->write_index ==
656*4882a593Smuzhiyun ath10k_ce_src_ring_write_index_get(ar, ctrl_addr)))
657*4882a593Smuzhiyun return;
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun src_ring->write_index--;
660*4882a593Smuzhiyun src_ring->write_index &= src_ring->nentries_mask;
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun src_ring->per_transfer_context[src_ring->write_index] = NULL;
663*4882a593Smuzhiyun }
664*4882a593Smuzhiyun EXPORT_SYMBOL(__ath10k_ce_send_revert);
665*4882a593Smuzhiyun
ath10k_ce_send(struct ath10k_ce_pipe * ce_state,void * per_transfer_context,dma_addr_t buffer,unsigned int nbytes,unsigned int transfer_id,unsigned int flags)666*4882a593Smuzhiyun int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
667*4882a593Smuzhiyun void *per_transfer_context,
668*4882a593Smuzhiyun dma_addr_t buffer,
669*4882a593Smuzhiyun unsigned int nbytes,
670*4882a593Smuzhiyun unsigned int transfer_id,
671*4882a593Smuzhiyun unsigned int flags)
672*4882a593Smuzhiyun {
673*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
674*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
675*4882a593Smuzhiyun int ret;
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
678*4882a593Smuzhiyun ret = ath10k_ce_send_nolock(ce_state, per_transfer_context,
679*4882a593Smuzhiyun buffer, nbytes, transfer_id, flags);
680*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun return ret;
683*4882a593Smuzhiyun }
684*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_send);
685*4882a593Smuzhiyun
ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe * pipe)686*4882a593Smuzhiyun int ath10k_ce_num_free_src_entries(struct ath10k_ce_pipe *pipe)
687*4882a593Smuzhiyun {
688*4882a593Smuzhiyun struct ath10k *ar = pipe->ar;
689*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
690*4882a593Smuzhiyun int delta;
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
693*4882a593Smuzhiyun delta = CE_RING_DELTA(pipe->src_ring->nentries_mask,
694*4882a593Smuzhiyun pipe->src_ring->write_index,
695*4882a593Smuzhiyun pipe->src_ring->sw_index - 1);
696*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun return delta;
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_num_free_src_entries);
701*4882a593Smuzhiyun
__ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe * pipe)702*4882a593Smuzhiyun int __ath10k_ce_rx_num_free_bufs(struct ath10k_ce_pipe *pipe)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun struct ath10k *ar = pipe->ar;
705*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
706*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
707*4882a593Smuzhiyun unsigned int nentries_mask = dest_ring->nentries_mask;
708*4882a593Smuzhiyun unsigned int write_index = dest_ring->write_index;
709*4882a593Smuzhiyun unsigned int sw_index = dest_ring->sw_index;
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun lockdep_assert_held(&ce->ce_lock);
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun return CE_RING_DELTA(nentries_mask, write_index, sw_index - 1);
714*4882a593Smuzhiyun }
715*4882a593Smuzhiyun EXPORT_SYMBOL(__ath10k_ce_rx_num_free_bufs);
716*4882a593Smuzhiyun
__ath10k_ce_rx_post_buf(struct ath10k_ce_pipe * pipe,void * ctx,dma_addr_t paddr)717*4882a593Smuzhiyun static int __ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
718*4882a593Smuzhiyun dma_addr_t paddr)
719*4882a593Smuzhiyun {
720*4882a593Smuzhiyun struct ath10k *ar = pipe->ar;
721*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
722*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
723*4882a593Smuzhiyun unsigned int nentries_mask = dest_ring->nentries_mask;
724*4882a593Smuzhiyun unsigned int write_index = dest_ring->write_index;
725*4882a593Smuzhiyun unsigned int sw_index = dest_ring->sw_index;
726*4882a593Smuzhiyun struct ce_desc *base = dest_ring->base_addr_owner_space;
727*4882a593Smuzhiyun struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, write_index);
728*4882a593Smuzhiyun u32 ctrl_addr = pipe->ctrl_addr;
729*4882a593Smuzhiyun
730*4882a593Smuzhiyun lockdep_assert_held(&ce->ce_lock);
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun if ((pipe->id != 5) &&
733*4882a593Smuzhiyun CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) == 0)
734*4882a593Smuzhiyun return -ENOSPC;
735*4882a593Smuzhiyun
736*4882a593Smuzhiyun desc->addr = __cpu_to_le32(paddr);
737*4882a593Smuzhiyun desc->nbytes = 0;
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun dest_ring->per_transfer_context[write_index] = ctx;
740*4882a593Smuzhiyun write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
741*4882a593Smuzhiyun ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
742*4882a593Smuzhiyun dest_ring->write_index = write_index;
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun return 0;
745*4882a593Smuzhiyun }
746*4882a593Smuzhiyun
__ath10k_ce_rx_post_buf_64(struct ath10k_ce_pipe * pipe,void * ctx,dma_addr_t paddr)747*4882a593Smuzhiyun static int __ath10k_ce_rx_post_buf_64(struct ath10k_ce_pipe *pipe,
748*4882a593Smuzhiyun void *ctx,
749*4882a593Smuzhiyun dma_addr_t paddr)
750*4882a593Smuzhiyun {
751*4882a593Smuzhiyun struct ath10k *ar = pipe->ar;
752*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
753*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
754*4882a593Smuzhiyun unsigned int nentries_mask = dest_ring->nentries_mask;
755*4882a593Smuzhiyun unsigned int write_index = dest_ring->write_index;
756*4882a593Smuzhiyun unsigned int sw_index = dest_ring->sw_index;
757*4882a593Smuzhiyun struct ce_desc_64 *base = dest_ring->base_addr_owner_space;
758*4882a593Smuzhiyun struct ce_desc_64 *desc =
759*4882a593Smuzhiyun CE_DEST_RING_TO_DESC_64(base, write_index);
760*4882a593Smuzhiyun u32 ctrl_addr = pipe->ctrl_addr;
761*4882a593Smuzhiyun
762*4882a593Smuzhiyun lockdep_assert_held(&ce->ce_lock);
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun if (CE_RING_DELTA(nentries_mask, write_index, sw_index - 1) == 0)
765*4882a593Smuzhiyun return -ENOSPC;
766*4882a593Smuzhiyun
767*4882a593Smuzhiyun desc->addr = __cpu_to_le64(paddr);
768*4882a593Smuzhiyun desc->addr &= __cpu_to_le64(CE_DESC_ADDR_MASK);
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun desc->nbytes = 0;
771*4882a593Smuzhiyun
772*4882a593Smuzhiyun dest_ring->per_transfer_context[write_index] = ctx;
773*4882a593Smuzhiyun write_index = CE_RING_IDX_INCR(nentries_mask, write_index);
774*4882a593Smuzhiyun ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
775*4882a593Smuzhiyun dest_ring->write_index = write_index;
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun return 0;
778*4882a593Smuzhiyun }
779*4882a593Smuzhiyun
ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe * pipe,u32 nentries)780*4882a593Smuzhiyun void ath10k_ce_rx_update_write_idx(struct ath10k_ce_pipe *pipe, u32 nentries)
781*4882a593Smuzhiyun {
782*4882a593Smuzhiyun struct ath10k *ar = pipe->ar;
783*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring = pipe->dest_ring;
784*4882a593Smuzhiyun unsigned int nentries_mask = dest_ring->nentries_mask;
785*4882a593Smuzhiyun unsigned int write_index = dest_ring->write_index;
786*4882a593Smuzhiyun u32 ctrl_addr = pipe->ctrl_addr;
787*4882a593Smuzhiyun u32 cur_write_idx = ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
788*4882a593Smuzhiyun
789*4882a593Smuzhiyun /* Prevent CE ring stuck issue that will occur when ring is full.
790*4882a593Smuzhiyun * Make sure that write index is 1 less than read index.
791*4882a593Smuzhiyun */
792*4882a593Smuzhiyun if (((cur_write_idx + nentries) & nentries_mask) == dest_ring->sw_index)
793*4882a593Smuzhiyun nentries -= 1;
794*4882a593Smuzhiyun
795*4882a593Smuzhiyun write_index = CE_RING_IDX_ADD(nentries_mask, write_index, nentries);
796*4882a593Smuzhiyun ath10k_ce_dest_ring_write_index_set(ar, ctrl_addr, write_index);
797*4882a593Smuzhiyun dest_ring->write_index = write_index;
798*4882a593Smuzhiyun }
799*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_rx_update_write_idx);
800*4882a593Smuzhiyun
ath10k_ce_rx_post_buf(struct ath10k_ce_pipe * pipe,void * ctx,dma_addr_t paddr)801*4882a593Smuzhiyun int ath10k_ce_rx_post_buf(struct ath10k_ce_pipe *pipe, void *ctx,
802*4882a593Smuzhiyun dma_addr_t paddr)
803*4882a593Smuzhiyun {
804*4882a593Smuzhiyun struct ath10k *ar = pipe->ar;
805*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
806*4882a593Smuzhiyun int ret;
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
809*4882a593Smuzhiyun ret = pipe->ops->ce_rx_post_buf(pipe, ctx, paddr);
810*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun return ret;
813*4882a593Smuzhiyun }
814*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_rx_post_buf);
815*4882a593Smuzhiyun
816*4882a593Smuzhiyun /*
817*4882a593Smuzhiyun * Guts of ath10k_ce_completed_recv_next.
818*4882a593Smuzhiyun * The caller takes responsibility for any necessary locking.
819*4882a593Smuzhiyun */
820*4882a593Smuzhiyun static int
_ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp,unsigned int * nbytesp)821*4882a593Smuzhiyun _ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
822*4882a593Smuzhiyun void **per_transfer_contextp,
823*4882a593Smuzhiyun unsigned int *nbytesp)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
826*4882a593Smuzhiyun unsigned int nentries_mask = dest_ring->nentries_mask;
827*4882a593Smuzhiyun unsigned int sw_index = dest_ring->sw_index;
828*4882a593Smuzhiyun
829*4882a593Smuzhiyun struct ce_desc *base = dest_ring->base_addr_owner_space;
830*4882a593Smuzhiyun struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
831*4882a593Smuzhiyun struct ce_desc sdesc;
832*4882a593Smuzhiyun u16 nbytes;
833*4882a593Smuzhiyun
834*4882a593Smuzhiyun /* Copy in one go for performance reasons */
835*4882a593Smuzhiyun sdesc = *desc;
836*4882a593Smuzhiyun
837*4882a593Smuzhiyun nbytes = __le16_to_cpu(sdesc.nbytes);
838*4882a593Smuzhiyun if (nbytes == 0) {
839*4882a593Smuzhiyun /*
840*4882a593Smuzhiyun * This closes a relatively unusual race where the Host
841*4882a593Smuzhiyun * sees the updated DRRI before the update to the
842*4882a593Smuzhiyun * corresponding descriptor has completed. We treat this
843*4882a593Smuzhiyun * as a descriptor that is not yet done.
844*4882a593Smuzhiyun */
845*4882a593Smuzhiyun return -EIO;
846*4882a593Smuzhiyun }
847*4882a593Smuzhiyun
848*4882a593Smuzhiyun desc->nbytes = 0;
849*4882a593Smuzhiyun
850*4882a593Smuzhiyun /* Return data from completed destination descriptor */
851*4882a593Smuzhiyun *nbytesp = nbytes;
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun if (per_transfer_contextp)
854*4882a593Smuzhiyun *per_transfer_contextp =
855*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index];
856*4882a593Smuzhiyun
857*4882a593Smuzhiyun /* Copy engine 5 (HTT Rx) will reuse the same transfer context.
858*4882a593Smuzhiyun * So update transfer context all CEs except CE5.
859*4882a593Smuzhiyun */
860*4882a593Smuzhiyun if (ce_state->id != 5)
861*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index] = NULL;
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun /* Update sw_index */
864*4882a593Smuzhiyun sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
865*4882a593Smuzhiyun dest_ring->sw_index = sw_index;
866*4882a593Smuzhiyun
867*4882a593Smuzhiyun return 0;
868*4882a593Smuzhiyun }
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun static int
_ath10k_ce_completed_recv_next_nolock_64(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp,unsigned int * nbytesp)871*4882a593Smuzhiyun _ath10k_ce_completed_recv_next_nolock_64(struct ath10k_ce_pipe *ce_state,
872*4882a593Smuzhiyun void **per_transfer_contextp,
873*4882a593Smuzhiyun unsigned int *nbytesp)
874*4882a593Smuzhiyun {
875*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
876*4882a593Smuzhiyun unsigned int nentries_mask = dest_ring->nentries_mask;
877*4882a593Smuzhiyun unsigned int sw_index = dest_ring->sw_index;
878*4882a593Smuzhiyun struct ce_desc_64 *base = dest_ring->base_addr_owner_space;
879*4882a593Smuzhiyun struct ce_desc_64 *desc =
880*4882a593Smuzhiyun CE_DEST_RING_TO_DESC_64(base, sw_index);
881*4882a593Smuzhiyun struct ce_desc_64 sdesc;
882*4882a593Smuzhiyun u16 nbytes;
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun /* Copy in one go for performance reasons */
885*4882a593Smuzhiyun sdesc = *desc;
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun nbytes = __le16_to_cpu(sdesc.nbytes);
888*4882a593Smuzhiyun if (nbytes == 0) {
889*4882a593Smuzhiyun /* This closes a relatively unusual race where the Host
890*4882a593Smuzhiyun * sees the updated DRRI before the update to the
891*4882a593Smuzhiyun * corresponding descriptor has completed. We treat this
892*4882a593Smuzhiyun * as a descriptor that is not yet done.
893*4882a593Smuzhiyun */
894*4882a593Smuzhiyun return -EIO;
895*4882a593Smuzhiyun }
896*4882a593Smuzhiyun
897*4882a593Smuzhiyun desc->nbytes = 0;
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun /* Return data from completed destination descriptor */
900*4882a593Smuzhiyun *nbytesp = nbytes;
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun if (per_transfer_contextp)
903*4882a593Smuzhiyun *per_transfer_contextp =
904*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index];
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun /* Copy engine 5 (HTT Rx) will reuse the same transfer context.
907*4882a593Smuzhiyun * So update transfer context all CEs except CE5.
908*4882a593Smuzhiyun */
909*4882a593Smuzhiyun if (ce_state->id != 5)
910*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index] = NULL;
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun /* Update sw_index */
913*4882a593Smuzhiyun sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
914*4882a593Smuzhiyun dest_ring->sw_index = sw_index;
915*4882a593Smuzhiyun
916*4882a593Smuzhiyun return 0;
917*4882a593Smuzhiyun }
918*4882a593Smuzhiyun
ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe * ce_state,void ** per_transfer_ctx,unsigned int * nbytesp)919*4882a593Smuzhiyun int ath10k_ce_completed_recv_next_nolock(struct ath10k_ce_pipe *ce_state,
920*4882a593Smuzhiyun void **per_transfer_ctx,
921*4882a593Smuzhiyun unsigned int *nbytesp)
922*4882a593Smuzhiyun {
923*4882a593Smuzhiyun return ce_state->ops->ce_completed_recv_next_nolock(ce_state,
924*4882a593Smuzhiyun per_transfer_ctx,
925*4882a593Smuzhiyun nbytesp);
926*4882a593Smuzhiyun }
927*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_completed_recv_next_nolock);
928*4882a593Smuzhiyun
ath10k_ce_completed_recv_next(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp,unsigned int * nbytesp)929*4882a593Smuzhiyun int ath10k_ce_completed_recv_next(struct ath10k_ce_pipe *ce_state,
930*4882a593Smuzhiyun void **per_transfer_contextp,
931*4882a593Smuzhiyun unsigned int *nbytesp)
932*4882a593Smuzhiyun {
933*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
934*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
935*4882a593Smuzhiyun int ret;
936*4882a593Smuzhiyun
937*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
938*4882a593Smuzhiyun ret = ce_state->ops->ce_completed_recv_next_nolock(ce_state,
939*4882a593Smuzhiyun per_transfer_contextp,
940*4882a593Smuzhiyun nbytesp);
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun return ret;
945*4882a593Smuzhiyun }
946*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_completed_recv_next);
947*4882a593Smuzhiyun
_ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp,dma_addr_t * bufferp)948*4882a593Smuzhiyun static int _ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
949*4882a593Smuzhiyun void **per_transfer_contextp,
950*4882a593Smuzhiyun dma_addr_t *bufferp)
951*4882a593Smuzhiyun {
952*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring;
953*4882a593Smuzhiyun unsigned int nentries_mask;
954*4882a593Smuzhiyun unsigned int sw_index;
955*4882a593Smuzhiyun unsigned int write_index;
956*4882a593Smuzhiyun int ret;
957*4882a593Smuzhiyun struct ath10k *ar;
958*4882a593Smuzhiyun struct ath10k_ce *ce;
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun dest_ring = ce_state->dest_ring;
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun if (!dest_ring)
963*4882a593Smuzhiyun return -EIO;
964*4882a593Smuzhiyun
965*4882a593Smuzhiyun ar = ce_state->ar;
966*4882a593Smuzhiyun ce = ath10k_ce_priv(ar);
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun nentries_mask = dest_ring->nentries_mask;
971*4882a593Smuzhiyun sw_index = dest_ring->sw_index;
972*4882a593Smuzhiyun write_index = dest_ring->write_index;
973*4882a593Smuzhiyun if (write_index != sw_index) {
974*4882a593Smuzhiyun struct ce_desc *base = dest_ring->base_addr_owner_space;
975*4882a593Smuzhiyun struct ce_desc *desc = CE_DEST_RING_TO_DESC(base, sw_index);
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun /* Return data from completed destination descriptor */
978*4882a593Smuzhiyun *bufferp = __le32_to_cpu(desc->addr);
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun if (per_transfer_contextp)
981*4882a593Smuzhiyun *per_transfer_contextp =
982*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index];
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun /* sanity */
985*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index] = NULL;
986*4882a593Smuzhiyun desc->nbytes = 0;
987*4882a593Smuzhiyun
988*4882a593Smuzhiyun /* Update sw_index */
989*4882a593Smuzhiyun sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
990*4882a593Smuzhiyun dest_ring->sw_index = sw_index;
991*4882a593Smuzhiyun ret = 0;
992*4882a593Smuzhiyun } else {
993*4882a593Smuzhiyun ret = -EIO;
994*4882a593Smuzhiyun }
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun return ret;
999*4882a593Smuzhiyun }
1000*4882a593Smuzhiyun
_ath10k_ce_revoke_recv_next_64(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp,dma_addr_t * bufferp)1001*4882a593Smuzhiyun static int _ath10k_ce_revoke_recv_next_64(struct ath10k_ce_pipe *ce_state,
1002*4882a593Smuzhiyun void **per_transfer_contextp,
1003*4882a593Smuzhiyun dma_addr_t *bufferp)
1004*4882a593Smuzhiyun {
1005*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring;
1006*4882a593Smuzhiyun unsigned int nentries_mask;
1007*4882a593Smuzhiyun unsigned int sw_index;
1008*4882a593Smuzhiyun unsigned int write_index;
1009*4882a593Smuzhiyun int ret;
1010*4882a593Smuzhiyun struct ath10k *ar;
1011*4882a593Smuzhiyun struct ath10k_ce *ce;
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun dest_ring = ce_state->dest_ring;
1014*4882a593Smuzhiyun
1015*4882a593Smuzhiyun if (!dest_ring)
1016*4882a593Smuzhiyun return -EIO;
1017*4882a593Smuzhiyun
1018*4882a593Smuzhiyun ar = ce_state->ar;
1019*4882a593Smuzhiyun ce = ath10k_ce_priv(ar);
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
1022*4882a593Smuzhiyun
1023*4882a593Smuzhiyun nentries_mask = dest_ring->nentries_mask;
1024*4882a593Smuzhiyun sw_index = dest_ring->sw_index;
1025*4882a593Smuzhiyun write_index = dest_ring->write_index;
1026*4882a593Smuzhiyun if (write_index != sw_index) {
1027*4882a593Smuzhiyun struct ce_desc_64 *base = dest_ring->base_addr_owner_space;
1028*4882a593Smuzhiyun struct ce_desc_64 *desc =
1029*4882a593Smuzhiyun CE_DEST_RING_TO_DESC_64(base, sw_index);
1030*4882a593Smuzhiyun
1031*4882a593Smuzhiyun /* Return data from completed destination descriptor */
1032*4882a593Smuzhiyun *bufferp = __le64_to_cpu(desc->addr);
1033*4882a593Smuzhiyun
1034*4882a593Smuzhiyun if (per_transfer_contextp)
1035*4882a593Smuzhiyun *per_transfer_contextp =
1036*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index];
1037*4882a593Smuzhiyun
1038*4882a593Smuzhiyun /* sanity */
1039*4882a593Smuzhiyun dest_ring->per_transfer_context[sw_index] = NULL;
1040*4882a593Smuzhiyun desc->nbytes = 0;
1041*4882a593Smuzhiyun
1042*4882a593Smuzhiyun /* Update sw_index */
1043*4882a593Smuzhiyun sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1044*4882a593Smuzhiyun dest_ring->sw_index = sw_index;
1045*4882a593Smuzhiyun ret = 0;
1046*4882a593Smuzhiyun } else {
1047*4882a593Smuzhiyun ret = -EIO;
1048*4882a593Smuzhiyun }
1049*4882a593Smuzhiyun
1050*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun return ret;
1053*4882a593Smuzhiyun }
1054*4882a593Smuzhiyun
ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp,dma_addr_t * bufferp)1055*4882a593Smuzhiyun int ath10k_ce_revoke_recv_next(struct ath10k_ce_pipe *ce_state,
1056*4882a593Smuzhiyun void **per_transfer_contextp,
1057*4882a593Smuzhiyun dma_addr_t *bufferp)
1058*4882a593Smuzhiyun {
1059*4882a593Smuzhiyun return ce_state->ops->ce_revoke_recv_next(ce_state,
1060*4882a593Smuzhiyun per_transfer_contextp,
1061*4882a593Smuzhiyun bufferp);
1062*4882a593Smuzhiyun }
1063*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_revoke_recv_next);
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun /*
1066*4882a593Smuzhiyun * Guts of ath10k_ce_completed_send_next.
1067*4882a593Smuzhiyun * The caller takes responsibility for any necessary locking.
1068*4882a593Smuzhiyun */
_ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp)1069*4882a593Smuzhiyun static int _ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
1070*4882a593Smuzhiyun void **per_transfer_contextp)
1071*4882a593Smuzhiyun {
1072*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring = ce_state->src_ring;
1073*4882a593Smuzhiyun u32 ctrl_addr = ce_state->ctrl_addr;
1074*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
1075*4882a593Smuzhiyun unsigned int nentries_mask = src_ring->nentries_mask;
1076*4882a593Smuzhiyun unsigned int sw_index = src_ring->sw_index;
1077*4882a593Smuzhiyun unsigned int read_index;
1078*4882a593Smuzhiyun struct ce_desc *desc;
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun if (src_ring->hw_index == sw_index) {
1081*4882a593Smuzhiyun /*
1082*4882a593Smuzhiyun * The SW completion index has caught up with the cached
1083*4882a593Smuzhiyun * version of the HW completion index.
1084*4882a593Smuzhiyun * Update the cached HW completion index to see whether
1085*4882a593Smuzhiyun * the SW has really caught up to the HW, or if the cached
1086*4882a593Smuzhiyun * value of the HW index has become stale.
1087*4882a593Smuzhiyun */
1088*4882a593Smuzhiyun
1089*4882a593Smuzhiyun read_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
1090*4882a593Smuzhiyun if (read_index == 0xffffffff)
1091*4882a593Smuzhiyun return -ENODEV;
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun read_index &= nentries_mask;
1094*4882a593Smuzhiyun src_ring->hw_index = read_index;
1095*4882a593Smuzhiyun }
1096*4882a593Smuzhiyun
1097*4882a593Smuzhiyun if (ar->hw_params.rri_on_ddr)
1098*4882a593Smuzhiyun read_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
1099*4882a593Smuzhiyun else
1100*4882a593Smuzhiyun read_index = src_ring->hw_index;
1101*4882a593Smuzhiyun
1102*4882a593Smuzhiyun if (read_index == sw_index)
1103*4882a593Smuzhiyun return -EIO;
1104*4882a593Smuzhiyun
1105*4882a593Smuzhiyun if (per_transfer_contextp)
1106*4882a593Smuzhiyun *per_transfer_contextp =
1107*4882a593Smuzhiyun src_ring->per_transfer_context[sw_index];
1108*4882a593Smuzhiyun
1109*4882a593Smuzhiyun /* sanity */
1110*4882a593Smuzhiyun src_ring->per_transfer_context[sw_index] = NULL;
1111*4882a593Smuzhiyun desc = CE_SRC_RING_TO_DESC(src_ring->base_addr_owner_space,
1112*4882a593Smuzhiyun sw_index);
1113*4882a593Smuzhiyun desc->nbytes = 0;
1114*4882a593Smuzhiyun
1115*4882a593Smuzhiyun /* Update sw_index */
1116*4882a593Smuzhiyun sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1117*4882a593Smuzhiyun src_ring->sw_index = sw_index;
1118*4882a593Smuzhiyun
1119*4882a593Smuzhiyun return 0;
1120*4882a593Smuzhiyun }
1121*4882a593Smuzhiyun
_ath10k_ce_completed_send_next_nolock_64(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp)1122*4882a593Smuzhiyun static int _ath10k_ce_completed_send_next_nolock_64(struct ath10k_ce_pipe *ce_state,
1123*4882a593Smuzhiyun void **per_transfer_contextp)
1124*4882a593Smuzhiyun {
1125*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring = ce_state->src_ring;
1126*4882a593Smuzhiyun u32 ctrl_addr = ce_state->ctrl_addr;
1127*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
1128*4882a593Smuzhiyun unsigned int nentries_mask = src_ring->nentries_mask;
1129*4882a593Smuzhiyun unsigned int sw_index = src_ring->sw_index;
1130*4882a593Smuzhiyun unsigned int read_index;
1131*4882a593Smuzhiyun struct ce_desc_64 *desc;
1132*4882a593Smuzhiyun
1133*4882a593Smuzhiyun if (src_ring->hw_index == sw_index) {
1134*4882a593Smuzhiyun /*
1135*4882a593Smuzhiyun * The SW completion index has caught up with the cached
1136*4882a593Smuzhiyun * version of the HW completion index.
1137*4882a593Smuzhiyun * Update the cached HW completion index to see whether
1138*4882a593Smuzhiyun * the SW has really caught up to the HW, or if the cached
1139*4882a593Smuzhiyun * value of the HW index has become stale.
1140*4882a593Smuzhiyun */
1141*4882a593Smuzhiyun
1142*4882a593Smuzhiyun read_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
1143*4882a593Smuzhiyun if (read_index == 0xffffffff)
1144*4882a593Smuzhiyun return -ENODEV;
1145*4882a593Smuzhiyun
1146*4882a593Smuzhiyun read_index &= nentries_mask;
1147*4882a593Smuzhiyun src_ring->hw_index = read_index;
1148*4882a593Smuzhiyun }
1149*4882a593Smuzhiyun
1150*4882a593Smuzhiyun if (ar->hw_params.rri_on_ddr)
1151*4882a593Smuzhiyun read_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
1152*4882a593Smuzhiyun else
1153*4882a593Smuzhiyun read_index = src_ring->hw_index;
1154*4882a593Smuzhiyun
1155*4882a593Smuzhiyun if (read_index == sw_index)
1156*4882a593Smuzhiyun return -EIO;
1157*4882a593Smuzhiyun
1158*4882a593Smuzhiyun if (per_transfer_contextp)
1159*4882a593Smuzhiyun *per_transfer_contextp =
1160*4882a593Smuzhiyun src_ring->per_transfer_context[sw_index];
1161*4882a593Smuzhiyun
1162*4882a593Smuzhiyun /* sanity */
1163*4882a593Smuzhiyun src_ring->per_transfer_context[sw_index] = NULL;
1164*4882a593Smuzhiyun desc = CE_SRC_RING_TO_DESC_64(src_ring->base_addr_owner_space,
1165*4882a593Smuzhiyun sw_index);
1166*4882a593Smuzhiyun desc->nbytes = 0;
1167*4882a593Smuzhiyun
1168*4882a593Smuzhiyun /* Update sw_index */
1169*4882a593Smuzhiyun sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1170*4882a593Smuzhiyun src_ring->sw_index = sw_index;
1171*4882a593Smuzhiyun
1172*4882a593Smuzhiyun return 0;
1173*4882a593Smuzhiyun }
1174*4882a593Smuzhiyun
ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp)1175*4882a593Smuzhiyun int ath10k_ce_completed_send_next_nolock(struct ath10k_ce_pipe *ce_state,
1176*4882a593Smuzhiyun void **per_transfer_contextp)
1177*4882a593Smuzhiyun {
1178*4882a593Smuzhiyun return ce_state->ops->ce_completed_send_next_nolock(ce_state,
1179*4882a593Smuzhiyun per_transfer_contextp);
1180*4882a593Smuzhiyun }
1181*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_completed_send_next_nolock);
1182*4882a593Smuzhiyun
ath10k_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)1183*4882a593Smuzhiyun static void ath10k_ce_extract_desc_data(struct ath10k *ar,
1184*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring,
1185*4882a593Smuzhiyun u32 sw_index,
1186*4882a593Smuzhiyun dma_addr_t *bufferp,
1187*4882a593Smuzhiyun u32 *nbytesp,
1188*4882a593Smuzhiyun u32 *transfer_idp)
1189*4882a593Smuzhiyun {
1190*4882a593Smuzhiyun struct ce_desc *base = src_ring->base_addr_owner_space;
1191*4882a593Smuzhiyun struct ce_desc *desc = CE_SRC_RING_TO_DESC(base, sw_index);
1192*4882a593Smuzhiyun
1193*4882a593Smuzhiyun /* Return data from completed source descriptor */
1194*4882a593Smuzhiyun *bufferp = __le32_to_cpu(desc->addr);
1195*4882a593Smuzhiyun *nbytesp = __le16_to_cpu(desc->nbytes);
1196*4882a593Smuzhiyun *transfer_idp = MS(__le16_to_cpu(desc->flags),
1197*4882a593Smuzhiyun CE_DESC_FLAGS_META_DATA);
1198*4882a593Smuzhiyun }
1199*4882a593Smuzhiyun
ath10k_ce_extract_desc_data_64(struct ath10k * ar,struct ath10k_ce_ring * src_ring,u32 sw_index,dma_addr_t * bufferp,u32 * nbytesp,u32 * transfer_idp)1200*4882a593Smuzhiyun static void ath10k_ce_extract_desc_data_64(struct ath10k *ar,
1201*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring,
1202*4882a593Smuzhiyun u32 sw_index,
1203*4882a593Smuzhiyun dma_addr_t *bufferp,
1204*4882a593Smuzhiyun u32 *nbytesp,
1205*4882a593Smuzhiyun u32 *transfer_idp)
1206*4882a593Smuzhiyun {
1207*4882a593Smuzhiyun struct ce_desc_64 *base = src_ring->base_addr_owner_space;
1208*4882a593Smuzhiyun struct ce_desc_64 *desc =
1209*4882a593Smuzhiyun CE_SRC_RING_TO_DESC_64(base, sw_index);
1210*4882a593Smuzhiyun
1211*4882a593Smuzhiyun /* Return data from completed source descriptor */
1212*4882a593Smuzhiyun *bufferp = __le64_to_cpu(desc->addr);
1213*4882a593Smuzhiyun *nbytesp = __le16_to_cpu(desc->nbytes);
1214*4882a593Smuzhiyun *transfer_idp = MS(__le16_to_cpu(desc->flags),
1215*4882a593Smuzhiyun CE_DESC_FLAGS_META_DATA);
1216*4882a593Smuzhiyun }
1217*4882a593Smuzhiyun
1218*4882a593Smuzhiyun /* NB: Modeled after ath10k_ce_completed_send_next */
ath10k_ce_cancel_send_next(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp,dma_addr_t * bufferp,unsigned int * nbytesp,unsigned int * transfer_idp)1219*4882a593Smuzhiyun int ath10k_ce_cancel_send_next(struct ath10k_ce_pipe *ce_state,
1220*4882a593Smuzhiyun void **per_transfer_contextp,
1221*4882a593Smuzhiyun dma_addr_t *bufferp,
1222*4882a593Smuzhiyun unsigned int *nbytesp,
1223*4882a593Smuzhiyun unsigned int *transfer_idp)
1224*4882a593Smuzhiyun {
1225*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring;
1226*4882a593Smuzhiyun unsigned int nentries_mask;
1227*4882a593Smuzhiyun unsigned int sw_index;
1228*4882a593Smuzhiyun unsigned int write_index;
1229*4882a593Smuzhiyun int ret;
1230*4882a593Smuzhiyun struct ath10k *ar;
1231*4882a593Smuzhiyun struct ath10k_ce *ce;
1232*4882a593Smuzhiyun
1233*4882a593Smuzhiyun src_ring = ce_state->src_ring;
1234*4882a593Smuzhiyun
1235*4882a593Smuzhiyun if (!src_ring)
1236*4882a593Smuzhiyun return -EIO;
1237*4882a593Smuzhiyun
1238*4882a593Smuzhiyun ar = ce_state->ar;
1239*4882a593Smuzhiyun ce = ath10k_ce_priv(ar);
1240*4882a593Smuzhiyun
1241*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun nentries_mask = src_ring->nentries_mask;
1244*4882a593Smuzhiyun sw_index = src_ring->sw_index;
1245*4882a593Smuzhiyun write_index = src_ring->write_index;
1246*4882a593Smuzhiyun
1247*4882a593Smuzhiyun if (write_index != sw_index) {
1248*4882a593Smuzhiyun ce_state->ops->ce_extract_desc_data(ar, src_ring, sw_index,
1249*4882a593Smuzhiyun bufferp, nbytesp,
1250*4882a593Smuzhiyun transfer_idp);
1251*4882a593Smuzhiyun
1252*4882a593Smuzhiyun if (per_transfer_contextp)
1253*4882a593Smuzhiyun *per_transfer_contextp =
1254*4882a593Smuzhiyun src_ring->per_transfer_context[sw_index];
1255*4882a593Smuzhiyun
1256*4882a593Smuzhiyun /* sanity */
1257*4882a593Smuzhiyun src_ring->per_transfer_context[sw_index] = NULL;
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun /* Update sw_index */
1260*4882a593Smuzhiyun sw_index = CE_RING_IDX_INCR(nentries_mask, sw_index);
1261*4882a593Smuzhiyun src_ring->sw_index = sw_index;
1262*4882a593Smuzhiyun ret = 0;
1263*4882a593Smuzhiyun } else {
1264*4882a593Smuzhiyun ret = -EIO;
1265*4882a593Smuzhiyun }
1266*4882a593Smuzhiyun
1267*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
1268*4882a593Smuzhiyun
1269*4882a593Smuzhiyun return ret;
1270*4882a593Smuzhiyun }
1271*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_cancel_send_next);
1272*4882a593Smuzhiyun
ath10k_ce_completed_send_next(struct ath10k_ce_pipe * ce_state,void ** per_transfer_contextp)1273*4882a593Smuzhiyun int ath10k_ce_completed_send_next(struct ath10k_ce_pipe *ce_state,
1274*4882a593Smuzhiyun void **per_transfer_contextp)
1275*4882a593Smuzhiyun {
1276*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
1277*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1278*4882a593Smuzhiyun int ret;
1279*4882a593Smuzhiyun
1280*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
1281*4882a593Smuzhiyun ret = ath10k_ce_completed_send_next_nolock(ce_state,
1282*4882a593Smuzhiyun per_transfer_contextp);
1283*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
1284*4882a593Smuzhiyun
1285*4882a593Smuzhiyun return ret;
1286*4882a593Smuzhiyun }
1287*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_completed_send_next);
1288*4882a593Smuzhiyun
1289*4882a593Smuzhiyun /*
1290*4882a593Smuzhiyun * Guts of interrupt handler for per-engine interrupts on a particular CE.
1291*4882a593Smuzhiyun *
1292*4882a593Smuzhiyun * Invokes registered callbacks for recv_complete,
1293*4882a593Smuzhiyun * send_complete, and watermarks.
1294*4882a593Smuzhiyun */
ath10k_ce_per_engine_service(struct ath10k * ar,unsigned int ce_id)1295*4882a593Smuzhiyun void ath10k_ce_per_engine_service(struct ath10k *ar, unsigned int ce_id)
1296*4882a593Smuzhiyun {
1297*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1298*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
1299*4882a593Smuzhiyun struct ath10k_hw_ce_host_wm_regs *wm_regs = ar->hw_ce_regs->wm_regs;
1300*4882a593Smuzhiyun u32 ctrl_addr = ce_state->ctrl_addr;
1301*4882a593Smuzhiyun
1302*4882a593Smuzhiyun /*
1303*4882a593Smuzhiyun * Clear before handling
1304*4882a593Smuzhiyun *
1305*4882a593Smuzhiyun * Misc CE interrupts are not being handled, but still need
1306*4882a593Smuzhiyun * to be cleared.
1307*4882a593Smuzhiyun *
1308*4882a593Smuzhiyun * NOTE: When the last copy engine interrupt is cleared the
1309*4882a593Smuzhiyun * hardware will go to sleep. Once this happens any access to
1310*4882a593Smuzhiyun * the CE registers can cause a hardware fault.
1311*4882a593Smuzhiyun */
1312*4882a593Smuzhiyun ath10k_ce_engine_int_status_clear(ar, ctrl_addr,
1313*4882a593Smuzhiyun wm_regs->cc_mask | wm_regs->wm_mask);
1314*4882a593Smuzhiyun
1315*4882a593Smuzhiyun if (ce_state->recv_cb)
1316*4882a593Smuzhiyun ce_state->recv_cb(ce_state);
1317*4882a593Smuzhiyun
1318*4882a593Smuzhiyun if (ce_state->send_cb)
1319*4882a593Smuzhiyun ce_state->send_cb(ce_state);
1320*4882a593Smuzhiyun }
1321*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_per_engine_service);
1322*4882a593Smuzhiyun
1323*4882a593Smuzhiyun /*
1324*4882a593Smuzhiyun * Handler for per-engine interrupts on ALL active CEs.
1325*4882a593Smuzhiyun * This is used in cases where the system is sharing a
1326*4882a593Smuzhiyun * single interrput for all CEs
1327*4882a593Smuzhiyun */
1328*4882a593Smuzhiyun
ath10k_ce_per_engine_service_any(struct ath10k * ar)1329*4882a593Smuzhiyun void ath10k_ce_per_engine_service_any(struct ath10k *ar)
1330*4882a593Smuzhiyun {
1331*4882a593Smuzhiyun int ce_id;
1332*4882a593Smuzhiyun u32 intr_summary;
1333*4882a593Smuzhiyun
1334*4882a593Smuzhiyun intr_summary = ath10k_ce_interrupt_summary(ar);
1335*4882a593Smuzhiyun
1336*4882a593Smuzhiyun for (ce_id = 0; intr_summary && (ce_id < CE_COUNT); ce_id++) {
1337*4882a593Smuzhiyun if (intr_summary & (1 << ce_id))
1338*4882a593Smuzhiyun intr_summary &= ~(1 << ce_id);
1339*4882a593Smuzhiyun else
1340*4882a593Smuzhiyun /* no intr pending on this CE */
1341*4882a593Smuzhiyun continue;
1342*4882a593Smuzhiyun
1343*4882a593Smuzhiyun ath10k_ce_per_engine_service(ar, ce_id);
1344*4882a593Smuzhiyun }
1345*4882a593Smuzhiyun }
1346*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_per_engine_service_any);
1347*4882a593Smuzhiyun
1348*4882a593Smuzhiyun /*
1349*4882a593Smuzhiyun * Adjust interrupts for the copy complete handler.
1350*4882a593Smuzhiyun * If it's needed for either send or recv, then unmask
1351*4882a593Smuzhiyun * this interrupt; otherwise, mask it.
1352*4882a593Smuzhiyun *
1353*4882a593Smuzhiyun * Called with ce_lock held.
1354*4882a593Smuzhiyun */
ath10k_ce_per_engine_handler_adjust(struct ath10k_ce_pipe * ce_state)1355*4882a593Smuzhiyun static void ath10k_ce_per_engine_handler_adjust(struct ath10k_ce_pipe *ce_state)
1356*4882a593Smuzhiyun {
1357*4882a593Smuzhiyun u32 ctrl_addr = ce_state->ctrl_addr;
1358*4882a593Smuzhiyun struct ath10k *ar = ce_state->ar;
1359*4882a593Smuzhiyun bool disable_copy_compl_intr = ce_state->attr_flags & CE_ATTR_DIS_INTR;
1360*4882a593Smuzhiyun
1361*4882a593Smuzhiyun if ((!disable_copy_compl_intr) &&
1362*4882a593Smuzhiyun (ce_state->send_cb || ce_state->recv_cb))
1363*4882a593Smuzhiyun ath10k_ce_copy_complete_inter_enable(ar, ctrl_addr);
1364*4882a593Smuzhiyun else
1365*4882a593Smuzhiyun ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
1368*4882a593Smuzhiyun }
1369*4882a593Smuzhiyun
ath10k_ce_disable_interrupt(struct ath10k * ar,int ce_id)1370*4882a593Smuzhiyun void ath10k_ce_disable_interrupt(struct ath10k *ar, int ce_id)
1371*4882a593Smuzhiyun {
1372*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1373*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state;
1374*4882a593Smuzhiyun u32 ctrl_addr;
1375*4882a593Smuzhiyun
1376*4882a593Smuzhiyun ce_state = &ce->ce_states[ce_id];
1377*4882a593Smuzhiyun if (ce_state->attr_flags & CE_ATTR_POLL)
1378*4882a593Smuzhiyun return;
1379*4882a593Smuzhiyun
1380*4882a593Smuzhiyun ctrl_addr = ath10k_ce_base_address(ar, ce_id);
1381*4882a593Smuzhiyun
1382*4882a593Smuzhiyun ath10k_ce_copy_complete_intr_disable(ar, ctrl_addr);
1383*4882a593Smuzhiyun ath10k_ce_error_intr_disable(ar, ctrl_addr);
1384*4882a593Smuzhiyun ath10k_ce_watermark_intr_disable(ar, ctrl_addr);
1385*4882a593Smuzhiyun }
1386*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_disable_interrupt);
1387*4882a593Smuzhiyun
ath10k_ce_disable_interrupts(struct ath10k * ar)1388*4882a593Smuzhiyun void ath10k_ce_disable_interrupts(struct ath10k *ar)
1389*4882a593Smuzhiyun {
1390*4882a593Smuzhiyun int ce_id;
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun for (ce_id = 0; ce_id < CE_COUNT; ce_id++)
1393*4882a593Smuzhiyun ath10k_ce_disable_interrupt(ar, ce_id);
1394*4882a593Smuzhiyun }
1395*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_disable_interrupts);
1396*4882a593Smuzhiyun
ath10k_ce_enable_interrupt(struct ath10k * ar,int ce_id)1397*4882a593Smuzhiyun void ath10k_ce_enable_interrupt(struct ath10k *ar, int ce_id)
1398*4882a593Smuzhiyun {
1399*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1400*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state;
1401*4882a593Smuzhiyun
1402*4882a593Smuzhiyun ce_state = &ce->ce_states[ce_id];
1403*4882a593Smuzhiyun if (ce_state->attr_flags & CE_ATTR_POLL)
1404*4882a593Smuzhiyun return;
1405*4882a593Smuzhiyun
1406*4882a593Smuzhiyun ath10k_ce_per_engine_handler_adjust(ce_state);
1407*4882a593Smuzhiyun }
1408*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_enable_interrupt);
1409*4882a593Smuzhiyun
ath10k_ce_enable_interrupts(struct ath10k * ar)1410*4882a593Smuzhiyun void ath10k_ce_enable_interrupts(struct ath10k *ar)
1411*4882a593Smuzhiyun {
1412*4882a593Smuzhiyun int ce_id;
1413*4882a593Smuzhiyun
1414*4882a593Smuzhiyun /* Enable interrupts for copy engine that
1415*4882a593Smuzhiyun * are not using polling mode.
1416*4882a593Smuzhiyun */
1417*4882a593Smuzhiyun for (ce_id = 0; ce_id < CE_COUNT; ce_id++)
1418*4882a593Smuzhiyun ath10k_ce_enable_interrupt(ar, ce_id);
1419*4882a593Smuzhiyun }
1420*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_enable_interrupts);
1421*4882a593Smuzhiyun
ath10k_ce_init_src_ring(struct ath10k * ar,unsigned int ce_id,const struct ce_attr * attr)1422*4882a593Smuzhiyun static int ath10k_ce_init_src_ring(struct ath10k *ar,
1423*4882a593Smuzhiyun unsigned int ce_id,
1424*4882a593Smuzhiyun const struct ce_attr *attr)
1425*4882a593Smuzhiyun {
1426*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1427*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
1428*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring = ce_state->src_ring;
1429*4882a593Smuzhiyun u32 nentries, ctrl_addr = ath10k_ce_base_address(ar, ce_id);
1430*4882a593Smuzhiyun
1431*4882a593Smuzhiyun nentries = roundup_pow_of_two(attr->src_nentries);
1432*4882a593Smuzhiyun
1433*4882a593Smuzhiyun if (ar->hw_params.target_64bit)
1434*4882a593Smuzhiyun memset(src_ring->base_addr_owner_space, 0,
1435*4882a593Smuzhiyun nentries * sizeof(struct ce_desc_64));
1436*4882a593Smuzhiyun else
1437*4882a593Smuzhiyun memset(src_ring->base_addr_owner_space, 0,
1438*4882a593Smuzhiyun nentries * sizeof(struct ce_desc));
1439*4882a593Smuzhiyun
1440*4882a593Smuzhiyun src_ring->sw_index = ath10k_ce_src_ring_read_index_get(ar, ctrl_addr);
1441*4882a593Smuzhiyun src_ring->sw_index &= src_ring->nentries_mask;
1442*4882a593Smuzhiyun src_ring->hw_index = src_ring->sw_index;
1443*4882a593Smuzhiyun
1444*4882a593Smuzhiyun src_ring->write_index =
1445*4882a593Smuzhiyun ath10k_ce_src_ring_write_index_get(ar, ctrl_addr);
1446*4882a593Smuzhiyun src_ring->write_index &= src_ring->nentries_mask;
1447*4882a593Smuzhiyun
1448*4882a593Smuzhiyun ath10k_ce_src_ring_base_addr_set(ar, ce_id,
1449*4882a593Smuzhiyun src_ring->base_addr_ce_space);
1450*4882a593Smuzhiyun ath10k_ce_src_ring_size_set(ar, ctrl_addr, nentries);
1451*4882a593Smuzhiyun ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, attr->src_sz_max);
1452*4882a593Smuzhiyun ath10k_ce_src_ring_byte_swap_set(ar, ctrl_addr, 0);
1453*4882a593Smuzhiyun ath10k_ce_src_ring_lowmark_set(ar, ctrl_addr, 0);
1454*4882a593Smuzhiyun ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, nentries);
1455*4882a593Smuzhiyun
1456*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_BOOT,
1457*4882a593Smuzhiyun "boot init ce src ring id %d entries %d base_addr %pK\n",
1458*4882a593Smuzhiyun ce_id, nentries, src_ring->base_addr_owner_space);
1459*4882a593Smuzhiyun
1460*4882a593Smuzhiyun return 0;
1461*4882a593Smuzhiyun }
1462*4882a593Smuzhiyun
ath10k_ce_init_dest_ring(struct ath10k * ar,unsigned int ce_id,const struct ce_attr * attr)1463*4882a593Smuzhiyun static int ath10k_ce_init_dest_ring(struct ath10k *ar,
1464*4882a593Smuzhiyun unsigned int ce_id,
1465*4882a593Smuzhiyun const struct ce_attr *attr)
1466*4882a593Smuzhiyun {
1467*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1468*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
1469*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring = ce_state->dest_ring;
1470*4882a593Smuzhiyun u32 nentries, ctrl_addr = ath10k_ce_base_address(ar, ce_id);
1471*4882a593Smuzhiyun
1472*4882a593Smuzhiyun nentries = roundup_pow_of_two(attr->dest_nentries);
1473*4882a593Smuzhiyun
1474*4882a593Smuzhiyun if (ar->hw_params.target_64bit)
1475*4882a593Smuzhiyun memset(dest_ring->base_addr_owner_space, 0,
1476*4882a593Smuzhiyun nentries * sizeof(struct ce_desc_64));
1477*4882a593Smuzhiyun else
1478*4882a593Smuzhiyun memset(dest_ring->base_addr_owner_space, 0,
1479*4882a593Smuzhiyun nentries * sizeof(struct ce_desc));
1480*4882a593Smuzhiyun
1481*4882a593Smuzhiyun dest_ring->sw_index = ath10k_ce_dest_ring_read_index_get(ar, ctrl_addr);
1482*4882a593Smuzhiyun dest_ring->sw_index &= dest_ring->nentries_mask;
1483*4882a593Smuzhiyun dest_ring->write_index =
1484*4882a593Smuzhiyun ath10k_ce_dest_ring_write_index_get(ar, ctrl_addr);
1485*4882a593Smuzhiyun dest_ring->write_index &= dest_ring->nentries_mask;
1486*4882a593Smuzhiyun
1487*4882a593Smuzhiyun ath10k_ce_dest_ring_base_addr_set(ar, ce_id,
1488*4882a593Smuzhiyun dest_ring->base_addr_ce_space);
1489*4882a593Smuzhiyun ath10k_ce_dest_ring_size_set(ar, ctrl_addr, nentries);
1490*4882a593Smuzhiyun ath10k_ce_dest_ring_byte_swap_set(ar, ctrl_addr, 0);
1491*4882a593Smuzhiyun ath10k_ce_dest_ring_lowmark_set(ar, ctrl_addr, 0);
1492*4882a593Smuzhiyun ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, nentries);
1493*4882a593Smuzhiyun
1494*4882a593Smuzhiyun ath10k_dbg(ar, ATH10K_DBG_BOOT,
1495*4882a593Smuzhiyun "boot ce dest ring id %d entries %d base_addr %pK\n",
1496*4882a593Smuzhiyun ce_id, nentries, dest_ring->base_addr_owner_space);
1497*4882a593Smuzhiyun
1498*4882a593Smuzhiyun return 0;
1499*4882a593Smuzhiyun }
1500*4882a593Smuzhiyun
ath10k_ce_alloc_shadow_base(struct ath10k * ar,struct ath10k_ce_ring * src_ring,u32 nentries)1501*4882a593Smuzhiyun static int ath10k_ce_alloc_shadow_base(struct ath10k *ar,
1502*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring,
1503*4882a593Smuzhiyun u32 nentries)
1504*4882a593Smuzhiyun {
1505*4882a593Smuzhiyun src_ring->shadow_base_unaligned = kcalloc(nentries,
1506*4882a593Smuzhiyun sizeof(struct ce_desc_64),
1507*4882a593Smuzhiyun GFP_KERNEL);
1508*4882a593Smuzhiyun if (!src_ring->shadow_base_unaligned)
1509*4882a593Smuzhiyun return -ENOMEM;
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun src_ring->shadow_base = (struct ce_desc_64 *)
1512*4882a593Smuzhiyun PTR_ALIGN(src_ring->shadow_base_unaligned,
1513*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1514*4882a593Smuzhiyun return 0;
1515*4882a593Smuzhiyun }
1516*4882a593Smuzhiyun
1517*4882a593Smuzhiyun static struct ath10k_ce_ring *
ath10k_ce_alloc_src_ring(struct ath10k * ar,unsigned int ce_id,const struct ce_attr * attr)1518*4882a593Smuzhiyun ath10k_ce_alloc_src_ring(struct ath10k *ar, unsigned int ce_id,
1519*4882a593Smuzhiyun const struct ce_attr *attr)
1520*4882a593Smuzhiyun {
1521*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring;
1522*4882a593Smuzhiyun u32 nentries = attr->src_nentries;
1523*4882a593Smuzhiyun dma_addr_t base_addr;
1524*4882a593Smuzhiyun int ret;
1525*4882a593Smuzhiyun
1526*4882a593Smuzhiyun nentries = roundup_pow_of_two(nentries);
1527*4882a593Smuzhiyun
1528*4882a593Smuzhiyun src_ring = kzalloc(struct_size(src_ring, per_transfer_context,
1529*4882a593Smuzhiyun nentries), GFP_KERNEL);
1530*4882a593Smuzhiyun if (src_ring == NULL)
1531*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1532*4882a593Smuzhiyun
1533*4882a593Smuzhiyun src_ring->nentries = nentries;
1534*4882a593Smuzhiyun src_ring->nentries_mask = nentries - 1;
1535*4882a593Smuzhiyun
1536*4882a593Smuzhiyun /*
1537*4882a593Smuzhiyun * Legacy platforms that do not support cache
1538*4882a593Smuzhiyun * coherent DMA are unsupported
1539*4882a593Smuzhiyun */
1540*4882a593Smuzhiyun src_ring->base_addr_owner_space_unaligned =
1541*4882a593Smuzhiyun dma_alloc_coherent(ar->dev,
1542*4882a593Smuzhiyun (nentries * sizeof(struct ce_desc) +
1543*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1544*4882a593Smuzhiyun &base_addr, GFP_KERNEL);
1545*4882a593Smuzhiyun if (!src_ring->base_addr_owner_space_unaligned) {
1546*4882a593Smuzhiyun kfree(src_ring);
1547*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1548*4882a593Smuzhiyun }
1549*4882a593Smuzhiyun
1550*4882a593Smuzhiyun src_ring->base_addr_ce_space_unaligned = base_addr;
1551*4882a593Smuzhiyun
1552*4882a593Smuzhiyun src_ring->base_addr_owner_space =
1553*4882a593Smuzhiyun PTR_ALIGN(src_ring->base_addr_owner_space_unaligned,
1554*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1555*4882a593Smuzhiyun src_ring->base_addr_ce_space =
1556*4882a593Smuzhiyun ALIGN(src_ring->base_addr_ce_space_unaligned,
1557*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1558*4882a593Smuzhiyun
1559*4882a593Smuzhiyun if (ar->hw_params.shadow_reg_support) {
1560*4882a593Smuzhiyun ret = ath10k_ce_alloc_shadow_base(ar, src_ring, nentries);
1561*4882a593Smuzhiyun if (ret) {
1562*4882a593Smuzhiyun dma_free_coherent(ar->dev,
1563*4882a593Smuzhiyun (nentries * sizeof(struct ce_desc) +
1564*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1565*4882a593Smuzhiyun src_ring->base_addr_owner_space_unaligned,
1566*4882a593Smuzhiyun base_addr);
1567*4882a593Smuzhiyun kfree(src_ring);
1568*4882a593Smuzhiyun return ERR_PTR(ret);
1569*4882a593Smuzhiyun }
1570*4882a593Smuzhiyun }
1571*4882a593Smuzhiyun
1572*4882a593Smuzhiyun return src_ring;
1573*4882a593Smuzhiyun }
1574*4882a593Smuzhiyun
1575*4882a593Smuzhiyun static struct ath10k_ce_ring *
ath10k_ce_alloc_src_ring_64(struct ath10k * ar,unsigned int ce_id,const struct ce_attr * attr)1576*4882a593Smuzhiyun ath10k_ce_alloc_src_ring_64(struct ath10k *ar, unsigned int ce_id,
1577*4882a593Smuzhiyun const struct ce_attr *attr)
1578*4882a593Smuzhiyun {
1579*4882a593Smuzhiyun struct ath10k_ce_ring *src_ring;
1580*4882a593Smuzhiyun u32 nentries = attr->src_nentries;
1581*4882a593Smuzhiyun dma_addr_t base_addr;
1582*4882a593Smuzhiyun int ret;
1583*4882a593Smuzhiyun
1584*4882a593Smuzhiyun nentries = roundup_pow_of_two(nentries);
1585*4882a593Smuzhiyun
1586*4882a593Smuzhiyun src_ring = kzalloc(struct_size(src_ring, per_transfer_context,
1587*4882a593Smuzhiyun nentries), GFP_KERNEL);
1588*4882a593Smuzhiyun if (!src_ring)
1589*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1590*4882a593Smuzhiyun
1591*4882a593Smuzhiyun src_ring->nentries = nentries;
1592*4882a593Smuzhiyun src_ring->nentries_mask = nentries - 1;
1593*4882a593Smuzhiyun
1594*4882a593Smuzhiyun /* Legacy platforms that do not support cache
1595*4882a593Smuzhiyun * coherent DMA are unsupported
1596*4882a593Smuzhiyun */
1597*4882a593Smuzhiyun src_ring->base_addr_owner_space_unaligned =
1598*4882a593Smuzhiyun dma_alloc_coherent(ar->dev,
1599*4882a593Smuzhiyun (nentries * sizeof(struct ce_desc_64) +
1600*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1601*4882a593Smuzhiyun &base_addr, GFP_KERNEL);
1602*4882a593Smuzhiyun if (!src_ring->base_addr_owner_space_unaligned) {
1603*4882a593Smuzhiyun kfree(src_ring);
1604*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1605*4882a593Smuzhiyun }
1606*4882a593Smuzhiyun
1607*4882a593Smuzhiyun src_ring->base_addr_ce_space_unaligned = base_addr;
1608*4882a593Smuzhiyun
1609*4882a593Smuzhiyun src_ring->base_addr_owner_space =
1610*4882a593Smuzhiyun PTR_ALIGN(src_ring->base_addr_owner_space_unaligned,
1611*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1612*4882a593Smuzhiyun src_ring->base_addr_ce_space =
1613*4882a593Smuzhiyun ALIGN(src_ring->base_addr_ce_space_unaligned,
1614*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1615*4882a593Smuzhiyun
1616*4882a593Smuzhiyun if (ar->hw_params.shadow_reg_support) {
1617*4882a593Smuzhiyun ret = ath10k_ce_alloc_shadow_base(ar, src_ring, nentries);
1618*4882a593Smuzhiyun if (ret) {
1619*4882a593Smuzhiyun dma_free_coherent(ar->dev,
1620*4882a593Smuzhiyun (nentries * sizeof(struct ce_desc_64) +
1621*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1622*4882a593Smuzhiyun src_ring->base_addr_owner_space_unaligned,
1623*4882a593Smuzhiyun base_addr);
1624*4882a593Smuzhiyun kfree(src_ring);
1625*4882a593Smuzhiyun return ERR_PTR(ret);
1626*4882a593Smuzhiyun }
1627*4882a593Smuzhiyun }
1628*4882a593Smuzhiyun
1629*4882a593Smuzhiyun return src_ring;
1630*4882a593Smuzhiyun }
1631*4882a593Smuzhiyun
1632*4882a593Smuzhiyun static struct ath10k_ce_ring *
ath10k_ce_alloc_dest_ring(struct ath10k * ar,unsigned int ce_id,const struct ce_attr * attr)1633*4882a593Smuzhiyun ath10k_ce_alloc_dest_ring(struct ath10k *ar, unsigned int ce_id,
1634*4882a593Smuzhiyun const struct ce_attr *attr)
1635*4882a593Smuzhiyun {
1636*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring;
1637*4882a593Smuzhiyun u32 nentries;
1638*4882a593Smuzhiyun dma_addr_t base_addr;
1639*4882a593Smuzhiyun
1640*4882a593Smuzhiyun nentries = roundup_pow_of_two(attr->dest_nentries);
1641*4882a593Smuzhiyun
1642*4882a593Smuzhiyun dest_ring = kzalloc(struct_size(dest_ring, per_transfer_context,
1643*4882a593Smuzhiyun nentries), GFP_KERNEL);
1644*4882a593Smuzhiyun if (dest_ring == NULL)
1645*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1646*4882a593Smuzhiyun
1647*4882a593Smuzhiyun dest_ring->nentries = nentries;
1648*4882a593Smuzhiyun dest_ring->nentries_mask = nentries - 1;
1649*4882a593Smuzhiyun
1650*4882a593Smuzhiyun /*
1651*4882a593Smuzhiyun * Legacy platforms that do not support cache
1652*4882a593Smuzhiyun * coherent DMA are unsupported
1653*4882a593Smuzhiyun */
1654*4882a593Smuzhiyun dest_ring->base_addr_owner_space_unaligned =
1655*4882a593Smuzhiyun dma_alloc_coherent(ar->dev,
1656*4882a593Smuzhiyun (nentries * sizeof(struct ce_desc) +
1657*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1658*4882a593Smuzhiyun &base_addr, GFP_KERNEL);
1659*4882a593Smuzhiyun if (!dest_ring->base_addr_owner_space_unaligned) {
1660*4882a593Smuzhiyun kfree(dest_ring);
1661*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1662*4882a593Smuzhiyun }
1663*4882a593Smuzhiyun
1664*4882a593Smuzhiyun dest_ring->base_addr_ce_space_unaligned = base_addr;
1665*4882a593Smuzhiyun
1666*4882a593Smuzhiyun dest_ring->base_addr_owner_space =
1667*4882a593Smuzhiyun PTR_ALIGN(dest_ring->base_addr_owner_space_unaligned,
1668*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1669*4882a593Smuzhiyun dest_ring->base_addr_ce_space =
1670*4882a593Smuzhiyun ALIGN(dest_ring->base_addr_ce_space_unaligned,
1671*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1672*4882a593Smuzhiyun
1673*4882a593Smuzhiyun return dest_ring;
1674*4882a593Smuzhiyun }
1675*4882a593Smuzhiyun
1676*4882a593Smuzhiyun static struct ath10k_ce_ring *
ath10k_ce_alloc_dest_ring_64(struct ath10k * ar,unsigned int ce_id,const struct ce_attr * attr)1677*4882a593Smuzhiyun ath10k_ce_alloc_dest_ring_64(struct ath10k *ar, unsigned int ce_id,
1678*4882a593Smuzhiyun const struct ce_attr *attr)
1679*4882a593Smuzhiyun {
1680*4882a593Smuzhiyun struct ath10k_ce_ring *dest_ring;
1681*4882a593Smuzhiyun u32 nentries;
1682*4882a593Smuzhiyun dma_addr_t base_addr;
1683*4882a593Smuzhiyun
1684*4882a593Smuzhiyun nentries = roundup_pow_of_two(attr->dest_nentries);
1685*4882a593Smuzhiyun
1686*4882a593Smuzhiyun dest_ring = kzalloc(struct_size(dest_ring, per_transfer_context,
1687*4882a593Smuzhiyun nentries), GFP_KERNEL);
1688*4882a593Smuzhiyun if (!dest_ring)
1689*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1690*4882a593Smuzhiyun
1691*4882a593Smuzhiyun dest_ring->nentries = nentries;
1692*4882a593Smuzhiyun dest_ring->nentries_mask = nentries - 1;
1693*4882a593Smuzhiyun
1694*4882a593Smuzhiyun /* Legacy platforms that do not support cache
1695*4882a593Smuzhiyun * coherent DMA are unsupported
1696*4882a593Smuzhiyun */
1697*4882a593Smuzhiyun dest_ring->base_addr_owner_space_unaligned =
1698*4882a593Smuzhiyun dma_alloc_coherent(ar->dev,
1699*4882a593Smuzhiyun (nentries * sizeof(struct ce_desc_64) +
1700*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1701*4882a593Smuzhiyun &base_addr, GFP_KERNEL);
1702*4882a593Smuzhiyun if (!dest_ring->base_addr_owner_space_unaligned) {
1703*4882a593Smuzhiyun kfree(dest_ring);
1704*4882a593Smuzhiyun return ERR_PTR(-ENOMEM);
1705*4882a593Smuzhiyun }
1706*4882a593Smuzhiyun
1707*4882a593Smuzhiyun dest_ring->base_addr_ce_space_unaligned = base_addr;
1708*4882a593Smuzhiyun
1709*4882a593Smuzhiyun /* Correctly initialize memory to 0 to prevent garbage
1710*4882a593Smuzhiyun * data crashing system when download firmware
1711*4882a593Smuzhiyun */
1712*4882a593Smuzhiyun dest_ring->base_addr_owner_space =
1713*4882a593Smuzhiyun PTR_ALIGN(dest_ring->base_addr_owner_space_unaligned,
1714*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1715*4882a593Smuzhiyun dest_ring->base_addr_ce_space =
1716*4882a593Smuzhiyun ALIGN(dest_ring->base_addr_ce_space_unaligned,
1717*4882a593Smuzhiyun CE_DESC_RING_ALIGN);
1718*4882a593Smuzhiyun
1719*4882a593Smuzhiyun return dest_ring;
1720*4882a593Smuzhiyun }
1721*4882a593Smuzhiyun
1722*4882a593Smuzhiyun /*
1723*4882a593Smuzhiyun * Initialize a Copy Engine based on caller-supplied attributes.
1724*4882a593Smuzhiyun * This may be called once to initialize both source and destination
1725*4882a593Smuzhiyun * rings or it may be called twice for separate source and destination
1726*4882a593Smuzhiyun * initialization. It may be that only one side or the other is
1727*4882a593Smuzhiyun * initialized by software/firmware.
1728*4882a593Smuzhiyun */
ath10k_ce_init_pipe(struct ath10k * ar,unsigned int ce_id,const struct ce_attr * attr)1729*4882a593Smuzhiyun int ath10k_ce_init_pipe(struct ath10k *ar, unsigned int ce_id,
1730*4882a593Smuzhiyun const struct ce_attr *attr)
1731*4882a593Smuzhiyun {
1732*4882a593Smuzhiyun int ret;
1733*4882a593Smuzhiyun
1734*4882a593Smuzhiyun if (attr->src_nentries) {
1735*4882a593Smuzhiyun ret = ath10k_ce_init_src_ring(ar, ce_id, attr);
1736*4882a593Smuzhiyun if (ret) {
1737*4882a593Smuzhiyun ath10k_err(ar, "Failed to initialize CE src ring for ID: %d (%d)\n",
1738*4882a593Smuzhiyun ce_id, ret);
1739*4882a593Smuzhiyun return ret;
1740*4882a593Smuzhiyun }
1741*4882a593Smuzhiyun }
1742*4882a593Smuzhiyun
1743*4882a593Smuzhiyun if (attr->dest_nentries) {
1744*4882a593Smuzhiyun ret = ath10k_ce_init_dest_ring(ar, ce_id, attr);
1745*4882a593Smuzhiyun if (ret) {
1746*4882a593Smuzhiyun ath10k_err(ar, "Failed to initialize CE dest ring for ID: %d (%d)\n",
1747*4882a593Smuzhiyun ce_id, ret);
1748*4882a593Smuzhiyun return ret;
1749*4882a593Smuzhiyun }
1750*4882a593Smuzhiyun }
1751*4882a593Smuzhiyun
1752*4882a593Smuzhiyun return 0;
1753*4882a593Smuzhiyun }
1754*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_init_pipe);
1755*4882a593Smuzhiyun
ath10k_ce_deinit_src_ring(struct ath10k * ar,unsigned int ce_id)1756*4882a593Smuzhiyun static void ath10k_ce_deinit_src_ring(struct ath10k *ar, unsigned int ce_id)
1757*4882a593Smuzhiyun {
1758*4882a593Smuzhiyun u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
1759*4882a593Smuzhiyun
1760*4882a593Smuzhiyun ath10k_ce_src_ring_base_addr_set(ar, ce_id, 0);
1761*4882a593Smuzhiyun ath10k_ce_src_ring_size_set(ar, ctrl_addr, 0);
1762*4882a593Smuzhiyun ath10k_ce_src_ring_dmax_set(ar, ctrl_addr, 0);
1763*4882a593Smuzhiyun ath10k_ce_src_ring_highmark_set(ar, ctrl_addr, 0);
1764*4882a593Smuzhiyun }
1765*4882a593Smuzhiyun
ath10k_ce_deinit_dest_ring(struct ath10k * ar,unsigned int ce_id)1766*4882a593Smuzhiyun static void ath10k_ce_deinit_dest_ring(struct ath10k *ar, unsigned int ce_id)
1767*4882a593Smuzhiyun {
1768*4882a593Smuzhiyun u32 ctrl_addr = ath10k_ce_base_address(ar, ce_id);
1769*4882a593Smuzhiyun
1770*4882a593Smuzhiyun ath10k_ce_dest_ring_base_addr_set(ar, ce_id, 0);
1771*4882a593Smuzhiyun ath10k_ce_dest_ring_size_set(ar, ctrl_addr, 0);
1772*4882a593Smuzhiyun ath10k_ce_dest_ring_highmark_set(ar, ctrl_addr, 0);
1773*4882a593Smuzhiyun }
1774*4882a593Smuzhiyun
ath10k_ce_deinit_pipe(struct ath10k * ar,unsigned int ce_id)1775*4882a593Smuzhiyun void ath10k_ce_deinit_pipe(struct ath10k *ar, unsigned int ce_id)
1776*4882a593Smuzhiyun {
1777*4882a593Smuzhiyun ath10k_ce_deinit_src_ring(ar, ce_id);
1778*4882a593Smuzhiyun ath10k_ce_deinit_dest_ring(ar, ce_id);
1779*4882a593Smuzhiyun }
1780*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_deinit_pipe);
1781*4882a593Smuzhiyun
_ath10k_ce_free_pipe(struct ath10k * ar,int ce_id)1782*4882a593Smuzhiyun static void _ath10k_ce_free_pipe(struct ath10k *ar, int ce_id)
1783*4882a593Smuzhiyun {
1784*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1785*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
1786*4882a593Smuzhiyun
1787*4882a593Smuzhiyun if (ce_state->src_ring) {
1788*4882a593Smuzhiyun if (ar->hw_params.shadow_reg_support)
1789*4882a593Smuzhiyun kfree(ce_state->src_ring->shadow_base_unaligned);
1790*4882a593Smuzhiyun dma_free_coherent(ar->dev,
1791*4882a593Smuzhiyun (ce_state->src_ring->nentries *
1792*4882a593Smuzhiyun sizeof(struct ce_desc) +
1793*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1794*4882a593Smuzhiyun ce_state->src_ring->base_addr_owner_space,
1795*4882a593Smuzhiyun ce_state->src_ring->base_addr_ce_space);
1796*4882a593Smuzhiyun kfree(ce_state->src_ring);
1797*4882a593Smuzhiyun }
1798*4882a593Smuzhiyun
1799*4882a593Smuzhiyun if (ce_state->dest_ring) {
1800*4882a593Smuzhiyun dma_free_coherent(ar->dev,
1801*4882a593Smuzhiyun (ce_state->dest_ring->nentries *
1802*4882a593Smuzhiyun sizeof(struct ce_desc) +
1803*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1804*4882a593Smuzhiyun ce_state->dest_ring->base_addr_owner_space,
1805*4882a593Smuzhiyun ce_state->dest_ring->base_addr_ce_space);
1806*4882a593Smuzhiyun kfree(ce_state->dest_ring);
1807*4882a593Smuzhiyun }
1808*4882a593Smuzhiyun
1809*4882a593Smuzhiyun ce_state->src_ring = NULL;
1810*4882a593Smuzhiyun ce_state->dest_ring = NULL;
1811*4882a593Smuzhiyun }
1812*4882a593Smuzhiyun
_ath10k_ce_free_pipe_64(struct ath10k * ar,int ce_id)1813*4882a593Smuzhiyun static void _ath10k_ce_free_pipe_64(struct ath10k *ar, int ce_id)
1814*4882a593Smuzhiyun {
1815*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1816*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
1817*4882a593Smuzhiyun
1818*4882a593Smuzhiyun if (ce_state->src_ring) {
1819*4882a593Smuzhiyun if (ar->hw_params.shadow_reg_support)
1820*4882a593Smuzhiyun kfree(ce_state->src_ring->shadow_base_unaligned);
1821*4882a593Smuzhiyun dma_free_coherent(ar->dev,
1822*4882a593Smuzhiyun (ce_state->src_ring->nentries *
1823*4882a593Smuzhiyun sizeof(struct ce_desc_64) +
1824*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1825*4882a593Smuzhiyun ce_state->src_ring->base_addr_owner_space,
1826*4882a593Smuzhiyun ce_state->src_ring->base_addr_ce_space);
1827*4882a593Smuzhiyun kfree(ce_state->src_ring);
1828*4882a593Smuzhiyun }
1829*4882a593Smuzhiyun
1830*4882a593Smuzhiyun if (ce_state->dest_ring) {
1831*4882a593Smuzhiyun dma_free_coherent(ar->dev,
1832*4882a593Smuzhiyun (ce_state->dest_ring->nentries *
1833*4882a593Smuzhiyun sizeof(struct ce_desc_64) +
1834*4882a593Smuzhiyun CE_DESC_RING_ALIGN),
1835*4882a593Smuzhiyun ce_state->dest_ring->base_addr_owner_space,
1836*4882a593Smuzhiyun ce_state->dest_ring->base_addr_ce_space);
1837*4882a593Smuzhiyun kfree(ce_state->dest_ring);
1838*4882a593Smuzhiyun }
1839*4882a593Smuzhiyun
1840*4882a593Smuzhiyun ce_state->src_ring = NULL;
1841*4882a593Smuzhiyun ce_state->dest_ring = NULL;
1842*4882a593Smuzhiyun }
1843*4882a593Smuzhiyun
ath10k_ce_free_pipe(struct ath10k * ar,int ce_id)1844*4882a593Smuzhiyun void ath10k_ce_free_pipe(struct ath10k *ar, int ce_id)
1845*4882a593Smuzhiyun {
1846*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1847*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
1848*4882a593Smuzhiyun
1849*4882a593Smuzhiyun ce_state->ops->ce_free_pipe(ar, ce_id);
1850*4882a593Smuzhiyun }
1851*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_free_pipe);
1852*4882a593Smuzhiyun
ath10k_ce_dump_registers(struct ath10k * ar,struct ath10k_fw_crash_data * crash_data)1853*4882a593Smuzhiyun void ath10k_ce_dump_registers(struct ath10k *ar,
1854*4882a593Smuzhiyun struct ath10k_fw_crash_data *crash_data)
1855*4882a593Smuzhiyun {
1856*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1857*4882a593Smuzhiyun struct ath10k_ce_crash_data ce_data;
1858*4882a593Smuzhiyun u32 addr, id;
1859*4882a593Smuzhiyun
1860*4882a593Smuzhiyun lockdep_assert_held(&ar->dump_mutex);
1861*4882a593Smuzhiyun
1862*4882a593Smuzhiyun ath10k_err(ar, "Copy Engine register dump:\n");
1863*4882a593Smuzhiyun
1864*4882a593Smuzhiyun spin_lock_bh(&ce->ce_lock);
1865*4882a593Smuzhiyun for (id = 0; id < CE_COUNT; id++) {
1866*4882a593Smuzhiyun addr = ath10k_ce_base_address(ar, id);
1867*4882a593Smuzhiyun ce_data.base_addr = cpu_to_le32(addr);
1868*4882a593Smuzhiyun
1869*4882a593Smuzhiyun ce_data.src_wr_idx =
1870*4882a593Smuzhiyun cpu_to_le32(ath10k_ce_src_ring_write_index_get(ar, addr));
1871*4882a593Smuzhiyun ce_data.src_r_idx =
1872*4882a593Smuzhiyun cpu_to_le32(ath10k_ce_src_ring_read_index_get(ar, addr));
1873*4882a593Smuzhiyun ce_data.dst_wr_idx =
1874*4882a593Smuzhiyun cpu_to_le32(ath10k_ce_dest_ring_write_index_get(ar, addr));
1875*4882a593Smuzhiyun ce_data.dst_r_idx =
1876*4882a593Smuzhiyun cpu_to_le32(ath10k_ce_dest_ring_read_index_get(ar, addr));
1877*4882a593Smuzhiyun
1878*4882a593Smuzhiyun if (crash_data)
1879*4882a593Smuzhiyun crash_data->ce_crash_data[id] = ce_data;
1880*4882a593Smuzhiyun
1881*4882a593Smuzhiyun ath10k_err(ar, "[%02d]: 0x%08x %3u %3u %3u %3u", id,
1882*4882a593Smuzhiyun le32_to_cpu(ce_data.base_addr),
1883*4882a593Smuzhiyun le32_to_cpu(ce_data.src_wr_idx),
1884*4882a593Smuzhiyun le32_to_cpu(ce_data.src_r_idx),
1885*4882a593Smuzhiyun le32_to_cpu(ce_data.dst_wr_idx),
1886*4882a593Smuzhiyun le32_to_cpu(ce_data.dst_r_idx));
1887*4882a593Smuzhiyun }
1888*4882a593Smuzhiyun
1889*4882a593Smuzhiyun spin_unlock_bh(&ce->ce_lock);
1890*4882a593Smuzhiyun }
1891*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_dump_registers);
1892*4882a593Smuzhiyun
1893*4882a593Smuzhiyun static const struct ath10k_ce_ops ce_ops = {
1894*4882a593Smuzhiyun .ce_alloc_src_ring = ath10k_ce_alloc_src_ring,
1895*4882a593Smuzhiyun .ce_alloc_dst_ring = ath10k_ce_alloc_dest_ring,
1896*4882a593Smuzhiyun .ce_rx_post_buf = __ath10k_ce_rx_post_buf,
1897*4882a593Smuzhiyun .ce_completed_recv_next_nolock = _ath10k_ce_completed_recv_next_nolock,
1898*4882a593Smuzhiyun .ce_revoke_recv_next = _ath10k_ce_revoke_recv_next,
1899*4882a593Smuzhiyun .ce_extract_desc_data = ath10k_ce_extract_desc_data,
1900*4882a593Smuzhiyun .ce_free_pipe = _ath10k_ce_free_pipe,
1901*4882a593Smuzhiyun .ce_send_nolock = _ath10k_ce_send_nolock,
1902*4882a593Smuzhiyun .ce_set_src_ring_base_addr_hi = NULL,
1903*4882a593Smuzhiyun .ce_set_dest_ring_base_addr_hi = NULL,
1904*4882a593Smuzhiyun .ce_completed_send_next_nolock = _ath10k_ce_completed_send_next_nolock,
1905*4882a593Smuzhiyun };
1906*4882a593Smuzhiyun
1907*4882a593Smuzhiyun static const struct ath10k_ce_ops ce_64_ops = {
1908*4882a593Smuzhiyun .ce_alloc_src_ring = ath10k_ce_alloc_src_ring_64,
1909*4882a593Smuzhiyun .ce_alloc_dst_ring = ath10k_ce_alloc_dest_ring_64,
1910*4882a593Smuzhiyun .ce_rx_post_buf = __ath10k_ce_rx_post_buf_64,
1911*4882a593Smuzhiyun .ce_completed_recv_next_nolock =
1912*4882a593Smuzhiyun _ath10k_ce_completed_recv_next_nolock_64,
1913*4882a593Smuzhiyun .ce_revoke_recv_next = _ath10k_ce_revoke_recv_next_64,
1914*4882a593Smuzhiyun .ce_extract_desc_data = ath10k_ce_extract_desc_data_64,
1915*4882a593Smuzhiyun .ce_free_pipe = _ath10k_ce_free_pipe_64,
1916*4882a593Smuzhiyun .ce_send_nolock = _ath10k_ce_send_nolock_64,
1917*4882a593Smuzhiyun .ce_set_src_ring_base_addr_hi = ath10k_ce_set_src_ring_base_addr_hi,
1918*4882a593Smuzhiyun .ce_set_dest_ring_base_addr_hi = ath10k_ce_set_dest_ring_base_addr_hi,
1919*4882a593Smuzhiyun .ce_completed_send_next_nolock = _ath10k_ce_completed_send_next_nolock_64,
1920*4882a593Smuzhiyun };
1921*4882a593Smuzhiyun
ath10k_ce_set_ops(struct ath10k * ar,struct ath10k_ce_pipe * ce_state)1922*4882a593Smuzhiyun static void ath10k_ce_set_ops(struct ath10k *ar,
1923*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state)
1924*4882a593Smuzhiyun {
1925*4882a593Smuzhiyun switch (ar->hw_rev) {
1926*4882a593Smuzhiyun case ATH10K_HW_WCN3990:
1927*4882a593Smuzhiyun ce_state->ops = &ce_64_ops;
1928*4882a593Smuzhiyun break;
1929*4882a593Smuzhiyun default:
1930*4882a593Smuzhiyun ce_state->ops = &ce_ops;
1931*4882a593Smuzhiyun break;
1932*4882a593Smuzhiyun }
1933*4882a593Smuzhiyun }
1934*4882a593Smuzhiyun
ath10k_ce_alloc_pipe(struct ath10k * ar,int ce_id,const struct ce_attr * attr)1935*4882a593Smuzhiyun int ath10k_ce_alloc_pipe(struct ath10k *ar, int ce_id,
1936*4882a593Smuzhiyun const struct ce_attr *attr)
1937*4882a593Smuzhiyun {
1938*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
1939*4882a593Smuzhiyun struct ath10k_ce_pipe *ce_state = &ce->ce_states[ce_id];
1940*4882a593Smuzhiyun int ret;
1941*4882a593Smuzhiyun
1942*4882a593Smuzhiyun ath10k_ce_set_ops(ar, ce_state);
1943*4882a593Smuzhiyun /* Make sure there's enough CE ringbuffer entries for HTT TX to avoid
1944*4882a593Smuzhiyun * additional TX locking checks.
1945*4882a593Smuzhiyun *
1946*4882a593Smuzhiyun * For the lack of a better place do the check here.
1947*4882a593Smuzhiyun */
1948*4882a593Smuzhiyun BUILD_BUG_ON(2 * TARGET_NUM_MSDU_DESC >
1949*4882a593Smuzhiyun (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1950*4882a593Smuzhiyun BUILD_BUG_ON(2 * TARGET_10_4_NUM_MSDU_DESC_PFC >
1951*4882a593Smuzhiyun (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1952*4882a593Smuzhiyun BUILD_BUG_ON(2 * TARGET_TLV_NUM_MSDU_DESC >
1953*4882a593Smuzhiyun (CE_HTT_H2T_MSG_SRC_NENTRIES - 1));
1954*4882a593Smuzhiyun
1955*4882a593Smuzhiyun ce_state->ar = ar;
1956*4882a593Smuzhiyun ce_state->id = ce_id;
1957*4882a593Smuzhiyun ce_state->ctrl_addr = ath10k_ce_base_address(ar, ce_id);
1958*4882a593Smuzhiyun ce_state->attr_flags = attr->flags;
1959*4882a593Smuzhiyun ce_state->src_sz_max = attr->src_sz_max;
1960*4882a593Smuzhiyun
1961*4882a593Smuzhiyun if (attr->src_nentries)
1962*4882a593Smuzhiyun ce_state->send_cb = attr->send_cb;
1963*4882a593Smuzhiyun
1964*4882a593Smuzhiyun if (attr->dest_nentries)
1965*4882a593Smuzhiyun ce_state->recv_cb = attr->recv_cb;
1966*4882a593Smuzhiyun
1967*4882a593Smuzhiyun if (attr->src_nentries) {
1968*4882a593Smuzhiyun ce_state->src_ring =
1969*4882a593Smuzhiyun ce_state->ops->ce_alloc_src_ring(ar, ce_id, attr);
1970*4882a593Smuzhiyun if (IS_ERR(ce_state->src_ring)) {
1971*4882a593Smuzhiyun ret = PTR_ERR(ce_state->src_ring);
1972*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc CE src ring %d: %d\n",
1973*4882a593Smuzhiyun ce_id, ret);
1974*4882a593Smuzhiyun ce_state->src_ring = NULL;
1975*4882a593Smuzhiyun return ret;
1976*4882a593Smuzhiyun }
1977*4882a593Smuzhiyun }
1978*4882a593Smuzhiyun
1979*4882a593Smuzhiyun if (attr->dest_nentries) {
1980*4882a593Smuzhiyun ce_state->dest_ring = ce_state->ops->ce_alloc_dst_ring(ar,
1981*4882a593Smuzhiyun ce_id,
1982*4882a593Smuzhiyun attr);
1983*4882a593Smuzhiyun if (IS_ERR(ce_state->dest_ring)) {
1984*4882a593Smuzhiyun ret = PTR_ERR(ce_state->dest_ring);
1985*4882a593Smuzhiyun ath10k_err(ar, "failed to alloc CE dest ring %d: %d\n",
1986*4882a593Smuzhiyun ce_id, ret);
1987*4882a593Smuzhiyun ce_state->dest_ring = NULL;
1988*4882a593Smuzhiyun return ret;
1989*4882a593Smuzhiyun }
1990*4882a593Smuzhiyun }
1991*4882a593Smuzhiyun
1992*4882a593Smuzhiyun return 0;
1993*4882a593Smuzhiyun }
1994*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_alloc_pipe);
1995*4882a593Smuzhiyun
ath10k_ce_alloc_rri(struct ath10k * ar)1996*4882a593Smuzhiyun void ath10k_ce_alloc_rri(struct ath10k *ar)
1997*4882a593Smuzhiyun {
1998*4882a593Smuzhiyun int i;
1999*4882a593Smuzhiyun u32 value;
2000*4882a593Smuzhiyun u32 ctrl1_regs;
2001*4882a593Smuzhiyun u32 ce_base_addr;
2002*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
2003*4882a593Smuzhiyun
2004*4882a593Smuzhiyun ce->vaddr_rri = dma_alloc_coherent(ar->dev,
2005*4882a593Smuzhiyun (CE_COUNT * sizeof(u32)),
2006*4882a593Smuzhiyun &ce->paddr_rri, GFP_KERNEL);
2007*4882a593Smuzhiyun
2008*4882a593Smuzhiyun if (!ce->vaddr_rri)
2009*4882a593Smuzhiyun return;
2010*4882a593Smuzhiyun
2011*4882a593Smuzhiyun ath10k_ce_write32(ar, ar->hw_ce_regs->ce_rri_low,
2012*4882a593Smuzhiyun lower_32_bits(ce->paddr_rri));
2013*4882a593Smuzhiyun ath10k_ce_write32(ar, ar->hw_ce_regs->ce_rri_high,
2014*4882a593Smuzhiyun (upper_32_bits(ce->paddr_rri) &
2015*4882a593Smuzhiyun CE_DESC_ADDR_HI_MASK));
2016*4882a593Smuzhiyun
2017*4882a593Smuzhiyun for (i = 0; i < CE_COUNT; i++) {
2018*4882a593Smuzhiyun ctrl1_regs = ar->hw_ce_regs->ctrl1_regs->addr;
2019*4882a593Smuzhiyun ce_base_addr = ath10k_ce_base_address(ar, i);
2020*4882a593Smuzhiyun value = ath10k_ce_read32(ar, ce_base_addr + ctrl1_regs);
2021*4882a593Smuzhiyun value |= ar->hw_ce_regs->upd->mask;
2022*4882a593Smuzhiyun ath10k_ce_write32(ar, ce_base_addr + ctrl1_regs, value);
2023*4882a593Smuzhiyun }
2024*4882a593Smuzhiyun }
2025*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_alloc_rri);
2026*4882a593Smuzhiyun
ath10k_ce_free_rri(struct ath10k * ar)2027*4882a593Smuzhiyun void ath10k_ce_free_rri(struct ath10k *ar)
2028*4882a593Smuzhiyun {
2029*4882a593Smuzhiyun struct ath10k_ce *ce = ath10k_ce_priv(ar);
2030*4882a593Smuzhiyun
2031*4882a593Smuzhiyun dma_free_coherent(ar->dev, (CE_COUNT * sizeof(u32)),
2032*4882a593Smuzhiyun ce->vaddr_rri,
2033*4882a593Smuzhiyun ce->paddr_rri);
2034*4882a593Smuzhiyun }
2035*4882a593Smuzhiyun EXPORT_SYMBOL(ath10k_ce_free_rri);
2036