blob: 282874fae07c13ec47dc734525994ed3afb1801f [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
jge62037862016-12-09 10:44:33 +08002 * Copyright (c) 2013-2017 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>
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +053051#include <ol_txrx.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"
Prakash Dhavali87b38e32016-11-14 16:22:53 -080058#include "wal_rx_desc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
Dhanashri Atreb08959a2016-03-01 17:28:03 -080060#include "cdp_txrx_ipa.h"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080061#include <cdp_txrx_handle.h>
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080062#include "wlan_policy_mgr_api.h"
63
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064#define HDD_IPA_DESC_BUFFER_RATIO 4
65#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
66#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
67
68#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080069#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
70/* WDI TX and RX PIPE */
71#define HDD_IPA_UC_NUM_WDI_PIPE 2
72#define HDD_IPA_UC_MAX_PENDING_EVENT 33
73
74#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
75#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
76#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
77#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
78
79#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
80#define HDD_IPA_MAX_IFACE 3
81#define HDD_IPA_MAX_SYSBAM_PIPE 4
82#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
83#define HDD_IPA_ENABLE_MASK BIT(0)
84#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
85#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
86#define HDD_IPA_RM_ENABLE_MASK BIT(3)
87#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
88#define HDD_IPA_UC_ENABLE_MASK BIT(5)
89#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
90#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
91
Yun Parkf19e07d2015-11-20 11:34:27 -080092#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
93
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080094typedef enum {
95 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
96 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
97 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
98 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
99 HDD_IPA_UC_OPCODE_STATS = 4,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800100 HDD_IPA_UC_OPCODE_UC_READY = 8,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800101 /* keep this last */
102 HDD_IPA_UC_OPCODE_MAX
103} hdd_ipa_uc_op_code;
104
105/**
106 * enum - Reason codes for stat query
107 *
108 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
109 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
110 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
Yun Parkb187d542016-11-14 18:10:04 -0800111 * @HDD_IPA_UC_STAT_REASON_DUMP_INFO: For debug info dump
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800112 */
113enum {
114 HDD_IPA_UC_STAT_REASON_NONE,
115 HDD_IPA_UC_STAT_REASON_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -0800116 HDD_IPA_UC_STAT_REASON_BW_CAL,
117 HDD_IPA_UC_STAT_REASON_DUMP_INFO
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800118};
119
120/**
121 * enum hdd_ipa_rm_state - IPA resource manager state
122 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
123 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
124 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
125 */
126enum hdd_ipa_rm_state {
127 HDD_IPA_RM_RELEASED,
128 HDD_IPA_RM_GRANT_PENDING,
129 HDD_IPA_RM_GRANTED,
130};
131
132struct llc_snap_hdr {
133 uint8_t dsap;
134 uint8_t ssap;
135 uint8_t resv[4];
136 __be16 eth_type;
137} __packed;
138
Leo Chang3bc8fed2015-11-13 10:59:47 -0800139/**
140 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
141 * @eth: ether II header
142 * @llc_snap: LLC snap header
143 *
144 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800145struct hdd_ipa_tx_hdr {
146 struct ethhdr eth;
147 struct llc_snap_hdr llc_snap;
148} __packed;
149
Leo Chang3bc8fed2015-11-13 10:59:47 -0800150/**
151 * struct frag_header - fragment header type registered to IPA hardware
152 * @length: fragment length
153 * @reserved1: Reserved not used
154 * @reserved2: Reserved not used
155 *
156 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800157struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800158 uint16_t length;
159 uint32_t reserved1;
160 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800161} __packed;
162
Leo Chang3bc8fed2015-11-13 10:59:47 -0800163/**
164 * struct ipa_header - ipa header type registered to IPA hardware
165 * @vdev_id: vdev id
166 * @reserved: Reserved not used
167 *
168 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800169struct ipa_header {
170 uint32_t
171 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
172 reserved:24;
173} __packed;
174
Leo Chang3bc8fed2015-11-13 10:59:47 -0800175/**
176 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
177 * @frag_hd: fragment header
178 * @ipa_hd: ipa header
179 * @eth: ether II header
180 *
181 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800182struct hdd_ipa_uc_tx_hdr {
183 struct frag_header frag_hd;
184 struct ipa_header ipa_hd;
185 struct ethhdr eth;
186} __packed;
187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800188/**
189 * struct hdd_ipa_cld_hdr - IPA CLD Header
190 * @reserved: reserved fields
191 * @iface_id: interface ID
192 * @sta_id: Station ID
193 *
194 * Packed 32-bit structure
195 * +----------+----------+--------------+--------+
196 * | Reserved | QCMAP ID | interface id | STA ID |
197 * +----------+----------+--------------+--------+
198 */
199struct hdd_ipa_cld_hdr {
200 uint8_t reserved[2];
201 uint8_t iface_id;
202 uint8_t sta_id;
203} __packed;
204
205struct hdd_ipa_rx_hdr {
206 struct hdd_ipa_cld_hdr cld_hdr;
207 struct ethhdr eth;
208} __packed;
209
210struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700211 bool exception;
212 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800213 struct hdd_ipa_iface_context *iface_context;
214 struct ipa_rx_data *ipa_tx_desc;
215};
216
217struct hdd_ipa_uc_rx_hdr {
218 struct ethhdr eth;
219} __packed;
220
221struct hdd_ipa_sys_pipe {
222 uint32_t conn_hdl;
223 uint8_t conn_hdl_valid;
224 struct ipa_sys_connect_params ipa_sys_params;
225};
226
227struct hdd_ipa_iface_stats {
228 uint64_t num_tx;
229 uint64_t num_tx_drop;
230 uint64_t num_tx_err;
231 uint64_t num_tx_cac_drop;
232 uint64_t num_rx_prefilter;
233 uint64_t num_rx_ipa_excep;
234 uint64_t num_rx_recv;
235 uint64_t num_rx_recv_mul;
236 uint64_t num_rx_send_desc_err;
237 uint64_t max_rx_mul;
238};
239
240struct hdd_ipa_priv;
241
242struct hdd_ipa_iface_context {
243 struct hdd_ipa_priv *hdd_ipa;
244 hdd_adapter_t *adapter;
245 void *tl_context;
246
247 enum ipa_client_type cons_client;
248 enum ipa_client_type prod_client;
249
250 uint8_t iface_id; /* This iface ID */
251 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530252 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800253 uint32_t ifa_address;
254 struct hdd_ipa_iface_stats stats;
255};
256
257struct hdd_ipa_stats {
258 uint32_t event[IPA_WLAN_EVENT_MAX];
259 uint64_t num_send_msg;
260 uint64_t num_free_msg;
261
262 uint64_t num_rm_grant;
263 uint64_t num_rm_release;
264 uint64_t num_rm_grant_imm;
265 uint64_t num_cons_perf_req;
266 uint64_t num_prod_perf_req;
267
268 uint64_t num_rx_drop;
269 uint64_t num_rx_ipa_tx_dp;
270 uint64_t num_rx_ipa_splice;
271 uint64_t num_rx_ipa_loop;
272 uint64_t num_rx_ipa_tx_dp_err;
273 uint64_t num_rx_ipa_write_done;
274 uint64_t num_max_ipa_tx_mul;
275 uint64_t num_rx_ipa_hw_maxed_out;
276 uint64_t max_pend_q_cnt;
277
278 uint64_t num_tx_comp_cnt;
279 uint64_t num_tx_queued;
280 uint64_t num_tx_dequeued;
281 uint64_t num_max_pm_queue;
282
283 uint64_t num_freeq_empty;
284 uint64_t num_pri_freeq_empty;
285 uint64_t num_rx_excep;
Yun Parkb187d542016-11-14 18:10:04 -0800286 uint64_t num_tx_fwd_ok;
287 uint64_t num_tx_fwd_err;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800288};
289
290struct ipa_uc_stas_map {
291 bool is_reserved;
292 uint8_t sta_id;
293};
294struct op_msg_type {
295 uint8_t msg_t;
296 uint8_t rsvd;
297 uint16_t op_code;
298 uint16_t len;
299 uint16_t rsvd_snd;
300};
301
302struct ipa_uc_fw_stats {
303 uint32_t tx_comp_ring_base;
304 uint32_t tx_comp_ring_size;
305 uint32_t tx_comp_ring_dbell_addr;
306 uint32_t tx_comp_ring_dbell_ind_val;
307 uint32_t tx_comp_ring_dbell_cached_val;
308 uint32_t tx_pkts_enqueued;
309 uint32_t tx_pkts_completed;
310 uint32_t tx_is_suspend;
311 uint32_t tx_reserved;
312 uint32_t rx_ind_ring_base;
313 uint32_t rx_ind_ring_size;
314 uint32_t rx_ind_ring_dbell_addr;
315 uint32_t rx_ind_ring_dbell_ind_val;
316 uint32_t rx_ind_ring_dbell_ind_cached_val;
317 uint32_t rx_ind_ring_rdidx_addr;
318 uint32_t rx_ind_ring_rd_idx_cached_val;
319 uint32_t rx_refill_idx;
320 uint32_t rx_num_pkts_indicated;
321 uint32_t rx_buf_refilled;
322 uint32_t rx_num_ind_drop_no_space;
323 uint32_t rx_num_ind_drop_no_buf;
324 uint32_t rx_is_suspend;
325 uint32_t rx_reserved;
326};
327
328struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530329 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330 hdd_adapter_t *adapter;
331 enum ipa_wlan_event type;
332 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530333 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334};
335
336/**
337 * struct uc_rm_work_struct
338 * @work: uC RM work
339 * @event: IPA RM event
340 */
341struct uc_rm_work_struct {
342 struct work_struct work;
343 enum ipa_rm_event event;
344};
345
346/**
347 * struct uc_op_work_struct
348 * @work: uC OP work
349 * @msg: OP message
350 */
351struct uc_op_work_struct {
352 struct work_struct work;
353 struct op_msg_type *msg;
354};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355
356/**
357 * struct uc_rt_debug_info
358 * @time: system time
359 * @ipa_excep_count: IPA exception packet count
360 * @rx_drop_count: IPA Rx drop packet count
361 * @net_sent_count: IPA Rx packet sent to network stack count
362 * @rx_discard_count: IPA Rx discard packet count
Yun Parkb187d542016-11-14 18:10:04 -0800363 * @tx_fwd_ok_count: IPA Tx forward success packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364 * @tx_fwd_count: IPA Tx forward packet count
365 * @rx_destructor_call: IPA Rx packet destructor count
366 */
367struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530368 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 uint64_t ipa_excep_count;
370 uint64_t rx_drop_count;
371 uint64_t net_sent_count;
372 uint64_t rx_discard_count;
Yun Parkb187d542016-11-14 18:10:04 -0800373 uint64_t tx_fwd_ok_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800374 uint64_t tx_fwd_count;
375 uint64_t rx_destructor_call;
376};
377
378struct hdd_ipa_priv {
379 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
380 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
381 uint8_t num_iface;
382 enum hdd_ipa_rm_state rm_state;
383 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530384 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800385 * APIs as it is taken care gracefully. Without this, kernel would throw
386 * an warning if spin_lock_bh is used while IRQ is disabled
387 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530388 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800389 struct uc_rm_work_struct uc_rm_work;
390 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530391 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800392 struct delayed_work wake_lock_work;
393 bool wake_lock_released;
394
395 enum ipa_client_type prod_client;
396
397 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530398 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530400 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800401 bool suspended;
402
403 uint32_t pending_hw_desc_cnt;
404 uint32_t hw_desc_cnt;
405 spinlock_t q_lock;
406 uint32_t freeq_cnt;
407 struct list_head free_desc_head;
408
409 uint32_t pend_q_cnt;
410 struct list_head pend_desc_head;
411
412 hdd_context_t *hdd_ctx;
413
414 struct dentry *debugfs_dir;
415 struct hdd_ipa_stats stats;
416
417 struct notifier_block ipv4_notifier;
418 uint32_t curr_prod_bw;
419 uint32_t curr_cons_bw;
420
421 uint8_t activated_fw_pipe;
422 uint8_t sap_num_connected_sta;
423 uint8_t sta_connected;
424 uint32_t tx_pipe_handle;
425 uint32_t rx_pipe_handle;
426 bool resource_loading;
427 bool resource_unloading;
428 bool pending_cons_req;
429 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530430 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530431 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700432 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433 uint32_t ipa_tx_packets_diff;
434 uint32_t ipa_rx_packets_diff;
435 uint32_t ipa_p_tx_packets;
436 uint32_t ipa_p_rx_packets;
437 uint32_t stat_req_reason;
438 uint64_t ipa_tx_forward;
439 uint64_t ipa_rx_discard;
440 uint64_t ipa_rx_net_send_count;
441 uint64_t ipa_rx_internel_drop_count;
442 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530443 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800444 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
445 unsigned int rt_buf_fill_index;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800446 struct ipa_wdi_in_params cons_pipe_in;
447 struct ipa_wdi_in_params prod_pipe_in;
448 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800449 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530450 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530451 qdf_mutex_t rt_debug_lock;
452 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800453 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800454 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530455 qdf_dma_addr_t tx_comp_doorbell_paddr;
456 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800457
458 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
459 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800460};
461
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800462/**
Houston Hoffman23e76f92016-02-26 12:19:11 -0800463 * FIXME: The following conversion routines are just stubs.
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800464 * They will be implemented fully by another update.
465 * The stubs will let the compile go ahead, and functionality
466 * is broken.
467 * This should be OK and IPA is not enabled yet
468 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700469static void *wlan_hdd_stub_priv_to_addr(uint32_t priv)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800470{
471 void *vaddr;
472 uint32_t ipa_priv = priv;
473
474 vaddr = &ipa_priv; /* just to use the var */
475 vaddr = NULL;
476 return vaddr;
477}
478
Jeff Johnsond7720632016-10-05 16:04:32 -0700479static uint32_t wlan_hdd_stub_addr_to_priv(void *ptr)
Houston Hoffman43d47fa2016-02-24 16:34:30 -0800480{
481 uint32_t ipa_priv = 0;
482
483 BUG_ON(ptr == NULL);
484 return ipa_priv;
485}
Leo Changcc923e22016-06-16 15:29:03 -0700486
487#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
488#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
490#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
491#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
492#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
493#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
494#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700495#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
496 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497
498#define HDD_IPA_GET_IFACE_ID(_data) \
499 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
500
501#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530502 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503 "%s:%d: "fmt, __func__, __LINE__, ## args)
504
Govind Singhb6a89772016-08-12 11:23:35 +0530505#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
506 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
507 "%s:%d: "fmt, __func__, __LINE__, ## args)
508
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800509#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
510 do { \
Yun Parkec845302016-12-15 09:22:57 -0800511 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
512 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800513 } while (0)
514
515#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
516 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
517
518#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
519 do { \
520 hdd_ipa->ipa_rx_internel_drop_count++; \
521 } while (0)
522#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
523 do { \
524 hdd_ipa->ipa_rx_net_send_count++; \
525 } while (0)
526#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
527
Leo Chang07b28f62016-05-11 12:29:22 -0700528#if defined (QCA_WIFI_3_0) && defined (CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800529#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
530do { \
531 pipe_in.u.ul.rdy_ring_rp_va = \
532 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
533 pipe_in.u.ul.rdy_comp_ring_base_pa = \
534 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
535 pipe_in.u.ul.rdy_comp_ring_size = \
536 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
537 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
538 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
539 pipe_in.u.ul.rdy_comp_ring_wp_va = \
540 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800541} while (0)
Leo Chang63d73612016-10-18 18:09:43 -0700542
543#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800544#else
545/* Do nothing */
546#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang63d73612016-10-18 18:09:43 -0700547#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700548#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800549
Yun Parkb187d542016-11-14 18:10:04 -0800550#define HDD_IPA_DBG_DUMP_RX_LEN 32
551#define HDD_IPA_DBG_DUMP_TX_LEN 48
552
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800553static struct hdd_ipa_adapter_2_client {
554 enum ipa_client_type cons_client;
555 enum ipa_client_type prod_client;
556} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
557 {
558 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
559 }, {
560 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
561 }, {
562 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
563 },
564};
565
566/* For Tx pipes, use Ethernet-II Header format */
567struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
568 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800569 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800570 0x00000000,
571 0x00000000
572 },
573 {
574 0x00000000
575 },
576 {
577 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
578 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
579 0x0008
580 }
581};
582
583/* For Tx pipes, use 802.3 Header format */
584static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
585 {
586 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
587 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
588 0x00 /* length can be zero */
589 },
590 {
591 /* LLC SNAP header 8 bytes */
592 0xaa, 0xaa,
593 {0x03, 0x00, 0x00, 0x00},
594 0x0008 /* type value(2 bytes) ,filled by wlan */
595 /* 0x0800 - IPV4, 0x86dd - IPV6 */
596 }
597};
598
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800599static struct hdd_ipa_priv *ghdd_ipa;
600
601/* Local Function Prototypes */
602static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
603 unsigned long data);
604static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
605 unsigned long data);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800606static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800607
608static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Mohit Khannafa99aea2016-05-12 21:43:13 -0700609static void hdd_ipa_uc_proc_pending_event (struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800610
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800611#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
612 defined(IPA_CLIENT_IS_MHI_CONS))
613/**
614 * hdd_ipa_uc_get_db_paddr() - Get Doorbell physical address
615 * @db_paddr: Doorbell physical address should be given bu IPA
616 * @client: IPA client type
617 *
618 * Query doorbell physical address from IPA
619 * IPA will give physical address for TX COMP and RX READY
620 *
621 * Return: None
622 */
623static void hdd_ipa_uc_get_db_paddr(qdf_dma_addr_t *db_paddr,
624 enum ipa_client_type client)
625{
626 struct ipa_wdi_db_params dbpa;
627
628 dbpa.client = client;
629 ipa_uc_wdi_get_dbpa(&dbpa);
630 *db_paddr = dbpa.uc_door_bell_pa;
631 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s PROD DB get dbpa 0x%x",
632 __func__, (unsigned int)dbpa.uc_door_bell_pa);
633}
634
635/**
636 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
637 * @priv_ctxt: hdd ipa local context
638 *
639 * Will be called by IPA context.
640 * It's atomic context, then should be scheduled to kworker thread
641 *
642 * Return: None
643 */
644static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
645{
646 struct hdd_ipa_priv *hdd_ipa;
647 struct op_msg_type *msg;
648 struct uc_op_work_struct *uc_op_work;
649
650 if (priv_ctxt == NULL) {
651 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
652 return;
653 }
654
655 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
656 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
657 if (!msg) {
658 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
659 return;
660 }
661
662 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
663
664 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
665
666 /* When the same uC OPCODE is already pended, just return */
667 if (uc_op_work->msg)
668 return;
669
670 uc_op_work->msg = msg;
671 schedule_work(&uc_op_work->work);
672}
673
674/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800675 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
676 * @ctrl: WDI control value
677 *
678 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
679 *
680 * Return: 0 on message send to ipa, -1 on failure
681 */
682static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
683{
684 struct ipa_msg_meta meta;
685 struct ipa_wlan_msg *ipa_msg;
686 int ret = 0;
687
688 /* WDI enable message to IPA */
689 meta.msg_len = sizeof(*ipa_msg);
690 ipa_msg = qdf_mem_malloc(meta.msg_len);
691 if (ipa_msg == NULL) {
692 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
693 "msg allocation failed");
694 return -ENOMEM;
695 }
696
697 if (ctrl == true)
698 meta.msg_type = WLAN_WDI_ENABLE;
699 else
700 meta.msg_type = WLAN_WDI_DISABLE;
701
702 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
703 "ipa_send_msg(Evt:%d)", meta.msg_type);
704 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
705 if (ret) {
706 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
707 "ipa_send_msg(Evt:%d)-fail=%d",
708 meta.msg_type, ret);
709 qdf_mem_free(ipa_msg);
710 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800711 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800712}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800713
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800714/**
715 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
716 * @hdd_ipa: HDD IPA local context
717 *
718 * Register IPA UC ready callback function to IPA kernel driver
719 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
720 * open WDI pipe after WLAN driver loading finished
721 *
722 * Return: 0 Success
723 * -EPERM Registration fail
724 */
725static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
726{
727 struct ipa_wdi_uc_ready_params uc_ready_param;
728 int ret = 0;
729
730 hdd_ipa->uc_loaded = false;
731 uc_ready_param.priv = (void *)hdd_ipa;
732 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
733 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
734 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
735 "UC Ready CB register fail");
736 return -EPERM;
737 }
738 if (true == uc_ready_param.is_uC_ready) {
739 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "UC Ready");
740 hdd_ipa->uc_loaded = true;
741 } else {
742 ret = hdd_ipa_uc_send_wdi_control_msg(false);
743 }
744
745 return ret;
746}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800747#else
748static void hdd_ipa_uc_get_db_paddr(qdf_dma_addr_t *db_paddr,
749 enum ipa_client_type client)
750{
751 /* Do nothing */
752}
753
754static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
755{
756 hdd_ipa->uc_loaded = true;
757 return 0;
758}
759
760static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
761{
762 return 0;
763}
764#endif
765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800766/**
767 * hdd_ipa_is_enabled() - Is IPA enabled?
768 * @hdd_ctx: Global HDD context
769 *
770 * Return: true if IPA is enabled, false otherwise
771 */
772bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
773{
774 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
775}
776
777/**
778 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
779 * @hdd_ctx: Global HDD context
780 *
781 * Return: true if IPA uC offload is enabled, false otherwise
782 */
783bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
784{
785 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
786}
787
788/**
789 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
790 * @hdd_ctx: Global HDD context
791 *
792 * Return: true if STA mode IPA uC offload is enabled, false otherwise
793 */
794static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
795{
796 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
797}
798
799/**
Guolei Bianca144d82016-11-10 11:07:42 +0800800 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
801 * @hdd_ipa: Global HDD IPA context
802 *
803 * Return: None
804 */
805#ifdef IPA_UC_STA_OFFLOAD
806static inline void hdd_ipa_uc_sta_reset_sta_connected(
807 struct hdd_ipa_priv *hdd_ipa)
808{
809 vos_lock_acquire(&hdd_ipa->event_lock);
810 hdd_ipa->sta_connected = 0;
811 vos_lock_release(&hdd_ipa->event_lock);
812}
813#else
814static inline void hdd_ipa_uc_sta_reset_sta_connected(
815 struct hdd_ipa_priv *hdd_ipa)
816{
817}
818#endif
819
820/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
822 * @hdd_ipa: Global HDD IPA context
823 *
824 * Return: true if pre-filter is enabled, otherwise false
825 */
826static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
827{
828 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
829 HDD_IPA_PRE_FILTER_ENABLE_MASK);
830}
831
832/**
833 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
834 * @hdd_ipa: Global HDD IPA context
835 *
836 * Return: true if IPv6 is enabled, otherwise false
837 */
838static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
839{
840 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
841}
842
843/**
844 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
845 * @hdd_ipa: Global HDD IPA context
846 *
847 * Return: true if resource manager is enabled, otherwise false
848 */
849static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
850{
851 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
852}
853
854/**
855 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
856 * @hdd_ipa: Global HDD IPA context
857 *
858 * Return: true if resource manager is enabled, otherwise false
859 */
860static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
861{
862 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
863}
864
865/**
866 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
867 * @hdd_ipa: Global HDD IPA context
868 *
869 * Return: true if clock scaling is enabled, otherwise false
870 */
871static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
872{
873 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
874 HDD_IPA_CLK_SCALING_ENABLE_MASK |
875 HDD_IPA_RM_ENABLE_MASK);
876}
877
878/**
879 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
880 * @ctext: pointer to hdd context.
881 *
882 * If rt debug enabled, periodically called, and fill debug buffer
883 *
884 * Return: none
885 */
886static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
887{
888 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
889 struct hdd_ipa_priv *hdd_ipa;
890 struct uc_rt_debug_info *dump_info = NULL;
891
892 if (wlan_hdd_validate_context(hdd_ctx))
893 return;
894
895 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530896 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800897 "%s: IPA UC is not enabled", __func__);
898 return;
899 }
900
901 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
902
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530903 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 dump_info = &hdd_ipa->rt_bug_buffer[
905 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
906
Deepthi Gowri6acee342016-10-28 15:00:38 +0530907 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800908 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
909 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
910 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800912 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
913 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800914 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
915 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530916 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917
Anurag Chouhan210db072016-02-22 18:42:15 +0530918 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
920}
921
922/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700923 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 * @hdd_ctx: pointer to hdd context.
925 *
926 * If rt debug enabled, dump debug buffer contents based on requirement
927 *
928 * Return: none
929 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700930static void __hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931{
932 struct hdd_ipa_priv *hdd_ipa;
933 unsigned int dump_count;
934 unsigned int dump_index;
935 struct uc_rt_debug_info *dump_info = NULL;
936
937 if (wlan_hdd_validate_context(hdd_ctx))
938 return;
939
940 hdd_ipa = hdd_ctx->hdd_ipa;
941 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530942 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800943 "%s: IPA UC is not enabled", __func__);
944 return;
945 }
946
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530947 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530949 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800950 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530952 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800953 for (dump_count = 0;
954 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
955 dump_count++) {
956 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
957 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
958 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530959 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530960 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 dump_info->time, dump_info->ipa_excep_count,
962 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800963 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800964 dump_info->rx_destructor_call,
965 dump_info->rx_discard_count);
966 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530967 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530968 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
970}
971
972/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700973 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
974 * __hdd_ipa_uc_rt_debug_host_dump
975 * @hdd_ctx: pointer to hdd context.
976 *
977 * If rt debug enabled, dump debug buffer contents based on requirement
978 *
979 * Return: none
980 */
981void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
982{
983 cds_ssr_protect(__func__);
984 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
985 cds_ssr_unprotect(__func__);
986}
987
988/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
990 * @ctext: pointer to hdd context.
991 *
992 * periodically called by timer expire
993 * will try to alloc dummy memory and detect out of memory condition
994 * if out of memory detected, dump wlan-ipa stats
995 *
996 * Return: none
997 */
998static void hdd_ipa_uc_rt_debug_handler(void *ctext)
999{
1000 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001001 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002 void *dummy_ptr = NULL;
1003
1004 if (wlan_hdd_validate_context(hdd_ctx))
1005 return;
1006
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001007 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb187d542016-11-14 18:10:04 -08001010 hdd_notice("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001011 return;
1012 }
1013
1014 /* Allocate dummy buffer periodically and free immediately. this will
1015 * proactively detect OOM and if allocation fails dump ipa stats
1016 */
1017 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
1018 GFP_KERNEL | GFP_ATOMIC);
1019 if (!dummy_ptr) {
Yun Parkb187d542016-11-14 18:10:04 -08001020 hdd_alert("Dummy alloc fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
1022 hdd_ipa_uc_stat_request(
Krunal Sonibe766b02016-03-10 13:00:44 -08001023 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE), 1);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001024 } else {
1025 kfree(dummy_ptr);
1026 }
1027
Anurag Chouhan210db072016-02-22 18:42:15 +05301028 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 HDD_IPA_UC_RT_DEBUG_PERIOD);
1030}
1031
1032/**
Yun Parkb187d542016-11-14 18:10:04 -08001033 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 * @skb: packet pinter
1035 *
1036 * when free data packet, will be invoked by wlan client and will increase
1037 * free counter
1038 *
1039 * Return: none
1040 */
Jeff Johnsond7720632016-10-05 16:04:32 -07001041static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042{
1043 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301044 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045 "%s: invalid hdd context", __func__);
1046 return;
1047 }
1048
1049 ghdd_ipa->ipa_rx_destructor_count++;
1050}
1051
1052/**
Yun Parkb187d542016-11-14 18:10:04 -08001053 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 * @hdd_ctx: hdd main context
1055 *
1056 * free all rt debugging resources
1057 *
1058 * Return: none
1059 */
1060static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
1061{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001062 struct hdd_ipa_priv *hdd_ipa;
1063
1064 if (wlan_hdd_validate_context(hdd_ctx))
1065 return;
1066
1067 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001068
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301069 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070
1071 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb187d542016-11-14 18:10:04 -08001072 hdd_notice("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 return;
1074 }
1075
Anurag Chouhan210db072016-02-22 18:42:15 +05301076 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001077 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1078 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1079 }
1080 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1081
1082 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301083 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1084 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001085 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301086 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001087}
1088
1089/**
Yun Parkb187d542016-11-14 18:10:04 -08001090 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001091 * @hdd_ctx: hdd main context
1092 *
1093 * alloc and initialize all rt debugging resources
1094 *
1095 * Return: none
1096 */
1097static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
1098{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001099 struct hdd_ipa_priv *hdd_ipa;
1100
1101 if (wlan_hdd_validate_context(hdd_ctx))
1102 return;
1103
1104 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301106 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301108 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 sizeof(struct uc_rt_debug_info) *
1110 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1111 hdd_ipa->ipa_tx_forward = 0;
1112 hdd_ipa->ipa_rx_discard = 0;
1113 hdd_ipa->ipa_rx_net_send_count = 0;
1114 hdd_ipa->ipa_rx_internel_drop_count = 0;
1115 hdd_ipa->ipa_rx_destructor_count = 0;
1116
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001117 /* Reatime debug enable on feature enable */
1118 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb187d542016-11-14 18:10:04 -08001119 hdd_notice("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001120 return;
1121 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001122
1123 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1124 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1125 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1126 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1127
Anurag Chouhan210db072016-02-22 18:42:15 +05301128 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301130 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001131 HDD_IPA_UC_RT_DEBUG_PERIOD);
1132
1133}
1134
1135/**
Yun Parkb187d542016-11-14 18:10:04 -08001136 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1137 * @hdd_ipa: HDD IPA struct
1138 *
1139 * Dump entries in struct hdd_ipa
1140 *
1141 * Return: none
1142 */
1143static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1144{
1145 int i;
1146
1147 /* HDD IPA */
1148 hdd_err("==== HDD IPA ====\n"
1149 "num_iface: %d\n"
1150 "rm_state: %d\n"
1151 "rm_lock: %p\n"
1152 "uc_rm_work: %p\n"
1153 "uc_op_work: %p\n"
1154 "wake_lock: %p\n"
1155 "wake_lock_work: %p\n"
1156 "wake_lock_released: %d\n"
1157 "prod_client: %d\n"
1158 "tx_ref_cnt: %d\n"
1159 "pm_queue_head----\n"
1160 "\thead: %p\n"
1161 "\ttail: %p\n"
1162 "\tqlen: %d\n"
1163 "pm_work: %p\n"
1164 "pm_lock: %p\n"
1165 "suspended: %d\n",
1166 hdd_ipa->num_iface,
1167 hdd_ipa->rm_state,
1168 &hdd_ipa->rm_lock,
1169 &hdd_ipa->uc_rm_work,
1170 &hdd_ipa->uc_op_work,
1171 &hdd_ipa->wake_lock,
1172 &hdd_ipa->wake_lock_work,
1173 hdd_ipa->wake_lock_released,
1174 hdd_ipa->prod_client,
1175 hdd_ipa->tx_ref_cnt.counter,
1176 hdd_ipa->pm_queue_head.head,
1177 hdd_ipa->pm_queue_head.tail,
1178 hdd_ipa->pm_queue_head.qlen,
1179 &hdd_ipa->pm_work,
1180 &hdd_ipa->pm_lock,
1181 hdd_ipa->suspended);
1182 hdd_err("\npending_hw_desc_cnt: %d\n"
1183 "hw_desc_cnt: %d\n"
1184 "q_lock: %p\n"
1185 "freeq_cnt: %d\n"
1186 "free_desc_head----\n"
1187 "\tnext: %p\n"
1188 "\tprev: %p\n"
1189 "pend_q_cnt: %d\n"
1190 "pend_desc_head----\n"
1191 "\tnext: %p\n"
1192 "\tprev: %p\n"
1193 "hdd_ctx: %p\n"
1194 "debugfs_dir: %p\n"
1195 "stats: %p\n"
1196 "ipv4_notifier: %p\n"
1197 "curr_prod_bw: %d\n"
1198 "curr_cons_bw: %d\n"
1199 "activated_fw_pipe: %d\n"
1200 "sap_num_connected_sta: %d\n"
1201 "sta_connected: %d\n",
1202 hdd_ipa->pending_hw_desc_cnt,
1203 hdd_ipa->hw_desc_cnt,
1204 &hdd_ipa->q_lock,
1205 hdd_ipa->freeq_cnt,
1206 hdd_ipa->free_desc_head.next,
1207 hdd_ipa->free_desc_head.prev,
1208 hdd_ipa->pend_q_cnt,
1209 hdd_ipa->pend_desc_head.next,
1210 hdd_ipa->pend_desc_head.prev,
1211 hdd_ipa->hdd_ctx,
1212 hdd_ipa->debugfs_dir,
1213 &hdd_ipa->stats,
1214 &hdd_ipa->ipv4_notifier,
1215 hdd_ipa->curr_prod_bw,
1216 hdd_ipa->curr_cons_bw,
1217 hdd_ipa->activated_fw_pipe,
1218 hdd_ipa->sap_num_connected_sta,
1219 (unsigned int)hdd_ipa->sta_connected
1220 );
1221 hdd_err("\ntx_pipe_handle: 0x%x\n"
1222 "rx_pipe_handle: 0x%x\n"
1223 "resource_loading: %d\n"
1224 "resource_unloading: %d\n"
1225 "pending_cons_req: %d\n"
1226 "pending_event----\n"
1227 "\tanchor.next: %p\n"
1228 "\tanchor.prev: %p\n"
1229 "\tcount: %d\n"
1230 "\tmax_size: %d\n"
1231 "event_lock: %p\n"
1232 "ipa_tx_packets_diff: %d\n"
1233 "ipa_rx_packets_diff: %d\n"
1234 "ipa_p_tx_packets: %d\n"
1235 "ipa_p_rx_packets: %d\n"
1236 "stat_req_reason: %d\n",
1237 hdd_ipa->tx_pipe_handle,
1238 hdd_ipa->rx_pipe_handle,
1239 hdd_ipa->resource_loading,
1240 hdd_ipa->resource_unloading,
1241 hdd_ipa->pending_cons_req,
1242 hdd_ipa->pending_event.anchor.next,
1243 hdd_ipa->pending_event.anchor.prev,
1244 hdd_ipa->pending_event.count,
1245 hdd_ipa->pending_event.max_size,
1246 &hdd_ipa->event_lock,
1247 hdd_ipa->ipa_tx_packets_diff,
1248 hdd_ipa->ipa_rx_packets_diff,
1249 hdd_ipa->ipa_p_tx_packets,
1250 hdd_ipa->ipa_p_rx_packets,
1251 hdd_ipa->stat_req_reason);
1252
1253 hdd_err("assoc_stas_map([id]is_reserved/sta_id): ");
1254 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
1255 hdd_err(" [%d]%d/%d", i,
1256 hdd_ipa->assoc_stas_map[i].is_reserved,
1257 hdd_ipa->assoc_stas_map[i].sta_id);
1258 }
1259}
1260
1261/**
1262 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1263 * @hdd_ipa: HDD IPA struct
1264 *
1265 * Dump entire struct hdd_ipa_sys_pipe
1266 *
1267 * Return: none
1268 */
1269static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1270{
1271 int i;
1272
1273 /* IPA SYS Pipes */
1274 hdd_err("==== IPA SYS Pipes ====\n");
1275
1276 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1277 struct hdd_ipa_sys_pipe *sys_pipe;
1278 struct ipa_sys_connect_params *ipa_sys_params;
1279
1280 sys_pipe = &hdd_ipa->sys_pipe[i];
1281 ipa_sys_params = &sys_pipe->ipa_sys_params;
1282
1283 hdd_err("sys_pipe[%d]----\n"
1284 "\tconn_hdl: 0x%x\n"
1285 "\tconn_hdl_valid: %d\n"
1286 "\tnat_en: %d\n"
1287 "\thdr_len %d\n"
1288 "\thdr_additional_const_len: %d\n"
1289 "\thdr_ofst_pkt_size_valid: %d\n"
1290 "\thdr_ofst_pkt_size: %d\n"
1291 "\thdr_little_endian: %d\n"
1292 "\tmode: %d\n"
1293 "\tclient: %d\n"
1294 "\tdesc_fifo_sz: %d\n"
1295 "\tpriv: %p\n"
1296 "\tnotify: %p\n"
1297 "\tskip_ep_cfg: %d\n"
1298 "\tkeep_ipa_awake: %d\n",
1299 i,
1300 sys_pipe->conn_hdl,
1301 sys_pipe->conn_hdl_valid,
1302 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1303 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1304 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1305 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1306 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1307 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1308 ipa_sys_params->ipa_ep_cfg.mode.mode,
1309 ipa_sys_params->client,
1310 ipa_sys_params->desc_fifo_sz,
1311 ipa_sys_params->priv,
1312 ipa_sys_params->notify,
1313 ipa_sys_params->skip_ep_cfg,
1314 ipa_sys_params->keep_ipa_awake);
1315 }
1316}
1317
1318/**
1319 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1320 * @hdd_ipa: HDD IPA struct
1321 *
1322 * Dump entire struct hdd_ipa_iface_context
1323 *
1324 * Return: none
1325 */
1326static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1327{
1328 int i;
1329
1330 /* IPA Interface Contexts */
1331 hdd_err("==== IPA Interface Contexts ====\n");
1332
1333 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1334 struct hdd_ipa_iface_context *iface_context;
1335
1336 iface_context = &hdd_ipa->iface_context[i];
1337
1338 hdd_err("iface_context[%d]----\n"
1339 "\thdd_ipa: %p\n"
1340 "\tadapter: %p\n"
1341 "\ttl_context: %p\n"
1342 "\tcons_client: %d\n"
1343 "\tprod_client: %d\n"
1344 "\tiface_id: %d\n"
1345 "\tsta_id: %d\n"
1346 "\tinterface_lock: %p\n"
1347 "\tifa_address: 0x%x\n",
1348 i,
1349 iface_context->hdd_ipa,
1350 iface_context->adapter,
1351 iface_context->tl_context,
1352 iface_context->cons_client,
1353 iface_context->prod_client,
1354 iface_context->iface_id,
1355 iface_context->sta_id,
1356 &iface_context->interface_lock,
1357 iface_context->ifa_address);
1358 }
1359}
1360
1361/**
1362 * hdd_ipa_dump_info() - dump HDD IPA struct
1363 * @pHddCtx: hdd main context
1364 *
1365 * Dump entire struct hdd_ipa
1366 *
1367 * Return: none
1368 */
1369void hdd_ipa_dump_info(hdd_context_t *hdd_ctx)
1370{
1371 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1372
1373 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1374 hdd_ipa_dump_sys_pipe(hdd_ipa);
1375 hdd_ipa_dump_iface_context(hdd_ipa);
1376}
1377
1378/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001379 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1380 * enabled
1381 *
1382 * This routine is called to set TX flow info if IPA is enabled
1383 *
1384 * Return: None
1385 */
1386void hdd_ipa_set_tx_flow_info(void)
1387{
1388 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1389 QDF_STATUS status;
1390 hdd_adapter_t *adapter;
1391 hdd_station_ctx_t *pHddStaCtx;
1392 hdd_ap_ctx_t *hdd_ap_ctx;
1393 hdd_hostapd_state_t *hostapd_state;
1394 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1395 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1396 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1397 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1398 const char *p2pMode = "DEV";
1399 hdd_context_t *hdd_ctx;
1400 cds_context_type *cds_ctx;
1401#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1402 uint8_t targetChannel = 0;
1403 uint8_t preAdapterChannel = 0;
1404 uint8_t channel24;
1405 uint8_t channel5;
1406 hdd_adapter_t *preAdapterContext = NULL;
1407 hdd_adapter_t *adapter2_4 = NULL;
1408 hdd_adapter_t *adapter5 = NULL;
1409 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1410#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1411 struct wlan_objmgr_psoc *psoc;
1412
1413 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1414 if (!hdd_ctx) {
1415 cds_err("HDD context is NULL");
1416 return;
1417 }
1418
1419 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1420 if (!cds_ctx) {
1421 cds_err("Invalid CDS Context");
1422 return;
1423 }
1424
1425 psoc = hdd_ctx->hdd_psoc;
1426 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1427 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1428 adapter = adapterNode->pAdapter;
1429 switch (adapter->device_mode) {
1430 case QDF_STA_MODE:
1431 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1432 if (eConnectionState_Associated ==
1433 pHddStaCtx->conn_info.connState) {
1434 staChannel =
1435 pHddStaCtx->conn_info.operationChannel;
1436 qdf_copy_macaddr(&staBssid,
1437 &pHddStaCtx->conn_info.bssId);
1438#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1439 targetChannel = staChannel;
1440#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1441 }
1442 break;
1443 case QDF_P2P_CLIENT_MODE:
1444 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1445 if (eConnectionState_Associated ==
1446 pHddStaCtx->conn_info.connState) {
1447 p2pChannel =
1448 pHddStaCtx->conn_info.operationChannel;
1449 qdf_copy_macaddr(&p2pBssid,
1450 &pHddStaCtx->conn_info.bssId);
1451 p2pMode = "CLI";
1452#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1453 targetChannel = p2pChannel;
1454#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1455 }
1456 break;
1457 case QDF_P2P_GO_MODE:
1458 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1459 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1460 if (hostapd_state->bssState == BSS_START
1461 && hostapd_state->qdf_status ==
1462 QDF_STATUS_SUCCESS) {
1463 p2pChannel = hdd_ap_ctx->operatingChannel;
1464 qdf_copy_macaddr(&p2pBssid,
1465 &adapter->macAddressCurrent);
1466#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1467 targetChannel = p2pChannel;
1468#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1469 }
1470 p2pMode = "GO";
1471 break;
1472 case QDF_SAP_MODE:
1473 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1474 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1475 if (hostapd_state->bssState == BSS_START
1476 && hostapd_state->qdf_status ==
1477 QDF_STATUS_SUCCESS) {
1478 apChannel = hdd_ap_ctx->operatingChannel;
1479 qdf_copy_macaddr(&apBssid,
1480 &adapter->macAddressCurrent);
1481#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1482 targetChannel = apChannel;
1483#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1484 }
1485 break;
1486 case QDF_IBSS_MODE:
1487 default:
1488 break;
1489 }
1490#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1491 if (targetChannel) {
1492 /*
1493 * This is first adapter detected as active
1494 * set as default for none concurrency case
1495 */
1496 if (!preAdapterChannel) {
1497 /* If IPA UC data path is enabled,
1498 * target should reserve extra tx descriptors
1499 * for IPA data path.
1500 * Then host data path should allow less TX
1501 * packet pumping in case IPA
1502 * data path enabled
1503 */
1504 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1505 (QDF_SAP_MODE == adapter->device_mode)) {
1506 adapter->tx_flow_low_watermark =
1507 hdd_ctx->config->TxFlowLowWaterMark +
1508 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1509 } else {
1510 adapter->tx_flow_low_watermark =
1511 hdd_ctx->config->
1512 TxFlowLowWaterMark;
1513 }
1514 adapter->tx_flow_high_watermark_offset =
1515 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1516 cdp_fc_ll_set_tx_pause_q_depth(soc,
1517 adapter->sessionId,
1518 hdd_ctx->config->TxFlowMaxQueueDepth);
1519 cds_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
1520 adapter->device_mode,
1521 targetChannel,
1522 adapter->tx_flow_low_watermark,
1523 adapter->tx_flow_low_watermark +
1524 adapter->tx_flow_high_watermark_offset,
1525 hdd_ctx->config->TxFlowMaxQueueDepth);
1526 preAdapterChannel = targetChannel;
1527 preAdapterContext = adapter;
1528 } else {
1529 /*
1530 * SCC, disable TX flow control for both
1531 * SCC each adapter cannot reserve dedicated
1532 * channel resource, as a result, if any adapter
1533 * blocked OS Q by flow control,
1534 * blocked adapter will lost chance to recover
1535 */
1536 if (preAdapterChannel == targetChannel) {
1537 /* Current adapter */
1538 adapter->tx_flow_low_watermark = 0;
1539 adapter->
1540 tx_flow_high_watermark_offset = 0;
1541 cdp_fc_ll_set_tx_pause_q_depth(soc,
1542 adapter->sessionId,
1543 hdd_ctx->config->
1544 TxHbwFlowMaxQueueDepth);
1545 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1546 hdd_device_mode_to_string(
1547 adapter->device_mode),
1548 adapter->device_mode,
1549 targetChannel,
1550 adapter->tx_flow_low_watermark,
1551 adapter->tx_flow_low_watermark +
1552 adapter->
1553 tx_flow_high_watermark_offset,
1554 hdd_ctx->config->
1555 TxHbwFlowMaxQueueDepth);
1556
1557 if (!preAdapterContext) {
1558 cds_err("SCC: Previous adapter context NULL");
1559 continue;
1560 }
1561
1562 /* Previous adapter */
1563 preAdapterContext->
1564 tx_flow_low_watermark = 0;
1565 preAdapterContext->
1566 tx_flow_high_watermark_offset = 0;
1567 cdp_fc_ll_set_tx_pause_q_depth(soc,
1568 preAdapterContext->sessionId,
1569 hdd_ctx->config->
1570 TxHbwFlowMaxQueueDepth);
1571 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1572 hdd_device_mode_to_string(
1573 preAdapterContext->device_mode
1574 ),
1575 preAdapterContext->device_mode,
1576 targetChannel,
1577 preAdapterContext->
1578 tx_flow_low_watermark,
1579 preAdapterContext->
1580 tx_flow_low_watermark +
1581 preAdapterContext->
1582 tx_flow_high_watermark_offset,
1583 hdd_ctx->config->
1584 TxHbwFlowMaxQueueDepth);
1585 }
1586 /*
1587 * MCC, each adapter will have dedicated
1588 * resource
1589 */
1590 else {
1591 /* current channel is 2.4 */
1592 if (targetChannel <=
1593 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1594 channel24 = targetChannel;
1595 channel5 = preAdapterChannel;
1596 adapter2_4 = adapter;
1597 adapter5 = preAdapterContext;
1598 } else {
1599 /* Current channel is 5 */
1600 channel24 = preAdapterChannel;
1601 channel5 = targetChannel;
1602 adapter2_4 = preAdapterContext;
1603 adapter5 = adapter;
1604 }
1605
1606 if (!adapter5) {
1607 cds_err("MCC: 5GHz adapter context NULL");
1608 continue;
1609 }
1610 adapter5->tx_flow_low_watermark =
1611 hdd_ctx->config->
1612 TxHbwFlowLowWaterMark;
1613 adapter5->
1614 tx_flow_high_watermark_offset =
1615 hdd_ctx->config->
1616 TxHbwFlowHighWaterMarkOffset;
1617 cdp_fc_ll_set_tx_pause_q_depth(soc,
1618 adapter5->sessionId,
1619 hdd_ctx->config->
1620 TxHbwFlowMaxQueueDepth);
1621 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1622 hdd_device_mode_to_string(
1623 adapter5->device_mode),
1624 adapter5->device_mode,
1625 channel5,
1626 adapter5->tx_flow_low_watermark,
1627 adapter5->
1628 tx_flow_low_watermark +
1629 adapter5->
1630 tx_flow_high_watermark_offset,
1631 hdd_ctx->config->
1632 TxHbwFlowMaxQueueDepth);
1633
1634 if (!adapter2_4) {
1635 cds_err("MCC: 2.4GHz adapter context NULL");
1636 continue;
1637 }
1638 adapter2_4->tx_flow_low_watermark =
1639 hdd_ctx->config->
1640 TxLbwFlowLowWaterMark;
1641 adapter2_4->
1642 tx_flow_high_watermark_offset =
1643 hdd_ctx->config->
1644 TxLbwFlowHighWaterMarkOffset;
1645 cdp_fc_ll_set_tx_pause_q_depth(soc,
1646 adapter2_4->sessionId,
1647 hdd_ctx->config->
1648 TxLbwFlowMaxQueueDepth);
1649 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1650 hdd_device_mode_to_string(
1651 adapter2_4->device_mode),
1652 adapter2_4->device_mode,
1653 channel24,
1654 adapter2_4->
1655 tx_flow_low_watermark,
1656 adapter2_4->
1657 tx_flow_low_watermark +
1658 adapter2_4->
1659 tx_flow_high_watermark_offset,
1660 hdd_ctx->config->
1661 TxLbwFlowMaxQueueDepth);
1662
1663 }
1664 }
1665 }
1666 targetChannel = 0;
1667#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1668 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1669 adapterNode = pNext;
1670 }
1671 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1672}
1673
1674/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001675 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001677 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1678 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679 *
1680 * Return: true if IPA is enabled, false otherwise
1681 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001682static void __hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1684{
1685 struct hdd_ipa_priv *hdd_ipa;
1686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001687 *ipa_tx_diff = 0;
1688 *ipa_rx_diff = 0;
1689
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001690 if (wlan_hdd_validate_context(hdd_ctx))
1691 return;
1692
1693 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1694
1695 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1696 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697 return;
1698 }
1699
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301700 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1702 (false == hdd_ipa->resource_loading)) {
1703 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1704 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001705 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706 *ipa_tx_diff, *ipa_rx_diff);
1707 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301708 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001709 return;
1710}
1711
1712/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001713 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1714 * @hdd_ctx: Global HDD context
1715 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1716 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1717 *
1718 * Return: true if IPA is enabled, false otherwise
1719 */
1720void hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
1721 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1722{
1723 cds_ssr_protect(__func__);
1724 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1725 cds_ssr_unprotect(__func__);
1726}
1727
1728/**
1729 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001730 * @adapter: network adapter
1731 * @reason: STAT REQ Reason
1732 *
1733 * Return: None
1734 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001735static void __hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001736{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001737 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001738 struct hdd_ipa_priv *hdd_ipa;
1739
1740 if (!adapter) {
1741 return;
1742 }
1743
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001744 hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
1745
1746 if (wlan_hdd_validate_context(hdd_ctx))
1747 return;
1748
1749 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1750 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1751 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752 return;
1753 }
1754
Yun Parkb187d542016-11-14 18:10:04 -08001755 hdd_debug("STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301756 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1758 (false == hdd_ipa->resource_loading)) {
1759 hdd_ipa->stat_req_reason = reason;
1760 wma_cli_set_command(
1761 (int)adapter->sessionId,
1762 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
1763 0, VDEV_CMD);
1764 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301765 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001766}
1767
1768/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001769 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1770 * @adapter: network adapter
1771 * @reason: STAT REQ Reason
1772 *
1773 * Return: None
1774 */
1775void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
1776{
1777 cds_ssr_protect(__func__);
1778 __hdd_ipa_uc_stat_request(adapter, reason);
1779 cds_ssr_unprotect(__func__);
1780}
1781
1782/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001783 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1784 * @hdd_ipa: Global HDD IPA context
1785 * @sta_add: Should station be added
1786 * @sta_id: ID of the station being queried
1787 *
1788 * Return: true if the station was found
1789 */
1790static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1791 bool sta_add, uint8_t sta_id)
1792{
1793 bool sta_found = false;
1794 uint8_t idx;
1795 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1796 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1797 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1798 sta_found = true;
1799 break;
1800 }
1801 }
1802 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301803 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001804 "%s: STA ID %d already exist, cannot add",
1805 __func__, sta_id);
1806 return sta_found;
1807 }
1808 if (sta_add) {
1809 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1810 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1811 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1812 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1813 return sta_found;
1814 }
1815 }
1816 }
1817 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301818 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001819 "%s: STA ID %d does not exist, cannot delete",
1820 __func__, sta_id);
1821 return sta_found;
1822 }
1823 if (!sta_add) {
1824 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1825 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1826 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1827 hdd_ipa->assoc_stas_map[idx].is_reserved =
1828 false;
1829 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1830 return sta_found;
1831 }
1832 }
1833 }
1834 return sta_found;
1835}
1836
1837/**
1838 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1839 * @hdd_ipa: Global HDD IPA context
1840 *
1841 * Return: 0 on success, negative errno if error
1842 */
1843static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1844{
1845 int result;
1846 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001847 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001848
1849 /* ACTIVATE TX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301850 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001851 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1852 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001853 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1854 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301855 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001856 "%s: Enable TX PIPE fail, code %d",
1857 __func__, result);
1858 return result;
1859 }
1860 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1861 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301862 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 "%s: Resume TX PIPE fail, code %d",
1864 __func__, result);
1865 return result;
1866 }
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001867 cdp_ipa_set_active(soc,
1868 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
1869 true, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001870
1871 /* ACTIVATE RX PIPE */
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301872 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001873 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1874 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1876 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301877 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878 "%s: Enable RX PIPE fail, code %d",
1879 __func__, result);
1880 return result;
1881 }
1882 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1883 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301884 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001885 "%s: Resume RX PIPE fail, code %d",
1886 __func__, result);
1887 return result;
1888 }
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001889 cdp_ipa_set_active(soc,
1890 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
1891 true, false);
Leo Change3e49442015-10-26 20:07:13 -07001892 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893 return 0;
1894}
1895
1896/**
1897 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1898 * @hdd_ipa: Global HDD IPA context
1899 *
1900 * Return: 0 on success, negative errno if error
1901 */
1902static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1903{
1904 int result;
1905
Leo Change3e49442015-10-26 20:07:13 -07001906 hdd_ipa->ipa_pipes_down = true;
1907
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301908 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1910 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301911 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912 "%s: Suspend RX PIPE fail, code %d",
1913 __func__, result);
1914 return result;
1915 }
1916 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1917 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301918 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001919 "%s: Disable RX PIPE fail, code %d",
1920 __func__, result);
1921 return result;
1922 }
1923
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301924 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
1926 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301927 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001928 "%s: Suspend TX PIPE fail, code %d",
1929 __func__, result);
1930 return result;
1931 }
1932 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1933 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301934 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935 "%s: Disable TX PIPE fail, code %d",
1936 __func__, result);
1937 return result;
1938 }
1939
1940 return 0;
1941}
1942
1943/**
1944 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1945 * @hdd_ipa: Global HDD IPA context
1946 *
1947 * Return: 0 on success, negative errno if error
1948 */
1949static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1950{
1951 hdd_ipa->activated_fw_pipe = 0;
1952 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954 /* If RM feature enabled
1955 * Request PROD Resource first
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08001956 * PROD resource may return sync or async manners
1957 */
Yun Park4cab6ee2015-10-27 11:43:40 -07001958 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
1959 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1960 /* RM PROD request sync return
1961 * enable pipe immediately
1962 */
1963 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301964 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001965 "%s: IPA WDI Pipe activation failed",
1966 __func__);
1967 hdd_ipa->resource_loading = false;
1968 return -EBUSY;
1969 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001970 }
1971 } else {
1972 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001973 * Just enabled all the PIPEs
1974 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001975 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301976 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07001977 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001978 __func__);
1979 hdd_ipa->resource_loading = false;
1980 return -EBUSY;
1981 }
1982 hdd_ipa->resource_loading = false;
1983 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001984
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301985 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park4cab6ee2015-10-27 11:43:40 -07001986 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001987 return 0;
1988}
1989
1990/**
1991 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1992 * @hdd_ipa: Global HDD IPA context
1993 *
1994 * Return: None
1995 */
1996static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1997{
1998 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001999 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002000
Yun Park7c4f31b2016-11-30 10:09:21 -08002001 if (!cds_ctx || !cds_ctx->pdev_txrx_ctx) {
2002 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
2003 QDF_ASSERT(0);
2004 return;
2005 }
2006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002007 hdd_ipa->resource_unloading = true;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302008 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW RX PIPE", __func__);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08002009 cdp_ipa_set_active(soc,
2010 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
2011 false, false);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302012 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Disable FW TX PIPE", __func__);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08002013 cdp_ipa_set_active(soc,
2014 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
2015 false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002016}
2017
2018/**
2019 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
2020 * @context: User context registered with TL (the IPA Global context is
2021 * registered
2022 * @rxpkt: Packet containing the notification
2023 * @staid: ID of the station associated with the packet
2024 *
2025 * Return: None
2026 */
2027static void
2028hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
2029{
2030 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302031 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002032
2033 /*
2034 * When SSR is going on or driver is unloading, just return.
2035 */
2036 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302037 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002039
2040 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2041 return;
2042
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302043 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044 __func__, event);
2045
2046 switch (event) {
2047 case IPA_RM_RESOURCE_GRANTED:
2048 /* Differed RM Granted */
2049 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302050 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002051 if ((false == hdd_ipa->resource_unloading) &&
2052 (!hdd_ipa->activated_fw_pipe)) {
2053 hdd_ipa_uc_enable_pipes(hdd_ipa);
2054 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302055 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002056 break;
2057
2058 case IPA_RM_RESOURCE_RELEASED:
2059 /* Differed RM Released */
2060 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061 break;
2062
2063 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302064 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 "%s, invalid event code %d", __func__, event);
2066 break;
2067 }
2068}
2069
2070/**
2071 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2072 * @hdd_ipa: Global HDD IPA context
2073 * @event: IPA resource manager event to be deferred
2074 *
2075 * This function is called when a resource manager event is received
2076 * from firmware in interrupt context. This function will defer the
2077 * handling to the OL RX thread
2078 *
2079 * Return: None
2080 */
2081static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2082{
2083 enum ipa_rm_event event;
2084 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2085 struct uc_rm_work_struct, work);
2086 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2087 struct hdd_ipa_priv, uc_rm_work);
2088
2089 cds_ssr_protect(__func__);
2090 event = uc_rm_work->event;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302091 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002092 "%s, posted event %d", __func__, event);
2093
2094 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2095 cds_ssr_unprotect(__func__);
2096
2097 return;
2098}
2099
2100/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002101 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
2102 * @ipa_ctxt: hdd ipa local context
2103 *
2104 * Will handle IPA UC image loaded indication comes from IPA kernel
2105 *
2106 * Return: None
2107 */
2108static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *ipa_ctxt)
2109{
2110 struct ipa_wdi_out_params pipe_out;
2111
2112 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
2113 if (true == ipa_ctxt->uc_loaded) {
2114 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH, "%s : UC already loaded",
2115 __func__);
2116 return;
2117 }
2118
2119 ipa_ctxt->uc_loaded = true;
2120 /* Connect pipe */
2121 ipa_connect_wdi_pipe(&ipa_ctxt->cons_pipe_in, &pipe_out);
2122 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
2123 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
2124 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2125 "%s : TX PIPE Handle %d, DBPA 0x%llx",
2126 __func__, ipa_ctxt->tx_pipe_handle,
2127 (unsigned long long) pipe_out.uc_door_bell_pa);
2128
2129 ipa_connect_wdi_pipe(&ipa_ctxt->prod_pipe_in, &pipe_out);
2130 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
2131 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
2132 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2133 "%s : RX PIPE Handle %d, DBPA 0x%llx",
2134 __func__, ipa_ctxt->rx_pipe_handle,
2135 (unsigned long long) pipe_out.uc_door_bell_pa);
2136
2137 /* If already any STA connected, enable IPA/FW PIPEs */
2138 if (ipa_ctxt->sap_num_connected_sta) {
2139 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
2140 "Client already connected, enable IPA/FW PIPEs");
2141 hdd_ipa_uc_handle_first_con(ipa_ctxt);
2142 }
2143}
2144
2145/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002146 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2147 * @op_msg: operation message received from firmware
2148 * @usr_ctxt: user context registered with TL (we register the HDD Global
2149 * context)
2150 *
2151 * Return: None
2152 */
2153static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2154{
2155 struct op_msg_type *msg = op_msg;
2156 struct ipa_uc_fw_stats *uc_fw_stat;
2157 struct IpaHwStatsWDIInfoData_t ipa_stat;
2158 struct hdd_ipa_priv *hdd_ipa;
2159 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302160 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002161
2162 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302163 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002164 return;
2165 }
2166
2167 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302168 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002169 "%s, INVALID OPCODE %d", __func__, msg->op_code);
2170 return;
2171 }
2172
2173 hdd_ctx = (hdd_context_t *) usr_ctxt;
2174
2175 /*
2176 * When SSR is going on or driver is unloading, just return.
2177 */
2178 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302179 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302180 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002181 return;
2182 }
2183
2184 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2185
Govind Singhb6a89772016-08-12 11:23:35 +05302186 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002187 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188
2189 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2190 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302191 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002192 hdd_ipa->activated_fw_pipe++;
2193 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2194 hdd_ipa->resource_loading = false;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002195 if (hdd_ipa->wdi_enabled == false) {
2196 hdd_ipa->wdi_enabled = true;
2197 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2198 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2199 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002200 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002201 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002202 if (hdd_ipa->pending_cons_req)
2203 ipa_rm_notify_completion(
2204 IPA_RM_RESOURCE_GRANTED,
2205 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002206 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002207 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302208 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002209 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002210 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302211 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002212 hdd_ipa->activated_fw_pipe--;
2213 if (!hdd_ipa->activated_fw_pipe) {
2214 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002215 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2216 ipa_rm_release_resource(
2217 IPA_RM_RESOURCE_WLAN_PROD);
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08002218 /*
2219 * Sync return success from IPA
2220 * Enable/resume all the PIPEs
2221 */
Yun Park5b635012015-12-02 15:05:01 -08002222 hdd_ipa->resource_unloading = false;
2223 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2224 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002225 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302226 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002227 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002228 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002229 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002230 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302231 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002232 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002233 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002234 "CE RING SIZE: %d\n"
2235 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002236 (unsigned long long)res->ce_sr_base_paddr,
2237 res->ce_sr_ring_size,
2238 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302239 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002240 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002241 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002242 "COMP RING SIZE: %d\n"
2243 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002244 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002245 (unsigned long long)res->tx_comp_ring_base_paddr,
2246 res->tx_comp_ring_size,
2247 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08002248 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302249 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002251 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002252 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002253 "IND RING DBELL : 0x%llx\n"
2254 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002255 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002256 "NUM TX FWD OK : %llu\n"
2257 "NUM TX FWD ERR : %llu",
Yun Park8b2bc4b2016-12-18 16:58:33 -08002258 (unsigned long long)res->rx_rdy_ring_base_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002259 res->rx_rdy_ring_size,
Yun Park8b2bc4b2016-12-18 16:58:33 -08002260 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
2261 (unsigned long long)res->rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002262 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002263 hdd_ipa->stats.num_tx_fwd_ok,
2264 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302265 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002266 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2267 "SAP NUM STAs: %d\n"
2268 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002269 "CONCURRENT MODE: %s\n"
2270 "TX PIPE HDL: 0x%x\n"
2271 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002272 "RSC LOADING : %d\n"
2273 "RSC UNLOADING : %d\n"
2274 "PNDNG CNS RQT : %d",
2275 hdd_ipa->sap_num_connected_sta,
2276 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002277 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002278 hdd_ipa->tx_pipe_handle,
2279 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002280 hdd_ipa->resource_loading,
2281 hdd_ipa->resource_unloading,
2282 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002283
2284 /* STATs from FW */
2285 uc_fw_stat = (struct ipa_uc_fw_stats *)
2286 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302287 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002288 "==== IPA_UC WLAN_FW TX ====\n"
2289 "COMP RING BASE: 0x%x\n"
2290 "COMP RING SIZE: %d\n"
2291 "COMP RING DBELL : 0x%x\n"
2292 "COMP RING DBELL IND VAL : %d\n"
2293 "COMP RING DBELL CACHED VAL : %d\n"
2294 "COMP RING DBELL CACHED VAL : %d\n"
2295 "PKTS ENQ : %d\n"
2296 "PKTS COMP : %d\n"
2297 "IS SUSPEND : %d\n"
2298 "RSVD : 0x%x",
2299 uc_fw_stat->tx_comp_ring_base,
2300 uc_fw_stat->tx_comp_ring_size,
2301 uc_fw_stat->tx_comp_ring_dbell_addr,
2302 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2303 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2304 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2305 uc_fw_stat->tx_pkts_enqueued,
2306 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002307 uc_fw_stat->tx_is_suspend,
2308 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302309 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 "==== IPA_UC WLAN_FW RX ====\n"
2311 "IND RING BASE: 0x%x\n"
2312 "IND RING SIZE: %d\n"
2313 "IND RING DBELL : 0x%x\n"
2314 "IND RING DBELL IND VAL : %d\n"
2315 "IND RING DBELL CACHED VAL : %d\n"
2316 "RDY IND ADDR : 0x%x\n"
2317 "RDY IND CACHE VAL : %d\n"
2318 "RFIL IND : %d\n"
2319 "NUM PKT INDICAT : %d\n"
2320 "BUF REFIL : %d\n"
2321 "NUM DROP NO SPC : %d\n"
2322 "NUM DROP NO BUF : %d\n"
2323 "IS SUSPND : %d\n"
2324 "RSVD : 0x%x\n",
2325 uc_fw_stat->rx_ind_ring_base,
2326 uc_fw_stat->rx_ind_ring_size,
2327 uc_fw_stat->rx_ind_ring_dbell_addr,
2328 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2329 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2330 uc_fw_stat->rx_ind_ring_rdidx_addr,
2331 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2332 uc_fw_stat->rx_refill_idx,
2333 uc_fw_stat->rx_num_pkts_indicated,
2334 uc_fw_stat->rx_buf_refilled,
2335 uc_fw_stat->rx_num_ind_drop_no_space,
2336 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002337 uc_fw_stat->rx_is_suspend,
2338 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002339 /* STATs from IPA */
2340 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302341 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002342 "==== IPA_UC IPA TX ====\n"
2343 "NUM PROCD : %d\n"
2344 "CE DBELL : 0x%x\n"
2345 "NUM DBELL FIRED : %d\n"
2346 "COMP RNG FULL : %d\n"
2347 "COMP RNG EMPT : %d\n"
2348 "COMP RNG USE HGH : %d\n"
2349 "COMP RNG USE LOW : %d\n"
2350 "BAM FIFO FULL : %d\n"
2351 "BAM FIFO EMPT : %d\n"
2352 "BAM FIFO USE HGH : %d\n"
2353 "BAM FIFO USE LOW : %d\n"
2354 "NUM DBELL : %d\n"
2355 "NUM UNEXP DBELL : %d\n"
2356 "NUM BAM INT HDL : 0x%x\n"
2357 "NUM BAM INT NON-RUN : 0x%x\n"
2358 "NUM QMB INT HDL : 0x%x",
2359 ipa_stat.tx_ch_stats.num_pkts_processed,
2360 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2361 ipa_stat.tx_ch_stats.num_db_fired,
2362 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2363 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2364 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2365 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2366 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2367 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2368 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2369 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2370 ipa_stat.tx_ch_stats.num_db,
2371 ipa_stat.tx_ch_stats.num_unexpected_db,
2372 ipa_stat.tx_ch_stats.num_bam_int_handled,
2373 ipa_stat.tx_ch_stats.
2374 num_bam_int_in_non_runnning_state,
2375 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2376
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302377 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002378 "==== IPA_UC IPA RX ====\n"
2379 "MAX OST PKT : %d\n"
2380 "NUM PKT PRCSD : %d\n"
2381 "RNG RP : 0x%x\n"
2382 "COMP RNG FULL : %d\n"
2383 "COMP RNG EMPT : %d\n"
2384 "COMP RNG USE HGH : %d\n"
2385 "COMP RNG USE LOW : %d\n"
2386 "BAM FIFO FULL : %d\n"
2387 "BAM FIFO EMPT : %d\n"
2388 "BAM FIFO USE HGH : %d\n"
2389 "BAM FIFO USE LOW : %d\n"
2390 "NUM DB : %d\n"
2391 "NUM UNEXP DB : %d\n"
2392 "NUM BAM INT HNDL : 0x%x\n",
2393 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2394 ipa_stat.rx_ch_stats.num_pkts_processed,
2395 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2396 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2397 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2398 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2399 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2400 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2401 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2402 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2403 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2404 ipa_stat.rx_ch_stats.num_db,
2405 ipa_stat.rx_ch_stats.num_unexpected_db,
2406 ipa_stat.rx_ch_stats.num_bam_int_handled);
2407 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2408 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2409 /* STATs from FW */
2410 uc_fw_stat = (struct ipa_uc_fw_stats *)
2411 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302412 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002413 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2414 uc_fw_stat->tx_pkts_completed,
2415 hdd_ipa->ipa_p_tx_packets);
2416 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2417 (uc_fw_stat->rx_num_ind_drop_no_space +
2418 uc_fw_stat->rx_num_ind_drop_no_buf +
2419 uc_fw_stat->rx_num_pkts_indicated),
2420 hdd_ipa->ipa_p_rx_packets);
2421
2422 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2423 hdd_ipa->ipa_p_rx_packets =
2424 (uc_fw_stat->rx_num_ind_drop_no_space +
2425 uc_fw_stat->rx_num_ind_drop_no_buf +
2426 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302427 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002428 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2429 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2430 hdd_ipa_uc_loaded_handler(hdd_ipa);
2431 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002432 } else {
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002433 HDD_IPA_LOG(LOGE, "INVALID REASON %d",
2434 hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002435 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302436 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002437}
2438
2439
2440/**
2441 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2442 * @adapter: device adapter instance
2443 * @offload_type: MCC or SCC
2444 * @enable: TX offload enable or disable
2445 *
2446 * Return: none
2447 */
2448static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002449 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002450{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002451 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002452 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002453 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002454 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002455
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002456 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002457 return;
2458
Yun Park8292dcb2016-10-07 16:46:06 -07002459 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002460 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002461
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002462 if (!iface_context) {
2463 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2464 "Interface context is NULL");
2465 return;
2466 }
2467
2468 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002469 /* IPA offload status is already set as desired */
2470 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002471 "%s: (offload_type=%d, vdev_id=%d, enable=%d)",
2472 "IPA offload status is already set",
2473 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002474 return;
2475 }
2476
Yun Park4540e862016-11-10 16:30:06 -08002477 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2478 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2479 "invalid session id: %d, offload_type=%d, enable=%d",
2480 adapter->sessionId, offload_type, enable);
2481 return;
2482 }
2483
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302484 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002485 sizeof(ipa_offload_enable_disable));
2486 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002487 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488 ipa_offload_enable_disable.enable = enable;
2489
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302490 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07002491 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002492 ipa_offload_enable_disable.offload_type,
2493 ipa_offload_enable_disable.vdev_id,
2494 ipa_offload_enable_disable.enable);
2495
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302496 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002497 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2498 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302499 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002500 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
2501 __func__,
2502 ipa_offload_enable_disable.offload_type,
2503 ipa_offload_enable_disable.vdev_id,
2504 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002505 } else {
2506 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002507 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002508 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002509 }
2510}
2511
2512/**
2513 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2514 * @work: uC OP work
2515 *
2516 * Return: None
2517 */
2518static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2519{
2520 struct op_msg_type *msg;
2521 struct uc_op_work_struct *uc_op_work = container_of(work,
2522 struct uc_op_work_struct, work);
2523 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2524
2525 cds_ssr_protect(__func__);
2526
2527 msg = uc_op_work->msg;
2528 uc_op_work->msg = NULL;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302529 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530 "%s, posted msg %d", __func__, msg->op_code);
2531
2532 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2533
2534 cds_ssr_unprotect(__func__);
2535
2536 return;
2537}
2538
2539/**
2540 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2541 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2542 * @op_msg: operation message received from firmware
2543 * @hdd_ctx: Global HDD context
2544 *
2545 * Return: None
2546 */
2547static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2548{
2549 struct hdd_ipa_priv *hdd_ipa;
2550 struct op_msg_type *msg;
2551 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302552 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002553
2554 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302555 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002556 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002557
2558 msg = (struct op_msg_type *)op_msg;
2559 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
2560
2561 if (unlikely(!hdd_ipa))
2562 goto end;
2563
2564 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302565 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002566 __func__, msg->op_code);
2567 goto end;
2568 }
2569
2570 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2571 if (uc_op_work->msg)
2572 /* When the same uC OPCODE is already pended, just return */
2573 goto end;
2574
2575 uc_op_work->msg = msg;
2576 schedule_work(&uc_op_work->work);
2577 return;
2578
2579end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302580 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002581}
2582
2583/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002584 * hdd_ipa_init_uc_op_work - init ipa uc op work
2585 * @work: struct work_struct
2586 * @work_handler: work_handler
2587 *
2588 * Return: none
2589 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002590static void hdd_ipa_init_uc_op_work(struct work_struct *work,
2591 work_func_t work_handler)
2592{
2593 INIT_WORK(work, work_handler);
2594}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002595
2596
2597/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002598 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2599 * @hdd_ctx: Global HDD context
2600 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302601 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002602 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002603QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002604{
2605 struct ipa_wdi_in_params pipe_in;
2606 struct ipa_wdi_out_params pipe_out;
2607 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002608 uint8_t i;
Leo Changfdb45c32016-10-28 11:09:23 -07002609 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002610 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
2611 int ret;
2612 QDF_STATUS stat = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002614 ENTER();
2615
Yun Parkbaa62862017-01-18 13:43:34 -08002616 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002617 if (!pdev || !soc) {
2618 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkbaa62862017-01-18 13:43:34 -08002619 stat = QDF_STATUS_E_FAILURE;
2620 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002621 }
Yun Parkbaa62862017-01-18 13:43:34 -08002622
2623 cdp_ipa_get_resource(soc, (void *)pdev, &ipa_ctxt->ipa_resource);
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002624 if ((ipa_ctxt->ipa_resource.ce_sr_base_paddr == 0) ||
2625 (ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr == 0) ||
2626 (ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr == 0) ||
2627 (ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr == 0)) {
2628 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2629 "IPA UC resource alloc fail");
2630 return QDF_STATUS_E_FAILURE;
2631 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002632 qdf_mem_zero(&ipa_ctxt->cons_pipe_in, sizeof(struct ipa_wdi_in_params));
2633 qdf_mem_zero(&ipa_ctxt->prod_pipe_in, sizeof(struct ipa_wdi_in_params));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302634 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
2635 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002636
Anurag Chouhanffb21542016-02-17 14:33:03 +05302637 qdf_list_create(&ipa_ctxt->pending_event, 1000);
Arun Khandavallicc544b32017-01-30 19:52:16 +05302638
2639 if (!cds_is_driver_recovering()) {
2640 qdf_mutex_create(&ipa_ctxt->event_lock);
2641 qdf_mutex_create(&ipa_ctxt->ipa_lock);
2642 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002643
2644 /* TX PIPE */
2645 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2646 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
2647 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2648 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2649 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
2650 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
2651 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
2652 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
2653 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
2654 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
2655 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
2656 pipe_in.sys.notify = hdd_ipa_i2w_cb;
2657 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302658 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Parkbaa62862017-01-18 13:43:34 -08002659 "IPA RM DISABLED, IPA AWAKE");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002660 pipe_in.sys.keep_ipa_awake = true;
2661 }
2662
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002663 pipe_in.u.dl.comp_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002664 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002665 pipe_in.u.dl.comp_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08002666 ipa_ctxt->ipa_resource.tx_comp_ring_size *
2667 sizeof(qdf_dma_addr_t);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002668 pipe_in.u.dl.ce_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002669 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002670 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
2671 pipe_in.u.dl.ce_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08002672 ipa_ctxt->ipa_resource.ce_sr_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002673 pipe_in.u.dl.num_tx_buffers =
Yun Parkbaa62862017-01-18 13:43:34 -08002674 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002675
Yun Parkbaa62862017-01-18 13:43:34 -08002676 qdf_mem_copy(&ipa_ctxt->cons_pipe_in, &pipe_in,
2677 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002678 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->tx_comp_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08002679 IPA_CLIENT_WLAN1_CONS);
2680
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002681 if (true == ipa_ctxt->uc_loaded) {
2682 /* Connect WDI IPA PIPE */
Yun Parkbaa62862017-01-18 13:43:34 -08002683 ret = ipa_connect_wdi_pipe(&ipa_ctxt->cons_pipe_in, &pipe_out);
2684 if (ret) {
2685 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2686 "ipa_connect_wdi_pipe falied for Tx: ret=%d",
2687 ret);
2688 stat = QDF_STATUS_E_FAILURE;
2689 goto fail_return;
2690 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002691 /* Micro Controller Doorbell register */
Yun Parkbaa62862017-01-18 13:43:34 -08002692 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
2693 "CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
2694 (unsigned int)pipe_out.uc_door_bell_pa,
2695 ipa_ctxt->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002696
2697 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Yun Parkbaa62862017-01-18 13:43:34 -08002698
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002699 /* WLAN TX PIPE Handle */
2700 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
2701 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Yun Parkbaa62862017-01-18 13:43:34 -08002702 "TX : 0x%x, %d, 0x%x, 0x%x, %d, %d, 0x%x",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002703 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
2704 pipe_in.u.dl.comp_ring_size,
2705 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
2706 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
2707 pipe_in.u.dl.ce_ring_size,
2708 pipe_in.u.dl.num_tx_buffers,
2709 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
2710 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711
2712 /* RX PIPE */
2713 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2714 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
2715 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
2716 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
2717 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
2718 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
2719 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
2720 sizeof(struct sps_iovec);
2721 pipe_in.sys.notify = hdd_ipa_w2i_cb;
2722 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302723 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkbaa62862017-01-18 13:43:34 -08002724 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002725 pipe_in.sys.keep_ipa_awake = true;
2726 }
2727
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002728 pipe_in.u.ul.rdy_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002729 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002730 pipe_in.u.ul.rdy_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08002731 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002732 pipe_in.u.ul.rdy_ring_rp_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002733 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002734 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Yun Parkbaa62862017-01-18 13:43:34 -08002735
2736 qdf_mem_copy(&ipa_ctxt->prod_pipe_in, &pipe_in,
2737 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002738 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->rx_ready_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08002739 IPA_CLIENT_WLAN1_PROD);
2740
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002741 if (true == ipa_ctxt->uc_loaded) {
Yun Parkbaa62862017-01-18 13:43:34 -08002742 ret = ipa_connect_wdi_pipe(&ipa_ctxt->prod_pipe_in, &pipe_out);
2743 if (ret) {
2744 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2745 "ipa_connect_wdi_pipe falied for Rx: ret=%d",
2746 ret);
2747 stat = QDF_STATUS_E_FAILURE;
2748 goto fail_return;
2749
2750 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002751 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
2752 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Yun Parkbaa62862017-01-18 13:43:34 -08002753 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
2754 "PROD DB pipe out 0x%x TX PIPE Handle 0x%x",
2755 (unsigned int)pipe_out.uc_door_bell_pa,
2756 ipa_ctxt->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002757 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
2758 "RX : RRBPA 0x%x, RRS %d, PDIPA 0x%x, RDY_DB_PAD 0x%x",
2759 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
2760 pipe_in.u.ul.rdy_ring_size,
2761 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
2762 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
2763 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002764
Yun Parkbaa62862017-01-18 13:43:34 -08002765 cdp_ipa_set_doorbell_paddr(soc, (void *)pdev,
2766 ipa_ctxt->tx_comp_doorbell_paddr,
2767 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002768
Yun Parkbaa62862017-01-18 13:43:34 -08002769 cdp_ipa_register_op_cb(soc, (void *)pdev,
2770 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2771
2772 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
2773 "ipa_uc_op_cb=0x%p, tx_comp_idx_paddr=0x%x, rx_rdy_idx_paddr=0x%x",
2774 pdev->ipa_uc_op_cb,
2775 (unsigned int)pdev->htt_pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr,
2776 (unsigned int)pdev->htt_pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002777
2778 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
Rajeev Kumar217f2172016-01-06 18:11:55 -08002779 hdd_ipa_init_uc_op_work(&ipa_ctxt->uc_op_work[i].work,
Yun Parkbaa62862017-01-18 13:43:34 -08002780 hdd_ipa_uc_fw_op_event_handler);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002781 ipa_ctxt->uc_op_work[i].msg = NULL;
2782 }
2783
Yun Parkbaa62862017-01-18 13:43:34 -08002784fail_return:
2785 EXIT();
2786 return stat;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002787}
2788
Leo Change3e49442015-10-26 20:07:13 -07002789/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002790 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002791 * @hdd_ctx: hdd main context
2792 *
2793 * Force shutdown IPA pipe
2794 * Independent of FW pipe status, IPA pipe shutdonw progress
2795 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2796 * independent from FW pipe status
2797 *
2798 * Return: NONE
2799 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002800static void __hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002801{
2802 struct hdd_ipa_priv *hdd_ipa;
2803
2804 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2805 return;
2806
2807 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2808 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302809 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07002810 "IPA pipes are not down yet, force shutdown");
2811 hdd_ipa_uc_disable_pipes(hdd_ipa);
2812 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302813 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Leo Change3e49442015-10-26 20:07:13 -07002814 "IPA pipes are down, do nothing");
2815 }
2816
2817 return;
2818}
2819
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002820/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002821 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2822 * __hdd_ipa_uc_force_pipe_shutdown
2823 * @hdd_ctx: hdd main context
2824 *
2825 * Force shutdown IPA pipe
2826 * Independent of FW pipe status, IPA pipe shutdonw progress
2827 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2828 * independent from FW pipe status
2829 *
2830 * Return: NONE
2831 */
2832void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
2833{
2834 cds_ssr_protect(__func__);
2835 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2836 cds_ssr_unprotect(__func__);
2837}
2838
2839/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302840 * hdd_ipa_msg_free_fn() - Free an IPA message
2841 * @buff: pointer to the IPA message
2842 * @len: length of the IPA message
2843 * @type: type of IPA message
2844 *
2845 * Return: None
2846 */
2847static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2848{
2849 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "msg type:%d, len:%d", type, len);
2850 ghdd_ipa->stats.num_free_msg++;
2851 qdf_mem_free(buff);
2852}
2853
Govind Singh9c58eba2016-09-02 16:23:06 +05302854/**
jge62037862016-12-09 10:44:33 +08002855 * hdd_ipa_uc_send_evt() - send event to ipa
2856 * @hdd_ctx: pointer to hdd context
2857 * @type: event type
2858 * @mac_addr: pointer to mac address
2859 *
2860 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05302861 *
2862 * Return: 0 - Success
2863 */
jge62037862016-12-09 10:44:33 +08002864static int hdd_ipa_uc_send_evt(hdd_adapter_t *adapter,
2865 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05302866{
jge62037862016-12-09 10:44:33 +08002867 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05302868 struct ipa_msg_meta meta;
2869 struct ipa_wlan_msg *msg;
2870 int ret = 0;
jge62037862016-12-09 10:44:33 +08002871
2872 meta.msg_len = sizeof(struct ipa_wlan_msg);
2873 msg = qdf_mem_malloc(meta.msg_len);
2874 if (msg == NULL) {
2875 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2876 "msg allocation failed");
2877 return -ENOMEM;
2878 }
2879
2880 meta.msg_type = type;
2881 strlcpy(msg->name, adapter->dev->name,
2882 IPA_RESOURCE_NAME_MAX);
2883 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
2884 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
2885 msg->name, meta.msg_type);
2886 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
2887 if (ret) {
2888 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2889 "%s: Evt: %d fail:%d",
2890 msg->name, meta.msg_type, ret);
2891 qdf_mem_free(msg);
2892 return ret;
2893 }
2894
2895 hdd_ipa->stats.num_send_msg++;
2896
2897 return ret;
2898}
2899
2900/**
2901 * hdd_ipa_uc_disconnect_client() - send client disconnect event
2902 * @hdd_ctx: pointer to hdd adapter
2903 *
2904 * Send disconnect client event to IPA driver during SSR
2905 *
2906 * Return: 0 - Success
2907 */
2908static int hdd_ipa_uc_disconnect_client(hdd_adapter_t *adapter)
2909{
2910 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2911 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05302912 int i;
2913
2914 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
2915 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
2916 continue;
2917 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08002918 (!adapter->aStaInfo[i].isDeauthInProgress) &&
2919 hdd_ipa->sap_num_connected_sta) {
2920 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
2921 adapter->aStaInfo[i].macAddrSTA.bytes);
2922 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05302923 }
2924 }
2925
2926 return ret;
2927}
2928
2929/**
jge62037862016-12-09 10:44:33 +08002930 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
2931 * @hdd_ctx: pointer to hdd adapter
2932 *
2933 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05302934 *
2935 * Return: 0 - Success
2936 */
jge62037862016-12-09 10:44:33 +08002937
2938static int hdd_ipa_uc_disconnect_ap(hdd_adapter_t *adapter)
2939{
2940 int ret = 0;
2941
2942 if (adapter->ipa_context)
2943 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
2944 adapter->dev->dev_addr);
2945
2946 return ret;
2947}
2948
jge62037862016-12-09 10:44:33 +08002949/**
2950 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
2951 * @hdd_ctx: pointer to hdd adapter
2952 *
2953 * Send disconnect sta event to IPA driver during SSR
2954 *
2955 * Return: 0 - Success
2956 */
2957static int hdd_ipa_uc_disconnect_sta(hdd_adapter_t *adapter)
2958{
2959 hdd_station_ctx_t *pHddStaCtx;
2960 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2961 int ret = 0;
2962
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002963 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08002964 hdd_ipa->sta_connected) {
2965 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2966 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002967 pHddStaCtx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08002968 }
2969
2970 return ret;
2971}
jge62037862016-12-09 10:44:33 +08002972
2973/**
2974 * hdd_ipa_uc_disconnect() - send disconnect ipa event
2975 * @hdd_ctx: pointer to hdd context
2976 *
2977 * Send disconnect event to IPA driver during SSR
2978 *
2979 * Return: 0 - Success
2980 */
2981static int hdd_ipa_uc_disconnect(hdd_context_t *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05302982{
2983 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
2984 QDF_STATUS status;
2985 hdd_adapter_t *adapter;
2986 int ret = 0;
2987
Govind Singh9c58eba2016-09-02 16:23:06 +05302988 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
2989 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
2990 adapter = adapter_node->pAdapter;
jge62037862016-12-09 10:44:33 +08002991 if (adapter->device_mode == QDF_SAP_MODE) {
2992 hdd_ipa_uc_disconnect_client(adapter);
2993 hdd_ipa_uc_disconnect_ap(adapter);
2994 } else if (adapter->device_mode == QDF_STA_MODE) {
2995 hdd_ipa_uc_disconnect_sta(adapter);
2996 }
2997
Govind Singh9c58eba2016-09-02 16:23:06 +05302998 status = hdd_get_next_adapter(
2999 hdd_ctx, adapter_node, &next);
3000 adapter_node = next;
3001 }
3002
3003 return ret;
3004}
3005
3006/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003007 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003008 *
3009 * Deinit basic IPA UC host side to be in sync reloaded FW during
3010 * SSR
3011 *
3012 * Return: 0 - Success
3013 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003014static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003015{
3016 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3017 int idx;
3018 struct hdd_ipa_iface_context *iface_context;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303019 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003020
Arun Khandavallicc544b32017-01-30 19:52:16 +05303021 if (!hdd_ipa)
3022 return 0;
3023
3024 hdd_ctx = hdd_ipa->hdd_ctx;
3025 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003026 return 0;
3027
jge62037862016-12-09 10:44:33 +08003028 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303029 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003030
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003031 /* Clean up HDD IPA interfaces */
3032 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3033 (idx < HDD_IPA_MAX_IFACE); idx++) {
3034 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003035 if (iface_context->adapter && iface_context->adapter->magic ==
3036 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003037 hdd_ipa_cleanup_iface(iface_context);
3038 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003039 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003040 /* After SSR, wlan driver reloads FW again. But we need to protect
3041 * IPA submodule during SSR transient state. So deinit basic IPA
3042 * UC host side to be in sync with reloaded FW during SSR
3043 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08003044 if (!hdd_ipa->ipa_pipes_down)
3045 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003046
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303047 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003048 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3049 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3050 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3051 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303052 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003053
Arun Khandavallicc544b32017-01-30 19:52:16 +05303054 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
3055 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
3056 __func__, hdd_ipa->tx_pipe_handle);
3057 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
3058
3059 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
3060 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
3061 __func__, hdd_ipa->rx_pipe_handle);
3062 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
3063
Guolei Bianca144d82016-11-10 11:07:42 +08003064 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3065 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3066
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003067 /* Full IPA driver cleanup not required since wlan driver is now
3068 * unloaded and reloaded after SSR.
3069 */
3070 return 0;
3071}
3072
3073/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003074 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3075 *
3076 * Deinit basic IPA UC host side to be in sync reloaded FW during
3077 * SSR
3078 *
3079 * Return: 0 - Success
3080 */
3081int hdd_ipa_uc_ssr_deinit(void)
3082{
3083 int ret;
3084
3085 cds_ssr_protect(__func__);
3086 ret = __hdd_ipa_uc_ssr_deinit();
3087 cds_ssr_unprotect(__func__);
3088
3089 return ret;
3090}
3091
3092/**
3093 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003094 *
3095 * Init basic IPA UC host side to be in sync with reloaded FW after
3096 * SSR to resume IPA UC operations
3097 *
3098 * Return: 0 - Success
3099 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303100static int __hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003102
Arun Khandavallicc544b32017-01-30 19:52:16 +05303103 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3104 int i;
3105 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303106
3107 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3108 return 0;
3109
Arun Khandavallicc544b32017-01-30 19:52:16 +05303110 /* Create the interface context */
3111 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3112 iface_context = &hdd_ipa->iface_context[i];
3113 iface_context->hdd_ipa = hdd_ipa;
3114 iface_context->cons_client =
3115 hdd_ipa_adapter_2_client[i].cons_client;
3116 iface_context->prod_client =
3117 hdd_ipa_adapter_2_client[i].prod_client;
3118 iface_context->iface_id = i;
3119 iface_context->adapter = NULL;
3120 }
3121 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3122 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3123 hdd_ipa->vdev_offload_enabled[i] = false;
3124 }
3125
3126 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3127 hdd_ipa->resource_loading = false;
3128 hdd_ipa->resource_unloading = false;
3129 hdd_ipa->sta_connected = 0;
3130 hdd_ipa->ipa_pipes_down = true;
3131 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303132 }
3133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003134 return 0;
3135}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003136
3137/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003138 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3139 *
3140 * Init basic IPA UC host side to be in sync with reloaded FW after
3141 * SSR to resume IPA UC operations
3142 *
3143 * Return: 0 - Success
3144 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303145int hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003146{
3147 int ret;
3148
3149 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303150 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003151 cds_ssr_unprotect(__func__);
3152
3153 return ret;
3154}
3155
3156/**
3157 * __hdd_ipa_tx_packet_ipa() - send packet to IPA
Leo Chang3bc8fed2015-11-13 10:59:47 -08003158 * @hdd_ctx: Global HDD context
3159 * @skb: skb sent to IPA
3160 * @session_id: send packet instance session id
3161 *
3162 * Send TX packet which generated by system to IPA.
3163 * This routine only will be used for function verification
3164 *
3165 * Return: NULL packet sent to IPA properly
3166 * NULL invalid packet drop
3167 * skb packet not sent to IPA. legacy data path should handle
3168 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003169static struct sk_buff *__hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08003170 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07003171{
Leo Chang3bc8fed2015-11-13 10:59:47 -08003172 struct ipa_header *ipa_header;
3173 struct frag_header *frag_header;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003174 struct hdd_ipa_priv *hdd_ipa;
3175
3176 if (wlan_hdd_validate_context(hdd_ctx))
3177 return skb;
3178
3179 hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08003180
3181 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3182 return skb;
3183
Leo Chang07b28f62016-05-11 12:29:22 -07003184 if (!hdd_ipa)
3185 return skb;
3186
3187 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
3188 return skb;
3189
Leo Changcc923e22016-06-16 15:29:03 -07003190 if (skb_headroom(skb) <
3191 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07003192 return skb;
3193
Leo Chang3bc8fed2015-11-13 10:59:47 -08003194 ipa_header = (struct ipa_header *) skb_push(skb,
3195 sizeof(struct ipa_header));
3196 if (!ipa_header) {
3197 /* No headroom, legacy */
3198 return skb;
3199 }
3200 memset(ipa_header, 0, sizeof(*ipa_header));
3201 ipa_header->vdev_id = 0;
3202
3203 frag_header = (struct frag_header *) skb_push(skb,
3204 sizeof(struct frag_header));
3205 if (!frag_header) {
3206 /* No headroom, drop */
3207 kfree_skb(skb);
3208 return NULL;
3209 }
3210 memset(frag_header, 0, sizeof(*frag_header));
3211 frag_header->length = skb->len - sizeof(struct frag_header)
3212 - sizeof(struct ipa_header);
3213
3214 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
3215 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07003216}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217
3218/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003219 * hdd_ipa_tx_packet_ipa() - SSR wrapper for __hdd_ipa_tx_packet_ipa
3220 * @hdd_ctx: Global HDD context
3221 * @skb: skb sent to IPA
3222 * @session_id: send packet instance session id
3223 *
3224 * Send TX packet which generated by system to IPA.
3225 * This routine only will be used for function verification
3226 *
3227 * Return: NULL packet sent to IPA properly
3228 * NULL invalid packet drop
3229 * skb packet not sent to IPA. legacy data path should handle
3230 */
3231struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
3232 struct sk_buff *skb, uint8_t session_id)
3233{
3234 struct sk_buff *ret;
3235
3236 cds_ssr_protect(__func__);
3237 ret = __hdd_ipa_tx_packet_ipa(hdd_ctx, skb, session_id);
3238 cds_ssr_unprotect(__func__);
3239
3240 return ret;
3241}
3242
3243/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003244 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3245 * @work: scheduled work
3246 *
3247 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3248 * not want to immediately release the wake lock since the system
3249 * would then potentially try to suspend when there is a healthy data
3250 * rate. Deferred work is scheduled and this function handles the
3251 * work. When this function is called, if the IPA resource is still
3252 * released then we release the wake lock.
3253 *
3254 * Return: None
3255 */
3256static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3257{
3258 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3259 struct hdd_ipa_priv,
3260 wake_lock_work);
3261
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303262 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263
3264 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3265 goto end;
3266
3267 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303268 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003269 WIFI_POWER_EVENT_WAKELOCK_IPA);
3270
3271end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303272 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273}
3274
3275/**
3276 * hdd_ipa_rm_request() - Request resource from IPA
3277 * @hdd_ipa: Global HDD IPA context
3278 *
3279 * Return: 0 on success, negative errno on error
3280 */
3281static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3282{
3283 int ret = 0;
3284
3285 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3286 return 0;
3287
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303288 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289
3290 switch (hdd_ipa->rm_state) {
3291 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303292 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003293 return 0;
3294 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303295 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003296 return -EINPROGRESS;
3297 case HDD_IPA_RM_RELEASED:
3298 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3299 break;
3300 }
3301
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303302 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003303
3304 ret = ipa_rm_inactivity_timer_request_resource(
3305 IPA_RM_RESOURCE_WLAN_PROD);
3306
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303307 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308 if (ret == 0) {
3309 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3310 hdd_ipa->stats.num_rm_grant_imm++;
3311 }
3312
3313 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3314 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303315 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003316 WIFI_POWER_EVENT_WAKELOCK_IPA);
3317 hdd_ipa->wake_lock_released = false;
3318 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303319 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003320
3321 return ret;
3322}
3323
3324/**
3325 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3326 * @hdd_ipa: Global HDD IPA context
3327 *
3328 * Return: 0 if resources released, negative errno otherwise
3329 */
3330static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3331{
3332 int ret = 0;
3333
3334 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3335 return 0;
3336
3337 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3338 return -EAGAIN;
3339
3340 spin_lock_bh(&hdd_ipa->q_lock);
3341 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
3342 (hdd_ipa->pending_hw_desc_cnt || hdd_ipa->pend_q_cnt)) {
3343 spin_unlock_bh(&hdd_ipa->q_lock);
3344 return -EAGAIN;
3345 }
3346 spin_unlock_bh(&hdd_ipa->q_lock);
3347
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303348 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003349
Nirav Shahcbc6d722016-03-01 16:24:53 +05303350 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303351 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352 return -EAGAIN;
3353 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303354 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303356 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357 switch (hdd_ipa->rm_state) {
3358 case HDD_IPA_RM_GRANTED:
3359 break;
3360 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303361 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003362 return -EINPROGRESS;
3363 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303364 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 return 0;
3366 }
3367
3368 /* IPA driver returns immediately so set the state here to avoid any
3369 * race condition.
3370 */
3371 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3372 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303373 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374
3375 ret =
3376 ipa_rm_inactivity_timer_release_resource(IPA_RM_RESOURCE_WLAN_PROD);
3377
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303378 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379 if (unlikely(ret != 0)) {
3380 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3381 WARN_ON(1);
3382 }
3383
3384 /*
3385 * If wake_lock is released immediately, kernel would try to suspend
3386 * immediately as well, Just avoid ping-pong between suspend-resume
3387 * while there is healthy amount of data transfer going on by
3388 * releasing the wake_lock after some delay.
3389 */
3390 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3391 msecs_to_jiffies
3392 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3393
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303394 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003395
3396 return ret;
3397}
3398
3399/**
3400 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3401 * @user_data: user data registered with IPA
3402 * @event: the IPA resource manager event that occurred
3403 * @data: the data associated with the event
3404 *
3405 * Return: None
3406 */
3407static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3408 unsigned long data)
3409{
3410 struct hdd_ipa_priv *hdd_ipa = user_data;
3411
3412 if (unlikely(!hdd_ipa))
3413 return;
3414
3415 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3416 return;
3417
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303418 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003419
3420 switch (event) {
3421 case IPA_RM_RESOURCE_GRANTED:
3422 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3423 /* RM Notification comes with ISR context
3424 * it should be serialized into work queue to avoid
3425 * ISR sleep problem
3426 */
3427 hdd_ipa->uc_rm_work.event = event;
3428 schedule_work(&hdd_ipa->uc_rm_work.work);
3429 break;
3430 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303431 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303433 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 hdd_ipa->stats.num_rm_grant++;
3435 break;
3436
3437 case IPA_RM_RESOURCE_RELEASED:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303438 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439 hdd_ipa->resource_unloading = false;
3440 break;
3441
3442 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303443 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003444 break;
3445 }
3446}
3447
3448/**
3449 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3450 *
3451 * Callback function registered with IPA that is called when IPA wants
3452 * to release the WLAN consumer resource
3453 *
3454 * Return: 0 if the request is granted, negative errno otherwise
3455 */
3456static int hdd_ipa_rm_cons_release(void)
3457{
3458 return 0;
3459}
3460
3461/**
3462 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3463 *
3464 * Callback function registered with IPA that is called when IPA wants
3465 * to access the WLAN consumer resource
3466 *
3467 * Return: 0 if the request is granted, negative errno otherwise
3468 */
3469static int hdd_ipa_rm_cons_request(void)
3470{
Yun Park4d8b60a2015-10-22 13:59:32 -07003471 int ret = 0;
3472
3473 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303474 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003475 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476 __func__);
3477 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003478 ret = -EINPROGRESS;
3479 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303480 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003481 "%s: IPA resource unloading in progress",
3482 __func__);
3483 ghdd_ipa->pending_cons_req = true;
3484 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003486
3487 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488}
3489
3490/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003491 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 * @hdd_ctx: Global HDD context
3493 * @tx_packets: Number of packets transmitted in the last sample period
3494 * @rx_packets: Number of packets received in the last sample period
3495 *
3496 * Return: 0 on success, negative errno on error
3497 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003498static int __hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 uint64_t rx_packets)
3500{
3501 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003502 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003503 struct ipa_rm_perf_profile profile;
3504 int ret;
3505
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003506 if (wlan_hdd_validate_context(hdd_ctx))
3507 return 0;
3508
3509 hdd_ipa = hdd_ctx->hdd_ipa;
3510
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003511 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3512 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3513 return 0;
3514
3515 memset(&profile, 0, sizeof(profile));
3516
3517 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3518 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3519 else if (tx_packets >
3520 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3521 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3522 else
3523 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3524
3525 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3526 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3527 else if (rx_packets >
3528 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3529 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3530 else
3531 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3532
Yun Parkec845302016-12-15 09:22:57 -08003533 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534 "CONS perf curr: %d, next: %d",
3535 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003536 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003537 "PROD perf curr: %d, next: %d",
3538 hdd_ipa->curr_prod_bw, next_prod_bw);
3539
3540 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003541 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542 hdd_ipa->curr_cons_bw, next_cons_bw);
3543 profile.max_supported_bandwidth_mbps = next_cons_bw;
3544 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
3545 &profile);
3546 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003547 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003548
3549 return ret;
3550 }
3551 hdd_ipa->curr_cons_bw = next_cons_bw;
3552 hdd_ipa->stats.num_cons_perf_req++;
3553 }
3554
3555 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003556 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 hdd_ipa->curr_prod_bw, next_prod_bw);
3558 profile.max_supported_bandwidth_mbps = next_prod_bw;
3559 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
3560 &profile);
3561 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003562 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003563 return ret;
3564 }
3565 hdd_ipa->curr_prod_bw = next_prod_bw;
3566 hdd_ipa->stats.num_prod_perf_req++;
3567 }
3568
3569 return 0;
3570}
3571
3572/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003573 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3574 * @hdd_ctx: Global HDD context
3575 * @tx_packets: Number of packets transmitted in the last sample period
3576 * @rx_packets: Number of packets received in the last sample period
3577 *
3578 * Return: 0 on success, negative errno on error
3579 */
3580int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
3581 uint64_t rx_packets)
3582{
3583 int ret;
3584
3585 cds_ssr_protect(__func__);
3586 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3587 cds_ssr_unprotect(__func__);
3588
3589 return ret;
3590}
3591
3592/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003593 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3594 * @work: struct work_struct
3595 * @work_handler: work_handler
3596 *
3597 * Return: none
3598 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003599static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3600 work_func_t work_handler)
3601{
3602 INIT_WORK(work, work_handler);
3603}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003604
3605/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003606 * hdd_ipa_setup_rm() - Setup IPA resource management
3607 * @hdd_ipa: Global HDD IPA context
3608 *
3609 * Return: 0 on success, negative errno on error
3610 */
3611static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3612{
3613 struct ipa_rm_create_params create_params = { 0 };
3614 int ret;
3615
3616 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3617 return 0;
3618
Rajeev Kumar217f2172016-01-06 18:11:55 -08003619 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3620 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621 memset(&create_params, 0, sizeof(create_params));
3622 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3623 create_params.reg_params.user_data = hdd_ipa;
3624 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3625 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3626
3627 ret = ipa_rm_create_resource(&create_params);
3628 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303629 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003630 "Create RM resource failed: %d", ret);
3631 goto setup_rm_fail;
3632 }
3633
3634 memset(&create_params, 0, sizeof(create_params));
3635 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3636 create_params.request_resource = hdd_ipa_rm_cons_request;
3637 create_params.release_resource = hdd_ipa_rm_cons_release;
3638 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3639
3640 ret = ipa_rm_create_resource(&create_params);
3641 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303642 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003643 "Create RM CONS resource failed: %d", ret);
3644 goto delete_prod;
3645 }
3646
3647 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3648 IPA_RM_RESOURCE_APPS_CONS);
3649
3650 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3651 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3652 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303653 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003654 ret);
3655 goto timer_init_failed;
3656 }
3657
3658 /* Set the lowest bandwidth to start with */
3659 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3660
3661 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303662 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003663 "Set perf level failed: %d", ret);
3664 goto set_perf_failed;
3665 }
3666
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303667 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003668 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3669 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303670 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003671 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3672 hdd_ipa->wake_lock_released = true;
3673 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3674
3675 return ret;
3676
3677set_perf_failed:
3678 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3679
3680timer_init_failed:
3681 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3682
3683delete_prod:
3684 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3685
3686setup_rm_fail:
3687 return ret;
3688}
3689
3690/**
3691 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3692 * @hdd_ipa: Global HDD IPA context
3693 *
3694 * Destroys all resources associated with the IPA resource manager
3695 *
3696 * Return: None
3697 */
3698static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3699{
3700 int ret;
3701
3702 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3703 return;
3704
3705 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303706 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707
3708#ifdef WLAN_OPEN_SOURCE
3709 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
3710#endif
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303711 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712
3713 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3714
3715 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3716 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303717 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003718 "RM PROD resource delete failed %d", ret);
3719
3720 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3721 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303722 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 "RM CONS resource delete failed %d", ret);
3724}
3725
3726/**
3727 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3728 * @skb: network buffer
3729 * @adapter: network adapter
3730 *
3731 * Called when a network buffer is received which should not be routed
3732 * to the IPA module.
3733 *
3734 * Return: None
3735 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303736static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737 hdd_adapter_t *adapter)
3738{
3739 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3740 unsigned int cpu_index;
3741
3742 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303743 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_LOW, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003744 adapter);
3745 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003746 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747 return;
3748 }
3749
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003750 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003752 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003753 return;
3754 }
3755
3756 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3757 skb->dev = adapter->dev;
3758 skb->protocol = eth_type_trans(skb, skb->dev);
3759 skb->ip_summed = CHECKSUM_NONE;
3760
3761 cpu_index = wlan_hdd_get_cpu();
3762
3763 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
3764 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
3765 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
3766 else
3767 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
3768
3769 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
3770 adapter->dev->last_rx = jiffies;
3771}
3772
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003773/**
Leo Chang69c39692016-10-12 20:11:12 -07003774 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3775 * @hdd_ipa: pointer to hdd ipa context
3776 * @adapter: network adapter
3777 * @skb: data pointer
3778 *
3779 * if exception packet has set forward bit, copied new packet should be
3780 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3781 * put into pm queue and tx procedure will be differed
3782 *
3783 * Return: None
3784 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003785static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
3786 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003787{
Leo Chang69c39692016-10-12 20:11:12 -07003788 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3789
Leo Chang69c39692016-10-12 20:11:12 -07003790 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
3791 /* WLAN subsystem is in suspend, put int queue */
3792 if (hdd_ipa->suspended) {
3793 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3794 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3795 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003796 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3797 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003798 pm_tx_cb->exception = true;
3799 pm_tx_cb->adapter = adapter;
3800 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003801 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003802 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3803 hdd_ipa->stats.num_tx_queued++;
3804 } else {
3805 /* Resume, put packet into WLAN TX */
3806 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003807 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003808 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3809 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003810 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003811 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003812 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003813 hdd_ipa->ipa_tx_forward++;
3814 }
3815 }
3816}
3817
3818/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003819 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3820 * @hdd_ipa: pointer to HDD IPA struct
3821 * @adapter: hdd adapter pointer
3822 * @desc: Firmware descriptor
3823 * @skb: Data buffer
3824 *
3825 * Return:
3826 * HDD_IPA_FORWARD_PKT_NONE
3827 * HDD_IPA_FORWARD_PKT_DISCARD
3828 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3829 *
3830 */
3831
3832static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3833 struct hdd_ipa_priv *hdd_ipa,
3834 hdd_adapter_t *adapter,
3835 uint8_t desc,
3836 qdf_nbuf_t skb)
3837{
3838 int ret = HDD_IPA_FORWARD_PKT_NONE;
3839
3840 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303841 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003842 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
3843 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303844 /* Drop the packet*/
3845 hdd_ipa->stats.num_tx_fwd_err++;
3846 kfree_skb(skb);
3847 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3848 return ret;
3849 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003850 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3851 "Forward packet to Tx (fw_desc=%d)", desc);
3852 hdd_ipa->ipa_tx_forward++;
3853
3854 if ((desc & FW_RX_DESC_DISCARD_M)) {
3855 hdd_ipa_forward(hdd_ipa, adapter, skb);
3856 hdd_ipa->ipa_rx_internel_drop_count++;
3857 hdd_ipa->ipa_rx_discard++;
3858 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3859 } else {
3860 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
3861 if (cloned_skb)
3862 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3863 else
3864 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3865 "%s: tx skb alloc failed",
3866 __func__);
3867 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3868 }
3869 }
3870
3871 return ret;
3872}
3873
3874/**
Leo Chang69c39692016-10-12 20:11:12 -07003875 * hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876 * @priv: pointer to private data registered with IPA (we register a
3877 * pointer to the global IPA context)
3878 * @evt: the IPA event which triggered the callback
3879 * @data: data associated with the event
3880 *
3881 * Return: None
3882 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003883static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884 unsigned long data)
3885{
3886 struct hdd_ipa_priv *hdd_ipa = NULL;
3887 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303888 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003889 uint8_t iface_id;
3890 uint8_t session_id;
3891 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003892 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003893 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003894
3895 hdd_ipa = (struct hdd_ipa_priv *)priv;
3896
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003897 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3898 return;
3899
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 switch (evt) {
3901 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303902 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003903
3904 /*
3905 * When SSR is going on or driver is unloading,
3906 * just drop the packets.
3907 */
3908 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
3909 if (0 != status) {
3910 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3911 "Invalid context: drop packet");
3912 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3913 kfree_skb(skb);
3914 return;
3915 }
3916
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3918 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003919 iface_id = hdd_ipa->vdev_to_iface[session_id];
Govind Singhb6a89772016-08-12 11:23:35 +05303920 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921 "IPA_RECEIVE: session_id=%u, iface_id=%u",
3922 session_id, iface_id);
3923 } else {
3924 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
3925 }
3926
3927 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303928 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 "IPA_RECEIVE: Invalid iface_id: %u",
3930 iface_id);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303931 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_INFO_HIGH,
Yun Parkb187d542016-11-14 18:10:04 -08003932 "w2i -- skb",
3933 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003935 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003936 return;
3937 }
3938
3939 iface_context = &hdd_ipa->iface_context[iface_id];
3940 adapter = iface_context->adapter;
3941
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303942 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003943 "w2i -- skb",
3944 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3946 hdd_ipa->stats.num_rx_excep++;
3947 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
3948 } else {
3949 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
3950 }
3951
3952 iface_context->stats.num_rx_ipa_excep++;
3953
3954 /* Disable to forward Intra-BSS Rx packets when
3955 * ap_isolate=1 in hostapd.conf
3956 */
Yun Park046101c2016-09-02 15:32:14 -07003957 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 /*
3959 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
3960 * all Rx packets to IPA uC, which need to be forwarded
3961 * to other interface.
3962 * And, IPA driver will send back to WLAN host driver
3963 * through exception pipe with fw_desc field set by FW.
3964 * Here we are checking fw_desc field for FORWARD bit
3965 * set, and forward to Tx. Then copy to kernel stack
3966 * only when DISCARD bit is not set.
3967 */
3968 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003969 if (HDD_IPA_FORWARD_PKT_DISCARD ==
3970 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
3971 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08003972 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303974 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 "Intra-BSS FWD is disabled-skip forward to Tx");
3976 }
3977
3978 hdd_ipa_send_skb_to_network(skb, adapter);
3979 break;
3980
3981 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303982 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 "w2i cb wrong event: 0x%x", evt);
3984 return;
3985 }
3986}
3987
3988/**
Yun Parkf8d6a122016-10-11 15:49:43 -07003989 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
3990 * @priv: pointer to private data registered with IPA (we register a
3991 * pointer to the global IPA context)
3992 * @evt: the IPA event which triggered the callback
3993 * @data: data associated with the event
3994 *
3995 * Return: None
3996 */
3997static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
3998 unsigned long data)
3999{
4000 cds_ssr_protect(__func__);
4001 __hdd_ipa_w2i_cb(priv, evt, data);
4002 cds_ssr_unprotect(__func__);
4003}
4004
4005/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004006 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4007 * @skb: packet buffer which was transmitted
4008 *
4009 * Return: None
4010 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304011void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012{
4013 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4014
Govind Singhb6a89772016-08-12 11:23:35 +05304015 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "%p",
Nirav Shahcbc6d722016-03-01 16:24:53 +05304016 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004017 /* FIXME: This is broken; PRIV_DATA is now 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304018 ipa_free_skb((struct ipa_rx_data *)
4019 wlan_hdd_stub_priv_to_addr(QDF_NBUF_CB_TX_IPA_PRIV(skb)));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020
4021 hdd_ipa->stats.num_tx_comp_cnt++;
4022
4023 atomic_dec(&hdd_ipa->tx_ref_cnt);
4024
4025 hdd_ipa_rm_try_release(hdd_ipa);
4026}
4027
4028/**
4029 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4030 * @iface_context: interface-specific IPA context
4031 * @ipa_tx_desc: packet data descriptor
4032 *
4033 * Return: None
4034 */
4035static void hdd_ipa_send_pkt_to_tl(
4036 struct hdd_ipa_iface_context *iface_context,
4037 struct ipa_rx_data *ipa_tx_desc)
4038{
4039 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004040 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304041 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004042
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304043 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044 adapter = iface_context->adapter;
4045 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304046 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047 ipa_free_skb(ipa_tx_desc);
4048 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304049 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 hdd_ipa_rm_try_release(hdd_ipa);
4051 return;
4052 }
4053
4054 /*
4055 * During CAC period, data packets shouldn't be sent over the air so
4056 * drop all the packets here
4057 */
4058 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4059 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304060 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 iface_context->stats.num_tx_cac_drop++;
4062 hdd_ipa_rm_try_release(hdd_ipa);
4063 return;
4064 }
4065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004066 ++adapter->stats.tx_packets;
4067
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304068 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069
4070 skb = ipa_tx_desc->skb;
4071
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304072 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304073 qdf_nbuf_ipa_owned_set(skb);
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004074 /* FIXME: This is broken. No such field in cb any more:
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08004075 * NBUF_CALLBACK_FN(skb) = hdd_ipa_nbuf_cb;
4076 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304078 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004079 ipa_tx_desc->dma_addr
4080 + HDD_IPA_WLAN_FRAG_HEADER
4081 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004082 ipa_tx_desc->skb->len -=
4083 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4084 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304085 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004087 /* FIXME: This is broken: priv_data is 31 bits */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304088 qdf_nbuf_ipa_priv_set(skb, wlan_hdd_stub_addr_to_priv(ipa_tx_desc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089
4090 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4091
Leo Changfdb45c32016-10-28 11:09:23 -07004092 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004093 (struct cdp_vdev *)iface_context->tl_context,
4094 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304096 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 ipa_free_skb(ipa_tx_desc);
4098 iface_context->stats.num_tx_err++;
4099 hdd_ipa_rm_try_release(hdd_ipa);
4100 return;
4101 }
4102
4103 atomic_inc(&hdd_ipa->tx_ref_cnt);
4104
4105 iface_context->stats.num_tx++;
4106
4107}
4108
4109/**
Leo Chang11545d62016-10-17 14:53:50 -07004110 * hdd_ipa_is_present() - get IPA hw status
4111 * @hdd_ctx: pointer to hdd context
4112 *
4113 * ipa_uc_reg_rdyCB is not directly designed to check
4114 * ipa hw status. This is an undocumented function which
4115 * has confirmed with IPA team.
4116 *
4117 * Return: true - ipa hw present
4118 * false - ipa hw not present
4119 */
4120bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
4121{
4122 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004123 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004124 return true;
4125 else
4126 return false;
4127}
4128
4129/**
Leo Chang69c39692016-10-12 20:11:12 -07004130 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131 * @work: pointer to the scheduled work
4132 *
4133 * Called during PM resume to send packets to TL which were queued
4134 * while host was in the process of suspending.
4135 *
4136 * Return: None
4137 */
Leo Chang69c39692016-10-12 20:11:12 -07004138static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139{
4140 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4141 struct hdd_ipa_priv,
4142 pm_work);
4143 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304144 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004145 uint32_t dequeued = 0;
4146
Leo Chang69c39692016-10-12 20:11:12 -07004147 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4148 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304149 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304150 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4151 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304152 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153
4154 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004156 if (pm_tx_cb->exception) {
4157 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4158 "FLUSH EXCEPTION");
4159 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
4160 } else {
4161 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004162 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004163 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304164 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304166 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004167 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4168 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004169
4170 hdd_ipa->stats.num_tx_dequeued += dequeued;
4171 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4172 hdd_ipa->stats.num_max_pm_queue = dequeued;
4173}
4174
4175/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004176 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004177 * @priv: pointer to private data registered with IPA (we register a
4178 * pointer to the interface-specific IPA context)
4179 * @evt: the IPA event which triggered the callback
4180 * @data: data associated with the event
4181 *
4182 * Return: None
4183 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004184static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 unsigned long data)
4186{
4187 struct hdd_ipa_priv *hdd_ipa = NULL;
4188 struct ipa_rx_data *ipa_tx_desc;
4189 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304190 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004191 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304192 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193
Mukul Sharma81661ae2015-10-30 20:26:02 +05304194 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004195 ipa_tx_desc = (struct ipa_rx_data *)data;
4196 hdd_ipa = iface_context->hdd_ipa;
4197
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004199 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4200 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201 iface_context->stats.num_tx_drop++;
4202 return;
4203 }
4204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 /*
4206 * When SSR is going on or driver is unloading, just drop the packets.
4207 * During SSR, there is no use in queueing the packets as STA has to
4208 * connect back any way
4209 */
4210 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304211 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 ipa_free_skb(ipa_tx_desc);
4213 iface_context->stats.num_tx_drop++;
4214 return;
4215 }
4216
4217 skb = ipa_tx_desc->skb;
4218
Yun Parkb187d542016-11-14 18:10:04 -08004219 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4220 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221
4222 /*
4223 * If PROD resource is not requested here then there may be cases where
4224 * IPA hardware may be clocked down because of not having proper
4225 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4226 * workaround to request PROD resource while data is going over CONS
4227 * pipe to prevent the IPA hardware clockdown.
4228 */
4229 hdd_ipa_rm_request(hdd_ipa);
4230
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304231 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232 /*
4233 * If host is still suspended then queue the packets and these will be
4234 * drained later when resume completes. When packet is arrived here and
4235 * host is suspended, this means that there is already resume is in
4236 * progress.
4237 */
4238 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304239 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4241 pm_tx_cb->iface_context = iface_context;
4242 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304243 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 hdd_ipa->stats.num_tx_queued++;
4245
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304246 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004247 return;
4248 }
4249
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304250 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251
4252 /*
4253 * If we are here means, host is not suspended, wait for the work queue
4254 * to finish.
4255 */
4256#ifdef WLAN_OPEN_SOURCE
4257 flush_work(&hdd_ipa->pm_work);
4258#endif
4259
4260 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4261}
4262
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004263/*
4264 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4265 * @priv: pointer to private data registered with IPA (we register a
4266 * pointer to the interface-specific IPA context)
4267 * @evt: the IPA event which triggered the callback
4268 * @data: data associated with the event
4269 *
4270 * Return: None
4271 */
4272static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4273 unsigned long data)
4274{
4275 cds_ssr_protect(__func__);
4276 __hdd_ipa_i2w_cb(priv, evt, data);
4277 cds_ssr_unprotect(__func__);
4278}
4279
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004281 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004282 * @hdd_ctx: Global HDD context
4283 *
4284 * Return: 0 on success, negativer errno on error
4285 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004286static int __hdd_ipa_suspend(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004287{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004288 struct hdd_ipa_priv *hdd_ipa;
4289
4290 if (wlan_hdd_validate_context(hdd_ctx))
4291 return 0;
4292
4293 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004294
4295 if (!hdd_ipa_is_enabled(hdd_ctx))
4296 return 0;
4297
4298 /*
4299 * Check if IPA is ready for suspend, If we are here means, there is
4300 * high chance that suspend would go through but just to avoid any race
4301 * condition after suspend started, these checks are conducted before
4302 * allowing to suspend.
4303 */
4304 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4305 return -EAGAIN;
4306
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304307 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308
4309 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304310 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311 return -EAGAIN;
4312 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304313 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304315 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304317 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318
4319 return 0;
4320}
4321
4322/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004323 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4324 * @hdd_ctx: Global HDD context
4325 *
4326 * Return: 0 on success, negativer errno on error
4327 */
4328int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
4329{
4330 int ret;
4331
4332 cds_ssr_protect(__func__);
4333 ret = __hdd_ipa_suspend(hdd_ctx);
4334 cds_ssr_unprotect(__func__);
4335
4336 return ret;
4337}
4338
4339/**
4340 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 * hdd_ctx: Global HDD context
4342 *
4343 * Return: 0 on success, negative errno on error
4344 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004345static int __hdd_ipa_resume(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004346{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004347 struct hdd_ipa_priv *hdd_ipa;
4348
4349 if (wlan_hdd_validate_context(hdd_ctx))
4350 return 0;
4351
4352 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004353
4354 if (!hdd_ipa_is_enabled(hdd_ctx))
4355 return 0;
4356
4357 schedule_work(&hdd_ipa->pm_work);
4358
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304359 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304361 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362
4363 return 0;
4364}
4365
4366/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004367 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4368 * hdd_ctx: Global HDD context
4369 *
4370 * Return: 0 on success, negative errno on error
4371 */
4372int hdd_ipa_resume(hdd_context_t *hdd_ctx)
4373{
4374 int ret;
4375
4376 cds_ssr_protect(__func__);
4377 ret = __hdd_ipa_resume(hdd_ctx);
4378 cds_ssr_unprotect(__func__);
4379
4380 return ret;
4381}
4382
4383/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4385 * @hdd_ipa: Global HDD IPA context
4386 *
4387 * Return: 0 on success, negative errno on error
4388 */
4389static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4390{
4391 int i, ret = 0;
4392 struct ipa_sys_connect_params *ipa;
4393 uint32_t desc_fifo_sz;
4394
4395 /* The maximum number of descriptors that can be provided to a BAM at
4396 * once is one less than the total number of descriptors that the buffer
4397 * can contain.
4398 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4399 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4400 * be provided at once.
4401 * Because of above requirement, one extra descriptor will be added to
4402 * make sure hardware always has one descriptor.
4403 */
4404 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4405 + sizeof(struct sps_iovec);
4406
4407 /*setup TX pipes */
4408 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4409 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4410
4411 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4412 ipa->desc_fifo_sz = desc_fifo_sz;
4413 ipa->priv = &hdd_ipa->iface_context[i];
4414 ipa->notify = hdd_ipa_i2w_cb;
4415
4416 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4417 ipa->ipa_ep_cfg.hdr.hdr_len =
4418 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4419 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4420 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4421 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4422 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4423 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4424 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4425 } else {
4426 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4427 }
4428 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4429
4430 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4431 ipa->keep_ipa_awake = 1;
4432
4433 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4434 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304435 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed for pipe %d"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004436 " ret: %d", i, ret);
4437 goto setup_sys_pipe_fail;
4438 }
4439 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4440 }
4441
4442 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4443 /*
4444 * Hard code it here, this can be extended if in case
4445 * PROD pipe is also per interface.
4446 * Right now there is no advantage of doing this.
4447 */
4448 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
4449
4450 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4451
4452 ipa->client = hdd_ipa->prod_client;
4453
4454 ipa->desc_fifo_sz = desc_fifo_sz;
4455 ipa->priv = hdd_ipa;
4456 ipa->notify = hdd_ipa_w2i_cb;
4457
4458 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4459 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4460 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4461 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4462
4463 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4464 ipa->keep_ipa_awake = 1;
4465
4466 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4467 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304468 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004469 "Failed for RX pipe: %d", ret);
4470 goto setup_sys_pipe_fail;
4471 }
4472 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4473 }
4474
4475 return ret;
4476
4477setup_sys_pipe_fail:
4478
4479 while (--i >= 0) {
4480 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304481 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004482 sizeof(struct hdd_ipa_sys_pipe));
4483 }
4484
4485 return ret;
4486}
4487
4488/**
4489 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4490 * @hdd_ipa: Global HDD IPA context
4491 *
4492 * Return: None
4493 */
4494static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4495{
4496 int ret = 0, i;
4497 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4498 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
4499 ret =
4500 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4501 conn_hdl);
4502 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304503 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004504 ret);
4505
4506 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4507 }
4508 }
4509}
4510
4511/**
4512 * hdd_ipa_register_interface() - register IPA interface
4513 * @hdd_ipa: Global IPA context
4514 * @iface_context: Per-interface IPA context
4515 *
4516 * Return: 0 on success, negative errno on error
4517 */
4518static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
4519 struct hdd_ipa_iface_context
4520 *iface_context)
4521{
4522 struct ipa_tx_intf tx_intf;
4523 struct ipa_rx_intf rx_intf;
4524 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
4525 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
4526 char *ifname = iface_context->adapter->dev->name;
4527
4528 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
4529 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
4530
4531 int num_prop = 1;
4532 int ret = 0;
4533
4534 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
4535 num_prop++;
4536
4537 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
4538 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304539 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304541 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542 goto register_interface_fail;
4543 }
4544
4545 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
4546 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304547 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004548 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304549 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004550 goto register_interface_fail;
4551 }
4552
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304553 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
4554 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004555
4556 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
4557 ifname, HDD_IPA_IPV4_NAME_EXT);
4558 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
4559 ifname, HDD_IPA_IPV6_NAME_EXT);
4560
4561 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
4562 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
4563 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
4564 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
4565
4566 /*
4567 * Interface ID is 3rd byte in the CLD header. Add the meta data and
4568 * mask to identify the interface in IPA hardware
4569 */
4570 rx_prop[IPA_IP_v4].attrib.meta_data =
4571 htonl(iface_context->adapter->sessionId << 16);
4572 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
4573
4574 rx_intf.num_props++;
4575 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
4576 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
4577 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
4578 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
4579 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
4580 rx_prop[IPA_IP_v4].attrib.meta_data =
4581 htonl(iface_context->adapter->sessionId << 16);
4582 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
4583
4584 rx_intf.num_props++;
4585 }
4586
4587 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
4588 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
4589 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
4590 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
4591 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
4592 IPA_RESOURCE_NAME_MAX);
4593 tx_intf.num_props++;
4594
4595 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
4596 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
4597 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
4598 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
4599 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
4600 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
4601 IPA_RESOURCE_NAME_MAX);
4602 tx_intf.num_props++;
4603 }
4604
4605 tx_intf.prop = tx_prop;
4606 rx_intf.prop = rx_prop;
4607
4608 /* Call the ipa api to register interface */
4609 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
4610
4611register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304612 qdf_mem_free(tx_prop);
4613 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004614 return ret;
4615}
4616
4617/**
4618 * hdd_remove_ipa_header() - Remove a specific header from IPA
4619 * @name: Name of the header to be removed
4620 *
4621 * Return: None
4622 */
4623static void hdd_ipa_remove_header(char *name)
4624{
4625 struct ipa_ioc_get_hdr hdrlookup;
4626 int ret = 0, len;
4627 struct ipa_ioc_del_hdr *ipa_hdr;
4628
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304629 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004630 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
4631 ret = ipa_get_hdr(&hdrlookup);
4632 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304633 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004634 name, ret);
4635 return;
4636 }
4637
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304638 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004639 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304640 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004641 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304642 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004643 return;
4644 }
4645 ipa_hdr->num_hdls = 1;
4646 ipa_hdr->commit = 0;
4647 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
4648 ipa_hdr->hdl[0].status = -1;
4649 ret = ipa_del_hdr(ipa_hdr);
4650 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304651 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652 ret);
4653
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304654 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655}
4656
4657/**
Yun Parkb187d542016-11-14 18:10:04 -08004658 * wlan_ipa_add_hdr() - Add IPA Tx header
4659 * @ipa_hdr: pointer to IPA header addition parameters
4660 *
4661 * Call IPA API to add IPA Tx header descriptor
4662 * and dump Tx header struct
4663 *
4664 * Return: 0 for success, non-zero for failure
4665 */
4666static int wlan_ipa_add_hdr(struct ipa_ioc_add_hdr *ipa_hdr)
4667{
4668 int ret;
4669
4670 hdd_info("==== IPA Tx Header ====\n"
4671 "name: %s\n"
4672 "hdr_len: %d\n"
4673 "type: %d\n"
4674 "is_partial: %d\n"
4675 "hdr_hdl: 0x%x\n"
4676 "status: %d\n"
4677 "is_eth2_ofst_valid: %d\n"
4678 "eth2_ofst: %d\n",
4679 ipa_hdr->hdr[0].name,
4680 ipa_hdr->hdr[0].hdr_len,
4681 ipa_hdr->hdr[0].type,
4682 ipa_hdr->hdr[0].is_partial,
4683 ipa_hdr->hdr[0].hdr_hdl,
4684 ipa_hdr->hdr[0].status,
4685 ipa_hdr->hdr[0].is_eth2_ofst_valid,
4686 ipa_hdr->hdr[0].eth2_ofst);
4687
4688 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_ERROR, "hdr:",
4689 ipa_hdr->hdr[0].hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
4690
4691 ret = ipa_add_hdr(ipa_hdr);
4692 return ret;
4693}
4694
4695/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004696 * hdd_ipa_add_header_info() - Add IPA header for a given interface
4697 * @hdd_ipa: Global HDD IPA context
4698 * @iface_context: Interface-specific HDD IPA context
4699 * @mac_addr: Interface MAC address
4700 *
4701 * Return: 0 on success, negativer errno value on error
4702 */
4703static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
4704 struct hdd_ipa_iface_context *iface_context,
4705 uint8_t *mac_addr)
4706{
4707 hdd_adapter_t *adapter = iface_context->adapter;
4708 char *ifname;
4709 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
4710 int ret = -EINVAL;
4711 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
4712 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
4713
4714 ifname = adapter->dev->name;
4715
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304716 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717 ifname, mac_addr);
4718
4719 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304720 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721 + sizeof(struct ipa_hdr_add));
4722 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304723 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004724 "%s: ipa_hdr allocation failed", ifname);
4725 ret = -ENOMEM;
4726 goto end;
4727 }
4728
4729 ipa_hdr->commit = 0;
4730 ipa_hdr->num_hdrs = 1;
4731
4732 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4733 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
4734 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
4735 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
4736 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304737 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004738 "ifname=%s, vdev_id=%d",
4739 ifname, uc_tx_hdr->ipa_hd.vdev_id);
4740 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
4741 ifname, HDD_IPA_IPV4_NAME_EXT);
4742 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
4743 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
4744 ipa_hdr->hdr[0].is_partial = 1;
4745 ipa_hdr->hdr[0].hdr_hdl = 0;
4746 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
4747 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
4748
Yun Parkb187d542016-11-14 18:10:04 -08004749 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750 } else {
4751 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
4752
4753 /* Set the Source MAC */
4754 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
4755 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
4756
4757 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
4758 ifname, HDD_IPA_IPV4_NAME_EXT);
4759 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4760 ipa_hdr->hdr[0].is_partial = 1;
4761 ipa_hdr->hdr[0].hdr_hdl = 0;
4762 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
4763 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
4764
4765 /* Set the type to IPV4 in the header */
4766 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
4767
4768 ret = ipa_add_hdr(ipa_hdr);
4769 }
4770 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304771 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772 ifname, ret);
4773 goto end;
4774 }
4775
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304776 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
4778
4779 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
4780 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
4781 ifname, HDD_IPA_IPV6_NAME_EXT);
4782
4783 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4784 uc_tx_hdr =
4785 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
4786 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08004787 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004788 } else {
4789 /* Set the type to IPV6 in the header */
4790 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
4791 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08004792 ret = ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793 }
4794
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004795 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304796 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004797 "%s: IPv6 add hdr failed: %d", ifname, ret);
4798 goto clean_ipv4_hdr;
4799 }
4800
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304801 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004802 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
4803 }
4804
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304805 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004806
4807 return ret;
4808
4809clean_ipv4_hdr:
4810 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
4811 ifname, HDD_IPA_IPV4_NAME_EXT);
4812 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
4813end:
4814 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304815 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004816
4817 return ret;
4818}
4819
4820/**
4821 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
4822 * @adapter: Adapter upon which IPA was previously configured
4823 *
4824 * Return: None
4825 */
4826static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
4827{
4828 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4829 int ret;
4830 char name_ipa[IPA_RESOURCE_NAME_MAX];
4831
4832 /* Remove the headers */
4833 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
4834 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
4835 hdd_ipa_remove_header(name_ipa);
4836
4837 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
4838 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
4839 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
4840 hdd_ipa_remove_header(name_ipa);
4841 }
4842 /* unregister the interface with IPA */
4843 ret = ipa_deregister_intf(adapter->dev->name);
4844 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304845 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846 "%s: ipa_deregister_intf fail: %d",
4847 adapter->dev->name, ret);
4848}
4849
4850/**
4851 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4852 * @iface_context: interface-specific IPA context
4853 *
4854 * Return: None
4855 */
4856static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4857{
4858 if (iface_context == NULL)
4859 return;
4860
4861 hdd_ipa_clean_hdr(iface_context->adapter);
4862
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304863 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004864 iface_context->adapter->ipa_context = NULL;
4865 iface_context->adapter = NULL;
4866 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304867 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004868 iface_context->ifa_address = 0;
4869 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304870 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004871 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304872 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873 }
4874 iface_context->hdd_ipa->num_iface--;
4875}
4876
4877/**
4878 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4879 * @hdd_ipa: HDD IPA global context
4880 * @adapter: Interface upon which IPA is being setup
4881 * @sta_id: Station ID of the API instance
4882 *
4883 * Return: 0 on success, negative errno value on error
4884 */
4885static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
4886 hdd_adapter_t *adapter, uint8_t sta_id)
4887{
4888 struct hdd_ipa_iface_context *iface_context = NULL;
4889 void *tl_context = NULL;
4890 int i, ret = 0;
4891
4892 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4893 * channel change indication. Since these indications are sent by lower
4894 * layer as SAP updates and IPA doesn't have to do anything for these
4895 * updates so ignoring!
4896 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004897 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004898 return 0;
4899
4900 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4901 if (hdd_ipa->iface_context[i].adapter == NULL) {
4902 iface_context = &(hdd_ipa->iface_context[i]);
4903 break;
4904 }
4905 }
4906
4907 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304908 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004909 "All the IPA interfaces are in use");
4910 ret = -ENOMEM;
4911 goto end;
4912 }
4913
4914 adapter->ipa_context = iface_context;
4915 iface_context->adapter = adapter;
4916 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004917 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07004918 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004919 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304920 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921 "Not able to get TL context sta_id: %d", sta_id);
4922 ret = -EINVAL;
4923 goto end;
4924 }
4925
4926 iface_context->tl_context = tl_context;
4927
4928 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
4929 adapter->dev->dev_addr);
4930
4931 if (ret)
4932 goto end;
4933
4934 /* Configure the TX and RX pipes filter rules */
4935 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
4936 if (ret)
4937 goto cleanup_header;
4938
4939 hdd_ipa->num_iface++;
4940 return ret;
4941
4942cleanup_header:
4943
4944 hdd_ipa_clean_hdr(adapter);
4945end:
4946 if (iface_context)
4947 hdd_ipa_cleanup_iface(iface_context);
4948 return ret;
4949}
4950
Yun Parka27049a2016-10-11 12:30:49 -07004951#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004952/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004953 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004954 * @mcc_mode: 0=MCC/1=SCC
4955 *
4956 * Return: 0 on success, negative errno value on error
4957 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004958static int __hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004959{
4960 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304961 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004962 hdd_adapter_t *pAdapter;
4963 struct ipa_msg_meta meta;
4964 struct ipa_wlan_msg *msg;
4965 int ret;
4966
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004967 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004968 return -EINVAL;
4969
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004970 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4971 return -EINVAL;
4972
4973 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004974 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004975 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304976 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08004978 if (pAdapter->device_mode == QDF_STA_MODE ||
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004979 pAdapter->device_mode == QDF_SAP_MODE) {
4980 hdd_info("MCC->SCC: Flush TxRx queue(d_mode=%d)",
4981 pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982 hdd_deinit_tx_rx(pAdapter);
4983 }
4984 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004985 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986 adapter_node = next;
4987 }
4988 }
4989
4990 /* Send SCC/MCC Switching event to IPA */
4991 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304992 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004994 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995 return -ENOMEM;
4996 }
4997
4998 meta.msg_type = mcc_mode ?
4999 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005000 hdd_info("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005001
5002 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5003
5004 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005005 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005006 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305007 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005008 }
5009
5010 return ret;
5011}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005012
5013/**
5014 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
5015 * @mcc_mode: 0=MCC/1=SCC
5016 *
5017 * Return: 0 on success, negative errno value on error
5018 */
5019int hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
5020{
5021 int ret;
5022
5023 cds_ssr_protect(__func__);
5024 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
5025 cds_ssr_unprotect(__func__);
5026
5027 return ret;
5028}
Yun Parka27049a2016-10-11 12:30:49 -07005029#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005030
5031/**
5032 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
5033 * @event: IPA WLAN event to be converted to a string
5034 *
5035 * Return: ASCII string representing the IPA WLAN event
5036 */
5037static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
5038{
5039 switch (event) {
5040 case WLAN_CLIENT_CONNECT:
5041 return "WLAN_CLIENT_CONNECT";
5042 case WLAN_CLIENT_DISCONNECT:
5043 return "WLAN_CLIENT_DISCONNECT";
5044 case WLAN_CLIENT_POWER_SAVE_MODE:
5045 return "WLAN_CLIENT_POWER_SAVE_MODE";
5046 case WLAN_CLIENT_NORMAL_MODE:
5047 return "WLAN_CLIENT_NORMAL_MODE";
5048 case SW_ROUTING_ENABLE:
5049 return "SW_ROUTING_ENABLE";
5050 case SW_ROUTING_DISABLE:
5051 return "SW_ROUTING_DISABLE";
5052 case WLAN_AP_CONNECT:
5053 return "WLAN_AP_CONNECT";
5054 case WLAN_AP_DISCONNECT:
5055 return "WLAN_AP_DISCONNECT";
5056 case WLAN_STA_CONNECT:
5057 return "WLAN_STA_CONNECT";
5058 case WLAN_STA_DISCONNECT:
5059 return "WLAN_STA_DISCONNECT";
5060 case WLAN_CLIENT_CONNECT_EX:
5061 return "WLAN_CLIENT_CONNECT_EX";
5062
5063 case IPA_WLAN_EVENT_MAX:
5064 default:
5065 return "UNKNOWN";
5066 }
5067}
5068
5069/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07005070 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
5071 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
5072 *
5073 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
5074 */
5075static enum ipa_wlan_event
5076hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
5077{
5078 enum ipa_wlan_event ipa_event;
5079
5080 switch (hdd_ipa_event_type) {
5081 case HDD_IPA_CLIENT_CONNECT:
5082 ipa_event = WLAN_CLIENT_CONNECT;
5083 break;
5084 case HDD_IPA_CLIENT_DISCONNECT:
5085 ipa_event = WLAN_CLIENT_DISCONNECT;
5086 break;
5087 case HDD_IPA_AP_CONNECT:
5088 ipa_event = WLAN_AP_CONNECT;
5089 break;
5090 case HDD_IPA_AP_DISCONNECT:
5091 ipa_event = WLAN_AP_DISCONNECT;
5092 break;
5093 case HDD_IPA_STA_CONNECT:
5094 ipa_event = WLAN_STA_CONNECT;
5095 break;
5096 case HDD_IPA_STA_DISCONNECT:
5097 ipa_event = WLAN_STA_DISCONNECT;
5098 break;
5099 case HDD_IPA_CLIENT_CONNECT_EX:
5100 ipa_event = WLAN_CLIENT_CONNECT_EX;
5101 break;
5102 case HDD_IPA_WLAN_EVENT_MAX:
5103 default:
5104 ipa_event = IPA_WLAN_EVENT_MAX;
5105 break;
5106 }
5107 return ipa_event;
5108
5109}
5110
5111/**
5112 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113 * @adapter: adapter upon which the event was received
5114 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07005115 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 * @mac_address: MAC address associated with the event
5117 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07005118 * This function is meant to be called from within wlan_hdd_ipa.c
5119 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005120 * Return: 0 on success, negative errno value on error
5121 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07005122static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123 enum ipa_wlan_event type, uint8_t *mac_addr)
5124{
5125 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5126 struct ipa_msg_meta meta;
5127 struct ipa_wlan_msg *msg;
5128 struct ipa_wlan_msg_ex *msg_ex = NULL;
5129 int ret;
5130
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305131 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5133 mac_addr, sta_id);
5134
5135 if (type >= IPA_WLAN_EVENT_MAX)
5136 return -EINVAL;
5137
5138 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5139 return -EINVAL;
5140
5141 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305142 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 return -EINVAL;
5144 }
5145
5146 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5147 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005148 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149 return 0;
5150 }
5151
5152 /*
5153 * During IPA UC resource loading/unloading new events can be issued.
5154 * Store the events separately and handle them later.
5155 */
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005156 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5157 if (hdd_ipa->resource_loading) {
5158 unsigned int pending_event_count;
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005159 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005160
Yun Park64c405e2017-01-10 22:35:51 -08005161 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5162 "IPA resource load in progress");
Yun Park7c4f31b2016-11-30 10:09:21 -08005163
Yun Park64c405e2017-01-10 22:35:51 -08005164 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005165
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005166 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
5167 if (pending_event_count >= HDD_IPA_MAX_PENDING_EVENT_COUNT) {
5168 hdd_notice("Reached max pending event count");
5169 qdf_list_remove_front(&hdd_ipa->pending_event,
5170 (qdf_list_node_t **)&pending_event);
5171 } else {
5172 pending_event =
5173 (struct ipa_uc_pending_event *)qdf_mem_malloc(
5174 sizeof(struct ipa_uc_pending_event));
5175 }
5176
5177 if (!pending_event) {
Yun Park64c405e2017-01-10 22:35:51 -08005178 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park7c4f31b2016-11-30 10:09:21 -08005179 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5180 "Pending event memory alloc fail");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005181 return -ENOMEM;
5182 }
5183
5184 pending_event->adapter = adapter;
5185 pending_event->sta_id = sta_id;
5186 pending_event->type = type;
5187 qdf_mem_copy(pending_event->mac_addr,
5188 mac_addr,
5189 QDF_MAC_ADDR_SIZE);
5190 qdf_list_insert_back(&hdd_ipa->pending_event,
5191 &pending_event->node);
5192
Yun Park64c405e2017-01-10 22:35:51 -08005193 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005194 return 0;
5195 } else if (hdd_ipa->resource_unloading) {
Yun Park64c405e2017-01-10 22:35:51 -08005196 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5197 "IPA resource unload in progress");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005198 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200 }
5201
5202 hdd_ipa->stats.event[type]++;
5203
Leo Chang3bc8fed2015-11-13 10:59:47 -08005204 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205 switch (type) {
5206 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005207 qdf_mutex_acquire(&hdd_ipa->event_lock);
5208
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005209 /* STA already connected and without disconnect, connect again
5210 * This is Roaming scenario
5211 */
5212 if (hdd_ipa->sta_connected)
5213 hdd_ipa_cleanup_iface(adapter->ipa_context);
5214
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5216 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305217 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005219 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005220
Yun Park8f289c82016-10-18 16:38:21 -07005221 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5222 (hdd_ipa->sap_num_connected_sta > 0) &&
5223 !hdd_ipa->sta_connected) {
5224 qdf_mutex_release(&hdd_ipa->event_lock);
5225 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005226 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005227 qdf_mutex_acquire(&hdd_ipa->event_lock);
5228 }
5229
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005230 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005232 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005235
5236 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237 break;
5238
5239 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005240 qdf_mutex_acquire(&hdd_ipa->event_lock);
5241
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005242 /* For DFS channel we get two start_bss event (before and after
5243 * CAC). Also when ACS range includes both DFS and non DFS
5244 * channels, we could possibly change channel many times due to
5245 * RADAR detection and chosen channel may not be a DFS channels.
5246 * So dont return error here. Just discard the event.
5247 */
Yun Park8f289c82016-10-18 16:38:21 -07005248 if (adapter->ipa_context) {
5249 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005250 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005251 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005252
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5254 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005255 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005256 hdd_err("%s: Evt: %d, Interface setup failed",
5257 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005259 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260
Yun Park8f289c82016-10-18 16:38:21 -07005261 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5262 qdf_mutex_release(&hdd_ipa->event_lock);
5263 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005264 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005265 qdf_mutex_acquire(&hdd_ipa->event_lock);
5266 }
5267
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005268 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005269 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005270 (adapter->ipa_context))->iface_id;
5271
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305272 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273 break;
5274
5275 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305276 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277
5278 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005279 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005280 hdd_err("%s: Evt: %d, STA already disconnected",
5281 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282 return -EINVAL;
5283 }
Yun Parka37592b2016-06-11 17:10:28 -07005284
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005285 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005286
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Parkb187d542016-11-14 18:10:04 -08005288 hdd_notice("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289 msg_ex->name);
5290 } else {
5291 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005292 if (!hdd_ipa->num_iface &&
5293 (HDD_IPA_UC_NUM_WDI_PIPE ==
5294 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005295 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005296 }
5297
Yun Park74127cf2016-09-18 11:22:41 -07005298 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5299 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005300 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005301 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005302 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005303 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005304 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5305 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005306 }
5307
Yun Park8f289c82016-10-18 16:38:21 -07005308 hdd_ipa_cleanup_iface(adapter->ipa_context);
5309
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305310 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 break;
5312
5313 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005314 qdf_mutex_acquire(&hdd_ipa->event_lock);
5315
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005316 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005317 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005318 hdd_err("%s: Evt: %d, SAP already disconnected",
5319 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005320 return -EINVAL;
5321 }
5322
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005323 if ((!hdd_ipa->num_iface) &&
5324 (HDD_IPA_UC_NUM_WDI_PIPE ==
5325 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005326 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005327 /*
5328 * We disable WDI pipes directly here since
5329 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5330 * processed when unloading WLAN driver is in
5331 * progress
5332 */
5333 hdd_ipa_uc_disable_pipes(hdd_ipa);
5334 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305335 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 "NO INTF left but still pipe clean up");
5337 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5338 }
5339 }
5340
5341 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005342 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005343 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005344 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005345 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005346 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5347 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348 }
Yun Parka37592b2016-06-11 17:10:28 -07005349
Yun Park8f289c82016-10-18 16:38:21 -07005350 hdd_ipa_cleanup_iface(adapter->ipa_context);
5351
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305352 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353 break;
5354
5355 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005356 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305357 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305359 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360 return 0;
5361 }
5362
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305363 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005364 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5365 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005366 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305367 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005368 "%s: STA ID %d found, not valid",
5369 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370 return 0;
5371 }
Yun Park312f71a2015-12-08 10:22:42 -08005372
5373 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005374 if (hdd_ipa->sap_num_connected_sta == 0 &&
5375 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005376 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005377 hdd_ipa->sta_connected) {
5378 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005379 hdd_ipa_uc_offload_enable_disable(
5380 hdd_get_adapter(hdd_ipa->hdd_ctx,
5381 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005382 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005383 qdf_mutex_acquire(&hdd_ipa->event_lock);
5384 }
Yun Parka37592b2016-06-11 17:10:28 -07005385
Yun Park312f71a2015-12-08 10:22:42 -08005386 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5387 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305388 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005389 "%s: handle 1st con ret %d",
5390 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005391
5392 if (hdd_ipa_uc_sta_is_enabled(
5393 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005394 hdd_ipa->sta_connected) {
5395 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005396 hdd_ipa_uc_offload_enable_disable(
5397 hdd_get_adapter(
5398 hdd_ipa->hdd_ctx,
5399 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005400 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005401 } else {
5402 qdf_mutex_release(&hdd_ipa->event_lock);
5403 }
Yun Parka37592b2016-06-11 17:10:28 -07005404
Yun Park312f71a2015-12-08 10:22:42 -08005405 return ret;
5406 }
5407 }
5408
5409 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005410
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305411 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412
5413 meta.msg_type = type;
5414 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5415 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305416 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005417
5418 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305419 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005420 "msg_ex allocation failed");
5421 return -ENOMEM;
5422 }
5423 strlcpy(msg_ex->name, adapter->dev->name,
5424 IPA_RESOURCE_NAME_MAX);
5425 msg_ex->num_of_attribs = 1;
5426 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5427 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5428 msg_ex->attribs[0].offset =
5429 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5430 } else {
5431 msg_ex->attribs[0].offset =
5432 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5433 }
5434 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5435 IPA_MAC_ADDR_SIZE);
5436
5437 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5438
5439 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305440 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305441 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305442 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005443 return ret;
5444 }
5445 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005446 return ret;
5447
5448 case WLAN_CLIENT_DISCONNECT:
5449 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305450 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005451 "%s: IPA UC OFFLOAD NOT ENABLED",
5452 msg_ex->name);
5453 return 0;
5454 }
5455
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305456 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005457 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005458 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305459 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005460 "%s: STA ID %d NOT found, not valid",
5461 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462 return 0;
5463 }
5464 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005465
Yun Park9b5030f2016-11-08 12:02:37 -08005466 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005467 if (!hdd_ipa->sap_num_connected_sta &&
5468 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005469 if ((false == hdd_ipa->resource_unloading)
5470 && (HDD_IPA_UC_NUM_WDI_PIPE ==
5471 hdd_ipa->activated_fw_pipe)) {
5472 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5473 }
5474
Yun Park8f289c82016-10-18 16:38:21 -07005475 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005476
5477 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5478 hdd_ipa->sta_connected)
5479 hdd_ipa_uc_offload_enable_disable(
5480 hdd_get_adapter(hdd_ipa->hdd_ctx,
5481 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005482 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005483 } else {
5484 qdf_mutex_release(&hdd_ipa->event_lock);
5485 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005486 break;
5487
5488 default:
5489 return 0;
5490 }
5491
5492 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305493 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005494 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305495 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005496 return -ENOMEM;
5497 }
5498
5499 meta.msg_type = type;
5500 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5501 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5502
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305503 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005504 msg->name, meta.msg_type);
5505
5506 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5507
5508 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005509 hdd_err("%s: Evt: %d fail:%d",
5510 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305511 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005512 return ret;
5513 }
5514
5515 hdd_ipa->stats.num_send_msg++;
5516
5517end:
5518 return ret;
5519}
5520
5521/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005522 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005523 * @adapter: adapter upon which the event was received
5524 * @sta_id: station id for the event
5525 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5526 * @mac_address: MAC address associated with the event
5527 *
5528 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5529 *
5530 * Return: 0 on success, negative errno value on error
5531 */
5532int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
5533 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5534{
5535 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005536 int ret = 0;
5537
5538 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005539
Leo Changa202b522016-10-14 16:13:50 -07005540 /* Data path offload only support for STA and SAP mode */
5541 if ((QDF_STA_MODE == adapter->device_mode) ||
5542 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005543 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005544
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005545 cds_ssr_unprotect(__func__);
5546
5547 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005548}
5549
5550/**
5551 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5552 * @hdd_ipa: Global HDD IPA context
5553 *
5554 * Return: None
5555 */
5556static void
5557hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5558{
5559 unsigned int pending_event_count;
5560 struct ipa_uc_pending_event *pending_event = NULL;
5561
5562 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
5563 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
5564 "%s, Pending Event Count %d", __func__, pending_event_count);
5565 if (!pending_event_count) {
5566 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
5567 "%s, No Pending Event", __func__);
5568 return;
5569 }
5570
5571 qdf_list_remove_front(&hdd_ipa->pending_event,
5572 (qdf_list_node_t **)&pending_event);
5573 while (pending_event != NULL) {
5574 __hdd_ipa_wlan_evt(pending_event->adapter,
5575 pending_event->type,
5576 pending_event->sta_id,
5577 pending_event->mac_addr);
5578 qdf_mem_free(pending_event);
5579 pending_event = NULL;
5580 qdf_list_remove_front(&hdd_ipa->pending_event,
5581 (qdf_list_node_t **)&pending_event);
5582 }
5583}
5584
5585/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005586 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5587 * @state: IPA RM state value
5588 *
5589 * Return: ASCII string representing the IPA RM state
5590 */
5591static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5592{
5593 switch (state) {
5594 case HDD_IPA_RM_RELEASED:
5595 return "RELEASED";
5596 case HDD_IPA_RM_GRANT_PENDING:
5597 return "GRANT_PENDING";
5598 case HDD_IPA_RM_GRANTED:
5599 return "GRANTED";
5600 }
5601
5602 return "UNKNOWN";
5603}
5604
5605/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005606 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005607 * @hdd_ctx: HDD global context
5608 *
5609 * Allocate hdd_ipa resources, ipa pipe resource and register
5610 * wlan interface with IPA module.
5611 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305612 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005613 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005614static QDF_STATUS __hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005615{
5616 struct hdd_ipa_priv *hdd_ipa = NULL;
5617 int ret, i;
5618 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005619 struct ol_txrx_pdev_t *pdev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005620
5621 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305622 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005623
Yun Parkbaa62862017-01-18 13:43:34 -08005624 ENTER();
5625
5626 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005627 if (!pdev) {
5628 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5629 goto fail_return;
5630 }
5631
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305632 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305634 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005635 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005636 }
5637
5638 hdd_ctx->hdd_ipa = hdd_ipa;
5639 ghdd_ipa = hdd_ipa;
5640 hdd_ipa->hdd_ctx = hdd_ctx;
5641 hdd_ipa->num_iface = 0;
5642
5643 /* Create the interface context */
5644 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5645 iface_context = &hdd_ipa->iface_context[i];
5646 iface_context->hdd_ipa = hdd_ipa;
5647 iface_context->cons_client =
5648 hdd_ipa_adapter_2_client[i].cons_client;
5649 iface_context->prod_client =
5650 hdd_ipa_adapter_2_client[i].prod_client;
5651 iface_context->iface_id = i;
5652 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305653 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005654 }
5655 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005656 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5657 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005658 }
5659
Leo Chang69c39692016-10-12 20:11:12 -07005660 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305661 qdf_spinlock_create(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305662 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005663
5664 ret = hdd_ipa_setup_rm(hdd_ipa);
5665 if (ret)
5666 goto fail_setup_rm;
5667
5668 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5669 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305670 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671 hdd_ipa->sap_num_connected_sta = 0;
5672 hdd_ipa->ipa_tx_packets_diff = 0;
5673 hdd_ipa->ipa_rx_packets_diff = 0;
5674 hdd_ipa->ipa_p_tx_packets = 0;
5675 hdd_ipa->ipa_p_rx_packets = 0;
5676 hdd_ipa->resource_loading = false;
5677 hdd_ipa->resource_unloading = false;
5678 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005679 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005680 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681 /* Setup IPA sys_pipe for MCC */
5682 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5683 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5684 if (ret)
5685 goto fail_create_sys_pipe;
5686 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005687 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5688 goto fail_create_sys_pipe;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689 } else {
5690 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5691 if (ret)
5692 goto fail_create_sys_pipe;
5693 }
5694
Yun Parkbaa62862017-01-18 13:43:34 -08005695 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305696 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697
5698fail_create_sys_pipe:
5699 hdd_ipa_destroy_rm_resource(hdd_ipa);
5700fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305701 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305702 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005703 hdd_ctx->hdd_ipa = NULL;
5704 ghdd_ipa = NULL;
5705fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08005706 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305707 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708}
5709
5710/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005711 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5712 * @hdd_ctx: HDD global context
5713 *
5714 * Allocate hdd_ipa resources, ipa pipe resource and register
5715 * wlan interface with IPA module.
5716 *
5717 * Return: QDF_STATUS enumeration
5718 */
5719QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
5720{
5721 QDF_STATUS ret;
5722
5723 cds_ssr_protect(__func__);
5724 ret = __hdd_ipa_init(hdd_ctx);
5725 cds_ssr_unprotect(__func__);
5726
5727 return ret;
5728}
5729
Arun Khandavallicc544b32017-01-30 19:52:16 +05305730
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005731/**
Yun Parkf19e07d2015-11-20 11:34:27 -08005732 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
5733 * @hdd_ipa: pointer to HDD IPA struct
5734 *
5735 * Return: none
5736 */
Jeff Johnsond7720632016-10-05 16:04:32 -07005737static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08005738{
5739 struct ipa_uc_pending_event *pending_event = NULL;
5740
Anurag Chouhanffb21542016-02-17 14:33:03 +05305741 while (qdf_list_remove_front(&hdd_ipa->pending_event,
5742 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305743 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005744 }
5745
Anurag Chouhanffb21542016-02-17 14:33:03 +05305746 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005747}
5748
5749/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005750 * __hdd_ipa_cleanup - IPA cleanup function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005751 * @hdd_ctx: HDD global context
5752 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305753 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005754 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005755static QDF_STATUS __hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005756{
5757 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5758 int i;
5759 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305760 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005761 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5762
5763 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305764 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005765
5766 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5767 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5768 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5769 }
5770
5771 /* Teardown IPA sys_pipe for MCC */
5772 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5773 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5774
5775 hdd_ipa_destroy_rm_resource(hdd_ipa);
5776
5777#ifdef WLAN_OPEN_SOURCE
5778 cancel_work_sync(&hdd_ipa->pm_work);
5779#endif
5780
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305781 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005782
Nirav Shahcbc6d722016-03-01 16:24:53 +05305783 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5784 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305785 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005786
5787 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
5788 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
5789
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305790 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005791 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305792 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005793
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305794 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005795
5796 /* destory the interface lock */
5797 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5798 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305799 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800 }
5801
5802 /* This should never hit but still make sure that there are no pending
5803 * descriptor in IPA hardware
5804 */
5805 if (hdd_ipa->pending_hw_desc_cnt != 0) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305806 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005807 "IPA Pending write done: %d Waiting!",
5808 hdd_ipa->pending_hw_desc_cnt);
5809
5810 for (i = 0; hdd_ipa->pending_hw_desc_cnt != 0 && i < 10; i++) {
5811 usleep_range(100, 100);
5812 }
5813
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305814 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005815 "IPA Pending write done: desc: %d %s(%d)!",
5816 hdd_ipa->pending_hw_desc_cnt,
5817 hdd_ipa->pending_hw_desc_cnt == 0 ? "completed"
5818 : "leak", i);
5819 }
5820 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005821 if (ipa_uc_dereg_rdyCB())
5822 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5823 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005824 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005825 if (true == hdd_ipa->uc_loaded) {
5826 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05305827 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
5828 __func__, hdd_ipa->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005829 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
5830 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Govind Singh0487bf22016-08-24 23:08:57 +05305831 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
5832 __func__, hdd_ipa->rx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005833 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
5834 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305835 qdf_mutex_destroy(&hdd_ipa->event_lock);
5836 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005837 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005838
5839#ifdef WLAN_OPEN_SOURCE
5840 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5841 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5842 hdd_ipa->uc_op_work[i].msg = NULL;
5843 }
5844#endif
5845 }
5846
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305847 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005848 hdd_ctx->hdd_ipa = NULL;
5849
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305850 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005851}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005852
5853/**
5854 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5855 * @hdd_ctx: HDD global context
5856 *
5857 * Return: QDF_STATUS enumeration
5858 */
5859QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
5860{
5861 QDF_STATUS ret;
5862
5863 cds_ssr_protect(__func__);
5864 ret = __hdd_ipa_cleanup(hdd_ctx);
5865 cds_ssr_unprotect(__func__);
5866
5867 return ret;
5868}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005869#endif /* IPA_OFFLOAD */