blob: 510a5717088fdd913932124ff7af75694e4faae8 [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 */
Mohit Khannafa99aea2016-05-12 21:43:13 -070038#include <linux/ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
42#include <linux/etherdevice.h>
43#include <linux/atomic.h>
44#include <linux/netdevice.h>
45#include <linux/skbuff.h>
46#include <linux/list.h>
47#include <linux/debugfs.h>
48#include <linux/inetdevice.h>
49#include <linux/ip.h>
50#include <wlan_hdd_softap_tx_rx.h>
51#include <ol_txrx_osif_api.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070052#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080053
54#include "cds_sched.h"
55
56#include "wma.h"
57#include "wma_api.h"
58
Dhanashri Atreb08959a2016-03-01 17:28:03 -080059#include "cdp_txrx_ipa.h"
60
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080061#define HDD_IPA_DESC_BUFFER_RATIO 4
62#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
63#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
64
65#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066#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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182/**
183 * struct hdd_ipa_cld_hdr - IPA CLD Header
184 * @reserved: reserved fields
185 * @iface_id: interface ID
186 * @sta_id: Station ID
187 *
188 * Packed 32-bit structure
189 * +----------+----------+--------------+--------+
190 * | Reserved | QCMAP ID | interface id | STA ID |
191 * +----------+----------+--------------+--------+
192 */
193struct hdd_ipa_cld_hdr {
194 uint8_t reserved[2];
195 uint8_t iface_id;
196 uint8_t sta_id;
197} __packed;
198
199struct hdd_ipa_rx_hdr {
200 struct hdd_ipa_cld_hdr cld_hdr;
201 struct ethhdr eth;
202} __packed;
203
204struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700205 bool exception;
206 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800207 struct hdd_ipa_iface_context *iface_context;
208 struct ipa_rx_data *ipa_tx_desc;
209};
210
211struct hdd_ipa_uc_rx_hdr {
212 struct ethhdr eth;
213} __packed;
214
215struct hdd_ipa_sys_pipe {
216 uint32_t conn_hdl;
217 uint8_t conn_hdl_valid;
218 struct ipa_sys_connect_params ipa_sys_params;
219};
220
221struct hdd_ipa_iface_stats {
222 uint64_t num_tx;
223 uint64_t num_tx_drop;
224 uint64_t num_tx_err;
225 uint64_t num_tx_cac_drop;
226 uint64_t num_rx_prefilter;
227 uint64_t num_rx_ipa_excep;
228 uint64_t num_rx_recv;
229 uint64_t num_rx_recv_mul;
230 uint64_t num_rx_send_desc_err;
231 uint64_t max_rx_mul;
232};
233
234struct hdd_ipa_priv;
235
236struct hdd_ipa_iface_context {
237 struct hdd_ipa_priv *hdd_ipa;
238 hdd_adapter_t *adapter;
239 void *tl_context;
240
241 enum ipa_client_type cons_client;
242 enum ipa_client_type prod_client;
243
244 uint8_t iface_id; /* This iface ID */
245 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530246 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 uint32_t ifa_address;
248 struct hdd_ipa_iface_stats stats;
Yun Park8292dcb2016-10-07 16:46:06 -0700249 uint32_t offload_enabled;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800250};
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 {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530365 uint64_t 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 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700460static void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800461{
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
Jeff Johnsond7720632016-10-05 16:04:32 -0700470static uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800471{
472 uint32_t ipa_priv = 0;
473
474 BUG_ON(ptr == NULL);
475 return ipa_priv;
476}
Leo Changcc923e22016-06-16 15:29:03 -0700477
478#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
479#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800480#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
481#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
482#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
483#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
484#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
485#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700486#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
487 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800488
Leo Chang3bc8fed2015-11-13 10:59:47 -0800489#define HDD_IPA_FW_RX_DESC_DISCARD_M 0x1
490#define HDD_IPA_FW_RX_DESC_FORWARD_M 0x2
491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492#define HDD_IPA_GET_IFACE_ID(_data) \
493 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
494
495#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530496 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 "%s:%d: "fmt, __func__, __LINE__, ## args)
498
Govind Singhb6a89772016-08-12 11:23:35 +0530499#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
500 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
501 "%s:%d: "fmt, __func__, __LINE__, ## args)
502
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
504 do { \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530505 QDF_TRACE(QDF_MODULE_ID_HDD, _lvl, "%s:", _prefix); \
506 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507 } while (0)
508
509#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
510 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
511
512#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
513 do { \
514 hdd_ipa->ipa_rx_internel_drop_count++; \
515 } while (0)
516#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
517 do { \
518 hdd_ipa->ipa_rx_net_send_count++; \
519 } while (0)
520#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
521
Leo Chang07b28f62016-05-11 12:29:22 -0700522#if defined (QCA_WIFI_3_0) && defined (CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800523#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
524do { \
525 pipe_in.u.ul.rdy_ring_rp_va = \
526 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
527 pipe_in.u.ul.rdy_comp_ring_base_pa = \
528 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
529 pipe_in.u.ul.rdy_comp_ring_size = \
530 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
531 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
532 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
533 pipe_in.u.ul.rdy_comp_ring_wp_va = \
534 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800535} while (0)
Leo Chang63d73612016-10-18 18:09:43 -0700536
537#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800538#else
539/* Do nothing */
540#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang63d73612016-10-18 18:09:43 -0700541#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700542#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800543
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800544static struct hdd_ipa_adapter_2_client {
545 enum ipa_client_type cons_client;
546 enum ipa_client_type prod_client;
547} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
548 {
549 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
550 }, {
551 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
552 }, {
553 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
554 },
555};
556
557/* For Tx pipes, use Ethernet-II Header format */
558struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
559 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800560 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800561 0x00000000,
562 0x00000000
563 },
564 {
565 0x00000000
566 },
567 {
568 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
569 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
570 0x0008
571 }
572};
573
574/* For Tx pipes, use 802.3 Header format */
575static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
576 {
577 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
578 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
579 0x00 /* length can be zero */
580 },
581 {
582 /* LLC SNAP header 8 bytes */
583 0xaa, 0xaa,
584 {0x03, 0x00, 0x00, 0x00},
585 0x0008 /* type value(2 bytes) ,filled by wlan */
586 /* 0x0800 - IPV4, 0x86dd - IPV6 */
587 }
588};
589
590static const char *op_string[] = {
591 "TX_SUSPEND",
592 "TX_RESUME",
593 "RX_SUSPEND",
594 "RX_RESUME",
595 "STATS",
596};
597
598static struct hdd_ipa_priv *ghdd_ipa;
599
600/* Local Function Prototypes */
601static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
602 unsigned long data);
603static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
604 unsigned long data);
605
606static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Mohit Khannafa99aea2016-05-12 21:43:13 -0700607static void hdd_ipa_uc_proc_pending_event (struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800608
609/**
610 * hdd_ipa_is_enabled() - Is IPA enabled?
611 * @hdd_ctx: Global HDD context
612 *
613 * Return: true if IPA is enabled, false otherwise
614 */
615bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
616{
617 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
618}
619
620/**
621 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
622 * @hdd_ctx: Global HDD context
623 *
624 * Return: true if IPA uC offload is enabled, false otherwise
625 */
626bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
627{
628 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
629}
630
631/**
632 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
633 * @hdd_ctx: Global HDD context
634 *
635 * Return: true if STA mode IPA uC offload is enabled, false otherwise
636 */
637static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
638{
639 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
640}
641
642/**
643 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
644 * @hdd_ipa: Global HDD IPA context
645 *
646 * Return: true if pre-filter is enabled, otherwise false
647 */
648static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
649{
650 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
651 HDD_IPA_PRE_FILTER_ENABLE_MASK);
652}
653
654/**
655 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
656 * @hdd_ipa: Global HDD IPA context
657 *
658 * Return: true if IPv6 is enabled, otherwise false
659 */
660static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
661{
662 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
663}
664
665/**
666 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
667 * @hdd_ipa: Global HDD IPA context
668 *
669 * Return: true if resource manager is enabled, otherwise false
670 */
671static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
672{
673 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
674}
675
676/**
677 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
678 * @hdd_ipa: Global HDD IPA context
679 *
680 * Return: true if resource manager is enabled, otherwise false
681 */
682static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
683{
684 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
685}
686
687/**
688 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
689 * @hdd_ipa: Global HDD IPA context
690 *
691 * Return: true if clock scaling is enabled, otherwise false
692 */
693static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
694{
695 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
696 HDD_IPA_CLK_SCALING_ENABLE_MASK |
697 HDD_IPA_RM_ENABLE_MASK);
698}
699
700/**
701 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
702 * @ctext: pointer to hdd context.
703 *
704 * If rt debug enabled, periodically called, and fill debug buffer
705 *
706 * Return: none
707 */
708static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
709{
710 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
711 struct hdd_ipa_priv *hdd_ipa;
712 struct uc_rt_debug_info *dump_info = NULL;
713
714 if (wlan_hdd_validate_context(hdd_ctx))
715 return;
716
717 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530718 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800719 "%s: IPA UC is not enabled", __func__);
720 return;
721 }
722
723 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
724
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530725 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800726 dump_info = &hdd_ipa->rt_bug_buffer[
727 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
728
Deepthi Gowri6acee342016-10-28 15:00:38 +0530729 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800730 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
731 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
732 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
733 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
734 dump_info->tx_mcbc_count = hdd_ipa->stats.num_tx_bcmc;
735 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
736 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
737 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530738 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800739
Anurag Chouhan210db072016-02-22 18:42:15 +0530740 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800741 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
742}
743
744/**
745 * hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
746 * @hdd_ctx: pointer to hdd context.
747 *
748 * If rt debug enabled, dump debug buffer contents based on requirement
749 *
750 * Return: none
751 */
752void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
753{
754 struct hdd_ipa_priv *hdd_ipa;
755 unsigned int dump_count;
756 unsigned int dump_index;
757 struct uc_rt_debug_info *dump_info = NULL;
758
759 if (wlan_hdd_validate_context(hdd_ctx))
760 return;
761
762 hdd_ipa = hdd_ctx->hdd_ipa;
763 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530764 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 "%s: IPA UC is not enabled", __func__);
766 return;
767 }
768
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530769 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530771 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772 " TM : EXEP : DROP : NETS : MCBC : TXFD : DSTR : DSCD\n");
773
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530774 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800775 for (dump_count = 0;
776 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
777 dump_count++) {
778 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
779 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
780 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530781 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530782 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783 dump_info->time, dump_info->ipa_excep_count,
784 dump_info->rx_drop_count, dump_info->net_sent_count,
785 dump_info->tx_mcbc_count, dump_info->tx_fwd_count,
786 dump_info->rx_destructor_call,
787 dump_info->rx_discard_count);
788 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530789 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530790 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800791 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
792}
793
794/**
795 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
796 * @ctext: pointer to hdd context.
797 *
798 * periodically called by timer expire
799 * will try to alloc dummy memory and detect out of memory condition
800 * if out of memory detected, dump wlan-ipa stats
801 *
802 * Return: none
803 */
804static void hdd_ipa_uc_rt_debug_handler(void *ctext)
805{
806 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
807 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
808 void *dummy_ptr = NULL;
809
810 if (wlan_hdd_validate_context(hdd_ctx))
811 return;
812
813 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530814 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800815 "%s: IPA RT debug is not enabled", __func__);
816 return;
817 }
818
819 /* Allocate dummy buffer periodically and free immediately. this will
820 * proactively detect OOM and if allocation fails dump ipa stats
821 */
822 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
823 GFP_KERNEL | GFP_ATOMIC);
824 if (!dummy_ptr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530825 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800826 "%s: Dummy alloc fail", __func__);
827 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
828 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -0800829 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 } else {
831 kfree(dummy_ptr);
832 }
833
Anurag Chouhan210db072016-02-22 18:42:15 +0530834 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 HDD_IPA_UC_RT_DEBUG_PERIOD);
836}
837
838/**
839 * hdd_ipa_uc_rt_debug_destructor - called by data packet free
840 * @skb: packet pinter
841 *
842 * when free data packet, will be invoked by wlan client and will increase
843 * free counter
844 *
845 * Return: none
846 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700847static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800848{
849 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530850 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 "%s: invalid hdd context", __func__);
852 return;
853 }
854
855 ghdd_ipa->ipa_rx_destructor_count++;
856}
857
858/**
859 * hdd_ipa_uc_rt_debug_deinit - remove resources to handle rt debugging
860 * @hdd_ctx: hdd main context
861 *
862 * free all rt debugging resources
863 *
864 * Return: none
865 */
866static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
867{
868 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
869
Anurag Chouhan210db072016-02-22 18:42:15 +0530870 if (QDF_TIMER_STATE_STOPPED !=
871 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
872 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530874 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530875 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800876
877 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530878 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 "%s: IPA RT debug is not enabled", __func__);
880 return;
881 }
882
Anurag Chouhan210db072016-02-22 18:42:15 +0530883 if (QDF_TIMER_STATE_STOPPED !=
884 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
885 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530887 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800888}
889
890/**
891 * hdd_ipa_uc_rt_debug_init - intialize resources to handle rt debugging
892 * @hdd_ctx: hdd main context
893 *
894 * alloc and initialize all rt debugging resources
895 *
896 * Return: none
897 */
898static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
899{
900 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
901
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530902 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Anurag Chouhan210db072016-02-22 18:42:15 +0530903 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
905 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530906 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 sizeof(struct uc_rt_debug_info) *
908 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
909 hdd_ipa->ipa_tx_forward = 0;
910 hdd_ipa->ipa_rx_discard = 0;
911 hdd_ipa->ipa_rx_net_send_count = 0;
912 hdd_ipa->ipa_rx_internel_drop_count = 0;
913 hdd_ipa->ipa_rx_destructor_count = 0;
914
Anurag Chouhan210db072016-02-22 18:42:15 +0530915 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
917
918 /* Reatime debug enable on feature enable */
919 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530920 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 "%s: IPA RT debug is not enabled", __func__);
922 return;
923 }
Anurag Chouhan210db072016-02-22 18:42:15 +0530924 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +0530926 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800927 HDD_IPA_UC_RT_DEBUG_PERIOD);
928
929}
930
931/**
932 * hdd_ipa_uc_stat_query() - Query the IPA stats
933 * @hdd_ctx: Global HDD context
934 * @ipa_tx_diff: tx packet count diff from previous
935 * tx packet count
936 * @ipa_rx_diff: rx packet count diff from previous
937 * rx packet count
938 *
939 * Return: true if IPA is enabled, false otherwise
940 */
941void hdd_ipa_uc_stat_query(hdd_context_t *pHddCtx,
942 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
943{
944 struct hdd_ipa_priv *hdd_ipa;
945
946 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
947 *ipa_tx_diff = 0;
948 *ipa_rx_diff = 0;
949
950 if (!hdd_ipa_is_enabled(pHddCtx) ||
951 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
952 return;
953 }
954
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530955 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
957 (false == hdd_ipa->resource_loading)) {
958 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
959 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkf8d6a122016-10-11 15:49:43 -0700960 HDD_IPA_LOG(LOGOFF, "STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 *ipa_tx_diff, *ipa_rx_diff);
962 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530963 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964 return;
965}
966
967/**
968 * hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
969 * @adapter: network adapter
970 * @reason: STAT REQ Reason
971 *
972 * Return: None
973 */
974void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
975{
976 hdd_context_t *pHddCtx;
977 struct hdd_ipa_priv *hdd_ipa;
978
979 if (!adapter) {
980 return;
981 }
982
983 pHddCtx = (hdd_context_t *)adapter->pHddCtx;
984 hdd_ipa = (struct hdd_ipa_priv *)pHddCtx->hdd_ipa;
985 if (!hdd_ipa_is_enabled(pHddCtx) ||
986 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
987 return;
988 }
989
Yun Park8f289c82016-10-18 16:38:21 -0700990 HDD_IPA_LOG(LOGOFF, "STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530991 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800992 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
993 (false == hdd_ipa->resource_loading)) {
994 hdd_ipa->stat_req_reason = reason;
995 wma_cli_set_command(
996 (int)adapter->sessionId,
997 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
998 0, VDEV_CMD);
999 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301000 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001}
1002
1003/**
1004 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1005 * @hdd_ipa: Global HDD IPA context
1006 * @sta_add: Should station be added
1007 * @sta_id: ID of the station being queried
1008 *
1009 * Return: true if the station was found
1010 */
1011static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1012 bool sta_add, uint8_t sta_id)
1013{
1014 bool sta_found = false;
1015 uint8_t idx;
1016 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1017 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1018 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1019 sta_found = true;
1020 break;
1021 }
1022 }
1023 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301024 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001025 "%s: STA ID %d already exist, cannot add",
1026 __func__, sta_id);
1027 return sta_found;
1028 }
1029 if (sta_add) {
1030 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1031 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1032 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1033 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1034 return sta_found;
1035 }
1036 }
1037 }
1038 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301039 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 "%s: STA ID %d does not exist, cannot delete",
1041 __func__, sta_id);
1042 return sta_found;
1043 }
1044 if (!sta_add) {
1045 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1046 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1047 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1048 hdd_ipa->assoc_stas_map[idx].is_reserved =
1049 false;
1050 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1051 return sta_found;
1052 }
1053 }
1054 }
1055 return sta_found;
1056}
1057
1058/**
1059 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1060 * @hdd_ipa: Global HDD IPA context
1061 *
1062 * Return: 0 on success, negative errno if error
1063 */
1064static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1065{
1066 int result;
1067 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1068
1069 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301070 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001071 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1072 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1074 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301075 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001076 "%s: Enable TX PIPE fail, code %d",
1077 __func__, result);
1078 return result;
1079 }
1080 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1081 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301082 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001083 "%s: Resume TX PIPE fail, code %d",
1084 __func__, result);
1085 return result;
1086 }
1087 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, true);
1088
1089 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301090 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001091 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1092 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1094 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301095 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001096 "%s: Enable RX PIPE fail, code %d",
1097 __func__, result);
1098 return result;
1099 }
1100 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1101 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301102 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103 "%s: Resume RX PIPE fail, code %d",
1104 __func__, result);
1105 return result;
1106 }
1107 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, true, false);
Leo Change3e49442015-10-26 20:07:13 -07001108 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 return 0;
1110}
1111
1112/**
1113 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1114 * @hdd_ipa: Global HDD IPA context
1115 *
1116 * Return: 0 on success, negative errno if error
1117 */
1118static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1119{
1120 int result;
1121
Leo Change3e49442015-10-26 20:07:13 -07001122 hdd_ipa->ipa_pipes_down = true;
1123
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301124 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1126 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301127 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 "%s: Suspend RX PIPE fail, code %d",
1129 __func__, result);
1130 return result;
1131 }
1132 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1133 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301134 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001135 "%s: Disable RX PIPE fail, code %d",
1136 __func__, result);
1137 return result;
1138 }
1139
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301140 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1142 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301143 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001144 "%s: Suspend TX PIPE fail, code %d",
1145 __func__, result);
1146 return result;
1147 }
1148 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1149 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301150 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 "%s: Disable TX PIPE fail, code %d",
1152 __func__, result);
1153 return result;
1154 }
1155
1156 return 0;
1157}
1158
1159/**
1160 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1161 * @hdd_ipa: Global HDD IPA context
1162 *
1163 * Return: 0 on success, negative errno if error
1164 */
1165static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1166{
1167 hdd_ipa->activated_fw_pipe = 0;
1168 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001169
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001170 /* If RM feature enabled
1171 * Request PROD Resource first
1172 * PROD resource may return sync or async manners */
Yun Park4cab6ee2015-10-27 11:43:40 -07001173 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1174 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1175 /* RM PROD request sync return
1176 * enable pipe immediately
1177 */
1178 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",
1181 __func__);
1182 hdd_ipa->resource_loading = false;
1183 return -EBUSY;
1184 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001185 }
1186 } else {
1187 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001188 * Just enabled all the PIPEs
1189 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001190 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301191 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001192 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001193 __func__);
1194 hdd_ipa->resource_loading = false;
1195 return -EBUSY;
1196 }
1197 hdd_ipa->resource_loading = false;
1198 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001199
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301200 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001201 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001202 return 0;
1203}
1204
1205/**
1206 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1207 * @hdd_ipa: Global HDD IPA context
1208 *
1209 * Return: None
1210 */
1211static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1212{
1213 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
1214
1215 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301216 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001217 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301218 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219 ol_txrx_ipa_uc_set_active(cds_ctx->pdev_txrx_ctx, false, true);
1220}
1221
1222/**
1223 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1224 * @context: User context registered with TL (the IPA Global context is
1225 * registered
1226 * @rxpkt: Packet containing the notification
1227 * @staid: ID of the station associated with the packet
1228 *
1229 * Return: None
1230 */
1231static void
1232hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1233{
1234 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301235 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236
1237 /*
1238 * When SSR is going on or driver is unloading, just return.
1239 */
1240 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301241 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001242 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243
1244 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1245 return;
1246
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301247 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001248 __func__, event);
1249
1250 switch (event) {
1251 case IPA_RM_RESOURCE_GRANTED:
1252 /* Differed RM Granted */
1253 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301254 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001255 if ((false == hdd_ipa->resource_unloading) &&
1256 (!hdd_ipa->activated_fw_pipe)) {
1257 hdd_ipa_uc_enable_pipes(hdd_ipa);
1258 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301259 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001260 break;
1261
1262 case IPA_RM_RESOURCE_RELEASED:
1263 /* Differed RM Released */
1264 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265 break;
1266
1267 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301268 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001269 "%s, invalid event code %d", __func__, event);
1270 break;
1271 }
1272}
1273
1274/**
1275 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
1276 * @hdd_ipa: Global HDD IPA context
1277 * @event: IPA resource manager event to be deferred
1278 *
1279 * This function is called when a resource manager event is received
1280 * from firmware in interrupt context. This function will defer the
1281 * handling to the OL RX thread
1282 *
1283 * Return: None
1284 */
1285static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
1286{
1287 enum ipa_rm_event event;
1288 struct uc_rm_work_struct *uc_rm_work = container_of(work,
1289 struct uc_rm_work_struct, work);
1290 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
1291 struct hdd_ipa_priv, uc_rm_work);
1292
1293 cds_ssr_protect(__func__);
1294 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301295 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001296 "%s, posted event %d", __func__, event);
1297
1298 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
1299 cds_ssr_unprotect(__func__);
1300
1301 return;
1302}
1303
1304/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305 * hdd_ipa_uc_op_cb() - IPA uC operation callback
1306 * @op_msg: operation message received from firmware
1307 * @usr_ctxt: user context registered with TL (we register the HDD Global
1308 * context)
1309 *
1310 * Return: None
1311 */
1312static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
1313{
1314 struct op_msg_type *msg = op_msg;
1315 struct ipa_uc_fw_stats *uc_fw_stat;
1316 struct IpaHwStatsWDIInfoData_t ipa_stat;
1317 struct hdd_ipa_priv *hdd_ipa;
1318 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301319 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320
1321 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301322 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001323 return;
1324 }
1325
1326 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301327 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001328 "%s, INVALID OPCODE %d", __func__, msg->op_code);
1329 return;
1330 }
1331
1332 hdd_ctx = (hdd_context_t *) usr_ctxt;
1333
1334 /*
1335 * When SSR is going on or driver is unloading, just return.
1336 */
1337 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301338 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301339 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001340 return;
1341 }
1342
1343 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1344
Govind Singhb6a89772016-08-12 11:23:35 +05301345 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001346 "%s, OPCODE %s", __func__, op_string[msg->op_code]);
1347
1348 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
1349 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301350 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001351 hdd_ipa->activated_fw_pipe++;
1352 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
1353 hdd_ipa->resource_loading = false;
1354 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08001355 if (hdd_ipa->pending_cons_req)
1356 ipa_rm_notify_completion(
1357 IPA_RM_RESOURCE_GRANTED,
1358 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08001359 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001360 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301361 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001362 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001363 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301364 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001365 hdd_ipa->activated_fw_pipe--;
1366 if (!hdd_ipa->activated_fw_pipe) {
1367 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08001368 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
1369 ipa_rm_release_resource(
1370 IPA_RM_RESOURCE_WLAN_PROD);
1371 /* Sync return success from IPA
1372 * Enable/resume all the PIPEs */
1373 hdd_ipa->resource_unloading = false;
1374 hdd_ipa_uc_proc_pending_event(hdd_ipa);
1375 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001376 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301377 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07001378 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001379 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001380 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001381 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301382 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001383 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001384 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001385 "CE RING SIZE: %d\n"
1386 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001387 (unsigned long long)res->ce_sr_base_paddr,
1388 res->ce_sr_ring_size,
1389 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301390 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001392 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001393 "COMP RING SIZE: %d\n"
1394 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001395 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001396 (unsigned long long)res->tx_comp_ring_base_paddr,
1397 res->tx_comp_ring_size,
1398 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001399 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301400 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001401 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001402 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001403 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08001404 "IND RING DBELL : 0x%llx\n"
1405 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406 "NUM EXCP PKT : %llu\n"
1407 "NUM TX BCMC : %llu\n"
1408 "NUM TX BCMC ERR : %llu",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001409 (unsigned long long)res->rx_rdy_ring_base_paddr,
1410 res->rx_rdy_ring_size,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001411 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001412 (unsigned long long)hdd_ipa->ipa_resource.
1413 rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001414 hdd_ipa->stats.num_rx_excep,
1415 hdd_ipa->stats.num_tx_bcmc,
Manikandan Mohan22b83722015-12-15 15:03:23 -08001416 (unsigned long long)hdd_ipa->stats.num_tx_bcmc_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301417 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418 "==== IPA_UC WLAN_HOST CONTROL ====\n"
1419 "SAP NUM STAs: %d\n"
1420 "STA CONNECTED: %d\n"
1421 "TX PIPE HDL: %d\n"
1422 "RX PIPE HDL : %d\n"
1423 "RSC LOADING : %d\n"
1424 "RSC UNLOADING : %d\n"
1425 "PNDNG CNS RQT : %d",
1426 hdd_ipa->sap_num_connected_sta,
1427 hdd_ipa->sta_connected,
1428 hdd_ipa->tx_pipe_handle,
1429 hdd_ipa->rx_pipe_handle,
1430 (unsigned int)hdd_ipa->resource_loading,
1431 (unsigned int)hdd_ipa->resource_unloading,
1432 (unsigned int)hdd_ipa->pending_cons_req);
1433
1434 /* STATs from FW */
1435 uc_fw_stat = (struct ipa_uc_fw_stats *)
1436 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301437 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001438 "==== IPA_UC WLAN_FW TX ====\n"
1439 "COMP RING BASE: 0x%x\n"
1440 "COMP RING SIZE: %d\n"
1441 "COMP RING DBELL : 0x%x\n"
1442 "COMP RING DBELL IND VAL : %d\n"
1443 "COMP RING DBELL CACHED VAL : %d\n"
1444 "COMP RING DBELL CACHED VAL : %d\n"
1445 "PKTS ENQ : %d\n"
1446 "PKTS COMP : %d\n"
1447 "IS SUSPEND : %d\n"
1448 "RSVD : 0x%x",
1449 uc_fw_stat->tx_comp_ring_base,
1450 uc_fw_stat->tx_comp_ring_size,
1451 uc_fw_stat->tx_comp_ring_dbell_addr,
1452 uc_fw_stat->tx_comp_ring_dbell_ind_val,
1453 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1454 uc_fw_stat->tx_comp_ring_dbell_cached_val,
1455 uc_fw_stat->tx_pkts_enqueued,
1456 uc_fw_stat->tx_pkts_completed,
1457 uc_fw_stat->tx_is_suspend, uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301458 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 "==== IPA_UC WLAN_FW RX ====\n"
1460 "IND RING BASE: 0x%x\n"
1461 "IND RING SIZE: %d\n"
1462 "IND RING DBELL : 0x%x\n"
1463 "IND RING DBELL IND VAL : %d\n"
1464 "IND RING DBELL CACHED VAL : %d\n"
1465 "RDY IND ADDR : 0x%x\n"
1466 "RDY IND CACHE VAL : %d\n"
1467 "RFIL IND : %d\n"
1468 "NUM PKT INDICAT : %d\n"
1469 "BUF REFIL : %d\n"
1470 "NUM DROP NO SPC : %d\n"
1471 "NUM DROP NO BUF : %d\n"
1472 "IS SUSPND : %d\n"
1473 "RSVD : 0x%x\n",
1474 uc_fw_stat->rx_ind_ring_base,
1475 uc_fw_stat->rx_ind_ring_size,
1476 uc_fw_stat->rx_ind_ring_dbell_addr,
1477 uc_fw_stat->rx_ind_ring_dbell_ind_val,
1478 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
1479 uc_fw_stat->rx_ind_ring_rdidx_addr,
1480 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
1481 uc_fw_stat->rx_refill_idx,
1482 uc_fw_stat->rx_num_pkts_indicated,
1483 uc_fw_stat->rx_buf_refilled,
1484 uc_fw_stat->rx_num_ind_drop_no_space,
1485 uc_fw_stat->rx_num_ind_drop_no_buf,
1486 uc_fw_stat->rx_is_suspend, uc_fw_stat->rx_reserved);
1487 /* STATs from IPA */
1488 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301489 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001490 "==== IPA_UC IPA TX ====\n"
1491 "NUM PROCD : %d\n"
1492 "CE DBELL : 0x%x\n"
1493 "NUM DBELL FIRED : %d\n"
1494 "COMP RNG FULL : %d\n"
1495 "COMP RNG EMPT : %d\n"
1496 "COMP RNG USE HGH : %d\n"
1497 "COMP RNG USE LOW : %d\n"
1498 "BAM FIFO FULL : %d\n"
1499 "BAM FIFO EMPT : %d\n"
1500 "BAM FIFO USE HGH : %d\n"
1501 "BAM FIFO USE LOW : %d\n"
1502 "NUM DBELL : %d\n"
1503 "NUM UNEXP DBELL : %d\n"
1504 "NUM BAM INT HDL : 0x%x\n"
1505 "NUM BAM INT NON-RUN : 0x%x\n"
1506 "NUM QMB INT HDL : 0x%x",
1507 ipa_stat.tx_ch_stats.num_pkts_processed,
1508 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
1509 ipa_stat.tx_ch_stats.num_db_fired,
1510 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
1511 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
1512 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
1513 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
1514 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
1515 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
1516 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
1517 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
1518 ipa_stat.tx_ch_stats.num_db,
1519 ipa_stat.tx_ch_stats.num_unexpected_db,
1520 ipa_stat.tx_ch_stats.num_bam_int_handled,
1521 ipa_stat.tx_ch_stats.
1522 num_bam_int_in_non_runnning_state,
1523 ipa_stat.tx_ch_stats.num_qmb_int_handled);
1524
Anurag Chouhandf2b2682016-02-29 14:15:27 +05301525 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001526 "==== IPA_UC IPA RX ====\n"
1527 "MAX OST PKT : %d\n"
1528 "NUM PKT PRCSD : %d\n"
1529 "RNG RP : 0x%x\n"
1530 "COMP RNG FULL : %d\n"
1531 "COMP RNG EMPT : %d\n"
1532 "COMP RNG USE HGH : %d\n"
1533 "COMP RNG USE LOW : %d\n"
1534 "BAM FIFO FULL : %d\n"
1535 "BAM FIFO EMPT : %d\n"
1536 "BAM FIFO USE HGH : %d\n"
1537 "BAM FIFO USE LOW : %d\n"
1538 "NUM DB : %d\n"
1539 "NUM UNEXP DB : %d\n"
1540 "NUM BAM INT HNDL : 0x%x\n",
1541 ipa_stat.rx_ch_stats.max_outstanding_pkts,
1542 ipa_stat.rx_ch_stats.num_pkts_processed,
1543 ipa_stat.rx_ch_stats.rx_ring_rp_value,
1544 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
1545 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
1546 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
1547 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
1548 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
1549 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
1550 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
1551 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
1552 ipa_stat.rx_ch_stats.num_db,
1553 ipa_stat.rx_ch_stats.num_unexpected_db,
1554 ipa_stat.rx_ch_stats.num_bam_int_handled);
1555 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
1556 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
1557 /* STATs from FW */
1558 uc_fw_stat = (struct ipa_uc_fw_stats *)
1559 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301560 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001561 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
1562 uc_fw_stat->tx_pkts_completed,
1563 hdd_ipa->ipa_p_tx_packets);
1564 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
1565 (uc_fw_stat->rx_num_ind_drop_no_space +
1566 uc_fw_stat->rx_num_ind_drop_no_buf +
1567 uc_fw_stat->rx_num_pkts_indicated),
1568 hdd_ipa->ipa_p_rx_packets);
1569
1570 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
1571 hdd_ipa->ipa_p_rx_packets =
1572 (uc_fw_stat->rx_num_ind_drop_no_space +
1573 uc_fw_stat->rx_num_ind_drop_no_buf +
1574 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301575 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001576 } else {
Yun Park8292dcb2016-10-07 16:46:06 -07001577 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
1578 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001579 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301580 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001581}
1582
1583
1584/**
1585 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
1586 * @adapter: device adapter instance
1587 * @offload_type: MCC or SCC
1588 * @enable: TX offload enable or disable
1589 *
1590 * Return: none
1591 */
1592static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
1593 uint32_t offload_type, uint32_t enable)
1594{
1595 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07001596 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001597
Yun Parka37592b2016-06-11 17:10:28 -07001598 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001599 return;
1600
Yun Park8292dcb2016-10-07 16:46:06 -07001601 iface_context = adapter->ipa_context;
1602
1603 if (!iface_context || (enable == iface_context->offload_enabled)) {
1604 /* IPA offload status is already set as desired */
1605 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001606 "IPA offload status is already set: (offload_type=%d, vdev_id=%d, enable=%d)",
Yun Park8292dcb2016-10-07 16:46:06 -07001607 offload_type, adapter->sessionId, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001608 return;
1609 }
1610
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301611 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 sizeof(ipa_offload_enable_disable));
1613 ipa_offload_enable_disable.offload_type = offload_type;
1614 ipa_offload_enable_disable.vdev_id = adapter->sessionId;
1615 ipa_offload_enable_disable.enable = enable;
1616
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301617 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07001618 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001619 ipa_offload_enable_disable.offload_type,
1620 ipa_offload_enable_disable.vdev_id,
1621 ipa_offload_enable_disable.enable);
1622
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301623 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001624 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
1625 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301626 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08001627 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
1628 __func__,
1629 ipa_offload_enable_disable.offload_type,
1630 ipa_offload_enable_disable.vdev_id,
1631 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07001632 } else {
1633 /* Update the IPA offload status */
1634 iface_context->offload_enabled =
1635 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 }
1637}
1638
1639/**
1640 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1641 * @work: uC OP work
1642 *
1643 * Return: None
1644 */
1645static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
1646{
1647 struct op_msg_type *msg;
1648 struct uc_op_work_struct *uc_op_work = container_of(work,
1649 struct uc_op_work_struct, work);
1650 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1651
1652 cds_ssr_protect(__func__);
1653
1654 msg = uc_op_work->msg;
1655 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301656 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001657 "%s, posted msg %d", __func__, msg->op_code);
1658
1659 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
1660
1661 cds_ssr_unprotect(__func__);
1662
1663 return;
1664}
1665
1666/**
1667 * hdd_ipa_uc_op_event_handler() - Adapter lookup
1668 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
1669 * @op_msg: operation message received from firmware
1670 * @hdd_ctx: Global HDD context
1671 *
1672 * Return: None
1673 */
1674static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
1675{
1676 struct hdd_ipa_priv *hdd_ipa;
1677 struct op_msg_type *msg;
1678 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301679 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001680
1681 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301682 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684
1685 msg = (struct op_msg_type *)op_msg;
1686 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
1687
1688 if (unlikely(!hdd_ipa))
1689 goto end;
1690
1691 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301692 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001693 __func__, msg->op_code);
1694 goto end;
1695 }
1696
1697 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
1698 if (uc_op_work->msg)
1699 /* When the same uC OPCODE is already pended, just return */
1700 goto end;
1701
1702 uc_op_work->msg = msg;
1703 schedule_work(&uc_op_work->work);
1704 return;
1705
1706end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301707 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708}
1709
1710/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08001711 * hdd_ipa_init_uc_op_work - init ipa uc op work
1712 * @work: struct work_struct
1713 * @work_handler: work_handler
1714 *
1715 * Return: none
1716 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08001717static void hdd_ipa_init_uc_op_work(struct work_struct *work,
1718 work_func_t work_handler)
1719{
1720 INIT_WORK(work, work_handler);
1721}
Rajeev Kumar217f2172016-01-06 18:11:55 -08001722
1723
1724/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001725 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
1726 * @hdd_ctx: Global HDD context
1727 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301728 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301730static QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001731{
1732 struct ipa_wdi_in_params pipe_in;
1733 struct ipa_wdi_out_params pipe_out;
1734 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1735 p_cds_contextType cds_ctx = hdd_ctx->pcds_context;
1736 uint8_t i;
1737
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301738 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
1739 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001740
Anurag Chouhanffb21542016-02-17 14:33:03 +05301741 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301742 qdf_mutex_create(&ipa_ctxt->event_lock);
1743 qdf_mutex_create(&ipa_ctxt->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744
1745 /* TX PIPE */
1746 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1747 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
1748 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
1749 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
1750 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
1751 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
1752 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1753 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
1754 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
1755 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
1756 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
1757 pipe_in.sys.notify = hdd_ipa_i2w_cb;
1758 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301759 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001760 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1761 pipe_in.sys.keep_ipa_awake = true;
1762 }
1763
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001764 pipe_in.u.dl.comp_ring_base_pa =
1765 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001766 pipe_in.u.dl.comp_ring_size =
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001767 ipa_ctxt->ipa_resource.tx_comp_ring_size *
1768 sizeof(qdf_dma_addr_t);
1769 pipe_in.u.dl.ce_ring_base_pa =
1770 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
1771 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
1772 pipe_in.u.dl.ce_ring_size =
1773 ipa_ctxt->ipa_resource.ce_sr_ring_size;
1774 pipe_in.u.dl.num_tx_buffers =
1775 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001776
1777 /* Connect WDI IPA PIPE */
1778 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
1779 /* Micro Controller Doorbell register */
Govind Singh0487bf22016-08-24 23:08:57 +05301780 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
1781 "%s CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
1782 __func__, (unsigned int)pipe_out.uc_door_bell_pa,
1783 ipa_ctxt->tx_pipe_handle);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001784 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001785 /* WLAN TX PIPE Handle */
1786 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301787 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001788 "TX : CRBPA 0x%x, CRS %d, CERBPA 0x%x, CEDPA 0x%x,"
1789 " CERZ %d, NB %d, CDBPAD 0x%x",
1790 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
1791 pipe_in.u.dl.comp_ring_size,
1792 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
1793 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
1794 pipe_in.u.dl.ce_ring_size,
1795 pipe_in.u.dl.num_tx_buffers,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001796 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797
1798 /* RX PIPE */
1799 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
1800 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
1801 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
1802 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
1803 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
1804 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
1805 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
1806 sizeof(struct sps_iovec);
1807 pipe_in.sys.notify = hdd_ipa_w2i_cb;
1808 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301809 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001810 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
1811 pipe_in.sys.keep_ipa_awake = true;
1812 }
1813
Dhanashri Atreb08959a2016-03-01 17:28:03 -08001814 pipe_in.u.ul.rdy_ring_base_pa =
1815 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
1816 pipe_in.u.ul.rdy_ring_size =
1817 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
1818 pipe_in.u.ul.rdy_ring_rp_pa =
1819 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08001820 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821 ipa_connect_wdi_pipe(&pipe_in, &pipe_out);
Leo Chang3bc8fed2015-11-13 10:59:47 -08001822 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001823 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301824 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001825 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
1826 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
1827 pipe_in.u.ul.rdy_ring_size,
1828 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001829 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001830
1831 ol_txrx_ipa_uc_set_doorbell_paddr(cds_ctx->pdev_txrx_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08001832 ipa_ctxt->tx_comp_doorbell_paddr,
1833 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834
1835 ol_txrx_ipa_uc_register_op_cb(cds_ctx->pdev_txrx_ctx,
1836 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
1837
1838 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08001839 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840 hdd_ipa_uc_fw_op_event_handler);
1841 ipa_ctxt->uc_op_work[i].msg = NULL;
1842 }
1843
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301844 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845}
1846
Leo Change3e49442015-10-26 20:07:13 -07001847/**
1848 * hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
1849 * @hdd_ctx: hdd main context
1850 *
1851 * Force shutdown IPA pipe
1852 * Independent of FW pipe status, IPA pipe shutdonw progress
1853 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
1854 * independent from FW pipe status
1855 *
1856 * Return: NONE
1857 */
1858void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
1859{
1860 struct hdd_ipa_priv *hdd_ipa;
1861
1862 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
1863 return;
1864
1865 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1866 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301867 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07001868 "IPA pipes are not down yet, force shutdown");
1869 hdd_ipa_uc_disable_pipes(hdd_ipa);
1870 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301871 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07001872 "IPA pipes are down, do nothing");
1873 }
1874
1875 return;
1876}
1877
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878/**
Govind Singh9c58eba2016-09-02 16:23:06 +05301879 * hdd_ipa_msg_free_fn() - Free an IPA message
1880 * @buff: pointer to the IPA message
1881 * @len: length of the IPA message
1882 * @type: type of IPA message
1883 *
1884 * Return: None
1885 */
1886static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
1887{
1888 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "msg type:%d, len:%d", type, len);
1889 ghdd_ipa->stats.num_free_msg++;
1890 qdf_mem_free(buff);
1891}
1892
1893
1894/**
1895 * hdd_ipa_send_disconnect() - ipa send disconnect clients
1896 * adapter: pointer to hdd adapter
1897 * Send disconnect evnt to IPA driver during SSR
1898 *
1899 * Return: 0 - Success
1900 */
1901static int hdd_ipa_send_disconnect(hdd_adapter_t *adapter)
1902{
1903 struct ipa_msg_meta meta;
1904 struct ipa_wlan_msg *msg;
1905 int ret = 0;
1906 int i;
1907
1908 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
1909 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
1910 continue;
1911 if ((adapter->aStaInfo[i].isUsed) &&
1912 (!adapter->aStaInfo[i].isDeauthInProgress)) {
1913 meta.msg_len = sizeof(struct ipa_wlan_msg);
1914 msg = qdf_mem_malloc(meta.msg_len);
1915 if (msg == NULL) {
1916 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1917 "msg allocation failed");
1918 return -ENOMEM;
1919 }
1920 meta.msg_type = WLAN_CLIENT_DISCONNECT;
1921 strlcpy(msg->name, adapter->dev->name,
1922 IPA_RESOURCE_NAME_MAX);
1923 memcpy(msg->mac_addr, adapter->aStaInfo[i].macAddrSTA.bytes,
1924 ETH_ALEN);
1925 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
1926 msg->name, meta.msg_type);
1927 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
1928 if (ret) {
1929 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
1930 "%s: Evt: %d fail:%d",
1931 msg->name, meta.msg_type, ret);
1932 qdf_mem_free(msg);
1933 return ret;
1934 }
1935 }
1936 }
1937
1938 return ret;
1939}
1940
1941/**
1942 * hdd_ipa_uc_disconnect_client() - disconnect ipa sap clients
1943 * hdd_ctx: pointer to hdd context
1944 * Send disconnect evnt to IPA driver during SSR
1945 *
1946 * Return: 0 - Success
1947 */
1948static int hdd_ipa_uc_disconnect_client(hdd_context_t *hdd_ctx)
1949{
1950 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
1951 QDF_STATUS status;
1952 hdd_adapter_t *adapter;
1953 int ret = 0;
1954
1955
1956 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
1957 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
1958 adapter = adapter_node->pAdapter;
1959 if (adapter->device_mode == QDF_SAP_MODE)
1960 hdd_ipa_send_disconnect(adapter);
1961 status = hdd_get_next_adapter(
1962 hdd_ctx, adapter_node, &next);
1963 adapter_node = next;
1964 }
1965
1966 return ret;
1967}
1968
1969/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001970 * hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
1971 *
1972 * Deinit basic IPA UC host side to be in sync reloaded FW during
1973 * SSR
1974 *
1975 * Return: 0 - Success
1976 */
1977int hdd_ipa_uc_ssr_deinit(void)
1978{
1979 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
1980 int idx;
1981 struct hdd_ipa_iface_context *iface_context;
1982
Leo Chang3bc8fed2015-11-13 10:59:47 -08001983 if ((!hdd_ipa) || (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001984 return 0;
1985
Govind Singh9c58eba2016-09-02 16:23:06 +05301986 /* send disconnect to ipa driver for connected clients */
1987 hdd_ipa_uc_disconnect_client(hdd_ipa->hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001988 /* Clean up HDD IPA interfaces */
1989 for (idx = 0; (hdd_ipa->num_iface > 0) &&
1990 (idx < HDD_IPA_MAX_IFACE); idx++) {
1991 iface_context = &hdd_ipa->iface_context[idx];
1992 if (iface_context && iface_context->adapter)
1993 hdd_ipa_cleanup_iface(iface_context);
1994 }
1995
1996 /* After SSR, wlan driver reloads FW again. But we need to protect
1997 * IPA submodule during SSR transient state. So deinit basic IPA
1998 * UC host side to be in sync with reloaded FW during SSR
1999 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08002000 if (!hdd_ipa->ipa_pipes_down)
2001 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002002
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302003 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002004 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
2005 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
2006 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
2007 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302008 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009
2010 /* Full IPA driver cleanup not required since wlan driver is now
2011 * unloaded and reloaded after SSR.
2012 */
2013 return 0;
2014}
2015
2016/**
2017 * hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
2018 *
2019 * Init basic IPA UC host side to be in sync with reloaded FW after
2020 * SSR to resume IPA UC operations
2021 *
2022 * Return: 0 - Success
2023 */
2024int hdd_ipa_uc_ssr_reinit(void)
2025{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002026
2027 /* After SSR is complete, IPA UC can resume operation. But now wlan
2028 * driver will be unloaded and reloaded, which takes care of IPA cleanup
2029 * and initialization. This is a placeholder func if IPA has to resume
2030 * operations without driver reload.
2031 */
2032 return 0;
2033}
Leo Chang3bc8fed2015-11-13 10:59:47 -08002034
2035/**
2036 * hdd_ipa_tx_packet_ipa() - send packet to IPA
2037 * @hdd_ctx: Global HDD context
2038 * @skb: skb sent to IPA
2039 * @session_id: send packet instance session id
2040 *
2041 * Send TX packet which generated by system to IPA.
2042 * This routine only will be used for function verification
2043 *
2044 * Return: NULL packet sent to IPA properly
2045 * NULL invalid packet drop
2046 * skb packet not sent to IPA. legacy data path should handle
2047 */
2048struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
2049 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07002050{
Leo Chang3bc8fed2015-11-13 10:59:47 -08002051 struct ipa_header *ipa_header;
2052 struct frag_header *frag_header;
Leo Chang07b28f62016-05-11 12:29:22 -07002053 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002054
2055 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2056 return skb;
2057
Leo Chang07b28f62016-05-11 12:29:22 -07002058 if (!hdd_ipa)
2059 return skb;
2060
2061 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
2062 return skb;
2063
Leo Changcc923e22016-06-16 15:29:03 -07002064 if (skb_headroom(skb) <
2065 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07002066 return skb;
2067
Leo Chang3bc8fed2015-11-13 10:59:47 -08002068 ipa_header = (struct ipa_header *) skb_push(skb,
2069 sizeof(struct ipa_header));
2070 if (!ipa_header) {
2071 /* No headroom, legacy */
2072 return skb;
2073 }
2074 memset(ipa_header, 0, sizeof(*ipa_header));
2075 ipa_header->vdev_id = 0;
2076
2077 frag_header = (struct frag_header *) skb_push(skb,
2078 sizeof(struct frag_header));
2079 if (!frag_header) {
2080 /* No headroom, drop */
2081 kfree_skb(skb);
2082 return NULL;
2083 }
2084 memset(frag_header, 0, sizeof(*frag_header));
2085 frag_header->length = skb->len - sizeof(struct frag_header)
2086 - sizeof(struct ipa_header);
2087
2088 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
2089 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07002090}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002091
2092/**
2093 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
2094 * @work: scheduled work
2095 *
2096 * When IPA resources are released in hdd_ipa_rm_try_release() we do
2097 * not want to immediately release the wake lock since the system
2098 * would then potentially try to suspend when there is a healthy data
2099 * rate. Deferred work is scheduled and this function handles the
2100 * work. When this function is called, if the IPA resource is still
2101 * released then we release the wake lock.
2102 *
2103 * Return: None
2104 */
2105static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
2106{
2107 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
2108 struct hdd_ipa_priv,
2109 wake_lock_work);
2110
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302111 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002112
2113 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
2114 goto end;
2115
2116 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302117 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002118 WIFI_POWER_EVENT_WAKELOCK_IPA);
2119
2120end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302121 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002122}
2123
2124/**
2125 * hdd_ipa_rm_request() - Request resource from IPA
2126 * @hdd_ipa: Global HDD IPA context
2127 *
2128 * Return: 0 on success, negative errno on error
2129 */
2130static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
2131{
2132 int ret = 0;
2133
2134 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2135 return 0;
2136
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302137 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138
2139 switch (hdd_ipa->rm_state) {
2140 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302141 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002142 return 0;
2143 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302144 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002145 return -EINPROGRESS;
2146 case HDD_IPA_RM_RELEASED:
2147 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
2148 break;
2149 }
2150
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302151 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152
2153 ret = ipa_rm_inactivity_timer_request_resource(
2154 IPA_RM_RESOURCE_WLAN_PROD);
2155
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302156 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002157 if (ret == 0) {
2158 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2159 hdd_ipa->stats.num_rm_grant_imm++;
2160 }
2161
2162 cancel_delayed_work(&hdd_ipa->wake_lock_work);
2163 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302164 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002165 WIFI_POWER_EVENT_WAKELOCK_IPA);
2166 hdd_ipa->wake_lock_released = false;
2167 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302168 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002169
2170 return ret;
2171}
2172
2173/**
2174 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
2175 * @hdd_ipa: Global HDD IPA context
2176 *
2177 * Return: 0 if resources released, negative errno otherwise
2178 */
2179static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
2180{
2181 int ret = 0;
2182
2183 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2184 return 0;
2185
2186 if (atomic_read(&hdd_ipa->tx_ref_cnt))
2187 return -EAGAIN;
2188
2189 spin_lock_bh(&hdd_ipa->q_lock);
2190 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
2191 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
2192 spin_unlock_bh(&hdd_ipa->q_lock);
2193 return -EAGAIN;
2194 }
2195 spin_unlock_bh(&hdd_ipa->q_lock);
2196
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302197 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002198
Nirav Shahcbc6d722016-03-01 16:24:53 +05302199 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302200 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002201 return -EAGAIN;
2202 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302203 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002204
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302205 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002206 switch (hdd_ipa->rm_state) {
2207 case HDD_IPA_RM_GRANTED:
2208 break;
2209 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302210 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002211 return -EINPROGRESS;
2212 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302213 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002214 return 0;
2215 }
2216
2217 /* IPA driver returns immediately so set the state here to avoid any
2218 * race condition.
2219 */
2220 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2221 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302222 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002223
2224 ret =
2225 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
2226
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302227 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002228 if (unlikely(ret != 0)) {
2229 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
2230 WARN_ON(1);
2231 }
2232
2233 /*
2234 * If wake_lock is released immediately, kernel would try to suspend
2235 * immediately as well, Just avoid ping-pong between suspend-resume
2236 * while there is healthy amount of data transfer going on by
2237 * releasing the wake_lock after some delay.
2238 */
2239 schedule_delayed_work(&hdd_ipa->wake_lock_work,
2240 msecs_to_jiffies
2241 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
2242
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302243 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002244
2245 return ret;
2246}
2247
2248/**
2249 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
2250 * @user_data: user data registered with IPA
2251 * @event: the IPA resource manager event that occurred
2252 * @data: the data associated with the event
2253 *
2254 * Return: None
2255 */
2256static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
2257 unsigned long data)
2258{
2259 struct hdd_ipa_priv *hdd_ipa = user_data;
2260
2261 if (unlikely(!hdd_ipa))
2262 return;
2263
2264 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2265 return;
2266
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302267 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002268
2269 switch (event) {
2270 case IPA_RM_RESOURCE_GRANTED:
2271 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2272 /* RM Notification comes with ISR context
2273 * it should be serialized into work queue to avoid
2274 * ISR sleep problem
2275 */
2276 hdd_ipa->uc_rm_work.event = event;
2277 schedule_work(&hdd_ipa->uc_rm_work.work);
2278 break;
2279 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302280 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002281 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302282 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002283 hdd_ipa->stats.num_rm_grant++;
2284 break;
2285
2286 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302287 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002288 hdd_ipa->resource_unloading = false;
2289 break;
2290
2291 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302292 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002293 break;
2294 }
2295}
2296
2297/**
2298 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
2299 *
2300 * Callback function registered with IPA that is called when IPA wants
2301 * to release the WLAN consumer resource
2302 *
2303 * Return: 0 if the request is granted, negative errno otherwise
2304 */
2305static int hdd_ipa_rm_cons_release(void)
2306{
2307 return 0;
2308}
2309
2310/**
2311 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
2312 *
2313 * Callback function registered with IPA that is called when IPA wants
2314 * to access the WLAN consumer resource
2315 *
2316 * Return: 0 if the request is granted, negative errno otherwise
2317 */
2318static int hdd_ipa_rm_cons_request(void)
2319{
Yun Park4d8b60a2015-10-22 13:59:32 -07002320 int ret = 0;
2321
2322 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302323 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002324 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002325 __func__);
2326 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07002327 ret = -EINPROGRESS;
2328 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302329 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07002330 "%s: IPA resource unloading in progress",
2331 __func__);
2332 ghdd_ipa->pending_cons_req = true;
2333 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002334 }
Yun Park4d8b60a2015-10-22 13:59:32 -07002335
2336 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002337}
2338
2339/**
2340 * hdd_ipa_set_perf_level() - Set IPA performance level
2341 * @hdd_ctx: Global HDD context
2342 * @tx_packets: Number of packets transmitted in the last sample period
2343 * @rx_packets: Number of packets received in the last sample period
2344 *
2345 * Return: 0 on success, negative errno on error
2346 */
2347int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
2348 uint64_t rx_packets)
2349{
2350 uint32_t next_cons_bw, next_prod_bw;
2351 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2352 struct ipa_rm_perf_profile profile;
2353 int ret;
2354
2355 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
2356 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
2357 return 0;
2358
2359 memset(&profile, 0, sizeof(profile));
2360
2361 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2362 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2363 else if (tx_packets >
2364 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2365 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2366 else
2367 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2368
2369 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
2370 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
2371 else if (rx_packets >
2372 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
2373 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
2374 else
2375 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
2376
Yun Park8f289c82016-10-18 16:38:21 -07002377 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002378 "CONS perf curr: %d, next: %d",
2379 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Park8f289c82016-10-18 16:38:21 -07002380 HDD_IPA_LOG(LOGOFF,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002381 "PROD perf curr: %d, next: %d",
2382 hdd_ipa->curr_prod_bw, next_prod_bw);
2383
2384 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302385 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002386 "Requesting CONS perf curr: %d, next: %d",
2387 hdd_ipa->curr_cons_bw, next_cons_bw);
2388 profile.max_supported_bandwidth_mbps = next_cons_bw;
2389 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
2390 &profile);
2391 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302392 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002393 "RM CONS set perf profile failed: %d", ret);
2394
2395 return ret;
2396 }
2397 hdd_ipa->curr_cons_bw = next_cons_bw;
2398 hdd_ipa->stats.num_cons_perf_req++;
2399 }
2400
2401 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302402 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002403 "Requesting PROD perf curr: %d, next: %d",
2404 hdd_ipa->curr_prod_bw, next_prod_bw);
2405 profile.max_supported_bandwidth_mbps = next_prod_bw;
2406 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
2407 &profile);
2408 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302409 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002410 "RM PROD set perf profile failed: %d", ret);
2411 return ret;
2412 }
2413 hdd_ipa->curr_prod_bw = next_prod_bw;
2414 hdd_ipa->stats.num_prod_perf_req++;
2415 }
2416
2417 return 0;
2418}
2419
2420/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002421 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
2422 * @work: struct work_struct
2423 * @work_handler: work_handler
2424 *
2425 * Return: none
2426 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002427static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
2428 work_func_t work_handler)
2429{
2430 INIT_WORK(work, work_handler);
2431}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002432
2433/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002434 * hdd_ipa_setup_rm() - Setup IPA resource management
2435 * @hdd_ipa: Global HDD IPA context
2436 *
2437 * Return: 0 on success, negative errno on error
2438 */
2439static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
2440{
2441 struct ipa_rm_create_params create_params = { 0 };
2442 int ret;
2443
2444 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2445 return 0;
2446
Rajeev Kumar217f2172016-01-06 18:11:55 -08002447 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
2448 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002449 memset(&create_params, 0, sizeof(create_params));
2450 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
2451 create_params.reg_params.user_data = hdd_ipa;
2452 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
2453 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2454
2455 ret = ipa_rm_create_resource(&create_params);
2456 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302457 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002458 "Create RM resource failed: %d", ret);
2459 goto setup_rm_fail;
2460 }
2461
2462 memset(&create_params, 0, sizeof(create_params));
2463 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
2464 create_params.request_resource = hdd_ipa_rm_cons_request;
2465 create_params.release_resource = hdd_ipa_rm_cons_release;
2466 create_params.floor_voltage = IPA_VOLTAGE_SVS;
2467
2468 ret = ipa_rm_create_resource(&create_params);
2469 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302470 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002471 "Create RM CONS resource failed: %d", ret);
2472 goto delete_prod;
2473 }
2474
2475 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
2476 IPA_RM_RESOURCE_APPS_CONS);
2477
2478 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
2479 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
2480 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302481 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002482 ret);
2483 goto timer_init_failed;
2484 }
2485
2486 /* Set the lowest bandwidth to start with */
2487 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
2488
2489 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302490 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491 "Set perf level failed: %d", ret);
2492 goto set_perf_failed;
2493 }
2494
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302495 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002496 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
2497 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302498 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002499 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
2500 hdd_ipa->wake_lock_released = true;
2501 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
2502
2503 return ret;
2504
2505set_perf_failed:
2506 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2507
2508timer_init_failed:
2509 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2510
2511delete_prod:
2512 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2513
2514setup_rm_fail:
2515 return ret;
2516}
2517
2518/**
2519 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
2520 * @hdd_ipa: Global HDD IPA context
2521 *
2522 * Destroys all resources associated with the IPA resource manager
2523 *
2524 * Return: None
2525 */
2526static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
2527{
2528 int ret;
2529
2530 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2531 return;
2532
2533 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302534 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002535
2536#ifdef WLAN_OPEN_SOURCE
2537 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
2538#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302539 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002540
2541 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
2542
2543 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
2544 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302545 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002546 "RM PROD resource delete failed %d", ret);
2547
2548 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
2549 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302550 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002551 "RM CONS resource delete failed %d", ret);
2552}
2553
2554/**
2555 * hdd_ipa_send_skb_to_network() - Send skb to kernel
2556 * @skb: network buffer
2557 * @adapter: network adapter
2558 *
2559 * Called when a network buffer is received which should not be routed
2560 * to the IPA module.
2561 *
2562 * Return: None
2563 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302564static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002565 hdd_adapter_t *adapter)
2566{
2567 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2568 unsigned int cpu_index;
2569
2570 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302571 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002572 adapter);
2573 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002574 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002575 return;
2576 }
2577
Prashanth Bhatta9e143052015-12-04 11:56:47 -08002578 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002579 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002580 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002581 return;
2582 }
2583
2584 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
2585 skb->dev = adapter->dev;
2586 skb->protocol = eth_type_trans(skb, skb->dev);
2587 skb->ip_summed = CHECKSUM_NONE;
2588
2589 cpu_index = wlan_hdd_get_cpu();
2590
2591 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
2592 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
2593 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
2594 else
2595 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
2596
2597 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
2598 adapter->dev->last_rx = jiffies;
2599}
2600
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002601/**
Leo Chang69c39692016-10-12 20:11:12 -07002602 * hdd_ipa_forward() - handle packet forwarding to wlan tx
2603 * @hdd_ipa: pointer to hdd ipa context
2604 * @adapter: network adapter
2605 * @skb: data pointer
2606 *
2607 * if exception packet has set forward bit, copied new packet should be
2608 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
2609 * put into pm queue and tx procedure will be differed
2610 *
2611 * Return: None
2612 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07002613static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
2614 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07002615{
2616 qdf_nbuf_t copy;
2617 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
2618
2619 copy = qdf_nbuf_copy(skb);
2620 if (!copy) {
2621 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "copy packet alloc fail");
2622 return;
2623 }
2624
2625 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2626 /* WLAN subsystem is in suspend, put int queue */
2627 if (hdd_ipa->suspended) {
2628 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2629 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2630 "TX in SUSPEND PUT QUEUE");
2631 qdf_mem_set(copy->cb, sizeof(copy->cb), 0);
2632 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)copy->cb;
2633 pm_tx_cb->exception = true;
2634 pm_tx_cb->adapter = adapter;
2635 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
2636 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, copy);
2637 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2638 hdd_ipa->stats.num_tx_queued++;
2639 } else {
2640 /* Resume, put packet into WLAN TX */
2641 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
2642 if (hdd_softap_hard_start_xmit(copy, adapter->dev)) {
2643 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2644 "packet tx fail");
2645 } else {
2646 hdd_ipa->stats.num_tx_bcmc++;
2647 hdd_ipa->ipa_tx_forward++;
2648 }
2649 }
2650}
2651
2652/**
2653 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002654 * @priv: pointer to private data registered with IPA (we register a
2655 * pointer to the global IPA context)
2656 * @evt: the IPA event which triggered the callback
2657 * @data: data associated with the event
2658 *
2659 * Return: None
2660 */
Yun Parkf8d6a122016-10-11 15:49:43 -07002661static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002662 unsigned long data)
2663{
2664 struct hdd_ipa_priv *hdd_ipa = NULL;
2665 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302666 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002667 uint8_t iface_id;
2668 uint8_t session_id;
2669 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002670 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07002671 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002672
2673 hdd_ipa = (struct hdd_ipa_priv *)priv;
2674
2675 switch (evt) {
2676 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05302677 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07002678
2679 /*
2680 * When SSR is going on or driver is unloading,
2681 * just drop the packets.
2682 */
2683 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
2684 if (0 != status) {
2685 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2686 "Invalid context: drop packet");
2687 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2688 kfree_skb(skb);
2689 return;
2690 }
2691
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002692 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2693 session_id = (uint8_t)skb->cb[0];
2694 iface_id = vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05302695 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002696 "IPA_RECEIVE: session_id=%u, iface_id=%u",
2697 session_id, iface_id);
2698 } else {
2699 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
2700 }
2701
2702 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302703 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002704 "IPA_RECEIVE: Invalid iface_id: %u",
2705 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302706 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707 "w2i -- skb", skb->data, 8);
2708 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07002709 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002710 return;
2711 }
2712
2713 iface_context = &hdd_ipa->iface_context[iface_id];
2714 adapter = iface_context->adapter;
2715
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302716 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002717 "w2i -- skb", skb->data, 8);
2718 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
2719 hdd_ipa->stats.num_rx_excep++;
2720 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
2721 } else {
2722 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
2723 }
2724
2725 iface_context->stats.num_rx_ipa_excep++;
2726
2727 /* Disable to forward Intra-BSS Rx packets when
2728 * ap_isolate=1 in hostapd.conf
2729 */
Yun Park046101c2016-09-02 15:32:14 -07002730 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002731 /*
2732 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
2733 * all Rx packets to IPA uC, which need to be forwarded
2734 * to other interface.
2735 * And, IPA driver will send back to WLAN host driver
2736 * through exception pipe with fw_desc field set by FW.
2737 * Here we are checking fw_desc field for FORWARD bit
2738 * set, and forward to Tx. Then copy to kernel stack
2739 * only when DISCARD bit is not set.
2740 */
2741 fw_desc = (uint8_t)skb->cb[1];
Leo Chang3bc8fed2015-11-13 10:59:47 -08002742 if (fw_desc & HDD_IPA_FW_RX_DESC_FORWARD_M) {
Govind Singhb6a89772016-08-12 11:23:35 +05302743 HDD_IPA_DP_LOG(
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302744 QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002745 "Forward packet to Tx (fw_desc=%d)",
2746 fw_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002747 hdd_ipa_forward(hdd_ipa, adapter, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002748 }
Leo Chang3bc8fed2015-11-13 10:59:47 -08002749 if (fw_desc & HDD_IPA_FW_RX_DESC_DISCARD_M) {
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002750 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
2751 hdd_ipa->ipa_rx_discard++;
Yun Parkf8d6a122016-10-11 15:49:43 -07002752 kfree_skb(skb);
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08002753 break;
2754 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002755 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302756 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002757 "Intra-BSS FWD is disabled-skip forward to Tx");
2758 }
2759
2760 hdd_ipa_send_skb_to_network(skb, adapter);
2761 break;
2762
2763 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302764 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002765 "w2i cb wrong event: 0x%x", evt);
2766 return;
2767 }
2768}
2769
2770/**
Yun Parkf8d6a122016-10-11 15:49:43 -07002771 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
2772 * @priv: pointer to private data registered with IPA (we register a
2773 * pointer to the global IPA context)
2774 * @evt: the IPA event which triggered the callback
2775 * @data: data associated with the event
2776 *
2777 * Return: None
2778 */
2779static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
2780 unsigned long data)
2781{
2782 cds_ssr_protect(__func__);
2783 __hdd_ipa_w2i_cb(priv, evt, data);
2784 cds_ssr_unprotect(__func__);
2785}
2786
2787/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788 * hdd_ipa_nbuf_cb() - IPA TX complete callback
2789 * @skb: packet buffer which was transmitted
2790 *
2791 * Return: None
2792 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302793void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002794{
2795 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2796
Govind Singhb6a89772016-08-12 11:23:35 +05302797 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05302798 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002799 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302800 ipa_free_skb((struct ipa_rx_data *)
2801 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002802
2803 hdd_ipa->stats.num_tx_comp_cnt++;
2804
2805 atomic_dec(&hdd_ipa->tx_ref_cnt);
2806
2807 hdd_ipa_rm_try_release(hdd_ipa);
2808}
2809
2810/**
2811 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
2812 * @iface_context: interface-specific IPA context
2813 * @ipa_tx_desc: packet data descriptor
2814 *
2815 * Return: None
2816 */
2817static void hdd_ipa_send_pkt_to_tl(
2818 struct hdd_ipa_iface_context *iface_context,
2819 struct ipa_rx_data *ipa_tx_desc)
2820{
2821 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
2822 uint8_t interface_id;
2823 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302824 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002825
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302826 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827 adapter = iface_context->adapter;
2828 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302829 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830 ipa_free_skb(ipa_tx_desc);
2831 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302832 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002833 hdd_ipa_rm_try_release(hdd_ipa);
2834 return;
2835 }
2836
2837 /*
2838 * During CAC period, data packets shouldn't be sent over the air so
2839 * drop all the packets here
2840 */
2841 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
2842 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302843 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002844 iface_context->stats.num_tx_cac_drop++;
2845 hdd_ipa_rm_try_release(hdd_ipa);
2846 return;
2847 }
2848
2849 interface_id = adapter->sessionId;
2850 ++adapter->stats.tx_packets;
2851
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302852 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002853
2854 skb = ipa_tx_desc->skb;
2855
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302856 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302857 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002858 /* FIXME: This is broken. No such field in cb any more:
2859 NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb; */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002860 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302861 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002862 ipa_tx_desc->dma_addr
2863 + HDD_IPA_WLAN_FRAG_HEADER
2864 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002865 ipa_tx_desc->skb->len -=
2866 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
2867 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05302868 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869
Houston Hoffman43d47fa2016-02-24 16:34:30 -08002870 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05302871 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002872
2873 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
2874
2875 skb = ol_tx_send_ipa_data_frame(iface_context->tl_context,
2876 ipa_tx_desc->skb);
2877 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302878 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002879 ipa_free_skb(ipa_tx_desc);
2880 iface_context->stats.num_tx_err++;
2881 hdd_ipa_rm_try_release(hdd_ipa);
2882 return;
2883 }
2884
2885 atomic_inc(&hdd_ipa->tx_ref_cnt);
2886
2887 iface_context->stats.num_tx++;
2888
2889}
2890
2891/**
Leo Chang11545d62016-10-17 14:53:50 -07002892 * hdd_ipa_is_present() - get IPA hw status
2893 * @hdd_ctx: pointer to hdd context
2894 *
2895 * ipa_uc_reg_rdyCB is not directly designed to check
2896 * ipa hw status. This is an undocumented function which
2897 * has confirmed with IPA team.
2898 *
2899 * Return: true - ipa hw present
2900 * false - ipa hw not present
2901 */
2902bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
2903{
2904 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07002905 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07002906 return true;
2907 else
2908 return false;
2909}
2910
2911/**
Leo Chang69c39692016-10-12 20:11:12 -07002912 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002913 * @work: pointer to the scheduled work
2914 *
2915 * Called during PM resume to send packets to TL which were queued
2916 * while host was in the process of suspending.
2917 *
2918 * Return: None
2919 */
Leo Chang69c39692016-10-12 20:11:12 -07002920static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002921{
2922 struct hdd_ipa_priv *hdd_ipa = container_of(work,
2923 struct hdd_ipa_priv,
2924 pm_work);
2925 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302926 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002927 uint32_t dequeued = 0;
2928
Leo Chang69c39692016-10-12 20:11:12 -07002929 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
2930 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302931 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05302932 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
2933 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302934 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935
2936 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002937 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07002938 if (pm_tx_cb->exception) {
2939 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2940 "FLUSH EXCEPTION");
2941 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
2942 } else {
2943 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07002945 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302946 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002947 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302948 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07002949 qdf_wake_lock_release(&hdd_ipa->wake_lock,
2950 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002951
2952 hdd_ipa->stats.num_tx_dequeued += dequeued;
2953 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
2954 hdd_ipa->stats.num_max_pm_queue = dequeued;
2955}
2956
2957/**
2958 * hdd_ipa_i2w_cb() - IPA to WLAN callback
2959 * @priv: pointer to private data registered with IPA (we register a
2960 * pointer to the interface-specific IPA context)
2961 * @evt: the IPA event which triggered the callback
2962 * @data: data associated with the event
2963 *
2964 * Return: None
2965 */
2966static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
2967 unsigned long data)
2968{
2969 struct hdd_ipa_priv *hdd_ipa = NULL;
2970 struct ipa_rx_data *ipa_tx_desc;
2971 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05302972 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002973 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302974 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002975
Mukul Sharma81661ae2015-10-30 20:26:02 +05302976 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002977 if (evt != IPA_RECEIVE) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05302978 skb = (qdf_nbuf_t) data;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002979 dev_kfree_skb_any(skb);
2980 iface_context->stats.num_tx_drop++;
2981 return;
2982 }
2983
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002984 ipa_tx_desc = (struct ipa_rx_data *)data;
2985
2986 hdd_ipa = iface_context->hdd_ipa;
2987
2988 /*
2989 * When SSR is going on or driver is unloading, just drop the packets.
2990 * During SSR, there is no use in queueing the packets as STA has to
2991 * connect back any way
2992 */
2993 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302994 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002995 ipa_free_skb(ipa_tx_desc);
2996 iface_context->stats.num_tx_drop++;
2997 return;
2998 }
2999
3000 skb = ipa_tx_desc->skb;
3001
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303002 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "i2w", skb->data, 8);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003003
3004 /*
3005 * If PROD resource is not requested here then there may be cases where
3006 * IPA hardware may be clocked down because of not having proper
3007 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
3008 * workaround to request PROD resource while data is going over CONS
3009 * pipe to prevent the IPA hardware clockdown.
3010 */
3011 hdd_ipa_rm_request(hdd_ipa);
3012
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303013 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003014 /*
3015 * If host is still suspended then queue the packets and these will be
3016 * drained later when resume completes. When packet is arrived here and
3017 * host is suspended, this means that there is already resume is in
3018 * progress.
3019 */
3020 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303021 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003022 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
3023 pm_tx_cb->iface_context = iface_context;
3024 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303025 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003026 hdd_ipa->stats.num_tx_queued++;
3027
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303028 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003029 return;
3030 }
3031
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303032 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003033
3034 /*
3035 * If we are here means, host is not suspended, wait for the work queue
3036 * to finish.
3037 */
3038#ifdef WLAN_OPEN_SOURCE
3039 flush_work(&hdd_ipa->pm_work);
3040#endif
3041
3042 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
3043}
3044
3045/**
3046 * hdd_ipa_suspend() - Suspend IPA
3047 * @hdd_ctx: Global HDD context
3048 *
3049 * Return: 0 on success, negativer errno on error
3050 */
3051int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
3052{
3053 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3054
3055 if (!hdd_ipa_is_enabled(hdd_ctx))
3056 return 0;
3057
3058 /*
3059 * Check if IPA is ready for suspend, If we are here means, there is
3060 * high chance that suspend would go through but just to avoid any race
3061 * condition after suspend started, these checks are conducted before
3062 * allowing to suspend.
3063 */
3064 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3065 return -EAGAIN;
3066
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303067 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003068
3069 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303070 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003071 return -EAGAIN;
3072 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303073 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003074
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303075 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003076 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303077 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003078
3079 return 0;
3080}
3081
3082/**
3083 * hdd_ipa_resume() - Resume IPA following suspend
3084 * hdd_ctx: Global HDD context
3085 *
3086 * Return: 0 on success, negative errno on error
3087 */
3088int hdd_ipa_resume(hdd_context_t *hdd_ctx)
3089{
3090 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3091
3092 if (!hdd_ipa_is_enabled(hdd_ctx))
3093 return 0;
3094
3095 schedule_work(&hdd_ipa->pm_work);
3096
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303097 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003098 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303099 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003100
3101 return 0;
3102}
3103
3104/**
3105 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
3106 * @hdd_ipa: Global HDD IPA context
3107 *
3108 * Return: 0 on success, negative errno on error
3109 */
3110static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3111{
3112 int i, ret = 0;
3113 struct ipa_sys_connect_params *ipa;
3114 uint32_t desc_fifo_sz;
3115
3116 /* The maximum number of descriptors that can be provided to a BAM at
3117 * once is one less than the total number of descriptors that the buffer
3118 * can contain.
3119 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
3120 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
3121 * be provided at once.
3122 * Because of above requirement, one extra descriptor will be added to
3123 * make sure hardware always has one descriptor.
3124 */
3125 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
3126 + sizeof(struct sps_iovec);
3127
3128 /*setup TX pipes */
3129 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3130 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
3131
3132 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
3133 ipa->desc_fifo_sz = desc_fifo_sz;
3134 ipa->priv = &hdd_ipa->iface_context[i];
3135 ipa->notify = hdd_ipa_i2w_cb;
3136
3137 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3138 ipa->ipa_ep_cfg.hdr.hdr_len =
3139 HDD_IPA_UC_WLAN_TX_HDR_LEN;
3140 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3141 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
3142 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
3143 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
3144 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
3145 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
3146 } else {
3147 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3148 }
3149 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3150
3151 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3152 ipa->keep_ipa_awake = 1;
3153
3154 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3155 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303156 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157 " ret: %d", i, ret);
3158 goto setup_sys_pipe_fail;
3159 }
3160 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
3161 }
3162
3163 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
3164 /*
3165 * Hard code it here, this can be extended if in case
3166 * PROD pipe is also per interface.
3167 * Right now there is no advantage of doing this.
3168 */
3169 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
3170
3171 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
3172
3173 ipa->client = hdd_ipa->prod_client;
3174
3175 ipa->desc_fifo_sz = desc_fifo_sz;
3176 ipa->priv = hdd_ipa;
3177 ipa->notify = hdd_ipa_w2i_cb;
3178
3179 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3180 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
3181 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
3182 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
3183
3184 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3185 ipa->keep_ipa_awake = 1;
3186
3187 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
3188 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303189 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190 "Failed for RX pipe: %d", ret);
3191 goto setup_sys_pipe_fail;
3192 }
3193 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
3194 }
3195
3196 return ret;
3197
3198setup_sys_pipe_fail:
3199
3200 while (--i >= 0) {
3201 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303202 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203 sizeof(struct hdd_ipa_sys_pipe));
3204 }
3205
3206 return ret;
3207}
3208
3209/**
3210 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
3211 * @hdd_ipa: Global HDD IPA context
3212 *
3213 * Return: None
3214 */
3215static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
3216{
3217 int ret = 0, i;
3218 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
3219 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
3220 ret =
3221 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
3222 conn_hdl);
3223 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303224 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003225 ret);
3226
3227 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
3228 }
3229 }
3230}
3231
3232/**
3233 * hdd_ipa_register_interface() - register IPA interface
3234 * @hdd_ipa: Global IPA context
3235 * @iface_context: Per-interface IPA context
3236 *
3237 * Return: 0 on success, negative errno on error
3238 */
3239static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
3240 struct hdd_ipa_iface_context
3241 *iface_context)
3242{
3243 struct ipa_tx_intf tx_intf;
3244 struct ipa_rx_intf rx_intf;
3245 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
3246 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
3247 char *ifname = iface_context->adapter->dev->name;
3248
3249 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
3250 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
3251
3252 int num_prop = 1;
3253 int ret = 0;
3254
3255 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
3256 num_prop++;
3257
3258 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
3259 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303260 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003261 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303262 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263 goto register_interface_fail;
3264 }
3265
3266 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
3267 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303268 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303270 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003271 goto register_interface_fail;
3272 }
3273
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303274 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
3275 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003276
3277 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3278 ifname, HDD_IPA_IPV4_NAME_EXT);
3279 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
3280 ifname, HDD_IPA_IPV6_NAME_EXT);
3281
3282 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3283 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
3284 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3285 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3286
3287 /*
3288 * Interface ID is 3rd byte in the CLD header. Add the meta data and
3289 * mask to identify the interface in IPA hardware
3290 */
3291 rx_prop[IPA_IP_v4].attrib.meta_data =
3292 htonl(iface_context->adapter->sessionId << 16);
3293 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3294
3295 rx_intf.num_props++;
3296 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3297 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3298 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
3299 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3300 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
3301 rx_prop[IPA_IP_v4].attrib.meta_data =
3302 htonl(iface_context->adapter->sessionId << 16);
3303 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
3304
3305 rx_intf.num_props++;
3306 }
3307
3308 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
3309 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3310 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3311 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
3312 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
3313 IPA_RESOURCE_NAME_MAX);
3314 tx_intf.num_props++;
3315
3316 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3317 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
3318 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
3319 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
3320 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
3321 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
3322 IPA_RESOURCE_NAME_MAX);
3323 tx_intf.num_props++;
3324 }
3325
3326 tx_intf.prop = tx_prop;
3327 rx_intf.prop = rx_prop;
3328
3329 /* Call the ipa api to register interface */
3330 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
3331
3332register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303333 qdf_mem_free(tx_prop);
3334 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003335 return ret;
3336}
3337
3338/**
3339 * hdd_remove_ipa_header() - Remove a specific header from IPA
3340 * @name: Name of the header to be removed
3341 *
3342 * Return: None
3343 */
3344static void hdd_ipa_remove_header(char *name)
3345{
3346 struct ipa_ioc_get_hdr hdrlookup;
3347 int ret = 0, len;
3348 struct ipa_ioc_del_hdr *ipa_hdr;
3349
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303350 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003351 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
3352 ret = ipa_get_hdr(&hdrlookup);
3353 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303354 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355 name, ret);
3356 return;
3357 }
3358
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303359 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303361 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003362 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303363 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 return;
3365 }
3366 ipa_hdr->num_hdls = 1;
3367 ipa_hdr->commit = 0;
3368 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
3369 ipa_hdr->hdl[0].status = -1;
3370 ret = ipa_del_hdr(ipa_hdr);
3371 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303372 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373 ret);
3374
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303375 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003376}
3377
3378/**
3379 * hdd_ipa_add_header_info() - Add IPA header for a given interface
3380 * @hdd_ipa: Global HDD IPA context
3381 * @iface_context: Interface-specific HDD IPA context
3382 * @mac_addr: Interface MAC address
3383 *
3384 * Return: 0 on success, negativer errno value on error
3385 */
3386static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
3387 struct hdd_ipa_iface_context *iface_context,
3388 uint8_t *mac_addr)
3389{
3390 hdd_adapter_t *adapter = iface_context->adapter;
3391 char *ifname;
3392 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
3393 int ret = -EINVAL;
3394 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
3395 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
3396
3397 ifname = adapter->dev->name;
3398
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303399 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003400 ifname, mac_addr);
3401
3402 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303403 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404 + sizeof(struct ipa_hdr_add));
3405 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303406 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 "%s: ipa_hdr allocation failed", ifname);
3408 ret = -ENOMEM;
3409 goto end;
3410 }
3411
3412 ipa_hdr->commit = 0;
3413 ipa_hdr->num_hdrs = 1;
3414
3415 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3416 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3417 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
3418 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3419 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303420 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421 "ifname=%s, vdev_id=%d",
3422 ifname, uc_tx_hdr->ipa_hd.vdev_id);
3423 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3424 ifname, HDD_IPA_IPV4_NAME_EXT);
3425 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
3426 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
3427 ipa_hdr->hdr[0].is_partial = 1;
3428 ipa_hdr->hdr[0].hdr_hdl = 0;
3429 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3430 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
3431
3432 ret = ipa_add_hdr(ipa_hdr);
3433 } else {
3434 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3435
3436 /* Set the Source MAC */
3437 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
3438 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
3439
3440 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3441 ifname, HDD_IPA_IPV4_NAME_EXT);
3442 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
3443 ipa_hdr->hdr[0].is_partial = 1;
3444 ipa_hdr->hdr[0].hdr_hdl = 0;
3445 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
3446 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
3447
3448 /* Set the type to IPV4 in the header */
3449 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
3450
3451 ret = ipa_add_hdr(ipa_hdr);
3452 }
3453 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303454 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455 ifname, ret);
3456 goto end;
3457 }
3458
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303459 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003460 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3461
3462 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3463 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3464 ifname, HDD_IPA_IPV6_NAME_EXT);
3465
3466 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3467 uc_tx_hdr =
3468 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
3469 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
3470 } else {
3471 /* Set the type to IPV6 in the header */
3472 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
3473 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
3474 }
3475
3476 ret = ipa_add_hdr(ipa_hdr);
3477 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303478 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 "%s: IPv6 add hdr failed: %d", ifname, ret);
3480 goto clean_ipv4_hdr;
3481 }
3482
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303483 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
3485 }
3486
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303487 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488
3489 return ret;
3490
3491clean_ipv4_hdr:
3492 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
3493 ifname, HDD_IPA_IPV4_NAME_EXT);
3494 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
3495end:
3496 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303497 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498
3499 return ret;
3500}
3501
3502/**
3503 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
3504 * @adapter: Adapter upon which IPA was previously configured
3505 *
3506 * Return: None
3507 */
3508static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
3509{
3510 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3511 int ret;
3512 char name_ipa[IPA_RESOURCE_NAME_MAX];
3513
3514 /* Remove the headers */
3515 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3516 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
3517 hdd_ipa_remove_header(name_ipa);
3518
3519 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
3520 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
3521 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
3522 hdd_ipa_remove_header(name_ipa);
3523 }
3524 /* unregister the interface with IPA */
3525 ret = ipa_deregister_intf(adapter->dev->name);
3526 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303527 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528 "%s: ipa_deregister_intf fail: %d",
3529 adapter->dev->name, ret);
3530}
3531
3532/**
3533 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
3534 * @iface_context: interface-specific IPA context
3535 *
3536 * Return: None
3537 */
3538static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
3539{
3540 if (iface_context == NULL)
3541 return;
3542
3543 hdd_ipa_clean_hdr(iface_context->adapter);
3544
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303545 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546 iface_context->adapter->ipa_context = NULL;
3547 iface_context->adapter = NULL;
3548 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303549 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003550 iface_context->ifa_address = 0;
3551 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303552 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05303554 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555 }
3556 iface_context->hdd_ipa->num_iface--;
3557}
3558
3559/**
3560 * hdd_ipa_setup_iface() - Setup IPA on a given interface
3561 * @hdd_ipa: HDD IPA global context
3562 * @adapter: Interface upon which IPA is being setup
3563 * @sta_id: Station ID of the API instance
3564 *
3565 * Return: 0 on success, negative errno value on error
3566 */
3567static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
3568 hdd_adapter_t *adapter, uint8_t sta_id)
3569{
3570 struct hdd_ipa_iface_context *iface_context = NULL;
3571 void *tl_context = NULL;
3572 int i, ret = 0;
3573
3574 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
3575 * channel change indication. Since these indications are sent by lower
3576 * layer as SAP updates and IPA doesn't have to do anything for these
3577 * updates so ignoring!
3578 */
Krunal Sonibe766b02016-03-10 13:00:44 -08003579 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580 return 0;
3581
3582 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3583 if (hdd_ipa->iface_context[i].adapter == NULL) {
3584 iface_context = &(hdd_ipa->iface_context[i]);
3585 break;
3586 }
3587 }
3588
3589 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303590 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 "All the IPA interfaces are in use");
3592 ret = -ENOMEM;
3593 goto end;
3594 }
3595
3596 adapter->ipa_context = iface_context;
3597 iface_context->adapter = adapter;
3598 iface_context->sta_id = sta_id;
3599 tl_context = ol_txrx_get_vdev_by_sta_id(sta_id);
3600
3601 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303602 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 "Not able to get TL context sta_id: %d", sta_id);
3604 ret = -EINVAL;
3605 goto end;
3606 }
3607
3608 iface_context->tl_context = tl_context;
3609
3610 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
3611 adapter->dev->dev_addr);
3612
3613 if (ret)
3614 goto end;
3615
3616 /* Configure the TX and RX pipes filter rules */
3617 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
3618 if (ret)
3619 goto cleanup_header;
3620
3621 hdd_ipa->num_iface++;
3622 return ret;
3623
3624cleanup_header:
3625
3626 hdd_ipa_clean_hdr(adapter);
3627end:
3628 if (iface_context)
3629 hdd_ipa_cleanup_iface(iface_context);
3630 return ret;
3631}
3632
Yun Parka27049a2016-10-11 12:30:49 -07003633#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634/**
3635 * hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
3636 * @mcc_mode: 0=MCC/1=SCC
3637 *
3638 * Return: 0 on success, negative errno value on error
3639 */
3640int hdd_ipa_send_mcc_scc_msg(hdd_context_t *pHddCtx, bool mcc_mode)
3641{
3642 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303643 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 hdd_adapter_t *pAdapter;
3645 struct ipa_msg_meta meta;
3646 struct ipa_wlan_msg *msg;
3647 int ret;
3648
3649 if (!hdd_ipa_uc_sta_is_enabled(pHddCtx))
3650 return -EINVAL;
3651
3652 if (!pHddCtx->mcc_mode) {
3653 /* Flush TxRx queue for each adapter before switch to SCC */
3654 status = hdd_get_front_adapter(pHddCtx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303655 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08003657 if (pAdapter->device_mode == QDF_STA_MODE ||
3658 pAdapter->device_mode == QDF_SAP_MODE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303659 hddLog(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003660 "MCC->SCC: Flush TxRx queue(d_mode=%d)",
3661 pAdapter->device_mode);
3662 hdd_deinit_tx_rx(pAdapter);
3663 }
3664 status = hdd_get_next_adapter(
3665 pHddCtx, adapter_node, &next);
3666 adapter_node = next;
3667 }
3668 }
3669
3670 /* Send SCC/MCC Switching event to IPA */
3671 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303672 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003673 if (msg == NULL) {
3674 hddLog(LOGE, "msg allocation failed");
3675 return -ENOMEM;
3676 }
3677
3678 meta.msg_type = mcc_mode ?
3679 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
3680 hddLog(LOG1, "ipa_send_msg(Evt:%d)", meta.msg_type);
3681
3682 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3683
3684 if (ret) {
3685 hddLog(LOGE, "ipa_send_msg(Evt:%d) - fail=%d",
3686 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303687 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003688 }
3689
3690 return ret;
3691}
Yun Parka27049a2016-10-11 12:30:49 -07003692#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003693
3694/**
3695 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
3696 * @event: IPA WLAN event to be converted to a string
3697 *
3698 * Return: ASCII string representing the IPA WLAN event
3699 */
3700static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
3701{
3702 switch (event) {
3703 case WLAN_CLIENT_CONNECT:
3704 return "WLAN_CLIENT_CONNECT";
3705 case WLAN_CLIENT_DISCONNECT:
3706 return "WLAN_CLIENT_DISCONNECT";
3707 case WLAN_CLIENT_POWER_SAVE_MODE:
3708 return "WLAN_CLIENT_POWER_SAVE_MODE";
3709 case WLAN_CLIENT_NORMAL_MODE:
3710 return "WLAN_CLIENT_NORMAL_MODE";
3711 case SW_ROUTING_ENABLE:
3712 return "SW_ROUTING_ENABLE";
3713 case SW_ROUTING_DISABLE:
3714 return "SW_ROUTING_DISABLE";
3715 case WLAN_AP_CONNECT:
3716 return "WLAN_AP_CONNECT";
3717 case WLAN_AP_DISCONNECT:
3718 return "WLAN_AP_DISCONNECT";
3719 case WLAN_STA_CONNECT:
3720 return "WLAN_STA_CONNECT";
3721 case WLAN_STA_DISCONNECT:
3722 return "WLAN_STA_DISCONNECT";
3723 case WLAN_CLIENT_CONNECT_EX:
3724 return "WLAN_CLIENT_CONNECT_EX";
3725
3726 case IPA_WLAN_EVENT_MAX:
3727 default:
3728 return "UNKNOWN";
3729 }
3730}
3731
3732/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07003733 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
3734 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
3735 *
3736 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
3737 */
3738static enum ipa_wlan_event
3739hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
3740{
3741 enum ipa_wlan_event ipa_event;
3742
3743 switch (hdd_ipa_event_type) {
3744 case HDD_IPA_CLIENT_CONNECT:
3745 ipa_event = WLAN_CLIENT_CONNECT;
3746 break;
3747 case HDD_IPA_CLIENT_DISCONNECT:
3748 ipa_event = WLAN_CLIENT_DISCONNECT;
3749 break;
3750 case HDD_IPA_AP_CONNECT:
3751 ipa_event = WLAN_AP_CONNECT;
3752 break;
3753 case HDD_IPA_AP_DISCONNECT:
3754 ipa_event = WLAN_AP_DISCONNECT;
3755 break;
3756 case HDD_IPA_STA_CONNECT:
3757 ipa_event = WLAN_STA_CONNECT;
3758 break;
3759 case HDD_IPA_STA_DISCONNECT:
3760 ipa_event = WLAN_STA_DISCONNECT;
3761 break;
3762 case HDD_IPA_CLIENT_CONNECT_EX:
3763 ipa_event = WLAN_CLIENT_CONNECT_EX;
3764 break;
3765 case HDD_IPA_WLAN_EVENT_MAX:
3766 default:
3767 ipa_event = IPA_WLAN_EVENT_MAX;
3768 break;
3769 }
3770 return ipa_event;
3771
3772}
3773
3774/**
3775 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776 * @adapter: adapter upon which the event was received
3777 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07003778 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003779 * @mac_address: MAC address associated with the event
3780 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07003781 * This function is meant to be called from within wlan_hdd_ipa.c
3782 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783 * Return: 0 on success, negative errno value on error
3784 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07003785static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786 enum ipa_wlan_event type, uint8_t *mac_addr)
3787{
3788 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3789 struct ipa_msg_meta meta;
3790 struct ipa_wlan_msg *msg;
3791 struct ipa_wlan_msg_ex *msg_ex = NULL;
3792 int ret;
3793
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303794 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003795 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
3796 mac_addr, sta_id);
3797
3798 if (type >= IPA_WLAN_EVENT_MAX)
3799 return -EINVAL;
3800
3801 if (WARN_ON(is_zero_ether_addr(mac_addr)))
3802 return -EINVAL;
3803
3804 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303805 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003806 return -EINVAL;
3807 }
3808
3809 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3810 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08003811 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812 return 0;
3813 }
3814
3815 /*
3816 * During IPA UC resource loading/unloading new events can be issued.
3817 * Store the events separately and handle them later.
3818 */
3819 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
3820 ((hdd_ipa->resource_loading) ||
3821 (hdd_ipa->resource_unloading))) {
Yun Parkf19e07d2015-11-20 11:34:27 -08003822 unsigned int pending_event_count;
3823 struct ipa_uc_pending_event *pending_event = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003824
Yun Parkf19e07d2015-11-20 11:34:27 -08003825 hdd_err("IPA resource %s inprogress",
3826 hdd_ipa->resource_loading ? "load":"unload");
3827
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303828 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08003829
Anurag Chouhanffb21542016-02-17 14:33:03 +05303830 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003831 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
3832 hdd_notice("Reached max pending event count");
Anurag Chouhanffb21542016-02-17 14:33:03 +05303833 qdf_list_remove_front(&hdd_ipa->pending_event,
3834 (qdf_list_node_t **)&pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08003835 } else {
3836 pending_event =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303837 (struct ipa_uc_pending_event *)qdf_mem_malloc(
Yun Parkf19e07d2015-11-20 11:34:27 -08003838 sizeof(struct ipa_uc_pending_event));
3839 }
3840
3841 if (!pending_event) {
3842 hdd_err("Pending event memory alloc fail");
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303843 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844 return -ENOMEM;
3845 }
Yun Parkf19e07d2015-11-20 11:34:27 -08003846
3847 pending_event->adapter = adapter;
3848 pending_event->sta_id = sta_id;
3849 pending_event->type = type;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05303850 qdf_mem_copy(pending_event->mac_addr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003851 mac_addr,
Anurag Chouhan6d760662016-02-20 16:05:43 +05303852 QDF_MAC_ADDR_SIZE);
Anurag Chouhanffb21542016-02-17 14:33:03 +05303853 qdf_list_insert_back(&hdd_ipa->pending_event,
Yun Parkf19e07d2015-11-20 11:34:27 -08003854 &pending_event->node);
3855
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303856 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857 return 0;
3858 }
3859
3860 hdd_ipa->stats.event[type]++;
3861
Leo Chang3bc8fed2015-11-13 10:59:47 -08003862 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003863 switch (type) {
3864 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003865 qdf_mutex_acquire(&hdd_ipa->event_lock);
3866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003867 /* STA already connected and without disconnect, connect again
3868 * This is Roaming scenario
3869 */
3870 if (hdd_ipa->sta_connected)
3871 hdd_ipa_cleanup_iface(adapter->ipa_context);
3872
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003873 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3874 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303875 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003877 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003878
Yun Park8f289c82016-10-18 16:38:21 -07003879 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3880 (hdd_ipa->sap_num_connected_sta > 0) &&
3881 !hdd_ipa->sta_connected) {
3882 qdf_mutex_release(&hdd_ipa->event_lock);
3883 hdd_ipa_uc_offload_enable_disable(adapter,
3884 SIR_STA_RX_DATA_OFFLOAD, 1);
3885 qdf_mutex_acquire(&hdd_ipa->event_lock);
3886 }
3887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003888 vdev_to_iface[adapter->sessionId] =
3889 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003890 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003892 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07003893
3894 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003895 break;
3896
3897 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003898 qdf_mutex_acquire(&hdd_ipa->event_lock);
3899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 /* For DFS channel we get two start_bss event (before and after
3901 * CAC). Also when ACS range includes both DFS and non DFS
3902 * channels, we could possibly change channel many times due to
3903 * RADAR detection and chosen channel may not be a DFS channels.
3904 * So dont return error here. Just discard the event.
3905 */
Yun Park8f289c82016-10-18 16:38:21 -07003906 if (adapter->ipa_context) {
3907 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07003909 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003910
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003911 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
3912 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303913 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 "%s: Evt: %d, Interface setup failed",
3915 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303916 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07003918 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003919
Yun Park8f289c82016-10-18 16:38:21 -07003920 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3921 qdf_mutex_release(&hdd_ipa->event_lock);
3922 hdd_ipa_uc_offload_enable_disable(adapter,
3923 SIR_AP_RX_DATA_OFFLOAD, 1);
3924 qdf_mutex_acquire(&hdd_ipa->event_lock);
3925 }
3926
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003927 vdev_to_iface[adapter->sessionId] =
3928 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07003929 (adapter->ipa_context))->iface_id;
3930
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303931 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003932 break;
3933
3934 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303935 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936
3937 if (!hdd_ipa->sta_connected) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303938 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003939 "%s: Evt: %d, STA already disconnected",
3940 msg_ex->name, meta.msg_type);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303941 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 return -EINVAL;
3943 }
Yun Parka37592b2016-06-11 17:10:28 -07003944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07003946
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003947 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303948 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 "%s: IPA UC OFFLOAD NOT ENABLED",
3950 msg_ex->name);
3951 } else {
3952 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07003953 if (!hdd_ipa->num_iface &&
3954 (HDD_IPA_UC_NUM_WDI_PIPE ==
3955 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 }
3958
Yun Park74127cf2016-09-18 11:22:41 -07003959 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3960 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07003961 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 hdd_ipa_uc_offload_enable_disable(adapter,
3963 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07003964 qdf_mutex_acquire(&hdd_ipa->event_lock);
3965 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 }
3967
Yun Park8f289c82016-10-18 16:38:21 -07003968 hdd_ipa_cleanup_iface(adapter->ipa_context);
3969
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303970 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 break;
3972
3973 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07003974 qdf_mutex_acquire(&hdd_ipa->event_lock);
3975
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976 if (!adapter->ipa_context) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303977 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003978 "%s: Evt: %d, SAP already disconnected",
3979 msg_ex->name, meta.msg_type);
Yun Park8f289c82016-10-18 16:38:21 -07003980 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 return -EINVAL;
3982 }
3983
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003984 if ((!hdd_ipa->num_iface) &&
3985 (HDD_IPA_UC_NUM_WDI_PIPE ==
3986 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003987 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988 /*
3989 * We disable WDI pipes directly here since
3990 * IPA_OPCODE_TX/RX_SUSPEND message will not be
3991 * processed when unloading WLAN driver is in
3992 * progress
3993 */
3994 hdd_ipa_uc_disable_pipes(hdd_ipa);
3995 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303996 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003997 "NO INTF left but still pipe clean up");
3998 hdd_ipa_uc_handle_last_discon(hdd_ipa);
3999 }
4000 }
4001
4002 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07004003 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 hdd_ipa_uc_offload_enable_disable(adapter,
4005 SIR_AP_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004006 qdf_mutex_acquire(&hdd_ipa->event_lock);
4007 vdev_to_iface[adapter->sessionId] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 }
Yun Parka37592b2016-06-11 17:10:28 -07004009
Yun Park8f289c82016-10-18 16:38:21 -07004010 hdd_ipa_cleanup_iface(adapter->ipa_context);
4011
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304012 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 break;
4014
4015 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004016 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304017 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
4019 adapter->dev->name, meta.msg_type);
4020 return 0;
4021 }
4022
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304023 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004024 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
4025 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07004026 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304027 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004028 "%s: STA ID %d found, not valid",
4029 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 return 0;
4031 }
Yun Park312f71a2015-12-08 10:22:42 -08004032
4033 /* Enable IPA UC Data PIPEs when first STA connected */
Yun Parka37592b2016-06-11 17:10:28 -07004034 if (0 == hdd_ipa->sap_num_connected_sta) {
4035 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004036 hdd_ipa->sta_connected) {
4037 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004038 hdd_ipa_uc_offload_enable_disable(
4039 hdd_get_adapter(hdd_ipa->hdd_ctx,
4040 QDF_STA_MODE),
4041 SIR_STA_RX_DATA_OFFLOAD, 1);
Yun Park8f289c82016-10-18 16:38:21 -07004042 qdf_mutex_acquire(&hdd_ipa->event_lock);
4043 }
Yun Parka37592b2016-06-11 17:10:28 -07004044
Yun Park312f71a2015-12-08 10:22:42 -08004045 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
4046 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304047 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08004048 "%s: handle 1st con ret %d",
4049 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07004050
4051 if (hdd_ipa_uc_sta_is_enabled(
4052 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07004053 hdd_ipa->sta_connected) {
4054 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07004055 hdd_ipa_uc_offload_enable_disable(
4056 hdd_get_adapter(
4057 hdd_ipa->hdd_ctx,
4058 QDF_STA_MODE),
4059 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004060 } else {
4061 qdf_mutex_release(&hdd_ipa->event_lock);
4062 }
Yun Parka37592b2016-06-11 17:10:28 -07004063
Yun Park312f71a2015-12-08 10:22:42 -08004064 return ret;
4065 }
4066 }
4067
4068 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08004069
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304070 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071
4072 meta.msg_type = type;
4073 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
4074 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304075 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076
4077 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304078 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079 "msg_ex allocation failed");
4080 return -ENOMEM;
4081 }
4082 strlcpy(msg_ex->name, adapter->dev->name,
4083 IPA_RESOURCE_NAME_MAX);
4084 msg_ex->num_of_attribs = 1;
4085 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
4086 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4087 msg_ex->attribs[0].offset =
4088 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4089 } else {
4090 msg_ex->attribs[0].offset =
4091 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4092 }
4093 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
4094 IPA_MAC_ADDR_SIZE);
4095
4096 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
4097
4098 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304099 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 msg_ex->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304101 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102 return ret;
4103 }
4104 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105 return ret;
4106
4107 case WLAN_CLIENT_DISCONNECT:
4108 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304109 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110 "%s: IPA UC OFFLOAD NOT ENABLED",
4111 msg_ex->name);
4112 return 0;
4113 }
4114
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304115 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004116 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304117 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118 "%s: STA ID %d NOT found, not valid",
4119 msg_ex->name, sta_id);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304120 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004121 return 0;
4122 }
4123 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07004124
Yun Park9b5030f2016-11-08 12:02:37 -08004125 /* Disable IPA UC TX PIPE when last STA disconnected */
4126 if (!hdd_ipa->sap_num_connected_sta) {
4127 if ((false == hdd_ipa->resource_unloading)
4128 && (HDD_IPA_UC_NUM_WDI_PIPE ==
4129 hdd_ipa->activated_fw_pipe)) {
4130 hdd_ipa_uc_handle_last_discon(hdd_ipa);
4131 }
4132
Yun Park8f289c82016-10-18 16:38:21 -07004133 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004134
4135 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4136 hdd_ipa->sta_connected)
4137 hdd_ipa_uc_offload_enable_disable(
4138 hdd_get_adapter(hdd_ipa->hdd_ctx,
4139 QDF_STA_MODE),
4140 SIR_STA_RX_DATA_OFFLOAD, 0);
Yun Park8f289c82016-10-18 16:38:21 -07004141 } else {
4142 qdf_mutex_release(&hdd_ipa->event_lock);
4143 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 break;
4145
4146 default:
4147 return 0;
4148 }
4149
4150 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304151 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004152 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304153 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154 return -ENOMEM;
4155 }
4156
4157 meta.msg_type = type;
4158 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
4159 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
4160
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304161 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162 msg->name, meta.msg_type);
4163
4164 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4165
4166 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304167 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d fail:%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304169 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004170 return ret;
4171 }
4172
4173 hdd_ipa->stats.num_send_msg++;
4174
4175end:
4176 return ret;
4177}
4178
4179/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004180 * hdd_ipa_wlan_evt() - IPA event handler
4181 * @adapter: adapter upon which the event was received
4182 * @sta_id: station id for the event
4183 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
4184 * @mac_address: MAC address associated with the event
4185 *
4186 * This function is meant to be called from outside of wlan_hdd_ipa.c.
4187 *
4188 * Return: 0 on success, negative errno value on error
4189 */
4190int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
4191 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
4192{
4193 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
4194
Leo Changa202b522016-10-14 16:13:50 -07004195 /* Data path offload only support for STA and SAP mode */
4196 if ((QDF_STA_MODE == adapter->device_mode) ||
4197 (QDF_SAP_MODE == adapter->device_mode))
4198 return __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
4199
4200 return 0;
Mohit Khannafa99aea2016-05-12 21:43:13 -07004201}
4202
4203/**
4204 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
4205 * @hdd_ipa: Global HDD IPA context
4206 *
4207 * Return: None
4208 */
4209static void
4210hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
4211{
4212 unsigned int pending_event_count;
4213 struct ipa_uc_pending_event *pending_event = NULL;
4214
4215 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
4216 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4217 "%s, Pending Event Count %d", __func__, pending_event_count);
4218 if (!pending_event_count) {
4219 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4220 "%s, No Pending Event", __func__);
4221 return;
4222 }
4223
4224 qdf_list_remove_front(&hdd_ipa->pending_event,
4225 (qdf_list_node_t **)&pending_event);
4226 while (pending_event != NULL) {
4227 __hdd_ipa_wlan_evt(pending_event->adapter,
4228 pending_event->type,
4229 pending_event->sta_id,
4230 pending_event->mac_addr);
4231 qdf_mem_free(pending_event);
4232 pending_event = NULL;
4233 qdf_list_remove_front(&hdd_ipa->pending_event,
4234 (qdf_list_node_t **)&pending_event);
4235 }
4236}
4237
4238/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
4240 * @state: IPA RM state value
4241 *
4242 * Return: ASCII string representing the IPA RM state
4243 */
4244static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
4245{
4246 switch (state) {
4247 case HDD_IPA_RM_RELEASED:
4248 return "RELEASED";
4249 case HDD_IPA_RM_GRANT_PENDING:
4250 return "GRANT_PENDING";
4251 case HDD_IPA_RM_GRANTED:
4252 return "GRANTED";
4253 }
4254
4255 return "UNKNOWN";
4256}
4257
4258/**
4259 * hdd_ipa_init() - IPA initialization function
4260 * @hdd_ctx: HDD global context
4261 *
4262 * Allocate hdd_ipa resources, ipa pipe resource and register
4263 * wlan interface with IPA module.
4264 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304265 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004266 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304267QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268{
4269 struct hdd_ipa_priv *hdd_ipa = NULL;
4270 int ret, i;
4271 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park7f171ab2016-07-29 15:44:22 -07004272 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004273
4274 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304275 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276
Yun Park7f171ab2016-07-29 15:44:22 -07004277 if (!pdev) {
4278 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
4279 goto fail_return;
4280 }
4281
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304282 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304284 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08004285 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004286 }
4287
4288 hdd_ctx->hdd_ipa = hdd_ipa;
4289 ghdd_ipa = hdd_ipa;
4290 hdd_ipa->hdd_ctx = hdd_ctx;
4291 hdd_ipa->num_iface = 0;
Yun Park7f171ab2016-07-29 15:44:22 -07004292 ol_txrx_ipa_uc_get_resource(pdev, &hdd_ipa->ipa_resource);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08004293 if ((0 == hdd_ipa->ipa_resource.ce_sr_base_paddr) ||
4294 (0 == hdd_ipa->ipa_resource.tx_comp_ring_base_paddr) ||
4295 (0 == hdd_ipa->ipa_resource.rx_rdy_ring_base_paddr) ||
4296 (0 == hdd_ipa->ipa_resource.rx2_rdy_ring_base_paddr)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304297 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Leo Chang3bc8fed2015-11-13 10:59:47 -08004298 "IPA UC resource alloc fail");
4299 goto fail_get_resource;
4300 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004301
4302 /* Create the interface context */
4303 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4304 iface_context = &hdd_ipa->iface_context[i];
4305 iface_context->hdd_ipa = hdd_ipa;
4306 iface_context->cons_client =
4307 hdd_ipa_adapter_2_client[i].cons_client;
4308 iface_context->prod_client =
4309 hdd_ipa_adapter_2_client[i].prod_client;
4310 iface_context->iface_id = i;
4311 iface_context->adapter = NULL;
Yun Park8292dcb2016-10-07 16:46:06 -07004312 iface_context->offload_enabled = 0;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304313 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08004314 }
4315 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Yun Park8f289c82016-10-18 16:38:21 -07004316 vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 }
4318
Leo Chang69c39692016-10-12 20:11:12 -07004319 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304320 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304321 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322
4323 ret = hdd_ipa_setup_rm(hdd_ipa);
4324 if (ret)
4325 goto fail_setup_rm;
4326
4327 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4328 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304329 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330 hdd_ipa->sap_num_connected_sta = 0;
4331 hdd_ipa->ipa_tx_packets_diff = 0;
4332 hdd_ipa->ipa_rx_packets_diff = 0;
4333 hdd_ipa->ipa_p_tx_packets = 0;
4334 hdd_ipa->ipa_p_rx_packets = 0;
4335 hdd_ipa->resource_loading = false;
4336 hdd_ipa->resource_unloading = false;
4337 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07004338 hdd_ipa->ipa_pipes_down = true;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 /* Setup IPA sys_pipe for MCC */
4340 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4341 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4342 if (ret)
4343 goto fail_create_sys_pipe;
4344 }
4345 hdd_ipa_uc_ol_init(hdd_ctx);
4346 } else {
4347 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
4348 if (ret)
4349 goto fail_create_sys_pipe;
4350 }
4351
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304352 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353
4354fail_create_sys_pipe:
4355 hdd_ipa_destroy_rm_resource(hdd_ipa);
4356fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304357 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004358fail_get_resource:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304359 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08004360 hdd_ctx->hdd_ipa = NULL;
4361 ghdd_ipa = NULL;
4362fail_return:
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304363 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364}
4365
4366/**
Yun Parkf19e07d2015-11-20 11:34:27 -08004367 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
4368 * @hdd_ipa: pointer to HDD IPA struct
4369 *
4370 * Return: none
4371 */
Jeff Johnsond7720632016-10-05 16:04:32 -07004372static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08004373{
4374 struct ipa_uc_pending_event *pending_event = NULL;
4375
Anurag Chouhanffb21542016-02-17 14:33:03 +05304376 while (qdf_list_remove_front(&hdd_ipa->pending_event,
4377 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304378 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004379 }
4380
Anurag Chouhanffb21542016-02-17 14:33:03 +05304381 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08004382}
4383
4384/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 * hdd_ipa_cleanup - IPA cleanup function
4386 * @hdd_ctx: HDD global context
4387 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304388 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389 */
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304390QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004391{
4392 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
4393 int i;
4394 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304395 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
4397
4398 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304399 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400
4401 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
4402 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
4403 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4404 }
4405
4406 /* Teardown IPA sys_pipe for MCC */
4407 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
4408 hdd_ipa_teardown_sys_pipe(hdd_ipa);
4409
4410 hdd_ipa_destroy_rm_resource(hdd_ipa);
4411
4412#ifdef WLAN_OPEN_SOURCE
4413 cancel_work_sync(&hdd_ipa->pm_work);
4414#endif
4415
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304416 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417
Nirav Shahcbc6d722016-03-01 16:24:53 +05304418 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4419 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304420 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421
4422 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4423 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
4424
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304425 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004426 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304427 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304429 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004430
4431 /* destory the interface lock */
4432 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4433 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304434 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004435 }
4436
4437 /* This should never hit but still make sure that there are no pending
4438 * descriptor in IPA hardware
4439 */
4440 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304441 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004442 "IPA Pending write done: %d Waiting!",
4443 hdd_ipa->pending_hw_desc_cnt);
4444
4445 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
4446 usleep_range(100, 100);
4447 }
4448
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304449 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004450 "IPA Pending write done: desc: %d %s(%d)!",
4451 hdd_ipa->pending_hw_desc_cnt,
4452 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
4453 : "leak", i);
4454 }
4455 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
4456 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304457 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304458 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
4459 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004460 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304461 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05304462 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
4463 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304465 qdf_mutex_destroy(&hdd_ipa->event_lock);
4466 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004467 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004468
4469#ifdef WLAN_OPEN_SOURCE
4470 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
4471 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
4472 hdd_ipa->uc_op_work[i].msg = NULL;
4473 }
4474#endif
4475 }
4476
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304477 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478 hdd_ctx->hdd_ipa = NULL;
4479
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304480 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481}
4482#endif /* IPA_OFFLOAD */