blob: 2b58237f15f8b9f2c572c4256e167de09a1d82dd [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 */
Dustin Brown0bec9a92017-08-17 15:44:34 -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"
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080061#include "wlan_policy_mgr_api.h"
62
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
Yun Parkb4f591d2017-03-29 15:51:01 -070065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066#define HDD_IPA_UC_NUM_WDI_PIPE 2
67#define HDD_IPA_UC_MAX_PENDING_EVENT 33
68
69#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
70#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
71#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
72#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
73
74#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
75#define HDD_IPA_MAX_IFACE 3
76#define HDD_IPA_MAX_SYSBAM_PIPE 4
Yun Parkb4f591d2017-03-29 15:51:01 -070077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080078#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
79#define HDD_IPA_ENABLE_MASK BIT(0)
80#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
81#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
82#define HDD_IPA_RM_ENABLE_MASK BIT(3)
83#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
84#define HDD_IPA_UC_ENABLE_MASK BIT(5)
85#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
86#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
87
Yun Parkf19e07d2015-11-20 11:34:27 -080088#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
89
tfyu0380a972017-07-13 18:19:37 +080090#define IPA_WLAN_RX_SOFTIRQ_THRESH 16
91
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -070092enum hdd_ipa_uc_op_code {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
94 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
95 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
96 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
97 HDD_IPA_UC_OPCODE_STATS = 4,
Yun Park637d6482016-10-05 10:51:33 -070098#ifdef FEATURE_METERING
99 HDD_IPA_UC_OPCODE_SHARING_STATS = 5,
100 HDD_IPA_UC_OPCODE_QUOTA_RSP = 6,
101 HDD_IPA_UC_OPCODE_QUOTA_IND = 7,
102#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800103 HDD_IPA_UC_OPCODE_UC_READY = 8,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104 /* keep this last */
105 HDD_IPA_UC_OPCODE_MAX
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700106};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800107
108/**
109 * enum - Reason codes for stat query
110 *
111 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
112 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
113 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
Yun Parkb187d542016-11-14 18:10:04 -0800114 * @HDD_IPA_UC_STAT_REASON_DUMP_INFO: For debug info dump
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800115 */
116enum {
117 HDD_IPA_UC_STAT_REASON_NONE,
118 HDD_IPA_UC_STAT_REASON_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -0800119 HDD_IPA_UC_STAT_REASON_BW_CAL,
120 HDD_IPA_UC_STAT_REASON_DUMP_INFO
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800121};
122
123/**
124 * enum hdd_ipa_rm_state - IPA resource manager state
125 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
126 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
127 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
128 */
129enum hdd_ipa_rm_state {
130 HDD_IPA_RM_RELEASED,
131 HDD_IPA_RM_GRANT_PENDING,
132 HDD_IPA_RM_GRANTED,
133};
134
135struct llc_snap_hdr {
136 uint8_t dsap;
137 uint8_t ssap;
138 uint8_t resv[4];
139 __be16 eth_type;
140} __packed;
141
Leo Chang3bc8fed2015-11-13 10:59:47 -0800142/**
143 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
144 * @eth: ether II header
145 * @llc_snap: LLC snap header
146 *
147 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800148struct hdd_ipa_tx_hdr {
149 struct ethhdr eth;
150 struct llc_snap_hdr llc_snap;
151} __packed;
152
Leo Chang3bc8fed2015-11-13 10:59:47 -0800153/**
154 * struct frag_header - fragment header type registered to IPA hardware
155 * @length: fragment length
156 * @reserved1: Reserved not used
157 * @reserved2: Reserved not used
158 *
159 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800160struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800161 uint16_t length;
162 uint32_t reserved1;
163 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164} __packed;
165
Leo Chang3bc8fed2015-11-13 10:59:47 -0800166/**
167 * struct ipa_header - ipa header type registered to IPA hardware
168 * @vdev_id: vdev id
169 * @reserved: Reserved not used
170 *
171 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800172struct ipa_header {
173 uint32_t
174 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
175 reserved:24;
176} __packed;
177
Leo Chang3bc8fed2015-11-13 10:59:47 -0800178/**
179 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
180 * @frag_hd: fragment header
181 * @ipa_hd: ipa header
182 * @eth: ether II header
183 *
184 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185struct hdd_ipa_uc_tx_hdr {
186 struct frag_header frag_hd;
187 struct ipa_header ipa_hd;
188 struct ethhdr eth;
189} __packed;
190
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800191/**
192 * struct hdd_ipa_cld_hdr - IPA CLD Header
193 * @reserved: reserved fields
194 * @iface_id: interface ID
195 * @sta_id: Station ID
196 *
197 * Packed 32-bit structure
198 * +----------+----------+--------------+--------+
199 * | Reserved | QCMAP ID | interface id | STA ID |
200 * +----------+----------+--------------+--------+
201 */
202struct hdd_ipa_cld_hdr {
203 uint8_t reserved[2];
204 uint8_t iface_id;
205 uint8_t sta_id;
206} __packed;
207
208struct hdd_ipa_rx_hdr {
209 struct hdd_ipa_cld_hdr cld_hdr;
210 struct ethhdr eth;
211} __packed;
212
213struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700214 bool exception;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700215 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216 struct hdd_ipa_iface_context *iface_context;
217 struct ipa_rx_data *ipa_tx_desc;
218};
219
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800220struct hdd_ipa_sys_pipe {
221 uint32_t conn_hdl;
222 uint8_t conn_hdl_valid;
223 struct ipa_sys_connect_params ipa_sys_params;
224};
225
226struct hdd_ipa_iface_stats {
227 uint64_t num_tx;
228 uint64_t num_tx_drop;
229 uint64_t num_tx_err;
230 uint64_t num_tx_cac_drop;
231 uint64_t num_rx_prefilter;
232 uint64_t num_rx_ipa_excep;
233 uint64_t num_rx_recv;
234 uint64_t num_rx_recv_mul;
235 uint64_t num_rx_send_desc_err;
236 uint64_t max_rx_mul;
237};
238
239struct hdd_ipa_priv;
240
241struct hdd_ipa_iface_context {
242 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700243 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800244 void *tl_context;
245
246 enum ipa_client_type cons_client;
247 enum ipa_client_type prod_client;
248
249 uint8_t iface_id; /* This iface ID */
250 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530251 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252 uint32_t ifa_address;
253 struct hdd_ipa_iface_stats stats;
254};
255
256struct hdd_ipa_stats {
257 uint32_t event[IPA_WLAN_EVENT_MAX];
258 uint64_t num_send_msg;
259 uint64_t num_free_msg;
260
261 uint64_t num_rm_grant;
262 uint64_t num_rm_release;
263 uint64_t num_rm_grant_imm;
264 uint64_t num_cons_perf_req;
265 uint64_t num_prod_perf_req;
266
267 uint64_t num_rx_drop;
268 uint64_t num_rx_ipa_tx_dp;
269 uint64_t num_rx_ipa_splice;
270 uint64_t num_rx_ipa_loop;
271 uint64_t num_rx_ipa_tx_dp_err;
272 uint64_t num_rx_ipa_write_done;
273 uint64_t num_max_ipa_tx_mul;
274 uint64_t num_rx_ipa_hw_maxed_out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800275
Yun Park52b2b992016-09-22 15:49:51 -0700276 uint64_t num_tx_desc_q_cnt;
277 uint64_t num_tx_desc_error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800278 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;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700330 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800331 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
Yun Park637d6482016-10-05 10:51:33 -0700378#ifdef FEATURE_METERING
379struct ipa_uc_sharing_stats {
380 uint64_t ipv4_rx_packets;
381 uint64_t ipv4_rx_bytes;
382 uint64_t ipv6_rx_packets;
383 uint64_t ipv6_rx_bytes;
384 uint64_t ipv4_tx_packets;
385 uint64_t ipv4_tx_bytes;
386 uint64_t ipv6_tx_packets;
387 uint64_t ipv6_tx_bytes;
388};
389
390struct ipa_uc_quota_rsp {
391 uint8_t success;
392 uint8_t reserved[3];
393 uint32_t quota_lo; /* quota limit low bytes */
394 uint32_t quota_hi; /* quota limit high bytes */
395};
396
397struct ipa_uc_quota_ind {
398 uint64_t quota_bytes; /* quota limit in bytes */
399};
400#endif
401
Yun Park52b2b992016-09-22 15:49:51 -0700402/**
403 * struct hdd_ipa_tx_desc
404 * @link: link to list head
405 * @priv: pointer to priv list entry
406 * @id: Tx desc idex
407 * @ipa_tx_desc_ptr: pointer to IPA Tx descriptor
408 */
409struct hdd_ipa_tx_desc {
410 struct list_head link;
411 void *priv;
412 uint32_t id;
413 struct ipa_rx_data *ipa_tx_desc_ptr;
414};
415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800416struct hdd_ipa_priv {
417 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
418 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
419 uint8_t num_iface;
420 enum hdd_ipa_rm_state rm_state;
421 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530422 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800423 * APIs as it is taken care gracefully. Without this, kernel would throw
424 * an warning if spin_lock_bh is used while IRQ is disabled
425 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530426 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427 struct uc_rm_work_struct uc_rm_work;
428 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530429 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800430 struct delayed_work wake_lock_work;
431 bool wake_lock_released;
432
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530434 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800435 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530436 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800437 bool suspended;
438
Yun Park52b2b992016-09-22 15:49:51 -0700439 qdf_spinlock_t q_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800441 struct list_head pend_desc_head;
jiad14fe4fb2017-08-08 13:33:14 +0800442 uint16_t tx_desc_size;
Yun Park52b2b992016-09-22 15:49:51 -0700443 struct hdd_ipa_tx_desc *tx_desc_list;
444 struct list_head free_tx_desc_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800445
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700446 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800447
448 struct dentry *debugfs_dir;
449 struct hdd_ipa_stats stats;
450
451 struct notifier_block ipv4_notifier;
452 uint32_t curr_prod_bw;
453 uint32_t curr_cons_bw;
454
455 uint8_t activated_fw_pipe;
456 uint8_t sap_num_connected_sta;
457 uint8_t sta_connected;
458 uint32_t tx_pipe_handle;
459 uint32_t rx_pipe_handle;
460 bool resource_loading;
461 bool resource_unloading;
462 bool pending_cons_req;
463 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530464 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530465 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700466 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800467 uint32_t ipa_tx_packets_diff;
468 uint32_t ipa_rx_packets_diff;
469 uint32_t ipa_p_tx_packets;
470 uint32_t ipa_p_rx_packets;
471 uint32_t stat_req_reason;
472 uint64_t ipa_tx_forward;
473 uint64_t ipa_rx_discard;
474 uint64_t ipa_rx_net_send_count;
475 uint64_t ipa_rx_internel_drop_count;
476 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530477 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
479 unsigned int rt_buf_fill_index;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800480 struct ipa_wdi_in_params cons_pipe_in;
481 struct ipa_wdi_in_params prod_pipe_in;
482 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800483 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530484 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530485 qdf_mutex_t rt_debug_lock;
486 qdf_mutex_t ipa_lock;
Yun Parkb4f591d2017-03-29 15:51:01 -0700487
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800488 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
489 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Yun Park637d6482016-10-05 10:51:33 -0700490#ifdef FEATURE_METERING
491 struct ipa_uc_sharing_stats ipa_sharing_stats;
492 struct ipa_uc_quota_rsp ipa_quota_rsp;
493 struct ipa_uc_quota_ind ipa_quota_ind;
494 struct completion ipa_uc_sharing_stats_comp;
495 struct completion ipa_uc_set_quota_comp;
496#endif
Yun Park777d7242017-03-30 15:38:33 -0700497 struct completion ipa_resource_comp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498};
499
Leo Changcc923e22016-06-16 15:29:03 -0700500#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
501#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800502#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
503#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
504#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
505#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
506#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700507#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
508 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800509
510#define HDD_IPA_GET_IFACE_ID(_data) \
511 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
512
513#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530514 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800515 "%s:%d: "fmt, __func__, __LINE__, ## args)
516
Govind Singhb6a89772016-08-12 11:23:35 +0530517#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
518 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
519 "%s:%d: "fmt, __func__, __LINE__, ## args)
520
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800521#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
522 do { \
Yun Parkec845302016-12-15 09:22:57 -0800523 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
524 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525 } while (0)
526
527#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
528 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
529
530#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700531 hdd_ipa->ipa_rx_internel_drop_count++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800532#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
Srinivas Girigowda576b2352017-08-25 14:44:26 -0700533 hdd_ipa->ipa_rx_net_send_count++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800534#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
535
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700536#if defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)
Leo Chang63d73612016-10-18 18:09:43 -0700537#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800538#else
539/* Do nothing */
Leo Chang63d73612016-10-18 18:09:43 -0700540#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700541#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800542
Yun Parkb187d542016-11-14 18:10:04 -0800543#define HDD_IPA_DBG_DUMP_RX_LEN 32
544#define HDD_IPA_DBG_DUMP_TX_LEN 48
545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800546static struct hdd_ipa_adapter_2_client {
547 enum ipa_client_type cons_client;
548 enum ipa_client_type prod_client;
549} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
550 {
551 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
552 }, {
553 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
554 }, {
555 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
556 },
557};
558
Yun Park637d6482016-10-05 10:51:33 -0700559#ifdef FEATURE_METERING
560#define IPA_UC_SHARING_STATES_WAIT_TIME 500
561#define IPA_UC_SET_QUOTA_WAIT_TIME 500
562#endif
563
Yun Park777d7242017-03-30 15:38:33 -0700564#define IPA_RESOURCE_COMP_WAIT_TIME 100
565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800566static struct hdd_ipa_priv *ghdd_ipa;
567
568/* Local Function Prototypes */
569static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
570 unsigned long data);
571static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
572 unsigned long data);
Yun Parkb4f591d2017-03-29 15:51:01 -0700573#ifdef FEATURE_METERING
574static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
575 void *data);
576#else
577static void hdd_ipa_wdi_meter_notifier_cb(void);
578#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800579static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580
581static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700582static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800584#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
585 defined(IPA_CLIENT_IS_MHI_CONS))
586/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800587 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
588 * @priv_ctxt: hdd ipa local context
589 *
590 * Will be called by IPA context.
591 * It's atomic context, then should be scheduled to kworker thread
592 *
593 * Return: None
594 */
595static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
596{
597 struct hdd_ipa_priv *hdd_ipa;
598 struct op_msg_type *msg;
599 struct uc_op_work_struct *uc_op_work;
600
601 if (priv_ctxt == NULL) {
602 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
603 return;
604 }
605
606 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
607 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
608 if (!msg) {
609 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
610 return;
611 }
612
613 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
614
615 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
616
617 /* When the same uC OPCODE is already pended, just return */
618 if (uc_op_work->msg)
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530619 goto done;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800620
621 uc_op_work->msg = msg;
622 schedule_work(&uc_op_work->work);
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530623
jiadd91a6842017-08-01 14:46:02 +0800624 /* work handler will free the msg buffer */
625 return;
626
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530627done:
628 qdf_mem_free(msg);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800629}
630
631/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800632 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
633 * @ctrl: WDI control value
634 *
635 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
636 *
637 * Return: 0 on message send to ipa, -1 on failure
638 */
639static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
640{
641 struct ipa_msg_meta meta;
642 struct ipa_wlan_msg *ipa_msg;
643 int ret = 0;
644
645 /* WDI enable message to IPA */
646 meta.msg_len = sizeof(*ipa_msg);
647 ipa_msg = qdf_mem_malloc(meta.msg_len);
648 if (ipa_msg == NULL) {
649 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
650 "msg allocation failed");
651 return -ENOMEM;
652 }
653
654 if (ctrl == true)
655 meta.msg_type = WLAN_WDI_ENABLE;
656 else
657 meta.msg_type = WLAN_WDI_DISABLE;
658
Srinivas Girigowda97852372017-03-06 16:52:59 -0800659 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800660 "ipa_send_msg(Evt:%d)", meta.msg_type);
661 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
662 if (ret) {
663 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
664 "ipa_send_msg(Evt:%d)-fail=%d",
665 meta.msg_type, ret);
666 qdf_mem_free(ipa_msg);
667 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800668 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800669}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800670
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800671/**
672 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
673 * @hdd_ipa: HDD IPA local context
674 *
675 * Register IPA UC ready callback function to IPA kernel driver
676 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
677 * open WDI pipe after WLAN driver loading finished
678 *
679 * Return: 0 Success
680 * -EPERM Registration fail
681 */
682static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
683{
684 struct ipa_wdi_uc_ready_params uc_ready_param;
685 int ret = 0;
686
687 hdd_ipa->uc_loaded = false;
688 uc_ready_param.priv = (void *)hdd_ipa;
689 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
690 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
691 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
692 "UC Ready CB register fail");
693 return -EPERM;
694 }
695 if (true == uc_ready_param.is_uC_ready) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700696 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800697 hdd_ipa->uc_loaded = true;
698 } else {
699 ret = hdd_ipa_uc_send_wdi_control_msg(false);
700 }
701
702 return ret;
703}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800704#else
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800705static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
706{
707 hdd_ipa->uc_loaded = true;
708 return 0;
709}
710
711static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
712{
713 return 0;
714}
715#endif
716
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717/**
718 * hdd_ipa_is_enabled() - Is IPA enabled?
719 * @hdd_ctx: Global HDD context
720 *
721 * Return: true if IPA is enabled, false otherwise
722 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700723bool hdd_ipa_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724{
725 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
726}
727
728/**
729 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
730 * @hdd_ctx: Global HDD context
731 *
732 * Return: true if IPA uC offload is enabled, false otherwise
733 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700734bool hdd_ipa_uc_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735{
736 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
737}
738
739/**
740 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
741 * @hdd_ctx: Global HDD context
742 *
743 * Return: true if STA mode IPA uC offload is enabled, false otherwise
744 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700745static inline bool hdd_ipa_uc_sta_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746{
747 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
748}
749
750/**
Guolei Bianca144d82016-11-10 11:07:42 +0800751 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
752 * @hdd_ipa: Global HDD IPA context
753 *
754 * Return: None
755 */
Guolei Bianca144d82016-11-10 11:07:42 +0800756static inline void hdd_ipa_uc_sta_reset_sta_connected(
757 struct hdd_ipa_priv *hdd_ipa)
758{
Yun Park637d6482016-10-05 10:51:33 -0700759 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800760 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700761 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800762}
Guolei Bianca144d82016-11-10 11:07:42 +0800763
764/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
766 * @hdd_ipa: Global HDD IPA context
767 *
768 * Return: true if pre-filter is enabled, otherwise false
769 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700770static inline bool hdd_ipa_is_pre_filter_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771{
772 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
773 HDD_IPA_PRE_FILTER_ENABLE_MASK);
774}
775
776/**
777 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
778 * @hdd_ipa: Global HDD IPA context
779 *
780 * Return: true if IPv6 is enabled, otherwise false
781 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700782static inline bool hdd_ipa_is_ipv6_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783{
784 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
785}
786
787/**
788 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
789 * @hdd_ipa: Global HDD IPA context
790 *
791 * Return: true if resource manager is enabled, otherwise false
792 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700793static inline bool hdd_ipa_is_rm_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794{
795 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
796}
797
798/**
799 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
800 * @hdd_ipa: Global HDD IPA context
801 *
802 * Return: true if resource manager is enabled, otherwise false
803 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700804static inline bool hdd_ipa_is_rt_debugging_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805{
806 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
807}
808
809/**
810 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
811 * @hdd_ipa: Global HDD IPA context
812 *
813 * Return: true if clock scaling is enabled, otherwise false
814 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700815static inline bool hdd_ipa_is_clk_scaling_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816{
817 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
818 HDD_IPA_CLK_SCALING_ENABLE_MASK |
819 HDD_IPA_RM_ENABLE_MASK);
820}
821
822/**
823 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
824 * @ctext: pointer to hdd context.
825 *
826 * If rt debug enabled, periodically called, and fill debug buffer
827 *
828 * Return: none
829 */
830static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
831{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700832 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800833 struct hdd_ipa_priv *hdd_ipa;
834 struct uc_rt_debug_info *dump_info = NULL;
835
836 if (wlan_hdd_validate_context(hdd_ctx))
837 return;
838
839 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700840 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 return;
842 }
843
844 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
845
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530846 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 dump_info = &hdd_ipa->rt_bug_buffer[
848 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
849
Deepthi Gowri6acee342016-10-28 15:00:38 +0530850 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
852 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
853 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800855 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
856 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
858 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530859 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860
Anurag Chouhan210db072016-02-22 18:42:15 +0530861 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
863}
864
865/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700866 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 * @hdd_ctx: pointer to hdd context.
868 *
869 * If rt debug enabled, dump debug buffer contents based on requirement
870 *
871 * Return: none
872 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700873static void __hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874{
875 struct hdd_ipa_priv *hdd_ipa;
876 unsigned int dump_count;
877 unsigned int dump_index;
878 struct uc_rt_debug_info *dump_info = NULL;
879
880 if (wlan_hdd_validate_context(hdd_ctx))
881 return;
882
883 hdd_ipa = hdd_ctx->hdd_ipa;
884 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700885 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 return;
887 }
888
Chris Guo1751acf2017-07-03 14:09:01 +0800889 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
890 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
891 "%s: IPA RT debug is not enabled", __func__);
892 return;
893 }
894
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530895 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530897 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800898 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530900 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 for (dump_count = 0;
902 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
903 dump_count++) {
904 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
905 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
906 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530907 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530908 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 dump_info->time, dump_info->ipa_excep_count,
910 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800911 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 dump_info->rx_destructor_call,
913 dump_info->rx_discard_count);
914 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530915 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530916 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
918}
919
920/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700921 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
922 * __hdd_ipa_uc_rt_debug_host_dump
923 * @hdd_ctx: pointer to hdd context.
924 *
925 * If rt debug enabled, dump debug buffer contents based on requirement
926 *
927 * Return: none
928 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700929void hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700930{
931 cds_ssr_protect(__func__);
932 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
933 cds_ssr_unprotect(__func__);
934}
935
936/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
938 * @ctext: pointer to hdd context.
939 *
940 * periodically called by timer expire
941 * will try to alloc dummy memory and detect out of memory condition
942 * if out of memory detected, dump wlan-ipa stats
943 *
944 * Return: none
945 */
946static void hdd_ipa_uc_rt_debug_handler(void *ctext)
947{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700948 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700949 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 void *dummy_ptr = NULL;
951
952 if (wlan_hdd_validate_context(hdd_ctx))
953 return;
954
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700955 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700958 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
959 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 return;
961 }
962
963 /* Allocate dummy buffer periodically and free immediately. this will
964 * proactively detect OOM and if allocation fails dump ipa stats
965 */
966 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
967 GFP_KERNEL | GFP_ATOMIC);
968 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
970 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -0700971 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
972 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 } else {
974 kfree(dummy_ptr);
975 }
976
Anurag Chouhan210db072016-02-22 18:42:15 +0530977 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 HDD_IPA_UC_RT_DEBUG_PERIOD);
979}
980
981/**
Yun Parkb187d542016-11-14 18:10:04 -0800982 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800983 * @skb: packet pinter
984 *
985 * when free data packet, will be invoked by wlan client and will increase
986 * free counter
987 *
988 * Return: none
989 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700990static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991{
992 if (!ghdd_ipa) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700993 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "invalid hdd context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 return;
995 }
996
997 ghdd_ipa->ipa_rx_destructor_count++;
998}
999
1000/**
Yun Parkb187d542016-11-14 18:10:04 -08001001 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002 * @hdd_ctx: hdd main context
1003 *
1004 * free all rt debugging resources
1005 *
1006 * Return: none
1007 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001008static void hdd_ipa_uc_rt_debug_deinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001010 struct hdd_ipa_priv *hdd_ipa;
1011
1012 if (wlan_hdd_validate_context(hdd_ctx))
1013 return;
1014
1015 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301017 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018
1019 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001020 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1021 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 return;
1023 }
1024
Anurag Chouhan210db072016-02-22 18:42:15 +05301025 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001026 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1027 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1028 }
1029 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1030
1031 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301032 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1033 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301035 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036}
1037
1038/**
Yun Parkb187d542016-11-14 18:10:04 -08001039 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 * @hdd_ctx: hdd main context
1041 *
1042 * alloc and initialize all rt debugging resources
1043 *
1044 * Return: none
1045 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001046static void hdd_ipa_uc_rt_debug_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001048 struct hdd_ipa_priv *hdd_ipa;
1049
Chris Guo1751acf2017-07-03 14:09:01 +08001050 if (wlan_hdd_validate_context_in_loading(hdd_ctx))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001051 return;
1052
1053 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301055 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001056 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301057 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058 sizeof(struct uc_rt_debug_info) *
1059 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1060 hdd_ipa->ipa_tx_forward = 0;
1061 hdd_ipa->ipa_rx_discard = 0;
1062 hdd_ipa->ipa_rx_net_send_count = 0;
1063 hdd_ipa->ipa_rx_internel_drop_count = 0;
1064 hdd_ipa->ipa_rx_destructor_count = 0;
1065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066 /* Reatime debug enable on feature enable */
1067 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001068 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1069 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 return;
1071 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001072
1073 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1074 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1075 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1076 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1077
Anurag Chouhan210db072016-02-22 18:42:15 +05301078 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301080 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081 HDD_IPA_UC_RT_DEBUG_PERIOD);
1082
1083}
1084
1085/**
Yun Parkb187d542016-11-14 18:10:04 -08001086 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1087 * @hdd_ipa: HDD IPA struct
1088 *
1089 * Dump entries in struct hdd_ipa
1090 *
1091 * Return: none
1092 */
1093static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1094{
1095 int i;
1096
1097 /* HDD IPA */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001098 hdd_info("==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001099 "num_iface: %d\n"
1100 "rm_state: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001101 "rm_lock: %pK\n"
1102 "uc_rm_work: %pK\n"
1103 "uc_op_work: %pK\n"
1104 "wake_lock: %pK\n"
1105 "wake_lock_work: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001106 "wake_lock_released: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08001107 "tx_ref_cnt: %d\n"
1108 "pm_queue_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001109 "\thead: %pK\n"
1110 "\ttail: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001111 "\tqlen: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001112 "pm_work: %pK\n"
1113 "pm_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001114 "suspended: %d\n",
1115 hdd_ipa->num_iface,
1116 hdd_ipa->rm_state,
1117 &hdd_ipa->rm_lock,
1118 &hdd_ipa->uc_rm_work,
1119 &hdd_ipa->uc_op_work,
1120 &hdd_ipa->wake_lock,
1121 &hdd_ipa->wake_lock_work,
1122 hdd_ipa->wake_lock_released,
Yun Parkb187d542016-11-14 18:10:04 -08001123 hdd_ipa->tx_ref_cnt.counter,
1124 hdd_ipa->pm_queue_head.head,
1125 hdd_ipa->pm_queue_head.tail,
1126 hdd_ipa->pm_queue_head.qlen,
1127 &hdd_ipa->pm_work,
1128 &hdd_ipa->pm_lock,
1129 hdd_ipa->suspended);
Jeff Johnson36e74c42017-09-18 08:15:42 -07001130 hdd_err("\nq_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001131 "pend_desc_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001132 "\tnext: %pK\n"
1133 "\tprev: %pK\n"
1134 "hdd_ctx: %pK\n"
1135 "debugfs_dir: %pK\n"
1136 "stats: %pK\n"
1137 "ipv4_notifier: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001138 "curr_prod_bw: %d\n"
1139 "curr_cons_bw: %d\n"
1140 "activated_fw_pipe: %d\n"
1141 "sap_num_connected_sta: %d\n"
1142 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001143 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001144 hdd_ipa->pend_desc_head.next,
1145 hdd_ipa->pend_desc_head.prev,
1146 hdd_ipa->hdd_ctx,
1147 hdd_ipa->debugfs_dir,
1148 &hdd_ipa->stats,
1149 &hdd_ipa->ipv4_notifier,
1150 hdd_ipa->curr_prod_bw,
1151 hdd_ipa->curr_cons_bw,
1152 hdd_ipa->activated_fw_pipe,
1153 hdd_ipa->sap_num_connected_sta,
1154 (unsigned int)hdd_ipa->sta_connected
1155 );
Srinivas Girigowda97852372017-03-06 16:52:59 -08001156 hdd_info("\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001157 "rx_pipe_handle: 0x%x\n"
1158 "resource_loading: %d\n"
1159 "resource_unloading: %d\n"
1160 "pending_cons_req: %d\n"
1161 "pending_event----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001162 "\tanchor.next: %pK\n"
1163 "\tanchor.prev: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001164 "\tcount: %d\n"
1165 "\tmax_size: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001166 "event_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001167 "ipa_tx_packets_diff: %d\n"
1168 "ipa_rx_packets_diff: %d\n"
1169 "ipa_p_tx_packets: %d\n"
1170 "ipa_p_rx_packets: %d\n"
1171 "stat_req_reason: %d\n",
1172 hdd_ipa->tx_pipe_handle,
1173 hdd_ipa->rx_pipe_handle,
1174 hdd_ipa->resource_loading,
1175 hdd_ipa->resource_unloading,
1176 hdd_ipa->pending_cons_req,
1177 hdd_ipa->pending_event.anchor.next,
1178 hdd_ipa->pending_event.anchor.prev,
1179 hdd_ipa->pending_event.count,
1180 hdd_ipa->pending_event.max_size,
1181 &hdd_ipa->event_lock,
1182 hdd_ipa->ipa_tx_packets_diff,
1183 hdd_ipa->ipa_rx_packets_diff,
1184 hdd_ipa->ipa_p_tx_packets,
1185 hdd_ipa->ipa_p_rx_packets,
1186 hdd_ipa->stat_req_reason);
1187
Srinivas Girigowda97852372017-03-06 16:52:59 -08001188 hdd_info("assoc_stas_map([id]is_reserved/sta_id): ");
Yun Parkb187d542016-11-14 18:10:04 -08001189 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001190 hdd_info(" [%d]%d/%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001191 hdd_ipa->assoc_stas_map[i].is_reserved,
1192 hdd_ipa->assoc_stas_map[i].sta_id);
1193 }
1194}
1195
1196/**
1197 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1198 * @hdd_ipa: HDD IPA struct
1199 *
1200 * Dump entire struct hdd_ipa_sys_pipe
1201 *
1202 * Return: none
1203 */
1204static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1205{
1206 int i;
1207
1208 /* IPA SYS Pipes */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001209 hdd_info("==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001210
1211 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1212 struct hdd_ipa_sys_pipe *sys_pipe;
1213 struct ipa_sys_connect_params *ipa_sys_params;
1214
1215 sys_pipe = &hdd_ipa->sys_pipe[i];
1216 ipa_sys_params = &sys_pipe->ipa_sys_params;
1217
Srinivas Girigowda97852372017-03-06 16:52:59 -08001218 hdd_info("sys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001219 "\tconn_hdl: 0x%x\n"
1220 "\tconn_hdl_valid: %d\n"
1221 "\tnat_en: %d\n"
1222 "\thdr_len %d\n"
1223 "\thdr_additional_const_len: %d\n"
1224 "\thdr_ofst_pkt_size_valid: %d\n"
1225 "\thdr_ofst_pkt_size: %d\n"
1226 "\thdr_little_endian: %d\n"
1227 "\tmode: %d\n"
1228 "\tclient: %d\n"
1229 "\tdesc_fifo_sz: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001230 "\tpriv: %pK\n"
1231 "\tnotify: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001232 "\tskip_ep_cfg: %d\n"
1233 "\tkeep_ipa_awake: %d\n",
1234 i,
1235 sys_pipe->conn_hdl,
1236 sys_pipe->conn_hdl_valid,
1237 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1238 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1239 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1240 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1241 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1242 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1243 ipa_sys_params->ipa_ep_cfg.mode.mode,
1244 ipa_sys_params->client,
1245 ipa_sys_params->desc_fifo_sz,
1246 ipa_sys_params->priv,
1247 ipa_sys_params->notify,
1248 ipa_sys_params->skip_ep_cfg,
1249 ipa_sys_params->keep_ipa_awake);
1250 }
1251}
1252
1253/**
1254 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1255 * @hdd_ipa: HDD IPA struct
1256 *
1257 * Dump entire struct hdd_ipa_iface_context
1258 *
1259 * Return: none
1260 */
1261static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1262{
1263 int i;
1264
1265 /* IPA Interface Contexts */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001266 hdd_info("==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001267
1268 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1269 struct hdd_ipa_iface_context *iface_context;
1270
1271 iface_context = &hdd_ipa->iface_context[i];
1272
Srinivas Girigowda97852372017-03-06 16:52:59 -08001273 hdd_info("iface_context[%d]----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001274 "\thdd_ipa: %pK\n"
1275 "\tadapter: %pK\n"
1276 "\ttl_context: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001277 "\tcons_client: %d\n"
1278 "\tprod_client: %d\n"
1279 "\tiface_id: %d\n"
1280 "\tsta_id: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001281 "\tinterface_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001282 "\tifa_address: 0x%x\n",
1283 i,
1284 iface_context->hdd_ipa,
1285 iface_context->adapter,
1286 iface_context->tl_context,
1287 iface_context->cons_client,
1288 iface_context->prod_client,
1289 iface_context->iface_id,
1290 iface_context->sta_id,
1291 &iface_context->interface_lock,
1292 iface_context->ifa_address);
1293 }
1294}
1295
1296/**
1297 * hdd_ipa_dump_info() - dump HDD IPA struct
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001298 * @hdd_ctx: hdd main context
Yun Parkb187d542016-11-14 18:10:04 -08001299 *
1300 * Dump entire struct hdd_ipa
1301 *
1302 * Return: none
1303 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001304void hdd_ipa_dump_info(struct hdd_context *hdd_ctx)
Yun Parkb187d542016-11-14 18:10:04 -08001305{
1306 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1307
1308 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1309 hdd_ipa_dump_sys_pipe(hdd_ipa);
1310 hdd_ipa_dump_iface_context(hdd_ipa);
1311}
1312
1313/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001314 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1315 * enabled
1316 *
1317 * This routine is called to set TX flow info if IPA is enabled
1318 *
1319 * Return: None
1320 */
1321void hdd_ipa_set_tx_flow_info(void)
1322{
1323 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1324 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001325 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07001326 struct hdd_station_ctx *pHddStaCtx;
Jeff Johnson87251032017-08-29 13:31:11 -07001327 struct hdd_ap_ctx *hdd_ap_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001328 hdd_hostapd_state_t *hostapd_state;
1329 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1330 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1331 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1332 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1333 const char *p2pMode = "DEV";
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001334 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001335 cds_context_type *cds_ctx;
1336#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1337 uint8_t targetChannel = 0;
1338 uint8_t preAdapterChannel = 0;
1339 uint8_t channel24;
1340 uint8_t channel5;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001341 struct hdd_adapter *preAdapterContext = NULL;
1342 struct hdd_adapter *adapter2_4 = NULL;
1343 struct hdd_adapter *adapter5 = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001344 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1345#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1346 struct wlan_objmgr_psoc *psoc;
1347
1348 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1349 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001350 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001351 return;
1352 }
1353
1354 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1355 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001356 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001357 return;
1358 }
1359
1360 psoc = hdd_ctx->hdd_psoc;
1361 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1362 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1363 adapter = adapterNode->pAdapter;
1364 switch (adapter->device_mode) {
1365 case QDF_STA_MODE:
1366 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1367 if (eConnectionState_Associated ==
1368 pHddStaCtx->conn_info.connState) {
1369 staChannel =
1370 pHddStaCtx->conn_info.operationChannel;
1371 qdf_copy_macaddr(&staBssid,
1372 &pHddStaCtx->conn_info.bssId);
1373#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1374 targetChannel = staChannel;
1375#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1376 }
1377 break;
1378 case QDF_P2P_CLIENT_MODE:
1379 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1380 if (eConnectionState_Associated ==
1381 pHddStaCtx->conn_info.connState) {
1382 p2pChannel =
1383 pHddStaCtx->conn_info.operationChannel;
1384 qdf_copy_macaddr(&p2pBssid,
1385 &pHddStaCtx->conn_info.bssId);
1386 p2pMode = "CLI";
1387#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1388 targetChannel = p2pChannel;
1389#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1390 }
1391 break;
1392 case QDF_P2P_GO_MODE:
1393 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1394 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1395 if (hostapd_state->bssState == BSS_START
1396 && hostapd_state->qdf_status ==
1397 QDF_STATUS_SUCCESS) {
1398 p2pChannel = hdd_ap_ctx->operatingChannel;
1399 qdf_copy_macaddr(&p2pBssid,
1400 &adapter->macAddressCurrent);
1401#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1402 targetChannel = p2pChannel;
1403#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1404 }
1405 p2pMode = "GO";
1406 break;
1407 case QDF_SAP_MODE:
1408 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1409 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1410 if (hostapd_state->bssState == BSS_START
1411 && hostapd_state->qdf_status ==
1412 QDF_STATUS_SUCCESS) {
1413 apChannel = hdd_ap_ctx->operatingChannel;
1414 qdf_copy_macaddr(&apBssid,
1415 &adapter->macAddressCurrent);
1416#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1417 targetChannel = apChannel;
1418#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1419 }
1420 break;
1421 case QDF_IBSS_MODE:
1422 default:
1423 break;
1424 }
1425#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1426 if (targetChannel) {
1427 /*
1428 * This is first adapter detected as active
1429 * set as default for none concurrency case
1430 */
1431 if (!preAdapterChannel) {
1432 /* If IPA UC data path is enabled,
1433 * target should reserve extra tx descriptors
1434 * for IPA data path.
1435 * Then host data path should allow less TX
1436 * packet pumping in case IPA
1437 * data path enabled
1438 */
1439 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1440 (QDF_SAP_MODE == adapter->device_mode)) {
1441 adapter->tx_flow_low_watermark =
1442 hdd_ctx->config->TxFlowLowWaterMark +
1443 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1444 } else {
1445 adapter->tx_flow_low_watermark =
1446 hdd_ctx->config->
1447 TxFlowLowWaterMark;
1448 }
1449 adapter->tx_flow_high_watermark_offset =
1450 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1451 cdp_fc_ll_set_tx_pause_q_depth(soc,
1452 adapter->sessionId,
1453 hdd_ctx->config->TxFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001454 hdd_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001455 adapter->device_mode,
1456 targetChannel,
1457 adapter->tx_flow_low_watermark,
1458 adapter->tx_flow_low_watermark +
1459 adapter->tx_flow_high_watermark_offset,
1460 hdd_ctx->config->TxFlowMaxQueueDepth);
1461 preAdapterChannel = targetChannel;
1462 preAdapterContext = adapter;
1463 } else {
1464 /*
1465 * SCC, disable TX flow control for both
1466 * SCC each adapter cannot reserve dedicated
1467 * channel resource, as a result, if any adapter
1468 * blocked OS Q by flow control,
1469 * blocked adapter will lost chance to recover
1470 */
1471 if (preAdapterChannel == targetChannel) {
1472 /* Current adapter */
1473 adapter->tx_flow_low_watermark = 0;
1474 adapter->
1475 tx_flow_high_watermark_offset = 0;
1476 cdp_fc_ll_set_tx_pause_q_depth(soc,
1477 adapter->sessionId,
1478 hdd_ctx->config->
1479 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001480 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001481 hdd_device_mode_to_string(
1482 adapter->device_mode),
1483 adapter->device_mode,
1484 targetChannel,
1485 adapter->tx_flow_low_watermark,
1486 adapter->tx_flow_low_watermark +
1487 adapter->
1488 tx_flow_high_watermark_offset,
1489 hdd_ctx->config->
1490 TxHbwFlowMaxQueueDepth);
1491
1492 if (!preAdapterContext) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001493 hdd_err("SCC: Previous adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001494 continue;
1495 }
1496
1497 /* Previous adapter */
1498 preAdapterContext->
1499 tx_flow_low_watermark = 0;
1500 preAdapterContext->
1501 tx_flow_high_watermark_offset = 0;
1502 cdp_fc_ll_set_tx_pause_q_depth(soc,
1503 preAdapterContext->sessionId,
1504 hdd_ctx->config->
1505 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001506 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001507 hdd_device_mode_to_string(
1508 preAdapterContext->device_mode
1509 ),
1510 preAdapterContext->device_mode,
1511 targetChannel,
1512 preAdapterContext->
1513 tx_flow_low_watermark,
1514 preAdapterContext->
1515 tx_flow_low_watermark +
1516 preAdapterContext->
1517 tx_flow_high_watermark_offset,
1518 hdd_ctx->config->
1519 TxHbwFlowMaxQueueDepth);
1520 }
1521 /*
1522 * MCC, each adapter will have dedicated
1523 * resource
1524 */
1525 else {
1526 /* current channel is 2.4 */
1527 if (targetChannel <=
1528 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1529 channel24 = targetChannel;
1530 channel5 = preAdapterChannel;
1531 adapter2_4 = adapter;
1532 adapter5 = preAdapterContext;
1533 } else {
1534 /* Current channel is 5 */
1535 channel24 = preAdapterChannel;
1536 channel5 = targetChannel;
1537 adapter2_4 = preAdapterContext;
1538 adapter5 = adapter;
1539 }
1540
1541 if (!adapter5) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001542 hdd_err("MCC: 5GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001543 continue;
1544 }
1545 adapter5->tx_flow_low_watermark =
1546 hdd_ctx->config->
1547 TxHbwFlowLowWaterMark;
1548 adapter5->
1549 tx_flow_high_watermark_offset =
1550 hdd_ctx->config->
1551 TxHbwFlowHighWaterMarkOffset;
1552 cdp_fc_ll_set_tx_pause_q_depth(soc,
1553 adapter5->sessionId,
1554 hdd_ctx->config->
1555 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001556 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001557 hdd_device_mode_to_string(
1558 adapter5->device_mode),
1559 adapter5->device_mode,
1560 channel5,
1561 adapter5->tx_flow_low_watermark,
1562 adapter5->
1563 tx_flow_low_watermark +
1564 adapter5->
1565 tx_flow_high_watermark_offset,
1566 hdd_ctx->config->
1567 TxHbwFlowMaxQueueDepth);
1568
1569 if (!adapter2_4) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001570 hdd_err("MCC: 2.4GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001571 continue;
1572 }
1573 adapter2_4->tx_flow_low_watermark =
1574 hdd_ctx->config->
1575 TxLbwFlowLowWaterMark;
1576 adapter2_4->
1577 tx_flow_high_watermark_offset =
1578 hdd_ctx->config->
1579 TxLbwFlowHighWaterMarkOffset;
1580 cdp_fc_ll_set_tx_pause_q_depth(soc,
1581 adapter2_4->sessionId,
1582 hdd_ctx->config->
1583 TxLbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001584 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001585 hdd_device_mode_to_string(
1586 adapter2_4->device_mode),
1587 adapter2_4->device_mode,
1588 channel24,
1589 adapter2_4->
1590 tx_flow_low_watermark,
1591 adapter2_4->
1592 tx_flow_low_watermark +
1593 adapter2_4->
1594 tx_flow_high_watermark_offset,
1595 hdd_ctx->config->
1596 TxLbwFlowMaxQueueDepth);
1597
1598 }
1599 }
1600 }
1601 targetChannel = 0;
1602#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1603 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1604 adapterNode = pNext;
1605 }
1606 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1607}
1608
1609/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001610 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001612 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1613 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 *
1615 * Return: true if IPA is enabled, false otherwise
1616 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001617static void __hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1619{
1620 struct hdd_ipa_priv *hdd_ipa;
1621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 *ipa_tx_diff = 0;
1623 *ipa_rx_diff = 0;
1624
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001625 if (wlan_hdd_validate_context(hdd_ctx))
1626 return;
1627
1628 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1629
1630 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1631 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 return;
1633 }
1634
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301635 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1637 (false == hdd_ipa->resource_loading)) {
1638 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1639 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001640 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641 *ipa_tx_diff, *ipa_rx_diff);
1642 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301643 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644}
1645
1646/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001647 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1648 * @hdd_ctx: Global HDD context
1649 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1650 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1651 *
1652 * Return: true if IPA is enabled, false otherwise
1653 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001654void hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001655 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1656{
1657 cds_ssr_protect(__func__);
1658 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1659 cds_ssr_unprotect(__func__);
1660}
1661
1662/**
1663 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664 * @adapter: network adapter
1665 * @reason: STAT REQ Reason
1666 *
1667 * Return: None
1668 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001669static void __hdd_ipa_uc_stat_request(struct hdd_adapter *adapter, uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001671 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 struct hdd_ipa_priv *hdd_ipa;
1673
Yun Park637d6482016-10-05 10:51:33 -07001674 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001675 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676
Jeff Johnson399c6272017-08-30 10:51:00 -07001677 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001678
1679 if (wlan_hdd_validate_context(hdd_ctx))
1680 return;
1681
1682 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1683 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1684 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685 return;
1686 }
1687
Yun Parkb187d542016-11-14 18:10:04 -08001688 hdd_debug("STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301689 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1691 (false == hdd_ipa->resource_loading)) {
1692 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001693 qdf_mutex_release(&hdd_ipa->ipa_lock);
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001694 sme_ipa_uc_stat_request(WLAN_HDD_GET_HAL_CTX(adapter),
1695 adapter->sessionId,
1696 WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001698 } else {
1699 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701}
1702
1703/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001704 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1705 * @adapter: network adapter
1706 * @reason: STAT REQ Reason
1707 *
1708 * Return: None
1709 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001710void hdd_ipa_uc_stat_request(struct hdd_adapter *adapter, uint8_t reason)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001711{
1712 cds_ssr_protect(__func__);
1713 __hdd_ipa_uc_stat_request(adapter, reason);
1714 cds_ssr_unprotect(__func__);
1715}
1716
Yun Park637d6482016-10-05 10:51:33 -07001717#ifdef FEATURE_METERING
1718/**
1719 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1720 * @adapter: network adapter
1721 * @reset_stats: reset stat countis after response
1722 *
1723 * Return: None
1724 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001725void hdd_ipa_uc_sharing_stats_request(struct hdd_adapter *adapter,
Yun Park637d6482016-10-05 10:51:33 -07001726 uint8_t reset_stats)
1727{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001728 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001729 struct hdd_ipa_priv *hdd_ipa;
1730
1731 if (!adapter)
1732 return;
1733
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001734 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1735 hdd_ipa = hdd_ctx->hdd_ipa;
1736 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1737 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001738 return;
1739 }
1740
1741 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1742 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001743 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001744 qdf_mutex_release(&hdd_ipa->ipa_lock);
1745 wma_cli_set_command(
1746 (int)adapter->sessionId,
1747 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1748 reset_stats, VDEV_CMD);
1749 } else {
1750 qdf_mutex_release(&hdd_ipa->ipa_lock);
1751 }
1752}
1753
1754/**
1755 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1756 * @adapter: network adapter
1757 * @set_quota: when 1, FW starts quota monitoring
1758 * @quota_bytes: quota limit in bytes
1759 *
1760 * Return: None
1761 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001762void hdd_ipa_uc_set_quota(struct hdd_adapter *adapter, uint8_t set_quota,
Yun Park637d6482016-10-05 10:51:33 -07001763 uint64_t quota_bytes)
1764{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001765 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001766 struct hdd_ipa_priv *hdd_ipa;
1767
1768 if (!adapter)
1769 return;
1770
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001771 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1772 hdd_ipa = hdd_ctx->hdd_ipa;
1773 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1774 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001775 return;
1776 }
1777
1778 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1779 set_quota, quota_bytes);
1780
1781 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001782 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001783 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001784 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001785 (int)adapter->sessionId,
1786 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001787 (set_quota ? quota_bytes&0xffffffff : 0),
1788 (set_quota ? quota_bytes>>32 : 0),
1789 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001790 } else {
1791 qdf_mutex_release(&hdd_ipa->ipa_lock);
1792 }
1793}
1794#endif
1795
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001796/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1798 * @hdd_ipa: Global HDD IPA context
1799 * @sta_add: Should station be added
1800 * @sta_id: ID of the station being queried
1801 *
1802 * Return: true if the station was found
1803 */
1804static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1805 bool sta_add, uint8_t sta_id)
1806{
1807 bool sta_found = false;
1808 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001809
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001810 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1811 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1812 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1813 sta_found = true;
1814 break;
1815 }
1816 }
1817 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301818 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001819 "STA ID %d already exist, cannot add", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001820 return sta_found;
1821 }
1822 if (sta_add) {
1823 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1824 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1825 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1826 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1827 return sta_found;
1828 }
1829 }
1830 }
1831 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301832 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001833 "STA ID %d does not exist, cannot delete", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 return sta_found;
1835 }
1836 if (!sta_add) {
1837 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1838 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1839 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1840 hdd_ipa->assoc_stas_map[idx].is_reserved =
1841 false;
1842 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1843 return sta_found;
1844 }
1845 }
1846 }
1847 return sta_found;
1848}
1849
1850/**
1851 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1852 * @hdd_ipa: Global HDD IPA context
1853 *
1854 * Return: 0 on success, negative errno if error
1855 */
1856static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1857{
1858 int result;
Leo Changfdb45c32016-10-28 11:09:23 -07001859 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001860 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001861
Yun Parkb4f591d2017-03-29 15:51:01 -07001862 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301864 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001865 "Enable PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866 return result;
1867 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001868
Yun Park777d7242017-03-30 15:38:33 -07001869 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Leo Change3e49442015-10-26 20:07:13 -07001870 hdd_ipa->ipa_pipes_down = false;
Yun Parkb4f591d2017-03-29 15:51:01 -07001871
1872 cdp_ipa_enable_autonomy(soc, (struct cdp_pdev *)pdev);
1873
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001874 return 0;
1875}
1876
1877/**
1878 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1879 * @hdd_ipa: Global HDD IPA context
1880 *
1881 * Return: 0 on success, negative errno if error
1882 */
1883static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1884{
Yun Parkb4f591d2017-03-29 15:51:01 -07001885 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1886 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887 int result;
1888
Leo Change3e49442015-10-26 20:07:13 -07001889 hdd_ipa->ipa_pipes_down = true;
1890
Yun Parkb4f591d2017-03-29 15:51:01 -07001891 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001892
Yun Parkb4f591d2017-03-29 15:51:01 -07001893 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001894 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301895 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001896 "Disable WDI PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001897 return result;
1898 }
1899
1900 return 0;
1901}
1902
1903/**
1904 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1905 * @hdd_ipa: Global HDD IPA context
1906 *
1907 * Return: 0 on success, negative errno if error
1908 */
1909static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1910{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001911 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07001912
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913 hdd_ipa->activated_fw_pipe = 0;
1914 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001915
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001916 /* If RM feature enabled
1917 * Request PROD Resource first
Yun Parkb4f591d2017-03-29 15:51:01 -07001918 * PROD resource may return sync or async manners */
1919 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001920 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1921 /* RM PROD request sync return
1922 * enable pipe immediately
1923 */
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301924 if (!hdd_ipa->ipa_pipes_down) {
1925 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1926 "%s: IPA WDI Pipe already activated",
1927 __func__);
1928 return 0;
1929 }
1930
Yun Park4cab6ee2015-10-27 11:43:40 -07001931 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301932 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001933 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001934 hdd_ipa->resource_loading = false;
1935 return -EBUSY;
1936 }
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301937 } else {
1938 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
1939 "%s: IPA WDI Pipe activation deferred",
1940 __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001941 }
1942 } else {
1943 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001944 * Just enabled all the PIPEs
1945 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001946 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301947 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001948 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001949 hdd_ipa->resource_loading = false;
1950 return -EBUSY;
1951 }
1952 hdd_ipa->resource_loading = false;
1953 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001954
Srinivas Girigowda97852372017-03-06 16:52:59 -08001955 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07001956 "IPA WDI Pipes activated successfully");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 return 0;
1958}
1959
1960/**
1961 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1962 * @hdd_ipa: Global HDD IPA context
1963 *
1964 * Return: None
1965 */
1966static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1967{
Leo Changfdb45c32016-10-28 11:09:23 -07001968 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001969 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001970
Yun Parkb4f591d2017-03-29 15:51:01 -07001971 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08001972 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
1973 QDF_ASSERT(0);
1974 return;
1975 }
1976
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001977 hdd_ipa->resource_unloading = true;
Yun Park777d7242017-03-30 15:38:33 -07001978 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Yun Parkb4f591d2017-03-29 15:51:01 -07001979 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
1980 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
1981 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
1982 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001983}
1984
1985/**
1986 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1987 * @context: User context registered with TL (the IPA Global context is
1988 * registered
1989 * @rxpkt: Packet containing the notification
1990 * @staid: ID of the station associated with the packet
1991 *
1992 * Return: None
1993 */
1994static void
1995hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1996{
1997 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301998 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001999 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002000
2001 /*
2002 * When SSR is going on or driver is unloading, just return.
2003 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002004 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302005 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002007
Yun Parkb4f591d2017-03-29 15:51:01 -07002008 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009 return;
2010
Srinivas Girigowda97852372017-03-06 16:52:59 -08002011 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012 __func__, event);
2013
2014 switch (event) {
2015 case IPA_RM_RESOURCE_GRANTED:
2016 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302017 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002018 if ((false == hdd_ipa->resource_unloading) &&
2019 (!hdd_ipa->activated_fw_pipe)) {
2020 hdd_ipa_uc_enable_pipes(hdd_ipa);
2021 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302022 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002023 break;
2024
2025 case IPA_RM_RESOURCE_RELEASED:
2026 /* Differed RM Released */
2027 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 break;
2029
2030 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302031 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002032 "%s, invalid event code %d", __func__, event);
2033 break;
2034 }
2035}
2036
2037/**
2038 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2039 * @hdd_ipa: Global HDD IPA context
2040 * @event: IPA resource manager event to be deferred
2041 *
2042 * This function is called when a resource manager event is received
2043 * from firmware in interrupt context. This function will defer the
2044 * handling to the OL RX thread
2045 *
2046 * Return: None
2047 */
2048static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2049{
2050 enum ipa_rm_event event;
2051 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2052 struct uc_rm_work_struct, work);
2053 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2054 struct hdd_ipa_priv, uc_rm_work);
2055
2056 cds_ssr_protect(__func__);
2057 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002058 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002059 "%s, posted event %d", __func__, event);
2060
2061 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2062 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002063}
2064
2065/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002066 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002067 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002068 *
2069 * Will handle IPA UC image loaded indication comes from IPA kernel
2070 *
2071 * Return: None
2072 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002073static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002074{
Yun Parkb4f591d2017-03-29 15:51:01 -07002075 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2076 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002077 struct hdd_context *hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07002078 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002079
2080 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
Yun Parkb4f591d2017-03-29 15:51:01 -07002081 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002082 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002083 __func__);
2084 return;
2085 }
2086
Yun Parkb4f591d2017-03-29 15:51:01 -07002087 hdd_ctx = hdd_ipa->hdd_ctx;
2088 hdd_ipa->uc_loaded = true;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002089
Yun Parkb4f591d2017-03-29 15:51:01 -07002090 /* Connect pipe */
2091 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2092 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2093 hdd_ipa_wdi_meter_notifier_cb,
2094 hdd_ctx->config->IpaDescSize,
2095 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2096 &hdd_ipa->tx_pipe_handle,
2097 &hdd_ipa->rx_pipe_handle);
2098 if (status) {
2099 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2100 "Failure to setup IPA pipes (status=%d)",
2101 status);
2102 return;
2103 }
2104
2105 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002106
2107 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002108 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002109 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002110 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002111 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002112 }
2113}
2114
2115/**
Yun Park637d6482016-10-05 10:51:33 -07002116 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2117 * @hdd_ctx: Global HDD context
2118 * @op_msg: operation message received from firmware
2119 *
2120 * Return: QDF_STATUS enumeration
2121 */
2122#ifdef FEATURE_METERING
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002123static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002124 struct op_msg_type *op_msg)
2125{
2126 struct op_msg_type *msg = op_msg;
2127 struct ipa_uc_sharing_stats *uc_sharing_stats;
2128 struct ipa_uc_quota_rsp *uc_quota_rsp;
2129 struct ipa_uc_quota_ind *uc_quota_ind;
2130 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002131 struct hdd_adapter *adapter;
Yun Park637d6482016-10-05 10:51:33 -07002132
2133 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2134
2135 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2136 /* fill-up ipa_uc_sharing_stats structure from FW */
2137 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2138 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2139
2140 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2141 sizeof(struct ipa_uc_sharing_stats));
2142
2143 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2144
2145 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2146 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2147 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2148 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2149 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2150 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2151 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2152 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2153 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2154 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2155 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2156 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2157 /* received set quota response */
2158 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2159 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2160
2161 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2162 sizeof(struct ipa_uc_quota_rsp));
2163
2164 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2165 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2166 "%s: success=%d, quota_bytes=%llu",
2167 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2168 hdd_ipa->ipa_quota_rsp.success,
2169 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2170 hdd_ipa->ipa_quota_rsp.quota_lo);
2171 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2172 /* hit quota limit */
2173 uc_quota_ind = (struct ipa_uc_quota_ind *)
2174 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2175
2176 hdd_ipa->ipa_quota_ind.quota_bytes =
2177 uc_quota_ind->quota_bytes;
2178
2179 /* send quota exceeded indication to IPA */
2180 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2181 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2182 hdd_ipa->ipa_quota_ind.quota_bytes);
2183
2184 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2185 if (adapter)
2186 ipa_broadcast_wdi_quota_reach_ind(
2187 adapter->dev->ifindex,
2188 uc_quota_ind->quota_bytes);
2189 else
2190 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2191 "Failed quota_reach_ind: NULL adapter");
2192 } else {
2193 return QDF_STATUS_E_INVAL;
2194 }
2195
2196 return QDF_STATUS_SUCCESS;
2197}
2198#else
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002199static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002200 struct op_msg_type *op_msg)
2201{
2202 return QDF_STATUS_E_INVAL;
2203}
2204#endif
2205
2206/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002207 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2208 * @op_msg: operation message received from firmware
2209 * @usr_ctxt: user context registered with TL (we register the HDD Global
2210 * context)
2211 *
2212 * Return: None
2213 */
2214static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2215{
2216 struct op_msg_type *msg = op_msg;
2217 struct ipa_uc_fw_stats *uc_fw_stat;
2218 struct IpaHwStatsWDIInfoData_t ipa_stat;
2219 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002220 struct hdd_context *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302221 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002222
2223 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302224 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002225 return;
2226 }
2227
2228 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302229 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002230 "%s, INVALID OPCODE %d", __func__, msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002231 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002232 return;
2233 }
2234
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002235 hdd_ctx = (struct hdd_context *) usr_ctxt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002236
2237 /*
2238 * When SSR is going on or driver is unloading, just return.
2239 */
2240 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302241 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302242 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002243 return;
2244 }
2245
2246 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2247
Govind Singhb6a89772016-08-12 11:23:35 +05302248 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002249 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250
2251 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2252 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302253 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002254 hdd_ipa->activated_fw_pipe++;
2255 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2256 hdd_ipa->resource_loading = false;
Yun Park777d7242017-03-30 15:38:33 -07002257 complete(&hdd_ipa->ipa_resource_comp);
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002258 if (hdd_ipa->wdi_enabled == false) {
2259 hdd_ipa->wdi_enabled = true;
2260 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2261 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2262 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002263 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002264 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002265 if (hdd_ipa->pending_cons_req)
2266 ipa_rm_notify_completion(
2267 IPA_RM_RESOURCE_GRANTED,
2268 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002269 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002270 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302271 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002272 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002273 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302274 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002275 hdd_ipa->activated_fw_pipe--;
2276 if (!hdd_ipa->activated_fw_pipe) {
Yun Park777d7242017-03-30 15:38:33 -07002277 /*
2278 * Async return success from FW
2279 * Disable/suspend all the PIPEs
2280 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002281 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002282 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2283 ipa_rm_release_resource(
2284 IPA_RM_RESOURCE_WLAN_PROD);
Yun Park5b635012015-12-02 15:05:01 -08002285 hdd_ipa->resource_unloading = false;
Yun Park777d7242017-03-30 15:38:33 -07002286 complete(&hdd_ipa->ipa_resource_comp);
Yun Park5b635012015-12-02 15:05:01 -08002287 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2288 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002289 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302290 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002291 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002292 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002293 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302294 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002295 "==== IPA_UC WLAN_HOST RX ====\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002296 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002297 "NUM TX FWD OK : %llu\n"
2298 "NUM TX FWD ERR : %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002299 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002300 hdd_ipa->stats.num_tx_fwd_ok,
2301 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302302 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002303 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2304 "SAP NUM STAs: %d\n"
2305 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002306 "CONCURRENT MODE: %s\n"
2307 "TX PIPE HDL: 0x%x\n"
2308 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002309 "RSC LOADING : %d\n"
2310 "RSC UNLOADING : %d\n"
2311 "PNDNG CNS RQT : %d",
2312 hdd_ipa->sap_num_connected_sta,
2313 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002314 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002315 hdd_ipa->tx_pipe_handle,
2316 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002317 hdd_ipa->resource_loading,
2318 hdd_ipa->resource_unloading,
2319 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002320
2321 /* STATs from FW */
2322 uc_fw_stat = (struct ipa_uc_fw_stats *)
2323 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302324 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002325 "==== IPA_UC WLAN_FW TX ====\n"
2326 "COMP RING BASE: 0x%x\n"
2327 "COMP RING SIZE: %d\n"
2328 "COMP RING DBELL : 0x%x\n"
2329 "COMP RING DBELL IND VAL : %d\n"
2330 "COMP RING DBELL CACHED VAL : %d\n"
2331 "COMP RING DBELL CACHED VAL : %d\n"
2332 "PKTS ENQ : %d\n"
2333 "PKTS COMP : %d\n"
2334 "IS SUSPEND : %d\n"
2335 "RSVD : 0x%x",
2336 uc_fw_stat->tx_comp_ring_base,
2337 uc_fw_stat->tx_comp_ring_size,
2338 uc_fw_stat->tx_comp_ring_dbell_addr,
2339 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2340 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2341 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2342 uc_fw_stat->tx_pkts_enqueued,
2343 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002344 uc_fw_stat->tx_is_suspend,
2345 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302346 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002347 "==== IPA_UC WLAN_FW RX ====\n"
2348 "IND RING BASE: 0x%x\n"
2349 "IND RING SIZE: %d\n"
2350 "IND RING DBELL : 0x%x\n"
2351 "IND RING DBELL IND VAL : %d\n"
2352 "IND RING DBELL CACHED VAL : %d\n"
2353 "RDY IND ADDR : 0x%x\n"
2354 "RDY IND CACHE VAL : %d\n"
2355 "RFIL IND : %d\n"
2356 "NUM PKT INDICAT : %d\n"
2357 "BUF REFIL : %d\n"
2358 "NUM DROP NO SPC : %d\n"
2359 "NUM DROP NO BUF : %d\n"
2360 "IS SUSPND : %d\n"
2361 "RSVD : 0x%x\n",
2362 uc_fw_stat->rx_ind_ring_base,
2363 uc_fw_stat->rx_ind_ring_size,
2364 uc_fw_stat->rx_ind_ring_dbell_addr,
2365 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2366 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2367 uc_fw_stat->rx_ind_ring_rdidx_addr,
2368 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2369 uc_fw_stat->rx_refill_idx,
2370 uc_fw_stat->rx_num_pkts_indicated,
2371 uc_fw_stat->rx_buf_refilled,
2372 uc_fw_stat->rx_num_ind_drop_no_space,
2373 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002374 uc_fw_stat->rx_is_suspend,
2375 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002376 /* STATs from IPA */
2377 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302378 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002379 "==== IPA_UC IPA TX ====\n"
2380 "NUM PROCD : %d\n"
2381 "CE DBELL : 0x%x\n"
2382 "NUM DBELL FIRED : %d\n"
2383 "COMP RNG FULL : %d\n"
2384 "COMP RNG EMPT : %d\n"
2385 "COMP RNG USE HGH : %d\n"
2386 "COMP RNG USE LOW : %d\n"
2387 "BAM FIFO FULL : %d\n"
2388 "BAM FIFO EMPT : %d\n"
2389 "BAM FIFO USE HGH : %d\n"
2390 "BAM FIFO USE LOW : %d\n"
2391 "NUM DBELL : %d\n"
2392 "NUM UNEXP DBELL : %d\n"
2393 "NUM BAM INT HDL : 0x%x\n"
2394 "NUM BAM INT NON-RUN : 0x%x\n"
2395 "NUM QMB INT HDL : 0x%x",
2396 ipa_stat.tx_ch_stats.num_pkts_processed,
2397 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2398 ipa_stat.tx_ch_stats.num_db_fired,
2399 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2400 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2401 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2402 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2403 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2404 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2405 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2406 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2407 ipa_stat.tx_ch_stats.num_db,
2408 ipa_stat.tx_ch_stats.num_unexpected_db,
2409 ipa_stat.tx_ch_stats.num_bam_int_handled,
2410 ipa_stat.tx_ch_stats.
2411 num_bam_int_in_non_runnning_state,
2412 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2413
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302414 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002415 "==== IPA_UC IPA RX ====\n"
2416 "MAX OST PKT : %d\n"
2417 "NUM PKT PRCSD : %d\n"
2418 "RNG RP : 0x%x\n"
2419 "COMP RNG FULL : %d\n"
2420 "COMP RNG EMPT : %d\n"
2421 "COMP RNG USE HGH : %d\n"
2422 "COMP RNG USE LOW : %d\n"
2423 "BAM FIFO FULL : %d\n"
2424 "BAM FIFO EMPT : %d\n"
2425 "BAM FIFO USE HGH : %d\n"
2426 "BAM FIFO USE LOW : %d\n"
2427 "NUM DB : %d\n"
2428 "NUM UNEXP DB : %d\n"
2429 "NUM BAM INT HNDL : 0x%x\n",
2430 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2431 ipa_stat.rx_ch_stats.num_pkts_processed,
2432 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2433 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2434 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2435 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2436 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2437 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2438 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2439 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2440 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2441 ipa_stat.rx_ch_stats.num_db,
2442 ipa_stat.rx_ch_stats.num_unexpected_db,
2443 ipa_stat.rx_ch_stats.num_bam_int_handled);
2444 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2445 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2446 /* STATs from FW */
2447 uc_fw_stat = (struct ipa_uc_fw_stats *)
2448 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302449 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002450 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2451 uc_fw_stat->tx_pkts_completed,
2452 hdd_ipa->ipa_p_tx_packets);
2453 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2454 (uc_fw_stat->rx_num_ind_drop_no_space +
2455 uc_fw_stat->rx_num_ind_drop_no_buf +
2456 uc_fw_stat->rx_num_pkts_indicated),
2457 hdd_ipa->ipa_p_rx_packets);
2458
2459 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2460 hdd_ipa->ipa_p_rx_packets =
2461 (uc_fw_stat->rx_num_ind_drop_no_space +
2462 uc_fw_stat->rx_num_ind_drop_no_buf +
2463 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302464 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002465 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2466 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2467 hdd_ipa_uc_loaded_handler(hdd_ipa);
2468 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002469 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2470 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2471 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002472 }
Yun Park8957d802017-01-25 12:27:29 -08002473
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302474 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002475}
2476
2477
2478/**
2479 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2480 * @adapter: device adapter instance
2481 * @offload_type: MCC or SCC
2482 * @enable: TX offload enable or disable
2483 *
2484 * Return: none
2485 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002486static void hdd_ipa_uc_offload_enable_disable(struct hdd_adapter *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002487 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002489 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002490 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002491 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002492 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002493
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002494 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002495 return;
2496
Yun Park8292dcb2016-10-07 16:46:06 -07002497 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002498 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002499
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002500 if (!iface_context) {
2501 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2502 "Interface context is NULL");
2503 return;
2504 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002505 if (session_id >= CSR_ROAM_SESSION_MAX) {
2506 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2507 "invalid session id: %d", session_id);
2508 return;
2509 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002510 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002511 /* IPA offload status is already set as desired */
2512 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002513 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002514 "IPA offload status is already set",
2515 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002516 return;
2517 }
2518
Yun Park4540e862016-11-10 16:30:06 -08002519 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2520 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2521 "invalid session id: %d, offload_type=%d, enable=%d",
2522 adapter->sessionId, offload_type, enable);
2523 return;
2524 }
2525
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302526 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002527 sizeof(ipa_offload_enable_disable));
2528 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002529 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530 ipa_offload_enable_disable.enable = enable;
2531
Srinivas Girigowda97852372017-03-06 16:52:59 -08002532 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002533 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002534 ipa_offload_enable_disable.offload_type,
2535 ipa_offload_enable_disable.vdev_id,
2536 ipa_offload_enable_disable.enable);
2537
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302538 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002539 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2540 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302541 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002542 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
2543 "Failure to enable IPA offload",
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002544 ipa_offload_enable_disable.offload_type,
2545 ipa_offload_enable_disable.vdev_id,
2546 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002547 } else {
2548 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002549 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002550 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002551 }
2552}
2553
2554/**
2555 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2556 * @work: uC OP work
2557 *
2558 * Return: None
2559 */
2560static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2561{
2562 struct op_msg_type *msg;
2563 struct uc_op_work_struct *uc_op_work = container_of(work,
2564 struct uc_op_work_struct, work);
2565 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2566
2567 cds_ssr_protect(__func__);
2568
2569 msg = uc_op_work->msg;
2570 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002571 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002572 "%s, posted msg %d", __func__, msg->op_code);
2573
2574 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2575
2576 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002577}
2578
2579/**
2580 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2581 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2582 * @op_msg: operation message received from firmware
2583 * @hdd_ctx: Global HDD context
2584 *
2585 * Return: None
2586 */
2587static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2588{
2589 struct hdd_ipa_priv *hdd_ipa;
2590 struct op_msg_type *msg;
2591 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302592 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593
2594 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302595 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002596 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002597
2598 msg = (struct op_msg_type *)op_msg;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002599 hdd_ipa = ((struct hdd_context *)hdd_ctx)->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002600
2601 if (unlikely(!hdd_ipa))
2602 goto end;
2603
2604 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002605 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2606 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002607 goto end;
2608 }
2609
2610 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2611 if (uc_op_work->msg)
2612 /* When the same uC OPCODE is already pended, just return */
2613 goto end;
2614
2615 uc_op_work->msg = msg;
2616 schedule_work(&uc_op_work->work);
2617 return;
2618
2619end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302620 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002621}
2622
2623/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002624 * hdd_ipa_init_uc_op_work - init ipa uc op work
2625 * @work: struct work_struct
2626 * @work_handler: work_handler
2627 *
2628 * Return: none
2629 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002630static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002631 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002632{
2633 INIT_WORK(work, work_handler);
2634}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002635
Yun Park637d6482016-10-05 10:51:33 -07002636#ifdef FEATURE_METERING
2637/**
2638 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2639 * IPA calls to get WLAN stats or set quota limit.
2640 * @priv: pointer to private data registered with IPA (we register a
2641 *» pointer to the global IPA context)
2642 * @evt: the IPA event which triggered the callback
2643 * @data: data associated with the event
2644 *
2645 * Return: None
2646 */
2647static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2648 void *data)
2649{
2650 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002651 struct hdd_adapter *adapter = NULL;
Yun Park637d6482016-10-05 10:51:33 -07002652 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2653 struct ipa_set_wifi_quota *ipa_set_quota;
2654 int ret = 0;
2655
2656 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2657 return;
2658
2659 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2660
2661 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2662
2663 switch (evt) {
2664 case IPA_GET_WDI_SAP_STATS:
2665 /* fill-up ipa_get_wdi_sap_stats structure after getting
2666 ipa_uc_fw_stats from FW */
2667 wdi_sap_stats = data;
2668
2669 if (!adapter) {
2670 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2671 "IPA uC share stats failed - no adapter");
2672 wdi_sap_stats->stats_valid = 0;
2673 return;
2674 }
2675
2676 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
Yun Park637d6482016-10-05 10:51:33 -07002677 hdd_ipa_uc_sharing_stats_request(adapter,
2678 wdi_sap_stats->reset_stats);
2679 ret = wait_for_completion_timeout(
2680 &hdd_ipa->ipa_uc_sharing_stats_comp,
2681 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2682 if (!ret) {
2683 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2684 "IPA uC share stats request timed out");
2685 wdi_sap_stats->stats_valid = 0;
2686 } else {
2687 wdi_sap_stats->stats_valid = 1;
2688
2689 wdi_sap_stats->ipv4_rx_packets =
2690 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2691 wdi_sap_stats->ipv4_rx_bytes =
2692 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2693 wdi_sap_stats->ipv6_rx_packets =
2694 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2695 wdi_sap_stats->ipv6_rx_bytes =
2696 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2697 wdi_sap_stats->ipv4_tx_packets =
2698 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2699 wdi_sap_stats->ipv4_tx_bytes =
2700 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2701 wdi_sap_stats->ipv6_tx_packets =
2702 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2703 wdi_sap_stats->ipv6_tx_bytes =
2704 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2705 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2706 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2707 "IPA_GET_WDI_SAP_STATS",
2708 wdi_sap_stats->stats_valid,
2709 wdi_sap_stats->ipv4_rx_packets,
2710 wdi_sap_stats->ipv4_rx_bytes,
2711 wdi_sap_stats->ipv6_rx_packets,
2712 wdi_sap_stats->ipv6_rx_bytes,
2713 wdi_sap_stats->ipv4_tx_packets,
2714 wdi_sap_stats->ipv4_tx_bytes,
2715 wdi_sap_stats->ipv6_tx_packets,
2716 wdi_sap_stats->ipv6_tx_bytes);
2717 }
2718 break;
2719 case IPA_SET_WIFI_QUOTA:
2720 /* get ipa_set_wifi_quota structure from IPA and pass to FW
2721 through quota_exceeded field in ipa_uc_fw_stats */
2722 ipa_set_quota = data;
2723
2724 if (!adapter) {
2725 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2726 "IPA uC set quota failed - no adapter");
2727 ipa_set_quota->set_valid = 0;
2728 return;
2729 }
2730
Yun Park777d7242017-03-30 15:38:33 -07002731 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
Yun Park637d6482016-10-05 10:51:33 -07002732 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2733 ipa_set_quota->quota_bytes);
2734
2735 ret = wait_for_completion_timeout(
2736 &hdd_ipa->ipa_uc_set_quota_comp,
2737 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2738 if (!ret) {
2739 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2740 "IPA uC set quota request timed out");
2741 ipa_set_quota->set_valid = 0;
2742 } else {
2743 ipa_set_quota->quota_bytes =
2744 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2745 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2746 ipa_set_quota->set_valid =
2747 hdd_ipa->ipa_quota_rsp.success;
2748 }
2749
2750 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2751 ipa_set_quota->quota_bytes,
2752 ipa_set_quota->set_valid);
2753 break;
2754 }
2755}
2756
2757/**
2758 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2759 * IPA calls to get WLAN stats or set quota limit.
2760 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07002761 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07002762 * @evt: the IPA event which triggered the callback
2763 * @data: data associated with the event
2764 *
2765 * Return: None
2766 */
2767static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2768 void *data)
2769{
2770 cds_ssr_protect(__func__);
2771 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2772 cds_ssr_unprotect(__func__);
2773}
2774
Yun Parkb4f591d2017-03-29 15:51:01 -07002775static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002776{
Yun Park637d6482016-10-05 10:51:33 -07002777 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2778 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2779}
2780#else
Yun Parkb4f591d2017-03-29 15:51:01 -07002781static void hdd_ipa_wdi_meter_notifier_cb(void)
2782{
2783}
2784
2785static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002786{
2787}
2788#endif
2789
Rajeev Kumar217f2172016-01-06 18:11:55 -08002790/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002791 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2792 * @hdd_ctx: Global HDD context
2793 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002794 * This function is called to update IPA pipe configuration with resources
2795 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2796 * (cds_enable)
2797 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302798 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002799 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002800QDF_STATUS hdd_ipa_uc_ol_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002801{
Yun Parkb4f591d2017-03-29 15:51:01 -07002802 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002803 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002804 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07002805 uint8_t i;
2806 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002807
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002808 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2809 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002810
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002811 ENTER();
2812 /* Do only IPA Pipe specific configuration here. All one time
2813 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2814 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2815 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002816 if (!pdev || !soc) {
2817 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07002818 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002819 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002820 }
Yun Parkb4f591d2017-03-29 15:51:01 -07002821 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002822 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2823 "IPA UC resource alloc fail");
2824 return QDF_STATUS_E_FAILURE;
2825 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002826
Yun Parkb4f591d2017-03-29 15:51:01 -07002827 if (true == hdd_ipa->uc_loaded) {
2828 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2829 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2830 hdd_ipa_wdi_meter_notifier_cb,
2831 hdd_ctx->config->IpaDescSize,
2832 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2833 &hdd_ipa->tx_pipe_handle,
2834 &hdd_ipa->rx_pipe_handle);
2835 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08002836 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002837 "Failure to setup IPA pipes (status=%d)",
2838 status);
2839 return QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002840 }
Yun Park637d6482016-10-05 10:51:33 -07002841
Yun Parkb4f591d2017-03-29 15:51:01 -07002842 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
2843 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002844 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845
Yun Parkb4f591d2017-03-29 15:51:01 -07002846 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08002847 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2848
Yun Parkb4f591d2017-03-29 15:51:01 -07002849 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
2850 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
2851 hdd_ipa_uc_fw_op_event_handler);
2852 hdd_ipa->uc_op_work[i].msg = NULL;
2853 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002854
Yun Parkbaa62862017-01-18 13:43:34 -08002855fail_return:
2856 EXIT();
Yun Parkb4f591d2017-03-29 15:51:01 -07002857 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858}
2859
Leo Change3e49442015-10-26 20:07:13 -07002860/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302861 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
2862 * @hdd_ctx: Global HDD context
2863 *
2864 * Return: 0 on success, negativer errno on error
2865 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002866int hdd_ipa_uc_ol_deinit(struct hdd_context *hdd_ctx)
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302867{
2868 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2869 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07002870 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302871
2872 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2873 return ret;
2874
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05302875 if (!hdd_ipa->ipa_pipes_down)
2876 hdd_ipa_uc_disable_pipes(hdd_ipa);
2877
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302878 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002879 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
2880 hdd_ipa->tx_pipe_handle,
2881 hdd_ipa->rx_pipe_handle);
2882 if (status) {
2883 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2884 "Failure to cleanup IPA pipes (status=%d)",
2885 status);
2886 return -EFAULT;
2887 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302888 }
2889
2890 return ret;
2891}
2892
2893/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002894 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002895 * @hdd_ctx: hdd main context
2896 *
2897 * Force shutdown IPA pipe
2898 * Independent of FW pipe status, IPA pipe shutdonw progress
2899 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2900 * independent from FW pipe status
2901 *
2902 * Return: NONE
2903 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002904static void __hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002905{
2906 struct hdd_ipa_priv *hdd_ipa;
2907
2908 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2909 return;
2910
2911 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2912 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302913 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002914 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07002915 hdd_ipa_uc_disable_pipes(hdd_ipa);
2916 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002917 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07002918 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07002919 }
Leo Change3e49442015-10-26 20:07:13 -07002920}
2921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002922/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002923 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2924 * __hdd_ipa_uc_force_pipe_shutdown
2925 * @hdd_ctx: hdd main context
2926 *
2927 * Force shutdown IPA pipe
2928 * Independent of FW pipe status, IPA pipe shutdonw progress
2929 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2930 * independent from FW pipe status
2931 *
2932 * Return: NONE
2933 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002934void hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002935{
2936 cds_ssr_protect(__func__);
2937 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2938 cds_ssr_unprotect(__func__);
2939}
2940
2941/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302942 * hdd_ipa_msg_free_fn() - Free an IPA message
2943 * @buff: pointer to the IPA message
2944 * @len: length of the IPA message
2945 * @type: type of IPA message
2946 *
2947 * Return: None
2948 */
2949static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2950{
Srinivas Girigowda97852372017-03-06 16:52:59 -08002951 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05302952 ghdd_ipa->stats.num_free_msg++;
2953 qdf_mem_free(buff);
2954}
2955
Govind Singh9c58eba2016-09-02 16:23:06 +05302956/**
jge62037862016-12-09 10:44:33 +08002957 * hdd_ipa_uc_send_evt() - send event to ipa
2958 * @hdd_ctx: pointer to hdd context
2959 * @type: event type
2960 * @mac_addr: pointer to mac address
2961 *
2962 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05302963 *
2964 * Return: 0 - Success
2965 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002966static int hdd_ipa_uc_send_evt(struct hdd_adapter *adapter,
jge62037862016-12-09 10:44:33 +08002967 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05302968{
jge62037862016-12-09 10:44:33 +08002969 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05302970 struct ipa_msg_meta meta;
2971 struct ipa_wlan_msg *msg;
2972 int ret = 0;
jge62037862016-12-09 10:44:33 +08002973
2974 meta.msg_len = sizeof(struct ipa_wlan_msg);
2975 msg = qdf_mem_malloc(meta.msg_len);
2976 if (msg == NULL) {
2977 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2978 "msg allocation failed");
2979 return -ENOMEM;
2980 }
2981
2982 meta.msg_type = type;
2983 strlcpy(msg->name, adapter->dev->name,
2984 IPA_RESOURCE_NAME_MAX);
2985 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Srinivas Girigowda97852372017-03-06 16:52:59 -08002986 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08002987 msg->name, meta.msg_type);
2988 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
2989 if (ret) {
2990 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2991 "%s: Evt: %d fail:%d",
2992 msg->name, meta.msg_type, ret);
2993 qdf_mem_free(msg);
2994 return ret;
2995 }
2996
2997 hdd_ipa->stats.num_send_msg++;
2998
2999 return ret;
3000}
3001
3002/**
3003 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3004 * @hdd_ctx: pointer to hdd adapter
3005 *
3006 * Send disconnect client event to IPA driver during SSR
3007 *
3008 * Return: 0 - Success
3009 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003010static int hdd_ipa_uc_disconnect_client(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003011{
3012 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3013 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303014 int i;
3015
3016 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3017 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3018 continue;
3019 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003020 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3021 hdd_ipa->sap_num_connected_sta) {
3022 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3023 adapter->aStaInfo[i].macAddrSTA.bytes);
3024 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303025 }
3026 }
3027
3028 return ret;
3029}
3030
3031/**
jge62037862016-12-09 10:44:33 +08003032 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3033 * @hdd_ctx: pointer to hdd adapter
3034 *
3035 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303036 *
3037 * Return: 0 - Success
3038 */
jge62037862016-12-09 10:44:33 +08003039
Jeff Johnson49d45e62017-08-29 14:30:42 -07003040static int hdd_ipa_uc_disconnect_ap(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003041{
3042 int ret = 0;
3043
3044 if (adapter->ipa_context)
3045 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3046 adapter->dev->dev_addr);
3047
3048 return ret;
3049}
3050
jge62037862016-12-09 10:44:33 +08003051/**
3052 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3053 * @hdd_ctx: pointer to hdd adapter
3054 *
3055 * Send disconnect sta event to IPA driver during SSR
3056 *
3057 * Return: 0 - Success
3058 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003059static int hdd_ipa_uc_disconnect_sta(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003060{
Jeff Johnson40dae4e2017-08-29 14:00:25 -07003061 struct hdd_station_ctx *pHddStaCtx;
jge62037862016-12-09 10:44:33 +08003062 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3063 int ret = 0;
3064
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003065 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003066 hdd_ipa->sta_connected) {
3067 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3068 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003069 pHddStaCtx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003070 }
3071
3072 return ret;
3073}
jge62037862016-12-09 10:44:33 +08003074
3075/**
3076 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3077 * @hdd_ctx: pointer to hdd context
3078 *
3079 * Send disconnect event to IPA driver during SSR
3080 *
3081 * Return: 0 - Success
3082 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003083static int hdd_ipa_uc_disconnect(struct hdd_context *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303084{
3085 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3086 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003087 struct hdd_adapter *adapter;
Govind Singh9c58eba2016-09-02 16:23:06 +05303088 int ret = 0;
3089
Govind Singh9c58eba2016-09-02 16:23:06 +05303090 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3091 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3092 adapter = adapter_node->pAdapter;
jge62037862016-12-09 10:44:33 +08003093 if (adapter->device_mode == QDF_SAP_MODE) {
3094 hdd_ipa_uc_disconnect_client(adapter);
3095 hdd_ipa_uc_disconnect_ap(adapter);
3096 } else if (adapter->device_mode == QDF_STA_MODE) {
3097 hdd_ipa_uc_disconnect_sta(adapter);
3098 }
3099
Govind Singh9c58eba2016-09-02 16:23:06 +05303100 status = hdd_get_next_adapter(
3101 hdd_ctx, adapter_node, &next);
3102 adapter_node = next;
3103 }
3104
3105 return ret;
3106}
3107
3108/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003109 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110 *
3111 * Deinit basic IPA UC host side to be in sync reloaded FW during
3112 * SSR
3113 *
3114 * Return: 0 - Success
3115 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003116static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003117{
3118 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3119 int idx;
3120 struct hdd_ipa_iface_context *iface_context;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003121 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122
Arun Khandavallicc544b32017-01-30 19:52:16 +05303123 if (!hdd_ipa)
3124 return 0;
3125
3126 hdd_ctx = hdd_ipa->hdd_ctx;
3127 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003128 return 0;
3129
jge62037862016-12-09 10:44:33 +08003130 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303131 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003132
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133 /* Clean up HDD IPA interfaces */
3134 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3135 (idx < HDD_IPA_MAX_IFACE); idx++) {
3136 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003137 if (iface_context->adapter && iface_context->adapter->magic ==
3138 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003139 hdd_ipa_cleanup_iface(iface_context);
3140 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003141 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003142 /* After SSR, wlan driver reloads FW again. But we need to protect
3143 * IPA submodule during SSR transient state. So deinit basic IPA
3144 * UC host side to be in sync with reloaded FW during SSR
3145 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303147 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003148 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3149 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3150 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3151 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303152 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153
Guolei Bianca144d82016-11-10 11:07:42 +08003154 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3155 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3156
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003157 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3158 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3159 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3160 hdd_ipa->uc_op_work[idx].msg = NULL;
3161 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003162 return 0;
3163}
3164
3165/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003166 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3167 *
3168 * Deinit basic IPA UC host side to be in sync reloaded FW during
3169 * SSR
3170 *
3171 * Return: 0 - Success
3172 */
3173int hdd_ipa_uc_ssr_deinit(void)
3174{
3175 int ret;
3176
3177 cds_ssr_protect(__func__);
3178 ret = __hdd_ipa_uc_ssr_deinit();
3179 cds_ssr_unprotect(__func__);
3180
3181 return ret;
3182}
3183
3184/**
3185 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 *
3187 * Init basic IPA UC host side to be in sync with reloaded FW after
3188 * SSR to resume IPA UC operations
3189 *
3190 * Return: 0 - Success
3191 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003192static int __hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003193{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194
Arun Khandavallicc544b32017-01-30 19:52:16 +05303195 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3196 int i;
3197 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303198
3199 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3200 return 0;
3201
Arun Khandavallicc544b32017-01-30 19:52:16 +05303202 /* Create the interface context */
3203 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3204 iface_context = &hdd_ipa->iface_context[i];
3205 iface_context->hdd_ipa = hdd_ipa;
3206 iface_context->cons_client =
3207 hdd_ipa_adapter_2_client[i].cons_client;
3208 iface_context->prod_client =
3209 hdd_ipa_adapter_2_client[i].prod_client;
3210 iface_context->iface_id = i;
3211 iface_context->adapter = NULL;
3212 }
3213 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3214 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3215 hdd_ipa->vdev_offload_enabled[i] = false;
3216 }
3217
3218 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3219 hdd_ipa->resource_loading = false;
3220 hdd_ipa->resource_unloading = false;
3221 hdd_ipa->sta_connected = 0;
3222 hdd_ipa->ipa_pipes_down = true;
3223 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303224 }
3225
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003226 return 0;
3227}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003228
3229/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003230 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3231 *
3232 * Init basic IPA UC host side to be in sync with reloaded FW after
3233 * SSR to resume IPA UC operations
3234 *
3235 * Return: 0 - Success
3236 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003237int hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003238{
3239 int ret;
3240
3241 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303242 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003243 cds_ssr_unprotect(__func__);
3244
3245 return ret;
3246}
3247
3248/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3250 * @work: scheduled work
3251 *
3252 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3253 * not want to immediately release the wake lock since the system
3254 * would then potentially try to suspend when there is a healthy data
3255 * rate. Deferred work is scheduled and this function handles the
3256 * work. When this function is called, if the IPA resource is still
3257 * released then we release the wake lock.
3258 *
3259 * Return: None
3260 */
3261static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3262{
3263 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3264 struct hdd_ipa_priv,
3265 wake_lock_work);
3266
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303267 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003268
3269 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3270 goto end;
3271
3272 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303273 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003274 WIFI_POWER_EVENT_WAKELOCK_IPA);
3275
3276end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303277 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278}
3279
3280/**
3281 * hdd_ipa_rm_request() - Request resource from IPA
3282 * @hdd_ipa: Global HDD IPA context
3283 *
3284 * Return: 0 on success, negative errno on error
3285 */
3286static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3287{
3288 int ret = 0;
3289
3290 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3291 return 0;
3292
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303293 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003294
3295 switch (hdd_ipa->rm_state) {
3296 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303297 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003298 return 0;
3299 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303300 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003301 return -EINPROGRESS;
3302 case HDD_IPA_RM_RELEASED:
3303 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3304 break;
3305 }
3306
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303307 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003308
3309 ret = ipa_rm_inactivity_timer_request_resource(
3310 IPA_RM_RESOURCE_WLAN_PROD);
3311
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303312 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003313 if (ret == 0) {
3314 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3315 hdd_ipa->stats.num_rm_grant_imm++;
3316 }
3317
3318 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3319 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303320 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003321 WIFI_POWER_EVENT_WAKELOCK_IPA);
3322 hdd_ipa->wake_lock_released = false;
3323 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303324 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003325
3326 return ret;
3327}
3328
3329/**
3330 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3331 * @hdd_ipa: Global HDD IPA context
3332 *
3333 * Return: 0 if resources released, negative errno otherwise
3334 */
3335static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3336{
3337 int ret = 0;
3338
3339 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3340 return 0;
3341
3342 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3343 return -EAGAIN;
3344
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303345 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003346
Nirav Shahcbc6d722016-03-01 16:24:53 +05303347 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303348 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003349 return -EAGAIN;
3350 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303351 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303353 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354 switch (hdd_ipa->rm_state) {
3355 case HDD_IPA_RM_GRANTED:
3356 break;
3357 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303358 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 return -EINPROGRESS;
3360 case HDD_IPA_RM_RELEASED:
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 0;
3363 }
3364
3365 /* IPA driver returns immediately so set the state here to avoid any
3366 * race condition.
3367 */
3368 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3369 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303370 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003372 ret = ipa_rm_inactivity_timer_release_resource(
3373 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303375 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003376 if (unlikely(ret != 0)) {
3377 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3378 WARN_ON(1);
3379 }
3380
3381 /*
3382 * If wake_lock is released immediately, kernel would try to suspend
3383 * immediately as well, Just avoid ping-pong between suspend-resume
3384 * while there is healthy amount of data transfer going on by
3385 * releasing the wake_lock after some delay.
3386 */
3387 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3388 msecs_to_jiffies
3389 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3390
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303391 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003392
3393 return ret;
3394}
3395
3396/**
3397 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3398 * @user_data: user data registered with IPA
3399 * @event: the IPA resource manager event that occurred
3400 * @data: the data associated with the event
3401 *
3402 * Return: None
3403 */
3404static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3405 unsigned long data)
3406{
3407 struct hdd_ipa_priv *hdd_ipa = user_data;
3408
3409 if (unlikely(!hdd_ipa))
3410 return;
3411
3412 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3413 return;
3414
Srinivas Girigowda97852372017-03-06 16:52:59 -08003415 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416
3417 switch (event) {
3418 case IPA_RM_RESOURCE_GRANTED:
3419 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3420 /* RM Notification comes with ISR context
3421 * it should be serialized into work queue to avoid
3422 * ISR sleep problem
3423 */
3424 hdd_ipa->uc_rm_work.event = event;
3425 schedule_work(&hdd_ipa->uc_rm_work.work);
3426 break;
3427 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303428 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303430 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431 hdd_ipa->stats.num_rm_grant++;
3432 break;
3433
3434 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003435 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 hdd_ipa->resource_unloading = false;
3437 break;
3438
3439 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303440 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003441 break;
3442 }
3443}
3444
3445/**
3446 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3447 *
3448 * Callback function registered with IPA that is called when IPA wants
3449 * to release the WLAN consumer resource
3450 *
3451 * Return: 0 if the request is granted, negative errno otherwise
3452 */
3453static int hdd_ipa_rm_cons_release(void)
3454{
3455 return 0;
3456}
3457
3458/**
3459 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3460 *
3461 * Callback function registered with IPA that is called when IPA wants
3462 * to access the WLAN consumer resource
3463 *
3464 * Return: 0 if the request is granted, negative errno otherwise
3465 */
3466static int hdd_ipa_rm_cons_request(void)
3467{
Yun Park4d8b60a2015-10-22 13:59:32 -07003468 int ret = 0;
3469
3470 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303471 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003472 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003474 ret = -EINPROGRESS;
3475 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303476 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003477 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003478 ghdd_ipa->pending_cons_req = true;
3479 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003480 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003481
3482 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483}
3484
3485/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003486 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487 * @hdd_ctx: Global HDD context
3488 * @tx_packets: Number of packets transmitted in the last sample period
3489 * @rx_packets: Number of packets received in the last sample period
3490 *
3491 * Return: 0 on success, negative errno on error
3492 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003493static int __hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494 uint64_t rx_packets)
3495{
3496 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003497 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003498 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003499 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500 int ret;
3501
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003502 if (wlan_hdd_validate_context(hdd_ctx))
3503 return 0;
3504
3505 hdd_ipa = hdd_ctx->hdd_ipa;
3506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003507 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3508 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3509 return 0;
3510
3511 memset(&profile, 0, sizeof(profile));
3512
3513 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3514 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3515 else if (tx_packets >
3516 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3517 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3518 else
3519 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3520
3521 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3522 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3523 else if (rx_packets >
3524 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3525 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3526 else
3527 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3528
Yun Parkec845302016-12-15 09:22:57 -08003529 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530 "CONS perf curr: %d, next: %d",
3531 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003532 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003533 "PROD perf curr: %d, next: %d",
3534 hdd_ipa->curr_prod_bw, next_prod_bw);
3535
3536 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003537 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003539 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3540 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003542 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543
3544 return ret;
3545 }
3546 hdd_ipa->curr_cons_bw = next_cons_bw;
3547 hdd_ipa->stats.num_cons_perf_req++;
3548 }
3549
3550 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003551 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003553 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3554 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003555 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003556 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 return ret;
3558 }
3559 hdd_ipa->curr_prod_bw = next_prod_bw;
3560 hdd_ipa->stats.num_prod_perf_req++;
3561 }
3562
3563 return 0;
3564}
3565
3566/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003567 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3568 * @hdd_ctx: Global HDD context
3569 * @tx_packets: Number of packets transmitted in the last sample period
3570 * @rx_packets: Number of packets received in the last sample period
3571 *
3572 * Return: 0 on success, negative errno on error
3573 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003574int hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003575 uint64_t rx_packets)
3576{
3577 int ret;
3578
3579 cds_ssr_protect(__func__);
3580 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3581 cds_ssr_unprotect(__func__);
3582
3583 return ret;
3584}
3585
3586/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003587 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3588 * @work: struct work_struct
3589 * @work_handler: work_handler
3590 *
3591 * Return: none
3592 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003593static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3594 work_func_t work_handler)
3595{
3596 INIT_WORK(work, work_handler);
3597}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003598
3599/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 * hdd_ipa_setup_rm() - Setup IPA resource management
3601 * @hdd_ipa: Global HDD IPA context
3602 *
3603 * Return: 0 on success, negative errno on error
3604 */
3605static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3606{
3607 struct ipa_rm_create_params create_params = { 0 };
3608 int ret;
3609
3610 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3611 return 0;
3612
Rajeev Kumar217f2172016-01-06 18:11:55 -08003613 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3614 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003615 memset(&create_params, 0, sizeof(create_params));
3616 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3617 create_params.reg_params.user_data = hdd_ipa;
3618 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3619 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3620
3621 ret = ipa_rm_create_resource(&create_params);
3622 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303623 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003624 "Create RM resource failed: %d", ret);
3625 goto setup_rm_fail;
3626 }
3627
3628 memset(&create_params, 0, sizeof(create_params));
3629 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3630 create_params.request_resource = hdd_ipa_rm_cons_request;
3631 create_params.release_resource = hdd_ipa_rm_cons_release;
3632 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3633
3634 ret = ipa_rm_create_resource(&create_params);
3635 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303636 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003637 "Create RM CONS resource failed: %d", ret);
3638 goto delete_prod;
3639 }
3640
3641 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3642 IPA_RM_RESOURCE_APPS_CONS);
3643
3644 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3645 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3646 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303647 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648 ret);
3649 goto timer_init_failed;
3650 }
3651
3652 /* Set the lowest bandwidth to start with */
3653 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3654
3655 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303656 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003657 "Set perf level failed: %d", ret);
3658 goto set_perf_failed;
3659 }
3660
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303661 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3663 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303664 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3666 hdd_ipa->wake_lock_released = true;
3667 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3668
3669 return ret;
3670
3671set_perf_failed:
3672 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3673
3674timer_init_failed:
3675 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3676
3677delete_prod:
3678 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3679
3680setup_rm_fail:
3681 return ret;
3682}
3683
3684/**
3685 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3686 * @hdd_ipa: Global HDD IPA context
3687 *
3688 * Destroys all resources associated with the IPA resource manager
3689 *
3690 * Return: None
3691 */
3692static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3693{
3694 int ret;
3695
3696 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3697 return;
3698
3699 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303700 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303703 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704
3705 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3706
3707 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3708 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303709 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003710 "RM PROD resource delete failed %d", ret);
3711
3712 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3713 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303714 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715 "RM CONS resource delete failed %d", ret);
3716}
3717
tfyu0380a972017-07-13 18:19:37 +08003718#ifdef QCA_CONFIG_SMP
3719static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3720{
3721 return netif_rx_ni(skb);
3722}
3723#else
3724static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3725{
3726 struct iphdr *ip_h;
3727 static atomic_t softirq_mitigation_cntr =
3728 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
3729 int result;
3730
3731 ip_h = (struct iphdr *)(skb->data);
3732 if ((skb->protocol == htons(ETH_P_IP)) &&
3733 (ip_h->protocol == IPPROTO_ICMP)) {
3734 result = netif_rx_ni(skb);
3735 } else {
3736 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
3737 * to avoid excessive softirq's.
3738 */
3739 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
3740 result = netif_rx_ni(skb);
3741 atomic_set(&softirq_mitigation_cntr,
3742 IPA_WLAN_RX_SOFTIRQ_THRESH);
3743 } else {
3744 result = netif_rx(skb);
3745 }
3746 }
3747
3748 return result;
3749}
3750#endif
3751
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003752/**
3753 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3754 * @skb: network buffer
3755 * @adapter: network adapter
3756 *
3757 * Called when a network buffer is received which should not be routed
3758 * to the IPA module.
3759 *
3760 * Return: None
3761 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303762static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003763 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003764{
tfyu0380a972017-07-13 18:19:37 +08003765 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003766 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3767 unsigned int cpu_index;
3768
3769 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07003770 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771 adapter);
3772 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003773 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774 return;
3775 }
3776
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003777 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003779 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780 return;
3781 }
3782
3783 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3784 skb->dev = adapter->dev;
3785 skb->protocol = eth_type_trans(skb, skb->dev);
3786 skb->ip_summed = CHECKSUM_NONE;
3787
3788 cpu_index = wlan_hdd_get_cpu();
3789
3790 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08003791 result = hdd_ipa_aggregated_rx_ind(skb);
3792 if (result == NET_RX_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003793 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
3794 else
3795 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
3796
3797 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003798}
3799
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003800/**
Leo Chang69c39692016-10-12 20:11:12 -07003801 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3802 * @hdd_ipa: pointer to hdd ipa context
3803 * @adapter: network adapter
3804 * @skb: data pointer
3805 *
3806 * if exception packet has set forward bit, copied new packet should be
3807 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3808 * put into pm queue and tx procedure will be differed
3809 *
3810 * Return: None
3811 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003812static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003813 struct hdd_adapter *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003814{
Leo Chang69c39692016-10-12 20:11:12 -07003815 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3816
Leo Chang69c39692016-10-12 20:11:12 -07003817 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
3818 /* WLAN subsystem is in suspend, put int queue */
3819 if (hdd_ipa->suspended) {
3820 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3821 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3822 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003823 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3824 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003825 pm_tx_cb->exception = true;
3826 pm_tx_cb->adapter = adapter;
3827 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003828 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003829 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3830 hdd_ipa->stats.num_tx_queued++;
3831 } else {
3832 /* Resume, put packet into WLAN TX */
3833 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003834 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003835 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3836 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003837 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003838 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003839 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003840 hdd_ipa->ipa_tx_forward++;
3841 }
3842 }
3843}
3844
3845/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003846 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3847 * @hdd_ipa: pointer to HDD IPA struct
3848 * @adapter: hdd adapter pointer
3849 * @desc: Firmware descriptor
3850 * @skb: Data buffer
3851 *
3852 * Return:
3853 * HDD_IPA_FORWARD_PKT_NONE
3854 * HDD_IPA_FORWARD_PKT_DISCARD
3855 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3856 *
3857 */
3858
3859static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3860 struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003861 struct hdd_adapter *adapter,
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003862 uint8_t desc,
3863 qdf_nbuf_t skb)
3864{
3865 int ret = HDD_IPA_FORWARD_PKT_NONE;
3866
3867 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303868 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003869 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
3870 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303871 /* Drop the packet*/
3872 hdd_ipa->stats.num_tx_fwd_err++;
3873 kfree_skb(skb);
3874 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3875 return ret;
3876 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003877 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3878 "Forward packet to Tx (fw_desc=%d)", desc);
3879 hdd_ipa->ipa_tx_forward++;
3880
3881 if ((desc & FW_RX_DESC_DISCARD_M)) {
3882 hdd_ipa_forward(hdd_ipa, adapter, skb);
3883 hdd_ipa->ipa_rx_internel_drop_count++;
3884 hdd_ipa->ipa_rx_discard++;
3885 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3886 } else {
3887 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003888
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003889 if (cloned_skb)
3890 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3891 else
3892 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3893 "%s: tx skb alloc failed",
3894 __func__);
3895 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3896 }
3897 }
3898
3899 return ret;
3900}
3901
3902/**
Yun Park637d6482016-10-05 10:51:33 -07003903 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003904 * @priv: pointer to private data registered with IPA (we register a
3905 * pointer to the global IPA context)
3906 * @evt: the IPA event which triggered the callback
3907 * @data: data associated with the event
3908 *
3909 * Return: None
3910 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003911static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003912 unsigned long data)
3913{
3914 struct hdd_ipa_priv *hdd_ipa = NULL;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003915 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303916 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003917 uint8_t iface_id;
3918 uint8_t session_id;
3919 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003920 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003921 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003922
3923 hdd_ipa = (struct hdd_ipa_priv *)priv;
3924
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003925 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3926 return;
3927
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003928 switch (evt) {
3929 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303930 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003931
3932 /*
3933 * When SSR is going on or driver is unloading,
3934 * just drop the packets.
3935 */
3936 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
3937 if (0 != status) {
3938 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3939 "Invalid context: drop packet");
3940 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3941 kfree_skb(skb);
3942 return;
3943 }
3944
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003945 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3946 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003947 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08003948 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 "IPA_RECEIVE: session_id=%u, iface_id=%u",
3950 session_id, iface_id);
3951 } else {
3952 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
3953 }
3954
3955 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303956 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 "IPA_RECEIVE: Invalid iface_id: %u",
3958 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003959 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003960 "w2i -- skb",
3961 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003963 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003964 return;
3965 }
3966
3967 iface_context = &hdd_ipa->iface_context[iface_id];
3968 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08003969 if (!adapter) {
3970 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3971 "IPA_RECEIVE: Adapter is NULL");
3972 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3973 kfree_skb(skb);
3974 return;
3975 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003976
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303977 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003978 "w2i -- skb",
3979 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3981 hdd_ipa->stats.num_rx_excep++;
3982 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
3983 } else {
3984 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
3985 }
3986
3987 iface_context->stats.num_rx_ipa_excep++;
3988
3989 /* Disable to forward Intra-BSS Rx packets when
3990 * ap_isolate=1 in hostapd.conf
3991 */
Yun Park046101c2016-09-02 15:32:14 -07003992 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003993 /*
3994 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
3995 * all Rx packets to IPA uC, which need to be forwarded
3996 * to other interface.
3997 * And, IPA driver will send back to WLAN host driver
3998 * through exception pipe with fw_desc field set by FW.
3999 * Here we are checking fw_desc field for FORWARD bit
4000 * set, and forward to Tx. Then copy to kernel stack
4001 * only when DISCARD bit is not set.
4002 */
4003 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004004 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4005 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4006 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004007 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004009 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004010 "Intra-BSS FWD is disabled-skip forward to Tx");
4011 }
4012
4013 hdd_ipa_send_skb_to_network(skb, adapter);
4014 break;
4015
4016 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304017 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004018 "w2i cb wrong event: 0x%x", evt);
4019 return;
4020 }
4021}
4022
4023/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004024 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4025 * @priv: pointer to private data registered with IPA (we register a
4026 * pointer to the global IPA context)
4027 * @evt: the IPA event which triggered the callback
4028 * @data: data associated with the event
4029 *
4030 * Return: None
4031 */
4032static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4033 unsigned long data)
4034{
4035 cds_ssr_protect(__func__);
4036 __hdd_ipa_w2i_cb(priv, evt, data);
4037 cds_ssr_unprotect(__func__);
4038}
4039
4040/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004041 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4042 * @skb: packet buffer which was transmitted
4043 *
4044 * Return: None
4045 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304046void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047{
4048 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004049 struct ipa_rx_data *ipa_tx_desc;
4050 struct hdd_ipa_tx_desc *tx_desc;
4051 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052
Yun Park52b2b992016-09-22 15:49:51 -07004053 if (!qdf_nbuf_ipa_owned_get(skb)) {
4054 dev_kfree_skb_any(skb);
4055 return;
4056 }
4057
4058 /* Get Tx desc pointer from SKB CB */
4059 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4060 tx_desc = hdd_ipa->tx_desc_list + id;
4061 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4062
4063 /* Return Tx Desc to IPA */
4064 ipa_free_skb(ipa_tx_desc);
4065
4066 /* Return to free tx desc list */
4067 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4068 tx_desc->ipa_tx_desc_ptr = NULL;
4069 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4070 hdd_ipa->stats.num_tx_desc_q_cnt--;
4071 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072
4073 hdd_ipa->stats.num_tx_comp_cnt++;
4074
4075 atomic_dec(&hdd_ipa->tx_ref_cnt);
4076
4077 hdd_ipa_rm_try_release(hdd_ipa);
4078}
4079
4080/**
4081 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4082 * @iface_context: interface-specific IPA context
4083 * @ipa_tx_desc: packet data descriptor
4084 *
4085 * Return: None
4086 */
4087static void hdd_ipa_send_pkt_to_tl(
4088 struct hdd_ipa_iface_context *iface_context,
4089 struct ipa_rx_data *ipa_tx_desc)
4090{
4091 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004092 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304093 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004094 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304096 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004097 adapter = iface_context->adapter;
4098 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304099 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 ipa_free_skb(ipa_tx_desc);
4101 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304102 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004103 hdd_ipa_rm_try_release(hdd_ipa);
4104 return;
4105 }
4106
4107 /*
4108 * During CAC period, data packets shouldn't be sent over the air so
4109 * drop all the packets here
4110 */
4111 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4112 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304113 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 iface_context->stats.num_tx_cac_drop++;
4115 hdd_ipa_rm_try_release(hdd_ipa);
4116 return;
4117 }
4118
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004119 ++adapter->stats.tx_packets;
4120
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304121 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004122
4123 skb = ipa_tx_desc->skb;
4124
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304125 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004126
4127 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304128 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304130 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004131 ipa_tx_desc->dma_addr
4132 + HDD_IPA_WLAN_FRAG_HEADER
4133 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134 ipa_tx_desc->skb->len -=
4135 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4136 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304137 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138
Yun Park52b2b992016-09-22 15:49:51 -07004139 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4140 /* get free Tx desc and assign ipa_tx_desc pointer */
4141 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4142 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4143 struct hdd_ipa_tx_desc, link);
4144 list_del(&tx_desc->link);
4145 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4146 hdd_ipa->stats.num_tx_desc_q_cnt++;
4147 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4148 /* Store Tx Desc index into SKB CB */
4149 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4150 } else {
4151 hdd_ipa->stats.num_tx_desc_error++;
4152 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4153 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4154 ipa_free_skb(ipa_tx_desc);
4155 hdd_ipa_rm_try_release(hdd_ipa);
4156 return;
4157 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158
4159 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4160
Leo Changfdb45c32016-10-28 11:09:23 -07004161 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004162 (struct cdp_vdev *)iface_context->tl_context,
4163 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004164 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304165 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
jiad05c1e812017-08-01 16:48:52 +08004166 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004167 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 return;
4169 }
4170
4171 atomic_inc(&hdd_ipa->tx_ref_cnt);
4172
4173 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004174}
4175
4176/**
Leo Chang11545d62016-10-17 14:53:50 -07004177 * hdd_ipa_is_present() - get IPA hw status
4178 * @hdd_ctx: pointer to hdd context
4179 *
4180 * ipa_uc_reg_rdyCB is not directly designed to check
4181 * ipa hw status. This is an undocumented function which
4182 * has confirmed with IPA team.
4183 *
4184 * Return: true - ipa hw present
4185 * false - ipa hw not present
4186 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004187bool hdd_ipa_is_present(struct hdd_context *hdd_ctx)
Leo Chang11545d62016-10-17 14:53:50 -07004188{
4189 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004190 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004191 return true;
4192 else
4193 return false;
4194}
4195
4196/**
Leo Chang69c39692016-10-12 20:11:12 -07004197 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198 * @work: pointer to the scheduled work
4199 *
4200 * Called during PM resume to send packets to TL which were queued
4201 * while host was in the process of suspending.
4202 *
4203 * Return: None
4204 */
Leo Chang69c39692016-10-12 20:11:12 -07004205static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206{
4207 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4208 struct hdd_ipa_priv,
4209 pm_work);
4210 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304211 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004212 uint32_t dequeued = 0;
4213
Leo Chang69c39692016-10-12 20:11:12 -07004214 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4215 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304216 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304217 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4218 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304219 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220
4221 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004222 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004223 if (pm_tx_cb->exception) {
4224 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4225 "FLUSH EXCEPTION");
Govind Singh1dab23b2017-08-12 13:31:00 +05304226 if (pm_tx_cb->adapter->dev)
4227 hdd_softap_hard_start_xmit(skb,
4228 pm_tx_cb->adapter->dev);
Govind Singh02075942017-08-15 11:13:28 +05304229 else
4230 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004231 } else {
4232 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004233 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004234 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304235 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004236 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304237 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004238 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4239 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240
4241 hdd_ipa->stats.num_tx_dequeued += dequeued;
4242 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4243 hdd_ipa->stats.num_max_pm_queue = dequeued;
4244}
4245
4246/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004247 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 * @priv: pointer to private data registered with IPA (we register a
4249 * pointer to the interface-specific IPA context)
4250 * @evt: the IPA event which triggered the callback
4251 * @data: data associated with the event
4252 *
4253 * Return: None
4254 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004255static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004256 unsigned long data)
4257{
4258 struct hdd_ipa_priv *hdd_ipa = NULL;
4259 struct ipa_rx_data *ipa_tx_desc;
4260 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304261 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304263 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264
Mukul Sharma81661ae2015-10-30 20:26:02 +05304265 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004266 ipa_tx_desc = (struct ipa_rx_data *)data;
4267 hdd_ipa = iface_context->hdd_ipa;
4268
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004270 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4271 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272 iface_context->stats.num_tx_drop++;
4273 return;
4274 }
4275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276 /*
4277 * When SSR is going on or driver is unloading, just drop the packets.
4278 * During SSR, there is no use in queueing the packets as STA has to
4279 * connect back any way
4280 */
4281 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304282 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 ipa_free_skb(ipa_tx_desc);
4284 iface_context->stats.num_tx_drop++;
4285 return;
4286 }
4287
4288 skb = ipa_tx_desc->skb;
4289
Yun Parkb187d542016-11-14 18:10:04 -08004290 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4291 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292
4293 /*
4294 * If PROD resource is not requested here then there may be cases where
4295 * IPA hardware may be clocked down because of not having proper
4296 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4297 * workaround to request PROD resource while data is going over CONS
4298 * pipe to prevent the IPA hardware clockdown.
4299 */
4300 hdd_ipa_rm_request(hdd_ipa);
4301
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304302 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004303 /*
4304 * If host is still suspended then queue the packets and these will be
4305 * drained later when resume completes. When packet is arrived here and
4306 * host is suspended, this means that there is already resume is in
4307 * progress.
4308 */
4309 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304310 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4312 pm_tx_cb->iface_context = iface_context;
4313 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304314 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315 hdd_ipa->stats.num_tx_queued++;
4316
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304317 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004318 return;
4319 }
4320
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304321 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322
4323 /*
4324 * If we are here means, host is not suspended, wait for the work queue
4325 * to finish.
4326 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328
4329 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4330}
4331
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004332/*
4333 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4334 * @priv: pointer to private data registered with IPA (we register a
4335 * pointer to the interface-specific IPA context)
4336 * @evt: the IPA event which triggered the callback
4337 * @data: data associated with the event
4338 *
4339 * Return: None
4340 */
4341static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4342 unsigned long data)
4343{
4344 cds_ssr_protect(__func__);
4345 __hdd_ipa_i2w_cb(priv, evt, data);
4346 cds_ssr_unprotect(__func__);
4347}
4348
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004350 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004351 * @hdd_ctx: Global HDD context
4352 *
4353 * Return: 0 on success, negativer errno on error
4354 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004355static int __hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004356{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004357 struct hdd_ipa_priv *hdd_ipa;
4358
4359 if (wlan_hdd_validate_context(hdd_ctx))
4360 return 0;
4361
4362 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363
4364 if (!hdd_ipa_is_enabled(hdd_ctx))
4365 return 0;
4366
4367 /*
4368 * Check if IPA is ready for suspend, If we are here means, there is
4369 * high chance that suspend would go through but just to avoid any race
4370 * condition after suspend started, these checks are conducted before
4371 * allowing to suspend.
4372 */
4373 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4374 return -EAGAIN;
4375
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304376 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377
4378 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304379 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004380 return -EAGAIN;
4381 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304382 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004383
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304384 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004385 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304386 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004387
4388 return 0;
4389}
4390
4391/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004392 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4393 * @hdd_ctx: Global HDD context
4394 *
4395 * Return: 0 on success, negativer errno on error
4396 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004397int hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004398{
4399 int ret;
4400
4401 cds_ssr_protect(__func__);
4402 ret = __hdd_ipa_suspend(hdd_ctx);
4403 cds_ssr_unprotect(__func__);
4404
4405 return ret;
4406}
4407
4408/**
4409 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004410 * hdd_ctx: Global HDD context
4411 *
4412 * Return: 0 on success, negative errno on error
4413 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004414static int __hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004416 struct hdd_ipa_priv *hdd_ipa;
4417
4418 if (wlan_hdd_validate_context(hdd_ctx))
4419 return 0;
4420
4421 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422
4423 if (!hdd_ipa_is_enabled(hdd_ctx))
4424 return 0;
4425
4426 schedule_work(&hdd_ipa->pm_work);
4427
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304428 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304430 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004431
4432 return 0;
4433}
4434
4435/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004436 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4437 * hdd_ctx: Global HDD context
4438 *
4439 * Return: 0 on success, negative errno on error
4440 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004441int hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004442{
4443 int ret;
4444
4445 cds_ssr_protect(__func__);
4446 ret = __hdd_ipa_resume(hdd_ctx);
4447 cds_ssr_unprotect(__func__);
4448
4449 return ret;
4450}
4451
4452/**
Yun Park52b2b992016-09-22 15:49:51 -07004453 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4454 * @hdd_ipa: Global HDD IPA context
4455 *
4456 * Return: 0 on success, negative errno on error
4457 */
4458static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4459{
4460 int i;
4461 uint32_t max_desc_cnt;
4462 struct hdd_ipa_tx_desc *tmp_desc;
jiad14fe4fb2017-08-08 13:33:14 +08004463 struct ol_txrx_pdev_t *pdev;
Yun Park52b2b992016-09-22 15:49:51 -07004464
jiad14fe4fb2017-08-08 13:33:14 +08004465 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
4466 if (!pdev) {
4467 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "pdev is NULL");
4468 return -ENODEV;
4469 }
4470
4471 hdd_ipa->tx_desc_size = QDF_MIN(
4472 hdd_ipa->hdd_ctx->config->IpaMccTxDescSize,
4473 pdev->tx_desc.pool_size);
Yun Park52b2b992016-09-22 15:49:51 -07004474
4475 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4476
jiad14fe4fb2017-08-08 13:33:14 +08004477 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc) *
4478 hdd_ipa->tx_desc_size);
Yun Park52b2b992016-09-22 15:49:51 -07004479
4480 if (!tmp_desc) {
4481 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4482 "Free Tx descriptor allocation failed");
4483 return -ENOMEM;
4484 }
4485
4486 hdd_ipa->tx_desc_list = tmp_desc;
4487
4488 qdf_spin_lock_bh(&hdd_ipa->q_lock);
jiad14fe4fb2017-08-08 13:33:14 +08004489 for (i = 0; i < hdd_ipa->tx_desc_size; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004490 tmp_desc->id = i;
4491 tmp_desc->ipa_tx_desc_ptr = NULL;
4492 list_add_tail(&tmp_desc->link,
4493 &hdd_ipa->free_tx_desc_head);
4494 tmp_desc++;
4495 }
4496
4497 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4498 hdd_ipa->stats.num_tx_desc_error = 0;
4499
4500 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4501
4502 return 0;
4503}
4504
4505/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4507 * @hdd_ipa: Global HDD IPA context
4508 *
4509 * Return: 0 on success, negative errno on error
4510 */
4511static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4512{
4513 int i, ret = 0;
4514 struct ipa_sys_connect_params *ipa;
4515 uint32_t desc_fifo_sz;
4516
4517 /* The maximum number of descriptors that can be provided to a BAM at
4518 * once is one less than the total number of descriptors that the buffer
4519 * can contain.
4520 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4521 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4522 * be provided at once.
4523 * Because of above requirement, one extra descriptor will be added to
4524 * make sure hardware always has one descriptor.
4525 */
4526 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4527 + sizeof(struct sps_iovec);
4528
4529 /*setup TX pipes */
4530 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4531 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4532
4533 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4534 ipa->desc_fifo_sz = desc_fifo_sz;
4535 ipa->priv = &hdd_ipa->iface_context[i];
4536 ipa->notify = hdd_ipa_i2w_cb;
4537
4538 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4539 ipa->ipa_ep_cfg.hdr.hdr_len =
4540 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4541 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4542 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4543 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4544 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4545 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4546 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4547 } else {
4548 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4549 }
4550 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4551
4552 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4553 ipa->keep_ipa_awake = 1;
4554
4555 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4556 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004557 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4558 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559 goto setup_sys_pipe_fail;
4560 }
4561 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4562 }
4563
4564 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4565 /*
4566 * Hard code it here, this can be extended if in case
4567 * PROD pipe is also per interface.
4568 * Right now there is no advantage of doing this.
4569 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004570 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4571
Yun Parkb4f591d2017-03-29 15:51:01 -07004572 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573
4574 ipa->desc_fifo_sz = desc_fifo_sz;
4575 ipa->priv = hdd_ipa;
4576 ipa->notify = hdd_ipa_w2i_cb;
4577
4578 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4579 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4580 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4581 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4582
4583 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4584 ipa->keep_ipa_awake = 1;
4585
4586 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4587 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304588 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004589 "Failed for RX pipe: %d", ret);
4590 goto setup_sys_pipe_fail;
4591 }
4592 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4593 }
4594
jiad14fe4fb2017-08-08 13:33:14 +08004595 /* Allocate free Tx desc list */
Yun Park52b2b992016-09-22 15:49:51 -07004596 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4597 if (ret)
4598 goto setup_sys_pipe_fail;
4599
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004600 return ret;
4601
4602setup_sys_pipe_fail:
4603
4604 while (--i >= 0) {
4605 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304606 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004607 sizeof(struct hdd_ipa_sys_pipe));
4608 }
4609
4610 return ret;
4611}
4612
4613/**
4614 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4615 * @hdd_ipa: Global HDD IPA context
4616 *
4617 * Return: None
4618 */
4619static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4620{
4621 int ret = 0, i;
Yun Park52b2b992016-09-22 15:49:51 -07004622 struct hdd_ipa_tx_desc *tmp_desc;
4623 struct ipa_rx_data *ipa_tx_desc;
4624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4626 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004627 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4628 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004629 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304630 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004631 ret);
4632
4633 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4634 }
4635 }
Yun Park52b2b992016-09-22 15:49:51 -07004636
4637 if (hdd_ipa->tx_desc_list) {
Yun Park52b2b992016-09-22 15:49:51 -07004638 qdf_spin_lock_bh(&hdd_ipa->q_lock);
jiad14fe4fb2017-08-08 13:33:14 +08004639 for (i = 0; i < hdd_ipa->tx_desc_size; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004640 tmp_desc = hdd_ipa->tx_desc_list + i;
4641 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4642 if (ipa_tx_desc)
4643 ipa_free_skb(ipa_tx_desc);
4644 }
4645 tmp_desc = hdd_ipa->tx_desc_list;
4646 hdd_ipa->tx_desc_list = NULL;
4647 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4648 hdd_ipa->stats.num_tx_desc_error = 0;
4649 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4650 qdf_mem_free(tmp_desc);
4651 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652}
4653
4654/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004655 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4656 * @iface_context: interface-specific IPA context
4657 *
4658 * Return: None
4659 */
4660static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4661{
4662 if (iface_context == NULL)
4663 return;
4664
Yun Parkb4f591d2017-03-29 15:51:01 -07004665 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4666 iface_context->adapter->dev->name,
4667 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004668
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304669 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004670 iface_context->adapter->ipa_context = NULL;
4671 iface_context->adapter = NULL;
4672 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304673 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 iface_context->ifa_address = 0;
4675 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304676 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004677 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304678 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679 }
4680 iface_context->hdd_ipa->num_iface--;
4681}
4682
4683/**
4684 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4685 * @hdd_ipa: HDD IPA global context
4686 * @adapter: Interface upon which IPA is being setup
4687 * @sta_id: Station ID of the API instance
4688 *
4689 * Return: 0 on success, negative errno value on error
4690 */
4691static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004692 struct hdd_adapter *adapter, uint8_t sta_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004693{
4694 struct hdd_ipa_iface_context *iface_context = NULL;
4695 void *tl_context = NULL;
4696 int i, ret = 0;
4697
4698 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4699 * channel change indication. Since these indications are sent by lower
4700 * layer as SAP updates and IPA doesn't have to do anything for these
4701 * updates so ignoring!
4702 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004703 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004704 return 0;
4705
4706 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4707 if (hdd_ipa->iface_context[i].adapter == NULL) {
4708 iface_context = &(hdd_ipa->iface_context[i]);
4709 break;
4710 }
4711 }
4712
4713 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304714 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004715 "All the IPA interfaces are in use");
4716 ret = -ENOMEM;
4717 goto end;
4718 }
4719
4720 adapter->ipa_context = iface_context;
4721 iface_context->adapter = adapter;
4722 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004723 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07004724 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004725 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304726 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727 "Not able to get TL context sta_id: %d", sta_id);
4728 ret = -EINVAL;
4729 goto end;
4730 }
4731
4732 iface_context->tl_context = tl_context;
4733
Yun Parkb4f591d2017-03-29 15:51:01 -07004734 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4735 adapter->dev->name, adapter->dev->dev_addr,
4736 iface_context->prod_client,
4737 iface_context->cons_client,
4738 adapter->sessionId,
4739 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004740 if (ret)
4741 goto end;
4742
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004743 hdd_ipa->num_iface++;
4744 return ret;
4745
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004746end:
4747 if (iface_context)
4748 hdd_ipa_cleanup_iface(iface_context);
4749 return ret;
4750}
4751
Yun Parka27049a2016-10-11 12:30:49 -07004752#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004753/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004754 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004755 * @mcc_mode: 0=MCC/1=SCC
4756 *
4757 * Return: 0 on success, negative errno value on error
4758 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004759static int __hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004760{
4761 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304762 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004763 struct hdd_adapter *pAdapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764 struct ipa_msg_meta meta;
4765 struct ipa_wlan_msg *msg;
4766 int ret;
4767
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004768 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769 return -EINVAL;
4770
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004771 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4772 return -EINVAL;
4773
4774 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004776 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304777 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004778 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08004779 if (pAdapter->device_mode == QDF_STA_MODE ||
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004780 pAdapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004781 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004782 pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004783 hdd_deinit_tx_rx(pAdapter);
4784 }
4785 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004786 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004787 adapter_node = next;
4788 }
4789 }
4790
4791 /* Send SCC/MCC Switching event to IPA */
4792 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304793 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004794 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004795 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796 return -ENOMEM;
4797 }
4798
4799 meta.msg_type = mcc_mode ?
4800 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08004801 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004802
4803 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4804
4805 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004806 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004807 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304808 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809 }
4810
4811 return ret;
4812}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004813
4814/**
4815 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
4816 * @mcc_mode: 0=MCC/1=SCC
4817 *
4818 * Return: 0 on success, negative errno value on error
4819 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004820int hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004821{
4822 int ret;
4823
4824 cds_ssr_protect(__func__);
4825 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
4826 cds_ssr_unprotect(__func__);
4827
4828 return ret;
4829}
Yun Parka27049a2016-10-11 12:30:49 -07004830#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004831
4832/**
4833 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
4834 * @event: IPA WLAN event to be converted to a string
4835 *
4836 * Return: ASCII string representing the IPA WLAN event
4837 */
4838static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
4839{
4840 switch (event) {
4841 case WLAN_CLIENT_CONNECT:
4842 return "WLAN_CLIENT_CONNECT";
4843 case WLAN_CLIENT_DISCONNECT:
4844 return "WLAN_CLIENT_DISCONNECT";
4845 case WLAN_CLIENT_POWER_SAVE_MODE:
4846 return "WLAN_CLIENT_POWER_SAVE_MODE";
4847 case WLAN_CLIENT_NORMAL_MODE:
4848 return "WLAN_CLIENT_NORMAL_MODE";
4849 case SW_ROUTING_ENABLE:
4850 return "SW_ROUTING_ENABLE";
4851 case SW_ROUTING_DISABLE:
4852 return "SW_ROUTING_DISABLE";
4853 case WLAN_AP_CONNECT:
4854 return "WLAN_AP_CONNECT";
4855 case WLAN_AP_DISCONNECT:
4856 return "WLAN_AP_DISCONNECT";
4857 case WLAN_STA_CONNECT:
4858 return "WLAN_STA_CONNECT";
4859 case WLAN_STA_DISCONNECT:
4860 return "WLAN_STA_DISCONNECT";
4861 case WLAN_CLIENT_CONNECT_EX:
4862 return "WLAN_CLIENT_CONNECT_EX";
4863
4864 case IPA_WLAN_EVENT_MAX:
4865 default:
4866 return "UNKNOWN";
4867 }
4868}
4869
4870/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004871 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
4872 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
4873 *
4874 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
4875 */
4876static enum ipa_wlan_event
4877hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
4878{
4879 enum ipa_wlan_event ipa_event;
4880
4881 switch (hdd_ipa_event_type) {
4882 case HDD_IPA_CLIENT_CONNECT:
4883 ipa_event = WLAN_CLIENT_CONNECT;
4884 break;
4885 case HDD_IPA_CLIENT_DISCONNECT:
4886 ipa_event = WLAN_CLIENT_DISCONNECT;
4887 break;
4888 case HDD_IPA_AP_CONNECT:
4889 ipa_event = WLAN_AP_CONNECT;
4890 break;
4891 case HDD_IPA_AP_DISCONNECT:
4892 ipa_event = WLAN_AP_DISCONNECT;
4893 break;
4894 case HDD_IPA_STA_CONNECT:
4895 ipa_event = WLAN_STA_CONNECT;
4896 break;
4897 case HDD_IPA_STA_DISCONNECT:
4898 ipa_event = WLAN_STA_DISCONNECT;
4899 break;
4900 case HDD_IPA_CLIENT_CONNECT_EX:
4901 ipa_event = WLAN_CLIENT_CONNECT_EX;
4902 break;
4903 case HDD_IPA_WLAN_EVENT_MAX:
4904 default:
4905 ipa_event = IPA_WLAN_EVENT_MAX;
4906 break;
4907 }
4908 return ipa_event;
4909
4910}
4911
4912/**
4913 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 * @adapter: adapter upon which the event was received
4915 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07004916 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004917 * @mac_address: MAC address associated with the event
4918 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07004919 * This function is meant to be called from within wlan_hdd_ipa.c
4920 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921 * Return: 0 on success, negative errno value on error
4922 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07004923static int __hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004924 enum ipa_wlan_event type, uint8_t *mac_addr)
4925{
4926 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4927 struct ipa_msg_meta meta;
4928 struct ipa_wlan_msg *msg;
4929 struct ipa_wlan_msg_ex *msg_ex = NULL;
4930 int ret;
4931
Srinivas Girigowda97852372017-03-06 16:52:59 -08004932 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004933 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
4934 mac_addr, sta_id);
4935
4936 if (type >= IPA_WLAN_EVENT_MAX)
4937 return -EINVAL;
4938
4939 if (WARN_ON(is_zero_ether_addr(mac_addr)))
4940 return -EINVAL;
4941
4942 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304943 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004944 return -EINVAL;
4945 }
4946
4947 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
4948 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08004949 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004950 return 0;
4951 }
4952
4953 /*
4954 * During IPA UC resource loading/unloading new events can be issued.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004955 */
Yun Park777d7242017-03-30 15:38:33 -07004956 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
4957 (hdd_ipa->resource_loading || hdd_ipa->resource_unloading)) {
4958 unsigned int pending_event_count;
4959 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08004960
Yun Park777d7242017-03-30 15:38:33 -07004961 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4962 "%s:IPA resource %s inprogress",
4963 hdd_ipa_wlan_event_to_str(type),
4964 hdd_ipa->resource_loading ?
4965 "load" : "unload");
4966
4967 /* Wait until completion of the long/unloading */
4968 ret = wait_for_completion_timeout(&hdd_ipa->ipa_resource_comp,
4969 msecs_to_jiffies(IPA_RESOURCE_COMP_WAIT_TIME));
4970 if (!ret) {
4971 /*
4972 * If timed out, store the events separately and
4973 * handle them later.
4974 */
Yun Park64c405e2017-01-10 22:35:51 -08004975 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park777d7242017-03-30 15:38:33 -07004976 "IPA resource %s timed out",
4977 hdd_ipa->resource_loading ?
4978 "load" : "unload");
Yun Park7c4f31b2016-11-30 10:09:21 -08004979
Yun Park777d7242017-03-30 15:38:33 -07004980 if (hdd_ipa->resource_loading) {
4981 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004982
Yun Park777d7242017-03-30 15:38:33 -07004983 pending_event_count =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004984 qdf_list_size(&hdd_ipa->pending_event);
Yun Park777d7242017-03-30 15:38:33 -07004985 if (pending_event_count >=
4986 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
4987 hdd_debug(
4988 "Reached max pending event count");
4989 qdf_list_remove_front(
4990 &hdd_ipa->pending_event,
4991 (qdf_list_node_t **)&pending_event);
4992 } else {
4993 pending_event =
4994 (struct ipa_uc_pending_event *)
4995 qdf_mem_malloc(sizeof(
4996 struct ipa_uc_pending_event));
4997 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004998
Yun Park777d7242017-03-30 15:38:33 -07004999 if (!pending_event) {
5000 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5001 "Pending event memory alloc fail");
5002 qdf_mutex_release(&hdd_ipa->ipa_lock);
5003 return -ENOMEM;
5004 }
5005
5006 pending_event->adapter = adapter;
5007 pending_event->sta_id = sta_id;
5008 pending_event->type = type;
5009 qdf_mem_copy(pending_event->mac_addr,
5010 mac_addr, QDF_MAC_ADDR_SIZE);
5011 qdf_list_insert_back(&hdd_ipa->pending_event,
5012 &pending_event->node);
5013
Yun Park64c405e2017-01-10 22:35:51 -08005014 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005015 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005016 return 0;
Yun Park777d7242017-03-30 15:38:33 -07005017 } else {
Yun Park64c405e2017-01-10 22:35:51 -08005018 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park777d7242017-03-30 15:38:33 -07005019 "IPA resource %s completed",
5020 hdd_ipa->resource_loading ?
5021 "load" : "unload");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005023 }
5024
5025 hdd_ipa->stats.event[type]++;
5026
Leo Chang3bc8fed2015-11-13 10:59:47 -08005027 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 switch (type) {
5029 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005030 qdf_mutex_acquire(&hdd_ipa->event_lock);
5031
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005032 /* STA already connected and without disconnect, connect again
5033 * This is Roaming scenario
5034 */
5035 if (hdd_ipa->sta_connected)
5036 hdd_ipa_cleanup_iface(adapter->ipa_context);
5037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005038 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5039 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305040 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005041 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005042 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005043
Yun Park8f289c82016-10-18 16:38:21 -07005044 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5045 (hdd_ipa->sap_num_connected_sta > 0) &&
5046 !hdd_ipa->sta_connected) {
5047 qdf_mutex_release(&hdd_ipa->event_lock);
5048 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005049 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005050 qdf_mutex_acquire(&hdd_ipa->event_lock);
5051 }
5052
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005053 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005054 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005055 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005057 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005058
5059 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005060 break;
5061
5062 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005063 qdf_mutex_acquire(&hdd_ipa->event_lock);
5064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005065 /* For DFS channel we get two start_bss event (before and after
5066 * CAC). Also when ACS range includes both DFS and non DFS
5067 * channels, we could possibly change channel many times due to
5068 * RADAR detection and chosen channel may not be a DFS channels.
5069 * So dont return error here. Just discard the event.
5070 */
Yun Park8f289c82016-10-18 16:38:21 -07005071 if (adapter->ipa_context) {
5072 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005074 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005075
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005076 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5077 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005078 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005079 hdd_err("%s: Evt: %d, Interface setup failed",
5080 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005082 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083
Yun Park8f289c82016-10-18 16:38:21 -07005084 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5085 qdf_mutex_release(&hdd_ipa->event_lock);
5086 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005087 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005088 qdf_mutex_acquire(&hdd_ipa->event_lock);
5089 }
5090
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005091 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005092 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005093 (adapter->ipa_context))->iface_id;
5094
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305095 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 break;
5097
5098 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305099 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100
5101 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005102 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005103 hdd_err("%s: Evt: %d, STA already disconnected",
5104 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005105 return -EINVAL;
5106 }
Yun Parka37592b2016-06-11 17:10:28 -07005107
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005108 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005109
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005110 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005111 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005112 msg_ex->name);
5113 } else {
5114 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005115 if (!hdd_ipa->num_iface &&
5116 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305117 hdd_ipa->activated_fw_pipe) &&
5118 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005119 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005120 }
5121
Yun Park74127cf2016-09-18 11:22:41 -07005122 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5123 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005124 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005125 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005126 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005127 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005128 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5129 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130 }
5131
Yun Park8f289c82016-10-18 16:38:21 -07005132 hdd_ipa_cleanup_iface(adapter->ipa_context);
5133
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305134 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 break;
5136
5137 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005138 qdf_mutex_acquire(&hdd_ipa->event_lock);
5139
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005141 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005142 hdd_err("%s: Evt: %d, SAP already disconnected",
5143 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144 return -EINVAL;
5145 }
5146
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 if ((!hdd_ipa->num_iface) &&
5148 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305149 hdd_ipa->activated_fw_pipe) &&
5150 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005151 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005152 /*
5153 * We disable WDI pipes directly here since
5154 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5155 * processed when unloading WLAN driver is in
5156 * progress
5157 */
5158 hdd_ipa_uc_disable_pipes(hdd_ipa);
5159 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305160 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005161 "NO INTF left but still pipe clean up");
5162 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5163 }
5164 }
5165
5166 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005167 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005168 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005169 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005170 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005171 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5172 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005173 }
Yun Parka37592b2016-06-11 17:10:28 -07005174
Yun Park8f289c82016-10-18 16:38:21 -07005175 hdd_ipa_cleanup_iface(adapter->ipa_context);
5176
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305177 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178 break;
5179
5180 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005182 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005183 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305184 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005185 return 0;
5186 }
5187
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305188 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5190 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005191 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305192 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193 "%s: STA ID %d found, not valid",
5194 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005195 return 0;
5196 }
Yun Park312f71a2015-12-08 10:22:42 -08005197
5198 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005199 if (hdd_ipa->sap_num_connected_sta == 0 &&
5200 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005201 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005202 hdd_ipa->sta_connected) {
5203 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005204 hdd_ipa_uc_offload_enable_disable(
5205 hdd_get_adapter(hdd_ipa->hdd_ctx,
5206 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005207 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005208 qdf_mutex_acquire(&hdd_ipa->event_lock);
5209 }
Yun Parka37592b2016-06-11 17:10:28 -07005210
Yun Park312f71a2015-12-08 10:22:42 -08005211 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5212 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305213 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005214 "%s: handle 1st con ret %d",
5215 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005216
5217 if (hdd_ipa_uc_sta_is_enabled(
5218 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005219 hdd_ipa->sta_connected) {
5220 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005221 hdd_ipa_uc_offload_enable_disable(
5222 hdd_get_adapter(
5223 hdd_ipa->hdd_ctx,
5224 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005225 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005226 } else {
5227 qdf_mutex_release(&hdd_ipa->event_lock);
5228 }
Yun Parka37592b2016-06-11 17:10:28 -07005229
Yun Park312f71a2015-12-08 10:22:42 -08005230 return ret;
5231 }
5232 }
5233
5234 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005235
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305236 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237
5238 meta.msg_type = type;
5239 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5240 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305241 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005242
5243 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305244 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005245 "msg_ex allocation failed");
5246 return -ENOMEM;
5247 }
5248 strlcpy(msg_ex->name, adapter->dev->name,
5249 IPA_RESOURCE_NAME_MAX);
5250 msg_ex->num_of_attribs = 1;
5251 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5252 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5253 msg_ex->attribs[0].offset =
5254 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5255 } else {
5256 msg_ex->attribs[0].offset =
5257 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5258 }
5259 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5260 IPA_MAC_ADDR_SIZE);
5261
5262 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5263
5264 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005265 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305266 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305267 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 return ret;
5269 }
5270 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271 return ret;
5272
5273 case WLAN_CLIENT_DISCONNECT:
5274 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005275 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005276 "%s: IPA UC OFFLOAD NOT ENABLED",
5277 msg_ex->name);
5278 return 0;
5279 }
5280
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305281 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005282 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005283 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305284 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005285 "%s: STA ID %d NOT found, not valid",
5286 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005287 return 0;
5288 }
5289 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005290
Yun Park9b5030f2016-11-08 12:02:37 -08005291 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005292 if (!hdd_ipa->sap_num_connected_sta &&
5293 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005294 if ((false == hdd_ipa->resource_unloading)
5295 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305296 hdd_ipa->activated_fw_pipe) &&
5297 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005298 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5299 }
5300
Yun Park9b5030f2016-11-08 12:02:37 -08005301 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005302 hdd_ipa->sta_connected) {
5303 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005304 hdd_ipa_uc_offload_enable_disable(
5305 hdd_get_adapter(hdd_ipa->hdd_ctx,
5306 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005307 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005308 } else {
5309 qdf_mutex_release(&hdd_ipa->event_lock);
5310 }
Yun Park8f289c82016-10-18 16:38:21 -07005311 } else {
5312 qdf_mutex_release(&hdd_ipa->event_lock);
5313 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005314 break;
5315
5316 default:
5317 return 0;
5318 }
5319
5320 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305321 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305323 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005324 return -ENOMEM;
5325 }
5326
5327 meta.msg_type = type;
5328 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5329 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5330
Srinivas Girigowda97852372017-03-06 16:52:59 -08005331 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005332 msg->name, meta.msg_type);
5333
5334 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5335
5336 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005337 hdd_err("%s: Evt: %d fail:%d",
5338 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305339 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005340 return ret;
5341 }
5342
5343 hdd_ipa->stats.num_send_msg++;
5344
5345end:
5346 return ret;
5347}
5348
5349/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005350 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005351 * @adapter: adapter upon which the event was received
5352 * @sta_id: station id for the event
5353 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5354 * @mac_address: MAC address associated with the event
5355 *
5356 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5357 *
5358 * Return: 0 on success, negative errno value on error
5359 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005360int hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005361 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5362{
5363 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005364 int ret = 0;
5365
5366 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005367
Leo Changa202b522016-10-14 16:13:50 -07005368 /* Data path offload only support for STA and SAP mode */
5369 if ((QDF_STA_MODE == adapter->device_mode) ||
5370 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005371 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005372
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005373 cds_ssr_unprotect(__func__);
5374
5375 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005376}
5377
5378/**
5379 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5380 * @hdd_ipa: Global HDD IPA context
5381 *
5382 * Return: None
5383 */
5384static void
5385hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5386{
5387 unsigned int pending_event_count;
5388 struct ipa_uc_pending_event *pending_event = NULL;
5389
5390 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005391 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005392 "%s, Pending Event Count %d", __func__, pending_event_count);
5393 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005394 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005395 "%s, No Pending Event", __func__);
5396 return;
5397 }
5398
5399 qdf_list_remove_front(&hdd_ipa->pending_event,
5400 (qdf_list_node_t **)&pending_event);
5401 while (pending_event != NULL) {
5402 __hdd_ipa_wlan_evt(pending_event->adapter,
5403 pending_event->type,
5404 pending_event->sta_id,
5405 pending_event->mac_addr);
5406 qdf_mem_free(pending_event);
5407 pending_event = NULL;
5408 qdf_list_remove_front(&hdd_ipa->pending_event,
5409 (qdf_list_node_t **)&pending_event);
5410 }
5411}
5412
5413/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5415 * @state: IPA RM state value
5416 *
5417 * Return: ASCII string representing the IPA RM state
5418 */
5419static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5420{
5421 switch (state) {
5422 case HDD_IPA_RM_RELEASED:
5423 return "RELEASED";
5424 case HDD_IPA_RM_GRANT_PENDING:
5425 return "GRANT_PENDING";
5426 case HDD_IPA_RM_GRANTED:
5427 return "GRANTED";
5428 }
5429
5430 return "UNKNOWN";
5431}
5432
5433/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005434 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435 * @hdd_ctx: HDD global context
5436 *
5437 * Allocate hdd_ipa resources, ipa pipe resource and register
5438 * wlan interface with IPA module.
5439 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305440 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005441 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005442static QDF_STATUS __hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005443{
5444 struct hdd_ipa_priv *hdd_ipa = NULL;
5445 int ret, i;
5446 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005447 struct ol_txrx_pdev_t *pdev = NULL;
Yun Park66f24c42017-03-20 10:39:47 -07005448 struct ipa_rm_perf_profile profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005449
5450 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305451 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005452
Yun Parkbaa62862017-01-18 13:43:34 -08005453 ENTER();
5454
5455 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005456 if (!pdev) {
5457 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5458 goto fail_return;
5459 }
5460
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305461 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305463 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005464 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005465 }
5466
5467 hdd_ctx->hdd_ipa = hdd_ipa;
5468 ghdd_ipa = hdd_ipa;
5469 hdd_ipa->hdd_ctx = hdd_ctx;
5470 hdd_ipa->num_iface = 0;
5471
5472 /* Create the interface context */
5473 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5474 iface_context = &hdd_ipa->iface_context[i];
5475 iface_context->hdd_ipa = hdd_ipa;
5476 iface_context->cons_client =
5477 hdd_ipa_adapter_2_client[i].cons_client;
5478 iface_context->prod_client =
5479 hdd_ipa_adapter_2_client[i].prod_client;
5480 iface_context->iface_id = i;
5481 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305482 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005483 }
5484 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005485 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5486 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005487 }
5488
Leo Chang69c39692016-10-12 20:11:12 -07005489 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305490 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005491 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305492 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005493 qdf_list_create(&hdd_ipa->pending_event, 1000);
5494 qdf_mutex_create(&hdd_ipa->event_lock);
5495 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005496
5497 ret = hdd_ipa_setup_rm(hdd_ipa);
5498 if (ret)
5499 goto fail_setup_rm;
5500
5501 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5502 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305503 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005504 hdd_ipa->sap_num_connected_sta = 0;
5505 hdd_ipa->ipa_tx_packets_diff = 0;
5506 hdd_ipa->ipa_rx_packets_diff = 0;
5507 hdd_ipa->ipa_p_tx_packets = 0;
5508 hdd_ipa->ipa_p_rx_packets = 0;
5509 hdd_ipa->resource_loading = false;
5510 hdd_ipa->resource_unloading = false;
5511 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005512 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005513 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005514 /* Setup IPA sys_pipe for MCC */
5515 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5516 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5517 if (ret)
5518 goto fail_create_sys_pipe;
5519 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005520 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5521 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005522
5523 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5524 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5525 hdd_ipa_uc_fw_op_event_handler);
5526 hdd_ipa->uc_op_work[i].msg = NULL;
5527 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005528 } else {
5529 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5530 if (ret)
5531 goto fail_create_sys_pipe;
5532 }
5533
Yun Park66f24c42017-03-20 10:39:47 -07005534 /* When IPA clock scaling is disabled, initialze maximum clock */
5535 if (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)) {
5536 profile.max_supported_bandwidth_mbps = 800;
5537 hdd_debug("IPA clock scaling is disabled.");
5538 hdd_debug("Set initial CONS/PROD perf: %d",
5539 profile.max_supported_bandwidth_mbps);
5540 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
5541 &profile);
5542 if (ret) {
5543 hdd_err("RM CONS set perf profile failed: %d", ret);
5544 goto fail_create_sys_pipe;
5545 }
5546
5547 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
5548 &profile);
5549 if (ret) {
5550 hdd_err("RM PROD set perf profile failed: %d", ret);
5551 goto fail_create_sys_pipe;
5552 }
5553 }
5554
Yun Park777d7242017-03-30 15:38:33 -07005555 init_completion(&hdd_ipa->ipa_resource_comp);
5556
Yun Parkbaa62862017-01-18 13:43:34 -08005557 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305558 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559
5560fail_create_sys_pipe:
5561 hdd_ipa_destroy_rm_resource(hdd_ipa);
5562fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305563 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305564 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005565 hdd_ctx->hdd_ipa = NULL;
5566 ghdd_ipa = NULL;
5567fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08005568 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305569 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005570}
5571
5572/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005573 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5574 * @hdd_ctx: HDD global context
5575 *
5576 * Allocate hdd_ipa resources, ipa pipe resource and register
5577 * wlan interface with IPA module.
5578 *
5579 * Return: QDF_STATUS enumeration
5580 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005581QDF_STATUS hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005582{
5583 QDF_STATUS ret;
5584
5585 cds_ssr_protect(__func__);
5586 ret = __hdd_ipa_init(hdd_ctx);
5587 cds_ssr_unprotect(__func__);
5588
5589 return ret;
5590}
5591
Arun Khandavallicc544b32017-01-30 19:52:16 +05305592
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005593/**
Yun Parkf19e07d2015-11-20 11:34:27 -08005594 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
5595 * @hdd_ipa: pointer to HDD IPA struct
5596 *
5597 * Return: none
5598 */
Jeff Johnsond7720632016-10-05 16:04:32 -07005599static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08005600{
5601 struct ipa_uc_pending_event *pending_event = NULL;
5602
Anurag Chouhanffb21542016-02-17 14:33:03 +05305603 while (qdf_list_remove_front(&hdd_ipa->pending_event,
5604 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305605 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005606 }
5607
Anurag Chouhanffb21542016-02-17 14:33:03 +05305608 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005609}
5610
5611/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305612 * __hdd_ipa_flush - flush IPA exception path SKB's
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005613 * @hdd_ctx: HDD global context
5614 *
Govind Singh1dab23b2017-08-12 13:31:00 +05305615 * Return: none
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616 */
Govind Singh1dab23b2017-08-12 13:31:00 +05305617static void __hdd_ipa_flush(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005618{
5619 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305620 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005621 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5622
5623 if (!hdd_ipa_is_enabled(hdd_ctx))
Govind Singh1dab23b2017-08-12 13:31:00 +05305624 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005626 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005627
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305628 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629
Nirav Shahcbc6d722016-03-01 16:24:53 +05305630 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5631 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305632 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005633
5634 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005635 if (pm_tx_cb->ipa_tx_desc)
5636 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005637
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305638 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305640 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Govind Singh1dab23b2017-08-12 13:31:00 +05305641}
5642
5643/**
5644 * __hdd_ipa_cleanup - IPA cleanup function
5645 * @hdd_ctx: HDD global context
5646 *
5647 * Return: QDF_STATUS enumeration
5648 */
5649static QDF_STATUS __hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
5650{
5651 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5652 int i;
5653 struct hdd_ipa_iface_context *iface_context = NULL;
5654
5655 if (!hdd_ipa_is_enabled(hdd_ctx))
5656 return QDF_STATUS_SUCCESS;
5657
5658 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5659 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5660 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5661 }
5662
5663 /* Teardown IPA sys_pipe for MCC */
5664 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5665 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5666
5667 hdd_ipa_destroy_rm_resource(hdd_ipa);
5668
5669 __hdd_ipa_flush(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005670
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305671 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005672 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673
5674 /* destory the interface lock */
5675 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5676 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305677 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005678 }
5679
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005680 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005681 if (ipa_uc_dereg_rdyCB())
5682 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5683 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005684 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305685 qdf_mutex_destroy(&hdd_ipa->event_lock);
5686 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005687 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005688
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5690 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5691 hdd_ipa->uc_op_work[i].msg = NULL;
5692 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693 }
5694
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305695 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005696 hdd_ctx->hdd_ipa = NULL;
5697
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305698 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005700
5701/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305702 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_flush
5703 * @hdd_ctx: HDD global context
5704 *
5705 * Return: None
5706 */
5707void hdd_ipa_flush(struct hdd_context *hdd_ctx)
5708{
5709 cds_ssr_protect(__func__);
5710 __hdd_ipa_flush(hdd_ctx);
5711 cds_ssr_unprotect(__func__);
5712}
5713
5714/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005715 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5716 * @hdd_ctx: HDD global context
5717 *
5718 * Return: QDF_STATUS enumeration
5719 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005720QDF_STATUS hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005721{
5722 QDF_STATUS ret;
5723
5724 cds_ssr_protect(__func__);
5725 ret = __hdd_ipa_cleanup(hdd_ctx);
5726 cds_ssr_unprotect(__func__);
5727
5728 return ret;
5729}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005730#endif /* IPA_OFFLOAD */