xref: /wlan-driver/qca-wifi-host-cmn/hif/src/ce/ce_main.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2013-2021 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name  * above copyright notice and this permission notice appear in all
8*5113495bSYour Name  * copies.
9*5113495bSYour Name  *
10*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name  */
19*5113495bSYour Name 
20*5113495bSYour Name #include "targcfg.h"
21*5113495bSYour Name #include "qdf_lock.h"
22*5113495bSYour Name #include "qdf_status.h"
23*5113495bSYour Name #include "qdf_status.h"
24*5113495bSYour Name #include <qdf_atomic.h>         /* qdf_atomic_read */
25*5113495bSYour Name #include <targaddrs.h>
26*5113495bSYour Name #include "hif_io32.h"
27*5113495bSYour Name #include <hif.h>
28*5113495bSYour Name #include <target_type.h>
29*5113495bSYour Name #include "regtable.h"
30*5113495bSYour Name #define ATH_MODULE_NAME hif
31*5113495bSYour Name #include <a_debug.h>
32*5113495bSYour Name #include "hif_main.h"
33*5113495bSYour Name #include "ce_api.h"
34*5113495bSYour Name #include "qdf_trace.h"
35*5113495bSYour Name #include "pld_common.h"
36*5113495bSYour Name #include "hif_debug.h"
37*5113495bSYour Name #include "ce_internal.h"
38*5113495bSYour Name #include "ce_reg.h"
39*5113495bSYour Name #include "ce_assignment.h"
40*5113495bSYour Name #include "ce_tasklet.h"
41*5113495bSYour Name #include "qdf_module.h"
42*5113495bSYour Name #include "qdf_ssr_driver_dump.h"
43*5113495bSYour Name #include <wbuff.h>
44*5113495bSYour Name 
45*5113495bSYour Name #define CE_POLL_TIMEOUT 10      /* ms */
46*5113495bSYour Name 
47*5113495bSYour Name #define AGC_DUMP         1
48*5113495bSYour Name #define CHANINFO_DUMP    2
49*5113495bSYour Name #define BB_WATCHDOG_DUMP 3
50*5113495bSYour Name #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
51*5113495bSYour Name #define PCIE_ACCESS_DUMP 4
52*5113495bSYour Name #endif
53*5113495bSYour Name #include "mp_dev.h"
54*5113495bSYour Name #ifdef HIF_CE_LOG_INFO
55*5113495bSYour Name #include "qdf_hang_event_notifier.h"
56*5113495bSYour Name #endif
57*5113495bSYour Name 
58*5113495bSYour Name #if (defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6290) || \
59*5113495bSYour Name 	defined(QCA_WIFI_QCA6018) || defined(QCA_WIFI_QCA5018) || \
60*5113495bSYour Name 	defined(QCA_WIFI_KIWI) || defined(QCA_WIFI_QCA5332) || \
61*5113495bSYour Name 	defined(QCA_WIFI_QCA9574)) && !defined(QCA_WIFI_SUPPORT_SRNG) && \
62*5113495bSYour Name 	!defined(QCA_WIFI_WCN6450)
63*5113495bSYour Name #define QCA_WIFI_SUPPORT_SRNG
64*5113495bSYour Name #endif
65*5113495bSYour Name 
66*5113495bSYour Name #ifdef QCA_WIFI_SUPPORT_SRNG
67*5113495bSYour Name #include <hal_api.h>
68*5113495bSYour Name #endif
69*5113495bSYour Name #include "qdf_ssr_driver_dump.h"
70*5113495bSYour Name 
71*5113495bSYour Name /* Forward references */
72*5113495bSYour Name QDF_STATUS hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info);
73*5113495bSYour Name 
74*5113495bSYour Name /*
75*5113495bSYour Name  * Fix EV118783, poll to check whether a BMI response comes
76*5113495bSYour Name  * other than waiting for the interruption which may be lost.
77*5113495bSYour Name  */
78*5113495bSYour Name /* #define BMI_RSP_POLLING */
79*5113495bSYour Name #define BMI_RSP_TO_MILLISEC  1000
80*5113495bSYour Name 
81*5113495bSYour Name #ifdef CONFIG_BYPASS_QMI
82*5113495bSYour Name #define BYPASS_QMI 1
83*5113495bSYour Name #else
84*5113495bSYour Name #define BYPASS_QMI 0
85*5113495bSYour Name #endif
86*5113495bSYour Name 
87*5113495bSYour Name static void hif_config_rri_on_ddr(struct hif_softc *scn);
88*5113495bSYour Name 
89*5113495bSYour Name /**
90*5113495bSYour Name  * hif_target_access_log_dump() - dump access log
91*5113495bSYour Name  *
92*5113495bSYour Name  * dump access log
93*5113495bSYour Name  *
94*5113495bSYour Name  * Return: n/a
95*5113495bSYour Name  */
96*5113495bSYour Name #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
hif_target_access_log_dump(void)97*5113495bSYour Name static void hif_target_access_log_dump(void)
98*5113495bSYour Name {
99*5113495bSYour Name 	hif_target_dump_access_log();
100*5113495bSYour Name }
101*5113495bSYour Name #endif
102*5113495bSYour Name 
103*5113495bSYour Name /*
104*5113495bSYour Name  * This structure contains the interrupt index for each Copy engine
105*5113495bSYour Name  * for various number of MSIs available in the system.
106*5113495bSYour Name  */
107*5113495bSYour Name static struct ce_int_assignment ce_int_context[NUM_CE_CONTEXT] = {
108*5113495bSYour Name 	/* Default configuration */
109*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
110*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
111*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
112*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
113*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
114*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
115*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
116*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
117*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
118*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
119*5113495bSYour Name 	  CE_INTERRUPT_IDX(10),
120*5113495bSYour Name 	  CE_INTERRUPT_IDX(11),
121*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
122*5113495bSYour Name 	  CE_INTERRUPT_IDX(12),
123*5113495bSYour Name 	  CE_INTERRUPT_IDX(13),
124*5113495bSYour Name 	  CE_INTERRUPT_IDX(14),
125*5113495bSYour Name 	  CE_INTERRUPT_IDX(15),
126*5113495bSYour Name #endif
127*5113495bSYour Name 	} },
128*5113495bSYour Name 	/* Interrupt assignment for 1 MSI combination */
129*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
130*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
131*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
132*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
133*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
134*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
135*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
136*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
137*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
138*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
139*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
140*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
141*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
142*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
143*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
144*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
145*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
146*5113495bSYour Name #endif
147*5113495bSYour Name 	} },
148*5113495bSYour Name 	/* Interrupt assignment for 2 MSI combination */
149*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
150*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
151*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
152*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
153*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
154*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
155*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
156*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
157*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
158*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
159*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
160*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
161*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
162*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
163*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
164*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
165*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
166*5113495bSYour Name #endif
167*5113495bSYour Name 	} },
168*5113495bSYour Name 	/* Interrupt assignment for 3 MSI combination */
169*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
170*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
171*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
172*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
173*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
174*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
175*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
176*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
177*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
178*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
179*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
180*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
181*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
182*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
183*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
184*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
185*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
186*5113495bSYour Name #endif
187*5113495bSYour Name 	} },
188*5113495bSYour Name 	/* Interrupt assignment for 4 MSI combination */
189*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
190*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
191*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
192*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
193*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
194*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
195*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
196*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
197*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
198*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
199*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
200*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
201*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
202*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
203*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
204*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
205*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
206*5113495bSYour Name #endif
207*5113495bSYour Name 	} },
208*5113495bSYour Name 	/* Interrupt assignment for 5 MSI combination */
209*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
210*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
211*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
212*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
213*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
214*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
215*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
216*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
217*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
218*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
219*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
220*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
221*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
222*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
223*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
224*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
225*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
226*5113495bSYour Name #endif
227*5113495bSYour Name 	} },
228*5113495bSYour Name 	/* Interrupt assignment for 6 MSI combination */
229*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
230*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
231*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
232*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
233*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
234*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
235*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
236*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
237*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
238*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
239*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
240*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
241*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
242*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
243*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
244*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
245*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
246*5113495bSYour Name #endif
247*5113495bSYour Name 	} },
248*5113495bSYour Name 	/* Interrupt assignment for 7 MSI combination */
249*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
250*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
251*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
252*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
253*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
254*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
255*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
256*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
257*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
258*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
259*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
260*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
261*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
262*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
263*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
264*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
265*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
266*5113495bSYour Name #endif
267*5113495bSYour Name 	} },
268*5113495bSYour Name 	/* Interrupt assignment for 8 MSI combination */
269*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
270*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
271*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
272*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
273*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
274*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
275*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
276*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
277*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
278*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
279*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
280*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
281*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
282*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
283*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
284*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
285*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
286*5113495bSYour Name #endif
287*5113495bSYour Name 	} },
288*5113495bSYour Name 	/* Interrupt assignment for 9 MSI combination */
289*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
290*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
291*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
292*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
293*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
294*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
295*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
296*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
297*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
298*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
299*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
300*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
301*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
302*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
303*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
304*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
305*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
306*5113495bSYour Name #endif
307*5113495bSYour Name 	} },
308*5113495bSYour Name 	/* Interrupt assignment for 10 MSI combination */
309*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
310*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
311*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
312*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
313*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
314*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
315*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
316*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
317*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
318*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
319*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
320*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
321*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
322*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
323*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
324*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
325*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
326*5113495bSYour Name #endif
327*5113495bSYour Name 	} },
328*5113495bSYour Name 	/* Interrupt assignment for 11 MSI combination */
329*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
330*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
331*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
332*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
333*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
334*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
335*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
336*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
337*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
338*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
339*5113495bSYour Name 	  CE_INTERRUPT_IDX(10),
340*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
341*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
342*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
343*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
344*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
345*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
346*5113495bSYour Name #endif
347*5113495bSYour Name 	} },
348*5113495bSYour Name 	/* Interrupt assignment for 12 MSI combination */
349*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
350*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
351*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
352*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
353*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
354*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
355*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
356*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
357*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
358*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
359*5113495bSYour Name 	  CE_INTERRUPT_IDX(10),
360*5113495bSYour Name 	  CE_INTERRUPT_IDX(11),
361*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
362*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
363*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
364*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
365*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
366*5113495bSYour Name #endif
367*5113495bSYour Name 	} },
368*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
369*5113495bSYour Name 	/* Interrupt assignment for 13 MSI combination */
370*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
371*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
372*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
373*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
374*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
375*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
376*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
377*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
378*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
379*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
380*5113495bSYour Name 	  CE_INTERRUPT_IDX(10),
381*5113495bSYour Name 	  CE_INTERRUPT_IDX(11),
382*5113495bSYour Name 	  CE_INTERRUPT_IDX(12),
383*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
384*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
385*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
386*5113495bSYour Name 	} },
387*5113495bSYour Name 	/* Interrupt assignment for 14 MSI combination */
388*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
389*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
390*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
391*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
392*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
393*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
394*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
395*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
396*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
397*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
398*5113495bSYour Name 	  CE_INTERRUPT_IDX(10),
399*5113495bSYour Name 	  CE_INTERRUPT_IDX(11),
400*5113495bSYour Name 	  CE_INTERRUPT_IDX(12),
401*5113495bSYour Name 	  CE_INTERRUPT_IDX(13),
402*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
403*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
404*5113495bSYour Name 	} },
405*5113495bSYour Name 	/* Interrupt assignment for 15 MSI combination */
406*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
407*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
408*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
409*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
410*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
411*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
412*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
413*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
414*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
415*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
416*5113495bSYour Name 	  CE_INTERRUPT_IDX(10),
417*5113495bSYour Name 	  CE_INTERRUPT_IDX(11),
418*5113495bSYour Name 	  CE_INTERRUPT_IDX(12),
419*5113495bSYour Name 	  CE_INTERRUPT_IDX(13),
420*5113495bSYour Name 	  CE_INTERRUPT_IDX(14),
421*5113495bSYour Name 	  CE_INTERRUPT_IDX(0),
422*5113495bSYour Name 	} },
423*5113495bSYour Name 	/* Interrupt assignment for 16 MSI combination */
424*5113495bSYour Name 	{{ CE_INTERRUPT_IDX(0),
425*5113495bSYour Name 	  CE_INTERRUPT_IDX(1),
426*5113495bSYour Name 	  CE_INTERRUPT_IDX(2),
427*5113495bSYour Name 	  CE_INTERRUPT_IDX(3),
428*5113495bSYour Name 	  CE_INTERRUPT_IDX(4),
429*5113495bSYour Name 	  CE_INTERRUPT_IDX(5),
430*5113495bSYour Name 	  CE_INTERRUPT_IDX(6),
431*5113495bSYour Name 	  CE_INTERRUPT_IDX(7),
432*5113495bSYour Name 	  CE_INTERRUPT_IDX(8),
433*5113495bSYour Name 	  CE_INTERRUPT_IDX(9),
434*5113495bSYour Name 	  CE_INTERRUPT_IDX(10),
435*5113495bSYour Name 	  CE_INTERRUPT_IDX(11),
436*5113495bSYour Name 	  CE_INTERRUPT_IDX(12),
437*5113495bSYour Name 	  CE_INTERRUPT_IDX(13),
438*5113495bSYour Name 	  CE_INTERRUPT_IDX(14),
439*5113495bSYour Name 	  CE_INTERRUPT_IDX(15),
440*5113495bSYour Name 	} },
441*5113495bSYour Name #endif
442*5113495bSYour Name };
443*5113495bSYour Name 
444*5113495bSYour Name 
hif_trigger_dump(struct hif_opaque_softc * hif_ctx,uint8_t cmd_id,bool start)445*5113495bSYour Name void hif_trigger_dump(struct hif_opaque_softc *hif_ctx,
446*5113495bSYour Name 		      uint8_t cmd_id, bool start)
447*5113495bSYour Name {
448*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
449*5113495bSYour Name 
450*5113495bSYour Name 	switch (cmd_id) {
451*5113495bSYour Name 	case AGC_DUMP:
452*5113495bSYour Name 		if (start)
453*5113495bSYour Name 			priv_start_agc(scn);
454*5113495bSYour Name 		else
455*5113495bSYour Name 			priv_dump_agc(scn);
456*5113495bSYour Name 		break;
457*5113495bSYour Name 	case CHANINFO_DUMP:
458*5113495bSYour Name 		if (start)
459*5113495bSYour Name 			priv_start_cap_chaninfo(scn);
460*5113495bSYour Name 		else
461*5113495bSYour Name 			priv_dump_chaninfo(scn);
462*5113495bSYour Name 		break;
463*5113495bSYour Name 	case BB_WATCHDOG_DUMP:
464*5113495bSYour Name 		priv_dump_bbwatchdog(scn);
465*5113495bSYour Name 		break;
466*5113495bSYour Name #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
467*5113495bSYour Name 	case PCIE_ACCESS_DUMP:
468*5113495bSYour Name 		hif_target_access_log_dump();
469*5113495bSYour Name 		break;
470*5113495bSYour Name #endif
471*5113495bSYour Name 	default:
472*5113495bSYour Name 		hif_err("Invalid htc dump command: %d", cmd_id);
473*5113495bSYour Name 		break;
474*5113495bSYour Name 	}
475*5113495bSYour Name }
476*5113495bSYour Name 
ce_poll_timeout(void * arg)477*5113495bSYour Name static void ce_poll_timeout(void *arg)
478*5113495bSYour Name {
479*5113495bSYour Name 	struct CE_state *CE_state = (struct CE_state *)arg;
480*5113495bSYour Name 
481*5113495bSYour Name 	if (CE_state->timer_inited) {
482*5113495bSYour Name 		ce_per_engine_service(CE_state->scn, CE_state->id);
483*5113495bSYour Name 		qdf_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT);
484*5113495bSYour Name 	}
485*5113495bSYour Name }
486*5113495bSYour Name 
roundup_pwr2(unsigned int n)487*5113495bSYour Name static unsigned int roundup_pwr2(unsigned int n)
488*5113495bSYour Name {
489*5113495bSYour Name 	int i;
490*5113495bSYour Name 	unsigned int test_pwr2;
491*5113495bSYour Name 
492*5113495bSYour Name 	if (!(n & (n - 1)))
493*5113495bSYour Name 		return n; /* already a power of 2 */
494*5113495bSYour Name 
495*5113495bSYour Name 	test_pwr2 = 4;
496*5113495bSYour Name 	for (i = 0; i < 29; i++) {
497*5113495bSYour Name 		if (test_pwr2 > n)
498*5113495bSYour Name 			return test_pwr2;
499*5113495bSYour Name 		test_pwr2 = test_pwr2 << 1;
500*5113495bSYour Name 	}
501*5113495bSYour Name 
502*5113495bSYour Name 	QDF_ASSERT(0); /* n too large */
503*5113495bSYour Name 	return 0;
504*5113495bSYour Name }
505*5113495bSYour Name 
506*5113495bSYour Name #define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C
507*5113495bSYour Name #define ADRASTEA_DST_WR_INDEX_OFFSET 0x40
508*5113495bSYour Name 
509*5113495bSYour Name static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = {
510*5113495bSYour Name 	{ 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
511*5113495bSYour Name 	{ 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
512*5113495bSYour Name 	{ 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
513*5113495bSYour Name 	{ 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
514*5113495bSYour Name 	{ 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
515*5113495bSYour Name 	{ 1, ADRASTEA_DST_WR_INDEX_OFFSET},
516*5113495bSYour Name 	{ 2, ADRASTEA_DST_WR_INDEX_OFFSET},
517*5113495bSYour Name 	{ 7, ADRASTEA_DST_WR_INDEX_OFFSET},
518*5113495bSYour Name 	{ 8, ADRASTEA_DST_WR_INDEX_OFFSET},
519*5113495bSYour Name #ifdef QCA_WIFI_3_0_ADRASTEA
520*5113495bSYour Name 	{ 9, ADRASTEA_DST_WR_INDEX_OFFSET},
521*5113495bSYour Name 	{ 10, ADRASTEA_DST_WR_INDEX_OFFSET},
522*5113495bSYour Name 	{ 11, ADRASTEA_DST_WR_INDEX_OFFSET},
523*5113495bSYour Name #endif
524*5113495bSYour Name };
525*5113495bSYour Name 
526*5113495bSYour Name #ifdef QCN7605_SUPPORT
527*5113495bSYour Name static struct shadow_reg_cfg target_shadow_reg_cfg_map_qcn7605[] = {
528*5113495bSYour Name 	{ 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
529*5113495bSYour Name 	{ 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
530*5113495bSYour Name 	{ 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
531*5113495bSYour Name 	{ 3, ADRASTEA_DST_WR_INDEX_OFFSET},
532*5113495bSYour Name 	{ 1, ADRASTEA_DST_WR_INDEX_OFFSET},
533*5113495bSYour Name 	{ 2, ADRASTEA_DST_WR_INDEX_OFFSET},
534*5113495bSYour Name 	{ 7, ADRASTEA_DST_WR_INDEX_OFFSET},
535*5113495bSYour Name 	{ 8, ADRASTEA_DST_WR_INDEX_OFFSET},
536*5113495bSYour Name };
537*5113495bSYour Name #endif
538*5113495bSYour Name 
539*5113495bSYour Name #ifdef WLAN_FEATURE_EPPING
540*5113495bSYour Name static struct shadow_reg_cfg target_shadow_reg_cfg_epping[] = {
541*5113495bSYour Name 	{ 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
542*5113495bSYour Name 	{ 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
543*5113495bSYour Name 	{ 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
544*5113495bSYour Name 	{ 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
545*5113495bSYour Name 	{ 1, ADRASTEA_DST_WR_INDEX_OFFSET},
546*5113495bSYour Name 	{ 2, ADRASTEA_DST_WR_INDEX_OFFSET},
547*5113495bSYour Name 	{ 5, ADRASTEA_DST_WR_INDEX_OFFSET},
548*5113495bSYour Name 	{ 7, ADRASTEA_DST_WR_INDEX_OFFSET},
549*5113495bSYour Name 	{ 8, ADRASTEA_DST_WR_INDEX_OFFSET},
550*5113495bSYour Name };
551*5113495bSYour Name #endif
552*5113495bSYour Name 
553*5113495bSYour Name /* CE_PCI TABLE */
554*5113495bSYour Name /*
555*5113495bSYour Name  * NOTE: the table below is out of date, though still a useful reference.
556*5113495bSYour Name  * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual
557*5113495bSYour Name  * mapping of HTC services to HIF pipes.
558*5113495bSYour Name  */
559*5113495bSYour Name /*
560*5113495bSYour Name  * This authoritative table defines Copy Engine configuration and the mapping
561*5113495bSYour Name  * of services/endpoints to CEs.  A subset of this information is passed to
562*5113495bSYour Name  * the Target during startup as a prerequisite to entering BMI phase.
563*5113495bSYour Name  * See:
564*5113495bSYour Name  *    target_service_to_ce_map - Target-side mapping
565*5113495bSYour Name  *    hif_map_service_to_pipe      - Host-side mapping
566*5113495bSYour Name  *    target_ce_config         - Target-side configuration
567*5113495bSYour Name  *    host_ce_config           - Host-side configuration
568*5113495bSYour Name    ============================================================================
569*5113495bSYour Name    Purpose    | Service / Endpoint   | CE   | Dire | Xfer     | Xfer
570*5113495bSYour Name  |                      |      | ctio | Size     | Frequency
571*5113495bSYour Name  |                      |      | n    |          |
572*5113495bSYour Name    ============================================================================
573*5113495bSYour Name    tx         | HTT_DATA (downlink)  | CE 0 | h->t | medium - | very frequent
574*5113495bSYour Name    descriptor |                      |      |      | O(100B)  | and regular
575*5113495bSYour Name    download   |                      |      |      |          |
576*5113495bSYour Name    ----------------------------------------------------------------------------
577*5113495bSYour Name    rx         | HTT_DATA (uplink)    | CE 1 | t->h | small -  | frequent and
578*5113495bSYour Name    indication |                      |      |      | O(10B)   | regular
579*5113495bSYour Name    upload     |                      |      |      |          |
580*5113495bSYour Name    ----------------------------------------------------------------------------
581*5113495bSYour Name    MSDU       | DATA_BK (uplink)     | CE 2 | t->h | large -  | rare
582*5113495bSYour Name    upload     |                      |      |      | O(1000B) | (frequent
583*5113495bSYour Name    e.g. noise |                      |      |      |          | during IP1.0
584*5113495bSYour Name    packets    |                      |      |      |          | testing)
585*5113495bSYour Name    ----------------------------------------------------------------------------
586*5113495bSYour Name    MSDU       | DATA_BK (downlink)   | CE 3 | h->t | large -  | very rare
587*5113495bSYour Name    download   |                      |      |      | O(1000B) | (frequent
588*5113495bSYour Name    e.g.       |                      |      |      |          | during IP1.0
589*5113495bSYour Name    misdirecte |                      |      |      |          | testing)
590*5113495bSYour Name    d EAPOL    |                      |      |      |          |
591*5113495bSYour Name    packets    |                      |      |      |          |
592*5113495bSYour Name    ----------------------------------------------------------------------------
593*5113495bSYour Name    n/a        | DATA_BE, DATA_VI     | CE 2 | t->h |          | never(?)
594*5113495bSYour Name  | DATA_VO (uplink)     |      |      |          |
595*5113495bSYour Name    ----------------------------------------------------------------------------
596*5113495bSYour Name    n/a        | DATA_BE, DATA_VI     | CE 3 | h->t |          | never(?)
597*5113495bSYour Name  | DATA_VO (downlink)   |      |      |          |
598*5113495bSYour Name    ----------------------------------------------------------------------------
599*5113495bSYour Name    WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent
600*5113495bSYour Name  |                      |      |      | O(100B)  |
601*5113495bSYour Name    ----------------------------------------------------------------------------
602*5113495bSYour Name    WMI        | WMI_CONTROL          | CE 5 | h->t | medium - | infrequent
603*5113495bSYour Name    messages   | (downlink)           |      |      | O(100B)  |
604*5113495bSYour Name  |                      |      |      |          |
605*5113495bSYour Name    ----------------------------------------------------------------------------
606*5113495bSYour Name    n/a        | HTC_CTRL_RSVD,       | CE 1 | t->h |          | never(?)
607*5113495bSYour Name  | HTC_RAW_STREAMS      |      |      |          |
608*5113495bSYour Name  | (uplink)             |      |      |          |
609*5113495bSYour Name    ----------------------------------------------------------------------------
610*5113495bSYour Name    n/a        | HTC_CTRL_RSVD,       | CE 0 | h->t |          | never(?)
611*5113495bSYour Name  | HTC_RAW_STREAMS      |      |      |          |
612*5113495bSYour Name  | (downlink)           |      |      |          |
613*5113495bSYour Name    ----------------------------------------------------------------------------
614*5113495bSYour Name    diag       | none (raw CE)        | CE 7 | t<>h |    4     | Diag Window
615*5113495bSYour Name  |                      |      |      |          | infrequent
616*5113495bSYour Name    ============================================================================
617*5113495bSYour Name  */
618*5113495bSYour Name 
619*5113495bSYour Name /*
620*5113495bSYour Name  * Map from service/endpoint to Copy Engine.
621*5113495bSYour Name  * This table is derived from the CE_PCI TABLE, above.
622*5113495bSYour Name  * It is passed to the Target at startup for use by firmware.
623*5113495bSYour Name  */
624*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_wlan[] = {
625*5113495bSYour Name 	{
626*5113495bSYour Name 		WMI_DATA_VO_SVC,
627*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
628*5113495bSYour Name 		3,
629*5113495bSYour Name 	},
630*5113495bSYour Name 	{
631*5113495bSYour Name 		WMI_DATA_VO_SVC,
632*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
633*5113495bSYour Name 		2,
634*5113495bSYour Name 	},
635*5113495bSYour Name 	{
636*5113495bSYour Name 		WMI_DATA_BK_SVC,
637*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
638*5113495bSYour Name 		3,
639*5113495bSYour Name 	},
640*5113495bSYour Name 	{
641*5113495bSYour Name 		WMI_DATA_BK_SVC,
642*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
643*5113495bSYour Name 		2,
644*5113495bSYour Name 	},
645*5113495bSYour Name 	{
646*5113495bSYour Name 		WMI_DATA_BE_SVC,
647*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
648*5113495bSYour Name 		3,
649*5113495bSYour Name 	},
650*5113495bSYour Name 	{
651*5113495bSYour Name 		WMI_DATA_BE_SVC,
652*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
653*5113495bSYour Name 		2,
654*5113495bSYour Name 	},
655*5113495bSYour Name 	{
656*5113495bSYour Name 		WMI_DATA_VI_SVC,
657*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
658*5113495bSYour Name 		3,
659*5113495bSYour Name 	},
660*5113495bSYour Name 	{
661*5113495bSYour Name 		WMI_DATA_VI_SVC,
662*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
663*5113495bSYour Name 		2,
664*5113495bSYour Name 	},
665*5113495bSYour Name 	{
666*5113495bSYour Name 		WMI_CONTROL_SVC,
667*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
668*5113495bSYour Name 		3,
669*5113495bSYour Name 	},
670*5113495bSYour Name 	{
671*5113495bSYour Name 		WMI_CONTROL_SVC,
672*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
673*5113495bSYour Name 		2,
674*5113495bSYour Name 	},
675*5113495bSYour Name 	{
676*5113495bSYour Name 		HTC_CTRL_RSVD_SVC,
677*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
678*5113495bSYour Name 		0,              /* could be moved to 3 (share with WMI) */
679*5113495bSYour Name 	},
680*5113495bSYour Name 	{
681*5113495bSYour Name 		HTC_CTRL_RSVD_SVC,
682*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
683*5113495bSYour Name 		2,
684*5113495bSYour Name 	},
685*5113495bSYour Name 	{
686*5113495bSYour Name 		HTC_RAW_STREAMS_SVC, /* not currently used */
687*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
688*5113495bSYour Name 		0,
689*5113495bSYour Name 	},
690*5113495bSYour Name 	{
691*5113495bSYour Name 		HTC_RAW_STREAMS_SVC, /* not currently used */
692*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
693*5113495bSYour Name 		2,
694*5113495bSYour Name 	},
695*5113495bSYour Name 	{
696*5113495bSYour Name 		HTT_DATA_MSG_SVC,
697*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
698*5113495bSYour Name 		4,
699*5113495bSYour Name 	},
700*5113495bSYour Name 	{
701*5113495bSYour Name 		HTT_DATA_MSG_SVC,
702*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
703*5113495bSYour Name 		1,
704*5113495bSYour Name 	},
705*5113495bSYour Name 	{
706*5113495bSYour Name 		WDI_IPA_TX_SVC,
707*5113495bSYour Name 		PIPEDIR_OUT,    /* in = DL = target -> host */
708*5113495bSYour Name 		5,
709*5113495bSYour Name 	},
710*5113495bSYour Name #if defined(QCA_WIFI_3_0_ADRASTEA)
711*5113495bSYour Name 	{
712*5113495bSYour Name 		HTT_DATA2_MSG_SVC,
713*5113495bSYour Name 		PIPEDIR_IN,    /* in = DL = target -> host */
714*5113495bSYour Name 		9,
715*5113495bSYour Name 	},
716*5113495bSYour Name 	{
717*5113495bSYour Name 		HTT_DATA3_MSG_SVC,
718*5113495bSYour Name 		PIPEDIR_IN,    /* in = DL = target -> host */
719*5113495bSYour Name 		10,
720*5113495bSYour Name 	},
721*5113495bSYour Name 	{
722*5113495bSYour Name 		PACKET_LOG_SVC,
723*5113495bSYour Name 		PIPEDIR_IN,    /* in = DL = target -> host */
724*5113495bSYour Name 		11,
725*5113495bSYour Name 	},
726*5113495bSYour Name #endif
727*5113495bSYour Name 	/* (Additions here) */
728*5113495bSYour Name 
729*5113495bSYour Name 	{                       /* Must be last */
730*5113495bSYour Name 		0,
731*5113495bSYour Name 		0,
732*5113495bSYour Name 		0,
733*5113495bSYour Name 	},
734*5113495bSYour Name };
735*5113495bSYour Name 
736*5113495bSYour Name /* PIPEDIR_OUT = HOST to Target */
737*5113495bSYour Name /* PIPEDIR_IN  = TARGET to HOST */
738*5113495bSYour Name #if (defined(QCA_WIFI_QCA8074))
739*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca8074[] = {
740*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
741*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
742*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
743*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
744*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
745*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
746*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
747*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
748*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
749*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
750*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
751*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
752*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
753*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
754*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
755*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
756*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
757*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
758*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
759*5113495bSYour Name 	/* (Additions here) */
760*5113495bSYour Name 	{ 0, 0, 0, },
761*5113495bSYour Name };
762*5113495bSYour Name #else
763*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca8074[] = {
764*5113495bSYour Name };
765*5113495bSYour Name #endif
766*5113495bSYour Name 
767*5113495bSYour Name #if (defined(QCA_WIFI_QCA9574))
768*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca9574[] = {
769*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
770*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
771*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
772*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
773*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
774*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
775*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
776*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
777*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
778*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
779*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
780*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
781*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
782*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
783*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
784*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
785*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
786*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
787*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
788*5113495bSYour Name 	/* (Additions here) */
789*5113495bSYour Name 	{ 0, 0, 0, },
790*5113495bSYour Name };
791*5113495bSYour Name #else
792*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca9574[] = {
793*5113495bSYour Name };
794*5113495bSYour Name #endif
795*5113495bSYour Name 
796*5113495bSYour Name #if (defined(QCA_WIFI_QCA8074V2))
797*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca8074_v2[] = {
798*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
799*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
800*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
801*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
802*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
803*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
804*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
805*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
806*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
807*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
808*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
809*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
810*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC2, PIPEDIR_OUT, 9},
811*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC2, PIPEDIR_IN, 2},
812*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
813*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
814*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
815*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
816*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
817*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
818*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
819*5113495bSYour Name 	/* (Additions here) */
820*5113495bSYour Name 	{ 0, 0, 0, },
821*5113495bSYour Name };
822*5113495bSYour Name #else
823*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca8074_v2[] = {
824*5113495bSYour Name };
825*5113495bSYour Name #endif
826*5113495bSYour Name 
827*5113495bSYour Name #if (defined(QCA_WIFI_QCA6018))
828*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6018[] = {
829*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
830*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
831*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
832*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
833*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
834*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
835*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
836*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
837*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
838*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
839*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
840*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
841*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
842*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
843*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
844*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
845*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
846*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
847*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
848*5113495bSYour Name 	/* (Additions here) */
849*5113495bSYour Name 	{ 0, 0, 0, },
850*5113495bSYour Name };
851*5113495bSYour Name #else
852*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6018[] = {
853*5113495bSYour Name };
854*5113495bSYour Name #endif
855*5113495bSYour Name 
856*5113495bSYour Name #if (defined(QCA_WIFI_QCN9000))
857*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qcn9000[] = {
858*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
859*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
860*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
861*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
862*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
863*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
864*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
865*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
866*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
867*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
868*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
869*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
870*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
871*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
872*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
873*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
874*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
875*5113495bSYour Name 	/* (Additions here) */
876*5113495bSYour Name 	{ 0, 0, 0, },
877*5113495bSYour Name };
878*5113495bSYour Name #else
879*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qcn9000[] = {
880*5113495bSYour Name };
881*5113495bSYour Name #endif
882*5113495bSYour Name 
883*5113495bSYour Name #if (defined(QCA_WIFI_QCA5332) || defined(QCA_WIFI_QCN6432))
884*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca5332[] = {
885*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
886*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
887*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
888*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
889*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
890*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
891*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
892*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
893*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
894*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
895*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
896*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
897*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
898*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
899*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
900*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
901*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
902*5113495bSYour Name #ifdef WLAN_DIAG_AND_DBR_OVER_SEPARATE_CE
903*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 9, },
904*5113495bSYour Name 	{ WMI_CONTROL_DBR_SVC, PIPEDIR_IN, 9, },
905*5113495bSYour Name #else
906*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 2, },
907*5113495bSYour Name 	{ WMI_CONTROL_DBR_SVC, PIPEDIR_IN, 2, },
908*5113495bSYour Name #endif
909*5113495bSYour Name 	/* (Additions here) */
910*5113495bSYour Name 	{ 0, 0, 0, },
911*5113495bSYour Name };
912*5113495bSYour Name #else
913*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca5332[] = {
914*5113495bSYour Name };
915*5113495bSYour Name #endif
916*5113495bSYour Name 
917*5113495bSYour Name #if (defined(QCA_WIFI_QCN9224))
918*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qcn9224[] = {
919*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
920*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
921*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
922*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
923*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
924*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
925*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
926*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
927*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
928*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
929*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
930*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
931*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
932*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
933*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
934*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
935*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7, },
936*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2, },
937*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
938*5113495bSYour Name #ifdef WLAN_DIAG_AND_DBR_OVER_SEPARATE_CE
939*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 14, },
940*5113495bSYour Name 	{ WMI_CONTROL_DBR_SVC, PIPEDIR_IN, 14, },
941*5113495bSYour Name #else
942*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 2, },
943*5113495bSYour Name 	{ WMI_CONTROL_DBR_SVC, PIPEDIR_IN, 2, },
944*5113495bSYour Name #endif
945*5113495bSYour Name 	/* (Additions here) */
946*5113495bSYour Name 	{ 0, 0, 0, },
947*5113495bSYour Name };
948*5113495bSYour Name #endif
949*5113495bSYour Name 
950*5113495bSYour Name #if defined(QCA_WIFI_QCA5018) || defined(QCA_WIFI_QCN9160)
951*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca5018[] = {
952*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
953*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
954*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
955*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
956*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
957*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
958*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
959*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
960*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
961*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
962*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
963*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
964*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
965*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
966*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
967*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
968*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
969*5113495bSYour Name 	/* (Additions here) */
970*5113495bSYour Name 	{ 0, 0, 0, },
971*5113495bSYour Name };
972*5113495bSYour Name #else
973*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca5018[] = {
974*5113495bSYour Name };
975*5113495bSYour Name #endif
976*5113495bSYour Name 
977*5113495bSYour Name /* PIPEDIR_OUT = HOST to Target */
978*5113495bSYour Name /* PIPEDIR_IN  = TARGET to HOST */
979*5113495bSYour Name #ifdef QCN7605_SUPPORT
980*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qcn7605[] = {
981*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 0, },
982*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
983*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 0, },
984*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
985*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 0, },
986*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
987*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 0, },
988*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
989*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 0, },
990*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
991*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
992*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
993*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0, },
994*5113495bSYour Name 	{ HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2, },
995*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
996*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
997*5113495bSYour Name 	{ HTT_DATA2_MSG_SVC, PIPEDIR_IN, 3, },
998*5113495bSYour Name #ifdef IPA_OFFLOAD
999*5113495bSYour Name 	{ WDI_IPA_TX_SVC, PIPEDIR_OUT, 5, },
1000*5113495bSYour Name #else
1001*5113495bSYour Name 	{ HTT_DATA3_MSG_SVC, PIPEDIR_IN, 8, },
1002*5113495bSYour Name #endif
1003*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 7, },
1004*5113495bSYour Name 	/* (Additions here) */
1005*5113495bSYour Name 	{ 0, 0, 0, },
1006*5113495bSYour Name };
1007*5113495bSYour Name #endif
1008*5113495bSYour Name 
1009*5113495bSYour Name #if (defined(QCA_WIFI_QCA6290))
1010*5113495bSYour Name #ifdef QCA_6290_AP_MODE
1011*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
1012*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1013*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN , 2, },
1014*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1015*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN , 2, },
1016*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1017*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN , 2, },
1018*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1019*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN , 2, },
1020*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1021*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN , 2, },
1022*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
1023*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN , 2, },
1024*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1025*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN , 1, },
1026*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
1027*5113495bSYour Name 	{ WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
1028*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
1029*5113495bSYour Name 	/* (Additions here) */
1030*5113495bSYour Name 	{ 0, 0, 0, },
1031*5113495bSYour Name };
1032*5113495bSYour Name #else
1033*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
1034*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1035*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
1036*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1037*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
1038*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1039*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
1040*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1041*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
1042*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1043*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
1044*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
1045*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
1046*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1047*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
1048*5113495bSYour Name 	/* (Additions here) */
1049*5113495bSYour Name 	{ 0, 0, 0, },
1050*5113495bSYour Name };
1051*5113495bSYour Name #endif
1052*5113495bSYour Name #else
1053*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
1054*5113495bSYour Name };
1055*5113495bSYour Name #endif
1056*5113495bSYour Name 
1057*5113495bSYour Name #if (defined(QCA_WIFI_QCA6390))
1058*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6390[] = {
1059*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1060*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
1061*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1062*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
1063*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1064*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
1065*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1066*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
1067*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1068*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
1069*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
1070*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
1071*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1072*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
1073*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
1074*5113495bSYour Name 	/* (Additions here) */
1075*5113495bSYour Name 	{ 0, 0, 0, },
1076*5113495bSYour Name };
1077*5113495bSYour Name #else
1078*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6390[] = {
1079*5113495bSYour Name };
1080*5113495bSYour Name #endif
1081*5113495bSYour Name 
1082*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6490[] = {
1083*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1084*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
1085*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1086*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
1087*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1088*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
1089*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1090*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
1091*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1092*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
1093*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
1094*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
1095*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1096*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
1097*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
1098*5113495bSYour Name 	/* (Additions here) */
1099*5113495bSYour Name 	{ 0, 0, 0, },
1100*5113495bSYour Name };
1101*5113495bSYour Name 
1102*5113495bSYour Name #if (defined(QCA_WIFI_QCA6750))
1103*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6750[] = {
1104*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1105*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
1106*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1107*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
1108*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1109*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
1110*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1111*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
1112*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1113*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
1114*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
1115*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
1116*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1117*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
1118*5113495bSYour Name 	{ PACKET_LOG_SVC, PIPEDIR_IN, 5, },
1119*5113495bSYour Name #ifdef WLAN_FEATURE_WMI_DIAG_OVER_CE7
1120*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 7, },
1121*5113495bSYour Name #endif
1122*5113495bSYour Name 	/* (Additions here) */
1123*5113495bSYour Name 	{ 0, 0, 0, },
1124*5113495bSYour Name };
1125*5113495bSYour Name #else
1126*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_qca6750[] = {
1127*5113495bSYour Name };
1128*5113495bSYour Name #endif
1129*5113495bSYour Name 
1130*5113495bSYour Name #if (defined(QCA_WIFI_KIWI))
1131*5113495bSYour Name #ifdef FEATURE_DIRECT_LINK
1132*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_kiwi_direct_link[] = {
1133*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1134*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
1135*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1136*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
1137*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1138*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
1139*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1140*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
1141*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1142*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
1143*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 4, },
1144*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
1145*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1146*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
1147*5113495bSYour Name #ifdef WLAN_FEATURE_WMI_DIAG_OVER_CE7
1148*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 7, },
1149*5113495bSYour Name #endif
1150*5113495bSYour Name 	{ LPASS_DATA_MSG_SVC, PIPEDIR_OUT, 0, },
1151*5113495bSYour Name 	{ LPASS_DATA_MSG_SVC, PIPEDIR_IN, 5, },
1152*5113495bSYour Name 	/* (Additions here) */
1153*5113495bSYour Name 	{ 0, 0, 0, },
1154*5113495bSYour Name };
1155*5113495bSYour Name #endif
1156*5113495bSYour Name 
1157*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_kiwi[] = {
1158*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1159*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
1160*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1161*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
1162*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1163*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
1164*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1165*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
1166*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1167*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
1168*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
1169*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
1170*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1171*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
1172*5113495bSYour Name #ifdef WLAN_FEATURE_WMI_DIAG_OVER_CE7
1173*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 7, },
1174*5113495bSYour Name #endif
1175*5113495bSYour Name 	/* (Additions here) */
1176*5113495bSYour Name 	{ 0, 0, 0, },
1177*5113495bSYour Name };
1178*5113495bSYour Name #else
1179*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_kiwi[] = {
1180*5113495bSYour Name };
1181*5113495bSYour Name #endif
1182*5113495bSYour Name 
1183*5113495bSYour Name #ifdef QCA_WIFI_WCN6450
1184*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_wcn6450[] = {
1185*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
1186*5113495bSYour Name 	{ WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
1187*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
1188*5113495bSYour Name 	{ WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
1189*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
1190*5113495bSYour Name 	{ WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
1191*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
1192*5113495bSYour Name 	{ WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
1193*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
1194*5113495bSYour Name 	{ WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
1195*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
1196*5113495bSYour Name 	{ HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
1197*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
1198*5113495bSYour Name 	{ HTT_DATA2_MSG_SVC, PIPEDIR_OUT, 5, },
1199*5113495bSYour Name 	{ HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
1200*5113495bSYour Name 	{ HTT_DATA2_MSG_SVC, PIPEDIR_IN, 10, },
1201*5113495bSYour Name 	{ HTT_DATA3_MSG_SVC, PIPEDIR_IN, 11, },
1202*5113495bSYour Name #ifdef WLAN_FEATURE_WMI_DIAG_OVER_CE7
1203*5113495bSYour Name 	{ WMI_CONTROL_DIAG_SVC, PIPEDIR_IN, 7, },
1204*5113495bSYour Name #endif
1205*5113495bSYour Name 	/* (Additions here) */
1206*5113495bSYour Name 	{ 0, 0, 0, },
1207*5113495bSYour Name };
1208*5113495bSYour Name #else
1209*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_wcn6450[] = {
1210*5113495bSYour Name };
1211*5113495bSYour Name #endif
1212*5113495bSYour Name 
1213*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_ar900b[] = {
1214*5113495bSYour Name 	{
1215*5113495bSYour Name 		WMI_DATA_VO_SVC,
1216*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1217*5113495bSYour Name 		3,
1218*5113495bSYour Name 	},
1219*5113495bSYour Name 	{
1220*5113495bSYour Name 		WMI_DATA_VO_SVC,
1221*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1222*5113495bSYour Name 		2,
1223*5113495bSYour Name 	},
1224*5113495bSYour Name 	{
1225*5113495bSYour Name 		WMI_DATA_BK_SVC,
1226*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1227*5113495bSYour Name 		3,
1228*5113495bSYour Name 	},
1229*5113495bSYour Name 	{
1230*5113495bSYour Name 		WMI_DATA_BK_SVC,
1231*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1232*5113495bSYour Name 		2,
1233*5113495bSYour Name 	},
1234*5113495bSYour Name 	{
1235*5113495bSYour Name 		WMI_DATA_BE_SVC,
1236*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1237*5113495bSYour Name 		3,
1238*5113495bSYour Name 	},
1239*5113495bSYour Name 	{
1240*5113495bSYour Name 		WMI_DATA_BE_SVC,
1241*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1242*5113495bSYour Name 		2,
1243*5113495bSYour Name 	},
1244*5113495bSYour Name 	{
1245*5113495bSYour Name 		WMI_DATA_VI_SVC,
1246*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1247*5113495bSYour Name 		3,
1248*5113495bSYour Name 	},
1249*5113495bSYour Name 	{
1250*5113495bSYour Name 		WMI_DATA_VI_SVC,
1251*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1252*5113495bSYour Name 		2,
1253*5113495bSYour Name 	},
1254*5113495bSYour Name 	{
1255*5113495bSYour Name 		WMI_CONTROL_SVC,
1256*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1257*5113495bSYour Name 		3,
1258*5113495bSYour Name 	},
1259*5113495bSYour Name 	{
1260*5113495bSYour Name 		WMI_CONTROL_SVC,
1261*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1262*5113495bSYour Name 		2,
1263*5113495bSYour Name 	},
1264*5113495bSYour Name 	{
1265*5113495bSYour Name 		HTC_CTRL_RSVD_SVC,
1266*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1267*5113495bSYour Name 		0,              /* could be moved to 3 (share with WMI) */
1268*5113495bSYour Name 	},
1269*5113495bSYour Name 	{
1270*5113495bSYour Name 		HTC_CTRL_RSVD_SVC,
1271*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1272*5113495bSYour Name 		1,
1273*5113495bSYour Name 	},
1274*5113495bSYour Name 	{
1275*5113495bSYour Name 		HTC_RAW_STREAMS_SVC, /* not currently used */
1276*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1277*5113495bSYour Name 		0,
1278*5113495bSYour Name 	},
1279*5113495bSYour Name 	{
1280*5113495bSYour Name 		HTC_RAW_STREAMS_SVC, /* not currently used */
1281*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1282*5113495bSYour Name 		1,
1283*5113495bSYour Name 	},
1284*5113495bSYour Name 	{
1285*5113495bSYour Name 		HTT_DATA_MSG_SVC,
1286*5113495bSYour Name 		PIPEDIR_OUT,    /* out = UL = host -> target */
1287*5113495bSYour Name 		4,
1288*5113495bSYour Name 	},
1289*5113495bSYour Name #ifdef WLAN_FEATURE_FASTPATH
1290*5113495bSYour Name 	{
1291*5113495bSYour Name 		HTT_DATA_MSG_SVC,
1292*5113495bSYour Name 		PIPEDIR_IN,     /* in = DL = target -> host */
1293*5113495bSYour Name 		5,
1294*5113495bSYour Name 	},
1295*5113495bSYour Name #else /* WLAN_FEATURE_FASTPATH */
1296*5113495bSYour Name 	{
1297*5113495bSYour Name 		HTT_DATA_MSG_SVC,
1298*5113495bSYour Name 		PIPEDIR_IN,  /* in = DL = target -> host */
1299*5113495bSYour Name 		1,
1300*5113495bSYour Name 	},
1301*5113495bSYour Name #endif /* WLAN_FEATURE_FASTPATH */
1302*5113495bSYour Name 
1303*5113495bSYour Name 	/* (Additions here) */
1304*5113495bSYour Name 
1305*5113495bSYour Name 	{                       /* Must be last */
1306*5113495bSYour Name 		0,
1307*5113495bSYour Name 		0,
1308*5113495bSYour Name 		0,
1309*5113495bSYour Name 	},
1310*5113495bSYour Name };
1311*5113495bSYour Name 
1312*5113495bSYour Name static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
1313*5113495bSYour Name static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
1314*5113495bSYour Name 
1315*5113495bSYour Name #ifdef WLAN_FEATURE_EPPING
1316*5113495bSYour Name static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
1317*5113495bSYour Name 	{WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,},     /* out = UL = host -> target */
1318*5113495bSYour Name 	{WMI_DATA_VO_SVC, PIPEDIR_IN, 2,},      /* in = DL = target -> host */
1319*5113495bSYour Name 	{WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,},     /* out = UL = host -> target */
1320*5113495bSYour Name 	{WMI_DATA_BK_SVC, PIPEDIR_IN, 1,},      /* in = DL = target -> host */
1321*5113495bSYour Name 	{WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,},     /* out = UL = host -> target */
1322*5113495bSYour Name 	{WMI_DATA_BE_SVC, PIPEDIR_IN, 2,},      /* in = DL = target -> host */
1323*5113495bSYour Name 	{WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,},     /* out = UL = host -> target */
1324*5113495bSYour Name 	{WMI_DATA_VI_SVC, PIPEDIR_IN, 2,},      /* in = DL = target -> host */
1325*5113495bSYour Name 	{WMI_CONTROL_SVC, PIPEDIR_OUT, 3,},     /* out = UL = host -> target */
1326*5113495bSYour Name 	{WMI_CONTROL_SVC, PIPEDIR_IN, 2,},      /* in = DL = target -> host */
1327*5113495bSYour Name 	{HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,},   /* out = UL = host -> target */
1328*5113495bSYour Name 	{HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,},    /* in = DL = target -> host */
1329*5113495bSYour Name 	{HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
1330*5113495bSYour Name 	{HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,},  /* in = DL = target -> host */
1331*5113495bSYour Name 	{HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,},    /* out = UL = host -> target */
1332*5113495bSYour Name 	{HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,},     /* in = DL = target -> host */
1333*5113495bSYour Name 	{0, 0, 0,},             /* Must be last */
1334*5113495bSYour Name };
1335*5113495bSYour Name 
hif_select_epping_service_to_pipe_map(struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1336*5113495bSYour Name void hif_select_epping_service_to_pipe_map(struct service_to_pipe
1337*5113495bSYour Name 					   **tgt_svc_map_to_use,
1338*5113495bSYour Name 					   uint32_t *sz_tgt_svc_map_to_use)
1339*5113495bSYour Name {
1340*5113495bSYour Name 	*tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
1341*5113495bSYour Name 	*sz_tgt_svc_map_to_use =
1342*5113495bSYour Name 			sizeof(target_service_to_ce_map_wlan_epping);
1343*5113495bSYour Name }
1344*5113495bSYour Name #endif
1345*5113495bSYour Name 
1346*5113495bSYour Name #ifdef QCN7605_SUPPORT
1347*5113495bSYour Name static inline
hif_select_ce_map_qcn7605(struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1348*5113495bSYour Name void hif_select_ce_map_qcn7605(struct service_to_pipe **tgt_svc_map_to_use,
1349*5113495bSYour Name 			       uint32_t *sz_tgt_svc_map_to_use)
1350*5113495bSYour Name {
1351*5113495bSYour Name 	*tgt_svc_map_to_use = target_service_to_ce_map_qcn7605;
1352*5113495bSYour Name 	*sz_tgt_svc_map_to_use = sizeof(target_service_to_ce_map_qcn7605);
1353*5113495bSYour Name }
1354*5113495bSYour Name #else
1355*5113495bSYour Name static inline
hif_select_ce_map_qcn7605(struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1356*5113495bSYour Name void hif_select_ce_map_qcn7605(struct service_to_pipe **tgt_svc_map_to_use,
1357*5113495bSYour Name 			       uint32_t *sz_tgt_svc_map_to_use)
1358*5113495bSYour Name {
1359*5113495bSYour Name 	hif_err("QCN7605 not supported");
1360*5113495bSYour Name }
1361*5113495bSYour Name #endif
1362*5113495bSYour Name 
1363*5113495bSYour Name #ifdef QCA_WIFI_QCN9224
1364*5113495bSYour Name static
hif_set_ce_config_qcn9224(struct hif_softc * scn,struct HIF_CE_state * hif_state)1365*5113495bSYour Name void hif_set_ce_config_qcn9224(struct hif_softc *scn,
1366*5113495bSYour Name 			       struct HIF_CE_state *hif_state)
1367*5113495bSYour Name {
1368*5113495bSYour Name 	hif_state->host_ce_config = host_ce_config_wlan_qcn9224;
1369*5113495bSYour Name 	hif_state->target_ce_config = target_ce_config_wlan_qcn9224;
1370*5113495bSYour Name 	hif_state->target_ce_config_sz =
1371*5113495bSYour Name 				 sizeof(target_ce_config_wlan_qcn9224);
1372*5113495bSYour Name 	scn->ce_count = QCN_9224_CE_COUNT;
1373*5113495bSYour Name 	scn->ini_cfg.disable_wake_irq = 1;
1374*5113495bSYour Name }
1375*5113495bSYour Name 
1376*5113495bSYour Name static
hif_select_ce_map_qcn9224(struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1377*5113495bSYour Name void hif_select_ce_map_qcn9224(struct service_to_pipe **tgt_svc_map_to_use,
1378*5113495bSYour Name 			       uint32_t *sz_tgt_svc_map_to_use)
1379*5113495bSYour Name {
1380*5113495bSYour Name 	*tgt_svc_map_to_use = target_service_to_ce_map_qcn9224;
1381*5113495bSYour Name 	*sz_tgt_svc_map_to_use = sizeof(target_service_to_ce_map_qcn9224);
1382*5113495bSYour Name }
1383*5113495bSYour Name #else
1384*5113495bSYour Name static inline
hif_set_ce_config_qcn9224(struct hif_softc * scn,struct HIF_CE_state * hif_state)1385*5113495bSYour Name void hif_set_ce_config_qcn9224(struct hif_softc *scn,
1386*5113495bSYour Name 			       struct HIF_CE_state *hif_state)
1387*5113495bSYour Name {
1388*5113495bSYour Name 	hif_err("QCN9224 not supported");
1389*5113495bSYour Name }
1390*5113495bSYour Name 
1391*5113495bSYour Name static inline
hif_select_ce_map_qcn9224(struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1392*5113495bSYour Name void hif_select_ce_map_qcn9224(struct service_to_pipe **tgt_svc_map_to_use,
1393*5113495bSYour Name 			       uint32_t *sz_tgt_svc_map_to_use)
1394*5113495bSYour Name {
1395*5113495bSYour Name 	hif_err("QCN9224 not supported");
1396*5113495bSYour Name }
1397*5113495bSYour Name #endif
1398*5113495bSYour Name 
1399*5113495bSYour Name #ifdef FEATURE_DIRECT_LINK
1400*5113495bSYour Name /**
1401*5113495bSYour Name  * hif_select_service_to_pipe_map_kiwi() - Select service to CE map
1402*5113495bSYour Name  *  configuration for Kiwi
1403*5113495bSYour Name  * @scn: HIF context
1404*5113495bSYour Name  * @tgt_svc_map_to_use: returned service map
1405*5113495bSYour Name  * @sz_tgt_svc_map_to_use: returned length of the service map
1406*5113495bSYour Name  *
1407*5113495bSYour Name  * Return: None
1408*5113495bSYour Name  */
1409*5113495bSYour Name static inline void
hif_select_service_to_pipe_map_kiwi(struct hif_softc * scn,struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1410*5113495bSYour Name hif_select_service_to_pipe_map_kiwi(struct hif_softc *scn,
1411*5113495bSYour Name 				    struct service_to_pipe **tgt_svc_map_to_use,
1412*5113495bSYour Name 				    uint32_t *sz_tgt_svc_map_to_use)
1413*5113495bSYour Name {
1414*5113495bSYour Name 	if (pld_is_direct_link_supported(scn->qdf_dev->dev)) {
1415*5113495bSYour Name 		*tgt_svc_map_to_use = target_service_to_ce_map_kiwi_direct_link;
1416*5113495bSYour Name 		*sz_tgt_svc_map_to_use =
1417*5113495bSYour Name 			sizeof(target_service_to_ce_map_kiwi_direct_link);
1418*5113495bSYour Name 	} else {
1419*5113495bSYour Name 		*tgt_svc_map_to_use = target_service_to_ce_map_kiwi;
1420*5113495bSYour Name 		*sz_tgt_svc_map_to_use = sizeof(target_service_to_ce_map_kiwi);
1421*5113495bSYour Name 	}
1422*5113495bSYour Name }
1423*5113495bSYour Name #else
1424*5113495bSYour Name static inline void
hif_select_service_to_pipe_map_kiwi(struct hif_softc * scn,struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1425*5113495bSYour Name hif_select_service_to_pipe_map_kiwi(struct hif_softc *scn,
1426*5113495bSYour Name 				    struct service_to_pipe **tgt_svc_map_to_use,
1427*5113495bSYour Name 				    uint32_t *sz_tgt_svc_map_to_use)
1428*5113495bSYour Name {
1429*5113495bSYour Name 	*tgt_svc_map_to_use = target_service_to_ce_map_kiwi;
1430*5113495bSYour Name 	*sz_tgt_svc_map_to_use = sizeof(target_service_to_ce_map_kiwi);
1431*5113495bSYour Name }
1432*5113495bSYour Name #endif
1433*5113495bSYour Name 
hif_select_service_to_pipe_map(struct hif_softc * scn,struct service_to_pipe ** tgt_svc_map_to_use,uint32_t * sz_tgt_svc_map_to_use)1434*5113495bSYour Name static void hif_select_service_to_pipe_map(struct hif_softc *scn,
1435*5113495bSYour Name 				    struct service_to_pipe **tgt_svc_map_to_use,
1436*5113495bSYour Name 				    uint32_t *sz_tgt_svc_map_to_use)
1437*5113495bSYour Name {
1438*5113495bSYour Name 	uint32_t mode = hif_get_conparam(scn);
1439*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1440*5113495bSYour Name 	struct hif_target_info *tgt_info = &scn->target_info;
1441*5113495bSYour Name 
1442*5113495bSYour Name 	if (QDF_IS_EPPING_ENABLED(mode)) {
1443*5113495bSYour Name 		hif_select_epping_service_to_pipe_map(tgt_svc_map_to_use,
1444*5113495bSYour Name 						      sz_tgt_svc_map_to_use);
1445*5113495bSYour Name 	} else {
1446*5113495bSYour Name 		switch (tgt_info->target_type) {
1447*5113495bSYour Name 		default:
1448*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_wlan;
1449*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1450*5113495bSYour Name 				sizeof(target_service_to_ce_map_wlan);
1451*5113495bSYour Name 			break;
1452*5113495bSYour Name 		case TARGET_TYPE_QCN7605:
1453*5113495bSYour Name 			hif_select_ce_map_qcn7605(tgt_svc_map_to_use,
1454*5113495bSYour Name 						  sz_tgt_svc_map_to_use);
1455*5113495bSYour Name 			break;
1456*5113495bSYour Name 		case TARGET_TYPE_AR900B:
1457*5113495bSYour Name 		case TARGET_TYPE_QCA9984:
1458*5113495bSYour Name 		case TARGET_TYPE_QCA9888:
1459*5113495bSYour Name 		case TARGET_TYPE_AR9888:
1460*5113495bSYour Name 		case TARGET_TYPE_AR9888V2:
1461*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
1462*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1463*5113495bSYour Name 				sizeof(target_service_to_ce_map_ar900b);
1464*5113495bSYour Name 			break;
1465*5113495bSYour Name 		case TARGET_TYPE_QCA6290:
1466*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_qca6290;
1467*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1468*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca6290);
1469*5113495bSYour Name 			break;
1470*5113495bSYour Name 		case TARGET_TYPE_QCA6390:
1471*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_qca6390;
1472*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1473*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca6390);
1474*5113495bSYour Name 			break;
1475*5113495bSYour Name 		case TARGET_TYPE_QCA6490:
1476*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_qca6490;
1477*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1478*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca6490);
1479*5113495bSYour Name 			break;
1480*5113495bSYour Name 		case TARGET_TYPE_QCA6750:
1481*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_qca6750;
1482*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1483*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca6750);
1484*5113495bSYour Name 			break;
1485*5113495bSYour Name 		case TARGET_TYPE_KIWI:
1486*5113495bSYour Name 		case TARGET_TYPE_MANGO:
1487*5113495bSYour Name 		case TARGET_TYPE_PEACH:
1488*5113495bSYour Name 			hif_select_service_to_pipe_map_kiwi(scn,
1489*5113495bSYour Name 							 tgt_svc_map_to_use,
1490*5113495bSYour Name 							 sz_tgt_svc_map_to_use);
1491*5113495bSYour Name 			break;
1492*5113495bSYour Name 		case TARGET_TYPE_WCN6450:
1493*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_wcn6450;
1494*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1495*5113495bSYour Name 				 sizeof(target_service_to_ce_map_wcn6450);
1496*5113495bSYour Name 			break;
1497*5113495bSYour Name 		case TARGET_TYPE_QCA8074:
1498*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_qca8074;
1499*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1500*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca8074);
1501*5113495bSYour Name 			break;
1502*5113495bSYour Name 		case TARGET_TYPE_QCA8074V2:
1503*5113495bSYour Name 			*tgt_svc_map_to_use =
1504*5113495bSYour Name 				target_service_to_ce_map_qca8074_v2;
1505*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1506*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca8074_v2);
1507*5113495bSYour Name 			break;
1508*5113495bSYour Name 		case TARGET_TYPE_QCA9574:
1509*5113495bSYour Name 			*tgt_svc_map_to_use =
1510*5113495bSYour Name 				target_service_to_ce_map_qca9574;
1511*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1512*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca9574);
1513*5113495bSYour Name 			break;
1514*5113495bSYour Name 		case TARGET_TYPE_QCA6018:
1515*5113495bSYour Name 			*tgt_svc_map_to_use =
1516*5113495bSYour Name 				target_service_to_ce_map_qca6018;
1517*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1518*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca6018);
1519*5113495bSYour Name 			break;
1520*5113495bSYour Name 		case TARGET_TYPE_QCN9000:
1521*5113495bSYour Name 			*tgt_svc_map_to_use =
1522*5113495bSYour Name 				target_service_to_ce_map_qcn9000;
1523*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1524*5113495bSYour Name 				sizeof(target_service_to_ce_map_qcn9000);
1525*5113495bSYour Name 			break;
1526*5113495bSYour Name 		case TARGET_TYPE_QCN9224:
1527*5113495bSYour Name 			hif_select_ce_map_qcn9224(tgt_svc_map_to_use,
1528*5113495bSYour Name 						  sz_tgt_svc_map_to_use);
1529*5113495bSYour Name 			break;
1530*5113495bSYour Name 		case TARGET_TYPE_QCA5332:
1531*5113495bSYour Name 		case TARGET_TYPE_QCN6432:
1532*5113495bSYour Name 			*tgt_svc_map_to_use = target_service_to_ce_map_qca5332;
1533*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1534*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca5332);
1535*5113495bSYour Name 			break;
1536*5113495bSYour Name 		case TARGET_TYPE_QCA5018:
1537*5113495bSYour Name 		case TARGET_TYPE_QCN6122:
1538*5113495bSYour Name 		case TARGET_TYPE_QCN9160:
1539*5113495bSYour Name 			*tgt_svc_map_to_use =
1540*5113495bSYour Name 				target_service_to_ce_map_qca5018;
1541*5113495bSYour Name 			*sz_tgt_svc_map_to_use =
1542*5113495bSYour Name 				sizeof(target_service_to_ce_map_qca5018);
1543*5113495bSYour Name 			break;
1544*5113495bSYour Name 		}
1545*5113495bSYour Name 	}
1546*5113495bSYour Name 	hif_state->tgt_svc_map = *tgt_svc_map_to_use;
1547*5113495bSYour Name 	hif_state->sz_tgt_svc_map = *sz_tgt_svc_map_to_use /
1548*5113495bSYour Name 					sizeof(struct service_to_pipe);
1549*5113495bSYour Name }
1550*5113495bSYour Name 
1551*5113495bSYour Name #ifndef QCA_WIFI_WCN6450
1552*5113495bSYour Name /**
1553*5113495bSYour Name  * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly
1554*5113495bSYour Name  * @ce_state : pointer to the state context of the CE
1555*5113495bSYour Name  *
1556*5113495bSYour Name  * Description:
1557*5113495bSYour Name  *   Sets htt_rx_data attribute of the state structure if the
1558*5113495bSYour Name  *   CE serves one of the HTT DATA services.
1559*5113495bSYour Name  *
1560*5113495bSYour Name  * Return:
1561*5113495bSYour Name  *  false (attribute set to false)
1562*5113495bSYour Name  *  true  (attribute set to true);
1563*5113495bSYour Name  */
ce_mark_datapath(struct CE_state * ce_state)1564*5113495bSYour Name static bool ce_mark_datapath(struct CE_state *ce_state)
1565*5113495bSYour Name {
1566*5113495bSYour Name 	struct service_to_pipe *svc_map;
1567*5113495bSYour Name 	uint32_t map_sz, map_len;
1568*5113495bSYour Name 	int    i;
1569*5113495bSYour Name 	bool   rc = false;
1570*5113495bSYour Name 
1571*5113495bSYour Name 	if (ce_state) {
1572*5113495bSYour Name 		hif_select_service_to_pipe_map(ce_state->scn, &svc_map,
1573*5113495bSYour Name 					       &map_sz);
1574*5113495bSYour Name 
1575*5113495bSYour Name 		map_len = map_sz / sizeof(struct service_to_pipe);
1576*5113495bSYour Name 		for (i = 0; i < map_len; i++) {
1577*5113495bSYour Name 			if ((svc_map[i].pipenum == ce_state->id) &&
1578*5113495bSYour Name 			    ((svc_map[i].service_id == HTT_DATA_MSG_SVC)  ||
1579*5113495bSYour Name 			     (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
1580*5113495bSYour Name 			     (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) {
1581*5113495bSYour Name 				/* HTT CEs are unidirectional */
1582*5113495bSYour Name 				if (svc_map[i].pipedir == PIPEDIR_IN)
1583*5113495bSYour Name 					ce_state->htt_rx_data = true;
1584*5113495bSYour Name 				else
1585*5113495bSYour Name 					ce_state->htt_tx_data = true;
1586*5113495bSYour Name 				rc = true;
1587*5113495bSYour Name 			}
1588*5113495bSYour Name 		}
1589*5113495bSYour Name 	}
1590*5113495bSYour Name 	return rc;
1591*5113495bSYour Name }
1592*5113495bSYour Name 
ce_update_msi_batch_intr_flags(struct CE_state * ce_state)1593*5113495bSYour Name static void ce_update_msi_batch_intr_flags(struct CE_state *ce_state)
1594*5113495bSYour Name {
1595*5113495bSYour Name }
1596*5113495bSYour Name 
ce_update_wrt_idx_offset(struct hif_softc * scn,struct CE_state * ce_state,struct CE_attr * attr)1597*5113495bSYour Name static inline void ce_update_wrt_idx_offset(struct hif_softc *scn,
1598*5113495bSYour Name 					    struct CE_state *ce_state,
1599*5113495bSYour Name 					    struct CE_attr *attr)
1600*5113495bSYour Name {
1601*5113495bSYour Name }
1602*5113495bSYour Name #else
ce_mark_datapath(struct CE_state * ce_state)1603*5113495bSYour Name static bool ce_mark_datapath(struct CE_state *ce_state)
1604*5113495bSYour Name {
1605*5113495bSYour Name 	struct service_to_pipe *svc_map;
1606*5113495bSYour Name 	uint32_t map_sz, map_len;
1607*5113495bSYour Name 	int i;
1608*5113495bSYour Name 
1609*5113495bSYour Name 	if (ce_state) {
1610*5113495bSYour Name 		hif_select_service_to_pipe_map(ce_state->scn, &svc_map,
1611*5113495bSYour Name 					       &map_sz);
1612*5113495bSYour Name 
1613*5113495bSYour Name 		map_len = map_sz / sizeof(struct service_to_pipe);
1614*5113495bSYour Name 		for (i = 0; i < map_len; i++) {
1615*5113495bSYour Name 			if ((svc_map[i].pipenum == ce_state->id) &&
1616*5113495bSYour Name 			    ((svc_map[i].service_id == HTT_DATA_MSG_SVC)  ||
1617*5113495bSYour Name 			     (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
1618*5113495bSYour Name 			     (svc_map[i].service_id == HTT_DATA3_MSG_SVC)) &&
1619*5113495bSYour Name 			    (svc_map[i].pipedir == PIPEDIR_IN))
1620*5113495bSYour Name 				ce_state->htt_rx_data = true;
1621*5113495bSYour Name 			else if ((svc_map[i].pipenum == ce_state->id) &&
1622*5113495bSYour Name 				 (svc_map[i].service_id == HTT_DATA2_MSG_SVC) &&
1623*5113495bSYour Name 				 (svc_map[i].pipedir == PIPEDIR_OUT))
1624*5113495bSYour Name 				ce_state->htt_tx_data = true;
1625*5113495bSYour Name 		}
1626*5113495bSYour Name 	}
1627*5113495bSYour Name 
1628*5113495bSYour Name 	return (ce_state->htt_rx_data || ce_state->htt_tx_data);
1629*5113495bSYour Name }
1630*5113495bSYour Name 
ce_update_msi_batch_intr_flags(struct CE_state * ce_state)1631*5113495bSYour Name static void ce_update_msi_batch_intr_flags(struct CE_state *ce_state)
1632*5113495bSYour Name {
1633*5113495bSYour Name 	ce_state->msi_supported = true;
1634*5113495bSYour Name 	ce_state->batch_intr_supported = true;
1635*5113495bSYour Name }
1636*5113495bSYour Name 
ce_update_wrt_idx_offset(struct hif_softc * scn,struct CE_state * ce_state,struct CE_attr * attr)1637*5113495bSYour Name static inline void ce_update_wrt_idx_offset(struct hif_softc *scn,
1638*5113495bSYour Name 					    struct CE_state *ce_state,
1639*5113495bSYour Name 					    struct CE_attr *attr)
1640*5113495bSYour Name {
1641*5113495bSYour Name 	/* Do not setup CE write index offset for FW only CE rings */
1642*5113495bSYour Name 	if (!attr->src_nentries && !attr->dest_nentries)
1643*5113495bSYour Name 		return;
1644*5113495bSYour Name 
1645*5113495bSYour Name 	if (attr->src_nentries)
1646*5113495bSYour Name 		ce_state->ce_wrt_idx_offset =
1647*5113495bSYour Name 			CE_SRC_WR_IDX_OFFSET_GET(scn, ce_state->ctrl_addr);
1648*5113495bSYour Name 	else if (attr->dest_nentries)
1649*5113495bSYour Name 		ce_state->ce_wrt_idx_offset =
1650*5113495bSYour Name 			CE_DST_WR_IDX_OFFSET_GET(scn, ce_state->ctrl_addr);
1651*5113495bSYour Name 	else
1652*5113495bSYour Name 		QDF_BUG(0);
1653*5113495bSYour Name }
1654*5113495bSYour Name 
1655*5113495bSYour Name /*
1656*5113495bSYour Name  * hif_ce_print_ring_stats() - Print ce ring statistics
1657*5113495bSYour Name  *
1658*5113495bSYour Name  * @hif_ctx: hif context
1659*5113495bSYour Name  *
1660*5113495bSYour Name  * Returns: None
1661*5113495bSYour Name  */
hif_ce_print_ring_stats(struct hif_opaque_softc * hif_ctx)1662*5113495bSYour Name void hif_ce_print_ring_stats(struct hif_opaque_softc *hif_ctx)
1663*5113495bSYour Name {
1664*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1665*5113495bSYour Name 	struct CE_state *ce_state;
1666*5113495bSYour Name 	int i;
1667*5113495bSYour Name 
1668*5113495bSYour Name 	for (i = 0; i < scn->ce_count; i++) {
1669*5113495bSYour Name 		ce_state = scn->ce_id_to_state[i];
1670*5113495bSYour Name 		if (!ce_state)
1671*5113495bSYour Name 			continue;
1672*5113495bSYour Name 
1673*5113495bSYour Name 		if (ce_state->src_ring) {
1674*5113495bSYour Name 			QDF_TRACE(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_FATAL,
1675*5113495bSYour Name 				  "ce%d:SW: sw_index %u write_index %u",
1676*5113495bSYour Name 				  ce_state->src_ring->sw_index,
1677*5113495bSYour Name 				  ce_state->src_ring->write_index);
1678*5113495bSYour Name 
1679*5113495bSYour Name 			QDF_TRACE(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_FATAL,
1680*5113495bSYour Name 				  "ce%d:HW: read_index %u write_index %u",
1681*5113495bSYour Name 				  CE_SRC_RING_READ_IDX_GET_FROM_REGISTER(scn, ce_state->ctrl_addr),
1682*5113495bSYour Name 				  CE_SRC_RING_WRITE_IDX_GET_FROM_REGISTER(scn, ce_state->ctrl_addr));
1683*5113495bSYour Name 		}
1684*5113495bSYour Name 
1685*5113495bSYour Name 		if (ce_state->dest_ring) {
1686*5113495bSYour Name 			QDF_TRACE(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_FATAL,
1687*5113495bSYour Name 				  "ce%d:SW: sw_index %u write_index %u",
1688*5113495bSYour Name 				  ce_state->dest_ring->sw_index,
1689*5113495bSYour Name 				  ce_state->dest_ring->write_index);
1690*5113495bSYour Name 
1691*5113495bSYour Name 			QDF_TRACE(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_FATAL,
1692*5113495bSYour Name 				  "ce%d:HW: read_index %u write_index %u",
1693*5113495bSYour Name 				  CE_DEST_RING_READ_IDX_GET_FROM_REGISTER(scn, ce_state->ctrl_addr),
1694*5113495bSYour Name 				  CE_DEST_RING_WRITE_IDX_GET_FROM_REGISTER(scn, ce_state->ctrl_addr));
1695*5113495bSYour Name 		}
1696*5113495bSYour Name 	}
1697*5113495bSYour Name }
1698*5113495bSYour Name #endif
1699*5113495bSYour Name 
1700*5113495bSYour Name /**
1701*5113495bSYour Name  * hif_get_max_wmi_ep() - Get max WMI EPs configured in target svc map
1702*5113495bSYour Name  * @hif_ctx: hif opaque handle
1703*5113495bSYour Name  *
1704*5113495bSYour Name  * Description:
1705*5113495bSYour Name  *   Gets number of WMI EPs configured in target svc map. Since EP map
1706*5113495bSYour Name  *   include IN and OUT direction pipes, count only OUT pipes to get EPs
1707*5113495bSYour Name  *   configured for WMI service.
1708*5113495bSYour Name  *
1709*5113495bSYour Name  * Return:
1710*5113495bSYour Name  *  uint8_t: count for WMI eps in target svc map
1711*5113495bSYour Name  */
hif_get_max_wmi_ep(struct hif_opaque_softc * hif_ctx)1712*5113495bSYour Name uint8_t hif_get_max_wmi_ep(struct hif_opaque_softc *hif_ctx)
1713*5113495bSYour Name {
1714*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1715*5113495bSYour Name 	struct service_to_pipe *svc_map;
1716*5113495bSYour Name 	uint32_t map_sz, map_len;
1717*5113495bSYour Name 	int    i;
1718*5113495bSYour Name 	uint8_t   wmi_ep_count = 0;
1719*5113495bSYour Name 
1720*5113495bSYour Name 	hif_select_service_to_pipe_map(scn, &svc_map,
1721*5113495bSYour Name 				       &map_sz);
1722*5113495bSYour Name 	map_len = map_sz / sizeof(struct service_to_pipe);
1723*5113495bSYour Name 
1724*5113495bSYour Name 	for (i = 0; i < map_len; i++) {
1725*5113495bSYour Name 		/* Count number of WMI EPs based on out direction */
1726*5113495bSYour Name 		if ((svc_map[i].pipedir == PIPEDIR_OUT) &&
1727*5113495bSYour Name 		    ((svc_map[i].service_id == WMI_CONTROL_SVC)  ||
1728*5113495bSYour Name 		    (svc_map[i].service_id == WMI_CONTROL_SVC_WMAC1) ||
1729*5113495bSYour Name 		    (svc_map[i].service_id == WMI_CONTROL_SVC_WMAC2))) {
1730*5113495bSYour Name 			wmi_ep_count++;
1731*5113495bSYour Name 		}
1732*5113495bSYour Name 	}
1733*5113495bSYour Name 
1734*5113495bSYour Name 	return wmi_ep_count;
1735*5113495bSYour Name }
1736*5113495bSYour Name 
1737*5113495bSYour Name /**
1738*5113495bSYour Name  * ce_ring_test_initial_indexes() - tests the initial ce ring indexes
1739*5113495bSYour Name  * @ce_id: ce in question
1740*5113495bSYour Name  * @ring: ring state being examined
1741*5113495bSYour Name  * @type: "src_ring" or "dest_ring" string for identifying the ring
1742*5113495bSYour Name  *
1743*5113495bSYour Name  * Warns on non-zero index values.
1744*5113495bSYour Name  * Causes a kernel panic if the ring is not empty during initialization.
1745*5113495bSYour Name  */
ce_ring_test_initial_indexes(int ce_id,struct CE_ring_state * ring,char * type)1746*5113495bSYour Name static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring,
1747*5113495bSYour Name 					 char *type)
1748*5113495bSYour Name {
1749*5113495bSYour Name 	if (ring->write_index != 0 || ring->sw_index != 0)
1750*5113495bSYour Name 		hif_err("ce %d, %s, initial sw_index = %d, initial write_index =%d",
1751*5113495bSYour Name 			  ce_id, type, ring->sw_index, ring->write_index);
1752*5113495bSYour Name 	if (ring->write_index != ring->sw_index)
1753*5113495bSYour Name 		QDF_BUG(0);
1754*5113495bSYour Name }
1755*5113495bSYour Name 
1756*5113495bSYour Name #ifdef IPA_OFFLOAD
1757*5113495bSYour Name /**
1758*5113495bSYour Name  * ce_alloc_desc_ring() - Allocate copyengine descriptor ring
1759*5113495bSYour Name  * @scn: softc instance
1760*5113495bSYour Name  * @CE_id: ce in question
1761*5113495bSYour Name  * @base_addr: pointer to copyengine ring base address
1762*5113495bSYour Name  * @ce_ring: copyengine instance
1763*5113495bSYour Name  * @nentries: number of entries should be allocated
1764*5113495bSYour Name  * @desc_size: ce desc size
1765*5113495bSYour Name  *
1766*5113495bSYour Name  * Return: QDF_STATUS_SUCCESS - for success
1767*5113495bSYour Name  */
ce_alloc_desc_ring(struct hif_softc * scn,unsigned int CE_id,qdf_dma_addr_t * base_addr,struct CE_ring_state * ce_ring,unsigned int nentries,uint32_t desc_size)1768*5113495bSYour Name static QDF_STATUS ce_alloc_desc_ring(struct hif_softc *scn, unsigned int CE_id,
1769*5113495bSYour Name 				     qdf_dma_addr_t *base_addr,
1770*5113495bSYour Name 				     struct CE_ring_state *ce_ring,
1771*5113495bSYour Name 				     unsigned int nentries, uint32_t desc_size)
1772*5113495bSYour Name {
1773*5113495bSYour Name 	if ((CE_id == HIF_PCI_IPA_UC_ASSIGNED_CE) &&
1774*5113495bSYour Name 	    !ce_srng_based(scn)) {
1775*5113495bSYour Name 		if (!scn->ipa_ce_ring) {
1776*5113495bSYour Name 			scn->ipa_ce_ring = qdf_mem_shared_mem_alloc(
1777*5113495bSYour Name 				scn->qdf_dev,
1778*5113495bSYour Name 				nentries * desc_size + CE_DESC_RING_ALIGN);
1779*5113495bSYour Name 			if (!scn->ipa_ce_ring) {
1780*5113495bSYour Name 				hif_err(
1781*5113495bSYour Name 				"Failed to allocate memory for IPA ce ring");
1782*5113495bSYour Name 				return QDF_STATUS_E_NOMEM;
1783*5113495bSYour Name 			}
1784*5113495bSYour Name 		}
1785*5113495bSYour Name 		*base_addr = qdf_mem_get_dma_addr(scn->qdf_dev,
1786*5113495bSYour Name 						&scn->ipa_ce_ring->mem_info);
1787*5113495bSYour Name 		ce_ring->base_addr_owner_space_unaligned =
1788*5113495bSYour Name 						scn->ipa_ce_ring->vaddr;
1789*5113495bSYour Name 	} else {
1790*5113495bSYour Name 		ce_ring->base_addr_owner_space_unaligned =
1791*5113495bSYour Name 			hif_mem_alloc_consistent_unaligned
1792*5113495bSYour Name 					(scn,
1793*5113495bSYour Name 					 (nentries * desc_size +
1794*5113495bSYour Name 					  CE_DESC_RING_ALIGN),
1795*5113495bSYour Name 					 base_addr,
1796*5113495bSYour Name 					 ce_ring->hal_ring_type,
1797*5113495bSYour Name 					 &ce_ring->is_ring_prealloc);
1798*5113495bSYour Name 
1799*5113495bSYour Name 		if (!ce_ring->base_addr_owner_space_unaligned) {
1800*5113495bSYour Name 			hif_err("Failed to allocate DMA memory for ce ring id: %u",
1801*5113495bSYour Name 			       CE_id);
1802*5113495bSYour Name 			return QDF_STATUS_E_NOMEM;
1803*5113495bSYour Name 		}
1804*5113495bSYour Name 	}
1805*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1806*5113495bSYour Name }
1807*5113495bSYour Name 
1808*5113495bSYour Name /**
1809*5113495bSYour Name  * ce_free_desc_ring() - Frees copyengine descriptor ring
1810*5113495bSYour Name  * @scn: softc instance
1811*5113495bSYour Name  * @CE_id: ce in question
1812*5113495bSYour Name  * @ce_ring: copyengine instance
1813*5113495bSYour Name  * @desc_size: ce desc size
1814*5113495bSYour Name  *
1815*5113495bSYour Name  * Return: None
1816*5113495bSYour Name  */
ce_free_desc_ring(struct hif_softc * scn,unsigned int CE_id,struct CE_ring_state * ce_ring,uint32_t desc_size)1817*5113495bSYour Name static void ce_free_desc_ring(struct hif_softc *scn, unsigned int CE_id,
1818*5113495bSYour Name 			      struct CE_ring_state *ce_ring, uint32_t desc_size)
1819*5113495bSYour Name {
1820*5113495bSYour Name 	if ((CE_id == HIF_PCI_IPA_UC_ASSIGNED_CE) &&
1821*5113495bSYour Name 	    !ce_srng_based(scn)) {
1822*5113495bSYour Name 		if (scn->ipa_ce_ring) {
1823*5113495bSYour Name 			qdf_mem_shared_mem_free(scn->qdf_dev,
1824*5113495bSYour Name 						scn->ipa_ce_ring);
1825*5113495bSYour Name 			scn->ipa_ce_ring = NULL;
1826*5113495bSYour Name 		}
1827*5113495bSYour Name 		ce_ring->base_addr_owner_space_unaligned = NULL;
1828*5113495bSYour Name 	} else {
1829*5113495bSYour Name 		hif_mem_free_consistent_unaligned
1830*5113495bSYour Name 			(scn,
1831*5113495bSYour Name 			 ce_ring->nentries * desc_size + CE_DESC_RING_ALIGN,
1832*5113495bSYour Name 			 ce_ring->base_addr_owner_space_unaligned,
1833*5113495bSYour Name 			 ce_ring->base_addr_CE_space, 0,
1834*5113495bSYour Name 			 ce_ring->is_ring_prealloc);
1835*5113495bSYour Name 		ce_ring->base_addr_owner_space_unaligned = NULL;
1836*5113495bSYour Name 	}
1837*5113495bSYour Name }
1838*5113495bSYour Name #else
ce_alloc_desc_ring(struct hif_softc * scn,unsigned int CE_id,qdf_dma_addr_t * base_addr,struct CE_ring_state * ce_ring,unsigned int nentries,uint32_t desc_size)1839*5113495bSYour Name static QDF_STATUS ce_alloc_desc_ring(struct hif_softc *scn, unsigned int CE_id,
1840*5113495bSYour Name 				     qdf_dma_addr_t *base_addr,
1841*5113495bSYour Name 				     struct CE_ring_state *ce_ring,
1842*5113495bSYour Name 				     unsigned int nentries, uint32_t desc_size)
1843*5113495bSYour Name {
1844*5113495bSYour Name 	ce_ring->base_addr_owner_space_unaligned =
1845*5113495bSYour Name 			hif_mem_alloc_consistent_unaligned
1846*5113495bSYour Name 					(scn,
1847*5113495bSYour Name 					 (nentries * desc_size +
1848*5113495bSYour Name 					  CE_DESC_RING_ALIGN),
1849*5113495bSYour Name 					 base_addr,
1850*5113495bSYour Name 					 ce_ring->hal_ring_type,
1851*5113495bSYour Name 					 &ce_ring->is_ring_prealloc);
1852*5113495bSYour Name 
1853*5113495bSYour Name 	if (!ce_ring->base_addr_owner_space_unaligned) {
1854*5113495bSYour Name 		hif_err("Failed to allocate DMA memory for ce ring id: %u",
1855*5113495bSYour Name 		       CE_id);
1856*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
1857*5113495bSYour Name 	}
1858*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
1859*5113495bSYour Name }
1860*5113495bSYour Name 
ce_free_desc_ring(struct hif_softc * scn,unsigned int CE_id,struct CE_ring_state * ce_ring,uint32_t desc_size)1861*5113495bSYour Name static void ce_free_desc_ring(struct hif_softc *scn, unsigned int CE_id,
1862*5113495bSYour Name 			      struct CE_ring_state *ce_ring, uint32_t desc_size)
1863*5113495bSYour Name {
1864*5113495bSYour Name 	hif_mem_free_consistent_unaligned
1865*5113495bSYour Name 		(scn,
1866*5113495bSYour Name 		 ce_ring->nentries * desc_size + CE_DESC_RING_ALIGN,
1867*5113495bSYour Name 		 ce_ring->base_addr_owner_space_unaligned,
1868*5113495bSYour Name 		 ce_ring->base_addr_CE_space, 0,
1869*5113495bSYour Name 		 ce_ring->is_ring_prealloc);
1870*5113495bSYour Name 	ce_ring->base_addr_owner_space_unaligned = NULL;
1871*5113495bSYour Name }
1872*5113495bSYour Name #endif /* IPA_OFFLOAD */
1873*5113495bSYour Name 
1874*5113495bSYour Name /*
1875*5113495bSYour Name  * TODO: Need to explore the possibility of having this as part of a
1876*5113495bSYour Name  * target context instead of a global array.
1877*5113495bSYour Name  */
1878*5113495bSYour Name static struct ce_ops* (*ce_attach_register[CE_MAX_TARGET_TYPE])(void);
1879*5113495bSYour Name 
ce_service_register_module(enum ce_target_type target_type,struct ce_ops * (* ce_attach)(void))1880*5113495bSYour Name void ce_service_register_module(enum ce_target_type target_type,
1881*5113495bSYour Name 				struct ce_ops* (*ce_attach)(void))
1882*5113495bSYour Name {
1883*5113495bSYour Name 	if (target_type < CE_MAX_TARGET_TYPE)
1884*5113495bSYour Name 		ce_attach_register[target_type] = ce_attach;
1885*5113495bSYour Name }
1886*5113495bSYour Name 
1887*5113495bSYour Name qdf_export_symbol(ce_service_register_module);
1888*5113495bSYour Name 
1889*5113495bSYour Name /**
1890*5113495bSYour Name  * ce_srng_based() - Does this target use srng
1891*5113495bSYour Name  * @scn: pointer to the state context of the CE
1892*5113495bSYour Name  *
1893*5113495bSYour Name  * Description:
1894*5113495bSYour Name  *   returns true if the target is SRNG based
1895*5113495bSYour Name  *
1896*5113495bSYour Name  * Return:
1897*5113495bSYour Name  *  false (attribute set to false)
1898*5113495bSYour Name  *  true  (attribute set to true);
1899*5113495bSYour Name  */
ce_srng_based(struct hif_softc * scn)1900*5113495bSYour Name bool ce_srng_based(struct hif_softc *scn)
1901*5113495bSYour Name {
1902*5113495bSYour Name 	struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
1903*5113495bSYour Name 	struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
1904*5113495bSYour Name 
1905*5113495bSYour Name 	switch (tgt_info->target_type) {
1906*5113495bSYour Name 	case TARGET_TYPE_QCA8074:
1907*5113495bSYour Name 	case TARGET_TYPE_QCA8074V2:
1908*5113495bSYour Name 	case TARGET_TYPE_QCA6290:
1909*5113495bSYour Name 	case TARGET_TYPE_QCA6390:
1910*5113495bSYour Name 	case TARGET_TYPE_QCA6490:
1911*5113495bSYour Name 	case TARGET_TYPE_QCA6750:
1912*5113495bSYour Name 	case TARGET_TYPE_QCA6018:
1913*5113495bSYour Name 	case TARGET_TYPE_QCN9000:
1914*5113495bSYour Name 	case TARGET_TYPE_QCN6122:
1915*5113495bSYour Name 	case TARGET_TYPE_QCN9160:
1916*5113495bSYour Name 	case TARGET_TYPE_QCA5018:
1917*5113495bSYour Name 	case TARGET_TYPE_KIWI:
1918*5113495bSYour Name 	case TARGET_TYPE_MANGO:
1919*5113495bSYour Name 	case TARGET_TYPE_PEACH:
1920*5113495bSYour Name 	case TARGET_TYPE_QCN9224:
1921*5113495bSYour Name 	case TARGET_TYPE_QCA9574:
1922*5113495bSYour Name 	case TARGET_TYPE_QCA5332:
1923*5113495bSYour Name 	case TARGET_TYPE_QCN6432:
1924*5113495bSYour Name 		return true;
1925*5113495bSYour Name 	default:
1926*5113495bSYour Name 		return false;
1927*5113495bSYour Name 	}
1928*5113495bSYour Name 	return false;
1929*5113495bSYour Name }
1930*5113495bSYour Name qdf_export_symbol(ce_srng_based);
1931*5113495bSYour Name 
1932*5113495bSYour Name #ifdef QCA_WIFI_SUPPORT_SRNG
ce_services_attach(struct hif_softc * scn)1933*5113495bSYour Name static struct ce_ops *ce_services_attach(struct hif_softc *scn)
1934*5113495bSYour Name {
1935*5113495bSYour Name 	struct ce_ops *ops = NULL;
1936*5113495bSYour Name 
1937*5113495bSYour Name 	if (ce_srng_based(scn)) {
1938*5113495bSYour Name 		if (ce_attach_register[CE_SVC_SRNG])
1939*5113495bSYour Name 			ops = ce_attach_register[CE_SVC_SRNG]();
1940*5113495bSYour Name 	} else if (ce_attach_register[CE_SVC_LEGACY]) {
1941*5113495bSYour Name 		ops = ce_attach_register[CE_SVC_LEGACY]();
1942*5113495bSYour Name 	}
1943*5113495bSYour Name 
1944*5113495bSYour Name 	return ops;
1945*5113495bSYour Name }
1946*5113495bSYour Name 
1947*5113495bSYour Name 
1948*5113495bSYour Name #else	/* QCA_LITHIUM */
ce_services_attach(struct hif_softc * scn)1949*5113495bSYour Name static struct ce_ops *ce_services_attach(struct hif_softc *scn)
1950*5113495bSYour Name {
1951*5113495bSYour Name 	if (ce_attach_register[CE_SVC_LEGACY])
1952*5113495bSYour Name 		return ce_attach_register[CE_SVC_LEGACY]();
1953*5113495bSYour Name 
1954*5113495bSYour Name 	return NULL;
1955*5113495bSYour Name }
1956*5113495bSYour Name #endif /* QCA_LITHIUM */
1957*5113495bSYour Name 
hif_prepare_hal_shadow_register_cfg(struct hif_softc * scn,struct pld_shadow_reg_v2_cfg ** shadow_config,int * num_shadow_registers_configured)1958*5113495bSYour Name static void hif_prepare_hal_shadow_register_cfg(struct hif_softc *scn,
1959*5113495bSYour Name 		struct pld_shadow_reg_v2_cfg **shadow_config,
1960*5113495bSYour Name 		int *num_shadow_registers_configured) {
1961*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1962*5113495bSYour Name 
1963*5113495bSYour Name 	hif_state->ce_services->ce_prepare_shadow_register_v2_cfg(
1964*5113495bSYour Name 			scn, shadow_config, num_shadow_registers_configured);
1965*5113495bSYour Name 
1966*5113495bSYour Name 	return;
1967*5113495bSYour Name }
1968*5113495bSYour Name 
1969*5113495bSYour Name #ifdef CONFIG_SHADOW_V3
1970*5113495bSYour Name static inline void
hif_prepare_hal_shadow_reg_cfg_v3(struct hif_softc * scn,struct pld_wlan_enable_cfg * cfg)1971*5113495bSYour Name hif_prepare_hal_shadow_reg_cfg_v3(struct hif_softc *scn,
1972*5113495bSYour Name 				  struct pld_wlan_enable_cfg *cfg)
1973*5113495bSYour Name {
1974*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1975*5113495bSYour Name 
1976*5113495bSYour Name 	if (!hif_state->ce_services->ce_prepare_shadow_register_v3_cfg)
1977*5113495bSYour Name 		return;
1978*5113495bSYour Name 
1979*5113495bSYour Name 	hif_state->ce_services->ce_prepare_shadow_register_v3_cfg(
1980*5113495bSYour Name 			scn, &cfg->shadow_reg_v3_cfg,
1981*5113495bSYour Name 			&cfg->num_shadow_reg_v3_cfg);
1982*5113495bSYour Name }
1983*5113495bSYour Name #else
1984*5113495bSYour Name static inline void
hif_prepare_hal_shadow_reg_cfg_v3(struct hif_softc * scn,struct pld_wlan_enable_cfg * cfg)1985*5113495bSYour Name hif_prepare_hal_shadow_reg_cfg_v3(struct hif_softc *scn,
1986*5113495bSYour Name 				  struct pld_wlan_enable_cfg *cfg)
1987*5113495bSYour Name {
1988*5113495bSYour Name }
1989*5113495bSYour Name #endif
1990*5113495bSYour Name 
ce_get_desc_size(struct hif_softc * scn,uint8_t ring_type)1991*5113495bSYour Name static inline uint32_t ce_get_desc_size(struct hif_softc *scn,
1992*5113495bSYour Name 						uint8_t ring_type)
1993*5113495bSYour Name {
1994*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1995*5113495bSYour Name 
1996*5113495bSYour Name 	return hif_state->ce_services->ce_get_desc_size(ring_type);
1997*5113495bSYour Name }
1998*5113495bSYour Name 
1999*5113495bSYour Name #ifdef QCA_WIFI_SUPPORT_SRNG
ce_ring_type_to_hal_ring_type(uint32_t ce_ring_type)2000*5113495bSYour Name static inline int32_t ce_ring_type_to_hal_ring_type(uint32_t ce_ring_type)
2001*5113495bSYour Name {
2002*5113495bSYour Name 	switch (ce_ring_type) {
2003*5113495bSYour Name 	case CE_RING_SRC:
2004*5113495bSYour Name 		return CE_SRC;
2005*5113495bSYour Name 	case CE_RING_DEST:
2006*5113495bSYour Name 		return CE_DST;
2007*5113495bSYour Name 	case CE_RING_STATUS:
2008*5113495bSYour Name 		return CE_DST_STATUS;
2009*5113495bSYour Name 	default:
2010*5113495bSYour Name 		return -EINVAL;
2011*5113495bSYour Name 	}
2012*5113495bSYour Name }
2013*5113495bSYour Name #else
ce_ring_type_to_hal_ring_type(uint32_t ce_ring_type)2014*5113495bSYour Name static int32_t ce_ring_type_to_hal_ring_type(uint32_t ce_ring_type)
2015*5113495bSYour Name {
2016*5113495bSYour Name 	return 0;
2017*5113495bSYour Name }
2018*5113495bSYour Name #endif
ce_alloc_ring_state(struct CE_state * CE_state,uint8_t ring_type,uint32_t nentries)2019*5113495bSYour Name static struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state,
2020*5113495bSYour Name 		uint8_t ring_type, uint32_t nentries)
2021*5113495bSYour Name {
2022*5113495bSYour Name 	uint32_t ce_nbytes;
2023*5113495bSYour Name 	char *ptr;
2024*5113495bSYour Name 	qdf_dma_addr_t base_addr;
2025*5113495bSYour Name 	struct CE_ring_state *ce_ring;
2026*5113495bSYour Name 	uint32_t desc_size;
2027*5113495bSYour Name 	struct hif_softc *scn = CE_state->scn;
2028*5113495bSYour Name 
2029*5113495bSYour Name 	ce_nbytes = sizeof(struct CE_ring_state)
2030*5113495bSYour Name 		+ (nentries * sizeof(void *));
2031*5113495bSYour Name 	ptr = qdf_mem_malloc(ce_nbytes);
2032*5113495bSYour Name 	if (!ptr)
2033*5113495bSYour Name 		return NULL;
2034*5113495bSYour Name 
2035*5113495bSYour Name 	ce_ring = (struct CE_ring_state *)ptr;
2036*5113495bSYour Name 	ptr += sizeof(struct CE_ring_state);
2037*5113495bSYour Name 	ce_ring->nentries = nentries;
2038*5113495bSYour Name 	ce_ring->nentries_mask = nentries - 1;
2039*5113495bSYour Name 
2040*5113495bSYour Name 	ce_ring->low_water_mark_nentries = 0;
2041*5113495bSYour Name 	ce_ring->high_water_mark_nentries = nentries;
2042*5113495bSYour Name 	ce_ring->per_transfer_context = (void **)ptr;
2043*5113495bSYour Name 	ce_ring->hal_ring_type = ce_ring_type_to_hal_ring_type(ring_type);
2044*5113495bSYour Name 
2045*5113495bSYour Name 	desc_size = ce_get_desc_size(scn, ring_type);
2046*5113495bSYour Name 
2047*5113495bSYour Name 	/* Legacy platforms that do not support cache
2048*5113495bSYour Name 	 * coherent DMA are unsupported
2049*5113495bSYour Name 	 */
2050*5113495bSYour Name 	if (ce_alloc_desc_ring(scn, CE_state->id, &base_addr,
2051*5113495bSYour Name 			       ce_ring, nentries,
2052*5113495bSYour Name 			       desc_size) !=
2053*5113495bSYour Name 	    QDF_STATUS_SUCCESS) {
2054*5113495bSYour Name 		hif_err("ring has no DMA mem");
2055*5113495bSYour Name 		qdf_mem_free(ce_ring);
2056*5113495bSYour Name 		return NULL;
2057*5113495bSYour Name 	}
2058*5113495bSYour Name 	ce_ring->base_addr_CE_space_unaligned = base_addr;
2059*5113495bSYour Name 
2060*5113495bSYour Name 	/* Correctly initialize memory to 0 to
2061*5113495bSYour Name 	 * prevent garbage data crashing system
2062*5113495bSYour Name 	 * when download firmware
2063*5113495bSYour Name 	 */
2064*5113495bSYour Name 	qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned,
2065*5113495bSYour Name 			nentries * desc_size +
2066*5113495bSYour Name 			CE_DESC_RING_ALIGN);
2067*5113495bSYour Name 
2068*5113495bSYour Name 	if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) {
2069*5113495bSYour Name 
2070*5113495bSYour Name 		ce_ring->base_addr_CE_space =
2071*5113495bSYour Name 			(ce_ring->base_addr_CE_space_unaligned +
2072*5113495bSYour Name 			 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1);
2073*5113495bSYour Name 
2074*5113495bSYour Name 		ce_ring->base_addr_owner_space = (void *)
2075*5113495bSYour Name 			(((size_t) ce_ring->base_addr_owner_space_unaligned +
2076*5113495bSYour Name 			 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1));
2077*5113495bSYour Name 	} else {
2078*5113495bSYour Name 		ce_ring->base_addr_CE_space =
2079*5113495bSYour Name 				ce_ring->base_addr_CE_space_unaligned;
2080*5113495bSYour Name 		ce_ring->base_addr_owner_space =
2081*5113495bSYour Name 				ce_ring->base_addr_owner_space_unaligned;
2082*5113495bSYour Name 	}
2083*5113495bSYour Name 
2084*5113495bSYour Name 	return ce_ring;
2085*5113495bSYour Name }
2086*5113495bSYour Name 
ce_ring_setup(struct hif_softc * scn,uint8_t ring_type,uint32_t ce_id,struct CE_ring_state * ring,struct CE_attr * attr)2087*5113495bSYour Name static int ce_ring_setup(struct hif_softc *scn, uint8_t ring_type,
2088*5113495bSYour Name 			uint32_t ce_id, struct CE_ring_state *ring,
2089*5113495bSYour Name 			struct CE_attr *attr)
2090*5113495bSYour Name {
2091*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2092*5113495bSYour Name 
2093*5113495bSYour Name 	return hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id,
2094*5113495bSYour Name 					      ring, attr);
2095*5113495bSYour Name }
2096*5113495bSYour Name 
ce_srng_cleanup(struct hif_softc * scn,struct CE_state * CE_state,uint8_t ring_type)2097*5113495bSYour Name static void ce_srng_cleanup(struct hif_softc *scn, struct CE_state *CE_state,
2098*5113495bSYour Name 			    uint8_t ring_type)
2099*5113495bSYour Name {
2100*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2101*5113495bSYour Name 
2102*5113495bSYour Name 	if (hif_state->ce_services->ce_srng_cleanup)
2103*5113495bSYour Name 		hif_state->ce_services->ce_srng_cleanup(scn,
2104*5113495bSYour Name 					CE_state, ring_type);
2105*5113495bSYour Name }
2106*5113495bSYour Name 
hif_ce_bus_early_suspend(struct hif_softc * scn)2107*5113495bSYour Name int hif_ce_bus_early_suspend(struct hif_softc *scn)
2108*5113495bSYour Name {
2109*5113495bSYour Name 	uint8_t ul_pipe, dl_pipe;
2110*5113495bSYour Name 	int ce_id, status, ul_is_polled, dl_is_polled;
2111*5113495bSYour Name 	struct CE_state *ce_state;
2112*5113495bSYour Name 
2113*5113495bSYour Name 	status = hif_map_service_to_pipe(&scn->osc, WMI_CONTROL_SVC,
2114*5113495bSYour Name 					 &ul_pipe, &dl_pipe,
2115*5113495bSYour Name 					 &ul_is_polled, &dl_is_polled);
2116*5113495bSYour Name 	if (status) {
2117*5113495bSYour Name 		hif_err("pipe_mapping failure");
2118*5113495bSYour Name 		return status;
2119*5113495bSYour Name 	}
2120*5113495bSYour Name 
2121*5113495bSYour Name 	for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
2122*5113495bSYour Name 		if (ce_id == ul_pipe)
2123*5113495bSYour Name 			continue;
2124*5113495bSYour Name 		if (ce_id == dl_pipe)
2125*5113495bSYour Name 			continue;
2126*5113495bSYour Name 
2127*5113495bSYour Name 		ce_state = scn->ce_id_to_state[ce_id];
2128*5113495bSYour Name 		qdf_spin_lock_bh(&ce_state->ce_index_lock);
2129*5113495bSYour Name 		if (ce_state->state == CE_RUNNING)
2130*5113495bSYour Name 			ce_state->state = CE_PAUSED;
2131*5113495bSYour Name 		qdf_spin_unlock_bh(&ce_state->ce_index_lock);
2132*5113495bSYour Name 	}
2133*5113495bSYour Name 
2134*5113495bSYour Name 	return status;
2135*5113495bSYour Name }
2136*5113495bSYour Name 
hif_ce_bus_late_resume(struct hif_softc * scn)2137*5113495bSYour Name int hif_ce_bus_late_resume(struct hif_softc *scn)
2138*5113495bSYour Name {
2139*5113495bSYour Name 	int ce_id;
2140*5113495bSYour Name 	struct CE_state *ce_state;
2141*5113495bSYour Name 	int write_index = 0;
2142*5113495bSYour Name 	bool index_updated;
2143*5113495bSYour Name 
2144*5113495bSYour Name 	for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
2145*5113495bSYour Name 		ce_state = scn->ce_id_to_state[ce_id];
2146*5113495bSYour Name 		qdf_spin_lock_bh(&ce_state->ce_index_lock);
2147*5113495bSYour Name 		if (ce_state->state == CE_PENDING) {
2148*5113495bSYour Name 			write_index = ce_state->src_ring->write_index;
2149*5113495bSYour Name 			CE_SRC_RING_WRITE_IDX_SET(scn, ce_state->ctrl_addr,
2150*5113495bSYour Name 					write_index);
2151*5113495bSYour Name 			ce_state->state = CE_RUNNING;
2152*5113495bSYour Name 			index_updated = true;
2153*5113495bSYour Name 		} else {
2154*5113495bSYour Name 			index_updated = false;
2155*5113495bSYour Name 		}
2156*5113495bSYour Name 
2157*5113495bSYour Name 		if (ce_state->state == CE_PAUSED)
2158*5113495bSYour Name 			ce_state->state = CE_RUNNING;
2159*5113495bSYour Name 		qdf_spin_unlock_bh(&ce_state->ce_index_lock);
2160*5113495bSYour Name 
2161*5113495bSYour Name 		if (index_updated)
2162*5113495bSYour Name 			hif_record_ce_desc_event(scn, ce_id,
2163*5113495bSYour Name 				RESUME_WRITE_INDEX_UPDATE,
2164*5113495bSYour Name 				NULL, NULL, write_index, 0);
2165*5113495bSYour Name 	}
2166*5113495bSYour Name 
2167*5113495bSYour Name 	return 0;
2168*5113495bSYour Name }
2169*5113495bSYour Name 
2170*5113495bSYour Name /**
2171*5113495bSYour Name  * ce_oom_recovery() - try to recover rx ce from oom condition
2172*5113495bSYour Name  * @context: CE_state of the CE with oom rx ring
2173*5113495bSYour Name  *
2174*5113495bSYour Name  * the executing work Will continue to be rescheduled until
2175*5113495bSYour Name  * at least 1 descriptor is successfully posted to the rx ring.
2176*5113495bSYour Name  *
2177*5113495bSYour Name  * return: none
2178*5113495bSYour Name  */
ce_oom_recovery(void * context)2179*5113495bSYour Name static void ce_oom_recovery(void *context)
2180*5113495bSYour Name {
2181*5113495bSYour Name 	struct CE_state *ce_state = context;
2182*5113495bSYour Name 	struct hif_softc *scn = ce_state->scn;
2183*5113495bSYour Name 	struct HIF_CE_state *ce_softc = HIF_GET_CE_STATE(scn);
2184*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info =
2185*5113495bSYour Name 		&ce_softc->pipe_info[ce_state->id];
2186*5113495bSYour Name 
2187*5113495bSYour Name 	hif_post_recv_buffers_for_pipe(pipe_info);
2188*5113495bSYour Name 
2189*5113495bSYour Name 	qdf_atomic_dec(&scn->active_oom_work_cnt);
2190*5113495bSYour Name }
2191*5113495bSYour Name 
2192*5113495bSYour Name #ifdef HIF_CE_DEBUG_DATA_BUF
2193*5113495bSYour Name /**
2194*5113495bSYour Name  * alloc_mem_ce_debug_hist_data() - Allocate mem for the data pointed by
2195*5113495bSYour Name  * the CE descriptors.
2196*5113495bSYour Name  * Allocate HIF_CE_HISTORY_MAX records by CE_DEBUG_MAX_DATA_BUF_SIZE
2197*5113495bSYour Name  * @scn: hif scn handle
2198*5113495bSYour Name  * @ce_id: Copy Engine Id
2199*5113495bSYour Name  *
2200*5113495bSYour Name  * Return: QDF_STATUS
2201*5113495bSYour Name  */
alloc_mem_ce_debug_hist_data(struct hif_softc * scn,uint32_t ce_id)2202*5113495bSYour Name QDF_STATUS alloc_mem_ce_debug_hist_data(struct hif_softc *scn, uint32_t ce_id)
2203*5113495bSYour Name {
2204*5113495bSYour Name 	struct hif_ce_desc_event *event = NULL;
2205*5113495bSYour Name 	struct hif_ce_desc_event *hist_ev = NULL;
2206*5113495bSYour Name 	uint32_t index = 0;
2207*5113495bSYour Name 
2208*5113495bSYour Name 	hist_ev =
2209*5113495bSYour Name 	(struct hif_ce_desc_event *)scn->hif_ce_desc_hist.hist_ev[ce_id];
2210*5113495bSYour Name 
2211*5113495bSYour Name 	if (!hist_ev)
2212*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
2213*5113495bSYour Name 
2214*5113495bSYour Name 	scn->hif_ce_desc_hist.data_enable[ce_id] = true;
2215*5113495bSYour Name 	for (index = 0; index < HIF_CE_HISTORY_MAX; index++) {
2216*5113495bSYour Name 		event = &hist_ev[index];
2217*5113495bSYour Name 		event->data =
2218*5113495bSYour Name 			(uint8_t *)qdf_mem_malloc(CE_DEBUG_MAX_DATA_BUF_SIZE);
2219*5113495bSYour Name 		if (!event->data) {
2220*5113495bSYour Name 			hif_err_rl("ce debug data alloc failed");
2221*5113495bSYour Name 			scn->hif_ce_desc_hist.data_enable[ce_id] = false;
2222*5113495bSYour Name 			return QDF_STATUS_E_NOMEM;
2223*5113495bSYour Name 		}
2224*5113495bSYour Name 	}
2225*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2226*5113495bSYour Name }
2227*5113495bSYour Name 
2228*5113495bSYour Name /**
2229*5113495bSYour Name  * free_mem_ce_debug_hist_data() - Free mem of the data pointed by
2230*5113495bSYour Name  * the CE descriptors.
2231*5113495bSYour Name  * @scn: hif scn handle
2232*5113495bSYour Name  * @ce_id: Copy Engine Id
2233*5113495bSYour Name  *
2234*5113495bSYour Name  * Return:
2235*5113495bSYour Name  */
free_mem_ce_debug_hist_data(struct hif_softc * scn,uint32_t ce_id)2236*5113495bSYour Name void free_mem_ce_debug_hist_data(struct hif_softc *scn, uint32_t ce_id)
2237*5113495bSYour Name {
2238*5113495bSYour Name 	struct hif_ce_desc_event *event = NULL;
2239*5113495bSYour Name 	struct hif_ce_desc_event *hist_ev = NULL;
2240*5113495bSYour Name 	uint32_t index = 0;
2241*5113495bSYour Name 
2242*5113495bSYour Name 	hist_ev =
2243*5113495bSYour Name 	(struct hif_ce_desc_event *)scn->hif_ce_desc_hist.hist_ev[ce_id];
2244*5113495bSYour Name 
2245*5113495bSYour Name 	if (!hist_ev)
2246*5113495bSYour Name 		return;
2247*5113495bSYour Name 
2248*5113495bSYour Name 	for (index = 0; index < HIF_CE_HISTORY_MAX; index++) {
2249*5113495bSYour Name 		event = &hist_ev[index];
2250*5113495bSYour Name 		if (event->data)
2251*5113495bSYour Name 			qdf_mem_free(event->data);
2252*5113495bSYour Name 		event->data = NULL;
2253*5113495bSYour Name 		event = NULL;
2254*5113495bSYour Name 	}
2255*5113495bSYour Name 
2256*5113495bSYour Name }
2257*5113495bSYour Name #endif /* HIF_CE_DEBUG_DATA_BUF */
2258*5113495bSYour Name 
2259*5113495bSYour Name #ifndef HIF_CE_DEBUG_DATA_DYNAMIC_BUF
2260*5113495bSYour Name #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF)
2261*5113495bSYour Name 
2262*5113495bSYour Name /* define below variables for crashscope parse */
2263*5113495bSYour Name struct hif_ce_desc_event *hif_ce_desc_history[CE_COUNT_MAX];
2264*5113495bSYour Name uint32_t hif_ce_history_max = HIF_CE_HISTORY_MAX;
2265*5113495bSYour Name uint32_t hif_ce_count_max = CE_COUNT_MAX;
2266*5113495bSYour Name 
2267*5113495bSYour Name /*
2268*5113495bSYour Name  * for debug build, it will enable ce history for all ce, but for
2269*5113495bSYour Name  * perf build(if CONFIG_SLUB_DEBUG_ON is N), it only enable for
2270*5113495bSYour Name  * ce2(wmi event) & ce3(wmi cmd) history.
2271*5113495bSYour Name  */
2272*5113495bSYour Name #if defined(CONFIG_SLUB_DEBUG_ON)
2273*5113495bSYour Name #define CE_DESC_HISTORY_BUFF_CNT  CE_COUNT_MAX
2274*5113495bSYour Name #define IS_CE_DEBUG_ONLY_FOR_CRIT_CE  0
2275*5113495bSYour Name #else
2276*5113495bSYour Name 
2277*5113495bSYour Name #ifdef QCA_WIFI_SUPPORT_SRNG
2278*5113495bSYour Name /* Enable CE-1 history only on targets not using CE-1 for datapath */
2279*5113495bSYour Name #define CE_DESC_HISTORY_BUFF_CNT  4
2280*5113495bSYour Name #define IS_CE_DEBUG_ONLY_FOR_CRIT_CE (BIT(1) | BIT(2) | BIT(3) | BIT(7))
2281*5113495bSYour Name #else
2282*5113495bSYour Name /* CE2, CE3, CE7 */
2283*5113495bSYour Name #define CE_DESC_HISTORY_BUFF_CNT  3
2284*5113495bSYour Name #define IS_CE_DEBUG_ONLY_FOR_CRIT_CE (BIT(2) | BIT(3) | BIT(7))
2285*5113495bSYour Name #endif /* QCA_WIFI_SUPPORT_SRNG */
2286*5113495bSYour Name #endif
2287*5113495bSYour Name bool hif_ce_only_for_crit = IS_CE_DEBUG_ONLY_FOR_CRIT_CE;
2288*5113495bSYour Name struct hif_ce_desc_event
2289*5113495bSYour Name 	hif_ce_desc_history_buff[CE_DESC_HISTORY_BUFF_CNT][HIF_CE_HISTORY_MAX];
2290*5113495bSYour Name 
2291*5113495bSYour Name static void
__hif_ce_desc_history_log_register(struct hif_softc * scn)2292*5113495bSYour Name __hif_ce_desc_history_log_register(struct hif_softc *scn)
2293*5113495bSYour Name {
2294*5113495bSYour Name 	qdf_ssr_driver_dump_register_region("hif_ce_desc_history_buff",
2295*5113495bSYour Name 					    hif_ce_desc_history_buff,
2296*5113495bSYour Name 					    sizeof(hif_ce_desc_history_buff));
2297*5113495bSYour Name 	qdf_ssr_driver_dump_register_region("hif_ce_desc_hist",
2298*5113495bSYour Name 					    &scn->hif_ce_desc_hist,
2299*5113495bSYour Name 					    sizeof(scn->hif_ce_desc_hist));
2300*5113495bSYour Name 	qdf_ssr_driver_dump_register_region("hif_ce_count_max",
2301*5113495bSYour Name 					    &hif_ce_count_max,
2302*5113495bSYour Name 					    sizeof(hif_ce_count_max));
2303*5113495bSYour Name 	qdf_ssr_driver_dump_register_region("hif_ce_history_max",
2304*5113495bSYour Name 					    &hif_ce_history_max,
2305*5113495bSYour Name 					    sizeof(hif_ce_history_max));
2306*5113495bSYour Name 	qdf_ssr_driver_dump_register_region("hif_ce_only_for_crit",
2307*5113495bSYour Name 					    &hif_ce_only_for_crit,
2308*5113495bSYour Name 					    sizeof(hif_ce_only_for_crit));
2309*5113495bSYour Name }
2310*5113495bSYour Name 
__hif_ce_desc_history_log_unregister(void)2311*5113495bSYour Name static void __hif_ce_desc_history_log_unregister(void)
2312*5113495bSYour Name {
2313*5113495bSYour Name 	qdf_ssr_driver_dump_unregister_region("hif_ce_only_for_crit");
2314*5113495bSYour Name 	qdf_ssr_driver_dump_unregister_region("hif_ce_history_max");
2315*5113495bSYour Name 	qdf_ssr_driver_dump_unregister_region("hif_ce_count_max");
2316*5113495bSYour Name 	qdf_ssr_driver_dump_unregister_region("hif_ce_desc_hist");
2317*5113495bSYour Name 	qdf_ssr_driver_dump_unregister_region("hif_ce_desc_history_buff");
2318*5113495bSYour Name }
2319*5113495bSYour Name 
2320*5113495bSYour Name static struct hif_ce_desc_event *
hif_ce_debug_history_buf_get(struct hif_softc * scn,unsigned int ce_id)2321*5113495bSYour Name 	hif_ce_debug_history_buf_get(struct hif_softc *scn, unsigned int ce_id)
2322*5113495bSYour Name {
2323*5113495bSYour Name 	struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
2324*5113495bSYour Name 
2325*5113495bSYour Name 	hif_debug("get ce debug buffer ce_id %u, only_ce2/ce3=0x%lx, idx=%u",
2326*5113495bSYour Name 		  ce_id, IS_CE_DEBUG_ONLY_FOR_CRIT_CE,
2327*5113495bSYour Name 		  ce_hist->ce_id_hist_map[ce_id]);
2328*5113495bSYour Name 	if (IS_CE_DEBUG_ONLY_FOR_CRIT_CE &&
2329*5113495bSYour Name 	    (IS_CE_DEBUG_ONLY_FOR_CRIT_CE & BIT(ce_id))) {
2330*5113495bSYour Name 		uint8_t idx = ce_hist->ce_id_hist_map[ce_id];
2331*5113495bSYour Name 
2332*5113495bSYour Name 		hif_ce_desc_history[ce_id] = hif_ce_desc_history_buff[idx];
2333*5113495bSYour Name 	} else {
2334*5113495bSYour Name 		hif_ce_desc_history[ce_id] =
2335*5113495bSYour Name 			hif_ce_desc_history_buff[ce_id];
2336*5113495bSYour Name 	}
2337*5113495bSYour Name 
2338*5113495bSYour Name 	return hif_ce_desc_history[ce_id];
2339*5113495bSYour Name }
2340*5113495bSYour Name 
2341*5113495bSYour Name /**
2342*5113495bSYour Name  * alloc_mem_ce_debug_history() - Allocate CE descriptor history
2343*5113495bSYour Name  * @scn: hif scn handle
2344*5113495bSYour Name  * @ce_id: Copy Engine Id
2345*5113495bSYour Name  * @src_nentries: source ce ring entries
2346*5113495bSYour Name  * Return: QDF_STATUS
2347*5113495bSYour Name  */
2348*5113495bSYour Name static QDF_STATUS
alloc_mem_ce_debug_history(struct hif_softc * scn,unsigned int ce_id,uint32_t src_nentries)2349*5113495bSYour Name alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int ce_id,
2350*5113495bSYour Name 			   uint32_t src_nentries)
2351*5113495bSYour Name {
2352*5113495bSYour Name 	struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
2353*5113495bSYour Name 	QDF_STATUS status = QDF_STATUS_SUCCESS;
2354*5113495bSYour Name 
2355*5113495bSYour Name 	/* For perf build, return directly for non ce2/ce3 */
2356*5113495bSYour Name 	if (IS_CE_DEBUG_ONLY_FOR_CRIT_CE &&
2357*5113495bSYour Name 	    !(IS_CE_DEBUG_ONLY_FOR_CRIT_CE & BIT(ce_id))) {
2358*5113495bSYour Name 		ce_hist->enable[ce_id] = false;
2359*5113495bSYour Name 		ce_hist->data_enable[ce_id] = false;
2360*5113495bSYour Name 		return QDF_STATUS_SUCCESS;
2361*5113495bSYour Name 	}
2362*5113495bSYour Name 
2363*5113495bSYour Name 	ce_hist->hist_ev[ce_id] = hif_ce_debug_history_buf_get(scn, ce_id);
2364*5113495bSYour Name 	ce_hist->enable[ce_id] = true;
2365*5113495bSYour Name 
2366*5113495bSYour Name 	if (src_nentries) {
2367*5113495bSYour Name 		status = alloc_mem_ce_debug_hist_data(scn, ce_id);
2368*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS) {
2369*5113495bSYour Name 			ce_hist->enable[ce_id] = false;
2370*5113495bSYour Name 			ce_hist->hist_ev[ce_id] = NULL;
2371*5113495bSYour Name 			return status;
2372*5113495bSYour Name 		}
2373*5113495bSYour Name 	} else {
2374*5113495bSYour Name 		ce_hist->data_enable[ce_id] = false;
2375*5113495bSYour Name 	}
2376*5113495bSYour Name 
2377*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2378*5113495bSYour Name }
2379*5113495bSYour Name 
2380*5113495bSYour Name /**
2381*5113495bSYour Name  * free_mem_ce_debug_history() - Free CE descriptor history
2382*5113495bSYour Name  * @scn: hif scn handle
2383*5113495bSYour Name  * @ce_id: Copy Engine Id
2384*5113495bSYour Name  *
2385*5113495bSYour Name  * Return: None
2386*5113495bSYour Name  */
free_mem_ce_debug_history(struct hif_softc * scn,unsigned int ce_id)2387*5113495bSYour Name static void free_mem_ce_debug_history(struct hif_softc *scn, unsigned int ce_id)
2388*5113495bSYour Name {
2389*5113495bSYour Name 	struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
2390*5113495bSYour Name 
2391*5113495bSYour Name 	if (!ce_hist->enable[ce_id])
2392*5113495bSYour Name 		return;
2393*5113495bSYour Name 
2394*5113495bSYour Name 	ce_hist->enable[ce_id] = false;
2395*5113495bSYour Name 	if (ce_hist->data_enable[ce_id]) {
2396*5113495bSYour Name 		ce_hist->data_enable[ce_id] = false;
2397*5113495bSYour Name 		free_mem_ce_debug_hist_data(scn, ce_id);
2398*5113495bSYour Name 	}
2399*5113495bSYour Name 	ce_hist->hist_ev[ce_id] = NULL;
2400*5113495bSYour Name }
2401*5113495bSYour Name #else
2402*5113495bSYour Name 
2403*5113495bSYour Name static void
__hif_ce_desc_history_log_register(struct hif_softc * scn)2404*5113495bSYour Name __hif_ce_desc_history_log_register(struct hif_softc *scn)
2405*5113495bSYour Name {
2406*5113495bSYour Name }
2407*5113495bSYour Name 
__hif_ce_desc_history_log_unregister(void)2408*5113495bSYour Name static void __hif_ce_desc_history_log_unregister(void) { }
2409*5113495bSYour Name 
2410*5113495bSYour Name static inline QDF_STATUS
alloc_mem_ce_debug_history(struct hif_softc * scn,unsigned int CE_id,uint32_t src_nentries)2411*5113495bSYour Name alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id,
2412*5113495bSYour Name 			   uint32_t src_nentries)
2413*5113495bSYour Name {
2414*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2415*5113495bSYour Name }
2416*5113495bSYour Name 
2417*5113495bSYour Name static inline void
free_mem_ce_debug_history(struct hif_softc * scn,unsigned int CE_id)2418*5113495bSYour Name free_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id) { }
2419*5113495bSYour Name #endif /* (HIF_CONFIG_SLUB_DEBUG_ON) || (HIF_CE_DEBUG_DATA_BUF) */
2420*5113495bSYour Name #else
2421*5113495bSYour Name #if defined(HIF_CE_DEBUG_DATA_BUF)
2422*5113495bSYour Name 
2423*5113495bSYour Name static void
__hif_ce_desc_history_log_register(struct hif_softc * scn)2424*5113495bSYour Name __hif_ce_desc_history_log_register(struct hif_softc *scn)
2425*5113495bSYour Name {
2426*5113495bSYour Name }
2427*5113495bSYour Name 
__hif_ce_desc_history_log_unregister(void)2428*5113495bSYour Name static void __hif_ce_desc_history_log_unregister(void) { }
2429*5113495bSYour Name 
2430*5113495bSYour Name static QDF_STATUS
alloc_mem_ce_debug_history(struct hif_softc * scn,unsigned int CE_id,uint32_t src_nentries)2431*5113495bSYour Name alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id,
2432*5113495bSYour Name 			   uint32_t src_nentries)
2433*5113495bSYour Name {
2434*5113495bSYour Name 	scn->hif_ce_desc_hist.hist_ev[CE_id] = (struct hif_ce_desc_event *)
2435*5113495bSYour Name 	qdf_mem_malloc(HIF_CE_HISTORY_MAX * sizeof(struct hif_ce_desc_event));
2436*5113495bSYour Name 
2437*5113495bSYour Name 	if (!scn->hif_ce_desc_hist.hist_ev[CE_id]) {
2438*5113495bSYour Name 		scn->hif_ce_desc_hist.enable[CE_id] = 0;
2439*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
2440*5113495bSYour Name 	} else {
2441*5113495bSYour Name 		scn->hif_ce_desc_hist.enable[CE_id] = 1;
2442*5113495bSYour Name 		return QDF_STATUS_SUCCESS;
2443*5113495bSYour Name 	}
2444*5113495bSYour Name }
2445*5113495bSYour Name 
free_mem_ce_debug_history(struct hif_softc * scn,unsigned int CE_id)2446*5113495bSYour Name static void free_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id)
2447*5113495bSYour Name {
2448*5113495bSYour Name 	struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
2449*5113495bSYour Name 	struct hif_ce_desc_event *hist_ev = ce_hist->hist_ev[CE_id];
2450*5113495bSYour Name 
2451*5113495bSYour Name 	if (!hist_ev)
2452*5113495bSYour Name 		return;
2453*5113495bSYour Name 
2454*5113495bSYour Name 	if (ce_hist->data_enable[CE_id]) {
2455*5113495bSYour Name 		ce_hist->data_enable[CE_id] = false;
2456*5113495bSYour Name 		free_mem_ce_debug_hist_data(scn, CE_id);
2457*5113495bSYour Name 	}
2458*5113495bSYour Name 
2459*5113495bSYour Name 	ce_hist->enable[CE_id] = false;
2460*5113495bSYour Name 	qdf_mem_free(ce_hist->hist_ev[CE_id]);
2461*5113495bSYour Name 	ce_hist->hist_ev[CE_id] = NULL;
2462*5113495bSYour Name }
2463*5113495bSYour Name 
2464*5113495bSYour Name #else
2465*5113495bSYour Name 
2466*5113495bSYour Name static void
__hif_ce_desc_history_log_register(struct hif_softc * scn)2467*5113495bSYour Name __hif_ce_desc_history_log_register(struct hif_softc *scn)
2468*5113495bSYour Name {
2469*5113495bSYour Name }
2470*5113495bSYour Name 
__hif_ce_desc_history_log_unregister(void)2471*5113495bSYour Name static void __hif_ce_desc_history_log_unregister(void) { }
2472*5113495bSYour Name 
2473*5113495bSYour Name static inline QDF_STATUS
alloc_mem_ce_debug_history(struct hif_softc * scn,unsigned int CE_id,uint32_t src_nentries)2474*5113495bSYour Name alloc_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id,
2475*5113495bSYour Name 			   uint32_t src_nentries)
2476*5113495bSYour Name {
2477*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
2478*5113495bSYour Name }
2479*5113495bSYour Name 
2480*5113495bSYour Name static inline void
free_mem_ce_debug_history(struct hif_softc * scn,unsigned int CE_id)2481*5113495bSYour Name free_mem_ce_debug_history(struct hif_softc *scn, unsigned int CE_id) { }
2482*5113495bSYour Name #endif /* HIF_CE_DEBUG_DATA_BUF */
2483*5113495bSYour Name #endif /* HIF_CE_DEBUG_DATA_DYNAMIC_BUF */
2484*5113495bSYour Name 
2485*5113495bSYour Name #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF)
2486*5113495bSYour Name /**
2487*5113495bSYour Name  * reset_ce_debug_history() - reset the index and ce id used for dumping the
2488*5113495bSYour Name  * CE records on the console using sysfs.
2489*5113495bSYour Name  * @scn: hif scn handle
2490*5113495bSYour Name  *
2491*5113495bSYour Name  * Return:
2492*5113495bSYour Name  */
reset_ce_debug_history(struct hif_softc * scn)2493*5113495bSYour Name static inline void reset_ce_debug_history(struct hif_softc *scn)
2494*5113495bSYour Name {
2495*5113495bSYour Name 	struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
2496*5113495bSYour Name 	/* Initialise the CE debug history sysfs interface inputs ce_id and
2497*5113495bSYour Name 	 * index. Disable data storing
2498*5113495bSYour Name 	 */
2499*5113495bSYour Name 	ce_hist->hist_index = 0;
2500*5113495bSYour Name 	ce_hist->hist_id = 0;
2501*5113495bSYour Name }
2502*5113495bSYour Name #else /* defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF) */
reset_ce_debug_history(struct hif_softc * scn)2503*5113495bSYour Name static inline void reset_ce_debug_history(struct hif_softc *scn) { }
2504*5113495bSYour Name #endif /*defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF) */
2505*5113495bSYour Name 
ce_enable_polling(void * cestate)2506*5113495bSYour Name void ce_enable_polling(void *cestate)
2507*5113495bSYour Name {
2508*5113495bSYour Name 	struct CE_state *CE_state = (struct CE_state *)cestate;
2509*5113495bSYour Name 
2510*5113495bSYour Name 	if (CE_state && CE_state->attr_flags & CE_ATTR_ENABLE_POLL)
2511*5113495bSYour Name 		CE_state->timer_inited = true;
2512*5113495bSYour Name }
2513*5113495bSYour Name 
ce_disable_polling(void * cestate)2514*5113495bSYour Name void ce_disable_polling(void *cestate)
2515*5113495bSYour Name {
2516*5113495bSYour Name 	struct CE_state *CE_state = (struct CE_state *)cestate;
2517*5113495bSYour Name 
2518*5113495bSYour Name 	if (CE_state && CE_state->attr_flags & CE_ATTR_ENABLE_POLL)
2519*5113495bSYour Name 		CE_state->timer_inited = false;
2520*5113495bSYour Name }
2521*5113495bSYour Name 
2522*5113495bSYour Name #ifdef WLAN_FEATURE_SSR_DRIVER_DUMP
2523*5113495bSYour Name #define MAX_CE_STR_LEN 50
2524*5113495bSYour Name /**
2525*5113495bSYour Name  * ce_ring_dump_register_region() - Register CE ring with SSR dump
2526*5113495bSYour Name  * @CE_state: CE_state pointer
2527*5113495bSYour Name  * @CE_id: CE id
2528*5113495bSYour Name  *
2529*5113495bSYour Name  * Return: None
2530*5113495bSYour Name  */
2531*5113495bSYour Name static inline
ce_ring_dump_register_region(struct CE_state * CE_state,unsigned int CE_id)2532*5113495bSYour Name void ce_ring_dump_register_region(struct CE_state *CE_state, unsigned int CE_id)
2533*5113495bSYour Name {
2534*5113495bSYour Name 	struct CE_ring_state *ce_ring;
2535*5113495bSYour Name 	char ce[MAX_CE_STR_LEN];
2536*5113495bSYour Name 	char CE_ring_state[MAX_CE_STR_LEN];
2537*5113495bSYour Name 	char srng[MAX_CE_STR_LEN];
2538*5113495bSYour Name 
2539*5113495bSYour Name 	qdf_snprint(ce, MAX_CE_STR_LEN, "%s%d", "ce_", CE_id);
2540*5113495bSYour Name 	qdf_ssr_driver_dump_register_region(ce, CE_state, sizeof(*CE_state));
2541*5113495bSYour Name 
2542*5113495bSYour Name 	if (CE_state->status_ring) {
2543*5113495bSYour Name 		ce_ring = CE_state->status_ring;
2544*5113495bSYour Name 		qdf_snprint(CE_ring_state, MAX_CE_STR_LEN,
2545*5113495bSYour Name 			    "%s%s", ce, "_status_ring");
2546*5113495bSYour Name 		qdf_ssr_driver_dump_register_region(CE_ring_state, ce_ring,
2547*5113495bSYour Name 						    sizeof(struct CE_ring_state)
2548*5113495bSYour Name 						   );
2549*5113495bSYour Name 		qdf_snprint(srng, MAX_CE_STR_LEN,
2550*5113495bSYour Name 			    "%s%s", CE_ring_state, "_ctx");
2551*5113495bSYour Name 		qdf_ssr_driver_dump_register_region(srng, ce_ring->srng_ctx,
2552*5113495bSYour Name 						    sizeof(struct hal_srng));
2553*5113495bSYour Name 	}
2554*5113495bSYour Name 	if (CE_state->dest_ring) {
2555*5113495bSYour Name 		ce_ring = CE_state->dest_ring;
2556*5113495bSYour Name 		qdf_snprint(CE_ring_state, MAX_CE_STR_LEN,
2557*5113495bSYour Name 			    "%s%s", ce, "_dest_ring");
2558*5113495bSYour Name 		qdf_ssr_driver_dump_register_region(CE_ring_state, ce_ring,
2559*5113495bSYour Name 						    sizeof(struct CE_ring_state)
2560*5113495bSYour Name 						   );
2561*5113495bSYour Name 		qdf_snprint(srng, MAX_CE_STR_LEN,
2562*5113495bSYour Name 			    "%s%s", CE_ring_state, "_ctx");
2563*5113495bSYour Name 		qdf_ssr_driver_dump_register_region(srng, ce_ring->srng_ctx,
2564*5113495bSYour Name 						    sizeof(struct hal_srng));
2565*5113495bSYour Name 	}
2566*5113495bSYour Name 	if (CE_state->src_ring) {
2567*5113495bSYour Name 		ce_ring = CE_state->src_ring;
2568*5113495bSYour Name 		qdf_snprint(CE_ring_state, MAX_CE_STR_LEN,
2569*5113495bSYour Name 			    "%s%s", ce, "_src_ring");
2570*5113495bSYour Name 		qdf_ssr_driver_dump_register_region(CE_ring_state, ce_ring,
2571*5113495bSYour Name 						    sizeof(struct CE_ring_state)
2572*5113495bSYour Name 						   );
2573*5113495bSYour Name 		qdf_snprint(srng, MAX_CE_STR_LEN,
2574*5113495bSYour Name 			    "%s%s", CE_ring_state, "_ctx");
2575*5113495bSYour Name 		qdf_ssr_driver_dump_register_region(srng, ce_ring->srng_ctx,
2576*5113495bSYour Name 						    sizeof(struct hal_srng));
2577*5113495bSYour Name 	}
2578*5113495bSYour Name }
2579*5113495bSYour Name 
2580*5113495bSYour Name /**
2581*5113495bSYour Name  * ce_ring_dump_unregister_region() - Unregister CE ring with SSR dump
2582*5113495bSYour Name  * @CE_state: CE_state pointer
2583*5113495bSYour Name  * @CE_id: CE id
2584*5113495bSYour Name  *
2585*5113495bSYour Name  * Return: None
2586*5113495bSYour Name  */
2587*5113495bSYour Name static inline void
ce_ring_dump_unregister_region(struct CE_state * CE_state,unsigned int CE_id)2588*5113495bSYour Name ce_ring_dump_unregister_region(struct CE_state *CE_state, unsigned int CE_id)
2589*5113495bSYour Name {
2590*5113495bSYour Name 	char ce[MAX_CE_STR_LEN];
2591*5113495bSYour Name 	char CE_ring_state[MAX_CE_STR_LEN];
2592*5113495bSYour Name 	char srng[MAX_CE_STR_LEN];
2593*5113495bSYour Name 
2594*5113495bSYour Name 	qdf_snprint(ce, MAX_CE_STR_LEN, "%s%d", "ce_", CE_id);
2595*5113495bSYour Name 	qdf_ssr_driver_dump_unregister_region(ce);
2596*5113495bSYour Name 	if (CE_state->status_ring) {
2597*5113495bSYour Name 		qdf_snprint(CE_ring_state, MAX_CE_STR_LEN,
2598*5113495bSYour Name 			    "%s%s", ce, "_status_ring");
2599*5113495bSYour Name 		qdf_snprint(srng, MAX_CE_STR_LEN,
2600*5113495bSYour Name 			    "%s%s", CE_ring_state, "_ctx");
2601*5113495bSYour Name 		qdf_ssr_driver_dump_unregister_region(CE_ring_state);
2602*5113495bSYour Name 		qdf_ssr_driver_dump_unregister_region(srng);
2603*5113495bSYour Name 	}
2604*5113495bSYour Name 	if (CE_state->dest_ring) {
2605*5113495bSYour Name 		qdf_snprint(CE_ring_state, MAX_CE_STR_LEN,
2606*5113495bSYour Name 			    "%s%s", ce, "_dest_ring");
2607*5113495bSYour Name 		qdf_snprint(srng, MAX_CE_STR_LEN,
2608*5113495bSYour Name 			    "%s%s", CE_ring_state, "_ctx");
2609*5113495bSYour Name 		qdf_ssr_driver_dump_unregister_region(CE_ring_state);
2610*5113495bSYour Name 		qdf_ssr_driver_dump_unregister_region(srng);
2611*5113495bSYour Name 	}
2612*5113495bSYour Name 	if (CE_state->src_ring) {
2613*5113495bSYour Name 		qdf_snprint(CE_ring_state, MAX_CE_STR_LEN,
2614*5113495bSYour Name 			    "%s%s", ce, "_src_ring");
2615*5113495bSYour Name 		qdf_snprint(srng, MAX_CE_STR_LEN,
2616*5113495bSYour Name 			    "%s%s", CE_ring_state, "_ctx");
2617*5113495bSYour Name 		qdf_ssr_driver_dump_unregister_region(CE_ring_state);
2618*5113495bSYour Name 		qdf_ssr_driver_dump_unregister_region(srng);
2619*5113495bSYour Name 	}
2620*5113495bSYour Name }
2621*5113495bSYour Name #else
2622*5113495bSYour Name static inline
ce_ring_dump_register_region(struct CE_state * CE_state,unsigned int CE_id)2623*5113495bSYour Name void ce_ring_dump_register_region(struct CE_state *CE_state, unsigned int CE_id)
2624*5113495bSYour Name {
2625*5113495bSYour Name }
2626*5113495bSYour Name 
2627*5113495bSYour Name static inline void
ce_ring_dump_unregister_region(struct CE_state * CE_state,unsigned int CE_id)2628*5113495bSYour Name ce_ring_dump_unregister_region(struct CE_state *CE_state, unsigned int CE_id)
2629*5113495bSYour Name {
2630*5113495bSYour Name }
2631*5113495bSYour Name #endif
2632*5113495bSYour Name /*
2633*5113495bSYour Name  * Initialize a Copy Engine based on caller-supplied attributes.
2634*5113495bSYour Name  * This may be called once to initialize both source and destination
2635*5113495bSYour Name  * rings or it may be called twice for separate source and destination
2636*5113495bSYour Name  * initialization. It may be that only one side or the other is
2637*5113495bSYour Name  * initialized by software/firmware.
2638*5113495bSYour Name  *
2639*5113495bSYour Name  * This should be called during the initialization sequence before
2640*5113495bSYour Name  * interrupts are enabled, so we don't have to worry about thread safety.
2641*5113495bSYour Name  */
ce_init(struct hif_softc * scn,unsigned int CE_id,struct CE_attr * attr)2642*5113495bSYour Name struct CE_handle *ce_init(struct hif_softc *scn,
2643*5113495bSYour Name 			  unsigned int CE_id, struct CE_attr *attr)
2644*5113495bSYour Name {
2645*5113495bSYour Name 	struct CE_state *CE_state;
2646*5113495bSYour Name 	uint32_t ctrl_addr;
2647*5113495bSYour Name 	unsigned int nentries;
2648*5113495bSYour Name 	bool malloc_CE_state = false;
2649*5113495bSYour Name 	bool malloc_src_ring = false;
2650*5113495bSYour Name 	int status;
2651*5113495bSYour Name 	QDF_STATUS mem_status = QDF_STATUS_SUCCESS;
2652*5113495bSYour Name 
2653*5113495bSYour Name 	QDF_ASSERT(CE_id < scn->ce_count);
2654*5113495bSYour Name 	ctrl_addr = CE_BASE_ADDRESS(CE_id);
2655*5113495bSYour Name 	CE_state = scn->ce_id_to_state[CE_id];
2656*5113495bSYour Name 
2657*5113495bSYour Name 	if (!CE_state) {
2658*5113495bSYour Name 		CE_state =
2659*5113495bSYour Name 		    (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
2660*5113495bSYour Name 		if (!CE_state)
2661*5113495bSYour Name 			return NULL;
2662*5113495bSYour Name 
2663*5113495bSYour Name 		malloc_CE_state = true;
2664*5113495bSYour Name 		qdf_spinlock_create(&CE_state->ce_index_lock);
2665*5113495bSYour Name #ifdef CE_TASKLET_SCHEDULE_ON_FULL
2666*5113495bSYour Name 		qdf_spinlock_create(&CE_state->ce_interrupt_lock);
2667*5113495bSYour Name #endif
2668*5113495bSYour Name 
2669*5113495bSYour Name 		CE_state->id = CE_id;
2670*5113495bSYour Name 		CE_state->ctrl_addr = ctrl_addr;
2671*5113495bSYour Name 		CE_state->state = CE_RUNNING;
2672*5113495bSYour Name 		CE_state->attr_flags = attr->flags;
2673*5113495bSYour Name 	}
2674*5113495bSYour Name 	CE_state->scn = scn;
2675*5113495bSYour Name 	CE_state->service = ce_engine_service_reg;
2676*5113495bSYour Name 
2677*5113495bSYour Name 	qdf_atomic_init(&CE_state->rx_pending);
2678*5113495bSYour Name 	if (!attr) {
2679*5113495bSYour Name 		/* Already initialized; caller wants the handle */
2680*5113495bSYour Name 		return (struct CE_handle *)CE_state;
2681*5113495bSYour Name 	}
2682*5113495bSYour Name 
2683*5113495bSYour Name 	if (CE_state->src_sz_max)
2684*5113495bSYour Name 		QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
2685*5113495bSYour Name 	else
2686*5113495bSYour Name 		CE_state->src_sz_max = attr->src_sz_max;
2687*5113495bSYour Name 
2688*5113495bSYour Name 	ce_init_ce_desc_event_log(scn, CE_id,
2689*5113495bSYour Name 				  attr->src_nentries + attr->dest_nentries);
2690*5113495bSYour Name 
2691*5113495bSYour Name 	/* source ring setup */
2692*5113495bSYour Name 	nentries = attr->src_nentries;
2693*5113495bSYour Name 	if (nentries) {
2694*5113495bSYour Name 		struct CE_ring_state *src_ring;
2695*5113495bSYour Name 
2696*5113495bSYour Name 		nentries = roundup_pwr2(nentries);
2697*5113495bSYour Name 		if (CE_state->src_ring) {
2698*5113495bSYour Name 			QDF_ASSERT(CE_state->src_ring->nentries == nentries);
2699*5113495bSYour Name 		} else {
2700*5113495bSYour Name 			src_ring = CE_state->src_ring =
2701*5113495bSYour Name 				ce_alloc_ring_state(CE_state,
2702*5113495bSYour Name 						CE_RING_SRC,
2703*5113495bSYour Name 						nentries);
2704*5113495bSYour Name 			if (!src_ring) {
2705*5113495bSYour Name 				/* cannot allocate src ring. If the
2706*5113495bSYour Name 				 * CE_state is allocated locally free
2707*5113495bSYour Name 				 * CE_State and return error.
2708*5113495bSYour Name 				 */
2709*5113495bSYour Name 				hif_err("src ring has no mem");
2710*5113495bSYour Name 				if (malloc_CE_state) {
2711*5113495bSYour Name 					/* allocated CE_state locally */
2712*5113495bSYour Name 					qdf_mem_free(CE_state);
2713*5113495bSYour Name 					malloc_CE_state = false;
2714*5113495bSYour Name 				}
2715*5113495bSYour Name 				return NULL;
2716*5113495bSYour Name 			}
2717*5113495bSYour Name 			/* we can allocate src ring. Mark that the src ring is
2718*5113495bSYour Name 			 * allocated locally
2719*5113495bSYour Name 			 */
2720*5113495bSYour Name 			malloc_src_ring = true;
2721*5113495bSYour Name 
2722*5113495bSYour Name 			/*
2723*5113495bSYour Name 			 * Also allocate a shadow src ring in
2724*5113495bSYour Name 			 * regular mem to use for faster access.
2725*5113495bSYour Name 			 */
2726*5113495bSYour Name 			src_ring->shadow_base_unaligned =
2727*5113495bSYour Name 				qdf_mem_malloc(nentries *
2728*5113495bSYour Name 					       sizeof(struct CE_src_desc) +
2729*5113495bSYour Name 					       CE_DESC_RING_ALIGN);
2730*5113495bSYour Name 			if (!src_ring->shadow_base_unaligned)
2731*5113495bSYour Name 				goto error_no_dma_mem;
2732*5113495bSYour Name 
2733*5113495bSYour Name 			src_ring->shadow_base = (struct CE_src_desc *)
2734*5113495bSYour Name 				(((size_t) src_ring->shadow_base_unaligned +
2735*5113495bSYour Name 				CE_DESC_RING_ALIGN - 1) &
2736*5113495bSYour Name 				 ~(CE_DESC_RING_ALIGN - 1));
2737*5113495bSYour Name 
2738*5113495bSYour Name 			status = ce_ring_setup(scn, CE_RING_SRC, CE_id,
2739*5113495bSYour Name 					       src_ring, attr);
2740*5113495bSYour Name 			if (status < 0)
2741*5113495bSYour Name 				goto error_target_access;
2742*5113495bSYour Name 			ce_ring_test_initial_indexes(CE_id, src_ring,
2743*5113495bSYour Name 						     "src_ring");
2744*5113495bSYour Name 			if (CE_state->attr_flags & CE_ATTR_ENABLE_POLL) {
2745*5113495bSYour Name 				qdf_timer_init(scn->qdf_dev,
2746*5113495bSYour Name 					       &CE_state->poll_timer,
2747*5113495bSYour Name 					       ce_poll_timeout,
2748*5113495bSYour Name 					       CE_state,
2749*5113495bSYour Name 					       QDF_TIMER_TYPE_WAKE_APPS);
2750*5113495bSYour Name 				ce_enable_polling(CE_state);
2751*5113495bSYour Name 				qdf_timer_mod(&CE_state->poll_timer,
2752*5113495bSYour Name 					      CE_POLL_TIMEOUT);
2753*5113495bSYour Name 			}
2754*5113495bSYour Name 		}
2755*5113495bSYour Name 	}
2756*5113495bSYour Name 
2757*5113495bSYour Name 	/* destination ring setup */
2758*5113495bSYour Name 	nentries = attr->dest_nentries;
2759*5113495bSYour Name 	if (nentries) {
2760*5113495bSYour Name 		struct CE_ring_state *dest_ring;
2761*5113495bSYour Name 
2762*5113495bSYour Name 		nentries = roundup_pwr2(nentries);
2763*5113495bSYour Name 		if (CE_state->dest_ring) {
2764*5113495bSYour Name 			QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
2765*5113495bSYour Name 		} else {
2766*5113495bSYour Name 			dest_ring = CE_state->dest_ring =
2767*5113495bSYour Name 				ce_alloc_ring_state(CE_state,
2768*5113495bSYour Name 						CE_RING_DEST,
2769*5113495bSYour Name 						nentries);
2770*5113495bSYour Name 			if (!dest_ring) {
2771*5113495bSYour Name 				/* cannot allocate dst ring. If the CE_state
2772*5113495bSYour Name 				 * or src ring is allocated locally free
2773*5113495bSYour Name 				 * CE_State and src ring and return error.
2774*5113495bSYour Name 				 */
2775*5113495bSYour Name 				hif_err("dest ring has no mem");
2776*5113495bSYour Name 				goto error_no_dma_mem;
2777*5113495bSYour Name 			}
2778*5113495bSYour Name 
2779*5113495bSYour Name 			status = ce_ring_setup(scn, CE_RING_DEST, CE_id,
2780*5113495bSYour Name 				      dest_ring, attr);
2781*5113495bSYour Name 			if (status < 0)
2782*5113495bSYour Name 				goto error_target_access;
2783*5113495bSYour Name 
2784*5113495bSYour Name 			ce_ring_test_initial_indexes(CE_id, dest_ring,
2785*5113495bSYour Name 						     "dest_ring");
2786*5113495bSYour Name 
2787*5113495bSYour Name 			/* For srng based target, init status ring here */
2788*5113495bSYour Name 			if (ce_srng_based(CE_state->scn)) {
2789*5113495bSYour Name 				CE_state->status_ring =
2790*5113495bSYour Name 					ce_alloc_ring_state(CE_state,
2791*5113495bSYour Name 							CE_RING_STATUS,
2792*5113495bSYour Name 							nentries);
2793*5113495bSYour Name 				if (!CE_state->status_ring) {
2794*5113495bSYour Name 					/*Allocation failed. Cleanup*/
2795*5113495bSYour Name 					qdf_mem_free(CE_state->dest_ring);
2796*5113495bSYour Name 					if (malloc_src_ring) {
2797*5113495bSYour Name 						qdf_mem_free
2798*5113495bSYour Name 							(CE_state->src_ring);
2799*5113495bSYour Name 						CE_state->src_ring = NULL;
2800*5113495bSYour Name 						malloc_src_ring = false;
2801*5113495bSYour Name 					}
2802*5113495bSYour Name 					if (malloc_CE_state) {
2803*5113495bSYour Name 						/* allocated CE_state locally */
2804*5113495bSYour Name 						scn->ce_id_to_state[CE_id] =
2805*5113495bSYour Name 							NULL;
2806*5113495bSYour Name 						qdf_mem_free(CE_state);
2807*5113495bSYour Name 						malloc_CE_state = false;
2808*5113495bSYour Name 					}
2809*5113495bSYour Name 
2810*5113495bSYour Name 					return NULL;
2811*5113495bSYour Name 				}
2812*5113495bSYour Name 
2813*5113495bSYour Name 				status = ce_ring_setup(scn, CE_RING_STATUS,
2814*5113495bSYour Name 					       CE_id, CE_state->status_ring,
2815*5113495bSYour Name 					       attr);
2816*5113495bSYour Name 				if (status < 0)
2817*5113495bSYour Name 					goto error_target_access;
2818*5113495bSYour Name 
2819*5113495bSYour Name 			}
2820*5113495bSYour Name 
2821*5113495bSYour Name 			/* epping */
2822*5113495bSYour Name 			/* poll timer */
2823*5113495bSYour Name 			if (CE_state->attr_flags & CE_ATTR_ENABLE_POLL) {
2824*5113495bSYour Name 				qdf_timer_init(scn->qdf_dev,
2825*5113495bSYour Name 						&CE_state->poll_timer,
2826*5113495bSYour Name 						ce_poll_timeout,
2827*5113495bSYour Name 						CE_state,
2828*5113495bSYour Name 						QDF_TIMER_TYPE_WAKE_APPS);
2829*5113495bSYour Name 				ce_enable_polling(CE_state);
2830*5113495bSYour Name 				qdf_timer_mod(&CE_state->poll_timer,
2831*5113495bSYour Name 						      CE_POLL_TIMEOUT);
2832*5113495bSYour Name 			}
2833*5113495bSYour Name 		}
2834*5113495bSYour Name 	}
2835*5113495bSYour Name 
2836*5113495bSYour Name 	if (!ce_srng_based(scn)) {
2837*5113495bSYour Name 		/* Enable CE error interrupts */
2838*5113495bSYour Name 		if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
2839*5113495bSYour Name 			goto error_target_access;
2840*5113495bSYour Name 		CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
2841*5113495bSYour Name 		if (Q_TARGET_ACCESS_END(scn) < 0)
2842*5113495bSYour Name 			goto error_target_access;
2843*5113495bSYour Name 	}
2844*5113495bSYour Name 
2845*5113495bSYour Name 	qdf_create_work(scn->qdf_dev, &CE_state->oom_allocation_work,
2846*5113495bSYour Name 			ce_oom_recovery, CE_state);
2847*5113495bSYour Name 
2848*5113495bSYour Name 	/* update the htt_data attribute */
2849*5113495bSYour Name 	ce_mark_datapath(CE_state);
2850*5113495bSYour Name 	scn->ce_id_to_state[CE_id] = CE_state;
2851*5113495bSYour Name 
2852*5113495bSYour Name 	ce_ring_dump_register_region(CE_state, CE_id);
2853*5113495bSYour Name 
2854*5113495bSYour Name 	mem_status = alloc_mem_ce_debug_history(scn, CE_id, attr->src_nentries);
2855*5113495bSYour Name 	if (mem_status != QDF_STATUS_SUCCESS)
2856*5113495bSYour Name 		goto error_target_access;
2857*5113495bSYour Name 
2858*5113495bSYour Name 	ce_update_msi_batch_intr_flags(CE_state);
2859*5113495bSYour Name 	ce_update_wrt_idx_offset(scn, CE_state, attr);
2860*5113495bSYour Name 
2861*5113495bSYour Name 	return (struct CE_handle *)CE_state;
2862*5113495bSYour Name 
2863*5113495bSYour Name error_target_access:
2864*5113495bSYour Name error_no_dma_mem:
2865*5113495bSYour Name 	ce_fini((struct CE_handle *)CE_state);
2866*5113495bSYour Name 	return NULL;
2867*5113495bSYour Name }
2868*5113495bSYour Name 
hif_ce_desc_history_log_register(struct hif_softc * scn)2869*5113495bSYour Name void hif_ce_desc_history_log_register(struct hif_softc *scn)
2870*5113495bSYour Name {
2871*5113495bSYour Name 	__hif_ce_desc_history_log_register(scn);
2872*5113495bSYour Name }
2873*5113495bSYour Name 
2874*5113495bSYour Name /**
2875*5113495bSYour Name  * hif_is_polled_mode_enabled - API to query if polling is enabled on all CEs
2876*5113495bSYour Name  * @hif_ctx: HIF Context
2877*5113495bSYour Name  *
2878*5113495bSYour Name  * API to check if polling is enabled on all CEs. Returns true when polling
2879*5113495bSYour Name  * is enabled on all CEs.
2880*5113495bSYour Name  *
2881*5113495bSYour Name  * Return: bool
2882*5113495bSYour Name  */
hif_is_polled_mode_enabled(struct hif_opaque_softc * hif_ctx)2883*5113495bSYour Name bool hif_is_polled_mode_enabled(struct hif_opaque_softc *hif_ctx)
2884*5113495bSYour Name {
2885*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
2886*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2887*5113495bSYour Name 	struct CE_attr *attr;
2888*5113495bSYour Name 	int id;
2889*5113495bSYour Name 
2890*5113495bSYour Name 	for (id = 0; id < scn->ce_count; id++) {
2891*5113495bSYour Name 		attr = &hif_state->host_ce_config[id];
2892*5113495bSYour Name 		if (attr && (attr->dest_nentries) &&
2893*5113495bSYour Name 		    !(attr->flags & CE_ATTR_ENABLE_POLL))
2894*5113495bSYour Name 			return false;
2895*5113495bSYour Name 	}
2896*5113495bSYour Name 	return true;
2897*5113495bSYour Name }
2898*5113495bSYour Name qdf_export_symbol(hif_is_polled_mode_enabled);
2899*5113495bSYour Name 
hif_get_pktlog_ce_num(struct hif_softc * scn)2900*5113495bSYour Name static int hif_get_pktlog_ce_num(struct hif_softc *scn)
2901*5113495bSYour Name {
2902*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2903*5113495bSYour Name 	int id;
2904*5113495bSYour Name 
2905*5113495bSYour Name 	for (id = 0; id < hif_state->sz_tgt_svc_map; id++) {
2906*5113495bSYour Name 		if (hif_state->tgt_svc_map[id].service_id ==  PACKET_LOG_SVC)
2907*5113495bSYour Name 			return hif_state->tgt_svc_map[id].pipenum;
2908*5113495bSYour Name 	}
2909*5113495bSYour Name 	return -EINVAL;
2910*5113495bSYour Name }
2911*5113495bSYour Name 
2912*5113495bSYour Name #ifdef WLAN_FEATURE_CE_RX_BUFFER_REUSE
2913*5113495bSYour Name 
2914*5113495bSYour Name #define HIF_CE_RX_NBUF_WMI_POOL_SIZE 32
2915*5113495bSYour Name 
hif_ce_rx_nbuf_alloc(struct hif_softc * scn,uint8_t ce_id)2916*5113495bSYour Name static qdf_nbuf_t hif_ce_rx_nbuf_alloc(struct hif_softc *scn, uint8_t ce_id)
2917*5113495bSYour Name {
2918*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2919*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info = &hif_state->pipe_info[ce_id];
2920*5113495bSYour Name 	qdf_nbuf_t nbuf;
2921*5113495bSYour Name 
2922*5113495bSYour Name 	nbuf = wbuff_buff_get(scn->wbuff_handle, ce_id, 0, __func__,
2923*5113495bSYour Name 			      __LINE__);
2924*5113495bSYour Name 	if (!nbuf)
2925*5113495bSYour Name 		nbuf = qdf_nbuf_alloc(scn->qdf_dev, pipe_info->buf_sz,
2926*5113495bSYour Name 				      0, 4, false);
2927*5113495bSYour Name 
2928*5113495bSYour Name 	if (!nbuf)
2929*5113495bSYour Name 		return NULL;
2930*5113495bSYour Name 
2931*5113495bSYour Name 	return nbuf;
2932*5113495bSYour Name }
2933*5113495bSYour Name 
hif_ce_rx_nbuf_free(qdf_nbuf_t nbuf)2934*5113495bSYour Name static void hif_ce_rx_nbuf_free(qdf_nbuf_t nbuf)
2935*5113495bSYour Name {
2936*5113495bSYour Name 	nbuf = wbuff_buff_put(nbuf);
2937*5113495bSYour Name 	if (nbuf)
2938*5113495bSYour Name 		qdf_nbuf_free(nbuf);
2939*5113495bSYour Name }
2940*5113495bSYour Name 
2941*5113495bSYour Name static int
hif_calc_wbuff_pool_size(struct hif_softc * scn,struct CE_state * ce_state)2942*5113495bSYour Name hif_calc_wbuff_pool_size(struct hif_softc *scn, struct CE_state *ce_state)
2943*5113495bSYour Name {
2944*5113495bSYour Name 	int ul_is_polled, dl_is_polled;
2945*5113495bSYour Name 	bool is_wmi_svc, wmi_diag_svc;
2946*5113495bSYour Name 	uint8_t ul_pipe, dl_pipe;
2947*5113495bSYour Name 	int pool_size;
2948*5113495bSYour Name 	int status;
2949*5113495bSYour Name 	int ce_id;
2950*5113495bSYour Name 
2951*5113495bSYour Name 	if (!ce_state)
2952*5113495bSYour Name 		return 0;
2953*5113495bSYour Name 
2954*5113495bSYour Name 	ce_id = ce_state->id;
2955*5113495bSYour Name 
2956*5113495bSYour Name 	status = hif_map_service_to_pipe(&scn->osc, WMI_CONTROL_SVC,
2957*5113495bSYour Name 					 &ul_pipe, &dl_pipe,
2958*5113495bSYour Name 					 &ul_is_polled, &dl_is_polled);
2959*5113495bSYour Name 	is_wmi_svc = !status && (dl_pipe == ce_id);
2960*5113495bSYour Name 
2961*5113495bSYour Name 	status = hif_map_service_to_pipe(GET_HIF_OPAQUE_HDL(scn),
2962*5113495bSYour Name 					 WMI_CONTROL_DIAG_SVC,
2963*5113495bSYour Name 					 &ul_pipe, &dl_pipe,
2964*5113495bSYour Name 					 &ul_is_polled, &dl_is_polled);
2965*5113495bSYour Name 	wmi_diag_svc = !status;
2966*5113495bSYour Name 
2967*5113495bSYour Name 	if (is_wmi_svc && !wmi_diag_svc)
2968*5113495bSYour Name 		pool_size = ce_state->dest_ring->nentries +
2969*5113495bSYour Name 			HIF_CE_RX_NBUF_WMI_POOL_SIZE;
2970*5113495bSYour Name 	else if (is_wmi_svc && wmi_diag_svc)
2971*5113495bSYour Name 		pool_size = ce_state->dest_ring->nentries +
2972*5113495bSYour Name 			HIF_CE_RX_NBUF_WMI_POOL_SIZE / 2;
2973*5113495bSYour Name 	else if (!is_wmi_svc && wmi_diag_svc && ce_id == dl_pipe)
2974*5113495bSYour Name 		pool_size = ce_state->dest_ring->nentries +
2975*5113495bSYour Name 			HIF_CE_RX_NBUF_WMI_POOL_SIZE / 2;
2976*5113495bSYour Name 	else
2977*5113495bSYour Name 		pool_size = ce_state->dest_ring->nentries;
2978*5113495bSYour Name 
2979*5113495bSYour Name 	return pool_size;
2980*5113495bSYour Name }
2981*5113495bSYour Name 
hif_ce_rx_wbuff_register(struct hif_softc * scn)2982*5113495bSYour Name static void hif_ce_rx_wbuff_register(struct hif_softc *scn)
2983*5113495bSYour Name {
2984*5113495bSYour Name 	struct wbuff_alloc_request wbuff_alloc[CE_COUNT_MAX] = {0};
2985*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2986*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
2987*5113495bSYour Name 	struct CE_state *ce_state;
2988*5113495bSYour Name 	int ce_id;
2989*5113495bSYour Name 
2990*5113495bSYour Name 	for (ce_id = 0; ce_id <  scn->ce_count; ce_id++) {
2991*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[ce_id];
2992*5113495bSYour Name 		ce_state = scn->ce_id_to_state[ce_id];
2993*5113495bSYour Name 
2994*5113495bSYour Name 		if (!pipe_info->buf_sz)
2995*5113495bSYour Name 			continue;
2996*5113495bSYour Name 
2997*5113495bSYour Name 		/* Only RX CEs need WBUFF registration. recv_bufs_needed
2998*5113495bSYour Name 		 * contains valid count for RX CEs during init time.
2999*5113495bSYour Name 		 */
3000*5113495bSYour Name 		if (!atomic_read(&pipe_info->recv_bufs_needed))
3001*5113495bSYour Name 			continue;
3002*5113495bSYour Name 
3003*5113495bSYour Name 		wbuff_alloc[ce_id].pool_id = ce_id;
3004*5113495bSYour Name 		wbuff_alloc[ce_id].buffer_size = pipe_info->buf_sz;
3005*5113495bSYour Name 		wbuff_alloc[ce_id].pool_size =
3006*5113495bSYour Name 				hif_calc_wbuff_pool_size(scn, ce_state);
3007*5113495bSYour Name 	}
3008*5113495bSYour Name 
3009*5113495bSYour Name 	scn->wbuff_handle =
3010*5113495bSYour Name 		wbuff_module_register(wbuff_alloc, CE_COUNT_MAX, 0, 4,
3011*5113495bSYour Name 				      WBUFF_MODULE_CE_RX);
3012*5113495bSYour Name }
3013*5113495bSYour Name 
hif_ce_rx_wbuff_deregister(struct hif_softc * scn)3014*5113495bSYour Name static void hif_ce_rx_wbuff_deregister(struct hif_softc *scn)
3015*5113495bSYour Name {
3016*5113495bSYour Name 	wbuff_module_deregister(scn->wbuff_handle);
3017*5113495bSYour Name 	scn->wbuff_handle = NULL;
3018*5113495bSYour Name }
3019*5113495bSYour Name #else
3020*5113495bSYour Name static inline qdf_nbuf_t
hif_ce_rx_nbuf_alloc(struct hif_softc * scn,uint8_t ce_id)3021*5113495bSYour Name hif_ce_rx_nbuf_alloc(struct hif_softc *scn, uint8_t ce_id)
3022*5113495bSYour Name {
3023*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3024*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info = &hif_state->pipe_info[ce_id];
3025*5113495bSYour Name 
3026*5113495bSYour Name 	return qdf_nbuf_alloc(scn->qdf_dev, pipe_info->buf_sz, 0, 4, false);
3027*5113495bSYour Name }
3028*5113495bSYour Name 
hif_ce_rx_nbuf_free(qdf_nbuf_t nbuf)3029*5113495bSYour Name static inline void hif_ce_rx_nbuf_free(qdf_nbuf_t nbuf)
3030*5113495bSYour Name {
3031*5113495bSYour Name 	return qdf_nbuf_free(nbuf);
3032*5113495bSYour Name }
3033*5113495bSYour Name 
hif_ce_rx_wbuff_register(struct hif_softc * scn)3034*5113495bSYour Name static inline void hif_ce_rx_wbuff_register(struct hif_softc *scn)
3035*5113495bSYour Name {
3036*5113495bSYour Name }
3037*5113495bSYour Name 
hif_ce_rx_wbuff_deregister(struct hif_softc * scn)3038*5113495bSYour Name static inline void hif_ce_rx_wbuff_deregister(struct hif_softc *scn)
3039*5113495bSYour Name {
3040*5113495bSYour Name }
3041*5113495bSYour Name #endif /* WLAN_FEATURE_CE_RX_BUFFER_REUSE */
3042*5113495bSYour Name 
3043*5113495bSYour Name #ifdef WLAN_FEATURE_FASTPATH
3044*5113495bSYour Name /**
3045*5113495bSYour Name  * hif_enable_fastpath() - Update that we have enabled fastpath mode
3046*5113495bSYour Name  * @hif_ctx: HIF context
3047*5113495bSYour Name  *
3048*5113495bSYour Name  * For use in data path
3049*5113495bSYour Name  *
3050*5113495bSYour Name  * Return: void
3051*5113495bSYour Name  */
hif_enable_fastpath(struct hif_opaque_softc * hif_ctx)3052*5113495bSYour Name void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
3053*5113495bSYour Name {
3054*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3055*5113495bSYour Name 
3056*5113495bSYour Name 	if (ce_srng_based(scn)) {
3057*5113495bSYour Name 		hif_warn("srng rings do not support fastpath");
3058*5113495bSYour Name 		return;
3059*5113495bSYour Name 	}
3060*5113495bSYour Name 	hif_debug("Enabling fastpath mode");
3061*5113495bSYour Name 	scn->fastpath_mode_on = true;
3062*5113495bSYour Name }
3063*5113495bSYour Name 
3064*5113495bSYour Name /**
3065*5113495bSYour Name  * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
3066*5113495bSYour Name  * @hif_ctx: HIF Context
3067*5113495bSYour Name  *
3068*5113495bSYour Name  * For use in data path to skip HTC
3069*5113495bSYour Name  *
3070*5113495bSYour Name  * Return: bool
3071*5113495bSYour Name  */
hif_is_fastpath_mode_enabled(struct hif_opaque_softc * hif_ctx)3072*5113495bSYour Name bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
3073*5113495bSYour Name {
3074*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3075*5113495bSYour Name 
3076*5113495bSYour Name 	return scn->fastpath_mode_on;
3077*5113495bSYour Name }
3078*5113495bSYour Name 
3079*5113495bSYour Name /**
3080*5113495bSYour Name  * hif_get_ce_handle - API to get CE handle for FastPath mode
3081*5113495bSYour Name  * @hif_ctx: HIF Context
3082*5113495bSYour Name  * @id: CopyEngine Id
3083*5113495bSYour Name  *
3084*5113495bSYour Name  * API to return CE handle for fastpath mode
3085*5113495bSYour Name  *
3086*5113495bSYour Name  * Return: void
3087*5113495bSYour Name  */
hif_get_ce_handle(struct hif_opaque_softc * hif_ctx,int id)3088*5113495bSYour Name void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
3089*5113495bSYour Name {
3090*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3091*5113495bSYour Name 
3092*5113495bSYour Name 	return scn->ce_id_to_state[id];
3093*5113495bSYour Name }
3094*5113495bSYour Name qdf_export_symbol(hif_get_ce_handle);
3095*5113495bSYour Name 
3096*5113495bSYour Name /**
3097*5113495bSYour Name  * ce_h2t_tx_ce_cleanup() - Place holder function for H2T CE cleanup.
3098*5113495bSYour Name  * No processing is required inside this function.
3099*5113495bSYour Name  * @ce_hdl: Cope engine handle
3100*5113495bSYour Name  * Using an assert, this function makes sure that,
3101*5113495bSYour Name  * the TX CE has been processed completely.
3102*5113495bSYour Name  *
3103*5113495bSYour Name  * This is called while dismantling CE structures. No other thread
3104*5113495bSYour Name  * should be using these structures while dismantling is occurring
3105*5113495bSYour Name  * therefore no locking is needed.
3106*5113495bSYour Name  *
3107*5113495bSYour Name  * Return: none
3108*5113495bSYour Name  */
ce_h2t_tx_ce_cleanup(struct CE_handle * ce_hdl)3109*5113495bSYour Name void ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
3110*5113495bSYour Name {
3111*5113495bSYour Name 	struct CE_state *ce_state = (struct CE_state *)ce_hdl;
3112*5113495bSYour Name 	struct CE_ring_state *src_ring = ce_state->src_ring;
3113*5113495bSYour Name 	struct hif_softc *sc = ce_state->scn;
3114*5113495bSYour Name 	uint32_t sw_index, write_index;
3115*5113495bSYour Name 
3116*5113495bSYour Name 	if (hif_is_nss_wifi_enabled(sc))
3117*5113495bSYour Name 		return;
3118*5113495bSYour Name 
3119*5113495bSYour Name 	if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
3120*5113495bSYour Name 		hif_debug("Fastpath mode ON, Cleaning up HTT Tx CE");
3121*5113495bSYour Name 		sw_index = src_ring->sw_index;
3122*5113495bSYour Name 		write_index = src_ring->sw_index;
3123*5113495bSYour Name 
3124*5113495bSYour Name 		/* At this point Tx CE should be clean */
3125*5113495bSYour Name 		qdf_assert_always(sw_index == write_index);
3126*5113495bSYour Name 	}
3127*5113495bSYour Name }
3128*5113495bSYour Name 
3129*5113495bSYour Name /**
3130*5113495bSYour Name  * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
3131*5113495bSYour Name  * @ce_hdl: Handle to CE
3132*5113495bSYour Name  *
3133*5113495bSYour Name  * These buffers are never allocated on the fly, but
3134*5113495bSYour Name  * are allocated only once during HIF start and freed
3135*5113495bSYour Name  * only once during HIF stop.
3136*5113495bSYour Name  * NOTE:
3137*5113495bSYour Name  * The assumption here is there is no in-flight DMA in progress
3138*5113495bSYour Name  * currently, so that buffers can be freed up safely.
3139*5113495bSYour Name  *
3140*5113495bSYour Name  * Return: NONE
3141*5113495bSYour Name  */
ce_t2h_msg_ce_cleanup(struct CE_handle * ce_hdl)3142*5113495bSYour Name void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
3143*5113495bSYour Name {
3144*5113495bSYour Name 	struct CE_state *ce_state = (struct CE_state *)ce_hdl;
3145*5113495bSYour Name 	struct CE_ring_state *dst_ring = ce_state->dest_ring;
3146*5113495bSYour Name 	qdf_nbuf_t nbuf;
3147*5113495bSYour Name 	int i;
3148*5113495bSYour Name 
3149*5113495bSYour Name 	if (ce_state->scn->fastpath_mode_on == false)
3150*5113495bSYour Name 		return;
3151*5113495bSYour Name 
3152*5113495bSYour Name 	if (!ce_state->htt_rx_data)
3153*5113495bSYour Name 		return;
3154*5113495bSYour Name 
3155*5113495bSYour Name 	/*
3156*5113495bSYour Name 	 * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
3157*5113495bSYour Name 	 * this CE is completely full: does not leave one blank space, to
3158*5113495bSYour Name 	 * distinguish between empty queue & full queue. So free all the
3159*5113495bSYour Name 	 * entries.
3160*5113495bSYour Name 	 */
3161*5113495bSYour Name 	for (i = 0; i < dst_ring->nentries; i++) {
3162*5113495bSYour Name 		nbuf = dst_ring->per_transfer_context[i];
3163*5113495bSYour Name 
3164*5113495bSYour Name 		/*
3165*5113495bSYour Name 		 * The reasons for doing this check are:
3166*5113495bSYour Name 		 * 1) Protect against calling cleanup before allocating buffers
3167*5113495bSYour Name 		 * 2) In a corner case, FASTPATH_mode_on may be set, but we
3168*5113495bSYour Name 		 *    could have a partially filled ring, because of a memory
3169*5113495bSYour Name 		 *    allocation failure in the middle of allocating ring.
3170*5113495bSYour Name 		 *    This check accounts for that case, checking
3171*5113495bSYour Name 		 *    fastpath_mode_on flag or started flag would not have
3172*5113495bSYour Name 		 *    covered that case. This is not in performance path,
3173*5113495bSYour Name 		 *    so OK to do this.
3174*5113495bSYour Name 		 */
3175*5113495bSYour Name 		if (nbuf) {
3176*5113495bSYour Name 			qdf_nbuf_unmap_single(ce_state->scn->qdf_dev, nbuf,
3177*5113495bSYour Name 					      QDF_DMA_FROM_DEVICE);
3178*5113495bSYour Name 			hif_ce_rx_nbuf_free(nbuf);
3179*5113495bSYour Name 		}
3180*5113495bSYour Name 	}
3181*5113495bSYour Name }
3182*5113495bSYour Name 
3183*5113495bSYour Name /**
3184*5113495bSYour Name  * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
3185*5113495bSYour Name  * @scn: HIF handle
3186*5113495bSYour Name  *
3187*5113495bSYour Name  * Datapath Rx CEs are special case, where we reuse all the message buffers.
3188*5113495bSYour Name  * Hence we have to post all the entries in the pipe, even, in the beginning
3189*5113495bSYour Name  * unlike for other CE pipes where one less than dest_nentries are filled in
3190*5113495bSYour Name  * the beginning.
3191*5113495bSYour Name  *
3192*5113495bSYour Name  * Return: None
3193*5113495bSYour Name  */
hif_update_fastpath_recv_bufs_cnt(struct hif_softc * scn)3194*5113495bSYour Name static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
3195*5113495bSYour Name {
3196*5113495bSYour Name 	int pipe_num;
3197*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3198*5113495bSYour Name 
3199*5113495bSYour Name 	if (scn->fastpath_mode_on == false)
3200*5113495bSYour Name 		return;
3201*5113495bSYour Name 
3202*5113495bSYour Name 	for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
3203*5113495bSYour Name 		struct HIF_CE_pipe_info *pipe_info =
3204*5113495bSYour Name 			&hif_state->pipe_info[pipe_num];
3205*5113495bSYour Name 		struct CE_state *ce_state =
3206*5113495bSYour Name 			scn->ce_id_to_state[pipe_info->pipe_num];
3207*5113495bSYour Name 
3208*5113495bSYour Name 		if (ce_state->htt_rx_data)
3209*5113495bSYour Name 			atomic_inc(&pipe_info->recv_bufs_needed);
3210*5113495bSYour Name 	}
3211*5113495bSYour Name }
3212*5113495bSYour Name #else
hif_update_fastpath_recv_bufs_cnt(struct hif_softc * scn)3213*5113495bSYour Name static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
3214*5113495bSYour Name {
3215*5113495bSYour Name }
3216*5113495bSYour Name 
ce_is_fastpath_enabled(struct hif_softc * scn)3217*5113495bSYour Name static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
3218*5113495bSYour Name {
3219*5113495bSYour Name 	return false;
3220*5113495bSYour Name }
3221*5113495bSYour Name #endif /* WLAN_FEATURE_FASTPATH */
3222*5113495bSYour Name 
ce_fini(struct CE_handle * copyeng)3223*5113495bSYour Name void ce_fini(struct CE_handle *copyeng)
3224*5113495bSYour Name {
3225*5113495bSYour Name 	struct CE_state *CE_state = (struct CE_state *)copyeng;
3226*5113495bSYour Name 	unsigned int CE_id = CE_state->id;
3227*5113495bSYour Name 	struct hif_softc *scn = CE_state->scn;
3228*5113495bSYour Name 	uint32_t desc_size;
3229*5113495bSYour Name 
3230*5113495bSYour Name 	bool inited = CE_state->timer_inited;
3231*5113495bSYour Name 	CE_state->state = CE_UNUSED;
3232*5113495bSYour Name 	scn->ce_id_to_state[CE_id] = NULL;
3233*5113495bSYour Name 	/* Set the flag to false first to stop processing in ce_poll_timeout */
3234*5113495bSYour Name 	ce_disable_polling(CE_state);
3235*5113495bSYour Name 
3236*5113495bSYour Name 	qdf_lro_deinit(CE_state->lro_data);
3237*5113495bSYour Name 
3238*5113495bSYour Name 	ce_ring_dump_unregister_region(CE_state, CE_id);
3239*5113495bSYour Name 
3240*5113495bSYour Name 	if (CE_state->src_ring) {
3241*5113495bSYour Name 		/* Cleanup the datapath Tx ring */
3242*5113495bSYour Name 		ce_h2t_tx_ce_cleanup(copyeng);
3243*5113495bSYour Name 
3244*5113495bSYour Name 		desc_size = ce_get_desc_size(scn, CE_RING_SRC);
3245*5113495bSYour Name 		if (CE_state->src_ring->shadow_base_unaligned)
3246*5113495bSYour Name 			qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
3247*5113495bSYour Name 		if (CE_state->src_ring->base_addr_owner_space_unaligned)
3248*5113495bSYour Name 			ce_free_desc_ring(scn, CE_state->id,
3249*5113495bSYour Name 					  CE_state->src_ring,
3250*5113495bSYour Name 					  desc_size);
3251*5113495bSYour Name 		ce_srng_cleanup(scn, CE_state, CE_RING_SRC);
3252*5113495bSYour Name 		qdf_mem_free(CE_state->src_ring);
3253*5113495bSYour Name 	}
3254*5113495bSYour Name 	if (CE_state->dest_ring) {
3255*5113495bSYour Name 		/* Cleanup the datapath Rx ring */
3256*5113495bSYour Name 		ce_t2h_msg_ce_cleanup(copyeng);
3257*5113495bSYour Name 
3258*5113495bSYour Name 		desc_size = ce_get_desc_size(scn, CE_RING_DEST);
3259*5113495bSYour Name 		if (CE_state->dest_ring->base_addr_owner_space_unaligned)
3260*5113495bSYour Name 			ce_free_desc_ring(scn, CE_state->id,
3261*5113495bSYour Name 					  CE_state->dest_ring,
3262*5113495bSYour Name 					  desc_size);
3263*5113495bSYour Name 		ce_srng_cleanup(scn, CE_state, CE_RING_DEST);
3264*5113495bSYour Name 		qdf_mem_free(CE_state->dest_ring);
3265*5113495bSYour Name 
3266*5113495bSYour Name 		/* epping */
3267*5113495bSYour Name 		if (inited) {
3268*5113495bSYour Name 			qdf_timer_free(&CE_state->poll_timer);
3269*5113495bSYour Name 		}
3270*5113495bSYour Name 	}
3271*5113495bSYour Name 	if ((ce_srng_based(CE_state->scn)) && (CE_state->status_ring)) {
3272*5113495bSYour Name 		/* Cleanup the datapath Tx ring */
3273*5113495bSYour Name 		ce_h2t_tx_ce_cleanup(copyeng);
3274*5113495bSYour Name 
3275*5113495bSYour Name 		if (CE_state->status_ring->shadow_base_unaligned)
3276*5113495bSYour Name 			qdf_mem_free(
3277*5113495bSYour Name 				CE_state->status_ring->shadow_base_unaligned);
3278*5113495bSYour Name 
3279*5113495bSYour Name 		desc_size = ce_get_desc_size(scn, CE_RING_STATUS);
3280*5113495bSYour Name 		if (CE_state->status_ring->base_addr_owner_space_unaligned)
3281*5113495bSYour Name 			ce_free_desc_ring(scn, CE_state->id,
3282*5113495bSYour Name 					  CE_state->status_ring,
3283*5113495bSYour Name 					  desc_size);
3284*5113495bSYour Name 		ce_srng_cleanup(scn, CE_state, CE_RING_STATUS);
3285*5113495bSYour Name 		qdf_mem_free(CE_state->status_ring);
3286*5113495bSYour Name 	}
3287*5113495bSYour Name 
3288*5113495bSYour Name 	free_mem_ce_debug_history(scn, CE_id);
3289*5113495bSYour Name 	reset_ce_debug_history(scn);
3290*5113495bSYour Name 	ce_deinit_ce_desc_event_log(scn, CE_id);
3291*5113495bSYour Name 
3292*5113495bSYour Name 	qdf_spinlock_destroy(&CE_state->ce_index_lock);
3293*5113495bSYour Name #ifdef CE_TASKLET_SCHEDULE_ON_FULL
3294*5113495bSYour Name 	qdf_spinlock_destroy(&CE_state->ce_interrupt_lock);
3295*5113495bSYour Name #endif
3296*5113495bSYour Name 	qdf_mem_free(CE_state);
3297*5113495bSYour Name }
3298*5113495bSYour Name 
hif_ce_desc_history_log_unregister(void)3299*5113495bSYour Name void hif_ce_desc_history_log_unregister(void)
3300*5113495bSYour Name {
3301*5113495bSYour Name 	__hif_ce_desc_history_log_unregister();
3302*5113495bSYour Name }
3303*5113495bSYour Name 
hif_detach_htc(struct hif_opaque_softc * hif_ctx)3304*5113495bSYour Name void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
3305*5113495bSYour Name {
3306*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
3307*5113495bSYour Name 
3308*5113495bSYour Name 	qdf_mem_zero(&hif_state->msg_callbacks_pending,
3309*5113495bSYour Name 		  sizeof(hif_state->msg_callbacks_pending));
3310*5113495bSYour Name 	qdf_mem_zero(&hif_state->msg_callbacks_current,
3311*5113495bSYour Name 		  sizeof(hif_state->msg_callbacks_current));
3312*5113495bSYour Name }
3313*5113495bSYour Name 
3314*5113495bSYour Name /* Send the first nbytes bytes of the buffer */
3315*5113495bSYour Name QDF_STATUS
hif_send_head(struct hif_opaque_softc * hif_ctx,uint8_t pipe,unsigned int transfer_id,unsigned int nbytes,qdf_nbuf_t nbuf,unsigned int data_attr)3316*5113495bSYour Name hif_send_head(struct hif_opaque_softc *hif_ctx,
3317*5113495bSYour Name 	      uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
3318*5113495bSYour Name 	      qdf_nbuf_t nbuf, unsigned int data_attr)
3319*5113495bSYour Name {
3320*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3321*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
3322*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
3323*5113495bSYour Name 	struct CE_handle *ce_hdl = pipe_info->ce_hdl;
3324*5113495bSYour Name 	int bytes = nbytes, nfrags = 0;
3325*5113495bSYour Name 	struct ce_sendlist sendlist;
3326*5113495bSYour Name 	int i = 0;
3327*5113495bSYour Name 	QDF_STATUS status;
3328*5113495bSYour Name 	unsigned int mux_id = 0;
3329*5113495bSYour Name 
3330*5113495bSYour Name 	if (nbytes > qdf_nbuf_len(nbuf)) {
3331*5113495bSYour Name 		hif_err("nbytes: %d nbuf_len: %d", nbytes,
3332*5113495bSYour Name 		       (uint32_t)qdf_nbuf_len(nbuf));
3333*5113495bSYour Name 		QDF_ASSERT(0);
3334*5113495bSYour Name 	}
3335*5113495bSYour Name 
3336*5113495bSYour Name 	transfer_id =
3337*5113495bSYour Name 		(mux_id & MUX_ID_MASK) |
3338*5113495bSYour Name 		(transfer_id & TRANSACTION_ID_MASK);
3339*5113495bSYour Name 	data_attr &= DESC_DATA_FLAG_MASK;
3340*5113495bSYour Name 	/*
3341*5113495bSYour Name 	 * The common case involves sending multiple fragments within a
3342*5113495bSYour Name 	 * single download (the tx descriptor and the tx frame header).
3343*5113495bSYour Name 	 * So, optimize for the case of multiple fragments by not even
3344*5113495bSYour Name 	 * checking whether it's necessary to use a sendlist.
3345*5113495bSYour Name 	 * The overhead of using a sendlist for a single buffer download
3346*5113495bSYour Name 	 * is not a big deal, since it happens rarely (for WMI messages).
3347*5113495bSYour Name 	 */
3348*5113495bSYour Name 	ce_sendlist_init(&sendlist);
3349*5113495bSYour Name 	do {
3350*5113495bSYour Name 		qdf_dma_addr_t frag_paddr;
3351*5113495bSYour Name 		int frag_bytes;
3352*5113495bSYour Name 
3353*5113495bSYour Name 		frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
3354*5113495bSYour Name 		frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
3355*5113495bSYour Name 		/*
3356*5113495bSYour Name 		 * Clear the packet offset for all but the first CE desc.
3357*5113495bSYour Name 		 */
3358*5113495bSYour Name 		if (i++ > 0)
3359*5113495bSYour Name 			data_attr &= ~CE_DESC_PKT_OFFSET_BIT_M;
3360*5113495bSYour Name 
3361*5113495bSYour Name 		status = ce_sendlist_buf_add(&sendlist, frag_paddr,
3362*5113495bSYour Name 				    frag_bytes >
3363*5113495bSYour Name 				    bytes ? bytes : frag_bytes,
3364*5113495bSYour Name 				    qdf_nbuf_get_frag_is_wordstream
3365*5113495bSYour Name 				    (nbuf,
3366*5113495bSYour Name 				    nfrags) ? 0 :
3367*5113495bSYour Name 				    CE_SEND_FLAG_SWAP_DISABLE,
3368*5113495bSYour Name 				    data_attr);
3369*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS) {
3370*5113495bSYour Name 			hif_err("frag_num: %d larger than limit (status=%d)",
3371*5113495bSYour Name 			       nfrags, status);
3372*5113495bSYour Name 			return status;
3373*5113495bSYour Name 		}
3374*5113495bSYour Name 		bytes -= frag_bytes;
3375*5113495bSYour Name 		nfrags++;
3376*5113495bSYour Name 	} while (bytes > 0);
3377*5113495bSYour Name 
3378*5113495bSYour Name 	/* Make sure we have resources to handle this request */
3379*5113495bSYour Name 	qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
3380*5113495bSYour Name 	if (pipe_info->num_sends_allowed < nfrags) {
3381*5113495bSYour Name 		qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
3382*5113495bSYour Name 		ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
3383*5113495bSYour Name 		return QDF_STATUS_E_RESOURCES;
3384*5113495bSYour Name 	}
3385*5113495bSYour Name 	pipe_info->num_sends_allowed -= nfrags;
3386*5113495bSYour Name 	qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
3387*5113495bSYour Name 
3388*5113495bSYour Name 	if (qdf_unlikely(!ce_hdl)) {
3389*5113495bSYour Name 		hif_err("CE handle is null");
3390*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
3391*5113495bSYour Name 	}
3392*5113495bSYour Name 
3393*5113495bSYour Name 	QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
3394*5113495bSYour Name 	DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
3395*5113495bSYour Name 		QDF_TRACE_DEFAULT_PDEV_ID, qdf_nbuf_data_addr(nbuf),
3396*5113495bSYour Name 		sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
3397*5113495bSYour Name 	status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
3398*5113495bSYour Name 	QDF_ASSERT(status == QDF_STATUS_SUCCESS);
3399*5113495bSYour Name 
3400*5113495bSYour Name 	return status;
3401*5113495bSYour Name }
3402*5113495bSYour Name 
hif_send_complete_check(struct hif_opaque_softc * hif_ctx,uint8_t pipe,int force)3403*5113495bSYour Name void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
3404*5113495bSYour Name 								int force)
3405*5113495bSYour Name {
3406*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3407*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
3408*5113495bSYour Name 
3409*5113495bSYour Name 	if (!force) {
3410*5113495bSYour Name 		int resources;
3411*5113495bSYour Name 		/*
3412*5113495bSYour Name 		 * Decide whether to actually poll for completions, or just
3413*5113495bSYour Name 		 * wait for a later chance. If there seem to be plenty of
3414*5113495bSYour Name 		 * resources left, then just wait, since checking involves
3415*5113495bSYour Name 		 * reading a CE register, which is a relatively expensive
3416*5113495bSYour Name 		 * operation.
3417*5113495bSYour Name 		 */
3418*5113495bSYour Name 		resources = hif_get_free_queue_number(hif_ctx, pipe);
3419*5113495bSYour Name 		/*
3420*5113495bSYour Name 		 * If at least 50% of the total resources are still available,
3421*5113495bSYour Name 		 * don't bother checking again yet.
3422*5113495bSYour Name 		 */
3423*5113495bSYour Name 		if (resources > (hif_state->host_ce_config[pipe].src_nentries >>
3424*5113495bSYour Name 									 1))
3425*5113495bSYour Name 			return;
3426*5113495bSYour Name 	}
3427*5113495bSYour Name #ifdef ATH_11AC_TXCOMPACT
3428*5113495bSYour Name 	ce_per_engine_servicereap(scn, pipe);
3429*5113495bSYour Name #else
3430*5113495bSYour Name 	ce_per_engine_service(scn, pipe);
3431*5113495bSYour Name #endif
3432*5113495bSYour Name }
3433*5113495bSYour Name 
3434*5113495bSYour Name #ifdef CUSTOM_CB_SCHEDULER_SUPPORT
3435*5113495bSYour Name QDF_STATUS
hif_register_ce_custom_cb(struct hif_opaque_softc * hif_ctx,uint8_t pipe,void (* custom_cb)(void *),void * custom_cb_context)3436*5113495bSYour Name hif_register_ce_custom_cb(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
3437*5113495bSYour Name 			  void (*custom_cb)(void *), void *custom_cb_context)
3438*5113495bSYour Name {
3439*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3440*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3441*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
3442*5113495bSYour Name 
3443*5113495bSYour Name 	if (pipe >= CE_COUNT_MAX)
3444*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
3445*5113495bSYour Name 
3446*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe];
3447*5113495bSYour Name 	ce_register_custom_cb(pipe_info->ce_hdl, custom_cb, custom_cb_context);
3448*5113495bSYour Name 
3449*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
3450*5113495bSYour Name }
3451*5113495bSYour Name 
3452*5113495bSYour Name QDF_STATUS
hif_unregister_ce_custom_cb(struct hif_opaque_softc * hif_ctx,uint8_t pipe)3453*5113495bSYour Name hif_unregister_ce_custom_cb(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
3454*5113495bSYour Name {
3455*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3456*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3457*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
3458*5113495bSYour Name 
3459*5113495bSYour Name 	if (pipe >= CE_COUNT_MAX)
3460*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
3461*5113495bSYour Name 
3462*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe];
3463*5113495bSYour Name 	ce_unregister_custom_cb(pipe_info->ce_hdl);
3464*5113495bSYour Name 
3465*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
3466*5113495bSYour Name }
3467*5113495bSYour Name 
3468*5113495bSYour Name QDF_STATUS
hif_enable_ce_custom_cb(struct hif_opaque_softc * hif_ctx,uint8_t pipe)3469*5113495bSYour Name hif_enable_ce_custom_cb(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
3470*5113495bSYour Name {
3471*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3472*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3473*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
3474*5113495bSYour Name 
3475*5113495bSYour Name 	if (pipe >= CE_COUNT_MAX)
3476*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
3477*5113495bSYour Name 
3478*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe];
3479*5113495bSYour Name 	ce_enable_custom_cb(pipe_info->ce_hdl);
3480*5113495bSYour Name 	ce_dispatch_interrupt(pipe, &hif_state->tasklets[pipe]);
3481*5113495bSYour Name 
3482*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
3483*5113495bSYour Name }
3484*5113495bSYour Name 
3485*5113495bSYour Name QDF_STATUS
hif_disable_ce_custom_cb(struct hif_opaque_softc * hif_ctx,uint8_t pipe)3486*5113495bSYour Name hif_disable_ce_custom_cb(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
3487*5113495bSYour Name {
3488*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
3489*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3490*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
3491*5113495bSYour Name 
3492*5113495bSYour Name 	if (pipe >= CE_COUNT_MAX)
3493*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
3494*5113495bSYour Name 
3495*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe];
3496*5113495bSYour Name 	ce_disable_custom_cb(pipe_info->ce_hdl);
3497*5113495bSYour Name 
3498*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
3499*5113495bSYour Name }
3500*5113495bSYour Name #endif /* CUSTOM_CB_SCHEDULER_SUPPORT */
3501*5113495bSYour Name 
3502*5113495bSYour Name #if defined(CE_TASKLET_SCHEDULE_ON_FULL) && defined(CE_TASKLET_DEBUG_ENABLE)
3503*5113495bSYour Name #define CE_RING_FULL_THRESHOLD_TIME 3000000
3504*5113495bSYour Name #define CE_RING_FULL_THRESHOLD 1024
3505*5113495bSYour Name /* This function is called from htc_send path. If there is no resourse to send
3506*5113495bSYour Name  * packet via HTC, then check if interrupts are not processed from that
3507*5113495bSYour Name  * CE for last 3 seconds. If so, schedule a tasklet to reap available entries.
3508*5113495bSYour Name  * Also if Queue has reached 1024 entries within 3 seconds, then also schedule
3509*5113495bSYour Name  * tasklet.
3510*5113495bSYour Name  */
hif_schedule_ce_tasklet(struct hif_opaque_softc * hif_ctx,uint8_t pipe)3511*5113495bSYour Name void hif_schedule_ce_tasklet(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
3512*5113495bSYour Name {
3513*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
3514*5113495bSYour Name 	int64_t diff_time = qdf_get_log_timestamp_usecs() -
3515*5113495bSYour Name 			hif_state->stats.tasklet_sched_entry_ts[pipe];
3516*5113495bSYour Name 
3517*5113495bSYour Name 	hif_state->stats.ce_ring_full_count[pipe]++;
3518*5113495bSYour Name 
3519*5113495bSYour Name 	if (diff_time >= CE_RING_FULL_THRESHOLD_TIME ||
3520*5113495bSYour Name 	    hif_state->stats.ce_ring_full_count[pipe] >=
3521*5113495bSYour Name 	    CE_RING_FULL_THRESHOLD) {
3522*5113495bSYour Name 		hif_state->stats.ce_ring_full_count[pipe] = 0;
3523*5113495bSYour Name 		hif_state->stats.ce_manual_tasklet_schedule_count[pipe]++;
3524*5113495bSYour Name 		hif_state->stats.ce_last_manual_tasklet_schedule_ts[pipe] =
3525*5113495bSYour Name 			qdf_get_log_timestamp_usecs();
3526*5113495bSYour Name 		ce_dispatch_interrupt(pipe, &hif_state->tasklets[pipe]);
3527*5113495bSYour Name 	}
3528*5113495bSYour Name }
3529*5113495bSYour Name #else
hif_schedule_ce_tasklet(struct hif_opaque_softc * hif_ctx,uint8_t pipe)3530*5113495bSYour Name void hif_schedule_ce_tasklet(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
3531*5113495bSYour Name {
3532*5113495bSYour Name }
3533*5113495bSYour Name #endif
3534*5113495bSYour Name 
3535*5113495bSYour Name uint16_t
hif_get_free_queue_number(struct hif_opaque_softc * hif_ctx,uint8_t pipe)3536*5113495bSYour Name hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
3537*5113495bSYour Name {
3538*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
3539*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
3540*5113495bSYour Name 	uint16_t rv;
3541*5113495bSYour Name 
3542*5113495bSYour Name 	qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
3543*5113495bSYour Name 	rv = pipe_info->num_sends_allowed;
3544*5113495bSYour Name 	qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
3545*5113495bSYour Name 	return rv;
3546*5113495bSYour Name }
3547*5113495bSYour Name 
3548*5113495bSYour Name /* Called by lower (CE) layer when a send to Target completes. */
3549*5113495bSYour Name static void
hif_pci_ce_send_done(struct CE_handle * copyeng,void * ce_context,void * transfer_context,qdf_dma_addr_t CE_data,unsigned int nbytes,unsigned int transfer_id,unsigned int sw_index,unsigned int hw_index,unsigned int toeplitz_hash_result)3550*5113495bSYour Name hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
3551*5113495bSYour Name 		     void *transfer_context, qdf_dma_addr_t CE_data,
3552*5113495bSYour Name 		     unsigned int nbytes, unsigned int transfer_id,
3553*5113495bSYour Name 		     unsigned int sw_index, unsigned int hw_index,
3554*5113495bSYour Name 		     unsigned int toeplitz_hash_result)
3555*5113495bSYour Name {
3556*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info =
3557*5113495bSYour Name 		(struct HIF_CE_pipe_info *)ce_context;
3558*5113495bSYour Name 	unsigned int sw_idx = sw_index, hw_idx = hw_index;
3559*5113495bSYour Name 	struct hif_msg_callbacks *msg_callbacks =
3560*5113495bSYour Name 		&pipe_info->pipe_callbacks;
3561*5113495bSYour Name 
3562*5113495bSYour Name 	do {
3563*5113495bSYour Name 		/*
3564*5113495bSYour Name 		 * The upper layer callback will be triggered
3565*5113495bSYour Name 		 * when last fragment is complteted.
3566*5113495bSYour Name 		 */
3567*5113495bSYour Name 		if (transfer_context != CE_SENDLIST_ITEM_CTXT)
3568*5113495bSYour Name 			msg_callbacks->txCompletionHandler(
3569*5113495bSYour Name 				msg_callbacks->Context,
3570*5113495bSYour Name 				transfer_context, transfer_id,
3571*5113495bSYour Name 				toeplitz_hash_result);
3572*5113495bSYour Name 
3573*5113495bSYour Name 		qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
3574*5113495bSYour Name 		pipe_info->num_sends_allowed++;
3575*5113495bSYour Name 		qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
3576*5113495bSYour Name 	} while (ce_completed_send_next(copyeng,
3577*5113495bSYour Name 			&ce_context, &transfer_context,
3578*5113495bSYour Name 			&CE_data, &nbytes, &transfer_id,
3579*5113495bSYour Name 			&sw_idx, &hw_idx,
3580*5113495bSYour Name 			&toeplitz_hash_result) == QDF_STATUS_SUCCESS);
3581*5113495bSYour Name }
3582*5113495bSYour Name 
3583*5113495bSYour Name /**
3584*5113495bSYour Name  * hif_ce_do_recv(): send message from copy engine to upper layers
3585*5113495bSYour Name  * @msg_callbacks: structure containing callback and callback context
3586*5113495bSYour Name  * @netbuf: skb containing message
3587*5113495bSYour Name  * @nbytes: number of bytes in the message
3588*5113495bSYour Name  * @pipe_info: used for the pipe_number info
3589*5113495bSYour Name  *
3590*5113495bSYour Name  * Checks the packet length, configures the length in the netbuff,
3591*5113495bSYour Name  * and calls the upper layer callback.
3592*5113495bSYour Name  *
3593*5113495bSYour Name  * return: None
3594*5113495bSYour Name  */
hif_ce_do_recv(struct hif_msg_callbacks * msg_callbacks,qdf_nbuf_t netbuf,int nbytes,struct HIF_CE_pipe_info * pipe_info)3595*5113495bSYour Name static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
3596*5113495bSYour Name 		qdf_nbuf_t netbuf, int nbytes,
3597*5113495bSYour Name 		struct HIF_CE_pipe_info *pipe_info) {
3598*5113495bSYour Name 	if (nbytes <= pipe_info->buf_sz) {
3599*5113495bSYour Name 		qdf_nbuf_set_pktlen(netbuf, nbytes);
3600*5113495bSYour Name 		msg_callbacks->
3601*5113495bSYour Name 			rxCompletionHandler(msg_callbacks->Context,
3602*5113495bSYour Name 					netbuf, pipe_info->pipe_num);
3603*5113495bSYour Name 	} else {
3604*5113495bSYour Name 		hif_err("Invalid Rx msg buf: %pK nbytes: %d", netbuf, nbytes);
3605*5113495bSYour Name 		hif_ce_rx_nbuf_free(netbuf);
3606*5113495bSYour Name 	}
3607*5113495bSYour Name }
3608*5113495bSYour Name 
3609*5113495bSYour Name #ifdef WLAN_FEATURE_WMI_DIAG_OVER_CE7
3610*5113495bSYour Name /**
3611*5113495bSYour Name  * hif_ce_rtpm_mark_last_busy() - record and mark last busy for RTPM
3612*5113495bSYour Name  * @scn: hif_softc pointer.
3613*5113495bSYour Name  * @ce_id: ce ID
3614*5113495bSYour Name  *
3615*5113495bSYour Name  * Return: None
3616*5113495bSYour Name  */
3617*5113495bSYour Name static inline void
hif_ce_rtpm_mark_last_busy(struct hif_softc * scn,uint32_t ce_id)3618*5113495bSYour Name hif_ce_rtpm_mark_last_busy(struct hif_softc *scn, uint32_t ce_id)
3619*5113495bSYour Name {
3620*5113495bSYour Name 	/* do NOT mark last busy for diag event, to avoid impacting RTPM */
3621*5113495bSYour Name 	if (ce_id == CE_ID_7)
3622*5113495bSYour Name 		return;
3623*5113495bSYour Name 
3624*5113495bSYour Name 	hif_rtpm_record_ce_last_busy_evt(scn, ce_id);
3625*5113495bSYour Name 	hif_rtpm_mark_last_busy(HIF_RTPM_ID_CE);
3626*5113495bSYour Name }
3627*5113495bSYour Name #else
3628*5113495bSYour Name static inline void
hif_ce_rtpm_mark_last_busy(struct hif_softc * scn,uint32_t ce_id)3629*5113495bSYour Name hif_ce_rtpm_mark_last_busy(struct hif_softc *scn, uint32_t ce_id)
3630*5113495bSYour Name {
3631*5113495bSYour Name 	hif_rtpm_record_ce_last_busy_evt(scn, ce_id);
3632*5113495bSYour Name 	hif_rtpm_mark_last_busy(HIF_RTPM_ID_CE);
3633*5113495bSYour Name }
3634*5113495bSYour Name #endif
3635*5113495bSYour Name 
3636*5113495bSYour Name /* Called by lower (CE) layer when data is received from the Target. */
3637*5113495bSYour Name static void
hif_pci_ce_recv_data(struct CE_handle * copyeng,void * ce_context,void * transfer_context,qdf_dma_addr_t CE_data,unsigned int nbytes,unsigned int transfer_id,unsigned int flags)3638*5113495bSYour Name hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
3639*5113495bSYour Name 		     void *transfer_context, qdf_dma_addr_t CE_data,
3640*5113495bSYour Name 		     unsigned int nbytes, unsigned int transfer_id,
3641*5113495bSYour Name 		     unsigned int flags)
3642*5113495bSYour Name {
3643*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info =
3644*5113495bSYour Name 		(struct HIF_CE_pipe_info *)ce_context;
3645*5113495bSYour Name 	struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
3646*5113495bSYour Name 	struct CE_state *ce_state = (struct CE_state *) copyeng;
3647*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
3648*5113495bSYour Name 	struct hif_msg_callbacks *msg_callbacks = &pipe_info->pipe_callbacks;
3649*5113495bSYour Name 
3650*5113495bSYour Name 	do {
3651*5113495bSYour Name 		hif_ce_rtpm_mark_last_busy(scn, ce_state->id);
3652*5113495bSYour Name 		qdf_nbuf_unmap_single(scn->qdf_dev,
3653*5113495bSYour Name 				      (qdf_nbuf_t) transfer_context,
3654*5113495bSYour Name 				      QDF_DMA_FROM_DEVICE);
3655*5113495bSYour Name 
3656*5113495bSYour Name 		atomic_inc(&pipe_info->recv_bufs_needed);
3657*5113495bSYour Name 		hif_post_recv_buffers_for_pipe(pipe_info);
3658*5113495bSYour Name 		if (scn->target_status == TARGET_STATUS_RESET)
3659*5113495bSYour Name 			hif_ce_rx_nbuf_free(transfer_context);
3660*5113495bSYour Name 		else
3661*5113495bSYour Name 			hif_ce_do_recv(msg_callbacks, transfer_context,
3662*5113495bSYour Name 				nbytes, pipe_info);
3663*5113495bSYour Name 
3664*5113495bSYour Name 		/* Set up force_break flag if num of receices reaches
3665*5113495bSYour Name 		 * MAX_NUM_OF_RECEIVES
3666*5113495bSYour Name 		 */
3667*5113495bSYour Name 		ce_state->receive_count++;
3668*5113495bSYour Name 		if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
3669*5113495bSYour Name 			ce_state->force_break = 1;
3670*5113495bSYour Name 			break;
3671*5113495bSYour Name 		}
3672*5113495bSYour Name 	} while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
3673*5113495bSYour Name 					&CE_data, &nbytes, &transfer_id,
3674*5113495bSYour Name 					&flags) == QDF_STATUS_SUCCESS);
3675*5113495bSYour Name 
3676*5113495bSYour Name }
3677*5113495bSYour Name 
3678*5113495bSYour Name /* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
3679*5113495bSYour Name 
3680*5113495bSYour Name void
hif_post_init(struct hif_opaque_softc * hif_ctx,void * unused,struct hif_msg_callbacks * callbacks)3681*5113495bSYour Name hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
3682*5113495bSYour Name 	      struct hif_msg_callbacks *callbacks)
3683*5113495bSYour Name {
3684*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
3685*5113495bSYour Name 
3686*5113495bSYour Name #ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
3687*5113495bSYour Name 	spin_lock_init(&pcie_access_log_lock);
3688*5113495bSYour Name #endif
3689*5113495bSYour Name 	/* Save callbacks for later installation */
3690*5113495bSYour Name 	qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
3691*5113495bSYour Name 		 sizeof(hif_state->msg_callbacks_pending));
3692*5113495bSYour Name 
3693*5113495bSYour Name }
3694*5113495bSYour Name 
hif_completion_thread_startup_by_ceid(struct HIF_CE_state * hif_state,int pipe_num)3695*5113495bSYour Name static int hif_completion_thread_startup_by_ceid(struct HIF_CE_state *hif_state,
3696*5113495bSYour Name 						 int pipe_num)
3697*5113495bSYour Name {
3698*5113495bSYour Name 	struct CE_attr attr;
3699*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
3700*5113495bSYour Name 	struct hif_msg_callbacks *hif_msg_callbacks =
3701*5113495bSYour Name 		&hif_state->msg_callbacks_current;
3702*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
3703*5113495bSYour Name 	struct CE_state *ce_state;
3704*5113495bSYour Name 
3705*5113495bSYour Name 	if (pipe_num >= CE_COUNT_MAX)
3706*5113495bSYour Name 		return -EINVAL;
3707*5113495bSYour Name 
3708*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe_num];
3709*5113495bSYour Name 	ce_state = scn->ce_id_to_state[pipe_num];
3710*5113495bSYour Name 
3711*5113495bSYour Name 	if (!hif_msg_callbacks ||
3712*5113495bSYour Name 	    !hif_msg_callbacks->rxCompletionHandler ||
3713*5113495bSYour Name 	    !hif_msg_callbacks->txCompletionHandler) {
3714*5113495bSYour Name 		hif_err("no completion handler registered");
3715*5113495bSYour Name 		return -EFAULT;
3716*5113495bSYour Name 	}
3717*5113495bSYour Name 
3718*5113495bSYour Name 	attr = hif_state->host_ce_config[pipe_num];
3719*5113495bSYour Name 	if (attr.src_nentries) {
3720*5113495bSYour Name 		/* pipe used to send to target */
3721*5113495bSYour Name 		hif_debug("pipe_num:%d pipe_info:0x%pK\n",
3722*5113495bSYour Name 			  pipe_num, pipe_info);
3723*5113495bSYour Name 		ce_send_cb_register(pipe_info->ce_hdl,
3724*5113495bSYour Name 				    hif_pci_ce_send_done, pipe_info,
3725*5113495bSYour Name 				    attr.flags & CE_ATTR_DISABLE_INTR);
3726*5113495bSYour Name 		pipe_info->num_sends_allowed = attr.src_nentries - 1;
3727*5113495bSYour Name 	}
3728*5113495bSYour Name 	if (attr.dest_nentries) {
3729*5113495bSYour Name 		hif_debug("pipe_num:%d pipe_info:0x%pK\n",
3730*5113495bSYour Name 			  pipe_num, pipe_info);
3731*5113495bSYour Name 		/* pipe used to receive from target */
3732*5113495bSYour Name 		ce_recv_cb_register(pipe_info->ce_hdl,
3733*5113495bSYour Name 				    hif_pci_ce_recv_data, pipe_info,
3734*5113495bSYour Name 				    attr.flags & CE_ATTR_DISABLE_INTR);
3735*5113495bSYour Name 	}
3736*5113495bSYour Name 
3737*5113495bSYour Name 	if (attr.src_nentries)
3738*5113495bSYour Name 		qdf_spinlock_create(&pipe_info->completion_freeq_lock);
3739*5113495bSYour Name 
3740*5113495bSYour Name 	if (!(ce_state->attr_flags & CE_ATTR_INIT_ON_DEMAND))
3741*5113495bSYour Name 		qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks,
3742*5113495bSYour Name 			     sizeof(pipe_info->pipe_callbacks));
3743*5113495bSYour Name 
3744*5113495bSYour Name 	return 0;
3745*5113495bSYour Name }
3746*5113495bSYour Name 
hif_completion_thread_startup(struct HIF_CE_state * hif_state)3747*5113495bSYour Name static int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
3748*5113495bSYour Name {
3749*5113495bSYour Name 	struct CE_handle *ce_diag = hif_state->ce_diag;
3750*5113495bSYour Name 	int pipe_num, ret;
3751*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
3752*5113495bSYour Name 
3753*5113495bSYour Name 	/* daemonize("hif_compl_thread"); */
3754*5113495bSYour Name 
3755*5113495bSYour Name 	if (scn->ce_count == 0) {
3756*5113495bSYour Name 		hif_err("ce_count is 0");
3757*5113495bSYour Name 		return -EINVAL;
3758*5113495bSYour Name 	}
3759*5113495bSYour Name 
3760*5113495bSYour Name 
3761*5113495bSYour Name 	A_TARGET_ACCESS_LIKELY(scn);
3762*5113495bSYour Name 	for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
3763*5113495bSYour Name 		struct HIF_CE_pipe_info *pipe_info;
3764*5113495bSYour Name 
3765*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[pipe_num];
3766*5113495bSYour Name 		if (pipe_info->ce_hdl == ce_diag)
3767*5113495bSYour Name 			continue;       /* Handle Diagnostic CE specially */
3768*5113495bSYour Name 
3769*5113495bSYour Name 		ret = hif_completion_thread_startup_by_ceid(hif_state,
3770*5113495bSYour Name 							    pipe_num);
3771*5113495bSYour Name 		if (ret < 0)
3772*5113495bSYour Name 			return ret;
3773*5113495bSYour Name 
3774*5113495bSYour Name 	}
3775*5113495bSYour Name 
3776*5113495bSYour Name 	A_TARGET_ACCESS_UNLIKELY(scn);
3777*5113495bSYour Name 	return 0;
3778*5113495bSYour Name }
3779*5113495bSYour Name 
3780*5113495bSYour Name /*
3781*5113495bSYour Name  * Install pending msg callbacks.
3782*5113495bSYour Name  *
3783*5113495bSYour Name  * TBDXXX: This hack is needed because upper layers install msg callbacks
3784*5113495bSYour Name  * for use with HTC before BMI is done; yet this HIF implementation
3785*5113495bSYour Name  * needs to continue to use BMI msg callbacks. Really, upper layers
3786*5113495bSYour Name  * should not register HTC callbacks until AFTER BMI phase.
3787*5113495bSYour Name  */
hif_msg_callbacks_install(struct hif_softc * scn)3788*5113495bSYour Name static void hif_msg_callbacks_install(struct hif_softc *scn)
3789*5113495bSYour Name {
3790*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3791*5113495bSYour Name 
3792*5113495bSYour Name 	qdf_mem_copy(&hif_state->msg_callbacks_current,
3793*5113495bSYour Name 		 &hif_state->msg_callbacks_pending,
3794*5113495bSYour Name 		 sizeof(hif_state->msg_callbacks_pending));
3795*5113495bSYour Name }
3796*5113495bSYour Name 
hif_get_default_pipe(struct hif_opaque_softc * hif_hdl,uint8_t * ULPipe,uint8_t * DLPipe)3797*5113495bSYour Name void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
3798*5113495bSYour Name 							uint8_t *DLPipe)
3799*5113495bSYour Name {
3800*5113495bSYour Name 	int ul_is_polled, dl_is_polled;
3801*5113495bSYour Name 
3802*5113495bSYour Name 	(void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
3803*5113495bSYour Name 		ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
3804*5113495bSYour Name }
3805*5113495bSYour Name 
3806*5113495bSYour Name /**
3807*5113495bSYour Name  * hif_dump_pipe_debug_count() - Log error count
3808*5113495bSYour Name  * @scn: hif_softc pointer.
3809*5113495bSYour Name  *
3810*5113495bSYour Name  * Output the pipe error counts of each pipe to log file
3811*5113495bSYour Name  *
3812*5113495bSYour Name  * Return: N/A
3813*5113495bSYour Name  */
hif_dump_pipe_debug_count(struct hif_softc * scn)3814*5113495bSYour Name void hif_dump_pipe_debug_count(struct hif_softc *scn)
3815*5113495bSYour Name {
3816*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3817*5113495bSYour Name 	int pipe_num;
3818*5113495bSYour Name 
3819*5113495bSYour Name 	if (!hif_state) {
3820*5113495bSYour Name 		hif_err("hif_state is NULL");
3821*5113495bSYour Name 		return;
3822*5113495bSYour Name 	}
3823*5113495bSYour Name 	for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
3824*5113495bSYour Name 		struct HIF_CE_pipe_info *pipe_info;
3825*5113495bSYour Name 
3826*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe_num];
3827*5113495bSYour Name 
3828*5113495bSYour Name 	if (pipe_info->nbuf_alloc_err_count > 0 ||
3829*5113495bSYour Name 			pipe_info->nbuf_dma_err_count > 0 ||
3830*5113495bSYour Name 			pipe_info->nbuf_ce_enqueue_err_count)
3831*5113495bSYour Name 		hif_err(
3832*5113495bSYour Name 			"pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
3833*5113495bSYour Name 			pipe_info->pipe_num,
3834*5113495bSYour Name 			atomic_read(&pipe_info->recv_bufs_needed),
3835*5113495bSYour Name 			pipe_info->nbuf_alloc_err_count,
3836*5113495bSYour Name 			pipe_info->nbuf_dma_err_count,
3837*5113495bSYour Name 			pipe_info->nbuf_ce_enqueue_err_count);
3838*5113495bSYour Name 	}
3839*5113495bSYour Name }
3840*5113495bSYour Name 
hif_post_recv_buffers_failure(struct HIF_CE_pipe_info * pipe_info,void * nbuf,uint32_t * error_cnt,enum hif_ce_event_type failure_type,const char * failure_type_string)3841*5113495bSYour Name static void hif_post_recv_buffers_failure(struct HIF_CE_pipe_info *pipe_info,
3842*5113495bSYour Name 					  void *nbuf, uint32_t *error_cnt,
3843*5113495bSYour Name 					  enum hif_ce_event_type failure_type,
3844*5113495bSYour Name 					  const char *failure_type_string)
3845*5113495bSYour Name {
3846*5113495bSYour Name 	int bufs_needed_tmp = atomic_inc_return(&pipe_info->recv_bufs_needed);
3847*5113495bSYour Name 	struct CE_state *CE_state = (struct CE_state *)pipe_info->ce_hdl;
3848*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
3849*5113495bSYour Name 	int ce_id = CE_state->id;
3850*5113495bSYour Name 	uint32_t error_cnt_tmp;
3851*5113495bSYour Name 
3852*5113495bSYour Name 	qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
3853*5113495bSYour Name 	error_cnt_tmp = ++(*error_cnt);
3854*5113495bSYour Name 	qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
3855*5113495bSYour Name 	hif_debug("pipe_num: %d, needed: %d, err_cnt: %u, fail_type: %s",
3856*5113495bSYour Name 		  pipe_info->pipe_num, bufs_needed_tmp, error_cnt_tmp,
3857*5113495bSYour Name 		  failure_type_string);
3858*5113495bSYour Name 	hif_record_ce_desc_event(scn, ce_id, failure_type,
3859*5113495bSYour Name 				 NULL, nbuf, bufs_needed_tmp, 0);
3860*5113495bSYour Name 	/* if we fail to allocate the last buffer for an rx pipe,
3861*5113495bSYour Name 	 *	there is no trigger to refill the ce and we will
3862*5113495bSYour Name 	 *	eventually crash
3863*5113495bSYour Name 	 */
3864*5113495bSYour Name 	if (bufs_needed_tmp == CE_state->dest_ring->nentries - 1 ||
3865*5113495bSYour Name 	    (ce_srng_based(scn) &&
3866*5113495bSYour Name 	     bufs_needed_tmp == CE_state->dest_ring->nentries - 2)) {
3867*5113495bSYour Name 		qdf_atomic_inc(&scn->active_oom_work_cnt);
3868*5113495bSYour Name 		if (!qdf_sched_work(scn->qdf_dev,
3869*5113495bSYour Name 				    &CE_state->oom_allocation_work))
3870*5113495bSYour Name 			qdf_atomic_dec(&scn->active_oom_work_cnt);
3871*5113495bSYour Name 	}
3872*5113495bSYour Name 
3873*5113495bSYour Name }
3874*5113495bSYour Name 
hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info * pipe_info)3875*5113495bSYour Name QDF_STATUS hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
3876*5113495bSYour Name {
3877*5113495bSYour Name 	struct CE_handle *ce_hdl;
3878*5113495bSYour Name 	qdf_size_t buf_sz;
3879*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
3880*5113495bSYour Name 	QDF_STATUS status;
3881*5113495bSYour Name 	uint32_t bufs_posted = 0;
3882*5113495bSYour Name 	unsigned int ce_id;
3883*5113495bSYour Name 
3884*5113495bSYour Name 	buf_sz = pipe_info->buf_sz;
3885*5113495bSYour Name 	if (buf_sz == 0) {
3886*5113495bSYour Name 		/* Unused Copy Engine */
3887*5113495bSYour Name 		return QDF_STATUS_SUCCESS;
3888*5113495bSYour Name 	}
3889*5113495bSYour Name 
3890*5113495bSYour Name 	ce_hdl = pipe_info->ce_hdl;
3891*5113495bSYour Name 	if (!ce_hdl) {
3892*5113495bSYour Name 		hif_err("ce_hdl is NULL");
3893*5113495bSYour Name 		return QDF_STATUS_E_INVAL;
3894*5113495bSYour Name 	}
3895*5113495bSYour Name 
3896*5113495bSYour Name 	ce_id = ((struct CE_state *)ce_hdl)->id;
3897*5113495bSYour Name 
3898*5113495bSYour Name 	qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
3899*5113495bSYour Name 	while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
3900*5113495bSYour Name 		qdf_dma_addr_t CE_data;      /* CE space buffer address */
3901*5113495bSYour Name 		qdf_nbuf_t nbuf;
3902*5113495bSYour Name 
3903*5113495bSYour Name 		atomic_dec(&pipe_info->recv_bufs_needed);
3904*5113495bSYour Name 		qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
3905*5113495bSYour Name 
3906*5113495bSYour Name 		hif_record_ce_desc_event(scn, ce_id,
3907*5113495bSYour Name 					 HIF_RX_DESC_PRE_NBUF_ALLOC, NULL, NULL,
3908*5113495bSYour Name 					 0, 0);
3909*5113495bSYour Name 		nbuf = hif_ce_rx_nbuf_alloc(scn, ce_id);
3910*5113495bSYour Name 		if (!nbuf) {
3911*5113495bSYour Name 			hif_post_recv_buffers_failure(pipe_info, nbuf,
3912*5113495bSYour Name 					&pipe_info->nbuf_alloc_err_count,
3913*5113495bSYour Name 					 HIF_RX_NBUF_ALLOC_FAILURE,
3914*5113495bSYour Name 					"HIF_RX_NBUF_ALLOC_FAILURE");
3915*5113495bSYour Name 			return QDF_STATUS_E_NOMEM;
3916*5113495bSYour Name 		}
3917*5113495bSYour Name 
3918*5113495bSYour Name 		hif_record_ce_desc_event(scn, ce_id,
3919*5113495bSYour Name 					 HIF_RX_DESC_PRE_NBUF_MAP, NULL, nbuf,
3920*5113495bSYour Name 					 0, 0);
3921*5113495bSYour Name 		/*
3922*5113495bSYour Name 		 * qdf_nbuf_peek_header(nbuf, &data, &unused);
3923*5113495bSYour Name 		 * CE_data = dma_map_single(dev, data, buf_sz, );
3924*5113495bSYour Name 		 * DMA_FROM_DEVICE);
3925*5113495bSYour Name 		 */
3926*5113495bSYour Name 		status = qdf_nbuf_map_single(scn->qdf_dev, nbuf,
3927*5113495bSYour Name 					    QDF_DMA_FROM_DEVICE);
3928*5113495bSYour Name 
3929*5113495bSYour Name 		if (qdf_unlikely(status != QDF_STATUS_SUCCESS)) {
3930*5113495bSYour Name 			hif_post_recv_buffers_failure(pipe_info, nbuf,
3931*5113495bSYour Name 					&pipe_info->nbuf_dma_err_count,
3932*5113495bSYour Name 					 HIF_RX_NBUF_MAP_FAILURE,
3933*5113495bSYour Name 					"HIF_RX_NBUF_MAP_FAILURE");
3934*5113495bSYour Name 			hif_ce_rx_nbuf_free(nbuf);
3935*5113495bSYour Name 			return status;
3936*5113495bSYour Name 		}
3937*5113495bSYour Name 
3938*5113495bSYour Name 		CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
3939*5113495bSYour Name 		hif_record_ce_desc_event(scn, ce_id,
3940*5113495bSYour Name 					 HIF_RX_DESC_POST_NBUF_MAP, NULL, nbuf,
3941*5113495bSYour Name 					 0, 0);
3942*5113495bSYour Name 		qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
3943*5113495bSYour Name 					       buf_sz, DMA_FROM_DEVICE);
3944*5113495bSYour Name 		status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
3945*5113495bSYour Name 		if (qdf_unlikely(status != QDF_STATUS_SUCCESS)) {
3946*5113495bSYour Name 			hif_post_recv_buffers_failure(pipe_info, nbuf,
3947*5113495bSYour Name 					&pipe_info->nbuf_ce_enqueue_err_count,
3948*5113495bSYour Name 					 HIF_RX_NBUF_ENQUEUE_FAILURE,
3949*5113495bSYour Name 					"HIF_RX_NBUF_ENQUEUE_FAILURE");
3950*5113495bSYour Name 
3951*5113495bSYour Name 			qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
3952*5113495bSYour Name 						QDF_DMA_FROM_DEVICE);
3953*5113495bSYour Name 			hif_ce_rx_nbuf_free(nbuf);
3954*5113495bSYour Name 			return status;
3955*5113495bSYour Name 		}
3956*5113495bSYour Name 
3957*5113495bSYour Name 		qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
3958*5113495bSYour Name 		bufs_posted++;
3959*5113495bSYour Name 	}
3960*5113495bSYour Name 	pipe_info->nbuf_alloc_err_count =
3961*5113495bSYour Name 		(pipe_info->nbuf_alloc_err_count > bufs_posted) ?
3962*5113495bSYour Name 		pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
3963*5113495bSYour Name 	pipe_info->nbuf_dma_err_count =
3964*5113495bSYour Name 		(pipe_info->nbuf_dma_err_count > bufs_posted) ?
3965*5113495bSYour Name 		pipe_info->nbuf_dma_err_count - bufs_posted : 0;
3966*5113495bSYour Name 	pipe_info->nbuf_ce_enqueue_err_count =
3967*5113495bSYour Name 		(pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
3968*5113495bSYour Name 	pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
3969*5113495bSYour Name 
3970*5113495bSYour Name 	qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
3971*5113495bSYour Name 
3972*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
3973*5113495bSYour Name }
3974*5113495bSYour Name 
3975*5113495bSYour Name #ifdef FEATURE_DIRECT_LINK
3976*5113495bSYour Name static QDF_STATUS
hif_alloc_pages_for_direct_link_recv_pipe(struct HIF_CE_state * hif_ce_state,int pipe_num)3977*5113495bSYour Name hif_alloc_pages_for_direct_link_recv_pipe(struct HIF_CE_state *hif_ce_state,
3978*5113495bSYour Name 					  int pipe_num)
3979*5113495bSYour Name {
3980*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ce_state);
3981*5113495bSYour Name 	struct service_to_pipe *tgt_svc_cfg;
3982*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
3983*5113495bSYour Name 	int32_t recv_bufs_needed;
3984*5113495bSYour Name 	qdf_dma_addr_t dma_addr;
3985*5113495bSYour Name 	uint16_t num_elem_per_page;
3986*5113495bSYour Name 	uint16_t i;
3987*5113495bSYour Name 	bool is_found = false;
3988*5113495bSYour Name 
3989*5113495bSYour Name 	tgt_svc_cfg = hif_ce_state->tgt_svc_map;
3990*5113495bSYour Name 
3991*5113495bSYour Name 	for (i = 0; i < hif_ce_state->sz_tgt_svc_map; i++) {
3992*5113495bSYour Name 		if (tgt_svc_cfg[i].service_id != LPASS_DATA_MSG_SVC ||
3993*5113495bSYour Name 		    tgt_svc_cfg[i].pipedir != PIPEDIR_IN ||
3994*5113495bSYour Name 		    tgt_svc_cfg[i].pipenum != pipe_num)
3995*5113495bSYour Name 			continue;
3996*5113495bSYour Name 
3997*5113495bSYour Name 		pipe_info = &hif_ce_state->pipe_info[pipe_num];
3998*5113495bSYour Name 		recv_bufs_needed = atomic_read(&pipe_info->recv_bufs_needed);
3999*5113495bSYour Name 
4000*5113495bSYour Name 		if (!pipe_info->buf_sz || !recv_bufs_needed)
4001*5113495bSYour Name 			continue;
4002*5113495bSYour Name 
4003*5113495bSYour Name 		is_found = true;
4004*5113495bSYour Name 		break;
4005*5113495bSYour Name 	}
4006*5113495bSYour Name 
4007*5113495bSYour Name 	if (!is_found)
4008*5113495bSYour Name 		return QDF_STATUS_E_NOSUPPORT;
4009*5113495bSYour Name 
4010*5113495bSYour Name 	scn->dl_recv_pipe_num = pipe_num;
4011*5113495bSYour Name 
4012*5113495bSYour Name 	hif_prealloc_get_multi_pages(scn, QDF_DP_RX_DIRECT_LINK_CE_BUF_TYPE,
4013*5113495bSYour Name 				     pipe_info->buf_sz, recv_bufs_needed,
4014*5113495bSYour Name 				     &scn->dl_recv_pages, false);
4015*5113495bSYour Name 	if (!scn->dl_recv_pages.num_pages)
4016*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
4017*5113495bSYour Name 
4018*5113495bSYour Name 	num_elem_per_page = scn->dl_recv_pages.num_element_per_page;
4019*5113495bSYour Name 	for (i = 0; i < recv_bufs_needed; i++) {
4020*5113495bSYour Name 		dma_addr = scn->dl_recv_pages.dma_pages[i / num_elem_per_page].page_p_addr;
4021*5113495bSYour Name 		dma_addr += (i % num_elem_per_page) * pipe_info->buf_sz;
4022*5113495bSYour Name 		ce_recv_buf_enqueue(pipe_info->ce_hdl, NULL, dma_addr);
4023*5113495bSYour Name 	}
4024*5113495bSYour Name 
4025*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
4026*5113495bSYour Name }
4027*5113495bSYour Name 
4028*5113495bSYour Name static QDF_STATUS
hif_free_pages_for_direct_link_recv_pipe(struct HIF_CE_state * hif_ce_state,int pipe_num)4029*5113495bSYour Name hif_free_pages_for_direct_link_recv_pipe(struct HIF_CE_state *hif_ce_state,
4030*5113495bSYour Name 					 int pipe_num)
4031*5113495bSYour Name {
4032*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ce_state);
4033*5113495bSYour Name 
4034*5113495bSYour Name 	if (pipe_num != scn->dl_recv_pipe_num)
4035*5113495bSYour Name 		return QDF_STATUS_E_NOSUPPORT;
4036*5113495bSYour Name 
4037*5113495bSYour Name 	hif_prealloc_put_multi_pages(scn, QDF_DP_RX_DIRECT_LINK_CE_BUF_TYPE,
4038*5113495bSYour Name 				     &scn->dl_recv_pages, false);
4039*5113495bSYour Name 
4040*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
4041*5113495bSYour Name }
4042*5113495bSYour Name #else
4043*5113495bSYour Name static inline QDF_STATUS
hif_alloc_pages_for_direct_link_recv_pipe(struct HIF_CE_state * hif_ce_state,int pipe_num)4044*5113495bSYour Name hif_alloc_pages_for_direct_link_recv_pipe(struct HIF_CE_state *hif_ce_state,
4045*5113495bSYour Name 					  int pipe_num)
4046*5113495bSYour Name {
4047*5113495bSYour Name 	return QDF_STATUS_E_NOSUPPORT;
4048*5113495bSYour Name }
4049*5113495bSYour Name 
4050*5113495bSYour Name static inline QDF_STATUS
hif_free_pages_for_direct_link_recv_pipe(struct HIF_CE_state * hif_ce_state,int pipe_num)4051*5113495bSYour Name hif_free_pages_for_direct_link_recv_pipe(struct HIF_CE_state *hif_ce_state,
4052*5113495bSYour Name 					 int pipe_num)
4053*5113495bSYour Name {
4054*5113495bSYour Name 	return QDF_STATUS_E_NOSUPPORT;
4055*5113495bSYour Name }
4056*5113495bSYour Name #endif
4057*5113495bSYour Name 
4058*5113495bSYour Name /*
4059*5113495bSYour Name  * Try to post all desired receive buffers for all pipes.
4060*5113495bSYour Name  * Returns 0 for non fastpath rx copy engine as
4061*5113495bSYour Name  * oom_allocation_work will be scheduled to recover any
4062*5113495bSYour Name  * failures, non-zero if unable to completely replenish
4063*5113495bSYour Name  * receive buffers for fastpath rx Copy engine.
4064*5113495bSYour Name  */
hif_post_recv_buffers(struct hif_softc * scn)4065*5113495bSYour Name static QDF_STATUS hif_post_recv_buffers(struct hif_softc *scn)
4066*5113495bSYour Name {
4067*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4068*5113495bSYour Name 	int pipe_num;
4069*5113495bSYour Name 	struct CE_state *ce_state = NULL;
4070*5113495bSYour Name 	QDF_STATUS qdf_status;
4071*5113495bSYour Name 
4072*5113495bSYour Name 	A_TARGET_ACCESS_LIKELY(scn);
4073*5113495bSYour Name 	for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
4074*5113495bSYour Name 		struct HIF_CE_pipe_info *pipe_info;
4075*5113495bSYour Name 
4076*5113495bSYour Name 		if (pipe_num >= CE_COUNT_MAX) {
4077*5113495bSYour Name 			A_TARGET_ACCESS_UNLIKELY(scn);
4078*5113495bSYour Name 			return QDF_STATUS_E_INVAL;
4079*5113495bSYour Name 		}
4080*5113495bSYour Name 
4081*5113495bSYour Name 		ce_state = scn->ce_id_to_state[pipe_num];
4082*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[pipe_num];
4083*5113495bSYour Name 
4084*5113495bSYour Name 		if (!ce_state)
4085*5113495bSYour Name 			continue;
4086*5113495bSYour Name 
4087*5113495bSYour Name 		/* Do not init dynamic CEs, during initial load */
4088*5113495bSYour Name 		if (ce_state->attr_flags & CE_ATTR_INIT_ON_DEMAND)
4089*5113495bSYour Name 			continue;
4090*5113495bSYour Name 
4091*5113495bSYour Name 		if (hif_is_nss_wifi_enabled(scn) &&
4092*5113495bSYour Name 		    ce_state && (ce_state->htt_rx_data))
4093*5113495bSYour Name 			continue;
4094*5113495bSYour Name 
4095*5113495bSYour Name 		qdf_status =
4096*5113495bSYour Name 			hif_alloc_pages_for_direct_link_recv_pipe(hif_state,
4097*5113495bSYour Name 								  pipe_num);
4098*5113495bSYour Name 		if (QDF_IS_STATUS_SUCCESS(qdf_status))
4099*5113495bSYour Name 			continue;
4100*5113495bSYour Name 
4101*5113495bSYour Name 		qdf_status = hif_post_recv_buffers_for_pipe(pipe_info);
4102*5113495bSYour Name 		if (!QDF_IS_STATUS_SUCCESS(qdf_status) && ce_state &&
4103*5113495bSYour Name 			ce_state->htt_rx_data &&
4104*5113495bSYour Name 			scn->fastpath_mode_on) {
4105*5113495bSYour Name 			A_TARGET_ACCESS_UNLIKELY(scn);
4106*5113495bSYour Name 			return qdf_status;
4107*5113495bSYour Name 		}
4108*5113495bSYour Name 	}
4109*5113495bSYour Name 
4110*5113495bSYour Name 	A_TARGET_ACCESS_UNLIKELY(scn);
4111*5113495bSYour Name 
4112*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
4113*5113495bSYour Name }
4114*5113495bSYour Name 
hif_start(struct hif_opaque_softc * hif_ctx)4115*5113495bSYour Name QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
4116*5113495bSYour Name {
4117*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
4118*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4119*5113495bSYour Name 	QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
4120*5113495bSYour Name 
4121*5113495bSYour Name 	hif_update_fastpath_recv_bufs_cnt(scn);
4122*5113495bSYour Name 
4123*5113495bSYour Name 	hif_msg_callbacks_install(scn);
4124*5113495bSYour Name 
4125*5113495bSYour Name 	if (hif_completion_thread_startup(hif_state))
4126*5113495bSYour Name 		return QDF_STATUS_E_FAILURE;
4127*5113495bSYour Name 
4128*5113495bSYour Name 	hif_ce_rx_wbuff_register(scn);
4129*5113495bSYour Name 
4130*5113495bSYour Name 	/* enable buffer cleanup */
4131*5113495bSYour Name 	hif_state->started = true;
4132*5113495bSYour Name 
4133*5113495bSYour Name 	/* Post buffers once to start things off. */
4134*5113495bSYour Name 	qdf_status = hif_post_recv_buffers(scn);
4135*5113495bSYour Name 	if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
4136*5113495bSYour Name 		/* cleanup is done in hif_ce_disable */
4137*5113495bSYour Name 		hif_err("Failed to post buffers");
4138*5113495bSYour Name 		return qdf_status;
4139*5113495bSYour Name 	}
4140*5113495bSYour Name 
4141*5113495bSYour Name 	return qdf_status;
4142*5113495bSYour Name }
4143*5113495bSYour Name 
hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info * pipe_info)4144*5113495bSYour Name static void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
4145*5113495bSYour Name {
4146*5113495bSYour Name 	struct hif_softc *scn;
4147*5113495bSYour Name 	struct CE_handle *ce_hdl;
4148*5113495bSYour Name 	uint32_t buf_sz;
4149*5113495bSYour Name 	struct HIF_CE_state *hif_state;
4150*5113495bSYour Name 	qdf_nbuf_t netbuf;
4151*5113495bSYour Name 	qdf_dma_addr_t CE_data;
4152*5113495bSYour Name 	void *per_CE_context;
4153*5113495bSYour Name 	QDF_STATUS status;
4154*5113495bSYour Name 
4155*5113495bSYour Name 	buf_sz = pipe_info->buf_sz;
4156*5113495bSYour Name 	/* Unused Copy Engine */
4157*5113495bSYour Name 	if (buf_sz == 0)
4158*5113495bSYour Name 		return;
4159*5113495bSYour Name 
4160*5113495bSYour Name 
4161*5113495bSYour Name 	hif_state = pipe_info->HIF_CE_state;
4162*5113495bSYour Name 	if (!hif_state->started)
4163*5113495bSYour Name 		return;
4164*5113495bSYour Name 
4165*5113495bSYour Name 	scn = HIF_GET_SOFTC(hif_state);
4166*5113495bSYour Name 	ce_hdl = pipe_info->ce_hdl;
4167*5113495bSYour Name 
4168*5113495bSYour Name 	if (!scn->qdf_dev)
4169*5113495bSYour Name 		return;
4170*5113495bSYour Name 
4171*5113495bSYour Name 	status = hif_free_pages_for_direct_link_recv_pipe(hif_state,
4172*5113495bSYour Name 							  pipe_info->pipe_num);
4173*5113495bSYour Name 	if (QDF_IS_STATUS_SUCCESS(status))
4174*5113495bSYour Name 		return;
4175*5113495bSYour Name 
4176*5113495bSYour Name 	while (ce_revoke_recv_next
4177*5113495bSYour Name 		       (ce_hdl, &per_CE_context, (void **)&netbuf,
4178*5113495bSYour Name 			&CE_data) == QDF_STATUS_SUCCESS) {
4179*5113495bSYour Name 		if (netbuf) {
4180*5113495bSYour Name 			qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
4181*5113495bSYour Name 					      QDF_DMA_FROM_DEVICE);
4182*5113495bSYour Name 			hif_ce_rx_nbuf_free(netbuf);
4183*5113495bSYour Name 		}
4184*5113495bSYour Name 	}
4185*5113495bSYour Name }
4186*5113495bSYour Name 
hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info * pipe_info)4187*5113495bSYour Name static void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
4188*5113495bSYour Name {
4189*5113495bSYour Name 	struct CE_handle *ce_hdl;
4190*5113495bSYour Name 	struct HIF_CE_state *hif_state;
4191*5113495bSYour Name 	struct hif_softc *scn;
4192*5113495bSYour Name 	qdf_nbuf_t netbuf;
4193*5113495bSYour Name 	void *per_CE_context;
4194*5113495bSYour Name 	qdf_dma_addr_t CE_data;
4195*5113495bSYour Name 	unsigned int nbytes;
4196*5113495bSYour Name 	unsigned int id;
4197*5113495bSYour Name 	uint32_t buf_sz;
4198*5113495bSYour Name 	uint32_t toeplitz_hash_result;
4199*5113495bSYour Name 
4200*5113495bSYour Name 	buf_sz = pipe_info->buf_sz;
4201*5113495bSYour Name 	if (buf_sz == 0) {
4202*5113495bSYour Name 		/* Unused Copy Engine */
4203*5113495bSYour Name 		return;
4204*5113495bSYour Name 	}
4205*5113495bSYour Name 
4206*5113495bSYour Name 	hif_state = pipe_info->HIF_CE_state;
4207*5113495bSYour Name 	if (!hif_state->started) {
4208*5113495bSYour Name 		return;
4209*5113495bSYour Name 	}
4210*5113495bSYour Name 
4211*5113495bSYour Name 	scn = HIF_GET_SOFTC(hif_state);
4212*5113495bSYour Name 
4213*5113495bSYour Name 	ce_hdl = pipe_info->ce_hdl;
4214*5113495bSYour Name 
4215*5113495bSYour Name 	while (ce_cancel_send_next
4216*5113495bSYour Name 		       (ce_hdl, &per_CE_context,
4217*5113495bSYour Name 		       (void **)&netbuf, &CE_data, &nbytes,
4218*5113495bSYour Name 		       &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
4219*5113495bSYour Name 		if (netbuf != CE_SENDLIST_ITEM_CTXT) {
4220*5113495bSYour Name 			/*
4221*5113495bSYour Name 			 * Packets enqueued by htt_h2t_ver_req_msg() and
4222*5113495bSYour Name 			 * htt_h2t_rx_ring_cfg_msg_ll() have already been
4223*5113495bSYour Name 			 * freed in htt_htc_misc_pkt_pool_free() in
4224*5113495bSYour Name 			 * wlantl_close(), so do not free them here again
4225*5113495bSYour Name 			 * by checking whether it's the endpoint
4226*5113495bSYour Name 			 * which they are queued in.
4227*5113495bSYour Name 			 */
4228*5113495bSYour Name 			if (id == scn->htc_htt_tx_endpoint)
4229*5113495bSYour Name 				return;
4230*5113495bSYour Name 			/* Indicate the completion to higher
4231*5113495bSYour Name 			 * layer to free the buffer
4232*5113495bSYour Name 			 */
4233*5113495bSYour Name 			if (pipe_info->pipe_callbacks.txCompletionHandler)
4234*5113495bSYour Name 				pipe_info->pipe_callbacks.
4235*5113495bSYour Name 				    txCompletionHandler(pipe_info->
4236*5113495bSYour Name 					    pipe_callbacks.Context,
4237*5113495bSYour Name 					    netbuf, id, toeplitz_hash_result);
4238*5113495bSYour Name 		}
4239*5113495bSYour Name 	}
4240*5113495bSYour Name }
4241*5113495bSYour Name 
4242*5113495bSYour Name /*
4243*5113495bSYour Name  * Cleanup residual buffers for device shutdown:
4244*5113495bSYour Name  *    buffers that were enqueued for receive
4245*5113495bSYour Name  *    buffers that were to be sent
4246*5113495bSYour Name  * Note: Buffers that had completed but which were
4247*5113495bSYour Name  * not yet processed are on a completion queue. They
4248*5113495bSYour Name  * are handled when the completion thread shuts down.
4249*5113495bSYour Name  */
hif_buffer_cleanup(struct HIF_CE_state * hif_state)4250*5113495bSYour Name static void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
4251*5113495bSYour Name {
4252*5113495bSYour Name 	int pipe_num;
4253*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
4254*5113495bSYour Name 	struct CE_state *ce_state;
4255*5113495bSYour Name 
4256*5113495bSYour Name 	for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
4257*5113495bSYour Name 		struct HIF_CE_pipe_info *pipe_info;
4258*5113495bSYour Name 
4259*5113495bSYour Name 		ce_state = scn->ce_id_to_state[pipe_num];
4260*5113495bSYour Name 		if (hif_is_nss_wifi_enabled(scn) && ce_state &&
4261*5113495bSYour Name 				((ce_state->htt_tx_data) ||
4262*5113495bSYour Name 				 (ce_state->htt_rx_data))) {
4263*5113495bSYour Name 			continue;
4264*5113495bSYour Name 		}
4265*5113495bSYour Name 
4266*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[pipe_num];
4267*5113495bSYour Name 		hif_recv_buffer_cleanup_on_pipe(pipe_info);
4268*5113495bSYour Name 		hif_send_buffer_cleanup_on_pipe(pipe_info);
4269*5113495bSYour Name 	}
4270*5113495bSYour Name }
4271*5113495bSYour Name 
hif_flush_surprise_remove(struct hif_opaque_softc * hif_ctx)4272*5113495bSYour Name void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
4273*5113495bSYour Name {
4274*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
4275*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4276*5113495bSYour Name 
4277*5113495bSYour Name 	hif_buffer_cleanup(hif_state);
4278*5113495bSYour Name }
4279*5113495bSYour Name 
hif_destroy_oom_work(struct hif_softc * scn)4280*5113495bSYour Name static void hif_destroy_oom_work(struct hif_softc *scn)
4281*5113495bSYour Name {
4282*5113495bSYour Name 	struct CE_state *ce_state;
4283*5113495bSYour Name 	int ce_id;
4284*5113495bSYour Name 
4285*5113495bSYour Name 	for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
4286*5113495bSYour Name 		ce_state = scn->ce_id_to_state[ce_id];
4287*5113495bSYour Name 		if (ce_state)
4288*5113495bSYour Name 			qdf_destroy_work(scn->qdf_dev,
4289*5113495bSYour Name 					 &ce_state->oom_allocation_work);
4290*5113495bSYour Name 	}
4291*5113495bSYour Name 	qdf_atomic_set(&scn->active_oom_work_cnt, 0);
4292*5113495bSYour Name }
4293*5113495bSYour Name 
hif_ce_stop(struct hif_softc * scn)4294*5113495bSYour Name void hif_ce_stop(struct hif_softc *scn)
4295*5113495bSYour Name {
4296*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4297*5113495bSYour Name 	int pipe_num;
4298*5113495bSYour Name 
4299*5113495bSYour Name 	/*
4300*5113495bSYour Name 	 * before cleaning up any memory, ensure irq &
4301*5113495bSYour Name 	 * bottom half contexts will not be re-entered
4302*5113495bSYour Name 	 */
4303*5113495bSYour Name 	hif_disable_isr(&scn->osc);
4304*5113495bSYour Name 	hif_destroy_oom_work(scn);
4305*5113495bSYour Name 	scn->hif_init_done = false;
4306*5113495bSYour Name 
4307*5113495bSYour Name 	/*
4308*5113495bSYour Name 	 * At this point, asynchronous threads are stopped,
4309*5113495bSYour Name 	 * The Target should not DMA nor interrupt, Host code may
4310*5113495bSYour Name 	 * not initiate anything more.  So we just need to clean
4311*5113495bSYour Name 	 * up Host-side state.
4312*5113495bSYour Name 	 */
4313*5113495bSYour Name 
4314*5113495bSYour Name 	if (scn->athdiag_procfs_inited) {
4315*5113495bSYour Name 		athdiag_procfs_remove();
4316*5113495bSYour Name 		scn->athdiag_procfs_inited = false;
4317*5113495bSYour Name 	}
4318*5113495bSYour Name 
4319*5113495bSYour Name 	hif_buffer_cleanup(hif_state);
4320*5113495bSYour Name 
4321*5113495bSYour Name 	for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
4322*5113495bSYour Name 		struct HIF_CE_pipe_info *pipe_info;
4323*5113495bSYour Name 		struct CE_attr attr;
4324*5113495bSYour Name 		struct CE_handle *ce_diag = hif_state->ce_diag;
4325*5113495bSYour Name 
4326*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[pipe_num];
4327*5113495bSYour Name 		if (pipe_info->ce_hdl) {
4328*5113495bSYour Name 			if (pipe_info->ce_hdl != ce_diag &&
4329*5113495bSYour Name 			    hif_state->started) {
4330*5113495bSYour Name 				attr = hif_state->host_ce_config[pipe_num];
4331*5113495bSYour Name 				if (attr.src_nentries)
4332*5113495bSYour Name 					qdf_spinlock_destroy(&pipe_info->
4333*5113495bSYour Name 							completion_freeq_lock);
4334*5113495bSYour Name 			}
4335*5113495bSYour Name 			ce_fini(pipe_info->ce_hdl);
4336*5113495bSYour Name 			pipe_info->ce_hdl = NULL;
4337*5113495bSYour Name 			pipe_info->buf_sz = 0;
4338*5113495bSYour Name 			qdf_spinlock_destroy(&pipe_info->recv_bufs_needed_lock);
4339*5113495bSYour Name 		}
4340*5113495bSYour Name 	}
4341*5113495bSYour Name 
4342*5113495bSYour Name 	hif_ce_rx_wbuff_deregister(scn);
4343*5113495bSYour Name 
4344*5113495bSYour Name 	if (hif_state->sleep_timer_init) {
4345*5113495bSYour Name 		qdf_timer_stop(&hif_state->sleep_timer);
4346*5113495bSYour Name 		qdf_timer_free(&hif_state->sleep_timer);
4347*5113495bSYour Name 		hif_state->sleep_timer_init = false;
4348*5113495bSYour Name 	}
4349*5113495bSYour Name 
4350*5113495bSYour Name 	hif_state->started = false;
4351*5113495bSYour Name }
4352*5113495bSYour Name 
4353*5113495bSYour Name #ifdef CONFIG_SHADOW_V3
hif_preare_shadow_register_cfg_v3(struct hif_softc * scn)4354*5113495bSYour Name void hif_preare_shadow_register_cfg_v3(struct hif_softc *scn)
4355*5113495bSYour Name {
4356*5113495bSYour Name 	int shadow_cfg_idx = scn->num_shadow_registers_configured;
4357*5113495bSYour Name 	int i;
4358*5113495bSYour Name 
4359*5113495bSYour Name 	/* shadow reg config for CE SRC registers */
4360*5113495bSYour Name 	for (i = 0; i < scn->ce_count; i++) {
4361*5113495bSYour Name 		scn->shadow_regs[shadow_cfg_idx].addr =
4362*5113495bSYour Name 				CE_BASE_ADDRESS(i) + SR_WR_INDEX_ADDRESS;
4363*5113495bSYour Name 		shadow_cfg_idx++;
4364*5113495bSYour Name 	}
4365*5113495bSYour Name 
4366*5113495bSYour Name 	/* shadow reg config for CE DST registers */
4367*5113495bSYour Name 	for (i = 0; i < scn->ce_count; i++) {
4368*5113495bSYour Name 		scn->shadow_regs[shadow_cfg_idx].addr =
4369*5113495bSYour Name 				CE_BASE_ADDRESS(i) + DST_WR_INDEX_ADDRESS;
4370*5113495bSYour Name 		shadow_cfg_idx++;
4371*5113495bSYour Name 	}
4372*5113495bSYour Name 
4373*5113495bSYour Name 	scn->num_shadow_registers_configured = shadow_cfg_idx;
4374*5113495bSYour Name }
4375*5113495bSYour Name 
hif_get_shadow_reg_config_v3(struct hif_softc * scn,struct pld_shadow_reg_v3_cfg ** shadow_config,int * num_shadow_registers_configured)4376*5113495bSYour Name void hif_get_shadow_reg_config_v3(struct hif_softc *scn,
4377*5113495bSYour Name 				  struct pld_shadow_reg_v3_cfg **shadow_config,
4378*5113495bSYour Name 				  int *num_shadow_registers_configured)
4379*5113495bSYour Name {
4380*5113495bSYour Name 	*shadow_config = scn->shadow_regs;
4381*5113495bSYour Name 	*num_shadow_registers_configured =
4382*5113495bSYour Name 				scn->num_shadow_registers_configured;
4383*5113495bSYour Name }
4384*5113495bSYour Name #endif
4385*5113495bSYour Name 
hif_get_shadow_reg_cfg(struct hif_softc * scn,struct shadow_reg_cfg ** target_shadow_reg_cfg_ret,uint32_t * shadow_cfg_sz_ret)4386*5113495bSYour Name static void hif_get_shadow_reg_cfg(struct hif_softc *scn,
4387*5113495bSYour Name 				   struct shadow_reg_cfg
4388*5113495bSYour Name 				   **target_shadow_reg_cfg_ret,
4389*5113495bSYour Name 				   uint32_t *shadow_cfg_sz_ret)
4390*5113495bSYour Name {
4391*5113495bSYour Name 	if (target_shadow_reg_cfg_ret)
4392*5113495bSYour Name 		*target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
4393*5113495bSYour Name 	if (shadow_cfg_sz_ret)
4394*5113495bSYour Name 		*shadow_cfg_sz_ret = shadow_cfg_sz;
4395*5113495bSYour Name }
4396*5113495bSYour Name 
4397*5113495bSYour Name /**
4398*5113495bSYour Name  * hif_get_target_ce_config() - get copy engine configuration
4399*5113495bSYour Name  * @scn: HIF context
4400*5113495bSYour Name  * @target_ce_config_ret: basic copy engine configuration
4401*5113495bSYour Name  * @target_ce_config_sz_ret: size of the basic configuration in bytes
4402*5113495bSYour Name  * @target_service_to_ce_map_ret: service mapping for the copy engines
4403*5113495bSYour Name  * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
4404*5113495bSYour Name  * @target_shadow_reg_cfg_ret: shadow register configuration
4405*5113495bSYour Name  * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
4406*5113495bSYour Name  *
4407*5113495bSYour Name  * providing accessor to these values outside of this file.
4408*5113495bSYour Name  * currently these are stored in static pointers to const sections.
4409*5113495bSYour Name  * there are multiple configurations that are selected from at compile time.
4410*5113495bSYour Name  * Runtime selection would need to consider mode, target type and bus type.
4411*5113495bSYour Name  *
4412*5113495bSYour Name  * Return: return by parameter.
4413*5113495bSYour Name  */
hif_get_target_ce_config(struct hif_softc * scn,struct CE_pipe_config ** target_ce_config_ret,uint32_t * target_ce_config_sz_ret,struct service_to_pipe ** target_service_to_ce_map_ret,uint32_t * target_service_to_ce_map_sz_ret,struct shadow_reg_cfg ** target_shadow_reg_cfg_ret,uint32_t * shadow_cfg_sz_ret)4414*5113495bSYour Name void hif_get_target_ce_config(struct hif_softc *scn,
4415*5113495bSYour Name 		struct CE_pipe_config **target_ce_config_ret,
4416*5113495bSYour Name 		uint32_t *target_ce_config_sz_ret,
4417*5113495bSYour Name 		struct service_to_pipe **target_service_to_ce_map_ret,
4418*5113495bSYour Name 		uint32_t *target_service_to_ce_map_sz_ret,
4419*5113495bSYour Name 		struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
4420*5113495bSYour Name 		uint32_t *shadow_cfg_sz_ret)
4421*5113495bSYour Name {
4422*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4423*5113495bSYour Name 
4424*5113495bSYour Name 	*target_ce_config_ret = hif_state->target_ce_config;
4425*5113495bSYour Name 	*target_ce_config_sz_ret = hif_state->target_ce_config_sz;
4426*5113495bSYour Name 
4427*5113495bSYour Name 	hif_select_service_to_pipe_map(scn, target_service_to_ce_map_ret,
4428*5113495bSYour Name 				       target_service_to_ce_map_sz_ret);
4429*5113495bSYour Name 	hif_get_shadow_reg_cfg(scn, target_shadow_reg_cfg_ret,
4430*5113495bSYour Name 			       shadow_cfg_sz_ret);
4431*5113495bSYour Name }
4432*5113495bSYour Name 
4433*5113495bSYour Name #ifdef CONFIG_SHADOW_V3
hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg * cfg)4434*5113495bSYour Name static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
4435*5113495bSYour Name {
4436*5113495bSYour Name 	int i;
4437*5113495bSYour Name 
4438*5113495bSYour Name 	hif_info("v3: num_config %d", cfg->num_shadow_reg_v3_cfg);
4439*5113495bSYour Name 	for (i = 0; i < cfg->num_shadow_reg_v3_cfg; i++)
4440*5113495bSYour Name 		hif_info("i %d, val %x", i, cfg->shadow_reg_v3_cfg[i].addr);
4441*5113495bSYour Name }
4442*5113495bSYour Name 
4443*5113495bSYour Name #elif defined(CONFIG_SHADOW_V2)
hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg * cfg)4444*5113495bSYour Name static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
4445*5113495bSYour Name {
4446*5113495bSYour Name 	int i;
4447*5113495bSYour Name 
4448*5113495bSYour Name 	hif_info("v2: num_config %d", cfg->num_shadow_reg_v2_cfg);
4449*5113495bSYour Name 	for (i = 0; i < cfg->num_shadow_reg_v2_cfg; i++)
4450*5113495bSYour Name 		hif_info("i %d, val %x", i, cfg->shadow_reg_v2_cfg[i].addr);
4451*5113495bSYour Name }
4452*5113495bSYour Name 
4453*5113495bSYour Name #else
hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg * cfg)4454*5113495bSYour Name static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
4455*5113495bSYour Name {
4456*5113495bSYour Name 	hif_info("CONFIG_SHADOW V2/V3 not defined");
4457*5113495bSYour Name }
4458*5113495bSYour Name #endif
4459*5113495bSYour Name 
4460*5113495bSYour Name #ifdef ADRASTEA_RRI_ON_DDR
4461*5113495bSYour Name /**
4462*5113495bSYour Name  * hif_get_src_ring_read_index(): Called to get the SRRI
4463*5113495bSYour Name  *
4464*5113495bSYour Name  * @scn: hif_softc pointer
4465*5113495bSYour Name  * @CE_ctrl_addr: base address of the CE whose RRI is to be read
4466*5113495bSYour Name  *
4467*5113495bSYour Name  * This function returns the SRRI to the caller. For CEs that
4468*5113495bSYour Name  * dont have interrupts enabled, we look at the DDR based SRRI
4469*5113495bSYour Name  *
4470*5113495bSYour Name  * Return: SRRI
4471*5113495bSYour Name  */
hif_get_src_ring_read_index(struct hif_softc * scn,uint32_t CE_ctrl_addr)4472*5113495bSYour Name inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
4473*5113495bSYour Name 		uint32_t CE_ctrl_addr)
4474*5113495bSYour Name {
4475*5113495bSYour Name 	struct CE_attr attr;
4476*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4477*5113495bSYour Name 
4478*5113495bSYour Name 	attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
4479*5113495bSYour Name 	if (attr.flags & CE_ATTR_DISABLE_INTR) {
4480*5113495bSYour Name 		return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
4481*5113495bSYour Name 	} else {
4482*5113495bSYour Name 		if (TARGET_REGISTER_ACCESS_ALLOWED(scn))
4483*5113495bSYour Name 			return A_TARGET_READ(scn,
4484*5113495bSYour Name 					(CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
4485*5113495bSYour Name 		else
4486*5113495bSYour Name 			return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn,
4487*5113495bSYour Name 					CE_ctrl_addr);
4488*5113495bSYour Name 	}
4489*5113495bSYour Name }
4490*5113495bSYour Name 
4491*5113495bSYour Name /**
4492*5113495bSYour Name  * hif_get_dst_ring_read_index(): Called to get the DRRI
4493*5113495bSYour Name  *
4494*5113495bSYour Name  * @scn: hif_softc pointer
4495*5113495bSYour Name  * @CE_ctrl_addr: base address of the CE whose RRI is to be read
4496*5113495bSYour Name  *
4497*5113495bSYour Name  * This function returns the DRRI to the caller. For CEs that
4498*5113495bSYour Name  * dont have interrupts enabled, we look at the DDR based DRRI
4499*5113495bSYour Name  *
4500*5113495bSYour Name  * Return: DRRI
4501*5113495bSYour Name  */
hif_get_dst_ring_read_index(struct hif_softc * scn,uint32_t CE_ctrl_addr)4502*5113495bSYour Name inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
4503*5113495bSYour Name 		uint32_t CE_ctrl_addr)
4504*5113495bSYour Name {
4505*5113495bSYour Name 	struct CE_attr attr;
4506*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4507*5113495bSYour Name 
4508*5113495bSYour Name 	attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
4509*5113495bSYour Name 
4510*5113495bSYour Name 	if (attr.flags & CE_ATTR_DISABLE_INTR) {
4511*5113495bSYour Name 		return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
4512*5113495bSYour Name 	} else {
4513*5113495bSYour Name 		if (TARGET_REGISTER_ACCESS_ALLOWED(scn))
4514*5113495bSYour Name 			return A_TARGET_READ(scn,
4515*5113495bSYour Name 					(CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
4516*5113495bSYour Name 		else
4517*5113495bSYour Name 			return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn,
4518*5113495bSYour Name 					CE_ctrl_addr);
4519*5113495bSYour Name 	}
4520*5113495bSYour Name }
4521*5113495bSYour Name 
4522*5113495bSYour Name /**
4523*5113495bSYour Name  * hif_alloc_rri_on_ddr() - Allocate memory for rri on ddr
4524*5113495bSYour Name  * @scn: hif_softc pointer
4525*5113495bSYour Name  *
4526*5113495bSYour Name  * Return: qdf status
4527*5113495bSYour Name  */
hif_alloc_rri_on_ddr(struct hif_softc * scn)4528*5113495bSYour Name static inline QDF_STATUS hif_alloc_rri_on_ddr(struct hif_softc *scn)
4529*5113495bSYour Name {
4530*5113495bSYour Name 	qdf_dma_addr_t paddr_rri_on_ddr = 0;
4531*5113495bSYour Name 
4532*5113495bSYour Name 	scn->vaddr_rri_on_ddr =
4533*5113495bSYour Name 		(void *)qdf_mem_alloc_consistent(scn->qdf_dev,
4534*5113495bSYour Name 		scn->qdf_dev->dev, RRI_ON_DDR_MEM_SIZE,
4535*5113495bSYour Name 		&paddr_rri_on_ddr);
4536*5113495bSYour Name 
4537*5113495bSYour Name 	if (!scn->vaddr_rri_on_ddr) {
4538*5113495bSYour Name 		hif_err("dmaable page alloc fail");
4539*5113495bSYour Name 		return QDF_STATUS_E_NOMEM;
4540*5113495bSYour Name 	}
4541*5113495bSYour Name 
4542*5113495bSYour Name 	scn->paddr_rri_on_ddr = paddr_rri_on_ddr;
4543*5113495bSYour Name 
4544*5113495bSYour Name 	qdf_mem_zero(scn->vaddr_rri_on_ddr, RRI_ON_DDR_MEM_SIZE);
4545*5113495bSYour Name 
4546*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
4547*5113495bSYour Name }
4548*5113495bSYour Name #endif
4549*5113495bSYour Name 
4550*5113495bSYour Name #if (!defined(QCN7605_SUPPORT)) && defined(ADRASTEA_RRI_ON_DDR)
4551*5113495bSYour Name /**
4552*5113495bSYour Name  * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
4553*5113495bSYour Name  *
4554*5113495bSYour Name  * @scn: hif_softc pointer
4555*5113495bSYour Name  *
4556*5113495bSYour Name  * This function allocates non cached memory on ddr and sends
4557*5113495bSYour Name  * the physical address of this memory to the CE hardware. The
4558*5113495bSYour Name  * hardware updates the RRI on this particular location.
4559*5113495bSYour Name  *
4560*5113495bSYour Name  * Return: None
4561*5113495bSYour Name  */
4562*5113495bSYour Name #ifdef QCA_WIFI_WCN6450
hif_config_rri_on_ddr(struct hif_softc * scn)4563*5113495bSYour Name static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
4564*5113495bSYour Name {
4565*5113495bSYour Name 	unsigned int i;
4566*5113495bSYour Name 	uint32_t high_paddr, low_paddr;
4567*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4568*5113495bSYour Name 	struct CE_attr *attr;
4569*5113495bSYour Name 
4570*5113495bSYour Name 	if (hif_alloc_rri_on_ddr(scn) != QDF_STATUS_SUCCESS)
4571*5113495bSYour Name 		return;
4572*5113495bSYour Name 
4573*5113495bSYour Name 	low_paddr  = RRI_ON_DDR_PADDR_LOW(scn->paddr_rri_on_ddr);
4574*5113495bSYour Name 	high_paddr = RRI_ON_DDR_PADDR_HIGH(scn->paddr_rri_on_ddr);
4575*5113495bSYour Name 
4576*5113495bSYour Name 	hif_debug("using srri and drri from DDR");
4577*5113495bSYour Name 
4578*5113495bSYour Name 	WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
4579*5113495bSYour Name 	WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
4580*5113495bSYour Name 
4581*5113495bSYour Name 	for (i = 0; i < CE_COUNT; i++) {
4582*5113495bSYour Name 		attr = &hif_state->host_ce_config[i];
4583*5113495bSYour Name 		if (attr->src_nentries || attr->dest_nentries)
4584*5113495bSYour Name 			CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
4585*5113495bSYour Name 	}
4586*5113495bSYour Name }
4587*5113495bSYour Name #else
hif_config_rri_on_ddr(struct hif_softc * scn)4588*5113495bSYour Name static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
4589*5113495bSYour Name {
4590*5113495bSYour Name 	unsigned int i;
4591*5113495bSYour Name 	uint32_t high_paddr, low_paddr;
4592*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4593*5113495bSYour Name 	struct CE_pipe_config *ce_config;
4594*5113495bSYour Name 
4595*5113495bSYour Name 	if (hif_alloc_rri_on_ddr(scn) != QDF_STATUS_SUCCESS)
4596*5113495bSYour Name 		return;
4597*5113495bSYour Name 
4598*5113495bSYour Name 	low_paddr  = RRI_ON_DDR_PADDR_LOW(scn->paddr_rri_on_ddr);
4599*5113495bSYour Name 	high_paddr = RRI_ON_DDR_PADDR_HIGH(scn->paddr_rri_on_ddr);
4600*5113495bSYour Name 
4601*5113495bSYour Name 	hif_debug("using srri and drri from DDR");
4602*5113495bSYour Name 
4603*5113495bSYour Name 	WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
4604*5113495bSYour Name 	WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
4605*5113495bSYour Name 
4606*5113495bSYour Name 	for (i = 0; i < CE_COUNT; i++) {
4607*5113495bSYour Name 		ce_config = &hif_state->target_ce_config[i];
4608*5113495bSYour Name 		/*
4609*5113495bSYour Name 		 * For DST channel program both IDX_UPD_EN and
4610*5113495bSYour Name 		 * DMAX length(behalf of F.W) at once to avoid
4611*5113495bSYour Name 		 * race with F.W register update.
4612*5113495bSYour Name 		 */
4613*5113495bSYour Name 		if (ce_config->pipedir == PIPEDIR_IN && ce_config->nbytes_max)
4614*5113495bSYour Name 			CE_IDX_UPD_EN_DMAX_LEN_SET(scn, CE_BASE_ADDRESS(i),
4615*5113495bSYour Name 						   ce_config->nbytes_max);
4616*5113495bSYour Name 		else
4617*5113495bSYour Name 			CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
4618*5113495bSYour Name 	}
4619*5113495bSYour Name }
4620*5113495bSYour Name #endif
4621*5113495bSYour Name 
4622*5113495bSYour Name #else
4623*5113495bSYour Name /**
4624*5113495bSYour Name  * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
4625*5113495bSYour Name  *
4626*5113495bSYour Name  * @scn: hif_softc pointer
4627*5113495bSYour Name  *
4628*5113495bSYour Name  * This is a dummy implementation for platforms that don't
4629*5113495bSYour Name  * support this functionality.
4630*5113495bSYour Name  *
4631*5113495bSYour Name  * Return: None
4632*5113495bSYour Name  */
hif_config_rri_on_ddr(struct hif_softc * scn)4633*5113495bSYour Name static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
4634*5113495bSYour Name {
4635*5113495bSYour Name }
4636*5113495bSYour Name #endif
4637*5113495bSYour Name 
4638*5113495bSYour Name /**
4639*5113495bSYour Name  * hif_update_rri_over_ddr_config() - update rri_over_ddr config for
4640*5113495bSYour Name  *                                    QMI command
4641*5113495bSYour Name  * @scn: hif context
4642*5113495bSYour Name  * @cfg: wlan enable config
4643*5113495bSYour Name  *
4644*5113495bSYour Name  * In case of Genoa, rri_over_ddr memory configuration is passed
4645*5113495bSYour Name  * to firmware through QMI configure command.
4646*5113495bSYour Name  */
4647*5113495bSYour Name #if defined(QCN7605_SUPPORT) && defined(ADRASTEA_RRI_ON_DDR)
hif_update_rri_over_ddr_config(struct hif_softc * scn,struct pld_wlan_enable_cfg * cfg)4648*5113495bSYour Name static void hif_update_rri_over_ddr_config(struct hif_softc *scn,
4649*5113495bSYour Name 					   struct pld_wlan_enable_cfg *cfg)
4650*5113495bSYour Name {
4651*5113495bSYour Name 	if (hif_alloc_rri_on_ddr(scn) != QDF_STATUS_SUCCESS)
4652*5113495bSYour Name 		return;
4653*5113495bSYour Name 
4654*5113495bSYour Name 	cfg->rri_over_ddr_cfg_valid = true;
4655*5113495bSYour Name 	cfg->rri_over_ddr_cfg.base_addr_low =
4656*5113495bSYour Name 		 BITS0_TO_31(scn->paddr_rri_on_ddr);
4657*5113495bSYour Name 	cfg->rri_over_ddr_cfg.base_addr_high =
4658*5113495bSYour Name 		 BITS32_TO_35(scn->paddr_rri_on_ddr);
4659*5113495bSYour Name }
4660*5113495bSYour Name #else
hif_update_rri_over_ddr_config(struct hif_softc * scn,struct pld_wlan_enable_cfg * cfg)4661*5113495bSYour Name static void hif_update_rri_over_ddr_config(struct hif_softc *scn,
4662*5113495bSYour Name 					   struct pld_wlan_enable_cfg *cfg)
4663*5113495bSYour Name {
4664*5113495bSYour Name }
4665*5113495bSYour Name #endif
4666*5113495bSYour Name 
4667*5113495bSYour Name /**
4668*5113495bSYour Name  * hif_wlan_enable(): call the platform driver to enable wlan
4669*5113495bSYour Name  * @scn: HIF Context
4670*5113495bSYour Name  *
4671*5113495bSYour Name  * This function passes the con_mode and CE configuration to
4672*5113495bSYour Name  * platform driver to enable wlan.
4673*5113495bSYour Name  *
4674*5113495bSYour Name  * Return: linux error code
4675*5113495bSYour Name  */
hif_wlan_enable(struct hif_softc * scn)4676*5113495bSYour Name int hif_wlan_enable(struct hif_softc *scn)
4677*5113495bSYour Name {
4678*5113495bSYour Name 	struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
4679*5113495bSYour Name 	struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
4680*5113495bSYour Name 	struct pld_wlan_enable_cfg cfg = { 0 };
4681*5113495bSYour Name 	enum pld_driver_mode mode;
4682*5113495bSYour Name 	uint32_t con_mode = hif_get_conparam(scn);
4683*5113495bSYour Name 
4684*5113495bSYour Name 	hif_get_target_ce_config(scn,
4685*5113495bSYour Name 			(struct CE_pipe_config **)&cfg.ce_tgt_cfg,
4686*5113495bSYour Name 			&cfg.num_ce_tgt_cfg,
4687*5113495bSYour Name 			(struct service_to_pipe **)&cfg.ce_svc_cfg,
4688*5113495bSYour Name 			&cfg.num_ce_svc_pipe_cfg,
4689*5113495bSYour Name 			(struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
4690*5113495bSYour Name 			&cfg.num_shadow_reg_cfg);
4691*5113495bSYour Name 
4692*5113495bSYour Name 	/* translate from structure size to array size */
4693*5113495bSYour Name 	cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
4694*5113495bSYour Name 	cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
4695*5113495bSYour Name 	cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
4696*5113495bSYour Name 
4697*5113495bSYour Name 	switch (tgt_info->target_type) {
4698*5113495bSYour Name 	case TARGET_TYPE_KIWI:
4699*5113495bSYour Name 	case TARGET_TYPE_MANGO:
4700*5113495bSYour Name 	case TARGET_TYPE_PEACH:
4701*5113495bSYour Name 	case TARGET_TYPE_WCN6450:
4702*5113495bSYour Name 		hif_prepare_hal_shadow_reg_cfg_v3(scn, &cfg);
4703*5113495bSYour Name 		break;
4704*5113495bSYour Name 	default:
4705*5113495bSYour Name 		hif_prepare_hal_shadow_register_cfg(scn,
4706*5113495bSYour Name 						    &cfg.shadow_reg_v2_cfg,
4707*5113495bSYour Name 						    &cfg.num_shadow_reg_v2_cfg);
4708*5113495bSYour Name 		break;
4709*5113495bSYour Name 	}
4710*5113495bSYour Name 
4711*5113495bSYour Name 	hif_print_hal_shadow_register_cfg(&cfg);
4712*5113495bSYour Name 
4713*5113495bSYour Name 	hif_update_rri_over_ddr_config(scn, &cfg);
4714*5113495bSYour Name 
4715*5113495bSYour Name 	if (QDF_GLOBAL_FTM_MODE == con_mode)
4716*5113495bSYour Name 		mode = PLD_FTM;
4717*5113495bSYour Name 	else if (QDF_GLOBAL_COLDBOOT_CALIB_MODE == con_mode)
4718*5113495bSYour Name 		mode = PLD_COLDBOOT_CALIBRATION;
4719*5113495bSYour Name 	else if (QDF_GLOBAL_FTM_COLDBOOT_CALIB_MODE == con_mode)
4720*5113495bSYour Name 		mode = PLD_FTM_COLDBOOT_CALIBRATION;
4721*5113495bSYour Name 	else if (QDF_IS_EPPING_ENABLED(con_mode))
4722*5113495bSYour Name 		mode = PLD_EPPING;
4723*5113495bSYour Name 	else
4724*5113495bSYour Name 		mode = PLD_MISSION;
4725*5113495bSYour Name 
4726*5113495bSYour Name 	if (BYPASS_QMI)
4727*5113495bSYour Name 		return 0;
4728*5113495bSYour Name 	else
4729*5113495bSYour Name 		return pld_wlan_enable(scn->qdf_dev->dev, &cfg, mode);
4730*5113495bSYour Name }
4731*5113495bSYour Name 
4732*5113495bSYour Name #ifdef WLAN_FEATURE_EPPING
4733*5113495bSYour Name 
4734*5113495bSYour Name #define CE_EPPING_USES_IRQ true
4735*5113495bSYour Name 
hif_ce_prepare_epping_config(struct hif_softc * scn,struct HIF_CE_state * hif_state)4736*5113495bSYour Name void hif_ce_prepare_epping_config(struct hif_softc *scn,
4737*5113495bSYour Name 				  struct HIF_CE_state *hif_state)
4738*5113495bSYour Name {
4739*5113495bSYour Name 	if (CE_EPPING_USES_IRQ)
4740*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_epping_irq;
4741*5113495bSYour Name 	else
4742*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_epping_poll;
4743*5113495bSYour Name 	hif_state->target_ce_config = target_ce_config_wlan_epping;
4744*5113495bSYour Name 	hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
4745*5113495bSYour Name 	target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
4746*5113495bSYour Name 	shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
4747*5113495bSYour Name 	scn->ce_count = EPPING_HOST_CE_COUNT;
4748*5113495bSYour Name }
4749*5113495bSYour Name #endif
4750*5113495bSYour Name 
4751*5113495bSYour Name #ifdef QCN7605_SUPPORT
4752*5113495bSYour Name static inline
hif_set_ce_config_qcn7605(struct hif_softc * scn,struct HIF_CE_state * hif_state)4753*5113495bSYour Name void hif_set_ce_config_qcn7605(struct hif_softc *scn,
4754*5113495bSYour Name 			       struct HIF_CE_state *hif_state)
4755*5113495bSYour Name {
4756*5113495bSYour Name 	hif_state->host_ce_config = host_ce_config_wlan_qcn7605;
4757*5113495bSYour Name 	hif_state->target_ce_config = target_ce_config_wlan_qcn7605;
4758*5113495bSYour Name 	hif_state->target_ce_config_sz =
4759*5113495bSYour Name 				 sizeof(target_ce_config_wlan_qcn7605);
4760*5113495bSYour Name 	target_shadow_reg_cfg = target_shadow_reg_cfg_map_qcn7605;
4761*5113495bSYour Name 	shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map_qcn7605);
4762*5113495bSYour Name 	scn->ce_count = QCN7605_CE_COUNT;
4763*5113495bSYour Name }
4764*5113495bSYour Name #else
4765*5113495bSYour Name static inline
hif_set_ce_config_qcn7605(struct hif_softc * scn,struct HIF_CE_state * hif_state)4766*5113495bSYour Name void hif_set_ce_config_qcn7605(struct hif_softc *scn,
4767*5113495bSYour Name 			       struct HIF_CE_state *hif_state)
4768*5113495bSYour Name {
4769*5113495bSYour Name 	hif_err("QCN7605 not supported");
4770*5113495bSYour Name }
4771*5113495bSYour Name #endif
4772*5113495bSYour Name 
4773*5113495bSYour Name #ifdef CE_SVC_CMN_INIT
4774*5113495bSYour Name #ifdef QCA_WIFI_SUPPORT_SRNG
hif_ce_service_init(void)4775*5113495bSYour Name static inline void hif_ce_service_init(void)
4776*5113495bSYour Name {
4777*5113495bSYour Name 	ce_service_srng_init();
4778*5113495bSYour Name }
4779*5113495bSYour Name #else
hif_ce_service_init(void)4780*5113495bSYour Name static inline void hif_ce_service_init(void)
4781*5113495bSYour Name {
4782*5113495bSYour Name 	ce_service_legacy_init();
4783*5113495bSYour Name }
4784*5113495bSYour Name #endif
4785*5113495bSYour Name #else
hif_ce_service_init(void)4786*5113495bSYour Name static inline void hif_ce_service_init(void)
4787*5113495bSYour Name {
4788*5113495bSYour Name }
4789*5113495bSYour Name #endif
4790*5113495bSYour Name 
4791*5113495bSYour Name #ifdef FEATURE_DIRECT_LINK
4792*5113495bSYour Name /**
4793*5113495bSYour Name  * hif_ce_select_config_kiwi() - Select the host and target CE
4794*5113495bSYour Name  *  configuration for Kiwi
4795*5113495bSYour Name  * @hif_state: HIF CE context
4796*5113495bSYour Name  *
4797*5113495bSYour Name  * Return: None
4798*5113495bSYour Name  */
4799*5113495bSYour Name static inline
hif_ce_select_config_kiwi(struct HIF_CE_state * hif_state)4800*5113495bSYour Name void hif_ce_select_config_kiwi(struct HIF_CE_state *hif_state)
4801*5113495bSYour Name {
4802*5113495bSYour Name 	struct hif_softc *hif_ctx = HIF_GET_SOFTC(hif_state);
4803*5113495bSYour Name 
4804*5113495bSYour Name 	if (pld_is_direct_link_supported(hif_ctx->qdf_dev->dev)) {
4805*5113495bSYour Name 		hif_state->host_ce_config =
4806*5113495bSYour Name 				host_ce_config_wlan_kiwi_direct_link;
4807*5113495bSYour Name 		hif_state->target_ce_config =
4808*5113495bSYour Name 				target_ce_config_wlan_kiwi_direct_link;
4809*5113495bSYour Name 		hif_state->target_ce_config_sz =
4810*5113495bSYour Name 				sizeof(target_ce_config_wlan_kiwi_direct_link);
4811*5113495bSYour Name 	} else {
4812*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_kiwi;
4813*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_kiwi;
4814*5113495bSYour Name 		hif_state->target_ce_config_sz =
4815*5113495bSYour Name 				sizeof(target_ce_config_wlan_kiwi);
4816*5113495bSYour Name 	}
4817*5113495bSYour Name }
4818*5113495bSYour Name #else
4819*5113495bSYour Name static inline
hif_ce_select_config_kiwi(struct HIF_CE_state * hif_state)4820*5113495bSYour Name void hif_ce_select_config_kiwi(struct HIF_CE_state *hif_state)
4821*5113495bSYour Name {
4822*5113495bSYour Name 	hif_state->host_ce_config = host_ce_config_wlan_kiwi;
4823*5113495bSYour Name 	hif_state->target_ce_config = target_ce_config_wlan_kiwi;
4824*5113495bSYour Name 	hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_kiwi);
4825*5113495bSYour Name }
4826*5113495bSYour Name #endif
4827*5113495bSYour Name 
4828*5113495bSYour Name /**
4829*5113495bSYour Name  * hif_ce_prepare_config() - load the correct static tables.
4830*5113495bSYour Name  * @scn: hif context
4831*5113495bSYour Name  *
4832*5113495bSYour Name  * Epping uses different static attribute tables than mission mode.
4833*5113495bSYour Name  */
hif_ce_prepare_config(struct hif_softc * scn)4834*5113495bSYour Name void hif_ce_prepare_config(struct hif_softc *scn)
4835*5113495bSYour Name {
4836*5113495bSYour Name 	uint32_t mode = hif_get_conparam(scn);
4837*5113495bSYour Name 	struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
4838*5113495bSYour Name 	struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
4839*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
4840*5113495bSYour Name 	int ret;
4841*5113495bSYour Name 	int msi_data_count = 0;
4842*5113495bSYour Name 	int msi_data_start = 0;
4843*5113495bSYour Name 	int msi_irq_start = 0;
4844*5113495bSYour Name 
4845*5113495bSYour Name 	hif_ce_service_init();
4846*5113495bSYour Name 	hif_state->ce_services = ce_services_attach(scn);
4847*5113495bSYour Name 
4848*5113495bSYour Name 	ret = pld_get_user_msi_assignment(scn->qdf_dev->dev, "CE",
4849*5113495bSYour Name 					  &msi_data_count, &msi_data_start,
4850*5113495bSYour Name 					  &msi_irq_start);
4851*5113495bSYour Name 
4852*5113495bSYour Name 	scn->ce_count = HOST_CE_COUNT;
4853*5113495bSYour Name 	scn->int_assignment = &ce_int_context[msi_data_count];
4854*5113495bSYour Name 	scn->free_irq_done = false;
4855*5113495bSYour Name 	/* if epping is enabled we need to use the epping configuration. */
4856*5113495bSYour Name 	if (QDF_IS_EPPING_ENABLED(mode)) {
4857*5113495bSYour Name 		hif_ce_prepare_epping_config(scn, hif_state);
4858*5113495bSYour Name 		return;
4859*5113495bSYour Name 	}
4860*5113495bSYour Name 
4861*5113495bSYour Name 	switch (tgt_info->target_type) {
4862*5113495bSYour Name 	default:
4863*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan;
4864*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan;
4865*5113495bSYour Name 		hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan);
4866*5113495bSYour Name 		break;
4867*5113495bSYour Name 	case TARGET_TYPE_QCN7605:
4868*5113495bSYour Name 		hif_set_ce_config_qcn7605(scn, hif_state);
4869*5113495bSYour Name 		break;
4870*5113495bSYour Name 	case TARGET_TYPE_AR900B:
4871*5113495bSYour Name 	case TARGET_TYPE_QCA9984:
4872*5113495bSYour Name 	case TARGET_TYPE_QCA9888:
4873*5113495bSYour Name 		if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
4874*5113495bSYour Name 			hif_state->host_ce_config =
4875*5113495bSYour Name 				host_lowdesc_ce_cfg_wlan_ar900b_nopktlog;
4876*5113495bSYour Name 		} else if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
4877*5113495bSYour Name 			hif_state->host_ce_config =
4878*5113495bSYour Name 				host_lowdesc_ce_cfg_wlan_ar900b;
4879*5113495bSYour Name 		} else {
4880*5113495bSYour Name 			hif_state->host_ce_config = host_ce_config_wlan_ar900b;
4881*5113495bSYour Name 		}
4882*5113495bSYour Name 
4883*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_ar900b;
4884*5113495bSYour Name 		hif_state->target_ce_config_sz =
4885*5113495bSYour Name 				sizeof(target_ce_config_wlan_ar900b);
4886*5113495bSYour Name 
4887*5113495bSYour Name 		break;
4888*5113495bSYour Name 
4889*5113495bSYour Name 	case TARGET_TYPE_AR9888:
4890*5113495bSYour Name 	case TARGET_TYPE_AR9888V2:
4891*5113495bSYour Name 		if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
4892*5113495bSYour Name 			hif_state->host_ce_config = host_lowdesc_ce_cfg_wlan_ar9888;
4893*5113495bSYour Name 		} else {
4894*5113495bSYour Name 			hif_state->host_ce_config = host_ce_config_wlan_ar9888;
4895*5113495bSYour Name 		}
4896*5113495bSYour Name 
4897*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_ar9888;
4898*5113495bSYour Name 		hif_state->target_ce_config_sz =
4899*5113495bSYour Name 					sizeof(target_ce_config_wlan_ar9888);
4900*5113495bSYour Name 
4901*5113495bSYour Name 		break;
4902*5113495bSYour Name 
4903*5113495bSYour Name 	case TARGET_TYPE_QCA8074:
4904*5113495bSYour Name 	case TARGET_TYPE_QCA8074V2:
4905*5113495bSYour Name 	case TARGET_TYPE_QCA6018:
4906*5113495bSYour Name 		if (scn->bus_type == QDF_BUS_TYPE_PCI) {
4907*5113495bSYour Name 			hif_state->host_ce_config =
4908*5113495bSYour Name 					host_ce_config_wlan_qca8074_pci;
4909*5113495bSYour Name 			hif_state->target_ce_config =
4910*5113495bSYour Name 				target_ce_config_wlan_qca8074_pci;
4911*5113495bSYour Name 			hif_state->target_ce_config_sz =
4912*5113495bSYour Name 				sizeof(target_ce_config_wlan_qca8074_pci);
4913*5113495bSYour Name 		} else {
4914*5113495bSYour Name 			hif_state->host_ce_config = host_ce_config_wlan_qca8074;
4915*5113495bSYour Name 			hif_state->target_ce_config =
4916*5113495bSYour Name 					target_ce_config_wlan_qca8074;
4917*5113495bSYour Name 			hif_state->target_ce_config_sz =
4918*5113495bSYour Name 				sizeof(target_ce_config_wlan_qca8074);
4919*5113495bSYour Name 		}
4920*5113495bSYour Name 		break;
4921*5113495bSYour Name 	case TARGET_TYPE_QCA6290:
4922*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qca6290;
4923*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qca6290;
4924*5113495bSYour Name 		hif_state->target_ce_config_sz =
4925*5113495bSYour Name 					sizeof(target_ce_config_wlan_qca6290);
4926*5113495bSYour Name 
4927*5113495bSYour Name 		scn->ce_count = QCA_6290_CE_COUNT;
4928*5113495bSYour Name 		break;
4929*5113495bSYour Name 	case TARGET_TYPE_QCN9000:
4930*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qcn9000;
4931*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qcn9000;
4932*5113495bSYour Name 		hif_state->target_ce_config_sz =
4933*5113495bSYour Name 					sizeof(target_ce_config_wlan_qcn9000);
4934*5113495bSYour Name 		scn->ce_count = QCN_9000_CE_COUNT;
4935*5113495bSYour Name 		scn->ini_cfg.disable_wake_irq = 1;
4936*5113495bSYour Name 		break;
4937*5113495bSYour Name 	case TARGET_TYPE_QCN9224:
4938*5113495bSYour Name 		hif_set_ce_config_qcn9224(scn, hif_state);
4939*5113495bSYour Name 		break;
4940*5113495bSYour Name 	case TARGET_TYPE_QCA5332:
4941*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qca5332;
4942*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qca5332;
4943*5113495bSYour Name 		hif_state->target_ce_config_sz =
4944*5113495bSYour Name 					 sizeof(target_ce_config_wlan_qca5332);
4945*5113495bSYour Name 		scn->ce_count = QCA_5332_CE_COUNT;
4946*5113495bSYour Name 		break;
4947*5113495bSYour Name 	case TARGET_TYPE_QCN6122:
4948*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qcn6122;
4949*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qcn6122;
4950*5113495bSYour Name 		hif_state->target_ce_config_sz =
4951*5113495bSYour Name 					sizeof(target_ce_config_wlan_qcn6122);
4952*5113495bSYour Name 		scn->ce_count = QCN_6122_CE_COUNT;
4953*5113495bSYour Name 		scn->ini_cfg.disable_wake_irq = 1;
4954*5113495bSYour Name 		break;
4955*5113495bSYour Name 	case TARGET_TYPE_QCN9160:
4956*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qcn9160;
4957*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qcn9160;
4958*5113495bSYour Name 		hif_state->target_ce_config_sz =
4959*5113495bSYour Name 					sizeof(target_ce_config_wlan_qcn9160);
4960*5113495bSYour Name 		scn->ce_count = QCN_9160_CE_COUNT;
4961*5113495bSYour Name 		scn->ini_cfg.disable_wake_irq = 1;
4962*5113495bSYour Name 		break;
4963*5113495bSYour Name 	case TARGET_TYPE_QCN6432:
4964*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qcn6432;
4965*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qcn6432;
4966*5113495bSYour Name 		hif_state->target_ce_config_sz =
4967*5113495bSYour Name 					sizeof(target_ce_config_wlan_qcn6432);
4968*5113495bSYour Name 		scn->ce_count = QCN_6432_CE_COUNT;
4969*5113495bSYour Name 		scn->ini_cfg.disable_wake_irq = 1;
4970*5113495bSYour Name 		break;
4971*5113495bSYour Name 	case TARGET_TYPE_QCA5018:
4972*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qca5018;
4973*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qca5018;
4974*5113495bSYour Name 		hif_state->target_ce_config_sz =
4975*5113495bSYour Name 					sizeof(target_ce_config_wlan_qca5018);
4976*5113495bSYour Name 		scn->ce_count = QCA_5018_CE_COUNT;
4977*5113495bSYour Name 		break;
4978*5113495bSYour Name 	case TARGET_TYPE_QCA9574:
4979*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qca9574;
4980*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qca9574;
4981*5113495bSYour Name 		hif_state->target_ce_config_sz =
4982*5113495bSYour Name 					sizeof(target_ce_config_wlan_qca9574);
4983*5113495bSYour Name 		break;
4984*5113495bSYour Name 	case TARGET_TYPE_QCA6390:
4985*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qca6390;
4986*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qca6390;
4987*5113495bSYour Name 		hif_state->target_ce_config_sz =
4988*5113495bSYour Name 					sizeof(target_ce_config_wlan_qca6390);
4989*5113495bSYour Name 
4990*5113495bSYour Name 		scn->ce_count = QCA_6390_CE_COUNT;
4991*5113495bSYour Name 		break;
4992*5113495bSYour Name 	case TARGET_TYPE_QCA6490:
4993*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qca6490;
4994*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qca6490;
4995*5113495bSYour Name 		hif_state->target_ce_config_sz =
4996*5113495bSYour Name 					sizeof(target_ce_config_wlan_qca6490);
4997*5113495bSYour Name 
4998*5113495bSYour Name 		scn->ce_count = QCA_6490_CE_COUNT;
4999*5113495bSYour Name 		break;
5000*5113495bSYour Name 	case TARGET_TYPE_QCA6750:
5001*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_qca6750;
5002*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_qca6750;
5003*5113495bSYour Name 		hif_state->target_ce_config_sz =
5004*5113495bSYour Name 					sizeof(target_ce_config_wlan_qca6750);
5005*5113495bSYour Name 
5006*5113495bSYour Name 		scn->ce_count = QCA_6750_CE_COUNT;
5007*5113495bSYour Name 		break;
5008*5113495bSYour Name 	case TARGET_TYPE_KIWI:
5009*5113495bSYour Name 	case TARGET_TYPE_MANGO:
5010*5113495bSYour Name 	case TARGET_TYPE_PEACH:
5011*5113495bSYour Name 		hif_ce_select_config_kiwi(hif_state);
5012*5113495bSYour Name 		scn->ce_count = KIWI_CE_COUNT;
5013*5113495bSYour Name 		break;
5014*5113495bSYour Name 	case TARGET_TYPE_ADRASTEA:
5015*5113495bSYour Name 		if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
5016*5113495bSYour Name 			hif_state->host_ce_config =
5017*5113495bSYour Name 				host_lowdesc_ce_config_wlan_adrastea_nopktlog;
5018*5113495bSYour Name 			hif_state->target_ce_config =
5019*5113495bSYour Name 			       target_lowdesc_ce_config_wlan_adrastea_nopktlog;
5020*5113495bSYour Name 			hif_state->target_ce_config_sz =
5021*5113495bSYour Name 			sizeof(target_lowdesc_ce_config_wlan_adrastea_nopktlog);
5022*5113495bSYour Name 		} else {
5023*5113495bSYour Name 			hif_state->host_ce_config =
5024*5113495bSYour Name 				host_ce_config_wlan_adrastea;
5025*5113495bSYour Name 			hif_state->target_ce_config =
5026*5113495bSYour Name 					target_ce_config_wlan_adrastea;
5027*5113495bSYour Name 			hif_state->target_ce_config_sz =
5028*5113495bSYour Name 					sizeof(target_ce_config_wlan_adrastea);
5029*5113495bSYour Name 		}
5030*5113495bSYour Name 		break;
5031*5113495bSYour Name 	case TARGET_TYPE_WCN6450:
5032*5113495bSYour Name 		hif_state->host_ce_config = host_ce_config_wlan_wcn6450;
5033*5113495bSYour Name 		hif_state->target_ce_config = target_ce_config_wlan_wcn6450;
5034*5113495bSYour Name 		hif_state->target_ce_config_sz =
5035*5113495bSYour Name 				sizeof(target_ce_config_wlan_wcn6450);
5036*5113495bSYour Name 		break;
5037*5113495bSYour Name 	}
5038*5113495bSYour Name 	QDF_BUG(scn->ce_count <= CE_COUNT_MAX);
5039*5113495bSYour Name }
5040*5113495bSYour Name 
5041*5113495bSYour Name /**
5042*5113495bSYour Name  * hif_ce_open() - do ce specific allocations
5043*5113495bSYour Name  * @hif_sc: pointer to hif context
5044*5113495bSYour Name  *
5045*5113495bSYour Name  * return: 0 for success or QDF_STATUS_E_NOMEM
5046*5113495bSYour Name  */
hif_ce_open(struct hif_softc * hif_sc)5047*5113495bSYour Name QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
5048*5113495bSYour Name {
5049*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
5050*5113495bSYour Name 
5051*5113495bSYour Name 	qdf_spinlock_create(&hif_state->irq_reg_lock);
5052*5113495bSYour Name 	qdf_spinlock_create(&hif_state->keep_awake_lock);
5053*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
5054*5113495bSYour Name }
5055*5113495bSYour Name 
5056*5113495bSYour Name /**
5057*5113495bSYour Name  * hif_ce_close() - do ce specific free
5058*5113495bSYour Name  * @hif_sc: pointer to hif context
5059*5113495bSYour Name  */
hif_ce_close(struct hif_softc * hif_sc)5060*5113495bSYour Name void hif_ce_close(struct hif_softc *hif_sc)
5061*5113495bSYour Name {
5062*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
5063*5113495bSYour Name 
5064*5113495bSYour Name 	qdf_spinlock_destroy(&hif_state->irq_reg_lock);
5065*5113495bSYour Name 	qdf_spinlock_destroy(&hif_state->keep_awake_lock);
5066*5113495bSYour Name }
5067*5113495bSYour Name 
5068*5113495bSYour Name /**
5069*5113495bSYour Name  * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
5070*5113495bSYour Name  * @hif_sc: hif context
5071*5113495bSYour Name  *
5072*5113495bSYour Name  * uses state variables to support cleaning up when hif_config_ce fails.
5073*5113495bSYour Name  */
hif_unconfig_ce(struct hif_softc * hif_sc)5074*5113495bSYour Name void hif_unconfig_ce(struct hif_softc *hif_sc)
5075*5113495bSYour Name {
5076*5113495bSYour Name 	int pipe_num;
5077*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
5078*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
5079*5113495bSYour Name 	struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(hif_sc);
5080*5113495bSYour Name 
5081*5113495bSYour Name 	for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
5082*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[pipe_num];
5083*5113495bSYour Name 		if (pipe_info->ce_hdl) {
5084*5113495bSYour Name 			ce_unregister_irq(hif_state, (1 << pipe_num));
5085*5113495bSYour Name 		}
5086*5113495bSYour Name 	}
5087*5113495bSYour Name 	deinit_tasklet_workers(hif_hdl);
5088*5113495bSYour Name 	for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
5089*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[pipe_num];
5090*5113495bSYour Name 		if (pipe_info->ce_hdl) {
5091*5113495bSYour Name 			ce_fini(pipe_info->ce_hdl);
5092*5113495bSYour Name 			pipe_info->ce_hdl = NULL;
5093*5113495bSYour Name 			pipe_info->buf_sz = 0;
5094*5113495bSYour Name 			qdf_spinlock_destroy(&pipe_info->recv_bufs_needed_lock);
5095*5113495bSYour Name 		}
5096*5113495bSYour Name 	}
5097*5113495bSYour Name 	if (hif_sc->athdiag_procfs_inited) {
5098*5113495bSYour Name 		athdiag_procfs_remove();
5099*5113495bSYour Name 		hif_sc->athdiag_procfs_inited = false;
5100*5113495bSYour Name 	}
5101*5113495bSYour Name }
5102*5113495bSYour Name 
5103*5113495bSYour Name #ifdef CONFIG_BYPASS_QMI
5104*5113495bSYour Name #ifdef QCN7605_SUPPORT
5105*5113495bSYour Name /**
5106*5113495bSYour Name  * hif_post_static_buf_to_target() - post static buffer to WLAN FW
5107*5113495bSYour Name  * @scn: pointer to HIF structure
5108*5113495bSYour Name  *
5109*5113495bSYour Name  * WLAN FW needs 2MB memory from DDR when QMI is disabled.
5110*5113495bSYour Name  *
5111*5113495bSYour Name  * Return: void
5112*5113495bSYour Name  */
hif_post_static_buf_to_target(struct hif_softc * scn)5113*5113495bSYour Name static void hif_post_static_buf_to_target(struct hif_softc *scn)
5114*5113495bSYour Name {
5115*5113495bSYour Name 	phys_addr_t target_pa;
5116*5113495bSYour Name 	struct ce_info *ce_info_ptr;
5117*5113495bSYour Name 	uint32_t msi_data_start;
5118*5113495bSYour Name 	uint32_t msi_data_count;
5119*5113495bSYour Name 	uint32_t msi_irq_start;
5120*5113495bSYour Name 	uint32_t i = 0;
5121*5113495bSYour Name 	int ret;
5122*5113495bSYour Name 
5123*5113495bSYour Name 	scn->vaddr_qmi_bypass =
5124*5113495bSYour Name 			(uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
5125*5113495bSYour Name 							     scn->qdf_dev->dev,
5126*5113495bSYour Name 							     FW_SHARED_MEM,
5127*5113495bSYour Name 							     &target_pa);
5128*5113495bSYour Name 	if (!scn->vaddr_qmi_bypass) {
5129*5113495bSYour Name 		hif_err("Memory allocation failed could not post target buf");
5130*5113495bSYour Name 		return;
5131*5113495bSYour Name 	}
5132*5113495bSYour Name 
5133*5113495bSYour Name 	scn->paddr_qmi_bypass = target_pa;
5134*5113495bSYour Name 
5135*5113495bSYour Name 	ce_info_ptr = (struct ce_info *)scn->vaddr_qmi_bypass;
5136*5113495bSYour Name 
5137*5113495bSYour Name 	if (scn->vaddr_rri_on_ddr) {
5138*5113495bSYour Name 		ce_info_ptr->rri_over_ddr_low_paddr  =
5139*5113495bSYour Name 			 BITS0_TO_31(scn->paddr_rri_on_ddr);
5140*5113495bSYour Name 		ce_info_ptr->rri_over_ddr_high_paddr =
5141*5113495bSYour Name 			 BITS32_TO_35(scn->paddr_rri_on_ddr);
5142*5113495bSYour Name 	}
5143*5113495bSYour Name 
5144*5113495bSYour Name 	ret = pld_get_user_msi_assignment(scn->qdf_dev->dev, "CE",
5145*5113495bSYour Name 					  &msi_data_count, &msi_data_start,
5146*5113495bSYour Name 					  &msi_irq_start);
5147*5113495bSYour Name 	if (ret) {
5148*5113495bSYour Name 		hif_err("Failed to get CE msi config");
5149*5113495bSYour Name 		return;
5150*5113495bSYour Name 	}
5151*5113495bSYour Name 
5152*5113495bSYour Name 	for (i = 0; i < CE_COUNT_MAX; i++) {
5153*5113495bSYour Name 		ce_info_ptr->cfg[i].ce_id = i;
5154*5113495bSYour Name 		ce_info_ptr->cfg[i].msi_vector =
5155*5113495bSYour Name 			 (i % msi_data_count) + msi_irq_start;
5156*5113495bSYour Name 	}
5157*5113495bSYour Name 
5158*5113495bSYour Name 	hif_write32_mb(scn, scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
5159*5113495bSYour Name 	hif_info("target va %pK target pa %pa", scn->vaddr_qmi_bypass,
5160*5113495bSYour Name 		 &target_pa);
5161*5113495bSYour Name }
5162*5113495bSYour Name 
5163*5113495bSYour Name /**
5164*5113495bSYour Name  * hif_cleanup_static_buf_to_target() -  clean up static buffer to WLAN FW
5165*5113495bSYour Name  * @scn: pointer to HIF structure
5166*5113495bSYour Name  *
5167*5113495bSYour Name  *
5168*5113495bSYour Name  * Return: void
5169*5113495bSYour Name  */
hif_cleanup_static_buf_to_target(struct hif_softc * scn)5170*5113495bSYour Name void hif_cleanup_static_buf_to_target(struct hif_softc *scn)
5171*5113495bSYour Name {
5172*5113495bSYour Name 	void *target_va = scn->vaddr_qmi_bypass;
5173*5113495bSYour Name 	phys_addr_t target_pa = scn->paddr_qmi_bypass;
5174*5113495bSYour Name 
5175*5113495bSYour Name 	qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev,
5176*5113495bSYour Name 				FW_SHARED_MEM, target_va,
5177*5113495bSYour Name 				target_pa, 0);
5178*5113495bSYour Name 	hif_write32_mb(scn, scn->mem + BYPASS_QMI_TEMP_REGISTER, 0);
5179*5113495bSYour Name }
5180*5113495bSYour Name #else
5181*5113495bSYour Name /**
5182*5113495bSYour Name  * hif_post_static_buf_to_target() - post static buffer to WLAN FW
5183*5113495bSYour Name  * @scn: pointer to HIF structure
5184*5113495bSYour Name  *
5185*5113495bSYour Name  * WLAN FW needs 2MB memory from DDR when QMI is disabled.
5186*5113495bSYour Name  *
5187*5113495bSYour Name  * Return: void
5188*5113495bSYour Name  */
hif_post_static_buf_to_target(struct hif_softc * scn)5189*5113495bSYour Name static void hif_post_static_buf_to_target(struct hif_softc *scn)
5190*5113495bSYour Name {
5191*5113495bSYour Name 	qdf_dma_addr_t target_pa;
5192*5113495bSYour Name 
5193*5113495bSYour Name 	scn->vaddr_qmi_bypass =
5194*5113495bSYour Name 			(uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
5195*5113495bSYour Name 							     scn->qdf_dev->dev,
5196*5113495bSYour Name 							     FW_SHARED_MEM,
5197*5113495bSYour Name 							     &target_pa);
5198*5113495bSYour Name 	if (!scn->vaddr_qmi_bypass) {
5199*5113495bSYour Name 		hif_err("Memory allocation failed could not post target buf");
5200*5113495bSYour Name 		return;
5201*5113495bSYour Name 	}
5202*5113495bSYour Name 
5203*5113495bSYour Name 	scn->paddr_qmi_bypass = target_pa;
5204*5113495bSYour Name 	hif_write32_mb(scn, scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
5205*5113495bSYour Name }
5206*5113495bSYour Name 
5207*5113495bSYour Name /**
5208*5113495bSYour Name  * hif_cleanup_static_buf_to_target() -  clean up static buffer to WLAN FW
5209*5113495bSYour Name  * @scn: pointer to HIF structure
5210*5113495bSYour Name  *
5211*5113495bSYour Name  *
5212*5113495bSYour Name  * Return: void
5213*5113495bSYour Name  */
hif_cleanup_static_buf_to_target(struct hif_softc * scn)5214*5113495bSYour Name void hif_cleanup_static_buf_to_target(struct hif_softc *scn)
5215*5113495bSYour Name {
5216*5113495bSYour Name 	void *target_va = scn->vaddr_qmi_bypass;
5217*5113495bSYour Name 	phys_addr_t target_pa = scn->paddr_qmi_bypass;
5218*5113495bSYour Name 
5219*5113495bSYour Name 	qdf_mem_free_consistent(scn->qdf_dev, scn->qdf_dev->dev,
5220*5113495bSYour Name 				FW_SHARED_MEM, target_va,
5221*5113495bSYour Name 				target_pa, 0);
5222*5113495bSYour Name 	hif_write32_mb(scn, scn->mem + BYPASS_QMI_TEMP_REGISTER, 0);
5223*5113495bSYour Name }
5224*5113495bSYour Name #endif
5225*5113495bSYour Name 
5226*5113495bSYour Name #else
hif_post_static_buf_to_target(struct hif_softc * scn)5227*5113495bSYour Name static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
5228*5113495bSYour Name {
5229*5113495bSYour Name }
5230*5113495bSYour Name 
hif_cleanup_static_buf_to_target(struct hif_softc * scn)5231*5113495bSYour Name void hif_cleanup_static_buf_to_target(struct hif_softc *scn)
5232*5113495bSYour Name {
5233*5113495bSYour Name }
5234*5113495bSYour Name #endif
5235*5113495bSYour Name 
hif_srng_sleep_state_adjust(struct hif_softc * scn,bool sleep_ok,bool wait_for_it)5236*5113495bSYour Name static int hif_srng_sleep_state_adjust(struct hif_softc *scn, bool sleep_ok,
5237*5113495bSYour Name 				bool wait_for_it)
5238*5113495bSYour Name {
5239*5113495bSYour Name 	/* todo */
5240*5113495bSYour Name 	return 0;
5241*5113495bSYour Name }
5242*5113495bSYour Name 
hif_config_ce_by_id(struct hif_softc * scn,int pipe_num)5243*5113495bSYour Name int hif_config_ce_by_id(struct hif_softc *scn, int pipe_num)
5244*5113495bSYour Name {
5245*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
5246*5113495bSYour Name 	struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
5247*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
5248*5113495bSYour Name 	struct CE_state *ce_state = NULL;
5249*5113495bSYour Name 	struct CE_attr *attr;
5250*5113495bSYour Name 	int rv = 0;
5251*5113495bSYour Name 
5252*5113495bSYour Name 	if (pipe_num >= CE_COUNT_MAX)
5253*5113495bSYour Name 		return -EINVAL;
5254*5113495bSYour Name 
5255*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe_num];
5256*5113495bSYour Name 	pipe_info->pipe_num = pipe_num;
5257*5113495bSYour Name 	pipe_info->HIF_CE_state = hif_state;
5258*5113495bSYour Name 	attr = &hif_state->host_ce_config[pipe_num];
5259*5113495bSYour Name 	ce_state = scn->ce_id_to_state[pipe_num];
5260*5113495bSYour Name 
5261*5113495bSYour Name 	if (ce_state) {
5262*5113495bSYour Name 		/* Do not reinitialize the CE if its done already */
5263*5113495bSYour Name 		rv = QDF_STATUS_E_BUSY;
5264*5113495bSYour Name 		goto err;
5265*5113495bSYour Name 	}
5266*5113495bSYour Name 
5267*5113495bSYour Name 	pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
5268*5113495bSYour Name 	ce_state = scn->ce_id_to_state[pipe_num];
5269*5113495bSYour Name 	if (!ce_state) {
5270*5113495bSYour Name 		A_TARGET_ACCESS_UNLIKELY(scn);
5271*5113495bSYour Name 		rv = QDF_STATUS_E_FAILURE;
5272*5113495bSYour Name 		goto err;
5273*5113495bSYour Name 	}
5274*5113495bSYour Name 	qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
5275*5113495bSYour Name 	QDF_ASSERT(pipe_info->ce_hdl);
5276*5113495bSYour Name 	if (!pipe_info->ce_hdl) {
5277*5113495bSYour Name 		rv = QDF_STATUS_E_FAILURE;
5278*5113495bSYour Name 		A_TARGET_ACCESS_UNLIKELY(scn);
5279*5113495bSYour Name 		goto err;
5280*5113495bSYour Name 	}
5281*5113495bSYour Name 
5282*5113495bSYour Name 	ce_state->lro_data = qdf_lro_init();
5283*5113495bSYour Name 
5284*5113495bSYour Name 	if (attr->flags & CE_ATTR_DIAG) {
5285*5113495bSYour Name 		/* Reserve the ultimate CE for
5286*5113495bSYour Name 		 * Diagnostic Window support
5287*5113495bSYour Name 		 */
5288*5113495bSYour Name 		hif_state->ce_diag = pipe_info->ce_hdl;
5289*5113495bSYour Name 		goto skip;
5290*5113495bSYour Name 	}
5291*5113495bSYour Name 
5292*5113495bSYour Name 	if (hif_is_nss_wifi_enabled(scn) && ce_state &&
5293*5113495bSYour Name 	    (ce_state->htt_rx_data)) {
5294*5113495bSYour Name 		goto skip;
5295*5113495bSYour Name 	}
5296*5113495bSYour Name 
5297*5113495bSYour Name 	pipe_info->buf_sz = (qdf_size_t)(attr->src_sz_max);
5298*5113495bSYour Name 	if (attr->dest_nentries > 0) {
5299*5113495bSYour Name 		atomic_set(&pipe_info->recv_bufs_needed,
5300*5113495bSYour Name 			   init_buffer_count(attr->dest_nentries - 1));
5301*5113495bSYour Name 		/*SRNG based CE has one entry less */
5302*5113495bSYour Name 		if (ce_srng_based(scn))
5303*5113495bSYour Name 			atomic_dec(&pipe_info->recv_bufs_needed);
5304*5113495bSYour Name 	} else {
5305*5113495bSYour Name 		atomic_set(&pipe_info->recv_bufs_needed, 0);
5306*5113495bSYour Name 	}
5307*5113495bSYour Name 	ce_tasklet_init(hif_state, (1 << pipe_num));
5308*5113495bSYour Name 	ce_register_irq(hif_state, (1 << pipe_num));
5309*5113495bSYour Name 
5310*5113495bSYour Name 	init_tasklet_worker_by_ceid(hif_hdl, pipe_num);
5311*5113495bSYour Name skip:
5312*5113495bSYour Name 	return 0;
5313*5113495bSYour Name err:
5314*5113495bSYour Name 	return rv;
5315*5113495bSYour Name }
5316*5113495bSYour Name 
5317*5113495bSYour Name #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || defined(HIF_CE_DEBUG_DATA_BUF)
hif_gen_ce_id_history_idx_mapping(struct hif_softc * scn)5318*5113495bSYour Name static inline void hif_gen_ce_id_history_idx_mapping(struct hif_softc *scn)
5319*5113495bSYour Name {
5320*5113495bSYour Name 	struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
5321*5113495bSYour Name 	uint8_t ce_id, hist_idx = 0;
5322*5113495bSYour Name 
5323*5113495bSYour Name 	for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
5324*5113495bSYour Name 		if (IS_CE_DEBUG_ONLY_FOR_CRIT_CE & (1 << ce_id))
5325*5113495bSYour Name 			ce_hist->ce_id_hist_map[ce_id] = hist_idx++;
5326*5113495bSYour Name 		else
5327*5113495bSYour Name 			ce_hist->ce_id_hist_map[ce_id] = -1;
5328*5113495bSYour Name 	}
5329*5113495bSYour Name }
5330*5113495bSYour Name #else
hif_gen_ce_id_history_idx_mapping(struct hif_softc * scn)5331*5113495bSYour Name static inline void hif_gen_ce_id_history_idx_mapping(struct hif_softc *scn)
5332*5113495bSYour Name {
5333*5113495bSYour Name }
5334*5113495bSYour Name #endif
5335*5113495bSYour Name 
5336*5113495bSYour Name /**
5337*5113495bSYour Name  * hif_config_ce() - configure copy engines
5338*5113495bSYour Name  * @scn: hif context
5339*5113495bSYour Name  *
5340*5113495bSYour Name  * Prepares fw, copy engine hardware and host sw according
5341*5113495bSYour Name  * to the attributes selected by hif_ce_prepare_config.
5342*5113495bSYour Name  *
5343*5113495bSYour Name  * also calls athdiag_procfs_init
5344*5113495bSYour Name  *
5345*5113495bSYour Name  * return: 0 for success nonzero for failure.
5346*5113495bSYour Name  */
hif_config_ce(struct hif_softc * scn)5347*5113495bSYour Name int hif_config_ce(struct hif_softc *scn)
5348*5113495bSYour Name {
5349*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
5350*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
5351*5113495bSYour Name 	int pipe_num;
5352*5113495bSYour Name 
5353*5113495bSYour Name #ifdef ADRASTEA_SHADOW_REGISTERS
5354*5113495bSYour Name 	int i;
5355*5113495bSYour Name #endif
5356*5113495bSYour Name 	QDF_STATUS rv = QDF_STATUS_SUCCESS;
5357*5113495bSYour Name 
5358*5113495bSYour Name 	scn->notice_send = true;
5359*5113495bSYour Name 	scn->ce_service_max_rx_ind_flush = MSG_FLUSH_NUM;
5360*5113495bSYour Name 
5361*5113495bSYour Name 	hif_post_static_buf_to_target(scn);
5362*5113495bSYour Name 
5363*5113495bSYour Name 	hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
5364*5113495bSYour Name 
5365*5113495bSYour Name 	hif_config_rri_on_ddr(scn);
5366*5113495bSYour Name 
5367*5113495bSYour Name 	if (ce_srng_based(scn))
5368*5113495bSYour Name 		scn->bus_ops.hif_target_sleep_state_adjust =
5369*5113495bSYour Name 			&hif_srng_sleep_state_adjust;
5370*5113495bSYour Name 
5371*5113495bSYour Name 	/* Initialise the CE debug history sysfs interface inputs ce_id and
5372*5113495bSYour Name 	 * index. Disable data storing
5373*5113495bSYour Name 	 */
5374*5113495bSYour Name 	reset_ce_debug_history(scn);
5375*5113495bSYour Name 	hif_gen_ce_id_history_idx_mapping(scn);
5376*5113495bSYour Name 
5377*5113495bSYour Name 	for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
5378*5113495bSYour Name 		struct CE_attr *attr;
5379*5113495bSYour Name 
5380*5113495bSYour Name 		pipe_info = &hif_state->pipe_info[pipe_num];
5381*5113495bSYour Name 		attr = &hif_state->host_ce_config[pipe_num];
5382*5113495bSYour Name 
5383*5113495bSYour Name 		if (attr->flags & CE_ATTR_INIT_ON_DEMAND)
5384*5113495bSYour Name 			continue;
5385*5113495bSYour Name 
5386*5113495bSYour Name 		if (hif_config_ce_by_id(scn, pipe_num))
5387*5113495bSYour Name 			goto err;
5388*5113495bSYour Name 	}
5389*5113495bSYour Name 
5390*5113495bSYour Name 	if (athdiag_procfs_init(scn) != 0) {
5391*5113495bSYour Name 		A_TARGET_ACCESS_UNLIKELY(scn);
5392*5113495bSYour Name 		goto err;
5393*5113495bSYour Name 	}
5394*5113495bSYour Name 	scn->athdiag_procfs_inited = true;
5395*5113495bSYour Name 
5396*5113495bSYour Name 	hif_debug("ce_init done");
5397*5113495bSYour Name 	hif_debug("X, ret = %d", rv);
5398*5113495bSYour Name 
5399*5113495bSYour Name #ifdef ADRASTEA_SHADOW_REGISTERS
5400*5113495bSYour Name 	hif_debug("Using Shadow Registers instead of CE Registers");
5401*5113495bSYour Name 	for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
5402*5113495bSYour Name 		hif_debug("Shadow Register%d is mapped to address %x",
5403*5113495bSYour Name 			  i,
5404*5113495bSYour Name 			  (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
5405*5113495bSYour Name 	}
5406*5113495bSYour Name #endif
5407*5113495bSYour Name 
5408*5113495bSYour Name 	return rv != QDF_STATUS_SUCCESS;
5409*5113495bSYour Name err:
5410*5113495bSYour Name 	/* Failure, so clean up */
5411*5113495bSYour Name 	hif_unconfig_ce(scn);
5412*5113495bSYour Name 	hif_info("X, ret = %d", rv);
5413*5113495bSYour Name 	return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
5414*5113495bSYour Name }
5415*5113495bSYour Name 
5416*5113495bSYour Name /**
5417*5113495bSYour Name  * hif_config_ce_pktlog() - configure copy engines
5418*5113495bSYour Name  * @hif_hdl: hif context
5419*5113495bSYour Name  *
5420*5113495bSYour Name  * Prepares fw, copy engine hardware and host sw according
5421*5113495bSYour Name  * to the attributes selected by hif_ce_prepare_config.
5422*5113495bSYour Name  *
5423*5113495bSYour Name  * also calls athdiag_procfs_init
5424*5113495bSYour Name  *
5425*5113495bSYour Name  * return: 0 for success nonzero for failure.
5426*5113495bSYour Name  */
hif_config_ce_pktlog(struct hif_opaque_softc * hif_hdl)5427*5113495bSYour Name int hif_config_ce_pktlog(struct hif_opaque_softc *hif_hdl)
5428*5113495bSYour Name {
5429*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
5430*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
5431*5113495bSYour Name 	int pipe_num;
5432*5113495bSYour Name 	QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
5433*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info;
5434*5113495bSYour Name 
5435*5113495bSYour Name 	if (!scn)
5436*5113495bSYour Name 		goto err;
5437*5113495bSYour Name 
5438*5113495bSYour Name 	if (scn->pktlog_init)
5439*5113495bSYour Name 		return QDF_STATUS_SUCCESS;
5440*5113495bSYour Name 
5441*5113495bSYour Name 	pipe_num =  hif_get_pktlog_ce_num(scn);
5442*5113495bSYour Name 	if (pipe_num < 0) {
5443*5113495bSYour Name 		qdf_status = QDF_STATUS_E_FAILURE;
5444*5113495bSYour Name 		goto err;
5445*5113495bSYour Name 	}
5446*5113495bSYour Name 
5447*5113495bSYour Name 	pipe_info = &hif_state->pipe_info[pipe_num];
5448*5113495bSYour Name 
5449*5113495bSYour Name 	qdf_status = hif_config_ce_by_id(scn, pipe_num);
5450*5113495bSYour Name 	/* CE Already initialized. Do not try to reinitialized again */
5451*5113495bSYour Name 	if (qdf_status == QDF_STATUS_E_BUSY)
5452*5113495bSYour Name 		return QDF_STATUS_SUCCESS;
5453*5113495bSYour Name 
5454*5113495bSYour Name 	qdf_status = hif_config_irq_by_ceid(scn, pipe_num);
5455*5113495bSYour Name 	if (qdf_status < 0)
5456*5113495bSYour Name 		goto err;
5457*5113495bSYour Name 
5458*5113495bSYour Name 	qdf_status = hif_completion_thread_startup_by_ceid(hif_state, pipe_num);
5459*5113495bSYour Name 	if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
5460*5113495bSYour Name 		hif_err("Failed to start hif thread");
5461*5113495bSYour Name 		goto err;
5462*5113495bSYour Name 	}
5463*5113495bSYour Name 
5464*5113495bSYour Name 	/* Post buffers for pktlog copy engine. */
5465*5113495bSYour Name 	qdf_status = hif_post_recv_buffers_for_pipe(pipe_info);
5466*5113495bSYour Name 	if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
5467*5113495bSYour Name 		/* cleanup is done in hif_ce_disable */
5468*5113495bSYour Name 		hif_err("Failed to post buffers");
5469*5113495bSYour Name 		return qdf_status;
5470*5113495bSYour Name 	}
5471*5113495bSYour Name 	scn->pktlog_init = true;
5472*5113495bSYour Name 	return qdf_status != QDF_STATUS_SUCCESS;
5473*5113495bSYour Name 
5474*5113495bSYour Name err:
5475*5113495bSYour Name 	hif_debug("X, ret = %d", qdf_status);
5476*5113495bSYour Name 	return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
5477*5113495bSYour Name }
5478*5113495bSYour Name 
5479*5113495bSYour Name #ifdef IPA_OFFLOAD
5480*5113495bSYour Name /**
5481*5113495bSYour Name  * hif_ce_ipa_get_ce_resource() - get uc resource on hif
5482*5113495bSYour Name  * @scn: bus context
5483*5113495bSYour Name  * @ce_sr: copyengine source ring base physical address
5484*5113495bSYour Name  * @ce_sr_ring_size: copyengine source ring size
5485*5113495bSYour Name  * @ce_reg_paddr: copyengine register physical address
5486*5113495bSYour Name  *
5487*5113495bSYour Name  * IPA micro controller data path offload feature enabled,
5488*5113495bSYour Name  * HIF should release copy engine related resource information to IPA UC
5489*5113495bSYour Name  * IPA UC will access hardware resource with released information
5490*5113495bSYour Name  *
5491*5113495bSYour Name  * Return: None
5492*5113495bSYour Name  */
hif_ce_ipa_get_ce_resource(struct hif_softc * scn,qdf_shared_mem_t ** ce_sr,uint32_t * ce_sr_ring_size,qdf_dma_addr_t * ce_reg_paddr)5493*5113495bSYour Name void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
5494*5113495bSYour Name 			     qdf_shared_mem_t **ce_sr,
5495*5113495bSYour Name 			     uint32_t *ce_sr_ring_size,
5496*5113495bSYour Name 			     qdf_dma_addr_t *ce_reg_paddr)
5497*5113495bSYour Name {
5498*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
5499*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info =
5500*5113495bSYour Name 		&(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
5501*5113495bSYour Name 	struct CE_handle *ce_hdl = pipe_info->ce_hdl;
5502*5113495bSYour Name 
5503*5113495bSYour Name 	ce_ipa_get_resource(ce_hdl, ce_sr, ce_sr_ring_size,
5504*5113495bSYour Name 			    ce_reg_paddr);
5505*5113495bSYour Name }
5506*5113495bSYour Name #endif /* IPA_OFFLOAD */
5507*5113495bSYour Name 
5508*5113495bSYour Name 
5509*5113495bSYour Name #ifdef ADRASTEA_SHADOW_REGISTERS
5510*5113495bSYour Name 
5511*5113495bSYour Name /*
5512*5113495bSYour Name  * Current shadow register config
5513*5113495bSYour Name  *
5514*5113495bSYour Name  * -----------------------------------------------------------
5515*5113495bSYour Name  * Shadow Register      |     CE   |    src/dst write index
5516*5113495bSYour Name  * -----------------------------------------------------------
5517*5113495bSYour Name  *         0            |     0    |           src
5518*5113495bSYour Name  *         1     No Config - Doesn't point to anything
5519*5113495bSYour Name  *         2     No Config - Doesn't point to anything
5520*5113495bSYour Name  *         3            |     3    |           src
5521*5113495bSYour Name  *         4            |     4    |           src
5522*5113495bSYour Name  *         5            |     5    |           src
5523*5113495bSYour Name  *         6     No Config - Doesn't point to anything
5524*5113495bSYour Name  *         7            |     7    |           src
5525*5113495bSYour Name  *         8     No Config - Doesn't point to anything
5526*5113495bSYour Name  *         9     No Config - Doesn't point to anything
5527*5113495bSYour Name  *         10    No Config - Doesn't point to anything
5528*5113495bSYour Name  *         11    No Config - Doesn't point to anything
5529*5113495bSYour Name  * -----------------------------------------------------------
5530*5113495bSYour Name  *         12    No Config - Doesn't point to anything
5531*5113495bSYour Name  *         13           |     1    |           dst
5532*5113495bSYour Name  *         14           |     2    |           dst
5533*5113495bSYour Name  *         15    No Config - Doesn't point to anything
5534*5113495bSYour Name  *         16    No Config - Doesn't point to anything
5535*5113495bSYour Name  *         17    No Config - Doesn't point to anything
5536*5113495bSYour Name  *         18    No Config - Doesn't point to anything
5537*5113495bSYour Name  *         19           |     7    |           dst
5538*5113495bSYour Name  *         20           |     8    |           dst
5539*5113495bSYour Name  *         21    No Config - Doesn't point to anything
5540*5113495bSYour Name  *         22    No Config - Doesn't point to anything
5541*5113495bSYour Name  *         23    No Config - Doesn't point to anything
5542*5113495bSYour Name  * -----------------------------------------------------------
5543*5113495bSYour Name  *
5544*5113495bSYour Name  *
5545*5113495bSYour Name  * ToDo - Move shadow register config to following in the future
5546*5113495bSYour Name  * This helps free up a block of shadow registers towards the end.
5547*5113495bSYour Name  * Can be used for other purposes
5548*5113495bSYour Name  *
5549*5113495bSYour Name  * -----------------------------------------------------------
5550*5113495bSYour Name  * Shadow Register      |     CE   |    src/dst write index
5551*5113495bSYour Name  * -----------------------------------------------------------
5552*5113495bSYour Name  *      0            |     0    |           src
5553*5113495bSYour Name  *      1            |     3    |           src
5554*5113495bSYour Name  *      2            |     4    |           src
5555*5113495bSYour Name  *      3            |     5    |           src
5556*5113495bSYour Name  *      4            |     7    |           src
5557*5113495bSYour Name  * -----------------------------------------------------------
5558*5113495bSYour Name  *      5            |     1    |           dst
5559*5113495bSYour Name  *      6            |     2    |           dst
5560*5113495bSYour Name  *      7            |     7    |           dst
5561*5113495bSYour Name  *      8            |     8    |           dst
5562*5113495bSYour Name  * -----------------------------------------------------------
5563*5113495bSYour Name  *      9     No Config - Doesn't point to anything
5564*5113495bSYour Name  *      12    No Config - Doesn't point to anything
5565*5113495bSYour Name  *      13    No Config - Doesn't point to anything
5566*5113495bSYour Name  *      14    No Config - Doesn't point to anything
5567*5113495bSYour Name  *      15    No Config - Doesn't point to anything
5568*5113495bSYour Name  *      16    No Config - Doesn't point to anything
5569*5113495bSYour Name  *      17    No Config - Doesn't point to anything
5570*5113495bSYour Name  *      18    No Config - Doesn't point to anything
5571*5113495bSYour Name  *      19    No Config - Doesn't point to anything
5572*5113495bSYour Name  *      20    No Config - Doesn't point to anything
5573*5113495bSYour Name  *      21    No Config - Doesn't point to anything
5574*5113495bSYour Name  *      22    No Config - Doesn't point to anything
5575*5113495bSYour Name  *      23    No Config - Doesn't point to anything
5576*5113495bSYour Name  * -----------------------------------------------------------
5577*5113495bSYour Name */
5578*5113495bSYour Name #ifndef QCN7605_SUPPORT
shadow_sr_wr_ind_addr(struct hif_softc * scn,u32 ctrl_addr)5579*5113495bSYour Name u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
5580*5113495bSYour Name {
5581*5113495bSYour Name 	u32 addr = 0;
5582*5113495bSYour Name 	u32 ce = COPY_ENGINE_ID(ctrl_addr);
5583*5113495bSYour Name 
5584*5113495bSYour Name 	switch (ce) {
5585*5113495bSYour Name 	case 0:
5586*5113495bSYour Name 		addr = SHADOW_VALUE0;
5587*5113495bSYour Name 		break;
5588*5113495bSYour Name 	case 3:
5589*5113495bSYour Name 		addr = SHADOW_VALUE3;
5590*5113495bSYour Name 		break;
5591*5113495bSYour Name 	case 4:
5592*5113495bSYour Name 		addr = SHADOW_VALUE4;
5593*5113495bSYour Name 		break;
5594*5113495bSYour Name 	case 5:
5595*5113495bSYour Name 		addr = SHADOW_VALUE5;
5596*5113495bSYour Name 		break;
5597*5113495bSYour Name 	case 7:
5598*5113495bSYour Name 		addr = SHADOW_VALUE7;
5599*5113495bSYour Name 		break;
5600*5113495bSYour Name 	default:
5601*5113495bSYour Name 		hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
5602*5113495bSYour Name 		QDF_ASSERT(0);
5603*5113495bSYour Name 	}
5604*5113495bSYour Name 	return addr;
5605*5113495bSYour Name 
5606*5113495bSYour Name }
5607*5113495bSYour Name 
shadow_dst_wr_ind_addr(struct hif_softc * scn,u32 ctrl_addr)5608*5113495bSYour Name u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
5609*5113495bSYour Name {
5610*5113495bSYour Name 	u32 addr = 0;
5611*5113495bSYour Name 	u32 ce = COPY_ENGINE_ID(ctrl_addr);
5612*5113495bSYour Name 
5613*5113495bSYour Name 	switch (ce) {
5614*5113495bSYour Name 	case 1:
5615*5113495bSYour Name 		addr = SHADOW_VALUE13;
5616*5113495bSYour Name 		break;
5617*5113495bSYour Name 	case 2:
5618*5113495bSYour Name 		addr = SHADOW_VALUE14;
5619*5113495bSYour Name 		break;
5620*5113495bSYour Name 	case 5:
5621*5113495bSYour Name 		addr = SHADOW_VALUE17;
5622*5113495bSYour Name 		break;
5623*5113495bSYour Name 	case 7:
5624*5113495bSYour Name 		addr = SHADOW_VALUE19;
5625*5113495bSYour Name 		break;
5626*5113495bSYour Name 	case 8:
5627*5113495bSYour Name 		addr = SHADOW_VALUE20;
5628*5113495bSYour Name 		break;
5629*5113495bSYour Name 	case 9:
5630*5113495bSYour Name 		addr = SHADOW_VALUE21;
5631*5113495bSYour Name 		break;
5632*5113495bSYour Name 	case 10:
5633*5113495bSYour Name 		addr = SHADOW_VALUE22;
5634*5113495bSYour Name 		break;
5635*5113495bSYour Name 	case 11:
5636*5113495bSYour Name 		addr = SHADOW_VALUE23;
5637*5113495bSYour Name 		break;
5638*5113495bSYour Name 	default:
5639*5113495bSYour Name 		hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
5640*5113495bSYour Name 		QDF_ASSERT(0);
5641*5113495bSYour Name 	}
5642*5113495bSYour Name 
5643*5113495bSYour Name 	return addr;
5644*5113495bSYour Name 
5645*5113495bSYour Name }
5646*5113495bSYour Name #else
shadow_sr_wr_ind_addr(struct hif_softc * scn,u32 ctrl_addr)5647*5113495bSYour Name u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
5648*5113495bSYour Name {
5649*5113495bSYour Name 	u32 addr = 0;
5650*5113495bSYour Name 	u32 ce = COPY_ENGINE_ID(ctrl_addr);
5651*5113495bSYour Name 
5652*5113495bSYour Name 	switch (ce) {
5653*5113495bSYour Name 	case 0:
5654*5113495bSYour Name 		addr = SHADOW_VALUE0;
5655*5113495bSYour Name 		break;
5656*5113495bSYour Name 	case 3:
5657*5113495bSYour Name 		addr = SHADOW_VALUE3;
5658*5113495bSYour Name 		break;
5659*5113495bSYour Name 	case 4:
5660*5113495bSYour Name 		addr = SHADOW_VALUE4;
5661*5113495bSYour Name 		break;
5662*5113495bSYour Name 	case 5:
5663*5113495bSYour Name 		addr = SHADOW_VALUE5;
5664*5113495bSYour Name 		break;
5665*5113495bSYour Name 	default:
5666*5113495bSYour Name 		hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
5667*5113495bSYour Name 		QDF_ASSERT(0);
5668*5113495bSYour Name 	}
5669*5113495bSYour Name 	return addr;
5670*5113495bSYour Name }
5671*5113495bSYour Name 
shadow_dst_wr_ind_addr(struct hif_softc * scn,u32 ctrl_addr)5672*5113495bSYour Name u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
5673*5113495bSYour Name {
5674*5113495bSYour Name 	u32 addr = 0;
5675*5113495bSYour Name 	u32 ce = COPY_ENGINE_ID(ctrl_addr);
5676*5113495bSYour Name 
5677*5113495bSYour Name 	switch (ce) {
5678*5113495bSYour Name 	case 1:
5679*5113495bSYour Name 		addr = SHADOW_VALUE13;
5680*5113495bSYour Name 		break;
5681*5113495bSYour Name 	case 2:
5682*5113495bSYour Name 		addr = SHADOW_VALUE14;
5683*5113495bSYour Name 		break;
5684*5113495bSYour Name 	case 3:
5685*5113495bSYour Name 		addr = SHADOW_VALUE15;
5686*5113495bSYour Name 		break;
5687*5113495bSYour Name 	case 5:
5688*5113495bSYour Name 		addr = SHADOW_VALUE17;
5689*5113495bSYour Name 		break;
5690*5113495bSYour Name 	case 7:
5691*5113495bSYour Name 		addr = SHADOW_VALUE19;
5692*5113495bSYour Name 		break;
5693*5113495bSYour Name 	case 8:
5694*5113495bSYour Name 		addr = SHADOW_VALUE20;
5695*5113495bSYour Name 		break;
5696*5113495bSYour Name 	case 9:
5697*5113495bSYour Name 		addr = SHADOW_VALUE21;
5698*5113495bSYour Name 		break;
5699*5113495bSYour Name 	case 10:
5700*5113495bSYour Name 		addr = SHADOW_VALUE22;
5701*5113495bSYour Name 		break;
5702*5113495bSYour Name 	case 11:
5703*5113495bSYour Name 		addr = SHADOW_VALUE23;
5704*5113495bSYour Name 		break;
5705*5113495bSYour Name 	default:
5706*5113495bSYour Name 		hif_err("Invalid CE ctrl_addr (CE=%d)", ce);
5707*5113495bSYour Name 		QDF_ASSERT(0);
5708*5113495bSYour Name 	}
5709*5113495bSYour Name 
5710*5113495bSYour Name 	return addr;
5711*5113495bSYour Name }
5712*5113495bSYour Name #endif
5713*5113495bSYour Name #endif
5714*5113495bSYour Name 
5715*5113495bSYour Name #if defined(FEATURE_LRO)
hif_ce_get_lro_ctx(struct hif_opaque_softc * hif_hdl,int ctx_id)5716*5113495bSYour Name void *hif_ce_get_lro_ctx(struct hif_opaque_softc *hif_hdl, int ctx_id)
5717*5113495bSYour Name {
5718*5113495bSYour Name 	struct CE_state *ce_state;
5719*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
5720*5113495bSYour Name 
5721*5113495bSYour Name 	ce_state = scn->ce_id_to_state[ctx_id];
5722*5113495bSYour Name 
5723*5113495bSYour Name 	return ce_state->lro_data;
5724*5113495bSYour Name }
5725*5113495bSYour Name #endif
5726*5113495bSYour Name 
5727*5113495bSYour Name /**
5728*5113495bSYour Name  * hif_map_service_to_pipe() - returns  the ce ids pertaining to
5729*5113495bSYour Name  * this service
5730*5113495bSYour Name  * @hif_hdl: hif_softc pointer.
5731*5113495bSYour Name  * @svc_id: Service ID for which the mapping is needed.
5732*5113495bSYour Name  * @ul_pipe: address of the container in which ul pipe is returned.
5733*5113495bSYour Name  * @dl_pipe: address of the container in which dl pipe is returned.
5734*5113495bSYour Name  * @ul_is_polled: address of the container in which a bool
5735*5113495bSYour Name  *			indicating if the UL CE for this service
5736*5113495bSYour Name  *			is polled is returned.
5737*5113495bSYour Name  * @dl_is_polled: address of the container in which a bool
5738*5113495bSYour Name  *			indicating if the DL CE for this service
5739*5113495bSYour Name  *			is polled is returned.
5740*5113495bSYour Name  *
5741*5113495bSYour Name  * Return: Indicates whether the service has been found in the table.
5742*5113495bSYour Name  *         Upon return, ul_is_polled is updated only if ul_pipe is updated.
5743*5113495bSYour Name  *         There will be warning logs if either leg has not been updated
5744*5113495bSYour Name  *         because it missed the entry in the table (but this is not an err).
5745*5113495bSYour Name  */
hif_map_service_to_pipe(struct hif_opaque_softc * hif_hdl,uint16_t svc_id,uint8_t * ul_pipe,uint8_t * dl_pipe,int * ul_is_polled,int * dl_is_polled)5746*5113495bSYour Name int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
5747*5113495bSYour Name 			uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
5748*5113495bSYour Name 			int *dl_is_polled)
5749*5113495bSYour Name {
5750*5113495bSYour Name 	int status = -EINVAL;
5751*5113495bSYour Name 	unsigned int i;
5752*5113495bSYour Name 	struct service_to_pipe element;
5753*5113495bSYour Name 	struct service_to_pipe *tgt_svc_map_to_use;
5754*5113495bSYour Name 	uint32_t sz_tgt_svc_map_to_use;
5755*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
5756*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
5757*5113495bSYour Name 	bool dl_updated = false;
5758*5113495bSYour Name 	bool ul_updated = false;
5759*5113495bSYour Name 
5760*5113495bSYour Name 	hif_select_service_to_pipe_map(scn, &tgt_svc_map_to_use,
5761*5113495bSYour Name 				       &sz_tgt_svc_map_to_use);
5762*5113495bSYour Name 
5763*5113495bSYour Name 	*dl_is_polled = 0;  /* polling for received messages not supported */
5764*5113495bSYour Name 
5765*5113495bSYour Name 	for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
5766*5113495bSYour Name 
5767*5113495bSYour Name 		memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
5768*5113495bSYour Name 		if (element.service_id == svc_id) {
5769*5113495bSYour Name 			if (element.pipedir == PIPEDIR_OUT) {
5770*5113495bSYour Name 				*ul_pipe = element.pipenum;
5771*5113495bSYour Name 				*ul_is_polled =
5772*5113495bSYour Name 					(hif_state->host_ce_config[*ul_pipe].flags &
5773*5113495bSYour Name 					 CE_ATTR_DISABLE_INTR) != 0;
5774*5113495bSYour Name 				ul_updated = true;
5775*5113495bSYour Name 			} else if (element.pipedir == PIPEDIR_IN) {
5776*5113495bSYour Name 				*dl_pipe = element.pipenum;
5777*5113495bSYour Name 				dl_updated = true;
5778*5113495bSYour Name 			}
5779*5113495bSYour Name 			status = 0;
5780*5113495bSYour Name 		}
5781*5113495bSYour Name 	}
5782*5113495bSYour Name 	if (ul_updated == false)
5783*5113495bSYour Name 		hif_debug("ul pipe is NOT updated for service %d", svc_id);
5784*5113495bSYour Name 	if (dl_updated == false)
5785*5113495bSYour Name 		hif_debug("dl pipe is NOT updated for service %d", svc_id);
5786*5113495bSYour Name 
5787*5113495bSYour Name 	return status;
5788*5113495bSYour Name }
5789*5113495bSYour Name 
5790*5113495bSYour Name #ifdef SHADOW_REG_DEBUG
DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc * scn,uint32_t CE_ctrl_addr)5791*5113495bSYour Name inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
5792*5113495bSYour Name 		uint32_t CE_ctrl_addr)
5793*5113495bSYour Name {
5794*5113495bSYour Name 	uint32_t read_from_hw, srri_from_ddr = 0;
5795*5113495bSYour Name 
5796*5113495bSYour Name 	read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
5797*5113495bSYour Name 
5798*5113495bSYour Name 	srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
5799*5113495bSYour Name 
5800*5113495bSYour Name 	if (read_from_hw != srri_from_ddr) {
5801*5113495bSYour Name 		hif_err("read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
5802*5113495bSYour Name 		       srri_from_ddr, read_from_hw,
5803*5113495bSYour Name 		       CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
5804*5113495bSYour Name 		QDF_ASSERT(0);
5805*5113495bSYour Name 	}
5806*5113495bSYour Name 	return srri_from_ddr;
5807*5113495bSYour Name }
5808*5113495bSYour Name 
5809*5113495bSYour Name 
DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc * scn,uint32_t CE_ctrl_addr)5810*5113495bSYour Name inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
5811*5113495bSYour Name 		uint32_t CE_ctrl_addr)
5812*5113495bSYour Name {
5813*5113495bSYour Name 	uint32_t read_from_hw, drri_from_ddr = 0;
5814*5113495bSYour Name 
5815*5113495bSYour Name 	read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
5816*5113495bSYour Name 
5817*5113495bSYour Name 	drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
5818*5113495bSYour Name 
5819*5113495bSYour Name 	if (read_from_hw != drri_from_ddr) {
5820*5113495bSYour Name 		hif_err("read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
5821*5113495bSYour Name 		       drri_from_ddr, read_from_hw,
5822*5113495bSYour Name 		       CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
5823*5113495bSYour Name 		QDF_ASSERT(0);
5824*5113495bSYour Name 	}
5825*5113495bSYour Name 	return drri_from_ddr;
5826*5113495bSYour Name }
5827*5113495bSYour Name 
5828*5113495bSYour Name #endif
5829*5113495bSYour Name 
5830*5113495bSYour Name /**
5831*5113495bSYour Name  * hif_dump_ce_registers() - dump ce registers
5832*5113495bSYour Name  * @scn: hif_opaque_softc pointer.
5833*5113495bSYour Name  *
5834*5113495bSYour Name  * Output the copy engine registers
5835*5113495bSYour Name  *
5836*5113495bSYour Name  * Return: 0 for success or error code
5837*5113495bSYour Name  */
hif_dump_ce_registers(struct hif_softc * scn)5838*5113495bSYour Name int hif_dump_ce_registers(struct hif_softc *scn)
5839*5113495bSYour Name {
5840*5113495bSYour Name 	struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
5841*5113495bSYour Name 	uint32_t ce_reg_address = CE0_BASE_ADDRESS;
5842*5113495bSYour Name 	uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
5843*5113495bSYour Name 	uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
5844*5113495bSYour Name 	uint16_t i;
5845*5113495bSYour Name 	QDF_STATUS status;
5846*5113495bSYour Name 
5847*5113495bSYour Name 	for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
5848*5113495bSYour Name 		if (!scn->ce_id_to_state[i]) {
5849*5113495bSYour Name 			hif_debug("CE%d not used", i);
5850*5113495bSYour Name 			continue;
5851*5113495bSYour Name 		}
5852*5113495bSYour Name 
5853*5113495bSYour Name 		status = hif_diag_read_mem(hif_hdl, ce_reg_address,
5854*5113495bSYour Name 					   (uint8_t *) &ce_reg_values[0],
5855*5113495bSYour Name 					   ce_reg_word_size * sizeof(uint32_t));
5856*5113495bSYour Name 
5857*5113495bSYour Name 		if (status != QDF_STATUS_SUCCESS) {
5858*5113495bSYour Name 			hif_err("Dumping CE register failed!");
5859*5113495bSYour Name 			return -EACCES;
5860*5113495bSYour Name 		}
5861*5113495bSYour Name 		hif_debug("CE%d=>", i);
5862*5113495bSYour Name 		qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
5863*5113495bSYour Name 				   (uint8_t *) &ce_reg_values[0],
5864*5113495bSYour Name 				   ce_reg_word_size * sizeof(uint32_t));
5865*5113495bSYour Name 		qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d", (ce_reg_address
5866*5113495bSYour Name 				+ SR_WR_INDEX_ADDRESS),
5867*5113495bSYour Name 				ce_reg_values[SR_WR_INDEX_ADDRESS/4]);
5868*5113495bSYour Name 		qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d", (ce_reg_address
5869*5113495bSYour Name 				+ CURRENT_SRRI_ADDRESS),
5870*5113495bSYour Name 				ce_reg_values[CURRENT_SRRI_ADDRESS/4]);
5871*5113495bSYour Name 		qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d", (ce_reg_address
5872*5113495bSYour Name 				+ DST_WR_INDEX_ADDRESS),
5873*5113495bSYour Name 				ce_reg_values[DST_WR_INDEX_ADDRESS/4]);
5874*5113495bSYour Name 		qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d", (ce_reg_address
5875*5113495bSYour Name 				+ CURRENT_DRRI_ADDRESS),
5876*5113495bSYour Name 				ce_reg_values[CURRENT_DRRI_ADDRESS/4]);
5877*5113495bSYour Name 		qdf_print("---");
5878*5113495bSYour Name 	}
5879*5113495bSYour Name 	return 0;
5880*5113495bSYour Name }
5881*5113495bSYour Name qdf_export_symbol(hif_dump_ce_registers);
5882*5113495bSYour Name #ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
hif_get_addl_pipe_info(struct hif_opaque_softc * osc,struct hif_pipe_addl_info * hif_info,uint32_t pipe)5883*5113495bSYour Name struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
5884*5113495bSYour Name 		struct hif_pipe_addl_info *hif_info, uint32_t pipe)
5885*5113495bSYour Name {
5886*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(osc);
5887*5113495bSYour Name 	struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
5888*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
5889*5113495bSYour Name 	struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
5890*5113495bSYour Name 	struct CE_handle *ce_hdl = pipe_info->ce_hdl;
5891*5113495bSYour Name 	struct CE_state *ce_state = (struct CE_state *)ce_hdl;
5892*5113495bSYour Name 	struct CE_ring_state *src_ring = ce_state->src_ring;
5893*5113495bSYour Name 	struct CE_ring_state *dest_ring = ce_state->dest_ring;
5894*5113495bSYour Name 
5895*5113495bSYour Name 	if (src_ring) {
5896*5113495bSYour Name 		hif_info->ul_pipe.nentries = src_ring->nentries;
5897*5113495bSYour Name 		hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
5898*5113495bSYour Name 		hif_info->ul_pipe.sw_index = src_ring->sw_index;
5899*5113495bSYour Name 		hif_info->ul_pipe.write_index = src_ring->write_index;
5900*5113495bSYour Name 		hif_info->ul_pipe.hw_index = src_ring->hw_index;
5901*5113495bSYour Name 		hif_info->ul_pipe.base_addr_CE_space =
5902*5113495bSYour Name 			src_ring->base_addr_CE_space;
5903*5113495bSYour Name 		hif_info->ul_pipe.base_addr_owner_space =
5904*5113495bSYour Name 			src_ring->base_addr_owner_space;
5905*5113495bSYour Name 	}
5906*5113495bSYour Name 
5907*5113495bSYour Name 
5908*5113495bSYour Name 	if (dest_ring) {
5909*5113495bSYour Name 		hif_info->dl_pipe.nentries = dest_ring->nentries;
5910*5113495bSYour Name 		hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
5911*5113495bSYour Name 		hif_info->dl_pipe.sw_index = dest_ring->sw_index;
5912*5113495bSYour Name 		hif_info->dl_pipe.write_index = dest_ring->write_index;
5913*5113495bSYour Name 		hif_info->dl_pipe.hw_index = dest_ring->hw_index;
5914*5113495bSYour Name 		hif_info->dl_pipe.base_addr_CE_space =
5915*5113495bSYour Name 			dest_ring->base_addr_CE_space;
5916*5113495bSYour Name 		hif_info->dl_pipe.base_addr_owner_space =
5917*5113495bSYour Name 			dest_ring->base_addr_owner_space;
5918*5113495bSYour Name 	}
5919*5113495bSYour Name 
5920*5113495bSYour Name 	hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
5921*5113495bSYour Name 	hif_info->ctrl_addr = ce_state->ctrl_addr;
5922*5113495bSYour Name 
5923*5113495bSYour Name 	return hif_info;
5924*5113495bSYour Name }
5925*5113495bSYour Name qdf_export_symbol(hif_get_addl_pipe_info);
5926*5113495bSYour Name 
hif_set_nss_wifiol_mode(struct hif_opaque_softc * osc,uint32_t mode)5927*5113495bSYour Name uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
5928*5113495bSYour Name {
5929*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(osc);
5930*5113495bSYour Name 
5931*5113495bSYour Name 	scn->nss_wifi_ol_mode = mode;
5932*5113495bSYour Name 	return 0;
5933*5113495bSYour Name }
5934*5113495bSYour Name qdf_export_symbol(hif_set_nss_wifiol_mode);
5935*5113495bSYour Name #endif
5936*5113495bSYour Name 
hif_set_attribute(struct hif_opaque_softc * osc,uint8_t hif_attrib)5937*5113495bSYour Name void hif_set_attribute(struct hif_opaque_softc *osc, uint8_t hif_attrib)
5938*5113495bSYour Name {
5939*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(osc);
5940*5113495bSYour Name 	scn->hif_attribute = hif_attrib;
5941*5113495bSYour Name }
5942*5113495bSYour Name 
5943*5113495bSYour Name 
5944*5113495bSYour Name /* disable interrupts (only applicable for legacy copy engine currently */
hif_disable_interrupt(struct hif_opaque_softc * osc,uint32_t pipe_num)5945*5113495bSYour Name void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
5946*5113495bSYour Name {
5947*5113495bSYour Name 	struct hif_softc *scn = HIF_GET_SOFTC(osc);
5948*5113495bSYour Name 	struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
5949*5113495bSYour Name 	uint32_t ctrl_addr = CE_state->ctrl_addr;
5950*5113495bSYour Name 
5951*5113495bSYour Name 	Q_TARGET_ACCESS_BEGIN(scn);
5952*5113495bSYour Name 	CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
5953*5113495bSYour Name 	Q_TARGET_ACCESS_END(scn);
5954*5113495bSYour Name }
5955*5113495bSYour Name qdf_export_symbol(hif_disable_interrupt);
5956*5113495bSYour Name 
5957*5113495bSYour Name /**
5958*5113495bSYour Name  * hif_fw_event_handler() - hif fw event handler
5959*5113495bSYour Name  * @hif_state: pointer to hif ce state structure
5960*5113495bSYour Name  *
5961*5113495bSYour Name  * Process fw events and raise HTC callback to process fw events.
5962*5113495bSYour Name  *
5963*5113495bSYour Name  * Return: none
5964*5113495bSYour Name  */
hif_fw_event_handler(struct HIF_CE_state * hif_state)5965*5113495bSYour Name static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
5966*5113495bSYour Name {
5967*5113495bSYour Name 	struct hif_msg_callbacks *msg_callbacks =
5968*5113495bSYour Name 		&hif_state->msg_callbacks_current;
5969*5113495bSYour Name 
5970*5113495bSYour Name 	if (!msg_callbacks->fwEventHandler)
5971*5113495bSYour Name 		return;
5972*5113495bSYour Name 
5973*5113495bSYour Name 	msg_callbacks->fwEventHandler(msg_callbacks->Context,
5974*5113495bSYour Name 			QDF_STATUS_E_FAILURE);
5975*5113495bSYour Name }
5976*5113495bSYour Name 
5977*5113495bSYour Name #ifndef QCA_WIFI_3_0
5978*5113495bSYour Name /**
5979*5113495bSYour Name  * hif_fw_interrupt_handler() - FW interrupt handler
5980*5113495bSYour Name  * @irq: irq number
5981*5113495bSYour Name  * @arg: the user pointer
5982*5113495bSYour Name  *
5983*5113495bSYour Name  * Called from the PCI interrupt handler when a
5984*5113495bSYour Name  * firmware-generated interrupt to the Host.
5985*5113495bSYour Name  *
5986*5113495bSYour Name  * only registered for legacy ce devices
5987*5113495bSYour Name  *
5988*5113495bSYour Name  * Return: status of handled irq
5989*5113495bSYour Name  */
hif_fw_interrupt_handler(int irq,void * arg)5990*5113495bSYour Name irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
5991*5113495bSYour Name {
5992*5113495bSYour Name 	struct hif_softc *scn = arg;
5993*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
5994*5113495bSYour Name 	uint32_t fw_indicator_address, fw_indicator;
5995*5113495bSYour Name 
5996*5113495bSYour Name 	if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
5997*5113495bSYour Name 		return ATH_ISR_NOSCHED;
5998*5113495bSYour Name 
5999*5113495bSYour Name 	fw_indicator_address = hif_state->fw_indicator_address;
6000*5113495bSYour Name 	/* For sudden unplug this will return ~0 */
6001*5113495bSYour Name 	fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
6002*5113495bSYour Name 
6003*5113495bSYour Name 	if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
6004*5113495bSYour Name 		/* ACK: clear Target-side pending event */
6005*5113495bSYour Name 		A_TARGET_WRITE(scn, fw_indicator_address,
6006*5113495bSYour Name 			       fw_indicator & ~FW_IND_EVENT_PENDING);
6007*5113495bSYour Name 		if (Q_TARGET_ACCESS_END(scn) < 0)
6008*5113495bSYour Name 			return ATH_ISR_SCHED;
6009*5113495bSYour Name 
6010*5113495bSYour Name 		if (hif_state->started) {
6011*5113495bSYour Name 			hif_fw_event_handler(hif_state);
6012*5113495bSYour Name 		} else {
6013*5113495bSYour Name 			/*
6014*5113495bSYour Name 			 * Probable Target failure before we're prepared
6015*5113495bSYour Name 			 * to handle it.  Generally unexpected.
6016*5113495bSYour Name 			 * fw_indicator used as bitmap, and defined as below:
6017*5113495bSYour Name 			 *     FW_IND_EVENT_PENDING    0x1
6018*5113495bSYour Name 			 *     FW_IND_INITIALIZED      0x2
6019*5113495bSYour Name 			 *     FW_IND_NEEDRECOVER      0x4
6020*5113495bSYour Name 			 */
6021*5113495bSYour Name 			AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
6022*5113495bSYour Name 				("%s: Early firmware event indicated 0x%x\n",
6023*5113495bSYour Name 				 __func__, fw_indicator));
6024*5113495bSYour Name 		}
6025*5113495bSYour Name 	} else {
6026*5113495bSYour Name 		if (Q_TARGET_ACCESS_END(scn) < 0)
6027*5113495bSYour Name 			return ATH_ISR_SCHED;
6028*5113495bSYour Name 	}
6029*5113495bSYour Name 
6030*5113495bSYour Name 	return ATH_ISR_SCHED;
6031*5113495bSYour Name }
6032*5113495bSYour Name #else
hif_fw_interrupt_handler(int irq,void * arg)6033*5113495bSYour Name irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
6034*5113495bSYour Name {
6035*5113495bSYour Name 	return ATH_ISR_SCHED;
6036*5113495bSYour Name }
6037*5113495bSYour Name #endif /* #ifdef QCA_WIFI_3_0 */
6038*5113495bSYour Name 
6039*5113495bSYour Name 
6040*5113495bSYour Name /**
6041*5113495bSYour Name  * hif_wlan_disable(): call the platform driver to disable wlan
6042*5113495bSYour Name  * @scn: HIF Context
6043*5113495bSYour Name  *
6044*5113495bSYour Name  * This function passes the con_mode to platform driver to disable
6045*5113495bSYour Name  * wlan.
6046*5113495bSYour Name  *
6047*5113495bSYour Name  * Return: void
6048*5113495bSYour Name  */
hif_wlan_disable(struct hif_softc * scn)6049*5113495bSYour Name void hif_wlan_disable(struct hif_softc *scn)
6050*5113495bSYour Name {
6051*5113495bSYour Name 	enum pld_driver_mode mode;
6052*5113495bSYour Name 	uint32_t con_mode = hif_get_conparam(scn);
6053*5113495bSYour Name 
6054*5113495bSYour Name 	if (scn->target_status == TARGET_STATUS_RESET)
6055*5113495bSYour Name 		return;
6056*5113495bSYour Name 
6057*5113495bSYour Name 	if (QDF_GLOBAL_FTM_MODE == con_mode)
6058*5113495bSYour Name 		mode = PLD_FTM;
6059*5113495bSYour Name 	else if (QDF_IS_EPPING_ENABLED(con_mode))
6060*5113495bSYour Name 		mode = PLD_EPPING;
6061*5113495bSYour Name 	else
6062*5113495bSYour Name 		mode = PLD_MISSION;
6063*5113495bSYour Name 
6064*5113495bSYour Name 	pld_wlan_disable(scn->qdf_dev->dev, mode);
6065*5113495bSYour Name }
6066*5113495bSYour Name 
hif_get_wake_ce_id(struct hif_softc * scn,uint8_t * ce_id)6067*5113495bSYour Name int hif_get_wake_ce_id(struct hif_softc *scn, uint8_t *ce_id)
6068*5113495bSYour Name {
6069*5113495bSYour Name 	int status;
6070*5113495bSYour Name 	uint8_t ul_pipe, dl_pipe;
6071*5113495bSYour Name 	int ul_is_polled, dl_is_polled;
6072*5113495bSYour Name 
6073*5113495bSYour Name 	/* DL pipe for HTC_CTRL_RSVD_SVC should map to the wake CE */
6074*5113495bSYour Name 	status = hif_map_service_to_pipe(GET_HIF_OPAQUE_HDL(scn),
6075*5113495bSYour Name 					 HTC_CTRL_RSVD_SVC,
6076*5113495bSYour Name 					 &ul_pipe, &dl_pipe,
6077*5113495bSYour Name 					 &ul_is_polled, &dl_is_polled);
6078*5113495bSYour Name 	if (status) {
6079*5113495bSYour Name 		hif_err("Failed to map pipe: %d", status);
6080*5113495bSYour Name 		return status;
6081*5113495bSYour Name 	}
6082*5113495bSYour Name 
6083*5113495bSYour Name 	*ce_id = dl_pipe;
6084*5113495bSYour Name 
6085*5113495bSYour Name 	return 0;
6086*5113495bSYour Name }
6087*5113495bSYour Name 
hif_get_fw_diag_ce_id(struct hif_softc * scn,uint8_t * ce_id)6088*5113495bSYour Name int hif_get_fw_diag_ce_id(struct hif_softc *scn, uint8_t *ce_id)
6089*5113495bSYour Name {
6090*5113495bSYour Name 	int status;
6091*5113495bSYour Name 	uint8_t ul_pipe, dl_pipe;
6092*5113495bSYour Name 	int ul_is_polled, dl_is_polled;
6093*5113495bSYour Name 
6094*5113495bSYour Name 	/* DL pipe for WMI_CONTROL_DIAG_SVC should map to the FW DIAG CE_ID */
6095*5113495bSYour Name 	status = hif_map_service_to_pipe(GET_HIF_OPAQUE_HDL(scn),
6096*5113495bSYour Name 					 WMI_CONTROL_DIAG_SVC,
6097*5113495bSYour Name 					 &ul_pipe, &dl_pipe,
6098*5113495bSYour Name 					 &ul_is_polled, &dl_is_polled);
6099*5113495bSYour Name 	if (status) {
6100*5113495bSYour Name 		hif_err("Failed to map pipe: %d", status);
6101*5113495bSYour Name 		return status;
6102*5113495bSYour Name 	}
6103*5113495bSYour Name 
6104*5113495bSYour Name 	*ce_id = dl_pipe;
6105*5113495bSYour Name 
6106*5113495bSYour Name 	return 0;
6107*5113495bSYour Name }
6108*5113495bSYour Name 
6109*5113495bSYour Name #ifdef HIF_CE_LOG_INFO
6110*5113495bSYour Name /**
6111*5113495bSYour Name  * ce_get_index_info(): Get CE index info
6112*5113495bSYour Name  * @scn: HIF Context
6113*5113495bSYour Name  * @ce_state: CE opaque handle
6114*5113495bSYour Name  * @info: CE info
6115*5113495bSYour Name  *
6116*5113495bSYour Name  * Return: 0 for success and non zero for failure
6117*5113495bSYour Name  */
6118*5113495bSYour Name static
ce_get_index_info(struct hif_softc * scn,void * ce_state,struct ce_index * info)6119*5113495bSYour Name int ce_get_index_info(struct hif_softc *scn, void *ce_state,
6120*5113495bSYour Name 		      struct ce_index *info)
6121*5113495bSYour Name {
6122*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
6123*5113495bSYour Name 
6124*5113495bSYour Name 	return hif_state->ce_services->ce_get_index_info(scn, ce_state, info);
6125*5113495bSYour Name }
6126*5113495bSYour Name 
hif_log_ce_info(struct hif_softc * scn,uint8_t * data,unsigned int * offset)6127*5113495bSYour Name void hif_log_ce_info(struct hif_softc *scn, uint8_t *data,
6128*5113495bSYour Name 		     unsigned int *offset)
6129*5113495bSYour Name {
6130*5113495bSYour Name 	struct hang_event_info info = {0};
6131*5113495bSYour Name 	static uint32_t tracked_ce = BIT(CE_ID_1) | BIT(CE_ID_2) |
6132*5113495bSYour Name 		BIT(CE_ID_3) | BIT(CE_ID_4) | BIT(CE_ID_9) | BIT(CE_ID_10);
6133*5113495bSYour Name 	uint8_t curr_index = 0;
6134*5113495bSYour Name 	uint8_t i;
6135*5113495bSYour Name 	uint16_t size;
6136*5113495bSYour Name 
6137*5113495bSYour Name 	info.active_tasklet_count = qdf_atomic_read(&scn->active_tasklet_cnt);
6138*5113495bSYour Name 	info.active_grp_tasklet_cnt =
6139*5113495bSYour Name 				qdf_atomic_read(&scn->active_grp_tasklet_cnt);
6140*5113495bSYour Name 
6141*5113495bSYour Name 	for (i = 0; i < scn->ce_count; i++) {
6142*5113495bSYour Name 		if (!(tracked_ce & BIT(i)) || !scn->ce_id_to_state[i])
6143*5113495bSYour Name 			continue;
6144*5113495bSYour Name 
6145*5113495bSYour Name 		if (ce_get_index_info(scn, scn->ce_id_to_state[i],
6146*5113495bSYour Name 				      &info.ce_info[curr_index]))
6147*5113495bSYour Name 			continue;
6148*5113495bSYour Name 
6149*5113495bSYour Name 		curr_index++;
6150*5113495bSYour Name 	}
6151*5113495bSYour Name 
6152*5113495bSYour Name 	info.ce_count = curr_index;
6153*5113495bSYour Name 	size = sizeof(info) -
6154*5113495bSYour Name 		(CE_COUNT_MAX - info.ce_count) * sizeof(struct ce_index);
6155*5113495bSYour Name 
6156*5113495bSYour Name 	if (*offset + size > QDF_WLAN_HANG_FW_OFFSET)
6157*5113495bSYour Name 		return;
6158*5113495bSYour Name 
6159*5113495bSYour Name 	QDF_HANG_EVT_SET_HDR(&info.tlv_header, HANG_EVT_TAG_CE_INFO,
6160*5113495bSYour Name 			     size - QDF_HANG_EVENT_TLV_HDR_SIZE);
6161*5113495bSYour Name 
6162*5113495bSYour Name 	qdf_mem_copy(data + *offset, &info, size);
6163*5113495bSYour Name 	*offset = *offset + size;
6164*5113495bSYour Name }
6165*5113495bSYour Name #endif
6166*5113495bSYour Name 
6167*5113495bSYour Name #ifdef FEATURE_DIRECT_LINK
6168*5113495bSYour Name QDF_STATUS
hif_set_irq_config_by_ceid(struct hif_opaque_softc * scn,uint8_t ce_id,uint64_t addr,uint32_t data)6169*5113495bSYour Name hif_set_irq_config_by_ceid(struct hif_opaque_softc *scn, uint8_t ce_id,
6170*5113495bSYour Name 			   uint64_t addr, uint32_t data)
6171*5113495bSYour Name {
6172*5113495bSYour Name 	struct hif_softc *hif_ctx = HIF_GET_SOFTC(scn);
6173*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
6174*5113495bSYour Name 
6175*5113495bSYour Name 	if (hif_state->ce_services->ce_set_irq_config_by_ceid)
6176*5113495bSYour Name 		return hif_state->ce_services->ce_set_irq_config_by_ceid(
6177*5113495bSYour Name 									hif_ctx,
6178*5113495bSYour Name 									ce_id,
6179*5113495bSYour Name 									addr,
6180*5113495bSYour Name 									data);
6181*5113495bSYour Name 
6182*5113495bSYour Name 	return QDF_STATUS_E_NOSUPPORT;
6183*5113495bSYour Name }
6184*5113495bSYour Name 
hif_get_direct_link_ce_dest_srng_buffers(struct hif_opaque_softc * scn,uint64_t ** dma_addr,uint32_t * buf_size)6185*5113495bSYour Name uint16_t hif_get_direct_link_ce_dest_srng_buffers(struct hif_opaque_softc *scn,
6186*5113495bSYour Name 						  uint64_t **dma_addr,
6187*5113495bSYour Name 						  uint32_t *buf_size)
6188*5113495bSYour Name {
6189*5113495bSYour Name 	struct hif_softc *hif_ctx = HIF_GET_SOFTC(scn);
6190*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
6191*5113495bSYour Name 	struct ce_ops *ce_services = hif_state->ce_services;
6192*5113495bSYour Name 
6193*5113495bSYour Name 	if (ce_services->ce_get_direct_link_dest_buffers)
6194*5113495bSYour Name 		return ce_services->ce_get_direct_link_dest_buffers(hif_ctx,
6195*5113495bSYour Name 								    dma_addr,
6196*5113495bSYour Name 								    buf_size);
6197*5113495bSYour Name 
6198*5113495bSYour Name 	return 0;
6199*5113495bSYour Name }
6200*5113495bSYour Name 
6201*5113495bSYour Name QDF_STATUS
hif_get_direct_link_ce_srng_info(struct hif_opaque_softc * scn,struct hif_direct_link_ce_info * info,uint8_t max_ce_info_len)6202*5113495bSYour Name hif_get_direct_link_ce_srng_info(struct hif_opaque_softc *scn,
6203*5113495bSYour Name 				 struct hif_direct_link_ce_info *info,
6204*5113495bSYour Name 				 uint8_t max_ce_info_len)
6205*5113495bSYour Name {
6206*5113495bSYour Name 	struct hif_softc *hif_ctx = HIF_GET_SOFTC(scn);
6207*5113495bSYour Name 	struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
6208*5113495bSYour Name 	struct ce_ops *ce_services = hif_state->ce_services;
6209*5113495bSYour Name 
6210*5113495bSYour Name 	if (ce_services->ce_get_direct_link_ring_info)
6211*5113495bSYour Name 		return ce_services->ce_get_direct_link_ring_info(hif_ctx,
6212*5113495bSYour Name 							       info,
6213*5113495bSYour Name 							       max_ce_info_len);
6214*5113495bSYour Name 
6215*5113495bSYour Name 	return QDF_STATUS_E_NOSUPPORT;
6216*5113495bSYour Name }
6217*5113495bSYour Name #endif
6218