blob: 53c4ee0f0b247c7e76c4452594f7c3ad064b723c [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Pratik Gandhi034cb7c2017-11-10 16:46:06 +05302 * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080027#include "targcfg.h"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053028#include "qdf_lock.h"
29#include "qdf_status.h"
30#include "qdf_status.h"
31#include <qdf_atomic.h> /* qdf_atomic_read */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080032#include <targaddrs.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080033#include "hif_io32.h"
34#include <hif.h>
Pratik Gandhi034cb7c2017-11-10 16:46:06 +053035#include <target_type.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080036#include "regtable.h"
37#define ATH_MODULE_NAME hif
38#include <a_debug.h>
39#include "hif_main.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080040#include "ce_api.h"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053041#include "qdf_trace.h"
Yuanyuan Liufd594c22016-04-25 13:59:19 -070042#include "pld_common.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080043#include "hif_debug.h"
44#include "ce_internal.h"
45#include "ce_reg.h"
46#include "ce_assignment.h"
47#include "ce_tasklet.h"
Houston Hoffman56e0d702016-05-05 17:48:06 -070048#ifndef CONFIG_WIN
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080049#include "qwlan_version.h"
Houston Hoffman56e0d702016-05-05 17:48:06 -070050#endif
Pratik Gandhidc82a772018-01-30 18:57:05 +053051#include "qdf_module.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080052
53#define CE_POLL_TIMEOUT 10 /* ms */
54
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053055#define AGC_DUMP 1
56#define CHANINFO_DUMP 2
57#define BB_WATCHDOG_DUMP 3
58#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
59#define PCIE_ACCESS_DUMP 4
60#endif
61#include "mp_dev.h"
62
Houston Hoffman5141f9d2017-01-05 10:49:17 -080063#if (defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6290)) && \
64 !defined(QCA_WIFI_SUPPORT_SRNG)
65#define QCA_WIFI_SUPPORT_SRNG
66#endif
67
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080068/* Forward references */
Nachiket Kukadee5738b52017-09-07 17:16:12 +053069QDF_STATUS hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080070
71/*
72 * Fix EV118783, poll to check whether a BMI response comes
73 * other than waiting for the interruption which may be lost.
74 */
75/* #define BMI_RSP_POLLING */
76#define BMI_RSP_TO_MILLISEC 1000
77
Yuanyuan Liua7a282f2016-04-15 12:55:04 -070078#ifdef CONFIG_BYPASS_QMI
79#define BYPASS_QMI 1
80#else
81#define BYPASS_QMI 0
82#endif
83
Houston Hoffmanabd00772016-05-06 17:02:48 -070084#ifdef CONFIG_WIN
Pratik Gandhi424c62e2016-08-23 19:47:09 +053085#if ENABLE_10_4_FW_HDR
Houston Hoffmanabd00772016-05-06 17:02:48 -070086#define WDI_IPA_SERVICE_GROUP 5
87#define WDI_IPA_TX_SVC MAKE_SERVICE_ID(WDI_IPA_SERVICE_GROUP, 0)
88#define HTT_DATA2_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 1)
89#define HTT_DATA3_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 2)
Pratik Gandhi424c62e2016-08-23 19:47:09 +053090#endif /* ENABLE_10_4_FW_HDR */
Houston Hoffmanabd00772016-05-06 17:02:48 -070091#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080092
Nachiket Kukadee5738b52017-09-07 17:16:12 +053093QDF_STATUS hif_post_recv_buffers(struct hif_softc *scn);
Komal Seelam644263d2016-02-22 20:45:49 +053094static void hif_config_rri_on_ddr(struct hif_softc *scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080095
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053096/**
97 * hif_target_access_log_dump() - dump access log
98 *
99 * dump access log
100 *
101 * Return: n/a
102 */
103#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
104static void hif_target_access_log_dump(void)
105{
106 hif_target_dump_access_log();
107}
108#endif
109
110
111void hif_trigger_dump(struct hif_opaque_softc *hif_ctx,
112 uint8_t cmd_id, bool start)
113{
114 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
115
116 switch (cmd_id) {
117 case AGC_DUMP:
118 if (start)
119 priv_start_agc(scn);
120 else
121 priv_dump_agc(scn);
122 break;
123 case CHANINFO_DUMP:
124 if (start)
125 priv_start_cap_chaninfo(scn);
126 else
127 priv_dump_chaninfo(scn);
128 break;
129 case BB_WATCHDOG_DUMP:
130 priv_dump_bbwatchdog(scn);
131 break;
132#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
133 case PCIE_ACCESS_DUMP:
134 hif_target_access_log_dump();
135 break;
136#endif
137 default:
138 HIF_ERROR("%s: Invalid htc dump command", __func__);
139 break;
140 }
141}
142
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800143static void ce_poll_timeout(void *arg)
144{
145 struct CE_state *CE_state = (struct CE_state *)arg;
Manikandan Mohanafd6e882017-04-07 17:46:41 -0700146
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800147 if (CE_state->timer_inited) {
148 ce_per_engine_service(CE_state->scn, CE_state->id);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530149 qdf_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800150 }
151}
152
153static unsigned int roundup_pwr2(unsigned int n)
154{
155 int i;
156 unsigned int test_pwr2;
157
158 if (!(n & (n - 1)))
159 return n; /* already a power of 2 */
160
161 test_pwr2 = 4;
162 for (i = 0; i < 29; i++) {
163 if (test_pwr2 > n)
164 return test_pwr2;
165 test_pwr2 = test_pwr2 << 1;
166 }
167
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530168 QDF_ASSERT(0); /* n too large */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800169 return 0;
170}
171
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700172#define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C
173#define ADRASTEA_DST_WR_INDEX_OFFSET 0x40
174
175static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = {
176 { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
177 { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
178 { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
179 { 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
180 { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
181 { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
182 { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
183 { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
184 { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
Houston Hoffmane6330442016-02-26 12:19:11 -0800185#ifdef QCA_WIFI_3_0_ADRASTEA
186 { 9, ADRASTEA_DST_WR_INDEX_OFFSET},
187 { 10, ADRASTEA_DST_WR_INDEX_OFFSET},
Nirav Shah75cc5c82016-05-25 10:52:38 +0530188 { 11, ADRASTEA_DST_WR_INDEX_OFFSET},
Houston Hoffmane6330442016-02-26 12:19:11 -0800189#endif
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700190};
191
Nirav Shah0d0cce82018-01-17 17:00:31 +0530192#ifdef WLAN_FEATURE_EPPING
Vishwajith Upendra70efc752016-04-18 11:23:49 -0700193static struct shadow_reg_cfg target_shadow_reg_cfg_epping[] = {
194 { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
195 { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
196 { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
197 { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
198 { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
199 { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
200 { 5, ADRASTEA_DST_WR_INDEX_OFFSET},
201 { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
202 { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
203};
Nirav Shah0d0cce82018-01-17 17:00:31 +0530204#endif
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700205
206/* CE_PCI TABLE */
207/*
208 * NOTE: the table below is out of date, though still a useful reference.
209 * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual
210 * mapping of HTC services to HIF pipes.
211 */
212/*
213 * This authoritative table defines Copy Engine configuration and the mapping
214 * of services/endpoints to CEs. A subset of this information is passed to
215 * the Target during startup as a prerequisite to entering BMI phase.
216 * See:
217 * target_service_to_ce_map - Target-side mapping
218 * hif_map_service_to_pipe - Host-side mapping
219 * target_ce_config - Target-side configuration
220 * host_ce_config - Host-side configuration
221 ============================================================================
222 Purpose | Service / Endpoint | CE | Dire | Xfer | Xfer
223 | | | ctio | Size | Frequency
224 | | | n | |
225 ============================================================================
226 tx | HTT_DATA (downlink) | CE 0 | h->t | medium - | very frequent
227 descriptor | | | | O(100B) | and regular
228 download | | | | |
229 ----------------------------------------------------------------------------
230 rx | HTT_DATA (uplink) | CE 1 | t->h | small - | frequent and
231 indication | | | | O(10B) | regular
232 upload | | | | |
233 ----------------------------------------------------------------------------
234 MSDU | DATA_BK (uplink) | CE 2 | t->h | large - | rare
235 upload | | | | O(1000B) | (frequent
236 e.g. noise | | | | | during IP1.0
237 packets | | | | | testing)
238 ----------------------------------------------------------------------------
239 MSDU | DATA_BK (downlink) | CE 3 | h->t | large - | very rare
240 download | | | | O(1000B) | (frequent
241 e.g. | | | | | during IP1.0
242 misdirecte | | | | | testing)
243 d EAPOL | | | | |
244 packets | | | | |
245 ----------------------------------------------------------------------------
246 n/a | DATA_BE, DATA_VI | CE 2 | t->h | | never(?)
247 | DATA_VO (uplink) | | | |
248 ----------------------------------------------------------------------------
249 n/a | DATA_BE, DATA_VI | CE 3 | h->t | | never(?)
250 | DATA_VO (downlink) | | | |
251 ----------------------------------------------------------------------------
252 WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent
253 | | | | O(100B) |
254 ----------------------------------------------------------------------------
255 WMI | WMI_CONTROL | CE 5 | h->t | medium - | infrequent
256 messages | (downlink) | | | O(100B) |
257 | | | | |
258 ----------------------------------------------------------------------------
259 n/a | HTC_CTRL_RSVD, | CE 1 | t->h | | never(?)
260 | HTC_RAW_STREAMS | | | |
261 | (uplink) | | | |
262 ----------------------------------------------------------------------------
263 n/a | HTC_CTRL_RSVD, | CE 0 | h->t | | never(?)
264 | HTC_RAW_STREAMS | | | |
265 | (downlink) | | | |
266 ----------------------------------------------------------------------------
267 diag | none (raw CE) | CE 7 | t<>h | 4 | Diag Window
268 | | | | | infrequent
269 ============================================================================
270 */
271
272/*
273 * Map from service/endpoint to Copy Engine.
274 * This table is derived from the CE_PCI TABLE, above.
275 * It is passed to the Target at startup for use by firmware.
276 */
277static struct service_to_pipe target_service_to_ce_map_wlan[] = {
278 {
279 WMI_DATA_VO_SVC,
280 PIPEDIR_OUT, /* out = UL = host -> target */
281 3,
282 },
283 {
284 WMI_DATA_VO_SVC,
285 PIPEDIR_IN, /* in = DL = target -> host */
286 2,
287 },
288 {
289 WMI_DATA_BK_SVC,
290 PIPEDIR_OUT, /* out = UL = host -> target */
291 3,
292 },
293 {
294 WMI_DATA_BK_SVC,
295 PIPEDIR_IN, /* in = DL = target -> host */
296 2,
297 },
298 {
299 WMI_DATA_BE_SVC,
300 PIPEDIR_OUT, /* out = UL = host -> target */
301 3,
302 },
303 {
304 WMI_DATA_BE_SVC,
305 PIPEDIR_IN, /* in = DL = target -> host */
306 2,
307 },
308 {
309 WMI_DATA_VI_SVC,
310 PIPEDIR_OUT, /* out = UL = host -> target */
311 3,
312 },
313 {
314 WMI_DATA_VI_SVC,
315 PIPEDIR_IN, /* in = DL = target -> host */
316 2,
317 },
318 {
319 WMI_CONTROL_SVC,
320 PIPEDIR_OUT, /* out = UL = host -> target */
321 3,
322 },
323 {
324 WMI_CONTROL_SVC,
325 PIPEDIR_IN, /* in = DL = target -> host */
326 2,
327 },
328 {
329 HTC_CTRL_RSVD_SVC,
330 PIPEDIR_OUT, /* out = UL = host -> target */
331 0, /* could be moved to 3 (share with WMI) */
332 },
333 {
334 HTC_CTRL_RSVD_SVC,
335 PIPEDIR_IN, /* in = DL = target -> host */
336 2,
337 },
338 {
339 HTC_RAW_STREAMS_SVC, /* not currently used */
340 PIPEDIR_OUT, /* out = UL = host -> target */
341 0,
342 },
343 {
344 HTC_RAW_STREAMS_SVC, /* not currently used */
345 PIPEDIR_IN, /* in = DL = target -> host */
346 2,
347 },
348 {
349 HTT_DATA_MSG_SVC,
350 PIPEDIR_OUT, /* out = UL = host -> target */
351 4,
352 },
353 {
354 HTT_DATA_MSG_SVC,
355 PIPEDIR_IN, /* in = DL = target -> host */
356 1,
357 },
358 {
359 WDI_IPA_TX_SVC,
360 PIPEDIR_OUT, /* in = DL = target -> host */
361 5,
362 },
Houston Hoffmane6330442016-02-26 12:19:11 -0800363#if defined(QCA_WIFI_3_0_ADRASTEA)
364 {
365 HTT_DATA2_MSG_SVC,
366 PIPEDIR_IN, /* in = DL = target -> host */
367 9,
368 },
369 {
370 HTT_DATA3_MSG_SVC,
371 PIPEDIR_IN, /* in = DL = target -> host */
372 10,
373 },
Nirav Shah75cc5c82016-05-25 10:52:38 +0530374 {
375 PACKET_LOG_SVC,
376 PIPEDIR_IN, /* in = DL = target -> host */
377 11,
378 },
Houston Hoffmane6330442016-02-26 12:19:11 -0800379#endif
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700380 /* (Additions here) */
381
382 { /* Must be last */
383 0,
384 0,
385 0,
386 },
387};
388
Houston Hoffman88c896f2016-12-14 09:56:35 -0800389/* PIPEDIR_OUT = HOST to Target */
390/* PIPEDIR_IN = TARGET to HOST */
Balamurugan Mahalingam20802b22017-05-02 19:11:38 +0530391static struct service_to_pipe target_service_to_ce_map_qca8074[] = {
392 { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
393 { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
394 { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
395 { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
396 { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
397 { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
398 { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
399 { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
400 { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
401 { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
402 { WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
403 { WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
404 { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
405 { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 1, },
406 { HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0},
407 { HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 1 },
408 { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
409 { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
Balamurugan Mahalingamdcb52262017-08-16 19:16:45 +0530410 { PACKET_LOG_SVC, PIPEDIR_IN, 5, },
Balamurugan Mahalingam20802b22017-05-02 19:11:38 +0530411 /* (Additions here) */
412 { 0, 0, 0, },
413};
414
Nandha Kishore Easwaran51f80b82018-02-21 12:04:34 +0530415#ifdef CONFIG_WIN
Houston Hoffman88c896f2016-12-14 09:56:35 -0800416static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
417 { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
418 { WMI_DATA_VO_SVC, PIPEDIR_IN , 2, },
419 { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
420 { WMI_DATA_BK_SVC, PIPEDIR_IN , 2, },
421 { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
422 { WMI_DATA_BE_SVC, PIPEDIR_IN , 2, },
423 { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
424 { WMI_DATA_VI_SVC, PIPEDIR_IN , 2, },
425 { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
426 { WMI_CONTROL_SVC, PIPEDIR_IN , 2, },
427 { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
428 { HTC_CTRL_RSVD_SVC, PIPEDIR_IN , 2, },
429 { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
430 { HTT_DATA_MSG_SVC, PIPEDIR_IN , 1, },
Nandha Kishore Easwaran51f80b82018-02-21 12:04:34 +0530431 { WMI_CONTROL_SVC_WMAC1, PIPEDIR_OUT, 7},
432 { WMI_CONTROL_SVC_WMAC1, PIPEDIR_IN, 2},
Houston Hoffman88c896f2016-12-14 09:56:35 -0800433 /* (Additions here) */
434 { 0, 0, 0, },
435};
Nandha Kishore Easwaran51f80b82018-02-21 12:04:34 +0530436#else
437static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
438 { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
439 { WMI_DATA_VO_SVC, PIPEDIR_IN, 2, },
440 { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
441 { WMI_DATA_BK_SVC, PIPEDIR_IN, 2, },
442 { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
443 { WMI_DATA_BE_SVC, PIPEDIR_IN, 2, },
444 { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
445 { WMI_DATA_VI_SVC, PIPEDIR_IN, 2, },
446 { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
447 { WMI_CONTROL_SVC, PIPEDIR_IN, 2, },
448 { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
449 { HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2, },
450 { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
451 { HTT_DATA_MSG_SVC, PIPEDIR_IN, 1, },
452 /* (Additions here) */
453 { 0, 0, 0, },
454};
455#endif
Houston Hoffman88c896f2016-12-14 09:56:35 -0800456
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700457static struct service_to_pipe target_service_to_ce_map_ar900b[] = {
458 {
459 WMI_DATA_VO_SVC,
460 PIPEDIR_OUT, /* out = UL = host -> target */
461 3,
462 },
463 {
464 WMI_DATA_VO_SVC,
465 PIPEDIR_IN, /* in = DL = target -> host */
466 2,
467 },
468 {
469 WMI_DATA_BK_SVC,
470 PIPEDIR_OUT, /* out = UL = host -> target */
471 3,
472 },
473 {
474 WMI_DATA_BK_SVC,
475 PIPEDIR_IN, /* in = DL = target -> host */
476 2,
477 },
478 {
479 WMI_DATA_BE_SVC,
480 PIPEDIR_OUT, /* out = UL = host -> target */
481 3,
482 },
483 {
484 WMI_DATA_BE_SVC,
485 PIPEDIR_IN, /* in = DL = target -> host */
486 2,
487 },
488 {
489 WMI_DATA_VI_SVC,
490 PIPEDIR_OUT, /* out = UL = host -> target */
491 3,
492 },
493 {
494 WMI_DATA_VI_SVC,
495 PIPEDIR_IN, /* in = DL = target -> host */
496 2,
497 },
498 {
499 WMI_CONTROL_SVC,
500 PIPEDIR_OUT, /* out = UL = host -> target */
501 3,
502 },
503 {
504 WMI_CONTROL_SVC,
505 PIPEDIR_IN, /* in = DL = target -> host */
506 2,
507 },
508 {
509 HTC_CTRL_RSVD_SVC,
510 PIPEDIR_OUT, /* out = UL = host -> target */
511 0, /* could be moved to 3 (share with WMI) */
512 },
513 {
514 HTC_CTRL_RSVD_SVC,
515 PIPEDIR_IN, /* in = DL = target -> host */
516 1,
517 },
518 {
519 HTC_RAW_STREAMS_SVC, /* not currently used */
520 PIPEDIR_OUT, /* out = UL = host -> target */
521 0,
522 },
523 {
524 HTC_RAW_STREAMS_SVC, /* not currently used */
525 PIPEDIR_IN, /* in = DL = target -> host */
526 1,
527 },
528 {
529 HTT_DATA_MSG_SVC,
530 PIPEDIR_OUT, /* out = UL = host -> target */
531 4,
532 },
533#if WLAN_FEATURE_FASTPATH
534 {
535 HTT_DATA_MSG_SVC,
536 PIPEDIR_IN, /* in = DL = target -> host */
537 5,
538 },
539#else /* WLAN_FEATURE_FASTPATH */
540 {
541 HTT_DATA_MSG_SVC,
542 PIPEDIR_IN, /* in = DL = target -> host */
543 1,
544 },
545#endif /* WLAN_FEATURE_FASTPATH */
546
547 /* (Additions here) */
548
549 { /* Must be last */
550 0,
551 0,
552 0,
553 },
554};
555
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700556static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
557static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
558
Nirav Shah0d0cce82018-01-17 17:00:31 +0530559#ifdef WLAN_FEATURE_EPPING
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700560static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
561 {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
562 {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
563 {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
564 {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
565 {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
566 {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
567 {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
568 {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
569 {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
570 {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
571 {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
572 {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
573 {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
574 {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
575 {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
576 {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
577 {0, 0, 0,}, /* Must be last */
578};
579
Nirav Shah0d0cce82018-01-17 17:00:31 +0530580void hif_select_epping_service_to_pipe_map(struct service_to_pipe
581 **tgt_svc_map_to_use,
582 uint32_t *sz_tgt_svc_map_to_use)
583{
584 *tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
585 *sz_tgt_svc_map_to_use =
586 sizeof(target_service_to_ce_map_wlan_epping);
587}
588#endif
589
Houston Hoffman748e1a62017-03-30 17:20:42 -0700590static void hif_select_service_to_pipe_map(struct hif_softc *scn,
591 struct service_to_pipe **tgt_svc_map_to_use,
592 uint32_t *sz_tgt_svc_map_to_use)
593{
594 uint32_t mode = hif_get_conparam(scn);
595 struct hif_target_info *tgt_info = &scn->target_info;
596
597 if (QDF_IS_EPPING_ENABLED(mode)) {
Nirav Shah0d0cce82018-01-17 17:00:31 +0530598 hif_select_epping_service_to_pipe_map(tgt_svc_map_to_use,
599 sz_tgt_svc_map_to_use);
Houston Hoffman748e1a62017-03-30 17:20:42 -0700600 } else {
601 switch (tgt_info->target_type) {
602 default:
603 *tgt_svc_map_to_use = target_service_to_ce_map_wlan;
604 *sz_tgt_svc_map_to_use =
605 sizeof(target_service_to_ce_map_wlan);
606 break;
607 case TARGET_TYPE_AR900B:
608 case TARGET_TYPE_QCA9984:
609 case TARGET_TYPE_IPQ4019:
610 case TARGET_TYPE_QCA9888:
611 case TARGET_TYPE_AR9888:
612 case TARGET_TYPE_AR9888V2:
613 *tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
614 *sz_tgt_svc_map_to_use =
615 sizeof(target_service_to_ce_map_ar900b);
616 break;
617 case TARGET_TYPE_QCA6290:
618 *tgt_svc_map_to_use = target_service_to_ce_map_qca6290;
619 *sz_tgt_svc_map_to_use =
620 sizeof(target_service_to_ce_map_qca6290);
621 break;
Balamurugan Mahalingam20802b22017-05-02 19:11:38 +0530622 case TARGET_TYPE_QCA8074:
623 *tgt_svc_map_to_use = target_service_to_ce_map_qca8074;
624 *sz_tgt_svc_map_to_use =
625 sizeof(target_service_to_ce_map_qca8074);
626 break;
Houston Hoffman748e1a62017-03-30 17:20:42 -0700627 }
628 }
629}
630
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700631/**
632 * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly
633 * @ce_state : pointer to the state context of the CE
634 *
635 * Description:
636 * Sets htt_rx_data attribute of the state structure if the
637 * CE serves one of the HTT DATA services.
638 *
639 * Return:
640 * false (attribute set to false)
641 * true (attribute set to true);
642 */
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700643static bool ce_mark_datapath(struct CE_state *ce_state)
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700644{
645 struct service_to_pipe *svc_map;
Kiran Venkatappac0687092017-04-13 16:45:03 +0530646 uint32_t map_sz, map_len;
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700647 int i;
648 bool rc = false;
649
650 if (ce_state != NULL) {
Houston Hoffman748e1a62017-03-30 17:20:42 -0700651 hif_select_service_to_pipe_map(ce_state->scn, &svc_map,
652 &map_sz);
Houston Hoffman55fcf5a2016-09-27 23:21:51 -0700653
Kiran Venkatappac0687092017-04-13 16:45:03 +0530654 map_len = map_sz / sizeof(struct service_to_pipe);
655 for (i = 0; i < map_len; i++) {
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700656 if ((svc_map[i].pipenum == ce_state->id) &&
657 ((svc_map[i].service_id == HTT_DATA_MSG_SVC) ||
658 (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
659 (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) {
660 /* HTT CEs are unidirectional */
661 if (svc_map[i].pipedir == PIPEDIR_IN)
662 ce_state->htt_rx_data = true;
663 else
664 ce_state->htt_tx_data = true;
665 rc = true;
666 }
667 }
668 }
669 return rc;
670}
671
Houston Hoffman47808172016-05-06 10:04:21 -0700672/**
673 * ce_ring_test_initial_indexes() - tests the initial ce ring indexes
674 * @ce_id: ce in question
675 * @ring: ring state being examined
676 * @type: "src_ring" or "dest_ring" string for identifying the ring
677 *
678 * Warns on non-zero index values.
679 * Causes a kernel panic if the ring is not empty durring initialization.
680 */
681static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring,
682 char *type)
683{
684 if (ring->write_index != 0 || ring->sw_index != 0)
685 HIF_ERROR("ce %d, %s, initial sw_index = %d, initial write_index =%d",
686 ce_id, type, ring->sw_index, ring->write_index);
687 if (ring->write_index != ring->sw_index)
688 QDF_BUG(0);
689}
690
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530691/**
692 * ce_srng_based() - Does this target use srng
693 * @ce_state : pointer to the state context of the CE
694 *
695 * Description:
696 * returns true if the target is SRNG based
697 *
698 * Return:
699 * false (attribute set to false)
700 * true (attribute set to true);
701 */
702bool ce_srng_based(struct hif_softc *scn)
703{
704 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
705 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
706
707 switch (tgt_info->target_type) {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530708 case TARGET_TYPE_QCA8074:
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700709 case TARGET_TYPE_QCA6290:
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530710 return true;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530711 default:
712 return false;
713 }
714 return false;
715}
Pratik Gandhidc82a772018-01-30 18:57:05 +0530716qdf_export_symbol(ce_srng_based);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530717
Houston Hoffman5141f9d2017-01-05 10:49:17 -0800718#ifdef QCA_WIFI_SUPPORT_SRNG
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700719static struct ce_ops *ce_services_attach(struct hif_softc *scn)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530720{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530721 if (ce_srng_based(scn))
722 return ce_services_srng();
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530723
724 return ce_services_legacy();
725}
Houston Hoffman5141f9d2017-01-05 10:49:17 -0800726
Houston Hoffman5141f9d2017-01-05 10:49:17 -0800727
Venkata Sharath Chandra Manchala837d3232017-01-18 15:11:56 -0800728#else /* QCA_LITHIUM */
729static struct ce_ops *ce_services_attach(struct hif_softc *scn)
730{
731 return ce_services_legacy();
732}
733#endif /* QCA_LITHIUM */
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530734
Houston Hoffman403c2df2017-01-27 12:51:15 -0800735static void hif_prepare_hal_shadow_register_cfg(struct hif_softc *scn,
Houston Hoffman10fedfc2017-01-23 15:23:09 -0800736 struct pld_shadow_reg_v2_cfg **shadow_config,
737 int *num_shadow_registers_configured) {
738 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
739
740 return hif_state->ce_services->ce_prepare_shadow_register_v2_cfg(
741 scn, shadow_config, num_shadow_registers_configured);
742}
743
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530744static inline uint32_t ce_get_desc_size(struct hif_softc *scn,
745 uint8_t ring_type)
746{
747 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
748
749 return hif_state->ce_services->ce_get_desc_size(ring_type);
750}
751
752
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700753static struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530754 uint8_t ring_type, uint32_t nentries)
755{
756 uint32_t ce_nbytes;
757 char *ptr;
758 qdf_dma_addr_t base_addr;
759 struct CE_ring_state *ce_ring;
760 uint32_t desc_size;
761 struct hif_softc *scn = CE_state->scn;
762
763 ce_nbytes = sizeof(struct CE_ring_state)
764 + (nentries * sizeof(void *));
765 ptr = qdf_mem_malloc(ce_nbytes);
766 if (!ptr)
767 return NULL;
768
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530769 ce_ring = (struct CE_ring_state *)ptr;
770 ptr += sizeof(struct CE_ring_state);
771 ce_ring->nentries = nentries;
772 ce_ring->nentries_mask = nentries - 1;
773
774 ce_ring->low_water_mark_nentries = 0;
775 ce_ring->high_water_mark_nentries = nentries;
776 ce_ring->per_transfer_context = (void **)ptr;
777
778 desc_size = ce_get_desc_size(scn, ring_type);
779
780 /* Legacy platforms that do not support cache
781 * coherent DMA are unsupported
782 */
783 ce_ring->base_addr_owner_space_unaligned =
784 qdf_mem_alloc_consistent(scn->qdf_dev,
785 scn->qdf_dev->dev,
786 (nentries *
787 desc_size +
788 CE_DESC_RING_ALIGN),
789 &base_addr);
790 if (ce_ring->base_addr_owner_space_unaligned
791 == NULL) {
792 HIF_ERROR("%s: ring has no DMA mem",
793 __func__);
794 qdf_mem_free(ptr);
795 return NULL;
796 }
797 ce_ring->base_addr_CE_space_unaligned = base_addr;
798
799 /* Correctly initialize memory to 0 to
800 * prevent garbage data crashing system
801 * when download firmware
802 */
803 qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned,
804 nentries * desc_size +
805 CE_DESC_RING_ALIGN);
806
807 if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) {
808
809 ce_ring->base_addr_CE_space =
810 (ce_ring->base_addr_CE_space_unaligned +
811 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1);
812
813 ce_ring->base_addr_owner_space = (void *)
814 (((size_t) ce_ring->base_addr_owner_space_unaligned +
815 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1));
816 } else {
817 ce_ring->base_addr_CE_space =
818 ce_ring->base_addr_CE_space_unaligned;
819 ce_ring->base_addr_owner_space =
820 ce_ring->base_addr_owner_space_unaligned;
821 }
822
823 return ce_ring;
824}
825
Yun Park3fb36442017-08-17 17:37:53 -0700826static int ce_ring_setup(struct hif_softc *scn, uint8_t ring_type,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530827 uint32_t ce_id, struct CE_ring_state *ring,
828 struct CE_attr *attr)
829{
830 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
831
Yun Park3fb36442017-08-17 17:37:53 -0700832 return hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id,
Manikandan Mohanafd6e882017-04-07 17:46:41 -0700833 ring, attr);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530834}
835
Houston Hoffmancbcd8392017-02-08 17:43:13 -0800836int hif_ce_bus_early_suspend(struct hif_softc *scn)
837{
838 uint8_t ul_pipe, dl_pipe;
839 int ce_id, status, ul_is_polled, dl_is_polled;
840 struct CE_state *ce_state;
Manikandan Mohanafd6e882017-04-07 17:46:41 -0700841
Houston Hoffmancbcd8392017-02-08 17:43:13 -0800842 status = hif_map_service_to_pipe(&scn->osc, WMI_CONTROL_SVC,
843 &ul_pipe, &dl_pipe,
844 &ul_is_polled, &dl_is_polled);
845 if (status) {
846 HIF_ERROR("%s: pipe_mapping failure", __func__);
847 return status;
848 }
849
850 for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
851 if (ce_id == ul_pipe)
852 continue;
853 if (ce_id == dl_pipe)
854 continue;
855
856 ce_state = scn->ce_id_to_state[ce_id];
857 qdf_spin_lock_bh(&ce_state->ce_index_lock);
858 if (ce_state->state == CE_RUNNING)
859 ce_state->state = CE_PAUSED;
860 qdf_spin_unlock_bh(&ce_state->ce_index_lock);
861 }
862
863 return status;
864}
865
866int hif_ce_bus_late_resume(struct hif_softc *scn)
867{
868 int ce_id;
869 struct CE_state *ce_state;
870 int write_index;
871 bool index_updated;
872
873 for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
874 ce_state = scn->ce_id_to_state[ce_id];
875 qdf_spin_lock_bh(&ce_state->ce_index_lock);
876 if (ce_state->state == CE_PENDING) {
877 write_index = ce_state->src_ring->write_index;
878 CE_SRC_RING_WRITE_IDX_SET(scn, ce_state->ctrl_addr,
879 write_index);
880 ce_state->state = CE_RUNNING;
881 index_updated = true;
882 } else {
883 index_updated = false;
884 }
885
886 if (ce_state->state == CE_PAUSED)
887 ce_state->state = CE_RUNNING;
888 qdf_spin_unlock_bh(&ce_state->ce_index_lock);
889
890 if (index_updated)
891 hif_record_ce_desc_event(scn, ce_id,
892 RESUME_WRITE_INDEX_UPDATE,
c_cgodavfda96ad2017-09-07 16:16:00 +0530893 NULL, NULL, write_index, 0);
Houston Hoffmancbcd8392017-02-08 17:43:13 -0800894 }
895
896 return 0;
897}
898
Houston Hoffmanb12ccb72017-03-01 20:02:28 -0800899/**
900 * ce_oom_recovery() - try to recover rx ce from oom condition
901 * @context: CE_state of the CE with oom rx ring
902 *
903 * the executing work Will continue to be rescheduled untill
904 * at least 1 descriptor is successfully posted to the rx ring.
905 *
906 * return: none
907 */
908static void ce_oom_recovery(void *context)
909{
910 struct CE_state *ce_state = context;
911 struct hif_softc *scn = ce_state->scn;
912 struct HIF_CE_state *ce_softc = HIF_GET_CE_STATE(scn);
913 struct HIF_CE_pipe_info *pipe_info =
914 &ce_softc->pipe_info[ce_state->id];
915
916 hif_post_recv_buffers_for_pipe(pipe_info);
917}
918
c_cgodavfda96ad2017-09-07 16:16:00 +0530919#if HIF_CE_DEBUG_DATA_BUF
920/**
921 * alloc_mem_ce_debug_hist_data() - Allocate mem for the data pointed by
922 * the CE descriptors.
923 * Allocate HIF_CE_HISTORY_MAX records by CE_DEBUG_MAX_DATA_BUF_SIZE
924 * @scn: hif scn handle
925 * ce_id: Copy Engine Id
926 *
927 * Return: QDF_STATUS
928 */
929QDF_STATUS alloc_mem_ce_debug_hist_data(struct hif_softc *scn, uint32_t ce_id)
930{
931 struct hif_ce_desc_event *event = NULL;
932 struct hif_ce_desc_event *hist_ev = NULL;
933 uint32_t index = 0;
934
935 hist_ev =
936 (struct hif_ce_desc_event *)scn->hif_ce_desc_hist.hist_ev[ce_id];
937
938 if (!hist_ev)
939 return QDF_STATUS_E_NOMEM;
940
941 for (index = 0; index < HIF_CE_HISTORY_MAX; index++) {
942 event = &hist_ev[index];
943 event->data =
944 (uint8_t *)qdf_mem_malloc(CE_DEBUG_MAX_DATA_BUF_SIZE);
945 if (event->data == NULL)
946 return QDF_STATUS_E_NOMEM;
947 }
948 return QDF_STATUS_SUCCESS;
949}
950
951/**
952 * free_mem_ce_debug_hist_data() - Free mem of the data pointed by
953 * the CE descriptors.
954 * @scn: hif scn handle
955 * ce_id: Copy Engine Id
956 *
957 * Return:
958 */
959void free_mem_ce_debug_hist_data(struct hif_softc *scn, uint32_t ce_id)
960{
961 struct hif_ce_desc_event *event = NULL;
962 struct hif_ce_desc_event *hist_ev = NULL;
963 uint32_t index = 0;
964
965 hist_ev =
966 (struct hif_ce_desc_event *)scn->hif_ce_desc_hist.hist_ev[ce_id];
967
968 if (!hist_ev)
969 return;
970
971 for (index = 0; index < HIF_CE_HISTORY_MAX; index++) {
972 event = &hist_ev[index];
973 if (event->data != NULL)
974 qdf_mem_free(event->data);
975 event->data = NULL;
976 event = NULL;
977 }
978}
979#endif /* HIF_CE_DEBUG_DATA_BUF */
980
981/*
982 * Note: For MCL, #if defined (HIF_CONFIG_SLUB_DEBUG_ON) needs to be checked
983 * for defined here
984 */
985#if HIF_CE_DEBUG_DATA_BUF
986/**
987 * alloc_mem_ce_debug_history() - Allocate mem for the CE descriptors storing
988 * @scn: hif scn handle
989 * ce_id: Copy Engine Id
990 *
991 * Return: QDF_STATUS
992 */
993static inline QDF_STATUS alloc_mem_ce_debug_history(struct hif_softc *scn,
994 unsigned int CE_id)
995{
996 scn->hif_ce_desc_hist.hist_ev[CE_id] = (struct hif_ce_desc_event *)
997 qdf_mem_malloc(HIF_CE_HISTORY_MAX * sizeof(struct hif_ce_desc_event));
998
999 if (scn->hif_ce_desc_hist.hist_ev[CE_id] == NULL) {
1000 scn->hif_ce_desc_hist.enable[CE_id] = 0;
1001 return QDF_STATUS_E_NOMEM;
1002 } else {
1003 scn->hif_ce_desc_hist.enable[CE_id] = 1;
1004 return QDF_STATUS_SUCCESS;
1005 }
1006}
1007
1008/**
1009 * free_mem_ce_debug_history() - Free mem allocated for the CE descriptors
1010 * storing.
1011 * @scn: hif scn handle
1012 * ce_id: Copy Engine Id
1013 *
1014 * Return:
1015 */
1016static inline void free_mem_ce_debug_history(struct hif_softc *scn,
1017 unsigned int CE_id)
1018{
1019 struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
1020 struct hif_ce_desc_event *hist_ev =
1021 (struct hif_ce_desc_event *)ce_hist->hist_ev[CE_id];
1022
1023 if (!hist_ev)
1024 return;
1025
1026#if HIF_CE_DEBUG_DATA_BUF
1027 if (ce_hist->data_enable[CE_id] == 1) {
1028 ce_hist->data_enable[CE_id] = 0;
1029 free_mem_ce_debug_hist_data(scn, CE_id);
1030 }
1031#endif
1032 ce_hist->enable[CE_id] = 0;
1033 qdf_mem_free(ce_hist->hist_ev[CE_id]);
1034 ce_hist->hist_ev[CE_id] = NULL;
1035}
1036
1037/**
1038 * reset_ce_debug_history() - reset the index and ce id used for dumping the
1039 * CE records on the console using sysfs.
1040 * @scn: hif scn handle
1041 *
1042 * Return:
1043 */
1044static inline void reset_ce_debug_history(struct hif_softc *scn)
1045{
1046 struct ce_desc_hist *ce_hist = &scn->hif_ce_desc_hist;
1047 /* Initialise the CE debug history sysfs interface inputs ce_id and
1048 * index. Disable data storing
1049 */
1050 ce_hist->hist_index = 0;
1051 ce_hist->hist_id = 0;
1052}
1053#else /*Note: #if defined(HIF_CONFIG_SLUB_DEBUG_ON) || HIF_CE_DEBUG_DATA_BUF */
1054static inline QDF_STATUS alloc_mem_ce_debug_history(struct hif_softc *scn,
1055 unsigned int CE_id)
1056{
1057 return QDF_STATUS_SUCCESS;
1058}
1059
1060static inline void free_mem_ce_debug_history(struct hif_softc *scn,
1061 unsigned int CE_id)
1062{
1063}
1064
1065static inline void reset_ce_debug_history(struct hif_softc *scn)
1066{
1067}
1068#endif /*Note: defined(HIF_CONFIG_SLUB_DEBUG_ON) || HIF_CE_DEBUG_DATA_BUF */
1069
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001070/*
1071 * Initialize a Copy Engine based on caller-supplied attributes.
1072 * This may be called once to initialize both source and destination
1073 * rings or it may be called twice for separate source and destination
1074 * initialization. It may be that only one side or the other is
1075 * initialized by software/firmware.
Houston Hoffman233e9092015-09-02 13:37:21 -07001076 *
1077 * This should be called durring the initialization sequence before
1078 * interupts are enabled, so we don't have to worry about thread safety.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001079 */
Komal Seelam644263d2016-02-22 20:45:49 +05301080struct CE_handle *ce_init(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001081 unsigned int CE_id, struct CE_attr *attr)
1082{
1083 struct CE_state *CE_state;
1084 uint32_t ctrl_addr;
1085 unsigned int nentries;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001086 bool malloc_CE_state = false;
1087 bool malloc_src_ring = false;
Yun Park3fb36442017-08-17 17:37:53 -07001088 int status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001089
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301090 QDF_ASSERT(CE_id < scn->ce_count);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001091 ctrl_addr = CE_BASE_ADDRESS(CE_id);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001092 CE_state = scn->ce_id_to_state[CE_id];
1093
1094 if (!CE_state) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001095 CE_state =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301096 (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001097 if (!CE_state) {
1098 HIF_ERROR("%s: CE_state has no mem", __func__);
1099 return NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001100 }
Houston Hoffman233e9092015-09-02 13:37:21 -07001101 malloc_CE_state = true;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301102 qdf_spinlock_create(&CE_state->ce_index_lock);
Houston Hoffman233e9092015-09-02 13:37:21 -07001103
1104 CE_state->id = CE_id;
1105 CE_state->ctrl_addr = ctrl_addr;
1106 CE_state->state = CE_RUNNING;
1107 CE_state->attr_flags = attr->flags;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001108 }
1109 CE_state->scn = scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001110
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301111 qdf_atomic_init(&CE_state->rx_pending);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001112 if (attr == NULL) {
1113 /* Already initialized; caller wants the handle */
1114 return (struct CE_handle *)CE_state;
1115 }
1116
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001117 if (CE_state->src_sz_max)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301118 QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001119 else
1120 CE_state->src_sz_max = attr->src_sz_max;
1121
c_cgodavfda96ad2017-09-07 16:16:00 +05301122 ce_init_ce_desc_event_log(scn, CE_id,
1123 attr->src_nentries + attr->dest_nentries);
Houston Hoffman68e837e2015-12-04 12:57:24 -08001124
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001125 /* source ring setup */
1126 nentries = attr->src_nentries;
1127 if (nentries) {
1128 struct CE_ring_state *src_ring;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001129
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001130 nentries = roundup_pwr2(nentries);
1131 if (CE_state->src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301132 QDF_ASSERT(CE_state->src_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001133 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301134 src_ring = CE_state->src_ring =
1135 ce_alloc_ring_state(CE_state,
1136 CE_RING_SRC,
1137 nentries);
1138 if (!src_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001139 /* cannot allocate src ring. If the
1140 * CE_state is allocated locally free
1141 * CE_State and return error.
1142 */
1143 HIF_ERROR("%s: src ring has no mem", __func__);
1144 if (malloc_CE_state) {
1145 /* allocated CE_state locally */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301146 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001147 malloc_CE_state = false;
1148 }
1149 return NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001150 }
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001151 /* we can allocate src ring. Mark that the src ring is
1152 * allocated locally
1153 */
1154 malloc_src_ring = true;
1155
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001156 /*
1157 * Also allocate a shadow src ring in
1158 * regular mem to use for faster access.
1159 */
1160 src_ring->shadow_base_unaligned =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301161 qdf_mem_malloc(nentries *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001162 sizeof(struct CE_src_desc) +
1163 CE_DESC_RING_ALIGN);
1164 if (src_ring->shadow_base_unaligned == NULL) {
1165 HIF_ERROR("%s: src ring no shadow_base mem",
1166 __func__);
1167 goto error_no_dma_mem;
1168 }
1169 src_ring->shadow_base = (struct CE_src_desc *)
1170 (((size_t) src_ring->shadow_base_unaligned +
1171 CE_DESC_RING_ALIGN - 1) &
1172 ~(CE_DESC_RING_ALIGN - 1));
1173
Yun Park3fb36442017-08-17 17:37:53 -07001174 status = ce_ring_setup(scn, CE_RING_SRC, CE_id,
1175 src_ring, attr);
1176 if (status < 0)
Houston Hoffman4411ad42016-03-14 21:12:04 -07001177 goto error_target_access;
Houston Hoffmanf789c662016-04-12 15:39:04 -07001178
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301179 ce_ring_test_initial_indexes(CE_id, src_ring,
1180 "src_ring");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001181 }
1182 }
1183
1184 /* destination ring setup */
1185 nentries = attr->dest_nentries;
1186 if (nentries) {
1187 struct CE_ring_state *dest_ring;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001188
1189 nentries = roundup_pwr2(nentries);
1190 if (CE_state->dest_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301191 QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001192 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301193 dest_ring = CE_state->dest_ring =
1194 ce_alloc_ring_state(CE_state,
1195 CE_RING_DEST,
1196 nentries);
1197 if (!dest_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001198 /* cannot allocate dst ring. If the CE_state
1199 * or src ring is allocated locally free
1200 * CE_State and src ring and return error.
1201 */
1202 HIF_ERROR("%s: dest ring has no mem",
1203 __func__);
Poddar, Siddarth55d6da02017-03-31 18:42:54 +05301204 goto error_no_dma_mem;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001205 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001206
Yun Park3fb36442017-08-17 17:37:53 -07001207 status = ce_ring_setup(scn, CE_RING_DEST, CE_id,
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001208 dest_ring, attr);
Yun Park3fb36442017-08-17 17:37:53 -07001209 if (status < 0)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301210 goto error_target_access;
Houston Hoffman47808172016-05-06 10:04:21 -07001211
1212 ce_ring_test_initial_indexes(CE_id, dest_ring,
1213 "dest_ring");
1214
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301215 /* For srng based target, init status ring here */
1216 if (ce_srng_based(CE_state->scn)) {
1217 CE_state->status_ring =
1218 ce_alloc_ring_state(CE_state,
1219 CE_RING_STATUS,
1220 nentries);
1221 if (CE_state->status_ring == NULL) {
1222 /*Allocation failed. Cleanup*/
1223 qdf_mem_free(CE_state->dest_ring);
1224 if (malloc_src_ring) {
1225 qdf_mem_free
1226 (CE_state->src_ring);
1227 CE_state->src_ring = NULL;
1228 malloc_src_ring = false;
1229 }
1230 if (malloc_CE_state) {
1231 /* allocated CE_state locally */
1232 scn->ce_id_to_state[CE_id] =
1233 NULL;
1234 qdf_mem_free(CE_state);
1235 malloc_CE_state = false;
1236 }
Houston Hoffman4411ad42016-03-14 21:12:04 -07001237
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301238 return NULL;
1239 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001240
Yun Park3fb36442017-08-17 17:37:53 -07001241 status = ce_ring_setup(scn, CE_RING_STATUS,
1242 CE_id, CE_state->status_ring,
1243 attr);
1244 if (status < 0)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301245 goto error_target_access;
1246
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001247 }
Houston Hoffman31b25ec2016-09-19 13:12:30 -07001248
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001249 /* epping */
1250 /* poll timer */
Balamurugan Mahalingam3ab36332018-01-29 19:15:02 +05301251 if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL) ||
1252 scn->polled_mode_on) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301253 qdf_timer_init(scn->qdf_dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001254 &CE_state->poll_timer,
1255 ce_poll_timeout,
1256 CE_state,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301257 QDF_TIMER_TYPE_SW);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001258 CE_state->timer_inited = true;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301259 qdf_timer_mod(&CE_state->poll_timer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001260 CE_POLL_TIMEOUT);
1261 }
1262 }
1263 }
1264
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301265 if (!ce_srng_based(scn)) {
1266 /* Enable CE error interrupts */
1267 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
1268 goto error_target_access;
1269 CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
1270 if (Q_TARGET_ACCESS_END(scn) < 0)
1271 goto error_target_access;
1272 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001273
Houston Hoffmanb12ccb72017-03-01 20:02:28 -08001274 qdf_create_work(scn->qdf_dev, &CE_state->oom_allocation_work,
1275 ce_oom_recovery, CE_state);
1276
Houston Hoffmanc7d54292016-04-13 18:55:37 -07001277 /* update the htt_data attribute */
1278 ce_mark_datapath(CE_state);
Houston Hoffmanb01db182017-03-13 14:38:09 -07001279 scn->ce_id_to_state[CE_id] = CE_state;
Houston Hoffmanc7d54292016-04-13 18:55:37 -07001280
c_cgodavfda96ad2017-09-07 16:16:00 +05301281 alloc_mem_ce_debug_history(scn, CE_id);
1282
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001283 return (struct CE_handle *)CE_state;
1284
Houston Hoffman4411ad42016-03-14 21:12:04 -07001285error_target_access:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001286error_no_dma_mem:
1287 ce_fini((struct CE_handle *)CE_state);
1288 return NULL;
1289}
1290
1291#ifdef WLAN_FEATURE_FASTPATH
1292/**
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001293 * hif_enable_fastpath() Update that we have enabled fastpath mode
1294 * @hif_ctx: HIF context
1295 *
1296 * For use in data path
1297 *
1298 * Retrun: void
1299 */
1300void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
1301{
1302 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1303
Houston Hoffmand63cd742016-12-05 11:59:56 -08001304 if (ce_srng_based(scn)) {
1305 HIF_INFO("%s, srng rings do not support fastpath", __func__);
1306 return;
1307 }
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -08001308 HIF_DBG("%s, Enabling fastpath mode", __func__);
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001309 scn->fastpath_mode_on = true;
1310}
1311
Balamurugan Mahalingam3ab36332018-01-29 19:15:02 +05301312void hif_enable_polled_mode(struct hif_opaque_softc *hif_ctx)
1313{
1314 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1315 HIF_DBG("%s, Enabling polled mode", __func__);
1316
1317 scn->polled_mode_on = true;
1318}
1319
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001320/**
1321 * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
1322 * @hif_ctx: HIF Context
1323 *
1324 * For use in data path to skip HTC
1325 *
1326 * Return: bool
1327 */
1328bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
1329{
1330 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1331
1332 return scn->fastpath_mode_on;
1333}
1334
Balamurugan Mahalingam3ab36332018-01-29 19:15:02 +05301335bool hif_is_polled_mode_enabled(struct hif_opaque_softc *hif_ctx)
1336{
1337 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1338
1339 return scn->polled_mode_on;
1340}
1341
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001342/**
1343 * hif_get_ce_handle - API to get CE handle for FastPath mode
1344 * @hif_ctx: HIF Context
1345 * @id: CopyEngine Id
1346 *
1347 * API to return CE handle for fastpath mode
1348 *
1349 * Return: void
1350 */
1351void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
1352{
1353 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1354
1355 return scn->ce_id_to_state[id];
1356}
1357
1358/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001359 * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
1360 * No processing is required inside this function.
1361 * @ce_hdl: Cope engine handle
1362 * Using an assert, this function makes sure that,
1363 * the TX CE has been processed completely.
Houston Hoffman9a831ef2015-09-03 14:42:40 -07001364 *
1365 * This is called while dismantling CE structures. No other thread
1366 * should be using these structures while dismantling is occuring
1367 * therfore no locking is needed.
1368 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001369 * Return: none
1370 */
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001371void ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001372{
1373 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1374 struct CE_ring_state *src_ring = ce_state->src_ring;
Komal Seelam644263d2016-02-22 20:45:49 +05301375 struct hif_softc *sc = ce_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001376 uint32_t sw_index, write_index;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001377
Houston Hoffman85925072016-05-06 17:02:18 -07001378 if (hif_is_nss_wifi_enabled(sc))
1379 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001380
Houston Hoffmanc7d54292016-04-13 18:55:37 -07001381 if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -08001382 HIF_DBG("%s %d Fastpath mode ON, Cleaning up HTT Tx CE",
Houston Hoffman85925072016-05-06 17:02:18 -07001383 __func__, __LINE__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001384 sw_index = src_ring->sw_index;
1385 write_index = src_ring->sw_index;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001386
1387 /* At this point Tx CE should be clean */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301388 qdf_assert_always(sw_index == write_index);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001389 }
1390}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001391
1392/**
1393 * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
1394 * @ce_hdl: Handle to CE
1395 *
1396 * These buffers are never allocated on the fly, but
1397 * are allocated only once during HIF start and freed
1398 * only once during HIF stop.
1399 * NOTE:
1400 * The assumption here is there is no in-flight DMA in progress
1401 * currently, so that buffers can be freed up safely.
1402 *
1403 * Return: NONE
1404 */
1405void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
1406{
1407 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1408 struct CE_ring_state *dst_ring = ce_state->dest_ring;
1409 qdf_nbuf_t nbuf;
1410 int i;
1411
Houston Hoffman7fe51b12016-11-14 18:01:05 -08001412 if (ce_state->scn->fastpath_mode_on == false)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001413 return;
Houston Hoffman7fe51b12016-11-14 18:01:05 -08001414
1415 if (!ce_state->htt_rx_data)
1416 return;
1417
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001418 /*
1419 * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
1420 * this CE is completely full: does not leave one blank space, to
1421 * distinguish between empty queue & full queue. So free all the
1422 * entries.
1423 */
1424 for (i = 0; i < dst_ring->nentries; i++) {
1425 nbuf = dst_ring->per_transfer_context[i];
1426
1427 /*
1428 * The reasons for doing this check are:
1429 * 1) Protect against calling cleanup before allocating buffers
1430 * 2) In a corner case, FASTPATH_mode_on may be set, but we
1431 * could have a partially filled ring, because of a memory
1432 * allocation failure in the middle of allocating ring.
1433 * This check accounts for that case, checking
1434 * fastpath_mode_on flag or started flag would not have
1435 * covered that case. This is not in performance path,
1436 * so OK to do this.
1437 */
Houston Hoffman1c728302017-03-10 16:58:49 -08001438 if (nbuf) {
1439 qdf_nbuf_unmap_single(ce_state->scn->qdf_dev, nbuf,
1440 QDF_DMA_FROM_DEVICE);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001441 qdf_nbuf_free(nbuf);
Houston Hoffman1c728302017-03-10 16:58:49 -08001442 }
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001443 }
1444}
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001445
1446/**
1447 * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
1448 * @scn: HIF handle
1449 *
1450 * Datapath Rx CEs are special case, where we reuse all the message buffers.
1451 * Hence we have to post all the entries in the pipe, even, in the beginning
1452 * unlike for other CE pipes where one less than dest_nentries are filled in
1453 * the beginning.
1454 *
1455 * Return: None
1456 */
1457static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
1458{
1459 int pipe_num;
1460 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1461
1462 if (scn->fastpath_mode_on == false)
1463 return;
1464
1465 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1466 struct HIF_CE_pipe_info *pipe_info =
1467 &hif_state->pipe_info[pipe_num];
1468 struct CE_state *ce_state =
1469 scn->ce_id_to_state[pipe_info->pipe_num];
1470
1471 if (ce_state->htt_rx_data)
1472 atomic_inc(&pipe_info->recv_bufs_needed);
1473 }
1474}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001475#else
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001476static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001477{
1478}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001479
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001480static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001481{
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001482 return false;
1483}
1484
1485static inline bool ce_is_fastpath_handler_registered(struct CE_state *ce_state)
1486{
1487 return false;
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001488}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001489#endif /* WLAN_FEATURE_FASTPATH */
1490
1491void ce_fini(struct CE_handle *copyeng)
1492{
1493 struct CE_state *CE_state = (struct CE_state *)copyeng;
1494 unsigned int CE_id = CE_state->id;
Komal Seelam644263d2016-02-22 20:45:49 +05301495 struct hif_softc *scn = CE_state->scn;
Kiran Venkatappaae1a3702017-12-29 21:08:10 +05301496 uint32_t desc_size;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001497
Balamurugan Mahalingamf6d30352018-01-31 16:17:24 +05301498 bool inited = CE_state->timer_inited;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001499 CE_state->state = CE_UNUSED;
1500 scn->ce_id_to_state[CE_id] = NULL;
Balamurugan Mahalingamf6d30352018-01-31 16:17:24 +05301501 /* Set the flag to false first to stop processing in ce_poll_timeout */
1502 CE_state->timer_inited = false;
Dhanashri Atre991ee4d2017-05-03 19:03:10 -07001503 qdf_lro_deinit(CE_state->lro_data);
1504
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001505 if (CE_state->src_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001506 /* Cleanup the datapath Tx ring */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001507 ce_h2t_tx_ce_cleanup(copyeng);
1508
Kiran Venkatappaae1a3702017-12-29 21:08:10 +05301509 desc_size = ce_get_desc_size(scn, CE_RING_SRC);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001510 if (CE_state->src_ring->shadow_base_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301511 qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001512 if (CE_state->src_ring->base_addr_owner_space_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301513 qdf_mem_free_consistent(scn->qdf_dev,
1514 scn->qdf_dev->dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001515 (CE_state->src_ring->nentries *
Kiran Venkatappaae1a3702017-12-29 21:08:10 +05301516 desc_size +
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001517 CE_DESC_RING_ALIGN),
1518 CE_state->src_ring->
1519 base_addr_owner_space_unaligned,
1520 CE_state->src_ring->
1521 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301522 qdf_mem_free(CE_state->src_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001523 }
1524 if (CE_state->dest_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001525 /* Cleanup the datapath Rx ring */
1526 ce_t2h_msg_ce_cleanup(copyeng);
1527
Kiran Venkatappaae1a3702017-12-29 21:08:10 +05301528 desc_size = ce_get_desc_size(scn, CE_RING_DEST);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001529 if (CE_state->dest_ring->base_addr_owner_space_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301530 qdf_mem_free_consistent(scn->qdf_dev,
1531 scn->qdf_dev->dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001532 (CE_state->dest_ring->nentries *
Kiran Venkatappaae1a3702017-12-29 21:08:10 +05301533 desc_size +
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001534 CE_DESC_RING_ALIGN),
1535 CE_state->dest_ring->
1536 base_addr_owner_space_unaligned,
1537 CE_state->dest_ring->
1538 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301539 qdf_mem_free(CE_state->dest_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001540
1541 /* epping */
Balamurugan Mahalingamf6d30352018-01-31 16:17:24 +05301542 if (inited) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301543 qdf_timer_free(&CE_state->poll_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001544 }
1545 }
Houston Hoffman31b25ec2016-09-19 13:12:30 -07001546 if ((ce_srng_based(CE_state->scn)) && (CE_state->status_ring)) {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301547 /* Cleanup the datapath Tx ring */
1548 ce_h2t_tx_ce_cleanup(copyeng);
1549
1550 if (CE_state->status_ring->shadow_base_unaligned)
1551 qdf_mem_free(
1552 CE_state->status_ring->shadow_base_unaligned);
1553
Kiran Venkatappaae1a3702017-12-29 21:08:10 +05301554 desc_size = ce_get_desc_size(scn, CE_RING_STATUS);
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301555 if (CE_state->status_ring->base_addr_owner_space_unaligned)
1556 qdf_mem_free_consistent(scn->qdf_dev,
1557 scn->qdf_dev->dev,
1558 (CE_state->status_ring->nentries *
Kiran Venkatappaae1a3702017-12-29 21:08:10 +05301559 desc_size +
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301560 CE_DESC_RING_ALIGN),
1561 CE_state->status_ring->
1562 base_addr_owner_space_unaligned,
1563 CE_state->status_ring->
1564 base_addr_CE_space, 0);
1565 qdf_mem_free(CE_state->status_ring);
1566 }
Houston Hoffman03f46572016-12-12 12:53:56 -08001567
c_cgodavfda96ad2017-09-07 16:16:00 +05301568 free_mem_ce_debug_history(scn, CE_id);
1569 reset_ce_debug_history(scn);
1570 ce_deinit_ce_desc_event_log(scn, CE_id);
1571
Houston Hoffman03f46572016-12-12 12:53:56 -08001572 qdf_spinlock_destroy(&CE_state->ce_index_lock);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301573 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001574}
1575
Komal Seelam5584a7c2016-02-24 19:22:48 +05301576void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001577{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301578 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001579
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301580 qdf_mem_zero(&hif_state->msg_callbacks_pending,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001581 sizeof(hif_state->msg_callbacks_pending));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301582 qdf_mem_zero(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001583 sizeof(hif_state->msg_callbacks_current));
1584}
1585
1586/* Send the first nbytes bytes of the buffer */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301587QDF_STATUS
Komal Seelam5584a7c2016-02-24 19:22:48 +05301588hif_send_head(struct hif_opaque_softc *hif_ctx,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001589 uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301590 qdf_nbuf_t nbuf, unsigned int data_attr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001591{
Komal Seelam644263d2016-02-22 20:45:49 +05301592 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301593 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001594 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1595 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
1596 int bytes = nbytes, nfrags = 0;
1597 struct ce_sendlist sendlist;
1598 int status, i = 0;
1599 unsigned int mux_id = 0;
1600
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301601 QDF_ASSERT(nbytes <= qdf_nbuf_len(nbuf));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001602
1603 transfer_id =
1604 (mux_id & MUX_ID_MASK) |
1605 (transfer_id & TRANSACTION_ID_MASK);
1606 data_attr &= DESC_DATA_FLAG_MASK;
1607 /*
1608 * The common case involves sending multiple fragments within a
1609 * single download (the tx descriptor and the tx frame header).
1610 * So, optimize for the case of multiple fragments by not even
1611 * checking whether it's necessary to use a sendlist.
1612 * The overhead of using a sendlist for a single buffer download
1613 * is not a big deal, since it happens rarely (for WMI messages).
1614 */
1615 ce_sendlist_init(&sendlist);
1616 do {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301617 qdf_dma_addr_t frag_paddr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001618 int frag_bytes;
1619
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301620 frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
1621 frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001622 /*
1623 * Clear the packet offset for all but the first CE desc.
1624 */
1625 if (i++ > 0)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301626 data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001627
1628 status = ce_sendlist_buf_add(&sendlist, frag_paddr,
1629 frag_bytes >
1630 bytes ? bytes : frag_bytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301631 qdf_nbuf_get_frag_is_wordstream
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001632 (nbuf,
1633 nfrags) ? 0 :
1634 CE_SEND_FLAG_SWAP_DISABLE,
1635 data_attr);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301636 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001637 HIF_ERROR("%s: error, frag_num %d larger than limit",
1638 __func__, nfrags);
1639 return status;
1640 }
1641 bytes -= frag_bytes;
1642 nfrags++;
1643 } while (bytes > 0);
1644
1645 /* Make sure we have resources to handle this request */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301646 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001647 if (pipe_info->num_sends_allowed < nfrags) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301648 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001649 ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301650 return QDF_STATUS_E_RESOURCES;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001651 }
1652 pipe_info->num_sends_allowed -= nfrags;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301653 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001654
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301655 if (qdf_unlikely(ce_hdl == NULL)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001656 HIF_ERROR("%s: error CE handle is null", __func__);
1657 return A_ERROR;
1658 }
1659
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301660 QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301661 DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
Nandha Kishore Easwarane43583f2017-05-15 21:01:13 +05301662 QDF_TRACE_DEFAULT_PDEV_ID, qdf_nbuf_data_addr(nbuf),
1663 sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001664 status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301665 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001666
1667 return status;
1668}
1669
Komal Seelam5584a7c2016-02-24 19:22:48 +05301670void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
1671 int force)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001672{
Komal Seelam644263d2016-02-22 20:45:49 +05301673 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301674 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Komal Seelam644263d2016-02-22 20:45:49 +05301675
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001676 if (!force) {
1677 int resources;
1678 /*
1679 * Decide whether to actually poll for completions, or just
1680 * wait for a later chance. If there seem to be plenty of
1681 * resources left, then just wait, since checking involves
1682 * reading a CE register, which is a relatively expensive
1683 * operation.
1684 */
Komal Seelam644263d2016-02-22 20:45:49 +05301685 resources = hif_get_free_queue_number(hif_ctx, pipe);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001686 /*
1687 * If at least 50% of the total resources are still available,
1688 * don't bother checking again yet.
1689 */
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001690 if (resources > (hif_state->host_ce_config[pipe].src_nentries >>
1691 1))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001692 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001693 }
Houston Hoffman56e0d702016-05-05 17:48:06 -07001694#if ATH_11AC_TXCOMPACT
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001695 ce_per_engine_servicereap(scn, pipe);
1696#else
1697 ce_per_engine_service(scn, pipe);
1698#endif
1699}
1700
Komal Seelam5584a7c2016-02-24 19:22:48 +05301701uint16_t
1702hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001703{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301704 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001705 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1706 uint16_t rv;
1707
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301708 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001709 rv = pipe_info->num_sends_allowed;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301710 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001711 return rv;
1712}
1713
1714/* Called by lower (CE) layer when a send to Target completes. */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001715static void
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001716hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301717 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001718 unsigned int nbytes, unsigned int transfer_id,
1719 unsigned int sw_index, unsigned int hw_index,
1720 unsigned int toeplitz_hash_result)
1721{
1722 struct HIF_CE_pipe_info *pipe_info =
1723 (struct HIF_CE_pipe_info *)ce_context;
1724 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Komal Seelam644263d2016-02-22 20:45:49 +05301725 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001726 unsigned int sw_idx = sw_index, hw_idx = hw_index;
Houston Hoffman85118512015-09-28 14:17:11 -07001727 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301728 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001729
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001730 do {
1731 /*
Houston Hoffman85118512015-09-28 14:17:11 -07001732 * The upper layer callback will be triggered
1733 * when last fragment is complteted.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001734 */
Houston Hoffman85118512015-09-28 14:17:11 -07001735 if (transfer_context != CE_SENDLIST_ITEM_CTXT) {
Houston Hoffman1c728302017-03-10 16:58:49 -08001736 if (scn->target_status == TARGET_STATUS_RESET) {
1737
1738 qdf_nbuf_unmap_single(scn->qdf_dev,
1739 transfer_context,
1740 QDF_DMA_TO_DEVICE);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301741 qdf_nbuf_free(transfer_context);
Houston Hoffman1c728302017-03-10 16:58:49 -08001742 } else
Houston Hoffman49794a32015-12-21 12:14:56 -08001743 msg_callbacks->txCompletionHandler(
Houston Hoffman85118512015-09-28 14:17:11 -07001744 msg_callbacks->Context,
1745 transfer_context, transfer_id,
1746 toeplitz_hash_result);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001747 }
1748
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301749 qdf_spin_lock(&pipe_info->completion_freeq_lock);
Houston Hoffman85118512015-09-28 14:17:11 -07001750 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301751 qdf_spin_unlock(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001752 } while (ce_completed_send_next(copyeng,
1753 &ce_context, &transfer_context,
1754 &CE_data, &nbytes, &transfer_id,
1755 &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301756 &toeplitz_hash_result) == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001757}
1758
Houston Hoffman910c6262015-09-28 12:56:25 -07001759/**
1760 * hif_ce_do_recv(): send message from copy engine to upper layers
1761 * @msg_callbacks: structure containing callback and callback context
1762 * @netbuff: skb containing message
1763 * @nbytes: number of bytes in the message
1764 * @pipe_info: used for the pipe_number info
1765 *
1766 * Checks the packet length, configures the lenght in the netbuff,
1767 * and calls the upper layer callback.
1768 *
1769 * return: None
1770 */
1771static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301772 qdf_nbuf_t netbuf, int nbytes,
Houston Hoffman910c6262015-09-28 12:56:25 -07001773 struct HIF_CE_pipe_info *pipe_info) {
1774 if (nbytes <= pipe_info->buf_sz) {
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301775 qdf_nbuf_set_pktlen(netbuf, nbytes);
Houston Hoffman910c6262015-09-28 12:56:25 -07001776 msg_callbacks->
1777 rxCompletionHandler(msg_callbacks->Context,
1778 netbuf, pipe_info->pipe_num);
1779 } else {
Jeff Johnsonb9450212017-09-18 10:12:38 -07001780 HIF_ERROR("%s: Invalid Rx msg buf:%pK nbytes:%d",
Houston Hoffman910c6262015-09-28 12:56:25 -07001781 __func__, netbuf, nbytes);
Houston Hoffman1c728302017-03-10 16:58:49 -08001782
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301783 qdf_nbuf_free(netbuf);
Houston Hoffman910c6262015-09-28 12:56:25 -07001784 }
1785}
1786
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001787/* Called by lower (CE) layer when data is received from the Target. */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001788static void
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001789hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301790 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001791 unsigned int nbytes, unsigned int transfer_id,
1792 unsigned int flags)
1793{
1794 struct HIF_CE_pipe_info *pipe_info =
1795 (struct HIF_CE_pipe_info *)ce_context;
1796 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001797 struct CE_state *ce_state = (struct CE_state *) copyeng;
Komal Seelam644263d2016-02-22 20:45:49 +05301798 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001799#ifdef HIF_PCI
1800 struct hif_pci_softc *hif_pci_sc = HIF_GET_PCI_SOFTC(hif_state);
1801#endif
Houston Hoffman910c6262015-09-28 12:56:25 -07001802 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301803 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001804
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001805 do {
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001806#ifdef HIF_PCI
1807 hif_pm_runtime_mark_last_busy(hif_pci_sc->dev);
1808#endif
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301809 qdf_nbuf_unmap_single(scn->qdf_dev,
1810 (qdf_nbuf_t) transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301811 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001812
Houston Hoffman910c6262015-09-28 12:56:25 -07001813 atomic_inc(&pipe_info->recv_bufs_needed);
1814 hif_post_recv_buffers_for_pipe(pipe_info);
Komal Seelam6ee55902016-04-11 17:11:07 +05301815 if (scn->target_status == TARGET_STATUS_RESET)
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301816 qdf_nbuf_free(transfer_context);
Houston Hoffman49794a32015-12-21 12:14:56 -08001817 else
1818 hif_ce_do_recv(msg_callbacks, transfer_context,
Houston Hoffman9c0f80a2015-09-28 18:36:36 -07001819 nbytes, pipe_info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001820
1821 /* Set up force_break flag if num of receices reaches
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001822 * MAX_NUM_OF_RECEIVES
1823 */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001824 ce_state->receive_count++;
Houston Hoffman05652722016-04-29 16:58:59 -07001825 if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001826 ce_state->force_break = 1;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001827 break;
1828 }
1829 } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
1830 &CE_data, &nbytes, &transfer_id,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301831 &flags) == QDF_STATUS_SUCCESS);
Houston Hoffmanf4607852015-12-17 17:14:40 -08001832
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001833}
1834
1835/* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
1836
1837void
Komal Seelam5584a7c2016-02-24 19:22:48 +05301838hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001839 struct hif_msg_callbacks *callbacks)
1840{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301841 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001842
1843#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
1844 spin_lock_init(&pcie_access_log_lock);
1845#endif
1846 /* Save callbacks for later installation */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301847 qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001848 sizeof(hif_state->msg_callbacks_pending));
1849
1850}
1851
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001852static int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001853{
1854 struct CE_handle *ce_diag = hif_state->ce_diag;
1855 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05301856 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001857 struct hif_msg_callbacks *hif_msg_callbacks =
1858 &hif_state->msg_callbacks_current;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001859
1860 /* daemonize("hif_compl_thread"); */
1861
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001862 if (scn->ce_count == 0) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07001863 HIF_ERROR("%s: Invalid ce_count", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001864 return -EINVAL;
1865 }
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001866
1867 if (!hif_msg_callbacks ||
1868 !hif_msg_callbacks->rxCompletionHandler ||
1869 !hif_msg_callbacks->txCompletionHandler) {
1870 HIF_ERROR("%s: no completion handler registered", __func__);
1871 return -EFAULT;
1872 }
1873
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001874 A_TARGET_ACCESS_LIKELY(scn);
1875 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1876 struct CE_attr attr;
1877 struct HIF_CE_pipe_info *pipe_info;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001878
1879 pipe_info = &hif_state->pipe_info[pipe_num];
Manikandan Mohanafd6e882017-04-07 17:46:41 -07001880 if (pipe_info->ce_hdl == ce_diag)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001881 continue; /* Handle Diagnostic CE specially */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301882 attr = hif_state->host_ce_config[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001883 if (attr.src_nentries) {
1884 /* pipe used to send to target */
Jeff Johnsonb9450212017-09-18 10:12:38 -07001885 HIF_DBG("%s: pipe_num:%d pipe_info:0x%pK",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001886 __func__, pipe_num, pipe_info);
1887 ce_send_cb_register(pipe_info->ce_hdl,
1888 hif_pci_ce_send_done, pipe_info,
1889 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001890 pipe_info->num_sends_allowed = attr.src_nentries - 1;
1891 }
1892 if (attr.dest_nentries) {
1893 /* pipe used to receive from target */
1894 ce_recv_cb_register(pipe_info->ce_hdl,
1895 hif_pci_ce_recv_data, pipe_info,
1896 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001897 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001898
1899 if (attr.src_nentries)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301900 qdf_spinlock_create(&pipe_info->completion_freeq_lock);
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301901
1902 qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks,
1903 sizeof(pipe_info->pipe_callbacks));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001904 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001905
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001906 A_TARGET_ACCESS_UNLIKELY(scn);
1907 return 0;
1908}
1909
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001910/*
1911 * Install pending msg callbacks.
1912 *
1913 * TBDXXX: This hack is needed because upper layers install msg callbacks
1914 * for use with HTC before BMI is done; yet this HIF implementation
1915 * needs to continue to use BMI msg callbacks. Really, upper layers
1916 * should not register HTC callbacks until AFTER BMI phase.
1917 */
Komal Seelam644263d2016-02-22 20:45:49 +05301918static void hif_msg_callbacks_install(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001919{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301920 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001921
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301922 qdf_mem_copy(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001923 &hif_state->msg_callbacks_pending,
1924 sizeof(hif_state->msg_callbacks_pending));
1925}
1926
Komal Seelam5584a7c2016-02-24 19:22:48 +05301927void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
1928 uint8_t *DLPipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001929{
1930 int ul_is_polled, dl_is_polled;
1931
Komal Seelam644263d2016-02-22 20:45:49 +05301932 (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001933 ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
1934}
1935
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001936/**
1937 * hif_dump_pipe_debug_count() - Log error count
Komal Seelam644263d2016-02-22 20:45:49 +05301938 * @scn: hif_softc pointer.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001939 *
1940 * Output the pipe error counts of each pipe to log file
1941 *
1942 * Return: N/A
1943 */
Komal Seelam644263d2016-02-22 20:45:49 +05301944void hif_dump_pipe_debug_count(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001945{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301946 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001947 int pipe_num;
1948
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001949 if (hif_state == NULL) {
1950 HIF_ERROR("%s hif_state is NULL", __func__);
1951 return;
1952 }
1953 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1954 struct HIF_CE_pipe_info *pipe_info;
1955
1956 pipe_info = &hif_state->pipe_info[pipe_num];
1957
1958 if (pipe_info->nbuf_alloc_err_count > 0 ||
1959 pipe_info->nbuf_dma_err_count > 0 ||
1960 pipe_info->nbuf_ce_enqueue_err_count)
1961 HIF_ERROR(
1962 "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
1963 __func__, pipe_info->pipe_num,
1964 atomic_read(&pipe_info->recv_bufs_needed),
1965 pipe_info->nbuf_alloc_err_count,
1966 pipe_info->nbuf_dma_err_count,
1967 pipe_info->nbuf_ce_enqueue_err_count);
1968 }
1969}
1970
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08001971static void hif_post_recv_buffers_failure(struct HIF_CE_pipe_info *pipe_info,
1972 void *nbuf, uint32_t *error_cnt,
1973 enum hif_ce_event_type failure_type,
1974 const char *failure_type_string)
1975{
1976 int bufs_needed_tmp = atomic_inc_return(&pipe_info->recv_bufs_needed);
1977 struct CE_state *CE_state = (struct CE_state *)pipe_info->ce_hdl;
1978 struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
1979 int ce_id = CE_state->id;
1980 uint32_t error_cnt_tmp;
1981
1982 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
1983 error_cnt_tmp = ++(*error_cnt);
1984 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Himanshu Agarwal38cea4a2017-03-30 19:02:52 +05301985 HIF_DBG("%s: pipe_num %d, needed %d, err_cnt = %u, fail_type = %s",
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08001986 __func__, pipe_info->pipe_num, bufs_needed_tmp, error_cnt_tmp,
1987 failure_type_string);
1988 hif_record_ce_desc_event(scn, ce_id, failure_type,
c_cgodavfda96ad2017-09-07 16:16:00 +05301989 NULL, nbuf, bufs_needed_tmp, 0);
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08001990 /* if we fail to allocate the last buffer for an rx pipe,
1991 * there is no trigger to refill the ce and we will
1992 * eventually crash
1993 */
Himanshu Agarwalbedeed92017-03-21 14:05:10 +05301994 if (bufs_needed_tmp == CE_state->dest_ring->nentries - 1)
Houston Hoffmanb12ccb72017-03-01 20:02:28 -08001995 qdf_sched_work(scn->qdf_dev, &CE_state->oom_allocation_work);
Himanshu Agarwalbedeed92017-03-21 14:05:10 +05301996
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08001997}
1998
1999
Houston Hoffmanb12ccb72017-03-01 20:02:28 -08002000
2001
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302002QDF_STATUS hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002003{
2004 struct CE_handle *ce_hdl;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302005 qdf_size_t buf_sz;
Komal Seelam644263d2016-02-22 20:45:49 +05302006 struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302007 QDF_STATUS status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002008 uint32_t bufs_posted = 0;
2009
2010 buf_sz = pipe_info->buf_sz;
2011 if (buf_sz == 0) {
2012 /* Unused Copy Engine */
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302013 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002014 }
2015
2016 ce_hdl = pipe_info->ce_hdl;
2017
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302018 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002019 while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302020 qdf_dma_addr_t CE_data; /* CE space buffer address */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302021 qdf_nbuf_t nbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002022
2023 atomic_dec(&pipe_info->recv_bufs_needed);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302024 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002025
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302026 nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002027 if (!nbuf) {
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08002028 hif_post_recv_buffers_failure(pipe_info, nbuf,
2029 &pipe_info->nbuf_alloc_err_count,
2030 HIF_RX_NBUF_ALLOC_FAILURE,
2031 "HIF_RX_NBUF_ALLOC_FAILURE");
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302032 return QDF_STATUS_E_NOMEM;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002033 }
2034
2035 /*
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302036 * qdf_nbuf_peek_header(nbuf, &data, &unused);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002037 * CE_data = dma_map_single(dev, data, buf_sz, );
2038 * DMA_FROM_DEVICE);
2039 */
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302040 status = qdf_nbuf_map_single(scn->qdf_dev, nbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302041 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002042
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302043 if (qdf_unlikely(status != QDF_STATUS_SUCCESS)) {
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08002044 hif_post_recv_buffers_failure(pipe_info, nbuf,
2045 &pipe_info->nbuf_dma_err_count,
2046 HIF_RX_NBUF_MAP_FAILURE,
2047 "HIF_RX_NBUF_MAP_FAILURE");
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302048 qdf_nbuf_free(nbuf);
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302049 return status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002050 }
2051
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302052 CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002053
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302054 qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002055 buf_sz, DMA_FROM_DEVICE);
2056 status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302057 if (qdf_unlikely(status != QDF_STATUS_SUCCESS)) {
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08002058 hif_post_recv_buffers_failure(pipe_info, nbuf,
2059 &pipe_info->nbuf_ce_enqueue_err_count,
2060 HIF_RX_NBUF_ENQUEUE_FAILURE,
2061 "HIF_RX_NBUF_ENQUEUE_FAILURE");
2062
Govind Singh4fcafd42016-08-08 12:37:31 +05302063 qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
2064 QDF_DMA_FROM_DEVICE);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302065 qdf_nbuf_free(nbuf);
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302066 return status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002067 }
2068
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302069 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002070 bufs_posted++;
2071 }
2072 pipe_info->nbuf_alloc_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07002073 (pipe_info->nbuf_alloc_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002074 pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
2075 pipe_info->nbuf_dma_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07002076 (pipe_info->nbuf_dma_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002077 pipe_info->nbuf_dma_err_count - bufs_posted : 0;
2078 pipe_info->nbuf_ce_enqueue_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07002079 (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
Houston Hoffmanc0c00a22017-02-24 17:37:46 -08002080 pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002081
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302082 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002083
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302084 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002085}
2086
2087/*
2088 * Try to post all desired receive buffers for all pipes.
Govind Singhcaa850e2017-04-20 16:41:36 +05302089 * Returns 0 for non fastpath rx copy engine as
2090 * oom_allocation_work will be scheduled to recover any
2091 * failures, non-zero if unable to completely replenish
2092 * receive buffers for fastpath rx Copy engine.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002093 */
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302094QDF_STATUS hif_post_recv_buffers(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002095{
Komal Seelam02cf2f82016-02-22 20:44:25 +05302096 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302097 int pipe_num;
Houston Hoffman85925072016-05-06 17:02:18 -07002098 struct CE_state *ce_state;
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302099 QDF_STATUS qdf_status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002100
2101 A_TARGET_ACCESS_LIKELY(scn);
2102 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
2103 struct HIF_CE_pipe_info *pipe_info;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002104
Houston Hoffman85925072016-05-06 17:02:18 -07002105 ce_state = scn->ce_id_to_state[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002106 pipe_info = &hif_state->pipe_info[pipe_num];
Houston Hoffman85925072016-05-06 17:02:18 -07002107
2108 if (hif_is_nss_wifi_enabled(scn) &&
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002109 ce_state && (ce_state->htt_rx_data))
Houston Hoffman85925072016-05-06 17:02:18 -07002110 continue;
Houston Hoffman85925072016-05-06 17:02:18 -07002111
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302112 qdf_status = hif_post_recv_buffers_for_pipe(pipe_info);
2113 if (!QDF_IS_STATUS_SUCCESS(qdf_status) &&
Govind Singhcaa850e2017-04-20 16:41:36 +05302114 ce_state->htt_rx_data &&
2115 scn->fastpath_mode_on) {
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302116 A_TARGET_ACCESS_UNLIKELY(scn);
2117 return qdf_status;
Govind Singhcaa850e2017-04-20 16:41:36 +05302118 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002119 }
2120
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002121 A_TARGET_ACCESS_UNLIKELY(scn);
2122
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302123 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002124}
2125
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302126QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002127{
Komal Seelam644263d2016-02-22 20:45:49 +05302128 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05302129 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302130 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002131
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07002132 hif_update_fastpath_recv_bufs_cnt(scn);
2133
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07002134 hif_msg_callbacks_install(scn);
2135
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002136 if (hif_completion_thread_startup(hif_state))
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302137 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002138
Houston Hoffman271951f2016-11-12 15:24:27 -08002139 /* enable buffer cleanup */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002140 hif_state->started = true;
2141
Houston Hoffman271951f2016-11-12 15:24:27 -08002142 /* Post buffers once to start things off. */
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302143 qdf_status = hif_post_recv_buffers(scn);
2144 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Houston Hoffman271951f2016-11-12 15:24:27 -08002145 /* cleanup is done in hif_ce_disable */
2146 HIF_ERROR("%s:failed to post buffers", __func__);
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302147 return qdf_status;
Houston Hoffman271951f2016-11-12 15:24:27 -08002148 }
2149
Nachiket Kukadee5738b52017-09-07 17:16:12 +05302150 return qdf_status;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002151}
2152
Jeff Johnson6950fdb2016-10-07 13:00:59 -07002153static void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002154{
Komal Seelam644263d2016-02-22 20:45:49 +05302155 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002156 struct CE_handle *ce_hdl;
2157 uint32_t buf_sz;
2158 struct HIF_CE_state *hif_state;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302159 qdf_nbuf_t netbuf;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302160 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002161 void *per_CE_context;
2162
2163 buf_sz = pipe_info->buf_sz;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002164 /* Unused Copy Engine */
2165 if (buf_sz == 0)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002166 return;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002167
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002168
2169 hif_state = pipe_info->HIF_CE_state;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002170 if (!hif_state->started)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002171 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002172
Komal Seelam02cf2f82016-02-22 20:44:25 +05302173 scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002174 ce_hdl = pipe_info->ce_hdl;
2175
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002176 if (scn->qdf_dev == NULL)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002177 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002178 while (ce_revoke_recv_next
2179 (ce_hdl, &per_CE_context, (void **)&netbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302180 &CE_data) == QDF_STATUS_SUCCESS) {
Govind Singhcaa850e2017-04-20 16:41:36 +05302181 if (netbuf) {
2182 qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
2183 QDF_DMA_FROM_DEVICE);
2184 qdf_nbuf_free(netbuf);
2185 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002186 }
2187}
2188
Jeff Johnson6950fdb2016-10-07 13:00:59 -07002189static void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002190{
2191 struct CE_handle *ce_hdl;
2192 struct HIF_CE_state *hif_state;
Komal Seelam644263d2016-02-22 20:45:49 +05302193 struct hif_softc *scn;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05302194 qdf_nbuf_t netbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002195 void *per_CE_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302196 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002197 unsigned int nbytes;
2198 unsigned int id;
2199 uint32_t buf_sz;
2200 uint32_t toeplitz_hash_result;
2201
2202 buf_sz = pipe_info->buf_sz;
2203 if (buf_sz == 0) {
2204 /* Unused Copy Engine */
2205 return;
2206 }
2207
2208 hif_state = pipe_info->HIF_CE_state;
2209 if (!hif_state->started) {
2210 return;
2211 }
2212
Komal Seelam02cf2f82016-02-22 20:44:25 +05302213 scn = HIF_GET_SOFTC(hif_state);
2214
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002215 ce_hdl = pipe_info->ce_hdl;
2216
2217 while (ce_cancel_send_next
2218 (ce_hdl, &per_CE_context,
2219 (void **)&netbuf, &CE_data, &nbytes,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302220 &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002221 if (netbuf != CE_SENDLIST_ITEM_CTXT) {
2222 /*
2223 * Packets enqueued by htt_h2t_ver_req_msg() and
2224 * htt_h2t_rx_ring_cfg_msg_ll() have already been
2225 * freed in htt_htc_misc_pkt_pool_free() in
2226 * wlantl_close(), so do not free them here again
Houston Hoffman29573d92015-10-20 17:49:44 -07002227 * by checking whether it's the endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002228 * which they are queued in.
2229 */
Nirav Shahd7f91592016-04-21 14:18:43 +05302230 if (id == scn->htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002231 return;
Nirav Shahd7f91592016-04-21 14:18:43 +05302232 /* Indicate the completion to higher
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002233 * layer to free the buffer
2234 */
2235 if (pipe_info->pipe_callbacks.txCompletionHandler)
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05302236 pipe_info->pipe_callbacks.
2237 txCompletionHandler(pipe_info->
2238 pipe_callbacks.Context,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002239 netbuf, id, toeplitz_hash_result);
2240 }
2241 }
2242}
2243
2244/*
2245 * Cleanup residual buffers for device shutdown:
2246 * buffers that were enqueued for receive
2247 * buffers that were to be sent
2248 * Note: Buffers that had completed but which were
2249 * not yet processed are on a completion queue. They
2250 * are handled when the completion thread shuts down.
2251 */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07002252static void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002253{
2254 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05302255 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman85925072016-05-06 17:02:18 -07002256 struct CE_state *ce_state;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002257
Komal Seelam02cf2f82016-02-22 20:44:25 +05302258 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002259 struct HIF_CE_pipe_info *pipe_info;
2260
Houston Hoffman85925072016-05-06 17:02:18 -07002261 ce_state = scn->ce_id_to_state[pipe_num];
2262 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
2263 ((ce_state->htt_tx_data) ||
2264 (ce_state->htt_rx_data))) {
2265 continue;
2266 }
2267
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002268 pipe_info = &hif_state->pipe_info[pipe_num];
2269 hif_recv_buffer_cleanup_on_pipe(pipe_info);
2270 hif_send_buffer_cleanup_on_pipe(pipe_info);
2271 }
2272}
2273
Komal Seelam5584a7c2016-02-24 19:22:48 +05302274void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002275{
Komal Seelam644263d2016-02-22 20:45:49 +05302276 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05302277 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Komal Seelam644263d2016-02-22 20:45:49 +05302278
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002279 hif_buffer_cleanup(hif_state);
2280}
2281
Houston Hoffmanb12ccb72017-03-01 20:02:28 -08002282static void hif_destroy_oom_work(struct hif_softc *scn)
2283{
2284 struct CE_state *ce_state;
2285 int ce_id;
2286
2287 for (ce_id = 0; ce_id < scn->ce_count; ce_id++) {
2288 ce_state = scn->ce_id_to_state[ce_id];
2289 if (ce_state)
2290 qdf_destroy_work(scn->qdf_dev,
2291 &ce_state->oom_allocation_work);
2292 }
2293}
2294
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302295void hif_ce_stop(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002296{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302297 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002298 int pipe_num;
2299
Houston Hoffmana69581e2016-11-14 18:03:19 -08002300 /*
2301 * before cleaning up any memory, ensure irq &
2302 * bottom half contexts will not be re-entered
2303 */
Houston Hoffman7622cd32017-04-06 14:17:49 -07002304 hif_disable_isr(&scn->osc);
Houston Hoffmanb12ccb72017-03-01 20:02:28 -08002305 hif_destroy_oom_work(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002306 scn->hif_init_done = false;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002307
2308 /*
2309 * At this point, asynchronous threads are stopped,
2310 * The Target should not DMA nor interrupt, Host code may
2311 * not initiate anything more. So we just need to clean
2312 * up Host-side state.
2313 */
2314
2315 if (scn->athdiag_procfs_inited) {
2316 athdiag_procfs_remove();
2317 scn->athdiag_procfs_inited = false;
2318 }
2319
2320 hif_buffer_cleanup(hif_state);
2321
2322 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
2323 struct HIF_CE_pipe_info *pipe_info;
Poddar, Siddarth725e9f52017-07-19 15:18:28 +05302324 struct CE_attr attr;
2325 struct CE_handle *ce_diag = hif_state->ce_diag;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002326
2327 pipe_info = &hif_state->pipe_info[pipe_num];
2328 if (pipe_info->ce_hdl) {
Poddar, Siddarth725e9f52017-07-19 15:18:28 +05302329 if (pipe_info->ce_hdl != ce_diag) {
2330 attr = hif_state->host_ce_config[pipe_num];
2331 if (attr.src_nentries)
2332 qdf_spinlock_destroy(&pipe_info->
2333 completion_freeq_lock);
2334 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002335 ce_fini(pipe_info->ce_hdl);
2336 pipe_info->ce_hdl = NULL;
2337 pipe_info->buf_sz = 0;
Poddar, Siddarth725e9f52017-07-19 15:18:28 +05302338 qdf_spinlock_destroy(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002339 }
2340 }
2341
2342 if (hif_state->sleep_timer_init) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302343 qdf_timer_stop(&hif_state->sleep_timer);
2344 qdf_timer_free(&hif_state->sleep_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002345 hif_state->sleep_timer_init = false;
2346 }
2347
2348 hif_state->started = false;
2349}
2350
Houston Hoffman748e1a62017-03-30 17:20:42 -07002351
Houston Hoffman854e67f2016-03-14 21:11:39 -07002352/**
2353 * hif_get_target_ce_config() - get copy engine configuration
2354 * @target_ce_config_ret: basic copy engine configuration
2355 * @target_ce_config_sz_ret: size of the basic configuration in bytes
2356 * @target_service_to_ce_map_ret: service mapping for the copy engines
2357 * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
2358 * @target_shadow_reg_cfg_ret: shadow register configuration
2359 * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
2360 *
2361 * providing accessor to these values outside of this file.
2362 * currently these are stored in static pointers to const sections.
2363 * there are multiple configurations that are selected from at compile time.
2364 * Runtime selection would need to consider mode, target type and bus type.
2365 *
2366 * Return: return by parameter.
2367 */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302368void hif_get_target_ce_config(struct hif_softc *scn,
2369 struct CE_pipe_config **target_ce_config_ret,
Houston Hoffman748e1a62017-03-30 17:20:42 -07002370 uint32_t *target_ce_config_sz_ret,
Houston Hoffman854e67f2016-03-14 21:11:39 -07002371 struct service_to_pipe **target_service_to_ce_map_ret,
Houston Hoffman748e1a62017-03-30 17:20:42 -07002372 uint32_t *target_service_to_ce_map_sz_ret,
Houston Hoffman854e67f2016-03-14 21:11:39 -07002373 struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
Houston Hoffman748e1a62017-03-30 17:20:42 -07002374 uint32_t *shadow_cfg_sz_ret)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002375{
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302376 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2377
2378 *target_ce_config_ret = hif_state->target_ce_config;
2379 *target_ce_config_sz_ret = hif_state->target_ce_config_sz;
Houston Hoffman748e1a62017-03-30 17:20:42 -07002380
2381 hif_select_service_to_pipe_map(scn, target_service_to_ce_map_ret,
2382 target_service_to_ce_map_sz_ret);
Houston Hoffman854e67f2016-03-14 21:11:39 -07002383
2384 if (target_shadow_reg_cfg_ret)
2385 *target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
2386
2387 if (shadow_cfg_sz_ret)
2388 *shadow_cfg_sz_ret = shadow_cfg_sz;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002389}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002390
Houston Hoffmanf60a3482017-01-31 10:45:07 -08002391#ifdef CONFIG_SHADOW_V2
Houston Hoffman403c2df2017-01-27 12:51:15 -08002392static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
Houston Hoffman5141f9d2017-01-05 10:49:17 -08002393{
2394 int i;
2395 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
2396 "%s: num_config %d\n", __func__, cfg->num_shadow_reg_v2_cfg);
2397
2398 for (i = 0; i < cfg->num_shadow_reg_v2_cfg; i++) {
2399 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
2400 "%s: i %d, val %x\n", __func__, i,
2401 cfg->shadow_reg_v2_cfg[i].addr);
2402 }
2403}
2404
Houston Hoffmanf60a3482017-01-31 10:45:07 -08002405#else
2406static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
2407{
2408 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
2409 "%s: CONFIG_SHADOW_V2 not defined\n", __func__);
2410}
2411#endif
2412
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002413/**
2414 * hif_wlan_enable(): call the platform driver to enable wlan
Komal Seelambd7c51d2016-02-24 10:27:30 +05302415 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002416 *
2417 * This function passes the con_mode and CE configuration to
2418 * platform driver to enable wlan.
2419 *
Houston Hoffman108da402016-03-14 21:11:24 -07002420 * Return: linux error code
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002421 */
Houston Hoffman108da402016-03-14 21:11:24 -07002422int hif_wlan_enable(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002423{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002424 struct pld_wlan_enable_cfg cfg;
2425 enum pld_driver_mode mode;
Komal Seelambd7c51d2016-02-24 10:27:30 +05302426 uint32_t con_mode = hif_get_conparam(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002427
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302428 hif_get_target_ce_config(scn,
2429 (struct CE_pipe_config **)&cfg.ce_tgt_cfg,
Houston Hoffman854e67f2016-03-14 21:11:39 -07002430 &cfg.num_ce_tgt_cfg,
2431 (struct service_to_pipe **)&cfg.ce_svc_cfg,
2432 &cfg.num_ce_svc_pipe_cfg,
2433 (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
2434 &cfg.num_shadow_reg_cfg);
2435
2436 /* translate from structure size to array size */
2437 cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
2438 cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
2439 cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002440
Houston Hoffman5141f9d2017-01-05 10:49:17 -08002441 hif_prepare_hal_shadow_register_cfg(scn, &cfg.shadow_reg_v2_cfg,
2442 &cfg.num_shadow_reg_v2_cfg);
2443
2444 hif_print_hal_shadow_register_cfg(&cfg);
2445
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302446 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002447 mode = PLD_FTM;
Balamurugan Mahalingam1666dd32017-09-14 15:19:42 +05302448 else if (QDF_GLOBAL_COLDBOOT_CALIB_MODE == con_mode)
2449 mode = PLD_COLDBOOT_CALIBRATION;
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002450 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002451 mode = PLD_EPPING;
Peng Xu7b962532015-10-02 17:17:03 -07002452 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002453 mode = PLD_MISSION;
Peng Xu7b962532015-10-02 17:17:03 -07002454
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002455 if (BYPASS_QMI)
2456 return 0;
2457 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002458 return pld_wlan_enable(scn->qdf_dev->dev, &cfg,
2459 mode, QWLAN_VERSIONSTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002460}
2461
Nirav Shah0d0cce82018-01-17 17:00:31 +05302462#ifdef WLAN_FEATURE_EPPING
2463
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002464#define CE_EPPING_USES_IRQ true
2465
Nirav Shah0d0cce82018-01-17 17:00:31 +05302466void hif_ce_prepare_epping_config(struct HIF_CE_state *hif_state)
2467{
2468 if (CE_EPPING_USES_IRQ)
2469 hif_state->host_ce_config = host_ce_config_wlan_epping_irq;
2470 else
2471 hif_state->host_ce_config = host_ce_config_wlan_epping_poll;
2472 hif_state->target_ce_config = target_ce_config_wlan_epping;
2473 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
2474 target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
2475 shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
2476}
2477#endif
2478
Houston Hoffman108da402016-03-14 21:11:24 -07002479/**
2480 * hif_ce_prepare_config() - load the correct static tables.
2481 * @scn: hif context
2482 *
2483 * Epping uses different static attribute tables than mission mode.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002484 */
Houston Hoffman108da402016-03-14 21:11:24 -07002485void hif_ce_prepare_config(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002486{
Komal Seelambd7c51d2016-02-24 10:27:30 +05302487 uint32_t mode = hif_get_conparam(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002488 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2489 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302490 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002491
Houston Hoffman10fedfc2017-01-23 15:23:09 -08002492 hif_state->ce_services = ce_services_attach(scn);
2493
Houston Hoffman710af5a2016-11-22 21:59:03 -08002494 scn->ce_count = HOST_CE_COUNT;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002495 /* if epping is enabled we need to use the epping configuration. */
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002496 if (QDF_IS_EPPING_ENABLED(mode)) {
Nirav Shah0d0cce82018-01-17 17:00:31 +05302497 hif_ce_prepare_epping_config(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002498 }
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002499
2500 switch (tgt_info->target_type) {
2501 default:
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302502 hif_state->host_ce_config = host_ce_config_wlan;
2503 hif_state->target_ce_config = target_ce_config_wlan;
2504 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002505 break;
2506 case TARGET_TYPE_AR900B:
2507 case TARGET_TYPE_QCA9984:
2508 case TARGET_TYPE_IPQ4019:
2509 case TARGET_TYPE_QCA9888:
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05302510 if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
2511 hif_state->host_ce_config =
2512 host_lowdesc_ce_cfg_wlan_ar900b_nopktlog;
2513 } else if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
2514 hif_state->host_ce_config =
2515 host_lowdesc_ce_cfg_wlan_ar900b;
2516 } else {
2517 hif_state->host_ce_config = host_ce_config_wlan_ar900b;
2518 }
2519
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302520 hif_state->target_ce_config = target_ce_config_wlan_ar900b;
2521 hif_state->target_ce_config_sz =
2522 sizeof(target_ce_config_wlan_ar900b);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002523
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002524 break;
2525
2526 case TARGET_TYPE_AR9888:
2527 case TARGET_TYPE_AR9888V2:
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05302528 if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
2529 hif_state->host_ce_config = host_lowdesc_ce_cfg_wlan_ar9888;
2530 } else {
2531 hif_state->host_ce_config = host_ce_config_wlan_ar9888;
2532 }
2533
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302534 hif_state->target_ce_config = target_ce_config_wlan_ar9888;
2535 hif_state->target_ce_config_sz =
2536 sizeof(target_ce_config_wlan_ar9888);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002537
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002538 break;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002539
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302540 case TARGET_TYPE_QCA8074:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -07002541 if (scn->bus_type == QDF_BUS_TYPE_PCI) {
2542 hif_state->host_ce_config =
2543 host_ce_config_wlan_qca8074_pci;
2544 hif_state->target_ce_config =
2545 target_ce_config_wlan_qca8074_pci;
2546 hif_state->target_ce_config_sz =
2547 sizeof(target_ce_config_wlan_qca8074_pci);
2548 } else {
2549 hif_state->host_ce_config = host_ce_config_wlan_qca8074;
2550 hif_state->target_ce_config =
2551 target_ce_config_wlan_qca8074;
2552 hif_state->target_ce_config_sz =
2553 sizeof(target_ce_config_wlan_qca8074);
2554 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302555 break;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002556 case TARGET_TYPE_QCA6290:
2557 hif_state->host_ce_config = host_ce_config_wlan_qca6290;
2558 hif_state->target_ce_config = target_ce_config_wlan_qca6290;
2559 hif_state->target_ce_config_sz =
2560 sizeof(target_ce_config_wlan_qca6290);
Houston Hoffman748e1a62017-03-30 17:20:42 -07002561
Houston Hoffman710af5a2016-11-22 21:59:03 -08002562 scn->ce_count = QCA_6290_CE_COUNT;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002563 break;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002564 }
Yun parkc80eea72017-10-06 15:33:36 -07002565 QDF_BUG(scn->ce_count <= CE_COUNT_MAX);
Houston Hoffman108da402016-03-14 21:11:24 -07002566}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002567
Houston Hoffman108da402016-03-14 21:11:24 -07002568/**
2569 * hif_ce_open() - do ce specific allocations
2570 * @hif_sc: pointer to hif context
2571 *
2572 * return: 0 for success or QDF_STATUS_E_NOMEM
2573 */
2574QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
2575{
2576 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002577
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302578 qdf_spinlock_create(&hif_state->irq_reg_lock);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302579 qdf_spinlock_create(&hif_state->keep_awake_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002580 return QDF_STATUS_SUCCESS;
2581}
2582
2583/**
2584 * hif_ce_close() - do ce specific free
2585 * @hif_sc: pointer to hif context
2586 */
2587void hif_ce_close(struct hif_softc *hif_sc)
2588{
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302589 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2590
2591 qdf_spinlock_destroy(&hif_state->irq_reg_lock);
Poddar, Siddarth725e9f52017-07-19 15:18:28 +05302592 qdf_spinlock_destroy(&hif_state->keep_awake_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002593}
2594
2595/**
2596 * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
2597 * @hif_sc: hif context
2598 *
2599 * uses state variables to support cleaning up when hif_config_ce fails.
2600 */
2601void hif_unconfig_ce(struct hif_softc *hif_sc)
2602{
2603 int pipe_num;
2604 struct HIF_CE_pipe_info *pipe_info;
2605 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2606
2607 for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
2608 pipe_info = &hif_state->pipe_info[pipe_num];
2609 if (pipe_info->ce_hdl) {
2610 ce_unregister_irq(hif_state, (1 << pipe_num));
Houston Hoffman108da402016-03-14 21:11:24 -07002611 ce_fini(pipe_info->ce_hdl);
2612 pipe_info->ce_hdl = NULL;
2613 pipe_info->buf_sz = 0;
Houston Hoffman03f46572016-12-12 12:53:56 -08002614 qdf_spinlock_destroy(&pipe_info->recv_bufs_needed_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002615 }
2616 }
Houston Hoffman108da402016-03-14 21:11:24 -07002617 if (hif_sc->athdiag_procfs_inited) {
2618 athdiag_procfs_remove();
2619 hif_sc->athdiag_procfs_inited = false;
2620 }
2621}
2622
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002623#ifdef CONFIG_BYPASS_QMI
2624#define FW_SHARED_MEM (2 * 1024 * 1024)
2625
2626/**
2627 * hif_post_static_buf_to_target() - post static buffer to WLAN FW
2628 * @scn: pointer to HIF structure
2629 *
2630 * WLAN FW needs 2MB memory from DDR when QMI is disabled.
2631 *
2632 * Return: void
2633 */
2634static void hif_post_static_buf_to_target(struct hif_softc *scn)
2635{
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002636 void *target_va;
2637 phys_addr_t target_pa;
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002638
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002639 target_va = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev,
2640 FW_SHARED_MEM, &target_pa);
2641 if (NULL == target_va) {
2642 HIF_TRACE("Memory allocation failed could not post target buf");
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002643 return;
2644 }
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002645 hif_write32_mb(scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
2646 HIF_TRACE("target va %pK target pa %pa", target_va, &target_pa);
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002647}
2648#else
2649static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
2650{
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002651}
2652#endif
2653
Houston Hoffman579c02f2017-08-02 01:57:38 -07002654static int hif_srng_sleep_state_adjust(struct hif_softc *scn, bool sleep_ok,
2655 bool wait_for_it)
2656{
2657 /* todo */
2658 return 0;
2659}
2660
Houston Hoffman108da402016-03-14 21:11:24 -07002661/**
2662 * hif_config_ce() - configure copy engines
2663 * @scn: hif context
2664 *
2665 * Prepares fw, copy engine hardware and host sw according
2666 * to the attributes selected by hif_ce_prepare_config.
2667 *
2668 * also calls athdiag_procfs_init
2669 *
2670 * return: 0 for success nonzero for failure.
2671 */
2672int hif_config_ce(struct hif_softc *scn)
2673{
2674 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2675 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2676 struct HIF_CE_pipe_info *pipe_info;
2677 int pipe_num;
Houston Hoffman85925072016-05-06 17:02:18 -07002678 struct CE_state *ce_state;
c_cgodavfda96ad2017-09-07 16:16:00 +05302679
Houston Hoffman108da402016-03-14 21:11:24 -07002680#ifdef ADRASTEA_SHADOW_REGISTERS
2681 int i;
2682#endif
2683 QDF_STATUS rv = QDF_STATUS_SUCCESS;
2684
2685 scn->notice_send = true;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002686
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002687 hif_post_static_buf_to_target(scn);
2688
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002689 hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
Houston Hoffman108da402016-03-14 21:11:24 -07002690
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002691 hif_config_rri_on_ddr(scn);
2692
Houston Hoffman579c02f2017-08-02 01:57:38 -07002693 if (ce_srng_based(scn))
2694 scn->bus_ops.hif_target_sleep_state_adjust =
2695 &hif_srng_sleep_state_adjust;
2696
c_cgodavfda96ad2017-09-07 16:16:00 +05302697 /* Initialise the CE debug history sysfs interface inputs ce_id and
2698 * index. Disable data storing
2699 */
2700 reset_ce_debug_history(scn);
2701
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002702 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
2703 struct CE_attr *attr;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002704
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002705 pipe_info = &hif_state->pipe_info[pipe_num];
2706 pipe_info->pipe_num = pipe_num;
2707 pipe_info->HIF_CE_state = hif_state;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302708 attr = &hif_state->host_ce_config[pipe_num];
Karunakar Dasinenif61cb072016-09-29 11:50:45 -07002709
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002710 pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
Houston Hoffman85925072016-05-06 17:02:18 -07002711 ce_state = scn->ce_id_to_state[pipe_num];
Houston Hoffman03f46572016-12-12 12:53:56 -08002712 qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302713 QDF_ASSERT(pipe_info->ce_hdl != NULL);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002714 if (pipe_info->ce_hdl == NULL) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302715 rv = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002716 A_TARGET_ACCESS_UNLIKELY(scn);
2717 goto err;
2718 }
2719
Dhanashri Atre991ee4d2017-05-03 19:03:10 -07002720 ce_state->lro_data = qdf_lro_init();
2721
Kiran Venkatappae17e3b62017-02-10 16:31:49 +05302722 if (attr->flags & CE_ATTR_DIAG) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002723 /* Reserve the ultimate CE for
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002724 * Diagnostic Window support
2725 */
Houston Hoffmanc1d9a412016-03-30 21:07:57 -07002726 hif_state->ce_diag = pipe_info->ce_hdl;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002727 continue;
2728 }
2729
Houston Hoffman85925072016-05-06 17:02:18 -07002730 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
2731 (ce_state->htt_rx_data))
2732 continue;
2733
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302734 pipe_info->buf_sz = (qdf_size_t) (attr->src_sz_max);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002735 if (attr->dest_nentries > 0) {
2736 atomic_set(&pipe_info->recv_bufs_needed,
2737 init_buffer_count(attr->dest_nentries - 1));
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302738 /*SRNG based CE has one entry less */
2739 if (ce_srng_based(scn))
2740 atomic_dec(&pipe_info->recv_bufs_needed);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002741 } else {
2742 atomic_set(&pipe_info->recv_bufs_needed, 0);
2743 }
2744 ce_tasklet_init(hif_state, (1 << pipe_num));
2745 ce_register_irq(hif_state, (1 << pipe_num));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002746 }
2747
2748 if (athdiag_procfs_init(scn) != 0) {
2749 A_TARGET_ACCESS_UNLIKELY(scn);
2750 goto err;
2751 }
2752 scn->athdiag_procfs_inited = true;
2753
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -08002754 HIF_DBG("%s: ce_init done", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002755
Houston Hoffman108da402016-03-14 21:11:24 -07002756 init_tasklet_workers(hif_hdl);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002757
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -08002758 HIF_DBG("%s: X, ret = %d", __func__, rv);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002759
2760#ifdef ADRASTEA_SHADOW_REGISTERS
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -08002761 HIF_DBG("%s, Using Shadow Registers instead of CE Registers", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002762 for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -08002763 HIF_DBG("%s Shadow Register%d is mapped to address %x",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002764 __func__, i,
2765 (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
2766 }
2767#endif
2768
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302769 return rv != QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002770
2771err:
2772 /* Failure, so clean up */
Houston Hoffman108da402016-03-14 21:11:24 -07002773 hif_unconfig_ce(scn);
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002774 HIF_TRACE("%s: X, ret = %d", __func__, rv);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302775 return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002776}
2777
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002778#ifdef WLAN_FEATURE_FASTPATH
2779/**
2780 * hif_ce_fastpath_cb_register() - Register callback for fastpath msg handler
2781 * @handler: Callback funtcion
2782 * @context: handle for callback function
2783 *
2784 * Return: QDF_STATUS_SUCCESS on success or QDF_STATUS_E_FAILURE
2785 */
Houston Hoffman127467f2016-04-26 22:37:14 -07002786int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
2787 fastpath_msg_handler handler,
2788 void *context)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002789{
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002790 struct CE_state *ce_state;
Houston Hoffman127467f2016-04-26 22:37:14 -07002791 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002792 int i;
2793
Himanshu Agarwal2a924592016-06-30 18:04:14 +05302794 if (!scn) {
2795 HIF_ERROR("%s: scn is NULL", __func__);
2796 QDF_ASSERT(0);
2797 return QDF_STATUS_E_FAILURE;
2798 }
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002799
2800 if (!scn->fastpath_mode_on) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002801 HIF_WARN("%s: Fastpath mode disabled", __func__);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002802 return QDF_STATUS_E_FAILURE;
2803 }
2804
Houston Hoffmand6f946c2016-04-06 15:16:00 -07002805 for (i = 0; i < scn->ce_count; i++) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002806 ce_state = scn->ce_id_to_state[i];
2807 if (ce_state->htt_rx_data) {
2808 ce_state->fastpath_handler = handler;
2809 ce_state->context = context;
2810 }
2811 }
2812
2813 return QDF_STATUS_SUCCESS;
2814}
Pratik Gandhidc82a772018-01-30 18:57:05 +05302815qdf_export_symbol(hif_ce_fastpath_cb_register);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002816#endif
2817
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002818#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08002819/**
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302820 * hif_ce_ipa_get_ce_resource() - get uc resource on hif
Leo Changd85f78d2015-11-13 10:55:34 -08002821 * @scn: bus context
2822 * @ce_sr_base_paddr: copyengine source ring base physical address
2823 * @ce_sr_ring_size: copyengine source ring size
2824 * @ce_reg_paddr: copyengine register physical address
2825 *
2826 * IPA micro controller data path offload feature enabled,
2827 * HIF should release copy engine related resource information to IPA UC
2828 * IPA UC will access hardware resource with released information
2829 *
2830 * Return: None
2831 */
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302832void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302833 qdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002834 uint32_t *ce_sr_ring_size,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302835 qdf_dma_addr_t *ce_reg_paddr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002836{
Komal Seelam02cf2f82016-02-22 20:44:25 +05302837 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002838 struct HIF_CE_pipe_info *pipe_info =
2839 &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
2840 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
2841
2842 ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size,
2843 ce_reg_paddr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002844}
2845#endif /* IPA_OFFLOAD */
2846
2847
2848#ifdef ADRASTEA_SHADOW_REGISTERS
2849
2850/*
Manikandan Mohanafd6e882017-04-07 17:46:41 -07002851 * Current shadow register config
2852 *
2853 * -----------------------------------------------------------
2854 * Shadow Register | CE | src/dst write index
2855 * -----------------------------------------------------------
2856 * 0 | 0 | src
2857 * 1 No Config - Doesn't point to anything
2858 * 2 No Config - Doesn't point to anything
2859 * 3 | 3 | src
2860 * 4 | 4 | src
2861 * 5 | 5 | src
2862 * 6 No Config - Doesn't point to anything
2863 * 7 | 7 | src
2864 * 8 No Config - Doesn't point to anything
2865 * 9 No Config - Doesn't point to anything
2866 * 10 No Config - Doesn't point to anything
2867 * 11 No Config - Doesn't point to anything
2868 * -----------------------------------------------------------
2869 * 12 No Config - Doesn't point to anything
2870 * 13 | 1 | dst
2871 * 14 | 2 | dst
2872 * 15 No Config - Doesn't point to anything
2873 * 16 No Config - Doesn't point to anything
2874 * 17 No Config - Doesn't point to anything
2875 * 18 No Config - Doesn't point to anything
2876 * 19 | 7 | dst
2877 * 20 | 8 | dst
2878 * 21 No Config - Doesn't point to anything
2879 * 22 No Config - Doesn't point to anything
2880 * 23 No Config - Doesn't point to anything
2881 * -----------------------------------------------------------
2882 *
2883 *
2884 * ToDo - Move shadow register config to following in the future
2885 * This helps free up a block of shadow registers towards the end.
2886 * Can be used for other purposes
2887 *
2888 * -----------------------------------------------------------
2889 * Shadow Register | CE | src/dst write index
2890 * -----------------------------------------------------------
2891 * 0 | 0 | src
2892 * 1 | 3 | src
2893 * 2 | 4 | src
2894 * 3 | 5 | src
2895 * 4 | 7 | src
2896 * -----------------------------------------------------------
2897 * 5 | 1 | dst
2898 * 6 | 2 | dst
2899 * 7 | 7 | dst
2900 * 8 | 8 | dst
2901 * -----------------------------------------------------------
2902 * 9 No Config - Doesn't point to anything
2903 * 12 No Config - Doesn't point to anything
2904 * 13 No Config - Doesn't point to anything
2905 * 14 No Config - Doesn't point to anything
2906 * 15 No Config - Doesn't point to anything
2907 * 16 No Config - Doesn't point to anything
2908 * 17 No Config - Doesn't point to anything
2909 * 18 No Config - Doesn't point to anything
2910 * 19 No Config - Doesn't point to anything
2911 * 20 No Config - Doesn't point to anything
2912 * 21 No Config - Doesn't point to anything
2913 * 22 No Config - Doesn't point to anything
2914 * 23 No Config - Doesn't point to anything
2915 * -----------------------------------------------------------
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002916*/
2917
Komal Seelam644263d2016-02-22 20:45:49 +05302918u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002919{
2920 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002921 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002922
Houston Hoffmane6330442016-02-26 12:19:11 -08002923 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002924 case 0:
2925 addr = SHADOW_VALUE0;
2926 break;
2927 case 3:
2928 addr = SHADOW_VALUE3;
2929 break;
2930 case 4:
2931 addr = SHADOW_VALUE4;
2932 break;
2933 case 5:
2934 addr = SHADOW_VALUE5;
2935 break;
2936 case 7:
2937 addr = SHADOW_VALUE7;
2938 break;
2939 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002940 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302941 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002942 }
2943 return addr;
2944
2945}
2946
Komal Seelam644263d2016-02-22 20:45:49 +05302947u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002948{
2949 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002950 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002951
Houston Hoffmane6330442016-02-26 12:19:11 -08002952 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002953 case 1:
2954 addr = SHADOW_VALUE13;
2955 break;
2956 case 2:
2957 addr = SHADOW_VALUE14;
2958 break;
Vishwajith Upendra70efc752016-04-18 11:23:49 -07002959 case 5:
2960 addr = SHADOW_VALUE17;
2961 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002962 case 7:
2963 addr = SHADOW_VALUE19;
2964 break;
2965 case 8:
2966 addr = SHADOW_VALUE20;
2967 break;
Houston Hoffmane6330442016-02-26 12:19:11 -08002968 case 9:
2969 addr = SHADOW_VALUE21;
2970 break;
2971 case 10:
2972 addr = SHADOW_VALUE22;
2973 break;
Nirav Shah75cc5c82016-05-25 10:52:38 +05302974 case 11:
2975 addr = SHADOW_VALUE23;
2976 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002977 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002978 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302979 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002980 }
2981
2982 return addr;
2983
2984}
2985#endif
2986
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002987#if defined(FEATURE_LRO)
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002988void *hif_ce_get_lro_ctx(struct hif_opaque_softc *hif_hdl, int ctx_id)
2989{
2990 struct CE_state *ce_state;
2991 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
2992
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002993 ce_state = scn->ce_id_to_state[ctx_id];
2994
2995 return ce_state->lro_data;
2996}
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002997#endif
Sanjay Devnanic319c822015-11-06 16:44:28 -08002998
2999/**
3000 * hif_map_service_to_pipe() - returns the ce ids pertaining to
3001 * this service
Komal Seelam644263d2016-02-22 20:45:49 +05303002 * @scn: hif_softc pointer.
Sanjay Devnanic319c822015-11-06 16:44:28 -08003003 * @svc_id: Service ID for which the mapping is needed.
3004 * @ul_pipe: address of the container in which ul pipe is returned.
3005 * @dl_pipe: address of the container in which dl pipe is returned.
3006 * @ul_is_polled: address of the container in which a bool
3007 * indicating if the UL CE for this service
3008 * is polled is returned.
3009 * @dl_is_polled: address of the container in which a bool
3010 * indicating if the DL CE for this service
3011 * is polled is returned.
3012 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003013 * Return: Indicates whether the service has been found in the table.
3014 * Upon return, ul_is_polled is updated only if ul_pipe is updated.
3015 * There will be warning logs if either leg has not been updated
3016 * because it missed the entry in the table (but this is not an err).
Sanjay Devnanic319c822015-11-06 16:44:28 -08003017 */
Komal Seelam5584a7c2016-02-24 19:22:48 +05303018int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
Sanjay Devnanic319c822015-11-06 16:44:28 -08003019 uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
3020 int *dl_is_polled)
3021{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003022 int status = QDF_STATUS_E_INVAL;
Sanjay Devnanic319c822015-11-06 16:44:28 -08003023 unsigned int i;
3024 struct service_to_pipe element;
Sanjay Devnanic319c822015-11-06 16:44:28 -08003025 struct service_to_pipe *tgt_svc_map_to_use;
Houston Hoffman748e1a62017-03-30 17:20:42 -07003026 uint32_t sz_tgt_svc_map_to_use;
Komal Seelambd7c51d2016-02-24 10:27:30 +05303027 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Houston Hoffman748e1a62017-03-30 17:20:42 -07003028 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003029 bool dl_updated = false;
3030 bool ul_updated = false;
Sanjay Devnanic319c822015-11-06 16:44:28 -08003031
Houston Hoffman748e1a62017-03-30 17:20:42 -07003032 hif_select_service_to_pipe_map(scn, &tgt_svc_map_to_use,
3033 &sz_tgt_svc_map_to_use);
Sanjay Devnanic319c822015-11-06 16:44:28 -08003034
3035 *dl_is_polled = 0; /* polling for received messages not supported */
3036
3037 for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
3038
3039 memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
3040 if (element.service_id == svc_id) {
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003041 if (element.pipedir == PIPEDIR_OUT) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08003042 *ul_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003043 *ul_is_polled =
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05303044 (hif_state->host_ce_config[*ul_pipe].flags &
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003045 CE_ATTR_DISABLE_INTR) != 0;
3046 ul_updated = true;
3047 } else if (element.pipedir == PIPEDIR_IN) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08003048 *dl_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003049 dl_updated = true;
3050 }
3051 status = QDF_STATUS_SUCCESS;
Sanjay Devnanic319c822015-11-06 16:44:28 -08003052 }
3053 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003054 if (ul_updated == false)
Poddar, Siddarthf53a9b02017-03-14 20:30:17 +05303055 HIF_INFO("%s: ul pipe is NOT updated for service %d",
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003056 __func__, svc_id);
3057 if (dl_updated == false)
Poddar, Siddarthf53a9b02017-03-14 20:30:17 +05303058 HIF_INFO("%s: dl pipe is NOT updated for service %d",
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07003059 __func__, svc_id);
Sanjay Devnanic319c822015-11-06 16:44:28 -08003060
3061 return status;
3062}
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003063
3064#ifdef SHADOW_REG_DEBUG
Komal Seelam644263d2016-02-22 20:45:49 +05303065inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003066 uint32_t CE_ctrl_addr)
3067{
3068 uint32_t read_from_hw, srri_from_ddr = 0;
3069
3070 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
3071
3072 srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
3073
3074 if (read_from_hw != srri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07003075 HIF_ERROR("%s: error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
3076 __func__, srri_from_ddr, read_from_hw,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003077 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303078 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003079 }
3080 return srri_from_ddr;
3081}
3082
3083
Komal Seelam644263d2016-02-22 20:45:49 +05303084inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003085 uint32_t CE_ctrl_addr)
3086{
3087 uint32_t read_from_hw, drri_from_ddr = 0;
3088
3089 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
3090
3091 drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
3092
3093 if (read_from_hw != drri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07003094 HIF_ERROR("error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003095 drri_from_ddr, read_from_hw,
3096 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303097 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003098 }
3099 return drri_from_ddr;
3100}
3101
3102#endif
3103
Houston Hoffman3d0cda82015-12-03 13:25:05 -08003104#ifdef ADRASTEA_RRI_ON_DDR
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003105/**
3106 * hif_get_src_ring_read_index(): Called to get the SRRI
3107 *
Komal Seelam644263d2016-02-22 20:45:49 +05303108 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003109 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
3110 *
3111 * This function returns the SRRI to the caller. For CEs that
3112 * dont have interrupts enabled, we look at the DDR based SRRI
3113 *
3114 * Return: SRRI
3115 */
Komal Seelam644263d2016-02-22 20:45:49 +05303116inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003117 uint32_t CE_ctrl_addr)
3118{
3119 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05303120 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003121
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05303122 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Govind Singhbc679dc2017-06-08 12:33:59 +05303123 if (attr.flags & CE_ATTR_DISABLE_INTR) {
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003124 return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
Govind Singhbc679dc2017-06-08 12:33:59 +05303125 } else {
3126 if (TARGET_REGISTER_ACCESS_ALLOWED(scn))
3127 return A_TARGET_READ(scn,
3128 (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
3129 else
3130 return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn,
3131 CE_ctrl_addr);
3132 }
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003133}
3134
3135/**
3136 * hif_get_dst_ring_read_index(): Called to get the DRRI
3137 *
Komal Seelam644263d2016-02-22 20:45:49 +05303138 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003139 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
3140 *
3141 * This function returns the DRRI to the caller. For CEs that
3142 * dont have interrupts enabled, we look at the DDR based DRRI
3143 *
3144 * Return: DRRI
3145 */
Komal Seelam644263d2016-02-22 20:45:49 +05303146inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003147 uint32_t CE_ctrl_addr)
3148{
3149 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05303150 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003151
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05303152 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003153
Govind Singhbc679dc2017-06-08 12:33:59 +05303154 if (attr.flags & CE_ATTR_DISABLE_INTR) {
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003155 return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
Govind Singhbc679dc2017-06-08 12:33:59 +05303156 } else {
3157 if (TARGET_REGISTER_ACCESS_ALLOWED(scn))
3158 return A_TARGET_READ(scn,
3159 (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
3160 else
3161 return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn,
3162 CE_ctrl_addr);
3163 }
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003164}
3165
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003166/**
3167 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
3168 *
Komal Seelam644263d2016-02-22 20:45:49 +05303169 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003170 *
3171 * This function allocates non cached memory on ddr and sends
3172 * the physical address of this memory to the CE hardware. The
3173 * hardware updates the RRI on this particular location.
3174 *
3175 * Return: None
3176 */
Komal Seelam644263d2016-02-22 20:45:49 +05303177static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003178{
3179 unsigned int i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303180 qdf_dma_addr_t paddr_rri_on_ddr;
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003181 uint32_t high_paddr, low_paddr;
Manikandan Mohanafd6e882017-04-07 17:46:41 -07003182
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003183 scn->vaddr_rri_on_ddr =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303184 (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
3185 scn->qdf_dev->dev, (CE_COUNT*sizeof(uint32_t)),
3186 &paddr_rri_on_ddr);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003187
Arunk Khandavallie14e8e92017-04-03 21:40:26 +05303188 scn->paddr_rri_on_ddr = paddr_rri_on_ddr;
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003189 low_paddr = BITS0_TO_31(paddr_rri_on_ddr);
3190 high_paddr = BITS32_TO_35(paddr_rri_on_ddr);
3191
Srinivas Girigowda6e0cfd92017-03-09 15:49:59 -08003192 HIF_DBG("%s using srri and drri from DDR", __func__);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003193
3194 WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
3195 WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
3196
3197 for (i = 0; i < CE_COUNT; i++)
3198 CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
3199
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303200 qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t));
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003201
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003202}
3203#else
3204
3205/**
3206 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
3207 *
Komal Seelam644263d2016-02-22 20:45:49 +05303208 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003209 *
3210 * This is a dummy implementation for platforms that don't
3211 * support this functionality.
3212 *
3213 * Return: None
3214 */
Komal Seelam644263d2016-02-22 20:45:49 +05303215static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003216{
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08003217}
3218#endif
Govind Singh2443fb32016-01-13 17:44:48 +05303219
3220/**
3221 * hif_dump_ce_registers() - dump ce registers
Komal Seelam5584a7c2016-02-24 19:22:48 +05303222 * @scn: hif_opaque_softc pointer.
Govind Singh2443fb32016-01-13 17:44:48 +05303223 *
3224 * Output the copy engine registers
3225 *
3226 * Return: 0 for success or error code
3227 */
Komal Seelam644263d2016-02-22 20:45:49 +05303228int hif_dump_ce_registers(struct hif_softc *scn)
Govind Singh2443fb32016-01-13 17:44:48 +05303229{
Komal Seelam5584a7c2016-02-24 19:22:48 +05303230 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Govind Singh2443fb32016-01-13 17:44:48 +05303231 uint32_t ce_reg_address = CE0_BASE_ADDRESS;
Houston Hoffman6296c3e2016-07-12 18:43:32 -07003232 uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
Govind Singh2443fb32016-01-13 17:44:48 +05303233 uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
3234 uint16_t i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303235 QDF_STATUS status;
Govind Singh2443fb32016-01-13 17:44:48 +05303236
Houston Hoffmand6f946c2016-04-06 15:16:00 -07003237 for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
3238 if (scn->ce_id_to_state[i] == NULL) {
3239 HIF_DBG("CE%d not used.", i);
3240 continue;
3241 }
3242
Komal Seelam644263d2016-02-22 20:45:49 +05303243 status = hif_diag_read_mem(hif_hdl, ce_reg_address,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07003244 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05303245 ce_reg_word_size * sizeof(uint32_t));
3246
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303247 if (status != QDF_STATUS_SUCCESS) {
Manikandan Mohanafd6e882017-04-07 17:46:41 -07003248 HIF_ERROR("Dumping CE register failed!");
3249 return -EACCES;
Govind Singh2443fb32016-01-13 17:44:48 +05303250 }
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05303251 HIF_ERROR("CE%d=>\n", i);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05303252 qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07003253 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05303254 ce_reg_word_size * sizeof(uint32_t));
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05303255 qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d\n", (ce_reg_address
3256 + SR_WR_INDEX_ADDRESS),
3257 ce_reg_values[SR_WR_INDEX_ADDRESS/4]);
3258 qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d\n", (ce_reg_address
3259 + CURRENT_SRRI_ADDRESS),
3260 ce_reg_values[CURRENT_SRRI_ADDRESS/4]);
3261 qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d\n", (ce_reg_address
3262 + DST_WR_INDEX_ADDRESS),
3263 ce_reg_values[DST_WR_INDEX_ADDRESS/4]);
3264 qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d\n", (ce_reg_address
3265 + CURRENT_DRRI_ADDRESS),
3266 ce_reg_values[CURRENT_DRRI_ADDRESS/4]);
3267 qdf_print("---\n");
Govind Singh2443fb32016-01-13 17:44:48 +05303268 }
Govind Singh2443fb32016-01-13 17:44:48 +05303269 return 0;
3270}
Pratik Gandhidc82a772018-01-30 18:57:05 +05303271qdf_export_symbol(hif_dump_ce_registers);
Houston Hoffman85925072016-05-06 17:02:18 -07003272#ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
3273struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
3274 struct hif_pipe_addl_info *hif_info, uint32_t pipe)
3275{
3276 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3277 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
3278 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
3279 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
3280 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
3281 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
3282 struct CE_ring_state *src_ring = ce_state->src_ring;
3283 struct CE_ring_state *dest_ring = ce_state->dest_ring;
3284
3285 if (src_ring) {
3286 hif_info->ul_pipe.nentries = src_ring->nentries;
3287 hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
3288 hif_info->ul_pipe.sw_index = src_ring->sw_index;
3289 hif_info->ul_pipe.write_index = src_ring->write_index;
3290 hif_info->ul_pipe.hw_index = src_ring->hw_index;
3291 hif_info->ul_pipe.base_addr_CE_space =
3292 src_ring->base_addr_CE_space;
3293 hif_info->ul_pipe.base_addr_owner_space =
3294 src_ring->base_addr_owner_space;
3295 }
3296
3297
3298 if (dest_ring) {
3299 hif_info->dl_pipe.nentries = dest_ring->nentries;
3300 hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
3301 hif_info->dl_pipe.sw_index = dest_ring->sw_index;
3302 hif_info->dl_pipe.write_index = dest_ring->write_index;
3303 hif_info->dl_pipe.hw_index = dest_ring->hw_index;
3304 hif_info->dl_pipe.base_addr_CE_space =
3305 dest_ring->base_addr_CE_space;
3306 hif_info->dl_pipe.base_addr_owner_space =
3307 dest_ring->base_addr_owner_space;
3308 }
3309
3310 hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
3311 hif_info->ctrl_addr = ce_state->ctrl_addr;
3312
3313 return hif_info;
3314}
Pratik Gandhidc82a772018-01-30 18:57:05 +05303315qdf_export_symbol(hif_get_addl_pipe_info);
Houston Hoffman85925072016-05-06 17:02:18 -07003316
3317uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
3318{
3319 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3320
3321 scn->nss_wifi_ol_mode = mode;
3322 return 0;
3323}
Pratik Gandhidc82a772018-01-30 18:57:05 +05303324qdf_export_symbol(hif_set_nss_wifiol_mode);
Houston Hoffman85925072016-05-06 17:02:18 -07003325#endif
3326
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05303327void hif_set_attribute(struct hif_opaque_softc *osc, uint8_t hif_attrib)
3328{
3329 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3330 scn->hif_attribute = hif_attrib;
3331}
3332
Yun Park3fb36442017-08-17 17:37:53 -07003333
3334/* disable interrupts (only applicable for legacy copy engine currently */
Houston Hoffman85925072016-05-06 17:02:18 -07003335void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
3336{
3337 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3338 struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
3339 uint32_t ctrl_addr = CE_state->ctrl_addr;
3340
3341 Q_TARGET_ACCESS_BEGIN(scn);
3342 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
3343 Q_TARGET_ACCESS_END(scn);
3344}
Pratik Gandhidc82a772018-01-30 18:57:05 +05303345qdf_export_symbol(hif_disable_interrupt);
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303346
3347/**
3348 * hif_fw_event_handler() - hif fw event handler
3349 * @hif_state: pointer to hif ce state structure
3350 *
3351 * Process fw events and raise HTC callback to process fw events.
3352 *
3353 * Return: none
3354 */
3355static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
3356{
3357 struct hif_msg_callbacks *msg_callbacks =
3358 &hif_state->msg_callbacks_current;
3359
3360 if (!msg_callbacks->fwEventHandler)
3361 return;
3362
3363 msg_callbacks->fwEventHandler(msg_callbacks->Context,
3364 QDF_STATUS_E_FAILURE);
3365}
3366
3367#ifndef QCA_WIFI_3_0
3368/**
3369 * hif_fw_interrupt_handler() - FW interrupt handler
3370 * @irq: irq number
3371 * @arg: the user pointer
3372 *
3373 * Called from the PCI interrupt handler when a
3374 * firmware-generated interrupt to the Host.
3375 *
Yun Park3fb36442017-08-17 17:37:53 -07003376 * only registered for legacy ce devices
3377 *
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303378 * Return: status of handled irq
3379 */
3380irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
3381{
3382 struct hif_softc *scn = arg;
3383 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3384 uint32_t fw_indicator_address, fw_indicator;
3385
3386 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
3387 return ATH_ISR_NOSCHED;
3388
3389 fw_indicator_address = hif_state->fw_indicator_address;
3390 /* For sudden unplug this will return ~0 */
3391 fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
3392
3393 if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
3394 /* ACK: clear Target-side pending event */
3395 A_TARGET_WRITE(scn, fw_indicator_address,
3396 fw_indicator & ~FW_IND_EVENT_PENDING);
3397 if (Q_TARGET_ACCESS_END(scn) < 0)
3398 return ATH_ISR_SCHED;
3399
3400 if (hif_state->started) {
3401 hif_fw_event_handler(hif_state);
3402 } else {
3403 /*
3404 * Probable Target failure before we're prepared
3405 * to handle it. Generally unexpected.
3406 */
3407 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
3408 ("%s: Early firmware event indicated\n",
3409 __func__));
3410 }
3411 } else {
3412 if (Q_TARGET_ACCESS_END(scn) < 0)
3413 return ATH_ISR_SCHED;
3414 }
3415
3416 return ATH_ISR_SCHED;
3417}
3418#else
3419irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
3420{
3421 return ATH_ISR_SCHED;
3422}
3423#endif /* #ifdef QCA_WIFI_3_0 */
3424
3425
3426/**
3427 * hif_wlan_disable(): call the platform driver to disable wlan
3428 * @scn: HIF Context
3429 *
3430 * This function passes the con_mode to platform driver to disable
3431 * wlan.
3432 *
3433 * Return: void
3434 */
3435void hif_wlan_disable(struct hif_softc *scn)
3436{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003437 enum pld_driver_mode mode;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303438 uint32_t con_mode = hif_get_conparam(scn);
3439
Vinay Adella2a6bd8a2018-02-07 20:07:37 +05303440 if (scn->target_status == TARGET_STATUS_RESET)
3441 return;
3442
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303443 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003444 mode = PLD_FTM;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303445 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003446 mode = PLD_EPPING;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303447 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003448 mode = PLD_MISSION;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303449
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003450 pld_wlan_disable(scn->qdf_dev->dev, mode);
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303451}
Dustin Brown6bdbda52016-09-27 15:52:30 -07003452
Dustin Brown6834d322017-03-20 15:02:48 -07003453int hif_get_wake_ce_id(struct hif_softc *scn, uint8_t *ce_id)
3454{
3455 QDF_STATUS status;
3456 uint8_t ul_pipe, dl_pipe;
3457 int ul_is_polled, dl_is_polled;
3458
3459 /* DL pipe for HTC_CTRL_RSVD_SVC should map to the wake CE */
3460 status = hif_map_service_to_pipe(GET_HIF_OPAQUE_HDL(scn),
3461 HTC_CTRL_RSVD_SVC,
3462 &ul_pipe, &dl_pipe,
3463 &ul_is_polled, &dl_is_polled);
3464 if (status) {
3465 HIF_ERROR("%s: failed to map pipe: %d", __func__, status);
3466 return qdf_status_to_os_return(status);
3467 }
3468
3469 *ce_id = dl_pipe;
3470
3471 return 0;
3472}