blob: e9a3a49395a8c1179210e4aebd7087388ae2df2f [file] [log] [blame]
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301/*
Sravan Kumar Kairam78870222018-12-31 12:47:17 +05302 * Copyright (c) 2013-2019 The Linux Foundation. All rights reserved.
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05303 *
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"
Sravan Kumar Kairamce792eb2018-06-15 15:07:11 +053025#include "qdf_str.h"
Jeff Johnson8feaa632018-12-07 11:56:02 -080026#include "sir_api.h"
27#include "host_diag_core_event.h"
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +053028
29static struct wlan_ipa_priv *gp_ipa;
30
31static struct wlan_ipa_iface_2_client {
32 qdf_ipa_client_type_t cons_client;
33 qdf_ipa_client_type_t prod_client;
34} wlan_ipa_iface_2_client[WLAN_IPA_MAX_IFACE] = {
35 {
36 QDF_IPA_CLIENT_WLAN2_CONS, QDF_IPA_CLIENT_WLAN1_PROD
37 }, {
38 QDF_IPA_CLIENT_WLAN3_CONS, QDF_IPA_CLIENT_WLAN1_PROD
39 }, {
40 QDF_IPA_CLIENT_WLAN4_CONS, QDF_IPA_CLIENT_WLAN1_PROD
41 }
42};
43
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +053044/* Local Function Prototypes */
45static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
46 unsigned long data);
47static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
48 unsigned long data);
49
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +053050/**
51 * wlan_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
52 * @ipa_cfg: IPA config
53 *
54 * Return: true if STA mode IPA uC offload is enabled, false otherwise
55 */
56static inline bool wlan_ipa_uc_sta_is_enabled(struct wlan_ipa_config *ipa_cfg)
57{
58 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_UC_STA_ENABLE_MASK);
59}
60
61/**
62 * wlan_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
63 * @ipa_cfg: IPA config
64 *
65 * Return: true if pre-filter is enabled, otherwise false
66 */
67static inline
68bool wlan_ipa_is_pre_filter_enabled(struct wlan_ipa_config *ipa_cfg)
69{
70 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg,
71 WLAN_IPA_PRE_FILTER_ENABLE_MASK);
72}
73
74/**
75 * wlan_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
76 * @ipa_cfg: IPA config
77 *
78 * Return: true if IPv6 is enabled, otherwise false
79 */
80static inline bool wlan_ipa_is_ipv6_enabled(struct wlan_ipa_config *ipa_cfg)
81{
82 return WLAN_IPA_IS_CONFIG_ENABLED(ipa_cfg, WLAN_IPA_IPV6_ENABLE_MASK);
83}
84
85/**
86 * wlan_ipa_msg_free_fn() - Free an IPA message
87 * @buff: pointer to the IPA message
88 * @len: length of the IPA message
89 * @type: type of IPA message
90 *
91 * Return: None
92 */
93static void wlan_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
94{
95 ipa_debug("msg type:%d, len:%d", type, len);
96 qdf_mem_free(buff);
97}
98
99/**
100 * wlan_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
101 * @priv_ctxt: IPA context
102 *
103 * Will be called by IPA context.
104 * It's atomic context, then should be scheduled to kworker thread
105 *
106 * Return: None
107 */
108static void wlan_ipa_uc_loaded_uc_cb(void *priv_ctxt)
109{
110 struct wlan_ipa_priv *ipa_ctx;
111 struct op_msg_type *msg;
112 struct uc_op_work_struct *uc_op_work;
113
114 if (!priv_ctxt) {
115 ipa_err("Invalid IPA context");
116 return;
117 }
118
119 ipa_ctx = priv_ctxt;
Sravan Kumar Kairam7eb6e4c2018-04-26 15:35:47 +0530120 ipa_ctx->uc_loaded = true;
121
122 uc_op_work = &ipa_ctx->uc_op_work[WLAN_IPA_UC_OPCODE_UC_READY];
123 if (!list_empty(&uc_op_work->work.work.entry)) {
124 /* uc_op_work is not initialized yet */
125 return;
126 }
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530127
128 msg = qdf_mem_malloc(sizeof(*msg));
129 if (!msg) {
130 ipa_err("op_msg allocation fails");
131 return;
132 }
133
134 msg->op_code = WLAN_IPA_UC_OPCODE_UC_READY;
135
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530136 /* When the same uC OPCODE is already pended, just return */
137 if (uc_op_work->msg)
138 goto done;
139
140 uc_op_work->msg = msg;
141 qdf_sched_work(0, &uc_op_work->work);
Sravan Kumar Kairam7eb6e4c2018-04-26 15:35:47 +0530142
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530143 /* work handler will free the msg buffer */
144 return;
145
146done:
147 qdf_mem_free(msg);
148}
149
150/**
151 * wlan_ipa_uc_send_wdi_control_msg() - Set WDI control message
152 * @ctrl: WDI control value
153 *
154 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
155 *
156 * Return: QDF_STATUS
157 */
158static QDF_STATUS wlan_ipa_uc_send_wdi_control_msg(bool ctrl)
159{
jiad629b2172018-05-11 15:34:22 +0800160 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530161 qdf_ipa_msg_meta_t meta;
162 qdf_ipa_wlan_msg_t *ipa_msg;
163 int ret = 0;
164
165 /* WDI enable message to IPA */
166 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*ipa_msg);
167 ipa_msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
168 if (!ipa_msg) {
169 ipa_err("msg allocation failed");
170 return QDF_STATUS_E_NOMEM;
171 }
172
jiad629b2172018-05-11 15:34:22 +0800173 if (ctrl) {
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530174 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_ENABLE);
jiad629b2172018-05-11 15:34:22 +0800175 ipa_ctx->stats.event[QDF_WDI_ENABLE]++;
176 } else {
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530177 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_WDI_DISABLE);
jiad629b2172018-05-11 15:34:22 +0800178 ipa_ctx->stats.event[QDF_WDI_DISABLE]++;
179 }
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530180
181 ipa_debug("ipa_send_msg(Evt:%d)", QDF_IPA_MSG_META_MSG_TYPE(&meta));
182 ret = qdf_ipa_send_msg(&meta, ipa_msg, wlan_ipa_msg_free_fn);
183 if (ret) {
184 ipa_err("ipa_send_msg(Evt:%d)-fail=%d",
185 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
186 qdf_mem_free(ipa_msg);
187 return QDF_STATUS_E_FAILURE;
188 }
189
190 return QDF_STATUS_SUCCESS;
191}
192
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +0530193struct wlan_ipa_priv *wlan_ipa_get_obj_context(void)
194{
195 return gp_ipa;
196}
197
Yun Parke74e6092018-04-27 11:36:34 -0700198/**
199 * wlan_ipa_send_pkt_to_tl() - Send an IPA packet to TL
200 * @iface_context: interface-specific IPA context
201 * @ipa_tx_desc: packet data descriptor
202 *
203 * Return: None
204 */
205static void wlan_ipa_send_pkt_to_tl(
206 struct wlan_ipa_iface_context *iface_context,
207 qdf_ipa_rx_data_t *ipa_tx_desc)
208{
209 struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx;
210 qdf_nbuf_t skb;
211 struct wlan_ipa_tx_desc *tx_desc;
212
213 qdf_spin_lock_bh(&iface_context->interface_lock);
214 /*
215 * During CAC period, data packets shouldn't be sent over the air so
216 * drop all the packets here
217 */
218 if (iface_context->device_mode == QDF_SAP_MODE ||
219 iface_context->device_mode == QDF_P2P_GO_MODE) {
220 if (ipa_ctx->dfs_cac_block_tx) {
221 ipa_free_skb(ipa_tx_desc);
222 qdf_spin_unlock_bh(&iface_context->interface_lock);
223 iface_context->stats.num_tx_cac_drop++;
224 wlan_ipa_wdi_rm_try_release(ipa_ctx);
225 return;
226 }
227 }
228 qdf_spin_unlock_bh(&iface_context->interface_lock);
229
230 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc);
231
hangtian127c9532019-01-12 13:29:07 +0800232 qdf_mem_zero(skb->cb, sizeof(skb->cb));
Yun Parke74e6092018-04-27 11:36:34 -0700233
234 /* Store IPA Tx buffer ownership into SKB CB */
235 qdf_nbuf_ipa_owned_set(skb);
236 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
237 qdf_nbuf_mapped_paddr_set(skb,
jiadaf210c02018-11-20 09:40:34 +0800238 QDF_IPA_RX_DATA_DMA_ADDR(ipa_tx_desc)
239 + WLAN_IPA_WLAN_FRAG_HEADER
240 + WLAN_IPA_WLAN_IPA_HEADER);
Yun Parke74e6092018-04-27 11:36:34 -0700241 QDF_IPA_RX_DATA_SKB_LEN(ipa_tx_desc) -=
242 WLAN_IPA_WLAN_FRAG_HEADER + WLAN_IPA_WLAN_IPA_HEADER;
jiadaf210c02018-11-20 09:40:34 +0800243 } else
244 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Yun Parke74e6092018-04-27 11:36:34 -0700245
246 qdf_spin_lock_bh(&ipa_ctx->q_lock);
247 /* get free Tx desc and assign ipa_tx_desc pointer */
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +0530248 if (qdf_list_remove_front(&ipa_ctx->tx_desc_free_list,
249 (qdf_list_node_t **)&tx_desc) ==
Yun Parke74e6092018-04-27 11:36:34 -0700250 QDF_STATUS_SUCCESS) {
251 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
252 ipa_ctx->stats.num_tx_desc_q_cnt++;
253 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
254 /* Store Tx Desc index into SKB CB */
255 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
256 } else {
257 ipa_ctx->stats.num_tx_desc_error++;
258 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
259 qdf_ipa_free_skb(ipa_tx_desc);
260 wlan_ipa_wdi_rm_try_release(ipa_ctx);
261 return;
262 }
263
264 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
265 (struct cdp_vdev *)iface_context->tl_context,
266 QDF_IPA_RX_DATA_SKB(ipa_tx_desc));
267 if (skb) {
268 qdf_nbuf_free(skb);
269 iface_context->stats.num_tx_err++;
270 return;
271 }
272
273 atomic_inc(&ipa_ctx->tx_ref_cnt);
274
275 iface_context->stats.num_tx++;
276}
277
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530278#ifdef CONFIG_IPA_WDI_UNIFIED_API
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530279/*
280 * TODO: Get WDI version through FW capabilities
281 */
Mohit Khannacabf5e72018-07-24 13:28:43 -0700282#if defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCA6390)
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530283static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
284{
285 ipa_ctx->wdi_version = IPA_WDI_3;
286}
287#elif defined(QCA_WIFI_3_0)
288static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
289{
290 ipa_ctx->wdi_version = IPA_WDI_2;
291}
292#else
293static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
294{
295 ipa_ctx->wdi_version = IPA_WDI_1;
296}
297#endif
298
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530299static inline bool wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx,
300 qdf_device_t osdev)
301{
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +0530302 return ipa_ctx->is_smmu_enabled && qdf_mem_smmu_s1_enabled(osdev);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530303}
304
305static inline QDF_STATUS wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx,
306 qdf_device_t osdev)
307{
308 qdf_ipa_sys_connect_params_t sys_in[WLAN_IPA_MAX_IFACE];
309 int i;
310
311 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++)
312 qdf_mem_copy(&sys_in[i],
313 &ipa_ctx->sys_pipe[i].ipa_sys_params,
314 sizeof(qdf_ipa_sys_connect_params_t));
315
316 return cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev,
317 wlan_ipa_i2w_cb, wlan_ipa_w2i_cb,
318 wlan_ipa_wdi_meter_notifier_cb,
319 ipa_ctx->config->desc_size,
320 ipa_ctx, wlan_ipa_is_rm_enabled(ipa_ctx->config),
321 &ipa_ctx->tx_pipe_handle,
322 &ipa_ctx->rx_pipe_handle,
323 wlan_ipa_wdi_is_smmu_enabled(ipa_ctx, osdev),
324 sys_in);
325}
326
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +0530327#ifdef FEATURE_METERING
328/**
329 * wlan_ipa_wdi_init_metering() - IPA WDI metering init
330 * @ipa_ctx: IPA context
331 * @in: IPA WDI in param
332 *
333 * Return: QDF_STATUS
334 */
335static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt,
336 qdf_ipa_wdi_init_in_params_t *in)
337{
338 QDF_IPA_WDI_INIT_IN_PARAMS_WDI_NOTIFY(in) =
339 wlan_ipa_wdi_meter_notifier_cb;
340}
341#else
342static inline void wlan_ipa_wdi_init_metering(struct wlan_ipa_priv *ipa_ctxt,
343 qdf_ipa_wdi_init_in_params_t *in)
344{
345}
346#endif
347
348/**
349 * wlan_ipa_wdi_init() - IPA WDI init
350 * @ipa_ctx: IPA context
351 *
352 * Return: QDF_STATUS
353 */
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530354static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx)
355{
356 qdf_ipa_wdi_init_in_params_t in;
357 qdf_ipa_wdi_init_out_params_t out;
358 int ret;
359
360 ipa_ctx->uc_loaded = false;
361
Sravan Kumar Kairameab90a02018-10-03 17:24:57 +0530362 qdf_mem_zero(&in, sizeof(in));
363 qdf_mem_zero(&out, sizeof(out));
364
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530365 QDF_IPA_WDI_INIT_IN_PARAMS_WDI_VERSION(&in) = ipa_ctx->wdi_version;
366 QDF_IPA_WDI_INIT_IN_PARAMS_NOTIFY(&in) = wlan_ipa_uc_loaded_uc_cb;
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +0530367 QDF_IPA_WDI_INIT_IN_PARAMS_PRIV(&in) = ipa_ctx;
368 wlan_ipa_wdi_init_metering(ipa_ctx, &in);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530369
370 ret = qdf_ipa_wdi_init(&in, &out);
371 if (ret) {
372 ipa_err("ipa_wdi_init failed with ret=%d", ret);
373 return QDF_STATUS_E_FAILURE;
374 }
375
376 if (QDF_IPA_WDI_INIT_OUT_PARAMS_IS_UC_READY(&out)) {
Dustin Brown7e761c72018-07-31 13:50:17 -0700377 ipa_debug("IPA uC READY");
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530378 ipa_ctx->uc_loaded = true;
379 ipa_ctx->is_smmu_enabled =
380 QDF_IPA_WDI_INIT_OUT_PARAMS_IS_SMMU_ENABLED(&out);
Dustin Brown7e761c72018-07-31 13:50:17 -0700381 ipa_debug("is_smmu_enabled=%d", ipa_ctx->is_smmu_enabled);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530382 } else {
383 return QDF_STATUS_E_BUSY;
384 }
385
386 return QDF_STATUS_SUCCESS;
387}
388
389static inline int wlan_ipa_wdi_cleanup(void)
390{
391 int ret;
392
393 ret = qdf_ipa_wdi_cleanup();
394 if (ret)
395 ipa_info("ipa_wdi_cleanup failed ret=%d", ret);
396 return ret;
397}
398
399static inline int wlan_ipa_wdi_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
400 struct ipa_sys_connect_params *sys,
401 uint32_t *handle)
402{
403 return 0;
404}
405
406static inline int wlan_ipa_wdi_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
407 uint32_t handle)
408{
409 return 0;
410}
411
Yun Parke74e6092018-04-27 11:36:34 -0700412/**
413 * wlan_ipa_pm_flush() - flush queued packets
414 * @work: pointer to the scheduled work
415 *
416 * Called during PM resume to send packets to TL which were queued
417 * while host was in the process of suspending.
418 *
419 * Return: None
420 */
421static void wlan_ipa_pm_flush(void *data)
422{
423 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data;
424 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL;
425 qdf_nbuf_t skb;
426 uint32_t dequeued = 0;
427
428 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
429 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) !=
430 NULL)) {
431 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
432
433 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
434 dequeued++;
435
jiadab8cea02018-05-24 09:16:14 +0800436 if (pm_tx_cb->exception) {
437 if (ipa_ctx->softap_xmit &&
438 pm_tx_cb->iface_context->dev) {
439 ipa_ctx->softap_xmit(skb,
440 pm_tx_cb->iface_context->dev);
441 ipa_ctx->stats.num_tx_fwd_ok++;
442 } else {
443 dev_kfree_skb_any(skb);
444 }
445 } else {
446 wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
447 pm_tx_cb->ipa_tx_desc);
448 }
Yun Parke74e6092018-04-27 11:36:34 -0700449
450 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
451 }
452 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
453
454 ipa_ctx->stats.num_tx_dequeued += dequeued;
455 if (dequeued > ipa_ctx->stats.num_max_pm_queue)
456 ipa_ctx->stats.num_max_pm_queue = dequeued;
457}
458
jiadae9959f2018-05-08 11:19:07 +0800459int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
460{
461 if (!num_buf) {
462 ipa_info("No buffers to map/unmap");
463 return 0;
464 }
465
466 if (map)
467 return qdf_ipa_wdi_create_smmu_mapping(num_buf, buf_arr);
468 else
469 return qdf_ipa_wdi_release_smmu_mapping(num_buf, buf_arr);
470}
471
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530472#else /* CONFIG_IPA_WDI_UNIFIED_API */
473
474static inline void wlan_ipa_wdi_get_wdi_version(struct wlan_ipa_priv *ipa_ctx)
475{
476}
477
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +0530478static inline int wlan_ipa_wdi_is_smmu_enabled(struct wlan_ipa_priv *ipa_ctx,
479 qdf_device_t osdev)
480{
481 return qdf_mem_smmu_s1_enabled(osdev);
482}
483
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530484static inline QDF_STATUS wlan_ipa_wdi_setup(struct wlan_ipa_priv *ipa_ctx,
485 qdf_device_t osdev)
486{
487 return cdp_ipa_setup(ipa_ctx->dp_soc, ipa_ctx->dp_pdev,
488 wlan_ipa_i2w_cb, wlan_ipa_w2i_cb,
489 wlan_ipa_wdi_meter_notifier_cb,
490 ipa_ctx->config->desc_size,
491 ipa_ctx, wlan_ipa_is_rm_enabled(ipa_ctx->config),
492 &ipa_ctx->tx_pipe_handle,
493 &ipa_ctx->rx_pipe_handle);
494}
495
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530496static inline QDF_STATUS wlan_ipa_wdi_init(struct wlan_ipa_priv *ipa_ctx)
497{
498 struct ipa_wdi_uc_ready_params uc_ready_param;
499
500 ipa_ctx->uc_loaded = false;
501 uc_ready_param.priv = (void *)ipa_ctx;
502 uc_ready_param.notify = wlan_ipa_uc_loaded_uc_cb;
503 if (qdf_ipa_uc_reg_rdyCB(&uc_ready_param)) {
504 ipa_info("UC Ready CB register fail");
505 return QDF_STATUS_E_FAILURE;
506 }
507
508 if (true == uc_ready_param.is_uC_ready) {
509 ipa_info("UC Ready");
510 ipa_ctx->uc_loaded = true;
511 } else {
512 return QDF_STATUS_E_BUSY;
513 }
514
515 return QDF_STATUS_SUCCESS;
516}
517
518static inline int wlan_ipa_wdi_cleanup(void)
519{
520 int ret;
521
522 ret = qdf_ipa_uc_dereg_rdyCB();
523 if (ret)
524 ipa_info("UC Ready CB deregister fail");
525 return ret;
526}
527
528static inline int wlan_ipa_wdi_setup_sys_pipe(
529 struct wlan_ipa_priv *ipa_ctx,
530 struct ipa_sys_connect_params *sys, uint32_t *handle)
531{
532 return qdf_ipa_setup_sys_pipe(sys, handle);
533}
534
535static inline int wlan_ipa_wdi_teardown_sys_pipe(
536 struct wlan_ipa_priv *ipa_ctx,
537 uint32_t handle)
538{
539 return qdf_ipa_teardown_sys_pipe(handle);
540}
541
Yun Parke74e6092018-04-27 11:36:34 -0700542/**
543 * wlan_ipa_pm_flush() - flush queued packets
544 * @work: pointer to the scheduled work
545 *
546 * Called during PM resume to send packets to TL which were queued
547 * while host was in the process of suspending.
548 *
549 * Return: None
550 */
551static void wlan_ipa_pm_flush(void *data)
552{
553 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data;
554 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL;
555 qdf_nbuf_t skb;
556 uint32_t dequeued = 0;
557
558 qdf_wake_lock_acquire(&ipa_ctx->wake_lock,
559 WIFI_POWER_EVENT_WAKELOCK_IPA);
560 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
561 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head)) !=
562 NULL)) {
563 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
564
565 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
566 dequeued++;
567
jiadab8cea02018-05-24 09:16:14 +0800568 if (pm_tx_cb->exception) {
569 if (ipa_ctx->softap_xmit &&
570 pm_tx_cb->iface_context->dev) {
571 ipa_ctx->softap_xmit(skb,
572 pm_tx_cb->iface_context->dev);
573 ipa_ctx->stats.num_tx_fwd_ok++;
574 } else {
575 dev_kfree_skb_any(skb);
576 }
577 } else {
578 wlan_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
579 pm_tx_cb->ipa_tx_desc);
580 }
Yun Parke74e6092018-04-27 11:36:34 -0700581
582 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
583 }
584 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
585 qdf_wake_lock_release(&ipa_ctx->wake_lock,
586 WIFI_POWER_EVENT_WAKELOCK_IPA);
587
588 ipa_ctx->stats.num_tx_dequeued += dequeued;
589 if (dequeued > ipa_ctx->stats.num_max_pm_queue)
590 ipa_ctx->stats.num_max_pm_queue = dequeued;
591}
592
jiadae9959f2018-05-08 11:19:07 +0800593int wlan_ipa_uc_smmu_map(bool map, uint32_t num_buf, qdf_mem_info_t *buf_arr)
594{
595 if (!num_buf) {
596 ipa_info("No buffers to map/unmap");
597 return 0;
598 }
599
600 if (map)
601 return qdf_ipa_create_wdi_mapping(num_buf, buf_arr);
602 else
603 return qdf_ipa_release_wdi_mapping(num_buf, buf_arr);
604}
605
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +0530606#endif /* CONFIG_IPA_WDI_UNIFIED_API */
607
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530608/**
609 * wlan_ipa_send_skb_to_network() - Send skb to kernel
610 * @skb: network buffer
611 * @iface_ctx: IPA interface context
612 *
613 * Called when a network buffer is received which should not be routed
614 * to the IPA module.
615 *
616 * Return: None
617 */
618static void
619wlan_ipa_send_skb_to_network(qdf_nbuf_t skb,
620 struct wlan_ipa_iface_context *iface_ctx)
621{
622 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
623
624 if (!iface_ctx->dev) {
jiadf3ecc752018-07-05 14:36:03 +0800625 ipa_debug_rl("Invalid interface");
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530626 ipa_ctx->ipa_rx_internal_drop_count++;
jiadf3ecc752018-07-05 14:36:03 +0800627 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530628 return;
629 }
630
631 skb->destructor = wlan_ipa_uc_rt_debug_destructor;
632
633 if (ipa_ctx->send_to_nw)
634 ipa_ctx->send_to_nw(skb, iface_ctx->dev);
635
636 ipa_ctx->ipa_rx_net_send_count++;
637}
638
639/**
640 * wlan_ipa_forward() - handle packet forwarding to wlan tx
641 * @ipa_ctx: pointer to ipa ipa context
642 * @iface_ctx: interface context
643 * @skb: data pointer
644 *
645 * if exception packet has set forward bit, copied new packet should be
646 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
647 * put into pm queue and tx procedure will be differed
648 *
649 * Return: None
650 */
651static void wlan_ipa_forward(struct wlan_ipa_priv *ipa_ctx,
652 struct wlan_ipa_iface_context *iface_ctx,
653 qdf_nbuf_t skb)
654{
655 struct wlan_ipa_pm_tx_cb *pm_tx_cb;
656
657 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
658
659 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
660 qdf_nbuf_ipa_owned_set(skb);
661
662 /* WLAN subsystem is in suspend, put in queue */
663 if (ipa_ctx->suspended) {
664 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
jiadf3ecc752018-07-05 14:36:03 +0800665 ipa_info_rl("Tx in suspend, put in queue");
hangtian127c9532019-01-12 13:29:07 +0800666 qdf_mem_zero(skb->cb, sizeof(skb->cb));
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530667 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
668 pm_tx_cb->exception = true;
669 pm_tx_cb->iface_context = iface_ctx;
670 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
671 qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb);
672 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
673 ipa_ctx->stats.num_tx_queued++;
674 } else {
675 /* Resume, put packet into WLAN TX */
676 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
677
678 if (ipa_ctx->softap_xmit) {
679 if (ipa_ctx->softap_xmit(skb, iface_ctx->dev)) {
jiadf3ecc752018-07-05 14:36:03 +0800680 ipa_err_rl("packet Tx fail");
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530681 ipa_ctx->stats.num_tx_fwd_err++;
682 } else {
683 ipa_ctx->stats.num_tx_fwd_ok++;
684 }
685 } else {
jiadab8cea02018-05-24 09:16:14 +0800686 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530687 }
688 }
689}
690
691/**
692 * wlan_ipa_intrabss_forward() - Forward intra bss packets.
693 * @ipa_ctx: pointer to IPA IPA struct
694 * @iface_ctx: ipa interface context
695 * @desc: Firmware descriptor
696 * @skb: Data buffer
697 *
698 * Return:
699 * WLAN_IPA_FORWARD_PKT_NONE
700 * WLAN_IPA_FORWARD_PKT_DISCARD
701 * WLAN_IPA_FORWARD_PKT_LOCAL_STACK
702 *
703 */
704
705static enum wlan_ipa_forward_type wlan_ipa_intrabss_forward(
706 struct wlan_ipa_priv *ipa_ctx,
707 struct wlan_ipa_iface_context *iface_ctx,
708 uint8_t desc,
709 qdf_nbuf_t skb)
710{
711 int ret = WLAN_IPA_FORWARD_PKT_NONE;
712 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Sravan Kumar Kairamf48210c2018-12-17 17:48:10 +0530713 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530714
715 if ((desc & FW_RX_DESC_FORWARD_M)) {
Sravan Kumar Kairamf48210c2018-12-17 17:48:10 +0530716 void *vdev = cdp_get_vdev_from_vdev_id(soc, pdev,
717 iface_ctx->session_id);
718 if (cdp_tx_desc_thresh_reached(soc, vdev)) {
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530719 /* Drop the packet*/
720 ipa_ctx->stats.num_tx_fwd_err++;
jiadab8cea02018-05-24 09:16:14 +0800721 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530722 ret = WLAN_IPA_FORWARD_PKT_DISCARD;
723 return ret;
724 }
jiadf3ecc752018-07-05 14:36:03 +0800725 ipa_debug_rl("Forward packet to Tx (fw_desc=%d)", desc);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530726 ipa_ctx->ipa_tx_forward++;
727
728 if ((desc & FW_RX_DESC_DISCARD_M)) {
729 wlan_ipa_forward(ipa_ctx, iface_ctx, skb);
730 ipa_ctx->ipa_rx_internal_drop_count++;
731 ipa_ctx->ipa_rx_discard++;
732 ret = WLAN_IPA_FORWARD_PKT_DISCARD;
733 } else {
734 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
735
736 if (cloned_skb)
737 wlan_ipa_forward(ipa_ctx, iface_ctx,
738 cloned_skb);
739 else
jiadf3ecc752018-07-05 14:36:03 +0800740 ipa_err_rl("tx skb alloc failed");
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530741 ret = WLAN_IPA_FORWARD_PKT_LOCAL_STACK;
742 }
743 }
744
745 return ret;
746}
747
748/**
jitiphilfdcaaba2018-09-03 16:19:52 +0530749 * __wlan_ipa_w2i_cb() - WLAN to IPA callback handler
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530750 * @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 */
jitiphilfdcaaba2018-09-03 16:19:52 +0530757static void __wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
758 unsigned long data)
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530759{
760 struct wlan_ipa_priv *ipa_ctx = NULL;
761 qdf_nbuf_t skb;
762 uint8_t iface_id;
Mohit Khannacabf5e72018-07-24 13:28:43 -0700763 uint8_t session_id = 0xff;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530764 struct wlan_ipa_iface_context *iface_context;
765 uint8_t fw_desc;
766
Sravan Kumar Kairam9cd68d02019-01-14 12:51:59 +0530767 ipa_ctx = (struct wlan_ipa_priv *)priv;
768 if (!ipa_ctx) {
769 if (evt == IPA_RECEIVE) {
770 skb = (qdf_nbuf_t)data;
771 dev_kfree_skb_any(skb);
772 }
jitiphilfdcaaba2018-09-03 16:19:52 +0530773 return;
774 }
775
Sravan Kumar Kairam9cd68d02019-01-14 12:51:59 +0530776 if (qdf_is_module_state_transitioning()) {
777 ipa_err_rl("Module transition in progress");
778 if (evt == IPA_RECEIVE) {
779 skb = (qdf_nbuf_t)data;
780 ipa_ctx->ipa_rx_internal_drop_count++;
781 dev_kfree_skb_any(skb);
782 }
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530783 return;
Sravan Kumar Kairam9cd68d02019-01-14 12:51:59 +0530784 }
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530785
786 switch (evt) {
787 case IPA_RECEIVE:
788 skb = (qdf_nbuf_t) data;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530789 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
790 session_id = (uint8_t)skb->cb[0];
791 iface_id = ipa_ctx->vdev_to_iface[session_id];
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530792 } else {
793 iface_id = WLAN_IPA_GET_IFACE_ID(skb->data);
794 }
795 if (iface_id >= WLAN_IPA_MAX_IFACE) {
Mohit Khannacabf5e72018-07-24 13:28:43 -0700796 ipa_err_rl("Invalid iface_id: %u,session id: %x %x %x %x. Dropped!",
797 iface_id, session_id, (uint8_t)skb->cb[1],
798 (uint8_t)skb->cb[2], (uint8_t)skb->cb[3]);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530799 ipa_ctx->ipa_rx_internal_drop_count++;
jiadab8cea02018-05-24 09:16:14 +0800800 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530801 return;
802 }
803
804 iface_context = &ipa_ctx->iface_context[iface_id];
805 if (!iface_context->tl_context) {
jiadf3ecc752018-07-05 14:36:03 +0800806 ipa_err_rl("TL context of iface_id %u is NULL",
807 iface_id);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530808 ipa_ctx->ipa_rx_internal_drop_count++;
jiadab8cea02018-05-24 09:16:14 +0800809 dev_kfree_skb_any(skb);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530810 return;
811 }
812
813 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
814 ipa_ctx->stats.num_rx_excep++;
815 qdf_nbuf_pull_head(skb, WLAN_IPA_UC_WLAN_CLD_HDR_LEN);
816 } else {
817 qdf_nbuf_pull_head(skb, WLAN_IPA_WLAN_CLD_HDR_LEN);
818 }
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530819 iface_context->stats.num_rx_ipa_excep++;
820
821 /* Disable to forward Intra-BSS Rx packets when
822 * ap_isolate=1 in hostapd.conf
823 */
824 if (!ipa_ctx->ap_intrabss_fwd) {
825 /*
826 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
827 * all Rx packets to IPA uC, which need to be forwarded
828 * to other interface.
829 * And, IPA driver will send back to WLAN host driver
830 * through exception pipe with fw_desc field set by FW.
831 * Here we are checking fw_desc field for FORWARD bit
832 * set, and forward to Tx. Then copy to kernel stack
833 * only when DISCARD bit is not set.
834 */
835 fw_desc = (uint8_t)skb->cb[1];
836 if (WLAN_IPA_FORWARD_PKT_DISCARD ==
837 wlan_ipa_intrabss_forward(ipa_ctx, iface_context,
838 fw_desc, skb))
839 break;
840 } else {
jiadf3ecc752018-07-05 14:36:03 +0800841 ipa_debug_rl("Intra-BSS forwarding is disabled");
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530842 }
843
844 wlan_ipa_send_skb_to_network(skb, iface_context);
845 break;
846
847 default:
jiadf3ecc752018-07-05 14:36:03 +0800848 ipa_err_rl("w2i cb wrong event: 0x%x", evt);
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530849 return;
850 }
851}
852
853/**
jitiphilfdcaaba2018-09-03 16:19:52 +0530854 * wlan_ipa_w2i_cb() - SSR wrapper for __wlan_ipa_w2i_cb
855 * @priv: pointer to private data registered with IPA (we register a
856 * pointer to the global IPA context)
857 * @evt: the IPA event which triggered the callback
858 * @data: data associated with the event
859 *
860 * Return: None
861 */
862static void wlan_ipa_w2i_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
863 unsigned long data)
864{
865 qdf_ssr_protect(__func__);
866 __wlan_ipa_w2i_cb(priv, evt, data);
867 qdf_ssr_unprotect(__func__);
868}
869
870/**
871 * __wlan_ipa_i2w_cb() - IPA to WLAN callback
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530872 * @priv: pointer to private data registered with IPA (we register a
873 * pointer to the interface-specific IPA context)
874 * @evt: the IPA event which triggered the callback
875 * @data: data associated with the event
876 *
877 * Return: None
878 */
jitiphilfdcaaba2018-09-03 16:19:52 +0530879static void __wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
880 unsigned long data)
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530881{
882 struct wlan_ipa_priv *ipa_ctx = NULL;
883 qdf_ipa_rx_data_t *ipa_tx_desc;
884 struct wlan_ipa_iface_context *iface_context;
885 qdf_nbuf_t skb;
886 struct wlan_ipa_pm_tx_cb *pm_tx_cb = NULL;
887
888 iface_context = (struct wlan_ipa_iface_context *)priv;
889 ipa_tx_desc = (qdf_ipa_rx_data_t *)data;
890 ipa_ctx = iface_context->ipa_ctx;
891
Sravan Kumar Kairam9cd68d02019-01-14 12:51:59 +0530892 if (qdf_is_module_state_transitioning()) {
893 ipa_err_rl("Module transition in progress");
894 ipa_free_skb(ipa_tx_desc);
895 iface_context->stats.num_tx_drop++;
896 return;
897 }
898
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530899 if (evt != IPA_RECEIVE) {
jiadf3ecc752018-07-05 14:36:03 +0800900 ipa_err_rl("Event is not IPA_RECEIVE");
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530901 ipa_free_skb(ipa_tx_desc);
902 iface_context->stats.num_tx_drop++;
903 return;
904 }
905
906 skb = QDF_IPA_RX_DATA_SKB(ipa_tx_desc);
907
908 /*
909 * If PROD resource is not requested here then there may be cases where
910 * IPA hardware may be clocked down because of not having proper
911 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
912 * workaround to request PROD resource while data is going over CONS
913 * pipe to prevent the IPA hardware clockdown.
914 */
915 wlan_ipa_wdi_rm_request(ipa_ctx);
916
917 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
918 /*
919 * If host is still suspended then queue the packets and these will be
920 * drained later when resume completes. When packet is arrived here and
921 * host is suspended, this means that there is already resume is in
922 * progress.
923 */
924 if (ipa_ctx->suspended) {
hangtian127c9532019-01-12 13:29:07 +0800925 qdf_mem_zero(skb->cb, sizeof(skb->cb));
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530926 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
927 pm_tx_cb->iface_context = iface_context;
928 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
929 qdf_nbuf_queue_add(&ipa_ctx->pm_queue_head, skb);
930 ipa_ctx->stats.num_tx_queued++;
931
932 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
933 return;
934 }
935
936 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
937
938 /*
939 * If we are here means, host is not suspended, wait for the work queue
940 * to finish.
941 */
942 qdf_flush_work(&ipa_ctx->pm_work);
943
944 return wlan_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
945}
946
jitiphilfdcaaba2018-09-03 16:19:52 +0530947/**
948 * wlan_ipa_i2w_cb() - IPA to WLAN callback
949 * @priv: pointer to private data registered with IPA (we register a
950 * pointer to the interface-specific IPA context)
951 * @evt: the IPA event which triggered the callback
952 * @data: data associated with the event
953 *
954 * Return: None
955 */
956static void wlan_ipa_i2w_cb(void *priv, qdf_ipa_dp_evt_type_t evt,
957 unsigned long data)
958{
959 qdf_ssr_protect(__func__);
960 __wlan_ipa_i2w_cb(priv, evt, data);
961 qdf_ssr_unprotect(__func__);
962}
963
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530964QDF_STATUS wlan_ipa_suspend(struct wlan_ipa_priv *ipa_ctx)
965{
966 /*
967 * Check if IPA is ready for suspend, If we are here means, there is
968 * high chance that suspend would go through but just to avoid any race
969 * condition after suspend started, these checks are conducted before
970 * allowing to suspend.
971 */
972 if (atomic_read(&ipa_ctx->tx_ref_cnt))
973 return QDF_STATUS_E_AGAIN;
974
Yun Parke74e6092018-04-27 11:36:34 -0700975 if (!wlan_ipa_is_rm_released(ipa_ctx))
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530976 return QDF_STATUS_E_AGAIN;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +0530977
978 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
979 ipa_ctx->suspended = true;
980 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
981
982 return QDF_STATUS_SUCCESS;
983}
984
985QDF_STATUS wlan_ipa_resume(struct wlan_ipa_priv *ipa_ctx)
986{
987 qdf_sched_work(0, &ipa_ctx->pm_work);
988
989 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
990 ipa_ctx->suspended = false;
991 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
992
993 return QDF_STATUS_SUCCESS;
994}
995
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +0530996QDF_STATUS wlan_ipa_uc_enable_pipes(struct wlan_ipa_priv *ipa_ctx)
997{
998 int result;
999
1000 ipa_debug("enter");
1001
1002 if (!ipa_ctx->ipa_pipes_down) {
1003 /*
1004 * IPA WDI Pipes are already activated due to
1005 * rm deferred resources grant
1006 */
1007 ipa_warn("IPA WDI Pipes are already activated");
1008 goto end;
1009 }
1010
1011 result = cdp_ipa_enable_pipes(ipa_ctx->dp_soc,
1012 ipa_ctx->dp_pdev);
1013 if (result) {
1014 ipa_err("Enable IPA WDI PIPE failed: ret=%d", result);
1015 return QDF_STATUS_E_FAILURE;
1016 }
1017
1018 qdf_event_reset(&ipa_ctx->ipa_resource_comp);
1019 ipa_ctx->ipa_pipes_down = false;
1020
1021 cdp_ipa_enable_autonomy(ipa_ctx->dp_soc,
1022 ipa_ctx->dp_pdev);
1023
1024end:
1025 ipa_debug("exit: ipa_pipes_down=%d", ipa_ctx->ipa_pipes_down);
1026
1027 return QDF_STATUS_SUCCESS;
1028}
1029
1030QDF_STATUS wlan_ipa_uc_disable_pipes(struct wlan_ipa_priv *ipa_ctx)
1031{
1032 int result;
1033
1034 ipa_debug("enter");
1035
1036 if (ipa_ctx->ipa_pipes_down) {
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05301037 ipa_warn("IPA WDI Pipes are already deactivated");
1038 goto end;
1039 }
1040
1041 cdp_ipa_disable_autonomy(ipa_ctx->dp_soc,
1042 ipa_ctx->dp_pdev);
1043
1044 result = cdp_ipa_disable_pipes(ipa_ctx->dp_soc,
1045 ipa_ctx->dp_pdev);
1046 if (result) {
1047 ipa_err("Disable IPA WDI PIPE failed: ret=%d", result);
1048 return QDF_STATUS_E_FAILURE;
1049 }
1050
1051 ipa_ctx->ipa_pipes_down = true;
1052
1053end:
1054 ipa_debug("exit: ipa_pipes_down=%d", ipa_ctx->ipa_pipes_down);
1055
1056 return QDF_STATUS_SUCCESS;
1057}
1058
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05301059/**
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301060 * wlan_ipa_uc_find_add_assoc_sta() - Find associated station
1061 * @ipa_ctx: Global IPA IPA context
1062 * @sta_add: Should station be added
1063 * @sta_id: ID of the station being queried
1064 *
1065 * Return: true if the station was found
1066 */
1067static bool wlan_ipa_uc_find_add_assoc_sta(struct wlan_ipa_priv *ipa_ctx,
1068 bool sta_add, uint8_t sta_id,
1069 uint8_t *mac_addr)
1070{
1071 bool sta_found = false;
1072 uint8_t idx;
1073
1074 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) {
1075 if ((ipa_ctx->assoc_stas_map[idx].is_reserved) &&
1076 (ipa_ctx->assoc_stas_map[idx].sta_id == sta_id)) {
1077 sta_found = true;
1078 break;
1079 }
1080 }
1081 if (sta_add && sta_found) {
1082 ipa_err("STA ID %d already exist, cannot add", sta_id);
1083 return sta_found;
1084 }
1085 if (sta_add) {
1086 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) {
1087 if (!ipa_ctx->assoc_stas_map[idx].is_reserved) {
1088 ipa_ctx->assoc_stas_map[idx].is_reserved = true;
1089 ipa_ctx->assoc_stas_map[idx].sta_id = sta_id;
1090 qdf_mem_copy(&ipa_ctx->assoc_stas_map[idx].
1091 mac_addr, mac_addr,
1092 QDF_NET_ETH_LEN);
1093 return sta_found;
1094 }
1095 }
1096 }
1097 if (!sta_add && !sta_found) {
1098 ipa_err("STA ID %d does not exist, cannot delete", sta_id);
1099 return sta_found;
1100 }
1101 if (!sta_add) {
1102 for (idx = 0; idx < WLAN_IPA_MAX_STA_COUNT; idx++) {
1103 if ((ipa_ctx->assoc_stas_map[idx].is_reserved) &&
1104 (ipa_ctx->assoc_stas_map[idx].sta_id == sta_id)) {
1105 ipa_ctx->assoc_stas_map[idx].is_reserved =
1106 false;
1107 ipa_ctx->assoc_stas_map[idx].sta_id = 0xFF;
hangtian127c9532019-01-12 13:29:07 +08001108 qdf_mem_zero(
1109 &ipa_ctx->assoc_stas_map[idx].mac_addr,
1110 QDF_NET_ETH_LEN);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301111 return sta_found;
1112 }
1113 }
1114 }
1115
1116 return sta_found;
1117}
1118
1119/**
1120 * wlan_ipa_get_ifaceid() - Get IPA context interface ID
1121 * @ipa_ctx: IPA context
1122 * @session_id: Session ID
1123 *
1124 * Return: None
1125 */
1126static int wlan_ipa_get_ifaceid(struct wlan_ipa_priv *ipa_ctx,
1127 uint8_t session_id)
1128{
1129 struct wlan_ipa_iface_context *iface_ctx;
1130 int i;
1131
1132 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1133 iface_ctx = &ipa_ctx->iface_context[i];
1134 if (iface_ctx->session_id == session_id)
1135 break;
1136 }
1137
1138 return i;
1139}
1140
1141/**
1142 * wlan_ipa_cleanup_iface() - Cleanup IPA on a given interface
1143 * @iface_context: interface-specific IPA context
1144 *
1145 * Return: None
1146 */
1147static void wlan_ipa_cleanup_iface(struct wlan_ipa_iface_context *iface_context)
1148{
1149 struct wlan_ipa_priv *ipa_ctx = iface_context->ipa_ctx;
1150
1151 ipa_debug("enter");
1152
1153 if (!iface_context->tl_context)
1154 return;
1155
1156 cdp_ipa_cleanup_iface(ipa_ctx->dp_soc,
1157 iface_context->dev->name,
1158 wlan_ipa_is_ipv6_enabled(ipa_ctx->config));
1159
1160 qdf_spin_lock_bh(&iface_context->interface_lock);
1161 iface_context->tl_context = NULL;
1162 iface_context->dev = NULL;
1163 iface_context->device_mode = QDF_MAX_NO_OF_MODE;
1164 iface_context->session_id = WLAN_IPA_MAX_SESSION;
1165 iface_context->sta_id = WLAN_IPA_MAX_STA_COUNT;
1166 qdf_spin_unlock_bh(&iface_context->interface_lock);
1167 iface_context->ifa_address = 0;
1168 if (!iface_context->ipa_ctx->num_iface) {
1169 ipa_err("NUM INTF 0, Invalid");
1170 QDF_ASSERT(0);
1171 }
1172 iface_context->ipa_ctx->num_iface--;
1173 ipa_debug("exit: num_iface=%d", iface_context->ipa_ctx->num_iface);
1174}
1175
1176/**
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05301177 * wlan_ipa_nbuf_cb() - IPA TX complete callback
1178 * @skb: packet buffer which was transmitted
1179 *
1180 * Return: None
1181 */
1182static void wlan_ipa_nbuf_cb(qdf_nbuf_t skb)
1183{
1184 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
1185 qdf_ipa_rx_data_t *ipa_tx_desc;
1186 struct wlan_ipa_tx_desc *tx_desc;
1187 uint16_t id;
1188
1189 if (!qdf_nbuf_ipa_owned_get(skb)) {
1190 dev_kfree_skb_any(skb);
1191 return;
1192 }
1193
1194 /* Get Tx desc pointer from SKB CB */
1195 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
1196 tx_desc = &ipa_ctx->tx_desc_pool[id];
1197 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
1198
1199 /* Return Tx Desc to IPA */
1200 qdf_ipa_free_skb(ipa_tx_desc);
1201
1202 /* Return to free tx desc list */
1203 qdf_spin_lock_bh(&ipa_ctx->q_lock);
1204 tx_desc->ipa_tx_desc_ptr = NULL;
1205 qdf_list_insert_back(&ipa_ctx->tx_desc_free_list, &tx_desc->node);
1206 ipa_ctx->stats.num_tx_desc_q_cnt--;
1207 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
1208
1209 ipa_ctx->stats.num_tx_comp_cnt++;
1210
1211 qdf_atomic_dec(&ipa_ctx->tx_ref_cnt);
1212
1213 wlan_ipa_wdi_rm_try_release(ipa_ctx);
1214}
1215
1216/**
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301217 * wlan_ipa_setup_iface() - Setup IPA on a given interface
1218 * @ipa_ctx: IPA IPA global context
1219 * @net_dev: Interface net device
1220 * @device_mode: Net interface device mode
1221 * @adapter: Interface upon which IPA is being setup
1222 * @sta_id: Station ID of the API instance
1223 * @session_id: Station ID of the API instance
1224 *
1225 * Return: QDF STATUS
1226 */
1227static QDF_STATUS wlan_ipa_setup_iface(struct wlan_ipa_priv *ipa_ctx,
1228 qdf_netdev_t net_dev,
1229 uint8_t device_mode, uint8_t sta_id,
1230 uint8_t session_id)
1231{
1232 struct wlan_ipa_iface_context *iface_context = NULL;
1233 void *tl_context = NULL;
1234 int i;
1235 QDF_STATUS status;
1236
1237 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1238 * channel change indication. Since these indications are sent by lower
1239 * layer as SAP updates and IPA doesn't have to do anything for these
1240 * updates so ignoring!
1241 */
1242 if (device_mode == QDF_SAP_MODE) {
1243 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1244 iface_context = &(ipa_ctx->iface_context[i]);
Mohit Khannacabf5e72018-07-24 13:28:43 -07001245 if (iface_context->dev == net_dev) {
1246 ipa_debug("found iface %u device_mode %u",
1247 i, device_mode);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301248 return QDF_STATUS_SUCCESS;
Mohit Khannacabf5e72018-07-24 13:28:43 -07001249 }
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301250 }
1251 }
1252
Yun Park21ec4902018-04-24 12:11:01 -07001253 if (WLAN_IPA_MAX_IFACE == ipa_ctx->num_iface) {
1254 ipa_err("Max interface reached %d", WLAN_IPA_MAX_IFACE);
1255 status = QDF_STATUS_E_NOMEM;
1256 QDF_ASSERT(0);
1257 goto end;
1258 }
1259
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301260 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1261 if (ipa_ctx->iface_context[i].tl_context == NULL) {
1262 iface_context = &(ipa_ctx->iface_context[i]);
1263 break;
1264 }
1265 }
1266
1267 if (iface_context == NULL) {
1268 ipa_err("All the IPA interfaces are in use");
1269 status = QDF_STATUS_E_NOMEM;
Yun Park21ec4902018-04-24 12:11:01 -07001270 QDF_ASSERT(0);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301271 goto end;
1272 }
1273
1274 iface_context->sta_id = sta_id;
1275 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(ipa_ctx->dp_soc,
1276 ipa_ctx->dp_pdev,
1277 sta_id);
1278 if (tl_context == NULL) {
1279 ipa_err("Not able to get TL context sta_id: %d", sta_id);
1280 status = QDF_STATUS_E_INVAL;
1281 goto end;
1282 }
1283
1284 iface_context->tl_context = tl_context;
1285 iface_context->dev = net_dev;
1286 iface_context->device_mode = device_mode;
1287 iface_context->session_id = session_id;
1288
1289 status = cdp_ipa_setup_iface(ipa_ctx->dp_soc, net_dev->name,
1290 net_dev->dev_addr,
1291 iface_context->prod_client,
1292 iface_context->cons_client,
1293 session_id,
1294 wlan_ipa_is_ipv6_enabled(ipa_ctx->config));
1295 if (status != QDF_STATUS_SUCCESS)
1296 goto end;
1297
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05301298 /* Register IPA Tx desc free callback */
1299 qdf_nbuf_reg_free_cb(wlan_ipa_nbuf_cb);
1300
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301301 ipa_ctx->num_iface++;
1302
1303 ipa_debug("exit: num_iface=%d", ipa_ctx->num_iface);
1304
1305 return status;
1306
1307end:
1308 if (iface_context)
1309 wlan_ipa_cleanup_iface(iface_context);
1310
1311 return status;
1312}
1313
Sravan Kumar Kairam361f4102018-12-17 18:47:04 +05301314#if defined(QCA_WIFI_QCA6290) || defined(QCA_WIFI_QCA6390)
1315/**
1316 * wlan_ipa_uc_handle_first_con() - Handle first uC IPA connection
1317 * @ipa_ctx: IPA context
1318 *
1319 * Return: QDF STATUS
1320 */
1321static QDF_STATUS wlan_ipa_uc_handle_first_con(struct wlan_ipa_priv *ipa_ctx)
1322{
1323 ipa_debug("enter");
1324
1325 if (wlan_ipa_uc_enable_pipes(ipa_ctx) != QDF_STATUS_SUCCESS) {
1326 ipa_err("IPA WDI Pipe activation failed");
1327 return QDF_STATUS_E_BUSY;
1328 }
1329
1330 ipa_debug("exit");
1331
1332 return QDF_STATUS_SUCCESS;
1333}
1334
1335/**
1336 * wlan_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1337 * @ipa_ctx: IPA context
1338 *
1339 * Return: None
1340 */
1341static void wlan_ipa_uc_handle_last_discon(struct wlan_ipa_priv *ipa_ctx)
1342{
1343 ipa_debug("enter");
1344
1345 wlan_ipa_uc_disable_pipes(ipa_ctx);
1346
1347 ipa_debug("exit: IPA WDI Pipes deactivated");
1348}
Sravan Kumar Kairam78870222018-12-31 12:47:17 +05301349
1350bool wlan_ipa_is_fw_wdi_activated(struct wlan_ipa_priv *ipa_ctx)
1351{
1352 return !ipa_ctx->ipa_pipes_down;
1353}
Sravan Kumar Kairam361f4102018-12-17 18:47:04 +05301354#else
1355
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301356/**
1357 * wlan_ipa_uc_handle_first_con() - Handle first uC IPA connection
1358 * @ipa_ctx: IPA context
1359 *
1360 * Return: QDF STATUS
1361 */
1362static QDF_STATUS wlan_ipa_uc_handle_first_con(struct wlan_ipa_priv *ipa_ctx)
1363{
1364 ipa_debug("enter");
1365
1366 ipa_ctx->activated_fw_pipe = 0;
1367 ipa_ctx->resource_loading = true;
1368
1369 /* If RM feature enabled
1370 * Request PROD Resource first
1371 * PROD resource may return sync or async manners
1372 */
1373 if (wlan_ipa_is_rm_enabled(ipa_ctx->config)) {
Yun Parke114fbf2018-04-05 20:02:12 -07001374 if (!wlan_ipa_wdi_rm_request_resource(ipa_ctx,
1375 IPA_RM_RESOURCE_WLAN_PROD)) {
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301376 /* RM PROD request sync return
1377 * enable pipe immediately
1378 */
1379 if (wlan_ipa_uc_enable_pipes(ipa_ctx)) {
1380 ipa_err("IPA WDI Pipe activation failed");
1381 ipa_ctx->resource_loading = false;
1382 return QDF_STATUS_E_BUSY;
1383 }
1384 } else {
1385 ipa_err("IPA WDI Pipe activation deferred");
1386 }
1387 } else {
1388 /* RM Disabled
1389 * Just enabled all the PIPEs
1390 */
1391 if (wlan_ipa_uc_enable_pipes(ipa_ctx)) {
1392 ipa_err("IPA WDI Pipe activation failed");
1393 ipa_ctx->resource_loading = false;
1394 return QDF_STATUS_E_BUSY;
1395 }
1396 ipa_ctx->resource_loading = false;
1397 }
1398
1399 ipa_debug("exit");
1400
1401 return QDF_STATUS_SUCCESS;
1402}
1403
1404/**
1405 * wlan_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1406 * @ipa_ctx: IPA context
1407 *
1408 * Return: None
1409 */
1410static void wlan_ipa_uc_handle_last_discon(struct wlan_ipa_priv *ipa_ctx)
1411{
1412 ipa_debug("enter");
1413
1414 ipa_ctx->resource_unloading = true;
1415 qdf_event_reset(&ipa_ctx->ipa_resource_comp);
1416 ipa_info("Disable FW RX PIPE");
1417 cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev, false, false);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301418
1419 ipa_debug("exit: IPA WDI Pipes deactivated");
1420}
Sravan Kumar Kairam78870222018-12-31 12:47:17 +05301421
1422bool wlan_ipa_is_fw_wdi_activated(struct wlan_ipa_priv *ipa_ctx)
1423{
1424 return (WLAN_IPA_UC_NUM_WDI_PIPE == ipa_ctx->activated_fw_pipe);
1425}
Sravan Kumar Kairam361f4102018-12-17 18:47:04 +05301426#endif
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301427
1428/**
1429 * wlan_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1430 * @ipa_ctx: global IPA context
1431 * @offload_type: MCC or SCC
1432 * @session_id: Session Id
1433 * @enable: TX offload enable or disable
1434 *
1435 * Return: none
1436 */
1437static void wlan_ipa_uc_offload_enable_disable(struct wlan_ipa_priv *ipa_ctx,
1438 uint32_t offload_type,
1439 uint8_t session_id,
1440 bool enable)
1441{
1442
1443 struct ipa_uc_offload_control_params req = {0};
1444
1445 if (session_id >= WLAN_IPA_MAX_SESSION) {
1446 ipa_err("invalid session id: %d", session_id);
1447 return;
1448 }
1449
1450 if (enable == ipa_ctx->vdev_offload_enabled[session_id]) {
Sravan Kumar Kairamcd430b62018-08-23 18:35:50 +05301451 ipa_info("IPA offload status is already set");
1452 ipa_info("offload_type=%d, vdev_id=%d, enable=%d",
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301453 offload_type, session_id, enable);
1454 return;
1455 }
1456
1457 ipa_info("offload_type=%d, session_id=%d, enable=%d",
1458 offload_type, session_id, enable);
1459
1460 req.offload_type = offload_type;
1461 req.vdev_id = session_id;
1462 req.enable = enable;
1463
1464 if (QDF_STATUS_SUCCESS !=
1465 ipa_send_uc_offload_enable_disable(ipa_ctx->pdev, &req)) {
1466 ipa_err("Fail to enable IPA offload");
1467 ipa_err("offload type=%d, vdev_id=%d, enable=%d",
1468 offload_type, session_id, enable);
1469 } else {
1470 ipa_ctx->vdev_offload_enabled[session_id] = enable;
1471 }
1472}
1473
1474/**
1475 * __wlan_ipa_wlan_evt() - IPA event handler
1476 * @net_dev: Interface net device
1477 * @device_mode: Net interface device mode
1478 * @sta_id: station id for the event
1479 * @session_id: session id for the event
1480 * @type: event enum of type ipa_wlan_event
1481 * @mac_address: MAC address associated with the event
1482 *
1483 * This function is meant to be called from within wlan_ipa_ctx.c
1484 *
1485 * Return: QDF STATUS
1486 */
1487static QDF_STATUS __wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode,
1488 uint8_t sta_id, uint8_t session_id,
1489 qdf_ipa_wlan_event type,
1490 uint8_t *mac_addr)
1491{
1492 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
1493 struct wlan_ipa_iface_context *iface_ctx = NULL;
1494 qdf_ipa_msg_meta_t meta;
1495 qdf_ipa_wlan_msg_t *msg;
1496 qdf_ipa_wlan_msg_ex_t *msg_ex = NULL;
1497 int i;
1498 QDF_STATUS status;
Ryan Hsub5783cf2018-05-14 12:13:15 -07001499 uint8_t sta_session_id = WLAN_IPA_MAX_SESSION;
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301500
Mohit Khannacabf5e72018-07-24 13:28:43 -07001501 ipa_debug("%s: EVT: %d, MAC: %pM, sta_id: %d session_id: %u",
1502 net_dev->name, type, mac_addr, sta_id, session_id);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301503
1504 if (type >= QDF_IPA_WLAN_EVENT_MAX)
1505 return QDF_STATUS_E_INVAL;
1506
1507 if (wlan_ipa_uc_is_enabled(ipa_ctx->config) &&
1508 !wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1509 (device_mode != QDF_SAP_MODE)) {
1510 return QDF_STATUS_SUCCESS;
1511 }
1512
Ryan Hsub5783cf2018-05-14 12:13:15 -07001513 if (ipa_ctx->sta_connected) {
1514 iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE);
1515 if (iface_ctx)
1516 sta_session_id = iface_ctx->session_id;
1517 else
1518 ipa_err("sta iface_ctx is NULL");
1519 }
1520
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301521 /*
1522 * During IPA UC resource loading/unloading new events can be issued.
1523 */
1524 if (wlan_ipa_uc_is_enabled(ipa_ctx->config) &&
1525 (ipa_ctx->resource_loading || ipa_ctx->resource_unloading)) {
1526 unsigned int pending_event_count;
1527 struct wlan_ipa_uc_pending_event *pending_event = NULL;
1528
1529 ipa_info("Event:%d IPA resource %s inprogress", type,
1530 ipa_ctx->resource_loading ?
1531 "load" : "unload");
1532
1533 /* Wait until completion of the long/unloading */
1534 status = qdf_wait_for_event_completion(
1535 &ipa_ctx->ipa_resource_comp,
jiada8c542c2018-05-29 16:24:13 +08001536 IPA_RESOURCE_COMP_WAIT_TIME);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301537 if (status != QDF_STATUS_SUCCESS) {
1538 /*
1539 * If timed out, store the events separately and
1540 * handle them later.
1541 */
1542 ipa_info("IPA resource %s timed out",
1543 ipa_ctx->resource_loading ?
1544 "load" : "unload");
1545
Sravan Kumar Kairamcd430b62018-08-23 18:35:50 +05301546 if (type == QDF_IPA_AP_DISCONNECT)
1547 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1548 SIR_AP_RX_DATA_OFFLOAD,
1549 session_id, false);
1550
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301551 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
1552
1553 pending_event_count =
1554 qdf_list_size(&ipa_ctx->pending_event);
1555 if (pending_event_count >=
1556 WLAN_IPA_MAX_PENDING_EVENT_COUNT) {
1557 ipa_info("Reached max pending evt count");
1558 qdf_list_remove_front(
1559 &ipa_ctx->pending_event,
1560 (qdf_list_node_t **)&pending_event);
1561 } else {
1562 pending_event =
1563 (struct wlan_ipa_uc_pending_event *)
1564 qdf_mem_malloc(sizeof(
1565 struct wlan_ipa_uc_pending_event));
1566 }
1567
1568 if (!pending_event) {
1569 ipa_err("Pending event memory alloc fail");
1570 qdf_mutex_release(&ipa_ctx->ipa_lock);
1571 return QDF_STATUS_E_NOMEM;
1572 }
1573
1574 pending_event->net_dev = net_dev;
1575 pending_event->device_mode = device_mode;
1576 pending_event->sta_id = sta_id;
1577 pending_event->session_id = session_id;
1578 pending_event->type = type;
1579 pending_event->is_loading = ipa_ctx->resource_loading;
1580 qdf_mem_copy(pending_event->mac_addr,
1581 mac_addr, QDF_MAC_ADDR_SIZE);
1582 qdf_list_insert_back(&ipa_ctx->pending_event,
1583 &pending_event->node);
1584
1585 qdf_mutex_release(&ipa_ctx->ipa_lock);
1586
Yun Park21ec4902018-04-24 12:11:01 -07001587 /* Cleanup interface */
1588 if (type == QDF_IPA_STA_DISCONNECT ||
1589 type == QDF_IPA_AP_DISCONNECT) {
1590 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1591 iface_ctx = &ipa_ctx->iface_context[i];
1592
1593 if (iface_ctx->dev == net_dev)
1594 break;
1595 }
1596 if (iface_ctx)
1597 wlan_ipa_cleanup_iface(iface_ctx);
1598 }
1599
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301600 return QDF_STATUS_SUCCESS;
1601 }
1602 ipa_info("IPA resource %s completed",
1603 ipa_ctx->resource_loading ?
1604 "load" : "unload");
1605 }
1606
1607 ipa_ctx->stats.event[type]++;
1608
1609 QDF_IPA_SET_META_MSG_TYPE(&meta, type);
1610 switch (type) {
1611 case QDF_IPA_STA_CONNECT:
1612 qdf_mutex_acquire(&ipa_ctx->event_lock);
1613
1614 /* STA already connected and without disconnect, connect again
1615 * This is Roaming scenario
1616 */
1617 if (ipa_ctx->sta_connected) {
1618 iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE);
1619 if (iface_ctx)
1620 wlan_ipa_cleanup_iface(iface_ctx);
1621 }
1622
1623 status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode,
1624 sta_id, session_id);
1625 if (status != QDF_STATUS_SUCCESS) {
Mohit Khannacabf5e72018-07-24 13:28:43 -07001626 ipa_err("wlan_ipa_setup_iface failed %u", status);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301627 qdf_mutex_release(&ipa_ctx->event_lock);
1628 goto end;
1629 }
1630
1631 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1632 (ipa_ctx->sap_num_connected_sta > 0) &&
1633 !ipa_ctx->sta_connected) {
1634 qdf_mutex_release(&ipa_ctx->event_lock);
1635 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1636 SIR_STA_RX_DATA_OFFLOAD, session_id,
1637 true);
1638 qdf_mutex_acquire(&ipa_ctx->event_lock);
1639 }
1640
1641 ipa_ctx->vdev_to_iface[session_id] =
1642 wlan_ipa_get_ifaceid(ipa_ctx, session_id);
1643
1644 ipa_ctx->sta_connected = 1;
1645
1646 qdf_mutex_release(&ipa_ctx->event_lock);
1647
Mohit Khannacabf5e72018-07-24 13:28:43 -07001648 ipa_debug("sta_connected=%d vdev_to_iface[%u] %u",
1649 ipa_ctx->sta_connected,
1650 session_id,
1651 ipa_ctx->vdev_to_iface[session_id]);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301652 break;
1653
1654 case QDF_IPA_AP_CONNECT:
1655 qdf_mutex_acquire(&ipa_ctx->event_lock);
1656
1657 /* For DFS channel we get two start_bss event (before and after
1658 * CAC). Also when ACS range includes both DFS and non DFS
1659 * channels, we could possibly change channel many times due to
1660 * RADAR detection and chosen channel may not be a DFS channels.
1661 * So dont return error here. Just discard the event.
1662 */
jiadc908ada2018-05-11 14:40:54 +08001663 if (ipa_ctx->vdev_to_iface[session_id] !=
1664 WLAN_IPA_MAX_SESSION) {
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301665 qdf_mutex_release(&ipa_ctx->event_lock);
1666 return 0;
1667 }
1668
1669 status = wlan_ipa_setup_iface(ipa_ctx, net_dev, device_mode,
1670 sta_id, session_id);
1671 if (status != QDF_STATUS_SUCCESS) {
1672 qdf_mutex_release(&ipa_ctx->event_lock);
1673 ipa_err("%s: Evt: %d, Interface setup failed",
1674 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
1675 goto end;
1676 }
1677
1678 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1679 qdf_mutex_release(&ipa_ctx->event_lock);
1680 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1681 SIR_AP_RX_DATA_OFFLOAD, session_id, true);
1682 qdf_mutex_acquire(&ipa_ctx->event_lock);
1683 }
1684
1685 ipa_ctx->vdev_to_iface[session_id] =
1686 wlan_ipa_get_ifaceid(ipa_ctx, session_id);
Mohit Khannacabf5e72018-07-24 13:28:43 -07001687 ipa_debug("vdev_to_iface[%u]=%u",
1688 session_id,
1689 ipa_ctx->vdev_to_iface[session_id]);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301690 qdf_mutex_release(&ipa_ctx->event_lock);
1691 break;
1692
1693 case QDF_IPA_STA_DISCONNECT:
1694 qdf_mutex_acquire(&ipa_ctx->event_lock);
1695
1696 if (!ipa_ctx->sta_connected) {
Sravan Kumar Kairam47578192019-01-14 17:13:09 +05301697 struct wlan_ipa_iface_context *iface;
1698
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301699 qdf_mutex_release(&ipa_ctx->event_lock);
1700 ipa_err("%s: Evt: %d, STA already disconnected",
1701 msg_ex->name, QDF_IPA_MSG_META_MSG_TYPE(&meta));
Sravan Kumar Kairam47578192019-01-14 17:13:09 +05301702
1703 iface = wlan_ipa_get_iface(ipa_ctx, QDF_STA_MODE);
1704 if (iface && (iface->dev == net_dev))
1705 wlan_ipa_cleanup_iface(iface);
1706
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301707 return QDF_STATUS_E_INVAL;
1708 }
1709
1710 ipa_ctx->sta_connected = 0;
1711
1712 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1713 ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED",
1714 msg_ex->name);
1715 } else {
1716 /* Disable IPA UC TX PIPE when STA disconnected */
1717 if ((ipa_ctx->num_iface == 1) &&
Yun Parka29974a2018-04-09 12:05:49 -07001718 wlan_ipa_is_fw_wdi_activated(ipa_ctx) &&
jiadfa131fe2018-08-06 13:41:36 +08001719 !ipa_ctx->ipa_pipes_down &&
1720 (ipa_ctx->resource_unloading == false)) {
jiad3a321f32018-07-16 18:16:39 +08001721 if (cds_is_driver_unloading()) {
1722 /*
1723 * We disable WDI pipes directly here
1724 * since IPA_OPCODE_TX/RX_SUSPEND
1725 * message will not be processed when
1726 * unloading WLAN driver is in progress
1727 */
1728 wlan_ipa_uc_disable_pipes(ipa_ctx);
1729 } else {
1730 wlan_ipa_uc_handle_last_discon(ipa_ctx);
1731 }
1732 }
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301733 }
1734
1735 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1736 (ipa_ctx->sap_num_connected_sta > 0)) {
1737 qdf_mutex_release(&ipa_ctx->event_lock);
1738 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1739 SIR_STA_RX_DATA_OFFLOAD, session_id, false);
1740 qdf_mutex_acquire(&ipa_ctx->event_lock);
1741 ipa_ctx->vdev_to_iface[session_id] =
1742 WLAN_IPA_MAX_SESSION;
Mohit Khannacabf5e72018-07-24 13:28:43 -07001743 ipa_debug("vdev_to_iface[%u]=%u",
1744 session_id,
1745 ipa_ctx->vdev_to_iface[session_id]);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301746 }
1747
1748 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1749 iface_ctx = &ipa_ctx->iface_context[i];
1750
1751 if (iface_ctx->dev == net_dev)
1752 break;
1753 }
1754 if (i < WLAN_IPA_MAX_IFACE)
1755 wlan_ipa_cleanup_iface(iface_ctx);
1756
1757 qdf_mutex_release(&ipa_ctx->event_lock);
1758
1759 ipa_debug("sta_connected=%d", ipa_ctx->sta_connected);
1760 break;
1761
1762 case QDF_IPA_AP_DISCONNECT:
1763 qdf_mutex_acquire(&ipa_ctx->event_lock);
1764
1765 if ((ipa_ctx->num_iface == 1) &&
Yun Parka29974a2018-04-09 12:05:49 -07001766 wlan_ipa_is_fw_wdi_activated(ipa_ctx) &&
jiadfa131fe2018-08-06 13:41:36 +08001767 !ipa_ctx->ipa_pipes_down &&
1768 (ipa_ctx->resource_unloading == false)) {
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301769 if (cds_is_driver_unloading()) {
1770 /*
1771 * We disable WDI pipes directly here since
1772 * IPA_OPCODE_TX/RX_SUSPEND message will not be
1773 * processed when unloading WLAN driver is in
1774 * progress
1775 */
1776 wlan_ipa_uc_disable_pipes(ipa_ctx);
1777 } else {
1778 /*
1779 * This shouldn't happen :
1780 * No interface left but WDI pipes are still
1781 * active - force close WDI pipes
1782 */
1783 ipa_err("No interface left but WDI pipes are still active");
1784 wlan_ipa_uc_handle_last_discon(ipa_ctx);
1785 }
1786 }
1787
1788 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1789 qdf_mutex_release(&ipa_ctx->event_lock);
1790 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1791 SIR_AP_RX_DATA_OFFLOAD, session_id, false);
1792 qdf_mutex_acquire(&ipa_ctx->event_lock);
1793 ipa_ctx->vdev_to_iface[session_id] =
1794 WLAN_IPA_MAX_SESSION;
Mohit Khannacabf5e72018-07-24 13:28:43 -07001795 ipa_debug("vdev_to_iface[%u]=%u",
1796 session_id,
1797 ipa_ctx->vdev_to_iface[session_id]);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301798 }
1799
1800 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
1801 iface_ctx = &ipa_ctx->iface_context[i];
1802
1803 if (iface_ctx->dev == net_dev)
1804 break;
1805 }
1806 if (i < WLAN_IPA_MAX_IFACE)
1807 wlan_ipa_cleanup_iface(iface_ctx);
1808
1809 qdf_mutex_release(&ipa_ctx->event_lock);
1810 break;
1811
1812 case QDF_IPA_CLIENT_CONNECT_EX:
1813 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1814 ipa_debug("%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
1815 net_dev->name, type);
1816 return QDF_STATUS_SUCCESS;
1817 }
1818
1819 qdf_mutex_acquire(&ipa_ctx->event_lock);
1820 if (wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, true, sta_id,
1821 mac_addr)) {
1822 qdf_mutex_release(&ipa_ctx->event_lock);
1823 ipa_err("%s: STA ID %d found", net_dev->name, sta_id);
1824 return QDF_STATUS_SUCCESS;
1825 }
1826
1827 /* Enable IPA UC Data PIPEs when first STA connected */
1828 if (ipa_ctx->sap_num_connected_sta == 0 &&
1829 ipa_ctx->uc_loaded == true) {
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301830
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301831 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1832 ipa_ctx->sta_connected) {
1833 qdf_mutex_release(&ipa_ctx->event_lock);
1834 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1835 SIR_STA_RX_DATA_OFFLOAD,
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301836 sta_session_id, true);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301837 qdf_mutex_acquire(&ipa_ctx->event_lock);
1838 }
1839
1840 status = wlan_ipa_uc_handle_first_con(ipa_ctx);
1841 if (status != QDF_STATUS_SUCCESS) {
1842 ipa_info("%s: handle 1st con fail",
1843 net_dev->name);
1844
1845 if (wlan_ipa_uc_sta_is_enabled(
1846 ipa_ctx->config) &&
1847 ipa_ctx->sta_connected) {
1848 qdf_mutex_release(&ipa_ctx->event_lock);
1849 wlan_ipa_uc_offload_enable_disable(
1850 ipa_ctx,
1851 SIR_STA_RX_DATA_OFFLOAD,
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301852 sta_session_id, false);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301853 } else {
1854 qdf_mutex_release(&ipa_ctx->event_lock);
1855 }
1856
1857 return status;
Mohit Khannacabf5e72018-07-24 13:28:43 -07001858 } else
1859 ipa_debug("%s: handle 1st con success",
1860 net_dev->name);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301861 }
1862
1863 ipa_ctx->sap_num_connected_sta++;
1864
1865 qdf_mutex_release(&ipa_ctx->event_lock);
1866
1867 QDF_IPA_SET_META_MSG_TYPE(&meta, type);
1868 QDF_IPA_MSG_META_MSG_LEN(&meta) =
1869 (sizeof(qdf_ipa_wlan_msg_ex_t) +
1870 sizeof(qdf_ipa_wlan_hdr_attrib_val_t));
1871 msg_ex = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
1872
1873 if (msg_ex == NULL) {
1874 ipa_err("msg_ex allocation failed");
1875 return QDF_STATUS_E_NOMEM;
1876 }
1877 strlcpy(msg_ex->name, net_dev->name,
1878 IPA_RESOURCE_NAME_MAX);
1879 msg_ex->num_of_attribs = 1;
1880 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
1881 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1882 msg_ex->attribs[0].offset =
1883 WLAN_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
1884 } else {
1885 msg_ex->attribs[0].offset =
1886 WLAN_IPA_WLAN_HDR_DES_MAC_OFFSET;
1887 }
1888 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
1889 IPA_MAC_ADDR_SIZE);
1890
1891 if (qdf_ipa_send_msg(&meta, msg_ex, wlan_ipa_msg_free_fn)) {
1892 ipa_info("%s: Evt: %d send ipa msg fail",
1893 net_dev->name, type);
1894 qdf_mem_free(msg_ex);
1895 return QDF_STATUS_E_FAILURE;
1896 }
1897 ipa_ctx->stats.num_send_msg++;
1898
1899 ipa_info("sap_num_connected_sta=%d",
1900 ipa_ctx->sap_num_connected_sta);
1901
1902 return QDF_STATUS_SUCCESS;
1903
1904 case WLAN_CLIENT_DISCONNECT:
1905 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
1906 ipa_debug("%s: IPA UC OFFLOAD NOT ENABLED",
1907 msg_ex->name);
1908 return QDF_STATUS_SUCCESS;
1909 }
1910
1911 qdf_mutex_acquire(&ipa_ctx->event_lock);
1912 if (!ipa_ctx->sap_num_connected_sta) {
1913 qdf_mutex_release(&ipa_ctx->event_lock);
1914 ipa_err("%s: Evt: %d, Client already disconnected",
1915 msg_ex->name,
1916 QDF_IPA_MSG_META_MSG_TYPE(&meta));
1917
1918 return QDF_STATUS_SUCCESS;
1919 }
1920 if (!wlan_ipa_uc_find_add_assoc_sta(ipa_ctx, false,
1921 sta_id, mac_addr)) {
1922 qdf_mutex_release(&ipa_ctx->event_lock);
1923 ipa_err("%s: STA ID %d NOT found, not valid",
1924 msg_ex->name, sta_id);
1925
1926 return QDF_STATUS_SUCCESS;
1927 }
1928 ipa_ctx->sap_num_connected_sta--;
1929
1930 /* Disable IPA UC TX PIPE when last STA disconnected */
1931 if (!ipa_ctx->sap_num_connected_sta &&
1932 ipa_ctx->uc_loaded == true) {
Yun Parka29974a2018-04-09 12:05:49 -07001933 if ((false == ipa_ctx->resource_unloading) &&
1934 wlan_ipa_is_fw_wdi_activated(ipa_ctx) &&
1935 !ipa_ctx->ipa_pipes_down) {
jiad3a321f32018-07-16 18:16:39 +08001936 if (cds_is_driver_unloading()) {
1937 /*
1938 * We disable WDI pipes directly here
1939 * since IPA_OPCODE_TX/RX_SUSPEND
1940 * message will not be processed when
1941 * unloading WLAN driver is in progress
1942 */
1943 wlan_ipa_uc_disable_pipes(ipa_ctx);
1944 } else {
1945 wlan_ipa_uc_handle_last_discon(ipa_ctx);
1946 }
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301947 }
1948
1949 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config) &&
1950 ipa_ctx->sta_connected) {
1951 qdf_mutex_release(&ipa_ctx->event_lock);
1952 wlan_ipa_uc_offload_enable_disable(ipa_ctx,
1953 SIR_STA_RX_DATA_OFFLOAD,
Sravan Kumar Kairamf59aec12018-03-23 19:35:01 +05301954 sta_session_id, false);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05301955 } else {
1956 qdf_mutex_release(&ipa_ctx->event_lock);
1957 }
1958 } else {
1959 qdf_mutex_release(&ipa_ctx->event_lock);
1960 }
1961
1962 ipa_info("sap_num_connected_sta=%d",
1963 ipa_ctx->sap_num_connected_sta);
1964 break;
1965
1966 default:
1967 return QDF_STATUS_SUCCESS;
1968 }
1969
1970 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t);
1971 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
1972 if (!msg) {
1973 ipa_err("msg allocation failed");
1974 return QDF_STATUS_E_NOMEM;
1975 }
1976
1977 QDF_IPA_SET_META_MSG_TYPE(&meta, type);
1978 strlcpy(QDF_IPA_WLAN_MSG_NAME(msg), net_dev->name,
1979 IPA_RESOURCE_NAME_MAX);
1980 qdf_mem_copy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, QDF_NET_ETH_LEN);
1981
1982 ipa_debug("%s: Evt: %d", QDF_IPA_WLAN_MSG_NAME(msg),
1983 QDF_IPA_MSG_META_MSG_TYPE(&meta));
1984
1985 if (qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn)) {
1986
1987 ipa_err("%s: Evt: %d fail",
1988 QDF_IPA_WLAN_MSG_NAME(msg),
1989 QDF_IPA_MSG_META_MSG_TYPE(&meta));
1990 qdf_mem_free(msg);
1991
1992 return QDF_STATUS_E_FAILURE;
1993 }
1994
1995 ipa_ctx->stats.num_send_msg++;
1996
1997end:
1998 return QDF_STATUS_SUCCESS;
1999}
2000
2001/**
2002 * wlan_host_to_ipa_wlan_event() - convert wlan_ipa_wlan_event to ipa_wlan_event
Yun Park84fbb272018-04-02 15:31:01 -07002003 * @wlan_ipa_event_type: event to be converted to an ipa_wlan_event
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302004 *
2005 * Return: qdf_ipa_wlan_event representing the wlan_ipa_wlan_event
2006 */
2007static qdf_ipa_wlan_event
2008wlan_host_to_ipa_wlan_event(enum wlan_ipa_wlan_event wlan_ipa_event_type)
2009{
Yun Park84fbb272018-04-02 15:31:01 -07002010 qdf_ipa_wlan_event ipa_event;
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302011
2012 switch (wlan_ipa_event_type) {
2013 case WLAN_IPA_CLIENT_CONNECT:
2014 ipa_event = QDF_IPA_CLIENT_CONNECT;
2015 break;
2016 case WLAN_IPA_CLIENT_DISCONNECT:
2017 ipa_event = QDF_IPA_CLIENT_DISCONNECT;
2018 break;
2019 case WLAN_IPA_AP_CONNECT:
2020 ipa_event = QDF_IPA_AP_CONNECT;
2021 break;
2022 case WLAN_IPA_AP_DISCONNECT:
2023 ipa_event = QDF_IPA_AP_DISCONNECT;
2024 break;
2025 case WLAN_IPA_STA_CONNECT:
2026 ipa_event = QDF_IPA_STA_CONNECT;
2027 break;
2028 case WLAN_IPA_STA_DISCONNECT:
2029 ipa_event = QDF_IPA_STA_DISCONNECT;
2030 break;
2031 case WLAN_IPA_CLIENT_CONNECT_EX:
2032 ipa_event = QDF_IPA_CLIENT_CONNECT_EX;
2033 break;
2034 case WLAN_IPA_WLAN_EVENT_MAX:
2035 default:
2036 ipa_event = QDF_IPA_WLAN_EVENT_MAX;
2037 break;
2038 }
2039
2040 return ipa_event;
2041}
2042
2043/**
2044 * wlan_ipa_wlan_evt() - SSR wrapper for __wlan_ipa_wlan_evt
2045 * @net_dev: Interface net device
2046 * @device_mode: Net interface device mode
2047 * @sta_id: station id for the event
2048 * @session_id: session id for the event
2049 * @ipa_event_type: event enum of type wlan_ipa_wlan_event
2050 * @mac_address: MAC address associated with the event
2051 *
2052 * Return: QDF_STATUS
2053 */
2054QDF_STATUS wlan_ipa_wlan_evt(qdf_netdev_t net_dev, uint8_t device_mode,
2055 uint8_t sta_id, uint8_t session_id,
2056 enum wlan_ipa_wlan_event ipa_event_type,
2057 uint8_t *mac_addr)
2058{
2059 qdf_ipa_wlan_event type = wlan_host_to_ipa_wlan_event(ipa_event_type);
2060 QDF_STATUS status = QDF_STATUS_SUCCESS;
2061
2062 /* Data path offload only support for STA and SAP mode */
2063 if ((device_mode == QDF_STA_MODE) ||
2064 (device_mode == QDF_SAP_MODE))
2065 status = __wlan_ipa_wlan_evt(net_dev, device_mode, sta_id,
2066 session_id, type, mac_addr);
2067
2068 return status;
2069}
2070
2071/**
2072 * wlan_ipa_uc_proc_pending_event() - Process IPA uC pending events
2073 * @ipa_ctx: Global IPA IPA context
2074 * @is_loading: Indicate if invoked during loading
2075 *
2076 * Return: None
2077 */
2078static void
2079wlan_ipa_uc_proc_pending_event(struct wlan_ipa_priv *ipa_ctx, bool is_loading)
2080{
2081 unsigned int pending_event_count;
2082 struct wlan_ipa_uc_pending_event *pending_event = NULL;
2083
2084 pending_event_count = qdf_list_size(&ipa_ctx->pending_event);
2085 ipa_debug("Pending Event Count %d", pending_event_count);
2086 if (!pending_event_count) {
2087 ipa_debug("No Pending Event");
2088 return;
2089 }
2090
2091 qdf_list_remove_front(&ipa_ctx->pending_event,
2092 (qdf_list_node_t **)&pending_event);
2093 while (pending_event != NULL) {
Sravan Kumar Kairam8c151e22018-06-15 16:35:39 +05302094 struct wlan_objmgr_pdev *pdev = ipa_ctx->pdev;
2095 struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev);
2096 struct wlan_objmgr_vdev *vdev =
2097 wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
2098 pending_event->session_id,
2099 WLAN_IPA_ID);
2100 if (pending_event->is_loading == is_loading && vdev) {
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302101 __wlan_ipa_wlan_evt(pending_event->net_dev,
2102 pending_event->device_mode,
2103 pending_event->sta_id,
2104 pending_event->session_id,
2105 pending_event->type,
2106 pending_event->mac_addr);
2107 }
Sravan Kumar Kairam8c151e22018-06-15 16:35:39 +05302108
2109 if (vdev)
2110 wlan_objmgr_vdev_release_ref(vdev, WLAN_IPA_ID);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302111 qdf_mem_free(pending_event);
2112 pending_event = NULL;
2113 qdf_list_remove_front(&ipa_ctx->pending_event,
2114 (qdf_list_node_t **)&pending_event);
2115 }
2116}
2117
2118/**
Ryan Hsub5783cf2018-05-14 12:13:15 -07002119 * wlan_ipa_free_tx_desc_list() - Free IPA Tx desc list
2120 * @ipa_ctx: IPA context
2121 *
2122 * Return: None
2123 */
2124static inline void wlan_ipa_free_tx_desc_list(struct wlan_ipa_priv *ipa_ctx)
2125{
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302126 int i;
Ryan Hsub5783cf2018-05-14 12:13:15 -07002127 qdf_ipa_rx_data_t *ipa_tx_desc;
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302128 uint32_t pool_size;
Ryan Hsub5783cf2018-05-14 12:13:15 -07002129
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302130 if (!ipa_ctx->tx_desc_pool)
2131 return;
Ryan Hsub5783cf2018-05-14 12:13:15 -07002132
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302133 qdf_spin_lock_bh(&ipa_ctx->q_lock);
2134 pool_size = ipa_ctx->tx_desc_free_list.max_size;
2135 for (i = 0; i < pool_size; i++) {
2136 ipa_tx_desc = ipa_ctx->tx_desc_pool[i].ipa_tx_desc_ptr;
Ryan Hsub5783cf2018-05-14 12:13:15 -07002137 if (ipa_tx_desc)
2138 qdf_ipa_free_skb(ipa_tx_desc);
2139
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302140 if (qdf_list_remove_node(&ipa_ctx->tx_desc_free_list,
2141 &ipa_ctx->tx_desc_pool[i].node) !=
2142 QDF_STATUS_SUCCESS)
2143 ipa_err("Failed to remove node from tx desc freelist");
Ryan Hsub5783cf2018-05-14 12:13:15 -07002144 }
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302145 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
2146
2147 qdf_list_destroy(&ipa_ctx->tx_desc_free_list);
2148 qdf_mem_free(ipa_ctx->tx_desc_pool);
2149 ipa_ctx->tx_desc_pool = NULL;
2150
2151 ipa_ctx->stats.num_tx_desc_q_cnt = 0;
2152 ipa_ctx->stats.num_tx_desc_error = 0;
Ryan Hsub5783cf2018-05-14 12:13:15 -07002153}
2154
2155/**
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302156 * wlan_ipa_alloc_tx_desc_free_list() - Allocate IPA Tx desc list
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302157 * @ipa_ctx: IPA context
2158 *
2159 * Return: QDF_STATUS
2160 */
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302161static QDF_STATUS
2162wlan_ipa_alloc_tx_desc_free_list(struct wlan_ipa_priv *ipa_ctx)
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302163{
2164 int i;
2165 uint32_t max_desc_cnt;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302166
2167 max_desc_cnt = ipa_ctx->config->txbuf_count;
2168
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302169 ipa_ctx->tx_desc_pool = qdf_mem_malloc(sizeof(struct wlan_ipa_tx_desc) *
2170 max_desc_cnt);
2171
2172 if (!ipa_ctx->tx_desc_pool) {
2173 ipa_err("Free Tx descriptor allocation failed");
2174 return QDF_STATUS_E_NOMEM;
2175 }
2176
2177 qdf_list_create(&ipa_ctx->tx_desc_free_list, max_desc_cnt);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302178
2179 qdf_spin_lock_bh(&ipa_ctx->q_lock);
2180 for (i = 0; i < max_desc_cnt; i++) {
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302181 ipa_ctx->tx_desc_pool[i].id = i;
2182 ipa_ctx->tx_desc_pool[i].ipa_tx_desc_ptr = NULL;
2183 qdf_list_insert_back(&ipa_ctx->tx_desc_free_list,
2184 &ipa_ctx->tx_desc_pool[i].node);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302185 }
2186
2187 ipa_ctx->stats.num_tx_desc_q_cnt = 0;
2188 ipa_ctx->stats.num_tx_desc_error = 0;
2189
2190 qdf_spin_unlock_bh(&ipa_ctx->q_lock);
2191
2192 return QDF_STATUS_SUCCESS;
2193}
2194
2195#ifndef QCA_LL_TX_FLOW_CONTROL_V2
2196/**
2197 * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes
2198 * @ipa_ctx: Global IPA IPA context
2199 * @desc_fifo_sz: Number of descriptors
2200 *
2201 * Return: 0 on success, negative errno on error
2202 */
2203static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
2204 int32_t desc_fifo_sz)
2205{
2206 int i, ret = 0;
2207 qdf_ipa_sys_connect_params_t *ipa;
2208
2209 /*setup TX pipes */
2210 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2211 ipa = &ipa_ctx->sys_pipe[i].ipa_sys_params;
2212
2213 ipa->client = wlan_ipa_iface_2_client[i].cons_client;
2214 ipa->desc_fifo_sz = desc_fifo_sz;
2215 ipa->priv = &ipa_ctx->iface_context[i];
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302216 ipa->notify = wlan_ipa_i2w_cb;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302217
2218 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
2219 ipa->ipa_ep_cfg.hdr.hdr_len =
2220 WLAN_IPA_UC_WLAN_TX_HDR_LEN;
2221 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2222 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2223 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2224 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
2225 WLAN_IPA_UC_WLAN_8023_HDR_SIZE;
2226 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
2227 } else {
2228 ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_TX_HDR_LEN;
2229 }
2230 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
2231
2232 ret = wlan_ipa_wdi_setup_sys_pipe(ipa_ctx, ipa,
2233 &ipa_ctx->sys_pipe[i].conn_hdl);
2234 if (ret) {
2235 ipa_err("Failed for pipe %d ret: %d", i, ret);
2236 return ret;
2237 }
2238 ipa_ctx->sys_pipe[i].conn_hdl_valid = 1;
2239 }
2240
2241 return ret;
2242}
2243#else
2244/**
2245 * wlan_ipa_setup_tx_sys_pipe() - Setup IPA Tx system pipes
2246 * @ipa_ctx: Global IPA IPA context
2247 * @desc_fifo_sz: Number of descriptors
2248 *
2249 * Return: 0 on success, negative errno on error
2250 */
2251static int wlan_ipa_setup_tx_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
2252 int32_t desc_fifo_sz)
2253{
2254 /*
2255 * The Tx system pipes are not needed for MCC when TX_FLOW_CONTROL_V2
2256 * is enabled, where per vdev descriptors are supported in firmware.
2257 */
2258 return 0;
2259}
2260#endif
2261
2262/**
2263 * wlan_ipa_setup_rx_sys_pipe() - Setup IPA Rx system pipes
2264 * @ipa_ctx: Global IPA IPA context
2265 * @desc_fifo_sz: Number of descriptors
2266 *
2267 * Return: 0 on success, negative errno on error
2268 */
2269static int wlan_ipa_setup_rx_sys_pipe(struct wlan_ipa_priv *ipa_ctx,
2270 int32_t desc_fifo_sz)
2271{
2272 int ret = 0;
2273 qdf_ipa_sys_connect_params_t *ipa;
2274
2275 /*
2276 * Hard code it here, this can be extended if in case
2277 * PROD pipe is also per interface.
2278 * Right now there is no advantage of doing this.
2279 */
2280 ipa = &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].ipa_sys_params;
2281
2282 ipa->client = IPA_CLIENT_WLAN1_PROD;
2283
2284 ipa->desc_fifo_sz = desc_fifo_sz;
2285 ipa->priv = ipa_ctx;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302286 ipa->notify = wlan_ipa_w2i_cb;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302287
2288 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2289 ipa->ipa_ep_cfg.hdr.hdr_len = WLAN_IPA_WLAN_RX_HDR_LEN;
2290 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
2291 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
2292
2293 ret = qdf_ipa_setup_sys_pipe(ipa,
2294 &ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl);
2295 if (ret) {
2296 ipa_err("Failed for RX pipe: %d", ret);
2297 return ret;
2298 }
2299 ipa_ctx->sys_pipe[WLAN_IPA_RX_PIPE].conn_hdl_valid = 1;
2300
2301 return ret;
2302}
2303
2304/**
Ryan Hsub5783cf2018-05-14 12:13:15 -07002305 * wlan_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
2306 * @ipa_ctx: Global IPA IPA context
2307 *
2308 * Return: None
2309 */
2310static void wlan_ipa_teardown_sys_pipe(struct wlan_ipa_priv *ipa_ctx)
2311{
2312 int ret, i;
2313
2314 if (!ipa_ctx)
2315 return;
2316
2317 for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++) {
2318 if (ipa_ctx->sys_pipe[i].conn_hdl_valid) {
2319 ret = wlan_ipa_wdi_teardown_sys_pipe(ipa_ctx,
2320 ipa_ctx->sys_pipe[i].conn_hdl);
2321 if (ret)
2322 ipa_err("Failed:%d", ret);
2323
2324 ipa_ctx->sys_pipe[i].conn_hdl_valid = 0;
2325 }
2326 }
2327
2328 wlan_ipa_free_tx_desc_list(ipa_ctx);
2329}
2330
2331/**
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302332 * wlan_ipa_setup_sys_pipe() - Setup all IPA system pipes
2333 * @ipa_ctx: Global IPA IPA context
2334 *
2335 * Return: 0 on success, negative errno on error
2336 */
2337static int wlan_ipa_setup_sys_pipe(struct wlan_ipa_priv *ipa_ctx)
2338{
Ryan Hsub5783cf2018-05-14 12:13:15 -07002339 int ret = 0;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302340 uint32_t desc_fifo_sz;
2341
2342 /* The maximum number of descriptors that can be provided to a BAM at
2343 * once is one less than the total number of descriptors that the buffer
2344 * can contain.
2345 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
2346 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
2347 * be provided at once.
2348 * Because of above requirement, one extra descriptor will be added to
2349 * make sure hardware always has one descriptor.
2350 */
2351 desc_fifo_sz = ipa_ctx->config->desc_size
2352 + SPS_DESC_SIZE;
2353
2354 ret = wlan_ipa_setup_tx_sys_pipe(ipa_ctx, desc_fifo_sz);
2355 if (ret) {
2356 ipa_err("Failed for TX pipe: %d", ret);
2357 goto setup_sys_pipe_fail;
2358 }
2359
2360 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
2361 ret = wlan_ipa_setup_rx_sys_pipe(ipa_ctx, desc_fifo_sz);
2362 if (ret) {
2363 ipa_err("Failed for RX pipe: %d", ret);
2364 goto setup_sys_pipe_fail;
2365 }
2366 }
2367
2368 /* Allocate free Tx desc list */
Sravan Kumar Kairam1f8f8b32018-07-06 16:05:24 +05302369 ret = wlan_ipa_alloc_tx_desc_free_list(ipa_ctx);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302370 if (ret)
2371 goto setup_sys_pipe_fail;
2372
2373 return ret;
2374
2375setup_sys_pipe_fail:
Ryan Hsub5783cf2018-05-14 12:13:15 -07002376 wlan_ipa_teardown_sys_pipe(ipa_ctx);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302377
2378 return ret;
2379}
2380
jiadbb47e132018-03-30 16:28:30 +08002381#ifndef QCA_LL_TX_FLOW_CONTROL_V2
2382QDF_STATUS wlan_ipa_send_mcc_scc_msg(struct wlan_ipa_priv *ipa_ctx,
2383 bool mcc_mode)
2384{
2385 qdf_ipa_msg_meta_t meta;
2386 qdf_ipa_wlan_msg_t *msg;
2387 int ret;
2388
2389 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config))
2390 return QDF_STATUS_SUCCESS;
2391
2392 /* Send SCC/MCC Switching event to IPA */
2393 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(*msg);
2394 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
2395 if (msg == NULL) {
2396 ipa_err("msg allocation failed");
2397 return QDF_STATUS_E_NOMEM;
2398 }
2399
jiad629b2172018-05-11 15:34:22 +08002400 if (mcc_mode) {
jiadbb47e132018-03-30 16:28:30 +08002401 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_MCC);
jiad629b2172018-05-11 15:34:22 +08002402 ipa_ctx->stats.event[QDF_SWITCH_TO_MCC]++;
2403 } else {
jiadbb47e132018-03-30 16:28:30 +08002404 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_SWITCH_TO_SCC);
jiad629b2172018-05-11 15:34:22 +08002405 ipa_ctx->stats.event[QDF_SWITCH_TO_SCC]++;
2406 }
2407
jiadbb47e132018-03-30 16:28:30 +08002408 WLAN_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
2409 "ipa_send_msg(Evt:%d)",
2410 QDF_IPA_MSG_META_MSG_TYPE(&meta));
2411
2412 ret = qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn);
2413
2414 if (ret) {
2415 ipa_err("ipa_send_msg(Evt:%d) - fail=%d",
2416 QDF_IPA_MSG_META_MSG_TYPE(&meta), ret);
2417 qdf_mem_free(msg);
2418 return QDF_STATUS_E_FAILURE;
2419 }
2420
2421 return QDF_STATUS_SUCCESS;
2422}
2423
2424static void wlan_ipa_mcc_work_handler(void *data)
2425{
2426 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)data;
2427
2428 wlan_ipa_send_mcc_scc_msg(ipa_ctx, ipa_ctx->mcc_mode);
2429}
2430#endif
2431
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302432/**
2433 * wlan_ipa_setup() - IPA initialization function
2434 * @ipa_ctx: IPA context
2435 * @ipa_cfg: IPA config
2436 *
2437 * Allocate ipa_ctx resources, ipa pipe resource and register
2438 * wlan interface with IPA module.
2439 *
2440 * Return: QDF_STATUS enumeration
2441 */
2442QDF_STATUS wlan_ipa_setup(struct wlan_ipa_priv *ipa_ctx,
2443 struct wlan_ipa_config *ipa_cfg)
2444{
2445 int ret, i;
2446 struct wlan_ipa_iface_context *iface_context = NULL;
2447 QDF_STATUS status;
2448
2449 ipa_debug("enter");
2450
2451 gp_ipa = ipa_ctx;
2452 ipa_ctx->num_iface = 0;
2453 ipa_ctx->config = ipa_cfg;
2454
2455 wlan_ipa_wdi_get_wdi_version(ipa_ctx);
2456
2457 /* Create the interface context */
2458 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2459 iface_context = &ipa_ctx->iface_context[i];
2460 iface_context->ipa_ctx = ipa_ctx;
2461 iface_context->cons_client =
2462 wlan_ipa_iface_2_client[i].cons_client;
2463 iface_context->prod_client =
2464 wlan_ipa_iface_2_client[i].prod_client;
2465 iface_context->iface_id = i;
2466 iface_context->dev = NULL;
2467 iface_context->device_mode = QDF_MAX_NO_OF_MODE;
2468 iface_context->tl_context = NULL;
2469 qdf_spinlock_create(&iface_context->interface_lock);
2470 }
2471
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302472 qdf_create_work(0, &ipa_ctx->pm_work, wlan_ipa_pm_flush, ipa_ctx);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302473 qdf_spinlock_create(&ipa_ctx->pm_lock);
2474 qdf_spinlock_create(&ipa_ctx->q_lock);
2475 qdf_nbuf_queue_init(&ipa_ctx->pm_queue_head);
2476 qdf_list_create(&ipa_ctx->pending_event, 1000);
2477 qdf_mutex_create(&ipa_ctx->event_lock);
2478 qdf_mutex_create(&ipa_ctx->ipa_lock);
2479
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302480 status = wlan_ipa_wdi_setup_rm(ipa_ctx);
2481 if (status != QDF_STATUS_SUCCESS)
2482 goto fail_setup_rm;
2483
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302484 for (i = 0; i < WLAN_IPA_MAX_SYSBAM_PIPE; i++)
2485 qdf_mem_zero(&ipa_ctx->sys_pipe[i],
2486 sizeof(struct wlan_ipa_sys_pipe));
2487
2488 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
2489 qdf_mem_zero(&ipa_ctx->stats, sizeof(ipa_ctx->stats));
2490 ipa_ctx->sap_num_connected_sta = 0;
2491 ipa_ctx->ipa_tx_packets_diff = 0;
2492 ipa_ctx->ipa_rx_packets_diff = 0;
2493 ipa_ctx->ipa_p_tx_packets = 0;
2494 ipa_ctx->ipa_p_rx_packets = 0;
2495 ipa_ctx->resource_loading = false;
2496 ipa_ctx->resource_unloading = false;
2497 ipa_ctx->sta_connected = 0;
2498 ipa_ctx->ipa_pipes_down = true;
2499 ipa_ctx->wdi_enabled = false;
2500 /* Setup IPA system pipes */
2501 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
2502 ret = wlan_ipa_setup_sys_pipe(ipa_ctx);
2503 if (ret)
2504 goto fail_create_sys_pipe;
jiadbb47e132018-03-30 16:28:30 +08002505
2506 qdf_create_work(0, &ipa_ctx->mcc_work,
2507 wlan_ipa_mcc_work_handler, ipa_ctx);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302508 }
2509
2510 status = wlan_ipa_wdi_init(ipa_ctx);
2511 if (status == QDF_STATUS_E_BUSY)
2512 status = wlan_ipa_uc_send_wdi_control_msg(false);
2513 if (status != QDF_STATUS_SUCCESS) {
Ryan Hsub5783cf2018-05-14 12:13:15 -07002514 ipa_err("IPA WDI init failed: ret=%d", status);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302515 goto fail_create_sys_pipe;
2516 }
2517 } else {
2518 ret = wlan_ipa_setup_sys_pipe(ipa_ctx);
2519 if (ret)
2520 goto fail_create_sys_pipe;
2521 }
2522
2523 qdf_event_create(&ipa_ctx->ipa_resource_comp);
2524
2525 ipa_debug("exit: success");
2526
2527 return QDF_STATUS_SUCCESS;
2528
2529fail_create_sys_pipe:
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302530 wlan_ipa_wdi_destroy_rm(ipa_ctx);
2531
2532fail_setup_rm:
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302533 qdf_spinlock_destroy(&ipa_ctx->pm_lock);
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302534 qdf_spinlock_destroy(&ipa_ctx->q_lock);
2535 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2536 iface_context = &ipa_ctx->iface_context[i];
2537 qdf_spinlock_destroy(&iface_context->interface_lock);
2538 }
2539 qdf_mutex_destroy(&ipa_ctx->event_lock);
2540 qdf_mutex_destroy(&ipa_ctx->ipa_lock);
2541 qdf_list_destroy(&ipa_ctx->pending_event);
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302542 gp_ipa = NULL;
2543 ipa_debug("exit: fail");
2544
2545 return QDF_STATUS_E_FAILURE;
2546}
2547
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302548void wlan_ipa_flush(struct wlan_ipa_priv *ipa_ctx)
2549{
2550 qdf_nbuf_t skb;
2551 struct wlan_ipa_pm_tx_cb *pm_tx_cb;
2552
2553 if (!wlan_ipa_is_enabled(ipa_ctx->config))
2554 return;
2555
2556 qdf_cancel_work(&ipa_ctx->pm_work);
2557
2558 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
2559
2560 while (((skb = qdf_nbuf_queue_remove(&ipa_ctx->pm_queue_head))
2561 != NULL)) {
2562 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
2563
2564 pm_tx_cb = (struct wlan_ipa_pm_tx_cb *)skb->cb;
jiadab8cea02018-05-24 09:16:14 +08002565
2566 if (pm_tx_cb->exception) {
2567 dev_kfree_skb_any(skb);
2568 } else {
2569 if (pm_tx_cb->ipa_tx_desc)
2570 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
2571 }
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302572
2573 qdf_spin_lock_bh(&ipa_ctx->pm_lock);
2574 }
2575 qdf_spin_unlock_bh(&ipa_ctx->pm_lock);
2576}
2577
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302578QDF_STATUS wlan_ipa_cleanup(struct wlan_ipa_priv *ipa_ctx)
2579{
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302580 struct wlan_ipa_iface_context *iface_context;
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302581 int i;
2582
2583 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config))
2584 wlan_ipa_teardown_sys_pipe(ipa_ctx);
2585
2586 /* Teardown IPA sys_pipe for MCC */
jiadbb47e132018-03-30 16:28:30 +08002587 if (wlan_ipa_uc_sta_is_enabled(ipa_ctx->config)) {
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302588 wlan_ipa_teardown_sys_pipe(ipa_ctx);
jiadbb47e132018-03-30 16:28:30 +08002589 qdf_cancel_work(&ipa_ctx->mcc_work);
2590 }
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302591
Sravan Kumar Kairam2e7aae92018-03-06 19:32:49 +05302592 wlan_ipa_wdi_destroy_rm(ipa_ctx);
2593
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302594 wlan_ipa_flush(ipa_ctx);
2595
Sravan Kumar Kairamd01b4452018-03-07 17:37:09 +05302596 qdf_spinlock_destroy(&ipa_ctx->pm_lock);
2597 qdf_spinlock_destroy(&ipa_ctx->q_lock);
2598
2599 /* destroy the interface lock */
2600 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2601 iface_context = &ipa_ctx->iface_context[i];
2602 qdf_spinlock_destroy(&iface_context->interface_lock);
2603 }
2604
2605 if (wlan_ipa_uc_is_enabled(ipa_ctx->config)) {
2606 wlan_ipa_wdi_cleanup();
2607 qdf_mutex_destroy(&ipa_ctx->event_lock);
2608 qdf_mutex_destroy(&ipa_ctx->ipa_lock);
2609 qdf_list_destroy(&ipa_ctx->pending_event);
2610
2611 }
2612
2613 gp_ipa = NULL;
2614
2615 return QDF_STATUS_SUCCESS;
2616}
Sravan Kumar Kairam271fab22018-03-07 18:57:41 +05302617
2618struct wlan_ipa_iface_context
2619*wlan_ipa_get_iface(struct wlan_ipa_priv *ipa_ctx, uint8_t mode)
2620{
2621 struct wlan_ipa_iface_context *iface_ctx = NULL;
2622 int i;
2623
2624 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
2625 iface_ctx = &ipa_ctx->iface_context[i];
2626
2627 if (iface_ctx->device_mode == mode)
2628 return iface_ctx;
2629 }
2630
2631 return NULL;
2632}
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302633
jiadbb47e132018-03-30 16:28:30 +08002634void wlan_ipa_set_mcc_mode(struct wlan_ipa_priv *ipa_ctx, bool mcc_mode)
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302635{
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302636 if (!wlan_ipa_uc_sta_is_enabled(ipa_ctx->config))
jiadbb47e132018-03-30 16:28:30 +08002637 return;
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302638
jiadbb47e132018-03-30 16:28:30 +08002639 if (ipa_ctx->mcc_mode == mcc_mode)
2640 return;
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302641
jiadbb47e132018-03-30 16:28:30 +08002642 ipa_ctx->mcc_mode = mcc_mode;
2643 qdf_sched_work(0, &ipa_ctx->mcc_work);
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302644}
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302645
2646/**
2647 * wlan_ipa_uc_loaded_handler() - Process IPA uC loaded indication
2648 * @ipa_ctx: ipa ipa local context
2649 *
2650 * Will handle IPA UC image loaded indication comes from IPA kernel
2651 *
2652 * Return: None
2653 */
2654static void wlan_ipa_uc_loaded_handler(struct wlan_ipa_priv *ipa_ctx)
2655{
2656 struct wlan_objmgr_pdev *pdev = ipa_ctx->pdev;
2657 struct wlan_objmgr_psoc *psoc = wlan_pdev_get_psoc(pdev);
2658 qdf_device_t qdf_dev = wlan_psoc_get_qdf_dev(psoc);
2659 QDF_STATUS status;
2660
2661 ipa_info("UC READY");
Ryan Hsub5783cf2018-05-14 12:13:15 -07002662
2663 if (!qdf_dev) {
2664 ipa_err("qdf device is NULL!");
2665 return;
2666 }
2667
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302668 if (true == ipa_ctx->uc_loaded) {
2669 ipa_info("UC already loaded");
2670 return;
2671 }
2672
Lihua Liu15f6e452018-05-30 17:31:06 +08002673 if (!qdf_dev) {
2674 ipa_err("qdf_dev is null");
2675 return;
2676 }
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302677 /* Connect pipe */
2678 status = wlan_ipa_wdi_setup(ipa_ctx, qdf_dev);
2679 if (status) {
2680 ipa_err("Failure to setup IPA pipes (status=%d)",
2681 status);
2682 return;
2683 }
2684
2685 cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, ipa_ctx->dp_pdev);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302686
2687 /* If already any STA connected, enable IPA/FW PIPEs */
2688 if (ipa_ctx->sap_num_connected_sta) {
2689 ipa_debug("Client already connected, enable IPA/FW PIPEs");
2690 wlan_ipa_uc_handle_first_con(ipa_ctx);
2691 }
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302692}
2693
2694/**
2695 * wlan_ipa_uc_op_cb() - IPA uC operation callback
2696 * @op_msg: operation message received from firmware
2697 * @usr_ctxt: user context registered with TL (we register the IPA Global
2698 * context)
2699 *
2700 * Return: None
2701 */
2702static void wlan_ipa_uc_op_cb(struct op_msg_type *op_msg,
2703 struct wlan_ipa_priv *ipa_ctx)
2704{
2705 struct op_msg_type *msg = op_msg;
2706 struct ipa_uc_fw_stats *uc_fw_stat;
2707
2708 if (!op_msg) {
2709 ipa_err("INVALID ARG");
2710 return;
2711 }
2712
2713 if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) {
2714 ipa_err("INVALID OPCODE %d", msg->op_code);
2715 qdf_mem_free(op_msg);
2716 return;
2717 }
2718
2719 ipa_debug("OPCODE=%d", msg->op_code);
2720
2721 if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_RESUME) ||
2722 (msg->op_code == WLAN_IPA_UC_OPCODE_RX_RESUME)) {
2723 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2724 ipa_ctx->activated_fw_pipe++;
Yun Parka29974a2018-04-09 12:05:49 -07002725 if (wlan_ipa_is_fw_wdi_activated(ipa_ctx)) {
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302726 ipa_ctx->resource_loading = false;
2727 qdf_event_set(&ipa_ctx->ipa_resource_comp);
2728 if (ipa_ctx->wdi_enabled == false) {
2729 ipa_ctx->wdi_enabled = true;
2730 if (wlan_ipa_uc_send_wdi_control_msg(true) == 0)
2731 wlan_ipa_send_mcc_scc_msg(ipa_ctx,
2732 ipa_ctx->mcc_mode);
2733 }
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302734 wlan_ipa_uc_proc_pending_event(ipa_ctx, true);
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302735 if (ipa_ctx->pending_cons_req)
Yun Parke114fbf2018-04-05 20:02:12 -07002736 wlan_ipa_wdi_rm_notify_completion(
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302737 QDF_IPA_RM_RESOURCE_GRANTED,
2738 QDF_IPA_RM_RESOURCE_WLAN_CONS);
2739 ipa_ctx->pending_cons_req = false;
2740 }
2741 qdf_mutex_release(&ipa_ctx->ipa_lock);
2742 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_TX_SUSPEND) ||
2743 (msg->op_code == WLAN_IPA_UC_OPCODE_RX_SUSPEND)) {
2744 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
Sravan Kumar Kairama61e5a92018-06-18 13:01:05 +05302745
2746 if (msg->op_code == WLAN_IPA_UC_OPCODE_RX_SUSPEND) {
2747 wlan_ipa_uc_disable_pipes(ipa_ctx);
2748 ipa_info("Disable FW TX PIPE");
2749 cdp_ipa_set_active(ipa_ctx->dp_soc, ipa_ctx->dp_pdev,
2750 false, true);
2751 }
2752
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302753 ipa_ctx->activated_fw_pipe--;
2754 if (!ipa_ctx->activated_fw_pipe) {
2755 /*
2756 * Async return success from FW
2757 * Disable/suspend all the PIPEs
2758 */
2759 ipa_ctx->resource_unloading = false;
2760 qdf_event_set(&ipa_ctx->ipa_resource_comp);
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302761 if (wlan_ipa_is_rm_enabled(ipa_ctx->config))
Yun Parke114fbf2018-04-05 20:02:12 -07002762 wlan_ipa_wdi_rm_release_resource(ipa_ctx,
2763 QDF_IPA_RM_RESOURCE_WLAN_PROD);
Sravan Kumar Kairam5214f652018-03-13 09:52:31 +05302764 wlan_ipa_uc_proc_pending_event(ipa_ctx, false);
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302765 ipa_ctx->pending_cons_req = false;
2766 }
2767 qdf_mutex_release(&ipa_ctx->ipa_lock);
2768 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) &&
2769 (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_DEBUG)) {
2770 uc_fw_stat = (struct ipa_uc_fw_stats *)
2771 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2772
2773 /* WLAN FW WDI stats */
2774 wlan_ipa_print_fw_wdi_stats(ipa_ctx, uc_fw_stat);
2775 } else if ((msg->op_code == WLAN_IPA_UC_OPCODE_STATS) &&
2776 (ipa_ctx->stat_req_reason == WLAN_IPA_UC_STAT_REASON_BW_CAL)) {
2777 /* STATs from FW */
2778 uc_fw_stat = (struct ipa_uc_fw_stats *)
2779 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2780 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2781 ipa_ctx->ipa_tx_packets_diff = BW_GET_DIFF(
2782 uc_fw_stat->tx_pkts_completed,
2783 ipa_ctx->ipa_p_tx_packets);
2784 ipa_ctx->ipa_rx_packets_diff = BW_GET_DIFF(
2785 (uc_fw_stat->rx_num_ind_drop_no_space +
2786 uc_fw_stat->rx_num_ind_drop_no_buf +
2787 uc_fw_stat->rx_num_pkts_indicated),
2788 ipa_ctx->ipa_p_rx_packets);
2789
2790 ipa_ctx->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2791 ipa_ctx->ipa_p_rx_packets =
2792 (uc_fw_stat->rx_num_ind_drop_no_space +
2793 uc_fw_stat->rx_num_ind_drop_no_buf +
2794 uc_fw_stat->rx_num_pkts_indicated);
2795 qdf_mutex_release(&ipa_ctx->ipa_lock);
2796 } else if (msg->op_code == WLAN_IPA_UC_OPCODE_UC_READY) {
2797 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2798 wlan_ipa_uc_loaded_handler(ipa_ctx);
2799 qdf_mutex_release(&ipa_ctx->ipa_lock);
2800 } else if (wlan_ipa_uc_op_metering(ipa_ctx, op_msg)) {
2801 ipa_err("Invalid message: op_code=%d, reason=%d",
2802 msg->op_code, ipa_ctx->stat_req_reason);
2803 }
2804
2805 qdf_mem_free(op_msg);
2806}
2807
2808/**
jitiphilfdcaaba2018-09-03 16:19:52 +05302809 * __wlan_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2810 * @data: uC OP work
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302811 *
2812 * Return: None
2813 */
jitiphilfdcaaba2018-09-03 16:19:52 +05302814static void __wlan_ipa_uc_fw_op_event_handler(void *data)
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302815{
2816 struct op_msg_type *msg;
2817 struct uc_op_work_struct *uc_op_work =
2818 (struct uc_op_work_struct *)data;
2819 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
2820
jitiphilfdcaaba2018-09-03 16:19:52 +05302821 if (qdf_is_module_state_transitioning()) {
2822 ipa_err("Module transition in progress");
2823 return;
2824 }
2825
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302826 msg = uc_op_work->msg;
2827 uc_op_work->msg = NULL;
2828 ipa_debug("posted msg %d", msg->op_code);
2829
2830 wlan_ipa_uc_op_cb(msg, ipa_ctx);
2831}
2832
2833/**
jitiphilfdcaaba2018-09-03 16:19:52 +05302834 * wlan_ipa_uc_fw_op_event_handler - SSR wrapper for
2835 * __wlan_ipa_uc_fw_op_event_handler
2836 * @data: uC OP work
2837 *
2838 * Return: None
2839 */
2840static void wlan_ipa_uc_fw_op_event_handler(void *data)
2841{
2842 qdf_ssr_protect(__func__);
2843 __wlan_ipa_uc_fw_op_event_handler(data);
2844 qdf_ssr_unprotect(__func__);
2845}
2846
2847/**
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302848 * wlan_ipa_uc_op_event_handler() - IPA UC OP event handler
2849 * @op_msg: operation message received from firmware
2850 * @ipa_ctx: Global IPA context
2851 *
2852 * Return: None
2853 */
2854static void wlan_ipa_uc_op_event_handler(uint8_t *op_msg, void *ctx)
2855{
2856 struct wlan_ipa_priv *ipa_ctx = (struct wlan_ipa_priv *)ctx;
2857 struct op_msg_type *msg;
2858 struct uc_op_work_struct *uc_op_work;
2859
2860 if (!ipa_ctx)
2861 goto end;
2862
2863 msg = (struct op_msg_type *)op_msg;
2864
2865 if (msg->op_code >= WLAN_IPA_UC_OPCODE_MAX) {
2866 ipa_err("Invalid OP Code (%d)", msg->op_code);
2867 goto end;
2868 }
2869
2870 uc_op_work = &ipa_ctx->uc_op_work[msg->op_code];
2871 if (uc_op_work->msg) {
2872 /* When the same uC OPCODE is already pended, just return */
2873 goto end;
2874 }
2875
2876 uc_op_work->msg = msg;
2877 qdf_sched_work(0, &uc_op_work->work);
2878 return;
2879
2880end:
2881 qdf_mem_free(op_msg);
2882}
2883
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302884QDF_STATUS wlan_ipa_uc_ol_init(struct wlan_ipa_priv *ipa_ctx,
2885 qdf_device_t osdev)
2886{
2887 uint8_t i;
2888 QDF_STATUS status = QDF_STATUS_SUCCESS;
2889
2890 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config))
2891 return QDF_STATUS_SUCCESS;
2892
2893 ipa_debug("enter");
2894
2895 for (i = 0; i < WLAN_IPA_MAX_SESSION; i++) {
2896 ipa_ctx->vdev_to_iface[i] = WLAN_IPA_MAX_SESSION;
2897 ipa_ctx->vdev_offload_enabled[i] = false;
2898 }
2899
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302900 if (cdp_ipa_get_resource(ipa_ctx->dp_soc, ipa_ctx->dp_pdev)) {
2901 ipa_err("IPA UC resource alloc fail");
2902 status = QDF_STATUS_E_FAILURE;
2903 goto fail_return;
2904 }
2905
2906 if (true == ipa_ctx->uc_loaded) {
2907 status = wlan_ipa_wdi_setup(ipa_ctx, osdev);
2908 if (status) {
2909 ipa_err("Failure to setup IPA pipes (status=%d)",
2910 status);
2911 status = QDF_STATUS_E_FAILURE;
2912 goto fail_return;
2913 }
2914
2915 cdp_ipa_set_doorbell_paddr(ipa_ctx->dp_soc, ipa_ctx->dp_pdev);
2916 wlan_ipa_init_metering(ipa_ctx);
jiadf9771182018-06-12 12:43:40 +08002917
2918 if (wlan_ipa_init_perf_level(ipa_ctx) != QDF_STATUS_SUCCESS)
2919 ipa_err("Failed to init perf level");
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302920 }
2921
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302922 cdp_ipa_register_op_cb(ipa_ctx->dp_soc, ipa_ctx->dp_pdev,
2923 wlan_ipa_uc_op_event_handler, (void *)ipa_ctx);
2924
2925 for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) {
2926 qdf_create_work(0, &ipa_ctx->uc_op_work[i].work,
2927 wlan_ipa_uc_fw_op_event_handler,
2928 &ipa_ctx->uc_op_work[i]);
2929 ipa_ctx->uc_op_work[i].msg = NULL;
2930 }
2931
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302932fail_return:
2933 ipa_debug("exit: status=%d", status);
2934 return status;
2935}
2936
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302937/**
2938 * wlan_ipa_cleanup_pending_event() - Cleanup IPA pending event list
2939 * @ipa_ctx: pointer to IPA IPA struct
2940 *
2941 * Return: none
2942 */
2943static void wlan_ipa_cleanup_pending_event(struct wlan_ipa_priv *ipa_ctx)
2944{
2945 struct wlan_ipa_uc_pending_event *pending_event = NULL;
2946
2947 while (qdf_list_remove_front(&ipa_ctx->pending_event,
2948 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS)
2949 qdf_mem_free(pending_event);
2950}
2951
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302952QDF_STATUS wlan_ipa_uc_ol_deinit(struct wlan_ipa_priv *ipa_ctx)
2953{
2954 QDF_STATUS status = QDF_STATUS_SUCCESS;
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302955 int i;
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302956
2957 ipa_debug("enter");
2958
2959 if (!wlan_ipa_uc_is_enabled(ipa_ctx->config))
2960 return status;
2961
2962 if (!ipa_ctx->ipa_pipes_down)
2963 wlan_ipa_uc_disable_pipes(ipa_ctx);
2964
2965 if (true == ipa_ctx->uc_loaded) {
2966 status = cdp_ipa_cleanup(ipa_ctx->dp_soc,
2967 ipa_ctx->tx_pipe_handle,
2968 ipa_ctx->rx_pipe_handle);
2969 if (status)
2970 ipa_err("Failure to cleanup IPA pipes (status=%d)",
2971 status);
2972 }
2973
Sravan Kumar Kairam7d931ff2018-03-13 09:42:02 +05302974 qdf_mutex_acquire(&ipa_ctx->ipa_lock);
2975 wlan_ipa_cleanup_pending_event(ipa_ctx);
2976 qdf_mutex_release(&ipa_ctx->ipa_lock);
2977
2978 for (i = 0; i < WLAN_IPA_UC_OPCODE_MAX; i++) {
2979 qdf_cancel_work(&ipa_ctx->uc_op_work[i].work);
2980 qdf_mem_free(ipa_ctx->uc_op_work[i].msg);
2981 ipa_ctx->uc_op_work[i].msg = NULL;
2982 }
2983
Sravan Kumar Kairam1309e7e2018-03-13 09:29:52 +05302984 ipa_debug("exit: ret=%d", status);
2985 return status;
2986}
Sravan Kumar Kairam983a4452018-03-20 13:30:22 +05302987
Sravan Kumar Kairamce792eb2018-06-15 15:07:11 +05302988/**
2989 * wlan_ipa_uc_send_evt() - send event to ipa
2990 * @net_dev: Interface net device
2991 * @type: event type
2992 * @mac_addr: pointer to mac address
2993 *
2994 * Send event to IPA driver
2995 *
2996 * Return: QDF_STATUS
2997 */
2998static QDF_STATUS wlan_ipa_uc_send_evt(qdf_netdev_t net_dev,
2999 qdf_ipa_wlan_event type,
3000 uint8_t *mac_addr)
3001{
3002 struct wlan_ipa_priv *ipa_ctx = gp_ipa;
3003 qdf_ipa_msg_meta_t meta;
3004 qdf_ipa_wlan_msg_t *msg;
3005
3006 QDF_IPA_MSG_META_MSG_LEN(&meta) = sizeof(qdf_ipa_wlan_msg_t);
3007 msg = qdf_mem_malloc(QDF_IPA_MSG_META_MSG_LEN(&meta));
3008 if (!msg) {
3009 ipa_err("msg allocation failed");
3010 return QDF_STATUS_E_NOMEM;
3011 }
3012
3013 QDF_IPA_SET_META_MSG_TYPE(&meta, type);
3014 qdf_str_lcopy(QDF_IPA_WLAN_MSG_NAME(msg), net_dev->name,
3015 IPA_RESOURCE_NAME_MAX);
3016 qdf_mem_copy(QDF_IPA_WLAN_MSG_MAC_ADDR(msg), mac_addr, QDF_NET_ETH_LEN);
3017
3018 if (qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn)) {
3019 ipa_err("%s: Evt: %d fail",
3020 QDF_IPA_WLAN_MSG_NAME(msg),
3021 QDF_IPA_MSG_META_MSG_TYPE(&meta));
3022 qdf_mem_free(msg);
3023
3024 return QDF_STATUS_E_FAILURE;
3025 }
3026
3027 ipa_ctx->stats.num_send_msg++;
3028
3029 return QDF_STATUS_SUCCESS;
3030}
3031
3032QDF_STATUS wlan_ipa_uc_disconnect_ap(struct wlan_ipa_priv *ipa_ctx,
3033 qdf_netdev_t net_dev)
3034{
3035 struct wlan_ipa_iface_context *iface_ctx;
3036 QDF_STATUS status;
3037
3038 ipa_debug("enter");
3039
3040 iface_ctx = wlan_ipa_get_iface(ipa_ctx, QDF_SAP_MODE);
3041 if (iface_ctx)
3042 status = wlan_ipa_uc_send_evt(net_dev, QDF_IPA_AP_DISCONNECT,
3043 net_dev->dev_addr);
3044 else
3045 return QDF_STATUS_E_INVAL;
3046
3047 ipa_debug("exit :%d", status);
3048
3049 return status;
3050}
3051
3052void wlan_ipa_cleanup_dev_iface(struct wlan_ipa_priv *ipa_ctx,
3053 qdf_netdev_t net_dev)
3054{
3055 struct wlan_ipa_iface_context *iface_ctx;
3056 int i;
3057
3058 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
3059 iface_ctx = &ipa_ctx->iface_context[i];
3060 if (iface_ctx->dev == net_dev)
3061 break;
3062 }
3063
3064 if (iface_ctx)
3065 wlan_ipa_cleanup_iface(iface_ctx);
3066}
Sravan Kumar Kairam657f89e2018-09-18 10:13:37 +05303067
3068void wlan_ipa_uc_ssr_cleanup(struct wlan_ipa_priv *ipa_ctx)
3069{
3070 struct wlan_ipa_iface_context *iface;
3071 int i;
3072
3073 ipa_info("enter");
3074
3075 for (i = 0; i < WLAN_IPA_MAX_IFACE; i++) {
3076 iface = &ipa_ctx->iface_context[i];
3077 if (iface->dev) {
3078 if (iface->device_mode == QDF_SAP_MODE)
3079 wlan_ipa_uc_send_evt(iface->dev,
3080 QDF_IPA_AP_DISCONNECT,
3081 iface->dev->dev_addr);
3082 else if (iface->device_mode == QDF_STA_MODE)
3083 wlan_ipa_uc_send_evt(iface->dev,
3084 QDF_IPA_STA_DISCONNECT,
3085 iface->dev->dev_addr);
3086 wlan_ipa_cleanup_iface(iface);
3087 }
3088 }
3089}
jitiphil0e3b5922018-07-24 18:43:50 +05303090
3091void wlan_ipa_fw_rejuvenate_send_msg(struct wlan_ipa_priv *ipa_ctx)
3092{
3093 qdf_ipa_msg_meta_t meta;
3094 qdf_ipa_wlan_msg_t *msg;
3095 int ret;
3096
3097 meta.msg_len = sizeof(*msg);
3098 msg = qdf_mem_malloc(meta.msg_len);
3099 if (!msg) {
3100 ipa_debug("msg allocation failed");
3101 return;
3102 }
3103
3104 QDF_IPA_SET_META_MSG_TYPE(&meta, QDF_FWR_SSR_BEFORE_SHUTDOWN);
3105 ipa_debug("ipa_send_msg(Evt:%d)",
3106 meta.msg_type);
3107 ret = qdf_ipa_send_msg(&meta, msg, wlan_ipa_msg_free_fn);
3108
3109 if (ret) {
3110 ipa_err("ipa_send_msg(Evt:%d)-fail=%d",
3111 meta.msg_type, ret);
3112 qdf_mem_free(msg);
3113 }
3114 ipa_ctx->stats.num_send_msg++;
3115}