blob: 8bf30a42de682882e5891a0e1c3d817e094bc2e4 [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 Park0dad1002017-07-14 14:57:01 -0700542#define HDD_IPA_DBG_DUMP_RX_LEN 84
Yun Parkb187d542016-11-14 18:10:04 -0800543#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;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001639 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301640 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641}
1642
1643/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001644 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1645 * @hdd_ctx: Global HDD context
1646 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1647 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1648 *
1649 * Return: true if IPA is enabled, false otherwise
1650 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001651void hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001652 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1653{
1654 cds_ssr_protect(__func__);
1655 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1656 cds_ssr_unprotect(__func__);
1657}
1658
1659/**
1660 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001661 * @adapter: network adapter
1662 * @reason: STAT REQ Reason
1663 *
1664 * Return: None
1665 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07001666static void __hdd_ipa_uc_stat_request(struct hdd_adapter *adapter,
1667 uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001668{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001669 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 struct hdd_ipa_priv *hdd_ipa;
1671
Yun Park637d6482016-10-05 10:51:33 -07001672 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674
Jeff Johnson399c6272017-08-30 10:51:00 -07001675 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001676
1677 if (wlan_hdd_validate_context(hdd_ctx))
1678 return;
1679
1680 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1681 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1682 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 return;
1684 }
1685
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301686 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001687 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1688 (false == hdd_ipa->resource_loading)) {
1689 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001690 qdf_mutex_release(&hdd_ipa->ipa_lock);
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001691 sme_ipa_uc_stat_request(WLAN_HDD_GET_HAL_CTX(adapter),
1692 adapter->sessionId,
1693 WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001695 } else {
1696 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698}
1699
1700/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001701 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1702 * @adapter: network adapter
1703 * @reason: STAT REQ Reason
1704 *
1705 * Return: None
1706 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001707void hdd_ipa_uc_stat_request(struct hdd_adapter *adapter, uint8_t reason)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001708{
1709 cds_ssr_protect(__func__);
1710 __hdd_ipa_uc_stat_request(adapter, reason);
1711 cds_ssr_unprotect(__func__);
1712}
1713
Yun Park637d6482016-10-05 10:51:33 -07001714#ifdef FEATURE_METERING
1715/**
1716 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1717 * @adapter: network adapter
1718 * @reset_stats: reset stat countis after response
1719 *
1720 * Return: None
1721 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001722void hdd_ipa_uc_sharing_stats_request(struct hdd_adapter *adapter,
Yun Park637d6482016-10-05 10:51:33 -07001723 uint8_t reset_stats)
1724{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001725 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001726 struct hdd_ipa_priv *hdd_ipa;
1727
1728 if (!adapter)
1729 return;
1730
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001731 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1732 hdd_ipa = hdd_ctx->hdd_ipa;
1733 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1734 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001735 return;
1736 }
1737
1738 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1739 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001740 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001741 qdf_mutex_release(&hdd_ipa->ipa_lock);
1742 wma_cli_set_command(
1743 (int)adapter->sessionId,
1744 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1745 reset_stats, VDEV_CMD);
1746 } else {
1747 qdf_mutex_release(&hdd_ipa->ipa_lock);
1748 }
1749}
1750
1751/**
1752 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1753 * @adapter: network adapter
1754 * @set_quota: when 1, FW starts quota monitoring
1755 * @quota_bytes: quota limit in bytes
1756 *
1757 * Return: None
1758 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001759void hdd_ipa_uc_set_quota(struct hdd_adapter *adapter, uint8_t set_quota,
Yun Park637d6482016-10-05 10:51:33 -07001760 uint64_t quota_bytes)
1761{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001762 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001763 struct hdd_ipa_priv *hdd_ipa;
1764
1765 if (!adapter)
1766 return;
1767
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001768 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1769 hdd_ipa = hdd_ctx->hdd_ipa;
1770 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1771 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001772 return;
1773 }
1774
1775 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1776 set_quota, quota_bytes);
1777
1778 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001779 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001780 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001781 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001782 (int)adapter->sessionId,
1783 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001784 (set_quota ? quota_bytes&0xffffffff : 0),
1785 (set_quota ? quota_bytes>>32 : 0),
1786 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001787 } else {
1788 qdf_mutex_release(&hdd_ipa->ipa_lock);
1789 }
1790}
1791#endif
1792
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001793/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001794 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1795 * @hdd_ipa: Global HDD IPA context
1796 * @sta_add: Should station be added
1797 * @sta_id: ID of the station being queried
1798 *
1799 * Return: true if the station was found
1800 */
1801static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1802 bool sta_add, uint8_t sta_id)
1803{
1804 bool sta_found = false;
1805 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001806
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001807 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1808 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1809 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1810 sta_found = true;
1811 break;
1812 }
1813 }
1814 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301815 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001816 "STA ID %d already exist, cannot add", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001817 return sta_found;
1818 }
1819 if (sta_add) {
1820 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1821 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1822 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1823 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1824 return sta_found;
1825 }
1826 }
1827 }
1828 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301829 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001830 "STA ID %d does not exist, cannot delete", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001831 return sta_found;
1832 }
1833 if (!sta_add) {
1834 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1835 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1836 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1837 hdd_ipa->assoc_stas_map[idx].is_reserved =
1838 false;
1839 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1840 return sta_found;
1841 }
1842 }
1843 }
1844 return sta_found;
1845}
1846
1847/**
1848 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1849 * @hdd_ipa: Global HDD IPA context
1850 *
1851 * Return: 0 on success, negative errno if error
1852 */
1853static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1854{
Yun Parkfec73dc2017-09-06 10:40:07 -07001855 int result = 0;
Leo Changfdb45c32016-10-28 11:09:23 -07001856 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001857 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001858
Yun Parkfec73dc2017-09-06 10:40:07 -07001859 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
1860
Yun Parkb4f591d2017-03-29 15:51:01 -07001861 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301863 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001864 "Enable PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001865 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001867
Yun Park777d7242017-03-30 15:38:33 -07001868 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Leo Change3e49442015-10-26 20:07:13 -07001869 hdd_ipa->ipa_pipes_down = false;
Yun Parkb4f591d2017-03-29 15:51:01 -07001870
1871 cdp_ipa_enable_autonomy(soc, (struct cdp_pdev *)pdev);
1872
Yun Parkfec73dc2017-09-06 10:40:07 -07001873end:
1874 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: ipa_pipes_down=%d",
1875 hdd_ipa->ipa_pipes_down);
1876 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001877}
1878
1879/**
1880 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1881 * @hdd_ipa: Global HDD IPA context
1882 *
1883 * Return: 0 on success, negative errno if error
1884 */
1885static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1886{
Yun Parkb4f591d2017-03-29 15:51:01 -07001887 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1888 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkfec73dc2017-09-06 10:40:07 -07001889 int result = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890
Yun Parkfec73dc2017-09-06 10:40:07 -07001891 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Leo Change3e49442015-10-26 20:07:13 -07001892
Yun Parkb4f591d2017-03-29 15:51:01 -07001893 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001894
Yun Parkb4f591d2017-03-29 15:51:01 -07001895 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001896 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301897 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001898 "Disable WDI PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001899 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 }
1901
Yun Parkfec73dc2017-09-06 10:40:07 -07001902 hdd_ipa->ipa_pipes_down = true;
1903
1904end:
1905 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: ipa_pipes_down=%d",
1906 hdd_ipa->ipa_pipes_down);
1907 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001908}
1909
1910/**
1911 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1912 * @hdd_ipa: Global HDD IPA context
1913 *
1914 * Return: 0 on success, negative errno if error
1915 */
1916static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1917{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001918 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07001919
Yun Parkfec73dc2017-09-06 10:40:07 -07001920 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
1921
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001922 hdd_ipa->activated_fw_pipe = 0;
1923 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001925 /* If RM feature enabled
1926 * Request PROD Resource first
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07001927 * PROD resource may return sync or async manners
1928 */
Yun Parkb4f591d2017-03-29 15:51:01 -07001929 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001930 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1931 /* RM PROD request sync return
1932 * enable pipe immediately
1933 */
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301934 if (!hdd_ipa->ipa_pipes_down) {
1935 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1936 "%s: IPA WDI Pipe already activated",
1937 __func__);
1938 return 0;
1939 }
1940
Yun Park4cab6ee2015-10-27 11:43:40 -07001941 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301942 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001943 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001944 hdd_ipa->resource_loading = false;
1945 return -EBUSY;
1946 }
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301947 } else {
1948 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
1949 "%s: IPA WDI Pipe activation deferred",
1950 __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001951 }
1952 } else {
1953 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001954 * Just enabled all the PIPEs
1955 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001956 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301957 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001958 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001959 hdd_ipa->resource_loading = false;
1960 return -EBUSY;
1961 }
1962 hdd_ipa->resource_loading = false;
1963 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001964
Yun Parkfec73dc2017-09-06 10:40:07 -07001965 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: IPA WDI Pipes activated!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001966 return 0;
1967}
1968
1969/**
1970 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1971 * @hdd_ipa: Global HDD IPA context
1972 *
1973 * Return: None
1974 */
1975static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1976{
Leo Changfdb45c32016-10-28 11:09:23 -07001977 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001978 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001979
Yun Parkfec73dc2017-09-06 10:40:07 -07001980 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
1981
Yun Parkb4f591d2017-03-29 15:51:01 -07001982 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08001983 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
1984 QDF_ASSERT(0);
1985 return;
1986 }
1987
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001988 hdd_ipa->resource_unloading = true;
Yun Park777d7242017-03-30 15:38:33 -07001989 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Yun Parkb4f591d2017-03-29 15:51:01 -07001990 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
1991 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
1992 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
1993 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Yun Parkfec73dc2017-09-06 10:40:07 -07001994
1995 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: IPA WDI Pipes deactivated");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996}
1997
1998/**
1999 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
2000 * @context: User context registered with TL (the IPA Global context is
2001 * registered
2002 * @rxpkt: Packet containing the notification
2003 * @staid: ID of the station associated with the packet
2004 *
2005 * Return: None
2006 */
2007static void
2008hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
2009{
2010 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302011 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002012 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002013
2014 /*
2015 * When SSR is going on or driver is unloading, just return.
2016 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002017 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302018 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020
Yun Parkb4f591d2017-03-29 15:51:01 -07002021 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002022 return;
2023
Srinivas Girigowda97852372017-03-06 16:52:59 -08002024 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 __func__, event);
2026
2027 switch (event) {
2028 case IPA_RM_RESOURCE_GRANTED:
2029 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302030 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002031 if ((false == hdd_ipa->resource_unloading) &&
2032 (!hdd_ipa->activated_fw_pipe)) {
2033 hdd_ipa_uc_enable_pipes(hdd_ipa);
2034 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302035 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002036 break;
2037
2038 case IPA_RM_RESOURCE_RELEASED:
2039 /* Differed RM Released */
2040 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041 break;
2042
2043 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302044 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002045 "%s, invalid event code %d", __func__, event);
2046 break;
2047 }
2048}
2049
2050/**
2051 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2052 * @hdd_ipa: Global HDD IPA context
2053 * @event: IPA resource manager event to be deferred
2054 *
2055 * This function is called when a resource manager event is received
2056 * from firmware in interrupt context. This function will defer the
2057 * handling to the OL RX thread
2058 *
2059 * Return: None
2060 */
2061static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2062{
2063 enum ipa_rm_event event;
2064 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2065 struct uc_rm_work_struct, work);
2066 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2067 struct hdd_ipa_priv, uc_rm_work);
2068
2069 cds_ssr_protect(__func__);
2070 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002071 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002072 "%s, posted event %d", __func__, event);
2073
2074 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2075 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002076}
2077
2078/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002079 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002080 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002081 *
2082 * Will handle IPA UC image loaded indication comes from IPA kernel
2083 *
2084 * Return: None
2085 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002086static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002087{
Yun Parkb4f591d2017-03-29 15:51:01 -07002088 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2089 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002090 struct hdd_context *hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07002091 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002092
2093 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
Yun Parkb4f591d2017-03-29 15:51:01 -07002094 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002095 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002096 __func__);
2097 return;
2098 }
2099
Yun Parkb4f591d2017-03-29 15:51:01 -07002100 hdd_ctx = hdd_ipa->hdd_ctx;
2101 hdd_ipa->uc_loaded = true;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002102
Yun Parkb4f591d2017-03-29 15:51:01 -07002103 /* Connect pipe */
2104 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2105 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2106 hdd_ipa_wdi_meter_notifier_cb,
2107 hdd_ctx->config->IpaDescSize,
2108 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2109 &hdd_ipa->tx_pipe_handle,
2110 &hdd_ipa->rx_pipe_handle);
2111 if (status) {
2112 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2113 "Failure to setup IPA pipes (status=%d)",
2114 status);
2115 return;
2116 }
2117
2118 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002119
2120 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002121 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002122 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002123 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002124 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002125 }
2126}
2127
2128/**
Yun Park637d6482016-10-05 10:51:33 -07002129 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2130 * @hdd_ctx: Global HDD context
2131 * @op_msg: operation message received from firmware
2132 *
2133 * Return: QDF_STATUS enumeration
2134 */
2135#ifdef FEATURE_METERING
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002136static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002137 struct op_msg_type *op_msg)
2138{
2139 struct op_msg_type *msg = op_msg;
2140 struct ipa_uc_sharing_stats *uc_sharing_stats;
2141 struct ipa_uc_quota_rsp *uc_quota_rsp;
2142 struct ipa_uc_quota_ind *uc_quota_ind;
2143 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002144 struct hdd_adapter *adapter;
Yun Park637d6482016-10-05 10:51:33 -07002145
2146 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2147
2148 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2149 /* fill-up ipa_uc_sharing_stats structure from FW */
2150 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2151 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2152
2153 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2154 sizeof(struct ipa_uc_sharing_stats));
2155
2156 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2157
2158 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2159 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2160 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2161 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2162 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2163 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2164 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2165 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2166 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2167 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2168 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2169 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2170 /* received set quota response */
2171 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2172 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2173
2174 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2175 sizeof(struct ipa_uc_quota_rsp));
2176
2177 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2178 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2179 "%s: success=%d, quota_bytes=%llu",
2180 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2181 hdd_ipa->ipa_quota_rsp.success,
2182 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2183 hdd_ipa->ipa_quota_rsp.quota_lo);
2184 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2185 /* hit quota limit */
2186 uc_quota_ind = (struct ipa_uc_quota_ind *)
2187 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2188
2189 hdd_ipa->ipa_quota_ind.quota_bytes =
2190 uc_quota_ind->quota_bytes;
2191
2192 /* send quota exceeded indication to IPA */
2193 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2194 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2195 hdd_ipa->ipa_quota_ind.quota_bytes);
2196
2197 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2198 if (adapter)
2199 ipa_broadcast_wdi_quota_reach_ind(
2200 adapter->dev->ifindex,
2201 uc_quota_ind->quota_bytes);
2202 else
2203 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2204 "Failed quota_reach_ind: NULL adapter");
2205 } else {
2206 return QDF_STATUS_E_INVAL;
2207 }
2208
2209 return QDF_STATUS_SUCCESS;
2210}
2211#else
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002212static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002213 struct op_msg_type *op_msg)
2214{
2215 return QDF_STATUS_E_INVAL;
2216}
2217#endif
2218
Yun Park657c7d72017-06-07 15:44:59 -07002219#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
2220/* older versions had a typo */
2221#define num_bam_int_in_non_running_state num_bam_int_in_non_runnning_state
2222#endif
2223
Yun Park637d6482016-10-05 10:51:33 -07002224/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002225 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2226 * @op_msg: operation message received from firmware
2227 * @usr_ctxt: user context registered with TL (we register the HDD Global
2228 * context)
2229 *
2230 * Return: None
2231 */
2232static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2233{
2234 struct op_msg_type *msg = op_msg;
2235 struct ipa_uc_fw_stats *uc_fw_stat;
2236 struct IpaHwStatsWDIInfoData_t ipa_stat;
2237 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002238 struct hdd_context *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302239 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002240
2241 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302242 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002243 return;
2244 }
2245
2246 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302247 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002248 "%s, INVALID OPCODE %d", __func__, msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002249 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250 return;
2251 }
2252
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002253 hdd_ctx = (struct hdd_context *) usr_ctxt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002254
2255 /*
2256 * When SSR is going on or driver is unloading, just return.
2257 */
2258 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302259 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302260 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002261 return;
2262 }
2263
2264 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2265
Govind Singhb6a89772016-08-12 11:23:35 +05302266 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002267 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002268
2269 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2270 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302271 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002272 hdd_ipa->activated_fw_pipe++;
2273 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2274 hdd_ipa->resource_loading = false;
Yun Park777d7242017-03-30 15:38:33 -07002275 complete(&hdd_ipa->ipa_resource_comp);
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002276 if (hdd_ipa->wdi_enabled == false) {
2277 hdd_ipa->wdi_enabled = true;
2278 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2279 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2280 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002281 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002282 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002283 if (hdd_ipa->pending_cons_req)
2284 ipa_rm_notify_completion(
2285 IPA_RM_RESOURCE_GRANTED,
2286 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002287 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002288 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302289 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002290 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002291 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302292 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002293 hdd_ipa->activated_fw_pipe--;
2294 if (!hdd_ipa->activated_fw_pipe) {
Yun Park777d7242017-03-30 15:38:33 -07002295 /*
2296 * Async return success from FW
2297 * Disable/suspend all the PIPEs
2298 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002299 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002300 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2301 ipa_rm_release_resource(
2302 IPA_RM_RESOURCE_WLAN_PROD);
Yun Park5b635012015-12-02 15:05:01 -08002303 hdd_ipa->resource_unloading = false;
Yun Park777d7242017-03-30 15:38:33 -07002304 complete(&hdd_ipa->ipa_resource_comp);
Yun Park5b635012015-12-02 15:05:01 -08002305 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2306 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002307 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302308 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002309 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002311 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302312 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002313 "==== IPA_UC WLAN_HOST RX ====\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002314 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002315 "NUM TX FWD OK : %llu\n"
2316 "NUM TX FWD ERR : %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002317 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002318 hdd_ipa->stats.num_tx_fwd_ok,
2319 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302320 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002321 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2322 "SAP NUM STAs: %d\n"
2323 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002324 "CONCURRENT MODE: %s\n"
2325 "TX PIPE HDL: 0x%x\n"
2326 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002327 "RSC LOADING : %d\n"
2328 "RSC UNLOADING : %d\n"
2329 "PNDNG CNS RQT : %d",
2330 hdd_ipa->sap_num_connected_sta,
2331 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002332 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002333 hdd_ipa->tx_pipe_handle,
2334 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002335 hdd_ipa->resource_loading,
2336 hdd_ipa->resource_unloading,
2337 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002338
2339 /* STATs from FW */
2340 uc_fw_stat = (struct ipa_uc_fw_stats *)
2341 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302342 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002343 "==== IPA_UC WLAN_FW TX ====\n"
2344 "COMP RING BASE: 0x%x\n"
2345 "COMP RING SIZE: %d\n"
2346 "COMP RING DBELL : 0x%x\n"
2347 "COMP RING DBELL IND VAL : %d\n"
2348 "COMP RING DBELL CACHED VAL : %d\n"
2349 "COMP RING DBELL CACHED VAL : %d\n"
2350 "PKTS ENQ : %d\n"
2351 "PKTS COMP : %d\n"
2352 "IS SUSPEND : %d\n"
2353 "RSVD : 0x%x",
2354 uc_fw_stat->tx_comp_ring_base,
2355 uc_fw_stat->tx_comp_ring_size,
2356 uc_fw_stat->tx_comp_ring_dbell_addr,
2357 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2358 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2359 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2360 uc_fw_stat->tx_pkts_enqueued,
2361 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002362 uc_fw_stat->tx_is_suspend,
2363 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302364 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002365 "==== IPA_UC WLAN_FW RX ====\n"
2366 "IND RING BASE: 0x%x\n"
2367 "IND RING SIZE: %d\n"
2368 "IND RING DBELL : 0x%x\n"
2369 "IND RING DBELL IND VAL : %d\n"
2370 "IND RING DBELL CACHED VAL : %d\n"
2371 "RDY IND ADDR : 0x%x\n"
2372 "RDY IND CACHE VAL : %d\n"
2373 "RFIL IND : %d\n"
2374 "NUM PKT INDICAT : %d\n"
2375 "BUF REFIL : %d\n"
2376 "NUM DROP NO SPC : %d\n"
2377 "NUM DROP NO BUF : %d\n"
2378 "IS SUSPND : %d\n"
2379 "RSVD : 0x%x\n",
2380 uc_fw_stat->rx_ind_ring_base,
2381 uc_fw_stat->rx_ind_ring_size,
2382 uc_fw_stat->rx_ind_ring_dbell_addr,
2383 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2384 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2385 uc_fw_stat->rx_ind_ring_rdidx_addr,
2386 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2387 uc_fw_stat->rx_refill_idx,
2388 uc_fw_stat->rx_num_pkts_indicated,
2389 uc_fw_stat->rx_buf_refilled,
2390 uc_fw_stat->rx_num_ind_drop_no_space,
2391 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002392 uc_fw_stat->rx_is_suspend,
2393 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002394 /* STATs from IPA */
2395 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302396 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002397 "==== IPA_UC IPA TX ====\n"
2398 "NUM PROCD : %d\n"
2399 "CE DBELL : 0x%x\n"
2400 "NUM DBELL FIRED : %d\n"
2401 "COMP RNG FULL : %d\n"
2402 "COMP RNG EMPT : %d\n"
2403 "COMP RNG USE HGH : %d\n"
2404 "COMP RNG USE LOW : %d\n"
2405 "BAM FIFO FULL : %d\n"
2406 "BAM FIFO EMPT : %d\n"
2407 "BAM FIFO USE HGH : %d\n"
2408 "BAM FIFO USE LOW : %d\n"
2409 "NUM DBELL : %d\n"
2410 "NUM UNEXP DBELL : %d\n"
2411 "NUM BAM INT HDL : 0x%x\n"
2412 "NUM BAM INT NON-RUN : 0x%x\n"
2413 "NUM QMB INT HDL : 0x%x",
2414 ipa_stat.tx_ch_stats.num_pkts_processed,
2415 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2416 ipa_stat.tx_ch_stats.num_db_fired,
2417 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2418 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2419 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2420 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2421 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2422 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2423 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2424 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2425 ipa_stat.tx_ch_stats.num_db,
2426 ipa_stat.tx_ch_stats.num_unexpected_db,
2427 ipa_stat.tx_ch_stats.num_bam_int_handled,
2428 ipa_stat.tx_ch_stats.
Yun Park657c7d72017-06-07 15:44:59 -07002429 num_bam_int_in_non_running_state,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002430 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2431
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302432 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002433 "==== IPA_UC IPA RX ====\n"
2434 "MAX OST PKT : %d\n"
2435 "NUM PKT PRCSD : %d\n"
2436 "RNG RP : 0x%x\n"
2437 "COMP RNG FULL : %d\n"
2438 "COMP RNG EMPT : %d\n"
2439 "COMP RNG USE HGH : %d\n"
2440 "COMP RNG USE LOW : %d\n"
2441 "BAM FIFO FULL : %d\n"
2442 "BAM FIFO EMPT : %d\n"
2443 "BAM FIFO USE HGH : %d\n"
2444 "BAM FIFO USE LOW : %d\n"
2445 "NUM DB : %d\n"
2446 "NUM UNEXP DB : %d\n"
2447 "NUM BAM INT HNDL : 0x%x\n",
2448 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2449 ipa_stat.rx_ch_stats.num_pkts_processed,
2450 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2451 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2452 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2453 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2454 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2455 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2456 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2457 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2458 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2459 ipa_stat.rx_ch_stats.num_db,
2460 ipa_stat.rx_ch_stats.num_unexpected_db,
2461 ipa_stat.rx_ch_stats.num_bam_int_handled);
2462 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2463 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2464 /* STATs from FW */
2465 uc_fw_stat = (struct ipa_uc_fw_stats *)
2466 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302467 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002468 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2469 uc_fw_stat->tx_pkts_completed,
2470 hdd_ipa->ipa_p_tx_packets);
2471 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2472 (uc_fw_stat->rx_num_ind_drop_no_space +
2473 uc_fw_stat->rx_num_ind_drop_no_buf +
2474 uc_fw_stat->rx_num_pkts_indicated),
2475 hdd_ipa->ipa_p_rx_packets);
2476
2477 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2478 hdd_ipa->ipa_p_rx_packets =
2479 (uc_fw_stat->rx_num_ind_drop_no_space +
2480 uc_fw_stat->rx_num_ind_drop_no_buf +
2481 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302482 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002483 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2484 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2485 hdd_ipa_uc_loaded_handler(hdd_ipa);
2486 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002487 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2488 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2489 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002490 }
Yun Park8957d802017-01-25 12:27:29 -08002491
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302492 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002493}
2494
2495
2496/**
2497 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2498 * @adapter: device adapter instance
2499 * @offload_type: MCC or SCC
2500 * @enable: TX offload enable or disable
2501 *
2502 * Return: none
2503 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002504static void hdd_ipa_uc_offload_enable_disable(struct hdd_adapter *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002505 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002506{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002507 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002508 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002509 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002510 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002511
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002512 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002513 return;
2514
Yun Park8292dcb2016-10-07 16:46:06 -07002515 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002516 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002517
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002518 if (!iface_context) {
2519 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2520 "Interface context is NULL");
2521 return;
2522 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002523 if (session_id >= CSR_ROAM_SESSION_MAX) {
2524 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2525 "invalid session id: %d", session_id);
2526 return;
2527 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002528 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002529 /* IPA offload status is already set as desired */
2530 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002531 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002532 "IPA offload status is already set",
2533 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002534 return;
2535 }
2536
Yun Park4540e862016-11-10 16:30:06 -08002537 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2538 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2539 "invalid session id: %d, offload_type=%d, enable=%d",
2540 adapter->sessionId, offload_type, enable);
2541 return;
2542 }
2543
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302544 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002545 sizeof(ipa_offload_enable_disable));
2546 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002547 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002548 ipa_offload_enable_disable.enable = enable;
2549
Srinivas Girigowda97852372017-03-06 16:52:59 -08002550 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002551 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002552 ipa_offload_enable_disable.offload_type,
2553 ipa_offload_enable_disable.vdev_id,
2554 ipa_offload_enable_disable.enable);
2555
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302556 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002557 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2558 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302559 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002560 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
2561 "Failure to enable IPA offload",
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002562 ipa_offload_enable_disable.offload_type,
2563 ipa_offload_enable_disable.vdev_id,
2564 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002565 } else {
2566 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002567 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002568 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002569 }
2570}
2571
2572/**
2573 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2574 * @work: uC OP work
2575 *
2576 * Return: None
2577 */
2578static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2579{
2580 struct op_msg_type *msg;
2581 struct uc_op_work_struct *uc_op_work = container_of(work,
2582 struct uc_op_work_struct, work);
2583 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2584
2585 cds_ssr_protect(__func__);
2586
2587 msg = uc_op_work->msg;
2588 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002589 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002590 "%s, posted msg %d", __func__, msg->op_code);
2591
2592 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2593
2594 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002595}
2596
2597/**
2598 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2599 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2600 * @op_msg: operation message received from firmware
2601 * @hdd_ctx: Global HDD context
2602 *
2603 * Return: None
2604 */
2605static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2606{
2607 struct hdd_ipa_priv *hdd_ipa;
2608 struct op_msg_type *msg;
2609 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302610 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611
2612 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302613 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002615
2616 msg = (struct op_msg_type *)op_msg;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002617 hdd_ipa = ((struct hdd_context *)hdd_ctx)->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002618
2619 if (unlikely(!hdd_ipa))
2620 goto end;
2621
2622 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002623 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2624 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002625 goto end;
2626 }
2627
2628 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2629 if (uc_op_work->msg)
2630 /* When the same uC OPCODE is already pended, just return */
2631 goto end;
2632
2633 uc_op_work->msg = msg;
2634 schedule_work(&uc_op_work->work);
2635 return;
2636
2637end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302638 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002639}
2640
2641/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002642 * hdd_ipa_init_uc_op_work - init ipa uc op work
2643 * @work: struct work_struct
2644 * @work_handler: work_handler
2645 *
2646 * Return: none
2647 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002648static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002649 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002650{
2651 INIT_WORK(work, work_handler);
2652}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002653
Yun Park637d6482016-10-05 10:51:33 -07002654#ifdef FEATURE_METERING
2655/**
2656 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2657 * IPA calls to get WLAN stats or set quota limit.
2658 * @priv: pointer to private data registered with IPA (we register a
2659 *» pointer to the global IPA context)
2660 * @evt: the IPA event which triggered the callback
2661 * @data: data associated with the event
2662 *
2663 * Return: None
2664 */
2665static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2666 void *data)
2667{
2668 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002669 struct hdd_adapter *adapter = NULL;
Yun Park637d6482016-10-05 10:51:33 -07002670 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2671 struct ipa_set_wifi_quota *ipa_set_quota;
2672 int ret = 0;
2673
2674 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2675 return;
2676
2677 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2678
2679 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2680
2681 switch (evt) {
2682 case IPA_GET_WDI_SAP_STATS:
2683 /* fill-up ipa_get_wdi_sap_stats structure after getting
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002684 * ipa_uc_fw_stats from FW
2685 */
Yun Park637d6482016-10-05 10:51:33 -07002686 wdi_sap_stats = data;
2687
2688 if (!adapter) {
2689 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2690 "IPA uC share stats failed - no adapter");
2691 wdi_sap_stats->stats_valid = 0;
2692 return;
2693 }
2694
2695 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
Yun Park637d6482016-10-05 10:51:33 -07002696 hdd_ipa_uc_sharing_stats_request(adapter,
2697 wdi_sap_stats->reset_stats);
2698 ret = wait_for_completion_timeout(
2699 &hdd_ipa->ipa_uc_sharing_stats_comp,
2700 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2701 if (!ret) {
2702 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2703 "IPA uC share stats request timed out");
2704 wdi_sap_stats->stats_valid = 0;
2705 } else {
2706 wdi_sap_stats->stats_valid = 1;
2707
2708 wdi_sap_stats->ipv4_rx_packets =
2709 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2710 wdi_sap_stats->ipv4_rx_bytes =
2711 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2712 wdi_sap_stats->ipv6_rx_packets =
2713 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2714 wdi_sap_stats->ipv6_rx_bytes =
2715 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2716 wdi_sap_stats->ipv4_tx_packets =
2717 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2718 wdi_sap_stats->ipv4_tx_bytes =
2719 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2720 wdi_sap_stats->ipv6_tx_packets =
2721 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2722 wdi_sap_stats->ipv6_tx_bytes =
2723 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2724 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2725 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2726 "IPA_GET_WDI_SAP_STATS",
2727 wdi_sap_stats->stats_valid,
2728 wdi_sap_stats->ipv4_rx_packets,
2729 wdi_sap_stats->ipv4_rx_bytes,
2730 wdi_sap_stats->ipv6_rx_packets,
2731 wdi_sap_stats->ipv6_rx_bytes,
2732 wdi_sap_stats->ipv4_tx_packets,
2733 wdi_sap_stats->ipv4_tx_bytes,
2734 wdi_sap_stats->ipv6_tx_packets,
2735 wdi_sap_stats->ipv6_tx_bytes);
2736 }
2737 break;
2738 case IPA_SET_WIFI_QUOTA:
2739 /* get ipa_set_wifi_quota structure from IPA and pass to FW
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002740 * through quota_exceeded field in ipa_uc_fw_stats
2741 */
Yun Park637d6482016-10-05 10:51:33 -07002742 ipa_set_quota = data;
2743
2744 if (!adapter) {
2745 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2746 "IPA uC set quota failed - no adapter");
2747 ipa_set_quota->set_valid = 0;
2748 return;
2749 }
2750
Yun Park777d7242017-03-30 15:38:33 -07002751 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
Yun Park637d6482016-10-05 10:51:33 -07002752 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2753 ipa_set_quota->quota_bytes);
2754
2755 ret = wait_for_completion_timeout(
2756 &hdd_ipa->ipa_uc_set_quota_comp,
2757 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2758 if (!ret) {
2759 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2760 "IPA uC set quota request timed out");
2761 ipa_set_quota->set_valid = 0;
2762 } else {
2763 ipa_set_quota->quota_bytes =
2764 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2765 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2766 ipa_set_quota->set_valid =
2767 hdd_ipa->ipa_quota_rsp.success;
2768 }
2769
2770 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2771 ipa_set_quota->quota_bytes,
2772 ipa_set_quota->set_valid);
2773 break;
2774 }
2775}
2776
2777/**
2778 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2779 * IPA calls to get WLAN stats or set quota limit.
2780 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07002781 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07002782 * @evt: the IPA event which triggered the callback
2783 * @data: data associated with the event
2784 *
2785 * Return: None
2786 */
2787static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2788 void *data)
2789{
2790 cds_ssr_protect(__func__);
2791 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2792 cds_ssr_unprotect(__func__);
2793}
2794
Yun Parkb4f591d2017-03-29 15:51:01 -07002795static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002796{
Yun Park637d6482016-10-05 10:51:33 -07002797 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2798 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2799}
2800#else
Yun Parkb4f591d2017-03-29 15:51:01 -07002801static void hdd_ipa_wdi_meter_notifier_cb(void)
2802{
2803}
2804
2805static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002806{
2807}
2808#endif
2809
Rajeev Kumar217f2172016-01-06 18:11:55 -08002810/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2812 * @hdd_ctx: Global HDD context
2813 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002814 * This function is called to update IPA pipe configuration with resources
2815 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2816 * (cds_enable)
2817 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302818 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002819 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002820QDF_STATUS hdd_ipa_uc_ol_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002821{
Yun Parkb4f591d2017-03-29 15:51:01 -07002822 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002823 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002824 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07002825 uint8_t i;
2826 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002828 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2829 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002830
Yun Parkfec73dc2017-09-06 10:40:07 -07002831 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2832
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002833 /* Do only IPA Pipe specific configuration here. All one time
2834 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2835 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2836 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002837 if (!pdev || !soc) {
2838 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07002839 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002840 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002841 }
Yun Parkb4f591d2017-03-29 15:51:01 -07002842 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002843 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2844 "IPA UC resource alloc fail");
2845 return QDF_STATUS_E_FAILURE;
2846 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002847
Yun Parkb4f591d2017-03-29 15:51:01 -07002848 if (true == hdd_ipa->uc_loaded) {
2849 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2850 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2851 hdd_ipa_wdi_meter_notifier_cb,
2852 hdd_ctx->config->IpaDescSize,
2853 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2854 &hdd_ipa->tx_pipe_handle,
2855 &hdd_ipa->rx_pipe_handle);
2856 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08002857 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002858 "Failure to setup IPA pipes (status=%d)",
2859 status);
2860 return QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002861 }
Yun Park637d6482016-10-05 10:51:33 -07002862
Yun Parkb4f591d2017-03-29 15:51:01 -07002863 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
2864 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002865 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002866
Yun Parkb4f591d2017-03-29 15:51:01 -07002867 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08002868 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2869
Yun Parkb4f591d2017-03-29 15:51:01 -07002870 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
2871 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
2872 hdd_ipa_uc_fw_op_event_handler);
2873 hdd_ipa->uc_op_work[i].msg = NULL;
2874 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002875
Yun Parkbaa62862017-01-18 13:43:34 -08002876fail_return:
Yun Parkedec48d2017-07-28 14:08:14 -07002877 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: stat=%d", status);
Yun Parkb4f591d2017-03-29 15:51:01 -07002878 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002879}
2880
Leo Change3e49442015-10-26 20:07:13 -07002881/**
Yun Parkd8fb1a82017-10-13 16:48:20 -07002882 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
2883 * @hdd_ipa: pointer to HDD IPA struct
2884 *
2885 * Return: none
2886 */
2887static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
2888{
2889 struct ipa_uc_pending_event *pending_event = NULL;
2890
2891 while (qdf_list_remove_front(&hdd_ipa->pending_event,
2892 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS)
2893 qdf_mem_free(pending_event);
2894}
2895
2896/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302897 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
2898 * @hdd_ctx: Global HDD context
2899 *
2900 * Return: 0 on success, negativer errno on error
2901 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002902int hdd_ipa_uc_ol_deinit(struct hdd_context *hdd_ctx)
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302903{
2904 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2905 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07002906 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302907
Yun Parkfec73dc2017-09-06 10:40:07 -07002908 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2909
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302910 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2911 return ret;
2912
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05302913 if (!hdd_ipa->ipa_pipes_down)
2914 hdd_ipa_uc_disable_pipes(hdd_ipa);
2915
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302916 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002917 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
2918 hdd_ipa->tx_pipe_handle,
2919 hdd_ipa->rx_pipe_handle);
2920 if (status) {
2921 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2922 "Failure to cleanup IPA pipes (status=%d)",
2923 status);
2924 return -EFAULT;
2925 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302926 }
2927
Yun Parkd8fb1a82017-10-13 16:48:20 -07002928 hdd_ipa_cleanup_pending_event(hdd_ipa);
2929
Yun Parkfec73dc2017-09-06 10:40:07 -07002930 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: ret=%d", ret);
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302931 return ret;
2932}
2933
2934/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002935 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002936 * @hdd_ctx: hdd main context
2937 *
2938 * Force shutdown IPA pipe
2939 * Independent of FW pipe status, IPA pipe shutdonw progress
2940 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2941 * independent from FW pipe status
2942 *
2943 * Return: NONE
2944 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002945static void __hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002946{
2947 struct hdd_ipa_priv *hdd_ipa;
2948
Yun Parkfec73dc2017-09-06 10:40:07 -07002949 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
2950
Leo Change3e49442015-10-26 20:07:13 -07002951 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2952 return;
2953
2954 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2955 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302956 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002957 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07002958 hdd_ipa_uc_disable_pipes(hdd_ipa);
2959 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002960 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07002961 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07002962 }
Yun Parkfec73dc2017-09-06 10:40:07 -07002963
2964 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Leo Change3e49442015-10-26 20:07:13 -07002965}
2966
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002967/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002968 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2969 * __hdd_ipa_uc_force_pipe_shutdown
2970 * @hdd_ctx: hdd main context
2971 *
2972 * Force shutdown IPA pipe
2973 * Independent of FW pipe status, IPA pipe shutdonw progress
2974 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2975 * independent from FW pipe status
2976 *
2977 * Return: NONE
2978 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002979void hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002980{
2981 cds_ssr_protect(__func__);
2982 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2983 cds_ssr_unprotect(__func__);
2984}
2985
2986/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302987 * hdd_ipa_msg_free_fn() - Free an IPA message
2988 * @buff: pointer to the IPA message
2989 * @len: length of the IPA message
2990 * @type: type of IPA message
2991 *
2992 * Return: None
2993 */
2994static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2995{
Srinivas Girigowda97852372017-03-06 16:52:59 -08002996 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05302997 ghdd_ipa->stats.num_free_msg++;
2998 qdf_mem_free(buff);
2999}
3000
Govind Singh9c58eba2016-09-02 16:23:06 +05303001/**
jge62037862016-12-09 10:44:33 +08003002 * hdd_ipa_uc_send_evt() - send event to ipa
3003 * @hdd_ctx: pointer to hdd context
3004 * @type: event type
3005 * @mac_addr: pointer to mac address
3006 *
3007 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303008 *
3009 * Return: 0 - Success
3010 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003011static int hdd_ipa_uc_send_evt(struct hdd_adapter *adapter,
jge62037862016-12-09 10:44:33 +08003012 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303013{
jge62037862016-12-09 10:44:33 +08003014 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05303015 struct ipa_msg_meta meta;
3016 struct ipa_wlan_msg *msg;
3017 int ret = 0;
jge62037862016-12-09 10:44:33 +08003018
3019 meta.msg_len = sizeof(struct ipa_wlan_msg);
3020 msg = qdf_mem_malloc(meta.msg_len);
3021 if (msg == NULL) {
3022 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3023 "msg allocation failed");
3024 return -ENOMEM;
3025 }
3026
3027 meta.msg_type = type;
3028 strlcpy(msg->name, adapter->dev->name,
3029 IPA_RESOURCE_NAME_MAX);
3030 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Yun Parkfec73dc2017-09-06 10:40:07 -07003031 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08003032 msg->name, meta.msg_type);
3033 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3034 if (ret) {
3035 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3036 "%s: Evt: %d fail:%d",
3037 msg->name, meta.msg_type, ret);
3038 qdf_mem_free(msg);
3039 return ret;
3040 }
3041
3042 hdd_ipa->stats.num_send_msg++;
3043
3044 return ret;
3045}
3046
3047/**
3048 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3049 * @hdd_ctx: pointer to hdd adapter
3050 *
3051 * Send disconnect client event to IPA driver during SSR
3052 *
3053 * Return: 0 - Success
3054 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003055static int hdd_ipa_uc_disconnect_client(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003056{
3057 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3058 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303059 int i;
3060
Yun Parkfec73dc2017-09-06 10:40:07 -07003061 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Govind Singh9c58eba2016-09-02 16:23:06 +05303062 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003063 if (qdf_is_macaddr_broadcast(&adapter->sta_info[i].sta_mac))
Govind Singh9c58eba2016-09-02 16:23:06 +05303064 continue;
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003065 if ((adapter->sta_info[i].in_use) &&
3066 (!adapter->sta_info[i].is_deauth_in_progress) &&
jge62037862016-12-09 10:44:33 +08003067 hdd_ipa->sap_num_connected_sta) {
3068 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003069 adapter->sta_info[i].sta_mac.bytes);
jge62037862016-12-09 10:44:33 +08003070 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303071 }
3072 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003073 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: sap_num_connected_sta=%d",
3074 hdd_ipa->sap_num_connected_sta);
Govind Singh9c58eba2016-09-02 16:23:06 +05303075
3076 return ret;
3077}
3078
3079/**
jge62037862016-12-09 10:44:33 +08003080 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3081 * @hdd_ctx: pointer to hdd adapter
3082 *
3083 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303084 *
3085 * Return: 0 - Success
3086 */
jge62037862016-12-09 10:44:33 +08003087
Jeff Johnson49d45e62017-08-29 14:30:42 -07003088static int hdd_ipa_uc_disconnect_ap(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003089{
3090 int ret = 0;
3091
Yun Parkfec73dc2017-09-06 10:40:07 -07003092 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3093 if (adapter->ipa_context) {
jge62037862016-12-09 10:44:33 +08003094 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3095 adapter->dev->dev_addr);
Yun Parkfec73dc2017-09-06 10:40:07 -07003096 }
3097 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
jge62037862016-12-09 10:44:33 +08003098
3099 return ret;
3100}
3101
jge62037862016-12-09 10:44:33 +08003102/**
3103 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3104 * @hdd_ctx: pointer to hdd adapter
3105 *
3106 * Send disconnect sta event to IPA driver during SSR
3107 *
3108 * Return: 0 - Success
3109 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003110static int hdd_ipa_uc_disconnect_sta(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003111{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003112 struct hdd_station_ctx *sta_ctx;
jge62037862016-12-09 10:44:33 +08003113 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3114 int ret = 0;
3115
Yun Parkfec73dc2017-09-06 10:40:07 -07003116 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003117 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003118 hdd_ipa->sta_connected) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07003119 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
jge62037862016-12-09 10:44:33 +08003120 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Jeff Johnsond377dce2017-10-04 10:32:42 -07003121 sta_ctx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003122 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003123 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
jge62037862016-12-09 10:44:33 +08003124
3125 return ret;
3126}
jge62037862016-12-09 10:44:33 +08003127
3128/**
3129 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3130 * @hdd_ctx: pointer to hdd context
3131 *
3132 * Send disconnect event to IPA driver during SSR
3133 *
3134 * Return: 0 - Success
3135 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003136static int hdd_ipa_uc_disconnect(struct hdd_context *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303137{
3138 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3139 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003140 struct hdd_adapter *adapter;
Govind Singh9c58eba2016-09-02 16:23:06 +05303141 int ret = 0;
3142
Govind Singh9c58eba2016-09-02 16:23:06 +05303143 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3144 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003145 adapter = adapter_node->adapter;
jge62037862016-12-09 10:44:33 +08003146 if (adapter->device_mode == QDF_SAP_MODE) {
3147 hdd_ipa_uc_disconnect_client(adapter);
3148 hdd_ipa_uc_disconnect_ap(adapter);
3149 } else if (adapter->device_mode == QDF_STA_MODE) {
3150 hdd_ipa_uc_disconnect_sta(adapter);
3151 }
3152
Govind Singh9c58eba2016-09-02 16:23:06 +05303153 status = hdd_get_next_adapter(
3154 hdd_ctx, adapter_node, &next);
3155 adapter_node = next;
3156 }
3157
3158 return ret;
3159}
3160
3161/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003162 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003163 *
3164 * Deinit basic IPA UC host side to be in sync reloaded FW during
3165 * SSR
3166 *
3167 * Return: 0 - Success
3168 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003169static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003170{
3171 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3172 int idx;
3173 struct hdd_ipa_iface_context *iface_context;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003174 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003175
Yun Parkfec73dc2017-09-06 10:40:07 -07003176 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3177
Arun Khandavallicc544b32017-01-30 19:52:16 +05303178 if (!hdd_ipa)
3179 return 0;
3180
3181 hdd_ctx = hdd_ipa->hdd_ctx;
3182 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003183 return 0;
3184
jge62037862016-12-09 10:44:33 +08003185 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303186 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003188 /* Clean up HDD IPA interfaces */
3189 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3190 (idx < HDD_IPA_MAX_IFACE); idx++) {
3191 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003192 if (iface_context->adapter && iface_context->adapter->magic ==
3193 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003194 hdd_ipa_cleanup_iface(iface_context);
3195 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003196 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197 /* After SSR, wlan driver reloads FW again. But we need to protect
3198 * IPA submodule during SSR transient state. So deinit basic IPA
3199 * UC host side to be in sync with reloaded FW during SSR
3200 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003201
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303202 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003203 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3204 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3205 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3206 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303207 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003208
Guolei Bianca144d82016-11-10 11:07:42 +08003209 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3210 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3211
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003212 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3213 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3214 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3215 hdd_ipa->uc_op_work[idx].msg = NULL;
3216 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003217
3218 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003219 return 0;
3220}
3221
3222/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003223 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3224 *
3225 * Deinit basic IPA UC host side to be in sync reloaded FW during
3226 * SSR
3227 *
3228 * Return: 0 - Success
3229 */
3230int hdd_ipa_uc_ssr_deinit(void)
3231{
3232 int ret;
3233
3234 cds_ssr_protect(__func__);
3235 ret = __hdd_ipa_uc_ssr_deinit();
3236 cds_ssr_unprotect(__func__);
3237
3238 return ret;
3239}
3240
3241/**
3242 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003243 *
3244 * Init basic IPA UC host side to be in sync with reloaded FW after
3245 * SSR to resume IPA UC operations
3246 *
3247 * Return: 0 - Success
3248 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003249static int __hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003250{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003251
Arun Khandavallicc544b32017-01-30 19:52:16 +05303252 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3253 int i;
3254 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303255
Yun Parkfec73dc2017-09-06 10:40:07 -07003256 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
3257
Arun Khandavallicc544b32017-01-30 19:52:16 +05303258 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3259 return 0;
3260
Arun Khandavallicc544b32017-01-30 19:52:16 +05303261 /* Create the interface context */
3262 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3263 iface_context = &hdd_ipa->iface_context[i];
3264 iface_context->hdd_ipa = hdd_ipa;
3265 iface_context->cons_client =
3266 hdd_ipa_adapter_2_client[i].cons_client;
3267 iface_context->prod_client =
3268 hdd_ipa_adapter_2_client[i].prod_client;
3269 iface_context->iface_id = i;
3270 iface_context->adapter = NULL;
3271 }
3272 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3273 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3274 hdd_ipa->vdev_offload_enabled[i] = false;
3275 }
3276
3277 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3278 hdd_ipa->resource_loading = false;
3279 hdd_ipa->resource_unloading = false;
3280 hdd_ipa->sta_connected = 0;
3281 hdd_ipa->ipa_pipes_down = true;
3282 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303283 }
3284
Yun Parkfec73dc2017-09-06 10:40:07 -07003285 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286 return 0;
3287}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003288
3289/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003290 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3291 *
3292 * Init basic IPA UC host side to be in sync with reloaded FW after
3293 * SSR to resume IPA UC operations
3294 *
3295 * Return: 0 - Success
3296 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003297int hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003298{
3299 int ret;
3300
3301 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303302 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003303 cds_ssr_unprotect(__func__);
3304
3305 return ret;
3306}
3307
3308/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003309 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3310 * @work: scheduled work
3311 *
3312 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3313 * not want to immediately release the wake lock since the system
3314 * would then potentially try to suspend when there is a healthy data
3315 * rate. Deferred work is scheduled and this function handles the
3316 * work. When this function is called, if the IPA resource is still
3317 * released then we release the wake lock.
3318 *
3319 * Return: None
3320 */
3321static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3322{
3323 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3324 struct hdd_ipa_priv,
3325 wake_lock_work);
3326
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303327 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328
3329 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3330 goto end;
3331
3332 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303333 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334 WIFI_POWER_EVENT_WAKELOCK_IPA);
3335
3336end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303337 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338}
3339
3340/**
3341 * hdd_ipa_rm_request() - Request resource from IPA
3342 * @hdd_ipa: Global HDD IPA context
3343 *
3344 * Return: 0 on success, negative errno on error
3345 */
3346static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3347{
3348 int ret = 0;
3349
3350 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3351 return 0;
3352
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303353 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354
3355 switch (hdd_ipa->rm_state) {
3356 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303357 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003358 return 0;
3359 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303360 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 return -EINPROGRESS;
3362 case HDD_IPA_RM_RELEASED:
3363 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3364 break;
3365 }
3366
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303367 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003368
3369 ret = ipa_rm_inactivity_timer_request_resource(
3370 IPA_RM_RESOURCE_WLAN_PROD);
3371
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303372 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373 if (ret == 0) {
3374 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3375 hdd_ipa->stats.num_rm_grant_imm++;
3376 }
3377
3378 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3379 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303380 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 WIFI_POWER_EVENT_WAKELOCK_IPA);
3382 hdd_ipa->wake_lock_released = false;
3383 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303384 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003385
3386 return ret;
3387}
3388
3389/**
3390 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3391 * @hdd_ipa: Global HDD IPA context
3392 *
3393 * Return: 0 if resources released, negative errno otherwise
3394 */
3395static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3396{
3397 int ret = 0;
3398
3399 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3400 return 0;
3401
3402 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3403 return -EAGAIN;
3404
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303405 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406
Nirav Shahcbc6d722016-03-01 16:24:53 +05303407 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303408 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003409 return -EAGAIN;
3410 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303411 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003412
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303413 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003414 switch (hdd_ipa->rm_state) {
3415 case HDD_IPA_RM_GRANTED:
3416 break;
3417 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303418 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003419 return -EINPROGRESS;
3420 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303421 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003422 return 0;
3423 }
3424
3425 /* IPA driver returns immediately so set the state here to avoid any
3426 * race condition.
3427 */
3428 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3429 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303430 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003431
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003432 ret = ipa_rm_inactivity_timer_release_resource(
3433 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003434
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303435 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436 if (unlikely(ret != 0)) {
3437 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3438 WARN_ON(1);
3439 }
3440
3441 /*
3442 * If wake_lock is released immediately, kernel would try to suspend
3443 * immediately as well, Just avoid ping-pong between suspend-resume
3444 * while there is healthy amount of data transfer going on by
3445 * releasing the wake_lock after some delay.
3446 */
3447 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3448 msecs_to_jiffies
3449 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3450
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303451 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452
3453 return ret;
3454}
3455
3456/**
3457 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3458 * @user_data: user data registered with IPA
3459 * @event: the IPA resource manager event that occurred
3460 * @data: the data associated with the event
3461 *
3462 * Return: None
3463 */
3464static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3465 unsigned long data)
3466{
3467 struct hdd_ipa_priv *hdd_ipa = user_data;
3468
3469 if (unlikely(!hdd_ipa))
3470 return;
3471
3472 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3473 return;
3474
Srinivas Girigowda97852372017-03-06 16:52:59 -08003475 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003476
3477 switch (event) {
3478 case IPA_RM_RESOURCE_GRANTED:
3479 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3480 /* RM Notification comes with ISR context
3481 * it should be serialized into work queue to avoid
3482 * ISR sleep problem
3483 */
3484 hdd_ipa->uc_rm_work.event = event;
3485 schedule_work(&hdd_ipa->uc_rm_work.work);
3486 break;
3487 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303488 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003489 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303490 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003491 hdd_ipa->stats.num_rm_grant++;
3492 break;
3493
3494 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003495 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003496 hdd_ipa->resource_unloading = false;
3497 break;
3498
3499 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303500 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003501 break;
3502 }
3503}
3504
3505/**
3506 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3507 *
3508 * Callback function registered with IPA that is called when IPA wants
3509 * to release the WLAN consumer resource
3510 *
3511 * Return: 0 if the request is granted, negative errno otherwise
3512 */
3513static int hdd_ipa_rm_cons_release(void)
3514{
3515 return 0;
3516}
3517
3518/**
3519 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3520 *
3521 * Callback function registered with IPA that is called when IPA wants
3522 * to access the WLAN consumer resource
3523 *
3524 * Return: 0 if the request is granted, negative errno otherwise
3525 */
3526static int hdd_ipa_rm_cons_request(void)
3527{
Yun Park4d8b60a2015-10-22 13:59:32 -07003528 int ret = 0;
3529
3530 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303531 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003532 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003533 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003534 ret = -EINPROGRESS;
3535 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303536 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003537 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003538 ghdd_ipa->pending_cons_req = true;
3539 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003541
3542 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543}
3544
3545/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003546 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003547 * @hdd_ctx: Global HDD context
3548 * @tx_packets: Number of packets transmitted in the last sample period
3549 * @rx_packets: Number of packets received in the last sample period
3550 *
3551 * Return: 0 on success, negative errno on error
3552 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07003553static int __hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx,
3554 uint64_t tx_packets,
3555 uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003556{
3557 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003558 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003559 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003560 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003561 int ret;
3562
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003563 if (wlan_hdd_validate_context(hdd_ctx))
3564 return 0;
3565
3566 hdd_ipa = hdd_ctx->hdd_ipa;
3567
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003568 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3569 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3570 return 0;
3571
3572 memset(&profile, 0, sizeof(profile));
3573
3574 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3575 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3576 else if (tx_packets >
3577 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3578 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3579 else
3580 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3581
3582 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3583 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3584 else if (rx_packets >
3585 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3586 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3587 else
3588 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3589
Yun Parkec845302016-12-15 09:22:57 -08003590 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003591 "CONS perf curr: %d, next: %d",
3592 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003593 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 "PROD perf curr: %d, next: %d",
3595 hdd_ipa->curr_prod_bw, next_prod_bw);
3596
3597 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003598 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003600 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3601 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003602 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003603 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604
3605 return ret;
3606 }
3607 hdd_ipa->curr_cons_bw = next_cons_bw;
3608 hdd_ipa->stats.num_cons_perf_req++;
3609 }
3610
3611 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003612 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003613 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003614 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3615 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003617 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618 return ret;
3619 }
3620 hdd_ipa->curr_prod_bw = next_prod_bw;
3621 hdd_ipa->stats.num_prod_perf_req++;
3622 }
3623
3624 return 0;
3625}
3626
3627/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003628 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3629 * @hdd_ctx: Global HDD context
3630 * @tx_packets: Number of packets transmitted in the last sample period
3631 * @rx_packets: Number of packets received in the last sample period
3632 *
3633 * Return: 0 on success, negative errno on error
3634 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003635int hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003636 uint64_t rx_packets)
3637{
3638 int ret;
3639
3640 cds_ssr_protect(__func__);
3641 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3642 cds_ssr_unprotect(__func__);
3643
3644 return ret;
3645}
3646
3647/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003648 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3649 * @work: struct work_struct
3650 * @work_handler: work_handler
3651 *
3652 * Return: none
3653 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003654static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3655 work_func_t work_handler)
3656{
3657 INIT_WORK(work, work_handler);
3658}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003659
3660/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661 * hdd_ipa_setup_rm() - Setup IPA resource management
3662 * @hdd_ipa: Global HDD IPA context
3663 *
3664 * Return: 0 on success, negative errno on error
3665 */
3666static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3667{
3668 struct ipa_rm_create_params create_params = { 0 };
3669 int ret;
3670
3671 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3672 return 0;
3673
Rajeev Kumar217f2172016-01-06 18:11:55 -08003674 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3675 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676 memset(&create_params, 0, sizeof(create_params));
3677 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3678 create_params.reg_params.user_data = hdd_ipa;
3679 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3680 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3681
3682 ret = ipa_rm_create_resource(&create_params);
3683 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303684 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003685 "Create RM resource failed: %d", ret);
3686 goto setup_rm_fail;
3687 }
3688
3689 memset(&create_params, 0, sizeof(create_params));
3690 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3691 create_params.request_resource = hdd_ipa_rm_cons_request;
3692 create_params.release_resource = hdd_ipa_rm_cons_release;
3693 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3694
3695 ret = ipa_rm_create_resource(&create_params);
3696 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303697 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003698 "Create RM CONS resource failed: %d", ret);
3699 goto delete_prod;
3700 }
3701
3702 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3703 IPA_RM_RESOURCE_APPS_CONS);
3704
3705 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3706 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3707 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303708 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709 ret);
3710 goto timer_init_failed;
3711 }
3712
3713 /* Set the lowest bandwidth to start with */
3714 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3715
3716 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303717 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003718 "Set perf level failed: %d", ret);
3719 goto set_perf_failed;
3720 }
3721
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303722 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3724 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303725 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003726 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3727 hdd_ipa->wake_lock_released = true;
3728 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3729
3730 return ret;
3731
3732set_perf_failed:
3733 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3734
3735timer_init_failed:
3736 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3737
3738delete_prod:
3739 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3740
3741setup_rm_fail:
3742 return ret;
3743}
3744
3745/**
3746 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3747 * @hdd_ipa: Global HDD IPA context
3748 *
3749 * Destroys all resources associated with the IPA resource manager
3750 *
3751 * Return: None
3752 */
3753static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3754{
3755 int ret;
3756
3757 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3758 return;
3759
3760 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303761 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003763 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303764 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765
3766 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3767
3768 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3769 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303770 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771 "RM PROD resource delete failed %d", ret);
3772
3773 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3774 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303775 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776 "RM CONS resource delete failed %d", ret);
3777}
3778
tfyu0380a972017-07-13 18:19:37 +08003779#ifdef QCA_CONFIG_SMP
3780static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3781{
3782 return netif_rx_ni(skb);
3783}
3784#else
3785static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3786{
3787 struct iphdr *ip_h;
3788 static atomic_t softirq_mitigation_cntr =
3789 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
3790 int result;
3791
3792 ip_h = (struct iphdr *)(skb->data);
3793 if ((skb->protocol == htons(ETH_P_IP)) &&
3794 (ip_h->protocol == IPPROTO_ICMP)) {
3795 result = netif_rx_ni(skb);
3796 } else {
3797 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
3798 * to avoid excessive softirq's.
3799 */
3800 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
3801 result = netif_rx_ni(skb);
3802 atomic_set(&softirq_mitigation_cntr,
3803 IPA_WLAN_RX_SOFTIRQ_THRESH);
3804 } else {
3805 result = netif_rx(skb);
3806 }
3807 }
3808
3809 return result;
3810}
3811#endif
3812
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813/**
3814 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3815 * @skb: network buffer
3816 * @adapter: network adapter
3817 *
3818 * Called when a network buffer is received which should not be routed
3819 * to the IPA module.
3820 *
3821 * Return: None
3822 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303823static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003824 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003825{
tfyu0380a972017-07-13 18:19:37 +08003826 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3828 unsigned int cpu_index;
3829
3830 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07003831 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003832 adapter);
3833 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003834 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003835 return;
3836 }
3837
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003838 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003840 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 return;
3842 }
3843
3844 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3845 skb->dev = adapter->dev;
3846 skb->protocol = eth_type_trans(skb, skb->dev);
3847 skb->ip_summed = CHECKSUM_NONE;
3848
3849 cpu_index = wlan_hdd_get_cpu();
3850
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003851 ++adapter->hdd_stats.tx_rx_stats.rx_packets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08003852 result = hdd_ipa_aggregated_rx_ind(skb);
3853 if (result == NET_RX_SUCCESS)
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003854 ++adapter->hdd_stats.tx_rx_stats.rx_delivered[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003855 else
Jeff Johnson6ced42c2017-10-20 12:48:11 -07003856 ++adapter->hdd_stats.tx_rx_stats.rx_refused[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003857
3858 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003859}
3860
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861/**
Leo Chang69c39692016-10-12 20:11:12 -07003862 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3863 * @hdd_ipa: pointer to hdd ipa context
3864 * @adapter: network adapter
3865 * @skb: data pointer
3866 *
3867 * if exception packet has set forward bit, copied new packet should be
3868 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3869 * put into pm queue and tx procedure will be differed
3870 *
3871 * Return: None
3872 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003873static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003874 struct hdd_adapter *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003875{
Leo Chang69c39692016-10-12 20:11:12 -07003876 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3877
Leo Chang69c39692016-10-12 20:11:12 -07003878 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Yun Park01deb2c2017-06-14 15:21:44 -07003879
3880 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
3881 qdf_nbuf_ipa_owned_set(skb);
3882
Leo Chang69c39692016-10-12 20:11:12 -07003883 /* WLAN subsystem is in suspend, put int queue */
3884 if (hdd_ipa->suspended) {
3885 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3886 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3887 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003888 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3889 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003890 pm_tx_cb->exception = true;
3891 pm_tx_cb->adapter = adapter;
3892 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003893 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003894 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3895 hdd_ipa->stats.num_tx_queued++;
3896 } else {
3897 /* Resume, put packet into WLAN TX */
3898 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003899 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003900 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3901 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003902 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003903 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003904 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003905 hdd_ipa->ipa_tx_forward++;
3906 }
3907 }
3908}
3909
3910/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003911 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3912 * @hdd_ipa: pointer to HDD IPA struct
3913 * @adapter: hdd adapter pointer
3914 * @desc: Firmware descriptor
3915 * @skb: Data buffer
3916 *
3917 * Return:
3918 * HDD_IPA_FORWARD_PKT_NONE
3919 * HDD_IPA_FORWARD_PKT_DISCARD
3920 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3921 *
3922 */
3923
3924static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3925 struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003926 struct hdd_adapter *adapter,
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003927 uint8_t desc,
3928 qdf_nbuf_t skb)
3929{
3930 int ret = HDD_IPA_FORWARD_PKT_NONE;
Yun Park0dad1002017-07-14 14:57:01 -07003931 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
3932 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003933
3934 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303935 if (!ol_txrx_fwd_desc_thresh_check(
Yun Park0dad1002017-07-14 14:57:01 -07003936 (struct ol_txrx_vdev_t *)cdp_get_vdev_from_vdev_id(soc,
3937 (struct cdp_pdev *)pdev,
3938 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303939 /* Drop the packet*/
3940 hdd_ipa->stats.num_tx_fwd_err++;
3941 kfree_skb(skb);
3942 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3943 return ret;
3944 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003945 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3946 "Forward packet to Tx (fw_desc=%d)", desc);
3947 hdd_ipa->ipa_tx_forward++;
3948
3949 if ((desc & FW_RX_DESC_DISCARD_M)) {
3950 hdd_ipa_forward(hdd_ipa, adapter, skb);
3951 hdd_ipa->ipa_rx_internel_drop_count++;
3952 hdd_ipa->ipa_rx_discard++;
3953 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3954 } else {
3955 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003956
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003957 if (cloned_skb)
3958 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3959 else
3960 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3961 "%s: tx skb alloc failed",
3962 __func__);
3963 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3964 }
3965 }
3966
3967 return ret;
3968}
3969
3970/**
Yun Park637d6482016-10-05 10:51:33 -07003971 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003972 * @priv: pointer to private data registered with IPA (we register a
3973 * pointer to the global IPA context)
3974 * @evt: the IPA event which triggered the callback
3975 * @data: data associated with the event
3976 *
3977 * Return: None
3978 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003979static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 unsigned long data)
3981{
3982 struct hdd_ipa_priv *hdd_ipa = NULL;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003983 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303984 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985 uint8_t iface_id;
3986 uint8_t session_id;
3987 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003989 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990
3991 hdd_ipa = (struct hdd_ipa_priv *)priv;
3992
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003993 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3994 return;
3995
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 switch (evt) {
3997 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303998 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003999
4000 /*
4001 * When SSR is going on or driver is unloading,
4002 * just drop the packets.
4003 */
4004 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4005 if (0 != status) {
4006 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4007 "Invalid context: drop packet");
4008 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4009 kfree_skb(skb);
4010 return;
4011 }
4012
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004013 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4014 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004015 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004016 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4018 session_id, iface_id);
4019 } else {
4020 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4021 }
4022
4023 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304024 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004025 "IPA_RECEIVE: Invalid iface_id: %u",
4026 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004027 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004028 "w2i -- skb",
4029 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004030 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004031 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032 return;
4033 }
4034
4035 iface_context = &hdd_ipa->iface_context[iface_id];
4036 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004037 if (!adapter) {
4038 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4039 "IPA_RECEIVE: Adapter is NULL");
4040 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4041 kfree_skb(skb);
4042 return;
4043 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304045 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004046 "w2i -- skb",
4047 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4049 hdd_ipa->stats.num_rx_excep++;
4050 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4051 } else {
4052 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4053 }
4054
4055 iface_context->stats.num_rx_ipa_excep++;
4056
4057 /* Disable to forward Intra-BSS Rx packets when
4058 * ap_isolate=1 in hostapd.conf
4059 */
Yun Park046101c2016-09-02 15:32:14 -07004060 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061 /*
4062 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4063 * all Rx packets to IPA uC, which need to be forwarded
4064 * to other interface.
4065 * And, IPA driver will send back to WLAN host driver
4066 * through exception pipe with fw_desc field set by FW.
4067 * Here we are checking fw_desc field for FORWARD bit
4068 * set, and forward to Tx. Then copy to kernel stack
4069 * only when DISCARD bit is not set.
4070 */
4071 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004072 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4073 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4074 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004075 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004077 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 "Intra-BSS FWD is disabled-skip forward to Tx");
4079 }
4080
4081 hdd_ipa_send_skb_to_network(skb, adapter);
4082 break;
4083
4084 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304085 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086 "w2i cb wrong event: 0x%x", evt);
4087 return;
4088 }
4089}
4090
4091/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004092 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4093 * @priv: pointer to private data registered with IPA (we register a
4094 * pointer to the global IPA context)
4095 * @evt: the IPA event which triggered the callback
4096 * @data: data associated with the event
4097 *
4098 * Return: None
4099 */
4100static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4101 unsigned long data)
4102{
4103 cds_ssr_protect(__func__);
4104 __hdd_ipa_w2i_cb(priv, evt, data);
4105 cds_ssr_unprotect(__func__);
4106}
4107
4108/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4110 * @skb: packet buffer which was transmitted
4111 *
4112 * Return: None
4113 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304114void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115{
4116 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004117 struct ipa_rx_data *ipa_tx_desc;
4118 struct hdd_ipa_tx_desc *tx_desc;
4119 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004120
Yun Park52b2b992016-09-22 15:49:51 -07004121 if (!qdf_nbuf_ipa_owned_get(skb)) {
4122 dev_kfree_skb_any(skb);
4123 return;
4124 }
4125
4126 /* Get Tx desc pointer from SKB CB */
4127 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4128 tx_desc = hdd_ipa->tx_desc_list + id;
4129 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4130
4131 /* Return Tx Desc to IPA */
4132 ipa_free_skb(ipa_tx_desc);
4133
4134 /* Return to free tx desc list */
4135 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4136 tx_desc->ipa_tx_desc_ptr = NULL;
4137 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4138 hdd_ipa->stats.num_tx_desc_q_cnt--;
4139 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004140
4141 hdd_ipa->stats.num_tx_comp_cnt++;
4142
4143 atomic_dec(&hdd_ipa->tx_ref_cnt);
4144
4145 hdd_ipa_rm_try_release(hdd_ipa);
4146}
4147
4148/**
4149 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4150 * @iface_context: interface-specific IPA context
4151 * @ipa_tx_desc: packet data descriptor
4152 *
4153 * Return: None
4154 */
4155static void hdd_ipa_send_pkt_to_tl(
4156 struct hdd_ipa_iface_context *iface_context,
4157 struct ipa_rx_data *ipa_tx_desc)
4158{
4159 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004160 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304161 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004162 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004163
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304164 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004165 adapter = iface_context->adapter;
4166 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304167 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004168 ipa_free_skb(ipa_tx_desc);
4169 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304170 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004171 hdd_ipa_rm_try_release(hdd_ipa);
4172 return;
4173 }
4174
4175 /*
4176 * During CAC period, data packets shouldn't be sent over the air so
4177 * drop all the packets here
4178 */
hqu70708ab2017-10-10 17:52:01 +08004179 if (QDF_SAP_MODE == adapter->device_mode ||
4180 QDF_P2P_GO_MODE == adapter->device_mode) {
4181 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4182 ipa_free_skb(ipa_tx_desc);
4183 qdf_spin_unlock_bh(&iface_context->interface_lock);
4184 iface_context->stats.num_tx_cac_drop++;
4185 hdd_ipa_rm_try_release(hdd_ipa);
4186 return;
4187 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004188 }
4189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004190 ++adapter->stats.tx_packets;
4191
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304192 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193
4194 skb = ipa_tx_desc->skb;
4195
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304196 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004197
4198 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304199 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004200 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304201 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004202 ipa_tx_desc->dma_addr
4203 + HDD_IPA_WLAN_FRAG_HEADER
4204 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004205 ipa_tx_desc->skb->len -=
4206 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4207 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304208 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004209
Yun Park52b2b992016-09-22 15:49:51 -07004210 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4211 /* get free Tx desc and assign ipa_tx_desc pointer */
4212 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4213 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4214 struct hdd_ipa_tx_desc, link);
4215 list_del(&tx_desc->link);
4216 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4217 hdd_ipa->stats.num_tx_desc_q_cnt++;
4218 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4219 /* Store Tx Desc index into SKB CB */
4220 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4221 } else {
4222 hdd_ipa->stats.num_tx_desc_error++;
4223 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4224 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4225 ipa_free_skb(ipa_tx_desc);
4226 hdd_ipa_rm_try_release(hdd_ipa);
4227 return;
4228 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004229
4230 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4231
Leo Changfdb45c32016-10-28 11:09:23 -07004232 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004233 (struct cdp_vdev *)iface_context->tl_context,
4234 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004235 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304236 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
jiad05c1e812017-08-01 16:48:52 +08004237 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 return;
4240 }
4241
4242 atomic_inc(&hdd_ipa->tx_ref_cnt);
4243
4244 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245}
4246
4247/**
Leo Chang11545d62016-10-17 14:53:50 -07004248 * hdd_ipa_is_present() - get IPA hw status
4249 * @hdd_ctx: pointer to hdd context
4250 *
4251 * ipa_uc_reg_rdyCB is not directly designed to check
4252 * ipa hw status. This is an undocumented function which
4253 * has confirmed with IPA team.
4254 *
4255 * Return: true - ipa hw present
4256 * false - ipa hw not present
4257 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004258bool hdd_ipa_is_present(struct hdd_context *hdd_ctx)
Leo Chang11545d62016-10-17 14:53:50 -07004259{
4260 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004261 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004262 return true;
4263 else
4264 return false;
4265}
4266
4267/**
Leo Chang69c39692016-10-12 20:11:12 -07004268 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269 * @work: pointer to the scheduled work
4270 *
4271 * Called during PM resume to send packets to TL which were queued
4272 * while host was in the process of suspending.
4273 *
4274 * Return: None
4275 */
Leo Chang69c39692016-10-12 20:11:12 -07004276static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004277{
4278 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4279 struct hdd_ipa_priv,
4280 pm_work);
4281 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304282 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004283 uint32_t dequeued = 0;
4284
Leo Chang69c39692016-10-12 20:11:12 -07004285 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4286 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304287 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304288 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4289 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304290 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291
4292 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004294 if (pm_tx_cb->exception) {
4295 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4296 "FLUSH EXCEPTION");
Govind Singh1dab23b2017-08-12 13:31:00 +05304297 if (pm_tx_cb->adapter->dev)
4298 hdd_softap_hard_start_xmit(skb,
4299 pm_tx_cb->adapter->dev);
Govind Singh02075942017-08-15 11:13:28 +05304300 else
4301 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004302 } else {
4303 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004305 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304306 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304308 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004309 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4310 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004311
4312 hdd_ipa->stats.num_tx_dequeued += dequeued;
4313 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4314 hdd_ipa->stats.num_max_pm_queue = dequeued;
4315}
4316
4317/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004318 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004319 * @priv: pointer to private data registered with IPA (we register a
4320 * pointer to the interface-specific IPA context)
4321 * @evt: the IPA event which triggered the callback
4322 * @data: data associated with the event
4323 *
4324 * Return: None
4325 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004326static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 unsigned long data)
4328{
4329 struct hdd_ipa_priv *hdd_ipa = NULL;
4330 struct ipa_rx_data *ipa_tx_desc;
4331 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304332 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304334 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004335
Mukul Sharma81661ae2015-10-30 20:26:02 +05304336 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004337 ipa_tx_desc = (struct ipa_rx_data *)data;
4338 hdd_ipa = iface_context->hdd_ipa;
4339
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004341 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4342 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004343 iface_context->stats.num_tx_drop++;
4344 return;
4345 }
4346
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004347 /*
4348 * When SSR is going on or driver is unloading, just drop the packets.
4349 * During SSR, there is no use in queueing the packets as STA has to
4350 * connect back any way
4351 */
4352 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304353 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354 ipa_free_skb(ipa_tx_desc);
4355 iface_context->stats.num_tx_drop++;
4356 return;
4357 }
4358
4359 skb = ipa_tx_desc->skb;
4360
Yun Parkb187d542016-11-14 18:10:04 -08004361 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4362 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363
4364 /*
4365 * If PROD resource is not requested here then there may be cases where
4366 * IPA hardware may be clocked down because of not having proper
4367 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4368 * workaround to request PROD resource while data is going over CONS
4369 * pipe to prevent the IPA hardware clockdown.
4370 */
4371 hdd_ipa_rm_request(hdd_ipa);
4372
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304373 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004374 /*
4375 * If host is still suspended then queue the packets and these will be
4376 * drained later when resume completes. When packet is arrived here and
4377 * host is suspended, this means that there is already resume is in
4378 * progress.
4379 */
4380 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304381 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004382 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4383 pm_tx_cb->iface_context = iface_context;
4384 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304385 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004386 hdd_ipa->stats.num_tx_queued++;
4387
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304388 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389 return;
4390 }
4391
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304392 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004393
4394 /*
4395 * If we are here means, host is not suspended, wait for the work queue
4396 * to finish.
4397 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004398 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399
4400 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4401}
4402
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004403/*
4404 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4405 * @priv: pointer to private data registered with IPA (we register a
4406 * pointer to the interface-specific IPA context)
4407 * @evt: the IPA event which triggered the callback
4408 * @data: data associated with the event
4409 *
4410 * Return: None
4411 */
4412static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4413 unsigned long data)
4414{
4415 cds_ssr_protect(__func__);
4416 __hdd_ipa_i2w_cb(priv, evt, data);
4417 cds_ssr_unprotect(__func__);
4418}
4419
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004421 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 * @hdd_ctx: Global HDD context
4423 *
4424 * Return: 0 on success, negativer errno on error
4425 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004426static int __hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004428 struct hdd_ipa_priv *hdd_ipa;
4429
4430 if (wlan_hdd_validate_context(hdd_ctx))
4431 return 0;
4432
4433 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434
4435 if (!hdd_ipa_is_enabled(hdd_ctx))
4436 return 0;
4437
4438 /*
4439 * Check if IPA is ready for suspend, If we are here means, there is
4440 * high chance that suspend would go through but just to avoid any race
4441 * condition after suspend started, these checks are conducted before
4442 * allowing to suspend.
4443 */
4444 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4445 return -EAGAIN;
4446
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304447 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448
4449 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304450 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451 return -EAGAIN;
4452 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304453 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004454
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304455 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004456 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304457 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458
4459 return 0;
4460}
4461
4462/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004463 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4464 * @hdd_ctx: Global HDD context
4465 *
4466 * Return: 0 on success, negativer errno on error
4467 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004468int hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004469{
4470 int ret;
4471
4472 cds_ssr_protect(__func__);
4473 ret = __hdd_ipa_suspend(hdd_ctx);
4474 cds_ssr_unprotect(__func__);
4475
4476 return ret;
4477}
4478
4479/**
4480 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004481 * hdd_ctx: Global HDD context
4482 *
4483 * Return: 0 on success, negative errno on error
4484 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004485static int __hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004486{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004487 struct hdd_ipa_priv *hdd_ipa;
4488
4489 if (wlan_hdd_validate_context(hdd_ctx))
4490 return 0;
4491
4492 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004493
4494 if (!hdd_ipa_is_enabled(hdd_ctx))
4495 return 0;
4496
4497 schedule_work(&hdd_ipa->pm_work);
4498
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304499 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004500 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304501 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004502
4503 return 0;
4504}
4505
4506/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004507 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4508 * hdd_ctx: Global HDD context
4509 *
4510 * Return: 0 on success, negative errno on error
4511 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004512int hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004513{
4514 int ret;
4515
4516 cds_ssr_protect(__func__);
4517 ret = __hdd_ipa_resume(hdd_ctx);
4518 cds_ssr_unprotect(__func__);
4519
4520 return ret;
4521}
4522
4523/**
Yun Park52b2b992016-09-22 15:49:51 -07004524 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4525 * @hdd_ipa: Global HDD IPA context
4526 *
4527 * Return: 0 on success, negative errno on error
4528 */
4529static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4530{
4531 int i;
4532 uint32_t max_desc_cnt;
4533 struct hdd_ipa_tx_desc *tmp_desc;
4534
Yun Parkd9c528e2017-08-30 16:34:57 -07004535 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
Yun Park52b2b992016-09-22 15:49:51 -07004536
4537 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4538
jiad14fe4fb2017-08-08 13:33:14 +08004539 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc) *
Yun Parkd9c528e2017-08-30 16:34:57 -07004540 max_desc_cnt);
Yun Park52b2b992016-09-22 15:49:51 -07004541
4542 if (!tmp_desc) {
4543 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkd9c528e2017-08-30 16:34:57 -07004544 "Free Tx descriptor allocation failed");
Yun Park52b2b992016-09-22 15:49:51 -07004545 return -ENOMEM;
4546 }
4547
4548 hdd_ipa->tx_desc_list = tmp_desc;
4549
4550 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004551 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004552 tmp_desc->id = i;
4553 tmp_desc->ipa_tx_desc_ptr = NULL;
4554 list_add_tail(&tmp_desc->link,
4555 &hdd_ipa->free_tx_desc_head);
4556 tmp_desc++;
4557 }
4558
4559 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4560 hdd_ipa->stats.num_tx_desc_error = 0;
4561
4562 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4563
4564 return 0;
4565}
4566
4567/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4569 * @hdd_ipa: Global HDD IPA context
4570 *
4571 * Return: 0 on success, negative errno on error
4572 */
4573static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4574{
4575 int i, ret = 0;
4576 struct ipa_sys_connect_params *ipa;
4577 uint32_t desc_fifo_sz;
4578
4579 /* The maximum number of descriptors that can be provided to a BAM at
4580 * once is one less than the total number of descriptors that the buffer
4581 * can contain.
4582 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4583 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4584 * be provided at once.
4585 * Because of above requirement, one extra descriptor will be added to
4586 * make sure hardware always has one descriptor.
4587 */
4588 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4589 + sizeof(struct sps_iovec);
4590
4591 /*setup TX pipes */
4592 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4593 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4594
4595 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4596 ipa->desc_fifo_sz = desc_fifo_sz;
4597 ipa->priv = &hdd_ipa->iface_context[i];
4598 ipa->notify = hdd_ipa_i2w_cb;
4599
4600 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4601 ipa->ipa_ep_cfg.hdr.hdr_len =
4602 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4603 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4604 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4605 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4606 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4607 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4608 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4609 } else {
4610 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4611 }
4612 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4613
4614 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4615 ipa->keep_ipa_awake = 1;
4616
4617 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4618 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004619 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4620 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004621 goto setup_sys_pipe_fail;
4622 }
4623 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4624 }
4625
4626 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4627 /*
4628 * Hard code it here, this can be extended if in case
4629 * PROD pipe is also per interface.
4630 * Right now there is no advantage of doing this.
4631 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004632 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4633
Yun Parkb4f591d2017-03-29 15:51:01 -07004634 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004635
4636 ipa->desc_fifo_sz = desc_fifo_sz;
4637 ipa->priv = hdd_ipa;
4638 ipa->notify = hdd_ipa_w2i_cb;
4639
4640 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4641 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4642 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4643 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4644
4645 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4646 ipa->keep_ipa_awake = 1;
4647
4648 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4649 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304650 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004651 "Failed for RX pipe: %d", ret);
4652 goto setup_sys_pipe_fail;
4653 }
4654 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4655 }
4656
Yun Parkd9c528e2017-08-30 16:34:57 -07004657 /* Allocate free Tx desc list */
Yun Park52b2b992016-09-22 15:49:51 -07004658 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4659 if (ret)
4660 goto setup_sys_pipe_fail;
4661
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004662 return ret;
4663
4664setup_sys_pipe_fail:
4665
4666 while (--i >= 0) {
4667 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304668 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004669 sizeof(struct hdd_ipa_sys_pipe));
4670 }
4671
4672 return ret;
4673}
4674
4675/**
4676 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4677 * @hdd_ipa: Global HDD IPA context
4678 *
4679 * Return: None
4680 */
4681static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4682{
4683 int ret = 0, i;
Yun Parkd9c528e2017-08-30 16:34:57 -07004684 uint32_t max_desc_cnt;
Yun Park52b2b992016-09-22 15:49:51 -07004685 struct hdd_ipa_tx_desc *tmp_desc;
4686 struct ipa_rx_data *ipa_tx_desc;
4687
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004688 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4689 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004690 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4691 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004692 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304693 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004694 ret);
4695
4696 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4697 }
4698 }
Yun Park52b2b992016-09-22 15:49:51 -07004699
4700 if (hdd_ipa->tx_desc_list) {
Yun Parkd9c528e2017-08-30 16:34:57 -07004701 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4702
Yun Park52b2b992016-09-22 15:49:51 -07004703 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004704 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004705 tmp_desc = hdd_ipa->tx_desc_list + i;
4706 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4707 if (ipa_tx_desc)
4708 ipa_free_skb(ipa_tx_desc);
4709 }
4710 tmp_desc = hdd_ipa->tx_desc_list;
4711 hdd_ipa->tx_desc_list = NULL;
4712 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4713 hdd_ipa->stats.num_tx_desc_error = 0;
4714 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4715 qdf_mem_free(tmp_desc);
4716 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004717}
4718
4719/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004720 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4721 * @iface_context: interface-specific IPA context
4722 *
4723 * Return: None
4724 */
4725static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4726{
Yun Parkfec73dc2017-09-06 10:40:07 -07004727 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
4728
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 if (iface_context == NULL)
4730 return;
4731
Yun Parkb4f591d2017-03-29 15:51:01 -07004732 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4733 iface_context->adapter->dev->name,
4734 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304736 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737 iface_context->adapter->ipa_context = NULL;
4738 iface_context->adapter = NULL;
4739 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304740 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004741 iface_context->ifa_address = 0;
4742 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304743 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304745 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004746 }
4747 iface_context->hdd_ipa->num_iface--;
Yun Parkfec73dc2017-09-06 10:40:07 -07004748 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: num_iface=%d",
4749 iface_context->hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750}
4751
4752/**
4753 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4754 * @hdd_ipa: HDD IPA global context
4755 * @adapter: Interface upon which IPA is being setup
4756 * @sta_id: Station ID of the API instance
4757 *
4758 * Return: 0 on success, negative errno value on error
4759 */
4760static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004761 struct hdd_adapter *adapter, uint8_t sta_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762{
4763 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park0dad1002017-07-14 14:57:01 -07004764 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
4765 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 void *tl_context = NULL;
4767 int i, ret = 0;
4768
Yun Parkfec73dc2017-09-06 10:40:07 -07004769 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
4770
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4772 * channel change indication. Since these indications are sent by lower
4773 * layer as SAP updates and IPA doesn't have to do anything for these
4774 * updates so ignoring!
4775 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004776 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777 return 0;
4778
4779 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4780 if (hdd_ipa->iface_context[i].adapter == NULL) {
4781 iface_context = &(hdd_ipa->iface_context[i]);
4782 break;
4783 }
4784 }
4785
4786 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304787 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004788 "All the IPA interfaces are in use");
4789 ret = -ENOMEM;
4790 goto end;
4791 }
4792
4793 adapter->ipa_context = iface_context;
4794 iface_context->adapter = adapter;
4795 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004796 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Yun Park0dad1002017-07-14 14:57:01 -07004797 soc, (struct cdp_pdev *)pdev, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004798 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304799 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004800 "Not able to get TL context sta_id: %d", sta_id);
4801 ret = -EINVAL;
4802 goto end;
4803 }
4804
4805 iface_context->tl_context = tl_context;
4806
Yun Parkb4f591d2017-03-29 15:51:01 -07004807 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4808 adapter->dev->name, adapter->dev->dev_addr,
4809 iface_context->prod_client,
4810 iface_context->cons_client,
4811 adapter->sessionId,
4812 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004813 if (ret)
4814 goto end;
4815
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004816 hdd_ipa->num_iface++;
Yun Parkfec73dc2017-09-06 10:40:07 -07004817
4818 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: num_iface=%d",
4819 hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004820 return ret;
4821
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004822end:
4823 if (iface_context)
4824 hdd_ipa_cleanup_iface(iface_context);
4825 return ret;
4826}
4827
Yun Parka27049a2016-10-11 12:30:49 -07004828#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004829/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004830 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Jeff Johnson4929cd92017-10-06 19:21:57 -07004831 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004832 * @mcc_mode: 0=MCC/1=SCC
4833 *
4834 * Return: 0 on success, negative errno value on error
4835 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07004836static int __hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx,
4837 bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004838{
4839 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304840 QDF_STATUS status;
Jeff Johnson089d0432017-10-02 13:27:21 -07004841 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004842 struct ipa_msg_meta meta;
4843 struct ipa_wlan_msg *msg;
4844 int ret;
4845
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004846 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004847 return -EINVAL;
4848
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004849 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4850 return -EINVAL;
4851
4852 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004853 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004854 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304855 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson089d0432017-10-02 13:27:21 -07004856 adapter = adapter_node->adapter;
4857 if (adapter->device_mode == QDF_STA_MODE ||
4858 adapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004859 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnson089d0432017-10-02 13:27:21 -07004860 adapter->device_mode);
4861 hdd_deinit_tx_rx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004862 }
4863 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004864 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004865 adapter_node = next;
4866 }
4867 }
4868
4869 /* Send SCC/MCC Switching event to IPA */
4870 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304871 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004872 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004873 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004874 return -ENOMEM;
4875 }
4876
4877 meta.msg_type = mcc_mode ?
4878 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08004879 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004880
4881 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4882
4883 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004884 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004885 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304886 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004887 }
4888
4889 return ret;
4890}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004891
4892/**
4893 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
4894 * @mcc_mode: 0=MCC/1=SCC
4895 *
4896 * Return: 0 on success, negative errno value on error
4897 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004898int hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004899{
4900 int ret;
4901
4902 cds_ssr_protect(__func__);
4903 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
4904 cds_ssr_unprotect(__func__);
4905
4906 return ret;
4907}
Yun Parka27049a2016-10-11 12:30:49 -07004908#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004909
4910/**
4911 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
4912 * @event: IPA WLAN event to be converted to a string
4913 *
4914 * Return: ASCII string representing the IPA WLAN event
4915 */
4916static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
4917{
4918 switch (event) {
4919 case WLAN_CLIENT_CONNECT:
4920 return "WLAN_CLIENT_CONNECT";
4921 case WLAN_CLIENT_DISCONNECT:
4922 return "WLAN_CLIENT_DISCONNECT";
4923 case WLAN_CLIENT_POWER_SAVE_MODE:
4924 return "WLAN_CLIENT_POWER_SAVE_MODE";
4925 case WLAN_CLIENT_NORMAL_MODE:
4926 return "WLAN_CLIENT_NORMAL_MODE";
4927 case SW_ROUTING_ENABLE:
4928 return "SW_ROUTING_ENABLE";
4929 case SW_ROUTING_DISABLE:
4930 return "SW_ROUTING_DISABLE";
4931 case WLAN_AP_CONNECT:
4932 return "WLAN_AP_CONNECT";
4933 case WLAN_AP_DISCONNECT:
4934 return "WLAN_AP_DISCONNECT";
4935 case WLAN_STA_CONNECT:
4936 return "WLAN_STA_CONNECT";
4937 case WLAN_STA_DISCONNECT:
4938 return "WLAN_STA_DISCONNECT";
4939 case WLAN_CLIENT_CONNECT_EX:
4940 return "WLAN_CLIENT_CONNECT_EX";
4941
4942 case IPA_WLAN_EVENT_MAX:
4943 default:
4944 return "UNKNOWN";
4945 }
4946}
4947
4948/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004949 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
4950 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
4951 *
4952 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
4953 */
4954static enum ipa_wlan_event
4955hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
4956{
4957 enum ipa_wlan_event ipa_event;
4958
4959 switch (hdd_ipa_event_type) {
4960 case HDD_IPA_CLIENT_CONNECT:
4961 ipa_event = WLAN_CLIENT_CONNECT;
4962 break;
4963 case HDD_IPA_CLIENT_DISCONNECT:
4964 ipa_event = WLAN_CLIENT_DISCONNECT;
4965 break;
4966 case HDD_IPA_AP_CONNECT:
4967 ipa_event = WLAN_AP_CONNECT;
4968 break;
4969 case HDD_IPA_AP_DISCONNECT:
4970 ipa_event = WLAN_AP_DISCONNECT;
4971 break;
4972 case HDD_IPA_STA_CONNECT:
4973 ipa_event = WLAN_STA_CONNECT;
4974 break;
4975 case HDD_IPA_STA_DISCONNECT:
4976 ipa_event = WLAN_STA_DISCONNECT;
4977 break;
4978 case HDD_IPA_CLIENT_CONNECT_EX:
4979 ipa_event = WLAN_CLIENT_CONNECT_EX;
4980 break;
4981 case HDD_IPA_WLAN_EVENT_MAX:
4982 default:
4983 ipa_event = IPA_WLAN_EVENT_MAX;
4984 break;
4985 }
4986 return ipa_event;
4987
4988}
4989
4990/**
4991 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004992 * @adapter: adapter upon which the event was received
4993 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07004994 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995 * @mac_address: MAC address associated with the event
4996 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07004997 * This function is meant to be called from within wlan_hdd_ipa.c
4998 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004999 * Return: 0 on success, negative errno value on error
5000 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005001static int __hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005002 enum ipa_wlan_event type, uint8_t *mac_addr)
5003{
5004 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5005 struct ipa_msg_meta meta;
5006 struct ipa_wlan_msg *msg;
5007 struct ipa_wlan_msg_ex *msg_ex = NULL;
5008 int ret;
5009
Yun Parkfec73dc2017-09-06 10:40:07 -07005010 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005011 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5012 mac_addr, sta_id);
5013
5014 if (type >= IPA_WLAN_EVENT_MAX)
5015 return -EINVAL;
5016
5017 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5018 return -EINVAL;
5019
5020 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305021 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022 return -EINVAL;
5023 }
5024
5025 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5026 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005027 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005028 return 0;
5029 }
5030
5031 /*
5032 * During IPA UC resource loading/unloading new events can be issued.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005033 */
Yun Park777d7242017-03-30 15:38:33 -07005034 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5035 (hdd_ipa->resource_loading || hdd_ipa->resource_unloading)) {
5036 unsigned int pending_event_count;
5037 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005038
Yun Park777d7242017-03-30 15:38:33 -07005039 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5040 "%s:IPA resource %s inprogress",
5041 hdd_ipa_wlan_event_to_str(type),
5042 hdd_ipa->resource_loading ?
5043 "load" : "unload");
5044
5045 /* Wait until completion of the long/unloading */
5046 ret = wait_for_completion_timeout(&hdd_ipa->ipa_resource_comp,
5047 msecs_to_jiffies(IPA_RESOURCE_COMP_WAIT_TIME));
5048 if (!ret) {
5049 /*
5050 * If timed out, store the events separately and
5051 * handle them later.
5052 */
Yun Park64c405e2017-01-10 22:35:51 -08005053 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park777d7242017-03-30 15:38:33 -07005054 "IPA resource %s timed out",
5055 hdd_ipa->resource_loading ?
5056 "load" : "unload");
Yun Park7c4f31b2016-11-30 10:09:21 -08005057
Yun Park777d7242017-03-30 15:38:33 -07005058 if (hdd_ipa->resource_loading) {
5059 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005060
Yun Park777d7242017-03-30 15:38:33 -07005061 pending_event_count =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005062 qdf_list_size(&hdd_ipa->pending_event);
Yun Park777d7242017-03-30 15:38:33 -07005063 if (pending_event_count >=
5064 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
5065 hdd_debug(
5066 "Reached max pending event count");
5067 qdf_list_remove_front(
5068 &hdd_ipa->pending_event,
5069 (qdf_list_node_t **)&pending_event);
5070 } else {
5071 pending_event =
5072 (struct ipa_uc_pending_event *)
5073 qdf_mem_malloc(sizeof(
5074 struct ipa_uc_pending_event));
5075 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005076
Yun Park777d7242017-03-30 15:38:33 -07005077 if (!pending_event) {
5078 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5079 "Pending event memory alloc fail");
5080 qdf_mutex_release(&hdd_ipa->ipa_lock);
5081 return -ENOMEM;
5082 }
5083
5084 pending_event->adapter = adapter;
5085 pending_event->sta_id = sta_id;
5086 pending_event->type = type;
5087 qdf_mem_copy(pending_event->mac_addr,
5088 mac_addr, QDF_MAC_ADDR_SIZE);
5089 qdf_list_insert_back(&hdd_ipa->pending_event,
5090 &pending_event->node);
5091
Yun Park64c405e2017-01-10 22:35:51 -08005092 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005093 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005094 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005095 }
Jeff Johnson4929cd92017-10-06 19:21:57 -07005096 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5097 "IPA resource %s completed",
5098 hdd_ipa->resource_loading ?
5099 "load" : "unload");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005100 }
5101
5102 hdd_ipa->stats.event[type]++;
5103
Leo Chang3bc8fed2015-11-13 10:59:47 -08005104 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005105 switch (type) {
5106 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005107 qdf_mutex_acquire(&hdd_ipa->event_lock);
5108
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005109 /* STA already connected and without disconnect, connect again
5110 * This is Roaming scenario
5111 */
5112 if (hdd_ipa->sta_connected)
5113 hdd_ipa_cleanup_iface(adapter->ipa_context);
5114
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5116 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305117 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005118 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005119 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005120
Yun Park8f289c82016-10-18 16:38:21 -07005121 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5122 (hdd_ipa->sap_num_connected_sta > 0) &&
5123 !hdd_ipa->sta_connected) {
5124 qdf_mutex_release(&hdd_ipa->event_lock);
5125 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005126 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005127 qdf_mutex_acquire(&hdd_ipa->event_lock);
5128 }
5129
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005130 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005131 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005132 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005135
5136 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005137
5138 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sta_connected=%d",
5139 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005140 break;
5141
5142 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005143 qdf_mutex_acquire(&hdd_ipa->event_lock);
5144
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005145 /* For DFS channel we get two start_bss event (before and after
5146 * CAC). Also when ACS range includes both DFS and non DFS
5147 * channels, we could possibly change channel many times due to
5148 * RADAR detection and chosen channel may not be a DFS channels.
5149 * So dont return error here. Just discard the event.
5150 */
Yun Park8f289c82016-10-18 16:38:21 -07005151 if (adapter->ipa_context) {
5152 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005153 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005154 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005155
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005156 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5157 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005158 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005159 hdd_err("%s: Evt: %d, Interface setup failed",
5160 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005161 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005162 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163
Yun Park8f289c82016-10-18 16:38:21 -07005164 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5165 qdf_mutex_release(&hdd_ipa->event_lock);
5166 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005167 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005168 qdf_mutex_acquire(&hdd_ipa->event_lock);
5169 }
5170
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005171 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005172 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005173 (adapter->ipa_context))->iface_id;
5174
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305175 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 break;
5177
5178 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305179 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005180
5181 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005182 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005183 hdd_err("%s: Evt: %d, STA already disconnected",
5184 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005185 return -EINVAL;
5186 }
Yun Parka37592b2016-06-11 17:10:28 -07005187
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005190 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005191 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005192 msg_ex->name);
5193 } else {
5194 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Park3b7152b2017-08-25 08:33:37 -07005195 if ((1 == hdd_ipa->num_iface) &&
Yun Parka37592b2016-06-11 17:10:28 -07005196 (HDD_IPA_UC_NUM_WDI_PIPE ==
Yun Park3b7152b2017-08-25 08:33:37 -07005197 hdd_ipa->activated_fw_pipe) &&
5198 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005200 }
5201
Yun Park74127cf2016-09-18 11:22:41 -07005202 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5203 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005204 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005205 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005206 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005207 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005208 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5209 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 }
5211
Yun Park8f289c82016-10-18 16:38:21 -07005212 hdd_ipa_cleanup_iface(adapter->ipa_context);
5213
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305214 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005215
5216 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sta_connected=%d",
5217 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005218 break;
5219
5220 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005221 qdf_mutex_acquire(&hdd_ipa->event_lock);
5222
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005223 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005224 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005225 hdd_err("%s: Evt: %d, SAP already disconnected",
5226 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227 return -EINVAL;
5228 }
5229
Yun Park3b7152b2017-08-25 08:33:37 -07005230 if ((1 == hdd_ipa->num_iface) &&
5231 (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
5232 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005233 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 /*
5235 * We disable WDI pipes directly here since
5236 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5237 * processed when unloading WLAN driver is in
5238 * progress
5239 */
5240 hdd_ipa_uc_disable_pipes(hdd_ipa);
5241 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305242 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005243 "NO INTF left but still pipe clean up");
5244 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5245 }
5246 }
5247
5248 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005249 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005250 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005251 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005252 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005253 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5254 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005255 }
Yun Parka37592b2016-06-11 17:10:28 -07005256
Yun Park8f289c82016-10-18 16:38:21 -07005257 hdd_ipa_cleanup_iface(adapter->ipa_context);
5258
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305259 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005260 break;
5261
5262 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005263 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005264 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005265 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305266 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005267 return 0;
5268 }
5269
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305270 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5272 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005273 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305274 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 "%s: STA ID %d found, not valid",
5276 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005277 return 0;
5278 }
Yun Park312f71a2015-12-08 10:22:42 -08005279
5280 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005281 if (hdd_ipa->sap_num_connected_sta == 0 &&
5282 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005283 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005284 hdd_ipa->sta_connected) {
5285 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005286 hdd_ipa_uc_offload_enable_disable(
5287 hdd_get_adapter(hdd_ipa->hdd_ctx,
5288 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005289 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005290 qdf_mutex_acquire(&hdd_ipa->event_lock);
5291 }
Yun Parka37592b2016-06-11 17:10:28 -07005292
Yun Park312f71a2015-12-08 10:22:42 -08005293 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5294 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305295 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005296 "%s: handle 1st con ret %d",
5297 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005298
5299 if (hdd_ipa_uc_sta_is_enabled(
5300 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005301 hdd_ipa->sta_connected) {
5302 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005303 hdd_ipa_uc_offload_enable_disable(
5304 hdd_get_adapter(
5305 hdd_ipa->hdd_ctx,
5306 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005307 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005308 } else {
5309 qdf_mutex_release(&hdd_ipa->event_lock);
5310 }
Yun Parka37592b2016-06-11 17:10:28 -07005311
Yun Park312f71a2015-12-08 10:22:42 -08005312 return ret;
5313 }
5314 }
5315
5316 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005317
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305318 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005319
5320 meta.msg_type = type;
5321 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5322 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305323 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005324
5325 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305326 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005327 "msg_ex allocation failed");
5328 return -ENOMEM;
5329 }
5330 strlcpy(msg_ex->name, adapter->dev->name,
5331 IPA_RESOURCE_NAME_MAX);
5332 msg_ex->num_of_attribs = 1;
5333 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5334 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5335 msg_ex->attribs[0].offset =
5336 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5337 } else {
5338 msg_ex->attribs[0].offset =
5339 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5340 }
5341 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5342 IPA_MAC_ADDR_SIZE);
5343
5344 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5345
5346 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005347 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305348 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305349 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005350 return ret;
5351 }
5352 hdd_ipa->stats.num_send_msg++;
Yun Parkfec73dc2017-09-06 10:40:07 -07005353
5354 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sap_num_connected_sta=%d",
5355 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005356 return ret;
5357
5358 case WLAN_CLIENT_DISCONNECT:
5359 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005360 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005361 "%s: IPA UC OFFLOAD NOT ENABLED",
5362 msg_ex->name);
5363 return 0;
5364 }
5365
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305366 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Park73ea8bb2017-08-25 07:27:39 -07005367 if (!hdd_ipa->sap_num_connected_sta) {
5368 qdf_mutex_release(&hdd_ipa->event_lock);
5369 hdd_err("%s: Evt: %d, Client already disconnected",
5370 msg_ex->name, meta.msg_type);
5371 return 0;
5372 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005373 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005374 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305375 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005376 "%s: STA ID %d NOT found, not valid",
5377 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005378 return 0;
5379 }
5380 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005381
Yun Park9b5030f2016-11-08 12:02:37 -08005382 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005383 if (!hdd_ipa->sap_num_connected_sta &&
5384 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005385 if ((false == hdd_ipa->resource_unloading)
5386 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305387 hdd_ipa->activated_fw_pipe) &&
5388 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005389 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5390 }
5391
Yun Park9b5030f2016-11-08 12:02:37 -08005392 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005393 hdd_ipa->sta_connected) {
5394 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005395 hdd_ipa_uc_offload_enable_disable(
5396 hdd_get_adapter(hdd_ipa->hdd_ctx,
5397 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005398 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005399 } else {
5400 qdf_mutex_release(&hdd_ipa->event_lock);
5401 }
Yun Park8f289c82016-10-18 16:38:21 -07005402 } else {
5403 qdf_mutex_release(&hdd_ipa->event_lock);
5404 }
Yun Parkfec73dc2017-09-06 10:40:07 -07005405
5406 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "sap_num_connected_sta=%d",
5407 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005408 break;
5409
5410 default:
5411 return 0;
5412 }
5413
5414 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305415 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305417 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005418 return -ENOMEM;
5419 }
5420
5421 meta.msg_type = type;
5422 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5423 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5424
Srinivas Girigowda97852372017-03-06 16:52:59 -08005425 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005426 msg->name, meta.msg_type);
5427
5428 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5429
5430 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005431 hdd_err("%s: Evt: %d fail:%d",
5432 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305433 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005434 return ret;
5435 }
5436
5437 hdd_ipa->stats.num_send_msg++;
5438
5439end:
5440 return ret;
5441}
5442
5443/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005444 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005445 * @adapter: adapter upon which the event was received
5446 * @sta_id: station id for the event
5447 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5448 * @mac_address: MAC address associated with the event
5449 *
5450 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5451 *
5452 * Return: 0 on success, negative errno value on error
5453 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005454int hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005455 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5456{
5457 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005458 int ret = 0;
5459
5460 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005461
Leo Changa202b522016-10-14 16:13:50 -07005462 /* Data path offload only support for STA and SAP mode */
5463 if ((QDF_STA_MODE == adapter->device_mode) ||
5464 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005465 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005466
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005467 cds_ssr_unprotect(__func__);
5468
5469 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005470}
5471
5472/**
5473 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5474 * @hdd_ipa: Global HDD IPA context
5475 *
5476 * Return: None
5477 */
5478static void
5479hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5480{
5481 unsigned int pending_event_count;
5482 struct ipa_uc_pending_event *pending_event = NULL;
5483
5484 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005485 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005486 "%s, Pending Event Count %d", __func__, pending_event_count);
5487 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005488 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005489 "%s, No Pending Event", __func__);
5490 return;
5491 }
5492
5493 qdf_list_remove_front(&hdd_ipa->pending_event,
5494 (qdf_list_node_t **)&pending_event);
5495 while (pending_event != NULL) {
5496 __hdd_ipa_wlan_evt(pending_event->adapter,
5497 pending_event->type,
5498 pending_event->sta_id,
5499 pending_event->mac_addr);
5500 qdf_mem_free(pending_event);
5501 pending_event = NULL;
5502 qdf_list_remove_front(&hdd_ipa->pending_event,
5503 (qdf_list_node_t **)&pending_event);
5504 }
5505}
5506
5507/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005508 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5509 * @state: IPA RM state value
5510 *
5511 * Return: ASCII string representing the IPA RM state
5512 */
5513static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5514{
5515 switch (state) {
5516 case HDD_IPA_RM_RELEASED:
5517 return "RELEASED";
5518 case HDD_IPA_RM_GRANT_PENDING:
5519 return "GRANT_PENDING";
5520 case HDD_IPA_RM_GRANTED:
5521 return "GRANTED";
5522 }
5523
5524 return "UNKNOWN";
5525}
5526
5527/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005528 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005529 * @hdd_ctx: HDD global context
5530 *
5531 * Allocate hdd_ipa resources, ipa pipe resource and register
5532 * wlan interface with IPA module.
5533 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305534 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005535 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005536static QDF_STATUS __hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005537{
5538 struct hdd_ipa_priv *hdd_ipa = NULL;
5539 int ret, i;
5540 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005541 struct ol_txrx_pdev_t *pdev = NULL;
Yun Park66f24c42017-03-20 10:39:47 -07005542 struct ipa_rm_perf_profile profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543
Yun Parkfec73dc2017-09-06 10:40:07 -07005544 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "enter");
5545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005546 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305547 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548
Yun Parkbaa62862017-01-18 13:43:34 -08005549 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005550 if (!pdev) {
5551 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5552 goto fail_return;
5553 }
5554
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305555 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005556 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305557 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005558 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559 }
5560
5561 hdd_ctx->hdd_ipa = hdd_ipa;
5562 ghdd_ipa = hdd_ipa;
5563 hdd_ipa->hdd_ctx = hdd_ctx;
5564 hdd_ipa->num_iface = 0;
5565
5566 /* Create the interface context */
5567 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5568 iface_context = &hdd_ipa->iface_context[i];
5569 iface_context->hdd_ipa = hdd_ipa;
5570 iface_context->cons_client =
5571 hdd_ipa_adapter_2_client[i].cons_client;
5572 iface_context->prod_client =
5573 hdd_ipa_adapter_2_client[i].prod_client;
5574 iface_context->iface_id = i;
5575 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305576 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005577 }
5578 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005579 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5580 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005581 }
5582
Leo Chang69c39692016-10-12 20:11:12 -07005583 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305584 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005585 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305586 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005587 qdf_list_create(&hdd_ipa->pending_event, 1000);
5588 qdf_mutex_create(&hdd_ipa->event_lock);
5589 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005590
5591 ret = hdd_ipa_setup_rm(hdd_ipa);
5592 if (ret)
5593 goto fail_setup_rm;
5594
5595 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5596 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305597 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598 hdd_ipa->sap_num_connected_sta = 0;
5599 hdd_ipa->ipa_tx_packets_diff = 0;
5600 hdd_ipa->ipa_rx_packets_diff = 0;
5601 hdd_ipa->ipa_p_tx_packets = 0;
5602 hdd_ipa->ipa_p_rx_packets = 0;
5603 hdd_ipa->resource_loading = false;
5604 hdd_ipa->resource_unloading = false;
5605 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005606 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005607 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005608 /* Setup IPA sys_pipe for MCC */
5609 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5610 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5611 if (ret)
5612 goto fail_create_sys_pipe;
5613 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005614 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5615 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005616
5617 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5618 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5619 hdd_ipa_uc_fw_op_event_handler);
5620 hdd_ipa->uc_op_work[i].msg = NULL;
5621 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005622 } else {
5623 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5624 if (ret)
5625 goto fail_create_sys_pipe;
5626 }
5627
Yun Park66f24c42017-03-20 10:39:47 -07005628 /* When IPA clock scaling is disabled, initialze maximum clock */
5629 if (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)) {
5630 profile.max_supported_bandwidth_mbps = 800;
5631 hdd_debug("IPA clock scaling is disabled.");
5632 hdd_debug("Set initial CONS/PROD perf: %d",
5633 profile.max_supported_bandwidth_mbps);
5634 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
5635 &profile);
5636 if (ret) {
5637 hdd_err("RM CONS set perf profile failed: %d", ret);
5638 goto fail_create_sys_pipe;
5639 }
5640
5641 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
5642 &profile);
5643 if (ret) {
5644 hdd_err("RM PROD set perf profile failed: %d", ret);
5645 goto fail_create_sys_pipe;
5646 }
5647 }
5648
Yun Park777d7242017-03-30 15:38:33 -07005649 init_completion(&hdd_ipa->ipa_resource_comp);
5650
Yun Parkfec73dc2017-09-06 10:40:07 -07005651 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: success");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305652 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005653
5654fail_create_sys_pipe:
5655 hdd_ipa_destroy_rm_resource(hdd_ipa);
5656fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305657 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305658 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005659 hdd_ctx->hdd_ipa = NULL;
5660 ghdd_ipa = NULL;
5661fail_return:
Yun Parkfec73dc2017-09-06 10:40:07 -07005662 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "exit: fail");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305663 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005664}
5665
5666/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005667 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5668 * @hdd_ctx: HDD global context
5669 *
5670 * Allocate hdd_ipa resources, ipa pipe resource and register
5671 * wlan interface with IPA module.
5672 *
5673 * Return: QDF_STATUS enumeration
5674 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005675QDF_STATUS hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005676{
5677 QDF_STATUS ret;
5678
5679 cds_ssr_protect(__func__);
5680 ret = __hdd_ipa_init(hdd_ctx);
5681 cds_ssr_unprotect(__func__);
5682
5683 return ret;
5684}
5685
Arun Khandavallicc544b32017-01-30 19:52:16 +05305686
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005687/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305688 * __hdd_ipa_flush - flush IPA exception path SKB's
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689 * @hdd_ctx: HDD global context
5690 *
Govind Singh1dab23b2017-08-12 13:31:00 +05305691 * Return: none
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005692 */
Govind Singh1dab23b2017-08-12 13:31:00 +05305693static void __hdd_ipa_flush(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005694{
5695 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305696 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5698
5699 if (!hdd_ipa_is_enabled(hdd_ctx))
Govind Singh1dab23b2017-08-12 13:31:00 +05305700 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005702 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005703
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305704 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005705
Nirav Shahcbc6d722016-03-01 16:24:53 +05305706 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5707 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305708 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709
5710 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005711 if (pm_tx_cb->ipa_tx_desc)
5712 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005713
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305714 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005715 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305716 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Govind Singh1dab23b2017-08-12 13:31:00 +05305717}
5718
5719/**
5720 * __hdd_ipa_cleanup - IPA cleanup function
5721 * @hdd_ctx: HDD global context
5722 *
5723 * Return: QDF_STATUS enumeration
5724 */
5725static QDF_STATUS __hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
5726{
5727 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5728 int i;
5729 struct hdd_ipa_iface_context *iface_context = NULL;
5730
5731 if (!hdd_ipa_is_enabled(hdd_ctx))
5732 return QDF_STATUS_SUCCESS;
5733
5734 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5735 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5736 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5737 }
5738
5739 /* Teardown IPA sys_pipe for MCC */
5740 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5741 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5742
5743 hdd_ipa_destroy_rm_resource(hdd_ipa);
5744
5745 __hdd_ipa_flush(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305747 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005748 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005749
5750 /* destory the interface lock */
5751 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5752 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305753 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005754 }
5755
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005756 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005757 if (ipa_uc_dereg_rdyCB())
5758 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5759 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305761 qdf_mutex_destroy(&hdd_ipa->event_lock);
5762 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkd8fb1a82017-10-13 16:48:20 -07005763 qdf_list_destroy(&hdd_ipa->pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005764
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005765 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5766 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5767 hdd_ipa->uc_op_work[i].msg = NULL;
5768 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005769 }
5770
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305771 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005772 hdd_ctx->hdd_ipa = NULL;
5773
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305774 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005775}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005776
5777/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305778 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_flush
5779 * @hdd_ctx: HDD global context
5780 *
5781 * Return: None
5782 */
5783void hdd_ipa_flush(struct hdd_context *hdd_ctx)
5784{
5785 cds_ssr_protect(__func__);
5786 __hdd_ipa_flush(hdd_ctx);
5787 cds_ssr_unprotect(__func__);
5788}
5789
5790/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005791 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5792 * @hdd_ctx: HDD global context
5793 *
5794 * Return: QDF_STATUS enumeration
5795 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005796QDF_STATUS hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005797{
5798 QDF_STATUS ret;
5799
5800 cds_ssr_protect(__func__);
5801 ret = __hdd_ipa_cleanup(hdd_ctx);
5802 cds_ssr_unprotect(__func__);
5803
5804 return ret;
5805}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005806#endif /* IPA_OFFLOAD */