blob: 7aa9089a2c32f4255bbf0dfb8f486bf18b37f213 [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;
Yun Park52b2b992016-09-22 15:49:51 -0700442 struct hdd_ipa_tx_desc *tx_desc_list;
443 struct list_head free_tx_desc_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800444
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700445 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800446
447 struct dentry *debugfs_dir;
448 struct hdd_ipa_stats stats;
449
450 struct notifier_block ipv4_notifier;
451 uint32_t curr_prod_bw;
452 uint32_t curr_cons_bw;
453
454 uint8_t activated_fw_pipe;
455 uint8_t sap_num_connected_sta;
456 uint8_t sta_connected;
457 uint32_t tx_pipe_handle;
458 uint32_t rx_pipe_handle;
459 bool resource_loading;
460 bool resource_unloading;
461 bool pending_cons_req;
462 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530463 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530464 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700465 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800466 uint32_t ipa_tx_packets_diff;
467 uint32_t ipa_rx_packets_diff;
468 uint32_t ipa_p_tx_packets;
469 uint32_t ipa_p_rx_packets;
470 uint32_t stat_req_reason;
471 uint64_t ipa_tx_forward;
472 uint64_t ipa_rx_discard;
473 uint64_t ipa_rx_net_send_count;
474 uint64_t ipa_rx_internel_drop_count;
475 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530476 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800477 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
478 unsigned int rt_buf_fill_index;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800479 struct ipa_wdi_in_params cons_pipe_in;
480 struct ipa_wdi_in_params prod_pipe_in;
481 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800482 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530483 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530484 qdf_mutex_t rt_debug_lock;
485 qdf_mutex_t ipa_lock;
Yun Parkb4f591d2017-03-29 15:51:01 -0700486
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800487 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
488 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Yun Park637d6482016-10-05 10:51:33 -0700489#ifdef FEATURE_METERING
490 struct ipa_uc_sharing_stats ipa_sharing_stats;
491 struct ipa_uc_quota_rsp ipa_quota_rsp;
492 struct ipa_uc_quota_ind ipa_quota_ind;
493 struct completion ipa_uc_sharing_stats_comp;
494 struct completion ipa_uc_set_quota_comp;
495#endif
Yun Park777d7242017-03-30 15:38:33 -0700496 struct completion ipa_resource_comp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497};
498
Leo Changcc923e22016-06-16 15:29:03 -0700499#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
500#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800501#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
502#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
503#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
504#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
505#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700506#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
507 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800508
509#define HDD_IPA_GET_IFACE_ID(_data) \
510 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
511
512#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530513 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800514 "%s:%d: "fmt, __func__, __LINE__, ## args)
515
Govind Singhb6a89772016-08-12 11:23:35 +0530516#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
517 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
518 "%s:%d: "fmt, __func__, __LINE__, ## args)
519
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800520#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
521 do { \
Yun Parkec845302016-12-15 09:22:57 -0800522 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
523 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800524 } while (0)
525
526#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
527 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
528
529#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
Jeff Johnsond5ba8a62017-09-30 14:30:53 -0700530 (hdd_ipa)->ipa_rx_internel_drop_count++
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
Jeff Johnsond5ba8a62017-09-30 14:30:53 -0700532 (hdd_ipa)->ipa_rx_net_send_count++
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800533#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
534
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700535#if defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)
Leo Chang63d73612016-10-18 18:09:43 -0700536#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800537#else
538/* Do nothing */
Leo Chang63d73612016-10-18 18:09:43 -0700539#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700540#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800541
Yun Parkb187d542016-11-14 18:10:04 -0800542#define HDD_IPA_DBG_DUMP_RX_LEN 32
543#define HDD_IPA_DBG_DUMP_TX_LEN 48
544
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800545static struct hdd_ipa_adapter_2_client {
546 enum ipa_client_type cons_client;
547 enum ipa_client_type prod_client;
548} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
549 {
550 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
551 }, {
552 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
553 }, {
554 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
555 },
556};
557
Yun Park637d6482016-10-05 10:51:33 -0700558#ifdef FEATURE_METERING
559#define IPA_UC_SHARING_STATES_WAIT_TIME 500
560#define IPA_UC_SET_QUOTA_WAIT_TIME 500
561#endif
562
Yun Park777d7242017-03-30 15:38:33 -0700563#define IPA_RESOURCE_COMP_WAIT_TIME 100
564
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800565static struct hdd_ipa_priv *ghdd_ipa;
566
567/* Local Function Prototypes */
568static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
569 unsigned long data);
570static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
571 unsigned long data);
Yun Parkb4f591d2017-03-29 15:51:01 -0700572#ifdef FEATURE_METERING
573static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
574 void *data);
575#else
576static void hdd_ipa_wdi_meter_notifier_cb(void);
577#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800578static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800579
580static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700581static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800582
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800583#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
584 defined(IPA_CLIENT_IS_MHI_CONS))
585/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800586 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
587 * @priv_ctxt: hdd ipa local context
588 *
589 * Will be called by IPA context.
590 * It's atomic context, then should be scheduled to kworker thread
591 *
592 * Return: None
593 */
594static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
595{
596 struct hdd_ipa_priv *hdd_ipa;
597 struct op_msg_type *msg;
598 struct uc_op_work_struct *uc_op_work;
599
600 if (priv_ctxt == NULL) {
601 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
602 return;
603 }
604
605 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
606 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
607 if (!msg) {
608 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
609 return;
610 }
611
612 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
613
614 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
615
616 /* When the same uC OPCODE is already pended, just return */
617 if (uc_op_work->msg)
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530618 goto done;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800619
620 uc_op_work->msg = msg;
621 schedule_work(&uc_op_work->work);
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530622
jiadd91a6842017-08-01 14:46:02 +0800623 /* work handler will free the msg buffer */
624 return;
625
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530626done:
627 qdf_mem_free(msg);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800628}
629
630/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800631 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
632 * @ctrl: WDI control value
633 *
634 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
635 *
636 * Return: 0 on message send to ipa, -1 on failure
637 */
638static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
639{
640 struct ipa_msg_meta meta;
641 struct ipa_wlan_msg *ipa_msg;
642 int ret = 0;
643
644 /* WDI enable message to IPA */
645 meta.msg_len = sizeof(*ipa_msg);
646 ipa_msg = qdf_mem_malloc(meta.msg_len);
647 if (ipa_msg == NULL) {
648 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
649 "msg allocation failed");
650 return -ENOMEM;
651 }
652
653 if (ctrl == true)
654 meta.msg_type = WLAN_WDI_ENABLE;
655 else
656 meta.msg_type = WLAN_WDI_DISABLE;
657
Srinivas Girigowda97852372017-03-06 16:52:59 -0800658 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800659 "ipa_send_msg(Evt:%d)", meta.msg_type);
660 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
661 if (ret) {
662 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
663 "ipa_send_msg(Evt:%d)-fail=%d",
664 meta.msg_type, ret);
665 qdf_mem_free(ipa_msg);
666 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800667 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800668}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800669
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800670/**
671 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
672 * @hdd_ipa: HDD IPA local context
673 *
674 * Register IPA UC ready callback function to IPA kernel driver
675 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
676 * open WDI pipe after WLAN driver loading finished
677 *
678 * Return: 0 Success
679 * -EPERM Registration fail
680 */
681static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
682{
683 struct ipa_wdi_uc_ready_params uc_ready_param;
684 int ret = 0;
685
686 hdd_ipa->uc_loaded = false;
687 uc_ready_param.priv = (void *)hdd_ipa;
688 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
689 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
690 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
691 "UC Ready CB register fail");
692 return -EPERM;
693 }
694 if (true == uc_ready_param.is_uC_ready) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700695 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800696 hdd_ipa->uc_loaded = true;
697 } else {
698 ret = hdd_ipa_uc_send_wdi_control_msg(false);
699 }
700
701 return ret;
702}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800703#else
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800704static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
705{
706 hdd_ipa->uc_loaded = true;
707 return 0;
708}
709
710static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
711{
712 return 0;
713}
714#endif
715
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800716/**
717 * hdd_ipa_is_enabled() - Is IPA enabled?
718 * @hdd_ctx: Global HDD context
719 *
720 * Return: true if IPA is enabled, false otherwise
721 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700722bool hdd_ipa_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800723{
724 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
725}
726
727/**
728 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
729 * @hdd_ctx: Global HDD context
730 *
731 * Return: true if IPA uC offload is enabled, false otherwise
732 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700733bool hdd_ipa_uc_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800734{
735 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
736}
737
738/**
739 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
740 * @hdd_ctx: Global HDD context
741 *
742 * Return: true if STA mode IPA uC offload is enabled, false otherwise
743 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700744static inline bool hdd_ipa_uc_sta_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800745{
746 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
747}
748
749/**
Guolei Bianca144d82016-11-10 11:07:42 +0800750 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
751 * @hdd_ipa: Global HDD IPA context
752 *
753 * Return: None
754 */
Guolei Bianca144d82016-11-10 11:07:42 +0800755static inline void hdd_ipa_uc_sta_reset_sta_connected(
756 struct hdd_ipa_priv *hdd_ipa)
757{
Yun Park637d6482016-10-05 10:51:33 -0700758 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800759 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700760 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800761}
Guolei Bianca144d82016-11-10 11:07:42 +0800762
763/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800764 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
765 * @hdd_ipa: Global HDD IPA context
766 *
767 * Return: true if pre-filter is enabled, otherwise false
768 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700769static inline bool hdd_ipa_is_pre_filter_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800770{
771 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
772 HDD_IPA_PRE_FILTER_ENABLE_MASK);
773}
774
775/**
776 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
777 * @hdd_ipa: Global HDD IPA context
778 *
779 * Return: true if IPv6 is enabled, otherwise false
780 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700781static inline bool hdd_ipa_is_ipv6_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800782{
783 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
784}
785
786/**
787 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
788 * @hdd_ipa: Global HDD IPA context
789 *
790 * Return: true if resource manager is enabled, otherwise false
791 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700792static inline bool hdd_ipa_is_rm_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793{
794 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
795}
796
797/**
798 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
799 * @hdd_ipa: Global HDD IPA context
800 *
801 * Return: true if resource manager is enabled, otherwise false
802 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700803static inline bool hdd_ipa_is_rt_debugging_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800804{
805 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
806}
807
808/**
809 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
810 * @hdd_ipa: Global HDD IPA context
811 *
812 * Return: true if clock scaling is enabled, otherwise false
813 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700814static inline bool hdd_ipa_is_clk_scaling_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800815{
816 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
817 HDD_IPA_CLK_SCALING_ENABLE_MASK |
818 HDD_IPA_RM_ENABLE_MASK);
819}
820
821/**
822 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
823 * @ctext: pointer to hdd context.
824 *
825 * If rt debug enabled, periodically called, and fill debug buffer
826 *
827 * Return: none
828 */
829static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
830{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700831 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800832 struct hdd_ipa_priv *hdd_ipa;
833 struct uc_rt_debug_info *dump_info = NULL;
834
835 if (wlan_hdd_validate_context(hdd_ctx))
836 return;
837
838 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700839 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 return;
841 }
842
843 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
844
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530845 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800846 dump_info = &hdd_ipa->rt_bug_buffer[
847 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
848
Deepthi Gowri6acee342016-10-28 15:00:38 +0530849 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800850 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
851 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
852 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800854 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
855 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800856 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
857 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530858 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800859
Anurag Chouhan210db072016-02-22 18:42:15 +0530860 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800861 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
862}
863
864/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700865 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 * @hdd_ctx: pointer to hdd context.
867 *
868 * If rt debug enabled, dump debug buffer contents based on requirement
869 *
870 * Return: none
871 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700872static void __hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800873{
874 struct hdd_ipa_priv *hdd_ipa;
875 unsigned int dump_count;
876 unsigned int dump_index;
877 struct uc_rt_debug_info *dump_info = NULL;
878
879 if (wlan_hdd_validate_context(hdd_ctx))
880 return;
881
882 hdd_ipa = hdd_ctx->hdd_ipa;
883 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700884 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800885 return;
886 }
887
Chris Guo1751acf2017-07-03 14:09:01 +0800888 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
889 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
890 "%s: IPA RT debug is not enabled", __func__);
891 return;
892 }
893
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530894 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530896 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800897 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800898
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530899 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800900 for (dump_count = 0;
901 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
902 dump_count++) {
903 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
904 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
905 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530906 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530907 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800908 dump_info->time, dump_info->ipa_excep_count,
909 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800910 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 dump_info->rx_destructor_call,
912 dump_info->rx_discard_count);
913 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530914 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530915 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
917}
918
919/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700920 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
921 * __hdd_ipa_uc_rt_debug_host_dump
922 * @hdd_ctx: pointer to hdd context.
923 *
924 * If rt debug enabled, dump debug buffer contents based on requirement
925 *
926 * Return: none
927 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700928void hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700929{
930 cds_ssr_protect(__func__);
931 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
932 cds_ssr_unprotect(__func__);
933}
934
935/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800936 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
937 * @ctext: pointer to hdd context.
938 *
939 * periodically called by timer expire
940 * will try to alloc dummy memory and detect out of memory condition
941 * if out of memory detected, dump wlan-ipa stats
942 *
943 * Return: none
944 */
945static void hdd_ipa_uc_rt_debug_handler(void *ctext)
946{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700947 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700948 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800949 void *dummy_ptr = NULL;
950
951 if (wlan_hdd_validate_context(hdd_ctx))
952 return;
953
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700954 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
955
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700957 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
958 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800959 return;
960 }
961
962 /* Allocate dummy buffer periodically and free immediately. this will
963 * proactively detect OOM and if allocation fails dump ipa stats
964 */
965 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
966 GFP_KERNEL | GFP_ATOMIC);
967 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
969 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -0700970 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
971 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800972 } else {
973 kfree(dummy_ptr);
974 }
975
Anurag Chouhan210db072016-02-22 18:42:15 +0530976 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 HDD_IPA_UC_RT_DEBUG_PERIOD);
978}
979
980/**
Yun Parkb187d542016-11-14 18:10:04 -0800981 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800982 * @skb: packet pinter
983 *
984 * when free data packet, will be invoked by wlan client and will increase
985 * free counter
986 *
987 * Return: none
988 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700989static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800990{
991 if (!ghdd_ipa) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700992 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "invalid hdd context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993 return;
994 }
995
996 ghdd_ipa->ipa_rx_destructor_count++;
997}
998
999/**
Yun Parkb187d542016-11-14 18:10:04 -08001000 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001 * @hdd_ctx: hdd main context
1002 *
1003 * free all rt debugging resources
1004 *
1005 * Return: none
1006 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001007static void hdd_ipa_uc_rt_debug_deinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001008{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001009 struct hdd_ipa_priv *hdd_ipa;
1010
1011 if (wlan_hdd_validate_context(hdd_ctx))
1012 return;
1013
1014 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001015
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301016 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017
1018 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001019 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1020 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001021 return;
1022 }
1023
Anurag Chouhan210db072016-02-22 18:42:15 +05301024 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001025 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1026 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1027 }
1028 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1029
1030 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301031 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1032 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301034 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035}
1036
1037/**
Yun Parkb187d542016-11-14 18:10:04 -08001038 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039 * @hdd_ctx: hdd main context
1040 *
1041 * alloc and initialize all rt debugging resources
1042 *
1043 * Return: none
1044 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001045static void hdd_ipa_uc_rt_debug_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001046{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001047 struct hdd_ipa_priv *hdd_ipa;
1048
Chris Guo1751acf2017-07-03 14:09:01 +08001049 if (wlan_hdd_validate_context_in_loading(hdd_ctx))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001050 return;
1051
1052 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001053
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301054 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001055 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301056 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 sizeof(struct uc_rt_debug_info) *
1058 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1059 hdd_ipa->ipa_tx_forward = 0;
1060 hdd_ipa->ipa_rx_discard = 0;
1061 hdd_ipa->ipa_rx_net_send_count = 0;
1062 hdd_ipa->ipa_rx_internel_drop_count = 0;
1063 hdd_ipa->ipa_rx_destructor_count = 0;
1064
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 /* Reatime debug enable on feature enable */
1066 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001067 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1068 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001069 return;
1070 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001071
1072 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1073 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1074 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1075 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1076
Anurag Chouhan210db072016-02-22 18:42:15 +05301077 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001078 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301079 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001080 HDD_IPA_UC_RT_DEBUG_PERIOD);
1081
1082}
1083
1084/**
Yun Parkb187d542016-11-14 18:10:04 -08001085 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1086 * @hdd_ipa: HDD IPA struct
1087 *
1088 * Dump entries in struct hdd_ipa
1089 *
1090 * Return: none
1091 */
1092static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1093{
1094 int i;
1095
1096 /* HDD IPA */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001097 hdd_info("==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001098 "num_iface: %d\n"
1099 "rm_state: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001100 "rm_lock: %pK\n"
1101 "uc_rm_work: %pK\n"
1102 "uc_op_work: %pK\n"
1103 "wake_lock: %pK\n"
1104 "wake_lock_work: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001105 "wake_lock_released: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08001106 "tx_ref_cnt: %d\n"
1107 "pm_queue_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001108 "\thead: %pK\n"
1109 "\ttail: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001110 "\tqlen: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001111 "pm_work: %pK\n"
1112 "pm_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001113 "suspended: %d\n",
1114 hdd_ipa->num_iface,
1115 hdd_ipa->rm_state,
1116 &hdd_ipa->rm_lock,
1117 &hdd_ipa->uc_rm_work,
1118 &hdd_ipa->uc_op_work,
1119 &hdd_ipa->wake_lock,
1120 &hdd_ipa->wake_lock_work,
1121 hdd_ipa->wake_lock_released,
Yun Parkb187d542016-11-14 18:10:04 -08001122 hdd_ipa->tx_ref_cnt.counter,
1123 hdd_ipa->pm_queue_head.head,
1124 hdd_ipa->pm_queue_head.tail,
1125 hdd_ipa->pm_queue_head.qlen,
1126 &hdd_ipa->pm_work,
1127 &hdd_ipa->pm_lock,
1128 hdd_ipa->suspended);
Jeff Johnson36e74c42017-09-18 08:15:42 -07001129 hdd_err("\nq_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001130 "pend_desc_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001131 "\tnext: %pK\n"
1132 "\tprev: %pK\n"
1133 "hdd_ctx: %pK\n"
1134 "debugfs_dir: %pK\n"
1135 "stats: %pK\n"
1136 "ipv4_notifier: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001137 "curr_prod_bw: %d\n"
1138 "curr_cons_bw: %d\n"
1139 "activated_fw_pipe: %d\n"
1140 "sap_num_connected_sta: %d\n"
1141 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001142 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001143 hdd_ipa->pend_desc_head.next,
1144 hdd_ipa->pend_desc_head.prev,
1145 hdd_ipa->hdd_ctx,
1146 hdd_ipa->debugfs_dir,
1147 &hdd_ipa->stats,
1148 &hdd_ipa->ipv4_notifier,
1149 hdd_ipa->curr_prod_bw,
1150 hdd_ipa->curr_cons_bw,
1151 hdd_ipa->activated_fw_pipe,
1152 hdd_ipa->sap_num_connected_sta,
1153 (unsigned int)hdd_ipa->sta_connected
1154 );
Srinivas Girigowda97852372017-03-06 16:52:59 -08001155 hdd_info("\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001156 "rx_pipe_handle: 0x%x\n"
1157 "resource_loading: %d\n"
1158 "resource_unloading: %d\n"
1159 "pending_cons_req: %d\n"
1160 "pending_event----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001161 "\tanchor.next: %pK\n"
1162 "\tanchor.prev: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001163 "\tcount: %d\n"
1164 "\tmax_size: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001165 "event_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001166 "ipa_tx_packets_diff: %d\n"
1167 "ipa_rx_packets_diff: %d\n"
1168 "ipa_p_tx_packets: %d\n"
1169 "ipa_p_rx_packets: %d\n"
1170 "stat_req_reason: %d\n",
1171 hdd_ipa->tx_pipe_handle,
1172 hdd_ipa->rx_pipe_handle,
1173 hdd_ipa->resource_loading,
1174 hdd_ipa->resource_unloading,
1175 hdd_ipa->pending_cons_req,
1176 hdd_ipa->pending_event.anchor.next,
1177 hdd_ipa->pending_event.anchor.prev,
1178 hdd_ipa->pending_event.count,
1179 hdd_ipa->pending_event.max_size,
1180 &hdd_ipa->event_lock,
1181 hdd_ipa->ipa_tx_packets_diff,
1182 hdd_ipa->ipa_rx_packets_diff,
1183 hdd_ipa->ipa_p_tx_packets,
1184 hdd_ipa->ipa_p_rx_packets,
1185 hdd_ipa->stat_req_reason);
1186
Srinivas Girigowda97852372017-03-06 16:52:59 -08001187 hdd_info("assoc_stas_map([id]is_reserved/sta_id): ");
Yun Parkb187d542016-11-14 18:10:04 -08001188 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001189 hdd_info(" [%d]%d/%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001190 hdd_ipa->assoc_stas_map[i].is_reserved,
1191 hdd_ipa->assoc_stas_map[i].sta_id);
1192 }
1193}
1194
1195/**
1196 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1197 * @hdd_ipa: HDD IPA struct
1198 *
1199 * Dump entire struct hdd_ipa_sys_pipe
1200 *
1201 * Return: none
1202 */
1203static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1204{
1205 int i;
1206
1207 /* IPA SYS Pipes */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001208 hdd_info("==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001209
1210 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1211 struct hdd_ipa_sys_pipe *sys_pipe;
1212 struct ipa_sys_connect_params *ipa_sys_params;
1213
1214 sys_pipe = &hdd_ipa->sys_pipe[i];
1215 ipa_sys_params = &sys_pipe->ipa_sys_params;
1216
Srinivas Girigowda97852372017-03-06 16:52:59 -08001217 hdd_info("sys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001218 "\tconn_hdl: 0x%x\n"
1219 "\tconn_hdl_valid: %d\n"
1220 "\tnat_en: %d\n"
1221 "\thdr_len %d\n"
1222 "\thdr_additional_const_len: %d\n"
1223 "\thdr_ofst_pkt_size_valid: %d\n"
1224 "\thdr_ofst_pkt_size: %d\n"
1225 "\thdr_little_endian: %d\n"
1226 "\tmode: %d\n"
1227 "\tclient: %d\n"
1228 "\tdesc_fifo_sz: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001229 "\tpriv: %pK\n"
1230 "\tnotify: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001231 "\tskip_ep_cfg: %d\n"
1232 "\tkeep_ipa_awake: %d\n",
1233 i,
1234 sys_pipe->conn_hdl,
1235 sys_pipe->conn_hdl_valid,
1236 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1237 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1238 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1239 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1240 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1241 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1242 ipa_sys_params->ipa_ep_cfg.mode.mode,
1243 ipa_sys_params->client,
1244 ipa_sys_params->desc_fifo_sz,
1245 ipa_sys_params->priv,
1246 ipa_sys_params->notify,
1247 ipa_sys_params->skip_ep_cfg,
1248 ipa_sys_params->keep_ipa_awake);
1249 }
1250}
1251
1252/**
1253 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1254 * @hdd_ipa: HDD IPA struct
1255 *
1256 * Dump entire struct hdd_ipa_iface_context
1257 *
1258 * Return: none
1259 */
1260static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1261{
1262 int i;
1263
1264 /* IPA Interface Contexts */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001265 hdd_info("==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001266
1267 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1268 struct hdd_ipa_iface_context *iface_context;
1269
1270 iface_context = &hdd_ipa->iface_context[i];
1271
Srinivas Girigowda97852372017-03-06 16:52:59 -08001272 hdd_info("iface_context[%d]----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001273 "\thdd_ipa: %pK\n"
1274 "\tadapter: %pK\n"
1275 "\ttl_context: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001276 "\tcons_client: %d\n"
1277 "\tprod_client: %d\n"
1278 "\tiface_id: %d\n"
1279 "\tsta_id: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001280 "\tinterface_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001281 "\tifa_address: 0x%x\n",
1282 i,
1283 iface_context->hdd_ipa,
1284 iface_context->adapter,
1285 iface_context->tl_context,
1286 iface_context->cons_client,
1287 iface_context->prod_client,
1288 iface_context->iface_id,
1289 iface_context->sta_id,
1290 &iface_context->interface_lock,
1291 iface_context->ifa_address);
1292 }
1293}
1294
1295/**
1296 * hdd_ipa_dump_info() - dump HDD IPA struct
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001297 * @hdd_ctx: hdd main context
Yun Parkb187d542016-11-14 18:10:04 -08001298 *
1299 * Dump entire struct hdd_ipa
1300 *
1301 * Return: none
1302 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001303void hdd_ipa_dump_info(struct hdd_context *hdd_ctx)
Yun Parkb187d542016-11-14 18:10:04 -08001304{
1305 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1306
1307 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1308 hdd_ipa_dump_sys_pipe(hdd_ipa);
1309 hdd_ipa_dump_iface_context(hdd_ipa);
1310}
1311
1312/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001313 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1314 * enabled
1315 *
1316 * This routine is called to set TX flow info if IPA is enabled
1317 *
1318 * Return: None
1319 */
1320void hdd_ipa_set_tx_flow_info(void)
1321{
1322 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1323 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001324 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07001325 struct hdd_station_ctx *sta_ctx;
Jeff Johnson87251032017-08-29 13:31:11 -07001326 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -07001327 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001328 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1329 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1330 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1331 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1332 const char *p2pMode = "DEV";
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001333 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001334 cds_context_type *cds_ctx;
1335#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1336 uint8_t targetChannel = 0;
1337 uint8_t preAdapterChannel = 0;
1338 uint8_t channel24;
1339 uint8_t channel5;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001340 struct hdd_adapter *preAdapterContext = NULL;
1341 struct hdd_adapter *adapter2_4 = NULL;
1342 struct hdd_adapter *adapter5 = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001343 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1344#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1345 struct wlan_objmgr_psoc *psoc;
1346
1347 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1348 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001349 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001350 return;
1351 }
1352
1353 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1354 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001355 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001356 return;
1357 }
1358
1359 psoc = hdd_ctx->hdd_psoc;
1360 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1361 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001362 adapter = adapterNode->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001363 switch (adapter->device_mode) {
1364 case QDF_STA_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001365 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001366 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001367 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001368 staChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001369 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001370 qdf_copy_macaddr(&staBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001371 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001372#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1373 targetChannel = staChannel;
1374#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1375 }
1376 break;
1377 case QDF_P2P_CLIENT_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001378 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001379 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001380 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001381 p2pChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001382 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001383 qdf_copy_macaddr(&p2pBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001384 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001385 p2pMode = "CLI";
1386#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1387 targetChannel = p2pChannel;
1388#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1389 }
1390 break;
1391 case QDF_P2P_GO_MODE:
1392 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1393 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1394 if (hostapd_state->bssState == BSS_START
1395 && hostapd_state->qdf_status ==
1396 QDF_STATUS_SUCCESS) {
1397 p2pChannel = hdd_ap_ctx->operatingChannel;
1398 qdf_copy_macaddr(&p2pBssid,
1399 &adapter->macAddressCurrent);
1400#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1401 targetChannel = p2pChannel;
1402#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1403 }
1404 p2pMode = "GO";
1405 break;
1406 case QDF_SAP_MODE:
1407 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1408 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1409 if (hostapd_state->bssState == BSS_START
1410 && hostapd_state->qdf_status ==
1411 QDF_STATUS_SUCCESS) {
1412 apChannel = hdd_ap_ctx->operatingChannel;
1413 qdf_copy_macaddr(&apBssid,
1414 &adapter->macAddressCurrent);
1415#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1416 targetChannel = apChannel;
1417#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1418 }
1419 break;
1420 case QDF_IBSS_MODE:
1421 default:
1422 break;
1423 }
1424#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1425 if (targetChannel) {
1426 /*
1427 * This is first adapter detected as active
1428 * set as default for none concurrency case
1429 */
1430 if (!preAdapterChannel) {
1431 /* If IPA UC data path is enabled,
1432 * target should reserve extra tx descriptors
1433 * for IPA data path.
1434 * Then host data path should allow less TX
1435 * packet pumping in case IPA
1436 * data path enabled
1437 */
1438 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1439 (QDF_SAP_MODE == adapter->device_mode)) {
1440 adapter->tx_flow_low_watermark =
1441 hdd_ctx->config->TxFlowLowWaterMark +
1442 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1443 } else {
1444 adapter->tx_flow_low_watermark =
1445 hdd_ctx->config->
1446 TxFlowLowWaterMark;
1447 }
1448 adapter->tx_flow_high_watermark_offset =
1449 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1450 cdp_fc_ll_set_tx_pause_q_depth(soc,
1451 adapter->sessionId,
1452 hdd_ctx->config->TxFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001453 hdd_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001454 adapter->device_mode,
1455 targetChannel,
1456 adapter->tx_flow_low_watermark,
1457 adapter->tx_flow_low_watermark +
1458 adapter->tx_flow_high_watermark_offset,
1459 hdd_ctx->config->TxFlowMaxQueueDepth);
1460 preAdapterChannel = targetChannel;
1461 preAdapterContext = adapter;
1462 } else {
1463 /*
1464 * SCC, disable TX flow control for both
1465 * SCC each adapter cannot reserve dedicated
1466 * channel resource, as a result, if any adapter
1467 * blocked OS Q by flow control,
1468 * blocked adapter will lost chance to recover
1469 */
1470 if (preAdapterChannel == targetChannel) {
1471 /* Current adapter */
1472 adapter->tx_flow_low_watermark = 0;
1473 adapter->
1474 tx_flow_high_watermark_offset = 0;
1475 cdp_fc_ll_set_tx_pause_q_depth(soc,
1476 adapter->sessionId,
1477 hdd_ctx->config->
1478 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001479 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001480 hdd_device_mode_to_string(
1481 adapter->device_mode),
1482 adapter->device_mode,
1483 targetChannel,
1484 adapter->tx_flow_low_watermark,
1485 adapter->tx_flow_low_watermark +
1486 adapter->
1487 tx_flow_high_watermark_offset,
1488 hdd_ctx->config->
1489 TxHbwFlowMaxQueueDepth);
1490
1491 if (!preAdapterContext) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001492 hdd_err("SCC: Previous adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001493 continue;
1494 }
1495
1496 /* Previous adapter */
1497 preAdapterContext->
1498 tx_flow_low_watermark = 0;
1499 preAdapterContext->
1500 tx_flow_high_watermark_offset = 0;
1501 cdp_fc_ll_set_tx_pause_q_depth(soc,
1502 preAdapterContext->sessionId,
1503 hdd_ctx->config->
1504 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001505 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001506 hdd_device_mode_to_string(
1507 preAdapterContext->device_mode
1508 ),
1509 preAdapterContext->device_mode,
1510 targetChannel,
1511 preAdapterContext->
1512 tx_flow_low_watermark,
1513 preAdapterContext->
1514 tx_flow_low_watermark +
1515 preAdapterContext->
1516 tx_flow_high_watermark_offset,
1517 hdd_ctx->config->
1518 TxHbwFlowMaxQueueDepth);
1519 }
1520 /*
1521 * MCC, each adapter will have dedicated
1522 * resource
1523 */
1524 else {
1525 /* current channel is 2.4 */
1526 if (targetChannel <=
1527 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1528 channel24 = targetChannel;
1529 channel5 = preAdapterChannel;
1530 adapter2_4 = adapter;
1531 adapter5 = preAdapterContext;
1532 } else {
1533 /* Current channel is 5 */
1534 channel24 = preAdapterChannel;
1535 channel5 = targetChannel;
1536 adapter2_4 = preAdapterContext;
1537 adapter5 = adapter;
1538 }
1539
1540 if (!adapter5) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001541 hdd_err("MCC: 5GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001542 continue;
1543 }
1544 adapter5->tx_flow_low_watermark =
1545 hdd_ctx->config->
1546 TxHbwFlowLowWaterMark;
1547 adapter5->
1548 tx_flow_high_watermark_offset =
1549 hdd_ctx->config->
1550 TxHbwFlowHighWaterMarkOffset;
1551 cdp_fc_ll_set_tx_pause_q_depth(soc,
1552 adapter5->sessionId,
1553 hdd_ctx->config->
1554 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001555 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001556 hdd_device_mode_to_string(
1557 adapter5->device_mode),
1558 adapter5->device_mode,
1559 channel5,
1560 adapter5->tx_flow_low_watermark,
1561 adapter5->
1562 tx_flow_low_watermark +
1563 adapter5->
1564 tx_flow_high_watermark_offset,
1565 hdd_ctx->config->
1566 TxHbwFlowMaxQueueDepth);
1567
1568 if (!adapter2_4) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001569 hdd_err("MCC: 2.4GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001570 continue;
1571 }
1572 adapter2_4->tx_flow_low_watermark =
1573 hdd_ctx->config->
1574 TxLbwFlowLowWaterMark;
1575 adapter2_4->
1576 tx_flow_high_watermark_offset =
1577 hdd_ctx->config->
1578 TxLbwFlowHighWaterMarkOffset;
1579 cdp_fc_ll_set_tx_pause_q_depth(soc,
1580 adapter2_4->sessionId,
1581 hdd_ctx->config->
1582 TxLbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001583 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001584 hdd_device_mode_to_string(
1585 adapter2_4->device_mode),
1586 adapter2_4->device_mode,
1587 channel24,
1588 adapter2_4->
1589 tx_flow_low_watermark,
1590 adapter2_4->
1591 tx_flow_low_watermark +
1592 adapter2_4->
1593 tx_flow_high_watermark_offset,
1594 hdd_ctx->config->
1595 TxLbwFlowMaxQueueDepth);
1596
1597 }
1598 }
1599 }
1600 targetChannel = 0;
1601#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1602 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1603 adapterNode = pNext;
1604 }
1605 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1606}
1607
1608/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001609 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001611 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1612 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001613 *
1614 * Return: true if IPA is enabled, false otherwise
1615 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001616static void __hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001617 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1618{
1619 struct hdd_ipa_priv *hdd_ipa;
1620
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001621 *ipa_tx_diff = 0;
1622 *ipa_rx_diff = 0;
1623
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001624 if (wlan_hdd_validate_context(hdd_ctx))
1625 return;
1626
1627 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1628
1629 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1630 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001631 return;
1632 }
1633
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301634 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001635 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1636 (false == hdd_ipa->resource_loading)) {
1637 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1638 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001639 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001640 *ipa_tx_diff, *ipa_rx_diff);
1641 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301642 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001643}
1644
1645/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001646 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1647 * @hdd_ctx: Global HDD context
1648 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1649 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1650 *
1651 * Return: true if IPA is enabled, false otherwise
1652 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001653void hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001654 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1655{
1656 cds_ssr_protect(__func__);
1657 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1658 cds_ssr_unprotect(__func__);
1659}
1660
1661/**
1662 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001663 * @adapter: network adapter
1664 * @reason: STAT REQ Reason
1665 *
1666 * Return: None
1667 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07001668static void __hdd_ipa_uc_stat_request(struct hdd_adapter *adapter,
1669 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{
Yun Parkfec73dc2017-09-06 10:40:07 -07001858 int result = 0;
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 Parkfec73dc2017-09-06 10:40:07 -07001862 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
1863
Yun Parkb4f591d2017-03-29 15:51:01 -07001864 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001865 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301866 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001867 "Enable PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001868 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001870
Yun Park777d7242017-03-30 15:38:33 -07001871 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Leo Change3e49442015-10-26 20:07:13 -07001872 hdd_ipa->ipa_pipes_down = false;
Yun Parkb4f591d2017-03-29 15:51:01 -07001873
1874 cdp_ipa_enable_autonomy(soc, (struct cdp_pdev *)pdev);
1875
Yun Parkfec73dc2017-09-06 10:40:07 -07001876end:
1877 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: ipa_pipes_down=%d",
1878 hdd_ipa->ipa_pipes_down);
1879 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880}
1881
1882/**
1883 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1884 * @hdd_ipa: Global HDD IPA context
1885 *
1886 * Return: 0 on success, negative errno if error
1887 */
1888static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1889{
Yun Parkb4f591d2017-03-29 15:51:01 -07001890 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1891 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkfec73dc2017-09-06 10:40:07 -07001892 int result = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893
Yun Parkfec73dc2017-09-06 10:40:07 -07001894 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Leo Change3e49442015-10-26 20:07:13 -07001895
Yun Parkb4f591d2017-03-29 15:51:01 -07001896 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001897
Yun Parkb4f591d2017-03-29 15:51:01 -07001898 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001899 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301900 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001901 "Disable WDI PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001902 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001903 }
1904
Yun Parkfec73dc2017-09-06 10:40:07 -07001905 hdd_ipa->ipa_pipes_down = true;
1906
1907end:
1908 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: ipa_pipes_down=%d",
1909 hdd_ipa->ipa_pipes_down);
1910 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001911}
1912
1913/**
1914 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1915 * @hdd_ipa: Global HDD IPA context
1916 *
1917 * Return: 0 on success, negative errno if error
1918 */
1919static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1920{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001921 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07001922
Yun Parkfec73dc2017-09-06 10:40:07 -07001923 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
1924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 hdd_ipa->activated_fw_pipe = 0;
1926 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001927
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001928 /* If RM feature enabled
1929 * Request PROD Resource first
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07001930 * PROD resource may return sync or async manners
1931 */
Yun Parkb4f591d2017-03-29 15:51:01 -07001932 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001933 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1934 /* RM PROD request sync return
1935 * enable pipe immediately
1936 */
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301937 if (!hdd_ipa->ipa_pipes_down) {
1938 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1939 "%s: IPA WDI Pipe already activated",
1940 __func__);
1941 return 0;
1942 }
1943
Yun Park4cab6ee2015-10-27 11:43:40 -07001944 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301945 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001946 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001947 hdd_ipa->resource_loading = false;
1948 return -EBUSY;
1949 }
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301950 } else {
1951 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
1952 "%s: IPA WDI Pipe activation deferred",
1953 __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954 }
1955 } else {
1956 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001957 * Just enabled all the PIPEs
1958 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001959 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301960 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001961 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001962 hdd_ipa->resource_loading = false;
1963 return -EBUSY;
1964 }
1965 hdd_ipa->resource_loading = false;
1966 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001967
Yun Parkfec73dc2017-09-06 10:40:07 -07001968 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: IPA WDI Pipes activated!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001969 return 0;
1970}
1971
1972/**
1973 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1974 * @hdd_ipa: Global HDD IPA context
1975 *
1976 * Return: None
1977 */
1978static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1979{
Leo Changfdb45c32016-10-28 11:09:23 -07001980 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001981 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001982
Yun Parkfec73dc2017-09-06 10:40:07 -07001983 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
1984
Yun Parkb4f591d2017-03-29 15:51:01 -07001985 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08001986 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
1987 QDF_ASSERT(0);
1988 return;
1989 }
1990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001991 hdd_ipa->resource_unloading = true;
Yun Park777d7242017-03-30 15:38:33 -07001992 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Yun Parkb4f591d2017-03-29 15:51:01 -07001993 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
1994 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
1995 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
1996 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Yun Parkfec73dc2017-09-06 10:40:07 -07001997
1998 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: IPA WDI Pipes deactivated");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999}
2000
2001/**
2002 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
2003 * @context: User context registered with TL (the IPA Global context is
2004 * registered
2005 * @rxpkt: Packet containing the notification
2006 * @staid: ID of the station associated with the packet
2007 *
2008 * Return: None
2009 */
2010static void
2011hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
2012{
2013 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302014 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002015 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002016
2017 /*
2018 * When SSR is going on or driver is unloading, just return.
2019 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002020 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302021 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002022 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002023
Yun Parkb4f591d2017-03-29 15:51:01 -07002024 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 return;
2026
Srinivas Girigowda97852372017-03-06 16:52:59 -08002027 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 __func__, event);
2029
2030 switch (event) {
2031 case IPA_RM_RESOURCE_GRANTED:
2032 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302033 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002034 if ((false == hdd_ipa->resource_unloading) &&
2035 (!hdd_ipa->activated_fw_pipe)) {
2036 hdd_ipa_uc_enable_pipes(hdd_ipa);
2037 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302038 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002039 break;
2040
2041 case IPA_RM_RESOURCE_RELEASED:
2042 /* Differed RM Released */
2043 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044 break;
2045
2046 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302047 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002048 "%s, invalid event code %d", __func__, event);
2049 break;
2050 }
2051}
2052
2053/**
2054 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2055 * @hdd_ipa: Global HDD IPA context
2056 * @event: IPA resource manager event to be deferred
2057 *
2058 * This function is called when a resource manager event is received
2059 * from firmware in interrupt context. This function will defer the
2060 * handling to the OL RX thread
2061 *
2062 * Return: None
2063 */
2064static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2065{
2066 enum ipa_rm_event event;
2067 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2068 struct uc_rm_work_struct, work);
2069 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2070 struct hdd_ipa_priv, uc_rm_work);
2071
2072 cds_ssr_protect(__func__);
2073 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002074 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002075 "%s, posted event %d", __func__, event);
2076
2077 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2078 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002079}
2080
2081/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002082 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002083 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002084 *
2085 * Will handle IPA UC image loaded indication comes from IPA kernel
2086 *
2087 * Return: None
2088 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002089static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002090{
Yun Parkb4f591d2017-03-29 15:51:01 -07002091 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2092 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002093 struct hdd_context *hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07002094 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002095
2096 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
Yun Parkb4f591d2017-03-29 15:51:01 -07002097 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002098 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002099 __func__);
2100 return;
2101 }
2102
Yun Parkb4f591d2017-03-29 15:51:01 -07002103 hdd_ctx = hdd_ipa->hdd_ctx;
2104 hdd_ipa->uc_loaded = true;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002105
Yun Parkb4f591d2017-03-29 15:51:01 -07002106 /* Connect pipe */
2107 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2108 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2109 hdd_ipa_wdi_meter_notifier_cb,
2110 hdd_ctx->config->IpaDescSize,
2111 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2112 &hdd_ipa->tx_pipe_handle,
2113 &hdd_ipa->rx_pipe_handle);
2114 if (status) {
2115 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2116 "Failure to setup IPA pipes (status=%d)",
2117 status);
2118 return;
2119 }
2120
2121 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002122
2123 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002124 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002125 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002126 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002127 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002128 }
2129}
2130
2131/**
Yun Park637d6482016-10-05 10:51:33 -07002132 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2133 * @hdd_ctx: Global HDD context
2134 * @op_msg: operation message received from firmware
2135 *
2136 * Return: QDF_STATUS enumeration
2137 */
2138#ifdef FEATURE_METERING
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002139static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002140 struct op_msg_type *op_msg)
2141{
2142 struct op_msg_type *msg = op_msg;
2143 struct ipa_uc_sharing_stats *uc_sharing_stats;
2144 struct ipa_uc_quota_rsp *uc_quota_rsp;
2145 struct ipa_uc_quota_ind *uc_quota_ind;
2146 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002147 struct hdd_adapter *adapter;
Yun Park637d6482016-10-05 10:51:33 -07002148
2149 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2150
2151 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2152 /* fill-up ipa_uc_sharing_stats structure from FW */
2153 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2154 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2155
2156 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2157 sizeof(struct ipa_uc_sharing_stats));
2158
2159 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2160
2161 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2162 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2163 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2164 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2165 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2166 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2167 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2168 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2169 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2170 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2171 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2172 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2173 /* received set quota response */
2174 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2175 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2176
2177 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2178 sizeof(struct ipa_uc_quota_rsp));
2179
2180 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2181 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2182 "%s: success=%d, quota_bytes=%llu",
2183 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2184 hdd_ipa->ipa_quota_rsp.success,
2185 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2186 hdd_ipa->ipa_quota_rsp.quota_lo);
2187 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2188 /* hit quota limit */
2189 uc_quota_ind = (struct ipa_uc_quota_ind *)
2190 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2191
2192 hdd_ipa->ipa_quota_ind.quota_bytes =
2193 uc_quota_ind->quota_bytes;
2194
2195 /* send quota exceeded indication to IPA */
2196 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2197 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2198 hdd_ipa->ipa_quota_ind.quota_bytes);
2199
2200 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2201 if (adapter)
2202 ipa_broadcast_wdi_quota_reach_ind(
2203 adapter->dev->ifindex,
2204 uc_quota_ind->quota_bytes);
2205 else
2206 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2207 "Failed quota_reach_ind: NULL adapter");
2208 } else {
2209 return QDF_STATUS_E_INVAL;
2210 }
2211
2212 return QDF_STATUS_SUCCESS;
2213}
2214#else
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002215static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002216 struct op_msg_type *op_msg)
2217{
2218 return QDF_STATUS_E_INVAL;
2219}
2220#endif
2221
Yun Park657c7d72017-06-07 15:44:59 -07002222#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
2223/* older versions had a typo */
2224#define num_bam_int_in_non_running_state num_bam_int_in_non_runnning_state
2225#endif
2226
Yun Park637d6482016-10-05 10:51:33 -07002227/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002228 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2229 * @op_msg: operation message received from firmware
2230 * @usr_ctxt: user context registered with TL (we register the HDD Global
2231 * context)
2232 *
2233 * Return: None
2234 */
2235static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2236{
2237 struct op_msg_type *msg = op_msg;
2238 struct ipa_uc_fw_stats *uc_fw_stat;
2239 struct IpaHwStatsWDIInfoData_t ipa_stat;
2240 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002241 struct hdd_context *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302242 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002243
2244 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302245 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002246 return;
2247 }
2248
2249 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302250 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002251 "%s, INVALID OPCODE %d", __func__, msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002252 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002253 return;
2254 }
2255
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002256 hdd_ctx = (struct hdd_context *) usr_ctxt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002257
2258 /*
2259 * When SSR is going on or driver is unloading, just return.
2260 */
2261 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302262 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302263 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002264 return;
2265 }
2266
2267 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2268
Govind Singhb6a89772016-08-12 11:23:35 +05302269 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002270 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002271
2272 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2273 (HDD_IPA_UC_OPCODE_RX_RESUME == 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_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2277 hdd_ipa->resource_loading = false;
Yun Park777d7242017-03-30 15:38:33 -07002278 complete(&hdd_ipa->ipa_resource_comp);
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002279 if (hdd_ipa->wdi_enabled == false) {
2280 hdd_ipa->wdi_enabled = true;
2281 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2282 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2283 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002284 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002285 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002286 if (hdd_ipa->pending_cons_req)
2287 ipa_rm_notify_completion(
2288 IPA_RM_RESOURCE_GRANTED,
2289 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002290 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002291 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302292 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002293 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002294 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302295 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002296 hdd_ipa->activated_fw_pipe--;
2297 if (!hdd_ipa->activated_fw_pipe) {
Yun Park777d7242017-03-30 15:38:33 -07002298 /*
2299 * Async return success from FW
2300 * Disable/suspend all the PIPEs
2301 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002302 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002303 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2304 ipa_rm_release_resource(
2305 IPA_RM_RESOURCE_WLAN_PROD);
Yun Park5b635012015-12-02 15:05:01 -08002306 hdd_ipa->resource_unloading = false;
Yun Park777d7242017-03-30 15:38:33 -07002307 complete(&hdd_ipa->ipa_resource_comp);
Yun Park5b635012015-12-02 15:05:01 -08002308 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2309 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302311 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002312 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002313 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002314 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302315 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002316 "==== IPA_UC WLAN_HOST RX ====\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002317 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002318 "NUM TX FWD OK : %llu\n"
2319 "NUM TX FWD ERR : %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002320 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002321 hdd_ipa->stats.num_tx_fwd_ok,
2322 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302323 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002324 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2325 "SAP NUM STAs: %d\n"
2326 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002327 "CONCURRENT MODE: %s\n"
2328 "TX PIPE HDL: 0x%x\n"
2329 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002330 "RSC LOADING : %d\n"
2331 "RSC UNLOADING : %d\n"
2332 "PNDNG CNS RQT : %d",
2333 hdd_ipa->sap_num_connected_sta,
2334 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002335 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002336 hdd_ipa->tx_pipe_handle,
2337 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002338 hdd_ipa->resource_loading,
2339 hdd_ipa->resource_unloading,
2340 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002341
2342 /* STATs from FW */
2343 uc_fw_stat = (struct ipa_uc_fw_stats *)
2344 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302345 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002346 "==== IPA_UC WLAN_FW TX ====\n"
2347 "COMP RING BASE: 0x%x\n"
2348 "COMP RING SIZE: %d\n"
2349 "COMP RING DBELL : 0x%x\n"
2350 "COMP RING DBELL IND VAL : %d\n"
2351 "COMP RING DBELL CACHED VAL : %d\n"
2352 "COMP RING DBELL CACHED VAL : %d\n"
2353 "PKTS ENQ : %d\n"
2354 "PKTS COMP : %d\n"
2355 "IS SUSPEND : %d\n"
2356 "RSVD : 0x%x",
2357 uc_fw_stat->tx_comp_ring_base,
2358 uc_fw_stat->tx_comp_ring_size,
2359 uc_fw_stat->tx_comp_ring_dbell_addr,
2360 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2361 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2362 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2363 uc_fw_stat->tx_pkts_enqueued,
2364 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002365 uc_fw_stat->tx_is_suspend,
2366 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302367 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368 "==== IPA_UC WLAN_FW RX ====\n"
2369 "IND RING BASE: 0x%x\n"
2370 "IND RING SIZE: %d\n"
2371 "IND RING DBELL : 0x%x\n"
2372 "IND RING DBELL IND VAL : %d\n"
2373 "IND RING DBELL CACHED VAL : %d\n"
2374 "RDY IND ADDR : 0x%x\n"
2375 "RDY IND CACHE VAL : %d\n"
2376 "RFIL IND : %d\n"
2377 "NUM PKT INDICAT : %d\n"
2378 "BUF REFIL : %d\n"
2379 "NUM DROP NO SPC : %d\n"
2380 "NUM DROP NO BUF : %d\n"
2381 "IS SUSPND : %d\n"
2382 "RSVD : 0x%x\n",
2383 uc_fw_stat->rx_ind_ring_base,
2384 uc_fw_stat->rx_ind_ring_size,
2385 uc_fw_stat->rx_ind_ring_dbell_addr,
2386 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2387 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2388 uc_fw_stat->rx_ind_ring_rdidx_addr,
2389 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2390 uc_fw_stat->rx_refill_idx,
2391 uc_fw_stat->rx_num_pkts_indicated,
2392 uc_fw_stat->rx_buf_refilled,
2393 uc_fw_stat->rx_num_ind_drop_no_space,
2394 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002395 uc_fw_stat->rx_is_suspend,
2396 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002397 /* STATs from IPA */
2398 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302399 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002400 "==== IPA_UC IPA TX ====\n"
2401 "NUM PROCD : %d\n"
2402 "CE DBELL : 0x%x\n"
2403 "NUM DBELL FIRED : %d\n"
2404 "COMP RNG FULL : %d\n"
2405 "COMP RNG EMPT : %d\n"
2406 "COMP RNG USE HGH : %d\n"
2407 "COMP RNG USE LOW : %d\n"
2408 "BAM FIFO FULL : %d\n"
2409 "BAM FIFO EMPT : %d\n"
2410 "BAM FIFO USE HGH : %d\n"
2411 "BAM FIFO USE LOW : %d\n"
2412 "NUM DBELL : %d\n"
2413 "NUM UNEXP DBELL : %d\n"
2414 "NUM BAM INT HDL : 0x%x\n"
2415 "NUM BAM INT NON-RUN : 0x%x\n"
2416 "NUM QMB INT HDL : 0x%x",
2417 ipa_stat.tx_ch_stats.num_pkts_processed,
2418 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2419 ipa_stat.tx_ch_stats.num_db_fired,
2420 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2421 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2422 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2423 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2424 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2425 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2426 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2427 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2428 ipa_stat.tx_ch_stats.num_db,
2429 ipa_stat.tx_ch_stats.num_unexpected_db,
2430 ipa_stat.tx_ch_stats.num_bam_int_handled,
2431 ipa_stat.tx_ch_stats.
Yun Park657c7d72017-06-07 15:44:59 -07002432 num_bam_int_in_non_running_state,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002433 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2434
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302435 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002436 "==== IPA_UC IPA RX ====\n"
2437 "MAX OST PKT : %d\n"
2438 "NUM PKT PRCSD : %d\n"
2439 "RNG RP : 0x%x\n"
2440 "COMP RNG FULL : %d\n"
2441 "COMP RNG EMPT : %d\n"
2442 "COMP RNG USE HGH : %d\n"
2443 "COMP RNG USE LOW : %d\n"
2444 "BAM FIFO FULL : %d\n"
2445 "BAM FIFO EMPT : %d\n"
2446 "BAM FIFO USE HGH : %d\n"
2447 "BAM FIFO USE LOW : %d\n"
2448 "NUM DB : %d\n"
2449 "NUM UNEXP DB : %d\n"
2450 "NUM BAM INT HNDL : 0x%x\n",
2451 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2452 ipa_stat.rx_ch_stats.num_pkts_processed,
2453 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2454 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2455 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2456 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2457 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2458 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2459 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2460 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2461 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2462 ipa_stat.rx_ch_stats.num_db,
2463 ipa_stat.rx_ch_stats.num_unexpected_db,
2464 ipa_stat.rx_ch_stats.num_bam_int_handled);
2465 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2466 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2467 /* STATs from FW */
2468 uc_fw_stat = (struct ipa_uc_fw_stats *)
2469 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302470 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002471 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2472 uc_fw_stat->tx_pkts_completed,
2473 hdd_ipa->ipa_p_tx_packets);
2474 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2475 (uc_fw_stat->rx_num_ind_drop_no_space +
2476 uc_fw_stat->rx_num_ind_drop_no_buf +
2477 uc_fw_stat->rx_num_pkts_indicated),
2478 hdd_ipa->ipa_p_rx_packets);
2479
2480 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2481 hdd_ipa->ipa_p_rx_packets =
2482 (uc_fw_stat->rx_num_ind_drop_no_space +
2483 uc_fw_stat->rx_num_ind_drop_no_buf +
2484 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302485 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002486 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2487 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2488 hdd_ipa_uc_loaded_handler(hdd_ipa);
2489 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002490 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2491 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2492 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002493 }
Yun Park8957d802017-01-25 12:27:29 -08002494
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302495 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002496}
2497
2498
2499/**
2500 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2501 * @adapter: device adapter instance
2502 * @offload_type: MCC or SCC
2503 * @enable: TX offload enable or disable
2504 *
2505 * Return: none
2506 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002507static void hdd_ipa_uc_offload_enable_disable(struct hdd_adapter *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002508 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002509{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002510 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002511 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002512 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002513 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002514
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002515 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002516 return;
2517
Yun Park8292dcb2016-10-07 16:46:06 -07002518 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002519 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002520
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002521 if (!iface_context) {
2522 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2523 "Interface context is NULL");
2524 return;
2525 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002526 if (session_id >= CSR_ROAM_SESSION_MAX) {
2527 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2528 "invalid session id: %d", session_id);
2529 return;
2530 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002531 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002532 /* IPA offload status is already set as desired */
2533 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002534 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002535 "IPA offload status is already set",
2536 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002537 return;
2538 }
2539
Yun Park4540e862016-11-10 16:30:06 -08002540 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2541 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2542 "invalid session id: %d, offload_type=%d, enable=%d",
2543 adapter->sessionId, offload_type, enable);
2544 return;
2545 }
2546
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302547 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548 sizeof(ipa_offload_enable_disable));
2549 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002550 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002551 ipa_offload_enable_disable.enable = enable;
2552
Srinivas Girigowda97852372017-03-06 16:52:59 -08002553 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002554 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002555 ipa_offload_enable_disable.offload_type,
2556 ipa_offload_enable_disable.vdev_id,
2557 ipa_offload_enable_disable.enable);
2558
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302559 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002560 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2561 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302562 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002563 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
2564 "Failure to enable IPA offload",
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002565 ipa_offload_enable_disable.offload_type,
2566 ipa_offload_enable_disable.vdev_id,
2567 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002568 } else {
2569 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002570 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002571 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002572 }
2573}
2574
2575/**
2576 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2577 * @work: uC OP work
2578 *
2579 * Return: None
2580 */
2581static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2582{
2583 struct op_msg_type *msg;
2584 struct uc_op_work_struct *uc_op_work = container_of(work,
2585 struct uc_op_work_struct, work);
2586 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2587
2588 cds_ssr_protect(__func__);
2589
2590 msg = uc_op_work->msg;
2591 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002592 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593 "%s, posted msg %d", __func__, msg->op_code);
2594
2595 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2596
2597 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002598}
2599
2600/**
2601 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2602 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2603 * @op_msg: operation message received from firmware
2604 * @hdd_ctx: Global HDD context
2605 *
2606 * Return: None
2607 */
2608static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2609{
2610 struct hdd_ipa_priv *hdd_ipa;
2611 struct op_msg_type *msg;
2612 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302613 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614
2615 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302616 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002617 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002618
2619 msg = (struct op_msg_type *)op_msg;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002620 hdd_ipa = ((struct hdd_context *)hdd_ctx)->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002621
2622 if (unlikely(!hdd_ipa))
2623 goto end;
2624
2625 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002626 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2627 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002628 goto end;
2629 }
2630
2631 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2632 if (uc_op_work->msg)
2633 /* When the same uC OPCODE is already pended, just return */
2634 goto end;
2635
2636 uc_op_work->msg = msg;
2637 schedule_work(&uc_op_work->work);
2638 return;
2639
2640end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302641 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002642}
2643
2644/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002645 * hdd_ipa_init_uc_op_work - init ipa uc op work
2646 * @work: struct work_struct
2647 * @work_handler: work_handler
2648 *
2649 * Return: none
2650 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002651static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002652 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002653{
2654 INIT_WORK(work, work_handler);
2655}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002656
Yun Park637d6482016-10-05 10:51:33 -07002657#ifdef FEATURE_METERING
2658/**
2659 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2660 * IPA calls to get WLAN stats or set quota limit.
2661 * @priv: pointer to private data registered with IPA (we register a
2662 *» pointer to the global IPA context)
2663 * @evt: the IPA event which triggered the callback
2664 * @data: data associated with the event
2665 *
2666 * Return: None
2667 */
2668static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2669 void *data)
2670{
2671 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002672 struct hdd_adapter *adapter = NULL;
Yun Park637d6482016-10-05 10:51:33 -07002673 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2674 struct ipa_set_wifi_quota *ipa_set_quota;
2675 int ret = 0;
2676
2677 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2678 return;
2679
2680 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2681
2682 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2683
2684 switch (evt) {
2685 case IPA_GET_WDI_SAP_STATS:
2686 /* fill-up ipa_get_wdi_sap_stats structure after getting
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002687 * ipa_uc_fw_stats from FW
2688 */
Yun Park637d6482016-10-05 10:51:33 -07002689 wdi_sap_stats = data;
2690
2691 if (!adapter) {
2692 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2693 "IPA uC share stats failed - no adapter");
2694 wdi_sap_stats->stats_valid = 0;
2695 return;
2696 }
2697
2698 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
Yun Park637d6482016-10-05 10:51:33 -07002699 hdd_ipa_uc_sharing_stats_request(adapter,
2700 wdi_sap_stats->reset_stats);
2701 ret = wait_for_completion_timeout(
2702 &hdd_ipa->ipa_uc_sharing_stats_comp,
2703 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2704 if (!ret) {
2705 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2706 "IPA uC share stats request timed out");
2707 wdi_sap_stats->stats_valid = 0;
2708 } else {
2709 wdi_sap_stats->stats_valid = 1;
2710
2711 wdi_sap_stats->ipv4_rx_packets =
2712 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2713 wdi_sap_stats->ipv4_rx_bytes =
2714 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2715 wdi_sap_stats->ipv6_rx_packets =
2716 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2717 wdi_sap_stats->ipv6_rx_bytes =
2718 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2719 wdi_sap_stats->ipv4_tx_packets =
2720 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2721 wdi_sap_stats->ipv4_tx_bytes =
2722 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2723 wdi_sap_stats->ipv6_tx_packets =
2724 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2725 wdi_sap_stats->ipv6_tx_bytes =
2726 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2727 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2728 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2729 "IPA_GET_WDI_SAP_STATS",
2730 wdi_sap_stats->stats_valid,
2731 wdi_sap_stats->ipv4_rx_packets,
2732 wdi_sap_stats->ipv4_rx_bytes,
2733 wdi_sap_stats->ipv6_rx_packets,
2734 wdi_sap_stats->ipv6_rx_bytes,
2735 wdi_sap_stats->ipv4_tx_packets,
2736 wdi_sap_stats->ipv4_tx_bytes,
2737 wdi_sap_stats->ipv6_tx_packets,
2738 wdi_sap_stats->ipv6_tx_bytes);
2739 }
2740 break;
2741 case IPA_SET_WIFI_QUOTA:
2742 /* get ipa_set_wifi_quota structure from IPA and pass to FW
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002743 * through quota_exceeded field in ipa_uc_fw_stats
2744 */
Yun Park637d6482016-10-05 10:51:33 -07002745 ipa_set_quota = data;
2746
2747 if (!adapter) {
2748 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2749 "IPA uC set quota failed - no adapter");
2750 ipa_set_quota->set_valid = 0;
2751 return;
2752 }
2753
Yun Park777d7242017-03-30 15:38:33 -07002754 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
Yun Park637d6482016-10-05 10:51:33 -07002755 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2756 ipa_set_quota->quota_bytes);
2757
2758 ret = wait_for_completion_timeout(
2759 &hdd_ipa->ipa_uc_set_quota_comp,
2760 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2761 if (!ret) {
2762 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2763 "IPA uC set quota request timed out");
2764 ipa_set_quota->set_valid = 0;
2765 } else {
2766 ipa_set_quota->quota_bytes =
2767 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2768 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2769 ipa_set_quota->set_valid =
2770 hdd_ipa->ipa_quota_rsp.success;
2771 }
2772
2773 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2774 ipa_set_quota->quota_bytes,
2775 ipa_set_quota->set_valid);
2776 break;
2777 }
2778}
2779
2780/**
2781 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2782 * IPA calls to get WLAN stats or set quota limit.
2783 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07002784 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07002785 * @evt: the IPA event which triggered the callback
2786 * @data: data associated with the event
2787 *
2788 * Return: None
2789 */
2790static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2791 void *data)
2792{
2793 cds_ssr_protect(__func__);
2794 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2795 cds_ssr_unprotect(__func__);
2796}
2797
Yun Parkb4f591d2017-03-29 15:51:01 -07002798static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002799{
Yun Park637d6482016-10-05 10:51:33 -07002800 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2801 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2802}
2803#else
Yun Parkb4f591d2017-03-29 15:51:01 -07002804static void hdd_ipa_wdi_meter_notifier_cb(void)
2805{
2806}
2807
2808static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002809{
2810}
2811#endif
2812
Rajeev Kumar217f2172016-01-06 18:11:55 -08002813/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002814 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2815 * @hdd_ctx: Global HDD context
2816 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002817 * This function is called to update IPA pipe configuration with resources
2818 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2819 * (cds_enable)
2820 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302821 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002822 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002823QDF_STATUS hdd_ipa_uc_ol_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824{
Yun Parkb4f591d2017-03-29 15:51:01 -07002825 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002826 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002827 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07002828 uint8_t i;
2829 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002831 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2832 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002833
Yun Parkfec73dc2017-09-06 10:40:07 -07002834 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2835
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002836 /* Do only IPA Pipe specific configuration here. All one time
2837 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2838 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2839 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002840 if (!pdev || !soc) {
2841 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07002842 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002843 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002844 }
Yun Parkb4f591d2017-03-29 15:51:01 -07002845 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002846 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2847 "IPA UC resource alloc fail");
2848 return QDF_STATUS_E_FAILURE;
2849 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002850
Yun Parkb4f591d2017-03-29 15:51:01 -07002851 if (true == hdd_ipa->uc_loaded) {
2852 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2853 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2854 hdd_ipa_wdi_meter_notifier_cb,
2855 hdd_ctx->config->IpaDescSize,
2856 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2857 &hdd_ipa->tx_pipe_handle,
2858 &hdd_ipa->rx_pipe_handle);
2859 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08002860 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002861 "Failure to setup IPA pipes (status=%d)",
2862 status);
2863 return QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002864 }
Yun Park637d6482016-10-05 10:51:33 -07002865
Yun Parkb4f591d2017-03-29 15:51:01 -07002866 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
2867 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002868 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869
Yun Parkb4f591d2017-03-29 15:51:01 -07002870 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08002871 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2872
Yun Parkb4f591d2017-03-29 15:51:01 -07002873 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
2874 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
2875 hdd_ipa_uc_fw_op_event_handler);
2876 hdd_ipa->uc_op_work[i].msg = NULL;
2877 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002878
Yun Parkbaa62862017-01-18 13:43:34 -08002879fail_return:
Yun Parkfec73dc2017-09-06 10:40:07 -07002880 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: stat=%d", stat);
Yun Parkb4f591d2017-03-29 15:51:01 -07002881 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002882}
2883
Leo Change3e49442015-10-26 20:07:13 -07002884/**
Yun Parkd8fb1a82017-10-13 16:48:20 -07002885 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
2886 * @hdd_ipa: pointer to HDD IPA struct
2887 *
2888 * Return: none
2889 */
2890static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
2891{
2892 struct ipa_uc_pending_event *pending_event = NULL;
2893
2894 while (qdf_list_remove_front(&hdd_ipa->pending_event,
2895 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS)
2896 qdf_mem_free(pending_event);
2897}
2898
2899/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302900 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
2901 * @hdd_ctx: Global HDD context
2902 *
2903 * Return: 0 on success, negativer errno on error
2904 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002905int hdd_ipa_uc_ol_deinit(struct hdd_context *hdd_ctx)
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302906{
2907 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2908 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07002909 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302910
Yun Parkfec73dc2017-09-06 10:40:07 -07002911 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2912
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302913 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2914 return ret;
2915
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05302916 if (!hdd_ipa->ipa_pipes_down)
2917 hdd_ipa_uc_disable_pipes(hdd_ipa);
2918
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302919 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002920 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
2921 hdd_ipa->tx_pipe_handle,
2922 hdd_ipa->rx_pipe_handle);
2923 if (status) {
2924 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2925 "Failure to cleanup IPA pipes (status=%d)",
2926 status);
2927 return -EFAULT;
2928 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302929 }
2930
Yun Parkd8fb1a82017-10-13 16:48:20 -07002931 hdd_ipa_cleanup_pending_event(hdd_ipa);
2932
Yun Parkfec73dc2017-09-06 10:40:07 -07002933 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: ret=%d", ret);
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302934 return ret;
2935}
2936
2937/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002938 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002939 * @hdd_ctx: hdd main context
2940 *
2941 * Force shutdown IPA pipe
2942 * Independent of FW pipe status, IPA pipe shutdonw progress
2943 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2944 * independent from FW pipe status
2945 *
2946 * Return: NONE
2947 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002948static void __hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002949{
2950 struct hdd_ipa_priv *hdd_ipa;
2951
Yun Parkfec73dc2017-09-06 10:40:07 -07002952 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2953
Leo Change3e49442015-10-26 20:07:13 -07002954 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2955 return;
2956
2957 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2958 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302959 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002960 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07002961 hdd_ipa_uc_disable_pipes(hdd_ipa);
2962 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002963 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07002964 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07002965 }
Yun Parkfec73dc2017-09-06 10:40:07 -07002966
2967 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Leo Change3e49442015-10-26 20:07:13 -07002968}
2969
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002970/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002971 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2972 * __hdd_ipa_uc_force_pipe_shutdown
2973 * @hdd_ctx: hdd main context
2974 *
2975 * Force shutdown IPA pipe
2976 * Independent of FW pipe status, IPA pipe shutdonw progress
2977 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2978 * independent from FW pipe status
2979 *
2980 * Return: NONE
2981 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002982void hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002983{
2984 cds_ssr_protect(__func__);
2985 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2986 cds_ssr_unprotect(__func__);
2987}
2988
2989/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302990 * hdd_ipa_msg_free_fn() - Free an IPA message
2991 * @buff: pointer to the IPA message
2992 * @len: length of the IPA message
2993 * @type: type of IPA message
2994 *
2995 * Return: None
2996 */
2997static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2998{
Srinivas Girigowda97852372017-03-06 16:52:59 -08002999 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05303000 ghdd_ipa->stats.num_free_msg++;
3001 qdf_mem_free(buff);
3002}
3003
Govind Singh9c58eba2016-09-02 16:23:06 +05303004/**
jge62037862016-12-09 10:44:33 +08003005 * hdd_ipa_uc_send_evt() - send event to ipa
3006 * @hdd_ctx: pointer to hdd context
3007 * @type: event type
3008 * @mac_addr: pointer to mac address
3009 *
3010 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303011 *
3012 * Return: 0 - Success
3013 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003014static int hdd_ipa_uc_send_evt(struct hdd_adapter *adapter,
jge62037862016-12-09 10:44:33 +08003015 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303016{
jge62037862016-12-09 10:44:33 +08003017 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05303018 struct ipa_msg_meta meta;
3019 struct ipa_wlan_msg *msg;
3020 int ret = 0;
jge62037862016-12-09 10:44:33 +08003021
3022 meta.msg_len = sizeof(struct ipa_wlan_msg);
3023 msg = qdf_mem_malloc(meta.msg_len);
3024 if (msg == NULL) {
3025 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3026 "msg allocation failed");
3027 return -ENOMEM;
3028 }
3029
3030 meta.msg_type = type;
3031 strlcpy(msg->name, adapter->dev->name,
3032 IPA_RESOURCE_NAME_MAX);
3033 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Yun Parkfec73dc2017-09-06 10:40:07 -07003034 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08003035 msg->name, meta.msg_type);
3036 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3037 if (ret) {
3038 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3039 "%s: Evt: %d fail:%d",
3040 msg->name, meta.msg_type, ret);
3041 qdf_mem_free(msg);
3042 return ret;
3043 }
3044
3045 hdd_ipa->stats.num_send_msg++;
3046
3047 return ret;
3048}
3049
3050/**
3051 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3052 * @hdd_ctx: pointer to hdd adapter
3053 *
3054 * Send disconnect client event to IPA driver during SSR
3055 *
3056 * Return: 0 - Success
3057 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003058static int hdd_ipa_uc_disconnect_client(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003059{
3060 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3061 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303062 int i;
3063
Yun Parkfec73dc2017-09-06 10:40:07 -07003064 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Govind Singh9c58eba2016-09-02 16:23:06 +05303065 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3066 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3067 continue;
3068 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003069 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3070 hdd_ipa->sap_num_connected_sta) {
3071 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3072 adapter->aStaInfo[i].macAddrSTA.bytes);
3073 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303074 }
3075 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003076 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: sap_num_connected_sta=%d",
3077 hdd_ipa->sap_num_connected_sta);
Govind Singh9c58eba2016-09-02 16:23:06 +05303078
3079 return ret;
3080}
3081
3082/**
jge62037862016-12-09 10:44:33 +08003083 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3084 * @hdd_ctx: pointer to hdd adapter
3085 *
3086 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303087 *
3088 * Return: 0 - Success
3089 */
jge62037862016-12-09 10:44:33 +08003090
Jeff Johnson49d45e62017-08-29 14:30:42 -07003091static int hdd_ipa_uc_disconnect_ap(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003092{
3093 int ret = 0;
3094
Yun Parkfec73dc2017-09-06 10:40:07 -07003095 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3096 if (adapter->ipa_context) {
jge62037862016-12-09 10:44:33 +08003097 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3098 adapter->dev->dev_addr);
Yun Parkfec73dc2017-09-06 10:40:07 -07003099 }
3100 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
jge62037862016-12-09 10:44:33 +08003101
3102 return ret;
3103}
3104
jge62037862016-12-09 10:44:33 +08003105/**
3106 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3107 * @hdd_ctx: pointer to hdd adapter
3108 *
3109 * Send disconnect sta event to IPA driver during SSR
3110 *
3111 * Return: 0 - Success
3112 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003113static int hdd_ipa_uc_disconnect_sta(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003114{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003115 struct hdd_station_ctx *sta_ctx;
jge62037862016-12-09 10:44:33 +08003116 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3117 int ret = 0;
3118
Yun Parkfec73dc2017-09-06 10:40:07 -07003119 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003120 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003121 hdd_ipa->sta_connected) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07003122 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
jge62037862016-12-09 10:44:33 +08003123 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Jeff Johnsond377dce2017-10-04 10:32:42 -07003124 sta_ctx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003125 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003126 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
jge62037862016-12-09 10:44:33 +08003127
3128 return ret;
3129}
jge62037862016-12-09 10:44:33 +08003130
3131/**
3132 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3133 * @hdd_ctx: pointer to hdd context
3134 *
3135 * Send disconnect event to IPA driver during SSR
3136 *
3137 * Return: 0 - Success
3138 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003139static int hdd_ipa_uc_disconnect(struct hdd_context *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303140{
3141 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3142 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003143 struct hdd_adapter *adapter;
Govind Singh9c58eba2016-09-02 16:23:06 +05303144 int ret = 0;
3145
Govind Singh9c58eba2016-09-02 16:23:06 +05303146 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3147 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003148 adapter = adapter_node->adapter;
jge62037862016-12-09 10:44:33 +08003149 if (adapter->device_mode == QDF_SAP_MODE) {
3150 hdd_ipa_uc_disconnect_client(adapter);
3151 hdd_ipa_uc_disconnect_ap(adapter);
3152 } else if (adapter->device_mode == QDF_STA_MODE) {
3153 hdd_ipa_uc_disconnect_sta(adapter);
3154 }
3155
Govind Singh9c58eba2016-09-02 16:23:06 +05303156 status = hdd_get_next_adapter(
3157 hdd_ctx, adapter_node, &next);
3158 adapter_node = next;
3159 }
3160
3161 return ret;
3162}
3163
3164/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003165 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166 *
3167 * Deinit basic IPA UC host side to be in sync reloaded FW during
3168 * SSR
3169 *
3170 * Return: 0 - Success
3171 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003172static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173{
3174 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3175 int idx;
3176 struct hdd_ipa_iface_context *iface_context;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003177 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178
Yun Parkfec73dc2017-09-06 10:40:07 -07003179 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3180
Arun Khandavallicc544b32017-01-30 19:52:16 +05303181 if (!hdd_ipa)
3182 return 0;
3183
3184 hdd_ctx = hdd_ipa->hdd_ctx;
3185 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 return 0;
3187
jge62037862016-12-09 10:44:33 +08003188 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303189 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003190
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003191 /* Clean up HDD IPA interfaces */
3192 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3193 (idx < HDD_IPA_MAX_IFACE); idx++) {
3194 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003195 if (iface_context->adapter && iface_context->adapter->magic ==
3196 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197 hdd_ipa_cleanup_iface(iface_context);
3198 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003199 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003200 /* After SSR, wlan driver reloads FW again. But we need to protect
3201 * IPA submodule during SSR transient state. So deinit basic IPA
3202 * UC host side to be in sync with reloaded FW during SSR
3203 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003204
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303205 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3207 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3208 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3209 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303210 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211
Guolei Bianca144d82016-11-10 11:07:42 +08003212 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3213 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3214
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003215 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3216 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3217 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3218 hdd_ipa->uc_op_work[idx].msg = NULL;
3219 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003220
3221 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003222 return 0;
3223}
3224
3225/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003226 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3227 *
3228 * Deinit basic IPA UC host side to be in sync reloaded FW during
3229 * SSR
3230 *
3231 * Return: 0 - Success
3232 */
3233int hdd_ipa_uc_ssr_deinit(void)
3234{
3235 int ret;
3236
3237 cds_ssr_protect(__func__);
3238 ret = __hdd_ipa_uc_ssr_deinit();
3239 cds_ssr_unprotect(__func__);
3240
3241 return ret;
3242}
3243
3244/**
3245 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003246 *
3247 * Init basic IPA UC host side to be in sync with reloaded FW after
3248 * SSR to resume IPA UC operations
3249 *
3250 * Return: 0 - Success
3251 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003252static int __hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003254
Arun Khandavallicc544b32017-01-30 19:52:16 +05303255 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3256 int i;
3257 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303258
Yun Parkfec73dc2017-09-06 10:40:07 -07003259 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3260
Arun Khandavallicc544b32017-01-30 19:52:16 +05303261 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3262 return 0;
3263
Arun Khandavallicc544b32017-01-30 19:52:16 +05303264 /* Create the interface context */
3265 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3266 iface_context = &hdd_ipa->iface_context[i];
3267 iface_context->hdd_ipa = hdd_ipa;
3268 iface_context->cons_client =
3269 hdd_ipa_adapter_2_client[i].cons_client;
3270 iface_context->prod_client =
3271 hdd_ipa_adapter_2_client[i].prod_client;
3272 iface_context->iface_id = i;
3273 iface_context->adapter = NULL;
3274 }
3275 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3276 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3277 hdd_ipa->vdev_offload_enabled[i] = false;
3278 }
3279
3280 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3281 hdd_ipa->resource_loading = false;
3282 hdd_ipa->resource_unloading = false;
3283 hdd_ipa->sta_connected = 0;
3284 hdd_ipa->ipa_pipes_down = true;
3285 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303286 }
3287
Yun Parkfec73dc2017-09-06 10:40:07 -07003288 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003289 return 0;
3290}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003291
3292/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003293 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3294 *
3295 * Init basic IPA UC host side to be in sync with reloaded FW after
3296 * SSR to resume IPA UC operations
3297 *
3298 * Return: 0 - Success
3299 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003300int hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003301{
3302 int ret;
3303
3304 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303305 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003306 cds_ssr_unprotect(__func__);
3307
3308 return ret;
3309}
3310
3311/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3313 * @work: scheduled work
3314 *
3315 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3316 * not want to immediately release the wake lock since the system
3317 * would then potentially try to suspend when there is a healthy data
3318 * rate. Deferred work is scheduled and this function handles the
3319 * work. When this function is called, if the IPA resource is still
3320 * released then we release the wake lock.
3321 *
3322 * Return: None
3323 */
3324static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3325{
3326 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3327 struct hdd_ipa_priv,
3328 wake_lock_work);
3329
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303330 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003331
3332 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3333 goto end;
3334
3335 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303336 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337 WIFI_POWER_EVENT_WAKELOCK_IPA);
3338
3339end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303340 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341}
3342
3343/**
3344 * hdd_ipa_rm_request() - Request resource from IPA
3345 * @hdd_ipa: Global HDD IPA context
3346 *
3347 * Return: 0 on success, negative errno on error
3348 */
3349static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3350{
3351 int ret = 0;
3352
3353 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3354 return 0;
3355
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303356 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003357
3358 switch (hdd_ipa->rm_state) {
3359 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303360 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 return 0;
3362 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303363 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 return -EINPROGRESS;
3365 case HDD_IPA_RM_RELEASED:
3366 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3367 break;
3368 }
3369
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303370 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371
3372 ret = ipa_rm_inactivity_timer_request_resource(
3373 IPA_RM_RESOURCE_WLAN_PROD);
3374
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 (ret == 0) {
3377 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3378 hdd_ipa->stats.num_rm_grant_imm++;
3379 }
3380
3381 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3382 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303383 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003384 WIFI_POWER_EVENT_WAKELOCK_IPA);
3385 hdd_ipa->wake_lock_released = false;
3386 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303387 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003388
3389 return ret;
3390}
3391
3392/**
3393 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3394 * @hdd_ipa: Global HDD IPA context
3395 *
3396 * Return: 0 if resources released, negative errno otherwise
3397 */
3398static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3399{
3400 int ret = 0;
3401
3402 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3403 return 0;
3404
3405 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3406 return -EAGAIN;
3407
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303408 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409
Nirav Shahcbc6d722016-03-01 16:24:53 +05303410 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303411 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 return -EAGAIN;
3413 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303414 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003415
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303416 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417 switch (hdd_ipa->rm_state) {
3418 case HDD_IPA_RM_GRANTED:
3419 break;
3420 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303421 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003422 return -EINPROGRESS;
3423 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303424 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003425 return 0;
3426 }
3427
3428 /* IPA driver returns immediately so set the state here to avoid any
3429 * race condition.
3430 */
3431 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3432 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303433 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003435 ret = ipa_rm_inactivity_timer_release_resource(
3436 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303438 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003439 if (unlikely(ret != 0)) {
3440 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3441 WARN_ON(1);
3442 }
3443
3444 /*
3445 * If wake_lock is released immediately, kernel would try to suspend
3446 * immediately as well, Just avoid ping-pong between suspend-resume
3447 * while there is healthy amount of data transfer going on by
3448 * releasing the wake_lock after some delay.
3449 */
3450 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3451 msecs_to_jiffies
3452 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3453
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303454 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455
3456 return ret;
3457}
3458
3459/**
3460 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3461 * @user_data: user data registered with IPA
3462 * @event: the IPA resource manager event that occurred
3463 * @data: the data associated with the event
3464 *
3465 * Return: None
3466 */
3467static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3468 unsigned long data)
3469{
3470 struct hdd_ipa_priv *hdd_ipa = user_data;
3471
3472 if (unlikely(!hdd_ipa))
3473 return;
3474
3475 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3476 return;
3477
Srinivas Girigowda97852372017-03-06 16:52:59 -08003478 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479
3480 switch (event) {
3481 case IPA_RM_RESOURCE_GRANTED:
3482 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3483 /* RM Notification comes with ISR context
3484 * it should be serialized into work queue to avoid
3485 * ISR sleep problem
3486 */
3487 hdd_ipa->uc_rm_work.event = event;
3488 schedule_work(&hdd_ipa->uc_rm_work.work);
3489 break;
3490 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303491 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303493 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494 hdd_ipa->stats.num_rm_grant++;
3495 break;
3496
3497 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003498 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 hdd_ipa->resource_unloading = false;
3500 break;
3501
3502 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303503 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003504 break;
3505 }
3506}
3507
3508/**
3509 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3510 *
3511 * Callback function registered with IPA that is called when IPA wants
3512 * to release the WLAN consumer resource
3513 *
3514 * Return: 0 if the request is granted, negative errno otherwise
3515 */
3516static int hdd_ipa_rm_cons_release(void)
3517{
3518 return 0;
3519}
3520
3521/**
3522 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3523 *
3524 * Callback function registered with IPA that is called when IPA wants
3525 * to access the WLAN consumer resource
3526 *
3527 * Return: 0 if the request is granted, negative errno otherwise
3528 */
3529static int hdd_ipa_rm_cons_request(void)
3530{
Yun Park4d8b60a2015-10-22 13:59:32 -07003531 int ret = 0;
3532
3533 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303534 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003535 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003537 ret = -EINPROGRESS;
3538 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303539 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003540 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003541 ghdd_ipa->pending_cons_req = true;
3542 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003544
3545 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546}
3547
3548/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003549 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003550 * @hdd_ctx: Global HDD context
3551 * @tx_packets: Number of packets transmitted in the last sample period
3552 * @rx_packets: Number of packets received in the last sample period
3553 *
3554 * Return: 0 on success, negative errno on error
3555 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07003556static int __hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx,
3557 uint64_t tx_packets,
3558 uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559{
3560 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003561 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003563 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003564 int ret;
3565
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003566 if (wlan_hdd_validate_context(hdd_ctx))
3567 return 0;
3568
3569 hdd_ipa = hdd_ctx->hdd_ipa;
3570
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003571 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3572 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3573 return 0;
3574
3575 memset(&profile, 0, sizeof(profile));
3576
3577 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3578 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3579 else if (tx_packets >
3580 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3581 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3582 else
3583 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3584
3585 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3586 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3587 else if (rx_packets >
3588 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3589 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3590 else
3591 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3592
Yun Parkec845302016-12-15 09:22:57 -08003593 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 "CONS perf curr: %d, next: %d",
3595 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003596 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597 "PROD perf curr: %d, next: %d",
3598 hdd_ipa->curr_prod_bw, next_prod_bw);
3599
3600 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003601 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003603 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3604 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003606 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003607
3608 return ret;
3609 }
3610 hdd_ipa->curr_cons_bw = next_cons_bw;
3611 hdd_ipa->stats.num_cons_perf_req++;
3612 }
3613
3614 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003615 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003617 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3618 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003619 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003620 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003621 return ret;
3622 }
3623 hdd_ipa->curr_prod_bw = next_prod_bw;
3624 hdd_ipa->stats.num_prod_perf_req++;
3625 }
3626
3627 return 0;
3628}
3629
3630/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003631 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3632 * @hdd_ctx: Global HDD context
3633 * @tx_packets: Number of packets transmitted in the last sample period
3634 * @rx_packets: Number of packets received in the last sample period
3635 *
3636 * Return: 0 on success, negative errno on error
3637 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003638int hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003639 uint64_t rx_packets)
3640{
3641 int ret;
3642
3643 cds_ssr_protect(__func__);
3644 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3645 cds_ssr_unprotect(__func__);
3646
3647 return ret;
3648}
3649
3650/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003651 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3652 * @work: struct work_struct
3653 * @work_handler: work_handler
3654 *
3655 * Return: none
3656 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003657static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3658 work_func_t work_handler)
3659{
3660 INIT_WORK(work, work_handler);
3661}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003662
3663/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003664 * hdd_ipa_setup_rm() - Setup IPA resource management
3665 * @hdd_ipa: Global HDD IPA context
3666 *
3667 * Return: 0 on success, negative errno on error
3668 */
3669static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3670{
3671 struct ipa_rm_create_params create_params = { 0 };
3672 int ret;
3673
3674 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3675 return 0;
3676
Rajeev Kumar217f2172016-01-06 18:11:55 -08003677 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3678 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 memset(&create_params, 0, sizeof(create_params));
3680 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3681 create_params.reg_params.user_data = hdd_ipa;
3682 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3683 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3684
3685 ret = ipa_rm_create_resource(&create_params);
3686 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303687 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003688 "Create RM resource failed: %d", ret);
3689 goto setup_rm_fail;
3690 }
3691
3692 memset(&create_params, 0, sizeof(create_params));
3693 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3694 create_params.request_resource = hdd_ipa_rm_cons_request;
3695 create_params.release_resource = hdd_ipa_rm_cons_release;
3696 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3697
3698 ret = ipa_rm_create_resource(&create_params);
3699 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303700 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701 "Create RM CONS resource failed: %d", ret);
3702 goto delete_prod;
3703 }
3704
3705 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3706 IPA_RM_RESOURCE_APPS_CONS);
3707
3708 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3709 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3710 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303711 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003712 ret);
3713 goto timer_init_failed;
3714 }
3715
3716 /* Set the lowest bandwidth to start with */
3717 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3718
3719 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303720 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721 "Set perf level failed: %d", ret);
3722 goto set_perf_failed;
3723 }
3724
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303725 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3727 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303728 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003729 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3730 hdd_ipa->wake_lock_released = true;
3731 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3732
3733 return ret;
3734
3735set_perf_failed:
3736 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3737
3738timer_init_failed:
3739 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3740
3741delete_prod:
3742 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3743
3744setup_rm_fail:
3745 return ret;
3746}
3747
3748/**
3749 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3750 * @hdd_ipa: Global HDD IPA context
3751 *
3752 * Destroys all resources associated with the IPA resource manager
3753 *
3754 * Return: None
3755 */
3756static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3757{
3758 int ret;
3759
3760 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3761 return;
3762
3763 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303764 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003766 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303767 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003768
3769 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3770
3771 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3772 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303773 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003774 "RM PROD resource delete failed %d", ret);
3775
3776 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3777 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303778 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003779 "RM CONS resource delete failed %d", ret);
3780}
3781
tfyu0380a972017-07-13 18:19:37 +08003782#ifdef QCA_CONFIG_SMP
3783static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3784{
3785 return netif_rx_ni(skb);
3786}
3787#else
3788static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3789{
3790 struct iphdr *ip_h;
3791 static atomic_t softirq_mitigation_cntr =
3792 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
3793 int result;
3794
3795 ip_h = (struct iphdr *)(skb->data);
3796 if ((skb->protocol == htons(ETH_P_IP)) &&
3797 (ip_h->protocol == IPPROTO_ICMP)) {
3798 result = netif_rx_ni(skb);
3799 } else {
3800 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
3801 * to avoid excessive softirq's.
3802 */
3803 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
3804 result = netif_rx_ni(skb);
3805 atomic_set(&softirq_mitigation_cntr,
3806 IPA_WLAN_RX_SOFTIRQ_THRESH);
3807 } else {
3808 result = netif_rx(skb);
3809 }
3810 }
3811
3812 return result;
3813}
3814#endif
3815
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816/**
3817 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3818 * @skb: network buffer
3819 * @adapter: network adapter
3820 *
3821 * Called when a network buffer is received which should not be routed
3822 * to the IPA module.
3823 *
3824 * Return: None
3825 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303826static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003827 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003828{
tfyu0380a972017-07-13 18:19:37 +08003829 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3831 unsigned int cpu_index;
3832
3833 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07003834 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003835 adapter);
3836 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003837 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003838 return;
3839 }
3840
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003841 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003842 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003843 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003844 return;
3845 }
3846
3847 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3848 skb->dev = adapter->dev;
3849 skb->protocol = eth_type_trans(skb, skb->dev);
3850 skb->ip_summed = CHECKSUM_NONE;
3851
3852 cpu_index = wlan_hdd_get_cpu();
3853
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003854 ++adapter->hdd_stats.tx_rx_stats.rx_packets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08003855 result = hdd_ipa_aggregated_rx_ind(skb);
3856 if (result == NET_RX_SUCCESS)
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003857 ++adapter->hdd_stats.tx_rx_stats.rx_delivered[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003858 else
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003859 ++adapter->hdd_stats.tx_rx_stats.rx_refused[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003860
3861 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862}
3863
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003864/**
Leo Chang69c39692016-10-12 20:11:12 -07003865 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3866 * @hdd_ipa: pointer to hdd ipa context
3867 * @adapter: network adapter
3868 * @skb: data pointer
3869 *
3870 * if exception packet has set forward bit, copied new packet should be
3871 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3872 * put into pm queue and tx procedure will be differed
3873 *
3874 * Return: None
3875 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003876static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003877 struct hdd_adapter *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003878{
Leo Chang69c39692016-10-12 20:11:12 -07003879 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3880
Leo Chang69c39692016-10-12 20:11:12 -07003881 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Yun Park01deb2c2017-06-14 15:21:44 -07003882
3883 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
3884 qdf_nbuf_ipa_owned_set(skb);
3885
Leo Chang69c39692016-10-12 20:11:12 -07003886 /* WLAN subsystem is in suspend, put int queue */
3887 if (hdd_ipa->suspended) {
3888 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3889 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3890 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003891 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3892 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003893 pm_tx_cb->exception = true;
3894 pm_tx_cb->adapter = adapter;
3895 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003896 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003897 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3898 hdd_ipa->stats.num_tx_queued++;
3899 } else {
3900 /* Resume, put packet into WLAN TX */
3901 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003902 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003903 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3904 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003905 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003906 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003907 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003908 hdd_ipa->ipa_tx_forward++;
3909 }
3910 }
3911}
3912
3913/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003914 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3915 * @hdd_ipa: pointer to HDD IPA struct
3916 * @adapter: hdd adapter pointer
3917 * @desc: Firmware descriptor
3918 * @skb: Data buffer
3919 *
3920 * Return:
3921 * HDD_IPA_FORWARD_PKT_NONE
3922 * HDD_IPA_FORWARD_PKT_DISCARD
3923 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3924 *
3925 */
3926
3927static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3928 struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003929 struct hdd_adapter *adapter,
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003930 uint8_t desc,
3931 qdf_nbuf_t skb)
3932{
3933 int ret = HDD_IPA_FORWARD_PKT_NONE;
3934
3935 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303936 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003937 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
3938 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303939 /* Drop the packet*/
3940 hdd_ipa->stats.num_tx_fwd_err++;
3941 kfree_skb(skb);
3942 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3943 return ret;
3944 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003945 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3946 "Forward packet to Tx (fw_desc=%d)", desc);
3947 hdd_ipa->ipa_tx_forward++;
3948
3949 if ((desc & FW_RX_DESC_DISCARD_M)) {
3950 hdd_ipa_forward(hdd_ipa, adapter, skb);
3951 hdd_ipa->ipa_rx_internel_drop_count++;
3952 hdd_ipa->ipa_rx_discard++;
3953 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3954 } else {
3955 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003956
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003957 if (cloned_skb)
3958 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3959 else
3960 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3961 "%s: tx skb alloc failed",
3962 __func__);
3963 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3964 }
3965 }
3966
3967 return ret;
3968}
3969
3970/**
Yun Park637d6482016-10-05 10:51:33 -07003971 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 * @priv: pointer to private data registered with IPA (we register a
3973 * pointer to the global IPA context)
3974 * @evt: the IPA event which triggered the callback
3975 * @data: data associated with the event
3976 *
3977 * Return: None
3978 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003979static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 unsigned long data)
3981{
3982 struct hdd_ipa_priv *hdd_ipa = NULL;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003983 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303984 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 uint8_t iface_id;
3986 uint8_t session_id;
3987 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003989 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990
3991 hdd_ipa = (struct hdd_ipa_priv *)priv;
3992
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003993 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3994 return;
3995
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 switch (evt) {
3997 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303998 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003999
4000 /*
4001 * When SSR is going on or driver is unloading,
4002 * just drop the packets.
4003 */
4004 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4005 if (0 != status) {
4006 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4007 "Invalid context: drop packet");
4008 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4009 kfree_skb(skb);
4010 return;
4011 }
4012
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4014 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004015 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004016 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4018 session_id, iface_id);
4019 } else {
4020 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4021 }
4022
4023 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304024 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 "IPA_RECEIVE: Invalid iface_id: %u",
4026 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004027 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004028 "w2i -- skb",
4029 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004031 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 return;
4033 }
4034
4035 iface_context = &hdd_ipa->iface_context[iface_id];
4036 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004037 if (!adapter) {
4038 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4039 "IPA_RECEIVE: Adapter is NULL");
4040 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4041 kfree_skb(skb);
4042 return;
4043 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304045 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004046 "w2i -- skb",
4047 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4049 hdd_ipa->stats.num_rx_excep++;
4050 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4051 } else {
4052 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4053 }
4054
4055 iface_context->stats.num_rx_ipa_excep++;
4056
4057 /* Disable to forward Intra-BSS Rx packets when
4058 * ap_isolate=1 in hostapd.conf
4059 */
Yun Park046101c2016-09-02 15:32:14 -07004060 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 /*
4062 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4063 * all Rx packets to IPA uC, which need to be forwarded
4064 * to other interface.
4065 * And, IPA driver will send back to WLAN host driver
4066 * through exception pipe with fw_desc field set by FW.
4067 * Here we are checking fw_desc field for FORWARD bit
4068 * set, and forward to Tx. Then copy to kernel stack
4069 * only when DISCARD bit is not set.
4070 */
4071 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004072 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4073 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4074 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004075 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004077 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 "Intra-BSS FWD is disabled-skip forward to Tx");
4079 }
4080
4081 hdd_ipa_send_skb_to_network(skb, adapter);
4082 break;
4083
4084 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304085 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086 "w2i cb wrong event: 0x%x", evt);
4087 return;
4088 }
4089}
4090
4091/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004092 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4093 * @priv: pointer to private data registered with IPA (we register a
4094 * pointer to the global IPA context)
4095 * @evt: the IPA event which triggered the callback
4096 * @data: data associated with the event
4097 *
4098 * Return: None
4099 */
4100static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4101 unsigned long data)
4102{
4103 cds_ssr_protect(__func__);
4104 __hdd_ipa_w2i_cb(priv, evt, data);
4105 cds_ssr_unprotect(__func__);
4106}
4107
4108/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4110 * @skb: packet buffer which was transmitted
4111 *
4112 * Return: None
4113 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304114void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115{
4116 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004117 struct ipa_rx_data *ipa_tx_desc;
4118 struct hdd_ipa_tx_desc *tx_desc;
4119 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004120
Yun Park52b2b992016-09-22 15:49:51 -07004121 if (!qdf_nbuf_ipa_owned_get(skb)) {
4122 dev_kfree_skb_any(skb);
4123 return;
4124 }
4125
4126 /* Get Tx desc pointer from SKB CB */
4127 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4128 tx_desc = hdd_ipa->tx_desc_list + id;
4129 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4130
4131 /* Return Tx Desc to IPA */
4132 ipa_free_skb(ipa_tx_desc);
4133
4134 /* Return to free tx desc list */
4135 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4136 tx_desc->ipa_tx_desc_ptr = NULL;
4137 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4138 hdd_ipa->stats.num_tx_desc_q_cnt--;
4139 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004140
4141 hdd_ipa->stats.num_tx_comp_cnt++;
4142
4143 atomic_dec(&hdd_ipa->tx_ref_cnt);
4144
4145 hdd_ipa_rm_try_release(hdd_ipa);
4146}
4147
4148/**
4149 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4150 * @iface_context: interface-specific IPA context
4151 * @ipa_tx_desc: packet data descriptor
4152 *
4153 * Return: None
4154 */
4155static void hdd_ipa_send_pkt_to_tl(
4156 struct hdd_ipa_iface_context *iface_context,
4157 struct ipa_rx_data *ipa_tx_desc)
4158{
4159 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004160 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304161 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004162 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304164 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165 adapter = iface_context->adapter;
4166 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304167 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 ipa_free_skb(ipa_tx_desc);
4169 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304170 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171 hdd_ipa_rm_try_release(hdd_ipa);
4172 return;
4173 }
4174
4175 /*
4176 * During CAC period, data packets shouldn't be sent over the air so
4177 * drop all the packets here
4178 */
hqu70708ab2017-10-10 17:52:01 +08004179 if (QDF_SAP_MODE == adapter->device_mode ||
4180 QDF_P2P_GO_MODE == adapter->device_mode) {
4181 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4182 ipa_free_skb(ipa_tx_desc);
4183 qdf_spin_unlock_bh(&iface_context->interface_lock);
4184 iface_context->stats.num_tx_cac_drop++;
4185 hdd_ipa_rm_try_release(hdd_ipa);
4186 return;
4187 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 }
4189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 ++adapter->stats.tx_packets;
4191
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304192 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193
4194 skb = ipa_tx_desc->skb;
4195
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304196 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004197
4198 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304199 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304201 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004202 ipa_tx_desc->dma_addr
4203 + HDD_IPA_WLAN_FRAG_HEADER
4204 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 ipa_tx_desc->skb->len -=
4206 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4207 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304208 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004209
Yun Park52b2b992016-09-22 15:49:51 -07004210 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4211 /* get free Tx desc and assign ipa_tx_desc pointer */
4212 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4213 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4214 struct hdd_ipa_tx_desc, link);
4215 list_del(&tx_desc->link);
4216 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4217 hdd_ipa->stats.num_tx_desc_q_cnt++;
4218 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4219 /* Store Tx Desc index into SKB CB */
4220 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4221 } else {
4222 hdd_ipa->stats.num_tx_desc_error++;
4223 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4224 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4225 ipa_free_skb(ipa_tx_desc);
4226 hdd_ipa_rm_try_release(hdd_ipa);
4227 return;
4228 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004229
4230 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4231
Leo Changfdb45c32016-10-28 11:09:23 -07004232 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004233 (struct cdp_vdev *)iface_context->tl_context,
4234 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304236 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
jiad05c1e812017-08-01 16:48:52 +08004237 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 return;
4240 }
4241
4242 atomic_inc(&hdd_ipa->tx_ref_cnt);
4243
4244 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245}
4246
4247/**
Leo Chang11545d62016-10-17 14:53:50 -07004248 * hdd_ipa_is_present() - get IPA hw status
4249 * @hdd_ctx: pointer to hdd context
4250 *
4251 * ipa_uc_reg_rdyCB is not directly designed to check
4252 * ipa hw status. This is an undocumented function which
4253 * has confirmed with IPA team.
4254 *
4255 * Return: true - ipa hw present
4256 * false - ipa hw not present
4257 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004258bool hdd_ipa_is_present(struct hdd_context *hdd_ctx)
Leo Chang11545d62016-10-17 14:53:50 -07004259{
4260 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004261 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004262 return true;
4263 else
4264 return false;
4265}
4266
4267/**
Leo Chang69c39692016-10-12 20:11:12 -07004268 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 * @work: pointer to the scheduled work
4270 *
4271 * Called during PM resume to send packets to TL which were queued
4272 * while host was in the process of suspending.
4273 *
4274 * Return: None
4275 */
Leo Chang69c39692016-10-12 20:11:12 -07004276static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004277{
4278 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4279 struct hdd_ipa_priv,
4280 pm_work);
4281 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304282 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 uint32_t dequeued = 0;
4284
Leo Chang69c39692016-10-12 20:11:12 -07004285 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4286 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304287 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304288 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4289 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304290 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291
4292 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004294 if (pm_tx_cb->exception) {
4295 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4296 "FLUSH EXCEPTION");
Govind Singh1dab23b2017-08-12 13:31:00 +05304297 if (pm_tx_cb->adapter->dev)
4298 hdd_softap_hard_start_xmit(skb,
4299 pm_tx_cb->adapter->dev);
Govind Singh02075942017-08-15 11:13:28 +05304300 else
4301 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004302 } else {
4303 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004305 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304306 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304308 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004309 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4310 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311
4312 hdd_ipa->stats.num_tx_dequeued += dequeued;
4313 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4314 hdd_ipa->stats.num_max_pm_queue = dequeued;
4315}
4316
4317/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004318 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004319 * @priv: pointer to private data registered with IPA (we register a
4320 * pointer to the interface-specific IPA context)
4321 * @evt: the IPA event which triggered the callback
4322 * @data: data associated with the event
4323 *
4324 * Return: None
4325 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004326static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 unsigned long data)
4328{
4329 struct hdd_ipa_priv *hdd_ipa = NULL;
4330 struct ipa_rx_data *ipa_tx_desc;
4331 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304332 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304334 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335
Mukul Sharma81661ae2015-10-30 20:26:02 +05304336 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004337 ipa_tx_desc = (struct ipa_rx_data *)data;
4338 hdd_ipa = iface_context->hdd_ipa;
4339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004341 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4342 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343 iface_context->stats.num_tx_drop++;
4344 return;
4345 }
4346
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347 /*
4348 * When SSR is going on or driver is unloading, just drop the packets.
4349 * During SSR, there is no use in queueing the packets as STA has to
4350 * connect back any way
4351 */
4352 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304353 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354 ipa_free_skb(ipa_tx_desc);
4355 iface_context->stats.num_tx_drop++;
4356 return;
4357 }
4358
4359 skb = ipa_tx_desc->skb;
4360
Yun Parkb187d542016-11-14 18:10:04 -08004361 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4362 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363
4364 /*
4365 * If PROD resource is not requested here then there may be cases where
4366 * IPA hardware may be clocked down because of not having proper
4367 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4368 * workaround to request PROD resource while data is going over CONS
4369 * pipe to prevent the IPA hardware clockdown.
4370 */
4371 hdd_ipa_rm_request(hdd_ipa);
4372
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304373 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004374 /*
4375 * If host is still suspended then queue the packets and these will be
4376 * drained later when resume completes. When packet is arrived here and
4377 * host is suspended, this means that there is already resume is in
4378 * progress.
4379 */
4380 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304381 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4383 pm_tx_cb->iface_context = iface_context;
4384 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304385 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004386 hdd_ipa->stats.num_tx_queued++;
4387
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304388 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389 return;
4390 }
4391
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304392 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393
4394 /*
4395 * If we are here means, host is not suspended, wait for the work queue
4396 * to finish.
4397 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399
4400 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4401}
4402
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004403/*
4404 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4405 * @priv: pointer to private data registered with IPA (we register a
4406 * pointer to the interface-specific IPA context)
4407 * @evt: the IPA event which triggered the callback
4408 * @data: data associated with the event
4409 *
4410 * Return: None
4411 */
4412static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4413 unsigned long data)
4414{
4415 cds_ssr_protect(__func__);
4416 __hdd_ipa_i2w_cb(priv, evt, data);
4417 cds_ssr_unprotect(__func__);
4418}
4419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004421 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 * @hdd_ctx: Global HDD context
4423 *
4424 * Return: 0 on success, negativer errno on error
4425 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004426static int __hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004428 struct hdd_ipa_priv *hdd_ipa;
4429
4430 if (wlan_hdd_validate_context(hdd_ctx))
4431 return 0;
4432
4433 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434
4435 if (!hdd_ipa_is_enabled(hdd_ctx))
4436 return 0;
4437
4438 /*
4439 * Check if IPA is ready for suspend, If we are here means, there is
4440 * high chance that suspend would go through but just to avoid any race
4441 * condition after suspend started, these checks are conducted before
4442 * allowing to suspend.
4443 */
4444 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4445 return -EAGAIN;
4446
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304447 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448
4449 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304450 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451 return -EAGAIN;
4452 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304453 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004454
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304455 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004456 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304457 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458
4459 return 0;
4460}
4461
4462/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004463 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4464 * @hdd_ctx: Global HDD context
4465 *
4466 * Return: 0 on success, negativer errno on error
4467 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004468int hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004469{
4470 int ret;
4471
4472 cds_ssr_protect(__func__);
4473 ret = __hdd_ipa_suspend(hdd_ctx);
4474 cds_ssr_unprotect(__func__);
4475
4476 return ret;
4477}
4478
4479/**
4480 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481 * hdd_ctx: Global HDD context
4482 *
4483 * Return: 0 on success, negative errno on error
4484 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004485static int __hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004487 struct hdd_ipa_priv *hdd_ipa;
4488
4489 if (wlan_hdd_validate_context(hdd_ctx))
4490 return 0;
4491
4492 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004493
4494 if (!hdd_ipa_is_enabled(hdd_ctx))
4495 return 0;
4496
4497 schedule_work(&hdd_ipa->pm_work);
4498
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304499 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304501 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004502
4503 return 0;
4504}
4505
4506/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004507 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4508 * hdd_ctx: Global HDD context
4509 *
4510 * Return: 0 on success, negative errno on error
4511 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004512int hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004513{
4514 int ret;
4515
4516 cds_ssr_protect(__func__);
4517 ret = __hdd_ipa_resume(hdd_ctx);
4518 cds_ssr_unprotect(__func__);
4519
4520 return ret;
4521}
4522
4523/**
Yun Park52b2b992016-09-22 15:49:51 -07004524 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4525 * @hdd_ipa: Global HDD IPA context
4526 *
4527 * Return: 0 on success, negative errno on error
4528 */
4529static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4530{
4531 int i;
4532 uint32_t max_desc_cnt;
4533 struct hdd_ipa_tx_desc *tmp_desc;
4534
Yun Parkd9c528e2017-08-30 16:34:57 -07004535 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
Yun Park52b2b992016-09-22 15:49:51 -07004536
4537 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4538
jiad14fe4fb2017-08-08 13:33:14 +08004539 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc) *
Yun Parkd9c528e2017-08-30 16:34:57 -07004540 max_desc_cnt);
Yun Park52b2b992016-09-22 15:49:51 -07004541
4542 if (!tmp_desc) {
4543 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkd9c528e2017-08-30 16:34:57 -07004544 "Free Tx descriptor allocation failed");
Yun Park52b2b992016-09-22 15:49:51 -07004545 return -ENOMEM;
4546 }
4547
4548 hdd_ipa->tx_desc_list = tmp_desc;
4549
4550 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004551 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004552 tmp_desc->id = i;
4553 tmp_desc->ipa_tx_desc_ptr = NULL;
4554 list_add_tail(&tmp_desc->link,
4555 &hdd_ipa->free_tx_desc_head);
4556 tmp_desc++;
4557 }
4558
4559 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4560 hdd_ipa->stats.num_tx_desc_error = 0;
4561
4562 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4563
4564 return 0;
4565}
4566
4567/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4569 * @hdd_ipa: Global HDD IPA context
4570 *
4571 * Return: 0 on success, negative errno on error
4572 */
4573static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4574{
4575 int i, ret = 0;
4576 struct ipa_sys_connect_params *ipa;
4577 uint32_t desc_fifo_sz;
4578
4579 /* The maximum number of descriptors that can be provided to a BAM at
4580 * once is one less than the total number of descriptors that the buffer
4581 * can contain.
4582 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4583 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4584 * be provided at once.
4585 * Because of above requirement, one extra descriptor will be added to
4586 * make sure hardware always has one descriptor.
4587 */
4588 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4589 + sizeof(struct sps_iovec);
4590
4591 /*setup TX pipes */
4592 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4593 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4594
4595 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4596 ipa->desc_fifo_sz = desc_fifo_sz;
4597 ipa->priv = &hdd_ipa->iface_context[i];
4598 ipa->notify = hdd_ipa_i2w_cb;
4599
4600 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4601 ipa->ipa_ep_cfg.hdr.hdr_len =
4602 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4603 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4604 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4605 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4606 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4607 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4608 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4609 } else {
4610 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4611 }
4612 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4613
4614 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4615 ipa->keep_ipa_awake = 1;
4616
4617 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4618 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004619 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4620 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004621 goto setup_sys_pipe_fail;
4622 }
4623 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4624 }
4625
4626 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4627 /*
4628 * Hard code it here, this can be extended if in case
4629 * PROD pipe is also per interface.
4630 * Right now there is no advantage of doing this.
4631 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004632 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4633
Yun Parkb4f591d2017-03-29 15:51:01 -07004634 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004635
4636 ipa->desc_fifo_sz = desc_fifo_sz;
4637 ipa->priv = hdd_ipa;
4638 ipa->notify = hdd_ipa_w2i_cb;
4639
4640 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4641 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4642 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4643 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4644
4645 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4646 ipa->keep_ipa_awake = 1;
4647
4648 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4649 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304650 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651 "Failed for RX pipe: %d", ret);
4652 goto setup_sys_pipe_fail;
4653 }
4654 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4655 }
4656
Yun Parkd9c528e2017-08-30 16:34:57 -07004657 /* Allocate free Tx desc list */
Yun Park52b2b992016-09-22 15:49:51 -07004658 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4659 if (ret)
4660 goto setup_sys_pipe_fail;
4661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 return ret;
4663
4664setup_sys_pipe_fail:
4665
4666 while (--i >= 0) {
4667 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304668 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669 sizeof(struct hdd_ipa_sys_pipe));
4670 }
4671
4672 return ret;
4673}
4674
4675/**
4676 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4677 * @hdd_ipa: Global HDD IPA context
4678 *
4679 * Return: None
4680 */
4681static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4682{
4683 int ret = 0, i;
Yun Parkd9c528e2017-08-30 16:34:57 -07004684 uint32_t max_desc_cnt;
Yun Park52b2b992016-09-22 15:49:51 -07004685 struct hdd_ipa_tx_desc *tmp_desc;
4686 struct ipa_rx_data *ipa_tx_desc;
4687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004688 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4689 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004690 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4691 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004692 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304693 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004694 ret);
4695
4696 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4697 }
4698 }
Yun Park52b2b992016-09-22 15:49:51 -07004699
4700 if (hdd_ipa->tx_desc_list) {
Yun Parkd9c528e2017-08-30 16:34:57 -07004701 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4702
Yun Park52b2b992016-09-22 15:49:51 -07004703 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004704 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004705 tmp_desc = hdd_ipa->tx_desc_list + i;
4706 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4707 if (ipa_tx_desc)
4708 ipa_free_skb(ipa_tx_desc);
4709 }
4710 tmp_desc = hdd_ipa->tx_desc_list;
4711 hdd_ipa->tx_desc_list = NULL;
4712 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4713 hdd_ipa->stats.num_tx_desc_error = 0;
4714 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4715 qdf_mem_free(tmp_desc);
4716 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717}
4718
4719/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004720 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4721 * @iface_context: interface-specific IPA context
4722 *
4723 * Return: None
4724 */
4725static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4726{
Yun Parkfec73dc2017-09-06 10:40:07 -07004727 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
4728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 if (iface_context == NULL)
4730 return;
4731
Yun Parkb4f591d2017-03-29 15:51:01 -07004732 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4733 iface_context->adapter->dev->name,
4734 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304736 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737 iface_context->adapter->ipa_context = NULL;
4738 iface_context->adapter = NULL;
4739 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304740 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004741 iface_context->ifa_address = 0;
4742 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304743 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304745 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004746 }
4747 iface_context->hdd_ipa->num_iface--;
Yun Parkfec73dc2017-09-06 10:40:07 -07004748 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: num_iface=%d",
4749 iface_context->hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750}
4751
4752/**
4753 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4754 * @hdd_ipa: HDD IPA global context
4755 * @adapter: Interface upon which IPA is being setup
4756 * @sta_id: Station ID of the API instance
4757 *
4758 * Return: 0 on success, negative errno value on error
4759 */
4760static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004761 struct hdd_adapter *adapter, uint8_t sta_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762{
4763 struct hdd_ipa_iface_context *iface_context = NULL;
4764 void *tl_context = NULL;
4765 int i, ret = 0;
4766
Yun Parkfec73dc2017-09-06 10:40:07 -07004767 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
4768
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4770 * channel change indication. Since these indications are sent by lower
4771 * layer as SAP updates and IPA doesn't have to do anything for these
4772 * updates so ignoring!
4773 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004774 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004775 return 0;
4776
4777 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4778 if (hdd_ipa->iface_context[i].adapter == NULL) {
4779 iface_context = &(hdd_ipa->iface_context[i]);
4780 break;
4781 }
4782 }
4783
4784 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304785 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004786 "All the IPA interfaces are in use");
4787 ret = -ENOMEM;
4788 goto end;
4789 }
4790
4791 adapter->ipa_context = iface_context;
4792 iface_context->adapter = adapter;
4793 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004794 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07004795 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004796 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304797 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004798 "Not able to get TL context sta_id: %d", sta_id);
4799 ret = -EINVAL;
4800 goto end;
4801 }
4802
4803 iface_context->tl_context = tl_context;
4804
Yun Parkb4f591d2017-03-29 15:51:01 -07004805 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4806 adapter->dev->name, adapter->dev->dev_addr,
4807 iface_context->prod_client,
4808 iface_context->cons_client,
4809 adapter->sessionId,
4810 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004811 if (ret)
4812 goto end;
4813
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004814 hdd_ipa->num_iface++;
Yun Parkfec73dc2017-09-06 10:40:07 -07004815
4816 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: num_iface=%d",
4817 hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004818 return ret;
4819
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820end:
4821 if (iface_context)
4822 hdd_ipa_cleanup_iface(iface_context);
4823 return ret;
4824}
4825
Yun Parka27049a2016-10-11 12:30:49 -07004826#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004827/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004828 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Jeff Johnson4929cd92017-10-06 19:21:57 -07004829 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004830 * @mcc_mode: 0=MCC/1=SCC
4831 *
4832 * Return: 0 on success, negative errno value on error
4833 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07004834static int __hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx,
4835 bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004836{
4837 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304838 QDF_STATUS status;
Jeff Johnson089d0432017-10-02 13:27:21 -07004839 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004840 struct ipa_msg_meta meta;
4841 struct ipa_wlan_msg *msg;
4842 int ret;
4843
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004844 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004845 return -EINVAL;
4846
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004847 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4848 return -EINVAL;
4849
4850 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004851 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004852 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304853 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson089d0432017-10-02 13:27:21 -07004854 adapter = adapter_node->adapter;
4855 if (adapter->device_mode == QDF_STA_MODE ||
4856 adapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004857 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnson089d0432017-10-02 13:27:21 -07004858 adapter->device_mode);
4859 hdd_deinit_tx_rx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004860 }
4861 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004862 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004863 adapter_node = next;
4864 }
4865 }
4866
4867 /* Send SCC/MCC Switching event to IPA */
4868 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304869 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004870 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004871 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004872 return -ENOMEM;
4873 }
4874
4875 meta.msg_type = mcc_mode ?
4876 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08004877 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878
4879 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4880
4881 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004882 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004883 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304884 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 }
4886
4887 return ret;
4888}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004889
4890/**
4891 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
4892 * @mcc_mode: 0=MCC/1=SCC
4893 *
4894 * Return: 0 on success, negative errno value on error
4895 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004896int hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004897{
4898 int ret;
4899
4900 cds_ssr_protect(__func__);
4901 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
4902 cds_ssr_unprotect(__func__);
4903
4904 return ret;
4905}
Yun Parka27049a2016-10-11 12:30:49 -07004906#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004907
4908/**
4909 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
4910 * @event: IPA WLAN event to be converted to a string
4911 *
4912 * Return: ASCII string representing the IPA WLAN event
4913 */
4914static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
4915{
4916 switch (event) {
4917 case WLAN_CLIENT_CONNECT:
4918 return "WLAN_CLIENT_CONNECT";
4919 case WLAN_CLIENT_DISCONNECT:
4920 return "WLAN_CLIENT_DISCONNECT";
4921 case WLAN_CLIENT_POWER_SAVE_MODE:
4922 return "WLAN_CLIENT_POWER_SAVE_MODE";
4923 case WLAN_CLIENT_NORMAL_MODE:
4924 return "WLAN_CLIENT_NORMAL_MODE";
4925 case SW_ROUTING_ENABLE:
4926 return "SW_ROUTING_ENABLE";
4927 case SW_ROUTING_DISABLE:
4928 return "SW_ROUTING_DISABLE";
4929 case WLAN_AP_CONNECT:
4930 return "WLAN_AP_CONNECT";
4931 case WLAN_AP_DISCONNECT:
4932 return "WLAN_AP_DISCONNECT";
4933 case WLAN_STA_CONNECT:
4934 return "WLAN_STA_CONNECT";
4935 case WLAN_STA_DISCONNECT:
4936 return "WLAN_STA_DISCONNECT";
4937 case WLAN_CLIENT_CONNECT_EX:
4938 return "WLAN_CLIENT_CONNECT_EX";
4939
4940 case IPA_WLAN_EVENT_MAX:
4941 default:
4942 return "UNKNOWN";
4943 }
4944}
4945
4946/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004947 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
4948 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
4949 *
4950 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
4951 */
4952static enum ipa_wlan_event
4953hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
4954{
4955 enum ipa_wlan_event ipa_event;
4956
4957 switch (hdd_ipa_event_type) {
4958 case HDD_IPA_CLIENT_CONNECT:
4959 ipa_event = WLAN_CLIENT_CONNECT;
4960 break;
4961 case HDD_IPA_CLIENT_DISCONNECT:
4962 ipa_event = WLAN_CLIENT_DISCONNECT;
4963 break;
4964 case HDD_IPA_AP_CONNECT:
4965 ipa_event = WLAN_AP_CONNECT;
4966 break;
4967 case HDD_IPA_AP_DISCONNECT:
4968 ipa_event = WLAN_AP_DISCONNECT;
4969 break;
4970 case HDD_IPA_STA_CONNECT:
4971 ipa_event = WLAN_STA_CONNECT;
4972 break;
4973 case HDD_IPA_STA_DISCONNECT:
4974 ipa_event = WLAN_STA_DISCONNECT;
4975 break;
4976 case HDD_IPA_CLIENT_CONNECT_EX:
4977 ipa_event = WLAN_CLIENT_CONNECT_EX;
4978 break;
4979 case HDD_IPA_WLAN_EVENT_MAX:
4980 default:
4981 ipa_event = IPA_WLAN_EVENT_MAX;
4982 break;
4983 }
4984 return ipa_event;
4985
4986}
4987
4988/**
4989 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990 * @adapter: adapter upon which the event was received
4991 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07004992 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004993 * @mac_address: MAC address associated with the event
4994 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07004995 * This function is meant to be called from within wlan_hdd_ipa.c
4996 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004997 * Return: 0 on success, negative errno value on error
4998 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07004999static int __hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005000 enum ipa_wlan_event type, uint8_t *mac_addr)
5001{
5002 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5003 struct ipa_msg_meta meta;
5004 struct ipa_wlan_msg *msg;
5005 struct ipa_wlan_msg_ex *msg_ex = NULL;
5006 int ret;
5007
Yun Parkfec73dc2017-09-06 10:40:07 -07005008 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5010 mac_addr, sta_id);
5011
5012 if (type >= IPA_WLAN_EVENT_MAX)
5013 return -EINVAL;
5014
5015 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5016 return -EINVAL;
5017
5018 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305019 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020 return -EINVAL;
5021 }
5022
5023 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5024 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005025 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026 return 0;
5027 }
5028
5029 /*
5030 * During IPA UC resource loading/unloading new events can be issued.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031 */
Yun Park777d7242017-03-30 15:38:33 -07005032 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5033 (hdd_ipa->resource_loading || hdd_ipa->resource_unloading)) {
5034 unsigned int pending_event_count;
5035 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005036
Yun Park777d7242017-03-30 15:38:33 -07005037 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5038 "%s:IPA resource %s inprogress",
5039 hdd_ipa_wlan_event_to_str(type),
5040 hdd_ipa->resource_loading ?
5041 "load" : "unload");
5042
5043 /* Wait until completion of the long/unloading */
5044 ret = wait_for_completion_timeout(&hdd_ipa->ipa_resource_comp,
5045 msecs_to_jiffies(IPA_RESOURCE_COMP_WAIT_TIME));
5046 if (!ret) {
5047 /*
5048 * If timed out, store the events separately and
5049 * handle them later.
5050 */
Yun Park64c405e2017-01-10 22:35:51 -08005051 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park777d7242017-03-30 15:38:33 -07005052 "IPA resource %s timed out",
5053 hdd_ipa->resource_loading ?
5054 "load" : "unload");
Yun Park7c4f31b2016-11-30 10:09:21 -08005055
Yun Park777d7242017-03-30 15:38:33 -07005056 if (hdd_ipa->resource_loading) {
5057 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005058
Yun Park777d7242017-03-30 15:38:33 -07005059 pending_event_count =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005060 qdf_list_size(&hdd_ipa->pending_event);
Yun Park777d7242017-03-30 15:38:33 -07005061 if (pending_event_count >=
5062 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
5063 hdd_debug(
5064 "Reached max pending event count");
5065 qdf_list_remove_front(
5066 &hdd_ipa->pending_event,
5067 (qdf_list_node_t **)&pending_event);
5068 } else {
5069 pending_event =
5070 (struct ipa_uc_pending_event *)
5071 qdf_mem_malloc(sizeof(
5072 struct ipa_uc_pending_event));
5073 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005074
Yun Park777d7242017-03-30 15:38:33 -07005075 if (!pending_event) {
5076 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5077 "Pending event memory alloc fail");
5078 qdf_mutex_release(&hdd_ipa->ipa_lock);
5079 return -ENOMEM;
5080 }
5081
5082 pending_event->adapter = adapter;
5083 pending_event->sta_id = sta_id;
5084 pending_event->type = type;
5085 qdf_mem_copy(pending_event->mac_addr,
5086 mac_addr, QDF_MAC_ADDR_SIZE);
5087 qdf_list_insert_back(&hdd_ipa->pending_event,
5088 &pending_event->node);
5089
Yun Park64c405e2017-01-10 22:35:51 -08005090 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005091 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005092 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 }
Jeff Johnson4929cd92017-10-06 19:21:57 -07005094 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5095 "IPA resource %s completed",
5096 hdd_ipa->resource_loading ?
5097 "load" : "unload");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 }
5099
5100 hdd_ipa->stats.event[type]++;
5101
Leo Chang3bc8fed2015-11-13 10:59:47 -08005102 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005103 switch (type) {
5104 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005105 qdf_mutex_acquire(&hdd_ipa->event_lock);
5106
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005107 /* STA already connected and without disconnect, connect again
5108 * This is Roaming scenario
5109 */
5110 if (hdd_ipa->sta_connected)
5111 hdd_ipa_cleanup_iface(adapter->ipa_context);
5112
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5114 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305115 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005116 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005117 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005118
Yun Park8f289c82016-10-18 16:38:21 -07005119 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5120 (hdd_ipa->sap_num_connected_sta > 0) &&
5121 !hdd_ipa->sta_connected) {
5122 qdf_mutex_release(&hdd_ipa->event_lock);
5123 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005124 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005125 qdf_mutex_acquire(&hdd_ipa->event_lock);
5126 }
5127
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005128 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005129 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005130 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005131
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005133
5134 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005135
5136 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sta_connected=%d",
5137 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 break;
5139
5140 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005141 qdf_mutex_acquire(&hdd_ipa->event_lock);
5142
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 /* For DFS channel we get two start_bss event (before and after
5144 * CAC). Also when ACS range includes both DFS and non DFS
5145 * channels, we could possibly change channel many times due to
5146 * RADAR detection and chosen channel may not be a DFS channels.
5147 * So dont return error here. Just discard the event.
5148 */
Yun Park8f289c82016-10-18 16:38:21 -07005149 if (adapter->ipa_context) {
5150 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005151 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005152 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005153
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5155 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005156 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005157 hdd_err("%s: Evt: %d, Interface setup failed",
5158 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005160 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005161
Yun Park8f289c82016-10-18 16:38:21 -07005162 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5163 qdf_mutex_release(&hdd_ipa->event_lock);
5164 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005165 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005166 qdf_mutex_acquire(&hdd_ipa->event_lock);
5167 }
5168
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005169 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005171 (adapter->ipa_context))->iface_id;
5172
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305173 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174 break;
5175
5176 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305177 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178
5179 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005180 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005181 hdd_err("%s: Evt: %d, STA already disconnected",
5182 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005183 return -EINVAL;
5184 }
Yun Parka37592b2016-06-11 17:10:28 -07005185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005186 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005189 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190 msg_ex->name);
5191 } else {
5192 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Park3b7152b2017-08-25 08:33:37 -07005193 if ((1 == hdd_ipa->num_iface) &&
Yun Parka37592b2016-06-11 17:10:28 -07005194 (HDD_IPA_UC_NUM_WDI_PIPE ==
Yun Park3b7152b2017-08-25 08:33:37 -07005195 hdd_ipa->activated_fw_pipe) &&
5196 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005197 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 }
5199
Yun Park74127cf2016-09-18 11:22:41 -07005200 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5201 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005202 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005204 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005205 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005206 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5207 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005208 }
5209
Yun Park8f289c82016-10-18 16:38:21 -07005210 hdd_ipa_cleanup_iface(adapter->ipa_context);
5211
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305212 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005213
5214 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sta_connected=%d",
5215 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 break;
5217
5218 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005219 qdf_mutex_acquire(&hdd_ipa->event_lock);
5220
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005221 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005222 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005223 hdd_err("%s: Evt: %d, SAP already disconnected",
5224 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 return -EINVAL;
5226 }
5227
Yun Park3b7152b2017-08-25 08:33:37 -07005228 if ((1 == hdd_ipa->num_iface) &&
5229 (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
5230 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005231 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232 /*
5233 * We disable WDI pipes directly here since
5234 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5235 * processed when unloading WLAN driver is in
5236 * progress
5237 */
5238 hdd_ipa_uc_disable_pipes(hdd_ipa);
5239 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305240 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 "NO INTF left but still pipe clean up");
5242 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5243 }
5244 }
5245
5246 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005247 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005248 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005249 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005250 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005251 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5252 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005253 }
Yun Parka37592b2016-06-11 17:10:28 -07005254
Yun Park8f289c82016-10-18 16:38:21 -07005255 hdd_ipa_cleanup_iface(adapter->ipa_context);
5256
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305257 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258 break;
5259
5260 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005261 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005262 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005263 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305264 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265 return 0;
5266 }
5267
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305268 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005269 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5270 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005271 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305272 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273 "%s: STA ID %d found, not valid",
5274 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 return 0;
5276 }
Yun Park312f71a2015-12-08 10:22:42 -08005277
5278 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005279 if (hdd_ipa->sap_num_connected_sta == 0 &&
5280 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005281 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005282 hdd_ipa->sta_connected) {
5283 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005284 hdd_ipa_uc_offload_enable_disable(
5285 hdd_get_adapter(hdd_ipa->hdd_ctx,
5286 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005287 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005288 qdf_mutex_acquire(&hdd_ipa->event_lock);
5289 }
Yun Parka37592b2016-06-11 17:10:28 -07005290
Yun Park312f71a2015-12-08 10:22:42 -08005291 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5292 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305293 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005294 "%s: handle 1st con ret %d",
5295 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005296
5297 if (hdd_ipa_uc_sta_is_enabled(
5298 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005299 hdd_ipa->sta_connected) {
5300 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005301 hdd_ipa_uc_offload_enable_disable(
5302 hdd_get_adapter(
5303 hdd_ipa->hdd_ctx,
5304 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005305 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005306 } else {
5307 qdf_mutex_release(&hdd_ipa->event_lock);
5308 }
Yun Parka37592b2016-06-11 17:10:28 -07005309
Yun Park312f71a2015-12-08 10:22:42 -08005310 return ret;
5311 }
5312 }
5313
5314 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005315
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305316 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005317
5318 meta.msg_type = type;
5319 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5320 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305321 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005322
5323 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305324 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005325 "msg_ex allocation failed");
5326 return -ENOMEM;
5327 }
5328 strlcpy(msg_ex->name, adapter->dev->name,
5329 IPA_RESOURCE_NAME_MAX);
5330 msg_ex->num_of_attribs = 1;
5331 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5332 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5333 msg_ex->attribs[0].offset =
5334 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5335 } else {
5336 msg_ex->attribs[0].offset =
5337 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5338 }
5339 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5340 IPA_MAC_ADDR_SIZE);
5341
5342 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5343
5344 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005345 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305346 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305347 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348 return ret;
5349 }
5350 hdd_ipa->stats.num_send_msg++;
Yun Parkfec73dc2017-09-06 10:40:07 -07005351
5352 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sap_num_connected_sta=%d",
5353 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005354 return ret;
5355
5356 case WLAN_CLIENT_DISCONNECT:
5357 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005358 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359 "%s: IPA UC OFFLOAD NOT ENABLED",
5360 msg_ex->name);
5361 return 0;
5362 }
5363
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305364 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Park73ea8bb2017-08-25 07:27:39 -07005365 if (!hdd_ipa->sap_num_connected_sta) {
5366 qdf_mutex_release(&hdd_ipa->event_lock);
5367 hdd_err("%s: Evt: %d, Client already disconnected",
5368 msg_ex->name, meta.msg_type);
5369 return 0;
5370 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005371 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005372 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305373 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005374 "%s: STA ID %d NOT found, not valid",
5375 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376 return 0;
5377 }
5378 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005379
Yun Park9b5030f2016-11-08 12:02:37 -08005380 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005381 if (!hdd_ipa->sap_num_connected_sta &&
5382 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005383 if ((false == hdd_ipa->resource_unloading)
5384 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305385 hdd_ipa->activated_fw_pipe) &&
5386 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005387 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5388 }
5389
Yun Park9b5030f2016-11-08 12:02:37 -08005390 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005391 hdd_ipa->sta_connected) {
5392 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005393 hdd_ipa_uc_offload_enable_disable(
5394 hdd_get_adapter(hdd_ipa->hdd_ctx,
5395 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005396 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005397 } else {
5398 qdf_mutex_release(&hdd_ipa->event_lock);
5399 }
Yun Park8f289c82016-10-18 16:38:21 -07005400 } else {
5401 qdf_mutex_release(&hdd_ipa->event_lock);
5402 }
Yun Parkfec73dc2017-09-06 10:40:07 -07005403
5404 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sap_num_connected_sta=%d",
5405 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406 break;
5407
5408 default:
5409 return 0;
5410 }
5411
5412 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305413 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005414 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305415 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416 return -ENOMEM;
5417 }
5418
5419 meta.msg_type = type;
5420 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5421 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5422
Srinivas Girigowda97852372017-03-06 16:52:59 -08005423 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005424 msg->name, meta.msg_type);
5425
5426 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5427
5428 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005429 hdd_err("%s: Evt: %d fail:%d",
5430 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305431 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 return ret;
5433 }
5434
5435 hdd_ipa->stats.num_send_msg++;
5436
5437end:
5438 return ret;
5439}
5440
5441/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005442 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005443 * @adapter: adapter upon which the event was received
5444 * @sta_id: station id for the event
5445 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5446 * @mac_address: MAC address associated with the event
5447 *
5448 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5449 *
5450 * Return: 0 on success, negative errno value on error
5451 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005452int hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005453 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5454{
5455 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005456 int ret = 0;
5457
5458 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005459
Leo Changa202b522016-10-14 16:13:50 -07005460 /* Data path offload only support for STA and SAP mode */
5461 if ((QDF_STA_MODE == adapter->device_mode) ||
5462 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005463 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005464
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005465 cds_ssr_unprotect(__func__);
5466
5467 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005468}
5469
5470/**
5471 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5472 * @hdd_ipa: Global HDD IPA context
5473 *
5474 * Return: None
5475 */
5476static void
5477hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5478{
5479 unsigned int pending_event_count;
5480 struct ipa_uc_pending_event *pending_event = NULL;
5481
5482 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005483 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005484 "%s, Pending Event Count %d", __func__, pending_event_count);
5485 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005486 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005487 "%s, No Pending Event", __func__);
5488 return;
5489 }
5490
5491 qdf_list_remove_front(&hdd_ipa->pending_event,
5492 (qdf_list_node_t **)&pending_event);
5493 while (pending_event != NULL) {
5494 __hdd_ipa_wlan_evt(pending_event->adapter,
5495 pending_event->type,
5496 pending_event->sta_id,
5497 pending_event->mac_addr);
5498 qdf_mem_free(pending_event);
5499 pending_event = NULL;
5500 qdf_list_remove_front(&hdd_ipa->pending_event,
5501 (qdf_list_node_t **)&pending_event);
5502 }
5503}
5504
5505/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005506 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5507 * @state: IPA RM state value
5508 *
5509 * Return: ASCII string representing the IPA RM state
5510 */
5511static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5512{
5513 switch (state) {
5514 case HDD_IPA_RM_RELEASED:
5515 return "RELEASED";
5516 case HDD_IPA_RM_GRANT_PENDING:
5517 return "GRANT_PENDING";
5518 case HDD_IPA_RM_GRANTED:
5519 return "GRANTED";
5520 }
5521
5522 return "UNKNOWN";
5523}
5524
5525/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005526 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005527 * @hdd_ctx: HDD global context
5528 *
5529 * Allocate hdd_ipa resources, ipa pipe resource and register
5530 * wlan interface with IPA module.
5531 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305532 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005533 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005534static QDF_STATUS __hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005535{
5536 struct hdd_ipa_priv *hdd_ipa = NULL;
5537 int ret, i;
5538 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005539 struct ol_txrx_pdev_t *pdev = NULL;
Yun Park66f24c42017-03-20 10:39:47 -07005540 struct ipa_rm_perf_profile profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005541
Yun Parkfec73dc2017-09-06 10:40:07 -07005542 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
5543
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005544 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305545 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005546
Yun Parkbaa62862017-01-18 13:43:34 -08005547 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005548 if (!pdev) {
5549 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5550 goto fail_return;
5551 }
5552
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305553 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305555 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005556 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005557 }
5558
5559 hdd_ctx->hdd_ipa = hdd_ipa;
5560 ghdd_ipa = hdd_ipa;
5561 hdd_ipa->hdd_ctx = hdd_ctx;
5562 hdd_ipa->num_iface = 0;
5563
5564 /* Create the interface context */
5565 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5566 iface_context = &hdd_ipa->iface_context[i];
5567 iface_context->hdd_ipa = hdd_ipa;
5568 iface_context->cons_client =
5569 hdd_ipa_adapter_2_client[i].cons_client;
5570 iface_context->prod_client =
5571 hdd_ipa_adapter_2_client[i].prod_client;
5572 iface_context->iface_id = i;
5573 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305574 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005575 }
5576 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005577 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5578 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005579 }
5580
Leo Chang69c39692016-10-12 20:11:12 -07005581 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305582 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005583 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305584 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005585 qdf_list_create(&hdd_ipa->pending_event, 1000);
5586 qdf_mutex_create(&hdd_ipa->event_lock);
5587 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588
5589 ret = hdd_ipa_setup_rm(hdd_ipa);
5590 if (ret)
5591 goto fail_setup_rm;
5592
5593 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5594 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305595 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005596 hdd_ipa->sap_num_connected_sta = 0;
5597 hdd_ipa->ipa_tx_packets_diff = 0;
5598 hdd_ipa->ipa_rx_packets_diff = 0;
5599 hdd_ipa->ipa_p_tx_packets = 0;
5600 hdd_ipa->ipa_p_rx_packets = 0;
5601 hdd_ipa->resource_loading = false;
5602 hdd_ipa->resource_unloading = false;
5603 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005604 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005605 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005606 /* Setup IPA sys_pipe for MCC */
5607 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5608 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5609 if (ret)
5610 goto fail_create_sys_pipe;
5611 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005612 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5613 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005614
5615 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5616 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5617 hdd_ipa_uc_fw_op_event_handler);
5618 hdd_ipa->uc_op_work[i].msg = NULL;
5619 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005620 } else {
5621 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5622 if (ret)
5623 goto fail_create_sys_pipe;
5624 }
5625
Yun Park66f24c42017-03-20 10:39:47 -07005626 /* When IPA clock scaling is disabled, initialze maximum clock */
5627 if (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)) {
5628 profile.max_supported_bandwidth_mbps = 800;
5629 hdd_debug("IPA clock scaling is disabled.");
5630 hdd_debug("Set initial CONS/PROD perf: %d",
5631 profile.max_supported_bandwidth_mbps);
5632 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
5633 &profile);
5634 if (ret) {
5635 hdd_err("RM CONS set perf profile failed: %d", ret);
5636 goto fail_create_sys_pipe;
5637 }
5638
5639 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
5640 &profile);
5641 if (ret) {
5642 hdd_err("RM PROD set perf profile failed: %d", ret);
5643 goto fail_create_sys_pipe;
5644 }
5645 }
5646
Yun Park777d7242017-03-30 15:38:33 -07005647 init_completion(&hdd_ipa->ipa_resource_comp);
5648
Yun Parkfec73dc2017-09-06 10:40:07 -07005649 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: success");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305650 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005651
5652fail_create_sys_pipe:
5653 hdd_ipa_destroy_rm_resource(hdd_ipa);
5654fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305655 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305656 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005657 hdd_ctx->hdd_ipa = NULL;
5658 ghdd_ipa = NULL;
5659fail_return:
Yun Parkfec73dc2017-09-06 10:40:07 -07005660 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: fail");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305661 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005662}
5663
5664/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005665 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5666 * @hdd_ctx: HDD global context
5667 *
5668 * Allocate hdd_ipa resources, ipa pipe resource and register
5669 * wlan interface with IPA module.
5670 *
5671 * Return: QDF_STATUS enumeration
5672 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005673QDF_STATUS hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005674{
5675 QDF_STATUS ret;
5676
5677 cds_ssr_protect(__func__);
5678 ret = __hdd_ipa_init(hdd_ctx);
5679 cds_ssr_unprotect(__func__);
5680
5681 return ret;
5682}
5683
Arun Khandavallicc544b32017-01-30 19:52:16 +05305684
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005685/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305686 * __hdd_ipa_flush - flush IPA exception path SKB's
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005687 * @hdd_ctx: HDD global context
5688 *
Govind Singh1dab23b2017-08-12 13:31:00 +05305689 * Return: none
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005690 */
Govind Singh1dab23b2017-08-12 13:31:00 +05305691static void __hdd_ipa_flush(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005692{
5693 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305694 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005695 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5696
5697 if (!hdd_ipa_is_enabled(hdd_ctx))
Govind Singh1dab23b2017-08-12 13:31:00 +05305698 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005700 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005701
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305702 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703
Nirav Shahcbc6d722016-03-01 16:24:53 +05305704 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5705 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305706 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707
5708 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005709 if (pm_tx_cb->ipa_tx_desc)
5710 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005711
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305712 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005713 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305714 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Govind Singh1dab23b2017-08-12 13:31:00 +05305715}
5716
5717/**
5718 * __hdd_ipa_cleanup - IPA cleanup function
5719 * @hdd_ctx: HDD global context
5720 *
5721 * Return: QDF_STATUS enumeration
5722 */
5723static QDF_STATUS __hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
5724{
5725 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5726 int i;
5727 struct hdd_ipa_iface_context *iface_context = NULL;
5728
5729 if (!hdd_ipa_is_enabled(hdd_ctx))
5730 return QDF_STATUS_SUCCESS;
5731
5732 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5733 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5734 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5735 }
5736
5737 /* Teardown IPA sys_pipe for MCC */
5738 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5739 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5740
5741 hdd_ipa_destroy_rm_resource(hdd_ipa);
5742
5743 __hdd_ipa_flush(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005744
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305745 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005746 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005747
5748 /* destory the interface lock */
5749 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5750 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305751 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005752 }
5753
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005754 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005755 if (ipa_uc_dereg_rdyCB())
5756 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5757 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305759 qdf_mutex_destroy(&hdd_ipa->event_lock);
5760 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkd8fb1a82017-10-13 16:48:20 -07005761 qdf_list_destroy(&hdd_ipa->pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5764 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5765 hdd_ipa->uc_op_work[i].msg = NULL;
5766 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005767 }
5768
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305769 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005770 hdd_ctx->hdd_ipa = NULL;
5771
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305772 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005773}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005774
5775/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305776 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_flush
5777 * @hdd_ctx: HDD global context
5778 *
5779 * Return: None
5780 */
5781void hdd_ipa_flush(struct hdd_context *hdd_ctx)
5782{
5783 cds_ssr_protect(__func__);
5784 __hdd_ipa_flush(hdd_ctx);
5785 cds_ssr_unprotect(__func__);
5786}
5787
5788/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005789 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5790 * @hdd_ctx: HDD global context
5791 *
5792 * Return: QDF_STATUS enumeration
5793 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005794QDF_STATUS hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005795{
5796 QDF_STATUS ret;
5797
5798 cds_ssr_protect(__func__);
5799 ret = __hdd_ipa_cleanup(hdd_ctx);
5800 cds_ssr_unprotect(__func__);
5801
5802 return ret;
5803}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005804#endif /* IPA_OFFLOAD */