blob: a396d54fa26911dda8a8078087ee6cf1b6988eb4 [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
Houston Hoffman5141f9d2017-01-05 10:49:17 -080061#if (defined(QCA_WIFI_QCA8074) || defined(QCA_WIFI_QCA6290)) && \
62 !defined(QCA_WIFI_SUPPORT_SRNG)
63#define QCA_WIFI_SUPPORT_SRNG
64#endif
65
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080066/* Forward references */
67static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info);
68
69/*
70 * Fix EV118783, poll to check whether a BMI response comes
71 * other than waiting for the interruption which may be lost.
72 */
73/* #define BMI_RSP_POLLING */
74#define BMI_RSP_TO_MILLISEC 1000
75
Yuanyuan Liua7a282f2016-04-15 12:55:04 -070076#ifdef CONFIG_BYPASS_QMI
77#define BYPASS_QMI 1
78#else
79#define BYPASS_QMI 0
80#endif
81
Houston Hoffmanabd00772016-05-06 17:02:48 -070082#ifdef CONFIG_WIN
Pratik Gandhi424c62e2016-08-23 19:47:09 +053083#if ENABLE_10_4_FW_HDR
Houston Hoffmanabd00772016-05-06 17:02:48 -070084#define WDI_IPA_SERVICE_GROUP 5
85#define WDI_IPA_TX_SVC MAKE_SERVICE_ID(WDI_IPA_SERVICE_GROUP, 0)
86#define HTT_DATA2_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 1)
87#define HTT_DATA3_MSG_SVC MAKE_SERVICE_ID(HTT_SERVICE_GROUP, 2)
Pratik Gandhi424c62e2016-08-23 19:47:09 +053088#endif /* ENABLE_10_4_FW_HDR */
Houston Hoffmanabd00772016-05-06 17:02:48 -070089#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080090
Komal Seelam644263d2016-02-22 20:45:49 +053091static int hif_post_recv_buffers(struct hif_softc *scn);
92static void hif_config_rri_on_ddr(struct hif_softc *scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080093
Poddar, Siddarthe41943f2016-04-27 15:33:48 +053094/**
95 * hif_target_access_log_dump() - dump access log
96 *
97 * dump access log
98 *
99 * Return: n/a
100 */
101#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
102static void hif_target_access_log_dump(void)
103{
104 hif_target_dump_access_log();
105}
106#endif
107
108
109void hif_trigger_dump(struct hif_opaque_softc *hif_ctx,
110 uint8_t cmd_id, bool start)
111{
112 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
113
114 switch (cmd_id) {
115 case AGC_DUMP:
116 if (start)
117 priv_start_agc(scn);
118 else
119 priv_dump_agc(scn);
120 break;
121 case CHANINFO_DUMP:
122 if (start)
123 priv_start_cap_chaninfo(scn);
124 else
125 priv_dump_chaninfo(scn);
126 break;
127 case BB_WATCHDOG_DUMP:
128 priv_dump_bbwatchdog(scn);
129 break;
130#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
131 case PCIE_ACCESS_DUMP:
132 hif_target_access_log_dump();
133 break;
134#endif
135 default:
136 HIF_ERROR("%s: Invalid htc dump command", __func__);
137 break;
138 }
139}
140
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800141static void ce_poll_timeout(void *arg)
142{
143 struct CE_state *CE_state = (struct CE_state *)arg;
144 if (CE_state->timer_inited) {
145 ce_per_engine_service(CE_state->scn, CE_state->id);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530146 qdf_timer_mod(&CE_state->poll_timer, CE_POLL_TIMEOUT);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800147 }
148}
149
150static unsigned int roundup_pwr2(unsigned int n)
151{
152 int i;
153 unsigned int test_pwr2;
154
155 if (!(n & (n - 1)))
156 return n; /* already a power of 2 */
157
158 test_pwr2 = 4;
159 for (i = 0; i < 29; i++) {
160 if (test_pwr2 > n)
161 return test_pwr2;
162 test_pwr2 = test_pwr2 << 1;
163 }
164
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530165 QDF_ASSERT(0); /* n too large */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800166 return 0;
167}
168
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700169#define ADRASTEA_SRC_WR_INDEX_OFFSET 0x3C
170#define ADRASTEA_DST_WR_INDEX_OFFSET 0x40
171
172static struct shadow_reg_cfg target_shadow_reg_cfg_map[] = {
173 { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
174 { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
175 { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
176 { 5, ADRASTEA_SRC_WR_INDEX_OFFSET},
177 { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
178 { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
179 { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
180 { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
181 { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
Houston Hoffmane6330442016-02-26 12:19:11 -0800182#ifdef QCA_WIFI_3_0_ADRASTEA
183 { 9, ADRASTEA_DST_WR_INDEX_OFFSET},
184 { 10, ADRASTEA_DST_WR_INDEX_OFFSET},
Nirav Shah75cc5c82016-05-25 10:52:38 +0530185 { 11, ADRASTEA_DST_WR_INDEX_OFFSET},
Houston Hoffmane6330442016-02-26 12:19:11 -0800186#endif
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700187};
188
Vishwajith Upendra70efc752016-04-18 11:23:49 -0700189static struct shadow_reg_cfg target_shadow_reg_cfg_epping[] = {
190 { 0, ADRASTEA_SRC_WR_INDEX_OFFSET},
191 { 3, ADRASTEA_SRC_WR_INDEX_OFFSET},
192 { 4, ADRASTEA_SRC_WR_INDEX_OFFSET},
193 { 7, ADRASTEA_SRC_WR_INDEX_OFFSET},
194 { 1, ADRASTEA_DST_WR_INDEX_OFFSET},
195 { 2, ADRASTEA_DST_WR_INDEX_OFFSET},
196 { 5, ADRASTEA_DST_WR_INDEX_OFFSET},
197 { 7, ADRASTEA_DST_WR_INDEX_OFFSET},
198 { 8, ADRASTEA_DST_WR_INDEX_OFFSET},
199};
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700200
201/* CE_PCI TABLE */
202/*
203 * NOTE: the table below is out of date, though still a useful reference.
204 * Refer to target_service_to_ce_map and hif_map_service_to_pipe for the actual
205 * mapping of HTC services to HIF pipes.
206 */
207/*
208 * This authoritative table defines Copy Engine configuration and the mapping
209 * of services/endpoints to CEs. A subset of this information is passed to
210 * the Target during startup as a prerequisite to entering BMI phase.
211 * See:
212 * target_service_to_ce_map - Target-side mapping
213 * hif_map_service_to_pipe - Host-side mapping
214 * target_ce_config - Target-side configuration
215 * host_ce_config - Host-side configuration
216 ============================================================================
217 Purpose | Service / Endpoint | CE | Dire | Xfer | Xfer
218 | | | ctio | Size | Frequency
219 | | | n | |
220 ============================================================================
221 tx | HTT_DATA (downlink) | CE 0 | h->t | medium - | very frequent
222 descriptor | | | | O(100B) | and regular
223 download | | | | |
224 ----------------------------------------------------------------------------
225 rx | HTT_DATA (uplink) | CE 1 | t->h | small - | frequent and
226 indication | | | | O(10B) | regular
227 upload | | | | |
228 ----------------------------------------------------------------------------
229 MSDU | DATA_BK (uplink) | CE 2 | t->h | large - | rare
230 upload | | | | O(1000B) | (frequent
231 e.g. noise | | | | | during IP1.0
232 packets | | | | | testing)
233 ----------------------------------------------------------------------------
234 MSDU | DATA_BK (downlink) | CE 3 | h->t | large - | very rare
235 download | | | | O(1000B) | (frequent
236 e.g. | | | | | during IP1.0
237 misdirecte | | | | | testing)
238 d EAPOL | | | | |
239 packets | | | | |
240 ----------------------------------------------------------------------------
241 n/a | DATA_BE, DATA_VI | CE 2 | t->h | | never(?)
242 | DATA_VO (uplink) | | | |
243 ----------------------------------------------------------------------------
244 n/a | DATA_BE, DATA_VI | CE 3 | h->t | | never(?)
245 | DATA_VO (downlink) | | | |
246 ----------------------------------------------------------------------------
247 WMI events | WMI_CONTROL (uplink) | CE 4 | t->h | medium - | infrequent
248 | | | | O(100B) |
249 ----------------------------------------------------------------------------
250 WMI | WMI_CONTROL | CE 5 | h->t | medium - | infrequent
251 messages | (downlink) | | | O(100B) |
252 | | | | |
253 ----------------------------------------------------------------------------
254 n/a | HTC_CTRL_RSVD, | CE 1 | t->h | | never(?)
255 | HTC_RAW_STREAMS | | | |
256 | (uplink) | | | |
257 ----------------------------------------------------------------------------
258 n/a | HTC_CTRL_RSVD, | CE 0 | h->t | | never(?)
259 | HTC_RAW_STREAMS | | | |
260 | (downlink) | | | |
261 ----------------------------------------------------------------------------
262 diag | none (raw CE) | CE 7 | t<>h | 4 | Diag Window
263 | | | | | infrequent
264 ============================================================================
265 */
266
267/*
268 * Map from service/endpoint to Copy Engine.
269 * This table is derived from the CE_PCI TABLE, above.
270 * It is passed to the Target at startup for use by firmware.
271 */
272static struct service_to_pipe target_service_to_ce_map_wlan[] = {
273 {
274 WMI_DATA_VO_SVC,
275 PIPEDIR_OUT, /* out = UL = host -> target */
276 3,
277 },
278 {
279 WMI_DATA_VO_SVC,
280 PIPEDIR_IN, /* in = DL = target -> host */
281 2,
282 },
283 {
284 WMI_DATA_BK_SVC,
285 PIPEDIR_OUT, /* out = UL = host -> target */
286 3,
287 },
288 {
289 WMI_DATA_BK_SVC,
290 PIPEDIR_IN, /* in = DL = target -> host */
291 2,
292 },
293 {
294 WMI_DATA_BE_SVC,
295 PIPEDIR_OUT, /* out = UL = host -> target */
296 3,
297 },
298 {
299 WMI_DATA_BE_SVC,
300 PIPEDIR_IN, /* in = DL = target -> host */
301 2,
302 },
303 {
304 WMI_DATA_VI_SVC,
305 PIPEDIR_OUT, /* out = UL = host -> target */
306 3,
307 },
308 {
309 WMI_DATA_VI_SVC,
310 PIPEDIR_IN, /* in = DL = target -> host */
311 2,
312 },
313 {
314 WMI_CONTROL_SVC,
315 PIPEDIR_OUT, /* out = UL = host -> target */
316 3,
317 },
318 {
319 WMI_CONTROL_SVC,
320 PIPEDIR_IN, /* in = DL = target -> host */
321 2,
322 },
323 {
324 HTC_CTRL_RSVD_SVC,
325 PIPEDIR_OUT, /* out = UL = host -> target */
326 0, /* could be moved to 3 (share with WMI) */
327 },
328 {
329 HTC_CTRL_RSVD_SVC,
330 PIPEDIR_IN, /* in = DL = target -> host */
331 2,
332 },
333 {
334 HTC_RAW_STREAMS_SVC, /* not currently used */
335 PIPEDIR_OUT, /* out = UL = host -> target */
336 0,
337 },
338 {
339 HTC_RAW_STREAMS_SVC, /* not currently used */
340 PIPEDIR_IN, /* in = DL = target -> host */
341 2,
342 },
343 {
344 HTT_DATA_MSG_SVC,
345 PIPEDIR_OUT, /* out = UL = host -> target */
346 4,
347 },
348 {
349 HTT_DATA_MSG_SVC,
350 PIPEDIR_IN, /* in = DL = target -> host */
351 1,
352 },
353 {
354 WDI_IPA_TX_SVC,
355 PIPEDIR_OUT, /* in = DL = target -> host */
356 5,
357 },
Houston Hoffmane6330442016-02-26 12:19:11 -0800358#if defined(QCA_WIFI_3_0_ADRASTEA)
359 {
360 HTT_DATA2_MSG_SVC,
361 PIPEDIR_IN, /* in = DL = target -> host */
362 9,
363 },
364 {
365 HTT_DATA3_MSG_SVC,
366 PIPEDIR_IN, /* in = DL = target -> host */
367 10,
368 },
Nirav Shah75cc5c82016-05-25 10:52:38 +0530369 {
370 PACKET_LOG_SVC,
371 PIPEDIR_IN, /* in = DL = target -> host */
372 11,
373 },
Houston Hoffmane6330442016-02-26 12:19:11 -0800374#endif
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700375 /* (Additions here) */
376
377 { /* Must be last */
378 0,
379 0,
380 0,
381 },
382};
383
Houston Hoffman88c896f2016-12-14 09:56:35 -0800384/* PIPEDIR_OUT = HOST to Target */
385/* PIPEDIR_IN = TARGET to HOST */
386static struct service_to_pipe target_service_to_ce_map_qca6290[] = {
387 { WMI_DATA_VO_SVC, PIPEDIR_OUT, 3, },
388 { WMI_DATA_VO_SVC, PIPEDIR_IN , 2, },
389 { WMI_DATA_BK_SVC, PIPEDIR_OUT, 3, },
390 { WMI_DATA_BK_SVC, PIPEDIR_IN , 2, },
391 { WMI_DATA_BE_SVC, PIPEDIR_OUT, 3, },
392 { WMI_DATA_BE_SVC, PIPEDIR_IN , 2, },
393 { WMI_DATA_VI_SVC, PIPEDIR_OUT, 3, },
394 { WMI_DATA_VI_SVC, PIPEDIR_IN , 2, },
395 { WMI_CONTROL_SVC, PIPEDIR_OUT, 3, },
396 { WMI_CONTROL_SVC, PIPEDIR_IN , 2, },
397 { HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0, },
398 { HTC_CTRL_RSVD_SVC, PIPEDIR_IN , 2, },
399 { HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4, },
400 { HTT_DATA_MSG_SVC, PIPEDIR_IN , 1, },
401 { PACKET_LOG_SVC, PIPEDIR_IN , 5, },
402 /* (Additions here) */
403 { 0, 0, 0, },
404};
405
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700406static struct service_to_pipe target_service_to_ce_map_ar900b[] = {
407 {
408 WMI_DATA_VO_SVC,
409 PIPEDIR_OUT, /* out = UL = host -> target */
410 3,
411 },
412 {
413 WMI_DATA_VO_SVC,
414 PIPEDIR_IN, /* in = DL = target -> host */
415 2,
416 },
417 {
418 WMI_DATA_BK_SVC,
419 PIPEDIR_OUT, /* out = UL = host -> target */
420 3,
421 },
422 {
423 WMI_DATA_BK_SVC,
424 PIPEDIR_IN, /* in = DL = target -> host */
425 2,
426 },
427 {
428 WMI_DATA_BE_SVC,
429 PIPEDIR_OUT, /* out = UL = host -> target */
430 3,
431 },
432 {
433 WMI_DATA_BE_SVC,
434 PIPEDIR_IN, /* in = DL = target -> host */
435 2,
436 },
437 {
438 WMI_DATA_VI_SVC,
439 PIPEDIR_OUT, /* out = UL = host -> target */
440 3,
441 },
442 {
443 WMI_DATA_VI_SVC,
444 PIPEDIR_IN, /* in = DL = target -> host */
445 2,
446 },
447 {
448 WMI_CONTROL_SVC,
449 PIPEDIR_OUT, /* out = UL = host -> target */
450 3,
451 },
452 {
453 WMI_CONTROL_SVC,
454 PIPEDIR_IN, /* in = DL = target -> host */
455 2,
456 },
457 {
458 HTC_CTRL_RSVD_SVC,
459 PIPEDIR_OUT, /* out = UL = host -> target */
460 0, /* could be moved to 3 (share with WMI) */
461 },
462 {
463 HTC_CTRL_RSVD_SVC,
464 PIPEDIR_IN, /* in = DL = target -> host */
465 1,
466 },
467 {
468 HTC_RAW_STREAMS_SVC, /* not currently used */
469 PIPEDIR_OUT, /* out = UL = host -> target */
470 0,
471 },
472 {
473 HTC_RAW_STREAMS_SVC, /* not currently used */
474 PIPEDIR_IN, /* in = DL = target -> host */
475 1,
476 },
477 {
478 HTT_DATA_MSG_SVC,
479 PIPEDIR_OUT, /* out = UL = host -> target */
480 4,
481 },
482#if WLAN_FEATURE_FASTPATH
483 {
484 HTT_DATA_MSG_SVC,
485 PIPEDIR_IN, /* in = DL = target -> host */
486 5,
487 },
488#else /* WLAN_FEATURE_FASTPATH */
489 {
490 HTT_DATA_MSG_SVC,
491 PIPEDIR_IN, /* in = DL = target -> host */
492 1,
493 },
494#endif /* WLAN_FEATURE_FASTPATH */
495
496 /* (Additions here) */
497
498 { /* Must be last */
499 0,
500 0,
501 0,
502 },
503};
504
505
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700506static struct service_to_pipe *target_service_to_ce_map =
507 target_service_to_ce_map_wlan;
508static int target_service_to_ce_map_sz = sizeof(target_service_to_ce_map_wlan);
509
510static struct shadow_reg_cfg *target_shadow_reg_cfg = target_shadow_reg_cfg_map;
511static int shadow_cfg_sz = sizeof(target_shadow_reg_cfg_map);
512
513static struct service_to_pipe target_service_to_ce_map_wlan_epping[] = {
514 {WMI_DATA_VO_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
515 {WMI_DATA_VO_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
516 {WMI_DATA_BK_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
517 {WMI_DATA_BK_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
518 {WMI_DATA_BE_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
519 {WMI_DATA_BE_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
520 {WMI_DATA_VI_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
521 {WMI_DATA_VI_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
522 {WMI_CONTROL_SVC, PIPEDIR_OUT, 3,}, /* out = UL = host -> target */
523 {WMI_CONTROL_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
524 {HTC_CTRL_RSVD_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
525 {HTC_CTRL_RSVD_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
526 {HTC_RAW_STREAMS_SVC, PIPEDIR_OUT, 0,}, /* out = UL = host -> target */
527 {HTC_RAW_STREAMS_SVC, PIPEDIR_IN, 2,}, /* in = DL = target -> host */
528 {HTT_DATA_MSG_SVC, PIPEDIR_OUT, 4,}, /* out = UL = host -> target */
529 {HTT_DATA_MSG_SVC, PIPEDIR_IN, 1,}, /* in = DL = target -> host */
530 {0, 0, 0,}, /* Must be last */
531};
532
533/**
534 * ce_mark_datapath() - marks the ce_state->htt_rx_data accordingly
535 * @ce_state : pointer to the state context of the CE
536 *
537 * Description:
538 * Sets htt_rx_data attribute of the state structure if the
539 * CE serves one of the HTT DATA services.
540 *
541 * Return:
542 * false (attribute set to false)
543 * true (attribute set to true);
544 */
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700545static bool ce_mark_datapath(struct CE_state *ce_state)
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700546{
547 struct service_to_pipe *svc_map;
548 size_t map_sz;
549 int i;
550 bool rc = false;
Houston Hoffman55fcf5a2016-09-27 23:21:51 -0700551 struct hif_target_info *tgt_info;
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700552
553 if (ce_state != NULL) {
Houston Hoffman55fcf5a2016-09-27 23:21:51 -0700554 tgt_info = &ce_state->scn->target_info;
555
Houston Hoffman75ef5a52016-04-14 17:15:49 -0700556 if (QDF_IS_EPPING_ENABLED(hif_get_conparam(ce_state->scn))) {
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700557 svc_map = target_service_to_ce_map_wlan_epping;
558 map_sz = sizeof(target_service_to_ce_map_wlan_epping) /
559 sizeof(struct service_to_pipe);
560 } else {
Houston Hoffmanfb698ef2016-05-05 19:50:44 -0700561 switch (tgt_info->target_type) {
562 default:
563 svc_map = target_service_to_ce_map_wlan;
564 map_sz =
565 sizeof(target_service_to_ce_map_wlan) /
566 sizeof(struct service_to_pipe);
567 break;
568 case TARGET_TYPE_AR900B:
569 case TARGET_TYPE_QCA9984:
570 case TARGET_TYPE_IPQ4019:
571 case TARGET_TYPE_QCA9888:
572 case TARGET_TYPE_AR9888:
573 case TARGET_TYPE_AR9888V2:
574 svc_map = target_service_to_ce_map_ar900b;
575 map_sz =
576 sizeof(target_service_to_ce_map_ar900b)
577 / sizeof(struct service_to_pipe);
578 break;
579 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700580 }
581 for (i = 0; i < map_sz; i++) {
582 if ((svc_map[i].pipenum == ce_state->id) &&
583 ((svc_map[i].service_id == HTT_DATA_MSG_SVC) ||
584 (svc_map[i].service_id == HTT_DATA2_MSG_SVC) ||
585 (svc_map[i].service_id == HTT_DATA3_MSG_SVC))) {
586 /* HTT CEs are unidirectional */
587 if (svc_map[i].pipedir == PIPEDIR_IN)
588 ce_state->htt_rx_data = true;
589 else
590 ce_state->htt_tx_data = true;
591 rc = true;
592 }
593 }
594 }
595 return rc;
596}
597
Houston Hoffman47808172016-05-06 10:04:21 -0700598/**
599 * ce_ring_test_initial_indexes() - tests the initial ce ring indexes
600 * @ce_id: ce in question
601 * @ring: ring state being examined
602 * @type: "src_ring" or "dest_ring" string for identifying the ring
603 *
604 * Warns on non-zero index values.
605 * Causes a kernel panic if the ring is not empty durring initialization.
606 */
607static void ce_ring_test_initial_indexes(int ce_id, struct CE_ring_state *ring,
608 char *type)
609{
610 if (ring->write_index != 0 || ring->sw_index != 0)
611 HIF_ERROR("ce %d, %s, initial sw_index = %d, initial write_index =%d",
612 ce_id, type, ring->sw_index, ring->write_index);
613 if (ring->write_index != ring->sw_index)
614 QDF_BUG(0);
615}
616
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530617/**
618 * ce_srng_based() - Does this target use srng
619 * @ce_state : pointer to the state context of the CE
620 *
621 * Description:
622 * returns true if the target is SRNG based
623 *
624 * Return:
625 * false (attribute set to false)
626 * true (attribute set to true);
627 */
628bool ce_srng_based(struct hif_softc *scn)
629{
630 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
631 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
632
633 switch (tgt_info->target_type) {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530634 case TARGET_TYPE_QCA8074:
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700635 case TARGET_TYPE_QCA6290:
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530636 return true;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530637 default:
638 return false;
639 }
640 return false;
641}
642
Houston Hoffman5141f9d2017-01-05 10:49:17 -0800643#ifdef QCA_WIFI_SUPPORT_SRNG
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700644static struct ce_ops *ce_services_attach(struct hif_softc *scn)
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530645{
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530646 if (ce_srng_based(scn))
647 return ce_services_srng();
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530648
649 return ce_services_legacy();
650}
Houston Hoffman5141f9d2017-01-05 10:49:17 -0800651
Houston Hoffman5141f9d2017-01-05 10:49:17 -0800652
Venkata Sharath Chandra Manchala837d3232017-01-18 15:11:56 -0800653#else /* QCA_LITHIUM */
654static struct ce_ops *ce_services_attach(struct hif_softc *scn)
655{
656 return ce_services_legacy();
657}
658#endif /* QCA_LITHIUM */
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530659
Houston Hoffman403c2df2017-01-27 12:51:15 -0800660static void hif_prepare_hal_shadow_register_cfg(struct hif_softc *scn,
Houston Hoffman10fedfc2017-01-23 15:23:09 -0800661 struct pld_shadow_reg_v2_cfg **shadow_config,
662 int *num_shadow_registers_configured) {
663 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
664
665 return hif_state->ce_services->ce_prepare_shadow_register_v2_cfg(
666 scn, shadow_config, num_shadow_registers_configured);
667}
668
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530669static inline uint32_t ce_get_desc_size(struct hif_softc *scn,
670 uint8_t ring_type)
671{
672 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
673
674 return hif_state->ce_services->ce_get_desc_size(ring_type);
675}
676
677
Jeff Johnson6950fdb2016-10-07 13:00:59 -0700678static struct CE_ring_state *ce_alloc_ring_state(struct CE_state *CE_state,
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530679 uint8_t ring_type, uint32_t nentries)
680{
681 uint32_t ce_nbytes;
682 char *ptr;
683 qdf_dma_addr_t base_addr;
684 struct CE_ring_state *ce_ring;
685 uint32_t desc_size;
686 struct hif_softc *scn = CE_state->scn;
687
688 ce_nbytes = sizeof(struct CE_ring_state)
689 + (nentries * sizeof(void *));
690 ptr = qdf_mem_malloc(ce_nbytes);
691 if (!ptr)
692 return NULL;
693
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530694 ce_ring = (struct CE_ring_state *)ptr;
695 ptr += sizeof(struct CE_ring_state);
696 ce_ring->nentries = nentries;
697 ce_ring->nentries_mask = nentries - 1;
698
699 ce_ring->low_water_mark_nentries = 0;
700 ce_ring->high_water_mark_nentries = nentries;
701 ce_ring->per_transfer_context = (void **)ptr;
702
703 desc_size = ce_get_desc_size(scn, ring_type);
704
705 /* Legacy platforms that do not support cache
706 * coherent DMA are unsupported
707 */
708 ce_ring->base_addr_owner_space_unaligned =
709 qdf_mem_alloc_consistent(scn->qdf_dev,
710 scn->qdf_dev->dev,
711 (nentries *
712 desc_size +
713 CE_DESC_RING_ALIGN),
714 &base_addr);
715 if (ce_ring->base_addr_owner_space_unaligned
716 == NULL) {
717 HIF_ERROR("%s: ring has no DMA mem",
718 __func__);
719 qdf_mem_free(ptr);
720 return NULL;
721 }
722 ce_ring->base_addr_CE_space_unaligned = base_addr;
723
724 /* Correctly initialize memory to 0 to
725 * prevent garbage data crashing system
726 * when download firmware
727 */
728 qdf_mem_zero(ce_ring->base_addr_owner_space_unaligned,
729 nentries * desc_size +
730 CE_DESC_RING_ALIGN);
731
732 if (ce_ring->base_addr_CE_space_unaligned & (CE_DESC_RING_ALIGN - 1)) {
733
734 ce_ring->base_addr_CE_space =
735 (ce_ring->base_addr_CE_space_unaligned +
736 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1);
737
738 ce_ring->base_addr_owner_space = (void *)
739 (((size_t) ce_ring->base_addr_owner_space_unaligned +
740 CE_DESC_RING_ALIGN - 1) & ~(CE_DESC_RING_ALIGN - 1));
741 } else {
742 ce_ring->base_addr_CE_space =
743 ce_ring->base_addr_CE_space_unaligned;
744 ce_ring->base_addr_owner_space =
745 ce_ring->base_addr_owner_space_unaligned;
746 }
747
748 return ce_ring;
749}
750
751static void ce_ring_setup(struct hif_softc *scn, uint8_t ring_type,
752 uint32_t ce_id, struct CE_ring_state *ring,
753 struct CE_attr *attr)
754{
755 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
756
757 hif_state->ce_services->ce_ring_setup(scn, ring_type, ce_id, ring, attr);
758}
759
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800760/*
761 * Initialize a Copy Engine based on caller-supplied attributes.
762 * This may be called once to initialize both source and destination
763 * rings or it may be called twice for separate source and destination
764 * initialization. It may be that only one side or the other is
765 * initialized by software/firmware.
Houston Hoffman233e9092015-09-02 13:37:21 -0700766 *
767 * This should be called durring the initialization sequence before
768 * interupts are enabled, so we don't have to worry about thread safety.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800769 */
Komal Seelam644263d2016-02-22 20:45:49 +0530770struct CE_handle *ce_init(struct hif_softc *scn,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800771 unsigned int CE_id, struct CE_attr *attr)
772{
773 struct CE_state *CE_state;
774 uint32_t ctrl_addr;
775 unsigned int nentries;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800776 bool malloc_CE_state = false;
777 bool malloc_src_ring = false;
778
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530779 QDF_ASSERT(CE_id < scn->ce_count);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800780 ctrl_addr = CE_BASE_ADDRESS(CE_id);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800781 CE_state = scn->ce_id_to_state[CE_id];
782
783 if (!CE_state) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800784 CE_state =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530785 (struct CE_state *)qdf_mem_malloc(sizeof(*CE_state));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800786 if (!CE_state) {
787 HIF_ERROR("%s: CE_state has no mem", __func__);
788 return NULL;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800789 }
Houston Hoffman233e9092015-09-02 13:37:21 -0700790 malloc_CE_state = true;
Houston Hoffman233e9092015-09-02 13:37:21 -0700791 scn->ce_id_to_state[CE_id] = CE_state;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530792 qdf_spinlock_create(&CE_state->ce_index_lock);
Houston Hoffman233e9092015-09-02 13:37:21 -0700793
794 CE_state->id = CE_id;
795 CE_state->ctrl_addr = ctrl_addr;
796 CE_state->state = CE_RUNNING;
797 CE_state->attr_flags = attr->flags;
Manjunathappa Prakash2146da32016-10-13 14:47:47 -0700798 qdf_spinlock_create(&CE_state->lro_unloading_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800799 }
800 CE_state->scn = scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800801
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530802 qdf_atomic_init(&CE_state->rx_pending);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800803 if (attr == NULL) {
804 /* Already initialized; caller wants the handle */
805 return (struct CE_handle *)CE_state;
806 }
807
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800808 if (CE_state->src_sz_max)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530809 QDF_ASSERT(CE_state->src_sz_max == attr->src_sz_max);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800810 else
811 CE_state->src_sz_max = attr->src_sz_max;
812
Houston Hoffman68e837e2015-12-04 12:57:24 -0800813 ce_init_ce_desc_event_log(CE_id,
814 attr->src_nentries + attr->dest_nentries);
815
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800816 /* source ring setup */
817 nentries = attr->src_nentries;
818 if (nentries) {
819 struct CE_ring_state *src_ring;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800820 nentries = roundup_pwr2(nentries);
821 if (CE_state->src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530822 QDF_ASSERT(CE_state->src_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800823 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530824 src_ring = CE_state->src_ring =
825 ce_alloc_ring_state(CE_state,
826 CE_RING_SRC,
827 nentries);
828 if (!src_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800829 /* cannot allocate src ring. If the
830 * CE_state is allocated locally free
831 * CE_State and return error.
832 */
833 HIF_ERROR("%s: src ring has no mem", __func__);
834 if (malloc_CE_state) {
835 /* allocated CE_state locally */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800836 scn->ce_id_to_state[CE_id] = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530837 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800838 malloc_CE_state = false;
839 }
840 return NULL;
841 } else {
842 /* we can allocate src ring.
843 * Mark that the src ring is
844 * allocated locally
845 */
846 malloc_src_ring = true;
847 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800848 /*
849 * Also allocate a shadow src ring in
850 * regular mem to use for faster access.
851 */
852 src_ring->shadow_base_unaligned =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530853 qdf_mem_malloc(nentries *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800854 sizeof(struct CE_src_desc) +
855 CE_DESC_RING_ALIGN);
856 if (src_ring->shadow_base_unaligned == NULL) {
857 HIF_ERROR("%s: src ring no shadow_base mem",
858 __func__);
859 goto error_no_dma_mem;
860 }
861 src_ring->shadow_base = (struct CE_src_desc *)
862 (((size_t) src_ring->shadow_base_unaligned +
863 CE_DESC_RING_ALIGN - 1) &
864 ~(CE_DESC_RING_ALIGN - 1));
865
Houston Hoffman4411ad42016-03-14 21:12:04 -0700866 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
867 goto error_target_access;
Houston Hoffmanf789c662016-04-12 15:39:04 -0700868
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530869 ce_ring_setup(scn, CE_RING_SRC, CE_id, src_ring, attr);
870
Houston Hoffman4411ad42016-03-14 21:12:04 -0700871 if (Q_TARGET_ACCESS_END(scn) < 0)
872 goto error_target_access;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530873 ce_ring_test_initial_indexes(CE_id, src_ring,
874 "src_ring");
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800875 }
876 }
877
878 /* destination ring setup */
879 nentries = attr->dest_nentries;
880 if (nentries) {
881 struct CE_ring_state *dest_ring;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800882
883 nentries = roundup_pwr2(nentries);
884 if (CE_state->dest_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530885 QDF_ASSERT(CE_state->dest_ring->nentries == nentries);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800886 } else {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530887 dest_ring = CE_state->dest_ring =
888 ce_alloc_ring_state(CE_state,
889 CE_RING_DEST,
890 nentries);
891 if (!dest_ring) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800892 /* cannot allocate dst ring. If the CE_state
893 * or src ring is allocated locally free
894 * CE_State and src ring and return error.
895 */
896 HIF_ERROR("%s: dest ring has no mem",
897 __func__);
898 if (malloc_src_ring) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530899 qdf_mem_free(CE_state->src_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800900 CE_state->src_ring = NULL;
901 malloc_src_ring = false;
902 }
903 if (malloc_CE_state) {
904 /* allocated CE_state locally */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800905 scn->ce_id_to_state[CE_id] = NULL;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530906 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800907 malloc_CE_state = false;
908 }
909 return NULL;
910 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800911
Houston Hoffman4411ad42016-03-14 21:12:04 -0700912 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
913 goto error_target_access;
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530914
915 ce_ring_setup(scn, CE_RING_DEST, CE_id, dest_ring, attr);
916
917 if (Q_TARGET_ACCESS_END(scn) < 0)
918 goto error_target_access;
Houston Hoffman47808172016-05-06 10:04:21 -0700919
920 ce_ring_test_initial_indexes(CE_id, dest_ring,
921 "dest_ring");
922
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530923 /* For srng based target, init status ring here */
924 if (ce_srng_based(CE_state->scn)) {
925 CE_state->status_ring =
926 ce_alloc_ring_state(CE_state,
927 CE_RING_STATUS,
928 nentries);
929 if (CE_state->status_ring == NULL) {
930 /*Allocation failed. Cleanup*/
931 qdf_mem_free(CE_state->dest_ring);
932 if (malloc_src_ring) {
933 qdf_mem_free
934 (CE_state->src_ring);
935 CE_state->src_ring = NULL;
936 malloc_src_ring = false;
937 }
938 if (malloc_CE_state) {
939 /* allocated CE_state locally */
940 scn->ce_id_to_state[CE_id] =
941 NULL;
942 qdf_mem_free(CE_state);
943 malloc_CE_state = false;
944 }
Houston Hoffman4411ad42016-03-14 21:12:04 -0700945
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530946 return NULL;
947 }
948 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
949 goto error_target_access;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800950
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530951 ce_ring_setup(scn, CE_RING_STATUS, CE_id,
952 CE_state->status_ring, attr);
953
954 if (Q_TARGET_ACCESS_END(scn) < 0)
955 goto error_target_access;
956
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800957 }
Houston Hoffman31b25ec2016-09-19 13:12:30 -0700958
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800959 /* epping */
960 /* poll timer */
961 if ((CE_state->attr_flags & CE_ATTR_ENABLE_POLL)) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530962 qdf_timer_init(scn->qdf_dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800963 &CE_state->poll_timer,
964 ce_poll_timeout,
965 CE_state,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530966 QDF_TIMER_TYPE_SW);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800967 CE_state->timer_inited = true;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530968 qdf_timer_mod(&CE_state->poll_timer,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800969 CE_POLL_TIMEOUT);
970 }
971 }
972 }
973
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +0530974 if (!ce_srng_based(scn)) {
975 /* Enable CE error interrupts */
976 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
977 goto error_target_access;
978 CE_ERROR_INTR_ENABLE(scn, ctrl_addr);
979 if (Q_TARGET_ACCESS_END(scn) < 0)
980 goto error_target_access;
981 }
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800982
Houston Hoffmanc7d54292016-04-13 18:55:37 -0700983 /* update the htt_data attribute */
984 ce_mark_datapath(CE_state);
985
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800986 return (struct CE_handle *)CE_state;
987
Houston Hoffman4411ad42016-03-14 21:12:04 -0700988error_target_access:
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800989error_no_dma_mem:
990 ce_fini((struct CE_handle *)CE_state);
991 return NULL;
992}
993
994#ifdef WLAN_FEATURE_FASTPATH
995/**
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -0700996 * hif_enable_fastpath() Update that we have enabled fastpath mode
997 * @hif_ctx: HIF context
998 *
999 * For use in data path
1000 *
1001 * Retrun: void
1002 */
1003void hif_enable_fastpath(struct hif_opaque_softc *hif_ctx)
1004{
1005 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1006
Houston Hoffmand63cd742016-12-05 11:59:56 -08001007 if (ce_srng_based(scn)) {
1008 HIF_INFO("%s, srng rings do not support fastpath", __func__);
1009 return;
1010 }
Houston Hoffmanc50572b2016-06-08 19:49:46 -07001011 HIF_INFO("%s, Enabling fastpath mode", __func__);
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001012 scn->fastpath_mode_on = true;
1013}
1014
1015/**
1016 * hif_is_fastpath_mode_enabled - API to query if fasthpath mode is enabled
1017 * @hif_ctx: HIF Context
1018 *
1019 * For use in data path to skip HTC
1020 *
1021 * Return: bool
1022 */
1023bool hif_is_fastpath_mode_enabled(struct hif_opaque_softc *hif_ctx)
1024{
1025 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1026
1027 return scn->fastpath_mode_on;
1028}
1029
1030/**
1031 * hif_get_ce_handle - API to get CE handle for FastPath mode
1032 * @hif_ctx: HIF Context
1033 * @id: CopyEngine Id
1034 *
1035 * API to return CE handle for fastpath mode
1036 *
1037 * Return: void
1038 */
1039void *hif_get_ce_handle(struct hif_opaque_softc *hif_ctx, int id)
1040{
1041 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
1042
1043 return scn->ce_id_to_state[id];
1044}
1045
1046/**
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001047 * ce_h2t_tx_ce_cleanup() Place holder function for H2T CE cleanup.
1048 * No processing is required inside this function.
1049 * @ce_hdl: Cope engine handle
1050 * Using an assert, this function makes sure that,
1051 * the TX CE has been processed completely.
Houston Hoffman9a831ef2015-09-03 14:42:40 -07001052 *
1053 * This is called while dismantling CE structures. No other thread
1054 * should be using these structures while dismantling is occuring
1055 * therfore no locking is needed.
1056 *
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001057 * Return: none
1058 */
1059void
1060ce_h2t_tx_ce_cleanup(struct CE_handle *ce_hdl)
1061{
1062 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1063 struct CE_ring_state *src_ring = ce_state->src_ring;
Komal Seelam644263d2016-02-22 20:45:49 +05301064 struct hif_softc *sc = ce_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001065 uint32_t sw_index, write_index;
Houston Hoffman85925072016-05-06 17:02:18 -07001066 if (hif_is_nss_wifi_enabled(sc))
1067 return;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001068
Houston Hoffmanc7d54292016-04-13 18:55:37 -07001069 if (sc->fastpath_mode_on && ce_state->htt_tx_data) {
Houston Hoffman85925072016-05-06 17:02:18 -07001070 HIF_INFO("%s %d Fastpath mode ON, Cleaning up HTT Tx CE",
1071 __func__, __LINE__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001072 sw_index = src_ring->sw_index;
1073 write_index = src_ring->sw_index;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001074
1075 /* At this point Tx CE should be clean */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301076 qdf_assert_always(sw_index == write_index);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001077 }
1078}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001079
1080/**
1081 * ce_t2h_msg_ce_cleanup() - Cleanup buffers on the t2h datapath msg queue.
1082 * @ce_hdl: Handle to CE
1083 *
1084 * These buffers are never allocated on the fly, but
1085 * are allocated only once during HIF start and freed
1086 * only once during HIF stop.
1087 * NOTE:
1088 * The assumption here is there is no in-flight DMA in progress
1089 * currently, so that buffers can be freed up safely.
1090 *
1091 * Return: NONE
1092 */
1093void ce_t2h_msg_ce_cleanup(struct CE_handle *ce_hdl)
1094{
1095 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
1096 struct CE_ring_state *dst_ring = ce_state->dest_ring;
1097 qdf_nbuf_t nbuf;
1098 int i;
1099
Houston Hoffman7fe51b12016-11-14 18:01:05 -08001100 if (ce_state->scn->fastpath_mode_on == false)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001101 return;
Houston Hoffman7fe51b12016-11-14 18:01:05 -08001102
1103 if (!ce_state->htt_rx_data)
1104 return;
1105
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001106 /*
1107 * when fastpath_mode is on and for datapath CEs. Unlike other CE's,
1108 * this CE is completely full: does not leave one blank space, to
1109 * distinguish between empty queue & full queue. So free all the
1110 * entries.
1111 */
1112 for (i = 0; i < dst_ring->nentries; i++) {
1113 nbuf = dst_ring->per_transfer_context[i];
1114
1115 /*
1116 * The reasons for doing this check are:
1117 * 1) Protect against calling cleanup before allocating buffers
1118 * 2) In a corner case, FASTPATH_mode_on may be set, but we
1119 * could have a partially filled ring, because of a memory
1120 * allocation failure in the middle of allocating ring.
1121 * This check accounts for that case, checking
1122 * fastpath_mode_on flag or started flag would not have
1123 * covered that case. This is not in performance path,
1124 * so OK to do this.
1125 */
1126 if (nbuf)
1127 qdf_nbuf_free(nbuf);
1128 }
1129}
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001130
1131/**
1132 * hif_update_fastpath_recv_bufs_cnt() - Increments the Rx buf count by 1
1133 * @scn: HIF handle
1134 *
1135 * Datapath Rx CEs are special case, where we reuse all the message buffers.
1136 * Hence we have to post all the entries in the pipe, even, in the beginning
1137 * unlike for other CE pipes where one less than dest_nentries are filled in
1138 * the beginning.
1139 *
1140 * Return: None
1141 */
1142static void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
1143{
1144 int pipe_num;
1145 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
1146
1147 if (scn->fastpath_mode_on == false)
1148 return;
1149
1150 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1151 struct HIF_CE_pipe_info *pipe_info =
1152 &hif_state->pipe_info[pipe_num];
1153 struct CE_state *ce_state =
1154 scn->ce_id_to_state[pipe_info->pipe_num];
1155
1156 if (ce_state->htt_rx_data)
1157 atomic_inc(&pipe_info->recv_bufs_needed);
1158 }
1159}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001160#else
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001161static inline void hif_update_fastpath_recv_bufs_cnt(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001162{
1163}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001164
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001165static inline bool ce_is_fastpath_enabled(struct hif_softc *scn)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001166{
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001167 return false;
1168}
1169
1170static inline bool ce_is_fastpath_handler_registered(struct CE_state *ce_state)
1171{
1172 return false;
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001173}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001174#endif /* WLAN_FEATURE_FASTPATH */
1175
1176void ce_fini(struct CE_handle *copyeng)
1177{
1178 struct CE_state *CE_state = (struct CE_state *)copyeng;
1179 unsigned int CE_id = CE_state->id;
Komal Seelam644263d2016-02-22 20:45:49 +05301180 struct hif_softc *scn = CE_state->scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001181
1182 CE_state->state = CE_UNUSED;
1183 scn->ce_id_to_state[CE_id] = NULL;
1184 if (CE_state->src_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001185 /* Cleanup the datapath Tx ring */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001186 ce_h2t_tx_ce_cleanup(copyeng);
1187
1188 if (CE_state->src_ring->shadow_base_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301189 qdf_mem_free(CE_state->src_ring->shadow_base_unaligned);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001190 if (CE_state->src_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->src_ring->nentries *
1194 sizeof(struct CE_src_desc) +
1195 CE_DESC_RING_ALIGN),
1196 CE_state->src_ring->
1197 base_addr_owner_space_unaligned,
1198 CE_state->src_ring->
1199 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301200 qdf_mem_free(CE_state->src_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001201 }
1202 if (CE_state->dest_ring) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07001203 /* Cleanup the datapath Rx ring */
1204 ce_t2h_msg_ce_cleanup(copyeng);
1205
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001206 if (CE_state->dest_ring->base_addr_owner_space_unaligned)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301207 qdf_mem_free_consistent(scn->qdf_dev,
1208 scn->qdf_dev->dev,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001209 (CE_state->dest_ring->nentries *
1210 sizeof(struct CE_dest_desc) +
1211 CE_DESC_RING_ALIGN),
1212 CE_state->dest_ring->
1213 base_addr_owner_space_unaligned,
1214 CE_state->dest_ring->
1215 base_addr_CE_space, 0);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301216 qdf_mem_free(CE_state->dest_ring);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001217
1218 /* epping */
1219 if (CE_state->timer_inited) {
1220 CE_state->timer_inited = false;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301221 qdf_timer_free(&CE_state->poll_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001222 }
1223 }
Houston Hoffman31b25ec2016-09-19 13:12:30 -07001224 if ((ce_srng_based(CE_state->scn)) && (CE_state->status_ring)) {
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05301225 /* Cleanup the datapath Tx ring */
1226 ce_h2t_tx_ce_cleanup(copyeng);
1227
1228 if (CE_state->status_ring->shadow_base_unaligned)
1229 qdf_mem_free(
1230 CE_state->status_ring->shadow_base_unaligned);
1231
1232 if (CE_state->status_ring->base_addr_owner_space_unaligned)
1233 qdf_mem_free_consistent(scn->qdf_dev,
1234 scn->qdf_dev->dev,
1235 (CE_state->status_ring->nentries *
1236 sizeof(struct CE_src_desc) +
1237 CE_DESC_RING_ALIGN),
1238 CE_state->status_ring->
1239 base_addr_owner_space_unaligned,
1240 CE_state->status_ring->
1241 base_addr_CE_space, 0);
1242 qdf_mem_free(CE_state->status_ring);
1243 }
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301244 qdf_mem_free(CE_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001245}
1246
Komal Seelam5584a7c2016-02-24 19:22:48 +05301247void hif_detach_htc(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001248{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301249 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001250
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301251 qdf_mem_zero(&hif_state->msg_callbacks_pending,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001252 sizeof(hif_state->msg_callbacks_pending));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301253 qdf_mem_zero(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001254 sizeof(hif_state->msg_callbacks_current));
1255}
1256
1257/* Send the first nbytes bytes of the buffer */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301258QDF_STATUS
Komal Seelam5584a7c2016-02-24 19:22:48 +05301259hif_send_head(struct hif_opaque_softc *hif_ctx,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001260 uint8_t pipe, unsigned int transfer_id, unsigned int nbytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301261 qdf_nbuf_t nbuf, unsigned int data_attr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001262{
Komal Seelam644263d2016-02-22 20:45:49 +05301263 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301264 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001265 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1266 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
1267 int bytes = nbytes, nfrags = 0;
1268 struct ce_sendlist sendlist;
1269 int status, i = 0;
1270 unsigned int mux_id = 0;
1271
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301272 QDF_ASSERT(nbytes <= qdf_nbuf_len(nbuf));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001273
1274 transfer_id =
1275 (mux_id & MUX_ID_MASK) |
1276 (transfer_id & TRANSACTION_ID_MASK);
1277 data_attr &= DESC_DATA_FLAG_MASK;
1278 /*
1279 * The common case involves sending multiple fragments within a
1280 * single download (the tx descriptor and the tx frame header).
1281 * So, optimize for the case of multiple fragments by not even
1282 * checking whether it's necessary to use a sendlist.
1283 * The overhead of using a sendlist for a single buffer download
1284 * is not a big deal, since it happens rarely (for WMI messages).
1285 */
1286 ce_sendlist_init(&sendlist);
1287 do {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301288 qdf_dma_addr_t frag_paddr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001289 int frag_bytes;
1290
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301291 frag_paddr = qdf_nbuf_get_frag_paddr(nbuf, nfrags);
1292 frag_bytes = qdf_nbuf_get_frag_len(nbuf, nfrags);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001293 /*
1294 * Clear the packet offset for all but the first CE desc.
1295 */
1296 if (i++ > 0)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301297 data_attr &= ~QDF_CE_TX_PKT_OFFSET_BIT_M;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001298
1299 status = ce_sendlist_buf_add(&sendlist, frag_paddr,
1300 frag_bytes >
1301 bytes ? bytes : frag_bytes,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301302 qdf_nbuf_get_frag_is_wordstream
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001303 (nbuf,
1304 nfrags) ? 0 :
1305 CE_SEND_FLAG_SWAP_DISABLE,
1306 data_attr);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301307 if (status != QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001308 HIF_ERROR("%s: error, frag_num %d larger than limit",
1309 __func__, nfrags);
1310 return status;
1311 }
1312 bytes -= frag_bytes;
1313 nfrags++;
1314 } while (bytes > 0);
1315
1316 /* Make sure we have resources to handle this request */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301317 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001318 if (pipe_info->num_sends_allowed < nfrags) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301319 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001320 ce_pkt_error_count_incr(hif_state, HIF_PIPE_NO_RESOURCE);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301321 return QDF_STATUS_E_RESOURCES;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001322 }
1323 pipe_info->num_sends_allowed -= nfrags;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301324 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001325
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301326 if (qdf_unlikely(ce_hdl == NULL)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001327 HIF_ERROR("%s: error CE handle is null", __func__);
1328 return A_ERROR;
1329 }
1330
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301331 QDF_NBUF_UPDATE_TX_PKT_COUNT(nbuf, QDF_NBUF_TX_PKT_HIF);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301332 DPTRACE(qdf_dp_trace(nbuf, QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
Nirav Shaheaa20d82016-04-25 18:01:05 +05301333 qdf_nbuf_data_addr(nbuf),
Nirav Shah29beae02016-04-26 22:58:54 +05301334 sizeof(qdf_nbuf_data(nbuf)), QDF_TX));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001335 status = ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301336 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001337
1338 return status;
1339}
1340
Komal Seelam5584a7c2016-02-24 19:22:48 +05301341void hif_send_complete_check(struct hif_opaque_softc *hif_ctx, uint8_t pipe,
1342 int force)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001343{
Komal Seelam644263d2016-02-22 20:45:49 +05301344 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301345 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Komal Seelam644263d2016-02-22 20:45:49 +05301346
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001347 if (!force) {
1348 int resources;
1349 /*
1350 * Decide whether to actually poll for completions, or just
1351 * wait for a later chance. If there seem to be plenty of
1352 * resources left, then just wait, since checking involves
1353 * reading a CE register, which is a relatively expensive
1354 * operation.
1355 */
Komal Seelam644263d2016-02-22 20:45:49 +05301356 resources = hif_get_free_queue_number(hif_ctx, pipe);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001357 /*
1358 * If at least 50% of the total resources are still available,
1359 * don't bother checking again yet.
1360 */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301361 if (resources > (hif_state->host_ce_config[pipe].src_nentries >> 1)) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001362 return;
1363 }
1364 }
Houston Hoffman56e0d702016-05-05 17:48:06 -07001365#if ATH_11AC_TXCOMPACT
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001366 ce_per_engine_servicereap(scn, pipe);
1367#else
1368 ce_per_engine_service(scn, pipe);
1369#endif
1370}
1371
Komal Seelam5584a7c2016-02-24 19:22:48 +05301372uint16_t
1373hif_get_free_queue_number(struct hif_opaque_softc *hif_ctx, uint8_t pipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001374{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301375 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001376 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
1377 uint16_t rv;
1378
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301379 qdf_spin_lock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001380 rv = pipe_info->num_sends_allowed;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301381 qdf_spin_unlock_bh(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001382 return rv;
1383}
1384
1385/* Called by lower (CE) layer when a send to Target completes. */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001386static void
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001387hif_pci_ce_send_done(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301388 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001389 unsigned int nbytes, unsigned int transfer_id,
1390 unsigned int sw_index, unsigned int hw_index,
1391 unsigned int toeplitz_hash_result)
1392{
1393 struct HIF_CE_pipe_info *pipe_info =
1394 (struct HIF_CE_pipe_info *)ce_context;
1395 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Komal Seelam644263d2016-02-22 20:45:49 +05301396 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001397 unsigned int sw_idx = sw_index, hw_idx = hw_index;
Houston Hoffman85118512015-09-28 14:17:11 -07001398 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301399 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001400
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001401 do {
1402 /*
Houston Hoffman85118512015-09-28 14:17:11 -07001403 * The upper layer callback will be triggered
1404 * when last fragment is complteted.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001405 */
Houston Hoffman85118512015-09-28 14:17:11 -07001406 if (transfer_context != CE_SENDLIST_ITEM_CTXT) {
Komal Seelam6ee55902016-04-11 17:11:07 +05301407 if (scn->target_status == TARGET_STATUS_RESET)
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301408 qdf_nbuf_free(transfer_context);
Houston Hoffman49794a32015-12-21 12:14:56 -08001409 else
1410 msg_callbacks->txCompletionHandler(
Houston Hoffman85118512015-09-28 14:17:11 -07001411 msg_callbacks->Context,
1412 transfer_context, transfer_id,
1413 toeplitz_hash_result);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001414 }
1415
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301416 qdf_spin_lock(&pipe_info->completion_freeq_lock);
Houston Hoffman85118512015-09-28 14:17:11 -07001417 pipe_info->num_sends_allowed++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301418 qdf_spin_unlock(&pipe_info->completion_freeq_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001419 } while (ce_completed_send_next(copyeng,
1420 &ce_context, &transfer_context,
1421 &CE_data, &nbytes, &transfer_id,
1422 &sw_idx, &hw_idx,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301423 &toeplitz_hash_result) == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001424}
1425
Houston Hoffman910c6262015-09-28 12:56:25 -07001426/**
1427 * hif_ce_do_recv(): send message from copy engine to upper layers
1428 * @msg_callbacks: structure containing callback and callback context
1429 * @netbuff: skb containing message
1430 * @nbytes: number of bytes in the message
1431 * @pipe_info: used for the pipe_number info
1432 *
1433 * Checks the packet length, configures the lenght in the netbuff,
1434 * and calls the upper layer callback.
1435 *
1436 * return: None
1437 */
1438static inline void hif_ce_do_recv(struct hif_msg_callbacks *msg_callbacks,
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301439 qdf_nbuf_t netbuf, int nbytes,
Houston Hoffman910c6262015-09-28 12:56:25 -07001440 struct HIF_CE_pipe_info *pipe_info) {
1441 if (nbytes <= pipe_info->buf_sz) {
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301442 qdf_nbuf_set_pktlen(netbuf, nbytes);
Houston Hoffman910c6262015-09-28 12:56:25 -07001443 msg_callbacks->
1444 rxCompletionHandler(msg_callbacks->Context,
1445 netbuf, pipe_info->pipe_num);
1446 } else {
1447 HIF_ERROR("%s: Invalid Rx msg buf:%p nbytes:%d",
1448 __func__, netbuf, nbytes);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301449 qdf_nbuf_free(netbuf);
Houston Hoffman910c6262015-09-28 12:56:25 -07001450 }
1451}
1452
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001453/* Called by lower (CE) layer when data is received from the Target. */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001454static void
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001455hif_pci_ce_recv_data(struct CE_handle *copyeng, void *ce_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301456 void *transfer_context, qdf_dma_addr_t CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001457 unsigned int nbytes, unsigned int transfer_id,
1458 unsigned int flags)
1459{
1460 struct HIF_CE_pipe_info *pipe_info =
1461 (struct HIF_CE_pipe_info *)ce_context;
1462 struct HIF_CE_state *hif_state = pipe_info->HIF_CE_state;
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001463 struct CE_state *ce_state = (struct CE_state *) copyeng;
Komal Seelam644263d2016-02-22 20:45:49 +05301464 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001465#ifdef HIF_PCI
1466 struct hif_pci_softc *hif_pci_sc = HIF_GET_PCI_SOFTC(hif_state);
1467#endif
Houston Hoffman910c6262015-09-28 12:56:25 -07001468 struct hif_msg_callbacks *msg_callbacks =
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301469 &pipe_info->pipe_callbacks;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001470
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001471 do {
Houston Hoffmane02e12d2016-03-14 21:11:36 -07001472#ifdef HIF_PCI
1473 hif_pm_runtime_mark_last_busy(hif_pci_sc->dev);
1474#endif
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301475 qdf_nbuf_unmap_single(scn->qdf_dev,
1476 (qdf_nbuf_t) transfer_context,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301477 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001478
Houston Hoffman910c6262015-09-28 12:56:25 -07001479 atomic_inc(&pipe_info->recv_bufs_needed);
1480 hif_post_recv_buffers_for_pipe(pipe_info);
Komal Seelam6ee55902016-04-11 17:11:07 +05301481 if (scn->target_status == TARGET_STATUS_RESET)
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301482 qdf_nbuf_free(transfer_context);
Houston Hoffman49794a32015-12-21 12:14:56 -08001483 else
1484 hif_ce_do_recv(msg_callbacks, transfer_context,
Houston Hoffman9c0f80a2015-09-28 18:36:36 -07001485 nbytes, pipe_info);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001486
1487 /* Set up force_break flag if num of receices reaches
1488 * MAX_NUM_OF_RECEIVES */
Houston Hoffman5bf441a2015-09-02 11:52:10 -07001489 ce_state->receive_count++;
Houston Hoffman05652722016-04-29 16:58:59 -07001490 if (qdf_unlikely(hif_ce_service_should_yield(scn, ce_state))) {
Houston Hoffman18c7fc52015-09-02 11:44:42 -07001491 ce_state->force_break = 1;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001492 break;
1493 }
1494 } while (ce_completed_recv_next(copyeng, &ce_context, &transfer_context,
1495 &CE_data, &nbytes, &transfer_id,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301496 &flags) == QDF_STATUS_SUCCESS);
Houston Hoffmanf4607852015-12-17 17:14:40 -08001497
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001498}
1499
1500/* TBDXXX: Set CE High Watermark; invoke txResourceAvailHandler in response */
1501
1502void
Komal Seelam5584a7c2016-02-24 19:22:48 +05301503hif_post_init(struct hif_opaque_softc *hif_ctx, void *unused,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001504 struct hif_msg_callbacks *callbacks)
1505{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301506 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_ctx);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001507
1508#ifdef CONFIG_ATH_PCIE_ACCESS_DEBUG
1509 spin_lock_init(&pcie_access_log_lock);
1510#endif
1511 /* Save callbacks for later installation */
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301512 qdf_mem_copy(&hif_state->msg_callbacks_pending, callbacks,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001513 sizeof(hif_state->msg_callbacks_pending));
1514
1515}
1516
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001517static int hif_completion_thread_startup(struct HIF_CE_state *hif_state)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001518{
1519 struct CE_handle *ce_diag = hif_state->ce_diag;
1520 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05301521 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001522 struct hif_msg_callbacks *hif_msg_callbacks =
1523 &hif_state->msg_callbacks_current;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001524
1525 /* daemonize("hif_compl_thread"); */
1526
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001527 if (scn->ce_count == 0) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07001528 HIF_ERROR("%s: Invalid ce_count", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001529 return -EINVAL;
1530 }
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001531
1532 if (!hif_msg_callbacks ||
1533 !hif_msg_callbacks->rxCompletionHandler ||
1534 !hif_msg_callbacks->txCompletionHandler) {
1535 HIF_ERROR("%s: no completion handler registered", __func__);
1536 return -EFAULT;
1537 }
1538
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001539 A_TARGET_ACCESS_LIKELY(scn);
1540 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1541 struct CE_attr attr;
1542 struct HIF_CE_pipe_info *pipe_info;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001543
1544 pipe_info = &hif_state->pipe_info[pipe_num];
1545 if (pipe_info->ce_hdl == ce_diag) {
1546 continue; /* Handle Diagnostic CE specially */
1547 }
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301548 attr = hif_state->host_ce_config[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001549 if (attr.src_nentries) {
1550 /* pipe used to send to target */
1551 HIF_INFO_MED("%s: pipe_num:%d pipe_info:0x%p",
1552 __func__, pipe_num, pipe_info);
1553 ce_send_cb_register(pipe_info->ce_hdl,
1554 hif_pci_ce_send_done, pipe_info,
1555 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001556 pipe_info->num_sends_allowed = attr.src_nentries - 1;
1557 }
1558 if (attr.dest_nentries) {
1559 /* pipe used to receive from target */
1560 ce_recv_cb_register(pipe_info->ce_hdl,
1561 hif_pci_ce_recv_data, pipe_info,
1562 attr.flags & CE_ATTR_DISABLE_INTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001563 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001564
1565 if (attr.src_nentries)
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301566 qdf_spinlock_create(&pipe_info->completion_freeq_lock);
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301567
1568 qdf_mem_copy(&pipe_info->pipe_callbacks, hif_msg_callbacks,
1569 sizeof(pipe_info->pipe_callbacks));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001570 }
Houston Hoffman6666df72015-11-30 16:48:35 -08001571
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001572 A_TARGET_ACCESS_UNLIKELY(scn);
1573 return 0;
1574}
1575
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001576/*
1577 * Install pending msg callbacks.
1578 *
1579 * TBDXXX: This hack is needed because upper layers install msg callbacks
1580 * for use with HTC before BMI is done; yet this HIF implementation
1581 * needs to continue to use BMI msg callbacks. Really, upper layers
1582 * should not register HTC callbacks until AFTER BMI phase.
1583 */
Komal Seelam644263d2016-02-22 20:45:49 +05301584static void hif_msg_callbacks_install(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001585{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301586 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001587
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301588 qdf_mem_copy(&hif_state->msg_callbacks_current,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001589 &hif_state->msg_callbacks_pending,
1590 sizeof(hif_state->msg_callbacks_pending));
1591}
1592
Komal Seelam5584a7c2016-02-24 19:22:48 +05301593void hif_get_default_pipe(struct hif_opaque_softc *hif_hdl, uint8_t *ULPipe,
1594 uint8_t *DLPipe)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001595{
1596 int ul_is_polled, dl_is_polled;
1597
Komal Seelam644263d2016-02-22 20:45:49 +05301598 (void)hif_map_service_to_pipe(hif_hdl, HTC_CTRL_RSVD_SVC,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001599 ULPipe, DLPipe, &ul_is_polled, &dl_is_polled);
1600}
1601
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001602/**
1603 * hif_dump_pipe_debug_count() - Log error count
Komal Seelam644263d2016-02-22 20:45:49 +05301604 * @scn: hif_softc pointer.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001605 *
1606 * Output the pipe error counts of each pipe to log file
1607 *
1608 * Return: N/A
1609 */
Komal Seelam644263d2016-02-22 20:45:49 +05301610void hif_dump_pipe_debug_count(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001611{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301612 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001613 int pipe_num;
1614
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001615 if (hif_state == NULL) {
1616 HIF_ERROR("%s hif_state is NULL", __func__);
1617 return;
1618 }
1619 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1620 struct HIF_CE_pipe_info *pipe_info;
1621
1622 pipe_info = &hif_state->pipe_info[pipe_num];
1623
1624 if (pipe_info->nbuf_alloc_err_count > 0 ||
1625 pipe_info->nbuf_dma_err_count > 0 ||
1626 pipe_info->nbuf_ce_enqueue_err_count)
1627 HIF_ERROR(
1628 "%s: pipe_id = %d, recv_bufs_needed = %d, nbuf_alloc_err_count = %u, nbuf_dma_err_count = %u, nbuf_ce_enqueue_err_count = %u",
1629 __func__, pipe_info->pipe_num,
1630 atomic_read(&pipe_info->recv_bufs_needed),
1631 pipe_info->nbuf_alloc_err_count,
1632 pipe_info->nbuf_dma_err_count,
1633 pipe_info->nbuf_ce_enqueue_err_count);
1634 }
1635}
1636
1637static int hif_post_recv_buffers_for_pipe(struct HIF_CE_pipe_info *pipe_info)
1638{
1639 struct CE_handle *ce_hdl;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301640 qdf_size_t buf_sz;
Komal Seelam644263d2016-02-22 20:45:49 +05301641 struct hif_softc *scn = HIF_GET_SOFTC(pipe_info->HIF_CE_state);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301642 QDF_STATUS ret;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001643 uint32_t bufs_posted = 0;
1644
1645 buf_sz = pipe_info->buf_sz;
1646 if (buf_sz == 0) {
1647 /* Unused Copy Engine */
1648 return 0;
1649 }
1650
1651 ce_hdl = pipe_info->ce_hdl;
1652
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301653 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001654 while (atomic_read(&pipe_info->recv_bufs_needed) > 0) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301655 qdf_dma_addr_t CE_data; /* CE space buffer address */
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301656 qdf_nbuf_t nbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001657 int status;
1658
1659 atomic_dec(&pipe_info->recv_bufs_needed);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301660 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001661
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301662 nbuf = qdf_nbuf_alloc(scn->qdf_dev, buf_sz, 0, 4, false);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001663 if (!nbuf) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301664 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001665 pipe_info->nbuf_alloc_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301666 qdf_spin_unlock_bh(
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001667 &pipe_info->recv_bufs_needed_lock);
1668 HIF_ERROR(
1669 "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
1670 __func__, pipe_info->pipe_num,
1671 atomic_read(&pipe_info->recv_bufs_needed),
1672 pipe_info->nbuf_alloc_err_count);
1673 atomic_inc(&pipe_info->recv_bufs_needed);
1674 return 1;
1675 }
1676
1677 /*
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301678 * qdf_nbuf_peek_header(nbuf, &data, &unused);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001679 * CE_data = dma_map_single(dev, data, buf_sz, );
1680 * DMA_FROM_DEVICE);
1681 */
1682 ret =
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301683 qdf_nbuf_map_single(scn->qdf_dev, nbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301684 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001685
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301686 if (unlikely(ret != QDF_STATUS_SUCCESS)) {
1687 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001688 pipe_info->nbuf_dma_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301689 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001690 HIF_ERROR(
1691 "%s buf alloc error [%d] needed %d, nbuf_dma_err_count = %u",
1692 __func__, pipe_info->pipe_num,
1693 atomic_read(&pipe_info->recv_bufs_needed),
1694 pipe_info->nbuf_dma_err_count);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301695 qdf_nbuf_free(nbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001696 atomic_inc(&pipe_info->recv_bufs_needed);
1697 return 1;
1698 }
1699
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301700 CE_data = qdf_nbuf_get_frag_paddr(nbuf, 0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001701
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301702 qdf_mem_dma_sync_single_for_device(scn->qdf_dev, CE_data,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001703 buf_sz, DMA_FROM_DEVICE);
1704 status = ce_recv_buf_enqueue(ce_hdl, (void *)nbuf, CE_data);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301705 QDF_ASSERT(status == QDF_STATUS_SUCCESS);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001706 if (status != EOK) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301707 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001708 pipe_info->nbuf_ce_enqueue_err_count++;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301709 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001710 HIF_ERROR(
1711 "%s buf alloc error [%d] needed %d, nbuf_alloc_err_count = %u",
1712 __func__, pipe_info->pipe_num,
1713 atomic_read(&pipe_info->recv_bufs_needed),
1714 pipe_info->nbuf_ce_enqueue_err_count);
Govind Singh4fcafd42016-08-08 12:37:31 +05301715 qdf_nbuf_unmap_single(scn->qdf_dev, nbuf,
1716 QDF_DMA_FROM_DEVICE);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001717 atomic_inc(&pipe_info->recv_bufs_needed);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301718 qdf_nbuf_free(nbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001719 return 1;
1720 }
1721
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301722 qdf_spin_lock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001723 bufs_posted++;
1724 }
1725 pipe_info->nbuf_alloc_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001726 (pipe_info->nbuf_alloc_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001727 pipe_info->nbuf_alloc_err_count - bufs_posted : 0;
1728 pipe_info->nbuf_dma_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001729 (pipe_info->nbuf_dma_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001730 pipe_info->nbuf_dma_err_count - bufs_posted : 0;
1731 pipe_info->nbuf_ce_enqueue_err_count =
Houston Hoffman56936832016-03-16 12:16:24 -07001732 (pipe_info->nbuf_ce_enqueue_err_count > bufs_posted) ?
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001733 pipe_info->nbuf_ce_enqueue_err_count - bufs_posted : 0;
1734
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301735 qdf_spin_unlock_bh(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001736
1737 return 0;
1738}
1739
1740/*
1741 * Try to post all desired receive buffers for all pipes.
1742 * Returns 0 if all desired buffers are posted,
1743 * non-zero if were were unable to completely
1744 * replenish receive buffers.
1745 */
Komal Seelam644263d2016-02-22 20:45:49 +05301746static int hif_post_recv_buffers(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001747{
Komal Seelam02cf2f82016-02-22 20:44:25 +05301748 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001749 int pipe_num, rv = 0;
Houston Hoffman85925072016-05-06 17:02:18 -07001750 struct CE_state *ce_state;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001751
1752 A_TARGET_ACCESS_LIKELY(scn);
1753 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1754 struct HIF_CE_pipe_info *pipe_info;
Houston Hoffman85925072016-05-06 17:02:18 -07001755 ce_state = scn->ce_id_to_state[pipe_num];
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001756 pipe_info = &hif_state->pipe_info[pipe_num];
Houston Hoffman85925072016-05-06 17:02:18 -07001757
1758 if (hif_is_nss_wifi_enabled(scn) &&
1759 ce_state && (ce_state->htt_rx_data)) {
1760 continue;
1761 }
1762
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001763 if (hif_post_recv_buffers_for_pipe(pipe_info)) {
1764 rv = 1;
1765 goto done;
1766 }
1767 }
1768
1769done:
1770 A_TARGET_ACCESS_UNLIKELY(scn);
1771
1772 return rv;
1773}
1774
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301775QDF_STATUS hif_start(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001776{
Komal Seelam644263d2016-02-22 20:45:49 +05301777 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301778 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001779
Manjunathappa Prakash4a9c3a82016-04-14 01:12:14 -07001780 hif_update_fastpath_recv_bufs_cnt(scn);
1781
Houston Hoffman9c12f7f2015-09-28 16:52:14 -07001782 hif_msg_callbacks_install(scn);
1783
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001784 if (hif_completion_thread_startup(hif_state))
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301785 return QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001786
Houston Hoffman271951f2016-11-12 15:24:27 -08001787 /* enable buffer cleanup */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001788 hif_state->started = true;
1789
Houston Hoffman271951f2016-11-12 15:24:27 -08001790 /* Post buffers once to start things off. */
1791 if (hif_post_recv_buffers(scn)) {
1792 /* cleanup is done in hif_ce_disable */
1793 HIF_ERROR("%s:failed to post buffers", __func__);
1794 return QDF_STATUS_E_FAILURE;
1795 }
1796
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301797 return QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001798}
1799
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001800static void hif_recv_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001801{
Komal Seelam644263d2016-02-22 20:45:49 +05301802 struct hif_softc *scn;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001803 struct CE_handle *ce_hdl;
1804 uint32_t buf_sz;
1805 struct HIF_CE_state *hif_state;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301806 qdf_nbuf_t netbuf;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301807 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001808 void *per_CE_context;
1809
1810 buf_sz = pipe_info->buf_sz;
1811 if (buf_sz == 0) {
1812 /* Unused Copy Engine */
1813 return;
1814 }
1815
1816 hif_state = pipe_info->HIF_CE_state;
1817 if (!hif_state->started) {
1818 return;
1819 }
1820
Komal Seelam02cf2f82016-02-22 20:44:25 +05301821 scn = HIF_GET_SOFTC(hif_state);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001822 ce_hdl = pipe_info->ce_hdl;
1823
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301824 if (scn->qdf_dev == NULL) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001825 return;
1826 }
1827 while (ce_revoke_recv_next
1828 (ce_hdl, &per_CE_context, (void **)&netbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301829 &CE_data) == QDF_STATUS_SUCCESS) {
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301830 qdf_nbuf_unmap_single(scn->qdf_dev, netbuf,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301831 QDF_DMA_FROM_DEVICE);
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301832 qdf_nbuf_free(netbuf);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001833 }
1834}
1835
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001836static void hif_send_buffer_cleanup_on_pipe(struct HIF_CE_pipe_info *pipe_info)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001837{
1838 struct CE_handle *ce_hdl;
1839 struct HIF_CE_state *hif_state;
Komal Seelam644263d2016-02-22 20:45:49 +05301840 struct hif_softc *scn;
Vishwajith Upendra70f8b6e2016-03-01 16:28:23 +05301841 qdf_nbuf_t netbuf;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001842 void *per_CE_context;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301843 qdf_dma_addr_t CE_data;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001844 unsigned int nbytes;
1845 unsigned int id;
1846 uint32_t buf_sz;
1847 uint32_t toeplitz_hash_result;
1848
1849 buf_sz = pipe_info->buf_sz;
1850 if (buf_sz == 0) {
1851 /* Unused Copy Engine */
1852 return;
1853 }
1854
1855 hif_state = pipe_info->HIF_CE_state;
1856 if (!hif_state->started) {
1857 return;
1858 }
1859
Komal Seelam02cf2f82016-02-22 20:44:25 +05301860 scn = HIF_GET_SOFTC(hif_state);
1861
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001862 ce_hdl = pipe_info->ce_hdl;
1863
1864 while (ce_cancel_send_next
1865 (ce_hdl, &per_CE_context,
1866 (void **)&netbuf, &CE_data, &nbytes,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301867 &id, &toeplitz_hash_result) == QDF_STATUS_SUCCESS) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001868 if (netbuf != CE_SENDLIST_ITEM_CTXT) {
1869 /*
1870 * Packets enqueued by htt_h2t_ver_req_msg() and
1871 * htt_h2t_rx_ring_cfg_msg_ll() have already been
1872 * freed in htt_htc_misc_pkt_pool_free() in
1873 * wlantl_close(), so do not free them here again
Houston Hoffman29573d92015-10-20 17:49:44 -07001874 * by checking whether it's the endpoint
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001875 * which they are queued in.
1876 */
Nirav Shahd7f91592016-04-21 14:18:43 +05301877 if (id == scn->htc_htt_tx_endpoint)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001878 return;
Nirav Shahd7f91592016-04-21 14:18:43 +05301879 /* Indicate the completion to higher
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001880 * layer to free the buffer */
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301881 if (pipe_info->pipe_callbacks.
Himanshu Agarwal8d0cdea2016-09-02 21:05:01 +05301882 txCompletionHandler)
Venkateswara Swamy Bandaru26f6f1e2016-10-03 19:35:57 +05301883 pipe_info->pipe_callbacks.
1884 txCompletionHandler(pipe_info->
1885 pipe_callbacks.Context,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001886 netbuf, id, toeplitz_hash_result);
1887 }
1888 }
1889}
1890
1891/*
1892 * Cleanup residual buffers for device shutdown:
1893 * buffers that were enqueued for receive
1894 * buffers that were to be sent
1895 * Note: Buffers that had completed but which were
1896 * not yet processed are on a completion queue. They
1897 * are handled when the completion thread shuts down.
1898 */
Jeff Johnson6950fdb2016-10-07 13:00:59 -07001899static void hif_buffer_cleanup(struct HIF_CE_state *hif_state)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001900{
1901 int pipe_num;
Komal Seelam644263d2016-02-22 20:45:49 +05301902 struct hif_softc *scn = HIF_GET_SOFTC(hif_state);
Houston Hoffman85925072016-05-06 17:02:18 -07001903 struct CE_state *ce_state;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001904
Komal Seelam02cf2f82016-02-22 20:44:25 +05301905 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001906 struct HIF_CE_pipe_info *pipe_info;
1907
Houston Hoffman85925072016-05-06 17:02:18 -07001908 ce_state = scn->ce_id_to_state[pipe_num];
1909 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
1910 ((ce_state->htt_tx_data) ||
1911 (ce_state->htt_rx_data))) {
1912 continue;
1913 }
1914
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001915 pipe_info = &hif_state->pipe_info[pipe_num];
1916 hif_recv_buffer_cleanup_on_pipe(pipe_info);
1917 hif_send_buffer_cleanup_on_pipe(pipe_info);
1918 }
1919}
1920
Komal Seelam5584a7c2016-02-24 19:22:48 +05301921void hif_flush_surprise_remove(struct hif_opaque_softc *hif_ctx)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001922{
Komal Seelam644263d2016-02-22 20:45:49 +05301923 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Komal Seelam02cf2f82016-02-22 20:44:25 +05301924 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Komal Seelam644263d2016-02-22 20:45:49 +05301925
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001926 hif_buffer_cleanup(hif_state);
1927}
1928
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05301929void hif_ce_stop(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001930{
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05301931 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001932 int pipe_num;
1933
Houston Hoffmana69581e2016-11-14 18:03:19 -08001934 /*
1935 * before cleaning up any memory, ensure irq &
1936 * bottom half contexts will not be re-entered
1937 */
1938 hif_nointrs(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001939 scn->hif_init_done = false;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001940
1941 /*
1942 * At this point, asynchronous threads are stopped,
1943 * The Target should not DMA nor interrupt, Host code may
1944 * not initiate anything more. So we just need to clean
1945 * up Host-side state.
1946 */
1947
1948 if (scn->athdiag_procfs_inited) {
1949 athdiag_procfs_remove();
1950 scn->athdiag_procfs_inited = false;
1951 }
1952
1953 hif_buffer_cleanup(hif_state);
1954
1955 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
1956 struct HIF_CE_pipe_info *pipe_info;
1957
1958 pipe_info = &hif_state->pipe_info[pipe_num];
1959 if (pipe_info->ce_hdl) {
1960 ce_fini(pipe_info->ce_hdl);
1961 pipe_info->ce_hdl = NULL;
1962 pipe_info->buf_sz = 0;
1963 }
1964 }
1965
1966 if (hif_state->sleep_timer_init) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05301967 qdf_timer_stop(&hif_state->sleep_timer);
1968 qdf_timer_free(&hif_state->sleep_timer);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001969 hif_state->sleep_timer_init = false;
1970 }
1971
1972 hif_state->started = false;
1973}
1974
Houston Hoffman854e67f2016-03-14 21:11:39 -07001975/**
1976 * hif_get_target_ce_config() - get copy engine configuration
1977 * @target_ce_config_ret: basic copy engine configuration
1978 * @target_ce_config_sz_ret: size of the basic configuration in bytes
1979 * @target_service_to_ce_map_ret: service mapping for the copy engines
1980 * @target_service_to_ce_map_sz_ret: size of the mapping in bytes
1981 * @target_shadow_reg_cfg_ret: shadow register configuration
1982 * @shadow_cfg_sz_ret: size of the shadow register configuration in bytes
1983 *
1984 * providing accessor to these values outside of this file.
1985 * currently these are stored in static pointers to const sections.
1986 * there are multiple configurations that are selected from at compile time.
1987 * Runtime selection would need to consider mode, target type and bus type.
1988 *
1989 * Return: return by parameter.
1990 */
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301991void hif_get_target_ce_config(struct hif_softc *scn,
1992 struct CE_pipe_config **target_ce_config_ret,
Houston Hoffman854e67f2016-03-14 21:11:39 -07001993 int *target_ce_config_sz_ret,
1994 struct service_to_pipe **target_service_to_ce_map_ret,
1995 int *target_service_to_ce_map_sz_ret,
1996 struct shadow_reg_cfg **target_shadow_reg_cfg_ret,
1997 int *shadow_cfg_sz_ret)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001998{
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05301999 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2000
2001 *target_ce_config_ret = hif_state->target_ce_config;
2002 *target_ce_config_sz_ret = hif_state->target_ce_config_sz;
Houston Hoffman854e67f2016-03-14 21:11:39 -07002003 *target_service_to_ce_map_ret = target_service_to_ce_map;
2004 *target_service_to_ce_map_sz_ret = target_service_to_ce_map_sz;
2005
2006 if (target_shadow_reg_cfg_ret)
2007 *target_shadow_reg_cfg_ret = target_shadow_reg_cfg;
2008
2009 if (shadow_cfg_sz_ret)
2010 *shadow_cfg_sz_ret = shadow_cfg_sz;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002011}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002012
Houston Hoffman5141f9d2017-01-05 10:49:17 -08002013
Houston Hoffman403c2df2017-01-27 12:51:15 -08002014static void hif_print_hal_shadow_register_cfg(struct pld_wlan_enable_cfg *cfg)
Houston Hoffman5141f9d2017-01-05 10:49:17 -08002015{
2016 int i;
2017 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
2018 "%s: num_config %d\n", __func__, cfg->num_shadow_reg_v2_cfg);
2019
2020 for (i = 0; i < cfg->num_shadow_reg_v2_cfg; i++) {
2021 QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO,
2022 "%s: i %d, val %x\n", __func__, i,
2023 cfg->shadow_reg_v2_cfg[i].addr);
2024 }
2025}
2026
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002027/**
2028 * hif_wlan_enable(): call the platform driver to enable wlan
Komal Seelambd7c51d2016-02-24 10:27:30 +05302029 * @scn: HIF Context
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002030 *
2031 * This function passes the con_mode and CE configuration to
2032 * platform driver to enable wlan.
2033 *
Houston Hoffman108da402016-03-14 21:11:24 -07002034 * Return: linux error code
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002035 */
Houston Hoffman108da402016-03-14 21:11:24 -07002036int hif_wlan_enable(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002037{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002038 struct pld_wlan_enable_cfg cfg;
2039 enum pld_driver_mode mode;
Komal Seelambd7c51d2016-02-24 10:27:30 +05302040 uint32_t con_mode = hif_get_conparam(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002041
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302042 hif_get_target_ce_config(scn,
2043 (struct CE_pipe_config **)&cfg.ce_tgt_cfg,
Houston Hoffman854e67f2016-03-14 21:11:39 -07002044 &cfg.num_ce_tgt_cfg,
2045 (struct service_to_pipe **)&cfg.ce_svc_cfg,
2046 &cfg.num_ce_svc_pipe_cfg,
2047 (struct shadow_reg_cfg **)&cfg.shadow_reg_cfg,
2048 &cfg.num_shadow_reg_cfg);
2049
2050 /* translate from structure size to array size */
2051 cfg.num_ce_tgt_cfg /= sizeof(struct CE_pipe_config);
2052 cfg.num_ce_svc_pipe_cfg /= sizeof(struct service_to_pipe);
2053 cfg.num_shadow_reg_cfg /= sizeof(struct shadow_reg_cfg);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002054
Houston Hoffman5141f9d2017-01-05 10:49:17 -08002055 hif_prepare_hal_shadow_register_cfg(scn, &cfg.shadow_reg_v2_cfg,
2056 &cfg.num_shadow_reg_v2_cfg);
2057
2058 hif_print_hal_shadow_register_cfg(&cfg);
2059
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302060 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002061 mode = PLD_FTM;
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002062 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002063 mode = PLD_EPPING;
Peng Xu7b962532015-10-02 17:17:03 -07002064 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002065 mode = PLD_MISSION;
Peng Xu7b962532015-10-02 17:17:03 -07002066
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002067 if (BYPASS_QMI)
2068 return 0;
2069 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07002070 return pld_wlan_enable(scn->qdf_dev->dev, &cfg,
2071 mode, QWLAN_VERSIONSTR);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002072}
2073
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002074#define CE_EPPING_USES_IRQ true
2075
Houston Hoffman108da402016-03-14 21:11:24 -07002076/**
2077 * hif_ce_prepare_config() - load the correct static tables.
2078 * @scn: hif context
2079 *
2080 * Epping uses different static attribute tables than mission mode.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002081 */
Houston Hoffman108da402016-03-14 21:11:24 -07002082void hif_ce_prepare_config(struct hif_softc *scn)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002083{
Komal Seelambd7c51d2016-02-24 10:27:30 +05302084 uint32_t mode = hif_get_conparam(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002085 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2086 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302087 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002088
Houston Hoffman10fedfc2017-01-23 15:23:09 -08002089 hif_state->ce_services = ce_services_attach(scn);
2090
Houston Hoffman710af5a2016-11-22 21:59:03 -08002091 scn->ce_count = HOST_CE_COUNT;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002092 /* if epping is enabled we need to use the epping configuration. */
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002093 if (QDF_IS_EPPING_ENABLED(mode)) {
2094 if (CE_EPPING_USES_IRQ)
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302095 hif_state->host_ce_config = host_ce_config_wlan_epping_irq;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002096 else
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302097 hif_state->host_ce_config = host_ce_config_wlan_epping_poll;
2098 hif_state->target_ce_config = target_ce_config_wlan_epping;
2099 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan_epping);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002100 target_service_to_ce_map =
2101 target_service_to_ce_map_wlan_epping;
2102 target_service_to_ce_map_sz =
2103 sizeof(target_service_to_ce_map_wlan_epping);
Vishwajith Upendra70efc752016-04-18 11:23:49 -07002104 target_shadow_reg_cfg = target_shadow_reg_cfg_epping;
2105 shadow_cfg_sz = sizeof(target_shadow_reg_cfg_epping);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002106 }
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002107
2108 switch (tgt_info->target_type) {
2109 default:
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302110 hif_state->host_ce_config = host_ce_config_wlan;
2111 hif_state->target_ce_config = target_ce_config_wlan;
2112 hif_state->target_ce_config_sz = sizeof(target_ce_config_wlan);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002113 break;
2114 case TARGET_TYPE_AR900B:
2115 case TARGET_TYPE_QCA9984:
2116 case TARGET_TYPE_IPQ4019:
2117 case TARGET_TYPE_QCA9888:
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05302118 if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_NO_PKTLOG_CFG)) {
2119 hif_state->host_ce_config =
2120 host_lowdesc_ce_cfg_wlan_ar900b_nopktlog;
2121 } else if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
2122 hif_state->host_ce_config =
2123 host_lowdesc_ce_cfg_wlan_ar900b;
2124 } else {
2125 hif_state->host_ce_config = host_ce_config_wlan_ar900b;
2126 }
2127
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302128 hif_state->target_ce_config = target_ce_config_wlan_ar900b;
2129 hif_state->target_ce_config_sz =
2130 sizeof(target_ce_config_wlan_ar900b);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002131
2132 target_service_to_ce_map = target_service_to_ce_map_ar900b;
2133 target_service_to_ce_map_sz =
2134 sizeof(target_service_to_ce_map_ar900b);
2135 break;
2136
2137 case TARGET_TYPE_AR9888:
2138 case TARGET_TYPE_AR9888V2:
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05302139 if (hif_is_attribute_set(scn, HIF_LOWDESC_CE_CFG)) {
2140 hif_state->host_ce_config = host_lowdesc_ce_cfg_wlan_ar9888;
2141 } else {
2142 hif_state->host_ce_config = host_ce_config_wlan_ar9888;
2143 }
2144
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302145 hif_state->target_ce_config = target_ce_config_wlan_ar9888;
2146 hif_state->target_ce_config_sz =
2147 sizeof(target_ce_config_wlan_ar9888);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002148
2149 target_service_to_ce_map = target_service_to_ce_map_ar900b;
2150 target_service_to_ce_map_sz =
2151 sizeof(target_service_to_ce_map_ar900b);
2152 break;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002153
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302154 case TARGET_TYPE_QCA8074:
Karunakar Dasinenif61cb072016-09-29 11:50:45 -07002155 if (scn->bus_type == QDF_BUS_TYPE_PCI) {
2156 hif_state->host_ce_config =
2157 host_ce_config_wlan_qca8074_pci;
2158 hif_state->target_ce_config =
2159 target_ce_config_wlan_qca8074_pci;
2160 hif_state->target_ce_config_sz =
2161 sizeof(target_ce_config_wlan_qca8074_pci);
2162 } else {
2163 hif_state->host_ce_config = host_ce_config_wlan_qca8074;
2164 hif_state->target_ce_config =
2165 target_ce_config_wlan_qca8074;
2166 hif_state->target_ce_config_sz =
2167 sizeof(target_ce_config_wlan_qca8074);
2168 }
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302169 break;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002170 case TARGET_TYPE_QCA6290:
2171 hif_state->host_ce_config = host_ce_config_wlan_qca6290;
2172 hif_state->target_ce_config = target_ce_config_wlan_qca6290;
2173 hif_state->target_ce_config_sz =
2174 sizeof(target_ce_config_wlan_qca6290);
Houston Hoffman710af5a2016-11-22 21:59:03 -08002175 scn->ce_count = QCA_6290_CE_COUNT;
Houston Hoffman31b25ec2016-09-19 13:12:30 -07002176 break;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002177 }
Houston Hoffman108da402016-03-14 21:11:24 -07002178}
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002179
Houston Hoffman108da402016-03-14 21:11:24 -07002180/**
2181 * hif_ce_open() - do ce specific allocations
2182 * @hif_sc: pointer to hif context
2183 *
2184 * return: 0 for success or QDF_STATUS_E_NOMEM
2185 */
2186QDF_STATUS hif_ce_open(struct hif_softc *hif_sc)
2187{
2188 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002189
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302190 qdf_spinlock_create(&hif_state->irq_reg_lock);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302191 qdf_spinlock_create(&hif_state->keep_awake_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002192 return QDF_STATUS_SUCCESS;
2193}
2194
2195/**
2196 * hif_ce_close() - do ce specific free
2197 * @hif_sc: pointer to hif context
2198 */
2199void hif_ce_close(struct hif_softc *hif_sc)
2200{
Venkateswara Swamy Bandaru9fd9af02016-09-20 20:27:31 +05302201 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2202
2203 qdf_spinlock_destroy(&hif_state->irq_reg_lock);
Houston Hoffman108da402016-03-14 21:11:24 -07002204}
2205
2206/**
2207 * hif_unconfig_ce() - ensure resources from hif_config_ce are freed
2208 * @hif_sc: hif context
2209 *
2210 * uses state variables to support cleaning up when hif_config_ce fails.
2211 */
2212void hif_unconfig_ce(struct hif_softc *hif_sc)
2213{
2214 int pipe_num;
2215 struct HIF_CE_pipe_info *pipe_info;
2216 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(hif_sc);
2217
2218 for (pipe_num = 0; pipe_num < hif_sc->ce_count; pipe_num++) {
2219 pipe_info = &hif_state->pipe_info[pipe_num];
2220 if (pipe_info->ce_hdl) {
2221 ce_unregister_irq(hif_state, (1 << pipe_num));
Houston Hoffman108da402016-03-14 21:11:24 -07002222 ce_fini(pipe_info->ce_hdl);
2223 pipe_info->ce_hdl = NULL;
2224 pipe_info->buf_sz = 0;
2225 }
2226 }
Houston Hoffman108da402016-03-14 21:11:24 -07002227 if (hif_sc->athdiag_procfs_inited) {
2228 athdiag_procfs_remove();
2229 hif_sc->athdiag_procfs_inited = false;
2230 }
2231}
2232
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002233#ifdef CONFIG_BYPASS_QMI
2234#define FW_SHARED_MEM (2 * 1024 * 1024)
2235
2236/**
2237 * hif_post_static_buf_to_target() - post static buffer to WLAN FW
2238 * @scn: pointer to HIF structure
2239 *
2240 * WLAN FW needs 2MB memory from DDR when QMI is disabled.
2241 *
2242 * Return: void
2243 */
2244static void hif_post_static_buf_to_target(struct hif_softc *scn)
2245{
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002246 void *target_va;
2247 phys_addr_t target_pa;
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002248
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002249 target_va = qdf_mem_alloc_consistent(scn->qdf_dev, scn->qdf_dev->dev,
2250 FW_SHARED_MEM, &target_pa);
2251 if (NULL == target_va) {
2252 HIF_TRACE("Memory allocation failed could not post target buf");
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002253 return;
2254 }
Hardik Kantilal Patelc5dc5f22016-04-21 14:11:33 -07002255 hif_write32_mb(scn->mem + BYPASS_QMI_TEMP_REGISTER, target_pa);
2256 HIF_TRACE("target va %pK target pa %pa", target_va, &target_pa);
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002257}
2258#else
2259static inline void hif_post_static_buf_to_target(struct hif_softc *scn)
2260{
2261 return;
2262}
2263#endif
2264
Dustin Brown6bdbda52016-09-27 15:52:30 -07002265#ifdef WLAN_SUSPEND_RESUME_TEST
2266static void hif_fake_apps_init_ctx(struct hif_softc *scn)
2267{
2268 INIT_WORK(&scn->fake_apps_ctx.resume_work,
2269 hif_fake_apps_resume_work);
2270}
2271#else
2272static inline void hif_fake_apps_init_ctx(struct hif_softc *scn) {}
2273#endif
2274
Houston Hoffman108da402016-03-14 21:11:24 -07002275/**
2276 * hif_config_ce() - configure copy engines
2277 * @scn: hif context
2278 *
2279 * Prepares fw, copy engine hardware and host sw according
2280 * to the attributes selected by hif_ce_prepare_config.
2281 *
2282 * also calls athdiag_procfs_init
2283 *
2284 * return: 0 for success nonzero for failure.
2285 */
2286int hif_config_ce(struct hif_softc *scn)
2287{
2288 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
2289 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
2290 struct HIF_CE_pipe_info *pipe_info;
2291 int pipe_num;
Houston Hoffman85925072016-05-06 17:02:18 -07002292 struct CE_state *ce_state;
Houston Hoffman108da402016-03-14 21:11:24 -07002293#ifdef ADRASTEA_SHADOW_REGISTERS
2294 int i;
2295#endif
2296 QDF_STATUS rv = QDF_STATUS_SUCCESS;
2297
2298 scn->notice_send = true;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002299
Yuanyuan Liua7a282f2016-04-15 12:55:04 -07002300 hif_post_static_buf_to_target(scn);
2301
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002302 hif_state->fw_indicator_address = FW_INDICATOR_ADDRESS;
Houston Hoffman108da402016-03-14 21:11:24 -07002303
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002304 hif_config_rri_on_ddr(scn);
2305
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002306 for (pipe_num = 0; pipe_num < scn->ce_count; pipe_num++) {
2307 struct CE_attr *attr;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002308 pipe_info = &hif_state->pipe_info[pipe_num];
2309 pipe_info->pipe_num = pipe_num;
2310 pipe_info->HIF_CE_state = hif_state;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302311 attr = &hif_state->host_ce_config[pipe_num];
Karunakar Dasinenif61cb072016-09-29 11:50:45 -07002312
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002313 pipe_info->ce_hdl = ce_init(scn, pipe_num, attr);
Houston Hoffman85925072016-05-06 17:02:18 -07002314 ce_state = scn->ce_id_to_state[pipe_num];
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302315 QDF_ASSERT(pipe_info->ce_hdl != NULL);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002316 if (pipe_info->ce_hdl == NULL) {
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302317 rv = QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002318 A_TARGET_ACCESS_UNLIKELY(scn);
2319 goto err;
2320 }
2321
2322 if (pipe_num == DIAG_CE_ID) {
2323 /* Reserve the ultimate CE for
2324 * Diagnostic Window support */
Houston Hoffmanc1d9a412016-03-30 21:07:57 -07002325 hif_state->ce_diag = pipe_info->ce_hdl;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002326 continue;
2327 }
2328
Houston Hoffman85925072016-05-06 17:02:18 -07002329 if (hif_is_nss_wifi_enabled(scn) && ce_state &&
2330 (ce_state->htt_rx_data))
2331 continue;
2332
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302333 pipe_info->buf_sz = (qdf_size_t) (attr->src_sz_max);
2334 qdf_spinlock_create(&pipe_info->recv_bufs_needed_lock);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002335 if (attr->dest_nentries > 0) {
2336 atomic_set(&pipe_info->recv_bufs_needed,
2337 init_buffer_count(attr->dest_nentries - 1));
Kiran Venkatappaf41ef2e2016-09-05 10:59:58 +05302338 /*SRNG based CE has one entry less */
2339 if (ce_srng_based(scn))
2340 atomic_dec(&pipe_info->recv_bufs_needed);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002341 } else {
2342 atomic_set(&pipe_info->recv_bufs_needed, 0);
2343 }
2344 ce_tasklet_init(hif_state, (1 << pipe_num));
2345 ce_register_irq(hif_state, (1 << pipe_num));
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002346 }
2347
2348 if (athdiag_procfs_init(scn) != 0) {
2349 A_TARGET_ACCESS_UNLIKELY(scn);
2350 goto err;
2351 }
2352 scn->athdiag_procfs_inited = true;
2353
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002354 HIF_INFO_MED("%s: ce_init done", __func__);
2355
Houston Hoffman108da402016-03-14 21:11:24 -07002356 init_tasklet_workers(hif_hdl);
Dustin Brown6bdbda52016-09-27 15:52:30 -07002357 hif_fake_apps_init_ctx(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002358
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002359 HIF_TRACE("%s: X, ret = %d", __func__, rv);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002360
2361#ifdef ADRASTEA_SHADOW_REGISTERS
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002362 HIF_INFO("%s, Using Shadow Registers instead of CE Registers", __func__);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002363 for (i = 0; i < NUM_SHADOW_REGISTERS; i++) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002364 HIF_INFO("%s Shadow Register%d is mapped to address %x",
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002365 __func__, i,
2366 (A_TARGET_READ(scn, (SHADOW_ADDRESS(i))) << 2));
2367 }
2368#endif
2369
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302370 return rv != QDF_STATUS_SUCCESS;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002371
2372err:
2373 /* Failure, so clean up */
Houston Hoffman108da402016-03-14 21:11:24 -07002374 hif_unconfig_ce(scn);
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002375 HIF_TRACE("%s: X, ret = %d", __func__, rv);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302376 return QDF_STATUS_SUCCESS != QDF_STATUS_E_FAILURE;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002377}
2378
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002379#ifdef WLAN_FEATURE_FASTPATH
2380/**
2381 * hif_ce_fastpath_cb_register() - Register callback for fastpath msg handler
2382 * @handler: Callback funtcion
2383 * @context: handle for callback function
2384 *
2385 * Return: QDF_STATUS_SUCCESS on success or QDF_STATUS_E_FAILURE
2386 */
Houston Hoffman127467f2016-04-26 22:37:14 -07002387int hif_ce_fastpath_cb_register(struct hif_opaque_softc *hif_ctx,
2388 fastpath_msg_handler handler,
2389 void *context)
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002390{
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002391 struct CE_state *ce_state;
Houston Hoffman127467f2016-04-26 22:37:14 -07002392 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002393 int i;
2394
Himanshu Agarwal2a924592016-06-30 18:04:14 +05302395 if (!scn) {
2396 HIF_ERROR("%s: scn is NULL", __func__);
2397 QDF_ASSERT(0);
2398 return QDF_STATUS_E_FAILURE;
2399 }
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002400
2401 if (!scn->fastpath_mode_on) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002402 HIF_WARN("%s: Fastpath mode disabled", __func__);
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002403 return QDF_STATUS_E_FAILURE;
2404 }
2405
Houston Hoffmand6f946c2016-04-06 15:16:00 -07002406 for (i = 0; i < scn->ce_count; i++) {
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002407 ce_state = scn->ce_id_to_state[i];
2408 if (ce_state->htt_rx_data) {
2409 ce_state->fastpath_handler = handler;
2410 ce_state->context = context;
2411 }
2412 }
2413
2414 return QDF_STATUS_SUCCESS;
2415}
Manjunathappa Prakash7399f142016-04-13 23:38:16 -07002416#endif
2417
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002418#ifdef IPA_OFFLOAD
Leo Changd85f78d2015-11-13 10:55:34 -08002419/**
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302420 * hif_ce_ipa_get_ce_resource() - get uc resource on hif
Leo Changd85f78d2015-11-13 10:55:34 -08002421 * @scn: bus context
2422 * @ce_sr_base_paddr: copyengine source ring base physical address
2423 * @ce_sr_ring_size: copyengine source ring size
2424 * @ce_reg_paddr: copyengine register physical address
2425 *
2426 * IPA micro controller data path offload feature enabled,
2427 * HIF should release copy engine related resource information to IPA UC
2428 * IPA UC will access hardware resource with released information
2429 *
2430 * Return: None
2431 */
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05302432void hif_ce_ipa_get_ce_resource(struct hif_softc *scn,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302433 qdf_dma_addr_t *ce_sr_base_paddr,
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002434 uint32_t *ce_sr_ring_size,
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302435 qdf_dma_addr_t *ce_reg_paddr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002436{
Komal Seelam02cf2f82016-02-22 20:44:25 +05302437 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002438 struct HIF_CE_pipe_info *pipe_info =
2439 &(hif_state->pipe_info[HIF_PCI_IPA_UC_ASSIGNED_CE]);
2440 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
2441
2442 ce_ipa_get_resource(ce_hdl, ce_sr_base_paddr, ce_sr_ring_size,
2443 ce_reg_paddr);
2444 return;
2445}
2446#endif /* IPA_OFFLOAD */
2447
2448
2449#ifdef ADRASTEA_SHADOW_REGISTERS
2450
2451/*
2452 Current shadow register config
2453
2454 -----------------------------------------------------------
2455 Shadow Register | CE | src/dst write index
2456 -----------------------------------------------------------
2457 0 | 0 | src
2458 1 No Config - Doesn't point to anything
2459 2 No Config - Doesn't point to anything
2460 3 | 3 | src
2461 4 | 4 | src
2462 5 | 5 | src
2463 6 No Config - Doesn't point to anything
2464 7 | 7 | src
2465 8 No Config - Doesn't point to anything
2466 9 No Config - Doesn't point to anything
2467 10 No Config - Doesn't point to anything
2468 11 No Config - Doesn't point to anything
2469 -----------------------------------------------------------
2470 12 No Config - Doesn't point to anything
2471 13 | 1 | dst
2472 14 | 2 | dst
2473 15 No Config - Doesn't point to anything
2474 16 No Config - Doesn't point to anything
2475 17 No Config - Doesn't point to anything
2476 18 No Config - Doesn't point to anything
2477 19 | 7 | dst
2478 20 | 8 | dst
2479 21 No Config - Doesn't point to anything
2480 22 No Config - Doesn't point to anything
2481 23 No Config - Doesn't point to anything
2482 -----------------------------------------------------------
2483
2484
2485 ToDo - Move shadow register config to following in the future
2486 This helps free up a block of shadow registers towards the end.
2487 Can be used for other purposes
2488
2489 -----------------------------------------------------------
2490 Shadow Register | CE | src/dst write index
2491 -----------------------------------------------------------
2492 0 | 0 | src
2493 1 | 3 | src
2494 2 | 4 | src
2495 3 | 5 | src
2496 4 | 7 | src
2497 -----------------------------------------------------------
2498 5 | 1 | dst
2499 6 | 2 | dst
2500 7 | 7 | dst
2501 8 | 8 | dst
2502 -----------------------------------------------------------
2503 9 No Config - Doesn't point to anything
2504 12 No Config - Doesn't point to anything
2505 13 No Config - Doesn't point to anything
2506 14 No Config - Doesn't point to anything
2507 15 No Config - Doesn't point to anything
2508 16 No Config - Doesn't point to anything
2509 17 No Config - Doesn't point to anything
2510 18 No Config - Doesn't point to anything
2511 19 No Config - Doesn't point to anything
2512 20 No Config - Doesn't point to anything
2513 21 No Config - Doesn't point to anything
2514 22 No Config - Doesn't point to anything
2515 23 No Config - Doesn't point to anything
2516 -----------------------------------------------------------
2517*/
2518
Komal Seelam644263d2016-02-22 20:45:49 +05302519u32 shadow_sr_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002520{
2521 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002522 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002523
Houston Hoffmane6330442016-02-26 12:19:11 -08002524 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002525 case 0:
2526 addr = SHADOW_VALUE0;
2527 break;
2528 case 3:
2529 addr = SHADOW_VALUE3;
2530 break;
2531 case 4:
2532 addr = SHADOW_VALUE4;
2533 break;
2534 case 5:
2535 addr = SHADOW_VALUE5;
2536 break;
2537 case 7:
2538 addr = SHADOW_VALUE7;
2539 break;
2540 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002541 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302542 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002543 }
2544 return addr;
2545
2546}
2547
Komal Seelam644263d2016-02-22 20:45:49 +05302548u32 shadow_dst_wr_ind_addr(struct hif_softc *scn, u32 ctrl_addr)
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002549{
2550 u32 addr = 0;
Houston Hoffmane6330442016-02-26 12:19:11 -08002551 u32 ce = COPY_ENGINE_ID(ctrl_addr);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002552
Houston Hoffmane6330442016-02-26 12:19:11 -08002553 switch (ce) {
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002554 case 1:
2555 addr = SHADOW_VALUE13;
2556 break;
2557 case 2:
2558 addr = SHADOW_VALUE14;
2559 break;
Vishwajith Upendra70efc752016-04-18 11:23:49 -07002560 case 5:
2561 addr = SHADOW_VALUE17;
2562 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002563 case 7:
2564 addr = SHADOW_VALUE19;
2565 break;
2566 case 8:
2567 addr = SHADOW_VALUE20;
2568 break;
Houston Hoffmane6330442016-02-26 12:19:11 -08002569 case 9:
2570 addr = SHADOW_VALUE21;
2571 break;
2572 case 10:
2573 addr = SHADOW_VALUE22;
2574 break;
Nirav Shah75cc5c82016-05-25 10:52:38 +05302575 case 11:
2576 addr = SHADOW_VALUE23;
2577 break;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002578 default:
Houston Hoffmane6330442016-02-26 12:19:11 -08002579 HIF_ERROR("invalid CE ctrl_addr (CE=%d)", ce);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302580 QDF_ASSERT(0);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002581 }
2582
2583 return addr;
2584
2585}
2586#endif
2587
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002588#if defined(FEATURE_LRO)
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002589void *hif_ce_get_lro_ctx(struct hif_opaque_softc *hif_hdl, int ctx_id)
2590{
2591 struct CE_state *ce_state;
2592 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
2593
2594 QDF_ASSERT(scn != NULL);
2595
2596 ce_state = scn->ce_id_to_state[ctx_id];
2597
2598 return ce_state->lro_data;
2599}
2600
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002601/**
2602 * ce_lro_flush_cb_register() - register the LRO flush
2603 * callback
2604 * @scn: HIF context
2605 * @handler: callback function
2606 * @data: opaque data pointer to be passed back
2607 *
2608 * Store the LRO flush callback provided
2609 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002610 * Return: Number of instances the callback is registered for
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002611 */
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002612int ce_lro_flush_cb_register(struct hif_opaque_softc *hif_hdl,
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002613 void (handler)(void *),
2614 void *(lro_init_handler)(void))
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002615{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002616 int rc = 0;
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002617 int i;
2618 struct CE_state *ce_state;
Komal Seelam5584a7c2016-02-24 19:22:48 +05302619 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002620 void *data = NULL;
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002621
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302622 QDF_ASSERT(scn != NULL);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002623
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002624 if (scn != NULL) {
2625 for (i = 0; i < scn->ce_count; i++) {
2626 ce_state = scn->ce_id_to_state[i];
2627 if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002628 data = lro_init_handler();
2629 if (data == NULL) {
2630 HIF_ERROR("%s: Failed to init LRO for CE %d",
2631 __func__, i);
2632 continue;
2633 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002634 ce_state->lro_flush_cb = handler;
2635 ce_state->lro_data = data;
2636 rc++;
2637 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002638 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002639 } else {
2640 HIF_ERROR("%s: hif_state NULL!", __func__);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002641 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002642 return rc;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08002643}
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002644
2645/**
2646 * ce_lro_flush_cb_deregister() - deregister the LRO flush
2647 * callback
2648 * @scn: HIF context
2649 *
2650 * Remove the LRO flush callback
2651 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002652 * Return: Number of instances the callback is de-registered
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002653 */
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002654int ce_lro_flush_cb_deregister(struct hif_opaque_softc *hif_hdl,
2655 void (lro_deinit_cb)(void *))
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002656{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002657 int rc = 0;
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002658 int i;
2659 struct CE_state *ce_state;
Komal Seelam5584a7c2016-02-24 19:22:48 +05302660 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002661
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302662 QDF_ASSERT(scn != NULL);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002663 if (scn != NULL) {
2664 for (i = 0; i < scn->ce_count; i++) {
2665 ce_state = scn->ce_id_to_state[i];
2666 if ((ce_state != NULL) && (ce_state->htt_rx_data)) {
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002667 qdf_spin_lock_bh(
2668 &ce_state->lro_unloading_lock);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002669 ce_state->lro_flush_cb = NULL;
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002670 lro_deinit_cb(ce_state->lro_data);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002671 ce_state->lro_data = NULL;
Manjunathappa Prakash2146da32016-10-13 14:47:47 -07002672 qdf_spin_unlock_bh(
2673 &ce_state->lro_unloading_lock);
2674 qdf_spinlock_destroy(
2675 &ce_state->lro_unloading_lock);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002676 rc++;
2677 }
Houston Hoffmanc7d54292016-04-13 18:55:37 -07002678 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002679 } else {
2680 HIF_ERROR("%s: hif_state NULL!", __func__);
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002681 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002682 return rc;
Dhanashri Atre65b674f2015-10-30 15:12:03 -07002683}
2684#endif
Sanjay Devnanic319c822015-11-06 16:44:28 -08002685
2686/**
2687 * hif_map_service_to_pipe() - returns the ce ids pertaining to
2688 * this service
Komal Seelam644263d2016-02-22 20:45:49 +05302689 * @scn: hif_softc pointer.
Sanjay Devnanic319c822015-11-06 16:44:28 -08002690 * @svc_id: Service ID for which the mapping is needed.
2691 * @ul_pipe: address of the container in which ul pipe is returned.
2692 * @dl_pipe: address of the container in which dl pipe is returned.
2693 * @ul_is_polled: address of the container in which a bool
2694 * indicating if the UL CE for this service
2695 * is polled is returned.
2696 * @dl_is_polled: address of the container in which a bool
2697 * indicating if the DL CE for this service
2698 * is polled is returned.
2699 *
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002700 * Return: Indicates whether the service has been found in the table.
2701 * Upon return, ul_is_polled is updated only if ul_pipe is updated.
2702 * There will be warning logs if either leg has not been updated
2703 * because it missed the entry in the table (but this is not an err).
Sanjay Devnanic319c822015-11-06 16:44:28 -08002704 */
Komal Seelam5584a7c2016-02-24 19:22:48 +05302705int hif_map_service_to_pipe(struct hif_opaque_softc *hif_hdl, uint16_t svc_id,
Sanjay Devnanic319c822015-11-06 16:44:28 -08002706 uint8_t *ul_pipe, uint8_t *dl_pipe, int *ul_is_polled,
2707 int *dl_is_polled)
2708{
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002709 int status = QDF_STATUS_E_INVAL;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002710 unsigned int i;
2711 struct service_to_pipe element;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002712 struct service_to_pipe *tgt_svc_map_to_use;
2713 size_t sz_tgt_svc_map_to_use;
Komal Seelambd7c51d2016-02-24 10:27:30 +05302714 struct hif_softc *scn = HIF_GET_SOFTC(hif_hdl);
2715 uint32_t mode = hif_get_conparam(scn);
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002716 struct hif_target_info *tgt_info = hif_get_target_info_handle(hif_hdl);
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002717 bool dl_updated = false;
2718 bool ul_updated = false;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302719 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanic319c822015-11-06 16:44:28 -08002720
Houston Hoffman75ef5a52016-04-14 17:15:49 -07002721 if (QDF_IS_EPPING_ENABLED(mode)) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002722 tgt_svc_map_to_use = target_service_to_ce_map_wlan_epping;
2723 sz_tgt_svc_map_to_use =
2724 sizeof(target_service_to_ce_map_wlan_epping);
2725 } else {
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002726 switch (tgt_info->target_type) {
2727 default:
2728 tgt_svc_map_to_use = target_service_to_ce_map_wlan;
2729 sz_tgt_svc_map_to_use =
2730 sizeof(target_service_to_ce_map_wlan);
2731 break;
2732 case TARGET_TYPE_AR900B:
2733 case TARGET_TYPE_QCA9984:
2734 case TARGET_TYPE_IPQ4019:
2735 case TARGET_TYPE_QCA9888:
2736 case TARGET_TYPE_AR9888:
2737 case TARGET_TYPE_AR9888V2:
2738 tgt_svc_map_to_use = target_service_to_ce_map_ar900b;
2739 sz_tgt_svc_map_to_use =
2740 sizeof(target_service_to_ce_map_ar900b);
2741 break;
Houston Hoffman88c896f2016-12-14 09:56:35 -08002742 case TARGET_TYPE_QCA6290:
2743 tgt_svc_map_to_use = target_service_to_ce_map_qca6290;
2744 sz_tgt_svc_map_to_use =
2745 sizeof(target_service_to_ce_map_qca6290);
2746 break;
Houston Hoffmanfb698ef2016-05-05 19:50:44 -07002747 }
Sanjay Devnanic319c822015-11-06 16:44:28 -08002748 }
2749
2750 *dl_is_polled = 0; /* polling for received messages not supported */
2751
2752 for (i = 0; i < (sz_tgt_svc_map_to_use/sizeof(element)); i++) {
2753
2754 memcpy(&element, &tgt_svc_map_to_use[i], sizeof(element));
2755 if (element.service_id == svc_id) {
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002756 if (element.pipedir == PIPEDIR_OUT) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002757 *ul_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002758 *ul_is_polled =
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302759 (hif_state->host_ce_config[*ul_pipe].flags &
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002760 CE_ATTR_DISABLE_INTR) != 0;
2761 ul_updated = true;
2762 } else if (element.pipedir == PIPEDIR_IN) {
Sanjay Devnanic319c822015-11-06 16:44:28 -08002763 *dl_pipe = element.pipenum;
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002764 dl_updated = true;
2765 }
2766 status = QDF_STATUS_SUCCESS;
Sanjay Devnanic319c822015-11-06 16:44:28 -08002767 }
2768 }
Manjunathappa Prakash32afe372016-04-29 11:12:41 -07002769 if (ul_updated == false)
2770 HIF_WARN("%s: ul pipe is NOT updated for service %d",
2771 __func__, svc_id);
2772 if (dl_updated == false)
2773 HIF_WARN("%s: dl pipe is NOT updated for service %d",
2774 __func__, svc_id);
Sanjay Devnanic319c822015-11-06 16:44:28 -08002775
2776 return status;
2777}
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002778
2779#ifdef SHADOW_REG_DEBUG
Komal Seelam644263d2016-02-22 20:45:49 +05302780inline uint32_t DEBUG_CE_SRC_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002781 uint32_t CE_ctrl_addr)
2782{
2783 uint32_t read_from_hw, srri_from_ddr = 0;
2784
2785 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_SRRI_ADDRESS);
2786
2787 srri_from_ddr = SRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
2788
2789 if (read_from_hw != srri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002790 HIF_ERROR("%s: error: read from ddr = %d actual read from register = %d, CE_MISC_INT_STATUS_GET = 0x%x",
2791 __func__, srri_from_ddr, read_from_hw,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002792 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302793 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002794 }
2795 return srri_from_ddr;
2796}
2797
2798
Komal Seelam644263d2016-02-22 20:45:49 +05302799inline uint32_t DEBUG_CE_DEST_RING_READ_IDX_GET(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002800 uint32_t CE_ctrl_addr)
2801{
2802 uint32_t read_from_hw, drri_from_ddr = 0;
2803
2804 read_from_hw = A_TARGET_READ(scn, CE_ctrl_addr + CURRENT_DRRI_ADDRESS);
2805
2806 drri_from_ddr = DRRI_FROM_DDR_ADDR(VADDR_FOR_CE(scn, CE_ctrl_addr));
2807
2808 if (read_from_hw != drri_from_ddr) {
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002809 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 -08002810 drri_from_ddr, read_from_hw,
2811 CE_MISC_INT_STATUS_GET(scn, CE_ctrl_addr));
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302812 QDF_ASSERT(0);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002813 }
2814 return drri_from_ddr;
2815}
2816
2817#endif
2818
Houston Hoffman3d0cda82015-12-03 13:25:05 -08002819#ifdef ADRASTEA_RRI_ON_DDR
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002820/**
2821 * hif_get_src_ring_read_index(): Called to get the SRRI
2822 *
Komal Seelam644263d2016-02-22 20:45:49 +05302823 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002824 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
2825 *
2826 * This function returns the SRRI to the caller. For CEs that
2827 * dont have interrupts enabled, we look at the DDR based SRRI
2828 *
2829 * Return: SRRI
2830 */
Komal Seelam644263d2016-02-22 20:45:49 +05302831inline unsigned int hif_get_src_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002832 uint32_t CE_ctrl_addr)
2833{
2834 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302835 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002836
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302837 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002838 if (attr.flags & CE_ATTR_DISABLE_INTR)
2839 return CE_SRC_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
2840 else
2841 return A_TARGET_READ(scn,
2842 (CE_ctrl_addr) + CURRENT_SRRI_ADDRESS);
2843}
2844
2845/**
2846 * hif_get_dst_ring_read_index(): Called to get the DRRI
2847 *
Komal Seelam644263d2016-02-22 20:45:49 +05302848 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002849 * @CE_ctrl_addr: base address of the CE whose RRI is to be read
2850 *
2851 * This function returns the DRRI to the caller. For CEs that
2852 * dont have interrupts enabled, we look at the DDR based DRRI
2853 *
2854 * Return: DRRI
2855 */
Komal Seelam644263d2016-02-22 20:45:49 +05302856inline unsigned int hif_get_dst_ring_read_index(struct hif_softc *scn,
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002857 uint32_t CE_ctrl_addr)
2858{
2859 struct CE_attr attr;
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302860 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002861
Venkateswara Swamy Bandaru13164aa2016-09-20 20:24:54 +05302862 attr = hif_state->host_ce_config[COPY_ENGINE_ID(CE_ctrl_addr)];
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002863
2864 if (attr.flags & CE_ATTR_DISABLE_INTR)
2865 return CE_DEST_RING_READ_IDX_GET_FROM_DDR(scn, CE_ctrl_addr);
2866 else
2867 return A_TARGET_READ(scn,
2868 (CE_ctrl_addr) + CURRENT_DRRI_ADDRESS);
2869}
2870
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002871/**
2872 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
2873 *
Komal Seelam644263d2016-02-22 20:45:49 +05302874 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002875 *
2876 * This function allocates non cached memory on ddr and sends
2877 * the physical address of this memory to the CE hardware. The
2878 * hardware updates the RRI on this particular location.
2879 *
2880 * Return: None
2881 */
Komal Seelam644263d2016-02-22 20:45:49 +05302882static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002883{
2884 unsigned int i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302885 qdf_dma_addr_t paddr_rri_on_ddr;
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002886 uint32_t high_paddr, low_paddr;
2887 scn->vaddr_rri_on_ddr =
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302888 (uint32_t *)qdf_mem_alloc_consistent(scn->qdf_dev,
2889 scn->qdf_dev->dev, (CE_COUNT*sizeof(uint32_t)),
2890 &paddr_rri_on_ddr);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002891
2892 low_paddr = BITS0_TO_31(paddr_rri_on_ddr);
2893 high_paddr = BITS32_TO_35(paddr_rri_on_ddr);
2894
Houston Hoffmanc50572b2016-06-08 19:49:46 -07002895 HIF_INFO("%s using srri and drri from DDR", __func__);
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002896
2897 WRITE_CE_DDR_ADDRESS_FOR_RRI_LOW(scn, low_paddr);
2898 WRITE_CE_DDR_ADDRESS_FOR_RRI_HIGH(scn, high_paddr);
2899
2900 for (i = 0; i < CE_COUNT; i++)
2901 CE_IDX_UPD_EN_SET(scn, CE_BASE_ADDRESS(i));
2902
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302903 qdf_mem_zero(scn->vaddr_rri_on_ddr, CE_COUNT*sizeof(uint32_t));
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002904
2905 return;
2906}
2907#else
2908
2909/**
2910 * hif_config_rri_on_ddr(): Configure the RRI on DDR mechanism
2911 *
Komal Seelam644263d2016-02-22 20:45:49 +05302912 * @scn: hif_softc pointer
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002913 *
2914 * This is a dummy implementation for platforms that don't
2915 * support this functionality.
2916 *
2917 * Return: None
2918 */
Komal Seelam644263d2016-02-22 20:45:49 +05302919static inline void hif_config_rri_on_ddr(struct hif_softc *scn)
Sanjay Devnanib925d7e2015-11-12 14:43:58 -08002920{
2921 return;
2922}
2923#endif
Govind Singh2443fb32016-01-13 17:44:48 +05302924
2925/**
2926 * hif_dump_ce_registers() - dump ce registers
Komal Seelam5584a7c2016-02-24 19:22:48 +05302927 * @scn: hif_opaque_softc pointer.
Govind Singh2443fb32016-01-13 17:44:48 +05302928 *
2929 * Output the copy engine registers
2930 *
2931 * Return: 0 for success or error code
2932 */
Komal Seelam644263d2016-02-22 20:45:49 +05302933int hif_dump_ce_registers(struct hif_softc *scn)
Govind Singh2443fb32016-01-13 17:44:48 +05302934{
Komal Seelam5584a7c2016-02-24 19:22:48 +05302935 struct hif_opaque_softc *hif_hdl = GET_HIF_OPAQUE_HDL(scn);
Govind Singh2443fb32016-01-13 17:44:48 +05302936 uint32_t ce_reg_address = CE0_BASE_ADDRESS;
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002937 uint32_t ce_reg_values[CE_USEFUL_SIZE >> 2];
Govind Singh2443fb32016-01-13 17:44:48 +05302938 uint32_t ce_reg_word_size = CE_USEFUL_SIZE >> 2;
2939 uint16_t i;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302940 QDF_STATUS status;
Govind Singh2443fb32016-01-13 17:44:48 +05302941
Houston Hoffmand6f946c2016-04-06 15:16:00 -07002942 for (i = 0; i < scn->ce_count; i++, ce_reg_address += CE_OFFSET) {
2943 if (scn->ce_id_to_state[i] == NULL) {
2944 HIF_DBG("CE%d not used.", i);
2945 continue;
2946 }
2947
Komal Seelam644263d2016-02-22 20:45:49 +05302948 status = hif_diag_read_mem(hif_hdl, ce_reg_address,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002949 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05302950 ce_reg_word_size * sizeof(uint32_t));
2951
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302952 if (status != QDF_STATUS_SUCCESS) {
Govind Singh2443fb32016-01-13 17:44:48 +05302953 HIF_ERROR("Dumping CE register failed!");
2954 return -EACCES;
2955 }
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05302956 HIF_ERROR("CE%d=>\n", i);
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +05302957 qdf_trace_hex_dump(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_DEBUG,
Houston Hoffman6296c3e2016-07-12 18:43:32 -07002958 (uint8_t *) &ce_reg_values[0],
Govind Singh2443fb32016-01-13 17:44:48 +05302959 ce_reg_word_size * sizeof(uint32_t));
Venkateswara Swamy Bandaru772377c2016-10-03 14:17:28 +05302960 qdf_print("ADDR:[0x%08X], SR_WR_INDEX:%d\n", (ce_reg_address
2961 + SR_WR_INDEX_ADDRESS),
2962 ce_reg_values[SR_WR_INDEX_ADDRESS/4]);
2963 qdf_print("ADDR:[0x%08X], CURRENT_SRRI:%d\n", (ce_reg_address
2964 + CURRENT_SRRI_ADDRESS),
2965 ce_reg_values[CURRENT_SRRI_ADDRESS/4]);
2966 qdf_print("ADDR:[0x%08X], DST_WR_INDEX:%d\n", (ce_reg_address
2967 + DST_WR_INDEX_ADDRESS),
2968 ce_reg_values[DST_WR_INDEX_ADDRESS/4]);
2969 qdf_print("ADDR:[0x%08X], CURRENT_DRRI:%d\n", (ce_reg_address
2970 + CURRENT_DRRI_ADDRESS),
2971 ce_reg_values[CURRENT_DRRI_ADDRESS/4]);
2972 qdf_print("---\n");
Govind Singh2443fb32016-01-13 17:44:48 +05302973 }
Govind Singh2443fb32016-01-13 17:44:48 +05302974 return 0;
2975}
Houston Hoffman85925072016-05-06 17:02:18 -07002976#ifdef QCA_NSS_WIFI_OFFLOAD_SUPPORT
2977struct hif_pipe_addl_info *hif_get_addl_pipe_info(struct hif_opaque_softc *osc,
2978 struct hif_pipe_addl_info *hif_info, uint32_t pipe)
2979{
2980 struct hif_softc *scn = HIF_GET_SOFTC(osc);
2981 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn);
2982 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(osc);
2983 struct HIF_CE_pipe_info *pipe_info = &(hif_state->pipe_info[pipe]);
2984 struct CE_handle *ce_hdl = pipe_info->ce_hdl;
2985 struct CE_state *ce_state = (struct CE_state *)ce_hdl;
2986 struct CE_ring_state *src_ring = ce_state->src_ring;
2987 struct CE_ring_state *dest_ring = ce_state->dest_ring;
2988
2989 if (src_ring) {
2990 hif_info->ul_pipe.nentries = src_ring->nentries;
2991 hif_info->ul_pipe.nentries_mask = src_ring->nentries_mask;
2992 hif_info->ul_pipe.sw_index = src_ring->sw_index;
2993 hif_info->ul_pipe.write_index = src_ring->write_index;
2994 hif_info->ul_pipe.hw_index = src_ring->hw_index;
2995 hif_info->ul_pipe.base_addr_CE_space =
2996 src_ring->base_addr_CE_space;
2997 hif_info->ul_pipe.base_addr_owner_space =
2998 src_ring->base_addr_owner_space;
2999 }
3000
3001
3002 if (dest_ring) {
3003 hif_info->dl_pipe.nentries = dest_ring->nentries;
3004 hif_info->dl_pipe.nentries_mask = dest_ring->nentries_mask;
3005 hif_info->dl_pipe.sw_index = dest_ring->sw_index;
3006 hif_info->dl_pipe.write_index = dest_ring->write_index;
3007 hif_info->dl_pipe.hw_index = dest_ring->hw_index;
3008 hif_info->dl_pipe.base_addr_CE_space =
3009 dest_ring->base_addr_CE_space;
3010 hif_info->dl_pipe.base_addr_owner_space =
3011 dest_ring->base_addr_owner_space;
3012 }
3013
3014 hif_info->pci_mem = pci_resource_start(sc->pdev, 0);
3015 hif_info->ctrl_addr = ce_state->ctrl_addr;
3016
3017 return hif_info;
3018}
3019
3020uint32_t hif_set_nss_wifiol_mode(struct hif_opaque_softc *osc, uint32_t mode)
3021{
3022 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3023
3024 scn->nss_wifi_ol_mode = mode;
3025 return 0;
3026}
3027
3028#endif
3029
Venkateswara Swamy Bandaru5432c1b2016-10-12 19:00:40 +05303030void hif_set_attribute(struct hif_opaque_softc *osc, uint8_t hif_attrib)
3031{
3032 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3033 scn->hif_attribute = hif_attrib;
3034}
3035
Houston Hoffman85925072016-05-06 17:02:18 -07003036void hif_disable_interrupt(struct hif_opaque_softc *osc, uint32_t pipe_num)
3037{
3038 struct hif_softc *scn = HIF_GET_SOFTC(osc);
3039 struct CE_state *CE_state = scn->ce_id_to_state[pipe_num];
3040 uint32_t ctrl_addr = CE_state->ctrl_addr;
3041
3042 Q_TARGET_ACCESS_BEGIN(scn);
3043 CE_COPY_COMPLETE_INTR_DISABLE(scn, ctrl_addr);
3044 Q_TARGET_ACCESS_END(scn);
3045}
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303046
3047/**
3048 * hif_fw_event_handler() - hif fw event handler
3049 * @hif_state: pointer to hif ce state structure
3050 *
3051 * Process fw events and raise HTC callback to process fw events.
3052 *
3053 * Return: none
3054 */
3055static inline void hif_fw_event_handler(struct HIF_CE_state *hif_state)
3056{
3057 struct hif_msg_callbacks *msg_callbacks =
3058 &hif_state->msg_callbacks_current;
3059
3060 if (!msg_callbacks->fwEventHandler)
3061 return;
3062
3063 msg_callbacks->fwEventHandler(msg_callbacks->Context,
3064 QDF_STATUS_E_FAILURE);
3065}
3066
3067#ifndef QCA_WIFI_3_0
3068/**
3069 * hif_fw_interrupt_handler() - FW interrupt handler
3070 * @irq: irq number
3071 * @arg: the user pointer
3072 *
3073 * Called from the PCI interrupt handler when a
3074 * firmware-generated interrupt to the Host.
3075 *
3076 * Return: status of handled irq
3077 */
3078irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
3079{
3080 struct hif_softc *scn = arg;
3081 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn);
3082 uint32_t fw_indicator_address, fw_indicator;
3083
3084 if (Q_TARGET_ACCESS_BEGIN(scn) < 0)
3085 return ATH_ISR_NOSCHED;
3086
3087 fw_indicator_address = hif_state->fw_indicator_address;
3088 /* For sudden unplug this will return ~0 */
3089 fw_indicator = A_TARGET_READ(scn, fw_indicator_address);
3090
3091 if ((fw_indicator != ~0) && (fw_indicator & FW_IND_EVENT_PENDING)) {
3092 /* ACK: clear Target-side pending event */
3093 A_TARGET_WRITE(scn, fw_indicator_address,
3094 fw_indicator & ~FW_IND_EVENT_PENDING);
3095 if (Q_TARGET_ACCESS_END(scn) < 0)
3096 return ATH_ISR_SCHED;
3097
3098 if (hif_state->started) {
3099 hif_fw_event_handler(hif_state);
3100 } else {
3101 /*
3102 * Probable Target failure before we're prepared
3103 * to handle it. Generally unexpected.
3104 */
3105 AR_DEBUG_PRINTF(ATH_DEBUG_ERR,
3106 ("%s: Early firmware event indicated\n",
3107 __func__));
3108 }
3109 } else {
3110 if (Q_TARGET_ACCESS_END(scn) < 0)
3111 return ATH_ISR_SCHED;
3112 }
3113
3114 return ATH_ISR_SCHED;
3115}
3116#else
3117irqreturn_t hif_fw_interrupt_handler(int irq, void *arg)
3118{
3119 return ATH_ISR_SCHED;
3120}
3121#endif /* #ifdef QCA_WIFI_3_0 */
3122
3123
3124/**
3125 * hif_wlan_disable(): call the platform driver to disable wlan
3126 * @scn: HIF Context
3127 *
3128 * This function passes the con_mode to platform driver to disable
3129 * wlan.
3130 *
3131 * Return: void
3132 */
3133void hif_wlan_disable(struct hif_softc *scn)
3134{
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003135 enum pld_driver_mode mode;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303136 uint32_t con_mode = hif_get_conparam(scn);
3137
3138 if (QDF_GLOBAL_FTM_MODE == con_mode)
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003139 mode = PLD_FTM;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303140 else if (QDF_IS_EPPING_ENABLED(con_mode))
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003141 mode = PLD_EPPING;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303142 else
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003143 mode = PLD_MISSION;
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303144
Yuanyuan Liufd594c22016-04-25 13:59:19 -07003145 pld_wlan_disable(scn->qdf_dev->dev, mode);
Poddar, Siddarthe41943f2016-04-27 15:33:48 +05303146}
Dustin Brown6bdbda52016-09-27 15:52:30 -07003147