blob: b86f9e4bc4de03f32526194dd5bf13b313688895 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Prashanth Bhattadfcae6b2015-12-04 11:56:47 -08002 * Copyright (c) 2013-2016 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>
35#include "regtable.h"
36#define ATH_MODULE_NAME hif
37#include <a_debug.h>
38#include "hif_main.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080039#include "ce_api.h"
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +053040#include "qdf_trace.h"
Yuanyuan Liufd594c22016-04-25 13:59:19 -070041#include "pld_common.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080042#include "hif_debug.h"
43#include "ce_internal.h"
44#include "ce_reg.h"
45#include "ce_assignment.h"
46#include "ce_tasklet.h"
Houston Hoffman56e0d702016-05-05 17:48:06 -070047#ifndef CONFIG_WIN
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080048#include "qwlan_version.h"
Houston Hoffman56e0d702016-05-05 17:48:06 -070049#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080050
51#define CE_POLL_TIMEOUT 10 /* ms */
52
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053053#define AGC_DUMP 1
54#define CHANINFO_DUMP 2
55#define BB_WATCHDOG_DUMP 3
56#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
57#define PCIE_ACCESS_DUMP 4
58#endif
59#include "mp_dev.h"
60
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080061/* Forward references */
62static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info);
63
64/*
65 * Fix EV118783, poll to check whether a BMI response comes
66 * other than waiting for the interruption which may be lost.
67 */
68/* #define BMI_RSP_POLLING */
69#define BMI_RSP_TO_MILLISEC 1000
70
Yuanyuan Liua7a282f2016-04-15 12:55:04 -070071#ifdef CONFIG_BYPASS_QMI
72#define BYPASS_QMI 1
73#else
74#define BYPASS_QMI 0
75#endif
76
Houston Hoffmanabd00772016-05-06 17:02:48 -070077#ifdef CONFIG_WIN
Pratik Gandhi424c62e2016-08-23 19:47:09 +053078#if ENABLE_10_4_FW_HDR
Houston Hoffmanabd00772016-05-06 17:02:48 -070079#define WDI_IPA_SERVICE_GROUP 5
80#define WDI_IPA_TX_SVC MAKE_SERVICE_ID(WDI_IPA_SERVICE_GROUP, 0)
81#define HTT_DATA2_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 1)
82#define HTT_DATA3_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 2)
Pratik Gandhi424c62e2016-08-23 19:47:09 +053083#endif /* ENABLE_10_4_FW_HDR */
Houston Hoffmanabd00772016-05-06 17:02:48 -070084#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080085
Komal Seelam644263d2016-02-22 20:45:49 +053086static int hif_post_recv_buffers(struct hif_softc *scn);
87static void hif_config_rri_on_ddr(struct hif_softc *scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080088
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053089/**
90 * hif_target_access_log_dump() - dump access log
91 *
92 * dump access log
93 *
94 * Return: n/a
95 */
96#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
97static void hif_target_access_log_dump(void)
98{
99 hif_target_dump_access_log();
100}
101#endif
102
103
104void hif_trigger_dump(struct hif_opaque_softc *hif_ctx,
105 uint8_t cmd_id, bool start)
106{
107 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
108
109 switch (cmd_id) {
110 case AGC_DUMP:
111 if (start)
112 priv_start_agc(scn);
113 else
114 priv_dump_agc(scn);
115 break;
116 case CHANINFO_DUMP:
117 if (start)
118 priv_start_cap_chaninfo(scn);
119 else
120 priv_dump_chaninfo(scn);
121 break;
122 case BB_WATCHDOG_DUMP:
123 priv_dump_bbwatchdog(scn);
124 break;
125#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
126 case PCIE_ACCESS_DUMP:
127 hif_target_access_log_dump();
128 break;
129#endif
130 default:
131 HIF_ERROR("%s: Invalid htc dump command", __func__);
132 break;
133 }
134}
135
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800136static void ce_poll_timeout(void *arg)
137{
138 struct CE_state *CE_state = (struct CE_state *)arg;
139 if (CE_state->timer_inited) {
140 ce_per_engine_service(CE_state->scn, CE_state->id);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530141 qdf_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800142 }
143}
144
145static unsigned int roundup_pwr2(unsigned int n)
146{
147 int i;
148 unsigned int test_pwr2;
149
150 if (!(n & (n - 1)))
151 return n; /* already a power of 2 */
152
153 test_pwr2 = 4;
154 for (i = 0; i < 29; i++) {
155 if (test_pwr2 > n)
156 return test_pwr2;
157 test_pwr2 = test_pwr2 << 1;
158 }
159
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530160 QDF_ASSERT(0); /* n too large */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800161 return 0;
162}
163
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700164#define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C
165#define ADRASTEA_DST_WR_INDEX_OFFSET 0x40
166
167static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = {
168 { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
169 { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
170 { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
171 { 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
172 { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
173 { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
174 { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
175 { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
176 { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
Houston Hoffmane6330442016-02-26 12:19:11 -0800177#ifdef QCA_WIFI_3_0_ADRASTEA
178 { 9, ADRASTEA_DST_WR_INDEX_OFFSET},
179 { 10, ADRASTEA_DST_WR_INDEX_OFFSET},
Nirav Shah75cc5c82016-05-25 10:52:38 +0530180 { 11, ADRASTEA_DST_WR_INDEX_OFFSET},
Houston Hoffmane6330442016-02-26 12:19:11 -0800181#endif
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700182};
183
Vishwajith Upendra70efc752016-04-18 11:23:49 -0700184static struct shadow_reg_cfg target_shadow_reg_cfg_epping[] = {
185 { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
186 { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
187 { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
188 { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
189 { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
190 { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
191 { 5, ADRASTEA_DST_WR_INDEX_OFFSET},
192 { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
193 { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
194};
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700195
196/* CE_PCI TABLE */
197/*
198 * NOTE: the table below is out of date, though still a useful reference.
199 * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual
200 * mapping of HTC services to HIF pipes.
201 */
202/*
203 * This authoritative table defines Copy Engine configuration and the mapping
204 * of services/endpoints to CEs. A subset of this information is passed to
205 * the Target during startup as a prerequisite to entering BMI phase.
206 * See:
207 * target_service_to_ce_map - Target-side mapping
208 * hif_map_service_to_pipe - Host-side mapping
209 * target_ce_config - Target-side configuration
210 * host_ce_config - Host-side configuration
211 ============================================================================
212 Purpose | Service / Endpoint | CE | Dire | Xfer | Xfer
213 | | | ctio | Size | Frequency
214 | | | n | |
215 ============================================================================
216 tx | HTT_DATA (downlink) | CE 0 | h->t | medium - | very frequent
217 descriptor | | | | O(100B) | and regular
218 download | | | | |
219 ----------------------------------------------------------------------------
220 rx | HTT_DATA (uplink) | CE 1 | t->h | small - | frequent and
221 indication | | | | O(10B) | regular
222 upload | | | | |
223 ----------------------------------------------------------------------------
224 MSDU | DATA_BK (uplink) | CE 2 | t->h | large - | rare
225 upload | | | | O(1000B) | (frequent
226 e.g. noise | | | | | during IP1.0
227 packets | | | | | testing)
228 ----------------------------------------------------------------------------
229 MSDU | DATA_BK (downlink) | CE 3 | h->t | large - | very rare
230 download | | | | O(1000B) | (frequent
231 e.g. | | | | | during IP1.0
232 misdirecte | | | | | testing)
233 d EAPOL | | | | |
234 packets | | | | |
235 ----------------------------------------------------------------------------
236 n/a | DATA_BE, DATA_VI | CE 2 | t->h | | never(?)
237 | DATA_VO (uplink) | | | |
238 ----------------------------------------------------------------------------
239 n/a | DATA_BE, DATA_VI | CE 3 | h->t | | never(?)
240 | DATA_VO (downlink) | | | |
241 ----------------------------------------------------------------------------
242 WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent
243 | | | | O(100B) |
244 ----------------------------------------------------------------------------
245 WMI | WMI_CONTROL | CE 5 | h->t | medium - | infrequent
246 messages | (downlink) | | | O(100B) |
247 | | | | |
248 ----------------------------------------------------------------------------
249 n/a | HTC_CTRL_RSVD, | CE 1 | t->h | | never(?)
250 | HTC_RAW_STREAMS | | | |
251 | (uplink) | | | |
252 ----------------------------------------------------------------------------
253 n/a | HTC_CTRL_RSVD, | CE 0 | h->t | | never(?)
254 | HTC_RAW_STREAMS | | | |
255 | (downlink) | | | |
256 ----------------------------------------------------------------------------
257 diag | none (raw CE) | CE 7 | t<>h | 4 | Diag Window
258 | | | | | infrequent
259 ============================================================================
260 */
261
262/*
263 * Map from service/endpoint to Copy Engine.
264 * This table is derived from the CE_PCI TABLE, above.
265 * It is passed to the Target at startup for use by firmware.
266 */
267static struct service_to_pipe target_service_to_ce_map_wlan[] = {
268 {
269 WMI_DATA_VO_SVC,
270 PIPEDIR_OUT, /* out = UL = host -> target */
271 3,
272 },
273 {
274 WMI_DATA_VO_SVC,
275 PIPEDIR_IN, /* in = DL = target -> host */
276 2,
277 },
278 {
279 WMI_DATA_BK_SVC,
280 PIPEDIR_OUT, /* out = UL = host -> target */
281 3,
282 },
283 {
284 WMI_DATA_BK_SVC,
285 PIPEDIR_IN, /* in = DL = target -> host */
286 2,
287 },
288 {
289 WMI_DATA_BE_SVC,
290 PIPEDIR_OUT, /* out = UL = host -> target */
291 3,
292 },
293 {
294 WMI_DATA_BE_SVC,
295 PIPEDIR_IN, /* in = DL = target -> host */
296 2,
297 },
298 {
299 WMI_DATA_VI_SVC,
300 PIPEDIR_OUT, /* out = UL = host -> target */
301 3,
302 },
303 {
304 WMI_DATA_VI_SVC,
305 PIPEDIR_IN, /* in = DL = target -> host */
306 2,
307 },
308 {
309 WMI_CONTROL_SVC,
310 PIPEDIR_OUT, /* out = UL = host -> target */
311 3,
312 },
313 {
314 WMI_CONTROL_SVC,
315 PIPEDIR_IN, /* in = DL = target -> host */
316 2,
317 },
318 {
319 HTC_CTRL_RSVD_SVC,
320 PIPEDIR_OUT, /* out = UL = host -> target */
321 0, /* could be moved to 3 (share with WMI) */
322 },
323 {
324 HTC_CTRL_RSVD_SVC,
325 PIPEDIR_IN, /* in = DL = target -> host */
326 2,
327 },
328 {
329 HTC_RAW_STREAMS_SVC, /* not currently used */
330 PIPEDIR_OUT, /* out = UL = host -> target */
331 0,
332 },
333 {
334 HTC_RAW_STREAMS_SVC, /* not currently used */
335 PIPEDIR_IN, /* in = DL = target -> host */
336 2,
337 },
338 {
339 HTT_DATA_MSG_SVC,
340 PIPEDIR_OUT, /* out = UL = host -> target */
341 4,
342 },
343 {
344 HTT_DATA_MSG_SVC,
345 PIPEDIR_IN, /* in = DL = target -> host */
346 1,
347 },
348 {
349 WDI_IPA_TX_SVC,
350 PIPEDIR_OUT, /* in = DL = target -> host */
351 5,
352 },
Houston Hoffmane6330442016-02-26 12:19:11 -0800353#if defined(QCA_WIFI_3_0_ADRASTEA)
354 {
355 HTT_DATA2_MSG_SVC,
356 PIPEDIR_IN, /* in = DL = target -> host */
357 9,
358 },
359 {
360 HTT_DATA3_MSG_SVC,
361 PIPEDIR_IN, /* in = DL = target -> host */
362 10,
363 },
Nirav Shah75cc5c82016-05-25 10:52:38 +0530364 {
365 PACKET_LOG_SVC,
366 PIPEDIR_IN, /* in = DL = target -> host */
367 11,
368 },
Houston Hoffmane6330442016-02-26 12:19:11 -0800369#endif
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700370 /* (Additions here) */
371
372 { /* Must be last */
373 0,
374 0,
375 0,
376 },
377};
378
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700379static struct service_to_pipe target_service_to_ce_map_ar900b[] = {
380 {
381 WMI_DATA_VO_SVC,
382 PIPEDIR_OUT, /* out = UL = host -> target */
383 3,
384 },
385 {
386 WMI_DATA_VO_SVC,
387 PIPEDIR_IN, /* in = DL = target -> host */
388 2,
389 },
390 {
391 WMI_DATA_BK_SVC,
392 PIPEDIR_OUT, /* out = UL = host -> target */
393 3,
394 },
395 {
396 WMI_DATA_BK_SVC,
397 PIPEDIR_IN, /* in = DL = target -> host */
398 2,
399 },
400 {
401 WMI_DATA_BE_SVC,
402 PIPEDIR_OUT, /* out = UL = host -> target */
403 3,
404 },
405 {
406 WMI_DATA_BE_SVC,
407 PIPEDIR_IN, /* in = DL = target -> host */
408 2,
409 },
410 {
411 WMI_DATA_VI_SVC,
412 PIPEDIR_OUT, /* out = UL = host -> target */
413 3,
414 },
415 {
416 WMI_DATA_VI_SVC,
417 PIPEDIR_IN, /* in = DL = target -> host */
418 2,
419 },
420 {
421 WMI_CONTROL_SVC,
422 PIPEDIR_OUT, /* out = UL = host -> target */
423 3,
424 },
425 {
426 WMI_CONTROL_SVC,
427 PIPEDIR_IN, /* in = DL = target -> host */
428 2,
429 },
430 {
431 HTC_CTRL_RSVD_SVC,
432 PIPEDIR_OUT, /* out = UL = host -> target */
433 0, /* could be moved to 3 (share with WMI) */
434 },
435 {
436 HTC_CTRL_RSVD_SVC,
437 PIPEDIR_IN, /* in = DL = target -> host */
438 1,
439 },
440 {
441 HTC_RAW_STREAMS_SVC, /* not currently used */
442 PIPEDIR_OUT, /* out = UL = host -> target */
443 0,
444 },
445 {
446 HTC_RAW_STREAMS_SVC, /* not currently used */
447 PIPEDIR_IN, /* in = DL = target -> host */
448 1,
449 },
450 {
451 HTT_DATA_MSG_SVC,
452 PIPEDIR_OUT, /* out = UL = host -> target */
453 4,
454 },
455#if WLAN_FEATURE_FASTPATH
456 {
457 HTT_DATA_MSG_SVC,
458 PIPEDIR_IN, /* in = DL = target -> host */
459 5,
460 },
461#else /* WLAN_FEATURE_FASTPATH */
462 {
463 HTT_DATA_MSG_SVC,
464 PIPEDIR_IN, /* in = DL = target -> host */
465 1,
466 },
467#endif /* WLAN_FEATURE_FASTPATH */
468
469 /* (Additions here) */
470
471 { /* Must be last */
472 0,
473 0,
474 0,
475 },
476};
477
478
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700479static struct service_to_pipe *target_service_to_ce_map =
480 target_service_to_ce_map_wlan;
481static int target_service_to_ce_map_sz = sizeof(target_service_to_ce_map_wlan);
482
483static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
484static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
485
486static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
487 {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
488 {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
489 {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
490 {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
491 {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
492 {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
493 {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
494 {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
495 {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
496 {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
497 {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
498 {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
499 {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
500 {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
501 {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
502 {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
503 {0, 0, 0,}, /* Must be last */
504};
505
506/**
507 * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly
508 * @ce_state : pointer to the state context of the CE
509 *
510 * Description:
511 * Sets htt_rx_data attribute of the state structure if the
512 * CE serves one of the HTT DATA services.
513 *
514 * Return:
515 * false (attribute set to false)
516 * true (attribute set to true);
517 */
518bool ce_mark_datapath(struct CE_state *ce_state)
519{
520 struct service_to_pipe *svc_map;
521 size_t map_sz;
522 int i;
523 bool rc = false;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700524 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(ce_state->scn);
525 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700526
527 if (ce_state != NULL) {
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700528 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(ce_state->scn))) {
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700529 svc_map = target_service_to_ce_map_wlan_epping;
530 map_sz = sizeof(target_service_to_ce_map_wlan_epping) /
531 sizeof(struct service_to_pipe);
532 } else {
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700533 switch (tgt_info->target_type) {
534 default:
535 svc_map = target_service_to_ce_map_wlan;
536 map_sz =
537 sizeof(target_service_to_ce_map_wlan) /
538 sizeof(struct service_to_pipe);
539 break;
540 case TARGET_TYPE_AR900B:
541 case TARGET_TYPE_QCA9984:
542 case TARGET_TYPE_IPQ4019:
543 case TARGET_TYPE_QCA9888:
544 case TARGET_TYPE_AR9888:
545 case TARGET_TYPE_AR9888V2:
546 svc_map = target_service_to_ce_map_ar900b;
547 map_sz =
548 sizeof(target_service_to_ce_map_ar900b)
549 / sizeof(struct service_to_pipe);
550 break;
551 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700552 }
553 for (i = 0; i < map_sz; i++) {
554 if ((svc_map[i].pipenum == ce_state->id) &&
555 ((svc_map[i].service_id == HTT_DATA_MSG_SVC) ||
556 (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
557 (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) {
558 /* HTT CEs are unidirectional */
559 if (svc_map[i].pipedir == PIPEDIR_IN)
560 ce_state->htt_rx_data = true;
561 else
562 ce_state->htt_tx_data = true;
563 rc = true;
564 }
565 }
566 }
567 return rc;
568}
569
Houston Hoffman47808172016-05-06 10:04:21 -0700570/**
571 * ce_ring_test_initial_indexes() - tests the initial ce ring indexes
572 * @ce_id: ce in question
573 * @ring: ring state being examined
574 * @type: "src_ring" or "dest_ring" string for identifying the ring
575 *
576 * Warns on non-zero index values.
577 * Causes a kernel panic if the ring is not empty durring initialization.
578 */
579static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring,
580 char *type)
581{
582 if (ring->write_index != 0 || ring->sw_index != 0)
583 HIF_ERROR("ce %d, %s, initial sw_index = %d, initial write_index =%d",
584 ce_id, type, ring->sw_index, ring->write_index);
585 if (ring->write_index != ring->sw_index)
586 QDF_BUG(0);
587}
588
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530589/**
590 * ce_srng_based() - Does this target use srng
591 * @ce_state : pointer to the state context of the CE
592 *
593 * Description:
594 * returns true if the target is SRNG based
595 *
596 * Return:
597 * false (attribute set to false)
598 * true (attribute set to true);
599 */
600bool ce_srng_based(struct hif_softc *scn)
601{
602 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
603 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
604
605 switch (tgt_info->target_type) {
606#ifdef QCA_WIFI_QCA8074
607 case TARGET_TYPE_QCA8074:
608 return true;
609#endif
610 default:
611 return false;
612 }
613 return false;
614}
615
616struct ce_ops *ce_services_attach(struct hif_softc *scn)
617{
618#ifdef QCA_WIFI_QCA8074
619 if (ce_srng_based(scn))
620 return ce_services_srng();
621#endif
622
623 return ce_services_legacy();
624}
625
626static inline uint32_t ce_get_desc_size(struct hif_softc *scn,
627 uint8_t ring_type)
628{
629 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
630
631 return hif_state->ce_services->ce_get_desc_size(ring_type);
632}
633
634
635struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state,
636 uint8_t ring_type, uint32_t nentries)
637{
638 uint32_t ce_nbytes;
639 char *ptr;
640 qdf_dma_addr_t base_addr;
641 struct CE_ring_state *ce_ring;
642 uint32_t desc_size;
643 struct hif_softc *scn = CE_state->scn;
644
645 ce_nbytes = sizeof(struct CE_ring_state)
646 + (nentries * sizeof(void *));
647 ptr = qdf_mem_malloc(ce_nbytes);
648 if (!ptr)
649 return NULL;
650
651 qdf_mem_zero(ptr, ce_nbytes);
652
653 ce_ring = (struct CE_ring_state *)ptr;
654 ptr += sizeof(struct CE_ring_state);
655 ce_ring->nentries = nentries;
656 ce_ring->nentries_mask = nentries - 1;
657
658 ce_ring->low_water_mark_nentries = 0;
659 ce_ring->high_water_mark_nentries = nentries;
660 ce_ring->per_transfer_context = (void **)ptr;
661
662 desc_size = ce_get_desc_size(scn, ring_type);
663
664 /* Legacy platforms that do not support cache
665 * coherent DMA are unsupported
666 */
667 ce_ring->base_addr_owner_space_unaligned =
668 qdf_mem_alloc_consistent(scn->qdf_dev,
669 scn->qdf_dev->dev,
670 (nentries *
671 desc_size +
672 CE_DESC_RING_ALIGN),
673 &base_addr);
674 if (ce_ring->base_addr_owner_space_unaligned
675 == NULL) {
676 HIF_ERROR("%s: ring has no DMA mem",
677 __func__);
678 qdf_mem_free(ptr);
679 return NULL;
680 }
681 ce_ring->base_addr_CE_space_unaligned = base_addr;
682
683 /* Correctly initialize memory to 0 to
684 * prevent garbage data crashing system
685 * when download firmware
686 */
687 qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned,
688 nentries * desc_size +
689 CE_DESC_RING_ALIGN);
690
691 if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) {
692
693 ce_ring->base_addr_CE_space =
694 (ce_ring->base_addr_CE_space_unaligned +
695 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1);
696
697 ce_ring->base_addr_owner_space = (void *)
698 (((size_t) ce_ring->base_addr_owner_space_unaligned +
699 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1));
700 } else {
701 ce_ring->base_addr_CE_space =
702 ce_ring->base_addr_CE_space_unaligned;
703 ce_ring->base_addr_owner_space =
704 ce_ring->base_addr_owner_space_unaligned;
705 }
706
707 return ce_ring;
708}
709
710static void ce_ring_setup(struct hif_softc *scn, uint8_t ring_type,
711 uint32_t ce_id, struct CE_ring_state *ring,
712 struct CE_attr *attr)
713{
714 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
715
716 hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id, ring, attr);
717}
718
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800719/*
720 * Initialize a Copy Engine based on caller-supplied attributes.
721 * This may be called once to initialize both source and destination
722 * rings or it may be called twice for separate source and destination
723 * initialization. It may be that only one side or the other is
724 * initialized by software/firmware.
Houston Hoffman233e9092015-09-02 13:37:21 -0700725 *
726 * This should be called durring the initialization sequence before
727 * interupts are enabled, so we don't have to worry about thread safety.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800728 */
Komal Seelam644263d2016-02-22 20:45:49 +0530729struct CE_handle *ce_init(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800730 unsigned int CE_id, struct CE_attr *attr)
731{
732 struct CE_state *CE_state;
733 uint32_t ctrl_addr;
734 unsigned int nentries;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800735 bool malloc_CE_state = false;
736 bool malloc_src_ring = false;
737
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530738 QDF_ASSERT(CE_id < scn->ce_count);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800739 ctrl_addr = CE_BASE_ADDRESS(CE_id);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800740 CE_state = scn->ce_id_to_state[CE_id];
741
742 if (!CE_state) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800743 CE_state =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530744 (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800745 if (!CE_state) {
746 HIF_ERROR("%s: CE_state has no mem", __func__);
747 return NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800748 }
Houston Hoffman233e9092015-09-02 13:37:21 -0700749 malloc_CE_state = true;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530750 qdf_mem_zero(CE_state, sizeof(*CE_state));
Houston Hoffman233e9092015-09-02 13:37:21 -0700751 scn->ce_id_to_state[CE_id] = CE_state;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530752 qdf_spinlock_create(&CE_state->ce_index_lock);
Houston Hoffman233e9092015-09-02 13:37:21 -0700753
754 CE_state->id = CE_id;
755 CE_state->ctrl_addr = ctrl_addr;
756 CE_state->state = CE_RUNNING;
757 CE_state->attr_flags = attr->flags;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800758 }
759 CE_state->scn = scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800760
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530761 qdf_atomic_init(&CE_state->rx_pending);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800762 if (attr == NULL) {
763 /* Already initialized; caller wants the handle */
764 return (struct CE_handle *)CE_state;
765 }
766
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800767 if (CE_state->src_sz_max)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530768 QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800769 else
770 CE_state->src_sz_max = attr->src_sz_max;
771
Houston Hoffman68e837e2015-12-04 12:57:24 -0800772 ce_init_ce_desc_event_log(CE_id,
773 attr->src_nentries + attr->dest_nentries);
774
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800775 /* source ring setup */
776 nentries = attr->src_nentries;
777 if (nentries) {
778 struct CE_ring_state *src_ring;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800779 nentries = roundup_pwr2(nentries);
780 if (CE_state->src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530781 QDF_ASSERT(CE_state->src_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800782 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530783 src_ring = CE_state->src_ring =
784 ce_alloc_ring_state(CE_state,
785 CE_RING_SRC,
786 nentries);
787 if (!src_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800788 /* cannot allocate src ring. If the
789 * CE_state is allocated locally free
790 * CE_State and return error.
791 */
792 HIF_ERROR("%s: src ring has no mem", __func__);
793 if (malloc_CE_state) {
794 /* allocated CE_state locally */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800795 scn->ce_id_to_state[CE_id] = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530796 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800797 malloc_CE_state = false;
798 }
799 return NULL;
800 } else {
801 /* we can allocate src ring.
802 * Mark that the src ring is
803 * allocated locally
804 */
805 malloc_src_ring = true;
806 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800807 /*
808 * Also allocate a shadow src ring in
809 * regular mem to use for faster access.
810 */
811 src_ring->shadow_base_unaligned =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530812 qdf_mem_malloc(nentries *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800813 sizeof(struct CE_src_desc) +
814 CE_DESC_RING_ALIGN);
815 if (src_ring->shadow_base_unaligned == NULL) {
816 HIF_ERROR("%s: src ring no shadow_base mem",
817 __func__);
818 goto error_no_dma_mem;
819 }
820 src_ring->shadow_base = (struct CE_src_desc *)
821 (((size_t) src_ring->shadow_base_unaligned +
822 CE_DESC_RING_ALIGN - 1) &
823 ~(CE_DESC_RING_ALIGN - 1));
824
Houston Hoffman4411ad42016-03-14 21:12:04 -0700825 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
826 goto error_target_access;
Houston Hoffmanf789c662016-04-12 15:39:04 -0700827
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530828 ce_ring_setup(scn, CE_RING_SRC, CE_id, src_ring, attr);
829
Houston Hoffman4411ad42016-03-14 21:12:04 -0700830 if (Q_TARGET_ACCESS_END(scn) < 0)
831 goto error_target_access;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530832 ce_ring_test_initial_indexes(CE_id, src_ring,
833 "src_ring");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800834 }
835 }
836
837 /* destination ring setup */
838 nentries = attr->dest_nentries;
839 if (nentries) {
840 struct CE_ring_state *dest_ring;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800841
842 nentries = roundup_pwr2(nentries);
843 if (CE_state->dest_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530844 QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800845 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530846 dest_ring = CE_state->dest_ring =
847 ce_alloc_ring_state(CE_state,
848 CE_RING_DEST,
849 nentries);
850 if (!dest_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800851 /* cannot allocate dst ring. If the CE_state
852 * or src ring is allocated locally free
853 * CE_State and src ring and return error.
854 */
855 HIF_ERROR("%s: dest ring has no mem",
856 __func__);
857 if (malloc_src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530858 qdf_mem_free(CE_state->src_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800859 CE_state->src_ring = NULL;
860 malloc_src_ring = false;
861 }
862 if (malloc_CE_state) {
863 /* allocated CE_state locally */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800864 scn->ce_id_to_state[CE_id] = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530865 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800866 malloc_CE_state = false;
867 }
868 return NULL;
869 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800870
Houston Hoffman4411ad42016-03-14 21:12:04 -0700871 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
872 goto error_target_access;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530873
874 ce_ring_setup(scn, CE_RING_DEST, CE_id, dest_ring, attr);
875
876 if (Q_TARGET_ACCESS_END(scn) < 0)
877 goto error_target_access;
Houston Hoffman47808172016-05-06 10:04:21 -0700878
879 ce_ring_test_initial_indexes(CE_id, dest_ring,
880 "dest_ring");
881
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530882#ifdef QCA_WIFI_QCA8074
883 /* For srng based target, init status ring here */
884 if (ce_srng_based(CE_state->scn)) {
885 CE_state->status_ring =
886 ce_alloc_ring_state(CE_state,
887 CE_RING_STATUS,
888 nentries);
889 if (CE_state->status_ring == NULL) {
890 /*Allocation failed. Cleanup*/
891 qdf_mem_free(CE_state->dest_ring);
892 if (malloc_src_ring) {
893 qdf_mem_free
894 (CE_state->src_ring);
895 CE_state->src_ring = NULL;
896 malloc_src_ring = false;
897 }
898 if (malloc_CE_state) {
899 /* allocated CE_state locally */
900 scn->ce_id_to_state[CE_id] =
901 NULL;
902 qdf_mem_free(CE_state);
903 malloc_CE_state = false;
904 }
Houston Hoffman4411ad42016-03-14 21:12:04 -0700905
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530906 return NULL;
907 }
908 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
909 goto error_target_access;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800910
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530911 ce_ring_setup(scn, CE_RING_STATUS, CE_id,
912 CE_state->status_ring, attr);
913
914 if (Q_TARGET_ACCESS_END(scn) < 0)
915 goto error_target_access;
916
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800917 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800918#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800919 /* epping */
920 /* poll timer */
921 if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530922 qdf_timer_init(scn->qdf_dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800923 &CE_state->poll_timer,
924 ce_poll_timeout,
925 CE_state,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530926 QDF_TIMER_TYPE_SW);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800927 CE_state->timer_inited = true;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530928 qdf_timer_mod(&CE_state->poll_timer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800929 CE_POLL_TIMEOUT);
930 }
931 }
932 }
933
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530934 if (!ce_srng_based(scn)) {
935 /* Enable CE error interrupts */
936 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
937 goto error_target_access;
938 CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
939 if (Q_TARGET_ACCESS_END(scn) < 0)
940 goto error_target_access;
941 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800942
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700943 /* update the htt_data attribute */
944 ce_mark_datapath(CE_state);
945
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800946 return (struct CE_handle *)CE_state;
947
Houston Hoffman4411ad42016-03-14 21:12:04 -0700948error_target_access:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800949error_no_dma_mem:
950 ce_fini((struct CE_handle *)CE_state);
951 return NULL;
952}
953
954#ifdef WLAN_FEATURE_FASTPATH
955/**
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -0700956 * hif_enable_fastpath() Update that we have enabled fastpath mode
957 * @hif_ctx: HIF context
958 *
959 * For use in data path
960 *
961 * Retrun: void
962 */
963void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
964{
965 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
966
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700967 HIF_INFO("%s, Enabling fastpath mode", __func__);
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -0700968 scn->fastpath_mode_on = true;
969}
970
971/**
972 * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
973 * @hif_ctx: HIF Context
974 *
975 * For use in data path to skip HTC
976 *
977 * Return: bool
978 */
979bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
980{
981 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
982
983 return scn->fastpath_mode_on;
984}
985
986/**
987 * hif_get_ce_handle - API to get CE handle for FastPath mode
988 * @hif_ctx: HIF Context
989 * @id: CopyEngine Id
990 *
991 * API to return CE handle for fastpath mode
992 *
993 * Return: void
994 */
995void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
996{
997 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
998
999 return scn->ce_id_to_state[id];
1000}
1001
1002/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001003 * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
1004 * No processing is required inside this function.
1005 * @ce_hdl: Cope engine handle
1006 * Using an assert, this function makes sure that,
1007 * the TX CE has been processed completely.
Houston Hoffman9a831ef2015-09-03 14:42:40 -07001008 *
1009 * This is called while dismantling CE structures. No other thread
1010 * should be using these structures while dismantling is occuring
1011 * therfore no locking is needed.
1012 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001013 * Return: none
1014 */
1015void
1016ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
1017{
1018 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1019 struct CE_ring_state *src_ring = ce_state->src_ring;
Komal Seelam644263d2016-02-22 20:45:49 +05301020 struct hif_softc *sc = ce_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001021 uint32_t sw_index, write_index;
Houston Hoffman85925072016-05-06 17:02:18 -07001022 if (hif_is_nss_wifi_enabled(sc))
1023 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001024
Houston Hoffmanc7d54292016-04-13 18:55:37 -07001025 if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
Houston Hoffman85925072016-05-06 17:02:18 -07001026 HIF_INFO("%s %d Fastpath mode ON, Cleaning up HTT Tx CE",
1027 __func__, __LINE__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001028 sw_index = src_ring->sw_index;
1029 write_index = src_ring->sw_index;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001030
1031 /* At this point Tx CE should be clean */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301032 qdf_assert_always(sw_index == write_index);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001033 }
1034}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001035
1036/**
1037 * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
1038 * @ce_hdl: Handle to CE
1039 *
1040 * These buffers are never allocated on the fly, but
1041 * are allocated only once during HIF start and freed
1042 * only once during HIF stop.
1043 * NOTE:
1044 * The assumption here is there is no in-flight DMA in progress
1045 * currently, so that buffers can be freed up safely.
1046 *
1047 * Return: NONE
1048 */
1049void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
1050{
1051 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1052 struct CE_ring_state *dst_ring = ce_state->dest_ring;
1053 qdf_nbuf_t nbuf;
1054 int i;
1055
1056 if (!ce_state->fastpath_handler)
1057 return;
1058 /*
1059 * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
1060 * this CE is completely full: does not leave one blank space, to
1061 * distinguish between empty queue & full queue. So free all the
1062 * entries.
1063 */
1064 for (i = 0; i < dst_ring->nentries; i++) {
1065 nbuf = dst_ring->per_transfer_context[i];
1066
1067 /*
1068 * The reasons for doing this check are:
1069 * 1) Protect against calling cleanup before allocating buffers
1070 * 2) In a corner case, FASTPATH_mode_on may be set, but we
1071 * could have a partially filled ring, because of a memory
1072 * allocation failure in the middle of allocating ring.
1073 * This check accounts for that case, checking
1074 * fastpath_mode_on flag or started flag would not have
1075 * covered that case. This is not in performance path,
1076 * so OK to do this.
1077 */
1078 if (nbuf)
1079 qdf_nbuf_free(nbuf);
1080 }
1081}
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001082
1083/**
1084 * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
1085 * @scn: HIF handle
1086 *
1087 * Datapath Rx CEs are special case, where we reuse all the message buffers.
1088 * Hence we have to post all the entries in the pipe, even, in the beginning
1089 * unlike for other CE pipes where one less than dest_nentries are filled in
1090 * the beginning.
1091 *
1092 * Return: None
1093 */
1094static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
1095{
1096 int pipe_num;
1097 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1098
1099 if (scn->fastpath_mode_on == false)
1100 return;
1101
1102 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1103 struct HIF_CE_pipe_info *pipe_info =
1104 &hif_state->pipe_info[pipe_num];
1105 struct CE_state *ce_state =
1106 scn->ce_id_to_state[pipe_info->pipe_num];
1107
1108 if (ce_state->htt_rx_data)
1109 atomic_inc(&pipe_info->recv_bufs_needed);
1110 }
1111}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001112#else
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001113static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001114{
1115}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001116
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001117static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001118{
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001119 return false;
1120}
1121
1122static inline bool ce_is_fastpath_handler_registered(struct CE_state *ce_state)
1123{
1124 return false;
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001125}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001126#endif /* WLAN_FEATURE_FASTPATH */
1127
1128void ce_fini(struct CE_handle *copyeng)
1129{
1130 struct CE_state *CE_state = (struct CE_state *)copyeng;
1131 unsigned int CE_id = CE_state->id;
Komal Seelam644263d2016-02-22 20:45:49 +05301132 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001133
1134 CE_state->state = CE_UNUSED;
1135 scn->ce_id_to_state[CE_id] = NULL;
1136 if (CE_state->src_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001137 /* Cleanup the datapath Tx ring */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001138 ce_h2t_tx_ce_cleanup(copyeng);
1139
1140 if (CE_state->src_ring->shadow_base_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301141 qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001142 if (CE_state->src_ring->base_addr_owner_space_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301143 qdf_mem_free_consistent(scn->qdf_dev,
1144 scn->qdf_dev->dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001145 (CE_state->src_ring->nentries *
1146 sizeof(struct CE_src_desc) +
1147 CE_DESC_RING_ALIGN),
1148 CE_state->src_ring->
1149 base_addr_owner_space_unaligned,
1150 CE_state->src_ring->
1151 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301152 qdf_mem_free(CE_state->src_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001153 }
1154 if (CE_state->dest_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001155 /* Cleanup the datapath Rx ring */
1156 ce_t2h_msg_ce_cleanup(copyeng);
1157
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001158 if (CE_state->dest_ring->base_addr_owner_space_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301159 qdf_mem_free_consistent(scn->qdf_dev,
1160 scn->qdf_dev->dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001161 (CE_state->dest_ring->nentries *
1162 sizeof(struct CE_dest_desc) +
1163 CE_DESC_RING_ALIGN),
1164 CE_state->dest_ring->
1165 base_addr_owner_space_unaligned,
1166 CE_state->dest_ring->
1167 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301168 qdf_mem_free(CE_state->dest_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001169
1170 /* epping */
1171 if (CE_state->timer_inited) {
1172 CE_state->timer_inited = false;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301173 qdf_timer_free(&CE_state->poll_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001174 }
1175 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301176#ifdef QCA_WIFI_QCA8074
1177 if (CE_state->status_ring) {
1178 /* Cleanup the datapath Tx ring */
1179 ce_h2t_tx_ce_cleanup(copyeng);
1180
1181 if (CE_state->status_ring->shadow_base_unaligned)
1182 qdf_mem_free(
1183 CE_state->status_ring->shadow_base_unaligned);
1184
1185 if (CE_state->status_ring->base_addr_owner_space_unaligned)
1186 qdf_mem_free_consistent(scn->qdf_dev,
1187 scn->qdf_dev->dev,
1188 (CE_state->status_ring->nentries *
1189 sizeof(struct CE_src_desc) +
1190 CE_DESC_RING_ALIGN),
1191 CE_state->status_ring->
1192 base_addr_owner_space_unaligned,
1193 CE_state->status_ring->
1194 base_addr_CE_space, 0);
1195 qdf_mem_free(CE_state->status_ring);
1196 }
1197#endif
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301198 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001199}
1200
Komal Seelam5584a7c2016-02-24 19:22:48 +05301201void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001202{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301203 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001204
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301205 qdf_mem_zero(&hif_state->msg_callbacks_pending,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001206 sizeof(hif_state->msg_callbacks_pending));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301207 qdf_mem_zero(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001208 sizeof(hif_state->msg_callbacks_current));
1209}
1210
1211/* Send the first nbytes bytes of the buffer */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301212QDF_STATUS
Komal Seelam5584a7c2016-02-24 19:22:48 +05301213hif_send_head(struct hif_opaque_softc *hif_ctx,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001214 uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301215 qdf_nbuf_t nbuf, unsigned int data_attr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001216{
Komal Seelam644263d2016-02-22 20:45:49 +05301217 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301218 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001219 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1220 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
1221 int bytes = nbytes, nfrags = 0;
1222 struct ce_sendlist sendlist;
1223 int status, i = 0;
1224 unsigned int mux_id = 0;
1225
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301226 QDF_ASSERT(nbytes <= qdf_nbuf_len(nbuf));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001227
1228 transfer_id =
1229 (mux_id & MUX_ID_MASK) |
1230 (transfer_id & TRANSACTION_ID_MASK);
1231 data_attr &= DESC_DATA_FLAG_MASK;
1232 /*
1233 * The common case involves sending multiple fragments within a
1234 * single download (the tx descriptor and the tx frame header).
1235 * So, optimize for the case of multiple fragments by not even
1236 * checking whether it's necessary to use a sendlist.
1237 * The overhead of using a sendlist for a single buffer download
1238 * is not a big deal, since it happens rarely (for WMI messages).
1239 */
1240 ce_sendlist_init(&sendlist);
1241 do {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301242 qdf_dma_addr_t frag_paddr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001243 int frag_bytes;
1244
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301245 frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
1246 frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001247 /*
1248 * Clear the packet offset for all but the first CE desc.
1249 */
1250 if (i++ > 0)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301251 data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001252
1253 status = ce_sendlist_buf_add(&sendlist, frag_paddr,
1254 frag_bytes >
1255 bytes ? bytes : frag_bytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301256 qdf_nbuf_get_frag_is_wordstream
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001257 (nbuf,
1258 nfrags) ? 0 :
1259 CE_SEND_FLAG_SWAP_DISABLE,
1260 data_attr);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301261 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001262 HIF_ERROR("%s: error, frag_num %d larger than limit",
1263 __func__, nfrags);
1264 return status;
1265 }
1266 bytes -= frag_bytes;
1267 nfrags++;
1268 } while (bytes > 0);
1269
1270 /* Make sure we have resources to handle this request */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301271 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001272 if (pipe_info->num_sends_allowed < nfrags) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301273 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001274 ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301275 return QDF_STATUS_E_RESOURCES;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001276 }
1277 pipe_info->num_sends_allowed -= nfrags;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301278 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001279
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301280 if (qdf_unlikely(ce_hdl == NULL)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001281 HIF_ERROR("%s: error CE handle is null", __func__);
1282 return A_ERROR;
1283 }
1284
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301285 QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301286 DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
Nirav Shaheaa20d82016-04-25 18:01:05 +05301287 qdf_nbuf_data_addr(nbuf),
Nirav Shah29beae02016-04-26 22:58:54 +05301288 sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001289 status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301290 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001291
1292 return status;
1293}
1294
Komal Seelam5584a7c2016-02-24 19:22:48 +05301295void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
1296 int force)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001297{
Komal Seelam644263d2016-02-22 20:45:49 +05301298 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301299 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Komal Seelam644263d2016-02-22 20:45:49 +05301300
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001301 if (!force) {
1302 int resources;
1303 /*
1304 * Decide whether to actually poll for completions, or just
1305 * wait for a later chance. If there seem to be plenty of
1306 * resources left, then just wait, since checking involves
1307 * reading a CE register, which is a relatively expensive
1308 * operation.
1309 */
Komal Seelam644263d2016-02-22 20:45:49 +05301310 resources = hif_get_free_queue_number(hif_ctx, pipe);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001311 /*
1312 * If at least 50% of the total resources are still available,
1313 * don't bother checking again yet.
1314 */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301315 if (resources > (hif_state->host_ce_config[pipe].src_nentries >> 1)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001316 return;
1317 }
1318 }
Houston Hoffman56e0d702016-05-05 17:48:06 -07001319#if ATH_11AC_TXCOMPACT
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001320 ce_per_engine_servicereap(scn, pipe);
1321#else
1322 ce_per_engine_service(scn, pipe);
1323#endif
1324}
1325
Komal Seelam5584a7c2016-02-24 19:22:48 +05301326uint16_t
1327hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001328{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301329 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001330 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1331 uint16_t rv;
1332
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301333 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001334 rv = pipe_info->num_sends_allowed;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301335 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001336 return rv;
1337}
1338
1339/* Called by lower (CE) layer when a send to Target completes. */
1340void
1341hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301342 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001343 unsigned int nbytes, unsigned int transfer_id,
1344 unsigned int sw_index, unsigned int hw_index,
1345 unsigned int toeplitz_hash_result)
1346{
1347 struct HIF_CE_pipe_info *pipe_info =
1348 (struct HIF_CE_pipe_info *)ce_context;
1349 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Komal Seelam644263d2016-02-22 20:45:49 +05301350 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001351 unsigned int sw_idx = sw_index, hw_idx = hw_index;
Houston Hoffman85118512015-09-28 14:17:11 -07001352 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301353 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001354
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001355 do {
1356 /*
Houston Hoffman85118512015-09-28 14:17:11 -07001357 * The upper layer callback will be triggered
1358 * when last fragment is complteted.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001359 */
Houston Hoffman85118512015-09-28 14:17:11 -07001360 if (transfer_context != CE_SENDLIST_ITEM_CTXT) {
Komal Seelam6ee55902016-04-11 17:11:07 +05301361 if (scn->target_status == TARGET_STATUS_RESET)
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301362 qdf_nbuf_free(transfer_context);
Houston Hoffman49794a32015-12-21 12:14:56 -08001363 else
1364 msg_callbacks->txCompletionHandler(
Houston Hoffman85118512015-09-28 14:17:11 -07001365 msg_callbacks->Context,
1366 transfer_context, transfer_id,
1367 toeplitz_hash_result);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001368 }
1369
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301370 qdf_spin_lock(&pipe_info->completion_freeq_lock);
Houston Hoffman85118512015-09-28 14:17:11 -07001371 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301372 qdf_spin_unlock(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001373 } while (ce_completed_send_next(copyeng,
1374 &ce_context, &transfer_context,
1375 &CE_data, &nbytes, &transfer_id,
1376 &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301377 &toeplitz_hash_result) == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001378}
1379
Houston Hoffman910c6262015-09-28 12:56:25 -07001380/**
1381 * hif_ce_do_recv(): send message from copy engine to upper layers
1382 * @msg_callbacks: structure containing callback and callback context
1383 * @netbuff: skb containing message
1384 * @nbytes: number of bytes in the message
1385 * @pipe_info: used for the pipe_number info
1386 *
1387 * Checks the packet length, configures the lenght in the netbuff,
1388 * and calls the upper layer callback.
1389 *
1390 * return: None
1391 */
1392static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301393 qdf_nbuf_t netbuf, int nbytes,
Houston Hoffman910c6262015-09-28 12:56:25 -07001394 struct HIF_CE_pipe_info *pipe_info) {
1395 if (nbytes <= pipe_info->buf_sz) {
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301396 qdf_nbuf_set_pktlen(netbuf, nbytes);
Houston Hoffman910c6262015-09-28 12:56:25 -07001397 msg_callbacks->
1398 rxCompletionHandler(msg_callbacks->Context,
1399 netbuf, pipe_info->pipe_num);
1400 } else {
1401 HIF_ERROR("%s: Invalid Rx msg buf:%p nbytes:%d",
1402 __func__, netbuf, nbytes);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301403 qdf_nbuf_free(netbuf);
Houston Hoffman910c6262015-09-28 12:56:25 -07001404 }
1405}
1406
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001407/* Called by lower (CE) layer when data is received from the Target. */
1408void
1409hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301410 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001411 unsigned int nbytes, unsigned int transfer_id,
1412 unsigned int flags)
1413{
1414 struct HIF_CE_pipe_info *pipe_info =
1415 (struct HIF_CE_pipe_info *)ce_context;
1416 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001417 struct CE_state *ce_state = (struct CE_state *) copyeng;
Komal Seelam644263d2016-02-22 20:45:49 +05301418 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001419#ifdef HIF_PCI
1420 struct hif_pci_softc *hif_pci_sc = HIF_GET_PCI_SOFTC(hif_state);
1421#endif
Houston Hoffman910c6262015-09-28 12:56:25 -07001422 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301423 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001424
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001425 do {
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001426#ifdef HIF_PCI
1427 hif_pm_runtime_mark_last_busy(hif_pci_sc->dev);
1428#endif
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301429 qdf_nbuf_unmap_single(scn->qdf_dev,
1430 (qdf_nbuf_t) transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301431 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001432
Houston Hoffman910c6262015-09-28 12:56:25 -07001433 atomic_inc(&pipe_info->recv_bufs_needed);
1434 hif_post_recv_buffers_for_pipe(pipe_info);
Komal Seelam6ee55902016-04-11 17:11:07 +05301435 if (scn->target_status == TARGET_STATUS_RESET)
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301436 qdf_nbuf_free(transfer_context);
Houston Hoffman49794a32015-12-21 12:14:56 -08001437 else
1438 hif_ce_do_recv(msg_callbacks, transfer_context,
Houston Hoffman9c0f80a2015-09-28 18:36:36 -07001439 nbytes, pipe_info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001440
1441 /* Set up force_break flag if num of receices reaches
1442 * MAX_NUM_OF_RECEIVES */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001443 ce_state->receive_count++;
Houston Hoffman05652722016-04-29 16:58:59 -07001444 if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001445 ce_state->force_break = 1;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001446 break;
1447 }
1448 } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
1449 &CE_data, &nbytes, &transfer_id,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301450 &flags) == QDF_STATUS_SUCCESS);
Houston Hoffmanf4607852015-12-17 17:14:40 -08001451
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001452}
1453
1454/* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
1455
1456void
Komal Seelam5584a7c2016-02-24 19:22:48 +05301457hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001458 struct hif_msg_callbacks *callbacks)
1459{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301460 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001461
1462#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
1463 spin_lock_init(&pcie_access_log_lock);
1464#endif
1465 /* Save callbacks for later installation */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301466 qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001467 sizeof(hif_state->msg_callbacks_pending));
1468
1469}
1470
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001471int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
1472{
1473 struct CE_handle *ce_diag = hif_state->ce_diag;
1474 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05301475 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001476 struct hif_msg_callbacks *hif_msg_callbacks =
1477 &hif_state->msg_callbacks_current;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001478
1479 /* daemonize("hif_compl_thread"); */
1480
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001481 if (scn->ce_count == 0) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07001482 HIF_ERROR("%s: Invalid ce_count", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001483 return -EINVAL;
1484 }
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001485
1486 if (!hif_msg_callbacks ||
1487 !hif_msg_callbacks->rxCompletionHandler ||
1488 !hif_msg_callbacks->txCompletionHandler) {
1489 HIF_ERROR("%s: no completion handler registered", __func__);
1490 return -EFAULT;
1491 }
1492
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001493 A_TARGET_ACCESS_LIKELY(scn);
1494 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1495 struct CE_attr attr;
1496 struct HIF_CE_pipe_info *pipe_info;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001497
1498 pipe_info = &hif_state->pipe_info[pipe_num];
1499 if (pipe_info->ce_hdl == ce_diag) {
1500 continue; /* Handle Diagnostic CE specially */
1501 }
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301502 attr = hif_state->host_ce_config[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001503 if (attr.src_nentries) {
1504 /* pipe used to send to target */
1505 HIF_INFO_MED("%s: pipe_num:%d pipe_info:0x%p",
1506 __func__, pipe_num, pipe_info);
1507 ce_send_cb_register(pipe_info->ce_hdl,
1508 hif_pci_ce_send_done, pipe_info,
1509 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001510 pipe_info->num_sends_allowed = attr.src_nentries - 1;
1511 }
1512 if (attr.dest_nentries) {
1513 /* pipe used to receive from target */
1514 ce_recv_cb_register(pipe_info->ce_hdl,
1515 hif_pci_ce_recv_data, pipe_info,
1516 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001517 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001518
1519 if (attr.src_nentries)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301520 qdf_spinlock_create(&pipe_info->completion_freeq_lock);
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301521
1522 qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks,
1523 sizeof(pipe_info->pipe_callbacks));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001524 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001525
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001526 A_TARGET_ACCESS_UNLIKELY(scn);
1527 return 0;
1528}
1529
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001530/*
1531 * Install pending msg callbacks.
1532 *
1533 * TBDXXX: This hack is needed because upper layers install msg callbacks
1534 * for use with HTC before BMI is done; yet this HIF implementation
1535 * needs to continue to use BMI msg callbacks. Really, upper layers
1536 * should not register HTC callbacks until AFTER BMI phase.
1537 */
Komal Seelam644263d2016-02-22 20:45:49 +05301538static void hif_msg_callbacks_install(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001539{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301540 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001541
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301542 qdf_mem_copy(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001543 &hif_state->msg_callbacks_pending,
1544 sizeof(hif_state->msg_callbacks_pending));
1545}
1546
Komal Seelam5584a7c2016-02-24 19:22:48 +05301547void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
1548 uint8_t *DLPipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001549{
1550 int ul_is_polled, dl_is_polled;
1551
Komal Seelam644263d2016-02-22 20:45:49 +05301552 (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001553 ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
1554}
1555
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001556/**
1557 * hif_dump_pipe_debug_count() - Log error count
Komal Seelam644263d2016-02-22 20:45:49 +05301558 * @scn: hif_softc pointer.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001559 *
1560 * Output the pipe error counts of each pipe to log file
1561 *
1562 * Return: N/A
1563 */
Komal Seelam644263d2016-02-22 20:45:49 +05301564void hif_dump_pipe_debug_count(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001565{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301566 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001567 int pipe_num;
1568
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001569 if (hif_state == NULL) {
1570 HIF_ERROR("%s hif_state is NULL", __func__);
1571 return;
1572 }
1573 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1574 struct HIF_CE_pipe_info *pipe_info;
1575
1576 pipe_info = &hif_state->pipe_info[pipe_num];
1577
1578 if (pipe_info->nbuf_alloc_err_count > 0 ||
1579 pipe_info->nbuf_dma_err_count > 0 ||
1580 pipe_info->nbuf_ce_enqueue_err_count)
1581 HIF_ERROR(
1582 "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
1583 __func__, pipe_info->pipe_num,
1584 atomic_read(&pipe_info->recv_bufs_needed),
1585 pipe_info->nbuf_alloc_err_count,
1586 pipe_info->nbuf_dma_err_count,
1587 pipe_info->nbuf_ce_enqueue_err_count);
1588 }
1589}
1590
1591static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
1592{
1593 struct CE_handle *ce_hdl;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301594 qdf_size_t buf_sz;
Komal Seelam644263d2016-02-22 20:45:49 +05301595 struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301596 QDF_STATUS ret;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001597 uint32_t bufs_posted = 0;
1598
1599 buf_sz = pipe_info->buf_sz;
1600 if (buf_sz == 0) {
1601 /* Unused Copy Engine */
1602 return 0;
1603 }
1604
1605 ce_hdl = pipe_info->ce_hdl;
1606
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301607 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001608 while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301609 qdf_dma_addr_t CE_data; /* CE space buffer address */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301610 qdf_nbuf_t nbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001611 int status;
1612
1613 atomic_dec(&pipe_info->recv_bufs_needed);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301614 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001615
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301616 nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001617 if (!nbuf) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301618 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001619 pipe_info->nbuf_alloc_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301620 qdf_spin_unlock_bh(
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001621 &pipe_info->recv_bufs_needed_lock);
1622 HIF_ERROR(
1623 "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
1624 __func__, pipe_info->pipe_num,
1625 atomic_read(&pipe_info->recv_bufs_needed),
1626 pipe_info->nbuf_alloc_err_count);
1627 atomic_inc(&pipe_info->recv_bufs_needed);
1628 return 1;
1629 }
1630
1631 /*
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301632 * qdf_nbuf_peek_header(nbuf, &data, &unused);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001633 * CE_data = dma_map_single(dev, data, buf_sz, );
1634 * DMA_FROM_DEVICE);
1635 */
1636 ret =
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301637 qdf_nbuf_map_single(scn->qdf_dev, nbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301638 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001639
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301640 if (unlikely(ret != QDF_STATUS_SUCCESS)) {
1641 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001642 pipe_info->nbuf_dma_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301643 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001644 HIF_ERROR(
1645 "%s buf alloc error [%d] needed %d, nbuf_dma_err_count = %u",
1646 __func__, pipe_info->pipe_num,
1647 atomic_read(&pipe_info->recv_bufs_needed),
1648 pipe_info->nbuf_dma_err_count);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301649 qdf_nbuf_free(nbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001650 atomic_inc(&pipe_info->recv_bufs_needed);
1651 return 1;
1652 }
1653
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301654 CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001655
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301656 qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001657 buf_sz, DMA_FROM_DEVICE);
1658 status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301659 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001660 if (status != EOK) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301661 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001662 pipe_info->nbuf_ce_enqueue_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301663 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001664 HIF_ERROR(
1665 "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
1666 __func__, pipe_info->pipe_num,
1667 atomic_read(&pipe_info->recv_bufs_needed),
1668 pipe_info->nbuf_ce_enqueue_err_count);
Govind Singh4fcafd42016-08-08 12:37:31 +05301669 qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
1670 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001671 atomic_inc(&pipe_info->recv_bufs_needed);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301672 qdf_nbuf_free(nbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001673 return 1;
1674 }
1675
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301676 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001677 bufs_posted++;
1678 }
1679 pipe_info->nbuf_alloc_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001680 (pipe_info->nbuf_alloc_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001681 pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
1682 pipe_info->nbuf_dma_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001683 (pipe_info->nbuf_dma_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001684 pipe_info->nbuf_dma_err_count - bufs_posted : 0;
1685 pipe_info->nbuf_ce_enqueue_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001686 (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001687 pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
1688
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301689 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001690
1691 return 0;
1692}
1693
1694/*
1695 * Try to post all desired receive buffers for all pipes.
1696 * Returns 0 if all desired buffers are posted,
1697 * non-zero if were were unable to completely
1698 * replenish receive buffers.
1699 */
Komal Seelam644263d2016-02-22 20:45:49 +05301700static int hif_post_recv_buffers(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001701{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301702 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001703 int pipe_num, rv = 0;
Houston Hoffman85925072016-05-06 17:02:18 -07001704 struct CE_state *ce_state;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001705
1706 A_TARGET_ACCESS_LIKELY(scn);
1707 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1708 struct HIF_CE_pipe_info *pipe_info;
Houston Hoffman85925072016-05-06 17:02:18 -07001709 ce_state = scn->ce_id_to_state[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001710 pipe_info = &hif_state->pipe_info[pipe_num];
Houston Hoffman85925072016-05-06 17:02:18 -07001711
1712 if (hif_is_nss_wifi_enabled(scn) &&
1713 ce_state && (ce_state->htt_rx_data)) {
1714 continue;
1715 }
1716
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001717 if (hif_post_recv_buffers_for_pipe(pipe_info)) {
1718 rv = 1;
1719 goto done;
1720 }
1721 }
1722
1723done:
1724 A_TARGET_ACCESS_UNLIKELY(scn);
1725
1726 return rv;
1727}
1728
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301729QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001730{
Komal Seelam644263d2016-02-22 20:45:49 +05301731 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301732 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001733
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001734 hif_update_fastpath_recv_bufs_cnt(scn);
1735
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001736 hif_msg_callbacks_install(scn);
1737
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001738 if (hif_completion_thread_startup(hif_state))
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301739 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001740
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001741 /* Post buffers once to start things off. */
1742 (void)hif_post_recv_buffers(scn);
1743
1744 hif_state->started = true;
1745
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301746 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001747}
1748
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001749void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
1750{
Komal Seelam644263d2016-02-22 20:45:49 +05301751 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001752 struct CE_handle *ce_hdl;
1753 uint32_t buf_sz;
1754 struct HIF_CE_state *hif_state;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301755 qdf_nbuf_t netbuf;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301756 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001757 void *per_CE_context;
1758
1759 buf_sz = pipe_info->buf_sz;
1760 if (buf_sz == 0) {
1761 /* Unused Copy Engine */
1762 return;
1763 }
1764
1765 hif_state = pipe_info->HIF_CE_state;
1766 if (!hif_state->started) {
1767 return;
1768 }
1769
Komal Seelam02cf2f82016-02-22 20:44:25 +05301770 scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001771 ce_hdl = pipe_info->ce_hdl;
1772
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301773 if (scn->qdf_dev == NULL) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001774 return;
1775 }
1776 while (ce_revoke_recv_next
1777 (ce_hdl, &per_CE_context, (void **)&netbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301778 &CE_data) == QDF_STATUS_SUCCESS) {
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301779 qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301780 QDF_DMA_FROM_DEVICE);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301781 qdf_nbuf_free(netbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001782 }
1783}
1784
1785void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
1786{
1787 struct CE_handle *ce_hdl;
1788 struct HIF_CE_state *hif_state;
Komal Seelam644263d2016-02-22 20:45:49 +05301789 struct hif_softc *scn;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301790 qdf_nbuf_t netbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001791 void *per_CE_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301792 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001793 unsigned int nbytes;
1794 unsigned int id;
1795 uint32_t buf_sz;
1796 uint32_t toeplitz_hash_result;
1797
1798 buf_sz = pipe_info->buf_sz;
1799 if (buf_sz == 0) {
1800 /* Unused Copy Engine */
1801 return;
1802 }
1803
1804 hif_state = pipe_info->HIF_CE_state;
1805 if (!hif_state->started) {
1806 return;
1807 }
1808
Komal Seelam02cf2f82016-02-22 20:44:25 +05301809 scn = HIF_GET_SOFTC(hif_state);
1810
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001811 ce_hdl = pipe_info->ce_hdl;
1812
1813 while (ce_cancel_send_next
1814 (ce_hdl, &per_CE_context,
1815 (void **)&netbuf, &CE_data, &nbytes,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301816 &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001817 if (netbuf != CE_SENDLIST_ITEM_CTXT) {
1818 /*
1819 * Packets enqueued by htt_h2t_ver_req_msg() and
1820 * htt_h2t_rx_ring_cfg_msg_ll() have already been
1821 * freed in htt_htc_misc_pkt_pool_free() in
1822 * wlantl_close(), so do not free them here again
Houston Hoffman29573d92015-10-20 17:49:44 -07001823 * by checking whether it's the endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001824 * which they are queued in.
1825 */
Nirav Shahd7f91592016-04-21 14:18:43 +05301826 if (id == scn->htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001827 return;
Nirav Shahd7f91592016-04-21 14:18:43 +05301828 /* Indicate the completion to higher
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001829 * layer to free the buffer */
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301830 if (pipe_info->pipe_callbacks.
Himanshu Agarwal8d0cdea2016-09-02 21:05:01 +05301831 txCompletionHandler)
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301832 pipe_info->pipe_callbacks.
1833 txCompletionHandler(pipe_info->
1834 pipe_callbacks.Context,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001835 netbuf, id, toeplitz_hash_result);
1836 }
1837 }
1838}
1839
1840/*
1841 * Cleanup residual buffers for device shutdown:
1842 * buffers that were enqueued for receive
1843 * buffers that were to be sent
1844 * Note: Buffers that had completed but which were
1845 * not yet processed are on a completion queue. They
1846 * are handled when the completion thread shuts down.
1847 */
1848void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
1849{
1850 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05301851 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman85925072016-05-06 17:02:18 -07001852 struct CE_state *ce_state;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001853
Komal Seelam02cf2f82016-02-22 20:44:25 +05301854 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001855 struct HIF_CE_pipe_info *pipe_info;
1856
Houston Hoffman85925072016-05-06 17:02:18 -07001857 ce_state = scn->ce_id_to_state[pipe_num];
1858 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
1859 ((ce_state->htt_tx_data) ||
1860 (ce_state->htt_rx_data))) {
1861 continue;
1862 }
1863
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001864 pipe_info = &hif_state->pipe_info[pipe_num];
1865 hif_recv_buffer_cleanup_on_pipe(pipe_info);
1866 hif_send_buffer_cleanup_on_pipe(pipe_info);
1867 }
1868}
1869
Komal Seelam5584a7c2016-02-24 19:22:48 +05301870void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001871{
Komal Seelam644263d2016-02-22 20:45:49 +05301872 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301873 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Komal Seelam644263d2016-02-22 20:45:49 +05301874
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001875 hif_buffer_cleanup(hif_state);
1876}
1877
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05301878void hif_ce_stop(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001879{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05301880 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001881 int pipe_num;
1882
1883 scn->hif_init_done = false;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001884
1885 /*
1886 * At this point, asynchronous threads are stopped,
1887 * The Target should not DMA nor interrupt, Host code may
1888 * not initiate anything more. So we just need to clean
1889 * up Host-side state.
1890 */
1891
1892 if (scn->athdiag_procfs_inited) {
1893 athdiag_procfs_remove();
1894 scn->athdiag_procfs_inited = false;
1895 }
1896
1897 hif_buffer_cleanup(hif_state);
1898
1899 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1900 struct HIF_CE_pipe_info *pipe_info;
1901
1902 pipe_info = &hif_state->pipe_info[pipe_num];
1903 if (pipe_info->ce_hdl) {
1904 ce_fini(pipe_info->ce_hdl);
1905 pipe_info->ce_hdl = NULL;
1906 pipe_info->buf_sz = 0;
1907 }
1908 }
1909
1910 if (hif_state->sleep_timer_init) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301911 qdf_timer_stop(&hif_state->sleep_timer);
1912 qdf_timer_free(&hif_state->sleep_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001913 hif_state->sleep_timer_init = false;
1914 }
1915
1916 hif_state->started = false;
1917}
1918
Houston Hoffman854e67f2016-03-14 21:11:39 -07001919/**
1920 * hif_get_target_ce_config() - get copy engine configuration
1921 * @target_ce_config_ret: basic copy engine configuration
1922 * @target_ce_config_sz_ret: size of the basic configuration in bytes
1923 * @target_service_to_ce_map_ret: service mapping for the copy engines
1924 * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
1925 * @target_shadow_reg_cfg_ret: shadow register configuration
1926 * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
1927 *
1928 * providing accessor to these values outside of this file.
1929 * currently these are stored in static pointers to const sections.
1930 * there are multiple configurations that are selected from at compile time.
1931 * Runtime selection would need to consider mode, target type and bus type.
1932 *
1933 * Return: return by parameter.
1934 */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301935void hif_get_target_ce_config(struct hif_softc *scn,
1936 struct CE_pipe_config **target_ce_config_ret,
Houston Hoffman854e67f2016-03-14 21:11:39 -07001937 int *target_ce_config_sz_ret,
1938 struct service_to_pipe **target_service_to_ce_map_ret,
1939 int *target_service_to_ce_map_sz_ret,
1940 struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
1941 int *shadow_cfg_sz_ret)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001942{
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301943 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1944
1945 *target_ce_config_ret = hif_state->target_ce_config;
1946 *target_ce_config_sz_ret = hif_state->target_ce_config_sz;
Houston Hoffman854e67f2016-03-14 21:11:39 -07001947 *target_service_to_ce_map_ret = target_service_to_ce_map;
1948 *target_service_to_ce_map_sz_ret = target_service_to_ce_map_sz;
1949
1950 if (target_shadow_reg_cfg_ret)
1951 *target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
1952
1953 if (shadow_cfg_sz_ret)
1954 *shadow_cfg_sz_ret = shadow_cfg_sz;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001955}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001956
1957/**
1958 * hif_wlan_enable(): call the platform driver to enable wlan
Komal Seelambd7c51d2016-02-24 10:27:30 +05301959 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001960 *
1961 * This function passes the con_mode and CE configuration to
1962 * platform driver to enable wlan.
1963 *
Houston Hoffman108da402016-03-14 21:11:24 -07001964 * Return: linux error code
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001965 */
Houston Hoffman108da402016-03-14 21:11:24 -07001966int hif_wlan_enable(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001967{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07001968 struct pld_wlan_enable_cfg cfg;
1969 enum pld_driver_mode mode;
Komal Seelambd7c51d2016-02-24 10:27:30 +05301970 uint32_t con_mode = hif_get_conparam(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001971
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301972 hif_get_target_ce_config(scn,
1973 (struct CE_pipe_config **)&cfg.ce_tgt_cfg,
Houston Hoffman854e67f2016-03-14 21:11:39 -07001974 &cfg.num_ce_tgt_cfg,
1975 (struct service_to_pipe **)&cfg.ce_svc_cfg,
1976 &cfg.num_ce_svc_pipe_cfg,
1977 (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
1978 &cfg.num_shadow_reg_cfg);
1979
1980 /* translate from structure size to array size */
1981 cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
1982 cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
1983 cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001984
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301985 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07001986 mode = PLD_FTM;
Houston Hoffman75ef5a52016-04-14 17:15:49 -07001987 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07001988 mode = PLD_EPPING;
Peng Xu7b962532015-10-02 17:17:03 -07001989 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07001990 mode = PLD_MISSION;
Peng Xu7b962532015-10-02 17:17:03 -07001991
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07001992 if (BYPASS_QMI)
1993 return 0;
1994 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07001995 return pld_wlan_enable(scn->qdf_dev->dev, &cfg,
1996 mode, QWLAN_VERSIONSTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001997}
1998
Houston Hoffman75ef5a52016-04-14 17:15:49 -07001999#define CE_EPPING_USES_IRQ true
2000
Houston Hoffman108da402016-03-14 21:11:24 -07002001/**
2002 * hif_ce_prepare_config() - load the correct static tables.
2003 * @scn: hif context
2004 *
2005 * Epping uses different static attribute tables than mission mode.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002006 */
Houston Hoffman108da402016-03-14 21:11:24 -07002007void hif_ce_prepare_config(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002008{
Komal Seelambd7c51d2016-02-24 10:27:30 +05302009 uint32_t mode = hif_get_conparam(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002010 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2011 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302012 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002013
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002014 /* if epping is enabled we need to use the epping configuration. */
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002015 if (QDF_IS_EPPING_ENABLED(mode)) {
2016 if (CE_EPPING_USES_IRQ)
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302017 hif_state->host_ce_config = host_ce_config_wlan_epping_irq;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002018 else
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302019 hif_state->host_ce_config = host_ce_config_wlan_epping_poll;
2020 hif_state->target_ce_config = target_ce_config_wlan_epping;
2021 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002022 target_service_to_ce_map =
2023 target_service_to_ce_map_wlan_epping;
2024 target_service_to_ce_map_sz =
2025 sizeof(target_service_to_ce_map_wlan_epping);
Vishwajith Upendra70efc752016-04-18 11:23:49 -07002026 target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
2027 shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002028 }
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002029
2030 switch (tgt_info->target_type) {
2031 default:
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302032 hif_state->host_ce_config = host_ce_config_wlan;
2033 hif_state->target_ce_config = target_ce_config_wlan;
2034 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002035 break;
2036 case TARGET_TYPE_AR900B:
2037 case TARGET_TYPE_QCA9984:
2038 case TARGET_TYPE_IPQ4019:
2039 case TARGET_TYPE_QCA9888:
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302040 hif_state->host_ce_config = host_ce_config_wlan_ar900b;
2041 hif_state->target_ce_config = target_ce_config_wlan_ar900b;
2042 hif_state->target_ce_config_sz =
2043 sizeof(target_ce_config_wlan_ar900b);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002044
2045 target_service_to_ce_map = target_service_to_ce_map_ar900b;
2046 target_service_to_ce_map_sz =
2047 sizeof(target_service_to_ce_map_ar900b);
2048 break;
2049
2050 case TARGET_TYPE_AR9888:
2051 case TARGET_TYPE_AR9888V2:
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302052 hif_state->host_ce_config = host_ce_config_wlan_ar9888;
2053 hif_state->target_ce_config = target_ce_config_wlan_ar9888;
2054 hif_state->target_ce_config_sz =
2055 sizeof(target_ce_config_wlan_ar9888);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002056
2057 target_service_to_ce_map = target_service_to_ce_map_ar900b;
2058 target_service_to_ce_map_sz =
2059 sizeof(target_service_to_ce_map_ar900b);
2060 break;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302061#ifdef QCA_WIFI_QCA8074
2062 case TARGET_TYPE_QCA8074:
2063 hif_state->host_ce_config = host_ce_config_wlan_qca8074;
2064 hif_state->target_ce_config = target_ce_config_wlan_qca8074;
2065 hif_state->target_ce_config_sz =
2066 sizeof(target_ce_config_wlan_qca8074);
2067 break;
2068#endif
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002069 }
Houston Hoffman108da402016-03-14 21:11:24 -07002070}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002071
Houston Hoffman108da402016-03-14 21:11:24 -07002072/**
2073 * hif_ce_open() - do ce specific allocations
2074 * @hif_sc: pointer to hif context
2075 *
2076 * return: 0 for success or QDF_STATUS_E_NOMEM
2077 */
2078QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
2079{
2080 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002081
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302082 qdf_spinlock_create(&hif_state->irq_reg_lock);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302083 qdf_spinlock_create(&hif_state->keep_awake_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002084 return QDF_STATUS_SUCCESS;
2085}
2086
2087/**
2088 * hif_ce_close() - do ce specific free
2089 * @hif_sc: pointer to hif context
2090 */
2091void hif_ce_close(struct hif_softc *hif_sc)
2092{
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302093 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2094
2095 qdf_spinlock_destroy(&hif_state->irq_reg_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002096}
2097
2098/**
2099 * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
2100 * @hif_sc: hif context
2101 *
2102 * uses state variables to support cleaning up when hif_config_ce fails.
2103 */
2104void hif_unconfig_ce(struct hif_softc *hif_sc)
2105{
2106 int pipe_num;
2107 struct HIF_CE_pipe_info *pipe_info;
2108 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2109
2110 for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
2111 pipe_info = &hif_state->pipe_info[pipe_num];
2112 if (pipe_info->ce_hdl) {
2113 ce_unregister_irq(hif_state, (1 << pipe_num));
2114 hif_sc->request_irq_done = false;
2115 ce_fini(pipe_info->ce_hdl);
2116 pipe_info->ce_hdl = NULL;
2117 pipe_info->buf_sz = 0;
2118 }
2119 }
Houston Hoffman108da402016-03-14 21:11:24 -07002120 if (hif_sc->athdiag_procfs_inited) {
2121 athdiag_procfs_remove();
2122 hif_sc->athdiag_procfs_inited = false;
2123 }
2124}
2125
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002126#ifdef CONFIG_BYPASS_QMI
2127#define FW_SHARED_MEM (2 * 1024 * 1024)
2128
2129/**
2130 * hif_post_static_buf_to_target() - post static buffer to WLAN FW
2131 * @scn: pointer to HIF structure
2132 *
2133 * WLAN FW needs 2MB memory from DDR when QMI is disabled.
2134 *
2135 * Return: void
2136 */
2137static void hif_post_static_buf_to_target(struct hif_softc *scn)
2138{
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002139 void *target_va;
2140 phys_addr_t target_pa;
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002141
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002142 target_va = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev,
2143 FW_SHARED_MEM, &target_pa);
2144 if (NULL == target_va) {
2145 HIF_TRACE("Memory allocation failed could not post target buf");
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002146 return;
2147 }
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002148 hif_write32_mb(scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
2149 HIF_TRACE("target va %pK target pa %pa", target_va, &target_pa);
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002150}
2151#else
2152static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
2153{
2154 return;
2155}
2156#endif
2157
Dustin Brown6bdbda52016-09-27 15:52:30 -07002158#ifdef WLAN_SUSPEND_RESUME_TEST
2159static void hif_fake_apps_init_ctx(struct hif_softc *scn)
2160{
2161 INIT_WORK(&scn->fake_apps_ctx.resume_work,
2162 hif_fake_apps_resume_work);
2163}
2164#else
2165static inline void hif_fake_apps_init_ctx(struct hif_softc *scn) {}
2166#endif
2167
Houston Hoffman108da402016-03-14 21:11:24 -07002168/**
2169 * hif_config_ce() - configure copy engines
2170 * @scn: hif context
2171 *
2172 * Prepares fw, copy engine hardware and host sw according
2173 * to the attributes selected by hif_ce_prepare_config.
2174 *
2175 * also calls athdiag_procfs_init
2176 *
2177 * return: 0 for success nonzero for failure.
2178 */
2179int hif_config_ce(struct hif_softc *scn)
2180{
2181 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2182 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2183 struct HIF_CE_pipe_info *pipe_info;
2184 int pipe_num;
Houston Hoffman85925072016-05-06 17:02:18 -07002185 struct CE_state *ce_state;
Houston Hoffman108da402016-03-14 21:11:24 -07002186#ifdef ADRASTEA_SHADOW_REGISTERS
2187 int i;
2188#endif
2189 QDF_STATUS rv = QDF_STATUS_SUCCESS;
2190
2191 scn->notice_send = true;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002192
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002193 hif_post_static_buf_to_target(scn);
2194
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002195 hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
Houston Hoffman108da402016-03-14 21:11:24 -07002196
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002197 hif_config_rri_on_ddr(scn);
2198
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302199 hif_state->ce_services = ce_services_attach(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002200 /* During CE initializtion */
2201 scn->ce_count = HOST_CE_COUNT;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002202 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
2203 struct CE_attr *attr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002204 pipe_info = &hif_state->pipe_info[pipe_num];
2205 pipe_info->pipe_num = pipe_num;
2206 pipe_info->HIF_CE_state = hif_state;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302207 attr = &hif_state->host_ce_config[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002208 pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
Houston Hoffman85925072016-05-06 17:02:18 -07002209 ce_state = scn->ce_id_to_state[pipe_num];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302210 QDF_ASSERT(pipe_info->ce_hdl != NULL);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002211 if (pipe_info->ce_hdl == NULL) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302212 rv = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002213 A_TARGET_ACCESS_UNLIKELY(scn);
2214 goto err;
2215 }
2216
2217 if (pipe_num == DIAG_CE_ID) {
2218 /* Reserve the ultimate CE for
2219 * Diagnostic Window support */
Houston Hoffmanc1d9a412016-03-30 21:07:57 -07002220 hif_state->ce_diag = pipe_info->ce_hdl;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002221 continue;
2222 }
2223
Houston Hoffman85925072016-05-06 17:02:18 -07002224 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
2225 (ce_state->htt_rx_data))
2226 continue;
2227
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302228 pipe_info->buf_sz = (qdf_size_t) (attr->src_sz_max);
2229 qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002230 if (attr->dest_nentries > 0) {
2231 atomic_set(&pipe_info->recv_bufs_needed,
2232 init_buffer_count(attr->dest_nentries - 1));
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302233 /*SRNG based CE has one entry less */
2234 if (ce_srng_based(scn))
2235 atomic_dec(&pipe_info->recv_bufs_needed);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002236 } else {
2237 atomic_set(&pipe_info->recv_bufs_needed, 0);
2238 }
2239 ce_tasklet_init(hif_state, (1 << pipe_num));
2240 ce_register_irq(hif_state, (1 << pipe_num));
2241 scn->request_irq_done = true;
2242 }
2243
2244 if (athdiag_procfs_init(scn) != 0) {
2245 A_TARGET_ACCESS_UNLIKELY(scn);
2246 goto err;
2247 }
2248 scn->athdiag_procfs_inited = true;
2249
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002250 HIF_INFO_MED("%s: ce_init done", __func__);
2251
Houston Hoffman108da402016-03-14 21:11:24 -07002252 init_tasklet_workers(hif_hdl);
Dustin Brown6bdbda52016-09-27 15:52:30 -07002253 hif_fake_apps_init_ctx(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002254
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002255 HIF_TRACE("%s: X, ret = %d", __func__, rv);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002256
2257#ifdef ADRASTEA_SHADOW_REGISTERS
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002258 HIF_INFO("%s, Using Shadow Registers instead of CE Registers", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002259 for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002260 HIF_INFO("%s Shadow Register%d is mapped to address %x",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002261 __func__, i,
2262 (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
2263 }
2264#endif
2265
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302266 return rv != QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002267
2268err:
2269 /* Failure, so clean up */
Houston Hoffman108da402016-03-14 21:11:24 -07002270 hif_unconfig_ce(scn);
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002271 HIF_TRACE("%s: X, ret = %d", __func__, rv);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302272 return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002273}
2274
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002275#ifdef WLAN_FEATURE_FASTPATH
2276/**
2277 * hif_ce_fastpath_cb_register() - Register callback for fastpath msg handler
2278 * @handler: Callback funtcion
2279 * @context: handle for callback function
2280 *
2281 * Return: QDF_STATUS_SUCCESS on success or QDF_STATUS_E_FAILURE
2282 */
Houston Hoffman127467f2016-04-26 22:37:14 -07002283int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
2284 fastpath_msg_handler handler,
2285 void *context)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002286{
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002287 struct CE_state *ce_state;
Houston Hoffman127467f2016-04-26 22:37:14 -07002288 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002289 int i;
2290
Himanshu Agarwal2a924592016-06-30 18:04:14 +05302291 if (!scn) {
2292 HIF_ERROR("%s: scn is NULL", __func__);
2293 QDF_ASSERT(0);
2294 return QDF_STATUS_E_FAILURE;
2295 }
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002296
2297 if (!scn->fastpath_mode_on) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002298 HIF_WARN("%s: Fastpath mode disabled", __func__);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002299 return QDF_STATUS_E_FAILURE;
2300 }
2301
Houston Hoffmand6f946c2016-04-06 15:16:00 -07002302 for (i = 0; i < scn->ce_count; i++) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002303 ce_state = scn->ce_id_to_state[i];
2304 if (ce_state->htt_rx_data) {
2305 ce_state->fastpath_handler = handler;
2306 ce_state->context = context;
2307 }
2308 }
2309
2310 return QDF_STATUS_SUCCESS;
2311}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002312#endif
2313
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002314#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08002315/**
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302316 * hif_ce_ipa_get_ce_resource() - get uc resource on hif
Leo Changd85f78d2015-11-13 10:55:34 -08002317 * @scn: bus context
2318 * @ce_sr_base_paddr: copyengine source ring base physical address
2319 * @ce_sr_ring_size: copyengine source ring size
2320 * @ce_reg_paddr: copyengine register physical address
2321 *
2322 * IPA micro controller data path offload feature enabled,
2323 * HIF should release copy engine related resource information to IPA UC
2324 * IPA UC will access hardware resource with released information
2325 *
2326 * Return: None
2327 */
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302328void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302329 qdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002330 uint32_t *ce_sr_ring_size,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302331 qdf_dma_addr_t *ce_reg_paddr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002332{
Komal Seelam02cf2f82016-02-22 20:44:25 +05302333 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002334 struct HIF_CE_pipe_info *pipe_info =
2335 &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
2336 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
2337
2338 ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size,
2339 ce_reg_paddr);
2340 return;
2341}
2342#endif /* IPA_OFFLOAD */
2343
2344
2345#ifdef ADRASTEA_SHADOW_REGISTERS
2346
2347/*
2348 Current shadow register config
2349
2350 -----------------------------------------------------------
2351 Shadow Register | CE | src/dst write index
2352 -----------------------------------------------------------
2353 0 | 0 | src
2354 1 No Config - Doesn't point to anything
2355 2 No Config - Doesn't point to anything
2356 3 | 3 | src
2357 4 | 4 | src
2358 5 | 5 | src
2359 6 No Config - Doesn't point to anything
2360 7 | 7 | src
2361 8 No Config - Doesn't point to anything
2362 9 No Config - Doesn't point to anything
2363 10 No Config - Doesn't point to anything
2364 11 No Config - Doesn't point to anything
2365 -----------------------------------------------------------
2366 12 No Config - Doesn't point to anything
2367 13 | 1 | dst
2368 14 | 2 | dst
2369 15 No Config - Doesn't point to anything
2370 16 No Config - Doesn't point to anything
2371 17 No Config - Doesn't point to anything
2372 18 No Config - Doesn't point to anything
2373 19 | 7 | dst
2374 20 | 8 | dst
2375 21 No Config - Doesn't point to anything
2376 22 No Config - Doesn't point to anything
2377 23 No Config - Doesn't point to anything
2378 -----------------------------------------------------------
2379
2380
2381 ToDo - Move shadow register config to following in the future
2382 This helps free up a block of shadow registers towards the end.
2383 Can be used for other purposes
2384
2385 -----------------------------------------------------------
2386 Shadow Register | CE | src/dst write index
2387 -----------------------------------------------------------
2388 0 | 0 | src
2389 1 | 3 | src
2390 2 | 4 | src
2391 3 | 5 | src
2392 4 | 7 | src
2393 -----------------------------------------------------------
2394 5 | 1 | dst
2395 6 | 2 | dst
2396 7 | 7 | dst
2397 8 | 8 | dst
2398 -----------------------------------------------------------
2399 9 No Config - Doesn't point to anything
2400 12 No Config - Doesn't point to anything
2401 13 No Config - Doesn't point to anything
2402 14 No Config - Doesn't point to anything
2403 15 No Config - Doesn't point to anything
2404 16 No Config - Doesn't point to anything
2405 17 No Config - Doesn't point to anything
2406 18 No Config - Doesn't point to anything
2407 19 No Config - Doesn't point to anything
2408 20 No Config - Doesn't point to anything
2409 21 No Config - Doesn't point to anything
2410 22 No Config - Doesn't point to anything
2411 23 No Config - Doesn't point to anything
2412 -----------------------------------------------------------
2413*/
2414
Komal Seelam644263d2016-02-22 20:45:49 +05302415u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002416{
2417 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002418 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002419
Houston Hoffmane6330442016-02-26 12:19:11 -08002420 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002421 case 0:
2422 addr = SHADOW_VALUE0;
2423 break;
2424 case 3:
2425 addr = SHADOW_VALUE3;
2426 break;
2427 case 4:
2428 addr = SHADOW_VALUE4;
2429 break;
2430 case 5:
2431 addr = SHADOW_VALUE5;
2432 break;
2433 case 7:
2434 addr = SHADOW_VALUE7;
2435 break;
2436 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002437 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302438 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002439 }
2440 return addr;
2441
2442}
2443
Komal Seelam644263d2016-02-22 20:45:49 +05302444u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002445{
2446 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002447 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002448
Houston Hoffmane6330442016-02-26 12:19:11 -08002449 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002450 case 1:
2451 addr = SHADOW_VALUE13;
2452 break;
2453 case 2:
2454 addr = SHADOW_VALUE14;
2455 break;
Vishwajith Upendra70efc752016-04-18 11:23:49 -07002456 case 5:
2457 addr = SHADOW_VALUE17;
2458 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002459 case 7:
2460 addr = SHADOW_VALUE19;
2461 break;
2462 case 8:
2463 addr = SHADOW_VALUE20;
2464 break;
Houston Hoffmane6330442016-02-26 12:19:11 -08002465 case 9:
2466 addr = SHADOW_VALUE21;
2467 break;
2468 case 10:
2469 addr = SHADOW_VALUE22;
2470 break;
Nirav Shah75cc5c82016-05-25 10:52:38 +05302471 case 11:
2472 addr = SHADOW_VALUE23;
2473 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002474 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002475 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302476 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002477 }
2478
2479 return addr;
2480
2481}
2482#endif
2483
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002484#if defined(FEATURE_LRO)
2485/**
2486 * ce_lro_flush_cb_register() - register the LRO flush
2487 * callback
2488 * @scn: HIF context
2489 * @handler: callback function
2490 * @data: opaque data pointer to be passed back
2491 *
2492 * Store the LRO flush callback provided
2493 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002494 * Return: Number of instances the callback is registered for
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002495 */
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002496int ce_lro_flush_cb_register(struct hif_opaque_softc *hif_hdl,
2497 void (handler)(void *), void *data)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002498{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002499 int rc = 0;
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002500 int i;
2501 struct CE_state *ce_state;
Komal Seelam5584a7c2016-02-24 19:22:48 +05302502 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002503
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302504 QDF_ASSERT(scn != NULL);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002505
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002506 if (scn != NULL) {
2507 for (i = 0; i < scn->ce_count; i++) {
2508 ce_state = scn->ce_id_to_state[i];
2509 if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
2510 ce_state->lro_flush_cb = handler;
2511 ce_state->lro_data = data;
2512 rc++;
2513 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002514 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002515 } else {
2516 HIF_ERROR("%s: hif_state NULL!", __func__);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002517 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002518 return rc;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002519}
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002520
2521/**
2522 * ce_lro_flush_cb_deregister() - deregister the LRO flush
2523 * callback
2524 * @scn: HIF context
2525 *
2526 * Remove the LRO flush callback
2527 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002528 * Return: Number of instances the callback is de-registered
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002529 */
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002530int ce_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl)
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002531{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002532 int rc = 0;
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002533 int i;
2534 struct CE_state *ce_state;
Komal Seelam5584a7c2016-02-24 19:22:48 +05302535 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002536
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302537 QDF_ASSERT(scn != NULL);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002538 if (scn != NULL) {
2539 for (i = 0; i < scn->ce_count; i++) {
2540 ce_state = scn->ce_id_to_state[i];
2541 if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
2542 ce_state->lro_flush_cb = NULL;
2543 ce_state->lro_data = NULL;
2544 rc++;
2545 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002546 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002547 } else {
2548 HIF_ERROR("%s: hif_state NULL!", __func__);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002549 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002550 return rc;
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002551}
2552#endif
Sanjay Devnanic319c822015-11-06 16:44:28 -08002553
2554/**
2555 * hif_map_service_to_pipe() - returns the ce ids pertaining to
2556 * this service
Komal Seelam644263d2016-02-22 20:45:49 +05302557 * @scn: hif_softc pointer.
Sanjay Devnanic319c822015-11-06 16:44:28 -08002558 * @svc_id: Service ID for which the mapping is needed.
2559 * @ul_pipe: address of the container in which ul pipe is returned.
2560 * @dl_pipe: address of the container in which dl pipe is returned.
2561 * @ul_is_polled: address of the container in which a bool
2562 * indicating if the UL CE for this service
2563 * is polled is returned.
2564 * @dl_is_polled: address of the container in which a bool
2565 * indicating if the DL CE for this service
2566 * is polled is returned.
2567 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002568 * Return: Indicates whether the service has been found in the table.
2569 * Upon return, ul_is_polled is updated only if ul_pipe is updated.
2570 * There will be warning logs if either leg has not been updated
2571 * because it missed the entry in the table (but this is not an err).
Sanjay Devnanic319c822015-11-06 16:44:28 -08002572 */
Komal Seelam5584a7c2016-02-24 19:22:48 +05302573int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
Sanjay Devnanic319c822015-11-06 16:44:28 -08002574 uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
2575 int *dl_is_polled)
2576{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002577 int status = QDF_STATUS_E_INVAL;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002578 unsigned int i;
2579 struct service_to_pipe element;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002580 struct service_to_pipe *tgt_svc_map_to_use;
2581 size_t sz_tgt_svc_map_to_use;
Komal Seelambd7c51d2016-02-24 10:27:30 +05302582 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
2583 uint32_t mode = hif_get_conparam(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002584 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002585 bool dl_updated = false;
2586 bool ul_updated = false;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302587 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanic319c822015-11-06 16:44:28 -08002588
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002589 if (QDF_IS_EPPING_ENABLED(mode)) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002590 tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
2591 sz_tgt_svc_map_to_use =
2592 sizeof(target_service_to_ce_map_wlan_epping);
2593 } else {
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002594 switch (tgt_info->target_type) {
2595 default:
2596 tgt_svc_map_to_use = target_service_to_ce_map_wlan;
2597 sz_tgt_svc_map_to_use =
2598 sizeof(target_service_to_ce_map_wlan);
2599 break;
2600 case TARGET_TYPE_AR900B:
2601 case TARGET_TYPE_QCA9984:
2602 case TARGET_TYPE_IPQ4019:
2603 case TARGET_TYPE_QCA9888:
2604 case TARGET_TYPE_AR9888:
2605 case TARGET_TYPE_AR9888V2:
2606 tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
2607 sz_tgt_svc_map_to_use =
2608 sizeof(target_service_to_ce_map_ar900b);
2609 break;
2610 }
Sanjay Devnanic319c822015-11-06 16:44:28 -08002611 }
2612
2613 *dl_is_polled = 0; /* polling for received messages not supported */
2614
2615 for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
2616
2617 memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
2618 if (element.service_id == svc_id) {
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002619 if (element.pipedir == PIPEDIR_OUT) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002620 *ul_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002621 *ul_is_polled =
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302622 (hif_state->host_ce_config[*ul_pipe].flags &
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002623 CE_ATTR_DISABLE_INTR) != 0;
2624 ul_updated = true;
2625 } else if (element.pipedir == PIPEDIR_IN) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002626 *dl_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002627 dl_updated = true;
2628 }
2629 status = QDF_STATUS_SUCCESS;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002630 }
2631 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002632 if (ul_updated == false)
2633 HIF_WARN("%s: ul pipe is NOT updated for service %d",
2634 __func__, svc_id);
2635 if (dl_updated == false)
2636 HIF_WARN("%s: dl pipe is NOT updated for service %d",
2637 __func__, svc_id);
Sanjay Devnanic319c822015-11-06 16:44:28 -08002638
2639 return status;
2640}
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002641
2642#ifdef SHADOW_REG_DEBUG
Komal Seelam644263d2016-02-22 20:45:49 +05302643inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002644 uint32_t CE_ctrl_addr)
2645{
2646 uint32_t read_from_hw, srri_from_ddr = 0;
2647
2648 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
2649
2650 srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
2651
2652 if (read_from_hw != srri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002653 HIF_ERROR("%s: error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
2654 __func__, srri_from_ddr, read_from_hw,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002655 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302656 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002657 }
2658 return srri_from_ddr;
2659}
2660
2661
Komal Seelam644263d2016-02-22 20:45:49 +05302662inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002663 uint32_t CE_ctrl_addr)
2664{
2665 uint32_t read_from_hw, drri_from_ddr = 0;
2666
2667 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
2668
2669 drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
2670
2671 if (read_from_hw != drri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002672 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 -08002673 drri_from_ddr, read_from_hw,
2674 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302675 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002676 }
2677 return drri_from_ddr;
2678}
2679
2680#endif
2681
Houston Hoffman3d0cda82015-12-03 13:25:05 -08002682#ifdef ADRASTEA_RRI_ON_DDR
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002683/**
2684 * hif_get_src_ring_read_index(): Called to get the SRRI
2685 *
Komal Seelam644263d2016-02-22 20:45:49 +05302686 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002687 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
2688 *
2689 * This function returns the SRRI to the caller. For CEs that
2690 * dont have interrupts enabled, we look at the DDR based SRRI
2691 *
2692 * Return: SRRI
2693 */
Komal Seelam644263d2016-02-22 20:45:49 +05302694inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002695 uint32_t CE_ctrl_addr)
2696{
2697 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302698 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002699
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302700 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002701 if (attr.flags & CE_ATTR_DISABLE_INTR)
2702 return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
2703 else
2704 return A_TARGET_READ(scn,
2705 (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
2706}
2707
2708/**
2709 * hif_get_dst_ring_read_index(): Called to get the DRRI
2710 *
Komal Seelam644263d2016-02-22 20:45:49 +05302711 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002712 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
2713 *
2714 * This function returns the DRRI to the caller. For CEs that
2715 * dont have interrupts enabled, we look at the DDR based DRRI
2716 *
2717 * Return: DRRI
2718 */
Komal Seelam644263d2016-02-22 20:45:49 +05302719inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002720 uint32_t CE_ctrl_addr)
2721{
2722 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302723 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002724
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302725 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002726
2727 if (attr.flags & CE_ATTR_DISABLE_INTR)
2728 return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
2729 else
2730 return A_TARGET_READ(scn,
2731 (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
2732}
2733
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002734/**
2735 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
2736 *
Komal Seelam644263d2016-02-22 20:45:49 +05302737 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002738 *
2739 * This function allocates non cached memory on ddr and sends
2740 * the physical address of this memory to the CE hardware. The
2741 * hardware updates the RRI on this particular location.
2742 *
2743 * Return: None
2744 */
Komal Seelam644263d2016-02-22 20:45:49 +05302745static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002746{
2747 unsigned int i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302748 qdf_dma_addr_t paddr_rri_on_ddr;
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002749 uint32_t high_paddr, low_paddr;
2750 scn->vaddr_rri_on_ddr =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302751 (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
2752 scn->qdf_dev->dev, (CE_COUNT*sizeof(uint32_t)),
2753 &paddr_rri_on_ddr);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002754
2755 low_paddr = BITS0_TO_31(paddr_rri_on_ddr);
2756 high_paddr = BITS32_TO_35(paddr_rri_on_ddr);
2757
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002758 HIF_INFO("%s using srri and drri from DDR", __func__);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002759
2760 WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
2761 WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
2762
2763 for (i = 0; i < CE_COUNT; i++)
2764 CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
2765
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302766 qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t));
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002767
2768 return;
2769}
2770#else
2771
2772/**
2773 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
2774 *
Komal Seelam644263d2016-02-22 20:45:49 +05302775 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002776 *
2777 * This is a dummy implementation for platforms that don't
2778 * support this functionality.
2779 *
2780 * Return: None
2781 */
Komal Seelam644263d2016-02-22 20:45:49 +05302782static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002783{
2784 return;
2785}
2786#endif
Govind Singh2443fb32016-01-13 17:44:48 +05302787
2788/**
2789 * hif_dump_ce_registers() - dump ce registers
Komal Seelam5584a7c2016-02-24 19:22:48 +05302790 * @scn: hif_opaque_softc pointer.
Govind Singh2443fb32016-01-13 17:44:48 +05302791 *
2792 * Output the copy engine registers
2793 *
2794 * Return: 0 for success or error code
2795 */
Komal Seelam644263d2016-02-22 20:45:49 +05302796int hif_dump_ce_registers(struct hif_softc *scn)
Govind Singh2443fb32016-01-13 17:44:48 +05302797{
Komal Seelam5584a7c2016-02-24 19:22:48 +05302798 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Govind Singh2443fb32016-01-13 17:44:48 +05302799 uint32_t ce_reg_address = CE0_BASE_ADDRESS;
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002800 uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
Govind Singh2443fb32016-01-13 17:44:48 +05302801 uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
2802 uint16_t i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302803 QDF_STATUS status;
Govind Singh2443fb32016-01-13 17:44:48 +05302804
Houston Hoffmand6f946c2016-04-06 15:16:00 -07002805 for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
2806 if (scn->ce_id_to_state[i] == NULL) {
2807 HIF_DBG("CE%d not used.", i);
2808 continue;
2809 }
2810
Komal Seelam644263d2016-02-22 20:45:49 +05302811 status = hif_diag_read_mem(hif_hdl, ce_reg_address,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002812 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05302813 ce_reg_word_size * sizeof(uint32_t));
2814
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302815 if (status != QDF_STATUS_SUCCESS) {
Govind Singh2443fb32016-01-13 17:44:48 +05302816 HIF_ERROR("Dumping CE register failed!");
2817 return -EACCES;
2818 }
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05302819 HIF_ERROR("CE%d=>\n", i);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302820 qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002821 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05302822 ce_reg_word_size * sizeof(uint32_t));
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05302823 qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d\n", (ce_reg_address
2824 + SR_WR_INDEX_ADDRESS),
2825 ce_reg_values[SR_WR_INDEX_ADDRESS/4]);
2826 qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d\n", (ce_reg_address
2827 + CURRENT_SRRI_ADDRESS),
2828 ce_reg_values[CURRENT_SRRI_ADDRESS/4]);
2829 qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d\n", (ce_reg_address
2830 + DST_WR_INDEX_ADDRESS),
2831 ce_reg_values[DST_WR_INDEX_ADDRESS/4]);
2832 qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d\n", (ce_reg_address
2833 + CURRENT_DRRI_ADDRESS),
2834 ce_reg_values[CURRENT_DRRI_ADDRESS/4]);
2835 qdf_print("---\n");
Govind Singh2443fb32016-01-13 17:44:48 +05302836 }
Govind Singh2443fb32016-01-13 17:44:48 +05302837 return 0;
2838}
Houston Hoffman85925072016-05-06 17:02:18 -07002839#ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
2840struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
2841 struct hif_pipe_addl_info *hif_info, uint32_t pipe)
2842{
2843 struct hif_softc *scn = HIF_GET_SOFTC(osc);
2844 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
2845 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
2846 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
2847 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
2848 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
2849 struct CE_ring_state *src_ring = ce_state->src_ring;
2850 struct CE_ring_state *dest_ring = ce_state->dest_ring;
2851
2852 if (src_ring) {
2853 hif_info->ul_pipe.nentries = src_ring->nentries;
2854 hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
2855 hif_info->ul_pipe.sw_index = src_ring->sw_index;
2856 hif_info->ul_pipe.write_index = src_ring->write_index;
2857 hif_info->ul_pipe.hw_index = src_ring->hw_index;
2858 hif_info->ul_pipe.base_addr_CE_space =
2859 src_ring->base_addr_CE_space;
2860 hif_info->ul_pipe.base_addr_owner_space =
2861 src_ring->base_addr_owner_space;
2862 }
2863
2864
2865 if (dest_ring) {
2866 hif_info->dl_pipe.nentries = dest_ring->nentries;
2867 hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
2868 hif_info->dl_pipe.sw_index = dest_ring->sw_index;
2869 hif_info->dl_pipe.write_index = dest_ring->write_index;
2870 hif_info->dl_pipe.hw_index = dest_ring->hw_index;
2871 hif_info->dl_pipe.base_addr_CE_space =
2872 dest_ring->base_addr_CE_space;
2873 hif_info->dl_pipe.base_addr_owner_space =
2874 dest_ring->base_addr_owner_space;
2875 }
2876
2877 hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
2878 hif_info->ctrl_addr = ce_state->ctrl_addr;
2879
2880 return hif_info;
2881}
2882
2883uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
2884{
2885 struct hif_softc *scn = HIF_GET_SOFTC(osc);
2886
2887 scn->nss_wifi_ol_mode = mode;
2888 return 0;
2889}
2890
2891#endif
2892
2893void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
2894{
2895 struct hif_softc *scn = HIF_GET_SOFTC(osc);
2896 struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
2897 uint32_t ctrl_addr = CE_state->ctrl_addr;
2898
2899 Q_TARGET_ACCESS_BEGIN(scn);
2900 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
2901 Q_TARGET_ACCESS_END(scn);
2902}
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302903
2904/**
2905 * hif_fw_event_handler() - hif fw event handler
2906 * @hif_state: pointer to hif ce state structure
2907 *
2908 * Process fw events and raise HTC callback to process fw events.
2909 *
2910 * Return: none
2911 */
2912static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
2913{
2914 struct hif_msg_callbacks *msg_callbacks =
2915 &hif_state->msg_callbacks_current;
2916
2917 if (!msg_callbacks->fwEventHandler)
2918 return;
2919
2920 msg_callbacks->fwEventHandler(msg_callbacks->Context,
2921 QDF_STATUS_E_FAILURE);
2922}
2923
2924#ifndef QCA_WIFI_3_0
2925/**
2926 * hif_fw_interrupt_handler() - FW interrupt handler
2927 * @irq: irq number
2928 * @arg: the user pointer
2929 *
2930 * Called from the PCI interrupt handler when a
2931 * firmware-generated interrupt to the Host.
2932 *
2933 * Return: status of handled irq
2934 */
2935irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
2936{
2937 struct hif_softc *scn = arg;
2938 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2939 uint32_t fw_indicator_address, fw_indicator;
2940
2941 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
2942 return ATH_ISR_NOSCHED;
2943
2944 fw_indicator_address = hif_state->fw_indicator_address;
2945 /* For sudden unplug this will return ~0 */
2946 fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
2947
2948 if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
2949 /* ACK: clear Target-side pending event */
2950 A_TARGET_WRITE(scn, fw_indicator_address,
2951 fw_indicator & ~FW_IND_EVENT_PENDING);
2952 if (Q_TARGET_ACCESS_END(scn) < 0)
2953 return ATH_ISR_SCHED;
2954
2955 if (hif_state->started) {
2956 hif_fw_event_handler(hif_state);
2957 } else {
2958 /*
2959 * Probable Target failure before we're prepared
2960 * to handle it. Generally unexpected.
2961 */
2962 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
2963 ("%s: Early firmware event indicated\n",
2964 __func__));
2965 }
2966 } else {
2967 if (Q_TARGET_ACCESS_END(scn) < 0)
2968 return ATH_ISR_SCHED;
2969 }
2970
2971 return ATH_ISR_SCHED;
2972}
2973#else
2974irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
2975{
2976 return ATH_ISR_SCHED;
2977}
2978#endif /* #ifdef QCA_WIFI_3_0 */
2979
2980
2981/**
2982 * hif_wlan_disable(): call the platform driver to disable wlan
2983 * @scn: HIF Context
2984 *
2985 * This function passes the con_mode to platform driver to disable
2986 * wlan.
2987 *
2988 * Return: void
2989 */
2990void hif_wlan_disable(struct hif_softc *scn)
2991{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002992 enum pld_driver_mode mode;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302993 uint32_t con_mode = hif_get_conparam(scn);
2994
2995 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002996 mode = PLD_FTM;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302997 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002998 mode = PLD_EPPING;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302999 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003000 mode = PLD_MISSION;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303001
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003002 pld_wlan_disable(scn->qdf_dev->dev, mode);
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303003}
Dustin Brown6bdbda52016-09-27 15:52:30 -07003004