blob: 69cbf006e891ccc2b677864d0cf6eb289c10074e [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ipa.c
30 *
31 * WLAN HDD and ipa interface implementation
32 * Originally written by Qualcomm Atheros, Inc
33 */
34
35#ifdef IPA_OFFLOAD
36
37/* Include Files */
38#include <wlan_hdd_includes.h>
39#include <wlan_hdd_ipa.h>
40
41#include <linux/etherdevice.h>
42#include <linux/atomic.h>
43#include <linux/netdevice.h>
44#include <linux/skbuff.h>
45#include <linux/list.h>
46#include <linux/debugfs.h>
47#include <linux/inetdevice.h>
48#include <linux/ip.h>
49#include <wlan_hdd_softap_tx_rx.h>
50#include <ol_txrx_osif_api.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070051#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080052
53#include "cds_sched.h"
54
55#include "wma.h"
56#include "wma_api.h"
57
Dhanashri Atreb08959a2016-03-01 17:28:03 -080058#include "cdp_txrx_ipa.h"
59
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080060#define HDD_IPA_DESC_BUFFER_RATIO 4
61#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
62#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
63
64#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
65#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET 12
66#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
67/* WDI TX and RX PIPE */
68#define HDD_IPA_UC_NUM_WDI_PIPE 2
69#define HDD_IPA_UC_MAX_PENDING_EVENT 33
70
71#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
72#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
73#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
74#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
75
76#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
77#define HDD_IPA_MAX_IFACE 3
78#define HDD_IPA_MAX_SYSBAM_PIPE 4
79#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
80#define HDD_IPA_ENABLE_MASK BIT(0)
81#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
82#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
83#define HDD_IPA_RM_ENABLE_MASK BIT(3)
84#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
85#define HDD_IPA_UC_ENABLE_MASK BIT(5)
86#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
87#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
88
Yun Parkf19e07d2015-11-20 11:34:27 -080089#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
90
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080091typedef enum {
92 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
93 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
94 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
95 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
96 HDD_IPA_UC_OPCODE_STATS = 4,
97 /* keep this last */
98 HDD_IPA_UC_OPCODE_MAX
99} hdd_ipa_uc_op_code;
100
101/**
102 * enum - Reason codes for stat query
103 *
104 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
105 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
106 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
107 */
108enum {
109 HDD_IPA_UC_STAT_REASON_NONE,
110 HDD_IPA_UC_STAT_REASON_DEBUG,
111 HDD_IPA_UC_STAT_REASON_BW_CAL
112};
113
114/**
115 * enum hdd_ipa_rm_state - IPA resource manager state
116 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
117 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
118 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
119 */
120enum hdd_ipa_rm_state {
121 HDD_IPA_RM_RELEASED,
122 HDD_IPA_RM_GRANT_PENDING,
123 HDD_IPA_RM_GRANTED,
124};
125
126struct llc_snap_hdr {
127 uint8_t dsap;
128 uint8_t ssap;
129 uint8_t resv[4];
130 __be16 eth_type;
131} __packed;
132
Leo Chang3bc8fed2015-11-13 10:59:47 -0800133/**
134 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
135 * @eth: ether II header
136 * @llc_snap: LLC snap header
137 *
138 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800139struct hdd_ipa_tx_hdr {
140 struct ethhdr eth;
141 struct llc_snap_hdr llc_snap;
142} __packed;
143
Leo Chang3bc8fed2015-11-13 10:59:47 -0800144/**
145 * struct frag_header - fragment header type registered to IPA hardware
146 * @length: fragment length
147 * @reserved1: Reserved not used
148 * @reserved2: Reserved not used
149 *
150 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800151struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800152 uint16_t length;
153 uint32_t reserved1;
154 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800155} __packed;
156
Leo Chang3bc8fed2015-11-13 10:59:47 -0800157/**
158 * struct ipa_header - ipa header type registered to IPA hardware
159 * @vdev_id: vdev id
160 * @reserved: Reserved not used
161 *
162 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800163struct ipa_header {
164 uint32_t
165 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
166 reserved:24;
167} __packed;
168
Leo Chang3bc8fed2015-11-13 10:59:47 -0800169/**
170 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
171 * @frag_hd: fragment header
172 * @ipa_hd: ipa header
173 * @eth: ether II header
174 *
175 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800176struct hdd_ipa_uc_tx_hdr {
177 struct frag_header frag_hd;
178 struct ipa_header ipa_hd;
179 struct ethhdr eth;
180} __packed;
181
182#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
183#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct frag_header)
184
185/**
186 * struct hdd_ipa_cld_hdr - IPA CLD Header
187 * @reserved: reserved fields
188 * @iface_id: interface ID
189 * @sta_id: Station ID
190 *
191 * Packed 32-bit structure
192 * +----------+----------+--------------+--------+
193 * | Reserved | QCMAP ID | interface id | STA ID |
194 * +----------+----------+--------------+--------+
195 */
196struct hdd_ipa_cld_hdr {
197 uint8_t reserved[2];
198 uint8_t iface_id;
199 uint8_t sta_id;
200} __packed;
201
202struct hdd_ipa_rx_hdr {
203 struct hdd_ipa_cld_hdr cld_hdr;
204 struct ethhdr eth;
205} __packed;
206
207struct hdd_ipa_pm_tx_cb {
208 struct hdd_ipa_iface_context *iface_context;
209 struct ipa_rx_data *ipa_tx_desc;
210};
211
212struct hdd_ipa_uc_rx_hdr {
213 struct ethhdr eth;
214} __packed;
215
216struct hdd_ipa_sys_pipe {
217 uint32_t conn_hdl;
218 uint8_t conn_hdl_valid;
219 struct ipa_sys_connect_params ipa_sys_params;
220};
221
222struct hdd_ipa_iface_stats {
223 uint64_t num_tx;
224 uint64_t num_tx_drop;
225 uint64_t num_tx_err;
226 uint64_t num_tx_cac_drop;
227 uint64_t num_rx_prefilter;
228 uint64_t num_rx_ipa_excep;
229 uint64_t num_rx_recv;
230 uint64_t num_rx_recv_mul;
231 uint64_t num_rx_send_desc_err;
232 uint64_t max_rx_mul;
233};
234
235struct hdd_ipa_priv;
236
237struct hdd_ipa_iface_context {
238 struct hdd_ipa_priv *hdd_ipa;
239 hdd_adapter_t *adapter;
240 void *tl_context;
241
242 enum ipa_client_type cons_client;
243 enum ipa_client_type prod_client;
244
245 uint8_t iface_id; /* This iface ID */
246 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530247 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800248 uint32_t ifa_address;
249 struct hdd_ipa_iface_stats stats;
250};
251
252struct hdd_ipa_stats {
253 uint32_t event[IPA_WLAN_EVENT_MAX];
254 uint64_t num_send_msg;
255 uint64_t num_free_msg;
256
257 uint64_t num_rm_grant;
258 uint64_t num_rm_release;
259 uint64_t num_rm_grant_imm;
260 uint64_t num_cons_perf_req;
261 uint64_t num_prod_perf_req;
262
263 uint64_t num_rx_drop;
264 uint64_t num_rx_ipa_tx_dp;
265 uint64_t num_rx_ipa_splice;
266 uint64_t num_rx_ipa_loop;
267 uint64_t num_rx_ipa_tx_dp_err;
268 uint64_t num_rx_ipa_write_done;
269 uint64_t num_max_ipa_tx_mul;
270 uint64_t num_rx_ipa_hw_maxed_out;
271 uint64_t max_pend_q_cnt;
272
273 uint64_t num_tx_comp_cnt;
274 uint64_t num_tx_queued;
275 uint64_t num_tx_dequeued;
276 uint64_t num_max_pm_queue;
277
278 uint64_t num_freeq_empty;
279 uint64_t num_pri_freeq_empty;
280 uint64_t num_rx_excep;
281 uint64_t num_tx_bcmc;
282 uint64_t num_tx_bcmc_err;
283};
284
285struct ipa_uc_stas_map {
286 bool is_reserved;
287 uint8_t sta_id;
288};
289struct op_msg_type {
290 uint8_t msg_t;
291 uint8_t rsvd;
292 uint16_t op_code;
293 uint16_t len;
294 uint16_t rsvd_snd;
295};
296
297struct ipa_uc_fw_stats {
298 uint32_t tx_comp_ring_base;
299 uint32_t tx_comp_ring_size;
300 uint32_t tx_comp_ring_dbell_addr;
301 uint32_t tx_comp_ring_dbell_ind_val;
302 uint32_t tx_comp_ring_dbell_cached_val;
303 uint32_t tx_pkts_enqueued;
304 uint32_t tx_pkts_completed;
305 uint32_t tx_is_suspend;
306 uint32_t tx_reserved;
307 uint32_t rx_ind_ring_base;
308 uint32_t rx_ind_ring_size;
309 uint32_t rx_ind_ring_dbell_addr;
310 uint32_t rx_ind_ring_dbell_ind_val;
311 uint32_t rx_ind_ring_dbell_ind_cached_val;
312 uint32_t rx_ind_ring_rdidx_addr;
313 uint32_t rx_ind_ring_rd_idx_cached_val;
314 uint32_t rx_refill_idx;
315 uint32_t rx_num_pkts_indicated;
316 uint32_t rx_buf_refilled;
317 uint32_t rx_num_ind_drop_no_space;
318 uint32_t rx_num_ind_drop_no_buf;
319 uint32_t rx_is_suspend;
320 uint32_t rx_reserved;
321};
322
323struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530324 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800325 hdd_adapter_t *adapter;
326 enum ipa_wlan_event type;
327 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530328 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800329};
330
331/**
332 * struct uc_rm_work_struct
333 * @work: uC RM work
334 * @event: IPA RM event
335 */
336struct uc_rm_work_struct {
337 struct work_struct work;
338 enum ipa_rm_event event;
339};
340
341/**
342 * struct uc_op_work_struct
343 * @work: uC OP work
344 * @msg: OP message
345 */
346struct uc_op_work_struct {
347 struct work_struct work;
348 struct op_msg_type *msg;
349};
350static uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
351
352/**
353 * struct uc_rt_debug_info
354 * @time: system time
355 * @ipa_excep_count: IPA exception packet count
356 * @rx_drop_count: IPA Rx drop packet count
357 * @net_sent_count: IPA Rx packet sent to network stack count
358 * @rx_discard_count: IPA Rx discard packet count
359 * @rx_mcbc_count: IPA Rx BCMC packet count
360 * @tx_mcbc_count: IPA Tx BCMC packet countt
361 * @tx_fwd_count: IPA Tx forward packet count
362 * @rx_destructor_call: IPA Rx packet destructor count
363 */
364struct uc_rt_debug_info {
Anurag Chouhan6d760662016-02-20 16:05:43 +0530365 unsigned long time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800366 uint64_t ipa_excep_count;
367 uint64_t rx_drop_count;
368 uint64_t net_sent_count;
369 uint64_t rx_discard_count;
370 uint64_t rx_mcbc_count;
371 uint64_t tx_mcbc_count;
372 uint64_t tx_fwd_count;
373 uint64_t rx_destructor_call;
374};
375
376struct hdd_ipa_priv {
377 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
378 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
379 uint8_t num_iface;
380 enum hdd_ipa_rm_state rm_state;
381 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530382 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800383 * APIs as it is taken care gracefully. Without this, kernel would throw
384 * an warning if spin_lock_bh is used while IRQ is disabled
385 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530386 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387 struct uc_rm_work_struct uc_rm_work;
388 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530389 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800390 struct delayed_work wake_lock_work;
391 bool wake_lock_released;
392
393 enum ipa_client_type prod_client;
394
395 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530396 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800397 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530398 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399 bool suspended;
400
401 uint32_t pending_hw_desc_cnt;
402 uint32_t hw_desc_cnt;
403 spinlock_t q_lock;
404 uint32_t freeq_cnt;
405 struct list_head free_desc_head;
406
407 uint32_t pend_q_cnt;
408 struct list_head pend_desc_head;
409
410 hdd_context_t *hdd_ctx;
411
412 struct dentry *debugfs_dir;
413 struct hdd_ipa_stats stats;
414
415 struct notifier_block ipv4_notifier;
416 uint32_t curr_prod_bw;
417 uint32_t curr_cons_bw;
418
419 uint8_t activated_fw_pipe;
420 uint8_t sap_num_connected_sta;
421 uint8_t sta_connected;
422 uint32_t tx_pipe_handle;
423 uint32_t rx_pipe_handle;
424 bool resource_loading;
425 bool resource_unloading;
426 bool pending_cons_req;
427 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530428 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530429 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700430 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800431 uint32_t ipa_tx_packets_diff;
432 uint32_t ipa_rx_packets_diff;
433 uint32_t ipa_p_tx_packets;
434 uint32_t ipa_p_rx_packets;
435 uint32_t stat_req_reason;
436 uint64_t ipa_tx_forward;
437 uint64_t ipa_rx_discard;
438 uint64_t ipa_rx_net_send_count;
439 uint64_t ipa_rx_internel_drop_count;
440 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530441 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800442 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
443 unsigned int rt_buf_fill_index;
Anurag Chouhan210db072016-02-22 18:42:15 +0530444 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530445 qdf_mutex_t rt_debug_lock;
446 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800447 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800448 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530449 qdf_dma_addr_t tx_comp_doorbell_paddr;
450 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800451};
452
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800453/**
Houston Hoffman23e76f92016-02-26 12:19:11 -0800454 * FIXME: The following conversion routines are just stubs.
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800455 * They will be implemented fully by another update.
456 * The stubs will let the compile go ahead, and functionality
457 * is broken.
458 * This should be OK and IPA is not enabled yet
459 */
460void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
461{
462 void *vaddr;
463 uint32_t ipa_priv = priv;
464
465 vaddr = &ipa_priv; /* just to use the var */
466 vaddr = NULL;
467 return vaddr;
468}
469
470uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
471{
472 uint32_t ipa_priv = 0;
473
474 BUG_ON(ptr == NULL);
475 return ipa_priv;
476}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
478#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
479#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
480#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
481#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
482#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
483
Leo Chang3bc8fed2015-11-13 10:59:47 -0800484#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
485#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
486
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800487#define HDD_IPA_GET_IFACE_ID(_data) \
488 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
489
490#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530491 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492 "%s:%d: "fmt, __func__, __LINE__, ## args)
493
494#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
495 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530496 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
497 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498 } while (0)
499
500#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
501 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
502
503#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
504 do { \
505 hdd_ipa->ipa_rx_internel_drop_count++; \
506 } while (0)
507#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
508 do { \
509 hdd_ipa->ipa_rx_net_send_count++; \
510 } while (0)
511#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
512
Leo Chang3bc8fed2015-11-13 10:59:47 -0800513/* Temporary macro to make a build without IPA V2 */
514#ifdef IPA_V2
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800515#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
516do { \
517 pipe_in.u.ul.rdy_ring_rp_va = \
518 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
519 pipe_in.u.ul.rdy_comp_ring_base_pa = \
520 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
521 pipe_in.u.ul.rdy_comp_ring_size = \
522 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
523 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
524 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
525 pipe_in.u.ul.rdy_comp_ring_wp_va = \
526 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800527} while (0)
528#else
529/* Do nothing */
530#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
531#endif /* IPA_V2 */
532
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800533static struct hdd_ipa_adapter_2_client {
534 enum ipa_client_type cons_client;
535 enum ipa_client_type prod_client;
536} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
537 {
538 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
539 }, {
540 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
541 }, {
542 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
543 },
544};
545
546/* For Tx pipes, use Ethernet-II Header format */
547struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
548 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800549 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550 0x00000000,
551 0x00000000
552 },
553 {
554 0x00000000
555 },
556 {
557 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
558 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
559 0x0008
560 }
561};
562
563/* For Tx pipes, use 802.3 Header format */
564static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
565 {
566 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
567 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
568 0x00 /* length can be zero */
569 },
570 {
571 /* LLC SNAP header 8 bytes */
572 0xaa, 0xaa,
573 {0x03, 0x00, 0x00, 0x00},
574 0x0008 /* type value(2 bytes) ,filled by wlan */
575 /* 0x0800 - IPV4, 0x86dd - IPV6 */
576 }
577};
578
579static const char *op_string[] = {
580 "TX_SUSPEND",
581 "TX_RESUME",
582 "RX_SUSPEND",
583 "RX_RESUME",
584 "STATS",
585};
586
587static struct hdd_ipa_priv *ghdd_ipa;
588
589/* Local Function Prototypes */
590static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
591 unsigned long data);
592static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
593 unsigned long data);
594
595static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
596
597/**
598 * hdd_ipa_is_enabled() - Is IPA enabled?
599 * @hdd_ctx: Global HDD context
600 *
601 * Return: true if IPA is enabled, false otherwise
602 */
603bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
604{
605 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
606}
607
608/**
609 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
610 * @hdd_ctx: Global HDD context
611 *
612 * Return: true if IPA uC offload is enabled, false otherwise
613 */
614bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
615{
616 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
617}
618
619/**
620 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
621 * @hdd_ctx: Global HDD context
622 *
623 * Return: true if STA mode IPA uC offload is enabled, false otherwise
624 */
625static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
626{
627 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
628}
629
630/**
631 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
632 * @hdd_ipa: Global HDD IPA context
633 *
634 * Return: true if pre-filter is enabled, otherwise false
635 */
636static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
637{
638 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
639 HDD_IPA_PRE_FILTER_ENABLE_MASK);
640}
641
642/**
643 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
644 * @hdd_ipa: Global HDD IPA context
645 *
646 * Return: true if IPv6 is enabled, otherwise false
647 */
648static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
649{
650 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
651}
652
653/**
654 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
655 * @hdd_ipa: Global HDD IPA context
656 *
657 * Return: true if resource manager is enabled, otherwise false
658 */
659static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
660{
661 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
662}
663
664/**
665 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
666 * @hdd_ipa: Global HDD IPA context
667 *
668 * Return: true if resource manager is enabled, otherwise false
669 */
670static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
671{
672 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
673}
674
675/**
676 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
677 * @hdd_ipa: Global HDD IPA context
678 *
679 * Return: true if clock scaling is enabled, otherwise false
680 */
681static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
682{
683 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
684 HDD_IPA_CLK_SCALING_ENABLE_MASK |
685 HDD_IPA_RM_ENABLE_MASK);
686}
687
688/**
689 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
690 * @ctext: pointer to hdd context.
691 *
692 * If rt debug enabled, periodically called, and fill debug buffer
693 *
694 * Return: none
695 */
696static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
697{
698 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
699 struct hdd_ipa_priv *hdd_ipa;
700 struct uc_rt_debug_info *dump_info = NULL;
701
702 if (wlan_hdd_validate_context(hdd_ctx))
703 return;
704
705 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530706 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800707 "%s: IPA UC is not enabled", __func__);
708 return;
709 }
710
711 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
712
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530713 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800714 dump_info = &hdd_ipa->rt_bug_buffer[
715 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
716
Anurag Chouhan210db072016-02-22 18:42:15 +0530717 dump_info->time = qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800718 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
719 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
720 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
721 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
722 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
723 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
724 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
725 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530726 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800727
Anurag Chouhan210db072016-02-22 18:42:15 +0530728 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800729 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
730}
731
732/**
733 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
734 * @hdd_ctx: pointer to hdd context.
735 *
736 * If rt debug enabled, dump debug buffer contents based on requirement
737 *
738 * Return: none
739 */
740void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
741{
742 struct hdd_ipa_priv *hdd_ipa;
743 unsigned int dump_count;
744 unsigned int dump_index;
745 struct uc_rt_debug_info *dump_info = NULL;
746
747 if (wlan_hdd_validate_context(hdd_ctx))
748 return;
749
750 hdd_ipa = hdd_ctx->hdd_ipa;
751 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530752 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800753 "%s: IPA UC is not enabled", __func__);
754 return;
755 }
756
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530757 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800758 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530759 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800760 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
761
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530762 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800763 for (dump_count = 0;
764 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
765 dump_count++) {
766 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
767 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
768 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530769 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770 "%12lu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
771 dump_info->time, dump_info->ipa_excep_count,
772 dump_info->rx_drop_count, dump_info->net_sent_count,
773 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
774 dump_info->rx_destructor_call,
775 dump_info->rx_discard_count);
776 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530777 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530778 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800779 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
780}
781
782/**
783 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
784 * @ctext: pointer to hdd context.
785 *
786 * periodically called by timer expire
787 * will try to alloc dummy memory and detect out of memory condition
788 * if out of memory detected, dump wlan-ipa stats
789 *
790 * Return: none
791 */
792static void hdd_ipa_uc_rt_debug_handler(void *ctext)
793{
794 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
795 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
796 void *dummy_ptr = NULL;
797
798 if (wlan_hdd_validate_context(hdd_ctx))
799 return;
800
801 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530802 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800803 "%s: IPA RT debug is not enabled", __func__);
804 return;
805 }
806
807 /* Allocate dummy buffer periodically and free immediately. this will
808 * proactively detect OOM and if allocation fails dump ipa stats
809 */
810 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
811 GFP_KERNEL | GFP_ATOMIC);
812 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530813 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800814 "%s: Dummy alloc fail", __func__);
815 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
816 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800817 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800818 } else {
819 kfree(dummy_ptr);
820 }
821
Anurag Chouhan210db072016-02-22 18:42:15 +0530822 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800823 HDD_IPA_UC_RT_DEBUG_PERIOD);
824}
825
826/**
827 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
828 * @skb: packet pinter
829 *
830 * when free data packet, will be invoked by wlan client and will increase
831 * free counter
832 *
833 * Return: none
834 */
835void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
836{
837 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530838 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839 "%s: invalid hdd context", __func__);
840 return;
841 }
842
843 ghdd_ipa->ipa_rx_destructor_count++;
844}
845
846/**
847 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
848 * @hdd_ctx: hdd main context
849 *
850 * free all rt debugging resources
851 *
852 * Return: none
853 */
854static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
855{
856 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
857
Anurag Chouhan210db072016-02-22 18:42:15 +0530858 if (QDF_TIMER_STATE_STOPPED !=
859 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
860 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530862 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530863 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864
865 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530866 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 "%s: IPA RT debug is not enabled", __func__);
868 return;
869 }
870
Anurag Chouhan210db072016-02-22 18:42:15 +0530871 if (QDF_TIMER_STATE_STOPPED !=
872 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
873 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530875 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876}
877
878/**
879 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
880 * @hdd_ctx: hdd main context
881 *
882 * alloc and initialize all rt debugging resources
883 *
884 * Return: none
885 */
886static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
887{
888 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
889
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530890 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530891 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
893 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530894 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 sizeof(struct uc_rt_debug_info) *
896 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
897 hdd_ipa->ipa_tx_forward = 0;
898 hdd_ipa->ipa_rx_discard = 0;
899 hdd_ipa->ipa_rx_net_send_count = 0;
900 hdd_ipa->ipa_rx_internel_drop_count = 0;
901 hdd_ipa->ipa_rx_destructor_count = 0;
902
Anurag Chouhan210db072016-02-22 18:42:15 +0530903 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
905
906 /* Reatime debug enable on feature enable */
907 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530908 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 "%s: IPA RT debug is not enabled", __func__);
910 return;
911 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530912 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800913 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530914 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 HDD_IPA_UC_RT_DEBUG_PERIOD);
916
917}
918
919/**
920 * hdd_ipa_uc_stat_query() - Query the IPA stats
921 * @hdd_ctx: Global HDD context
922 * @ipa_tx_diff: tx packet count diff from previous
923 * tx packet count
924 * @ipa_rx_diff: rx packet count diff from previous
925 * rx packet count
926 *
927 * Return: true if IPA is enabled, false otherwise
928 */
929void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
930 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
931{
932 struct hdd_ipa_priv *hdd_ipa;
933
934 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
935 *ipa_tx_diff = 0;
936 *ipa_rx_diff = 0;
937
938 if (!hdd_ipa_is_enabled(pHddCtx) ||
939 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
940 return;
941 }
942
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530943 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800944 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
945 (false == hdd_ipa->resource_loading)) {
946 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
947 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
948 HDD_IPA_LOG(LOG1, "STAT Query TX DIFF %d, RX DIFF %d",
949 *ipa_tx_diff, *ipa_rx_diff);
950 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530951 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800952 return;
953}
954
955/**
956 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
957 * @adapter: network adapter
958 * @reason: STAT REQ Reason
959 *
960 * Return: None
961 */
962void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
963{
964 hdd_context_t *pHddCtx;
965 struct hdd_ipa_priv *hdd_ipa;
966
967 if (!adapter) {
968 return;
969 }
970
971 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
972 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
973 if (!hdd_ipa_is_enabled(pHddCtx) ||
974 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
975 return;
976 }
977
978 HDD_IPA_LOG(LOG1, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530979 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800980 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
981 (false == hdd_ipa->resource_loading)) {
982 hdd_ipa->stat_req_reason = reason;
983 wma_cli_set_command(
984 (int)adapter->sessionId,
985 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
986 0, VDEV_CMD);
987 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530988 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989}
990
991/**
992 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
993 * @hdd_ipa: Global HDD IPA context
994 * @sta_add: Should station be added
995 * @sta_id: ID of the station being queried
996 *
997 * Return: true if the station was found
998 */
999static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1000 bool sta_add, uint8_t sta_id)
1001{
1002 bool sta_found = false;
1003 uint8_t idx;
1004 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1005 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1006 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1007 sta_found = true;
1008 break;
1009 }
1010 }
1011 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301012 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001013 "%s: STA ID %d already exist, cannot add",
1014 __func__, sta_id);
1015 return sta_found;
1016 }
1017 if (sta_add) {
1018 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1019 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1020 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1021 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1022 return sta_found;
1023 }
1024 }
1025 }
1026 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301027 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 "%s: STA ID %d does not exist, cannot delete",
1029 __func__, sta_id);
1030 return sta_found;
1031 }
1032 if (!sta_add) {
1033 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1034 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1035 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1036 hdd_ipa->assoc_stas_map[idx].is_reserved =
1037 false;
1038 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1039 return sta_found;
1040 }
1041 }
1042 }
1043 return sta_found;
1044}
1045
1046/**
1047 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1048 * @hdd_ipa: Global HDD IPA context
1049 *
1050 * Return: 0 on success, negative errno if error
1051 */
1052static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1053{
1054 int result;
1055 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1056
1057 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301058 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001059 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1060 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001061 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1062 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301063 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064 "%s: Enable TX PIPE fail, code %d",
1065 __func__, result);
1066 return result;
1067 }
1068 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1069 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301070 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001071 "%s: Resume TX PIPE fail, code %d",
1072 __func__, result);
1073 return result;
1074 }
1075 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, true);
1076
1077 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301078 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001079 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1080 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1082 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301083 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001084 "%s: Enable RX PIPE fail, code %d",
1085 __func__, result);
1086 return result;
1087 }
1088 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1089 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301090 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 "%s: Resume RX PIPE fail, code %d",
1092 __func__, result);
1093 return result;
1094 }
1095 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001096 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001097 return 0;
1098}
1099
1100/**
1101 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1102 * @hdd_ipa: Global HDD IPA context
1103 *
1104 * Return: 0 on success, negative errno if error
1105 */
1106static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1107{
1108 int result;
1109
Leo Change3e49442015-10-26 20:07:13 -07001110 hdd_ipa->ipa_pipes_down = true;
1111
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301112 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001113 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1114 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301115 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001116 "%s: Suspend RX PIPE fail, code %d",
1117 __func__, result);
1118 return result;
1119 }
1120 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1121 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301122 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001123 "%s: Disable RX PIPE fail, code %d",
1124 __func__, result);
1125 return result;
1126 }
1127
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301128 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1130 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301131 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001132 "%s: Suspend TX PIPE fail, code %d",
1133 __func__, result);
1134 return result;
1135 }
1136 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1137 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301138 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001139 "%s: Disable TX PIPE fail, code %d",
1140 __func__, result);
1141 return result;
1142 }
1143
1144 return 0;
1145}
1146
1147/**
1148 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1149 * @hdd_ipa: Global HDD IPA context
1150 *
1151 * Return: 0 on success, negative errno if error
1152 */
1153static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1154{
1155 hdd_ipa->activated_fw_pipe = 0;
1156 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001157
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001158 /* If RM feature enabled
1159 * Request PROD Resource first
1160 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001161 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1162 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1163 /* RM PROD request sync return
1164 * enable pipe immediately
1165 */
1166 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301167 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001168 "%s: IPA WDI Pipe activation failed",
1169 __func__);
1170 hdd_ipa->resource_loading = false;
1171 return -EBUSY;
1172 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001173 }
1174 } else {
1175 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001176 * Just enabled all the PIPEs
1177 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001178 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301179 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001180 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001181 __func__);
1182 hdd_ipa->resource_loading = false;
1183 return -EBUSY;
1184 }
1185 hdd_ipa->resource_loading = false;
1186 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001187
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301188 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001189 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190 return 0;
1191}
1192
1193/**
1194 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1195 * @hdd_ipa: Global HDD IPA context
1196 *
1197 * Return: None
1198 */
1199static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1200{
1201 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1202
1203 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301204 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001205 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301206 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001207 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, true);
1208}
1209
1210/**
1211 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1212 * @context: User context registered with TL (the IPA Global context is
1213 * registered
1214 * @rxpkt: Packet containing the notification
1215 * @staid: ID of the station associated with the packet
1216 *
1217 * Return: None
1218 */
1219static void
1220hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1221{
1222 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301223 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001224
1225 /*
1226 * When SSR is going on or driver is unloading, just return.
1227 */
1228 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301229 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001231
1232 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1233 return;
1234
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301235 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 __func__, event);
1237
1238 switch (event) {
1239 case IPA_RM_RESOURCE_GRANTED:
1240 /* Differed RM Granted */
1241 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301242 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243 if ((false == hdd_ipa->resource_unloading) &&
1244 (!hdd_ipa->activated_fw_pipe)) {
1245 hdd_ipa_uc_enable_pipes(hdd_ipa);
1246 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301247 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 break;
1249
1250 case IPA_RM_RESOURCE_RELEASED:
1251 /* Differed RM Released */
1252 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001253 break;
1254
1255 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301256 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001257 "%s, invalid event code %d", __func__, event);
1258 break;
1259 }
1260}
1261
1262/**
1263 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1264 * @hdd_ipa: Global HDD IPA context
1265 * @event: IPA resource manager event to be deferred
1266 *
1267 * This function is called when a resource manager event is received
1268 * from firmware in interrupt context. This function will defer the
1269 * handling to the OL RX thread
1270 *
1271 * Return: None
1272 */
1273static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1274{
1275 enum ipa_rm_event event;
1276 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1277 struct uc_rm_work_struct, work);
1278 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1279 struct hdd_ipa_priv, uc_rm_work);
1280
1281 cds_ssr_protect(__func__);
1282 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301283 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001284 "%s, posted event %d", __func__, event);
1285
1286 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1287 cds_ssr_unprotect(__func__);
1288
1289 return;
1290}
1291
1292/**
1293 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
1294 * @hdd_ipa: Global HDD IPA context
1295 *
1296 * Return: None
1297 */
1298static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
1299{
1300 unsigned int pending_event_count;
1301 struct ipa_uc_pending_event *pending_event = NULL;
1302
Anurag Chouhanffb21542016-02-17 14:33:03 +05301303 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301304 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305 "%s, Pending Event Count %d", __func__, pending_event_count);
1306 if (!pending_event_count) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301307 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001308 "%s, No Pending Event", __func__);
1309 return;
1310 }
1311
Anurag Chouhanffb21542016-02-17 14:33:03 +05301312 qdf_list_remove_front(&hdd_ipa->pending_event,
1313 (qdf_list_node_t **)&pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001314 while (pending_event != NULL) {
1315 hdd_ipa_wlan_evt(pending_event->adapter,
1316 pending_event->type,
1317 pending_event->sta_id,
1318 pending_event->mac_addr);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301319 qdf_mem_free(pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320 pending_event = NULL;
Anurag Chouhanffb21542016-02-17 14:33:03 +05301321 qdf_list_remove_front(&hdd_ipa->pending_event,
1322 (qdf_list_node_t **)&pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 }
1324}
1325
1326/**
1327 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1328 * @op_msg: operation message received from firmware
1329 * @usr_ctxt: user context registered with TL (we register the HDD Global
1330 * context)
1331 *
1332 * Return: None
1333 */
1334static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1335{
1336 struct op_msg_type *msg = op_msg;
1337 struct ipa_uc_fw_stats *uc_fw_stat;
1338 struct IpaHwStatsWDIInfoData_t ipa_stat;
1339 struct hdd_ipa_priv *hdd_ipa;
1340 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301341 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001342
1343 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301344 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001345 return;
1346 }
1347
1348 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301349 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001350 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1351 return;
1352 }
1353
1354 hdd_ctx = (hdd_context_t *) usr_ctxt;
1355
1356 /*
1357 * When SSR is going on or driver is unloading, just return.
1358 */
1359 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301360 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301361 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001362 return;
1363 }
1364
1365 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1366
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301367 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001368 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1369
1370 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1371 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301372 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001373 hdd_ipa->activated_fw_pipe++;
1374 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1375 hdd_ipa->resource_loading = false;
1376 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001377 if (hdd_ipa->pending_cons_req)
1378 ipa_rm_notify_completion(
1379 IPA_RM_RESOURCE_GRANTED,
1380 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001381 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001382 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301383 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384 }
1385
1386 if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
1387 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301388 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001389 hdd_ipa->activated_fw_pipe--;
1390 if (!hdd_ipa->activated_fw_pipe) {
1391 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001392 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1393 ipa_rm_release_resource(
1394 IPA_RM_RESOURCE_WLAN_PROD);
1395 /* Sync return success from IPA
1396 * Enable/resume all the PIPEs */
1397 hdd_ipa->resource_unloading = false;
1398 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1399 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001400 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301401 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402 }
1403
1404 if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1405 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001406 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001407 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301408 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001409 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001410 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001411 "CE RING SIZE: %d\n"
1412 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001413 (unsigned long long)res->ce_sr_base_paddr,
1414 res->ce_sr_ring_size,
1415 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301416 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001417 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001418 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419 "COMP RING SIZE: %d\n"
1420 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001421 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001422 (unsigned long long)res->tx_comp_ring_base_paddr,
1423 res->tx_comp_ring_size,
1424 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001425 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301426 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001428 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001429 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001430 "IND RING DBELL : 0x%llx\n"
1431 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001432 "NUM EXCP PKT : %llu\n"
1433 "NUM TX BCMC : %llu\n"
1434 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001435 (unsigned long long)res->rx_rdy_ring_base_paddr,
1436 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001437 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001438 (unsigned long long)hdd_ipa->ipa_resource.
1439 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 hdd_ipa->stats.num_rx_excep,
1441 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001442 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301443 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001444 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1445 "SAP NUM STAs: %d\n"
1446 "STA CONNECTED: %d\n"
1447 "TX PIPE HDL: %d\n"
1448 "RX PIPE HDL : %d\n"
1449 "RSC LOADING : %d\n"
1450 "RSC UNLOADING : %d\n"
1451 "PNDNG CNS RQT : %d",
1452 hdd_ipa->sap_num_connected_sta,
1453 hdd_ipa->sta_connected,
1454 hdd_ipa->tx_pipe_handle,
1455 hdd_ipa->rx_pipe_handle,
1456 (unsigned int)hdd_ipa->resource_loading,
1457 (unsigned int)hdd_ipa->resource_unloading,
1458 (unsigned int)hdd_ipa->pending_cons_req);
1459
1460 /* STATs from FW */
1461 uc_fw_stat = (struct ipa_uc_fw_stats *)
1462 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301463 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464 "==== IPA_UC WLAN_FW TX ====\n"
1465 "COMP RING BASE: 0x%x\n"
1466 "COMP RING SIZE: %d\n"
1467 "COMP RING DBELL : 0x%x\n"
1468 "COMP RING DBELL IND VAL : %d\n"
1469 "COMP RING DBELL CACHED VAL : %d\n"
1470 "COMP RING DBELL CACHED VAL : %d\n"
1471 "PKTS ENQ : %d\n"
1472 "PKTS COMP : %d\n"
1473 "IS SUSPEND : %d\n"
1474 "RSVD : 0x%x",
1475 uc_fw_stat->tx_comp_ring_base,
1476 uc_fw_stat->tx_comp_ring_size,
1477 uc_fw_stat->tx_comp_ring_dbell_addr,
1478 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1479 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1480 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1481 uc_fw_stat->tx_pkts_enqueued,
1482 uc_fw_stat->tx_pkts_completed,
1483 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301484 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001485 "==== IPA_UC WLAN_FW RX ====\n"
1486 "IND RING BASE: 0x%x\n"
1487 "IND RING SIZE: %d\n"
1488 "IND RING DBELL : 0x%x\n"
1489 "IND RING DBELL IND VAL : %d\n"
1490 "IND RING DBELL CACHED VAL : %d\n"
1491 "RDY IND ADDR : 0x%x\n"
1492 "RDY IND CACHE VAL : %d\n"
1493 "RFIL IND : %d\n"
1494 "NUM PKT INDICAT : %d\n"
1495 "BUF REFIL : %d\n"
1496 "NUM DROP NO SPC : %d\n"
1497 "NUM DROP NO BUF : %d\n"
1498 "IS SUSPND : %d\n"
1499 "RSVD : 0x%x\n",
1500 uc_fw_stat->rx_ind_ring_base,
1501 uc_fw_stat->rx_ind_ring_size,
1502 uc_fw_stat->rx_ind_ring_dbell_addr,
1503 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1504 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1505 uc_fw_stat->rx_ind_ring_rdidx_addr,
1506 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1507 uc_fw_stat->rx_refill_idx,
1508 uc_fw_stat->rx_num_pkts_indicated,
1509 uc_fw_stat->rx_buf_refilled,
1510 uc_fw_stat->rx_num_ind_drop_no_space,
1511 uc_fw_stat->rx_num_ind_drop_no_buf,
1512 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1513 /* STATs from IPA */
1514 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301515 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 "==== IPA_UC IPA TX ====\n"
1517 "NUM PROCD : %d\n"
1518 "CE DBELL : 0x%x\n"
1519 "NUM DBELL FIRED : %d\n"
1520 "COMP RNG FULL : %d\n"
1521 "COMP RNG EMPT : %d\n"
1522 "COMP RNG USE HGH : %d\n"
1523 "COMP RNG USE LOW : %d\n"
1524 "BAM FIFO FULL : %d\n"
1525 "BAM FIFO EMPT : %d\n"
1526 "BAM FIFO USE HGH : %d\n"
1527 "BAM FIFO USE LOW : %d\n"
1528 "NUM DBELL : %d\n"
1529 "NUM UNEXP DBELL : %d\n"
1530 "NUM BAM INT HDL : 0x%x\n"
1531 "NUM BAM INT NON-RUN : 0x%x\n"
1532 "NUM QMB INT HDL : 0x%x",
1533 ipa_stat.tx_ch_stats.num_pkts_processed,
1534 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1535 ipa_stat.tx_ch_stats.num_db_fired,
1536 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1537 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1538 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1539 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1540 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1541 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1542 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1543 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1544 ipa_stat.tx_ch_stats.num_db,
1545 ipa_stat.tx_ch_stats.num_unexpected_db,
1546 ipa_stat.tx_ch_stats.num_bam_int_handled,
1547 ipa_stat.tx_ch_stats.
1548 num_bam_int_in_non_runnning_state,
1549 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1550
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301551 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001552 "==== IPA_UC IPA RX ====\n"
1553 "MAX OST PKT : %d\n"
1554 "NUM PKT PRCSD : %d\n"
1555 "RNG RP : 0x%x\n"
1556 "COMP RNG FULL : %d\n"
1557 "COMP RNG EMPT : %d\n"
1558 "COMP RNG USE HGH : %d\n"
1559 "COMP RNG USE LOW : %d\n"
1560 "BAM FIFO FULL : %d\n"
1561 "BAM FIFO EMPT : %d\n"
1562 "BAM FIFO USE HGH : %d\n"
1563 "BAM FIFO USE LOW : %d\n"
1564 "NUM DB : %d\n"
1565 "NUM UNEXP DB : %d\n"
1566 "NUM BAM INT HNDL : 0x%x\n",
1567 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1568 ipa_stat.rx_ch_stats.num_pkts_processed,
1569 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1570 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1571 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1572 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1573 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1574 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1575 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1576 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1577 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1578 ipa_stat.rx_ch_stats.num_db,
1579 ipa_stat.rx_ch_stats.num_unexpected_db,
1580 ipa_stat.rx_ch_stats.num_bam_int_handled);
1581 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1582 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1583 /* STATs from FW */
1584 uc_fw_stat = (struct ipa_uc_fw_stats *)
1585 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301586 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001587 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1588 uc_fw_stat->tx_pkts_completed,
1589 hdd_ipa->ipa_p_tx_packets);
1590 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1591 (uc_fw_stat->rx_num_ind_drop_no_space +
1592 uc_fw_stat->rx_num_ind_drop_no_buf +
1593 uc_fw_stat->rx_num_pkts_indicated),
1594 hdd_ipa->ipa_p_rx_packets);
1595
1596 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1597 hdd_ipa->ipa_p_rx_packets =
1598 (uc_fw_stat->rx_num_ind_drop_no_space +
1599 uc_fw_stat->rx_num_ind_drop_no_buf +
1600 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301601 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001602 } else {
1603 HDD_IPA_LOG(LOGE, "INVALID REASON %d",
1604 hdd_ipa->stat_req_reason);
1605 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301606 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001607}
1608
1609
1610/**
1611 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1612 * @adapter: device adapter instance
1613 * @offload_type: MCC or SCC
1614 * @enable: TX offload enable or disable
1615 *
1616 * Return: none
1617 */
1618static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1619 uint32_t offload_type, uint32_t enable)
1620{
1621 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
1622
1623 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1624 * channel change indication. Since these indications are sent by lower
1625 * layer as SAP updates and IPA doesn't have to do anything for these
1626 * updates so ignoring!
1627 */
Krunal Sonibe766b02016-03-10 13:00:44 -08001628 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 return;
1630
1631 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
1632 * channel change indication. Since these indications are sent by lower
1633 * layer as SAP updates and IPA doesn't have to do anything for these
1634 * updates so ignoring!
1635 */
1636 if (adapter->ipa_context)
1637 return;
1638
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301639 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001640 sizeof(ipa_offload_enable_disable));
1641 ipa_offload_enable_disable.offload_type = offload_type;
1642 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1643 ipa_offload_enable_disable.enable = enable;
1644
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301645 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001646 "%s: offload_type=%d, vdev_id=%d, enable=%d", __func__,
1647 ipa_offload_enable_disable.offload_type,
1648 ipa_offload_enable_disable.vdev_id,
1649 ipa_offload_enable_disable.enable);
1650
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301651 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1653 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301654 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001655 "%s: Failure to enable IPA offload \
1656 (offload_type=%d, vdev_id=%d, enable=%d)", __func__,
1657 ipa_offload_enable_disable.offload_type,
1658 ipa_offload_enable_disable.vdev_id,
1659 ipa_offload_enable_disable.enable);
1660 }
1661}
1662
1663/**
1664 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1665 * @work: uC OP work
1666 *
1667 * Return: None
1668 */
1669static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1670{
1671 struct op_msg_type *msg;
1672 struct uc_op_work_struct *uc_op_work = container_of(work,
1673 struct uc_op_work_struct, work);
1674 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1675
1676 cds_ssr_protect(__func__);
1677
1678 msg = uc_op_work->msg;
1679 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301680 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001681 "%s, posted msg %d", __func__, msg->op_code);
1682
1683 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1684
1685 cds_ssr_unprotect(__func__);
1686
1687 return;
1688}
1689
1690/**
1691 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1692 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1693 * @op_msg: operation message received from firmware
1694 * @hdd_ctx: Global HDD context
1695 *
1696 * Return: None
1697 */
1698static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1699{
1700 struct hdd_ipa_priv *hdd_ipa;
1701 struct op_msg_type *msg;
1702 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301703 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704
1705 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301706 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001707 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708
1709 msg = (struct op_msg_type *)op_msg;
1710 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1711
1712 if (unlikely(!hdd_ipa))
1713 goto end;
1714
1715 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301716 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001717 __func__, msg->op_code);
1718 goto end;
1719 }
1720
1721 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1722 if (uc_op_work->msg)
1723 /* When the same uC OPCODE is already pended, just return */
1724 goto end;
1725
1726 uc_op_work->msg = msg;
1727 schedule_work(&uc_op_work->work);
1728 return;
1729
1730end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301731 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732}
1733
1734/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001735 * hdd_ipa_init_uc_op_work - init ipa uc op work
1736 * @work: struct work_struct
1737 * @work_handler: work_handler
1738 *
1739 * Return: none
1740 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001741static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1742 work_func_t work_handler)
1743{
1744 INIT_WORK(work, work_handler);
1745}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001746
1747
1748/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001749 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1750 * @hdd_ctx: Global HDD context
1751 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301752 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001753 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301754static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755{
1756 struct ipa_wdi_in_params pipe_in;
1757 struct ipa_wdi_out_params pipe_out;
1758 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1759 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1760 uint8_t i;
1761
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301762 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1763 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001764
Anurag Chouhanffb21542016-02-17 14:33:03 +05301765 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301766 qdf_mutex_create(&ipa_ctxt->event_lock);
1767 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768
1769 /* TX PIPE */
1770 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1771 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1772 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1773 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1774 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1775 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1776 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1777 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1778 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1779 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1780 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1781 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1782 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301783 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001784 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1785 pipe_in.sys.keep_ipa_awake = true;
1786 }
1787
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001788 pipe_in.u.dl.comp_ring_base_pa =
1789 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001790 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001791 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1792 sizeof(qdf_dma_addr_t);
1793 pipe_in.u.dl.ce_ring_base_pa =
1794 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1795 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1796 pipe_in.u.dl.ce_ring_size =
1797 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1798 pipe_in.u.dl.num_tx_buffers =
1799 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001800
1801 /* Connect WDI IPA PIPE */
1802 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1803 /* Micro Controller Doorbell register */
Leo Chang3bc8fed2015-11-13 10:59:47 -08001804 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001805 /* WLAN TX PIPE Handle */
1806 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301807 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001808 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1809 " CERZ %d, NB %d, CDBPAD 0x%x",
1810 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1811 pipe_in.u.dl.comp_ring_size,
1812 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1813 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1814 pipe_in.u.dl.ce_ring_size,
1815 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001816 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001817
1818 /* RX PIPE */
1819 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1820 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1821 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1822 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1823 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1824 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1825 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1826 sizeof(struct sps_iovec);
1827 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1828 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301829 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1831 pipe_in.sys.keep_ipa_awake = true;
1832 }
1833
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001834 pipe_in.u.ul.rdy_ring_base_pa =
1835 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1836 pipe_in.u.ul.rdy_ring_size =
1837 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1838 pipe_in.u.ul.rdy_ring_rp_pa =
1839 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001840 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001841 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001842 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301844 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1846 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1847 pipe_in.u.ul.rdy_ring_size,
1848 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001849 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001850
1851 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001852 ipa_ctxt->tx_comp_doorbell_paddr,
1853 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001854
1855 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1856 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1857
1858 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001859 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001860 hdd_ipa_uc_fw_op_event_handler);
1861 ipa_ctxt->uc_op_work[i].msg = NULL;
1862 }
1863
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301864 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001865}
1866
Leo Change3e49442015-10-26 20:07:13 -07001867/**
1868 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1869 * @hdd_ctx: hdd main context
1870 *
1871 * Force shutdown IPA pipe
1872 * Independent of FW pipe status, IPA pipe shutdonw progress
1873 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1874 * independent from FW pipe status
1875 *
1876 * Return: NONE
1877 */
1878void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1879{
1880 struct hdd_ipa_priv *hdd_ipa;
1881
1882 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1883 return;
1884
1885 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1886 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301887 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001888 "IPA pipes are not down yet, force shutdown");
1889 hdd_ipa_uc_disable_pipes(hdd_ipa);
1890 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301891 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001892 "IPA pipes are down, do nothing");
1893 }
1894
1895 return;
1896}
1897
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898/**
1899 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1900 *
1901 * Deinit basic IPA UC host side to be in sync reloaded FW during
1902 * SSR
1903 *
1904 * Return: 0 - Success
1905 */
1906int hdd_ipa_uc_ssr_deinit(void)
1907{
1908 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1909 int idx;
1910 struct hdd_ipa_iface_context *iface_context;
1911
Leo Chang3bc8fed2015-11-13 10:59:47 -08001912 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913 return 0;
1914
1915 /* Clean up HDD IPA interfaces */
1916 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1917 (idx < HDD_IPA_MAX_IFACE); idx++) {
1918 iface_context = &hdd_ipa->iface_context[idx];
1919 if (iface_context && iface_context->adapter)
1920 hdd_ipa_cleanup_iface(iface_context);
1921 }
1922
1923 /* After SSR, wlan driver reloads FW again. But we need to protect
1924 * IPA submodule during SSR transient state. So deinit basic IPA
1925 * UC host side to be in sync with reloaded FW during SSR
1926 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08001927 if (!hdd_ipa->ipa_pipes_down)
1928 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001929
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301930 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001931 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1932 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
1933 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1934 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301935 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001936
1937 /* Full IPA driver cleanup not required since wlan driver is now
1938 * unloaded and reloaded after SSR.
1939 */
1940 return 0;
1941}
1942
1943/**
1944 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
1945 *
1946 * Init basic IPA UC host side to be in sync with reloaded FW after
1947 * SSR to resume IPA UC operations
1948 *
1949 * Return: 0 - Success
1950 */
1951int hdd_ipa_uc_ssr_reinit(void)
1952{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001953
1954 /* After SSR is complete, IPA UC can resume operation. But now wlan
1955 * driver will be unloaded and reloaded, which takes care of IPA cleanup
1956 * and initialization. This is a placeholder func if IPA has to resume
1957 * operations without driver reload.
1958 */
1959 return 0;
1960}
Leo Chang3bc8fed2015-11-13 10:59:47 -08001961
1962/**
1963 * hdd_ipa_tx_packet_ipa() - send packet to IPA
1964 * @hdd_ctx: Global HDD context
1965 * @skb: skb sent to IPA
1966 * @session_id: send packet instance session id
1967 *
1968 * Send TX packet which generated by system to IPA.
1969 * This routine only will be used for function verification
1970 *
1971 * Return: NULL packet sent to IPA properly
1972 * NULL invalid packet drop
1973 * skb packet not sent to IPA. legacy data path should handle
1974 */
1975struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
1976 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07001977{
Leo Chang3bc8fed2015-11-13 10:59:47 -08001978 struct ipa_header *ipa_header;
1979 struct frag_header *frag_header;
1980
1981 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
1982 return skb;
1983
1984 ipa_header = (struct ipa_header *) skb_push(skb,
1985 sizeof(struct ipa_header));
1986 if (!ipa_header) {
1987 /* No headroom, legacy */
1988 return skb;
1989 }
1990 memset(ipa_header, 0, sizeof(*ipa_header));
1991 ipa_header->vdev_id = 0;
1992
1993 frag_header = (struct frag_header *) skb_push(skb,
1994 sizeof(struct frag_header));
1995 if (!frag_header) {
1996 /* No headroom, drop */
1997 kfree_skb(skb);
1998 return NULL;
1999 }
2000 memset(frag_header, 0, sizeof(*frag_header));
2001 frag_header->length = skb->len - sizeof(struct frag_header)
2002 - sizeof(struct ipa_header);
2003
2004 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2005 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002006}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002007
2008/**
2009 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2010 * @work: scheduled work
2011 *
2012 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2013 * not want to immediately release the wake lock since the system
2014 * would then potentially try to suspend when there is a healthy data
2015 * rate. Deferred work is scheduled and this function handles the
2016 * work. When this function is called, if the IPA resource is still
2017 * released then we release the wake lock.
2018 *
2019 * Return: None
2020 */
2021static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2022{
2023 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2024 struct hdd_ipa_priv,
2025 wake_lock_work);
2026
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302027 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028
2029 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2030 goto end;
2031
2032 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302033 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002034 WIFI_POWER_EVENT_WAKELOCK_IPA);
2035
2036end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302037 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038}
2039
2040/**
2041 * hdd_ipa_rm_request() - Request resource from IPA
2042 * @hdd_ipa: Global HDD IPA context
2043 *
2044 * Return: 0 on success, negative errno on error
2045 */
2046static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2047{
2048 int ret = 0;
2049
2050 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2051 return 0;
2052
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302053 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002054
2055 switch (hdd_ipa->rm_state) {
2056 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302057 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058 return 0;
2059 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302060 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061 return -EINPROGRESS;
2062 case HDD_IPA_RM_RELEASED:
2063 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2064 break;
2065 }
2066
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302067 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002068
2069 ret = ipa_rm_inactivity_timer_request_resource(
2070 IPA_RM_RESOURCE_WLAN_PROD);
2071
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302072 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002073 if (ret == 0) {
2074 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2075 hdd_ipa->stats.num_rm_grant_imm++;
2076 }
2077
2078 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2079 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302080 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002081 WIFI_POWER_EVENT_WAKELOCK_IPA);
2082 hdd_ipa->wake_lock_released = false;
2083 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302084 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002085
2086 return ret;
2087}
2088
2089/**
2090 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2091 * @hdd_ipa: Global HDD IPA context
2092 *
2093 * Return: 0 if resources released, negative errno otherwise
2094 */
2095static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2096{
2097 int ret = 0;
2098
2099 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2100 return 0;
2101
2102 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2103 return -EAGAIN;
2104
2105 spin_lock_bh(&hdd_ipa->q_lock);
2106 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2107 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2108 spin_unlock_bh(&hdd_ipa->q_lock);
2109 return -EAGAIN;
2110 }
2111 spin_unlock_bh(&hdd_ipa->q_lock);
2112
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302113 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002114
Nirav Shahcbc6d722016-03-01 16:24:53 +05302115 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302116 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002117 return -EAGAIN;
2118 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302119 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002120
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302121 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002122 switch (hdd_ipa->rm_state) {
2123 case HDD_IPA_RM_GRANTED:
2124 break;
2125 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302126 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002127 return -EINPROGRESS;
2128 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302129 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002130 return 0;
2131 }
2132
2133 /* IPA driver returns immediately so set the state here to avoid any
2134 * race condition.
2135 */
2136 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2137 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302138 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002139
2140 ret =
2141 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2142
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302143 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002144 if (unlikely(ret != 0)) {
2145 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2146 WARN_ON(1);
2147 }
2148
2149 /*
2150 * If wake_lock is released immediately, kernel would try to suspend
2151 * immediately as well, Just avoid ping-pong between suspend-resume
2152 * while there is healthy amount of data transfer going on by
2153 * releasing the wake_lock after some delay.
2154 */
2155 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2156 msecs_to_jiffies
2157 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2158
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302159 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002160
2161 return ret;
2162}
2163
2164/**
2165 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2166 * @user_data: user data registered with IPA
2167 * @event: the IPA resource manager event that occurred
2168 * @data: the data associated with the event
2169 *
2170 * Return: None
2171 */
2172static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2173 unsigned long data)
2174{
2175 struct hdd_ipa_priv *hdd_ipa = user_data;
2176
2177 if (unlikely(!hdd_ipa))
2178 return;
2179
2180 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2181 return;
2182
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302183 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002184
2185 switch (event) {
2186 case IPA_RM_RESOURCE_GRANTED:
2187 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2188 /* RM Notification comes with ISR context
2189 * it should be serialized into work queue to avoid
2190 * ISR sleep problem
2191 */
2192 hdd_ipa->uc_rm_work.event = event;
2193 schedule_work(&hdd_ipa->uc_rm_work.work);
2194 break;
2195 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302196 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002197 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302198 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002199 hdd_ipa->stats.num_rm_grant++;
2200 break;
2201
2202 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302203 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002204 hdd_ipa->resource_unloading = false;
2205 break;
2206
2207 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302208 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002209 break;
2210 }
2211}
2212
2213/**
2214 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2215 *
2216 * Callback function registered with IPA that is called when IPA wants
2217 * to release the WLAN consumer resource
2218 *
2219 * Return: 0 if the request is granted, negative errno otherwise
2220 */
2221static int hdd_ipa_rm_cons_release(void)
2222{
2223 return 0;
2224}
2225
2226/**
2227 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2228 *
2229 * Callback function registered with IPA that is called when IPA wants
2230 * to access the WLAN consumer resource
2231 *
2232 * Return: 0 if the request is granted, negative errno otherwise
2233 */
2234static int hdd_ipa_rm_cons_request(void)
2235{
Yun Park4d8b60a2015-10-22 13:59:32 -07002236 int ret = 0;
2237
2238 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302239 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002240 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241 __func__);
2242 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002243 ret = -EINPROGRESS;
2244 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302245 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002246 "%s: IPA resource unloading in progress",
2247 __func__);
2248 ghdd_ipa->pending_cons_req = true;
2249 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002251
2252 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002253}
2254
2255/**
2256 * hdd_ipa_set_perf_level() - Set IPA performance level
2257 * @hdd_ctx: Global HDD context
2258 * @tx_packets: Number of packets transmitted in the last sample period
2259 * @rx_packets: Number of packets received in the last sample period
2260 *
2261 * Return: 0 on success, negative errno on error
2262 */
2263int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2264 uint64_t rx_packets)
2265{
2266 uint32_t next_cons_bw, next_prod_bw;
2267 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2268 struct ipa_rm_perf_profile profile;
2269 int ret;
2270
2271 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2272 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2273 return 0;
2274
2275 memset(&profile, 0, sizeof(profile));
2276
2277 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2278 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2279 else if (tx_packets >
2280 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2281 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2282 else
2283 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2284
2285 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2286 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2287 else if (rx_packets >
2288 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2289 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2290 else
2291 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2292
2293 HDD_IPA_LOG(LOG1,
2294 "CONS perf curr: %d, next: %d",
2295 hdd_ipa->curr_cons_bw, next_cons_bw);
2296 HDD_IPA_LOG(LOG1,
2297 "PROD perf curr: %d, next: %d",
2298 hdd_ipa->curr_prod_bw, next_prod_bw);
2299
2300 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302301 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002302 "Requesting CONS perf curr: %d, next: %d",
2303 hdd_ipa->curr_cons_bw, next_cons_bw);
2304 profile.max_supported_bandwidth_mbps = next_cons_bw;
2305 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2306 &profile);
2307 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302308 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002309 "RM CONS set perf profile failed: %d", ret);
2310
2311 return ret;
2312 }
2313 hdd_ipa->curr_cons_bw = next_cons_bw;
2314 hdd_ipa->stats.num_cons_perf_req++;
2315 }
2316
2317 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302318 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002319 "Requesting PROD perf curr: %d, next: %d",
2320 hdd_ipa->curr_prod_bw, next_prod_bw);
2321 profile.max_supported_bandwidth_mbps = next_prod_bw;
2322 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2323 &profile);
2324 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302325 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002326 "RM PROD set perf profile failed: %d", ret);
2327 return ret;
2328 }
2329 hdd_ipa->curr_prod_bw = next_prod_bw;
2330 hdd_ipa->stats.num_prod_perf_req++;
2331 }
2332
2333 return 0;
2334}
2335
2336/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002337 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2338 * @work: struct work_struct
2339 * @work_handler: work_handler
2340 *
2341 * Return: none
2342 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002343static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2344 work_func_t work_handler)
2345{
2346 INIT_WORK(work, work_handler);
2347}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002348
2349/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002350 * hdd_ipa_setup_rm() - Setup IPA resource management
2351 * @hdd_ipa: Global HDD IPA context
2352 *
2353 * Return: 0 on success, negative errno on error
2354 */
2355static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2356{
2357 struct ipa_rm_create_params create_params = { 0 };
2358 int ret;
2359
2360 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2361 return 0;
2362
Rajeev Kumar217f2172016-01-06 18:11:55 -08002363 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2364 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002365 memset(&create_params, 0, sizeof(create_params));
2366 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2367 create_params.reg_params.user_data = hdd_ipa;
2368 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2369 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2370
2371 ret = ipa_rm_create_resource(&create_params);
2372 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302373 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002374 "Create RM resource failed: %d", ret);
2375 goto setup_rm_fail;
2376 }
2377
2378 memset(&create_params, 0, sizeof(create_params));
2379 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2380 create_params.request_resource = hdd_ipa_rm_cons_request;
2381 create_params.release_resource = hdd_ipa_rm_cons_release;
2382 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2383
2384 ret = ipa_rm_create_resource(&create_params);
2385 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302386 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002387 "Create RM CONS resource failed: %d", ret);
2388 goto delete_prod;
2389 }
2390
2391 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2392 IPA_RM_RESOURCE_APPS_CONS);
2393
2394 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2395 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2396 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302397 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002398 ret);
2399 goto timer_init_failed;
2400 }
2401
2402 /* Set the lowest bandwidth to start with */
2403 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2404
2405 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302406 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002407 "Set perf level failed: %d", ret);
2408 goto set_perf_failed;
2409 }
2410
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302411 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002412 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2413 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302414 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002415 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2416 hdd_ipa->wake_lock_released = true;
2417 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2418
2419 return ret;
2420
2421set_perf_failed:
2422 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2423
2424timer_init_failed:
2425 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2426
2427delete_prod:
2428 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2429
2430setup_rm_fail:
2431 return ret;
2432}
2433
2434/**
2435 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2436 * @hdd_ipa: Global HDD IPA context
2437 *
2438 * Destroys all resources associated with the IPA resource manager
2439 *
2440 * Return: None
2441 */
2442static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2443{
2444 int ret;
2445
2446 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2447 return;
2448
2449 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302450 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002451
2452#ifdef WLAN_OPEN_SOURCE
2453 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2454#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302455 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002456
2457 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2458
2459 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2460 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302461 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002462 "RM PROD resource delete failed %d", ret);
2463
2464 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2465 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302466 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002467 "RM CONS resource delete failed %d", ret);
2468}
2469
2470/**
2471 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2472 * @skb: network buffer
2473 * @adapter: network adapter
2474 *
2475 * Called when a network buffer is received which should not be routed
2476 * to the IPA module.
2477 *
2478 * Return: None
2479 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302480static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002481 hdd_adapter_t *adapter)
2482{
2483 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2484 unsigned int cpu_index;
2485
2486 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302487 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488 adapter);
2489 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302490 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 return;
2492 }
2493
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002494 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002495 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302496 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002497 return;
2498 }
2499
2500 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2501 skb->dev = adapter->dev;
2502 skb->protocol = eth_type_trans(skb, skb->dev);
2503 skb->ip_summed = CHECKSUM_NONE;
2504
2505 cpu_index = wlan_hdd_get_cpu();
2506
2507 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2508 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2509 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2510 else
2511 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2512
2513 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2514 adapter->dev->last_rx = jiffies;
2515}
2516
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002517/**
2518 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
2519 * @priv: pointer to private data registered with IPA (we register a
2520 * pointer to the global IPA context)
2521 * @evt: the IPA event which triggered the callback
2522 * @data: data associated with the event
2523 *
2524 * Return: None
2525 */
2526static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2527 unsigned long data)
2528{
2529 struct hdd_ipa_priv *hdd_ipa = NULL;
2530 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302531 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002532 uint8_t iface_id;
2533 uint8_t session_id;
2534 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302535 qdf_nbuf_t copy;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002536 uint8_t fw_desc;
2537 int ret;
2538
2539 hdd_ipa = (struct hdd_ipa_priv *)priv;
2540
2541 switch (evt) {
2542 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302543 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002544 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2545 session_id = (uint8_t)skb->cb[0];
2546 iface_id = vdev_to_iface[session_id];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302547 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2549 session_id, iface_id);
2550 } else {
2551 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2552 }
2553
2554 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302555 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002556 "IPA_RECEIVE: Invalid iface_id: %u",
2557 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302558 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002559 "w2i -- skb", skb->data, 8);
2560 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302561 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562 return;
2563 }
2564
2565 iface_context = &hdd_ipa->iface_context[iface_id];
2566 adapter = iface_context->adapter;
2567
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302568 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002569 "w2i -- skb", skb->data, 8);
2570 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2571 hdd_ipa->stats.num_rx_excep++;
2572 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2573 } else {
2574 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2575 }
2576
2577 iface_context->stats.num_rx_ipa_excep++;
2578
2579 /* Disable to forward Intra-BSS Rx packets when
2580 * ap_isolate=1 in hostapd.conf
2581 */
2582 if (adapter->sessionCtx.ap.apDisableIntraBssFwd) {
2583 /*
2584 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2585 * all Rx packets to IPA uC, which need to be forwarded
2586 * to other interface.
2587 * And, IPA driver will send back to WLAN host driver
2588 * through exception pipe with fw_desc field set by FW.
2589 * Here we are checking fw_desc field for FORWARD bit
2590 * set, and forward to Tx. Then copy to kernel stack
2591 * only when DISCARD bit is not set.
2592 */
2593 fw_desc = (uint8_t)skb->cb[1];
2594
Leo Chang3bc8fed2015-11-13 10:59:47 -08002595 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002596 HDD_IPA_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302597 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002598 "Forward packet to Tx (fw_desc=%d)",
2599 fw_desc);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302600 copy = qdf_nbuf_copy(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002601 if (copy) {
2602 hdd_ipa->ipa_tx_forward++;
2603 ret = hdd_softap_hard_start_xmit(
2604 (struct sk_buff *)copy,
2605 adapter->dev);
2606 if (ret) {
2607 HDD_IPA_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302608 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609 "Forward packet tx fail");
2610 hdd_ipa->stats.
2611 num_tx_bcmc_err++;
2612 } else {
2613 hdd_ipa->stats.num_tx_bcmc++;
2614 }
2615 }
2616 }
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002617
Leo Chang3bc8fed2015-11-13 10:59:47 -08002618 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002619 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2620 hdd_ipa->ipa_rx_discard++;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302621 qdf_nbuf_free(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002622 break;
2623 }
2624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002625 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302626 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002627 "Intra-BSS FWD is disabled-skip forward to Tx");
2628 }
2629
2630 hdd_ipa_send_skb_to_network(skb, adapter);
2631 break;
2632
2633 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302634 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002635 "w2i cb wrong event: 0x%x", evt);
2636 return;
2637 }
2638}
2639
2640/**
2641 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2642 * @skb: packet buffer which was transmitted
2643 *
2644 * Return: None
2645 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302646void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002647{
2648 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2649
Nirav Shahcbc6d722016-03-01 16:24:53 +05302650 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
2651 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002652 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302653 ipa_free_skb((struct ipa_rx_data *)
2654 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002655
2656 hdd_ipa->stats.num_tx_comp_cnt++;
2657
2658 atomic_dec(&hdd_ipa->tx_ref_cnt);
2659
2660 hdd_ipa_rm_try_release(hdd_ipa);
2661}
2662
2663/**
2664 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2665 * @iface_context: interface-specific IPA context
2666 * @ipa_tx_desc: packet data descriptor
2667 *
2668 * Return: None
2669 */
2670static void hdd_ipa_send_pkt_to_tl(
2671 struct hdd_ipa_iface_context *iface_context,
2672 struct ipa_rx_data *ipa_tx_desc)
2673{
2674 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2675 uint8_t interface_id;
2676 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302677 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002678
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302679 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002680 adapter = iface_context->adapter;
2681 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302682 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002683 ipa_free_skb(ipa_tx_desc);
2684 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302685 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686 hdd_ipa_rm_try_release(hdd_ipa);
2687 return;
2688 }
2689
2690 /*
2691 * During CAC period, data packets shouldn't be sent over the air so
2692 * drop all the packets here
2693 */
2694 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2695 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302696 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002697 iface_context->stats.num_tx_cac_drop++;
2698 hdd_ipa_rm_try_release(hdd_ipa);
2699 return;
2700 }
2701
2702 interface_id = adapter->sessionId;
2703 ++adapter->stats.tx_packets;
2704
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302705 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002706
2707 skb = ipa_tx_desc->skb;
2708
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302709 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302710 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002711 /* FIXME: This is broken. No such field in cb any more:
2712 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002713 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302714 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002715 ipa_tx_desc->dma_addr
2716 + HDD_IPA_WLAN_FRAG_HEADER
2717 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002718 ipa_tx_desc->skb->len -=
2719 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2720 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302721 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002722
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002723 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302724 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002725
2726 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2727
2728 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2729 ipa_tx_desc->skb);
2730 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302731 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002732 ipa_free_skb(ipa_tx_desc);
2733 iface_context->stats.num_tx_err++;
2734 hdd_ipa_rm_try_release(hdd_ipa);
2735 return;
2736 }
2737
2738 atomic_inc(&hdd_ipa->tx_ref_cnt);
2739
2740 iface_context->stats.num_tx++;
2741
2742}
2743
2744/**
2745 * hdd_ipa_pm_send_pkt_to_tl() - Send queued packets to TL
2746 * @work: pointer to the scheduled work
2747 *
2748 * Called during PM resume to send packets to TL which were queued
2749 * while host was in the process of suspending.
2750 *
2751 * Return: None
2752 */
2753static void hdd_ipa_pm_send_pkt_to_tl(struct work_struct *work)
2754{
2755 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2756 struct hdd_ipa_priv,
2757 pm_work);
2758 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302759 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002760 uint32_t dequeued = 0;
2761
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302762 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002763
Nirav Shahcbc6d722016-03-01 16:24:53 +05302764 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2765 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302766 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002767
2768 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2769
2770 dequeued++;
2771
2772 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
2773 pm_tx_cb->ipa_tx_desc);
2774
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302775 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776 }
2777
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302778 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002779
2780 hdd_ipa->stats.num_tx_dequeued += dequeued;
2781 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2782 hdd_ipa->stats.num_max_pm_queue = dequeued;
2783}
2784
2785/**
2786 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2787 * @priv: pointer to private data registered with IPA (we register a
2788 * pointer to the interface-specific IPA context)
2789 * @evt: the IPA event which triggered the callback
2790 * @data: data associated with the event
2791 *
2792 * Return: None
2793 */
2794static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2795 unsigned long data)
2796{
2797 struct hdd_ipa_priv *hdd_ipa = NULL;
2798 struct ipa_rx_data *ipa_tx_desc;
2799 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302800 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302802 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803
Mukul Sharma81661ae2015-10-30 20:26:02 +05302804 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002805 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302806 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002807 dev_kfree_skb_any(skb);
2808 iface_context->stats.num_tx_drop++;
2809 return;
2810 }
2811
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002812 ipa_tx_desc = (struct ipa_rx_data *)data;
2813
2814 hdd_ipa = iface_context->hdd_ipa;
2815
2816 /*
2817 * When SSR is going on or driver is unloading, just drop the packets.
2818 * During SSR, there is no use in queueing the packets as STA has to
2819 * connect back any way
2820 */
2821 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302822 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002823 ipa_free_skb(ipa_tx_desc);
2824 iface_context->stats.num_tx_drop++;
2825 return;
2826 }
2827
2828 skb = ipa_tx_desc->skb;
2829
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302830 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002831
2832 /*
2833 * If PROD resource is not requested here then there may be cases where
2834 * IPA hardware may be clocked down because of not having proper
2835 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
2836 * workaround to request PROD resource while data is going over CONS
2837 * pipe to prevent the IPA hardware clockdown.
2838 */
2839 hdd_ipa_rm_request(hdd_ipa);
2840
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302841 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002842 /*
2843 * If host is still suspended then queue the packets and these will be
2844 * drained later when resume completes. When packet is arrived here and
2845 * host is suspended, this means that there is already resume is in
2846 * progress.
2847 */
2848 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302849 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002850 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
2851 pm_tx_cb->iface_context = iface_context;
2852 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302853 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002854 hdd_ipa->stats.num_tx_queued++;
2855
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302856 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002857 return;
2858 }
2859
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302860 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002861
2862 /*
2863 * If we are here means, host is not suspended, wait for the work queue
2864 * to finish.
2865 */
2866#ifdef WLAN_OPEN_SOURCE
2867 flush_work(&hdd_ipa->pm_work);
2868#endif
2869
2870 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
2871}
2872
2873/**
2874 * hdd_ipa_suspend() - Suspend IPA
2875 * @hdd_ctx: Global HDD context
2876 *
2877 * Return: 0 on success, negativer errno on error
2878 */
2879int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
2880{
2881 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2882
2883 if (!hdd_ipa_is_enabled(hdd_ctx))
2884 return 0;
2885
2886 /*
2887 * Check if IPA is ready for suspend, If we are here means, there is
2888 * high chance that suspend would go through but just to avoid any race
2889 * condition after suspend started, these checks are conducted before
2890 * allowing to suspend.
2891 */
2892 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2893 return -EAGAIN;
2894
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302895 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002896
2897 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302898 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002899 return -EAGAIN;
2900 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302901 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002902
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302903 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002904 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302905 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002906
2907 return 0;
2908}
2909
2910/**
2911 * hdd_ipa_resume() - Resume IPA following suspend
2912 * hdd_ctx: Global HDD context
2913 *
2914 * Return: 0 on success, negative errno on error
2915 */
2916int hdd_ipa_resume(hdd_context_t *hdd_ctx)
2917{
2918 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2919
2920 if (!hdd_ipa_is_enabled(hdd_ctx))
2921 return 0;
2922
2923 schedule_work(&hdd_ipa->pm_work);
2924
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302925 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302927 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002928
2929 return 0;
2930}
2931
2932/**
2933 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
2934 * @hdd_ipa: Global HDD IPA context
2935 *
2936 * Return: 0 on success, negative errno on error
2937 */
2938static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
2939{
2940 int i, ret = 0;
2941 struct ipa_sys_connect_params *ipa;
2942 uint32_t desc_fifo_sz;
2943
2944 /* The maximum number of descriptors that can be provided to a BAM at
2945 * once is one less than the total number of descriptors that the buffer
2946 * can contain.
2947 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
2948 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
2949 * be provided at once.
2950 * Because of above requirement, one extra descriptor will be added to
2951 * make sure hardware always has one descriptor.
2952 */
2953 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
2954 + sizeof(struct sps_iovec);
2955
2956 /*setup TX pipes */
2957 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2958 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
2959
2960 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
2961 ipa->desc_fifo_sz = desc_fifo_sz;
2962 ipa->priv = &hdd_ipa->iface_context[i];
2963 ipa->notify = hdd_ipa_i2w_cb;
2964
2965 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
2966 ipa->ipa_ep_cfg.hdr.hdr_len =
2967 HDD_IPA_UC_WLAN_TX_HDR_LEN;
2968 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2969 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2970 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2971 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
2972 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
2973 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
2974 } else {
2975 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
2976 }
2977 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
2978
2979 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2980 ipa->keep_ipa_awake = 1;
2981
2982 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
2983 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302984 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002985 " ret: %d", i, ret);
2986 goto setup_sys_pipe_fail;
2987 }
2988 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
2989 }
2990
2991 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
2992 /*
2993 * Hard code it here, this can be extended if in case
2994 * PROD pipe is also per interface.
2995 * Right now there is no advantage of doing this.
2996 */
2997 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
2998
2999 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3000
3001 ipa->client = hdd_ipa->prod_client;
3002
3003 ipa->desc_fifo_sz = desc_fifo_sz;
3004 ipa->priv = hdd_ipa;
3005 ipa->notify = hdd_ipa_w2i_cb;
3006
3007 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3008 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3009 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3010 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3011
3012 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3013 ipa->keep_ipa_awake = 1;
3014
3015 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3016 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303017 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003018 "Failed for RX pipe: %d", ret);
3019 goto setup_sys_pipe_fail;
3020 }
3021 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3022 }
3023
3024 return ret;
3025
3026setup_sys_pipe_fail:
3027
3028 while (--i >= 0) {
3029 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303030 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031 sizeof(struct hdd_ipa_sys_pipe));
3032 }
3033
3034 return ret;
3035}
3036
3037/**
3038 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3039 * @hdd_ipa: Global HDD IPA context
3040 *
3041 * Return: None
3042 */
3043static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3044{
3045 int ret = 0, i;
3046 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3047 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3048 ret =
3049 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3050 conn_hdl);
3051 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303052 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003053 ret);
3054
3055 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3056 }
3057 }
3058}
3059
3060/**
3061 * hdd_ipa_register_interface() - register IPA interface
3062 * @hdd_ipa: Global IPA context
3063 * @iface_context: Per-interface IPA context
3064 *
3065 * Return: 0 on success, negative errno on error
3066 */
3067static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3068 struct hdd_ipa_iface_context
3069 *iface_context)
3070{
3071 struct ipa_tx_intf tx_intf;
3072 struct ipa_rx_intf rx_intf;
3073 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3074 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3075 char *ifname = iface_context->adapter->dev->name;
3076
3077 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3078 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3079
3080 int num_prop = 1;
3081 int ret = 0;
3082
3083 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3084 num_prop++;
3085
3086 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3087 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303088 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303090 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003091 goto register_interface_fail;
3092 }
3093
3094 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3095 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303096 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303098 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003099 goto register_interface_fail;
3100 }
3101
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303102 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3103 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003104
3105 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3106 ifname, HDD_IPA_IPV4_NAME_EXT);
3107 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3108 ifname, HDD_IPA_IPV6_NAME_EXT);
3109
3110 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3111 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3112 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3113 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3114
3115 /*
3116 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3117 * mask to identify the interface in IPA hardware
3118 */
3119 rx_prop[IPA_IP_v4].attrib.meta_data =
3120 htonl(iface_context->adapter->sessionId << 16);
3121 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3122
3123 rx_intf.num_props++;
3124 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3125 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3126 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3127 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3128 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3129 rx_prop[IPA_IP_v4].attrib.meta_data =
3130 htonl(iface_context->adapter->sessionId << 16);
3131 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3132
3133 rx_intf.num_props++;
3134 }
3135
3136 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3137 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3138 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3139 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3140 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3141 IPA_RESOURCE_NAME_MAX);
3142 tx_intf.num_props++;
3143
3144 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3145 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3146 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3147 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3148 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3149 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3150 IPA_RESOURCE_NAME_MAX);
3151 tx_intf.num_props++;
3152 }
3153
3154 tx_intf.prop = tx_prop;
3155 rx_intf.prop = rx_prop;
3156
3157 /* Call the ipa api to register interface */
3158 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3159
3160register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303161 qdf_mem_free(tx_prop);
3162 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163 return ret;
3164}
3165
3166/**
3167 * hdd_remove_ipa_header() - Remove a specific header from IPA
3168 * @name: Name of the header to be removed
3169 *
3170 * Return: None
3171 */
3172static void hdd_ipa_remove_header(char *name)
3173{
3174 struct ipa_ioc_get_hdr hdrlookup;
3175 int ret = 0, len;
3176 struct ipa_ioc_del_hdr *ipa_hdr;
3177
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303178 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3180 ret = ipa_get_hdr(&hdrlookup);
3181 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303182 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183 name, ret);
3184 return;
3185 }
3186
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303187 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303189 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303191 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 return;
3193 }
3194 ipa_hdr->num_hdls = 1;
3195 ipa_hdr->commit = 0;
3196 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3197 ipa_hdr->hdl[0].status = -1;
3198 ret = ipa_del_hdr(ipa_hdr);
3199 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303200 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201 ret);
3202
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303203 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204}
3205
3206/**
3207 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3208 * @hdd_ipa: Global HDD IPA context
3209 * @iface_context: Interface-specific HDD IPA context
3210 * @mac_addr: Interface MAC address
3211 *
3212 * Return: 0 on success, negativer errno value on error
3213 */
3214static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3215 struct hdd_ipa_iface_context *iface_context,
3216 uint8_t *mac_addr)
3217{
3218 hdd_adapter_t *adapter = iface_context->adapter;
3219 char *ifname;
3220 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3221 int ret = -EINVAL;
3222 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3223 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3224
3225 ifname = adapter->dev->name;
3226
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303227 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003228 ifname, mac_addr);
3229
3230 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303231 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003232 + sizeof(struct ipa_hdr_add));
3233 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303234 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003235 "%s: ipa_hdr allocation failed", ifname);
3236 ret = -ENOMEM;
3237 goto end;
3238 }
3239
3240 ipa_hdr->commit = 0;
3241 ipa_hdr->num_hdrs = 1;
3242
3243 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3244 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3245 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3246 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3247 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303248 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249 "ifname=%s, vdev_id=%d",
3250 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3251 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3252 ifname, HDD_IPA_IPV4_NAME_EXT);
3253 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3254 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3255 ipa_hdr->hdr[0].is_partial = 1;
3256 ipa_hdr->hdr[0].hdr_hdl = 0;
3257 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3258 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3259
3260 ret = ipa_add_hdr(ipa_hdr);
3261 } else {
3262 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3263
3264 /* Set the Source MAC */
3265 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3266 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3267
3268 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3269 ifname, HDD_IPA_IPV4_NAME_EXT);
3270 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3271 ipa_hdr->hdr[0].is_partial = 1;
3272 ipa_hdr->hdr[0].hdr_hdl = 0;
3273 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3274 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3275
3276 /* Set the type to IPV4 in the header */
3277 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3278
3279 ret = ipa_add_hdr(ipa_hdr);
3280 }
3281 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303282 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 ifname, ret);
3284 goto end;
3285 }
3286
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303287 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003288 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3289
3290 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3291 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3292 ifname, HDD_IPA_IPV6_NAME_EXT);
3293
3294 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3295 uc_tx_hdr =
3296 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3297 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3298 } else {
3299 /* Set the type to IPV6 in the header */
3300 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3301 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3302 }
3303
3304 ret = ipa_add_hdr(ipa_hdr);
3305 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303306 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 "%s: IPv6 add hdr failed: %d", ifname, ret);
3308 goto clean_ipv4_hdr;
3309 }
3310
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303311 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3313 }
3314
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303315 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316
3317 return ret;
3318
3319clean_ipv4_hdr:
3320 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3321 ifname, HDD_IPA_IPV4_NAME_EXT);
3322 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3323end:
3324 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303325 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326
3327 return ret;
3328}
3329
3330/**
3331 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3332 * @adapter: Adapter upon which IPA was previously configured
3333 *
3334 * Return: None
3335 */
3336static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3337{
3338 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3339 int ret;
3340 char name_ipa[IPA_RESOURCE_NAME_MAX];
3341
3342 /* Remove the headers */
3343 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3344 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3345 hdd_ipa_remove_header(name_ipa);
3346
3347 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3348 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3349 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3350 hdd_ipa_remove_header(name_ipa);
3351 }
3352 /* unregister the interface with IPA */
3353 ret = ipa_deregister_intf(adapter->dev->name);
3354 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303355 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356 "%s: ipa_deregister_intf fail: %d",
3357 adapter->dev->name, ret);
3358}
3359
3360/**
3361 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3362 * @iface_context: interface-specific IPA context
3363 *
3364 * Return: None
3365 */
3366static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3367{
3368 if (iface_context == NULL)
3369 return;
3370
3371 hdd_ipa_clean_hdr(iface_context->adapter);
3372
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303373 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374 iface_context->adapter->ipa_context = NULL;
3375 iface_context->adapter = NULL;
3376 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303377 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378 iface_context->ifa_address = 0;
3379 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303380 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303382 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003383 }
3384 iface_context->hdd_ipa->num_iface--;
3385}
3386
3387/**
3388 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3389 * @hdd_ipa: HDD IPA global context
3390 * @adapter: Interface upon which IPA is being setup
3391 * @sta_id: Station ID of the API instance
3392 *
3393 * Return: 0 on success, negative errno value on error
3394 */
3395static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3396 hdd_adapter_t *adapter, uint8_t sta_id)
3397{
3398 struct hdd_ipa_iface_context *iface_context = NULL;
3399 void *tl_context = NULL;
3400 int i, ret = 0;
3401
3402 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3403 * channel change indication. Since these indications are sent by lower
3404 * layer as SAP updates and IPA doesn't have to do anything for these
3405 * updates so ignoring!
3406 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003407 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408 return 0;
3409
3410 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3411 if (hdd_ipa->iface_context[i].adapter == NULL) {
3412 iface_context = &(hdd_ipa->iface_context[i]);
3413 break;
3414 }
3415 }
3416
3417 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303418 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003419 "All the IPA interfaces are in use");
3420 ret = -ENOMEM;
3421 goto end;
3422 }
3423
3424 adapter->ipa_context = iface_context;
3425 iface_context->adapter = adapter;
3426 iface_context->sta_id = sta_id;
3427 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3428
3429 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303430 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 "Not able to get TL context sta_id: %d", sta_id);
3432 ret = -EINVAL;
3433 goto end;
3434 }
3435
3436 iface_context->tl_context = tl_context;
3437
3438 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3439 adapter->dev->dev_addr);
3440
3441 if (ret)
3442 goto end;
3443
3444 /* Configure the TX and RX pipes filter rules */
3445 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3446 if (ret)
3447 goto cleanup_header;
3448
3449 hdd_ipa->num_iface++;
3450 return ret;
3451
3452cleanup_header:
3453
3454 hdd_ipa_clean_hdr(adapter);
3455end:
3456 if (iface_context)
3457 hdd_ipa_cleanup_iface(iface_context);
3458 return ret;
3459}
3460
3461/**
3462 * hdd_ipa_msg_free_fn() - Free an IPA message
3463 * @buff: pointer to the IPA message
3464 * @len: length of the IPA message
3465 * @type: type of IPA message
3466 *
3467 * Return: None
3468 */
3469static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3470{
3471 hddLog(LOG1, "msg type:%d, len:%d", type, len);
3472 ghdd_ipa->stats.num_free_msg++;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303473 qdf_mem_free(buff);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474}
3475
3476/**
3477 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3478 * @mcc_mode: 0=MCC/1=SCC
3479 *
3480 * Return: 0 on success, negative errno value on error
3481 */
3482int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3483{
3484 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303485 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486 hdd_adapter_t *pAdapter;
3487 struct ipa_msg_meta meta;
3488 struct ipa_wlan_msg *msg;
3489 int ret;
3490
3491 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3492 return -EINVAL;
3493
3494 if (!pHddCtx->mcc_mode) {
3495 /* Flush TxRx queue for each adapter before switch to SCC */
3496 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303497 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003499 if (pAdapter->device_mode == QDF_STA_MODE ||
3500 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303501 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003502 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3503 pAdapter->device_mode);
3504 hdd_deinit_tx_rx(pAdapter);
3505 }
3506 status = hdd_get_next_adapter(
3507 pHddCtx, adapter_node, &next);
3508 adapter_node = next;
3509 }
3510 }
3511
3512 /* Send SCC/MCC Switching event to IPA */
3513 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303514 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515 if (msg == NULL) {
3516 hddLog(LOGE, "msg allocation failed");
3517 return -ENOMEM;
3518 }
3519
3520 meta.msg_type = mcc_mode ?
3521 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3522 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3523
3524 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3525
3526 if (ret) {
3527 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3528 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303529 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 }
3531
3532 return ret;
3533}
3534
3535/**
3536 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3537 * @event: IPA WLAN event to be converted to a string
3538 *
3539 * Return: ASCII string representing the IPA WLAN event
3540 */
3541static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3542{
3543 switch (event) {
3544 case WLAN_CLIENT_CONNECT:
3545 return "WLAN_CLIENT_CONNECT";
3546 case WLAN_CLIENT_DISCONNECT:
3547 return "WLAN_CLIENT_DISCONNECT";
3548 case WLAN_CLIENT_POWER_SAVE_MODE:
3549 return "WLAN_CLIENT_POWER_SAVE_MODE";
3550 case WLAN_CLIENT_NORMAL_MODE:
3551 return "WLAN_CLIENT_NORMAL_MODE";
3552 case SW_ROUTING_ENABLE:
3553 return "SW_ROUTING_ENABLE";
3554 case SW_ROUTING_DISABLE:
3555 return "SW_ROUTING_DISABLE";
3556 case WLAN_AP_CONNECT:
3557 return "WLAN_AP_CONNECT";
3558 case WLAN_AP_DISCONNECT:
3559 return "WLAN_AP_DISCONNECT";
3560 case WLAN_STA_CONNECT:
3561 return "WLAN_STA_CONNECT";
3562 case WLAN_STA_DISCONNECT:
3563 return "WLAN_STA_DISCONNECT";
3564 case WLAN_CLIENT_CONNECT_EX:
3565 return "WLAN_CLIENT_CONNECT_EX";
3566
3567 case IPA_WLAN_EVENT_MAX:
3568 default:
3569 return "UNKNOWN";
3570 }
3571}
3572
3573/**
3574 * hdd_ipa_wlan_evt() - IPA event handler
3575 * @adapter: adapter upon which the event was received
3576 * @sta_id: station id for the event
3577 * @type: the event type
3578 * @mac_address: MAC address associated with the event
3579 *
3580 * Return: 0 on success, negative errno value on error
3581 */
3582int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
3583 enum ipa_wlan_event type, uint8_t *mac_addr)
3584{
3585 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3586 struct ipa_msg_meta meta;
3587 struct ipa_wlan_msg *msg;
3588 struct ipa_wlan_msg_ex *msg_ex = NULL;
3589 int ret;
3590
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303591 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3593 mac_addr, sta_id);
3594
3595 if (type >= IPA_WLAN_EVENT_MAX)
3596 return -EINVAL;
3597
3598 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3599 return -EINVAL;
3600
3601 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303602 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 return -EINVAL;
3604 }
3605
3606 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3607 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003608 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 return 0;
3610 }
3611
3612 /*
3613 * During IPA UC resource loading/unloading new events can be issued.
3614 * Store the events separately and handle them later.
3615 */
3616 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3617 ((hdd_ipa->resource_loading) ||
3618 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003619 unsigned int pending_event_count;
3620 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621
Yun Parkf19e07d2015-11-20 11:34:27 -08003622 hdd_err("IPA resource %s inprogress",
3623 hdd_ipa->resource_loading ? "load":"unload");
3624
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303625 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003626
Anurag Chouhanffb21542016-02-17 14:33:03 +05303627 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003628 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3629 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303630 qdf_list_remove_front(&hdd_ipa->pending_event,
3631 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003632 } else {
3633 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303634 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003635 sizeof(struct ipa_uc_pending_event));
3636 }
3637
3638 if (!pending_event) {
3639 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303640 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 return -ENOMEM;
3642 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003643
3644 pending_event->adapter = adapter;
3645 pending_event->sta_id = sta_id;
3646 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303647 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303649 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303650 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003651 &pending_event->node);
3652
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303653 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003654 return 0;
3655 }
3656
3657 hdd_ipa->stats.event[type]++;
3658
Leo Chang3bc8fed2015-11-13 10:59:47 -08003659 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 switch (type) {
3661 case WLAN_STA_CONNECT:
3662 /* STA already connected and without disconnect, connect again
3663 * This is Roaming scenario
3664 */
3665 if (hdd_ipa->sta_connected)
3666 hdd_ipa_cleanup_iface(adapter->ipa_context);
3667
3668 if ((hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) &&
3669 (!hdd_ipa->sta_connected))
3670 hdd_ipa_uc_offload_enable_disable(adapter,
3671 SIR_STA_RX_DATA_OFFLOAD, 1);
3672
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303673 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674
3675 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303676 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3678 msg_ex->name, meta.msg_type);
3679 } else if ((!hdd_ipa->sap_num_connected_sta) &&
3680 (!hdd_ipa->sta_connected)) {
3681 /* Enable IPA UC TX PIPE when STA connected */
3682 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
Yun Park4cab6ee2015-10-27 11:43:40 -07003683 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303684 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303685 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686 "handle 1st con ret %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687 hdd_ipa_uc_offload_enable_disable(adapter,
3688 SIR_STA_RX_DATA_OFFLOAD, 0);
3689 goto end;
3690 }
3691 }
3692 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3693 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303694 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695 hdd_ipa_uc_offload_enable_disable(adapter,
3696 SIR_STA_RX_DATA_OFFLOAD, 0);
3697 goto end;
3698
3699#ifdef IPA_UC_OFFLOAD
3700 vdev_to_iface[adapter->sessionId] =
3701 ((struct hdd_ipa_iface_context *)
3702 (adapter->ipa_context))->iface_id;
3703#endif /* IPA_UC_OFFLOAD */
3704 }
3705
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303706 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707
3708 hdd_ipa->sta_connected = 1;
3709 break;
3710
3711 case WLAN_AP_CONNECT:
3712 /* For DFS channel we get two start_bss event (before and after
3713 * CAC). Also when ACS range includes both DFS and non DFS
3714 * channels, we could possibly change channel many times due to
3715 * RADAR detection and chosen channel may not be a DFS channels.
3716 * So dont return error here. Just discard the event.
3717 */
3718 if (adapter->ipa_context)
3719 return 0;
3720
3721 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3722 hdd_ipa_uc_offload_enable_disable(adapter,
3723 SIR_AP_RX_DATA_OFFLOAD, 1);
3724 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303725 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3727 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303728 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729 "%s: Evt: %d, Interface setup failed",
3730 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303731 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003732 goto end;
3733
3734#ifdef IPA_UC_OFFLOAD
3735 vdev_to_iface[adapter->sessionId] =
3736 ((struct hdd_ipa_iface_context *)
3737 (adapter->ipa_context))->iface_id;
3738#endif /* IPA_UC_OFFLOAD */
3739 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303740 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003741 break;
3742
3743 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303744 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003745 hdd_ipa_cleanup_iface(adapter->ipa_context);
3746
3747 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303748 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003749 "%s: Evt: %d, STA already disconnected",
3750 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303751 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003752 return -EINVAL;
3753 }
3754 hdd_ipa->sta_connected = 0;
3755 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303756 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003757 "%s: IPA UC OFFLOAD NOT ENABLED",
3758 msg_ex->name);
3759 } else {
3760 /* Disable IPA UC TX PIPE when STA disconnected */
3761 if ((!hdd_ipa->sap_num_connected_sta) ||
3762 ((!hdd_ipa->num_iface) &&
3763 (HDD_IPA_UC_NUM_WDI_PIPE ==
3764 hdd_ipa->activated_fw_pipe))) {
3765 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3766 }
3767 }
3768
3769 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3770 hdd_ipa_uc_offload_enable_disable(adapter,
3771 SIR_STA_RX_DATA_OFFLOAD, 0);
3772 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3773 }
3774
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303775 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776 break;
3777
3778 case WLAN_AP_DISCONNECT:
3779 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303780 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003781 "%s: Evt: %d, SAP already disconnected",
3782 msg_ex->name, meta.msg_type);
3783 return -EINVAL;
3784 }
3785
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303786 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003787 hdd_ipa_cleanup_iface(adapter->ipa_context);
3788 if ((!hdd_ipa->num_iface) &&
3789 (HDD_IPA_UC_NUM_WDI_PIPE ==
3790 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003791 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003792 /*
3793 * We disable WDI pipes directly here since
3794 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3795 * processed when unloading WLAN driver is in
3796 * progress
3797 */
3798 hdd_ipa_uc_disable_pipes(hdd_ipa);
3799 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303800 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003801 "NO INTF left but still pipe clean up");
3802 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3803 }
3804 }
3805
3806 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3807 hdd_ipa_uc_offload_enable_disable(adapter,
3808 SIR_AP_RX_DATA_OFFLOAD, 0);
3809 vdev_to_iface[adapter->sessionId] = HDD_IPA_MAX_IFACE;
3810 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303811 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812 break;
3813
3814 case WLAN_CLIENT_CONNECT_EX:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303815 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%d %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816 adapter->dev->ifindex, sta_id);
3817
3818 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303819 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
3821 adapter->dev->name, meta.msg_type);
3822 return 0;
3823 }
3824
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303825 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
3827 true, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303828 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 "%s: STA ID %d found, not valid",
3830 adapter->dev->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303831 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832 return 0;
3833 }
Yun Park312f71a2015-12-08 10:22:42 -08003834
3835 /* Enable IPA UC Data PIPEs when first STA connected */
3836 if ((0 == hdd_ipa->sap_num_connected_sta) &&
3837 (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3838 !hdd_ipa->sta_connected)) {
3839 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
3840 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303841 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303842 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08003843 "%s: handle 1st con ret %d",
3844 adapter->dev->name, ret);
3845 return ret;
3846 }
3847 }
3848
3849 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08003850
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303851 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003852
3853 meta.msg_type = type;
3854 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
3855 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303856 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857
3858 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303859 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860 "msg_ex allocation failed");
3861 return -ENOMEM;
3862 }
3863 strlcpy(msg_ex->name, adapter->dev->name,
3864 IPA_RESOURCE_NAME_MAX);
3865 msg_ex->num_of_attribs = 1;
3866 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
3867 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3868 msg_ex->attribs[0].offset =
3869 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3870 } else {
3871 msg_ex->attribs[0].offset =
3872 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3873 }
3874 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
3875 IPA_MAC_ADDR_SIZE);
3876
3877 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
3878
3879 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303880 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303882 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003883 return ret;
3884 }
3885 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886 return ret;
3887
3888 case WLAN_CLIENT_DISCONNECT:
3889 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303890 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 "%s: IPA UC OFFLOAD NOT ENABLED",
3892 msg_ex->name);
3893 return 0;
3894 }
3895
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303896 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303898 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003899 "%s: STA ID %d NOT found, not valid",
3900 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303901 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902 return 0;
3903 }
3904 hdd_ipa->sap_num_connected_sta--;
3905 /* Disable IPA UC TX PIPE when last STA disconnected */
3906 if (!hdd_ipa->sap_num_connected_sta
3907 && (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) ||
3908 !hdd_ipa->sta_connected)
3909 && (false == hdd_ipa->resource_unloading)
3910 && (HDD_IPA_UC_NUM_WDI_PIPE ==
3911 hdd_ipa->activated_fw_pipe))
3912 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303913 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 break;
3915
3916 default:
3917 return 0;
3918 }
3919
3920 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303921 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303923 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003924 return -ENOMEM;
3925 }
3926
3927 meta.msg_type = type;
3928 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
3929 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
3930
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303931 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932 msg->name, meta.msg_type);
3933
3934 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3935
3936 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303937 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003938 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303939 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003940 return ret;
3941 }
3942
3943 hdd_ipa->stats.num_send_msg++;
3944
3945end:
3946 return ret;
3947}
3948
3949/**
3950 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
3951 * @state: IPA RM state value
3952 *
3953 * Return: ASCII string representing the IPA RM state
3954 */
3955static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
3956{
3957 switch (state) {
3958 case HDD_IPA_RM_RELEASED:
3959 return "RELEASED";
3960 case HDD_IPA_RM_GRANT_PENDING:
3961 return "GRANT_PENDING";
3962 case HDD_IPA_RM_GRANTED:
3963 return "GRANTED";
3964 }
3965
3966 return "UNKNOWN";
3967}
3968
3969/**
3970 * hdd_ipa_init() - IPA initialization function
3971 * @hdd_ctx: HDD global context
3972 *
3973 * Allocate hdd_ipa resources, ipa pipe resource and register
3974 * wlan interface with IPA module.
3975 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303976 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003977 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303978QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979{
3980 struct hdd_ipa_priv *hdd_ipa = NULL;
3981 int ret, i;
3982 struct hdd_ipa_iface_context *iface_context = NULL;
3983
3984 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303985 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003986
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303987 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303989 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08003990 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 }
3992
3993 hdd_ctx->hdd_ipa = hdd_ipa;
3994 ghdd_ipa = hdd_ipa;
3995 hdd_ipa->hdd_ctx = hdd_ctx;
3996 hdd_ipa->num_iface = 0;
Anurag Chouhan6d760662016-02-20 16:05:43 +05303997 ol_txrx_ipa_uc_get_resource(cds_get_context(QDF_MODULE_ID_TXRX),
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003998 &hdd_ipa->ipa_resource);
3999 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4000 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4001 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4002 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304003 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004004 "IPA UC resource alloc fail");
4005 goto fail_get_resource;
4006 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004007
4008 /* Create the interface context */
4009 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4010 iface_context = &hdd_ipa->iface_context[i];
4011 iface_context->hdd_ipa = hdd_ipa;
4012 iface_context->cons_client =
4013 hdd_ipa_adapter_2_client[i].cons_client;
4014 iface_context->prod_client =
4015 hdd_ipa_adapter_2_client[i].prod_client;
4016 iface_context->iface_id = i;
4017 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304018 qdf_spinlock_create(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 }
4020
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_send_pkt_to_tl);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304022 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304023 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024
4025 ret = hdd_ipa_setup_rm(hdd_ipa);
4026 if (ret)
4027 goto fail_setup_rm;
4028
4029 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4030 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304031 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 hdd_ipa->sap_num_connected_sta = 0;
4033 hdd_ipa->ipa_tx_packets_diff = 0;
4034 hdd_ipa->ipa_rx_packets_diff = 0;
4035 hdd_ipa->ipa_p_tx_packets = 0;
4036 hdd_ipa->ipa_p_rx_packets = 0;
4037 hdd_ipa->resource_loading = false;
4038 hdd_ipa->resource_unloading = false;
4039 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004040 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 /* Setup IPA sys_pipe for MCC */
4042 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4043 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4044 if (ret)
4045 goto fail_create_sys_pipe;
4046 }
4047 hdd_ipa_uc_ol_init(hdd_ctx);
4048 } else {
4049 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4050 if (ret)
4051 goto fail_create_sys_pipe;
4052 }
4053
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304054 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004055
4056fail_create_sys_pipe:
4057 hdd_ipa_destroy_rm_resource(hdd_ipa);
4058fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304059 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004060fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304061 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004062 hdd_ctx->hdd_ipa = NULL;
4063 ghdd_ipa = NULL;
4064fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304065 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066}
4067
4068/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004069 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4070 * @hdd_ipa: pointer to HDD IPA struct
4071 *
4072 * Return: none
4073 */
4074void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
4075{
4076 struct ipa_uc_pending_event *pending_event = NULL;
4077
Anurag Chouhanffb21542016-02-17 14:33:03 +05304078 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4079 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304080 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004081 }
4082
Anurag Chouhanffb21542016-02-17 14:33:03 +05304083 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004084}
4085
4086/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004087 * hdd_ipa_cleanup - IPA cleanup function
4088 * @hdd_ctx: HDD global context
4089 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304090 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004091 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304092QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004093{
4094 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4095 int i;
4096 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304097 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4099
4100 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304101 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102
4103 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4104 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4105 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4106 }
4107
4108 /* Teardown IPA sys_pipe for MCC */
4109 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4110 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4111
4112 hdd_ipa_destroy_rm_resource(hdd_ipa);
4113
4114#ifdef WLAN_OPEN_SOURCE
4115 cancel_work_sync(&hdd_ipa->pm_work);
4116#endif
4117
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304118 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004119
Nirav Shahcbc6d722016-03-01 16:24:53 +05304120 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4121 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304122 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123
4124 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4125 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4126
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304127 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004128 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304129 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004130
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304131 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004132
4133 /* destory the interface lock */
4134 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4135 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304136 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137 }
4138
4139 /* This should never hit but still make sure that there are no pending
4140 * descriptor in IPA hardware
4141 */
4142 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304143 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 "IPA Pending write done: %d Waiting!",
4145 hdd_ipa->pending_hw_desc_cnt);
4146
4147 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4148 usleep_range(100, 100);
4149 }
4150
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304151 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 "IPA Pending write done: desc: %d %s(%d)!",
4153 hdd_ipa->pending_hw_desc_cnt,
4154 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4155 : "leak", i);
4156 }
4157 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4158 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304159 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160 "%s: Disconnect TX PIPE", __func__);
4161 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304162 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163 "%s: Disconnect RX PIPE", __func__);
4164 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304165 qdf_mutex_destroy(&hdd_ipa->event_lock);
4166 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004167 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168
4169#ifdef WLAN_OPEN_SOURCE
4170 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4171 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4172 hdd_ipa->uc_op_work[i].msg = NULL;
4173 }
4174#endif
4175 }
4176
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304177 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004178 hdd_ctx->hdd_ipa = NULL;
4179
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304180 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004181}
4182#endif /* IPA_OFFLOAD */