blob: 43542f444d0d19ff424feee84817c1a13e96e1e2 [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
2222/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002223 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2224 * @op_msg: operation message received from firmware
2225 * @usr_ctxt: user context registered with TL (we register the HDD Global
2226 * context)
2227 *
2228 * Return: None
2229 */
2230static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2231{
2232 struct op_msg_type *msg = op_msg;
2233 struct ipa_uc_fw_stats *uc_fw_stat;
2234 struct IpaHwStatsWDIInfoData_t ipa_stat;
2235 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002236 struct hdd_context *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302237 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002238
2239 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302240 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241 return;
2242 }
2243
2244 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302245 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002246 "%s, INVALID OPCODE %d", __func__, msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002247 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002248 return;
2249 }
2250
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002251 hdd_ctx = (struct hdd_context *) usr_ctxt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002252
2253 /*
2254 * When SSR is going on or driver is unloading, just return.
2255 */
2256 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302257 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302258 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002259 return;
2260 }
2261
2262 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2263
Govind Singhb6a89772016-08-12 11:23:35 +05302264 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002265 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002266
2267 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2268 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302269 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002270 hdd_ipa->activated_fw_pipe++;
2271 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2272 hdd_ipa->resource_loading = false;
Yun Park777d7242017-03-30 15:38:33 -07002273 complete(&hdd_ipa->ipa_resource_comp);
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002274 if (hdd_ipa->wdi_enabled == false) {
2275 hdd_ipa->wdi_enabled = true;
2276 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2277 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2278 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002279 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002280 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002281 if (hdd_ipa->pending_cons_req)
2282 ipa_rm_notify_completion(
2283 IPA_RM_RESOURCE_GRANTED,
2284 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002285 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002286 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302287 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002288 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002289 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302290 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002291 hdd_ipa->activated_fw_pipe--;
2292 if (!hdd_ipa->activated_fw_pipe) {
Yun Park777d7242017-03-30 15:38:33 -07002293 /*
2294 * Async return success from FW
2295 * Disable/suspend all the PIPEs
2296 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002297 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002298 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2299 ipa_rm_release_resource(
2300 IPA_RM_RESOURCE_WLAN_PROD);
Yun Park5b635012015-12-02 15:05:01 -08002301 hdd_ipa->resource_unloading = false;
Yun Park777d7242017-03-30 15:38:33 -07002302 complete(&hdd_ipa->ipa_resource_comp);
Yun Park5b635012015-12-02 15:05:01 -08002303 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2304 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002305 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302306 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002307 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002308 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002309 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302310 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002311 "==== IPA_UC WLAN_HOST RX ====\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002312 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002313 "NUM TX FWD OK : %llu\n"
2314 "NUM TX FWD ERR : %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002315 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002316 hdd_ipa->stats.num_tx_fwd_ok,
2317 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302318 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002319 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2320 "SAP NUM STAs: %d\n"
2321 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002322 "CONCURRENT MODE: %s\n"
2323 "TX PIPE HDL: 0x%x\n"
2324 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002325 "RSC LOADING : %d\n"
2326 "RSC UNLOADING : %d\n"
2327 "PNDNG CNS RQT : %d",
2328 hdd_ipa->sap_num_connected_sta,
2329 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002330 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002331 hdd_ipa->tx_pipe_handle,
2332 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002333 hdd_ipa->resource_loading,
2334 hdd_ipa->resource_unloading,
2335 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002336
2337 /* STATs from FW */
2338 uc_fw_stat = (struct ipa_uc_fw_stats *)
2339 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302340 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002341 "==== IPA_UC WLAN_FW TX ====\n"
2342 "COMP RING BASE: 0x%x\n"
2343 "COMP RING SIZE: %d\n"
2344 "COMP RING DBELL : 0x%x\n"
2345 "COMP RING DBELL IND VAL : %d\n"
2346 "COMP RING DBELL CACHED VAL : %d\n"
2347 "COMP RING DBELL CACHED VAL : %d\n"
2348 "PKTS ENQ : %d\n"
2349 "PKTS COMP : %d\n"
2350 "IS SUSPEND : %d\n"
2351 "RSVD : 0x%x",
2352 uc_fw_stat->tx_comp_ring_base,
2353 uc_fw_stat->tx_comp_ring_size,
2354 uc_fw_stat->tx_comp_ring_dbell_addr,
2355 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2356 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2357 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2358 uc_fw_stat->tx_pkts_enqueued,
2359 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002360 uc_fw_stat->tx_is_suspend,
2361 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302362 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002363 "==== IPA_UC WLAN_FW RX ====\n"
2364 "IND RING BASE: 0x%x\n"
2365 "IND RING SIZE: %d\n"
2366 "IND RING DBELL : 0x%x\n"
2367 "IND RING DBELL IND VAL : %d\n"
2368 "IND RING DBELL CACHED VAL : %d\n"
2369 "RDY IND ADDR : 0x%x\n"
2370 "RDY IND CACHE VAL : %d\n"
2371 "RFIL IND : %d\n"
2372 "NUM PKT INDICAT : %d\n"
2373 "BUF REFIL : %d\n"
2374 "NUM DROP NO SPC : %d\n"
2375 "NUM DROP NO BUF : %d\n"
2376 "IS SUSPND : %d\n"
2377 "RSVD : 0x%x\n",
2378 uc_fw_stat->rx_ind_ring_base,
2379 uc_fw_stat->rx_ind_ring_size,
2380 uc_fw_stat->rx_ind_ring_dbell_addr,
2381 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2382 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2383 uc_fw_stat->rx_ind_ring_rdidx_addr,
2384 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2385 uc_fw_stat->rx_refill_idx,
2386 uc_fw_stat->rx_num_pkts_indicated,
2387 uc_fw_stat->rx_buf_refilled,
2388 uc_fw_stat->rx_num_ind_drop_no_space,
2389 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002390 uc_fw_stat->rx_is_suspend,
2391 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002392 /* STATs from IPA */
2393 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302394 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002395 "==== IPA_UC IPA TX ====\n"
2396 "NUM PROCD : %d\n"
2397 "CE DBELL : 0x%x\n"
2398 "NUM DBELL FIRED : %d\n"
2399 "COMP RNG FULL : %d\n"
2400 "COMP RNG EMPT : %d\n"
2401 "COMP RNG USE HGH : %d\n"
2402 "COMP RNG USE LOW : %d\n"
2403 "BAM FIFO FULL : %d\n"
2404 "BAM FIFO EMPT : %d\n"
2405 "BAM FIFO USE HGH : %d\n"
2406 "BAM FIFO USE LOW : %d\n"
2407 "NUM DBELL : %d\n"
2408 "NUM UNEXP DBELL : %d\n"
2409 "NUM BAM INT HDL : 0x%x\n"
2410 "NUM BAM INT NON-RUN : 0x%x\n"
2411 "NUM QMB INT HDL : 0x%x",
2412 ipa_stat.tx_ch_stats.num_pkts_processed,
2413 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2414 ipa_stat.tx_ch_stats.num_db_fired,
2415 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2416 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2417 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2418 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2419 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2420 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2421 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2422 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2423 ipa_stat.tx_ch_stats.num_db,
2424 ipa_stat.tx_ch_stats.num_unexpected_db,
2425 ipa_stat.tx_ch_stats.num_bam_int_handled,
2426 ipa_stat.tx_ch_stats.
2427 num_bam_int_in_non_runnning_state,
2428 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2429
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302430 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002431 "==== IPA_UC IPA RX ====\n"
2432 "MAX OST PKT : %d\n"
2433 "NUM PKT PRCSD : %d\n"
2434 "RNG RP : 0x%x\n"
2435 "COMP RNG FULL : %d\n"
2436 "COMP RNG EMPT : %d\n"
2437 "COMP RNG USE HGH : %d\n"
2438 "COMP RNG USE LOW : %d\n"
2439 "BAM FIFO FULL : %d\n"
2440 "BAM FIFO EMPT : %d\n"
2441 "BAM FIFO USE HGH : %d\n"
2442 "BAM FIFO USE LOW : %d\n"
2443 "NUM DB : %d\n"
2444 "NUM UNEXP DB : %d\n"
2445 "NUM BAM INT HNDL : 0x%x\n",
2446 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2447 ipa_stat.rx_ch_stats.num_pkts_processed,
2448 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2449 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2450 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2451 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2452 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2453 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2454 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2455 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2456 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2457 ipa_stat.rx_ch_stats.num_db,
2458 ipa_stat.rx_ch_stats.num_unexpected_db,
2459 ipa_stat.rx_ch_stats.num_bam_int_handled);
2460 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2461 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2462 /* STATs from FW */
2463 uc_fw_stat = (struct ipa_uc_fw_stats *)
2464 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302465 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002466 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2467 uc_fw_stat->tx_pkts_completed,
2468 hdd_ipa->ipa_p_tx_packets);
2469 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2470 (uc_fw_stat->rx_num_ind_drop_no_space +
2471 uc_fw_stat->rx_num_ind_drop_no_buf +
2472 uc_fw_stat->rx_num_pkts_indicated),
2473 hdd_ipa->ipa_p_rx_packets);
2474
2475 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2476 hdd_ipa->ipa_p_rx_packets =
2477 (uc_fw_stat->rx_num_ind_drop_no_space +
2478 uc_fw_stat->rx_num_ind_drop_no_buf +
2479 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302480 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002481 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2482 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2483 hdd_ipa_uc_loaded_handler(hdd_ipa);
2484 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002485 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2486 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2487 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002488 }
Yun Park8957d802017-01-25 12:27:29 -08002489
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302490 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002491}
2492
2493
2494/**
2495 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2496 * @adapter: device adapter instance
2497 * @offload_type: MCC or SCC
2498 * @enable: TX offload enable or disable
2499 *
2500 * Return: none
2501 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002502static void hdd_ipa_uc_offload_enable_disable(struct hdd_adapter *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002503 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002504{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002505 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002506 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002507 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002508 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002509
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002510 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002511 return;
2512
Yun Park8292dcb2016-10-07 16:46:06 -07002513 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002514 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002515
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002516 if (!iface_context) {
2517 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2518 "Interface context is NULL");
2519 return;
2520 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002521 if (session_id >= CSR_ROAM_SESSION_MAX) {
2522 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2523 "invalid session id: %d", session_id);
2524 return;
2525 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002526 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002527 /* IPA offload status is already set as desired */
2528 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002529 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002530 "IPA offload status is already set",
2531 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002532 return;
2533 }
2534
Yun Park4540e862016-11-10 16:30:06 -08002535 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2536 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2537 "invalid session id: %d, offload_type=%d, enable=%d",
2538 adapter->sessionId, offload_type, enable);
2539 return;
2540 }
2541
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302542 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002543 sizeof(ipa_offload_enable_disable));
2544 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002545 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002546 ipa_offload_enable_disable.enable = enable;
2547
Srinivas Girigowda97852372017-03-06 16:52:59 -08002548 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002549 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002550 ipa_offload_enable_disable.offload_type,
2551 ipa_offload_enable_disable.vdev_id,
2552 ipa_offload_enable_disable.enable);
2553
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302554 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002555 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2556 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302557 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002558 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
2559 "Failure to enable IPA offload",
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002560 ipa_offload_enable_disable.offload_type,
2561 ipa_offload_enable_disable.vdev_id,
2562 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002563 } else {
2564 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002565 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002566 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002567 }
2568}
2569
2570/**
2571 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2572 * @work: uC OP work
2573 *
2574 * Return: None
2575 */
2576static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2577{
2578 struct op_msg_type *msg;
2579 struct uc_op_work_struct *uc_op_work = container_of(work,
2580 struct uc_op_work_struct, work);
2581 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2582
2583 cds_ssr_protect(__func__);
2584
2585 msg = uc_op_work->msg;
2586 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002587 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002588 "%s, posted msg %d", __func__, msg->op_code);
2589
2590 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2591
2592 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002593}
2594
2595/**
2596 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2597 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2598 * @op_msg: operation message received from firmware
2599 * @hdd_ctx: Global HDD context
2600 *
2601 * Return: None
2602 */
2603static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2604{
2605 struct hdd_ipa_priv *hdd_ipa;
2606 struct op_msg_type *msg;
2607 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302608 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609
2610 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302611 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002612 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613
2614 msg = (struct op_msg_type *)op_msg;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002615 hdd_ipa = ((struct hdd_context *)hdd_ctx)->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002616
2617 if (unlikely(!hdd_ipa))
2618 goto end;
2619
2620 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002621 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2622 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002623 goto end;
2624 }
2625
2626 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2627 if (uc_op_work->msg)
2628 /* When the same uC OPCODE is already pended, just return */
2629 goto end;
2630
2631 uc_op_work->msg = msg;
2632 schedule_work(&uc_op_work->work);
2633 return;
2634
2635end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302636 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002637}
2638
2639/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002640 * hdd_ipa_init_uc_op_work - init ipa uc op work
2641 * @work: struct work_struct
2642 * @work_handler: work_handler
2643 *
2644 * Return: none
2645 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002646static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002647 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002648{
2649 INIT_WORK(work, work_handler);
2650}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002651
Yun Park637d6482016-10-05 10:51:33 -07002652#ifdef FEATURE_METERING
2653/**
2654 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2655 * IPA calls to get WLAN stats or set quota limit.
2656 * @priv: pointer to private data registered with IPA (we register a
2657 *» pointer to the global IPA context)
2658 * @evt: the IPA event which triggered the callback
2659 * @data: data associated with the event
2660 *
2661 * Return: None
2662 */
2663static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2664 void *data)
2665{
2666 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002667 struct hdd_adapter *adapter = NULL;
Yun Park637d6482016-10-05 10:51:33 -07002668 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2669 struct ipa_set_wifi_quota *ipa_set_quota;
2670 int ret = 0;
2671
2672 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2673 return;
2674
2675 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2676
2677 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2678
2679 switch (evt) {
2680 case IPA_GET_WDI_SAP_STATS:
2681 /* fill-up ipa_get_wdi_sap_stats structure after getting
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002682 * ipa_uc_fw_stats from FW
2683 */
Yun Park637d6482016-10-05 10:51:33 -07002684 wdi_sap_stats = data;
2685
2686 if (!adapter) {
2687 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2688 "IPA uC share stats failed - no adapter");
2689 wdi_sap_stats->stats_valid = 0;
2690 return;
2691 }
2692
2693 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
Yun Park637d6482016-10-05 10:51:33 -07002694 hdd_ipa_uc_sharing_stats_request(adapter,
2695 wdi_sap_stats->reset_stats);
2696 ret = wait_for_completion_timeout(
2697 &hdd_ipa->ipa_uc_sharing_stats_comp,
2698 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2699 if (!ret) {
2700 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2701 "IPA uC share stats request timed out");
2702 wdi_sap_stats->stats_valid = 0;
2703 } else {
2704 wdi_sap_stats->stats_valid = 1;
2705
2706 wdi_sap_stats->ipv4_rx_packets =
2707 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2708 wdi_sap_stats->ipv4_rx_bytes =
2709 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2710 wdi_sap_stats->ipv6_rx_packets =
2711 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2712 wdi_sap_stats->ipv6_rx_bytes =
2713 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2714 wdi_sap_stats->ipv4_tx_packets =
2715 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2716 wdi_sap_stats->ipv4_tx_bytes =
2717 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2718 wdi_sap_stats->ipv6_tx_packets =
2719 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2720 wdi_sap_stats->ipv6_tx_bytes =
2721 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2722 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2723 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2724 "IPA_GET_WDI_SAP_STATS",
2725 wdi_sap_stats->stats_valid,
2726 wdi_sap_stats->ipv4_rx_packets,
2727 wdi_sap_stats->ipv4_rx_bytes,
2728 wdi_sap_stats->ipv6_rx_packets,
2729 wdi_sap_stats->ipv6_rx_bytes,
2730 wdi_sap_stats->ipv4_tx_packets,
2731 wdi_sap_stats->ipv4_tx_bytes,
2732 wdi_sap_stats->ipv6_tx_packets,
2733 wdi_sap_stats->ipv6_tx_bytes);
2734 }
2735 break;
2736 case IPA_SET_WIFI_QUOTA:
2737 /* get ipa_set_wifi_quota structure from IPA and pass to FW
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002738 * through quota_exceeded field in ipa_uc_fw_stats
2739 */
Yun Park637d6482016-10-05 10:51:33 -07002740 ipa_set_quota = data;
2741
2742 if (!adapter) {
2743 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2744 "IPA uC set quota failed - no adapter");
2745 ipa_set_quota->set_valid = 0;
2746 return;
2747 }
2748
Yun Park777d7242017-03-30 15:38:33 -07002749 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
Yun Park637d6482016-10-05 10:51:33 -07002750 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2751 ipa_set_quota->quota_bytes);
2752
2753 ret = wait_for_completion_timeout(
2754 &hdd_ipa->ipa_uc_set_quota_comp,
2755 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2756 if (!ret) {
2757 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2758 "IPA uC set quota request timed out");
2759 ipa_set_quota->set_valid = 0;
2760 } else {
2761 ipa_set_quota->quota_bytes =
2762 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2763 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2764 ipa_set_quota->set_valid =
2765 hdd_ipa->ipa_quota_rsp.success;
2766 }
2767
2768 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2769 ipa_set_quota->quota_bytes,
2770 ipa_set_quota->set_valid);
2771 break;
2772 }
2773}
2774
2775/**
2776 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2777 * IPA calls to get WLAN stats or set quota limit.
2778 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07002779 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07002780 * @evt: the IPA event which triggered the callback
2781 * @data: data associated with the event
2782 *
2783 * Return: None
2784 */
2785static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2786 void *data)
2787{
2788 cds_ssr_protect(__func__);
2789 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2790 cds_ssr_unprotect(__func__);
2791}
2792
Yun Parkb4f591d2017-03-29 15:51:01 -07002793static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002794{
Yun Park637d6482016-10-05 10:51:33 -07002795 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2796 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2797}
2798#else
Yun Parkb4f591d2017-03-29 15:51:01 -07002799static void hdd_ipa_wdi_meter_notifier_cb(void)
2800{
2801}
2802
2803static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002804{
2805}
2806#endif
2807
Rajeev Kumar217f2172016-01-06 18:11:55 -08002808/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002809 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2810 * @hdd_ctx: Global HDD context
2811 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002812 * This function is called to update IPA pipe configuration with resources
2813 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2814 * (cds_enable)
2815 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302816 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002817 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002818QDF_STATUS hdd_ipa_uc_ol_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002819{
Yun Parkb4f591d2017-03-29 15:51:01 -07002820 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002821 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002822 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07002823 uint8_t i;
2824 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002825
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002826 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2827 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002828
Yun Parkfec73dc2017-09-06 10:40:07 -07002829 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2830
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002831 /* Do only IPA Pipe specific configuration here. All one time
2832 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2833 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2834 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002835 if (!pdev || !soc) {
2836 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07002837 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002838 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002839 }
Yun Parkb4f591d2017-03-29 15:51:01 -07002840 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002841 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2842 "IPA UC resource alloc fail");
2843 return QDF_STATUS_E_FAILURE;
2844 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002845
Yun Parkb4f591d2017-03-29 15:51:01 -07002846 if (true == hdd_ipa->uc_loaded) {
2847 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2848 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2849 hdd_ipa_wdi_meter_notifier_cb,
2850 hdd_ctx->config->IpaDescSize,
2851 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2852 &hdd_ipa->tx_pipe_handle,
2853 &hdd_ipa->rx_pipe_handle);
2854 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08002855 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002856 "Failure to setup IPA pipes (status=%d)",
2857 status);
2858 return QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002859 }
Yun Park637d6482016-10-05 10:51:33 -07002860
Yun Parkb4f591d2017-03-29 15:51:01 -07002861 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
2862 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002863 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002864
Yun Parkb4f591d2017-03-29 15:51:01 -07002865 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08002866 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2867
Yun Parkb4f591d2017-03-29 15:51:01 -07002868 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
2869 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
2870 hdd_ipa_uc_fw_op_event_handler);
2871 hdd_ipa->uc_op_work[i].msg = NULL;
2872 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002873
Yun Parkbaa62862017-01-18 13:43:34 -08002874fail_return:
Yun Parkfec73dc2017-09-06 10:40:07 -07002875 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: stat=%d", stat);
Yun Parkb4f591d2017-03-29 15:51:01 -07002876 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002877}
2878
Leo Change3e49442015-10-26 20:07:13 -07002879/**
Yun Parkd8fb1a82017-10-13 16:48:20 -07002880 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
2881 * @hdd_ipa: pointer to HDD IPA struct
2882 *
2883 * Return: none
2884 */
2885static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
2886{
2887 struct ipa_uc_pending_event *pending_event = NULL;
2888
2889 while (qdf_list_remove_front(&hdd_ipa->pending_event,
2890 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS)
2891 qdf_mem_free(pending_event);
2892}
2893
2894/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302895 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
2896 * @hdd_ctx: Global HDD context
2897 *
2898 * Return: 0 on success, negativer errno on error
2899 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002900int hdd_ipa_uc_ol_deinit(struct hdd_context *hdd_ctx)
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302901{
2902 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2903 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07002904 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302905
Yun Parkfec73dc2017-09-06 10:40:07 -07002906 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2907
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302908 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2909 return ret;
2910
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05302911 if (!hdd_ipa->ipa_pipes_down)
2912 hdd_ipa_uc_disable_pipes(hdd_ipa);
2913
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302914 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002915 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
2916 hdd_ipa->tx_pipe_handle,
2917 hdd_ipa->rx_pipe_handle);
2918 if (status) {
2919 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2920 "Failure to cleanup IPA pipes (status=%d)",
2921 status);
2922 return -EFAULT;
2923 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302924 }
2925
Yun Parkd8fb1a82017-10-13 16:48:20 -07002926 hdd_ipa_cleanup_pending_event(hdd_ipa);
2927
Yun Parkfec73dc2017-09-06 10:40:07 -07002928 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: ret=%d", ret);
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302929 return ret;
2930}
2931
2932/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002933 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002934 * @hdd_ctx: hdd main context
2935 *
2936 * Force shutdown IPA pipe
2937 * Independent of FW pipe status, IPA pipe shutdonw progress
2938 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2939 * independent from FW pipe status
2940 *
2941 * Return: NONE
2942 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002943static void __hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002944{
2945 struct hdd_ipa_priv *hdd_ipa;
2946
Yun Parkfec73dc2017-09-06 10:40:07 -07002947 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2948
Leo Change3e49442015-10-26 20:07:13 -07002949 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2950 return;
2951
2952 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2953 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302954 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002955 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07002956 hdd_ipa_uc_disable_pipes(hdd_ipa);
2957 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002958 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07002959 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07002960 }
Yun Parkfec73dc2017-09-06 10:40:07 -07002961
2962 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Leo Change3e49442015-10-26 20:07:13 -07002963}
2964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002965/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002966 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2967 * __hdd_ipa_uc_force_pipe_shutdown
2968 * @hdd_ctx: hdd main context
2969 *
2970 * Force shutdown IPA pipe
2971 * Independent of FW pipe status, IPA pipe shutdonw progress
2972 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2973 * independent from FW pipe status
2974 *
2975 * Return: NONE
2976 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002977void hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002978{
2979 cds_ssr_protect(__func__);
2980 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2981 cds_ssr_unprotect(__func__);
2982}
2983
2984/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302985 * hdd_ipa_msg_free_fn() - Free an IPA message
2986 * @buff: pointer to the IPA message
2987 * @len: length of the IPA message
2988 * @type: type of IPA message
2989 *
2990 * Return: None
2991 */
2992static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2993{
Srinivas Girigowda97852372017-03-06 16:52:59 -08002994 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05302995 ghdd_ipa->stats.num_free_msg++;
2996 qdf_mem_free(buff);
2997}
2998
Govind Singh9c58eba2016-09-02 16:23:06 +05302999/**
jge62037862016-12-09 10:44:33 +08003000 * hdd_ipa_uc_send_evt() - send event to ipa
3001 * @hdd_ctx: pointer to hdd context
3002 * @type: event type
3003 * @mac_addr: pointer to mac address
3004 *
3005 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303006 *
3007 * Return: 0 - Success
3008 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003009static int hdd_ipa_uc_send_evt(struct hdd_adapter *adapter,
jge62037862016-12-09 10:44:33 +08003010 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303011{
jge62037862016-12-09 10:44:33 +08003012 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05303013 struct ipa_msg_meta meta;
3014 struct ipa_wlan_msg *msg;
3015 int ret = 0;
jge62037862016-12-09 10:44:33 +08003016
3017 meta.msg_len = sizeof(struct ipa_wlan_msg);
3018 msg = qdf_mem_malloc(meta.msg_len);
3019 if (msg == NULL) {
3020 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3021 "msg allocation failed");
3022 return -ENOMEM;
3023 }
3024
3025 meta.msg_type = type;
3026 strlcpy(msg->name, adapter->dev->name,
3027 IPA_RESOURCE_NAME_MAX);
3028 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Yun Parkfec73dc2017-09-06 10:40:07 -07003029 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08003030 msg->name, meta.msg_type);
3031 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3032 if (ret) {
3033 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3034 "%s: Evt: %d fail:%d",
3035 msg->name, meta.msg_type, ret);
3036 qdf_mem_free(msg);
3037 return ret;
3038 }
3039
3040 hdd_ipa->stats.num_send_msg++;
3041
3042 return ret;
3043}
3044
3045/**
3046 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3047 * @hdd_ctx: pointer to hdd adapter
3048 *
3049 * Send disconnect client event to IPA driver during SSR
3050 *
3051 * Return: 0 - Success
3052 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003053static int hdd_ipa_uc_disconnect_client(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003054{
3055 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3056 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303057 int i;
3058
Yun Parkfec73dc2017-09-06 10:40:07 -07003059 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Govind Singh9c58eba2016-09-02 16:23:06 +05303060 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3061 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3062 continue;
3063 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003064 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3065 hdd_ipa->sap_num_connected_sta) {
3066 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3067 adapter->aStaInfo[i].macAddrSTA.bytes);
3068 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303069 }
3070 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003071 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: sap_num_connected_sta=%d",
3072 hdd_ipa->sap_num_connected_sta);
Govind Singh9c58eba2016-09-02 16:23:06 +05303073
3074 return ret;
3075}
3076
3077/**
jge62037862016-12-09 10:44:33 +08003078 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3079 * @hdd_ctx: pointer to hdd adapter
3080 *
3081 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303082 *
3083 * Return: 0 - Success
3084 */
jge62037862016-12-09 10:44:33 +08003085
Jeff Johnson49d45e62017-08-29 14:30:42 -07003086static int hdd_ipa_uc_disconnect_ap(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003087{
3088 int ret = 0;
3089
Yun Parkfec73dc2017-09-06 10:40:07 -07003090 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3091 if (adapter->ipa_context) {
jge62037862016-12-09 10:44:33 +08003092 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3093 adapter->dev->dev_addr);
Yun Parkfec73dc2017-09-06 10:40:07 -07003094 }
3095 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
jge62037862016-12-09 10:44:33 +08003096
3097 return ret;
3098}
3099
jge62037862016-12-09 10:44:33 +08003100/**
3101 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3102 * @hdd_ctx: pointer to hdd adapter
3103 *
3104 * Send disconnect sta event to IPA driver during SSR
3105 *
3106 * Return: 0 - Success
3107 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003108static int hdd_ipa_uc_disconnect_sta(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003109{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003110 struct hdd_station_ctx *sta_ctx;
jge62037862016-12-09 10:44:33 +08003111 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3112 int ret = 0;
3113
Yun Parkfec73dc2017-09-06 10:40:07 -07003114 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003115 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003116 hdd_ipa->sta_connected) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07003117 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
jge62037862016-12-09 10:44:33 +08003118 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Jeff Johnsond377dce2017-10-04 10:32:42 -07003119 sta_ctx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003120 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003121 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
jge62037862016-12-09 10:44:33 +08003122
3123 return ret;
3124}
jge62037862016-12-09 10:44:33 +08003125
3126/**
3127 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3128 * @hdd_ctx: pointer to hdd context
3129 *
3130 * Send disconnect event to IPA driver during SSR
3131 *
3132 * Return: 0 - Success
3133 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003134static int hdd_ipa_uc_disconnect(struct hdd_context *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303135{
3136 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3137 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003138 struct hdd_adapter *adapter;
Govind Singh9c58eba2016-09-02 16:23:06 +05303139 int ret = 0;
3140
Govind Singh9c58eba2016-09-02 16:23:06 +05303141 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3142 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003143 adapter = adapter_node->adapter;
jge62037862016-12-09 10:44:33 +08003144 if (adapter->device_mode == QDF_SAP_MODE) {
3145 hdd_ipa_uc_disconnect_client(adapter);
3146 hdd_ipa_uc_disconnect_ap(adapter);
3147 } else if (adapter->device_mode == QDF_STA_MODE) {
3148 hdd_ipa_uc_disconnect_sta(adapter);
3149 }
3150
Govind Singh9c58eba2016-09-02 16:23:06 +05303151 status = hdd_get_next_adapter(
3152 hdd_ctx, adapter_node, &next);
3153 adapter_node = next;
3154 }
3155
3156 return ret;
3157}
3158
3159/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003160 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003161 *
3162 * Deinit basic IPA UC host side to be in sync reloaded FW during
3163 * SSR
3164 *
3165 * Return: 0 - Success
3166 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003167static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003168{
3169 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3170 int idx;
3171 struct hdd_ipa_iface_context *iface_context;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003172 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173
Yun Parkfec73dc2017-09-06 10:40:07 -07003174 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3175
Arun Khandavallicc544b32017-01-30 19:52:16 +05303176 if (!hdd_ipa)
3177 return 0;
3178
3179 hdd_ctx = hdd_ipa->hdd_ctx;
3180 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003181 return 0;
3182
jge62037862016-12-09 10:44:33 +08003183 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303184 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003185
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003186 /* Clean up HDD IPA interfaces */
3187 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3188 (idx < HDD_IPA_MAX_IFACE); idx++) {
3189 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003190 if (iface_context->adapter && iface_context->adapter->magic ==
3191 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003192 hdd_ipa_cleanup_iface(iface_context);
3193 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003194 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003195 /* After SSR, wlan driver reloads FW again. But we need to protect
3196 * IPA submodule during SSR transient state. So deinit basic IPA
3197 * UC host side to be in sync with reloaded FW during SSR
3198 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003199
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303200 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3202 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3203 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3204 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303205 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003206
Guolei Bianca144d82016-11-10 11:07:42 +08003207 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3208 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3209
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003210 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3211 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3212 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3213 hdd_ipa->uc_op_work[idx].msg = NULL;
3214 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003215
3216 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003217 return 0;
3218}
3219
3220/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003221 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3222 *
3223 * Deinit basic IPA UC host side to be in sync reloaded FW during
3224 * SSR
3225 *
3226 * Return: 0 - Success
3227 */
3228int hdd_ipa_uc_ssr_deinit(void)
3229{
3230 int ret;
3231
3232 cds_ssr_protect(__func__);
3233 ret = __hdd_ipa_uc_ssr_deinit();
3234 cds_ssr_unprotect(__func__);
3235
3236 return ret;
3237}
3238
3239/**
3240 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003241 *
3242 * Init basic IPA UC host side to be in sync with reloaded FW after
3243 * SSR to resume IPA UC operations
3244 *
3245 * Return: 0 - Success
3246 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003247static int __hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003248{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003249
Arun Khandavallicc544b32017-01-30 19:52:16 +05303250 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3251 int i;
3252 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303253
Yun Parkfec73dc2017-09-06 10:40:07 -07003254 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3255
Arun Khandavallicc544b32017-01-30 19:52:16 +05303256 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3257 return 0;
3258
Arun Khandavallicc544b32017-01-30 19:52:16 +05303259 /* Create the interface context */
3260 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3261 iface_context = &hdd_ipa->iface_context[i];
3262 iface_context->hdd_ipa = hdd_ipa;
3263 iface_context->cons_client =
3264 hdd_ipa_adapter_2_client[i].cons_client;
3265 iface_context->prod_client =
3266 hdd_ipa_adapter_2_client[i].prod_client;
3267 iface_context->iface_id = i;
3268 iface_context->adapter = NULL;
3269 }
3270 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3271 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3272 hdd_ipa->vdev_offload_enabled[i] = false;
3273 }
3274
3275 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3276 hdd_ipa->resource_loading = false;
3277 hdd_ipa->resource_unloading = false;
3278 hdd_ipa->sta_connected = 0;
3279 hdd_ipa->ipa_pipes_down = true;
3280 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303281 }
3282
Yun Parkfec73dc2017-09-06 10:40:07 -07003283 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003284 return 0;
3285}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003286
3287/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003288 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3289 *
3290 * Init basic IPA UC host side to be in sync with reloaded FW after
3291 * SSR to resume IPA UC operations
3292 *
3293 * Return: 0 - Success
3294 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003295int hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003296{
3297 int ret;
3298
3299 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303300 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003301 cds_ssr_unprotect(__func__);
3302
3303 return ret;
3304}
3305
3306/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003307 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3308 * @work: scheduled work
3309 *
3310 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3311 * not want to immediately release the wake lock since the system
3312 * would then potentially try to suspend when there is a healthy data
3313 * rate. Deferred work is scheduled and this function handles the
3314 * work. When this function is called, if the IPA resource is still
3315 * released then we release the wake lock.
3316 *
3317 * Return: None
3318 */
3319static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3320{
3321 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3322 struct hdd_ipa_priv,
3323 wake_lock_work);
3324
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303325 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003326
3327 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3328 goto end;
3329
3330 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303331 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003332 WIFI_POWER_EVENT_WAKELOCK_IPA);
3333
3334end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303335 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003336}
3337
3338/**
3339 * hdd_ipa_rm_request() - Request resource from IPA
3340 * @hdd_ipa: Global HDD IPA context
3341 *
3342 * Return: 0 on success, negative errno on error
3343 */
3344static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3345{
3346 int ret = 0;
3347
3348 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3349 return 0;
3350
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303351 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003352
3353 switch (hdd_ipa->rm_state) {
3354 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303355 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356 return 0;
3357 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303358 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 return -EINPROGRESS;
3360 case HDD_IPA_RM_RELEASED:
3361 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3362 break;
3363 }
3364
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303365 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366
3367 ret = ipa_rm_inactivity_timer_request_resource(
3368 IPA_RM_RESOURCE_WLAN_PROD);
3369
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303370 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371 if (ret == 0) {
3372 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3373 hdd_ipa->stats.num_rm_grant_imm++;
3374 }
3375
3376 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3377 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303378 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379 WIFI_POWER_EVENT_WAKELOCK_IPA);
3380 hdd_ipa->wake_lock_released = false;
3381 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303382 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003383
3384 return ret;
3385}
3386
3387/**
3388 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3389 * @hdd_ipa: Global HDD IPA context
3390 *
3391 * Return: 0 if resources released, negative errno otherwise
3392 */
3393static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3394{
3395 int ret = 0;
3396
3397 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3398 return 0;
3399
3400 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3401 return -EAGAIN;
3402
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303403 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003404
Nirav Shahcbc6d722016-03-01 16:24:53 +05303405 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303406 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003407 return -EAGAIN;
3408 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303409 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303411 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412 switch (hdd_ipa->rm_state) {
3413 case HDD_IPA_RM_GRANTED:
3414 break;
3415 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303416 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003417 return -EINPROGRESS;
3418 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303419 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420 return 0;
3421 }
3422
3423 /* IPA driver returns immediately so set the state here to avoid any
3424 * race condition.
3425 */
3426 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3427 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303428 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003430 ret = ipa_rm_inactivity_timer_release_resource(
3431 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003432
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303433 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434 if (unlikely(ret != 0)) {
3435 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3436 WARN_ON(1);
3437 }
3438
3439 /*
3440 * If wake_lock is released immediately, kernel would try to suspend
3441 * immediately as well, Just avoid ping-pong between suspend-resume
3442 * while there is healthy amount of data transfer going on by
3443 * releasing the wake_lock after some delay.
3444 */
3445 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3446 msecs_to_jiffies
3447 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3448
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303449 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450
3451 return ret;
3452}
3453
3454/**
3455 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3456 * @user_data: user data registered with IPA
3457 * @event: the IPA resource manager event that occurred
3458 * @data: the data associated with the event
3459 *
3460 * Return: None
3461 */
3462static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3463 unsigned long data)
3464{
3465 struct hdd_ipa_priv *hdd_ipa = user_data;
3466
3467 if (unlikely(!hdd_ipa))
3468 return;
3469
3470 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3471 return;
3472
Srinivas Girigowda97852372017-03-06 16:52:59 -08003473 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474
3475 switch (event) {
3476 case IPA_RM_RESOURCE_GRANTED:
3477 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3478 /* RM Notification comes with ISR context
3479 * it should be serialized into work queue to avoid
3480 * ISR sleep problem
3481 */
3482 hdd_ipa->uc_rm_work.event = event;
3483 schedule_work(&hdd_ipa->uc_rm_work.work);
3484 break;
3485 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303486 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303488 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 hdd_ipa->stats.num_rm_grant++;
3490 break;
3491
3492 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003493 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003494 hdd_ipa->resource_unloading = false;
3495 break;
3496
3497 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303498 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 break;
3500 }
3501}
3502
3503/**
3504 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3505 *
3506 * Callback function registered with IPA that is called when IPA wants
3507 * to release the WLAN consumer resource
3508 *
3509 * Return: 0 if the request is granted, negative errno otherwise
3510 */
3511static int hdd_ipa_rm_cons_release(void)
3512{
3513 return 0;
3514}
3515
3516/**
3517 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3518 *
3519 * Callback function registered with IPA that is called when IPA wants
3520 * to access the WLAN consumer resource
3521 *
3522 * Return: 0 if the request is granted, negative errno otherwise
3523 */
3524static int hdd_ipa_rm_cons_request(void)
3525{
Yun Park4d8b60a2015-10-22 13:59:32 -07003526 int ret = 0;
3527
3528 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303529 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003530 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003532 ret = -EINPROGRESS;
3533 } else if (ghdd_ipa->resource_unloading) {
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 unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003536 ghdd_ipa->pending_cons_req = true;
3537 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003539
3540 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003541}
3542
3543/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003544 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003545 * @hdd_ctx: Global HDD context
3546 * @tx_packets: Number of packets transmitted in the last sample period
3547 * @rx_packets: Number of packets received in the last sample period
3548 *
3549 * Return: 0 on success, negative errno on error
3550 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07003551static int __hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx,
3552 uint64_t tx_packets,
3553 uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003554{
3555 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003556 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003558 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559 int ret;
3560
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003561 if (wlan_hdd_validate_context(hdd_ctx))
3562 return 0;
3563
3564 hdd_ipa = hdd_ctx->hdd_ipa;
3565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003566 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3567 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3568 return 0;
3569
3570 memset(&profile, 0, sizeof(profile));
3571
3572 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3573 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3574 else if (tx_packets >
3575 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3576 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3577 else
3578 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3579
3580 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3581 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3582 else if (rx_packets >
3583 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3584 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3585 else
3586 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3587
Yun Parkec845302016-12-15 09:22:57 -08003588 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 "CONS perf curr: %d, next: %d",
3590 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003591 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003592 "PROD perf curr: %d, next: %d",
3593 hdd_ipa->curr_prod_bw, next_prod_bw);
3594
3595 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003596 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003597 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003598 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3599 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003601 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602
3603 return ret;
3604 }
3605 hdd_ipa->curr_cons_bw = next_cons_bw;
3606 hdd_ipa->stats.num_cons_perf_req++;
3607 }
3608
3609 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003610 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003611 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003612 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3613 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003615 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 return ret;
3617 }
3618 hdd_ipa->curr_prod_bw = next_prod_bw;
3619 hdd_ipa->stats.num_prod_perf_req++;
3620 }
3621
3622 return 0;
3623}
3624
3625/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003626 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3627 * @hdd_ctx: Global HDD context
3628 * @tx_packets: Number of packets transmitted in the last sample period
3629 * @rx_packets: Number of packets received in the last sample period
3630 *
3631 * Return: 0 on success, negative errno on error
3632 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003633int hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003634 uint64_t rx_packets)
3635{
3636 int ret;
3637
3638 cds_ssr_protect(__func__);
3639 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3640 cds_ssr_unprotect(__func__);
3641
3642 return ret;
3643}
3644
3645/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003646 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3647 * @work: struct work_struct
3648 * @work_handler: work_handler
3649 *
3650 * Return: none
3651 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003652static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3653 work_func_t work_handler)
3654{
3655 INIT_WORK(work, work_handler);
3656}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003657
3658/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003659 * hdd_ipa_setup_rm() - Setup IPA resource management
3660 * @hdd_ipa: Global HDD IPA context
3661 *
3662 * Return: 0 on success, negative errno on error
3663 */
3664static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3665{
3666 struct ipa_rm_create_params create_params = { 0 };
3667 int ret;
3668
3669 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3670 return 0;
3671
Rajeev Kumar217f2172016-01-06 18:11:55 -08003672 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3673 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003674 memset(&create_params, 0, sizeof(create_params));
3675 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3676 create_params.reg_params.user_data = hdd_ipa;
3677 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3678 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3679
3680 ret = ipa_rm_create_resource(&create_params);
3681 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303682 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683 "Create RM resource failed: %d", ret);
3684 goto setup_rm_fail;
3685 }
3686
3687 memset(&create_params, 0, sizeof(create_params));
3688 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3689 create_params.request_resource = hdd_ipa_rm_cons_request;
3690 create_params.release_resource = hdd_ipa_rm_cons_release;
3691 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3692
3693 ret = ipa_rm_create_resource(&create_params);
3694 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303695 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003696 "Create RM CONS resource failed: %d", ret);
3697 goto delete_prod;
3698 }
3699
3700 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3701 IPA_RM_RESOURCE_APPS_CONS);
3702
3703 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3704 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3705 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303706 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 ret);
3708 goto timer_init_failed;
3709 }
3710
3711 /* Set the lowest bandwidth to start with */
3712 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3713
3714 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303715 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716 "Set perf level failed: %d", ret);
3717 goto set_perf_failed;
3718 }
3719
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303720 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3722 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303723 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003724 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3725 hdd_ipa->wake_lock_released = true;
3726 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3727
3728 return ret;
3729
3730set_perf_failed:
3731 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3732
3733timer_init_failed:
3734 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3735
3736delete_prod:
3737 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3738
3739setup_rm_fail:
3740 return ret;
3741}
3742
3743/**
3744 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3745 * @hdd_ipa: Global HDD IPA context
3746 *
3747 * Destroys all resources associated with the IPA resource manager
3748 *
3749 * Return: None
3750 */
3751static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3752{
3753 int ret;
3754
3755 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3756 return;
3757
3758 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303759 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003761 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303762 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003763
3764 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3765
3766 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3767 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303768 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769 "RM PROD resource delete failed %d", ret);
3770
3771 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
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 CONS resource delete failed %d", ret);
3775}
3776
tfyu0380a972017-07-13 18:19:37 +08003777#ifdef QCA_CONFIG_SMP
3778static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3779{
3780 return netif_rx_ni(skb);
3781}
3782#else
3783static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3784{
3785 struct iphdr *ip_h;
3786 static atomic_t softirq_mitigation_cntr =
3787 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
3788 int result;
3789
3790 ip_h = (struct iphdr *)(skb->data);
3791 if ((skb->protocol == htons(ETH_P_IP)) &&
3792 (ip_h->protocol == IPPROTO_ICMP)) {
3793 result = netif_rx_ni(skb);
3794 } else {
3795 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
3796 * to avoid excessive softirq's.
3797 */
3798 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
3799 result = netif_rx_ni(skb);
3800 atomic_set(&softirq_mitigation_cntr,
3801 IPA_WLAN_RX_SOFTIRQ_THRESH);
3802 } else {
3803 result = netif_rx(skb);
3804 }
3805 }
3806
3807 return result;
3808}
3809#endif
3810
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003811/**
3812 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3813 * @skb: network buffer
3814 * @adapter: network adapter
3815 *
3816 * Called when a network buffer is received which should not be routed
3817 * to the IPA module.
3818 *
3819 * Return: None
3820 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303821static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003822 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003823{
tfyu0380a972017-07-13 18:19:37 +08003824 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003825 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3826 unsigned int cpu_index;
3827
3828 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07003829 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 adapter);
3831 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003832 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003833 return;
3834 }
3835
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003836 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003837 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003838 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839 return;
3840 }
3841
3842 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3843 skb->dev = adapter->dev;
3844 skb->protocol = eth_type_trans(skb, skb->dev);
3845 skb->ip_summed = CHECKSUM_NONE;
3846
3847 cpu_index = wlan_hdd_get_cpu();
3848
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003849 ++adapter->hdd_stats.tx_rx_stats.rx_packets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08003850 result = hdd_ipa_aggregated_rx_ind(skb);
3851 if (result == NET_RX_SUCCESS)
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003852 ++adapter->hdd_stats.tx_rx_stats.rx_delivered[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003853 else
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003854 ++adapter->hdd_stats.tx_rx_stats.rx_refused[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855
3856 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857}
3858
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003859/**
Leo Chang69c39692016-10-12 20:11:12 -07003860 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3861 * @hdd_ipa: pointer to hdd ipa context
3862 * @adapter: network adapter
3863 * @skb: data pointer
3864 *
3865 * if exception packet has set forward bit, copied new packet should be
3866 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3867 * put into pm queue and tx procedure will be differed
3868 *
3869 * Return: None
3870 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003871static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003872 struct hdd_adapter *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003873{
Leo Chang69c39692016-10-12 20:11:12 -07003874 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3875
Leo Chang69c39692016-10-12 20:11:12 -07003876 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Yun Park01deb2c2017-06-14 15:21:44 -07003877
3878 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
3879 qdf_nbuf_ipa_owned_set(skb);
3880
Leo Chang69c39692016-10-12 20:11:12 -07003881 /* WLAN subsystem is in suspend, put int queue */
3882 if (hdd_ipa->suspended) {
3883 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3884 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3885 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003886 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3887 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003888 pm_tx_cb->exception = true;
3889 pm_tx_cb->adapter = adapter;
3890 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003891 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003892 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3893 hdd_ipa->stats.num_tx_queued++;
3894 } else {
3895 /* Resume, put packet into WLAN TX */
3896 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003897 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003898 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3899 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003900 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003901 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003902 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003903 hdd_ipa->ipa_tx_forward++;
3904 }
3905 }
3906}
3907
3908/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003909 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3910 * @hdd_ipa: pointer to HDD IPA struct
3911 * @adapter: hdd adapter pointer
3912 * @desc: Firmware descriptor
3913 * @skb: Data buffer
3914 *
3915 * Return:
3916 * HDD_IPA_FORWARD_PKT_NONE
3917 * HDD_IPA_FORWARD_PKT_DISCARD
3918 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3919 *
3920 */
3921
3922static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3923 struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003924 struct hdd_adapter *adapter,
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003925 uint8_t desc,
3926 qdf_nbuf_t skb)
3927{
3928 int ret = HDD_IPA_FORWARD_PKT_NONE;
3929
3930 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303931 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003932 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
3933 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303934 /* Drop the packet*/
3935 hdd_ipa->stats.num_tx_fwd_err++;
3936 kfree_skb(skb);
3937 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3938 return ret;
3939 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003940 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3941 "Forward packet to Tx (fw_desc=%d)", desc);
3942 hdd_ipa->ipa_tx_forward++;
3943
3944 if ((desc & FW_RX_DESC_DISCARD_M)) {
3945 hdd_ipa_forward(hdd_ipa, adapter, skb);
3946 hdd_ipa->ipa_rx_internel_drop_count++;
3947 hdd_ipa->ipa_rx_discard++;
3948 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3949 } else {
3950 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003951
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003952 if (cloned_skb)
3953 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3954 else
3955 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3956 "%s: tx skb alloc failed",
3957 __func__);
3958 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3959 }
3960 }
3961
3962 return ret;
3963}
3964
3965/**
Yun Park637d6482016-10-05 10:51:33 -07003966 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 * @priv: pointer to private data registered with IPA (we register a
3968 * pointer to the global IPA context)
3969 * @evt: the IPA event which triggered the callback
3970 * @data: data associated with the event
3971 *
3972 * Return: None
3973 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003974static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003975 unsigned long data)
3976{
3977 struct hdd_ipa_priv *hdd_ipa = NULL;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003978 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303979 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 uint8_t iface_id;
3981 uint8_t session_id;
3982 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003983 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003984 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985
3986 hdd_ipa = (struct hdd_ipa_priv *)priv;
3987
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003988 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3989 return;
3990
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 switch (evt) {
3992 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303993 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003994
3995 /*
3996 * When SSR is going on or driver is unloading,
3997 * just drop the packets.
3998 */
3999 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4000 if (0 != status) {
4001 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4002 "Invalid context: drop packet");
4003 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4004 kfree_skb(skb);
4005 return;
4006 }
4007
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4009 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004010 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004011 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004012 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4013 session_id, iface_id);
4014 } else {
4015 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4016 }
4017
4018 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304019 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004020 "IPA_RECEIVE: Invalid iface_id: %u",
4021 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004022 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004023 "w2i -- skb",
4024 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004026 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 return;
4028 }
4029
4030 iface_context = &hdd_ipa->iface_context[iface_id];
4031 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004032 if (!adapter) {
4033 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4034 "IPA_RECEIVE: Adapter is NULL");
4035 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4036 kfree_skb(skb);
4037 return;
4038 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004039
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304040 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004041 "w2i -- skb",
4042 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4044 hdd_ipa->stats.num_rx_excep++;
4045 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4046 } else {
4047 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4048 }
4049
4050 iface_context->stats.num_rx_ipa_excep++;
4051
4052 /* Disable to forward Intra-BSS Rx packets when
4053 * ap_isolate=1 in hostapd.conf
4054 */
Yun Park046101c2016-09-02 15:32:14 -07004055 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056 /*
4057 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4058 * all Rx packets to IPA uC, which need to be forwarded
4059 * to other interface.
4060 * And, IPA driver will send back to WLAN host driver
4061 * through exception pipe with fw_desc field set by FW.
4062 * Here we are checking fw_desc field for FORWARD bit
4063 * set, and forward to Tx. Then copy to kernel stack
4064 * only when DISCARD bit is not set.
4065 */
4066 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004067 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4068 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4069 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004070 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004071 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004072 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 "Intra-BSS FWD is disabled-skip forward to Tx");
4074 }
4075
4076 hdd_ipa_send_skb_to_network(skb, adapter);
4077 break;
4078
4079 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304080 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081 "w2i cb wrong event: 0x%x", evt);
4082 return;
4083 }
4084}
4085
4086/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004087 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4088 * @priv: pointer to private data registered with IPA (we register a
4089 * pointer to the global IPA context)
4090 * @evt: the IPA event which triggered the callback
4091 * @data: data associated with the event
4092 *
4093 * Return: None
4094 */
4095static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4096 unsigned long data)
4097{
4098 cds_ssr_protect(__func__);
4099 __hdd_ipa_w2i_cb(priv, evt, data);
4100 cds_ssr_unprotect(__func__);
4101}
4102
4103/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4105 * @skb: packet buffer which was transmitted
4106 *
4107 * Return: None
4108 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304109void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004110{
4111 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004112 struct ipa_rx_data *ipa_tx_desc;
4113 struct hdd_ipa_tx_desc *tx_desc;
4114 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115
Yun Park52b2b992016-09-22 15:49:51 -07004116 if (!qdf_nbuf_ipa_owned_get(skb)) {
4117 dev_kfree_skb_any(skb);
4118 return;
4119 }
4120
4121 /* Get Tx desc pointer from SKB CB */
4122 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4123 tx_desc = hdd_ipa->tx_desc_list + id;
4124 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4125
4126 /* Return Tx Desc to IPA */
4127 ipa_free_skb(ipa_tx_desc);
4128
4129 /* Return to free tx desc list */
4130 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4131 tx_desc->ipa_tx_desc_ptr = NULL;
4132 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4133 hdd_ipa->stats.num_tx_desc_q_cnt--;
4134 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004135
4136 hdd_ipa->stats.num_tx_comp_cnt++;
4137
4138 atomic_dec(&hdd_ipa->tx_ref_cnt);
4139
4140 hdd_ipa_rm_try_release(hdd_ipa);
4141}
4142
4143/**
4144 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4145 * @iface_context: interface-specific IPA context
4146 * @ipa_tx_desc: packet data descriptor
4147 *
4148 * Return: None
4149 */
4150static void hdd_ipa_send_pkt_to_tl(
4151 struct hdd_ipa_iface_context *iface_context,
4152 struct ipa_rx_data *ipa_tx_desc)
4153{
4154 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004155 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304156 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004157 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004158
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304159 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160 adapter = iface_context->adapter;
4161 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304162 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163 ipa_free_skb(ipa_tx_desc);
4164 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304165 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004166 hdd_ipa_rm_try_release(hdd_ipa);
4167 return;
4168 }
4169
4170 /*
4171 * During CAC period, data packets shouldn't be sent over the air so
4172 * drop all the packets here
4173 */
hqu70708ab2017-10-10 17:52:01 +08004174 if (QDF_SAP_MODE == adapter->device_mode ||
4175 QDF_P2P_GO_MODE == adapter->device_mode) {
4176 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4177 ipa_free_skb(ipa_tx_desc);
4178 qdf_spin_unlock_bh(&iface_context->interface_lock);
4179 iface_context->stats.num_tx_cac_drop++;
4180 hdd_ipa_rm_try_release(hdd_ipa);
4181 return;
4182 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004183 }
4184
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004185 ++adapter->stats.tx_packets;
4186
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304187 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188
4189 skb = ipa_tx_desc->skb;
4190
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304191 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004192
4193 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304194 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004195 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304196 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004197 ipa_tx_desc->dma_addr
4198 + HDD_IPA_WLAN_FRAG_HEADER
4199 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200 ipa_tx_desc->skb->len -=
4201 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4202 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304203 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004204
Yun Park52b2b992016-09-22 15:49:51 -07004205 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4206 /* get free Tx desc and assign ipa_tx_desc pointer */
4207 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4208 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4209 struct hdd_ipa_tx_desc, link);
4210 list_del(&tx_desc->link);
4211 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4212 hdd_ipa->stats.num_tx_desc_q_cnt++;
4213 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4214 /* Store Tx Desc index into SKB CB */
4215 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4216 } else {
4217 hdd_ipa->stats.num_tx_desc_error++;
4218 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4219 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4220 ipa_free_skb(ipa_tx_desc);
4221 hdd_ipa_rm_try_release(hdd_ipa);
4222 return;
4223 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224
4225 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4226
Leo Changfdb45c32016-10-28 11:09:23 -07004227 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004228 (struct cdp_vdev *)iface_context->tl_context,
4229 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304231 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
jiad05c1e812017-08-01 16:48:52 +08004232 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004233 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004234 return;
4235 }
4236
4237 atomic_inc(&hdd_ipa->tx_ref_cnt);
4238
4239 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004240}
4241
4242/**
Leo Chang11545d62016-10-17 14:53:50 -07004243 * hdd_ipa_is_present() - get IPA hw status
4244 * @hdd_ctx: pointer to hdd context
4245 *
4246 * ipa_uc_reg_rdyCB is not directly designed to check
4247 * ipa hw status. This is an undocumented function which
4248 * has confirmed with IPA team.
4249 *
4250 * Return: true - ipa hw present
4251 * false - ipa hw not present
4252 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004253bool hdd_ipa_is_present(struct hdd_context *hdd_ctx)
Leo Chang11545d62016-10-17 14:53:50 -07004254{
4255 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004256 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004257 return true;
4258 else
4259 return false;
4260}
4261
4262/**
Leo Chang69c39692016-10-12 20:11:12 -07004263 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004264 * @work: pointer to the scheduled work
4265 *
4266 * Called during PM resume to send packets to TL which were queued
4267 * while host was in the process of suspending.
4268 *
4269 * Return: None
4270 */
Leo Chang69c39692016-10-12 20:11:12 -07004271static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004272{
4273 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4274 struct hdd_ipa_priv,
4275 pm_work);
4276 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304277 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 uint32_t dequeued = 0;
4279
Leo Chang69c39692016-10-12 20:11:12 -07004280 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4281 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304282 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304283 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4284 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304285 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004286
4287 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004289 if (pm_tx_cb->exception) {
4290 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4291 "FLUSH EXCEPTION");
Govind Singh1dab23b2017-08-12 13:31:00 +05304292 if (pm_tx_cb->adapter->dev)
4293 hdd_softap_hard_start_xmit(skb,
4294 pm_tx_cb->adapter->dev);
Govind Singh02075942017-08-15 11:13:28 +05304295 else
4296 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004297 } else {
4298 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004299 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004300 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304301 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004302 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304303 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004304 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4305 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004306
4307 hdd_ipa->stats.num_tx_dequeued += dequeued;
4308 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4309 hdd_ipa->stats.num_max_pm_queue = dequeued;
4310}
4311
4312/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004313 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004314 * @priv: pointer to private data registered with IPA (we register a
4315 * pointer to the interface-specific IPA context)
4316 * @evt: the IPA event which triggered the callback
4317 * @data: data associated with the event
4318 *
4319 * Return: None
4320 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004321static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004322 unsigned long data)
4323{
4324 struct hdd_ipa_priv *hdd_ipa = NULL;
4325 struct ipa_rx_data *ipa_tx_desc;
4326 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304327 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304329 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330
Mukul Sharma81661ae2015-10-30 20:26:02 +05304331 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004332 ipa_tx_desc = (struct ipa_rx_data *)data;
4333 hdd_ipa = iface_context->hdd_ipa;
4334
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004336 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4337 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338 iface_context->stats.num_tx_drop++;
4339 return;
4340 }
4341
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004342 /*
4343 * When SSR is going on or driver is unloading, just drop the packets.
4344 * During SSR, there is no use in queueing the packets as STA has to
4345 * connect back any way
4346 */
4347 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304348 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004349 ipa_free_skb(ipa_tx_desc);
4350 iface_context->stats.num_tx_drop++;
4351 return;
4352 }
4353
4354 skb = ipa_tx_desc->skb;
4355
Yun Parkb187d542016-11-14 18:10:04 -08004356 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4357 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358
4359 /*
4360 * If PROD resource is not requested here then there may be cases where
4361 * IPA hardware may be clocked down because of not having proper
4362 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4363 * workaround to request PROD resource while data is going over CONS
4364 * pipe to prevent the IPA hardware clockdown.
4365 */
4366 hdd_ipa_rm_request(hdd_ipa);
4367
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304368 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369 /*
4370 * If host is still suspended then queue the packets and these will be
4371 * drained later when resume completes. When packet is arrived here and
4372 * host is suspended, this means that there is already resume is in
4373 * progress.
4374 */
4375 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304376 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004377 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4378 pm_tx_cb->iface_context = iface_context;
4379 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304380 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004381 hdd_ipa->stats.num_tx_queued++;
4382
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304383 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004384 return;
4385 }
4386
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304387 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004388
4389 /*
4390 * If we are here means, host is not suspended, wait for the work queue
4391 * to finish.
4392 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394
4395 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4396}
4397
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004398/*
4399 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4400 * @priv: pointer to private data registered with IPA (we register a
4401 * pointer to the interface-specific IPA context)
4402 * @evt: the IPA event which triggered the callback
4403 * @data: data associated with the event
4404 *
4405 * Return: None
4406 */
4407static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4408 unsigned long data)
4409{
4410 cds_ssr_protect(__func__);
4411 __hdd_ipa_i2w_cb(priv, evt, data);
4412 cds_ssr_unprotect(__func__);
4413}
4414
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004415/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004416 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004417 * @hdd_ctx: Global HDD context
4418 *
4419 * Return: 0 on success, negativer errno on error
4420 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004421static int __hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004423 struct hdd_ipa_priv *hdd_ipa;
4424
4425 if (wlan_hdd_validate_context(hdd_ctx))
4426 return 0;
4427
4428 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429
4430 if (!hdd_ipa_is_enabled(hdd_ctx))
4431 return 0;
4432
4433 /*
4434 * Check if IPA is ready for suspend, If we are here means, there is
4435 * high chance that suspend would go through but just to avoid any race
4436 * condition after suspend started, these checks are conducted before
4437 * allowing to suspend.
4438 */
4439 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4440 return -EAGAIN;
4441
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304442 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443
4444 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304445 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004446 return -EAGAIN;
4447 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304448 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004449
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304450 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304452 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004453
4454 return 0;
4455}
4456
4457/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004458 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4459 * @hdd_ctx: Global HDD context
4460 *
4461 * Return: 0 on success, negativer errno on error
4462 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004463int hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004464{
4465 int ret;
4466
4467 cds_ssr_protect(__func__);
4468 ret = __hdd_ipa_suspend(hdd_ctx);
4469 cds_ssr_unprotect(__func__);
4470
4471 return ret;
4472}
4473
4474/**
4475 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004476 * hdd_ctx: Global HDD context
4477 *
4478 * Return: 0 on success, negative errno on error
4479 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004480static int __hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004482 struct hdd_ipa_priv *hdd_ipa;
4483
4484 if (wlan_hdd_validate_context(hdd_ctx))
4485 return 0;
4486
4487 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004488
4489 if (!hdd_ipa_is_enabled(hdd_ctx))
4490 return 0;
4491
4492 schedule_work(&hdd_ipa->pm_work);
4493
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304494 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004495 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304496 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004497
4498 return 0;
4499}
4500
4501/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004502 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4503 * hdd_ctx: Global HDD context
4504 *
4505 * Return: 0 on success, negative errno on error
4506 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004507int hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004508{
4509 int ret;
4510
4511 cds_ssr_protect(__func__);
4512 ret = __hdd_ipa_resume(hdd_ctx);
4513 cds_ssr_unprotect(__func__);
4514
4515 return ret;
4516}
4517
4518/**
Yun Park52b2b992016-09-22 15:49:51 -07004519 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4520 * @hdd_ipa: Global HDD IPA context
4521 *
4522 * Return: 0 on success, negative errno on error
4523 */
4524static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4525{
4526 int i;
4527 uint32_t max_desc_cnt;
4528 struct hdd_ipa_tx_desc *tmp_desc;
4529
Yun Parkd9c528e2017-08-30 16:34:57 -07004530 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
Yun Park52b2b992016-09-22 15:49:51 -07004531
4532 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4533
jiad14fe4fb2017-08-08 13:33:14 +08004534 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc) *
Yun Parkd9c528e2017-08-30 16:34:57 -07004535 max_desc_cnt);
Yun Park52b2b992016-09-22 15:49:51 -07004536
4537 if (!tmp_desc) {
4538 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkd9c528e2017-08-30 16:34:57 -07004539 "Free Tx descriptor allocation failed");
Yun Park52b2b992016-09-22 15:49:51 -07004540 return -ENOMEM;
4541 }
4542
4543 hdd_ipa->tx_desc_list = tmp_desc;
4544
4545 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004546 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004547 tmp_desc->id = i;
4548 tmp_desc->ipa_tx_desc_ptr = NULL;
4549 list_add_tail(&tmp_desc->link,
4550 &hdd_ipa->free_tx_desc_head);
4551 tmp_desc++;
4552 }
4553
4554 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4555 hdd_ipa->stats.num_tx_desc_error = 0;
4556
4557 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4558
4559 return 0;
4560}
4561
4562/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004563 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4564 * @hdd_ipa: Global HDD IPA context
4565 *
4566 * Return: 0 on success, negative errno on error
4567 */
4568static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4569{
4570 int i, ret = 0;
4571 struct ipa_sys_connect_params *ipa;
4572 uint32_t desc_fifo_sz;
4573
4574 /* The maximum number of descriptors that can be provided to a BAM at
4575 * once is one less than the total number of descriptors that the buffer
4576 * can contain.
4577 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4578 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4579 * be provided at once.
4580 * Because of above requirement, one extra descriptor will be added to
4581 * make sure hardware always has one descriptor.
4582 */
4583 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4584 + sizeof(struct sps_iovec);
4585
4586 /*setup TX pipes */
4587 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4588 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4589
4590 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4591 ipa->desc_fifo_sz = desc_fifo_sz;
4592 ipa->priv = &hdd_ipa->iface_context[i];
4593 ipa->notify = hdd_ipa_i2w_cb;
4594
4595 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4596 ipa->ipa_ep_cfg.hdr.hdr_len =
4597 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4598 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4599 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4600 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4601 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4602 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4603 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4604 } else {
4605 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4606 }
4607 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4608
4609 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4610 ipa->keep_ipa_awake = 1;
4611
4612 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4613 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004614 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4615 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004616 goto setup_sys_pipe_fail;
4617 }
4618 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4619 }
4620
4621 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4622 /*
4623 * Hard code it here, this can be extended if in case
4624 * PROD pipe is also per interface.
4625 * Right now there is no advantage of doing this.
4626 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4628
Yun Parkb4f591d2017-03-29 15:51:01 -07004629 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004630
4631 ipa->desc_fifo_sz = desc_fifo_sz;
4632 ipa->priv = hdd_ipa;
4633 ipa->notify = hdd_ipa_w2i_cb;
4634
4635 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4636 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4637 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4638 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4639
4640 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4641 ipa->keep_ipa_awake = 1;
4642
4643 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4644 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304645 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004646 "Failed for RX pipe: %d", ret);
4647 goto setup_sys_pipe_fail;
4648 }
4649 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4650 }
4651
Yun Parkd9c528e2017-08-30 16:34:57 -07004652 /* Allocate free Tx desc list */
Yun Park52b2b992016-09-22 15:49:51 -07004653 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4654 if (ret)
4655 goto setup_sys_pipe_fail;
4656
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004657 return ret;
4658
4659setup_sys_pipe_fail:
4660
4661 while (--i >= 0) {
4662 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304663 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004664 sizeof(struct hdd_ipa_sys_pipe));
4665 }
4666
4667 return ret;
4668}
4669
4670/**
4671 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4672 * @hdd_ipa: Global HDD IPA context
4673 *
4674 * Return: None
4675 */
4676static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4677{
4678 int ret = 0, i;
Yun Parkd9c528e2017-08-30 16:34:57 -07004679 uint32_t max_desc_cnt;
Yun Park52b2b992016-09-22 15:49:51 -07004680 struct hdd_ipa_tx_desc *tmp_desc;
4681 struct ipa_rx_data *ipa_tx_desc;
4682
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004683 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4684 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004685 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4686 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004687 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304688 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689 ret);
4690
4691 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4692 }
4693 }
Yun Park52b2b992016-09-22 15:49:51 -07004694
4695 if (hdd_ipa->tx_desc_list) {
Yun Parkd9c528e2017-08-30 16:34:57 -07004696 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4697
Yun Park52b2b992016-09-22 15:49:51 -07004698 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004699 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004700 tmp_desc = hdd_ipa->tx_desc_list + i;
4701 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4702 if (ipa_tx_desc)
4703 ipa_free_skb(ipa_tx_desc);
4704 }
4705 tmp_desc = hdd_ipa->tx_desc_list;
4706 hdd_ipa->tx_desc_list = NULL;
4707 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4708 hdd_ipa->stats.num_tx_desc_error = 0;
4709 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4710 qdf_mem_free(tmp_desc);
4711 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712}
4713
4714/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004715 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4716 * @iface_context: interface-specific IPA context
4717 *
4718 * Return: None
4719 */
4720static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4721{
Yun Parkfec73dc2017-09-06 10:40:07 -07004722 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
4723
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004724 if (iface_context == NULL)
4725 return;
4726
Yun Parkb4f591d2017-03-29 15:51:01 -07004727 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4728 iface_context->adapter->dev->name,
4729 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004730
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304731 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004732 iface_context->adapter->ipa_context = NULL;
4733 iface_context->adapter = NULL;
4734 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304735 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004736 iface_context->ifa_address = 0;
4737 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304738 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004739 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304740 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004741 }
4742 iface_context->hdd_ipa->num_iface--;
Yun Parkfec73dc2017-09-06 10:40:07 -07004743 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: num_iface=%d",
4744 iface_context->hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004745}
4746
4747/**
4748 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4749 * @hdd_ipa: HDD IPA global context
4750 * @adapter: Interface upon which IPA is being setup
4751 * @sta_id: Station ID of the API instance
4752 *
4753 * Return: 0 on success, negative errno value on error
4754 */
4755static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004756 struct hdd_adapter *adapter, uint8_t sta_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004757{
4758 struct hdd_ipa_iface_context *iface_context = NULL;
4759 void *tl_context = NULL;
4760 int i, ret = 0;
4761
Yun Parkfec73dc2017-09-06 10:40:07 -07004762 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
4763
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4765 * channel change indication. Since these indications are sent by lower
4766 * layer as SAP updates and IPA doesn't have to do anything for these
4767 * updates so ignoring!
4768 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004769 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004770 return 0;
4771
4772 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4773 if (hdd_ipa->iface_context[i].adapter == NULL) {
4774 iface_context = &(hdd_ipa->iface_context[i]);
4775 break;
4776 }
4777 }
4778
4779 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304780 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004781 "All the IPA interfaces are in use");
4782 ret = -ENOMEM;
4783 goto end;
4784 }
4785
4786 adapter->ipa_context = iface_context;
4787 iface_context->adapter = adapter;
4788 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004789 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07004790 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004791 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304792 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793 "Not able to get TL context sta_id: %d", sta_id);
4794 ret = -EINVAL;
4795 goto end;
4796 }
4797
4798 iface_context->tl_context = tl_context;
4799
Yun Parkb4f591d2017-03-29 15:51:01 -07004800 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4801 adapter->dev->name, adapter->dev->dev_addr,
4802 iface_context->prod_client,
4803 iface_context->cons_client,
4804 adapter->sessionId,
4805 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004806 if (ret)
4807 goto end;
4808
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004809 hdd_ipa->num_iface++;
Yun Parkfec73dc2017-09-06 10:40:07 -07004810
4811 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: num_iface=%d",
4812 hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004813 return ret;
4814
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004815end:
4816 if (iface_context)
4817 hdd_ipa_cleanup_iface(iface_context);
4818 return ret;
4819}
4820
Yun Parka27049a2016-10-11 12:30:49 -07004821#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004822/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004823 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Jeff Johnson4929cd92017-10-06 19:21:57 -07004824 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004825 * @mcc_mode: 0=MCC/1=SCC
4826 *
4827 * Return: 0 on success, negative errno value on error
4828 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07004829static int __hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx,
4830 bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004831{
4832 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304833 QDF_STATUS status;
Jeff Johnson089d0432017-10-02 13:27:21 -07004834 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004835 struct ipa_msg_meta meta;
4836 struct ipa_wlan_msg *msg;
4837 int ret;
4838
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004839 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004840 return -EINVAL;
4841
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004842 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4843 return -EINVAL;
4844
4845 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004847 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304848 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson089d0432017-10-02 13:27:21 -07004849 adapter = adapter_node->adapter;
4850 if (adapter->device_mode == QDF_STA_MODE ||
4851 adapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004852 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnson089d0432017-10-02 13:27:21 -07004853 adapter->device_mode);
4854 hdd_deinit_tx_rx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004855 }
4856 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004857 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004858 adapter_node = next;
4859 }
4860 }
4861
4862 /* Send SCC/MCC Switching event to IPA */
4863 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304864 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004865 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004866 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004867 return -ENOMEM;
4868 }
4869
4870 meta.msg_type = mcc_mode ?
4871 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08004872 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004873
4874 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4875
4876 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004877 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304879 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880 }
4881
4882 return ret;
4883}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004884
4885/**
4886 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
4887 * @mcc_mode: 0=MCC/1=SCC
4888 *
4889 * Return: 0 on success, negative errno value on error
4890 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004891int hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004892{
4893 int ret;
4894
4895 cds_ssr_protect(__func__);
4896 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
4897 cds_ssr_unprotect(__func__);
4898
4899 return ret;
4900}
Yun Parka27049a2016-10-11 12:30:49 -07004901#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004902
4903/**
4904 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
4905 * @event: IPA WLAN event to be converted to a string
4906 *
4907 * Return: ASCII string representing the IPA WLAN event
4908 */
4909static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
4910{
4911 switch (event) {
4912 case WLAN_CLIENT_CONNECT:
4913 return "WLAN_CLIENT_CONNECT";
4914 case WLAN_CLIENT_DISCONNECT:
4915 return "WLAN_CLIENT_DISCONNECT";
4916 case WLAN_CLIENT_POWER_SAVE_MODE:
4917 return "WLAN_CLIENT_POWER_SAVE_MODE";
4918 case WLAN_CLIENT_NORMAL_MODE:
4919 return "WLAN_CLIENT_NORMAL_MODE";
4920 case SW_ROUTING_ENABLE:
4921 return "SW_ROUTING_ENABLE";
4922 case SW_ROUTING_DISABLE:
4923 return "SW_ROUTING_DISABLE";
4924 case WLAN_AP_CONNECT:
4925 return "WLAN_AP_CONNECT";
4926 case WLAN_AP_DISCONNECT:
4927 return "WLAN_AP_DISCONNECT";
4928 case WLAN_STA_CONNECT:
4929 return "WLAN_STA_CONNECT";
4930 case WLAN_STA_DISCONNECT:
4931 return "WLAN_STA_DISCONNECT";
4932 case WLAN_CLIENT_CONNECT_EX:
4933 return "WLAN_CLIENT_CONNECT_EX";
4934
4935 case IPA_WLAN_EVENT_MAX:
4936 default:
4937 return "UNKNOWN";
4938 }
4939}
4940
4941/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004942 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
4943 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
4944 *
4945 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
4946 */
4947static enum ipa_wlan_event
4948hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
4949{
4950 enum ipa_wlan_event ipa_event;
4951
4952 switch (hdd_ipa_event_type) {
4953 case HDD_IPA_CLIENT_CONNECT:
4954 ipa_event = WLAN_CLIENT_CONNECT;
4955 break;
4956 case HDD_IPA_CLIENT_DISCONNECT:
4957 ipa_event = WLAN_CLIENT_DISCONNECT;
4958 break;
4959 case HDD_IPA_AP_CONNECT:
4960 ipa_event = WLAN_AP_CONNECT;
4961 break;
4962 case HDD_IPA_AP_DISCONNECT:
4963 ipa_event = WLAN_AP_DISCONNECT;
4964 break;
4965 case HDD_IPA_STA_CONNECT:
4966 ipa_event = WLAN_STA_CONNECT;
4967 break;
4968 case HDD_IPA_STA_DISCONNECT:
4969 ipa_event = WLAN_STA_DISCONNECT;
4970 break;
4971 case HDD_IPA_CLIENT_CONNECT_EX:
4972 ipa_event = WLAN_CLIENT_CONNECT_EX;
4973 break;
4974 case HDD_IPA_WLAN_EVENT_MAX:
4975 default:
4976 ipa_event = IPA_WLAN_EVENT_MAX;
4977 break;
4978 }
4979 return ipa_event;
4980
4981}
4982
4983/**
4984 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985 * @adapter: adapter upon which the event was received
4986 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07004987 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004988 * @mac_address: MAC address associated with the event
4989 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07004990 * This function is meant to be called from within wlan_hdd_ipa.c
4991 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004992 * Return: 0 on success, negative errno value on error
4993 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07004994static int __hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995 enum ipa_wlan_event type, uint8_t *mac_addr)
4996{
4997 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4998 struct ipa_msg_meta meta;
4999 struct ipa_wlan_msg *msg;
5000 struct ipa_wlan_msg_ex *msg_ex = NULL;
5001 int ret;
5002
Yun Parkfec73dc2017-09-06 10:40:07 -07005003 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005004 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5005 mac_addr, sta_id);
5006
5007 if (type >= IPA_WLAN_EVENT_MAX)
5008 return -EINVAL;
5009
5010 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5011 return -EINVAL;
5012
5013 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305014 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005015 return -EINVAL;
5016 }
5017
5018 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5019 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005020 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005021 return 0;
5022 }
5023
5024 /*
5025 * During IPA UC resource loading/unloading new events can be issued.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026 */
Yun Park777d7242017-03-30 15:38:33 -07005027 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5028 (hdd_ipa->resource_loading || hdd_ipa->resource_unloading)) {
5029 unsigned int pending_event_count;
5030 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005031
Yun Park777d7242017-03-30 15:38:33 -07005032 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5033 "%s:IPA resource %s inprogress",
5034 hdd_ipa_wlan_event_to_str(type),
5035 hdd_ipa->resource_loading ?
5036 "load" : "unload");
5037
5038 /* Wait until completion of the long/unloading */
5039 ret = wait_for_completion_timeout(&hdd_ipa->ipa_resource_comp,
5040 msecs_to_jiffies(IPA_RESOURCE_COMP_WAIT_TIME));
5041 if (!ret) {
5042 /*
5043 * If timed out, store the events separately and
5044 * handle them later.
5045 */
Yun Park64c405e2017-01-10 22:35:51 -08005046 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park777d7242017-03-30 15:38:33 -07005047 "IPA resource %s timed out",
5048 hdd_ipa->resource_loading ?
5049 "load" : "unload");
Yun Park7c4f31b2016-11-30 10:09:21 -08005050
Yun Park777d7242017-03-30 15:38:33 -07005051 if (hdd_ipa->resource_loading) {
5052 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005053
Yun Park777d7242017-03-30 15:38:33 -07005054 pending_event_count =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005055 qdf_list_size(&hdd_ipa->pending_event);
Yun Park777d7242017-03-30 15:38:33 -07005056 if (pending_event_count >=
5057 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
5058 hdd_debug(
5059 "Reached max pending event count");
5060 qdf_list_remove_front(
5061 &hdd_ipa->pending_event,
5062 (qdf_list_node_t **)&pending_event);
5063 } else {
5064 pending_event =
5065 (struct ipa_uc_pending_event *)
5066 qdf_mem_malloc(sizeof(
5067 struct ipa_uc_pending_event));
5068 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005069
Yun Park777d7242017-03-30 15:38:33 -07005070 if (!pending_event) {
5071 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5072 "Pending event memory alloc fail");
5073 qdf_mutex_release(&hdd_ipa->ipa_lock);
5074 return -ENOMEM;
5075 }
5076
5077 pending_event->adapter = adapter;
5078 pending_event->sta_id = sta_id;
5079 pending_event->type = type;
5080 qdf_mem_copy(pending_event->mac_addr,
5081 mac_addr, QDF_MAC_ADDR_SIZE);
5082 qdf_list_insert_back(&hdd_ipa->pending_event,
5083 &pending_event->node);
5084
Yun Park64c405e2017-01-10 22:35:51 -08005085 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005086 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005087 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088 }
Jeff Johnson4929cd92017-10-06 19:21:57 -07005089 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5090 "IPA resource %s completed",
5091 hdd_ipa->resource_loading ?
5092 "load" : "unload");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 }
5094
5095 hdd_ipa->stats.event[type]++;
5096
Leo Chang3bc8fed2015-11-13 10:59:47 -08005097 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 switch (type) {
5099 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005100 qdf_mutex_acquire(&hdd_ipa->event_lock);
5101
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005102 /* STA already connected and without disconnect, connect again
5103 * This is Roaming scenario
5104 */
5105 if (hdd_ipa->sta_connected)
5106 hdd_ipa_cleanup_iface(adapter->ipa_context);
5107
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005108 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5109 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305110 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005111 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005112 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113
Yun Park8f289c82016-10-18 16:38:21 -07005114 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5115 (hdd_ipa->sap_num_connected_sta > 0) &&
5116 !hdd_ipa->sta_connected) {
5117 qdf_mutex_release(&hdd_ipa->event_lock);
5118 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005119 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005120 qdf_mutex_acquire(&hdd_ipa->event_lock);
5121 }
5122
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005123 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005124 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005125 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005126
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005127 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005128
5129 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005130
5131 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sta_connected=%d",
5132 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133 break;
5134
5135 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005136 qdf_mutex_acquire(&hdd_ipa->event_lock);
5137
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 /* For DFS channel we get two start_bss event (before and after
5139 * CAC). Also when ACS range includes both DFS and non DFS
5140 * channels, we could possibly change channel many times due to
5141 * RADAR detection and chosen channel may not be a DFS channels.
5142 * So dont return error here. Just discard the event.
5143 */
Yun Park8f289c82016-10-18 16:38:21 -07005144 if (adapter->ipa_context) {
5145 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005146 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005147 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005148
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5150 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005151 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005152 hdd_err("%s: Evt: %d, Interface setup failed",
5153 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005154 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005155 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005156
Yun Park8f289c82016-10-18 16:38:21 -07005157 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5158 qdf_mutex_release(&hdd_ipa->event_lock);
5159 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005160 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005161 qdf_mutex_acquire(&hdd_ipa->event_lock);
5162 }
5163
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005164 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005166 (adapter->ipa_context))->iface_id;
5167
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305168 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005169 break;
5170
5171 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305172 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005173
5174 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005175 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005176 hdd_err("%s: Evt: %d, STA already disconnected",
5177 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005178 return -EINVAL;
5179 }
Yun Parka37592b2016-06-11 17:10:28 -07005180
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005182
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005183 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005184 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005185 msg_ex->name);
5186 } else {
5187 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005188 if (!hdd_ipa->num_iface &&
5189 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305190 hdd_ipa->activated_fw_pipe) &&
5191 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005193 }
5194
Yun Park74127cf2016-09-18 11:22:41 -07005195 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5196 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005197 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005199 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005200 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005201 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5202 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005203 }
5204
Yun Park8f289c82016-10-18 16:38:21 -07005205 hdd_ipa_cleanup_iface(adapter->ipa_context);
5206
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305207 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005208
5209 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sta_connected=%d",
5210 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005211 break;
5212
5213 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005214 qdf_mutex_acquire(&hdd_ipa->event_lock);
5215
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005217 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005218 hdd_err("%s: Evt: %d, SAP already disconnected",
5219 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005220 return -EINVAL;
5221 }
5222
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 if ((!hdd_ipa->num_iface) &&
5224 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305225 hdd_ipa->activated_fw_pipe) &&
5226 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005227 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005228 /*
5229 * We disable WDI pipes directly here since
5230 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5231 * processed when unloading WLAN driver is in
5232 * progress
5233 */
5234 hdd_ipa_uc_disable_pipes(hdd_ipa);
5235 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305236 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005237 "NO INTF left but still pipe clean up");
5238 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5239 }
5240 }
5241
5242 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005243 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005245 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005246 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005247 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5248 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 }
Yun Parka37592b2016-06-11 17:10:28 -07005250
Yun Park8f289c82016-10-18 16:38:21 -07005251 hdd_ipa_cleanup_iface(adapter->ipa_context);
5252
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305253 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254 break;
5255
5256 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005257 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005258 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005259 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305260 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005261 return 0;
5262 }
5263
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305264 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5266 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005267 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305268 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005269 "%s: STA ID %d found, not valid",
5270 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271 return 0;
5272 }
Yun Park312f71a2015-12-08 10:22:42 -08005273
5274 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005275 if (hdd_ipa->sap_num_connected_sta == 0 &&
5276 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005277 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005278 hdd_ipa->sta_connected) {
5279 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005280 hdd_ipa_uc_offload_enable_disable(
5281 hdd_get_adapter(hdd_ipa->hdd_ctx,
5282 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005283 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005284 qdf_mutex_acquire(&hdd_ipa->event_lock);
5285 }
Yun Parka37592b2016-06-11 17:10:28 -07005286
Yun Park312f71a2015-12-08 10:22:42 -08005287 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5288 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305289 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005290 "%s: handle 1st con ret %d",
5291 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005292
5293 if (hdd_ipa_uc_sta_is_enabled(
5294 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005295 hdd_ipa->sta_connected) {
5296 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005297 hdd_ipa_uc_offload_enable_disable(
5298 hdd_get_adapter(
5299 hdd_ipa->hdd_ctx,
5300 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005301 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005302 } else {
5303 qdf_mutex_release(&hdd_ipa->event_lock);
5304 }
Yun Parka37592b2016-06-11 17:10:28 -07005305
Yun Park312f71a2015-12-08 10:22:42 -08005306 return ret;
5307 }
5308 }
5309
5310 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005311
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305312 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005313
5314 meta.msg_type = type;
5315 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5316 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305317 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005318
5319 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305320 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005321 "msg_ex allocation failed");
5322 return -ENOMEM;
5323 }
5324 strlcpy(msg_ex->name, adapter->dev->name,
5325 IPA_RESOURCE_NAME_MAX);
5326 msg_ex->num_of_attribs = 1;
5327 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5328 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5329 msg_ex->attribs[0].offset =
5330 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5331 } else {
5332 msg_ex->attribs[0].offset =
5333 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5334 }
5335 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5336 IPA_MAC_ADDR_SIZE);
5337
5338 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5339
5340 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005341 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305342 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305343 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005344 return ret;
5345 }
5346 hdd_ipa->stats.num_send_msg++;
Yun Parkfec73dc2017-09-06 10:40:07 -07005347
5348 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sap_num_connected_sta=%d",
5349 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005350 return ret;
5351
5352 case WLAN_CLIENT_DISCONNECT:
5353 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005354 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005355 "%s: IPA UC OFFLOAD NOT ENABLED",
5356 msg_ex->name);
5357 return 0;
5358 }
5359
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305360 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Park73ea8bb2017-08-25 07:27:39 -07005361 if (!hdd_ipa->sap_num_connected_sta) {
5362 qdf_mutex_release(&hdd_ipa->event_lock);
5363 hdd_err("%s: Evt: %d, Client already disconnected",
5364 msg_ex->name, meta.msg_type);
5365 return 0;
5366 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005367 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005368 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305369 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005370 "%s: STA ID %d NOT found, not valid",
5371 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005372 return 0;
5373 }
5374 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005375
Yun Park9b5030f2016-11-08 12:02:37 -08005376 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005377 if (!hdd_ipa->sap_num_connected_sta &&
5378 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005379 if ((false == hdd_ipa->resource_unloading)
5380 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305381 hdd_ipa->activated_fw_pipe) &&
5382 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005383 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5384 }
5385
Yun Park9b5030f2016-11-08 12:02:37 -08005386 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005387 hdd_ipa->sta_connected) {
5388 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005389 hdd_ipa_uc_offload_enable_disable(
5390 hdd_get_adapter(hdd_ipa->hdd_ctx,
5391 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005392 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005393 } else {
5394 qdf_mutex_release(&hdd_ipa->event_lock);
5395 }
Yun Park8f289c82016-10-18 16:38:21 -07005396 } else {
5397 qdf_mutex_release(&hdd_ipa->event_lock);
5398 }
Yun Parkfec73dc2017-09-06 10:40:07 -07005399
5400 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sap_num_connected_sta=%d",
5401 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005402 break;
5403
5404 default:
5405 return 0;
5406 }
5407
5408 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305409 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305411 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412 return -ENOMEM;
5413 }
5414
5415 meta.msg_type = type;
5416 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5417 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5418
Srinivas Girigowda97852372017-03-06 16:52:59 -08005419 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005420 msg->name, meta.msg_type);
5421
5422 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5423
5424 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005425 hdd_err("%s: Evt: %d fail:%d",
5426 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305427 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005428 return ret;
5429 }
5430
5431 hdd_ipa->stats.num_send_msg++;
5432
5433end:
5434 return ret;
5435}
5436
5437/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005438 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005439 * @adapter: adapter upon which the event was received
5440 * @sta_id: station id for the event
5441 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5442 * @mac_address: MAC address associated with the event
5443 *
5444 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5445 *
5446 * Return: 0 on success, negative errno value on error
5447 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005448int hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005449 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5450{
5451 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005452 int ret = 0;
5453
5454 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005455
Leo Changa202b522016-10-14 16:13:50 -07005456 /* Data path offload only support for STA and SAP mode */
5457 if ((QDF_STA_MODE == adapter->device_mode) ||
5458 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005459 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005460
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005461 cds_ssr_unprotect(__func__);
5462
5463 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005464}
5465
5466/**
5467 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5468 * @hdd_ipa: Global HDD IPA context
5469 *
5470 * Return: None
5471 */
5472static void
5473hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5474{
5475 unsigned int pending_event_count;
5476 struct ipa_uc_pending_event *pending_event = NULL;
5477
5478 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005479 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005480 "%s, Pending Event Count %d", __func__, pending_event_count);
5481 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005482 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005483 "%s, No Pending Event", __func__);
5484 return;
5485 }
5486
5487 qdf_list_remove_front(&hdd_ipa->pending_event,
5488 (qdf_list_node_t **)&pending_event);
5489 while (pending_event != NULL) {
5490 __hdd_ipa_wlan_evt(pending_event->adapter,
5491 pending_event->type,
5492 pending_event->sta_id,
5493 pending_event->mac_addr);
5494 qdf_mem_free(pending_event);
5495 pending_event = NULL;
5496 qdf_list_remove_front(&hdd_ipa->pending_event,
5497 (qdf_list_node_t **)&pending_event);
5498 }
5499}
5500
5501/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005502 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5503 * @state: IPA RM state value
5504 *
5505 * Return: ASCII string representing the IPA RM state
5506 */
5507static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5508{
5509 switch (state) {
5510 case HDD_IPA_RM_RELEASED:
5511 return "RELEASED";
5512 case HDD_IPA_RM_GRANT_PENDING:
5513 return "GRANT_PENDING";
5514 case HDD_IPA_RM_GRANTED:
5515 return "GRANTED";
5516 }
5517
5518 return "UNKNOWN";
5519}
5520
5521/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005522 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005523 * @hdd_ctx: HDD global context
5524 *
5525 * Allocate hdd_ipa resources, ipa pipe resource and register
5526 * wlan interface with IPA module.
5527 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305528 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005530static QDF_STATUS __hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005531{
5532 struct hdd_ipa_priv *hdd_ipa = NULL;
5533 int ret, i;
5534 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005535 struct ol_txrx_pdev_t *pdev = NULL;
Yun Park66f24c42017-03-20 10:39:47 -07005536 struct ipa_rm_perf_profile profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005537
Yun Parkfec73dc2017-09-06 10:40:07 -07005538 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
5539
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005540 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305541 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005542
Yun Parkbaa62862017-01-18 13:43:34 -08005543 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005544 if (!pdev) {
5545 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5546 goto fail_return;
5547 }
5548
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305549 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005550 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305551 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005552 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005553 }
5554
5555 hdd_ctx->hdd_ipa = hdd_ipa;
5556 ghdd_ipa = hdd_ipa;
5557 hdd_ipa->hdd_ctx = hdd_ctx;
5558 hdd_ipa->num_iface = 0;
5559
5560 /* Create the interface context */
5561 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5562 iface_context = &hdd_ipa->iface_context[i];
5563 iface_context->hdd_ipa = hdd_ipa;
5564 iface_context->cons_client =
5565 hdd_ipa_adapter_2_client[i].cons_client;
5566 iface_context->prod_client =
5567 hdd_ipa_adapter_2_client[i].prod_client;
5568 iface_context->iface_id = i;
5569 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305570 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005571 }
5572 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005573 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5574 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005575 }
5576
Leo Chang69c39692016-10-12 20:11:12 -07005577 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305578 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005579 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305580 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005581 qdf_list_create(&hdd_ipa->pending_event, 1000);
5582 qdf_mutex_create(&hdd_ipa->event_lock);
5583 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005584
5585 ret = hdd_ipa_setup_rm(hdd_ipa);
5586 if (ret)
5587 goto fail_setup_rm;
5588
5589 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5590 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305591 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005592 hdd_ipa->sap_num_connected_sta = 0;
5593 hdd_ipa->ipa_tx_packets_diff = 0;
5594 hdd_ipa->ipa_rx_packets_diff = 0;
5595 hdd_ipa->ipa_p_tx_packets = 0;
5596 hdd_ipa->ipa_p_rx_packets = 0;
5597 hdd_ipa->resource_loading = false;
5598 hdd_ipa->resource_unloading = false;
5599 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005600 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005601 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602 /* Setup IPA sys_pipe for MCC */
5603 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5604 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5605 if (ret)
5606 goto fail_create_sys_pipe;
5607 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005608 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5609 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005610
5611 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5612 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5613 hdd_ipa_uc_fw_op_event_handler);
5614 hdd_ipa->uc_op_work[i].msg = NULL;
5615 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005616 } else {
5617 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5618 if (ret)
5619 goto fail_create_sys_pipe;
5620 }
5621
Yun Park66f24c42017-03-20 10:39:47 -07005622 /* When IPA clock scaling is disabled, initialze maximum clock */
5623 if (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)) {
5624 profile.max_supported_bandwidth_mbps = 800;
5625 hdd_debug("IPA clock scaling is disabled.");
5626 hdd_debug("Set initial CONS/PROD perf: %d",
5627 profile.max_supported_bandwidth_mbps);
5628 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
5629 &profile);
5630 if (ret) {
5631 hdd_err("RM CONS set perf profile failed: %d", ret);
5632 goto fail_create_sys_pipe;
5633 }
5634
5635 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
5636 &profile);
5637 if (ret) {
5638 hdd_err("RM PROD set perf profile failed: %d", ret);
5639 goto fail_create_sys_pipe;
5640 }
5641 }
5642
Yun Park777d7242017-03-30 15:38:33 -07005643 init_completion(&hdd_ipa->ipa_resource_comp);
5644
Yun Parkfec73dc2017-09-06 10:40:07 -07005645 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: success");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305646 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005647
5648fail_create_sys_pipe:
5649 hdd_ipa_destroy_rm_resource(hdd_ipa);
5650fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305651 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305652 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005653 hdd_ctx->hdd_ipa = NULL;
5654 ghdd_ipa = NULL;
5655fail_return:
Yun Parkfec73dc2017-09-06 10:40:07 -07005656 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: fail");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305657 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005658}
5659
5660/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005661 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5662 * @hdd_ctx: HDD global context
5663 *
5664 * Allocate hdd_ipa resources, ipa pipe resource and register
5665 * wlan interface with IPA module.
5666 *
5667 * Return: QDF_STATUS enumeration
5668 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005669QDF_STATUS hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005670{
5671 QDF_STATUS ret;
5672
5673 cds_ssr_protect(__func__);
5674 ret = __hdd_ipa_init(hdd_ctx);
5675 cds_ssr_unprotect(__func__);
5676
5677 return ret;
5678}
5679
Arun Khandavallicc544b32017-01-30 19:52:16 +05305680
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005681/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305682 * __hdd_ipa_flush - flush IPA exception path SKB's
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683 * @hdd_ctx: HDD global context
5684 *
Govind Singh1dab23b2017-08-12 13:31:00 +05305685 * Return: none
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005686 */
Govind Singh1dab23b2017-08-12 13:31:00 +05305687static void __hdd_ipa_flush(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005688{
5689 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305690 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5692
5693 if (!hdd_ipa_is_enabled(hdd_ctx))
Govind Singh1dab23b2017-08-12 13:31:00 +05305694 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005695
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005696 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305698 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699
Nirav Shahcbc6d722016-03-01 16:24:53 +05305700 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5701 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305702 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703
5704 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005705 if (pm_tx_cb->ipa_tx_desc)
5706 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005707
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305708 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305710 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Govind Singh1dab23b2017-08-12 13:31:00 +05305711}
5712
5713/**
5714 * __hdd_ipa_cleanup - IPA cleanup function
5715 * @hdd_ctx: HDD global context
5716 *
5717 * Return: QDF_STATUS enumeration
5718 */
5719static QDF_STATUS __hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
5720{
5721 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5722 int i;
5723 struct hdd_ipa_iface_context *iface_context = NULL;
5724
5725 if (!hdd_ipa_is_enabled(hdd_ctx))
5726 return QDF_STATUS_SUCCESS;
5727
5728 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5729 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5730 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5731 }
5732
5733 /* Teardown IPA sys_pipe for MCC */
5734 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5735 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5736
5737 hdd_ipa_destroy_rm_resource(hdd_ipa);
5738
5739 __hdd_ipa_flush(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005740
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305741 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005742 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743
5744 /* destory the interface lock */
5745 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5746 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305747 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005748 }
5749
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005750 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005751 if (ipa_uc_dereg_rdyCB())
5752 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5753 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005754 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305755 qdf_mutex_destroy(&hdd_ipa->event_lock);
5756 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkd8fb1a82017-10-13 16:48:20 -07005757 qdf_list_destroy(&hdd_ipa->pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005758
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005759 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5760 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5761 hdd_ipa->uc_op_work[i].msg = NULL;
5762 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 }
5764
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305765 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005766 hdd_ctx->hdd_ipa = NULL;
5767
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305768 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005769}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005770
5771/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305772 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_flush
5773 * @hdd_ctx: HDD global context
5774 *
5775 * Return: None
5776 */
5777void hdd_ipa_flush(struct hdd_context *hdd_ctx)
5778{
5779 cds_ssr_protect(__func__);
5780 __hdd_ipa_flush(hdd_ctx);
5781 cds_ssr_unprotect(__func__);
5782}
5783
5784/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005785 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5786 * @hdd_ctx: HDD global context
5787 *
5788 * Return: QDF_STATUS enumeration
5789 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005790QDF_STATUS hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005791{
5792 QDF_STATUS ret;
5793
5794 cds_ssr_protect(__func__);
5795 ret = __hdd_ipa_cleanup(hdd_ctx);
5796 cds_ssr_unprotect(__func__);
5797
5798 return ret;
5799}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800#endif /* IPA_OFFLOAD */