blob: d2a7abb9ab2aa1da59a5b68d345c7cfd7567aff6 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
yeshwanth sriram guntuka78ee68f2016-10-25 11:57:58 +05302 * Copyright (c) 2013-2017 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 Hoffman88c896f2016-12-14 09:56:35 -0800379/* PIPEDIR_OUT = HOST to Target */
380/* PIPEDIR_IN = TARGET to HOST */
381static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
382 { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
383 { WMI_DATA_VO_SVC, PIPEDIR_IN , 2, },
384 { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
385 { WMI_DATA_BK_SVC, PIPEDIR_IN , 2, },
386 { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
387 { WMI_DATA_BE_SVC, PIPEDIR_IN , 2, },
388 { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
389 { WMI_DATA_VI_SVC, PIPEDIR_IN , 2, },
390 { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
391 { WMI_CONTROL_SVC, PIPEDIR_IN , 2, },
392 { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
393 { HTC_CTRL_RSVD_SVC, PIPEDIR_IN , 2, },
394 { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
395 { HTT_DATA_MSG_SVC, PIPEDIR_IN , 1, },
396 { PACKET_LOG_SVC, PIPEDIR_IN , 5, },
397 /* (Additions here) */
398 { 0, 0, 0, },
399};
400
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700401static struct service_to_pipe target_service_to_ce_map_ar900b[] = {
402 {
403 WMI_DATA_VO_SVC,
404 PIPEDIR_OUT, /* out = UL = host -> target */
405 3,
406 },
407 {
408 WMI_DATA_VO_SVC,
409 PIPEDIR_IN, /* in = DL = target -> host */
410 2,
411 },
412 {
413 WMI_DATA_BK_SVC,
414 PIPEDIR_OUT, /* out = UL = host -> target */
415 3,
416 },
417 {
418 WMI_DATA_BK_SVC,
419 PIPEDIR_IN, /* in = DL = target -> host */
420 2,
421 },
422 {
423 WMI_DATA_BE_SVC,
424 PIPEDIR_OUT, /* out = UL = host -> target */
425 3,
426 },
427 {
428 WMI_DATA_BE_SVC,
429 PIPEDIR_IN, /* in = DL = target -> host */
430 2,
431 },
432 {
433 WMI_DATA_VI_SVC,
434 PIPEDIR_OUT, /* out = UL = host -> target */
435 3,
436 },
437 {
438 WMI_DATA_VI_SVC,
439 PIPEDIR_IN, /* in = DL = target -> host */
440 2,
441 },
442 {
443 WMI_CONTROL_SVC,
444 PIPEDIR_OUT, /* out = UL = host -> target */
445 3,
446 },
447 {
448 WMI_CONTROL_SVC,
449 PIPEDIR_IN, /* in = DL = target -> host */
450 2,
451 },
452 {
453 HTC_CTRL_RSVD_SVC,
454 PIPEDIR_OUT, /* out = UL = host -> target */
455 0, /* could be moved to 3 (share with WMI) */
456 },
457 {
458 HTC_CTRL_RSVD_SVC,
459 PIPEDIR_IN, /* in = DL = target -> host */
460 1,
461 },
462 {
463 HTC_RAW_STREAMS_SVC, /* not currently used */
464 PIPEDIR_OUT, /* out = UL = host -> target */
465 0,
466 },
467 {
468 HTC_RAW_STREAMS_SVC, /* not currently used */
469 PIPEDIR_IN, /* in = DL = target -> host */
470 1,
471 },
472 {
473 HTT_DATA_MSG_SVC,
474 PIPEDIR_OUT, /* out = UL = host -> target */
475 4,
476 },
477#if WLAN_FEATURE_FASTPATH
478 {
479 HTT_DATA_MSG_SVC,
480 PIPEDIR_IN, /* in = DL = target -> host */
481 5,
482 },
483#else /* WLAN_FEATURE_FASTPATH */
484 {
485 HTT_DATA_MSG_SVC,
486 PIPEDIR_IN, /* in = DL = target -> host */
487 1,
488 },
489#endif /* WLAN_FEATURE_FASTPATH */
490
491 /* (Additions here) */
492
493 { /* Must be last */
494 0,
495 0,
496 0,
497 },
498};
499
500
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700501static struct service_to_pipe *target_service_to_ce_map =
502 target_service_to_ce_map_wlan;
503static int target_service_to_ce_map_sz = sizeof(target_service_to_ce_map_wlan);
504
505static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
506static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
507
508static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
509 {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
510 {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
511 {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
512 {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
513 {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
514 {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
515 {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
516 {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
517 {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
518 {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
519 {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
520 {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
521 {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
522 {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
523 {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
524 {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
525 {0, 0, 0,}, /* Must be last */
526};
527
528/**
529 * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly
530 * @ce_state : pointer to the state context of the CE
531 *
532 * Description:
533 * Sets htt_rx_data attribute of the state structure if the
534 * CE serves one of the HTT DATA services.
535 *
536 * Return:
537 * false (attribute set to false)
538 * true (attribute set to true);
539 */
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700540static bool ce_mark_datapath(struct CE_state *ce_state)
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700541{
542 struct service_to_pipe *svc_map;
543 size_t map_sz;
544 int i;
545 bool rc = false;
Houston Hoffman55fcf5a2016-09-27 23:21:51 -0700546 struct hif_target_info *tgt_info;
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700547
548 if (ce_state != NULL) {
Houston Hoffman55fcf5a2016-09-27 23:21:51 -0700549 tgt_info = &ce_state->scn->target_info;
550
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700551 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(ce_state->scn))) {
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700552 svc_map = target_service_to_ce_map_wlan_epping;
553 map_sz = sizeof(target_service_to_ce_map_wlan_epping) /
554 sizeof(struct service_to_pipe);
555 } else {
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700556 switch (tgt_info->target_type) {
557 default:
558 svc_map = target_service_to_ce_map_wlan;
559 map_sz =
560 sizeof(target_service_to_ce_map_wlan) /
561 sizeof(struct service_to_pipe);
562 break;
563 case TARGET_TYPE_AR900B:
564 case TARGET_TYPE_QCA9984:
565 case TARGET_TYPE_IPQ4019:
566 case TARGET_TYPE_QCA9888:
567 case TARGET_TYPE_AR9888:
568 case TARGET_TYPE_AR9888V2:
569 svc_map = target_service_to_ce_map_ar900b;
570 map_sz =
571 sizeof(target_service_to_ce_map_ar900b)
572 / sizeof(struct service_to_pipe);
573 break;
574 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700575 }
576 for (i = 0; i < map_sz; i++) {
577 if ((svc_map[i].pipenum == ce_state->id) &&
578 ((svc_map[i].service_id == HTT_DATA_MSG_SVC) ||
579 (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
580 (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) {
581 /* HTT CEs are unidirectional */
582 if (svc_map[i].pipedir == PIPEDIR_IN)
583 ce_state->htt_rx_data = true;
584 else
585 ce_state->htt_tx_data = true;
586 rc = true;
587 }
588 }
589 }
590 return rc;
591}
592
Houston Hoffman47808172016-05-06 10:04:21 -0700593/**
594 * ce_ring_test_initial_indexes() - tests the initial ce ring indexes
595 * @ce_id: ce in question
596 * @ring: ring state being examined
597 * @type: "src_ring" or "dest_ring" string for identifying the ring
598 *
599 * Warns on non-zero index values.
600 * Causes a kernel panic if the ring is not empty durring initialization.
601 */
602static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring,
603 char *type)
604{
605 if (ring->write_index != 0 || ring->sw_index != 0)
606 HIF_ERROR("ce %d, %s, initial sw_index = %d, initial write_index =%d",
607 ce_id, type, ring->sw_index, ring->write_index);
608 if (ring->write_index != ring->sw_index)
609 QDF_BUG(0);
610}
611
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530612/**
613 * ce_srng_based() - Does this target use srng
614 * @ce_state : pointer to the state context of the CE
615 *
616 * Description:
617 * returns true if the target is SRNG based
618 *
619 * Return:
620 * false (attribute set to false)
621 * true (attribute set to true);
622 */
623bool ce_srng_based(struct hif_softc *scn)
624{
625 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
626 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
627
628 switch (tgt_info->target_type) {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530629 case TARGET_TYPE_QCA8074:
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700630 case TARGET_TYPE_QCA6290:
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530631 return true;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530632 default:
633 return false;
634 }
635 return false;
636}
637
Venkata Sharath Chandra Manchala837d3232017-01-18 15:11:56 -0800638#if defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6290)
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700639static struct ce_ops *ce_services_attach(struct hif_softc *scn)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530640{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530641 if (ce_srng_based(scn))
642 return ce_services_srng();
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530643
644 return ce_services_legacy();
645}
Venkata Sharath Chandra Manchala837d3232017-01-18 15:11:56 -0800646#else /* QCA_LITHIUM */
647static struct ce_ops *ce_services_attach(struct hif_softc *scn)
648{
649 return ce_services_legacy();
650}
651#endif /* QCA_LITHIUM */
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530652
653static inline uint32_t ce_get_desc_size(struct hif_softc *scn,
654 uint8_t ring_type)
655{
656 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
657
658 return hif_state->ce_services->ce_get_desc_size(ring_type);
659}
660
661
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700662static struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530663 uint8_t ring_type, uint32_t nentries)
664{
665 uint32_t ce_nbytes;
666 char *ptr;
667 qdf_dma_addr_t base_addr;
668 struct CE_ring_state *ce_ring;
669 uint32_t desc_size;
670 struct hif_softc *scn = CE_state->scn;
671
672 ce_nbytes = sizeof(struct CE_ring_state)
673 + (nentries * sizeof(void *));
674 ptr = qdf_mem_malloc(ce_nbytes);
675 if (!ptr)
676 return NULL;
677
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530678 ce_ring = (struct CE_ring_state *)ptr;
679 ptr += sizeof(struct CE_ring_state);
680 ce_ring->nentries = nentries;
681 ce_ring->nentries_mask = nentries - 1;
682
683 ce_ring->low_water_mark_nentries = 0;
684 ce_ring->high_water_mark_nentries = nentries;
685 ce_ring->per_transfer_context = (void **)ptr;
686
687 desc_size = ce_get_desc_size(scn, ring_type);
688
689 /* Legacy platforms that do not support cache
690 * coherent DMA are unsupported
691 */
692 ce_ring->base_addr_owner_space_unaligned =
693 qdf_mem_alloc_consistent(scn->qdf_dev,
694 scn->qdf_dev->dev,
695 (nentries *
696 desc_size +
697 CE_DESC_RING_ALIGN),
698 &base_addr);
699 if (ce_ring->base_addr_owner_space_unaligned
700 == NULL) {
701 HIF_ERROR("%s: ring has no DMA mem",
702 __func__);
703 qdf_mem_free(ptr);
704 return NULL;
705 }
706 ce_ring->base_addr_CE_space_unaligned = base_addr;
707
708 /* Correctly initialize memory to 0 to
709 * prevent garbage data crashing system
710 * when download firmware
711 */
712 qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned,
713 nentries * desc_size +
714 CE_DESC_RING_ALIGN);
715
716 if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) {
717
718 ce_ring->base_addr_CE_space =
719 (ce_ring->base_addr_CE_space_unaligned +
720 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1);
721
722 ce_ring->base_addr_owner_space = (void *)
723 (((size_t) ce_ring->base_addr_owner_space_unaligned +
724 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1));
725 } else {
726 ce_ring->base_addr_CE_space =
727 ce_ring->base_addr_CE_space_unaligned;
728 ce_ring->base_addr_owner_space =
729 ce_ring->base_addr_owner_space_unaligned;
730 }
731
732 return ce_ring;
733}
734
735static void ce_ring_setup(struct hif_softc *scn, uint8_t ring_type,
736 uint32_t ce_id, struct CE_ring_state *ring,
737 struct CE_attr *attr)
738{
739 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
740
741 hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id, ring, attr);
742}
743
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800744/*
745 * Initialize a Copy Engine based on caller-supplied attributes.
746 * This may be called once to initialize both source and destination
747 * rings or it may be called twice for separate source and destination
748 * initialization. It may be that only one side or the other is
749 * initialized by software/firmware.
Houston Hoffman233e9092015-09-02 13:37:21 -0700750 *
751 * This should be called durring the initialization sequence before
752 * interupts are enabled, so we don't have to worry about thread safety.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800753 */
Komal Seelam644263d2016-02-22 20:45:49 +0530754struct CE_handle *ce_init(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800755 unsigned int CE_id, struct CE_attr *attr)
756{
757 struct CE_state *CE_state;
758 uint32_t ctrl_addr;
759 unsigned int nentries;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800760 bool malloc_CE_state = false;
761 bool malloc_src_ring = false;
762
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530763 QDF_ASSERT(CE_id < scn->ce_count);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800764 ctrl_addr = CE_BASE_ADDRESS(CE_id);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800765 CE_state = scn->ce_id_to_state[CE_id];
766
767 if (!CE_state) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800768 CE_state =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530769 (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800770 if (!CE_state) {
771 HIF_ERROR("%s: CE_state has no mem", __func__);
772 return NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800773 }
Houston Hoffman233e9092015-09-02 13:37:21 -0700774 malloc_CE_state = true;
Houston Hoffman233e9092015-09-02 13:37:21 -0700775 scn->ce_id_to_state[CE_id] = CE_state;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530776 qdf_spinlock_create(&CE_state->ce_index_lock);
Houston Hoffman233e9092015-09-02 13:37:21 -0700777
778 CE_state->id = CE_id;
779 CE_state->ctrl_addr = ctrl_addr;
780 CE_state->state = CE_RUNNING;
781 CE_state->attr_flags = attr->flags;
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700782 qdf_spinlock_create(&CE_state->lro_unloading_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800783 }
784 CE_state->scn = scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800785
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530786 qdf_atomic_init(&CE_state->rx_pending);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800787 if (attr == NULL) {
788 /* Already initialized; caller wants the handle */
789 return (struct CE_handle *)CE_state;
790 }
791
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800792 if (CE_state->src_sz_max)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530793 QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800794 else
795 CE_state->src_sz_max = attr->src_sz_max;
796
Houston Hoffman68e837e2015-12-04 12:57:24 -0800797 ce_init_ce_desc_event_log(CE_id,
798 attr->src_nentries + attr->dest_nentries);
799
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800800 /* source ring setup */
801 nentries = attr->src_nentries;
802 if (nentries) {
803 struct CE_ring_state *src_ring;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800804 nentries = roundup_pwr2(nentries);
805 if (CE_state->src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530806 QDF_ASSERT(CE_state->src_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800807 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530808 src_ring = CE_state->src_ring =
809 ce_alloc_ring_state(CE_state,
810 CE_RING_SRC,
811 nentries);
812 if (!src_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800813 /* cannot allocate src ring. If the
814 * CE_state is allocated locally free
815 * CE_State and return error.
816 */
817 HIF_ERROR("%s: src ring has no mem", __func__);
818 if (malloc_CE_state) {
819 /* allocated CE_state locally */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800820 scn->ce_id_to_state[CE_id] = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530821 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800822 malloc_CE_state = false;
823 }
824 return NULL;
825 } else {
826 /* we can allocate src ring.
827 * Mark that the src ring is
828 * allocated locally
829 */
830 malloc_src_ring = true;
831 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800832 /*
833 * Also allocate a shadow src ring in
834 * regular mem to use for faster access.
835 */
836 src_ring->shadow_base_unaligned =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530837 qdf_mem_malloc(nentries *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800838 sizeof(struct CE_src_desc) +
839 CE_DESC_RING_ALIGN);
840 if (src_ring->shadow_base_unaligned == NULL) {
841 HIF_ERROR("%s: src ring no shadow_base mem",
842 __func__);
843 goto error_no_dma_mem;
844 }
845 src_ring->shadow_base = (struct CE_src_desc *)
846 (((size_t) src_ring->shadow_base_unaligned +
847 CE_DESC_RING_ALIGN - 1) &
848 ~(CE_DESC_RING_ALIGN - 1));
849
Houston Hoffman4411ad42016-03-14 21:12:04 -0700850 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
851 goto error_target_access;
Houston Hoffmanf789c662016-04-12 15:39:04 -0700852
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530853 ce_ring_setup(scn, CE_RING_SRC, CE_id, src_ring, attr);
854
Houston Hoffman4411ad42016-03-14 21:12:04 -0700855 if (Q_TARGET_ACCESS_END(scn) < 0)
856 goto error_target_access;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530857 ce_ring_test_initial_indexes(CE_id, src_ring,
858 "src_ring");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800859 }
860 }
861
862 /* destination ring setup */
863 nentries = attr->dest_nentries;
864 if (nentries) {
865 struct CE_ring_state *dest_ring;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800866
867 nentries = roundup_pwr2(nentries);
868 if (CE_state->dest_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530869 QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800870 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530871 dest_ring = CE_state->dest_ring =
872 ce_alloc_ring_state(CE_state,
873 CE_RING_DEST,
874 nentries);
875 if (!dest_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800876 /* cannot allocate dst ring. If the CE_state
877 * or src ring is allocated locally free
878 * CE_State and src ring and return error.
879 */
880 HIF_ERROR("%s: dest ring has no mem",
881 __func__);
882 if (malloc_src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530883 qdf_mem_free(CE_state->src_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800884 CE_state->src_ring = NULL;
885 malloc_src_ring = false;
886 }
887 if (malloc_CE_state) {
888 /* allocated CE_state locally */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800889 scn->ce_id_to_state[CE_id] = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530890 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800891 malloc_CE_state = false;
892 }
893 return NULL;
894 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800895
Houston Hoffman4411ad42016-03-14 21:12:04 -0700896 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
897 goto error_target_access;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530898
899 ce_ring_setup(scn, CE_RING_DEST, CE_id, dest_ring, attr);
900
901 if (Q_TARGET_ACCESS_END(scn) < 0)
902 goto error_target_access;
Houston Hoffman47808172016-05-06 10:04:21 -0700903
904 ce_ring_test_initial_indexes(CE_id, dest_ring,
905 "dest_ring");
906
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530907 /* For srng based target, init status ring here */
908 if (ce_srng_based(CE_state->scn)) {
909 CE_state->status_ring =
910 ce_alloc_ring_state(CE_state,
911 CE_RING_STATUS,
912 nentries);
913 if (CE_state->status_ring == NULL) {
914 /*Allocation failed. Cleanup*/
915 qdf_mem_free(CE_state->dest_ring);
916 if (malloc_src_ring) {
917 qdf_mem_free
918 (CE_state->src_ring);
919 CE_state->src_ring = NULL;
920 malloc_src_ring = false;
921 }
922 if (malloc_CE_state) {
923 /* allocated CE_state locally */
924 scn->ce_id_to_state[CE_id] =
925 NULL;
926 qdf_mem_free(CE_state);
927 malloc_CE_state = false;
928 }
Houston Hoffman4411ad42016-03-14 21:12:04 -0700929
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530930 return NULL;
931 }
932 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
933 goto error_target_access;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800934
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530935 ce_ring_setup(scn, CE_RING_STATUS, CE_id,
936 CE_state->status_ring, attr);
937
938 if (Q_TARGET_ACCESS_END(scn) < 0)
939 goto error_target_access;
940
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800941 }
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700942
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800943 /* epping */
944 /* poll timer */
945 if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530946 qdf_timer_init(scn->qdf_dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800947 &CE_state->poll_timer,
948 ce_poll_timeout,
949 CE_state,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530950 QDF_TIMER_TYPE_SW);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800951 CE_state->timer_inited = true;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530952 qdf_timer_mod(&CE_state->poll_timer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800953 CE_POLL_TIMEOUT);
954 }
955 }
956 }
957
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530958 if (!ce_srng_based(scn)) {
959 /* Enable CE error interrupts */
960 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
961 goto error_target_access;
962 CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
963 if (Q_TARGET_ACCESS_END(scn) < 0)
964 goto error_target_access;
965 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800966
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700967 /* update the htt_data attribute */
968 ce_mark_datapath(CE_state);
969
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800970 return (struct CE_handle *)CE_state;
971
Houston Hoffman4411ad42016-03-14 21:12:04 -0700972error_target_access:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800973error_no_dma_mem:
974 ce_fini((struct CE_handle *)CE_state);
975 return NULL;
976}
977
978#ifdef WLAN_FEATURE_FASTPATH
979/**
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -0700980 * hif_enable_fastpath() Update that we have enabled fastpath mode
981 * @hif_ctx: HIF context
982 *
983 * For use in data path
984 *
985 * Retrun: void
986 */
987void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
988{
989 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
990
Houston Hoffmand63cd742016-12-05 11:59:56 -0800991 if (ce_srng_based(scn)) {
992 HIF_INFO("%s, srng rings do not support fastpath", __func__);
993 return;
994 }
Houston Hoffmanc50572b2016-06-08 19:49:46 -0700995 HIF_INFO("%s, Enabling fastpath mode", __func__);
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -0700996 scn->fastpath_mode_on = true;
997}
998
999/**
1000 * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
1001 * @hif_ctx: HIF Context
1002 *
1003 * For use in data path to skip HTC
1004 *
1005 * Return: bool
1006 */
1007bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
1008{
1009 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1010
1011 return scn->fastpath_mode_on;
1012}
1013
1014/**
1015 * hif_get_ce_handle - API to get CE handle for FastPath mode
1016 * @hif_ctx: HIF Context
1017 * @id: CopyEngine Id
1018 *
1019 * API to return CE handle for fastpath mode
1020 *
1021 * Return: void
1022 */
1023void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
1024{
1025 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1026
1027 return scn->ce_id_to_state[id];
1028}
1029
1030/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001031 * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
1032 * No processing is required inside this function.
1033 * @ce_hdl: Cope engine handle
1034 * Using an assert, this function makes sure that,
1035 * the TX CE has been processed completely.
Houston Hoffman9a831ef2015-09-03 14:42:40 -07001036 *
1037 * This is called while dismantling CE structures. No other thread
1038 * should be using these structures while dismantling is occuring
1039 * therfore no locking is needed.
1040 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001041 * Return: none
1042 */
1043void
1044ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
1045{
1046 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1047 struct CE_ring_state *src_ring = ce_state->src_ring;
Komal Seelam644263d2016-02-22 20:45:49 +05301048 struct hif_softc *sc = ce_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001049 uint32_t sw_index, write_index;
Houston Hoffman85925072016-05-06 17:02:18 -07001050 if (hif_is_nss_wifi_enabled(sc))
1051 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001052
Houston Hoffmanc7d54292016-04-13 18:55:37 -07001053 if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
Houston Hoffman85925072016-05-06 17:02:18 -07001054 HIF_INFO("%s %d Fastpath mode ON, Cleaning up HTT Tx CE",
1055 __func__, __LINE__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001056 sw_index = src_ring->sw_index;
1057 write_index = src_ring->sw_index;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001058
1059 /* At this point Tx CE should be clean */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301060 qdf_assert_always(sw_index == write_index);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001061 }
1062}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001063
1064/**
1065 * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
1066 * @ce_hdl: Handle to CE
1067 *
1068 * These buffers are never allocated on the fly, but
1069 * are allocated only once during HIF start and freed
1070 * only once during HIF stop.
1071 * NOTE:
1072 * The assumption here is there is no in-flight DMA in progress
1073 * currently, so that buffers can be freed up safely.
1074 *
1075 * Return: NONE
1076 */
1077void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
1078{
1079 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1080 struct CE_ring_state *dst_ring = ce_state->dest_ring;
1081 qdf_nbuf_t nbuf;
1082 int i;
1083
Houston Hoffman7fe51b12016-11-14 18:01:05 -08001084 if (ce_state->scn->fastpath_mode_on == false)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001085 return;
Houston Hoffman7fe51b12016-11-14 18:01:05 -08001086
1087 if (!ce_state->htt_rx_data)
1088 return;
1089
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001090 /*
1091 * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
1092 * this CE is completely full: does not leave one blank space, to
1093 * distinguish between empty queue & full queue. So free all the
1094 * entries.
1095 */
1096 for (i = 0; i < dst_ring->nentries; i++) {
1097 nbuf = dst_ring->per_transfer_context[i];
1098
1099 /*
1100 * The reasons for doing this check are:
1101 * 1) Protect against calling cleanup before allocating buffers
1102 * 2) In a corner case, FASTPATH_mode_on may be set, but we
1103 * could have a partially filled ring, because of a memory
1104 * allocation failure in the middle of allocating ring.
1105 * This check accounts for that case, checking
1106 * fastpath_mode_on flag or started flag would not have
1107 * covered that case. This is not in performance path,
1108 * so OK to do this.
1109 */
1110 if (nbuf)
1111 qdf_nbuf_free(nbuf);
1112 }
1113}
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001114
1115/**
1116 * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
1117 * @scn: HIF handle
1118 *
1119 * Datapath Rx CEs are special case, where we reuse all the message buffers.
1120 * Hence we have to post all the entries in the pipe, even, in the beginning
1121 * unlike for other CE pipes where one less than dest_nentries are filled in
1122 * the beginning.
1123 *
1124 * Return: None
1125 */
1126static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
1127{
1128 int pipe_num;
1129 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1130
1131 if (scn->fastpath_mode_on == false)
1132 return;
1133
1134 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1135 struct HIF_CE_pipe_info *pipe_info =
1136 &hif_state->pipe_info[pipe_num];
1137 struct CE_state *ce_state =
1138 scn->ce_id_to_state[pipe_info->pipe_num];
1139
1140 if (ce_state->htt_rx_data)
1141 atomic_inc(&pipe_info->recv_bufs_needed);
1142 }
1143}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001144#else
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001145static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001146{
1147}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001148
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001149static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001150{
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001151 return false;
1152}
1153
1154static inline bool ce_is_fastpath_handler_registered(struct CE_state *ce_state)
1155{
1156 return false;
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001157}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001158#endif /* WLAN_FEATURE_FASTPATH */
1159
1160void ce_fini(struct CE_handle *copyeng)
1161{
1162 struct CE_state *CE_state = (struct CE_state *)copyeng;
1163 unsigned int CE_id = CE_state->id;
Komal Seelam644263d2016-02-22 20:45:49 +05301164 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001165
1166 CE_state->state = CE_UNUSED;
1167 scn->ce_id_to_state[CE_id] = NULL;
1168 if (CE_state->src_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001169 /* Cleanup the datapath Tx ring */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001170 ce_h2t_tx_ce_cleanup(copyeng);
1171
1172 if (CE_state->src_ring->shadow_base_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301173 qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001174 if (CE_state->src_ring->base_addr_owner_space_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301175 qdf_mem_free_consistent(scn->qdf_dev,
1176 scn->qdf_dev->dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001177 (CE_state->src_ring->nentries *
1178 sizeof(struct CE_src_desc) +
1179 CE_DESC_RING_ALIGN),
1180 CE_state->src_ring->
1181 base_addr_owner_space_unaligned,
1182 CE_state->src_ring->
1183 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301184 qdf_mem_free(CE_state->src_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001185 }
1186 if (CE_state->dest_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001187 /* Cleanup the datapath Rx ring */
1188 ce_t2h_msg_ce_cleanup(copyeng);
1189
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001190 if (CE_state->dest_ring->base_addr_owner_space_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301191 qdf_mem_free_consistent(scn->qdf_dev,
1192 scn->qdf_dev->dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001193 (CE_state->dest_ring->nentries *
1194 sizeof(struct CE_dest_desc) +
1195 CE_DESC_RING_ALIGN),
1196 CE_state->dest_ring->
1197 base_addr_owner_space_unaligned,
1198 CE_state->dest_ring->
1199 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301200 qdf_mem_free(CE_state->dest_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001201
1202 /* epping */
1203 if (CE_state->timer_inited) {
1204 CE_state->timer_inited = false;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301205 qdf_timer_free(&CE_state->poll_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001206 }
1207 }
Houston Hoffman31b25ec2016-09-19 13:12:30 -07001208 if ((ce_srng_based(CE_state->scn)) && (CE_state->status_ring)) {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301209 /* Cleanup the datapath Tx ring */
1210 ce_h2t_tx_ce_cleanup(copyeng);
1211
1212 if (CE_state->status_ring->shadow_base_unaligned)
1213 qdf_mem_free(
1214 CE_state->status_ring->shadow_base_unaligned);
1215
1216 if (CE_state->status_ring->base_addr_owner_space_unaligned)
1217 qdf_mem_free_consistent(scn->qdf_dev,
1218 scn->qdf_dev->dev,
1219 (CE_state->status_ring->nentries *
1220 sizeof(struct CE_src_desc) +
1221 CE_DESC_RING_ALIGN),
1222 CE_state->status_ring->
1223 base_addr_owner_space_unaligned,
1224 CE_state->status_ring->
1225 base_addr_CE_space, 0);
1226 qdf_mem_free(CE_state->status_ring);
1227 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301228 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001229}
1230
Komal Seelam5584a7c2016-02-24 19:22:48 +05301231void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001232{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301233 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001234
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301235 qdf_mem_zero(&hif_state->msg_callbacks_pending,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001236 sizeof(hif_state->msg_callbacks_pending));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301237 qdf_mem_zero(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001238 sizeof(hif_state->msg_callbacks_current));
1239}
1240
1241/* Send the first nbytes bytes of the buffer */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301242QDF_STATUS
Komal Seelam5584a7c2016-02-24 19:22:48 +05301243hif_send_head(struct hif_opaque_softc *hif_ctx,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001244 uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301245 qdf_nbuf_t nbuf, unsigned int data_attr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001246{
Komal Seelam644263d2016-02-22 20:45:49 +05301247 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301248 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001249 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1250 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
1251 int bytes = nbytes, nfrags = 0;
1252 struct ce_sendlist sendlist;
1253 int status, i = 0;
1254 unsigned int mux_id = 0;
1255
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301256 QDF_ASSERT(nbytes <= qdf_nbuf_len(nbuf));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001257
1258 transfer_id =
1259 (mux_id & MUX_ID_MASK) |
1260 (transfer_id & TRANSACTION_ID_MASK);
1261 data_attr &= DESC_DATA_FLAG_MASK;
1262 /*
1263 * The common case involves sending multiple fragments within a
1264 * single download (the tx descriptor and the tx frame header).
1265 * So, optimize for the case of multiple fragments by not even
1266 * checking whether it's necessary to use a sendlist.
1267 * The overhead of using a sendlist for a single buffer download
1268 * is not a big deal, since it happens rarely (for WMI messages).
1269 */
1270 ce_sendlist_init(&sendlist);
1271 do {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301272 qdf_dma_addr_t frag_paddr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001273 int frag_bytes;
1274
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301275 frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
1276 frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001277 /*
1278 * Clear the packet offset for all but the first CE desc.
1279 */
1280 if (i++ > 0)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301281 data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001282
1283 status = ce_sendlist_buf_add(&sendlist, frag_paddr,
1284 frag_bytes >
1285 bytes ? bytes : frag_bytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301286 qdf_nbuf_get_frag_is_wordstream
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001287 (nbuf,
1288 nfrags) ? 0 :
1289 CE_SEND_FLAG_SWAP_DISABLE,
1290 data_attr);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301291 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001292 HIF_ERROR("%s: error, frag_num %d larger than limit",
1293 __func__, nfrags);
1294 return status;
1295 }
1296 bytes -= frag_bytes;
1297 nfrags++;
1298 } while (bytes > 0);
1299
1300 /* Make sure we have resources to handle this request */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301301 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001302 if (pipe_info->num_sends_allowed < nfrags) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301303 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001304 ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301305 return QDF_STATUS_E_RESOURCES;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001306 }
1307 pipe_info->num_sends_allowed -= nfrags;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301308 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001309
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301310 if (qdf_unlikely(ce_hdl == NULL)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001311 HIF_ERROR("%s: error CE handle is null", __func__);
1312 return A_ERROR;
1313 }
1314
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301315 QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301316 DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
Nirav Shaheaa20d82016-04-25 18:01:05 +05301317 qdf_nbuf_data_addr(nbuf),
Nirav Shah29beae02016-04-26 22:58:54 +05301318 sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001319 status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301320 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001321
1322 return status;
1323}
1324
Komal Seelam5584a7c2016-02-24 19:22:48 +05301325void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
1326 int force)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001327{
Komal Seelam644263d2016-02-22 20:45:49 +05301328 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301329 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Komal Seelam644263d2016-02-22 20:45:49 +05301330
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001331 if (!force) {
1332 int resources;
1333 /*
1334 * Decide whether to actually poll for completions, or just
1335 * wait for a later chance. If there seem to be plenty of
1336 * resources left, then just wait, since checking involves
1337 * reading a CE register, which is a relatively expensive
1338 * operation.
1339 */
Komal Seelam644263d2016-02-22 20:45:49 +05301340 resources = hif_get_free_queue_number(hif_ctx, pipe);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001341 /*
1342 * If at least 50% of the total resources are still available,
1343 * don't bother checking again yet.
1344 */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301345 if (resources > (hif_state->host_ce_config[pipe].src_nentries >> 1)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001346 return;
1347 }
1348 }
Houston Hoffman56e0d702016-05-05 17:48:06 -07001349#if ATH_11AC_TXCOMPACT
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001350 ce_per_engine_servicereap(scn, pipe);
1351#else
1352 ce_per_engine_service(scn, pipe);
1353#endif
1354}
1355
Komal Seelam5584a7c2016-02-24 19:22:48 +05301356uint16_t
1357hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001358{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301359 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001360 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1361 uint16_t rv;
1362
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301363 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001364 rv = pipe_info->num_sends_allowed;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301365 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001366 return rv;
1367}
1368
1369/* Called by lower (CE) layer when a send to Target completes. */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001370static void
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001371hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301372 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001373 unsigned int nbytes, unsigned int transfer_id,
1374 unsigned int sw_index, unsigned int hw_index,
1375 unsigned int toeplitz_hash_result)
1376{
1377 struct HIF_CE_pipe_info *pipe_info =
1378 (struct HIF_CE_pipe_info *)ce_context;
1379 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Komal Seelam644263d2016-02-22 20:45:49 +05301380 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001381 unsigned int sw_idx = sw_index, hw_idx = hw_index;
Houston Hoffman85118512015-09-28 14:17:11 -07001382 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301383 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001384
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001385 do {
1386 /*
Houston Hoffman85118512015-09-28 14:17:11 -07001387 * The upper layer callback will be triggered
1388 * when last fragment is complteted.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001389 */
Houston Hoffman85118512015-09-28 14:17:11 -07001390 if (transfer_context != CE_SENDLIST_ITEM_CTXT) {
Komal Seelam6ee55902016-04-11 17:11:07 +05301391 if (scn->target_status == TARGET_STATUS_RESET)
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301392 qdf_nbuf_free(transfer_context);
Houston Hoffman49794a32015-12-21 12:14:56 -08001393 else
1394 msg_callbacks->txCompletionHandler(
Houston Hoffman85118512015-09-28 14:17:11 -07001395 msg_callbacks->Context,
1396 transfer_context, transfer_id,
1397 toeplitz_hash_result);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001398 }
1399
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301400 qdf_spin_lock(&pipe_info->completion_freeq_lock);
Houston Hoffman85118512015-09-28 14:17:11 -07001401 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301402 qdf_spin_unlock(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001403 } while (ce_completed_send_next(copyeng,
1404 &ce_context, &transfer_context,
1405 &CE_data, &nbytes, &transfer_id,
1406 &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301407 &toeplitz_hash_result) == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001408}
1409
Houston Hoffman910c6262015-09-28 12:56:25 -07001410/**
1411 * hif_ce_do_recv(): send message from copy engine to upper layers
1412 * @msg_callbacks: structure containing callback and callback context
1413 * @netbuff: skb containing message
1414 * @nbytes: number of bytes in the message
1415 * @pipe_info: used for the pipe_number info
1416 *
1417 * Checks the packet length, configures the lenght in the netbuff,
1418 * and calls the upper layer callback.
1419 *
1420 * return: None
1421 */
1422static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301423 qdf_nbuf_t netbuf, int nbytes,
Houston Hoffman910c6262015-09-28 12:56:25 -07001424 struct HIF_CE_pipe_info *pipe_info) {
1425 if (nbytes <= pipe_info->buf_sz) {
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301426 qdf_nbuf_set_pktlen(netbuf, nbytes);
Houston Hoffman910c6262015-09-28 12:56:25 -07001427 msg_callbacks->
1428 rxCompletionHandler(msg_callbacks->Context,
1429 netbuf, pipe_info->pipe_num);
1430 } else {
1431 HIF_ERROR("%s: Invalid Rx msg buf:%p nbytes:%d",
1432 __func__, netbuf, nbytes);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301433 qdf_nbuf_free(netbuf);
Houston Hoffman910c6262015-09-28 12:56:25 -07001434 }
1435}
1436
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001437/* Called by lower (CE) layer when data is received from the Target. */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001438static void
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001439hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301440 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001441 unsigned int nbytes, unsigned int transfer_id,
1442 unsigned int flags)
1443{
1444 struct HIF_CE_pipe_info *pipe_info =
1445 (struct HIF_CE_pipe_info *)ce_context;
1446 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001447 struct CE_state *ce_state = (struct CE_state *) copyeng;
Komal Seelam644263d2016-02-22 20:45:49 +05301448 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001449#ifdef HIF_PCI
1450 struct hif_pci_softc *hif_pci_sc = HIF_GET_PCI_SOFTC(hif_state);
1451#endif
Houston Hoffman910c6262015-09-28 12:56:25 -07001452 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301453 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001454
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001455 do {
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001456#ifdef HIF_PCI
1457 hif_pm_runtime_mark_last_busy(hif_pci_sc->dev);
1458#endif
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301459 qdf_nbuf_unmap_single(scn->qdf_dev,
1460 (qdf_nbuf_t) transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301461 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001462
Houston Hoffman910c6262015-09-28 12:56:25 -07001463 atomic_inc(&pipe_info->recv_bufs_needed);
1464 hif_post_recv_buffers_for_pipe(pipe_info);
Komal Seelam6ee55902016-04-11 17:11:07 +05301465 if (scn->target_status == TARGET_STATUS_RESET)
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301466 qdf_nbuf_free(transfer_context);
Houston Hoffman49794a32015-12-21 12:14:56 -08001467 else
1468 hif_ce_do_recv(msg_callbacks, transfer_context,
Houston Hoffman9c0f80a2015-09-28 18:36:36 -07001469 nbytes, pipe_info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001470
1471 /* Set up force_break flag if num of receices reaches
1472 * MAX_NUM_OF_RECEIVES */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001473 ce_state->receive_count++;
Houston Hoffman05652722016-04-29 16:58:59 -07001474 if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001475 ce_state->force_break = 1;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001476 break;
1477 }
1478 } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
1479 &CE_data, &nbytes, &transfer_id,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301480 &flags) == QDF_STATUS_SUCCESS);
Houston Hoffmanf4607852015-12-17 17:14:40 -08001481
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001482}
1483
1484/* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
1485
1486void
Komal Seelam5584a7c2016-02-24 19:22:48 +05301487hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001488 struct hif_msg_callbacks *callbacks)
1489{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301490 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001491
1492#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
1493 spin_lock_init(&pcie_access_log_lock);
1494#endif
1495 /* Save callbacks for later installation */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301496 qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001497 sizeof(hif_state->msg_callbacks_pending));
1498
1499}
1500
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001501static int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001502{
1503 struct CE_handle *ce_diag = hif_state->ce_diag;
1504 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05301505 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001506 struct hif_msg_callbacks *hif_msg_callbacks =
1507 &hif_state->msg_callbacks_current;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001508
1509 /* daemonize("hif_compl_thread"); */
1510
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001511 if (scn->ce_count == 0) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07001512 HIF_ERROR("%s: Invalid ce_count", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001513 return -EINVAL;
1514 }
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001515
1516 if (!hif_msg_callbacks ||
1517 !hif_msg_callbacks->rxCompletionHandler ||
1518 !hif_msg_callbacks->txCompletionHandler) {
1519 HIF_ERROR("%s: no completion handler registered", __func__);
1520 return -EFAULT;
1521 }
1522
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001523 A_TARGET_ACCESS_LIKELY(scn);
1524 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1525 struct CE_attr attr;
1526 struct HIF_CE_pipe_info *pipe_info;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001527
1528 pipe_info = &hif_state->pipe_info[pipe_num];
1529 if (pipe_info->ce_hdl == ce_diag) {
1530 continue; /* Handle Diagnostic CE specially */
1531 }
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301532 attr = hif_state->host_ce_config[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001533 if (attr.src_nentries) {
1534 /* pipe used to send to target */
1535 HIF_INFO_MED("%s: pipe_num:%d pipe_info:0x%p",
1536 __func__, pipe_num, pipe_info);
1537 ce_send_cb_register(pipe_info->ce_hdl,
1538 hif_pci_ce_send_done, pipe_info,
1539 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001540 pipe_info->num_sends_allowed = attr.src_nentries - 1;
1541 }
1542 if (attr.dest_nentries) {
1543 /* pipe used to receive from target */
1544 ce_recv_cb_register(pipe_info->ce_hdl,
1545 hif_pci_ce_recv_data, pipe_info,
1546 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001547 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001548
1549 if (attr.src_nentries)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301550 qdf_spinlock_create(&pipe_info->completion_freeq_lock);
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301551
1552 qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks,
1553 sizeof(pipe_info->pipe_callbacks));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001554 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001555
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001556 A_TARGET_ACCESS_UNLIKELY(scn);
1557 return 0;
1558}
1559
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001560/*
1561 * Install pending msg callbacks.
1562 *
1563 * TBDXXX: This hack is needed because upper layers install msg callbacks
1564 * for use with HTC before BMI is done; yet this HIF implementation
1565 * needs to continue to use BMI msg callbacks. Really, upper layers
1566 * should not register HTC callbacks until AFTER BMI phase.
1567 */
Komal Seelam644263d2016-02-22 20:45:49 +05301568static void hif_msg_callbacks_install(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001569{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301570 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001571
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301572 qdf_mem_copy(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001573 &hif_state->msg_callbacks_pending,
1574 sizeof(hif_state->msg_callbacks_pending));
1575}
1576
Komal Seelam5584a7c2016-02-24 19:22:48 +05301577void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
1578 uint8_t *DLPipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001579{
1580 int ul_is_polled, dl_is_polled;
1581
Komal Seelam644263d2016-02-22 20:45:49 +05301582 (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001583 ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
1584}
1585
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001586/**
1587 * hif_dump_pipe_debug_count() - Log error count
Komal Seelam644263d2016-02-22 20:45:49 +05301588 * @scn: hif_softc pointer.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001589 *
1590 * Output the pipe error counts of each pipe to log file
1591 *
1592 * Return: N/A
1593 */
Komal Seelam644263d2016-02-22 20:45:49 +05301594void hif_dump_pipe_debug_count(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001595{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301596 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001597 int pipe_num;
1598
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001599 if (hif_state == NULL) {
1600 HIF_ERROR("%s hif_state is NULL", __func__);
1601 return;
1602 }
1603 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1604 struct HIF_CE_pipe_info *pipe_info;
1605
1606 pipe_info = &hif_state->pipe_info[pipe_num];
1607
1608 if (pipe_info->nbuf_alloc_err_count > 0 ||
1609 pipe_info->nbuf_dma_err_count > 0 ||
1610 pipe_info->nbuf_ce_enqueue_err_count)
1611 HIF_ERROR(
1612 "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
1613 __func__, pipe_info->pipe_num,
1614 atomic_read(&pipe_info->recv_bufs_needed),
1615 pipe_info->nbuf_alloc_err_count,
1616 pipe_info->nbuf_dma_err_count,
1617 pipe_info->nbuf_ce_enqueue_err_count);
1618 }
1619}
1620
1621static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
1622{
1623 struct CE_handle *ce_hdl;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301624 qdf_size_t buf_sz;
Komal Seelam644263d2016-02-22 20:45:49 +05301625 struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301626 QDF_STATUS ret;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001627 uint32_t bufs_posted = 0;
1628
1629 buf_sz = pipe_info->buf_sz;
1630 if (buf_sz == 0) {
1631 /* Unused Copy Engine */
1632 return 0;
1633 }
1634
1635 ce_hdl = pipe_info->ce_hdl;
1636
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301637 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001638 while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301639 qdf_dma_addr_t CE_data; /* CE space buffer address */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301640 qdf_nbuf_t nbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001641 int status;
1642
1643 atomic_dec(&pipe_info->recv_bufs_needed);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301644 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001645
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301646 nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001647 if (!nbuf) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301648 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001649 pipe_info->nbuf_alloc_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301650 qdf_spin_unlock_bh(
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001651 &pipe_info->recv_bufs_needed_lock);
1652 HIF_ERROR(
1653 "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
1654 __func__, pipe_info->pipe_num,
1655 atomic_read(&pipe_info->recv_bufs_needed),
1656 pipe_info->nbuf_alloc_err_count);
1657 atomic_inc(&pipe_info->recv_bufs_needed);
1658 return 1;
1659 }
1660
1661 /*
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301662 * qdf_nbuf_peek_header(nbuf, &data, &unused);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001663 * CE_data = dma_map_single(dev, data, buf_sz, );
1664 * DMA_FROM_DEVICE);
1665 */
1666 ret =
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301667 qdf_nbuf_map_single(scn->qdf_dev, nbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301668 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001669
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301670 if (unlikely(ret != QDF_STATUS_SUCCESS)) {
1671 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001672 pipe_info->nbuf_dma_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301673 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001674 HIF_ERROR(
1675 "%s buf alloc error [%d] needed %d, nbuf_dma_err_count = %u",
1676 __func__, pipe_info->pipe_num,
1677 atomic_read(&pipe_info->recv_bufs_needed),
1678 pipe_info->nbuf_dma_err_count);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301679 qdf_nbuf_free(nbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001680 atomic_inc(&pipe_info->recv_bufs_needed);
1681 return 1;
1682 }
1683
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301684 CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001685
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301686 qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001687 buf_sz, DMA_FROM_DEVICE);
1688 status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301689 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001690 if (status != EOK) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301691 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001692 pipe_info->nbuf_ce_enqueue_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301693 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001694 HIF_ERROR(
1695 "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
1696 __func__, pipe_info->pipe_num,
1697 atomic_read(&pipe_info->recv_bufs_needed),
1698 pipe_info->nbuf_ce_enqueue_err_count);
Govind Singh4fcafd42016-08-08 12:37:31 +05301699 qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
1700 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001701 atomic_inc(&pipe_info->recv_bufs_needed);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301702 qdf_nbuf_free(nbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001703 return 1;
1704 }
1705
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301706 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001707 bufs_posted++;
1708 }
1709 pipe_info->nbuf_alloc_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001710 (pipe_info->nbuf_alloc_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001711 pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
1712 pipe_info->nbuf_dma_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001713 (pipe_info->nbuf_dma_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001714 pipe_info->nbuf_dma_err_count - bufs_posted : 0;
1715 pipe_info->nbuf_ce_enqueue_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001716 (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001717 pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
1718
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301719 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001720
1721 return 0;
1722}
1723
1724/*
1725 * Try to post all desired receive buffers for all pipes.
1726 * Returns 0 if all desired buffers are posted,
1727 * non-zero if were were unable to completely
1728 * replenish receive buffers.
1729 */
Komal Seelam644263d2016-02-22 20:45:49 +05301730static int hif_post_recv_buffers(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001731{
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 int pipe_num, rv = 0;
Houston Hoffman85925072016-05-06 17:02:18 -07001734 struct CE_state *ce_state;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001735
1736 A_TARGET_ACCESS_LIKELY(scn);
1737 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1738 struct HIF_CE_pipe_info *pipe_info;
Houston Hoffman85925072016-05-06 17:02:18 -07001739 ce_state = scn->ce_id_to_state[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001740 pipe_info = &hif_state->pipe_info[pipe_num];
Houston Hoffman85925072016-05-06 17:02:18 -07001741
1742 if (hif_is_nss_wifi_enabled(scn) &&
1743 ce_state && (ce_state->htt_rx_data)) {
1744 continue;
1745 }
1746
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001747 if (hif_post_recv_buffers_for_pipe(pipe_info)) {
1748 rv = 1;
1749 goto done;
1750 }
1751 }
1752
1753done:
1754 A_TARGET_ACCESS_UNLIKELY(scn);
1755
1756 return rv;
1757}
1758
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301759QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001760{
Komal Seelam644263d2016-02-22 20:45:49 +05301761 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301762 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001763
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001764 hif_update_fastpath_recv_bufs_cnt(scn);
1765
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001766 hif_msg_callbacks_install(scn);
1767
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001768 if (hif_completion_thread_startup(hif_state))
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301769 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001770
Houston Hoffman271951f2016-11-12 15:24:27 -08001771 /* enable buffer cleanup */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001772 hif_state->started = true;
1773
Houston Hoffman271951f2016-11-12 15:24:27 -08001774 /* Post buffers once to start things off. */
1775 if (hif_post_recv_buffers(scn)) {
1776 /* cleanup is done in hif_ce_disable */
1777 HIF_ERROR("%s:failed to post buffers", __func__);
1778 return QDF_STATUS_E_FAILURE;
1779 }
1780
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301781 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001782}
1783
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001784static void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001785{
Komal Seelam644263d2016-02-22 20:45:49 +05301786 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001787 struct CE_handle *ce_hdl;
1788 uint32_t buf_sz;
1789 struct HIF_CE_state *hif_state;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301790 qdf_nbuf_t netbuf;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301791 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001792 void *per_CE_context;
1793
1794 buf_sz = pipe_info->buf_sz;
1795 if (buf_sz == 0) {
1796 /* Unused Copy Engine */
1797 return;
1798 }
1799
1800 hif_state = pipe_info->HIF_CE_state;
1801 if (!hif_state->started) {
1802 return;
1803 }
1804
Komal Seelam02cf2f82016-02-22 20:44:25 +05301805 scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001806 ce_hdl = pipe_info->ce_hdl;
1807
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301808 if (scn->qdf_dev == NULL) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001809 return;
1810 }
1811 while (ce_revoke_recv_next
1812 (ce_hdl, &per_CE_context, (void **)&netbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301813 &CE_data) == QDF_STATUS_SUCCESS) {
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301814 qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301815 QDF_DMA_FROM_DEVICE);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301816 qdf_nbuf_free(netbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001817 }
1818}
1819
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001820static void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001821{
1822 struct CE_handle *ce_hdl;
1823 struct HIF_CE_state *hif_state;
Komal Seelam644263d2016-02-22 20:45:49 +05301824 struct hif_softc *scn;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301825 qdf_nbuf_t netbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001826 void *per_CE_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301827 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001828 unsigned int nbytes;
1829 unsigned int id;
1830 uint32_t buf_sz;
1831 uint32_t toeplitz_hash_result;
1832
1833 buf_sz = pipe_info->buf_sz;
1834 if (buf_sz == 0) {
1835 /* Unused Copy Engine */
1836 return;
1837 }
1838
1839 hif_state = pipe_info->HIF_CE_state;
1840 if (!hif_state->started) {
1841 return;
1842 }
1843
Komal Seelam02cf2f82016-02-22 20:44:25 +05301844 scn = HIF_GET_SOFTC(hif_state);
1845
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001846 ce_hdl = pipe_info->ce_hdl;
1847
1848 while (ce_cancel_send_next
1849 (ce_hdl, &per_CE_context,
1850 (void **)&netbuf, &CE_data, &nbytes,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301851 &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001852 if (netbuf != CE_SENDLIST_ITEM_CTXT) {
1853 /*
1854 * Packets enqueued by htt_h2t_ver_req_msg() and
1855 * htt_h2t_rx_ring_cfg_msg_ll() have already been
1856 * freed in htt_htc_misc_pkt_pool_free() in
1857 * wlantl_close(), so do not free them here again
Houston Hoffman29573d92015-10-20 17:49:44 -07001858 * by checking whether it's the endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001859 * which they are queued in.
1860 */
Nirav Shahd7f91592016-04-21 14:18:43 +05301861 if (id == scn->htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001862 return;
Nirav Shahd7f91592016-04-21 14:18:43 +05301863 /* Indicate the completion to higher
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001864 * layer to free the buffer */
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301865 if (pipe_info->pipe_callbacks.
Himanshu Agarwal8d0cdea2016-09-02 21:05:01 +05301866 txCompletionHandler)
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301867 pipe_info->pipe_callbacks.
1868 txCompletionHandler(pipe_info->
1869 pipe_callbacks.Context,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001870 netbuf, id, toeplitz_hash_result);
1871 }
1872 }
1873}
1874
1875/*
1876 * Cleanup residual buffers for device shutdown:
1877 * buffers that were enqueued for receive
1878 * buffers that were to be sent
1879 * Note: Buffers that had completed but which were
1880 * not yet processed are on a completion queue. They
1881 * are handled when the completion thread shuts down.
1882 */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001883static void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001884{
1885 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05301886 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman85925072016-05-06 17:02:18 -07001887 struct CE_state *ce_state;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001888
Komal Seelam02cf2f82016-02-22 20:44:25 +05301889 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001890 struct HIF_CE_pipe_info *pipe_info;
1891
Houston Hoffman85925072016-05-06 17:02:18 -07001892 ce_state = scn->ce_id_to_state[pipe_num];
1893 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
1894 ((ce_state->htt_tx_data) ||
1895 (ce_state->htt_rx_data))) {
1896 continue;
1897 }
1898
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001899 pipe_info = &hif_state->pipe_info[pipe_num];
1900 hif_recv_buffer_cleanup_on_pipe(pipe_info);
1901 hif_send_buffer_cleanup_on_pipe(pipe_info);
1902 }
1903}
1904
Komal Seelam5584a7c2016-02-24 19:22:48 +05301905void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001906{
Komal Seelam644263d2016-02-22 20:45:49 +05301907 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301908 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Komal Seelam644263d2016-02-22 20:45:49 +05301909
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001910 hif_buffer_cleanup(hif_state);
1911}
1912
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05301913void hif_ce_stop(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001914{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05301915 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001916 int pipe_num;
1917
Houston Hoffmana69581e2016-11-14 18:03:19 -08001918 /*
1919 * before cleaning up any memory, ensure irq &
1920 * bottom half contexts will not be re-entered
1921 */
1922 hif_nointrs(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001923 scn->hif_init_done = false;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001924
1925 /*
1926 * At this point, asynchronous threads are stopped,
1927 * The Target should not DMA nor interrupt, Host code may
1928 * not initiate anything more. So we just need to clean
1929 * up Host-side state.
1930 */
1931
1932 if (scn->athdiag_procfs_inited) {
1933 athdiag_procfs_remove();
1934 scn->athdiag_procfs_inited = false;
1935 }
1936
1937 hif_buffer_cleanup(hif_state);
1938
1939 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1940 struct HIF_CE_pipe_info *pipe_info;
1941
1942 pipe_info = &hif_state->pipe_info[pipe_num];
1943 if (pipe_info->ce_hdl) {
1944 ce_fini(pipe_info->ce_hdl);
1945 pipe_info->ce_hdl = NULL;
1946 pipe_info->buf_sz = 0;
1947 }
1948 }
1949
1950 if (hif_state->sleep_timer_init) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301951 qdf_timer_stop(&hif_state->sleep_timer);
1952 qdf_timer_free(&hif_state->sleep_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001953 hif_state->sleep_timer_init = false;
1954 }
1955
1956 hif_state->started = false;
1957}
1958
Houston Hoffman854e67f2016-03-14 21:11:39 -07001959/**
1960 * hif_get_target_ce_config() - get copy engine configuration
1961 * @target_ce_config_ret: basic copy engine configuration
1962 * @target_ce_config_sz_ret: size of the basic configuration in bytes
1963 * @target_service_to_ce_map_ret: service mapping for the copy engines
1964 * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
1965 * @target_shadow_reg_cfg_ret: shadow register configuration
1966 * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
1967 *
1968 * providing accessor to these values outside of this file.
1969 * currently these are stored in static pointers to const sections.
1970 * there are multiple configurations that are selected from at compile time.
1971 * Runtime selection would need to consider mode, target type and bus type.
1972 *
1973 * Return: return by parameter.
1974 */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301975void hif_get_target_ce_config(struct hif_softc *scn,
1976 struct CE_pipe_config **target_ce_config_ret,
Houston Hoffman854e67f2016-03-14 21:11:39 -07001977 int *target_ce_config_sz_ret,
1978 struct service_to_pipe **target_service_to_ce_map_ret,
1979 int *target_service_to_ce_map_sz_ret,
1980 struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
1981 int *shadow_cfg_sz_ret)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001982{
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301983 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1984
1985 *target_ce_config_ret = hif_state->target_ce_config;
1986 *target_ce_config_sz_ret = hif_state->target_ce_config_sz;
Houston Hoffman854e67f2016-03-14 21:11:39 -07001987 *target_service_to_ce_map_ret = target_service_to_ce_map;
1988 *target_service_to_ce_map_sz_ret = target_service_to_ce_map_sz;
1989
1990 if (target_shadow_reg_cfg_ret)
1991 *target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
1992
1993 if (shadow_cfg_sz_ret)
1994 *shadow_cfg_sz_ret = shadow_cfg_sz;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001995}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001996
1997/**
1998 * hif_wlan_enable(): call the platform driver to enable wlan
Komal Seelambd7c51d2016-02-24 10:27:30 +05301999 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002000 *
2001 * This function passes the con_mode and CE configuration to
2002 * platform driver to enable wlan.
2003 *
Houston Hoffman108da402016-03-14 21:11:24 -07002004 * Return: linux error code
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002005 */
Houston Hoffman108da402016-03-14 21:11:24 -07002006int hif_wlan_enable(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002007{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002008 struct pld_wlan_enable_cfg cfg;
2009 enum pld_driver_mode mode;
Komal Seelambd7c51d2016-02-24 10:27:30 +05302010 uint32_t con_mode = hif_get_conparam(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002011
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302012 hif_get_target_ce_config(scn,
2013 (struct CE_pipe_config **)&cfg.ce_tgt_cfg,
Houston Hoffman854e67f2016-03-14 21:11:39 -07002014 &cfg.num_ce_tgt_cfg,
2015 (struct service_to_pipe **)&cfg.ce_svc_cfg,
2016 &cfg.num_ce_svc_pipe_cfg,
2017 (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
2018 &cfg.num_shadow_reg_cfg);
2019
2020 /* translate from structure size to array size */
2021 cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
2022 cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
2023 cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002024
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302025 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002026 mode = PLD_FTM;
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002027 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002028 mode = PLD_EPPING;
Peng Xu7b962532015-10-02 17:17:03 -07002029 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002030 mode = PLD_MISSION;
Peng Xu7b962532015-10-02 17:17:03 -07002031
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002032 if (BYPASS_QMI)
2033 return 0;
2034 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002035 return pld_wlan_enable(scn->qdf_dev->dev, &cfg,
2036 mode, QWLAN_VERSIONSTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002037}
2038
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002039#define CE_EPPING_USES_IRQ true
2040
Houston Hoffman108da402016-03-14 21:11:24 -07002041/**
2042 * hif_ce_prepare_config() - load the correct static tables.
2043 * @scn: hif context
2044 *
2045 * Epping uses different static attribute tables than mission mode.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002046 */
Houston Hoffman108da402016-03-14 21:11:24 -07002047void hif_ce_prepare_config(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002048{
Komal Seelambd7c51d2016-02-24 10:27:30 +05302049 uint32_t mode = hif_get_conparam(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002050 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2051 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302052 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002053
Houston Hoffman710af5a2016-11-22 21:59:03 -08002054 scn->ce_count = HOST_CE_COUNT;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002055 /* if epping is enabled we need to use the epping configuration. */
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002056 if (QDF_IS_EPPING_ENABLED(mode)) {
2057 if (CE_EPPING_USES_IRQ)
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302058 hif_state->host_ce_config = host_ce_config_wlan_epping_irq;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002059 else
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302060 hif_state->host_ce_config = host_ce_config_wlan_epping_poll;
2061 hif_state->target_ce_config = target_ce_config_wlan_epping;
2062 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002063 target_service_to_ce_map =
2064 target_service_to_ce_map_wlan_epping;
2065 target_service_to_ce_map_sz =
2066 sizeof(target_service_to_ce_map_wlan_epping);
Vishwajith Upendra70efc752016-04-18 11:23:49 -07002067 target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
2068 shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002069 }
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002070
2071 switch (tgt_info->target_type) {
2072 default:
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302073 hif_state->host_ce_config = host_ce_config_wlan;
2074 hif_state->target_ce_config = target_ce_config_wlan;
2075 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002076 break;
2077 case TARGET_TYPE_AR900B:
2078 case TARGET_TYPE_QCA9984:
2079 case TARGET_TYPE_IPQ4019:
2080 case TARGET_TYPE_QCA9888:
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05302081 if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
2082 hif_state->host_ce_config =
2083 host_lowdesc_ce_cfg_wlan_ar900b_nopktlog;
2084 } else if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
2085 hif_state->host_ce_config =
2086 host_lowdesc_ce_cfg_wlan_ar900b;
2087 } else {
2088 hif_state->host_ce_config = host_ce_config_wlan_ar900b;
2089 }
2090
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302091 hif_state->target_ce_config = target_ce_config_wlan_ar900b;
2092 hif_state->target_ce_config_sz =
2093 sizeof(target_ce_config_wlan_ar900b);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002094
2095 target_service_to_ce_map = target_service_to_ce_map_ar900b;
2096 target_service_to_ce_map_sz =
2097 sizeof(target_service_to_ce_map_ar900b);
2098 break;
2099
2100 case TARGET_TYPE_AR9888:
2101 case TARGET_TYPE_AR9888V2:
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05302102 if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
2103 hif_state->host_ce_config = host_lowdesc_ce_cfg_wlan_ar9888;
2104 } else {
2105 hif_state->host_ce_config = host_ce_config_wlan_ar9888;
2106 }
2107
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302108 hif_state->target_ce_config = target_ce_config_wlan_ar9888;
2109 hif_state->target_ce_config_sz =
2110 sizeof(target_ce_config_wlan_ar9888);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002111
2112 target_service_to_ce_map = target_service_to_ce_map_ar900b;
2113 target_service_to_ce_map_sz =
2114 sizeof(target_service_to_ce_map_ar900b);
2115 break;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002116
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302117 case TARGET_TYPE_QCA8074:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -07002118 if (scn->bus_type == QDF_BUS_TYPE_PCI) {
2119 hif_state->host_ce_config =
2120 host_ce_config_wlan_qca8074_pci;
2121 hif_state->target_ce_config =
2122 target_ce_config_wlan_qca8074_pci;
2123 hif_state->target_ce_config_sz =
2124 sizeof(target_ce_config_wlan_qca8074_pci);
2125 } else {
2126 hif_state->host_ce_config = host_ce_config_wlan_qca8074;
2127 hif_state->target_ce_config =
2128 target_ce_config_wlan_qca8074;
2129 hif_state->target_ce_config_sz =
2130 sizeof(target_ce_config_wlan_qca8074);
2131 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302132 break;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002133 case TARGET_TYPE_QCA6290:
2134 hif_state->host_ce_config = host_ce_config_wlan_qca6290;
2135 hif_state->target_ce_config = target_ce_config_wlan_qca6290;
2136 hif_state->target_ce_config_sz =
2137 sizeof(target_ce_config_wlan_qca6290);
Houston Hoffman710af5a2016-11-22 21:59:03 -08002138 scn->ce_count = QCA_6290_CE_COUNT;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002139 break;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002140 }
Houston Hoffman108da402016-03-14 21:11:24 -07002141}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002142
Houston Hoffman108da402016-03-14 21:11:24 -07002143/**
2144 * hif_ce_open() - do ce specific allocations
2145 * @hif_sc: pointer to hif context
2146 *
2147 * return: 0 for success or QDF_STATUS_E_NOMEM
2148 */
2149QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
2150{
2151 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002152
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302153 qdf_spinlock_create(&hif_state->irq_reg_lock);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302154 qdf_spinlock_create(&hif_state->keep_awake_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002155 return QDF_STATUS_SUCCESS;
2156}
2157
2158/**
2159 * hif_ce_close() - do ce specific free
2160 * @hif_sc: pointer to hif context
2161 */
2162void hif_ce_close(struct hif_softc *hif_sc)
2163{
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302164 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2165
2166 qdf_spinlock_destroy(&hif_state->irq_reg_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002167}
2168
2169/**
2170 * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
2171 * @hif_sc: hif context
2172 *
2173 * uses state variables to support cleaning up when hif_config_ce fails.
2174 */
2175void hif_unconfig_ce(struct hif_softc *hif_sc)
2176{
2177 int pipe_num;
2178 struct HIF_CE_pipe_info *pipe_info;
2179 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2180
2181 for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
2182 pipe_info = &hif_state->pipe_info[pipe_num];
2183 if (pipe_info->ce_hdl) {
2184 ce_unregister_irq(hif_state, (1 << pipe_num));
Houston Hoffman108da402016-03-14 21:11:24 -07002185 ce_fini(pipe_info->ce_hdl);
2186 pipe_info->ce_hdl = NULL;
2187 pipe_info->buf_sz = 0;
2188 }
2189 }
Houston Hoffman108da402016-03-14 21:11:24 -07002190 if (hif_sc->athdiag_procfs_inited) {
2191 athdiag_procfs_remove();
2192 hif_sc->athdiag_procfs_inited = false;
2193 }
2194}
2195
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002196#ifdef CONFIG_BYPASS_QMI
2197#define FW_SHARED_MEM (2 * 1024 * 1024)
2198
2199/**
2200 * hif_post_static_buf_to_target() - post static buffer to WLAN FW
2201 * @scn: pointer to HIF structure
2202 *
2203 * WLAN FW needs 2MB memory from DDR when QMI is disabled.
2204 *
2205 * Return: void
2206 */
2207static void hif_post_static_buf_to_target(struct hif_softc *scn)
2208{
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002209 void *target_va;
2210 phys_addr_t target_pa;
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002211
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002212 target_va = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev,
2213 FW_SHARED_MEM, &target_pa);
2214 if (NULL == target_va) {
2215 HIF_TRACE("Memory allocation failed could not post target buf");
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002216 return;
2217 }
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002218 hif_write32_mb(scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
2219 HIF_TRACE("target va %pK target pa %pa", target_va, &target_pa);
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002220}
2221#else
2222static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
2223{
2224 return;
2225}
2226#endif
2227
Dustin Brown6bdbda52016-09-27 15:52:30 -07002228#ifdef WLAN_SUSPEND_RESUME_TEST
2229static void hif_fake_apps_init_ctx(struct hif_softc *scn)
2230{
2231 INIT_WORK(&scn->fake_apps_ctx.resume_work,
2232 hif_fake_apps_resume_work);
2233}
2234#else
2235static inline void hif_fake_apps_init_ctx(struct hif_softc *scn) {}
2236#endif
2237
Houston Hoffman108da402016-03-14 21:11:24 -07002238/**
2239 * hif_config_ce() - configure copy engines
2240 * @scn: hif context
2241 *
2242 * Prepares fw, copy engine hardware and host sw according
2243 * to the attributes selected by hif_ce_prepare_config.
2244 *
2245 * also calls athdiag_procfs_init
2246 *
2247 * return: 0 for success nonzero for failure.
2248 */
2249int hif_config_ce(struct hif_softc *scn)
2250{
2251 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2252 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2253 struct HIF_CE_pipe_info *pipe_info;
2254 int pipe_num;
Houston Hoffman85925072016-05-06 17:02:18 -07002255 struct CE_state *ce_state;
Houston Hoffman108da402016-03-14 21:11:24 -07002256#ifdef ADRASTEA_SHADOW_REGISTERS
2257 int i;
2258#endif
2259 QDF_STATUS rv = QDF_STATUS_SUCCESS;
2260
2261 scn->notice_send = true;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002262
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002263 hif_post_static_buf_to_target(scn);
2264
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002265 hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
Houston Hoffman108da402016-03-14 21:11:24 -07002266
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002267 hif_config_rri_on_ddr(scn);
2268
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302269 hif_state->ce_services = ce_services_attach(scn);
Houston Hoffman710af5a2016-11-22 21:59:03 -08002270
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002271 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
2272 struct CE_attr *attr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002273 pipe_info = &hif_state->pipe_info[pipe_num];
2274 pipe_info->pipe_num = pipe_num;
2275 pipe_info->HIF_CE_state = hif_state;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302276 attr = &hif_state->host_ce_config[pipe_num];
Karunakar Dasinenif61cb072016-09-29 11:50:45 -07002277
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002278 pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
Houston Hoffman85925072016-05-06 17:02:18 -07002279 ce_state = scn->ce_id_to_state[pipe_num];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302280 QDF_ASSERT(pipe_info->ce_hdl != NULL);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002281 if (pipe_info->ce_hdl == NULL) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302282 rv = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002283 A_TARGET_ACCESS_UNLIKELY(scn);
2284 goto err;
2285 }
2286
2287 if (pipe_num == DIAG_CE_ID) {
2288 /* Reserve the ultimate CE for
2289 * Diagnostic Window support */
Houston Hoffmanc1d9a412016-03-30 21:07:57 -07002290 hif_state->ce_diag = pipe_info->ce_hdl;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002291 continue;
2292 }
2293
Houston Hoffman85925072016-05-06 17:02:18 -07002294 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
2295 (ce_state->htt_rx_data))
2296 continue;
2297
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302298 pipe_info->buf_sz = (qdf_size_t) (attr->src_sz_max);
2299 qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002300 if (attr->dest_nentries > 0) {
2301 atomic_set(&pipe_info->recv_bufs_needed,
2302 init_buffer_count(attr->dest_nentries - 1));
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302303 /*SRNG based CE has one entry less */
2304 if (ce_srng_based(scn))
2305 atomic_dec(&pipe_info->recv_bufs_needed);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002306 } else {
2307 atomic_set(&pipe_info->recv_bufs_needed, 0);
2308 }
2309 ce_tasklet_init(hif_state, (1 << pipe_num));
2310 ce_register_irq(hif_state, (1 << pipe_num));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002311 }
2312
2313 if (athdiag_procfs_init(scn) != 0) {
2314 A_TARGET_ACCESS_UNLIKELY(scn);
2315 goto err;
2316 }
2317 scn->athdiag_procfs_inited = true;
2318
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002319 HIF_INFO_MED("%s: ce_init done", __func__);
2320
Houston Hoffman108da402016-03-14 21:11:24 -07002321 init_tasklet_workers(hif_hdl);
Dustin Brown6bdbda52016-09-27 15:52:30 -07002322 hif_fake_apps_init_ctx(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002323
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002324 HIF_TRACE("%s: X, ret = %d", __func__, rv);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002325
2326#ifdef ADRASTEA_SHADOW_REGISTERS
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002327 HIF_INFO("%s, Using Shadow Registers instead of CE Registers", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002328 for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002329 HIF_INFO("%s Shadow Register%d is mapped to address %x",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002330 __func__, i,
2331 (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
2332 }
2333#endif
2334
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302335 return rv != QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002336
2337err:
2338 /* Failure, so clean up */
Houston Hoffman108da402016-03-14 21:11:24 -07002339 hif_unconfig_ce(scn);
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002340 HIF_TRACE("%s: X, ret = %d", __func__, rv);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302341 return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002342}
2343
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002344#ifdef WLAN_FEATURE_FASTPATH
2345/**
2346 * hif_ce_fastpath_cb_register() - Register callback for fastpath msg handler
2347 * @handler: Callback funtcion
2348 * @context: handle for callback function
2349 *
2350 * Return: QDF_STATUS_SUCCESS on success or QDF_STATUS_E_FAILURE
2351 */
Houston Hoffman127467f2016-04-26 22:37:14 -07002352int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
2353 fastpath_msg_handler handler,
2354 void *context)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002355{
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002356 struct CE_state *ce_state;
Houston Hoffman127467f2016-04-26 22:37:14 -07002357 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002358 int i;
2359
Himanshu Agarwal2a924592016-06-30 18:04:14 +05302360 if (!scn) {
2361 HIF_ERROR("%s: scn is NULL", __func__);
2362 QDF_ASSERT(0);
2363 return QDF_STATUS_E_FAILURE;
2364 }
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002365
2366 if (!scn->fastpath_mode_on) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002367 HIF_WARN("%s: Fastpath mode disabled", __func__);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002368 return QDF_STATUS_E_FAILURE;
2369 }
2370
Houston Hoffmand6f946c2016-04-06 15:16:00 -07002371 for (i = 0; i < scn->ce_count; i++) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002372 ce_state = scn->ce_id_to_state[i];
2373 if (ce_state->htt_rx_data) {
2374 ce_state->fastpath_handler = handler;
2375 ce_state->context = context;
2376 }
2377 }
2378
2379 return QDF_STATUS_SUCCESS;
2380}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002381#endif
2382
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002383#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08002384/**
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302385 * hif_ce_ipa_get_ce_resource() - get uc resource on hif
Leo Changd85f78d2015-11-13 10:55:34 -08002386 * @scn: bus context
2387 * @ce_sr_base_paddr: copyengine source ring base physical address
2388 * @ce_sr_ring_size: copyengine source ring size
2389 * @ce_reg_paddr: copyengine register physical address
2390 *
2391 * IPA micro controller data path offload feature enabled,
2392 * HIF should release copy engine related resource information to IPA UC
2393 * IPA UC will access hardware resource with released information
2394 *
2395 * Return: None
2396 */
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302397void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302398 qdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002399 uint32_t *ce_sr_ring_size,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302400 qdf_dma_addr_t *ce_reg_paddr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002401{
Komal Seelam02cf2f82016-02-22 20:44:25 +05302402 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002403 struct HIF_CE_pipe_info *pipe_info =
2404 &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
2405 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
2406
2407 ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size,
2408 ce_reg_paddr);
2409 return;
2410}
2411#endif /* IPA_OFFLOAD */
2412
2413
2414#ifdef ADRASTEA_SHADOW_REGISTERS
2415
2416/*
2417 Current shadow register config
2418
2419 -----------------------------------------------------------
2420 Shadow Register | CE | src/dst write index
2421 -----------------------------------------------------------
2422 0 | 0 | src
2423 1 No Config - Doesn't point to anything
2424 2 No Config - Doesn't point to anything
2425 3 | 3 | src
2426 4 | 4 | src
2427 5 | 5 | src
2428 6 No Config - Doesn't point to anything
2429 7 | 7 | src
2430 8 No Config - Doesn't point to anything
2431 9 No Config - Doesn't point to anything
2432 10 No Config - Doesn't point to anything
2433 11 No Config - Doesn't point to anything
2434 -----------------------------------------------------------
2435 12 No Config - Doesn't point to anything
2436 13 | 1 | dst
2437 14 | 2 | dst
2438 15 No Config - Doesn't point to anything
2439 16 No Config - Doesn't point to anything
2440 17 No Config - Doesn't point to anything
2441 18 No Config - Doesn't point to anything
2442 19 | 7 | dst
2443 20 | 8 | dst
2444 21 No Config - Doesn't point to anything
2445 22 No Config - Doesn't point to anything
2446 23 No Config - Doesn't point to anything
2447 -----------------------------------------------------------
2448
2449
2450 ToDo - Move shadow register config to following in the future
2451 This helps free up a block of shadow registers towards the end.
2452 Can be used for other purposes
2453
2454 -----------------------------------------------------------
2455 Shadow Register | CE | src/dst write index
2456 -----------------------------------------------------------
2457 0 | 0 | src
2458 1 | 3 | src
2459 2 | 4 | src
2460 3 | 5 | src
2461 4 | 7 | src
2462 -----------------------------------------------------------
2463 5 | 1 | dst
2464 6 | 2 | dst
2465 7 | 7 | dst
2466 8 | 8 | dst
2467 -----------------------------------------------------------
2468 9 No Config - Doesn't point to anything
2469 12 No Config - Doesn't point to anything
2470 13 No Config - Doesn't point to anything
2471 14 No Config - Doesn't point to anything
2472 15 No Config - Doesn't point to anything
2473 16 No Config - Doesn't point to anything
2474 17 No Config - Doesn't point to anything
2475 18 No Config - Doesn't point to anything
2476 19 No Config - Doesn't point to anything
2477 20 No Config - Doesn't point to anything
2478 21 No Config - Doesn't point to anything
2479 22 No Config - Doesn't point to anything
2480 23 No Config - Doesn't point to anything
2481 -----------------------------------------------------------
2482*/
2483
Komal Seelam644263d2016-02-22 20:45:49 +05302484u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002485{
2486 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002487 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002488
Houston Hoffmane6330442016-02-26 12:19:11 -08002489 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002490 case 0:
2491 addr = SHADOW_VALUE0;
2492 break;
2493 case 3:
2494 addr = SHADOW_VALUE3;
2495 break;
2496 case 4:
2497 addr = SHADOW_VALUE4;
2498 break;
2499 case 5:
2500 addr = SHADOW_VALUE5;
2501 break;
2502 case 7:
2503 addr = SHADOW_VALUE7;
2504 break;
2505 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002506 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302507 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002508 }
2509 return addr;
2510
2511}
2512
Komal Seelam644263d2016-02-22 20:45:49 +05302513u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002514{
2515 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002516 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002517
Houston Hoffmane6330442016-02-26 12:19:11 -08002518 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002519 case 1:
2520 addr = SHADOW_VALUE13;
2521 break;
2522 case 2:
2523 addr = SHADOW_VALUE14;
2524 break;
Vishwajith Upendra70efc752016-04-18 11:23:49 -07002525 case 5:
2526 addr = SHADOW_VALUE17;
2527 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002528 case 7:
2529 addr = SHADOW_VALUE19;
2530 break;
2531 case 8:
2532 addr = SHADOW_VALUE20;
2533 break;
Houston Hoffmane6330442016-02-26 12:19:11 -08002534 case 9:
2535 addr = SHADOW_VALUE21;
2536 break;
2537 case 10:
2538 addr = SHADOW_VALUE22;
2539 break;
Nirav Shah75cc5c82016-05-25 10:52:38 +05302540 case 11:
2541 addr = SHADOW_VALUE23;
2542 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002543 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002544 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302545 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002546 }
2547
2548 return addr;
2549
2550}
2551#endif
2552
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002553#if defined(FEATURE_LRO)
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002554void *hif_ce_get_lro_ctx(struct hif_opaque_softc *hif_hdl, int ctx_id)
2555{
2556 struct CE_state *ce_state;
2557 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
2558
2559 QDF_ASSERT(scn != NULL);
2560
2561 ce_state = scn->ce_id_to_state[ctx_id];
2562
2563 return ce_state->lro_data;
2564}
2565
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002566/**
2567 * ce_lro_flush_cb_register() - register the LRO flush
2568 * callback
2569 * @scn: HIF context
2570 * @handler: callback function
2571 * @data: opaque data pointer to be passed back
2572 *
2573 * Store the LRO flush callback provided
2574 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002575 * Return: Number of instances the callback is registered for
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002576 */
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002577int ce_lro_flush_cb_register(struct hif_opaque_softc *hif_hdl,
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002578 void (handler)(void *),
2579 void *(lro_init_handler)(void))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002580{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002581 int rc = 0;
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002582 int i;
2583 struct CE_state *ce_state;
Komal Seelam5584a7c2016-02-24 19:22:48 +05302584 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002585 void *data = NULL;
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002586
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302587 QDF_ASSERT(scn != NULL);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002588
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002589 if (scn != NULL) {
2590 for (i = 0; i < scn->ce_count; i++) {
2591 ce_state = scn->ce_id_to_state[i];
2592 if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002593 data = lro_init_handler();
2594 if (data == NULL) {
2595 HIF_ERROR("%s: Failed to init LRO for CE %d",
2596 __func__, i);
2597 continue;
2598 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002599 ce_state->lro_flush_cb = handler;
2600 ce_state->lro_data = data;
2601 rc++;
2602 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002603 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002604 } else {
2605 HIF_ERROR("%s: hif_state NULL!", __func__);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002606 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002607 return rc;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002608}
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002609
2610/**
2611 * ce_lro_flush_cb_deregister() - deregister the LRO flush
2612 * callback
2613 * @scn: HIF context
2614 *
2615 * Remove the LRO flush callback
2616 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002617 * Return: Number of instances the callback is de-registered
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002618 */
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002619int ce_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl,
2620 void (lro_deinit_cb)(void *))
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002621{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002622 int rc = 0;
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002623 int i;
2624 struct CE_state *ce_state;
Komal Seelam5584a7c2016-02-24 19:22:48 +05302625 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002626
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302627 QDF_ASSERT(scn != NULL);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002628 if (scn != NULL) {
2629 for (i = 0; i < scn->ce_count; i++) {
2630 ce_state = scn->ce_id_to_state[i];
2631 if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002632 qdf_spin_lock_bh(
2633 &ce_state->lro_unloading_lock);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002634 ce_state->lro_flush_cb = NULL;
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002635 lro_deinit_cb(ce_state->lro_data);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002636 ce_state->lro_data = NULL;
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002637 qdf_spin_unlock_bh(
2638 &ce_state->lro_unloading_lock);
2639 qdf_spinlock_destroy(
2640 &ce_state->lro_unloading_lock);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002641 rc++;
2642 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002643 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002644 } else {
2645 HIF_ERROR("%s: hif_state NULL!", __func__);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002646 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002647 return rc;
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002648}
2649#endif
Sanjay Devnanic319c822015-11-06 16:44:28 -08002650
2651/**
2652 * hif_map_service_to_pipe() - returns the ce ids pertaining to
2653 * this service
Komal Seelam644263d2016-02-22 20:45:49 +05302654 * @scn: hif_softc pointer.
Sanjay Devnanic319c822015-11-06 16:44:28 -08002655 * @svc_id: Service ID for which the mapping is needed.
2656 * @ul_pipe: address of the container in which ul pipe is returned.
2657 * @dl_pipe: address of the container in which dl pipe is returned.
2658 * @ul_is_polled: address of the container in which a bool
2659 * indicating if the UL CE for this service
2660 * is polled is returned.
2661 * @dl_is_polled: address of the container in which a bool
2662 * indicating if the DL CE for this service
2663 * is polled is returned.
2664 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002665 * Return: Indicates whether the service has been found in the table.
2666 * Upon return, ul_is_polled is updated only if ul_pipe is updated.
2667 * There will be warning logs if either leg has not been updated
2668 * because it missed the entry in the table (but this is not an err).
Sanjay Devnanic319c822015-11-06 16:44:28 -08002669 */
Komal Seelam5584a7c2016-02-24 19:22:48 +05302670int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
Sanjay Devnanic319c822015-11-06 16:44:28 -08002671 uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
2672 int *dl_is_polled)
2673{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002674 int status = QDF_STATUS_E_INVAL;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002675 unsigned int i;
2676 struct service_to_pipe element;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002677 struct service_to_pipe *tgt_svc_map_to_use;
2678 size_t sz_tgt_svc_map_to_use;
Komal Seelambd7c51d2016-02-24 10:27:30 +05302679 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
2680 uint32_t mode = hif_get_conparam(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002681 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002682 bool dl_updated = false;
2683 bool ul_updated = false;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302684 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanic319c822015-11-06 16:44:28 -08002685
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002686 if (QDF_IS_EPPING_ENABLED(mode)) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002687 tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
2688 sz_tgt_svc_map_to_use =
2689 sizeof(target_service_to_ce_map_wlan_epping);
2690 } else {
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002691 switch (tgt_info->target_type) {
2692 default:
2693 tgt_svc_map_to_use = target_service_to_ce_map_wlan;
2694 sz_tgt_svc_map_to_use =
2695 sizeof(target_service_to_ce_map_wlan);
2696 break;
2697 case TARGET_TYPE_AR900B:
2698 case TARGET_TYPE_QCA9984:
2699 case TARGET_TYPE_IPQ4019:
2700 case TARGET_TYPE_QCA9888:
2701 case TARGET_TYPE_AR9888:
2702 case TARGET_TYPE_AR9888V2:
2703 tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
2704 sz_tgt_svc_map_to_use =
2705 sizeof(target_service_to_ce_map_ar900b);
2706 break;
Houston Hoffman88c896f2016-12-14 09:56:35 -08002707 case TARGET_TYPE_QCA6290:
2708 tgt_svc_map_to_use = target_service_to_ce_map_qca6290;
2709 sz_tgt_svc_map_to_use =
2710 sizeof(target_service_to_ce_map_qca6290);
2711 break;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002712 }
Sanjay Devnanic319c822015-11-06 16:44:28 -08002713 }
2714
2715 *dl_is_polled = 0; /* polling for received messages not supported */
2716
2717 for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
2718
2719 memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
2720 if (element.service_id == svc_id) {
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002721 if (element.pipedir == PIPEDIR_OUT) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002722 *ul_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002723 *ul_is_polled =
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302724 (hif_state->host_ce_config[*ul_pipe].flags &
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002725 CE_ATTR_DISABLE_INTR) != 0;
2726 ul_updated = true;
2727 } else if (element.pipedir == PIPEDIR_IN) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002728 *dl_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002729 dl_updated = true;
2730 }
2731 status = QDF_STATUS_SUCCESS;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002732 }
2733 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002734 if (ul_updated == false)
2735 HIF_WARN("%s: ul pipe is NOT updated for service %d",
2736 __func__, svc_id);
2737 if (dl_updated == false)
2738 HIF_WARN("%s: dl pipe is NOT updated for service %d",
2739 __func__, svc_id);
Sanjay Devnanic319c822015-11-06 16:44:28 -08002740
2741 return status;
2742}
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002743
2744#ifdef SHADOW_REG_DEBUG
Komal Seelam644263d2016-02-22 20:45:49 +05302745inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002746 uint32_t CE_ctrl_addr)
2747{
2748 uint32_t read_from_hw, srri_from_ddr = 0;
2749
2750 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
2751
2752 srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
2753
2754 if (read_from_hw != srri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002755 HIF_ERROR("%s: error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
2756 __func__, srri_from_ddr, read_from_hw,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002757 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302758 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002759 }
2760 return srri_from_ddr;
2761}
2762
2763
Komal Seelam644263d2016-02-22 20:45:49 +05302764inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002765 uint32_t CE_ctrl_addr)
2766{
2767 uint32_t read_from_hw, drri_from_ddr = 0;
2768
2769 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
2770
2771 drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
2772
2773 if (read_from_hw != drri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002774 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 -08002775 drri_from_ddr, read_from_hw,
2776 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302777 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002778 }
2779 return drri_from_ddr;
2780}
2781
2782#endif
2783
Houston Hoffman3d0cda82015-12-03 13:25:05 -08002784#ifdef ADRASTEA_RRI_ON_DDR
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002785/**
2786 * hif_get_src_ring_read_index(): Called to get the SRRI
2787 *
Komal Seelam644263d2016-02-22 20:45:49 +05302788 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002789 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
2790 *
2791 * This function returns the SRRI to the caller. For CEs that
2792 * dont have interrupts enabled, we look at the DDR based SRRI
2793 *
2794 * Return: SRRI
2795 */
Komal Seelam644263d2016-02-22 20:45:49 +05302796inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002797 uint32_t CE_ctrl_addr)
2798{
2799 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302800 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002801
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302802 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002803 if (attr.flags & CE_ATTR_DISABLE_INTR)
2804 return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
2805 else
2806 return A_TARGET_READ(scn,
2807 (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
2808}
2809
2810/**
2811 * hif_get_dst_ring_read_index(): Called to get the DRRI
2812 *
Komal Seelam644263d2016-02-22 20:45:49 +05302813 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002814 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
2815 *
2816 * This function returns the DRRI to the caller. For CEs that
2817 * dont have interrupts enabled, we look at the DDR based DRRI
2818 *
2819 * Return: DRRI
2820 */
Komal Seelam644263d2016-02-22 20:45:49 +05302821inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002822 uint32_t CE_ctrl_addr)
2823{
2824 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302825 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002826
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302827 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002828
2829 if (attr.flags & CE_ATTR_DISABLE_INTR)
2830 return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
2831 else
2832 return A_TARGET_READ(scn,
2833 (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
2834}
2835
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002836/**
2837 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
2838 *
Komal Seelam644263d2016-02-22 20:45:49 +05302839 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002840 *
2841 * This function allocates non cached memory on ddr and sends
2842 * the physical address of this memory to the CE hardware. The
2843 * hardware updates the RRI on this particular location.
2844 *
2845 * Return: None
2846 */
Komal Seelam644263d2016-02-22 20:45:49 +05302847static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002848{
2849 unsigned int i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302850 qdf_dma_addr_t paddr_rri_on_ddr;
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002851 uint32_t high_paddr, low_paddr;
2852 scn->vaddr_rri_on_ddr =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302853 (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
2854 scn->qdf_dev->dev, (CE_COUNT*sizeof(uint32_t)),
2855 &paddr_rri_on_ddr);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002856
2857 low_paddr = BITS0_TO_31(paddr_rri_on_ddr);
2858 high_paddr = BITS32_TO_35(paddr_rri_on_ddr);
2859
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002860 HIF_INFO("%s using srri and drri from DDR", __func__);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002861
2862 WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
2863 WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
2864
2865 for (i = 0; i < CE_COUNT; i++)
2866 CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
2867
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302868 qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t));
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002869
2870 return;
2871}
2872#else
2873
2874/**
2875 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
2876 *
Komal Seelam644263d2016-02-22 20:45:49 +05302877 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002878 *
2879 * This is a dummy implementation for platforms that don't
2880 * support this functionality.
2881 *
2882 * Return: None
2883 */
Komal Seelam644263d2016-02-22 20:45:49 +05302884static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002885{
2886 return;
2887}
2888#endif
Govind Singh2443fb32016-01-13 17:44:48 +05302889
2890/**
2891 * hif_dump_ce_registers() - dump ce registers
Komal Seelam5584a7c2016-02-24 19:22:48 +05302892 * @scn: hif_opaque_softc pointer.
Govind Singh2443fb32016-01-13 17:44:48 +05302893 *
2894 * Output the copy engine registers
2895 *
2896 * Return: 0 for success or error code
2897 */
Komal Seelam644263d2016-02-22 20:45:49 +05302898int hif_dump_ce_registers(struct hif_softc *scn)
Govind Singh2443fb32016-01-13 17:44:48 +05302899{
Komal Seelam5584a7c2016-02-24 19:22:48 +05302900 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Govind Singh2443fb32016-01-13 17:44:48 +05302901 uint32_t ce_reg_address = CE0_BASE_ADDRESS;
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002902 uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
Govind Singh2443fb32016-01-13 17:44:48 +05302903 uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
2904 uint16_t i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302905 QDF_STATUS status;
Govind Singh2443fb32016-01-13 17:44:48 +05302906
Houston Hoffmand6f946c2016-04-06 15:16:00 -07002907 for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
2908 if (scn->ce_id_to_state[i] == NULL) {
2909 HIF_DBG("CE%d not used.", i);
2910 continue;
2911 }
2912
Komal Seelam644263d2016-02-22 20:45:49 +05302913 status = hif_diag_read_mem(hif_hdl, ce_reg_address,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002914 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05302915 ce_reg_word_size * sizeof(uint32_t));
2916
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302917 if (status != QDF_STATUS_SUCCESS) {
Govind Singh2443fb32016-01-13 17:44:48 +05302918 HIF_ERROR("Dumping CE register failed!");
2919 return -EACCES;
2920 }
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05302921 HIF_ERROR("CE%d=>\n", i);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302922 qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002923 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05302924 ce_reg_word_size * sizeof(uint32_t));
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05302925 qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d\n", (ce_reg_address
2926 + SR_WR_INDEX_ADDRESS),
2927 ce_reg_values[SR_WR_INDEX_ADDRESS/4]);
2928 qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d\n", (ce_reg_address
2929 + CURRENT_SRRI_ADDRESS),
2930 ce_reg_values[CURRENT_SRRI_ADDRESS/4]);
2931 qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d\n", (ce_reg_address
2932 + DST_WR_INDEX_ADDRESS),
2933 ce_reg_values[DST_WR_INDEX_ADDRESS/4]);
2934 qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d\n", (ce_reg_address
2935 + CURRENT_DRRI_ADDRESS),
2936 ce_reg_values[CURRENT_DRRI_ADDRESS/4]);
2937 qdf_print("---\n");
Govind Singh2443fb32016-01-13 17:44:48 +05302938 }
Govind Singh2443fb32016-01-13 17:44:48 +05302939 return 0;
2940}
Houston Hoffman85925072016-05-06 17:02:18 -07002941#ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
2942struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
2943 struct hif_pipe_addl_info *hif_info, uint32_t pipe)
2944{
2945 struct hif_softc *scn = HIF_GET_SOFTC(osc);
2946 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
2947 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
2948 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
2949 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
2950 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
2951 struct CE_ring_state *src_ring = ce_state->src_ring;
2952 struct CE_ring_state *dest_ring = ce_state->dest_ring;
2953
2954 if (src_ring) {
2955 hif_info->ul_pipe.nentries = src_ring->nentries;
2956 hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
2957 hif_info->ul_pipe.sw_index = src_ring->sw_index;
2958 hif_info->ul_pipe.write_index = src_ring->write_index;
2959 hif_info->ul_pipe.hw_index = src_ring->hw_index;
2960 hif_info->ul_pipe.base_addr_CE_space =
2961 src_ring->base_addr_CE_space;
2962 hif_info->ul_pipe.base_addr_owner_space =
2963 src_ring->base_addr_owner_space;
2964 }
2965
2966
2967 if (dest_ring) {
2968 hif_info->dl_pipe.nentries = dest_ring->nentries;
2969 hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
2970 hif_info->dl_pipe.sw_index = dest_ring->sw_index;
2971 hif_info->dl_pipe.write_index = dest_ring->write_index;
2972 hif_info->dl_pipe.hw_index = dest_ring->hw_index;
2973 hif_info->dl_pipe.base_addr_CE_space =
2974 dest_ring->base_addr_CE_space;
2975 hif_info->dl_pipe.base_addr_owner_space =
2976 dest_ring->base_addr_owner_space;
2977 }
2978
2979 hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
2980 hif_info->ctrl_addr = ce_state->ctrl_addr;
2981
2982 return hif_info;
2983}
2984
2985uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
2986{
2987 struct hif_softc *scn = HIF_GET_SOFTC(osc);
2988
2989 scn->nss_wifi_ol_mode = mode;
2990 return 0;
2991}
2992
2993#endif
2994
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05302995void hif_set_attribute(struct hif_opaque_softc *osc, uint8_t hif_attrib)
2996{
2997 struct hif_softc *scn = HIF_GET_SOFTC(osc);
2998 scn->hif_attribute = hif_attrib;
2999}
3000
Houston Hoffman85925072016-05-06 17:02:18 -07003001void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
3002{
3003 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3004 struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
3005 uint32_t ctrl_addr = CE_state->ctrl_addr;
3006
3007 Q_TARGET_ACCESS_BEGIN(scn);
3008 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
3009 Q_TARGET_ACCESS_END(scn);
3010}
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303011
3012/**
3013 * hif_fw_event_handler() - hif fw event handler
3014 * @hif_state: pointer to hif ce state structure
3015 *
3016 * Process fw events and raise HTC callback to process fw events.
3017 *
3018 * Return: none
3019 */
3020static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
3021{
3022 struct hif_msg_callbacks *msg_callbacks =
3023 &hif_state->msg_callbacks_current;
3024
3025 if (!msg_callbacks->fwEventHandler)
3026 return;
3027
3028 msg_callbacks->fwEventHandler(msg_callbacks->Context,
3029 QDF_STATUS_E_FAILURE);
3030}
3031
3032#ifndef QCA_WIFI_3_0
3033/**
3034 * hif_fw_interrupt_handler() - FW interrupt handler
3035 * @irq: irq number
3036 * @arg: the user pointer
3037 *
3038 * Called from the PCI interrupt handler when a
3039 * firmware-generated interrupt to the Host.
3040 *
3041 * Return: status of handled irq
3042 */
3043irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
3044{
3045 struct hif_softc *scn = arg;
3046 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3047 uint32_t fw_indicator_address, fw_indicator;
3048
3049 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
3050 return ATH_ISR_NOSCHED;
3051
3052 fw_indicator_address = hif_state->fw_indicator_address;
3053 /* For sudden unplug this will return ~0 */
3054 fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
3055
3056 if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
3057 /* ACK: clear Target-side pending event */
3058 A_TARGET_WRITE(scn, fw_indicator_address,
3059 fw_indicator & ~FW_IND_EVENT_PENDING);
3060 if (Q_TARGET_ACCESS_END(scn) < 0)
3061 return ATH_ISR_SCHED;
3062
3063 if (hif_state->started) {
3064 hif_fw_event_handler(hif_state);
3065 } else {
3066 /*
3067 * Probable Target failure before we're prepared
3068 * to handle it. Generally unexpected.
3069 */
3070 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
3071 ("%s: Early firmware event indicated\n",
3072 __func__));
3073 }
3074 } else {
3075 if (Q_TARGET_ACCESS_END(scn) < 0)
3076 return ATH_ISR_SCHED;
3077 }
3078
3079 return ATH_ISR_SCHED;
3080}
3081#else
3082irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
3083{
3084 return ATH_ISR_SCHED;
3085}
3086#endif /* #ifdef QCA_WIFI_3_0 */
3087
3088
3089/**
3090 * hif_wlan_disable(): call the platform driver to disable wlan
3091 * @scn: HIF Context
3092 *
3093 * This function passes the con_mode to platform driver to disable
3094 * wlan.
3095 *
3096 * Return: void
3097 */
3098void hif_wlan_disable(struct hif_softc *scn)
3099{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003100 enum pld_driver_mode mode;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303101 uint32_t con_mode = hif_get_conparam(scn);
3102
3103 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003104 mode = PLD_FTM;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303105 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003106 mode = PLD_EPPING;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303107 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003108 mode = PLD_MISSION;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303109
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003110 pld_wlan_disable(scn->qdf_dev->dev, mode);
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303111}
Dustin Brown6bdbda52016-09-27 15:52:30 -07003112