blob: 3a54833fc48b7272dac17c31971509f8fc4a6e8d [file] [log] [blame]
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301/*
2 * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
3 *
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +053019/* Include Files */
20#include "wlan_ipa_core.h"
21#include "wlan_ipa_main.h"
22#include <ol_txrx.h>
23#include "cdp_txrx_ipa.h"
24#include "wal_rx_desc.h"
25
26static struct wlan_ipa_priv *gp_ipa;
27
28static struct wlan_ipa_iface_2_client {
29 qdf_ipa_client_type_t cons_client;
30 qdf_ipa_client_type_t prod_client;
31} wlan_ipa_iface_2_client[WLAN_IPA_MAX_IFACE] = {
32 {
33 QDF_IPA_CLIENT_WLAN2_CONS, QDF_IPA_CLIENT_WLAN1_PROD
34 }, {
35 QDF_IPA_CLIENT_WLAN3_CONS, QDF_IPA_CLIENT_WLAN1_PROD
36 }, {
37 QDF_IPA_CLIENT_WLAN4_CONS, QDF_IPA_CLIENT_WLAN1_PROD
38 }
39};
40
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053041/* Local Function Prototypes */
42static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
43 unsigned long data);
44static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
45 unsigned long data);
46
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +053047/**
48 * wlan_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
49 * @ipa_cfg: IPA config
50 *
51 * Return: true if STA mode IPA uC offload is enabled, false otherwise
52 */
53static inline bool wlan_ipa_uc_sta_is_enabled(struct wlan_ipa_config *ipa_cfg)
54{
55 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_UC_STA_ENABLE_MASK);
56}
57
58/**
59 * wlan_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
60 * @ipa_cfg: IPA config
61 *
62 * Return: true if pre-filter is enabled, otherwise false
63 */
64static inline
65bool wlan_ipa_is_pre_filter_enabled(struct wlan_ipa_config *ipa_cfg)
66{
67 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg,
68 WLAN_IPA_PRE_FILTER_ENABLE_MASK);
69}
70
71/**
72 * wlan_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
73 * @ipa_cfg: IPA config
74 *
75 * Return: true if IPv6 is enabled, otherwise false
76 */
77static inline bool wlan_ipa_is_ipv6_enabled(struct wlan_ipa_config *ipa_cfg)
78{
79 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_IPV6_ENABLE_MASK);
80}
81
82/**
83 * wlan_ipa_msg_free_fn() - Free an IPA message
84 * @buff: pointer to the IPA message
85 * @len: length of the IPA message
86 * @type: type of IPA message
87 *
88 * Return: None
89 */
90static void wlan_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
91{
92 ipa_debug("msg type:%d, len:%d", type, len);
93 qdf_mem_free(buff);
94}
95
96/**
97 * wlan_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
98 * @priv_ctxt: IPA context
99 *
100 * Will be called by IPA context.
101 * It's atomic context, then should be scheduled to kworker thread
102 *
103 * Return: None
104 */
105static void wlan_ipa_uc_loaded_uc_cb(void *priv_ctxt)
106{
107 struct wlan_ipa_priv *ipa_ctx;
108 struct op_msg_type *msg;
109 struct uc_op_work_struct *uc_op_work;
110
111 if (!priv_ctxt) {
112 ipa_err("Invalid IPA context");
113 return;
114 }
115
116 ipa_ctx = priv_ctxt;
Sravan Kumar Kairam7eb6e4c2018-04-26 15:35:47 +0530117 ipa_ctx->uc_loaded = true;
118
119 uc_op_work = &ipa_ctx->uc_op_work[WLAN_IPA_UC_OPCODE_UC_READY];
120 if (!list_empty(&uc_op_work->work.work.entry)) {
121 /* uc_op_work is not initialized yet */
122 return;
123 }
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530124
125 msg = qdf_mem_malloc(sizeof(*msg));
126 if (!msg) {
127 ipa_err("op_msg allocation fails");
128 return;
129 }
130
131 msg->op_code = WLAN_IPA_UC_OPCODE_UC_READY;
132
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530133 /* When the same uC OPCODE is already pended, just return */
134 if (uc_op_work->msg)
135 goto done;
136
137 uc_op_work->msg = msg;
138 qdf_sched_work(0, &uc_op_work->work);
Sravan Kumar Kairam7eb6e4c2018-04-26 15:35:47 +0530139
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530140 /* work handler will free the msg buffer */
141 return;
142
143done:
144 qdf_mem_free(msg);
145}
146
147/**
148 * wlan_ipa_uc_send_wdi_control_msg() - Set WDI control message
149 * @ctrl: WDI control value
150 *
151 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
152 *
153 * Return: QDF_STATUS
154 */
155static QDF_STATUS wlan_ipa_uc_send_wdi_control_msg(bool ctrl)
156{
jiad629b2172018-05-11 15:34:22 +0800157 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530158 qdf_ipa_msg_meta_t meta;
159 qdf_ipa_wlan_msg_t *ipa_msg;
160 int ret = 0;
161
162 /* WDI enable message to IPA */
163 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*ipa_msg);
164 ipa_msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
165 if (!ipa_msg) {
166 ipa_err("msg allocation failed");
167 return QDF_STATUS_E_NOMEM;
168 }
169
jiad629b2172018-05-11 15:34:22 +0800170 if (ctrl) {
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530171 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_ENABLE);
jiad629b2172018-05-11 15:34:22 +0800172 ipa_ctx->stats.event[QDF_WDI_ENABLE]++;
173 } else {
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530174 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_DISABLE);
jiad629b2172018-05-11 15:34:22 +0800175 ipa_ctx->stats.event[QDF_WDI_DISABLE]++;
176 }
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530177
178 ipa_debug("ipa_send_msg(Evt:%d)", QDF_IPA_MSG_META_MSG_TYPE(&meta));
179 ret = qdf_ipa_send_msg(&meta, ipa_msg, wlan_ipa_msg_free_fn);
180 if (ret) {
181 ipa_err("ipa_send_msg(Evt:%d)-fail=%d",
182 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
183 qdf_mem_free(ipa_msg);
184 return QDF_STATUS_E_FAILURE;
185 }
186
187 return QDF_STATUS_SUCCESS;
188}
189
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +0530190struct wlan_ipa_priv *wlan_ipa_get_obj_context(void)
191{
192 return gp_ipa;
193}
194
Yun Parke74e6092018-04-27 11:36:34 -0700195/**
196 * wlan_ipa_send_pkt_to_tl() - Send an IPA packet to TL
197 * @iface_context: interface-specific IPA context
198 * @ipa_tx_desc: packet data descriptor
199 *
200 * Return: None
201 */
202static void wlan_ipa_send_pkt_to_tl(
203 struct wlan_ipa_iface_context *iface_context,
204 qdf_ipa_rx_data_t *ipa_tx_desc)
205{
206 struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx;
207 qdf_nbuf_t skb;
208 struct wlan_ipa_tx_desc *tx_desc;
209
210 qdf_spin_lock_bh(&iface_context->interface_lock);
211 /*
212 * During CAC period, data packets shouldn't be sent over the air so
213 * drop all the packets here
214 */
215 if (iface_context->device_mode == QDF_SAP_MODE ||
216 iface_context->device_mode == QDF_P2P_GO_MODE) {
217 if (ipa_ctx->dfs_cac_block_tx) {
218 ipa_free_skb(ipa_tx_desc);
219 qdf_spin_unlock_bh(&iface_context->interface_lock);
220 iface_context->stats.num_tx_cac_drop++;
221 wlan_ipa_wdi_rm_try_release(ipa_ctx);
222 return;
223 }
224 }
225 qdf_spin_unlock_bh(&iface_context->interface_lock);
226
227 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc);
228
229 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
230
231 /* Store IPA Tx buffer ownership into SKB CB */
232 qdf_nbuf_ipa_owned_set(skb);
233 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
234 qdf_nbuf_mapped_paddr_set(skb,
235 QDF_IPA_RX_DATA_DMA_ADDR(ipa_tx_desc)
236 + WLAN_IPA_WLAN_FRAG_HEADER
237 + WLAN_IPA_WLAN_IPA_HEADER);
238 QDF_IPA_RX_DATA_SKB_LEN(ipa_tx_desc) -=
239 WLAN_IPA_WLAN_FRAG_HEADER + WLAN_IPA_WLAN_IPA_HEADER;
240 } else
241 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
242
243 qdf_spin_lock_bh(&ipa_ctx->q_lock);
244 /* get free Tx desc and assign ipa_tx_desc pointer */
245 if (qdf_list_remove_front(&ipa_ctx->tx_desc_list,
246 (qdf_list_node_t **)&tx_desc) ==
247 QDF_STATUS_SUCCESS) {
248 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
249 ipa_ctx->stats.num_tx_desc_q_cnt++;
250 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
251 /* Store Tx Desc index into SKB CB */
252 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
253 } else {
254 ipa_ctx->stats.num_tx_desc_error++;
255 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
256 qdf_ipa_free_skb(ipa_tx_desc);
257 wlan_ipa_wdi_rm_try_release(ipa_ctx);
258 return;
259 }
260
261 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
262 (struct cdp_vdev *)iface_context->tl_context,
263 QDF_IPA_RX_DATA_SKB(ipa_tx_desc));
264 if (skb) {
265 qdf_nbuf_free(skb);
266 iface_context->stats.num_tx_err++;
267 return;
268 }
269
270 atomic_inc(&ipa_ctx->tx_ref_cnt);
271
272 iface_context->stats.num_tx++;
273}
274
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530275#ifdef CONFIG_IPA_WDI_UNIFIED_API
276
277/*
278 * TODO: Get WDI version through FW capabilities
279 */
280#ifdef CONFIG_LITHIUM
281static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
282{
283 ipa_ctx->wdi_version = IPA_WDI_3;
284}
285#elif defined(QCA_WIFI_3_0)
286static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
287{
288 ipa_ctx->wdi_version = IPA_WDI_2;
289}
290#else
291static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
292{
293 ipa_ctx->wdi_version = IPA_WDI_1;
294}
295#endif
296
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530297static inline bool wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx,
298 qdf_device_t osdev)
299{
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +0530300 return ipa_ctx->is_smmu_enabled && qdf_mem_smmu_s1_enabled(osdev);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530301}
302
303static inline QDF_STATUS wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx,
304 qdf_device_t osdev)
305{
306 qdf_ipa_sys_connect_params_t sys_in[WLAN_IPA_MAX_IFACE];
307 int i;
308
309 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++)
310 qdf_mem_copy(&sys_in[i],
311 &ipa_ctx->sys_pipe[i].ipa_sys_params,
312 sizeof(qdf_ipa_sys_connect_params_t));
313
314 return cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev,
315 wlan_ipa_i2w_cb, wlan_ipa_w2i_cb,
316 wlan_ipa_wdi_meter_notifier_cb,
317 ipa_ctx->config->desc_size,
318 ipa_ctx, wlan_ipa_is_rm_enabled(ipa_ctx->config),
319 &ipa_ctx->tx_pipe_handle,
320 &ipa_ctx->rx_pipe_handle,
321 wlan_ipa_wdi_is_smmu_enabled(ipa_ctx, osdev),
322 sys_in);
323}
324
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +0530325#ifdef FEATURE_METERING
326/**
327 * wlan_ipa_wdi_init_metering() - IPA WDI metering init
328 * @ipa_ctx: IPA context
329 * @in: IPA WDI in param
330 *
331 * Return: QDF_STATUS
332 */
333static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt,
334 qdf_ipa_wdi_init_in_params_t *in)
335{
336 QDF_IPA_WDI_INIT_IN_PARAMS_WDI_NOTIFY(in) =
337 wlan_ipa_wdi_meter_notifier_cb;
338}
339#else
340static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt,
341 qdf_ipa_wdi_init_in_params_t *in)
342{
343}
344#endif
345
346/**
347 * wlan_ipa_wdi_init() - IPA WDI init
348 * @ipa_ctx: IPA context
349 *
350 * Return: QDF_STATUS
351 */
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530352static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx)
353{
354 qdf_ipa_wdi_init_in_params_t in;
355 qdf_ipa_wdi_init_out_params_t out;
356 int ret;
357
358 ipa_ctx->uc_loaded = false;
359
360 QDF_IPA_WDI_INIT_IN_PARAMS_WDI_VERSION(&in) = ipa_ctx->wdi_version;
361 QDF_IPA_WDI_INIT_IN_PARAMS_NOTIFY(&in) = wlan_ipa_uc_loaded_uc_cb;
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +0530362 QDF_IPA_WDI_INIT_IN_PARAMS_PRIV(&in) = ipa_ctx;
363 wlan_ipa_wdi_init_metering(ipa_ctx, &in);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530364
365 ret = qdf_ipa_wdi_init(&in, &out);
366 if (ret) {
367 ipa_err("ipa_wdi_init failed with ret=%d", ret);
368 return QDF_STATUS_E_FAILURE;
369 }
370
371 if (QDF_IPA_WDI_INIT_OUT_PARAMS_IS_UC_READY(&out)) {
372 ipa_info("IPA uC READY");
373 ipa_ctx->uc_loaded = true;
374 ipa_ctx->is_smmu_enabled =
375 QDF_IPA_WDI_INIT_OUT_PARAMS_IS_SMMU_ENABLED(&out);
376 ipa_info("is_smmu_enabled=%d", ipa_ctx->is_smmu_enabled);
377 } else {
378 return QDF_STATUS_E_BUSY;
379 }
380
381 return QDF_STATUS_SUCCESS;
382}
383
384static inline int wlan_ipa_wdi_cleanup(void)
385{
386 int ret;
387
388 ret = qdf_ipa_wdi_cleanup();
389 if (ret)
390 ipa_info("ipa_wdi_cleanup failed ret=%d", ret);
391 return ret;
392}
393
394static inline int wlan_ipa_wdi_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
395 struct ipa_sys_connect_params *sys,
396 uint32_t *handle)
397{
398 return 0;
399}
400
401static inline int wlan_ipa_wdi_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
402 uint32_t handle)
403{
404 return 0;
405}
406
Yun Parke74e6092018-04-27 11:36:34 -0700407/**
408 * wlan_ipa_pm_flush() - flush queued packets
409 * @work: pointer to the scheduled work
410 *
411 * Called during PM resume to send packets to TL which were queued
412 * while host was in the process of suspending.
413 *
414 * Return: None
415 */
416static void wlan_ipa_pm_flush(void *data)
417{
418 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data;
419 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL;
420 qdf_nbuf_t skb;
421 uint32_t dequeued = 0;
422
423 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
424 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) !=
425 NULL)) {
426 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
427
428 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
429 dequeued++;
430
jiadab8cea02018-05-24 09:16:14 +0800431 if (pm_tx_cb->exception) {
432 if (ipa_ctx->softap_xmit &&
433 pm_tx_cb->iface_context->dev) {
434 ipa_ctx->softap_xmit(skb,
435 pm_tx_cb->iface_context->dev);
436 ipa_ctx->stats.num_tx_fwd_ok++;
437 } else {
438 dev_kfree_skb_any(skb);
439 }
440 } else {
441 wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
442 pm_tx_cb->ipa_tx_desc);
443 }
Yun Parke74e6092018-04-27 11:36:34 -0700444
445 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
446 }
447 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
448
449 ipa_ctx->stats.num_tx_dequeued += dequeued;
450 if (dequeued > ipa_ctx->stats.num_max_pm_queue)
451 ipa_ctx->stats.num_max_pm_queue = dequeued;
452}
453
jiadae9959f2018-05-08 11:19:07 +0800454int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
455{
456 if (!num_buf) {
457 ipa_info("No buffers to map/unmap");
458 return 0;
459 }
460
461 if (map)
462 return qdf_ipa_wdi_create_smmu_mapping(num_buf, buf_arr);
463 else
464 return qdf_ipa_wdi_release_smmu_mapping(num_buf, buf_arr);
465}
466
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530467#else /* CONFIG_IPA_WDI_UNIFIED_API */
468
469static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
470{
471}
472
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +0530473static inline int wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx,
474 qdf_device_t osdev)
475{
476 return qdf_mem_smmu_s1_enabled(osdev);
477}
478
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530479static inline QDF_STATUS wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx,
480 qdf_device_t osdev)
481{
482 return cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev,
483 wlan_ipa_i2w_cb, wlan_ipa_w2i_cb,
484 wlan_ipa_wdi_meter_notifier_cb,
485 ipa_ctx->config->desc_size,
486 ipa_ctx, wlan_ipa_is_rm_enabled(ipa_ctx->config),
487 &ipa_ctx->tx_pipe_handle,
488 &ipa_ctx->rx_pipe_handle);
489}
490
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530491static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx)
492{
493 struct ipa_wdi_uc_ready_params uc_ready_param;
494
495 ipa_ctx->uc_loaded = false;
496 uc_ready_param.priv = (void *)ipa_ctx;
497 uc_ready_param.notify = wlan_ipa_uc_loaded_uc_cb;
498 if (qdf_ipa_uc_reg_rdyCB(&uc_ready_param)) {
499 ipa_info("UC Ready CB register fail");
500 return QDF_STATUS_E_FAILURE;
501 }
502
503 if (true == uc_ready_param.is_uC_ready) {
504 ipa_info("UC Ready");
505 ipa_ctx->uc_loaded = true;
506 } else {
507 return QDF_STATUS_E_BUSY;
508 }
509
510 return QDF_STATUS_SUCCESS;
511}
512
513static inline int wlan_ipa_wdi_cleanup(void)
514{
515 int ret;
516
517 ret = qdf_ipa_uc_dereg_rdyCB();
518 if (ret)
519 ipa_info("UC Ready CB deregister fail");
520 return ret;
521}
522
523static inline int wlan_ipa_wdi_setup_sys_pipe(
524 struct wlan_ipa_priv *ipa_ctx,
525 struct ipa_sys_connect_params *sys, uint32_t *handle)
526{
527 return qdf_ipa_setup_sys_pipe(sys, handle);
528}
529
530static inline int wlan_ipa_wdi_teardown_sys_pipe(
531 struct wlan_ipa_priv *ipa_ctx,
532 uint32_t handle)
533{
534 return qdf_ipa_teardown_sys_pipe(handle);
535}
536
Yun Parke74e6092018-04-27 11:36:34 -0700537/**
538 * wlan_ipa_pm_flush() - flush queued packets
539 * @work: pointer to the scheduled work
540 *
541 * Called during PM resume to send packets to TL which were queued
542 * while host was in the process of suspending.
543 *
544 * Return: None
545 */
546static void wlan_ipa_pm_flush(void *data)
547{
548 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data;
549 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL;
550 qdf_nbuf_t skb;
551 uint32_t dequeued = 0;
552
553 qdf_wake_lock_acquire(&ipa_ctx->wake_lock,
554 WIFI_POWER_EVENT_WAKELOCK_IPA);
555 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
556 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) !=
557 NULL)) {
558 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
559
560 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
561 dequeued++;
562
jiadab8cea02018-05-24 09:16:14 +0800563 if (pm_tx_cb->exception) {
564 if (ipa_ctx->softap_xmit &&
565 pm_tx_cb->iface_context->dev) {
566 ipa_ctx->softap_xmit(skb,
567 pm_tx_cb->iface_context->dev);
568 ipa_ctx->stats.num_tx_fwd_ok++;
569 } else {
570 dev_kfree_skb_any(skb);
571 }
572 } else {
573 wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
574 pm_tx_cb->ipa_tx_desc);
575 }
Yun Parke74e6092018-04-27 11:36:34 -0700576
577 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
578 }
579 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
580 qdf_wake_lock_release(&ipa_ctx->wake_lock,
581 WIFI_POWER_EVENT_WAKELOCK_IPA);
582
583 ipa_ctx->stats.num_tx_dequeued += dequeued;
584 if (dequeued > ipa_ctx->stats.num_max_pm_queue)
585 ipa_ctx->stats.num_max_pm_queue = dequeued;
586}
587
jiadae9959f2018-05-08 11:19:07 +0800588int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
589{
590 if (!num_buf) {
591 ipa_info("No buffers to map/unmap");
592 return 0;
593 }
594
595 if (map)
596 return qdf_ipa_create_wdi_mapping(num_buf, buf_arr);
597 else
598 return qdf_ipa_release_wdi_mapping(num_buf, buf_arr);
599}
600
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530601#endif /* CONFIG_IPA_WDI_UNIFIED_API */
602
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530603/**
604 * wlan_ipa_send_skb_to_network() - Send skb to kernel
605 * @skb: network buffer
606 * @iface_ctx: IPA interface context
607 *
608 * Called when a network buffer is received which should not be routed
609 * to the IPA module.
610 *
611 * Return: None
612 */
613static void
614wlan_ipa_send_skb_to_network(qdf_nbuf_t skb,
615 struct wlan_ipa_iface_context *iface_ctx)
616{
617 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
618
619 if (!iface_ctx->dev) {
620 WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid interface");
621 ipa_ctx->ipa_rx_internal_drop_count++;
622 qdf_nbuf_free(skb);
623 return;
624 }
625
626 skb->destructor = wlan_ipa_uc_rt_debug_destructor;
627
628 if (ipa_ctx->send_to_nw)
629 ipa_ctx->send_to_nw(skb, iface_ctx->dev);
630
631 ipa_ctx->ipa_rx_net_send_count++;
632}
633
634/**
635 * wlan_ipa_forward() - handle packet forwarding to wlan tx
636 * @ipa_ctx: pointer to ipa ipa context
637 * @iface_ctx: interface context
638 * @skb: data pointer
639 *
640 * if exception packet has set forward bit, copied new packet should be
641 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
642 * put into pm queue and tx procedure will be differed
643 *
644 * Return: None
645 */
646static void wlan_ipa_forward(struct wlan_ipa_priv *ipa_ctx,
647 struct wlan_ipa_iface_context *iface_ctx,
648 qdf_nbuf_t skb)
649{
650 struct wlan_ipa_pm_tx_cb *pm_tx_cb;
651
652 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
653
654 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
655 qdf_nbuf_ipa_owned_set(skb);
656
657 /* WLAN subsystem is in suspend, put in queue */
658 if (ipa_ctx->suspended) {
659 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
660 WLAN_IPA_LOG(QDF_TRACE_LEVEL_INFO,
661 "Tx in suspend, put in queue");
662 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
663 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
664 pm_tx_cb->exception = true;
665 pm_tx_cb->iface_context = iface_ctx;
666 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
667 qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb);
668 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
669 ipa_ctx->stats.num_tx_queued++;
670 } else {
671 /* Resume, put packet into WLAN TX */
672 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
673
674 if (ipa_ctx->softap_xmit) {
675 if (ipa_ctx->softap_xmit(skb, iface_ctx->dev)) {
676 WLAN_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
677 "packet Tx fail");
678 ipa_ctx->stats.num_tx_fwd_err++;
679 } else {
680 ipa_ctx->stats.num_tx_fwd_ok++;
681 }
682 } else {
jiadab8cea02018-05-24 09:16:14 +0800683 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530684 }
685 }
686}
687
688/**
689 * wlan_ipa_intrabss_forward() - Forward intra bss packets.
690 * @ipa_ctx: pointer to IPA IPA struct
691 * @iface_ctx: ipa interface context
692 * @desc: Firmware descriptor
693 * @skb: Data buffer
694 *
695 * Return:
696 * WLAN_IPA_FORWARD_PKT_NONE
697 * WLAN_IPA_FORWARD_PKT_DISCARD
698 * WLAN_IPA_FORWARD_PKT_LOCAL_STACK
699 *
700 */
701
702static enum wlan_ipa_forward_type wlan_ipa_intrabss_forward(
703 struct wlan_ipa_priv *ipa_ctx,
704 struct wlan_ipa_iface_context *iface_ctx,
705 uint8_t desc,
706 qdf_nbuf_t skb)
707{
708 int ret = WLAN_IPA_FORWARD_PKT_NONE;
709 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
710 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
711
712 if ((desc & FW_RX_DESC_FORWARD_M)) {
713 if (!ol_txrx_fwd_desc_thresh_check(
714 (struct ol_txrx_vdev_t *)cdp_get_vdev_from_vdev_id(soc,
715 (struct cdp_pdev *)pdev,
716 iface_ctx->session_id))) {
717 /* Drop the packet*/
718 ipa_ctx->stats.num_tx_fwd_err++;
jiadab8cea02018-05-24 09:16:14 +0800719 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530720 ret = WLAN_IPA_FORWARD_PKT_DISCARD;
721 return ret;
722 }
723 WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
724 "Forward packet to Tx (fw_desc=%d)", desc);
725 ipa_ctx->ipa_tx_forward++;
726
727 if ((desc & FW_RX_DESC_DISCARD_M)) {
728 wlan_ipa_forward(ipa_ctx, iface_ctx, skb);
729 ipa_ctx->ipa_rx_internal_drop_count++;
730 ipa_ctx->ipa_rx_discard++;
731 ret = WLAN_IPA_FORWARD_PKT_DISCARD;
732 } else {
733 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
734
735 if (cloned_skb)
736 wlan_ipa_forward(ipa_ctx, iface_ctx,
737 cloned_skb);
738 else
739 WLAN_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
740 "tx skb alloc failed");
741 ret = WLAN_IPA_FORWARD_PKT_LOCAL_STACK;
742 }
743 }
744
745 return ret;
746}
747
748/**
749 * wlan_ipa_w2i_cb() - WLAN to IPA callback handler
750 * @priv: pointer to private data registered with IPA (we register a
751 * pointer to the global IPA context)
752 * @evt: the IPA event which triggered the callback
753 * @data: data associated with the event
754 *
755 * Return: None
756 */
757static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
758 unsigned long data)
759{
760 struct wlan_ipa_priv *ipa_ctx = NULL;
761 qdf_nbuf_t skb;
762 uint8_t iface_id;
763 uint8_t session_id;
764 struct wlan_ipa_iface_context *iface_context;
765 uint8_t fw_desc;
766
767 ipa_ctx = (struct wlan_ipa_priv *)priv;
768
769 if (!ipa_ctx)
770 return;
771
772 switch (evt) {
773 case IPA_RECEIVE:
774 skb = (qdf_nbuf_t) data;
775
776 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
777 session_id = (uint8_t)skb->cb[0];
778 iface_id = ipa_ctx->vdev_to_iface[session_id];
779 ipa_debug("IPA_RECEIVE: session_id=%u, iface_id=%u",
780 session_id, iface_id);
781 } else {
782 iface_id = WLAN_IPA_GET_IFACE_ID(skb->data);
783 }
784 if (iface_id >= WLAN_IPA_MAX_IFACE) {
785 ipa_err("IPA_RECEIVE: Invalid iface_id: %u",
786 iface_id);
787 ipa_ctx->ipa_rx_internal_drop_count++;
jiadab8cea02018-05-24 09:16:14 +0800788 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530789 return;
790 }
791
792 iface_context = &ipa_ctx->iface_context[iface_id];
793 if (!iface_context->tl_context) {
794 ipa_err("IPA_RECEIVE: TL context is NULL");
795 ipa_ctx->ipa_rx_internal_drop_count++;
jiadab8cea02018-05-24 09:16:14 +0800796 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530797 return;
798 }
799
800 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
801 ipa_ctx->stats.num_rx_excep++;
802 qdf_nbuf_pull_head(skb, WLAN_IPA_UC_WLAN_CLD_HDR_LEN);
803 } else {
804 qdf_nbuf_pull_head(skb, WLAN_IPA_WLAN_CLD_HDR_LEN);
805 }
806
807 iface_context->stats.num_rx_ipa_excep++;
808
809 /* Disable to forward Intra-BSS Rx packets when
810 * ap_isolate=1 in hostapd.conf
811 */
812 if (!ipa_ctx->ap_intrabss_fwd) {
813 /*
814 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
815 * all Rx packets to IPA uC, which need to be forwarded
816 * to other interface.
817 * And, IPA driver will send back to WLAN host driver
818 * through exception pipe with fw_desc field set by FW.
819 * Here we are checking fw_desc field for FORWARD bit
820 * set, and forward to Tx. Then copy to kernel stack
821 * only when DISCARD bit is not set.
822 */
823 fw_desc = (uint8_t)skb->cb[1];
824 if (WLAN_IPA_FORWARD_PKT_DISCARD ==
825 wlan_ipa_intrabss_forward(ipa_ctx, iface_context,
826 fw_desc, skb))
827 break;
828 } else {
829 ipa_debug("Intra-BSS FWD is disabled-skip forward to Tx");
830 }
831
832 wlan_ipa_send_skb_to_network(skb, iface_context);
833 break;
834
835 default:
836 ipa_err("w2i cb wrong event: 0x%x", evt);
837 return;
838 }
839}
840
841/**
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530842 * wlan_ipa_i2w_cb() - IPA to WLAN callback
843 * @priv: pointer to private data registered with IPA (we register a
844 * pointer to the interface-specific IPA context)
845 * @evt: the IPA event which triggered the callback
846 * @data: data associated with the event
847 *
848 * Return: None
849 */
850static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
851 unsigned long data)
852{
853 struct wlan_ipa_priv *ipa_ctx = NULL;
854 qdf_ipa_rx_data_t *ipa_tx_desc;
855 struct wlan_ipa_iface_context *iface_context;
856 qdf_nbuf_t skb;
857 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL;
858
859 iface_context = (struct wlan_ipa_iface_context *)priv;
860 ipa_tx_desc = (qdf_ipa_rx_data_t *)data;
861 ipa_ctx = iface_context->ipa_ctx;
862
863 if (evt != IPA_RECEIVE) {
864 WLAN_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
865 ipa_free_skb(ipa_tx_desc);
866 iface_context->stats.num_tx_drop++;
867 return;
868 }
869
870 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc);
871
872 /*
873 * If PROD resource is not requested here then there may be cases where
874 * IPA hardware may be clocked down because of not having proper
875 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
876 * workaround to request PROD resource while data is going over CONS
877 * pipe to prevent the IPA hardware clockdown.
878 */
879 wlan_ipa_wdi_rm_request(ipa_ctx);
880
881 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
882 /*
883 * If host is still suspended then queue the packets and these will be
884 * drained later when resume completes. When packet is arrived here and
885 * host is suspended, this means that there is already resume is in
886 * progress.
887 */
888 if (ipa_ctx->suspended) {
889 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
890 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
891 pm_tx_cb->iface_context = iface_context;
892 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
893 qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb);
894 ipa_ctx->stats.num_tx_queued++;
895
896 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
897 return;
898 }
899
900 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
901
902 /*
903 * If we are here means, host is not suspended, wait for the work queue
904 * to finish.
905 */
906 qdf_flush_work(&ipa_ctx->pm_work);
907
908 return wlan_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
909}
910
911QDF_STATUS wlan_ipa_suspend(struct wlan_ipa_priv *ipa_ctx)
912{
913 /*
914 * Check if IPA is ready for suspend, If we are here means, there is
915 * high chance that suspend would go through but just to avoid any race
916 * condition after suspend started, these checks are conducted before
917 * allowing to suspend.
918 */
919 if (atomic_read(&ipa_ctx->tx_ref_cnt))
920 return QDF_STATUS_E_AGAIN;
921
Yun Parke74e6092018-04-27 11:36:34 -0700922 if (!wlan_ipa_is_rm_released(ipa_ctx))
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530923 return QDF_STATUS_E_AGAIN;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530924
925 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
926 ipa_ctx->suspended = true;
927 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
928
929 return QDF_STATUS_SUCCESS;
930}
931
932QDF_STATUS wlan_ipa_resume(struct wlan_ipa_priv *ipa_ctx)
933{
934 qdf_sched_work(0, &ipa_ctx->pm_work);
935
936 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
937 ipa_ctx->suspended = false;
938 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
939
940 return QDF_STATUS_SUCCESS;
941}
942
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +0530943QDF_STATUS wlan_ipa_uc_enable_pipes(struct wlan_ipa_priv *ipa_ctx)
944{
945 int result;
946
947 ipa_debug("enter");
948
949 if (!ipa_ctx->ipa_pipes_down) {
950 /*
951 * IPA WDI Pipes are already activated due to
952 * rm deferred resources grant
953 */
954 ipa_warn("IPA WDI Pipes are already activated");
955 goto end;
956 }
957
958 result = cdp_ipa_enable_pipes(ipa_ctx->dp_soc,
959 ipa_ctx->dp_pdev);
960 if (result) {
961 ipa_err("Enable IPA WDI PIPE failed: ret=%d", result);
962 return QDF_STATUS_E_FAILURE;
963 }
964
965 qdf_event_reset(&ipa_ctx->ipa_resource_comp);
966 ipa_ctx->ipa_pipes_down = false;
967
968 cdp_ipa_enable_autonomy(ipa_ctx->dp_soc,
969 ipa_ctx->dp_pdev);
970
971end:
972 ipa_debug("exit: ipa_pipes_down=%d", ipa_ctx->ipa_pipes_down);
973
974 return QDF_STATUS_SUCCESS;
975}
976
977QDF_STATUS wlan_ipa_uc_disable_pipes(struct wlan_ipa_priv *ipa_ctx)
978{
979 int result;
980
981 ipa_debug("enter");
982
983 if (ipa_ctx->ipa_pipes_down) {
984 /*
985 * This shouldn't happen :
986 * IPA WDI Pipes are already deactivated
987 */
988 QDF_ASSERT(0);
989 ipa_warn("IPA WDI Pipes are already deactivated");
990 goto end;
991 }
992
993 cdp_ipa_disable_autonomy(ipa_ctx->dp_soc,
994 ipa_ctx->dp_pdev);
995
996 result = cdp_ipa_disable_pipes(ipa_ctx->dp_soc,
997 ipa_ctx->dp_pdev);
998 if (result) {
999 ipa_err("Disable IPA WDI PIPE failed: ret=%d", result);
1000 return QDF_STATUS_E_FAILURE;
1001 }
1002
1003 ipa_ctx->ipa_pipes_down = true;
1004
1005end:
1006 ipa_debug("exit: ipa_pipes_down=%d", ipa_ctx->ipa_pipes_down);
1007
1008 return QDF_STATUS_SUCCESS;
1009}
1010
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301011/**
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301012 * wlan_ipa_uc_find_add_assoc_sta() - Find associated station
1013 * @ipa_ctx: Global IPA IPA context
1014 * @sta_add: Should station be added
1015 * @sta_id: ID of the station being queried
1016 *
1017 * Return: true if the station was found
1018 */
1019static bool wlan_ipa_uc_find_add_assoc_sta(struct wlan_ipa_priv *ipa_ctx,
1020 bool sta_add, uint8_t sta_id,
1021 uint8_t *mac_addr)
1022{
1023 bool sta_found = false;
1024 uint8_t idx;
1025
1026 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) {
1027 if ((ipa_ctx->assoc_stas_map[idx].is_reserved) &&
1028 (ipa_ctx->assoc_stas_map[idx].sta_id == sta_id)) {
1029 sta_found = true;
1030 break;
1031 }
1032 }
1033 if (sta_add && sta_found) {
1034 ipa_err("STA ID %d already exist, cannot add", sta_id);
1035 return sta_found;
1036 }
1037 if (sta_add) {
1038 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) {
1039 if (!ipa_ctx->assoc_stas_map[idx].is_reserved) {
1040 ipa_ctx->assoc_stas_map[idx].is_reserved = true;
1041 ipa_ctx->assoc_stas_map[idx].sta_id = sta_id;
1042 qdf_mem_copy(&ipa_ctx->assoc_stas_map[idx].
1043 mac_addr, mac_addr,
1044 QDF_NET_ETH_LEN);
1045 return sta_found;
1046 }
1047 }
1048 }
1049 if (!sta_add && !sta_found) {
1050 ipa_err("STA ID %d does not exist, cannot delete", sta_id);
1051 return sta_found;
1052 }
1053 if (!sta_add) {
1054 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) {
1055 if ((ipa_ctx->assoc_stas_map[idx].is_reserved) &&
1056 (ipa_ctx->assoc_stas_map[idx].sta_id == sta_id)) {
1057 ipa_ctx->assoc_stas_map[idx].is_reserved =
1058 false;
1059 ipa_ctx->assoc_stas_map[idx].sta_id = 0xFF;
1060 qdf_mem_set(&ipa_ctx->assoc_stas_map[idx].
1061 mac_addr, 0, QDF_NET_ETH_LEN);
1062 return sta_found;
1063 }
1064 }
1065 }
1066
1067 return sta_found;
1068}
1069
1070/**
1071 * wlan_ipa_get_ifaceid() - Get IPA context interface ID
1072 * @ipa_ctx: IPA context
1073 * @session_id: Session ID
1074 *
1075 * Return: None
1076 */
1077static int wlan_ipa_get_ifaceid(struct wlan_ipa_priv *ipa_ctx,
1078 uint8_t session_id)
1079{
1080 struct wlan_ipa_iface_context *iface_ctx;
1081 int i;
1082
1083 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1084 iface_ctx = &ipa_ctx->iface_context[i];
1085 if (iface_ctx->session_id == session_id)
1086 break;
1087 }
1088
1089 return i;
1090}
1091
1092/**
1093 * wlan_ipa_cleanup_iface() - Cleanup IPA on a given interface
1094 * @iface_context: interface-specific IPA context
1095 *
1096 * Return: None
1097 */
1098static void wlan_ipa_cleanup_iface(struct wlan_ipa_iface_context *iface_context)
1099{
1100 struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx;
1101
1102 ipa_debug("enter");
1103
1104 if (!iface_context->tl_context)
1105 return;
1106
1107 cdp_ipa_cleanup_iface(ipa_ctx->dp_soc,
1108 iface_context->dev->name,
1109 wlan_ipa_is_ipv6_enabled(ipa_ctx->config));
1110
1111 qdf_spin_lock_bh(&iface_context->interface_lock);
1112 iface_context->tl_context = NULL;
1113 iface_context->dev = NULL;
1114 iface_context->device_mode = QDF_MAX_NO_OF_MODE;
1115 iface_context->session_id = WLAN_IPA_MAX_SESSION;
1116 iface_context->sta_id = WLAN_IPA_MAX_STA_COUNT;
1117 qdf_spin_unlock_bh(&iface_context->interface_lock);
1118 iface_context->ifa_address = 0;
1119 if (!iface_context->ipa_ctx->num_iface) {
1120 ipa_err("NUM INTF 0, Invalid");
1121 QDF_ASSERT(0);
1122 }
1123 iface_context->ipa_ctx->num_iface--;
1124 ipa_debug("exit: num_iface=%d", iface_context->ipa_ctx->num_iface);
1125}
1126
1127/**
1128 * wlan_ipa_setup_iface() - Setup IPA on a given interface
1129 * @ipa_ctx: IPA IPA global context
1130 * @net_dev: Interface net device
1131 * @device_mode: Net interface device mode
1132 * @adapter: Interface upon which IPA is being setup
1133 * @sta_id: Station ID of the API instance
1134 * @session_id: Station ID of the API instance
1135 *
1136 * Return: QDF STATUS
1137 */
1138static QDF_STATUS wlan_ipa_setup_iface(struct wlan_ipa_priv *ipa_ctx,
1139 qdf_netdev_t net_dev,
1140 uint8_t device_mode, uint8_t sta_id,
1141 uint8_t session_id)
1142{
1143 struct wlan_ipa_iface_context *iface_context = NULL;
1144 void *tl_context = NULL;
1145 int i;
1146 QDF_STATUS status;
1147
1148 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1149 * channel change indication. Since these indications are sent by lower
1150 * layer as SAP updates and IPA doesn't have to do anything for these
1151 * updates so ignoring!
1152 */
1153 if (device_mode == QDF_SAP_MODE) {
1154 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1155 iface_context = &(ipa_ctx->iface_context[i]);
1156 if (iface_context->dev == net_dev)
1157 return QDF_STATUS_SUCCESS;
1158 }
1159 }
1160
Yun Park21ec4902018-04-24 12:11:01 -07001161 if (WLAN_IPA_MAX_IFACE == ipa_ctx->num_iface) {
1162 ipa_err("Max interface reached %d", WLAN_IPA_MAX_IFACE);
1163 status = QDF_STATUS_E_NOMEM;
1164 QDF_ASSERT(0);
1165 goto end;
1166 }
1167
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301168 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1169 if (ipa_ctx->iface_context[i].tl_context == NULL) {
1170 iface_context = &(ipa_ctx->iface_context[i]);
1171 break;
1172 }
1173 }
1174
1175 if (iface_context == NULL) {
1176 ipa_err("All the IPA interfaces are in use");
1177 status = QDF_STATUS_E_NOMEM;
Yun Park21ec4902018-04-24 12:11:01 -07001178 QDF_ASSERT(0);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301179 goto end;
1180 }
1181
1182 iface_context->sta_id = sta_id;
1183 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(ipa_ctx->dp_soc,
1184 ipa_ctx->dp_pdev,
1185 sta_id);
1186 if (tl_context == NULL) {
1187 ipa_err("Not able to get TL context sta_id: %d", sta_id);
1188 status = QDF_STATUS_E_INVAL;
1189 goto end;
1190 }
1191
1192 iface_context->tl_context = tl_context;
1193 iface_context->dev = net_dev;
1194 iface_context->device_mode = device_mode;
1195 iface_context->session_id = session_id;
1196
1197 status = cdp_ipa_setup_iface(ipa_ctx->dp_soc, net_dev->name,
1198 net_dev->dev_addr,
1199 iface_context->prod_client,
1200 iface_context->cons_client,
1201 session_id,
1202 wlan_ipa_is_ipv6_enabled(ipa_ctx->config));
1203 if (status != QDF_STATUS_SUCCESS)
1204 goto end;
1205
1206 ipa_ctx->num_iface++;
1207
1208 ipa_debug("exit: num_iface=%d", ipa_ctx->num_iface);
1209
1210 return status;
1211
1212end:
1213 if (iface_context)
1214 wlan_ipa_cleanup_iface(iface_context);
1215
1216 return status;
1217}
1218
1219/**
1220 * wlan_ipa_uc_handle_first_con() - Handle first uC IPA connection
1221 * @ipa_ctx: IPA context
1222 *
1223 * Return: QDF STATUS
1224 */
1225static QDF_STATUS wlan_ipa_uc_handle_first_con(struct wlan_ipa_priv *ipa_ctx)
1226{
1227 ipa_debug("enter");
1228
1229 ipa_ctx->activated_fw_pipe = 0;
1230 ipa_ctx->resource_loading = true;
1231
1232 /* If RM feature enabled
1233 * Request PROD Resource first
1234 * PROD resource may return sync or async manners
1235 */
1236 if (wlan_ipa_is_rm_enabled(ipa_ctx->config)) {
Yun Parke114fbf2018-04-05 20:02:12 -07001237 if (!wlan_ipa_wdi_rm_request_resource(ipa_ctx,
1238 IPA_RM_RESOURCE_WLAN_PROD)) {
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301239 /* RM PROD request sync return
1240 * enable pipe immediately
1241 */
1242 if (wlan_ipa_uc_enable_pipes(ipa_ctx)) {
1243 ipa_err("IPA WDI Pipe activation failed");
1244 ipa_ctx->resource_loading = false;
1245 return QDF_STATUS_E_BUSY;
1246 }
1247 } else {
1248 ipa_err("IPA WDI Pipe activation deferred");
1249 }
1250 } else {
1251 /* RM Disabled
1252 * Just enabled all the PIPEs
1253 */
1254 if (wlan_ipa_uc_enable_pipes(ipa_ctx)) {
1255 ipa_err("IPA WDI Pipe activation failed");
1256 ipa_ctx->resource_loading = false;
1257 return QDF_STATUS_E_BUSY;
1258 }
1259 ipa_ctx->resource_loading = false;
1260 }
1261
1262 ipa_debug("exit");
1263
1264 return QDF_STATUS_SUCCESS;
1265}
1266
1267/**
1268 * wlan_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1269 * @ipa_ctx: IPA context
1270 *
1271 * Return: None
1272 */
1273static void wlan_ipa_uc_handle_last_discon(struct wlan_ipa_priv *ipa_ctx)
1274{
1275 ipa_debug("enter");
1276
1277 ipa_ctx->resource_unloading = true;
1278 qdf_event_reset(&ipa_ctx->ipa_resource_comp);
1279 ipa_info("Disable FW RX PIPE");
1280 cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, false, false);
1281 ipa_info("Disable FW TX PIPE");
1282 cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, false, true);
1283
1284 ipa_debug("exit: IPA WDI Pipes deactivated");
1285}
1286
1287/**
1288 * wlan_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1289 * @ipa_ctx: global IPA context
1290 * @offload_type: MCC or SCC
1291 * @session_id: Session Id
1292 * @enable: TX offload enable or disable
1293 *
1294 * Return: none
1295 */
1296static void wlan_ipa_uc_offload_enable_disable(struct wlan_ipa_priv *ipa_ctx,
1297 uint32_t offload_type,
1298 uint8_t session_id,
1299 bool enable)
1300{
1301
1302 struct ipa_uc_offload_control_params req = {0};
1303
1304 if (session_id >= WLAN_IPA_MAX_SESSION) {
1305 ipa_err("invalid session id: %d", session_id);
1306 return;
1307 }
1308
1309 if (enable == ipa_ctx->vdev_offload_enabled[session_id]) {
1310 /*
1311 * This shouldn't happen :
1312 * IPA offload status is already set as desired
1313 */
1314 QDF_ASSERT(0);
1315 ipa_warn("IPA offload status is already set");
1316 ipa_warn("offload_type=%d, vdev_id=%d, enable=%d",
1317 offload_type, session_id, enable);
1318 return;
1319 }
1320
1321 ipa_info("offload_type=%d, session_id=%d, enable=%d",
1322 offload_type, session_id, enable);
1323
1324 req.offload_type = offload_type;
1325 req.vdev_id = session_id;
1326 req.enable = enable;
1327
1328 if (QDF_STATUS_SUCCESS !=
1329 ipa_send_uc_offload_enable_disable(ipa_ctx->pdev, &req)) {
1330 ipa_err("Fail to enable IPA offload");
1331 ipa_err("offload type=%d, vdev_id=%d, enable=%d",
1332 offload_type, session_id, enable);
1333 } else {
1334 ipa_ctx->vdev_offload_enabled[session_id] = enable;
1335 }
1336}
1337
1338/**
1339 * __wlan_ipa_wlan_evt() - IPA event handler
1340 * @net_dev: Interface net device
1341 * @device_mode: Net interface device mode
1342 * @sta_id: station id for the event
1343 * @session_id: session id for the event
1344 * @type: event enum of type ipa_wlan_event
1345 * @mac_address: MAC address associated with the event
1346 *
1347 * This function is meant to be called from within wlan_ipa_ctx.c
1348 *
1349 * Return: QDF STATUS
1350 */
1351static QDF_STATUS __wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode,
1352 uint8_t sta_id, uint8_t session_id,
1353 qdf_ipa_wlan_event type,
1354 uint8_t *mac_addr)
1355{
1356 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
1357 struct wlan_ipa_iface_context *iface_ctx = NULL;
1358 qdf_ipa_msg_meta_t meta;
1359 qdf_ipa_wlan_msg_t *msg;
1360 qdf_ipa_wlan_msg_ex_t *msg_ex = NULL;
1361 int i;
1362 QDF_STATUS status;
1363
1364 ipa_debug("%s: EVT: %d, MAC: %pM, sta_id: %d",
1365 net_dev->name, type, mac_addr, sta_id);
1366
1367 if (type >= QDF_IPA_WLAN_EVENT_MAX)
1368 return QDF_STATUS_E_INVAL;
1369
1370 if (wlan_ipa_uc_is_enabled(ipa_ctx->config) &&
1371 !wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1372 (device_mode != QDF_SAP_MODE)) {
1373 return QDF_STATUS_SUCCESS;
1374 }
1375
1376 /*
1377 * During IPA UC resource loading/unloading new events can be issued.
1378 */
1379 if (wlan_ipa_uc_is_enabled(ipa_ctx->config) &&
1380 (ipa_ctx->resource_loading || ipa_ctx->resource_unloading)) {
1381 unsigned int pending_event_count;
1382 struct wlan_ipa_uc_pending_event *pending_event = NULL;
1383
1384 ipa_info("Event:%d IPA resource %s inprogress", type,
1385 ipa_ctx->resource_loading ?
1386 "load" : "unload");
1387
1388 /* Wait until completion of the long/unloading */
1389 status = qdf_wait_for_event_completion(
1390 &ipa_ctx->ipa_resource_comp,
jiada8c542c2018-05-29 16:24:13 +08001391 IPA_RESOURCE_COMP_WAIT_TIME);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301392 if (status != QDF_STATUS_SUCCESS) {
1393 /*
1394 * If timed out, store the events separately and
1395 * handle them later.
1396 */
1397 ipa_info("IPA resource %s timed out",
1398 ipa_ctx->resource_loading ?
1399 "load" : "unload");
1400
1401 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
1402
1403 pending_event_count =
1404 qdf_list_size(&ipa_ctx->pending_event);
1405 if (pending_event_count >=
1406 WLAN_IPA_MAX_PENDING_EVENT_COUNT) {
1407 ipa_info("Reached max pending evt count");
1408 qdf_list_remove_front(
1409 &ipa_ctx->pending_event,
1410 (qdf_list_node_t **)&pending_event);
1411 } else {
1412 pending_event =
1413 (struct wlan_ipa_uc_pending_event *)
1414 qdf_mem_malloc(sizeof(
1415 struct wlan_ipa_uc_pending_event));
1416 }
1417
1418 if (!pending_event) {
1419 ipa_err("Pending event memory alloc fail");
1420 qdf_mutex_release(&ipa_ctx->ipa_lock);
1421 return QDF_STATUS_E_NOMEM;
1422 }
1423
1424 pending_event->net_dev = net_dev;
1425 pending_event->device_mode = device_mode;
1426 pending_event->sta_id = sta_id;
1427 pending_event->session_id = session_id;
1428 pending_event->type = type;
1429 pending_event->is_loading = ipa_ctx->resource_loading;
1430 qdf_mem_copy(pending_event->mac_addr,
1431 mac_addr, QDF_MAC_ADDR_SIZE);
1432 qdf_list_insert_back(&ipa_ctx->pending_event,
1433 &pending_event->node);
1434
1435 qdf_mutex_release(&ipa_ctx->ipa_lock);
1436
Yun Park21ec4902018-04-24 12:11:01 -07001437 /* Cleanup interface */
1438 if (type == QDF_IPA_STA_DISCONNECT ||
1439 type == QDF_IPA_AP_DISCONNECT) {
1440 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1441 iface_ctx = &ipa_ctx->iface_context[i];
1442
1443 if (iface_ctx->dev == net_dev)
1444 break;
1445 }
1446 if (iface_ctx)
1447 wlan_ipa_cleanup_iface(iface_ctx);
1448 }
1449
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301450 return QDF_STATUS_SUCCESS;
1451 }
1452 ipa_info("IPA resource %s completed",
1453 ipa_ctx->resource_loading ?
1454 "load" : "unload");
1455 }
1456
1457 ipa_ctx->stats.event[type]++;
1458
1459 QDF_IPA_SET_META_MSG_TYPE(&meta, type);
1460 switch (type) {
1461 case QDF_IPA_STA_CONNECT:
1462 qdf_mutex_acquire(&ipa_ctx->event_lock);
1463
1464 /* STA already connected and without disconnect, connect again
1465 * This is Roaming scenario
1466 */
1467 if (ipa_ctx->sta_connected) {
1468 iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE);
1469 if (iface_ctx)
1470 wlan_ipa_cleanup_iface(iface_ctx);
1471 }
1472
1473 status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode,
1474 sta_id, session_id);
1475 if (status != QDF_STATUS_SUCCESS) {
1476 qdf_mutex_release(&ipa_ctx->event_lock);
1477 goto end;
1478 }
1479
1480 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1481 (ipa_ctx->sap_num_connected_sta > 0) &&
1482 !ipa_ctx->sta_connected) {
1483 qdf_mutex_release(&ipa_ctx->event_lock);
1484 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1485 SIR_STA_RX_DATA_OFFLOAD, session_id,
1486 true);
1487 qdf_mutex_acquire(&ipa_ctx->event_lock);
1488 }
1489
1490 ipa_ctx->vdev_to_iface[session_id] =
1491 wlan_ipa_get_ifaceid(ipa_ctx, session_id);
1492
1493 ipa_ctx->sta_connected = 1;
1494
1495 qdf_mutex_release(&ipa_ctx->event_lock);
1496
1497 ipa_debug("sta_connected=%d", ipa_ctx->sta_connected);
1498 break;
1499
1500 case QDF_IPA_AP_CONNECT:
1501 qdf_mutex_acquire(&ipa_ctx->event_lock);
1502
1503 /* For DFS channel we get two start_bss event (before and after
1504 * CAC). Also when ACS range includes both DFS and non DFS
1505 * channels, we could possibly change channel many times due to
1506 * RADAR detection and chosen channel may not be a DFS channels.
1507 * So dont return error here. Just discard the event.
1508 */
jiadc908ada2018-05-11 14:40:54 +08001509 if (ipa_ctx->vdev_to_iface[session_id] !=
1510 WLAN_IPA_MAX_SESSION) {
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301511 qdf_mutex_release(&ipa_ctx->event_lock);
1512 return 0;
1513 }
1514
1515 status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode,
1516 sta_id, session_id);
1517 if (status != QDF_STATUS_SUCCESS) {
1518 qdf_mutex_release(&ipa_ctx->event_lock);
1519 ipa_err("%s: Evt: %d, Interface setup failed",
1520 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
1521 goto end;
1522 }
1523
1524 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1525 qdf_mutex_release(&ipa_ctx->event_lock);
1526 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1527 SIR_AP_RX_DATA_OFFLOAD, session_id, true);
1528 qdf_mutex_acquire(&ipa_ctx->event_lock);
1529 }
1530
1531 ipa_ctx->vdev_to_iface[session_id] =
1532 wlan_ipa_get_ifaceid(ipa_ctx, session_id);
1533 qdf_mutex_release(&ipa_ctx->event_lock);
1534 break;
1535
1536 case QDF_IPA_STA_DISCONNECT:
1537 qdf_mutex_acquire(&ipa_ctx->event_lock);
1538
1539 if (!ipa_ctx->sta_connected) {
1540 qdf_mutex_release(&ipa_ctx->event_lock);
1541 ipa_err("%s: Evt: %d, STA already disconnected",
1542 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
1543 return QDF_STATUS_E_INVAL;
1544 }
1545
1546 ipa_ctx->sta_connected = 0;
1547
1548 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1549 ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED",
1550 msg_ex->name);
1551 } else {
1552 /* Disable IPA UC TX PIPE when STA disconnected */
1553 if ((ipa_ctx->num_iface == 1) &&
Yun Parka29974a2018-04-09 12:05:49 -07001554 wlan_ipa_is_fw_wdi_activated(ipa_ctx) &&
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301555 !ipa_ctx->ipa_pipes_down)
1556 wlan_ipa_uc_handle_last_discon(ipa_ctx);
1557 }
1558
1559 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1560 (ipa_ctx->sap_num_connected_sta > 0)) {
1561 qdf_mutex_release(&ipa_ctx->event_lock);
1562 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1563 SIR_STA_RX_DATA_OFFLOAD, session_id, false);
1564 qdf_mutex_acquire(&ipa_ctx->event_lock);
1565 ipa_ctx->vdev_to_iface[session_id] =
1566 WLAN_IPA_MAX_SESSION;
1567 }
1568
1569 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1570 iface_ctx = &ipa_ctx->iface_context[i];
1571
1572 if (iface_ctx->dev == net_dev)
1573 break;
1574 }
1575 if (i < WLAN_IPA_MAX_IFACE)
1576 wlan_ipa_cleanup_iface(iface_ctx);
1577
1578 qdf_mutex_release(&ipa_ctx->event_lock);
1579
1580 ipa_debug("sta_connected=%d", ipa_ctx->sta_connected);
1581 break;
1582
1583 case QDF_IPA_AP_DISCONNECT:
1584 qdf_mutex_acquire(&ipa_ctx->event_lock);
1585
1586 if ((ipa_ctx->num_iface == 1) &&
Yun Parka29974a2018-04-09 12:05:49 -07001587 wlan_ipa_is_fw_wdi_activated(ipa_ctx) &&
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301588 !ipa_ctx->ipa_pipes_down) {
1589 if (cds_is_driver_unloading()) {
1590 /*
1591 * We disable WDI pipes directly here since
1592 * IPA_OPCODE_TX/RX_SUSPEND message will not be
1593 * processed when unloading WLAN driver is in
1594 * progress
1595 */
1596 wlan_ipa_uc_disable_pipes(ipa_ctx);
1597 } else {
1598 /*
1599 * This shouldn't happen :
1600 * No interface left but WDI pipes are still
1601 * active - force close WDI pipes
1602 */
1603 ipa_err("No interface left but WDI pipes are still active");
1604 wlan_ipa_uc_handle_last_discon(ipa_ctx);
1605 }
1606 }
1607
1608 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1609 qdf_mutex_release(&ipa_ctx->event_lock);
1610 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1611 SIR_AP_RX_DATA_OFFLOAD, session_id, false);
1612 qdf_mutex_acquire(&ipa_ctx->event_lock);
1613 ipa_ctx->vdev_to_iface[session_id] =
1614 WLAN_IPA_MAX_SESSION;
1615 }
1616
1617 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1618 iface_ctx = &ipa_ctx->iface_context[i];
1619
1620 if (iface_ctx->dev == net_dev)
1621 break;
1622 }
1623 if (i < WLAN_IPA_MAX_IFACE)
1624 wlan_ipa_cleanup_iface(iface_ctx);
1625
1626 qdf_mutex_release(&ipa_ctx->event_lock);
1627 break;
1628
1629 case QDF_IPA_CLIENT_CONNECT_EX:
1630 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1631 ipa_debug("%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
1632 net_dev->name, type);
1633 return QDF_STATUS_SUCCESS;
1634 }
1635
1636 qdf_mutex_acquire(&ipa_ctx->event_lock);
1637 if (wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, true, sta_id,
1638 mac_addr)) {
1639 qdf_mutex_release(&ipa_ctx->event_lock);
1640 ipa_err("%s: STA ID %d found", net_dev->name, sta_id);
1641 return QDF_STATUS_SUCCESS;
1642 }
1643
1644 /* Enable IPA UC Data PIPEs when first STA connected */
1645 if (ipa_ctx->sap_num_connected_sta == 0 &&
1646 ipa_ctx->uc_loaded == true) {
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301647 struct wlan_ipa_iface_context *iface_ctx;
1648 uint8_t sta_session_id;
1649
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301650 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1651 ipa_ctx->sta_connected) {
1652 qdf_mutex_release(&ipa_ctx->event_lock);
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301653 iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE);
1654 sta_session_id = iface_ctx->session_id;
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301655 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1656 SIR_STA_RX_DATA_OFFLOAD,
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301657 sta_session_id, true);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301658 qdf_mutex_acquire(&ipa_ctx->event_lock);
1659 }
1660
1661 status = wlan_ipa_uc_handle_first_con(ipa_ctx);
1662 if (status != QDF_STATUS_SUCCESS) {
1663 ipa_info("%s: handle 1st con fail",
1664 net_dev->name);
1665
1666 if (wlan_ipa_uc_sta_is_enabled(
1667 ipa_ctx->config) &&
1668 ipa_ctx->sta_connected) {
1669 qdf_mutex_release(&ipa_ctx->event_lock);
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301670 iface_ctx = wlan_ipa_get_iface(ipa_ctx,
1671 QDF_STA_MODE);
1672 sta_session_id = iface_ctx->session_id;
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301673 wlan_ipa_uc_offload_enable_disable(
1674 ipa_ctx,
1675 SIR_STA_RX_DATA_OFFLOAD,
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301676 sta_session_id, false);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301677 } else {
1678 qdf_mutex_release(&ipa_ctx->event_lock);
1679 }
1680
1681 return status;
1682 }
1683 }
1684
1685 ipa_ctx->sap_num_connected_sta++;
1686
1687 qdf_mutex_release(&ipa_ctx->event_lock);
1688
1689 QDF_IPA_SET_META_MSG_TYPE(&meta, type);
1690 QDF_IPA_MSG_META_MSG_LEN(&meta) =
1691 (sizeof(qdf_ipa_wlan_msg_ex_t) +
1692 sizeof(qdf_ipa_wlan_hdr_attrib_val_t));
1693 msg_ex = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
1694
1695 if (msg_ex == NULL) {
1696 ipa_err("msg_ex allocation failed");
1697 return QDF_STATUS_E_NOMEM;
1698 }
1699 strlcpy(msg_ex->name, net_dev->name,
1700 IPA_RESOURCE_NAME_MAX);
1701 msg_ex->num_of_attribs = 1;
1702 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
1703 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1704 msg_ex->attribs[0].offset =
1705 WLAN_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
1706 } else {
1707 msg_ex->attribs[0].offset =
1708 WLAN_IPA_WLAN_HDR_DES_MAC_OFFSET;
1709 }
1710 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
1711 IPA_MAC_ADDR_SIZE);
1712
1713 if (qdf_ipa_send_msg(&meta, msg_ex, wlan_ipa_msg_free_fn)) {
1714 ipa_info("%s: Evt: %d send ipa msg fail",
1715 net_dev->name, type);
1716 qdf_mem_free(msg_ex);
1717 return QDF_STATUS_E_FAILURE;
1718 }
1719 ipa_ctx->stats.num_send_msg++;
1720
1721 ipa_info("sap_num_connected_sta=%d",
1722 ipa_ctx->sap_num_connected_sta);
1723
1724 return QDF_STATUS_SUCCESS;
1725
1726 case WLAN_CLIENT_DISCONNECT:
1727 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1728 ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED",
1729 msg_ex->name);
1730 return QDF_STATUS_SUCCESS;
1731 }
1732
1733 qdf_mutex_acquire(&ipa_ctx->event_lock);
1734 if (!ipa_ctx->sap_num_connected_sta) {
1735 qdf_mutex_release(&ipa_ctx->event_lock);
1736 ipa_err("%s: Evt: %d, Client already disconnected",
1737 msg_ex->name,
1738 QDF_IPA_MSG_META_MSG_TYPE(&meta));
1739
1740 return QDF_STATUS_SUCCESS;
1741 }
1742 if (!wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, false,
1743 sta_id, mac_addr)) {
1744 qdf_mutex_release(&ipa_ctx->event_lock);
1745 ipa_err("%s: STA ID %d NOT found, not valid",
1746 msg_ex->name, sta_id);
1747
1748 return QDF_STATUS_SUCCESS;
1749 }
1750 ipa_ctx->sap_num_connected_sta--;
1751
1752 /* Disable IPA UC TX PIPE when last STA disconnected */
1753 if (!ipa_ctx->sap_num_connected_sta &&
1754 ipa_ctx->uc_loaded == true) {
Yun Parka29974a2018-04-09 12:05:49 -07001755 if ((false == ipa_ctx->resource_unloading) &&
1756 wlan_ipa_is_fw_wdi_activated(ipa_ctx) &&
1757 !ipa_ctx->ipa_pipes_down) {
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301758 wlan_ipa_uc_handle_last_discon(ipa_ctx);
1759 }
1760
1761 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1762 ipa_ctx->sta_connected) {
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301763 struct wlan_ipa_iface_context *iface_ctx;
1764 uint8_t sta_session_id;
1765
1766 iface_ctx = wlan_ipa_get_iface(ipa_ctx,
1767 QDF_STA_MODE);
1768 sta_session_id = iface_ctx->session_id;
1769
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301770 qdf_mutex_release(&ipa_ctx->event_lock);
1771 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1772 SIR_STA_RX_DATA_OFFLOAD,
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301773 sta_session_id, false);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301774 } else {
1775 qdf_mutex_release(&ipa_ctx->event_lock);
1776 }
1777 } else {
1778 qdf_mutex_release(&ipa_ctx->event_lock);
1779 }
1780
1781 ipa_info("sap_num_connected_sta=%d",
1782 ipa_ctx->sap_num_connected_sta);
1783 break;
1784
1785 default:
1786 return QDF_STATUS_SUCCESS;
1787 }
1788
1789 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t);
1790 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
1791 if (!msg) {
1792 ipa_err("msg allocation failed");
1793 return QDF_STATUS_E_NOMEM;
1794 }
1795
1796 QDF_IPA_SET_META_MSG_TYPE(&meta, type);
1797 strlcpy(QDF_IPA_WLAN_MSG_NAME(msg), net_dev->name,
1798 IPA_RESOURCE_NAME_MAX);
1799 qdf_mem_copy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, QDF_NET_ETH_LEN);
1800
1801 ipa_debug("%s: Evt: %d", QDF_IPA_WLAN_MSG_NAME(msg),
1802 QDF_IPA_MSG_META_MSG_TYPE(&meta));
1803
1804 if (qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn)) {
1805
1806 ipa_err("%s: Evt: %d fail",
1807 QDF_IPA_WLAN_MSG_NAME(msg),
1808 QDF_IPA_MSG_META_MSG_TYPE(&meta));
1809 qdf_mem_free(msg);
1810
1811 return QDF_STATUS_E_FAILURE;
1812 }
1813
1814 ipa_ctx->stats.num_send_msg++;
1815
1816end:
1817 return QDF_STATUS_SUCCESS;
1818}
1819
1820/**
1821 * wlan_host_to_ipa_wlan_event() - convert wlan_ipa_wlan_event to ipa_wlan_event
Yun Park84fbb272018-04-02 15:31:01 -07001822 * @wlan_ipa_event_type: event to be converted to an ipa_wlan_event
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301823 *
1824 * Return: qdf_ipa_wlan_event representing the wlan_ipa_wlan_event
1825 */
1826static qdf_ipa_wlan_event
1827wlan_host_to_ipa_wlan_event(enum wlan_ipa_wlan_event wlan_ipa_event_type)
1828{
Yun Park84fbb272018-04-02 15:31:01 -07001829 qdf_ipa_wlan_event ipa_event;
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301830
1831 switch (wlan_ipa_event_type) {
1832 case WLAN_IPA_CLIENT_CONNECT:
1833 ipa_event = QDF_IPA_CLIENT_CONNECT;
1834 break;
1835 case WLAN_IPA_CLIENT_DISCONNECT:
1836 ipa_event = QDF_IPA_CLIENT_DISCONNECT;
1837 break;
1838 case WLAN_IPA_AP_CONNECT:
1839 ipa_event = QDF_IPA_AP_CONNECT;
1840 break;
1841 case WLAN_IPA_AP_DISCONNECT:
1842 ipa_event = QDF_IPA_AP_DISCONNECT;
1843 break;
1844 case WLAN_IPA_STA_CONNECT:
1845 ipa_event = QDF_IPA_STA_CONNECT;
1846 break;
1847 case WLAN_IPA_STA_DISCONNECT:
1848 ipa_event = QDF_IPA_STA_DISCONNECT;
1849 break;
1850 case WLAN_IPA_CLIENT_CONNECT_EX:
1851 ipa_event = QDF_IPA_CLIENT_CONNECT_EX;
1852 break;
1853 case WLAN_IPA_WLAN_EVENT_MAX:
1854 default:
1855 ipa_event = QDF_IPA_WLAN_EVENT_MAX;
1856 break;
1857 }
1858
1859 return ipa_event;
1860}
1861
1862/**
1863 * wlan_ipa_wlan_evt() - SSR wrapper for __wlan_ipa_wlan_evt
1864 * @net_dev: Interface net device
1865 * @device_mode: Net interface device mode
1866 * @sta_id: station id for the event
1867 * @session_id: session id for the event
1868 * @ipa_event_type: event enum of type wlan_ipa_wlan_event
1869 * @mac_address: MAC address associated with the event
1870 *
1871 * Return: QDF_STATUS
1872 */
1873QDF_STATUS wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode,
1874 uint8_t sta_id, uint8_t session_id,
1875 enum wlan_ipa_wlan_event ipa_event_type,
1876 uint8_t *mac_addr)
1877{
1878 qdf_ipa_wlan_event type = wlan_host_to_ipa_wlan_event(ipa_event_type);
1879 QDF_STATUS status = QDF_STATUS_SUCCESS;
1880
1881 /* Data path offload only support for STA and SAP mode */
1882 if ((device_mode == QDF_STA_MODE) ||
1883 (device_mode == QDF_SAP_MODE))
1884 status = __wlan_ipa_wlan_evt(net_dev, device_mode, sta_id,
1885 session_id, type, mac_addr);
1886
1887 return status;
1888}
1889
1890/**
1891 * wlan_ipa_uc_proc_pending_event() - Process IPA uC pending events
1892 * @ipa_ctx: Global IPA IPA context
1893 * @is_loading: Indicate if invoked during loading
1894 *
1895 * Return: None
1896 */
1897static void
1898wlan_ipa_uc_proc_pending_event(struct wlan_ipa_priv *ipa_ctx, bool is_loading)
1899{
1900 unsigned int pending_event_count;
1901 struct wlan_ipa_uc_pending_event *pending_event = NULL;
1902
1903 pending_event_count = qdf_list_size(&ipa_ctx->pending_event);
1904 ipa_debug("Pending Event Count %d", pending_event_count);
1905 if (!pending_event_count) {
1906 ipa_debug("No Pending Event");
1907 return;
1908 }
1909
1910 qdf_list_remove_front(&ipa_ctx->pending_event,
1911 (qdf_list_node_t **)&pending_event);
1912 while (pending_event != NULL) {
1913 if (pending_event->is_loading == is_loading) {
1914 __wlan_ipa_wlan_evt(pending_event->net_dev,
1915 pending_event->device_mode,
1916 pending_event->sta_id,
1917 pending_event->session_id,
1918 pending_event->type,
1919 pending_event->mac_addr);
1920 }
1921 qdf_mem_free(pending_event);
1922 pending_event = NULL;
1923 qdf_list_remove_front(&ipa_ctx->pending_event,
1924 (qdf_list_node_t **)&pending_event);
1925 }
1926}
1927
1928/**
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301929 * wlan_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
1930 * @ipa_ctx: IPA context
1931 *
1932 * Return: QDF_STATUS
1933 */
1934static int wlan_ipa_alloc_tx_desc_list(struct wlan_ipa_priv *ipa_ctx)
1935{
1936 int i;
1937 uint32_t max_desc_cnt;
1938 struct wlan_ipa_tx_desc *tmp_desc;
1939
1940 max_desc_cnt = ipa_ctx->config->txbuf_count;
1941
1942 qdf_list_create(&ipa_ctx->tx_desc_list, max_desc_cnt);
1943
1944 qdf_spin_lock_bh(&ipa_ctx->q_lock);
1945 for (i = 0; i < max_desc_cnt; i++) {
1946 tmp_desc = qdf_mem_malloc(sizeof(*tmp_desc));
1947 tmp_desc->id = i;
1948 tmp_desc->ipa_tx_desc_ptr = NULL;
1949 qdf_list_insert_back(&ipa_ctx->tx_desc_list,
1950 &tmp_desc->node);
1951 tmp_desc++;
1952 }
1953
1954 ipa_ctx->stats.num_tx_desc_q_cnt = 0;
1955 ipa_ctx->stats.num_tx_desc_error = 0;
1956
1957 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
1958
1959 return QDF_STATUS_SUCCESS;
1960}
1961
1962#ifndef QCA_LL_TX_FLOW_CONTROL_V2
1963/**
1964 * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes
1965 * @ipa_ctx: Global IPA IPA context
1966 * @desc_fifo_sz: Number of descriptors
1967 *
1968 * Return: 0 on success, negative errno on error
1969 */
1970static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
1971 int32_t desc_fifo_sz)
1972{
1973 int i, ret = 0;
1974 qdf_ipa_sys_connect_params_t *ipa;
1975
1976 /*setup TX pipes */
1977 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1978 ipa = &ipa_ctx->sys_pipe[i].ipa_sys_params;
1979
1980 ipa->client = wlan_ipa_iface_2_client[i].cons_client;
1981 ipa->desc_fifo_sz = desc_fifo_sz;
1982 ipa->priv = &ipa_ctx->iface_context[i];
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05301983 ipa->notify = wlan_ipa_i2w_cb;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301984
1985 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
1986 ipa->ipa_ep_cfg.hdr.hdr_len =
1987 WLAN_IPA_UC_WLAN_TX_HDR_LEN;
1988 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1989 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1990 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1991 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
1992 WLAN_IPA_UC_WLAN_8023_HDR_SIZE;
1993 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1994 } else {
1995 ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_TX_HDR_LEN;
1996 }
1997 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
1998
1999 ret = wlan_ipa_wdi_setup_sys_pipe(ipa_ctx, ipa,
2000 &ipa_ctx->sys_pipe[i].conn_hdl);
2001 if (ret) {
2002 ipa_err("Failed for pipe %d ret: %d", i, ret);
2003 return ret;
2004 }
2005 ipa_ctx->sys_pipe[i].conn_hdl_valid = 1;
2006 }
2007
2008 return ret;
2009}
2010#else
2011/**
2012 * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes
2013 * @ipa_ctx: Global IPA IPA context
2014 * @desc_fifo_sz: Number of descriptors
2015 *
2016 * Return: 0 on success, negative errno on error
2017 */
2018static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
2019 int32_t desc_fifo_sz)
2020{
2021 /*
2022 * The Tx system pipes are not needed for MCC when TX_FLOW_CONTROL_V2
2023 * is enabled, where per vdev descriptors are supported in firmware.
2024 */
2025 return 0;
2026}
2027#endif
2028
2029/**
2030 * wlan_ipa_setup_rx_sys_pipe() - Setup IPA Rx system pipes
2031 * @ipa_ctx: Global IPA IPA context
2032 * @desc_fifo_sz: Number of descriptors
2033 *
2034 * Return: 0 on success, negative errno on error
2035 */
2036static int wlan_ipa_setup_rx_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
2037 int32_t desc_fifo_sz)
2038{
2039 int ret = 0;
2040 qdf_ipa_sys_connect_params_t *ipa;
2041
2042 /*
2043 * Hard code it here, this can be extended if in case
2044 * PROD pipe is also per interface.
2045 * Right now there is no advantage of doing this.
2046 */
2047 ipa = &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].ipa_sys_params;
2048
2049 ipa->client = IPA_CLIENT_WLAN1_PROD;
2050
2051 ipa->desc_fifo_sz = desc_fifo_sz;
2052 ipa->priv = ipa_ctx;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302053 ipa->notify = wlan_ipa_w2i_cb;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302054
2055 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2056 ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_RX_HDR_LEN;
2057 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
2058 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
2059
2060 ret = qdf_ipa_setup_sys_pipe(ipa,
2061 &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl);
2062 if (ret) {
2063 ipa_err("Failed for RX pipe: %d", ret);
2064 return ret;
2065 }
2066 ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl_valid = 1;
2067
2068 return ret;
2069}
2070
2071/**
2072 * wlan_ipa_setup_sys_pipe() - Setup all IPA system pipes
2073 * @ipa_ctx: Global IPA IPA context
2074 *
2075 * Return: 0 on success, negative errno on error
2076 */
2077static int wlan_ipa_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx)
2078{
2079 int i = WLAN_IPA_MAX_IFACE, ret = 0;
2080 uint32_t desc_fifo_sz;
2081
2082 /* The maximum number of descriptors that can be provided to a BAM at
2083 * once is one less than the total number of descriptors that the buffer
2084 * can contain.
2085 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
2086 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
2087 * be provided at once.
2088 * Because of above requirement, one extra descriptor will be added to
2089 * make sure hardware always has one descriptor.
2090 */
2091 desc_fifo_sz = ipa_ctx->config->desc_size
2092 + SPS_DESC_SIZE;
2093
2094 ret = wlan_ipa_setup_tx_sys_pipe(ipa_ctx, desc_fifo_sz);
2095 if (ret) {
2096 ipa_err("Failed for TX pipe: %d", ret);
2097 goto setup_sys_pipe_fail;
2098 }
2099
2100 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
2101 ret = wlan_ipa_setup_rx_sys_pipe(ipa_ctx, desc_fifo_sz);
2102 if (ret) {
2103 ipa_err("Failed for RX pipe: %d", ret);
2104 goto setup_sys_pipe_fail;
2105 }
2106 }
2107
2108 /* Allocate free Tx desc list */
2109 ret = wlan_ipa_alloc_tx_desc_list(ipa_ctx);
2110 if (ret)
2111 goto setup_sys_pipe_fail;
2112
2113 return ret;
2114
2115setup_sys_pipe_fail:
2116
2117 for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) {
2118 if (ipa_ctx->sys_pipe[i].conn_hdl_valid)
2119 qdf_ipa_teardown_sys_pipe(
2120 ipa_ctx->sys_pipe[i].conn_hdl);
2121 qdf_mem_zero(&ipa_ctx->sys_pipe[i],
2122 sizeof(struct wlan_ipa_sys_pipe));
2123 }
2124
2125 return ret;
2126}
2127
2128/**
2129 * wlan_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
2130 * @ipa_ctx: Global IPA IPA context
2131 *
2132 * Return: None
2133 */
2134static void wlan_ipa_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx)
2135{
2136 int ret = 0, i;
2137 struct wlan_ipa_tx_desc *tmp_desc;
2138 qdf_ipa_rx_data_t *ipa_tx_desc;
2139 qdf_list_node_t *node;
2140
2141 for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) {
2142 if (ipa_ctx->sys_pipe[i].conn_hdl_valid) {
2143 ret = wlan_ipa_wdi_teardown_sys_pipe(ipa_ctx,
2144 ipa_ctx->sys_pipe[i].conn_hdl);
2145 if (ret)
2146 ipa_err("Failed:%d", ret);
2147
2148 ipa_ctx->sys_pipe[i].conn_hdl_valid = 0;
2149 }
2150 }
2151
2152 while (qdf_list_remove_front(&ipa_ctx->tx_desc_list, &node) ==
2153 QDF_STATUS_SUCCESS) {
2154 tmp_desc = qdf_container_of(node, struct wlan_ipa_tx_desc,
2155 node);
2156 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
2157 if (ipa_tx_desc)
2158 qdf_ipa_free_skb(ipa_tx_desc);
2159
2160 qdf_mem_free(tmp_desc);
2161 }
2162}
2163
jiadbb47e132018-03-30 16:28:30 +08002164#ifndef QCA_LL_TX_FLOW_CONTROL_V2
2165QDF_STATUS wlan_ipa_send_mcc_scc_msg(struct wlan_ipa_priv *ipa_ctx,
2166 bool mcc_mode)
2167{
2168 qdf_ipa_msg_meta_t meta;
2169 qdf_ipa_wlan_msg_t *msg;
2170 int ret;
2171
2172 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config))
2173 return QDF_STATUS_SUCCESS;
2174
2175 /* Send SCC/MCC Switching event to IPA */
2176 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*msg);
2177 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
2178 if (msg == NULL) {
2179 ipa_err("msg allocation failed");
2180 return QDF_STATUS_E_NOMEM;
2181 }
2182
jiad629b2172018-05-11 15:34:22 +08002183 if (mcc_mode) {
jiadbb47e132018-03-30 16:28:30 +08002184 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_MCC);
jiad629b2172018-05-11 15:34:22 +08002185 ipa_ctx->stats.event[QDF_SWITCH_TO_MCC]++;
2186 } else {
jiadbb47e132018-03-30 16:28:30 +08002187 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_SCC);
jiad629b2172018-05-11 15:34:22 +08002188 ipa_ctx->stats.event[QDF_SWITCH_TO_SCC]++;
2189 }
2190
jiadbb47e132018-03-30 16:28:30 +08002191 WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
2192 "ipa_send_msg(Evt:%d)",
2193 QDF_IPA_MSG_META_MSG_TYPE(&meta));
2194
2195 ret = qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn);
2196
2197 if (ret) {
2198 ipa_err("ipa_send_msg(Evt:%d) - fail=%d",
2199 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
2200 qdf_mem_free(msg);
2201 return QDF_STATUS_E_FAILURE;
2202 }
2203
2204 return QDF_STATUS_SUCCESS;
2205}
2206
2207static void wlan_ipa_mcc_work_handler(void *data)
2208{
2209 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data;
2210
2211 wlan_ipa_send_mcc_scc_msg(ipa_ctx, ipa_ctx->mcc_mode);
2212}
2213#endif
2214
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302215/**
2216 * wlan_ipa_setup() - IPA initialization function
2217 * @ipa_ctx: IPA context
2218 * @ipa_cfg: IPA config
2219 *
2220 * Allocate ipa_ctx resources, ipa pipe resource and register
2221 * wlan interface with IPA module.
2222 *
2223 * Return: QDF_STATUS enumeration
2224 */
2225QDF_STATUS wlan_ipa_setup(struct wlan_ipa_priv *ipa_ctx,
2226 struct wlan_ipa_config *ipa_cfg)
2227{
2228 int ret, i;
2229 struct wlan_ipa_iface_context *iface_context = NULL;
2230 QDF_STATUS status;
2231
2232 ipa_debug("enter");
2233
2234 gp_ipa = ipa_ctx;
2235 ipa_ctx->num_iface = 0;
2236 ipa_ctx->config = ipa_cfg;
2237
2238 wlan_ipa_wdi_get_wdi_version(ipa_ctx);
2239
2240 /* Create the interface context */
2241 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2242 iface_context = &ipa_ctx->iface_context[i];
2243 iface_context->ipa_ctx = ipa_ctx;
2244 iface_context->cons_client =
2245 wlan_ipa_iface_2_client[i].cons_client;
2246 iface_context->prod_client =
2247 wlan_ipa_iface_2_client[i].prod_client;
2248 iface_context->iface_id = i;
2249 iface_context->dev = NULL;
2250 iface_context->device_mode = QDF_MAX_NO_OF_MODE;
2251 iface_context->tl_context = NULL;
2252 qdf_spinlock_create(&iface_context->interface_lock);
2253 }
2254
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302255 qdf_create_work(0, &ipa_ctx->pm_work, wlan_ipa_pm_flush, ipa_ctx);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302256 qdf_spinlock_create(&ipa_ctx->pm_lock);
2257 qdf_spinlock_create(&ipa_ctx->q_lock);
2258 qdf_nbuf_queue_init(&ipa_ctx->pm_queue_head);
2259 qdf_list_create(&ipa_ctx->pending_event, 1000);
2260 qdf_mutex_create(&ipa_ctx->event_lock);
2261 qdf_mutex_create(&ipa_ctx->ipa_lock);
2262
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302263 status = wlan_ipa_wdi_setup_rm(ipa_ctx);
2264 if (status != QDF_STATUS_SUCCESS)
2265 goto fail_setup_rm;
2266
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302267 for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++)
2268 qdf_mem_zero(&ipa_ctx->sys_pipe[i],
2269 sizeof(struct wlan_ipa_sys_pipe));
2270
2271 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
2272 qdf_mem_zero(&ipa_ctx->stats, sizeof(ipa_ctx->stats));
2273 ipa_ctx->sap_num_connected_sta = 0;
2274 ipa_ctx->ipa_tx_packets_diff = 0;
2275 ipa_ctx->ipa_rx_packets_diff = 0;
2276 ipa_ctx->ipa_p_tx_packets = 0;
2277 ipa_ctx->ipa_p_rx_packets = 0;
2278 ipa_ctx->resource_loading = false;
2279 ipa_ctx->resource_unloading = false;
2280 ipa_ctx->sta_connected = 0;
2281 ipa_ctx->ipa_pipes_down = true;
2282 ipa_ctx->wdi_enabled = false;
2283 /* Setup IPA system pipes */
2284 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
2285 ret = wlan_ipa_setup_sys_pipe(ipa_ctx);
2286 if (ret)
2287 goto fail_create_sys_pipe;
jiadbb47e132018-03-30 16:28:30 +08002288
2289 qdf_create_work(0, &ipa_ctx->mcc_work,
2290 wlan_ipa_mcc_work_handler, ipa_ctx);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302291 }
2292
2293 status = wlan_ipa_wdi_init(ipa_ctx);
2294 if (status == QDF_STATUS_E_BUSY)
2295 status = wlan_ipa_uc_send_wdi_control_msg(false);
2296 if (status != QDF_STATUS_SUCCESS) {
2297 ipa_err("IPA WDI init failed: ret=%d", ret);
2298 goto fail_create_sys_pipe;
2299 }
2300 } else {
2301 ret = wlan_ipa_setup_sys_pipe(ipa_ctx);
2302 if (ret)
2303 goto fail_create_sys_pipe;
2304 }
2305
2306 qdf_event_create(&ipa_ctx->ipa_resource_comp);
2307
2308 ipa_debug("exit: success");
2309
2310 return QDF_STATUS_SUCCESS;
2311
2312fail_create_sys_pipe:
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302313 wlan_ipa_wdi_destroy_rm(ipa_ctx);
2314
2315fail_setup_rm:
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302316 qdf_spinlock_destroy(&ipa_ctx->pm_lock);
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302317 qdf_spinlock_destroy(&ipa_ctx->q_lock);
2318 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2319 iface_context = &ipa_ctx->iface_context[i];
2320 qdf_spinlock_destroy(&iface_context->interface_lock);
2321 }
2322 qdf_mutex_destroy(&ipa_ctx->event_lock);
2323 qdf_mutex_destroy(&ipa_ctx->ipa_lock);
2324 qdf_list_destroy(&ipa_ctx->pending_event);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302325 gp_ipa = NULL;
2326 ipa_debug("exit: fail");
2327
2328 return QDF_STATUS_E_FAILURE;
2329}
2330
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302331void wlan_ipa_flush(struct wlan_ipa_priv *ipa_ctx)
2332{
2333 qdf_nbuf_t skb;
2334 struct wlan_ipa_pm_tx_cb *pm_tx_cb;
2335
2336 if (!wlan_ipa_is_enabled(ipa_ctx->config))
2337 return;
2338
2339 qdf_cancel_work(&ipa_ctx->pm_work);
2340
2341 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
2342
2343 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head))
2344 != NULL)) {
2345 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
2346
2347 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
jiadab8cea02018-05-24 09:16:14 +08002348
2349 if (pm_tx_cb->exception) {
2350 dev_kfree_skb_any(skb);
2351 } else {
2352 if (pm_tx_cb->ipa_tx_desc)
2353 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
2354 }
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302355
2356 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
2357 }
2358 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
2359}
2360
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302361QDF_STATUS wlan_ipa_cleanup(struct wlan_ipa_priv *ipa_ctx)
2362{
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302363 struct wlan_ipa_iface_context *iface_context;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302364 int i;
2365
2366 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config))
2367 wlan_ipa_teardown_sys_pipe(ipa_ctx);
2368
2369 /* Teardown IPA sys_pipe for MCC */
jiadbb47e132018-03-30 16:28:30 +08002370 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302371 wlan_ipa_teardown_sys_pipe(ipa_ctx);
jiadbb47e132018-03-30 16:28:30 +08002372 qdf_cancel_work(&ipa_ctx->mcc_work);
2373 }
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302374
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302375 wlan_ipa_wdi_destroy_rm(ipa_ctx);
2376
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302377 wlan_ipa_flush(ipa_ctx);
2378
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302379 qdf_spinlock_destroy(&ipa_ctx->pm_lock);
2380 qdf_spinlock_destroy(&ipa_ctx->q_lock);
2381
2382 /* destroy the interface lock */
2383 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2384 iface_context = &ipa_ctx->iface_context[i];
2385 qdf_spinlock_destroy(&iface_context->interface_lock);
2386 }
2387
2388 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
2389 wlan_ipa_wdi_cleanup();
2390 qdf_mutex_destroy(&ipa_ctx->event_lock);
2391 qdf_mutex_destroy(&ipa_ctx->ipa_lock);
2392 qdf_list_destroy(&ipa_ctx->pending_event);
2393
2394 }
2395
2396 gp_ipa = NULL;
2397
2398 return QDF_STATUS_SUCCESS;
2399}
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05302400
2401struct wlan_ipa_iface_context
2402*wlan_ipa_get_iface(struct wlan_ipa_priv *ipa_ctx, uint8_t mode)
2403{
2404 struct wlan_ipa_iface_context *iface_ctx = NULL;
2405 int i;
2406
2407 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2408 iface_ctx = &ipa_ctx->iface_context[i];
2409
2410 if (iface_ctx->device_mode == mode)
2411 return iface_ctx;
2412 }
2413
2414 return NULL;
2415}
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302416
jiadbb47e132018-03-30 16:28:30 +08002417void wlan_ipa_set_mcc_mode(struct wlan_ipa_priv *ipa_ctx, bool mcc_mode)
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302418{
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302419 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config))
jiadbb47e132018-03-30 16:28:30 +08002420 return;
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302421
jiadbb47e132018-03-30 16:28:30 +08002422 if (ipa_ctx->mcc_mode == mcc_mode)
2423 return;
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302424
jiadbb47e132018-03-30 16:28:30 +08002425 ipa_ctx->mcc_mode = mcc_mode;
2426 qdf_sched_work(0, &ipa_ctx->mcc_work);
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302427}
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302428
2429/**
2430 * wlan_ipa_uc_loaded_handler() - Process IPA uC loaded indication
2431 * @ipa_ctx: ipa ipa local context
2432 *
2433 * Will handle IPA UC image loaded indication comes from IPA kernel
2434 *
2435 * Return: None
2436 */
2437static void wlan_ipa_uc_loaded_handler(struct wlan_ipa_priv *ipa_ctx)
2438{
2439 struct wlan_objmgr_pdev *pdev = ipa_ctx->pdev;
2440 struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev);
2441 qdf_device_t qdf_dev = wlan_psoc_get_qdf_dev(psoc);
2442 QDF_STATUS status;
2443
2444 ipa_info("UC READY");
2445 if (true == ipa_ctx->uc_loaded) {
2446 ipa_info("UC already loaded");
2447 return;
2448 }
2449
Lihua Liu15f6e452018-05-30 17:31:06 +08002450 if (!qdf_dev) {
2451 ipa_err("qdf_dev is null");
2452 return;
2453 }
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302454 /* Connect pipe */
2455 status = wlan_ipa_wdi_setup(ipa_ctx, qdf_dev);
2456 if (status) {
2457 ipa_err("Failure to setup IPA pipes (status=%d)",
2458 status);
2459 return;
2460 }
2461
2462 cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, ipa_ctx->dp_pdev);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302463
2464 /* If already any STA connected, enable IPA/FW PIPEs */
2465 if (ipa_ctx->sap_num_connected_sta) {
2466 ipa_debug("Client already connected, enable IPA/FW PIPEs");
2467 wlan_ipa_uc_handle_first_con(ipa_ctx);
2468 }
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302469}
2470
2471/**
2472 * wlan_ipa_uc_op_cb() - IPA uC operation callback
2473 * @op_msg: operation message received from firmware
2474 * @usr_ctxt: user context registered with TL (we register the IPA Global
2475 * context)
2476 *
2477 * Return: None
2478 */
2479static void wlan_ipa_uc_op_cb(struct op_msg_type *op_msg,
2480 struct wlan_ipa_priv *ipa_ctx)
2481{
2482 struct op_msg_type *msg = op_msg;
2483 struct ipa_uc_fw_stats *uc_fw_stat;
2484
2485 if (!op_msg) {
2486 ipa_err("INVALID ARG");
2487 return;
2488 }
2489
2490 if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) {
2491 ipa_err("INVALID OPCODE %d", msg->op_code);
2492 qdf_mem_free(op_msg);
2493 return;
2494 }
2495
2496 ipa_debug("OPCODE=%d", msg->op_code);
2497
2498 if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_RESUME) ||
2499 (msg->op_code == WLAN_IPA_UC_OPCODE_RX_RESUME)) {
2500 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2501 ipa_ctx->activated_fw_pipe++;
Yun Parka29974a2018-04-09 12:05:49 -07002502 if (wlan_ipa_is_fw_wdi_activated(ipa_ctx)) {
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302503 ipa_ctx->resource_loading = false;
2504 qdf_event_set(&ipa_ctx->ipa_resource_comp);
2505 if (ipa_ctx->wdi_enabled == false) {
2506 ipa_ctx->wdi_enabled = true;
2507 if (wlan_ipa_uc_send_wdi_control_msg(true) == 0)
2508 wlan_ipa_send_mcc_scc_msg(ipa_ctx,
2509 ipa_ctx->mcc_mode);
2510 }
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302511 wlan_ipa_uc_proc_pending_event(ipa_ctx, true);
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302512 if (ipa_ctx->pending_cons_req)
Yun Parke114fbf2018-04-05 20:02:12 -07002513 wlan_ipa_wdi_rm_notify_completion(
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302514 QDF_IPA_RM_RESOURCE_GRANTED,
2515 QDF_IPA_RM_RESOURCE_WLAN_CONS);
2516 ipa_ctx->pending_cons_req = false;
2517 }
2518 qdf_mutex_release(&ipa_ctx->ipa_lock);
2519 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_SUSPEND) ||
2520 (msg->op_code == WLAN_IPA_UC_OPCODE_RX_SUSPEND)) {
2521 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2522 ipa_ctx->activated_fw_pipe--;
2523 if (!ipa_ctx->activated_fw_pipe) {
2524 /*
2525 * Async return success from FW
2526 * Disable/suspend all the PIPEs
2527 */
2528 ipa_ctx->resource_unloading = false;
2529 qdf_event_set(&ipa_ctx->ipa_resource_comp);
2530 wlan_ipa_uc_disable_pipes(ipa_ctx);
2531 if (wlan_ipa_is_rm_enabled(ipa_ctx->config))
Yun Parke114fbf2018-04-05 20:02:12 -07002532 wlan_ipa_wdi_rm_release_resource(ipa_ctx,
2533 QDF_IPA_RM_RESOURCE_WLAN_PROD);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302534 wlan_ipa_uc_proc_pending_event(ipa_ctx, false);
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302535 ipa_ctx->pending_cons_req = false;
2536 }
2537 qdf_mutex_release(&ipa_ctx->ipa_lock);
2538 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) &&
2539 (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_DEBUG)) {
2540 uc_fw_stat = (struct ipa_uc_fw_stats *)
2541 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2542
2543 /* WLAN FW WDI stats */
2544 wlan_ipa_print_fw_wdi_stats(ipa_ctx, uc_fw_stat);
2545 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) &&
2546 (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_BW_CAL)) {
2547 /* STATs from FW */
2548 uc_fw_stat = (struct ipa_uc_fw_stats *)
2549 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2550 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2551 ipa_ctx->ipa_tx_packets_diff = BW_GET_DIFF(
2552 uc_fw_stat->tx_pkts_completed,
2553 ipa_ctx->ipa_p_tx_packets);
2554 ipa_ctx->ipa_rx_packets_diff = BW_GET_DIFF(
2555 (uc_fw_stat->rx_num_ind_drop_no_space +
2556 uc_fw_stat->rx_num_ind_drop_no_buf +
2557 uc_fw_stat->rx_num_pkts_indicated),
2558 ipa_ctx->ipa_p_rx_packets);
2559
2560 ipa_ctx->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2561 ipa_ctx->ipa_p_rx_packets =
2562 (uc_fw_stat->rx_num_ind_drop_no_space +
2563 uc_fw_stat->rx_num_ind_drop_no_buf +
2564 uc_fw_stat->rx_num_pkts_indicated);
2565 qdf_mutex_release(&ipa_ctx->ipa_lock);
2566 } else if (msg->op_code == WLAN_IPA_UC_OPCODE_UC_READY) {
2567 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2568 wlan_ipa_uc_loaded_handler(ipa_ctx);
2569 qdf_mutex_release(&ipa_ctx->ipa_lock);
2570 } else if (wlan_ipa_uc_op_metering(ipa_ctx, op_msg)) {
2571 ipa_err("Invalid message: op_code=%d, reason=%d",
2572 msg->op_code, ipa_ctx->stat_req_reason);
2573 }
2574
2575 qdf_mem_free(op_msg);
2576}
2577
2578/**
2579 * wlan_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2580 * @work: uC OP work
2581 *
2582 * Return: None
2583 */
2584static void wlan_ipa_uc_fw_op_event_handler(void *data)
2585{
2586 struct op_msg_type *msg;
2587 struct uc_op_work_struct *uc_op_work =
2588 (struct uc_op_work_struct *)data;
2589 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
2590
2591 msg = uc_op_work->msg;
2592 uc_op_work->msg = NULL;
2593 ipa_debug("posted msg %d", msg->op_code);
2594
2595 wlan_ipa_uc_op_cb(msg, ipa_ctx);
2596}
2597
2598/**
2599 * wlan_ipa_uc_op_event_handler() - IPA UC OP event handler
2600 * @op_msg: operation message received from firmware
2601 * @ipa_ctx: Global IPA context
2602 *
2603 * Return: None
2604 */
2605static void wlan_ipa_uc_op_event_handler(uint8_t *op_msg, void *ctx)
2606{
2607 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)ctx;
2608 struct op_msg_type *msg;
2609 struct uc_op_work_struct *uc_op_work;
2610
2611 if (!ipa_ctx)
2612 goto end;
2613
2614 msg = (struct op_msg_type *)op_msg;
2615
2616 if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) {
2617 ipa_err("Invalid OP Code (%d)", msg->op_code);
2618 goto end;
2619 }
2620
2621 uc_op_work = &ipa_ctx->uc_op_work[msg->op_code];
2622 if (uc_op_work->msg) {
2623 /* When the same uC OPCODE is already pended, just return */
2624 goto end;
2625 }
2626
2627 uc_op_work->msg = msg;
2628 qdf_sched_work(0, &uc_op_work->work);
2629 return;
2630
2631end:
2632 qdf_mem_free(op_msg);
2633}
2634
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302635QDF_STATUS wlan_ipa_uc_ol_init(struct wlan_ipa_priv *ipa_ctx,
2636 qdf_device_t osdev)
2637{
2638 uint8_t i;
2639 QDF_STATUS status = QDF_STATUS_SUCCESS;
2640
2641 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config))
2642 return QDF_STATUS_SUCCESS;
2643
2644 ipa_debug("enter");
2645
2646 for (i = 0; i < WLAN_IPA_MAX_SESSION; i++) {
2647 ipa_ctx->vdev_to_iface[i] = WLAN_IPA_MAX_SESSION;
2648 ipa_ctx->vdev_offload_enabled[i] = false;
2649 }
2650
2651 /* Set the lowest bandwidth to start with */
2652 status = wlan_ipa_set_perf_level(ipa_ctx, 0, 0);
2653 if (status != QDF_STATUS_SUCCESS) {
2654 ipa_err("Set perf level failed: %d", status);
Yun Parke114fbf2018-04-05 20:02:12 -07002655 wlan_ipa_wdi_rm_inactivity_timer_destroy(
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302656 QDF_IPA_RM_RESOURCE_WLAN_PROD);
2657 goto fail_return;
2658 }
2659
2660 if (cdp_ipa_get_resource(ipa_ctx->dp_soc, ipa_ctx->dp_pdev)) {
2661 ipa_err("IPA UC resource alloc fail");
2662 status = QDF_STATUS_E_FAILURE;
2663 goto fail_return;
2664 }
2665
2666 if (true == ipa_ctx->uc_loaded) {
2667 status = wlan_ipa_wdi_setup(ipa_ctx, osdev);
2668 if (status) {
2669 ipa_err("Failure to setup IPA pipes (status=%d)",
2670 status);
2671 status = QDF_STATUS_E_FAILURE;
2672 goto fail_return;
2673 }
2674
2675 cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, ipa_ctx->dp_pdev);
2676 wlan_ipa_init_metering(ipa_ctx);
2677 }
2678
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302679 cdp_ipa_register_op_cb(ipa_ctx->dp_soc, ipa_ctx->dp_pdev,
2680 wlan_ipa_uc_op_event_handler, (void *)ipa_ctx);
2681
2682 for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) {
2683 qdf_create_work(0, &ipa_ctx->uc_op_work[i].work,
2684 wlan_ipa_uc_fw_op_event_handler,
2685 &ipa_ctx->uc_op_work[i]);
2686 ipa_ctx->uc_op_work[i].msg = NULL;
2687 }
2688
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302689fail_return:
2690 ipa_debug("exit: status=%d", status);
2691 return status;
2692}
2693
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302694/**
2695 * wlan_ipa_cleanup_pending_event() - Cleanup IPA pending event list
2696 * @ipa_ctx: pointer to IPA IPA struct
2697 *
2698 * Return: none
2699 */
2700static void wlan_ipa_cleanup_pending_event(struct wlan_ipa_priv *ipa_ctx)
2701{
2702 struct wlan_ipa_uc_pending_event *pending_event = NULL;
2703
2704 while (qdf_list_remove_front(&ipa_ctx->pending_event,
2705 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS)
2706 qdf_mem_free(pending_event);
2707}
2708
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302709QDF_STATUS wlan_ipa_uc_ol_deinit(struct wlan_ipa_priv *ipa_ctx)
2710{
2711 QDF_STATUS status = QDF_STATUS_SUCCESS;
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302712 int i;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302713
2714 ipa_debug("enter");
2715
2716 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config))
2717 return status;
2718
2719 if (!ipa_ctx->ipa_pipes_down)
2720 wlan_ipa_uc_disable_pipes(ipa_ctx);
2721
2722 if (true == ipa_ctx->uc_loaded) {
2723 status = cdp_ipa_cleanup(ipa_ctx->dp_soc,
2724 ipa_ctx->tx_pipe_handle,
2725 ipa_ctx->rx_pipe_handle);
2726 if (status)
2727 ipa_err("Failure to cleanup IPA pipes (status=%d)",
2728 status);
2729 }
2730
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302731 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2732 wlan_ipa_cleanup_pending_event(ipa_ctx);
2733 qdf_mutex_release(&ipa_ctx->ipa_lock);
2734
2735 for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) {
2736 qdf_cancel_work(&ipa_ctx->uc_op_work[i].work);
2737 qdf_mem_free(ipa_ctx->uc_op_work[i].msg);
2738 ipa_ctx->uc_op_work[i].msg = NULL;
2739 }
2740
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302741 ipa_debug("exit: ret=%d", status);
2742 return status;
2743}
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +05302744
Yun Parka29974a2018-04-09 12:05:49 -07002745/**
2746 * wlan_ipa_is_fw_wdi_activated() - Is FW WDI actived?
2747 * @ipa_ctx: IPA contex
2748 *
2749 * Return: true if FW WDI actived, false otherwise
2750 */
2751bool wlan_ipa_is_fw_wdi_activated(struct wlan_ipa_priv *ipa_ctx)
2752{
2753 return (WLAN_IPA_UC_NUM_WDI_PIPE == ipa_ctx->activated_fw_pipe);
2754}
2755