blob: aaa14b49da8c3a71d18d03e2c8190356c50704c4 [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 */
Yun Parkb4f591d2017-03-29 15:51:01 -070038#include <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;
215 hdd_adapter_t *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;
243 hdd_adapter_t *adapter;
244 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;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800330 hdd_adapter_t *adapter;
331 enum ipa_wlan_event type;
332 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530333 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334};
335
336/**
337 * struct uc_rm_work_struct
338 * @work: uC RM work
339 * @event: IPA RM event
340 */
341struct uc_rm_work_struct {
342 struct work_struct work;
343 enum ipa_rm_event event;
344};
345
346/**
347 * struct uc_op_work_struct
348 * @work: uC OP work
349 * @msg: OP message
350 */
351struct uc_op_work_struct {
352 struct work_struct work;
353 struct op_msg_type *msg;
354};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355
356/**
357 * struct uc_rt_debug_info
358 * @time: system time
359 * @ipa_excep_count: IPA exception packet count
360 * @rx_drop_count: IPA Rx drop packet count
361 * @net_sent_count: IPA Rx packet sent to network stack count
362 * @rx_discard_count: IPA Rx discard packet count
Yun Parkb187d542016-11-14 18:10:04 -0800363 * @tx_fwd_ok_count: IPA Tx forward success packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364 * @tx_fwd_count: IPA Tx forward packet count
365 * @rx_destructor_call: IPA Rx packet destructor count
366 */
367struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530368 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 uint64_t ipa_excep_count;
370 uint64_t rx_drop_count;
371 uint64_t net_sent_count;
372 uint64_t rx_discard_count;
Yun Parkb187d542016-11-14 18:10:04 -0800373 uint64_t tx_fwd_ok_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800374 uint64_t tx_fwd_count;
375 uint64_t rx_destructor_call;
376};
377
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
445 hdd_context_t *hdd_ctx;
446
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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800496};
497
Leo Changcc923e22016-06-16 15:29:03 -0700498#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
499#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800500#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
501#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
502#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
503#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
504#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700505#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
506 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507
508#define HDD_IPA_GET_IFACE_ID(_data) \
509 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
510
511#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530512 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800513 "%s:%d: "fmt, __func__, __LINE__, ## args)
514
Govind Singhb6a89772016-08-12 11:23:35 +0530515#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
516 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
517 "%s:%d: "fmt, __func__, __LINE__, ## args)
518
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800519#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
520 do { \
Yun Parkec845302016-12-15 09:22:57 -0800521 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
522 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800523 } while (0)
524
525#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
526 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
527
528#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
529 do { \
530 hdd_ipa->ipa_rx_internel_drop_count++; \
531 } while (0)
532#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
533 do { \
534 hdd_ipa->ipa_rx_net_send_count++; \
535 } while (0)
536#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
537
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700538#if defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)
Leo Chang63d73612016-10-18 18:09:43 -0700539#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800540#else
541/* Do nothing */
Leo Chang63d73612016-10-18 18:09:43 -0700542#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700543#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800544
Yun Parkb187d542016-11-14 18:10:04 -0800545#define HDD_IPA_DBG_DUMP_RX_LEN 32
546#define HDD_IPA_DBG_DUMP_TX_LEN 48
547
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800548static struct hdd_ipa_adapter_2_client {
549 enum ipa_client_type cons_client;
550 enum ipa_client_type prod_client;
551} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
552 {
553 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
554 }, {
555 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
556 }, {
557 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
558 },
559};
560
Yun Park637d6482016-10-05 10:51:33 -0700561#ifdef FEATURE_METERING
562#define IPA_UC_SHARING_STATES_WAIT_TIME 500
563#define IPA_UC_SET_QUOTA_WAIT_TIME 500
564#endif
565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800566static struct hdd_ipa_priv *ghdd_ipa;
567
568/* Local Function Prototypes */
569static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
570 unsigned long data);
571static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
572 unsigned long data);
Yun Parkb4f591d2017-03-29 15:51:01 -0700573#ifdef FEATURE_METERING
574static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
575 void *data);
576#else
577static void hdd_ipa_wdi_meter_notifier_cb(void);
578#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800579static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580
581static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700582static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800584#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
585 defined(IPA_CLIENT_IS_MHI_CONS))
586/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800587 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
588 * @priv_ctxt: hdd ipa local context
589 *
590 * Will be called by IPA context.
591 * It's atomic context, then should be scheduled to kworker thread
592 *
593 * Return: None
594 */
595static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
596{
597 struct hdd_ipa_priv *hdd_ipa;
598 struct op_msg_type *msg;
599 struct uc_op_work_struct *uc_op_work;
600
601 if (priv_ctxt == NULL) {
602 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
603 return;
604 }
605
606 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
607 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
608 if (!msg) {
609 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
610 return;
611 }
612
613 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
614
615 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
616
617 /* When the same uC OPCODE is already pended, just return */
618 if (uc_op_work->msg)
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530619 goto done;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800620
621 uc_op_work->msg = msg;
622 schedule_work(&uc_op_work->work);
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530623
jiadd91a6842017-08-01 14:46:02 +0800624 /* work handler will free the msg buffer */
625 return;
626
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530627done:
628 qdf_mem_free(msg);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800629}
630
631/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800632 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
633 * @ctrl: WDI control value
634 *
635 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
636 *
637 * Return: 0 on message send to ipa, -1 on failure
638 */
639static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
640{
641 struct ipa_msg_meta meta;
642 struct ipa_wlan_msg *ipa_msg;
643 int ret = 0;
644
645 /* WDI enable message to IPA */
646 meta.msg_len = sizeof(*ipa_msg);
647 ipa_msg = qdf_mem_malloc(meta.msg_len);
648 if (ipa_msg == NULL) {
649 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
650 "msg allocation failed");
651 return -ENOMEM;
652 }
653
654 if (ctrl == true)
655 meta.msg_type = WLAN_WDI_ENABLE;
656 else
657 meta.msg_type = WLAN_WDI_DISABLE;
658
Srinivas Girigowda97852372017-03-06 16:52:59 -0800659 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800660 "ipa_send_msg(Evt:%d)", meta.msg_type);
661 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
662 if (ret) {
663 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
664 "ipa_send_msg(Evt:%d)-fail=%d",
665 meta.msg_type, ret);
666 qdf_mem_free(ipa_msg);
667 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800668 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800669}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800670
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800671/**
672 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
673 * @hdd_ipa: HDD IPA local context
674 *
675 * Register IPA UC ready callback function to IPA kernel driver
676 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
677 * open WDI pipe after WLAN driver loading finished
678 *
679 * Return: 0 Success
680 * -EPERM Registration fail
681 */
682static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
683{
684 struct ipa_wdi_uc_ready_params uc_ready_param;
685 int ret = 0;
686
687 hdd_ipa->uc_loaded = false;
688 uc_ready_param.priv = (void *)hdd_ipa;
689 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
690 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
691 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
692 "UC Ready CB register fail");
693 return -EPERM;
694 }
695 if (true == uc_ready_param.is_uC_ready) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700696 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800697 hdd_ipa->uc_loaded = true;
698 } else {
699 ret = hdd_ipa_uc_send_wdi_control_msg(false);
700 }
701
702 return ret;
703}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800704#else
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800705static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
706{
707 hdd_ipa->uc_loaded = true;
708 return 0;
709}
710
711static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
712{
713 return 0;
714}
715#endif
716
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717/**
718 * hdd_ipa_is_enabled() - Is IPA enabled?
719 * @hdd_ctx: Global HDD context
720 *
721 * Return: true if IPA is enabled, false otherwise
722 */
723bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
724{
725 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
726}
727
728/**
729 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
730 * @hdd_ctx: Global HDD context
731 *
732 * Return: true if IPA uC offload is enabled, false otherwise
733 */
734bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
735{
736 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
737}
738
739/**
740 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
741 * @hdd_ctx: Global HDD context
742 *
743 * Return: true if STA mode IPA uC offload is enabled, false otherwise
744 */
745static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
746{
747 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
748}
749
750/**
Guolei Bianca144d82016-11-10 11:07:42 +0800751 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
752 * @hdd_ipa: Global HDD IPA context
753 *
754 * Return: None
755 */
Guolei Bianca144d82016-11-10 11:07:42 +0800756static inline void hdd_ipa_uc_sta_reset_sta_connected(
757 struct hdd_ipa_priv *hdd_ipa)
758{
Yun Park637d6482016-10-05 10:51:33 -0700759 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800760 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700761 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800762}
Guolei Bianca144d82016-11-10 11:07:42 +0800763
764/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
766 * @hdd_ipa: Global HDD IPA context
767 *
768 * Return: true if pre-filter is enabled, otherwise false
769 */
770static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
771{
772 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
773 HDD_IPA_PRE_FILTER_ENABLE_MASK);
774}
775
776/**
777 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
778 * @hdd_ipa: Global HDD IPA context
779 *
780 * Return: true if IPv6 is enabled, otherwise false
781 */
782static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
783{
784 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
785}
786
787/**
788 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
789 * @hdd_ipa: Global HDD IPA context
790 *
791 * Return: true if resource manager is enabled, otherwise false
792 */
793static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
794{
795 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
796}
797
798/**
799 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
800 * @hdd_ipa: Global HDD IPA context
801 *
802 * Return: true if resource manager is enabled, otherwise false
803 */
804static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
805{
806 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
807}
808
809/**
810 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
811 * @hdd_ipa: Global HDD IPA context
812 *
813 * Return: true if clock scaling is enabled, otherwise false
814 */
815static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
816{
817 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
818 HDD_IPA_CLK_SCALING_ENABLE_MASK |
819 HDD_IPA_RM_ENABLE_MASK);
820}
821
822/**
823 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
824 * @ctext: pointer to hdd context.
825 *
826 * If rt debug enabled, periodically called, and fill debug buffer
827 *
828 * Return: none
829 */
830static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
831{
832 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
833 struct hdd_ipa_priv *hdd_ipa;
834 struct uc_rt_debug_info *dump_info = NULL;
835
836 if (wlan_hdd_validate_context(hdd_ctx))
837 return;
838
839 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700840 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 return;
842 }
843
844 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
845
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530846 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 dump_info = &hdd_ipa->rt_bug_buffer[
848 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
849
Deepthi Gowri6acee342016-10-28 15:00:38 +0530850 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
852 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
853 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800855 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
856 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
858 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530859 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860
Anurag Chouhan210db072016-02-22 18:42:15 +0530861 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
863}
864
865/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700866 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 * @hdd_ctx: pointer to hdd context.
868 *
869 * If rt debug enabled, dump debug buffer contents based on requirement
870 *
871 * Return: none
872 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700873static void __hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874{
875 struct hdd_ipa_priv *hdd_ipa;
876 unsigned int dump_count;
877 unsigned int dump_index;
878 struct uc_rt_debug_info *dump_info = NULL;
879
880 if (wlan_hdd_validate_context(hdd_ctx))
881 return;
882
883 hdd_ipa = hdd_ctx->hdd_ipa;
884 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700885 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 return;
887 }
888
Chris Guo1751acf2017-07-03 14:09:01 +0800889 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
890 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
891 "%s: IPA RT debug is not enabled", __func__);
892 return;
893 }
894
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530895 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530897 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800898 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530900 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 for (dump_count = 0;
902 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
903 dump_count++) {
904 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
905 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
906 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530907 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530908 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 dump_info->time, dump_info->ipa_excep_count,
910 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800911 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 dump_info->rx_destructor_call,
913 dump_info->rx_discard_count);
914 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530915 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530916 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
918}
919
920/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700921 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
922 * __hdd_ipa_uc_rt_debug_host_dump
923 * @hdd_ctx: pointer to hdd context.
924 *
925 * If rt debug enabled, dump debug buffer contents based on requirement
926 *
927 * Return: none
928 */
929void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
930{
931 cds_ssr_protect(__func__);
932 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
933 cds_ssr_unprotect(__func__);
934}
935
936/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
938 * @ctext: pointer to hdd context.
939 *
940 * periodically called by timer expire
941 * will try to alloc dummy memory and detect out of memory condition
942 * if out of memory detected, dump wlan-ipa stats
943 *
944 * Return: none
945 */
946static void hdd_ipa_uc_rt_debug_handler(void *ctext)
947{
948 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700949 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 void *dummy_ptr = NULL;
951
952 if (wlan_hdd_validate_context(hdd_ctx))
953 return;
954
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700955 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700958 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
959 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 return;
961 }
962
963 /* Allocate dummy buffer periodically and free immediately. this will
964 * proactively detect OOM and if allocation fails dump ipa stats
965 */
966 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
967 GFP_KERNEL | GFP_ATOMIC);
968 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
970 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -0700971 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
972 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 } else {
974 kfree(dummy_ptr);
975 }
976
Anurag Chouhan210db072016-02-22 18:42:15 +0530977 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 HDD_IPA_UC_RT_DEBUG_PERIOD);
979}
980
981/**
Yun Parkb187d542016-11-14 18:10:04 -0800982 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800983 * @skb: packet pinter
984 *
985 * when free data packet, will be invoked by wlan client and will increase
986 * free counter
987 *
988 * Return: none
989 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700990static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991{
992 if (!ghdd_ipa) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700993 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "invalid hdd context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 return;
995 }
996
997 ghdd_ipa->ipa_rx_destructor_count++;
998}
999
1000/**
Yun Parkb187d542016-11-14 18:10:04 -08001001 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002 * @hdd_ctx: hdd main context
1003 *
1004 * free all rt debugging resources
1005 *
1006 * Return: none
1007 */
1008static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
1009{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001010 struct hdd_ipa_priv *hdd_ipa;
1011
1012 if (wlan_hdd_validate_context(hdd_ctx))
1013 return;
1014
1015 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301017 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018
1019 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001020 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1021 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 return;
1023 }
1024
Anurag Chouhan210db072016-02-22 18:42:15 +05301025 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001026 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1027 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1028 }
1029 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1030
1031 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301032 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1033 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301035 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036}
1037
1038/**
Yun Parkb187d542016-11-14 18:10:04 -08001039 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 * @hdd_ctx: hdd main context
1041 *
1042 * alloc and initialize all rt debugging resources
1043 *
1044 * Return: none
1045 */
1046static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
1047{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001048 struct hdd_ipa_priv *hdd_ipa;
1049
Chris Guo1751acf2017-07-03 14:09:01 +08001050 if (wlan_hdd_validate_context_in_loading(hdd_ctx))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001051 return;
1052
1053 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301055 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001056 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301057 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058 sizeof(struct uc_rt_debug_info) *
1059 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1060 hdd_ipa->ipa_tx_forward = 0;
1061 hdd_ipa->ipa_rx_discard = 0;
1062 hdd_ipa->ipa_rx_net_send_count = 0;
1063 hdd_ipa->ipa_rx_internel_drop_count = 0;
1064 hdd_ipa->ipa_rx_destructor_count = 0;
1065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066 /* Reatime debug enable on feature enable */
1067 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001068 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1069 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 return;
1071 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001072
1073 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1074 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1075 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1076 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1077
Anurag Chouhan210db072016-02-22 18:42:15 +05301078 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301080 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081 HDD_IPA_UC_RT_DEBUG_PERIOD);
1082
1083}
1084
1085/**
Yun Parkb187d542016-11-14 18:10:04 -08001086 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1087 * @hdd_ipa: HDD IPA struct
1088 *
1089 * Dump entries in struct hdd_ipa
1090 *
1091 * Return: none
1092 */
1093static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1094{
1095 int i;
1096
1097 /* HDD IPA */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001098 hdd_info("==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001099 "num_iface: %d\n"
1100 "rm_state: %d\n"
1101 "rm_lock: %p\n"
1102 "uc_rm_work: %p\n"
1103 "uc_op_work: %p\n"
1104 "wake_lock: %p\n"
1105 "wake_lock_work: %p\n"
1106 "wake_lock_released: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08001107 "tx_ref_cnt: %d\n"
1108 "pm_queue_head----\n"
1109 "\thead: %p\n"
1110 "\ttail: %p\n"
1111 "\tqlen: %d\n"
1112 "pm_work: %p\n"
1113 "pm_lock: %p\n"
1114 "suspended: %d\n",
1115 hdd_ipa->num_iface,
1116 hdd_ipa->rm_state,
1117 &hdd_ipa->rm_lock,
1118 &hdd_ipa->uc_rm_work,
1119 &hdd_ipa->uc_op_work,
1120 &hdd_ipa->wake_lock,
1121 &hdd_ipa->wake_lock_work,
1122 hdd_ipa->wake_lock_released,
Yun Parkb187d542016-11-14 18:10:04 -08001123 hdd_ipa->tx_ref_cnt.counter,
1124 hdd_ipa->pm_queue_head.head,
1125 hdd_ipa->pm_queue_head.tail,
1126 hdd_ipa->pm_queue_head.qlen,
1127 &hdd_ipa->pm_work,
1128 &hdd_ipa->pm_lock,
1129 hdd_ipa->suspended);
Yun Park52b2b992016-09-22 15:49:51 -07001130 hdd_err("\nq_lock: %p\n"
Yun Parkb187d542016-11-14 18:10:04 -08001131 "pend_desc_head----\n"
1132 "\tnext: %p\n"
1133 "\tprev: %p\n"
1134 "hdd_ctx: %p\n"
1135 "debugfs_dir: %p\n"
1136 "stats: %p\n"
1137 "ipv4_notifier: %p\n"
1138 "curr_prod_bw: %d\n"
1139 "curr_cons_bw: %d\n"
1140 "activated_fw_pipe: %d\n"
1141 "sap_num_connected_sta: %d\n"
1142 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001143 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001144 hdd_ipa->pend_desc_head.next,
1145 hdd_ipa->pend_desc_head.prev,
1146 hdd_ipa->hdd_ctx,
1147 hdd_ipa->debugfs_dir,
1148 &hdd_ipa->stats,
1149 &hdd_ipa->ipv4_notifier,
1150 hdd_ipa->curr_prod_bw,
1151 hdd_ipa->curr_cons_bw,
1152 hdd_ipa->activated_fw_pipe,
1153 hdd_ipa->sap_num_connected_sta,
1154 (unsigned int)hdd_ipa->sta_connected
1155 );
Srinivas Girigowda97852372017-03-06 16:52:59 -08001156 hdd_info("\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001157 "rx_pipe_handle: 0x%x\n"
1158 "resource_loading: %d\n"
1159 "resource_unloading: %d\n"
1160 "pending_cons_req: %d\n"
1161 "pending_event----\n"
1162 "\tanchor.next: %p\n"
1163 "\tanchor.prev: %p\n"
1164 "\tcount: %d\n"
1165 "\tmax_size: %d\n"
1166 "event_lock: %p\n"
1167 "ipa_tx_packets_diff: %d\n"
1168 "ipa_rx_packets_diff: %d\n"
1169 "ipa_p_tx_packets: %d\n"
1170 "ipa_p_rx_packets: %d\n"
1171 "stat_req_reason: %d\n",
1172 hdd_ipa->tx_pipe_handle,
1173 hdd_ipa->rx_pipe_handle,
1174 hdd_ipa->resource_loading,
1175 hdd_ipa->resource_unloading,
1176 hdd_ipa->pending_cons_req,
1177 hdd_ipa->pending_event.anchor.next,
1178 hdd_ipa->pending_event.anchor.prev,
1179 hdd_ipa->pending_event.count,
1180 hdd_ipa->pending_event.max_size,
1181 &hdd_ipa->event_lock,
1182 hdd_ipa->ipa_tx_packets_diff,
1183 hdd_ipa->ipa_rx_packets_diff,
1184 hdd_ipa->ipa_p_tx_packets,
1185 hdd_ipa->ipa_p_rx_packets,
1186 hdd_ipa->stat_req_reason);
1187
Srinivas Girigowda97852372017-03-06 16:52:59 -08001188 hdd_info("assoc_stas_map([id]is_reserved/sta_id): ");
Yun Parkb187d542016-11-14 18:10:04 -08001189 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001190 hdd_info(" [%d]%d/%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001191 hdd_ipa->assoc_stas_map[i].is_reserved,
1192 hdd_ipa->assoc_stas_map[i].sta_id);
1193 }
1194}
1195
1196/**
1197 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1198 * @hdd_ipa: HDD IPA struct
1199 *
1200 * Dump entire struct hdd_ipa_sys_pipe
1201 *
1202 * Return: none
1203 */
1204static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1205{
1206 int i;
1207
1208 /* IPA SYS Pipes */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001209 hdd_info("==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001210
1211 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1212 struct hdd_ipa_sys_pipe *sys_pipe;
1213 struct ipa_sys_connect_params *ipa_sys_params;
1214
1215 sys_pipe = &hdd_ipa->sys_pipe[i];
1216 ipa_sys_params = &sys_pipe->ipa_sys_params;
1217
Srinivas Girigowda97852372017-03-06 16:52:59 -08001218 hdd_info("sys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001219 "\tconn_hdl: 0x%x\n"
1220 "\tconn_hdl_valid: %d\n"
1221 "\tnat_en: %d\n"
1222 "\thdr_len %d\n"
1223 "\thdr_additional_const_len: %d\n"
1224 "\thdr_ofst_pkt_size_valid: %d\n"
1225 "\thdr_ofst_pkt_size: %d\n"
1226 "\thdr_little_endian: %d\n"
1227 "\tmode: %d\n"
1228 "\tclient: %d\n"
1229 "\tdesc_fifo_sz: %d\n"
1230 "\tpriv: %p\n"
1231 "\tnotify: %p\n"
1232 "\tskip_ep_cfg: %d\n"
1233 "\tkeep_ipa_awake: %d\n",
1234 i,
1235 sys_pipe->conn_hdl,
1236 sys_pipe->conn_hdl_valid,
1237 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1238 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1239 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1240 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1241 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1242 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1243 ipa_sys_params->ipa_ep_cfg.mode.mode,
1244 ipa_sys_params->client,
1245 ipa_sys_params->desc_fifo_sz,
1246 ipa_sys_params->priv,
1247 ipa_sys_params->notify,
1248 ipa_sys_params->skip_ep_cfg,
1249 ipa_sys_params->keep_ipa_awake);
1250 }
1251}
1252
1253/**
1254 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1255 * @hdd_ipa: HDD IPA struct
1256 *
1257 * Dump entire struct hdd_ipa_iface_context
1258 *
1259 * Return: none
1260 */
1261static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1262{
1263 int i;
1264
1265 /* IPA Interface Contexts */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001266 hdd_info("==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001267
1268 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1269 struct hdd_ipa_iface_context *iface_context;
1270
1271 iface_context = &hdd_ipa->iface_context[i];
1272
Srinivas Girigowda97852372017-03-06 16:52:59 -08001273 hdd_info("iface_context[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001274 "\thdd_ipa: %p\n"
1275 "\tadapter: %p\n"
1276 "\ttl_context: %p\n"
1277 "\tcons_client: %d\n"
1278 "\tprod_client: %d\n"
1279 "\tiface_id: %d\n"
1280 "\tsta_id: %d\n"
1281 "\tinterface_lock: %p\n"
1282 "\tifa_address: 0x%x\n",
1283 i,
1284 iface_context->hdd_ipa,
1285 iface_context->adapter,
1286 iface_context->tl_context,
1287 iface_context->cons_client,
1288 iface_context->prod_client,
1289 iface_context->iface_id,
1290 iface_context->sta_id,
1291 &iface_context->interface_lock,
1292 iface_context->ifa_address);
1293 }
1294}
1295
1296/**
1297 * hdd_ipa_dump_info() - dump HDD IPA struct
1298 * @pHddCtx: hdd main context
1299 *
1300 * Dump entire struct hdd_ipa
1301 *
1302 * Return: none
1303 */
1304void hdd_ipa_dump_info(hdd_context_t *hdd_ctx)
1305{
1306 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1307
1308 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1309 hdd_ipa_dump_sys_pipe(hdd_ipa);
1310 hdd_ipa_dump_iface_context(hdd_ipa);
1311}
1312
1313/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001314 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1315 * enabled
1316 *
1317 * This routine is called to set TX flow info if IPA is enabled
1318 *
1319 * Return: None
1320 */
1321void hdd_ipa_set_tx_flow_info(void)
1322{
1323 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1324 QDF_STATUS status;
1325 hdd_adapter_t *adapter;
1326 hdd_station_ctx_t *pHddStaCtx;
1327 hdd_ap_ctx_t *hdd_ap_ctx;
1328 hdd_hostapd_state_t *hostapd_state;
1329 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1330 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1331 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1332 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1333 const char *p2pMode = "DEV";
1334 hdd_context_t *hdd_ctx;
1335 cds_context_type *cds_ctx;
1336#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1337 uint8_t targetChannel = 0;
1338 uint8_t preAdapterChannel = 0;
1339 uint8_t channel24;
1340 uint8_t channel5;
1341 hdd_adapter_t *preAdapterContext = NULL;
1342 hdd_adapter_t *adapter2_4 = NULL;
1343 hdd_adapter_t *adapter5 = NULL;
1344 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1345#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1346 struct wlan_objmgr_psoc *psoc;
1347
1348 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1349 if (!hdd_ctx) {
1350 cds_err("HDD context is NULL");
1351 return;
1352 }
1353
1354 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1355 if (!cds_ctx) {
1356 cds_err("Invalid CDS Context");
1357 return;
1358 }
1359
1360 psoc = hdd_ctx->hdd_psoc;
1361 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1362 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1363 adapter = adapterNode->pAdapter;
1364 switch (adapter->device_mode) {
1365 case QDF_STA_MODE:
1366 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1367 if (eConnectionState_Associated ==
1368 pHddStaCtx->conn_info.connState) {
1369 staChannel =
1370 pHddStaCtx->conn_info.operationChannel;
1371 qdf_copy_macaddr(&staBssid,
1372 &pHddStaCtx->conn_info.bssId);
1373#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1374 targetChannel = staChannel;
1375#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1376 }
1377 break;
1378 case QDF_P2P_CLIENT_MODE:
1379 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1380 if (eConnectionState_Associated ==
1381 pHddStaCtx->conn_info.connState) {
1382 p2pChannel =
1383 pHddStaCtx->conn_info.operationChannel;
1384 qdf_copy_macaddr(&p2pBssid,
1385 &pHddStaCtx->conn_info.bssId);
1386 p2pMode = "CLI";
1387#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1388 targetChannel = p2pChannel;
1389#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1390 }
1391 break;
1392 case QDF_P2P_GO_MODE:
1393 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1394 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1395 if (hostapd_state->bssState == BSS_START
1396 && hostapd_state->qdf_status ==
1397 QDF_STATUS_SUCCESS) {
1398 p2pChannel = hdd_ap_ctx->operatingChannel;
1399 qdf_copy_macaddr(&p2pBssid,
1400 &adapter->macAddressCurrent);
1401#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1402 targetChannel = p2pChannel;
1403#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1404 }
1405 p2pMode = "GO";
1406 break;
1407 case QDF_SAP_MODE:
1408 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1409 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1410 if (hostapd_state->bssState == BSS_START
1411 && hostapd_state->qdf_status ==
1412 QDF_STATUS_SUCCESS) {
1413 apChannel = hdd_ap_ctx->operatingChannel;
1414 qdf_copy_macaddr(&apBssid,
1415 &adapter->macAddressCurrent);
1416#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1417 targetChannel = apChannel;
1418#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1419 }
1420 break;
1421 case QDF_IBSS_MODE:
1422 default:
1423 break;
1424 }
1425#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1426 if (targetChannel) {
1427 /*
1428 * This is first adapter detected as active
1429 * set as default for none concurrency case
1430 */
1431 if (!preAdapterChannel) {
1432 /* If IPA UC data path is enabled,
1433 * target should reserve extra tx descriptors
1434 * for IPA data path.
1435 * Then host data path should allow less TX
1436 * packet pumping in case IPA
1437 * data path enabled
1438 */
1439 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1440 (QDF_SAP_MODE == adapter->device_mode)) {
1441 adapter->tx_flow_low_watermark =
1442 hdd_ctx->config->TxFlowLowWaterMark +
1443 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1444 } else {
1445 adapter->tx_flow_low_watermark =
1446 hdd_ctx->config->
1447 TxFlowLowWaterMark;
1448 }
1449 adapter->tx_flow_high_watermark_offset =
1450 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1451 cdp_fc_ll_set_tx_pause_q_depth(soc,
1452 adapter->sessionId,
1453 hdd_ctx->config->TxFlowMaxQueueDepth);
1454 cds_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
1455 adapter->device_mode,
1456 targetChannel,
1457 adapter->tx_flow_low_watermark,
1458 adapter->tx_flow_low_watermark +
1459 adapter->tx_flow_high_watermark_offset,
1460 hdd_ctx->config->TxFlowMaxQueueDepth);
1461 preAdapterChannel = targetChannel;
1462 preAdapterContext = adapter;
1463 } else {
1464 /*
1465 * SCC, disable TX flow control for both
1466 * SCC each adapter cannot reserve dedicated
1467 * channel resource, as a result, if any adapter
1468 * blocked OS Q by flow control,
1469 * blocked adapter will lost chance to recover
1470 */
1471 if (preAdapterChannel == targetChannel) {
1472 /* Current adapter */
1473 adapter->tx_flow_low_watermark = 0;
1474 adapter->
1475 tx_flow_high_watermark_offset = 0;
1476 cdp_fc_ll_set_tx_pause_q_depth(soc,
1477 adapter->sessionId,
1478 hdd_ctx->config->
1479 TxHbwFlowMaxQueueDepth);
1480 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1481 hdd_device_mode_to_string(
1482 adapter->device_mode),
1483 adapter->device_mode,
1484 targetChannel,
1485 adapter->tx_flow_low_watermark,
1486 adapter->tx_flow_low_watermark +
1487 adapter->
1488 tx_flow_high_watermark_offset,
1489 hdd_ctx->config->
1490 TxHbwFlowMaxQueueDepth);
1491
1492 if (!preAdapterContext) {
1493 cds_err("SCC: Previous adapter context NULL");
1494 continue;
1495 }
1496
1497 /* Previous adapter */
1498 preAdapterContext->
1499 tx_flow_low_watermark = 0;
1500 preAdapterContext->
1501 tx_flow_high_watermark_offset = 0;
1502 cdp_fc_ll_set_tx_pause_q_depth(soc,
1503 preAdapterContext->sessionId,
1504 hdd_ctx->config->
1505 TxHbwFlowMaxQueueDepth);
1506 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1507 hdd_device_mode_to_string(
1508 preAdapterContext->device_mode
1509 ),
1510 preAdapterContext->device_mode,
1511 targetChannel,
1512 preAdapterContext->
1513 tx_flow_low_watermark,
1514 preAdapterContext->
1515 tx_flow_low_watermark +
1516 preAdapterContext->
1517 tx_flow_high_watermark_offset,
1518 hdd_ctx->config->
1519 TxHbwFlowMaxQueueDepth);
1520 }
1521 /*
1522 * MCC, each adapter will have dedicated
1523 * resource
1524 */
1525 else {
1526 /* current channel is 2.4 */
1527 if (targetChannel <=
1528 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1529 channel24 = targetChannel;
1530 channel5 = preAdapterChannel;
1531 adapter2_4 = adapter;
1532 adapter5 = preAdapterContext;
1533 } else {
1534 /* Current channel is 5 */
1535 channel24 = preAdapterChannel;
1536 channel5 = targetChannel;
1537 adapter2_4 = preAdapterContext;
1538 adapter5 = adapter;
1539 }
1540
1541 if (!adapter5) {
1542 cds_err("MCC: 5GHz adapter context NULL");
1543 continue;
1544 }
1545 adapter5->tx_flow_low_watermark =
1546 hdd_ctx->config->
1547 TxHbwFlowLowWaterMark;
1548 adapter5->
1549 tx_flow_high_watermark_offset =
1550 hdd_ctx->config->
1551 TxHbwFlowHighWaterMarkOffset;
1552 cdp_fc_ll_set_tx_pause_q_depth(soc,
1553 adapter5->sessionId,
1554 hdd_ctx->config->
1555 TxHbwFlowMaxQueueDepth);
1556 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1557 hdd_device_mode_to_string(
1558 adapter5->device_mode),
1559 adapter5->device_mode,
1560 channel5,
1561 adapter5->tx_flow_low_watermark,
1562 adapter5->
1563 tx_flow_low_watermark +
1564 adapter5->
1565 tx_flow_high_watermark_offset,
1566 hdd_ctx->config->
1567 TxHbwFlowMaxQueueDepth);
1568
1569 if (!adapter2_4) {
1570 cds_err("MCC: 2.4GHz adapter context NULL");
1571 continue;
1572 }
1573 adapter2_4->tx_flow_low_watermark =
1574 hdd_ctx->config->
1575 TxLbwFlowLowWaterMark;
1576 adapter2_4->
1577 tx_flow_high_watermark_offset =
1578 hdd_ctx->config->
1579 TxLbwFlowHighWaterMarkOffset;
1580 cdp_fc_ll_set_tx_pause_q_depth(soc,
1581 adapter2_4->sessionId,
1582 hdd_ctx->config->
1583 TxLbwFlowMaxQueueDepth);
1584 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1585 hdd_device_mode_to_string(
1586 adapter2_4->device_mode),
1587 adapter2_4->device_mode,
1588 channel24,
1589 adapter2_4->
1590 tx_flow_low_watermark,
1591 adapter2_4->
1592 tx_flow_low_watermark +
1593 adapter2_4->
1594 tx_flow_high_watermark_offset,
1595 hdd_ctx->config->
1596 TxLbwFlowMaxQueueDepth);
1597
1598 }
1599 }
1600 }
1601 targetChannel = 0;
1602#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1603 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1604 adapterNode = pNext;
1605 }
1606 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1607}
1608
1609/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001610 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001612 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1613 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 *
1615 * Return: true if IPA is enabled, false otherwise
1616 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001617static void __hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1619{
1620 struct hdd_ipa_priv *hdd_ipa;
1621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 *ipa_tx_diff = 0;
1623 *ipa_rx_diff = 0;
1624
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001625 if (wlan_hdd_validate_context(hdd_ctx))
1626 return;
1627
1628 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1629
1630 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1631 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 return;
1633 }
1634
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301635 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1637 (false == hdd_ipa->resource_loading)) {
1638 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1639 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001640 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641 *ipa_tx_diff, *ipa_rx_diff);
1642 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301643 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644}
1645
1646/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001647 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1648 * @hdd_ctx: Global HDD context
1649 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1650 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1651 *
1652 * Return: true if IPA is enabled, false otherwise
1653 */
1654void hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
1655 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1656{
1657 cds_ssr_protect(__func__);
1658 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1659 cds_ssr_unprotect(__func__);
1660}
1661
1662/**
1663 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664 * @adapter: network adapter
1665 * @reason: STAT REQ Reason
1666 *
1667 * Return: None
1668 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001669static void __hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001671 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001672 struct hdd_ipa_priv *hdd_ipa;
1673
Yun Park637d6482016-10-05 10:51:33 -07001674 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001675 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001677 hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
1678
1679 if (wlan_hdd_validate_context(hdd_ctx))
1680 return;
1681
1682 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1683 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1684 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001685 return;
1686 }
1687
Yun Parkb187d542016-11-14 18:10:04 -08001688 hdd_debug("STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301689 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1691 (false == hdd_ipa->resource_loading)) {
1692 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001693 qdf_mutex_release(&hdd_ipa->ipa_lock);
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001694 sme_ipa_uc_stat_request(WLAN_HDD_GET_HAL_CTX(adapter),
1695 adapter->sessionId,
1696 WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001697 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001698 } else {
1699 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001700 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701}
1702
1703/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001704 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1705 * @adapter: network adapter
1706 * @reason: STAT REQ Reason
1707 *
1708 * Return: None
1709 */
1710void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
1711{
1712 cds_ssr_protect(__func__);
1713 __hdd_ipa_uc_stat_request(adapter, reason);
1714 cds_ssr_unprotect(__func__);
1715}
1716
Yun Park637d6482016-10-05 10:51:33 -07001717#ifdef FEATURE_METERING
1718/**
1719 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1720 * @adapter: network adapter
1721 * @reset_stats: reset stat countis after response
1722 *
1723 * Return: None
1724 */
1725void hdd_ipa_uc_sharing_stats_request(hdd_adapter_t *adapter,
1726 uint8_t reset_stats)
1727{
1728 hdd_context_t *pHddCtx;
1729 struct hdd_ipa_priv *hdd_ipa;
1730
1731 if (!adapter)
1732 return;
1733
1734 pHddCtx = adapter->pHddCtx;
1735 hdd_ipa = pHddCtx->hdd_ipa;
1736 if (!hdd_ipa_is_enabled(pHddCtx) ||
1737 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1738 return;
1739 }
1740
1741 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1742 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001743 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001744 qdf_mutex_release(&hdd_ipa->ipa_lock);
1745 wma_cli_set_command(
1746 (int)adapter->sessionId,
1747 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1748 reset_stats, VDEV_CMD);
1749 } else {
1750 qdf_mutex_release(&hdd_ipa->ipa_lock);
1751 }
1752}
1753
1754/**
1755 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1756 * @adapter: network adapter
1757 * @set_quota: when 1, FW starts quota monitoring
1758 * @quota_bytes: quota limit in bytes
1759 *
1760 * Return: None
1761 */
1762void hdd_ipa_uc_set_quota(hdd_adapter_t *adapter, uint8_t set_quota,
1763 uint64_t quota_bytes)
1764{
1765 hdd_context_t *pHddCtx;
1766 struct hdd_ipa_priv *hdd_ipa;
1767
1768 if (!adapter)
1769 return;
1770
1771 pHddCtx = adapter->pHddCtx;
1772 hdd_ipa = pHddCtx->hdd_ipa;
1773 if (!hdd_ipa_is_enabled(pHddCtx) ||
1774 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1775 return;
1776 }
1777
1778 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1779 set_quota, quota_bytes);
1780
1781 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001782 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001783 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001784 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001785 (int)adapter->sessionId,
1786 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001787 (set_quota ? quota_bytes&0xffffffff : 0),
1788 (set_quota ? quota_bytes>>32 : 0),
1789 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001790 } else {
1791 qdf_mutex_release(&hdd_ipa->ipa_lock);
1792 }
1793}
1794#endif
1795
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001796/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1798 * @hdd_ipa: Global HDD IPA context
1799 * @sta_add: Should station be added
1800 * @sta_id: ID of the station being queried
1801 *
1802 * Return: true if the station was found
1803 */
1804static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1805 bool sta_add, uint8_t sta_id)
1806{
1807 bool sta_found = false;
1808 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001809
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001810 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1811 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1812 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1813 sta_found = true;
1814 break;
1815 }
1816 }
1817 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301818 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001819 "STA ID %d already exist, cannot add", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001820 return sta_found;
1821 }
1822 if (sta_add) {
1823 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1824 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1825 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1826 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1827 return sta_found;
1828 }
1829 }
1830 }
1831 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301832 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001833 "STA ID %d does not exist, cannot delete", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 return sta_found;
1835 }
1836 if (!sta_add) {
1837 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1838 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1839 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1840 hdd_ipa->assoc_stas_map[idx].is_reserved =
1841 false;
1842 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1843 return sta_found;
1844 }
1845 }
1846 }
1847 return sta_found;
1848}
1849
1850/**
1851 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1852 * @hdd_ipa: Global HDD IPA context
1853 *
1854 * Return: 0 on success, negative errno if error
1855 */
1856static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1857{
1858 int result;
Leo Changfdb45c32016-10-28 11:09:23 -07001859 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001860 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001861
Yun Parkb4f591d2017-03-29 15:51:01 -07001862 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001863 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301864 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001865 "Enable PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866 return result;
1867 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001868
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
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001873 return 0;
1874}
1875
1876/**
1877 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1878 * @hdd_ipa: Global HDD IPA context
1879 *
1880 * Return: 0 on success, negative errno if error
1881 */
1882static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1883{
Yun Parkb4f591d2017-03-29 15:51:01 -07001884 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1885 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001886 int result;
1887
Leo Change3e49442015-10-26 20:07:13 -07001888 hdd_ipa->ipa_pipes_down = true;
1889
Yun Parkb4f591d2017-03-29 15:51:01 -07001890 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891
Yun Parkb4f591d2017-03-29 15:51:01 -07001892 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301894 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001895 "Disable WDI PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001896 return result;
1897 }
1898
1899 return 0;
1900}
1901
1902/**
1903 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1904 * @hdd_ipa: Global HDD IPA context
1905 *
1906 * Return: 0 on success, negative errno if error
1907 */
1908static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1909{
Yun Parkb4f591d2017-03-29 15:51:01 -07001910 hdd_context_t *hdd_ctx = hdd_ipa->hdd_ctx;
1911
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912 hdd_ipa->activated_fw_pipe = 0;
1913 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001914
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001915 /* If RM feature enabled
1916 * Request PROD Resource first
Yun Parkb4f591d2017-03-29 15:51:01 -07001917 * PROD resource may return sync or async manners */
1918 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001919 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1920 /* RM PROD request sync return
1921 * enable pipe immediately
1922 */
1923 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301924 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001925 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001926 hdd_ipa->resource_loading = false;
1927 return -EBUSY;
1928 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001929 }
1930 } else {
1931 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001932 * Just enabled all the PIPEs
1933 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001934 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301935 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001936 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001937 hdd_ipa->resource_loading = false;
1938 return -EBUSY;
1939 }
1940 hdd_ipa->resource_loading = false;
1941 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001942
Srinivas Girigowda97852372017-03-06 16:52:59 -08001943 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07001944 "IPA WDI Pipes activated successfully");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001945 return 0;
1946}
1947
1948/**
1949 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1950 * @hdd_ipa: Global HDD IPA context
1951 *
1952 * Return: None
1953 */
1954static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1955{
Leo Changfdb45c32016-10-28 11:09:23 -07001956 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001957 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001958
Yun Parkb4f591d2017-03-29 15:51:01 -07001959 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08001960 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
1961 QDF_ASSERT(0);
1962 return;
1963 }
1964
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001965 hdd_ipa->resource_unloading = true;
Yun Parkb4f591d2017-03-29 15:51:01 -07001966 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
1967 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
1968 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
1969 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001970}
1971
1972/**
1973 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1974 * @context: User context registered with TL (the IPA Global context is
1975 * registered
1976 * @rxpkt: Packet containing the notification
1977 * @staid: ID of the station associated with the packet
1978 *
1979 * Return: None
1980 */
1981static void
1982hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1983{
1984 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301985 QDF_STATUS status = QDF_STATUS_SUCCESS;
Yun Parkb4f591d2017-03-29 15:51:01 -07001986 hdd_context_t *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001987
1988 /*
1989 * When SSR is going on or driver is unloading, just return.
1990 */
Yun Parkb4f591d2017-03-29 15:51:01 -07001991 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301992 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001993 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001994
Yun Parkb4f591d2017-03-29 15:51:01 -07001995 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996 return;
1997
Srinivas Girigowda97852372017-03-06 16:52:59 -08001998 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999 __func__, event);
2000
2001 switch (event) {
2002 case IPA_RM_RESOURCE_GRANTED:
2003 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302004 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002005 if ((false == hdd_ipa->resource_unloading) &&
2006 (!hdd_ipa->activated_fw_pipe)) {
2007 hdd_ipa_uc_enable_pipes(hdd_ipa);
2008 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302009 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002010 break;
2011
2012 case IPA_RM_RESOURCE_RELEASED:
2013 /* Differed RM Released */
2014 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015 break;
2016
2017 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302018 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002019 "%s, invalid event code %d", __func__, event);
2020 break;
2021 }
2022}
2023
2024/**
2025 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2026 * @hdd_ipa: Global HDD IPA context
2027 * @event: IPA resource manager event to be deferred
2028 *
2029 * This function is called when a resource manager event is received
2030 * from firmware in interrupt context. This function will defer the
2031 * handling to the OL RX thread
2032 *
2033 * Return: None
2034 */
2035static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2036{
2037 enum ipa_rm_event event;
2038 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2039 struct uc_rm_work_struct, work);
2040 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2041 struct hdd_ipa_priv, uc_rm_work);
2042
2043 cds_ssr_protect(__func__);
2044 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002045 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046 "%s, posted event %d", __func__, event);
2047
2048 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2049 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002050}
2051
2052/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002053 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002054 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002055 *
2056 * Will handle IPA UC image loaded indication comes from IPA kernel
2057 *
2058 * Return: None
2059 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002060static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002061{
Yun Parkb4f591d2017-03-29 15:51:01 -07002062 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2063 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
2064 hdd_context_t *hdd_ctx;
2065 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002066
2067 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
Yun Parkb4f591d2017-03-29 15:51:01 -07002068 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002069 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002070 __func__);
2071 return;
2072 }
2073
Yun Parkb4f591d2017-03-29 15:51:01 -07002074 hdd_ctx = hdd_ipa->hdd_ctx;
2075 hdd_ipa->uc_loaded = true;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002076
Yun Parkb4f591d2017-03-29 15:51:01 -07002077 /* Connect pipe */
2078 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2079 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2080 hdd_ipa_wdi_meter_notifier_cb,
2081 hdd_ctx->config->IpaDescSize,
2082 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2083 &hdd_ipa->tx_pipe_handle,
2084 &hdd_ipa->rx_pipe_handle);
2085 if (status) {
2086 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2087 "Failure to setup IPA pipes (status=%d)",
2088 status);
2089 return;
2090 }
2091
2092 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002093
2094 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002095 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002096 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002097 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002098 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002099 }
2100}
2101
2102/**
Yun Park637d6482016-10-05 10:51:33 -07002103 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2104 * @hdd_ctx: Global HDD context
2105 * @op_msg: operation message received from firmware
2106 *
2107 * Return: QDF_STATUS enumeration
2108 */
2109#ifdef FEATURE_METERING
2110static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2111 struct op_msg_type *op_msg)
2112{
2113 struct op_msg_type *msg = op_msg;
2114 struct ipa_uc_sharing_stats *uc_sharing_stats;
2115 struct ipa_uc_quota_rsp *uc_quota_rsp;
2116 struct ipa_uc_quota_ind *uc_quota_ind;
2117 struct hdd_ipa_priv *hdd_ipa;
2118 hdd_adapter_t *adapter;
2119
2120 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2121
2122 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2123 /* fill-up ipa_uc_sharing_stats structure from FW */
2124 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2125 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2126
2127 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2128 sizeof(struct ipa_uc_sharing_stats));
2129
2130 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2131
2132 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2133 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2134 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2135 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2136 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2137 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2138 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2139 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2140 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2141 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2142 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2143 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2144 /* received set quota response */
2145 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2146 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2147
2148 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2149 sizeof(struct ipa_uc_quota_rsp));
2150
2151 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2152 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2153 "%s: success=%d, quota_bytes=%llu",
2154 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2155 hdd_ipa->ipa_quota_rsp.success,
2156 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2157 hdd_ipa->ipa_quota_rsp.quota_lo);
2158 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2159 /* hit quota limit */
2160 uc_quota_ind = (struct ipa_uc_quota_ind *)
2161 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2162
2163 hdd_ipa->ipa_quota_ind.quota_bytes =
2164 uc_quota_ind->quota_bytes;
2165
2166 /* send quota exceeded indication to IPA */
2167 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2168 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2169 hdd_ipa->ipa_quota_ind.quota_bytes);
2170
2171 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2172 if (adapter)
2173 ipa_broadcast_wdi_quota_reach_ind(
2174 adapter->dev->ifindex,
2175 uc_quota_ind->quota_bytes);
2176 else
2177 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2178 "Failed quota_reach_ind: NULL adapter");
2179 } else {
2180 return QDF_STATUS_E_INVAL;
2181 }
2182
2183 return QDF_STATUS_SUCCESS;
2184}
2185#else
2186static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2187 struct op_msg_type *op_msg)
2188{
2189 return QDF_STATUS_E_INVAL;
2190}
2191#endif
2192
2193/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002194 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2195 * @op_msg: operation message received from firmware
2196 * @usr_ctxt: user context registered with TL (we register the HDD Global
2197 * context)
2198 *
2199 * Return: None
2200 */
2201static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2202{
2203 struct op_msg_type *msg = op_msg;
2204 struct ipa_uc_fw_stats *uc_fw_stat;
2205 struct IpaHwStatsWDIInfoData_t ipa_stat;
2206 struct hdd_ipa_priv *hdd_ipa;
2207 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302208 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002209
2210 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302211 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002212 return;
2213 }
2214
2215 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302216 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002217 "%s, INVALID OPCODE %d", __func__, msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002218 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002219 return;
2220 }
2221
2222 hdd_ctx = (hdd_context_t *) usr_ctxt;
2223
2224 /*
2225 * When SSR is going on or driver is unloading, just return.
2226 */
2227 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302228 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302229 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002230 return;
2231 }
2232
2233 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2234
Govind Singhb6a89772016-08-12 11:23:35 +05302235 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002236 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002237
2238 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2239 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302240 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002241 hdd_ipa->activated_fw_pipe++;
2242 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2243 hdd_ipa->resource_loading = false;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002244 if (hdd_ipa->wdi_enabled == false) {
2245 hdd_ipa->wdi_enabled = true;
2246 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2247 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2248 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002249 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002251 if (hdd_ipa->pending_cons_req)
2252 ipa_rm_notify_completion(
2253 IPA_RM_RESOURCE_GRANTED,
2254 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002255 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002256 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302257 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002258 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002259 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302260 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002261 hdd_ipa->activated_fw_pipe--;
2262 if (!hdd_ipa->activated_fw_pipe) {
2263 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002264 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2265 ipa_rm_release_resource(
2266 IPA_RM_RESOURCE_WLAN_PROD);
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08002267 /*
2268 * Sync return success from IPA
2269 * Enable/resume all the PIPEs
2270 */
Yun Park5b635012015-12-02 15:05:01 -08002271 hdd_ipa->resource_unloading = false;
2272 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2273 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002274 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302275 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002276 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002277 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002278 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302279 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002280 "==== IPA_UC WLAN_HOST RX ====\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002281 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002282 "NUM TX FWD OK : %llu\n"
2283 "NUM TX FWD ERR : %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002284 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002285 hdd_ipa->stats.num_tx_fwd_ok,
2286 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302287 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002288 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2289 "SAP NUM STAs: %d\n"
2290 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002291 "CONCURRENT MODE: %s\n"
2292 "TX PIPE HDL: 0x%x\n"
2293 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002294 "RSC LOADING : %d\n"
2295 "RSC UNLOADING : %d\n"
2296 "PNDNG CNS RQT : %d",
2297 hdd_ipa->sap_num_connected_sta,
2298 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002299 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002300 hdd_ipa->tx_pipe_handle,
2301 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002302 hdd_ipa->resource_loading,
2303 hdd_ipa->resource_unloading,
2304 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002305
2306 /* STATs from FW */
2307 uc_fw_stat = (struct ipa_uc_fw_stats *)
2308 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302309 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002310 "==== IPA_UC WLAN_FW TX ====\n"
2311 "COMP RING BASE: 0x%x\n"
2312 "COMP RING SIZE: %d\n"
2313 "COMP RING DBELL : 0x%x\n"
2314 "COMP RING DBELL IND VAL : %d\n"
2315 "COMP RING DBELL CACHED VAL : %d\n"
2316 "COMP RING DBELL CACHED VAL : %d\n"
2317 "PKTS ENQ : %d\n"
2318 "PKTS COMP : %d\n"
2319 "IS SUSPEND : %d\n"
2320 "RSVD : 0x%x",
2321 uc_fw_stat->tx_comp_ring_base,
2322 uc_fw_stat->tx_comp_ring_size,
2323 uc_fw_stat->tx_comp_ring_dbell_addr,
2324 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2325 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2326 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2327 uc_fw_stat->tx_pkts_enqueued,
2328 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002329 uc_fw_stat->tx_is_suspend,
2330 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302331 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002332 "==== IPA_UC WLAN_FW RX ====\n"
2333 "IND RING BASE: 0x%x\n"
2334 "IND RING SIZE: %d\n"
2335 "IND RING DBELL : 0x%x\n"
2336 "IND RING DBELL IND VAL : %d\n"
2337 "IND RING DBELL CACHED VAL : %d\n"
2338 "RDY IND ADDR : 0x%x\n"
2339 "RDY IND CACHE VAL : %d\n"
2340 "RFIL IND : %d\n"
2341 "NUM PKT INDICAT : %d\n"
2342 "BUF REFIL : %d\n"
2343 "NUM DROP NO SPC : %d\n"
2344 "NUM DROP NO BUF : %d\n"
2345 "IS SUSPND : %d\n"
2346 "RSVD : 0x%x\n",
2347 uc_fw_stat->rx_ind_ring_base,
2348 uc_fw_stat->rx_ind_ring_size,
2349 uc_fw_stat->rx_ind_ring_dbell_addr,
2350 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2351 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2352 uc_fw_stat->rx_ind_ring_rdidx_addr,
2353 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2354 uc_fw_stat->rx_refill_idx,
2355 uc_fw_stat->rx_num_pkts_indicated,
2356 uc_fw_stat->rx_buf_refilled,
2357 uc_fw_stat->rx_num_ind_drop_no_space,
2358 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002359 uc_fw_stat->rx_is_suspend,
2360 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002361 /* STATs from IPA */
2362 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302363 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002364 "==== IPA_UC IPA TX ====\n"
2365 "NUM PROCD : %d\n"
2366 "CE DBELL : 0x%x\n"
2367 "NUM DBELL FIRED : %d\n"
2368 "COMP RNG FULL : %d\n"
2369 "COMP RNG EMPT : %d\n"
2370 "COMP RNG USE HGH : %d\n"
2371 "COMP RNG USE LOW : %d\n"
2372 "BAM FIFO FULL : %d\n"
2373 "BAM FIFO EMPT : %d\n"
2374 "BAM FIFO USE HGH : %d\n"
2375 "BAM FIFO USE LOW : %d\n"
2376 "NUM DBELL : %d\n"
2377 "NUM UNEXP DBELL : %d\n"
2378 "NUM BAM INT HDL : 0x%x\n"
2379 "NUM BAM INT NON-RUN : 0x%x\n"
2380 "NUM QMB INT HDL : 0x%x",
2381 ipa_stat.tx_ch_stats.num_pkts_processed,
2382 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2383 ipa_stat.tx_ch_stats.num_db_fired,
2384 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2385 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2386 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2387 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2388 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2389 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2390 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2391 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2392 ipa_stat.tx_ch_stats.num_db,
2393 ipa_stat.tx_ch_stats.num_unexpected_db,
2394 ipa_stat.tx_ch_stats.num_bam_int_handled,
2395 ipa_stat.tx_ch_stats.
2396 num_bam_int_in_non_runnning_state,
2397 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2398
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302399 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002400 "==== IPA_UC IPA RX ====\n"
2401 "MAX OST PKT : %d\n"
2402 "NUM PKT PRCSD : %d\n"
2403 "RNG RP : 0x%x\n"
2404 "COMP RNG FULL : %d\n"
2405 "COMP RNG EMPT : %d\n"
2406 "COMP RNG USE HGH : %d\n"
2407 "COMP RNG USE LOW : %d\n"
2408 "BAM FIFO FULL : %d\n"
2409 "BAM FIFO EMPT : %d\n"
2410 "BAM FIFO USE HGH : %d\n"
2411 "BAM FIFO USE LOW : %d\n"
2412 "NUM DB : %d\n"
2413 "NUM UNEXP DB : %d\n"
2414 "NUM BAM INT HNDL : 0x%x\n",
2415 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2416 ipa_stat.rx_ch_stats.num_pkts_processed,
2417 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2418 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2419 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2420 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2421 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2422 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2423 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2424 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2425 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2426 ipa_stat.rx_ch_stats.num_db,
2427 ipa_stat.rx_ch_stats.num_unexpected_db,
2428 ipa_stat.rx_ch_stats.num_bam_int_handled);
2429 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2430 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2431 /* STATs from FW */
2432 uc_fw_stat = (struct ipa_uc_fw_stats *)
2433 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302434 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002435 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2436 uc_fw_stat->tx_pkts_completed,
2437 hdd_ipa->ipa_p_tx_packets);
2438 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2439 (uc_fw_stat->rx_num_ind_drop_no_space +
2440 uc_fw_stat->rx_num_ind_drop_no_buf +
2441 uc_fw_stat->rx_num_pkts_indicated),
2442 hdd_ipa->ipa_p_rx_packets);
2443
2444 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2445 hdd_ipa->ipa_p_rx_packets =
2446 (uc_fw_stat->rx_num_ind_drop_no_space +
2447 uc_fw_stat->rx_num_ind_drop_no_buf +
2448 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302449 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002450 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2451 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2452 hdd_ipa_uc_loaded_handler(hdd_ipa);
2453 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002454 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2455 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2456 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002457 }
Yun Park8957d802017-01-25 12:27:29 -08002458
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302459 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002460}
2461
2462
2463/**
2464 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2465 * @adapter: device adapter instance
2466 * @offload_type: MCC or SCC
2467 * @enable: TX offload enable or disable
2468 *
2469 * Return: none
2470 */
2471static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002472 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002473{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002474 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002475 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002476 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002477 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002478
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002479 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002480 return;
2481
Yun Park8292dcb2016-10-07 16:46:06 -07002482 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002483 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002484
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002485 if (!iface_context) {
2486 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2487 "Interface context is NULL");
2488 return;
2489 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002490 if (session_id >= CSR_ROAM_SESSION_MAX) {
2491 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2492 "invalid session id: %d", session_id);
2493 return;
2494 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002495 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002496 /* IPA offload status is already set as desired */
2497 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002498 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002499 "IPA offload status is already set",
2500 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002501 return;
2502 }
2503
Yun Park4540e862016-11-10 16:30:06 -08002504 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2505 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2506 "invalid session id: %d, offload_type=%d, enable=%d",
2507 adapter->sessionId, offload_type, enable);
2508 return;
2509 }
2510
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302511 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002512 sizeof(ipa_offload_enable_disable));
2513 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002514 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002515 ipa_offload_enable_disable.enable = enable;
2516
Srinivas Girigowda97852372017-03-06 16:52:59 -08002517 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002518 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002519 ipa_offload_enable_disable.offload_type,
2520 ipa_offload_enable_disable.vdev_id,
2521 ipa_offload_enable_disable.enable);
2522
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302523 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002524 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2525 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302526 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002527 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
2528 "Failure to enable IPA offload",
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002529 ipa_offload_enable_disable.offload_type,
2530 ipa_offload_enable_disable.vdev_id,
2531 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002532 } else {
2533 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002534 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002535 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002536 }
2537}
2538
2539/**
2540 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2541 * @work: uC OP work
2542 *
2543 * Return: None
2544 */
2545static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2546{
2547 struct op_msg_type *msg;
2548 struct uc_op_work_struct *uc_op_work = container_of(work,
2549 struct uc_op_work_struct, work);
2550 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2551
2552 cds_ssr_protect(__func__);
2553
2554 msg = uc_op_work->msg;
2555 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002556 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002557 "%s, posted msg %d", __func__, msg->op_code);
2558
2559 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2560
2561 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002562}
2563
2564/**
2565 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2566 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2567 * @op_msg: operation message received from firmware
2568 * @hdd_ctx: Global HDD context
2569 *
2570 * Return: None
2571 */
2572static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2573{
2574 struct hdd_ipa_priv *hdd_ipa;
2575 struct op_msg_type *msg;
2576 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302577 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002578
2579 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302580 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002581 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002582
2583 msg = (struct op_msg_type *)op_msg;
2584 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
2585
2586 if (unlikely(!hdd_ipa))
2587 goto end;
2588
2589 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002590 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2591 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002592 goto end;
2593 }
2594
2595 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2596 if (uc_op_work->msg)
2597 /* When the same uC OPCODE is already pended, just return */
2598 goto end;
2599
2600 uc_op_work->msg = msg;
2601 schedule_work(&uc_op_work->work);
2602 return;
2603
2604end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302605 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002606}
2607
2608/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002609 * hdd_ipa_init_uc_op_work - init ipa uc op work
2610 * @work: struct work_struct
2611 * @work_handler: work_handler
2612 *
2613 * Return: none
2614 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002615static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002616 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002617{
2618 INIT_WORK(work, work_handler);
2619}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002620
Yun Park637d6482016-10-05 10:51:33 -07002621#ifdef FEATURE_METERING
2622/**
2623 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2624 * IPA calls to get WLAN stats or set quota limit.
2625 * @priv: pointer to private data registered with IPA (we register a
2626 *» pointer to the global IPA context)
2627 * @evt: the IPA event which triggered the callback
2628 * @data: data associated with the event
2629 *
2630 * Return: None
2631 */
2632static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2633 void *data)
2634{
2635 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2636 hdd_adapter_t *adapter = NULL;
2637 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2638 struct ipa_set_wifi_quota *ipa_set_quota;
2639 int ret = 0;
2640
2641 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2642 return;
2643
2644 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2645
2646 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2647
2648 switch (evt) {
2649 case IPA_GET_WDI_SAP_STATS:
2650 /* fill-up ipa_get_wdi_sap_stats structure after getting
2651 ipa_uc_fw_stats from FW */
2652 wdi_sap_stats = data;
2653
2654 if (!adapter) {
2655 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2656 "IPA uC share stats failed - no adapter");
2657 wdi_sap_stats->stats_valid = 0;
2658 return;
2659 }
2660
2661 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
2662 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
2663 hdd_ipa_uc_sharing_stats_request(adapter,
2664 wdi_sap_stats->reset_stats);
2665 ret = wait_for_completion_timeout(
2666 &hdd_ipa->ipa_uc_sharing_stats_comp,
2667 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2668 if (!ret) {
2669 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2670 "IPA uC share stats request timed out");
2671 wdi_sap_stats->stats_valid = 0;
2672 } else {
2673 wdi_sap_stats->stats_valid = 1;
2674
2675 wdi_sap_stats->ipv4_rx_packets =
2676 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2677 wdi_sap_stats->ipv4_rx_bytes =
2678 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2679 wdi_sap_stats->ipv6_rx_packets =
2680 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2681 wdi_sap_stats->ipv6_rx_bytes =
2682 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2683 wdi_sap_stats->ipv4_tx_packets =
2684 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2685 wdi_sap_stats->ipv4_tx_bytes =
2686 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2687 wdi_sap_stats->ipv6_tx_packets =
2688 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2689 wdi_sap_stats->ipv6_tx_bytes =
2690 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2691 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2692 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2693 "IPA_GET_WDI_SAP_STATS",
2694 wdi_sap_stats->stats_valid,
2695 wdi_sap_stats->ipv4_rx_packets,
2696 wdi_sap_stats->ipv4_rx_bytes,
2697 wdi_sap_stats->ipv6_rx_packets,
2698 wdi_sap_stats->ipv6_rx_bytes,
2699 wdi_sap_stats->ipv4_tx_packets,
2700 wdi_sap_stats->ipv4_tx_bytes,
2701 wdi_sap_stats->ipv6_tx_packets,
2702 wdi_sap_stats->ipv6_tx_bytes);
2703 }
2704 break;
2705 case IPA_SET_WIFI_QUOTA:
2706 /* get ipa_set_wifi_quota structure from IPA and pass to FW
2707 through quota_exceeded field in ipa_uc_fw_stats */
2708 ipa_set_quota = data;
2709
2710 if (!adapter) {
2711 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2712 "IPA uC set quota failed - no adapter");
2713 ipa_set_quota->set_valid = 0;
2714 return;
2715 }
2716
2717 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2718 ipa_set_quota->quota_bytes);
2719
2720 ret = wait_for_completion_timeout(
2721 &hdd_ipa->ipa_uc_set_quota_comp,
2722 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2723 if (!ret) {
2724 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2725 "IPA uC set quota request timed out");
2726 ipa_set_quota->set_valid = 0;
2727 } else {
2728 ipa_set_quota->quota_bytes =
2729 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2730 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2731 ipa_set_quota->set_valid =
2732 hdd_ipa->ipa_quota_rsp.success;
2733 }
2734
2735 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2736 ipa_set_quota->quota_bytes,
2737 ipa_set_quota->set_valid);
2738 break;
2739 }
2740}
2741
2742/**
2743 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2744 * IPA calls to get WLAN stats or set quota limit.
2745 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07002746 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07002747 * @evt: the IPA event which triggered the callback
2748 * @data: data associated with the event
2749 *
2750 * Return: None
2751 */
2752static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2753 void *data)
2754{
2755 cds_ssr_protect(__func__);
2756 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2757 cds_ssr_unprotect(__func__);
2758}
2759
Yun Parkb4f591d2017-03-29 15:51:01 -07002760static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002761{
Yun Park637d6482016-10-05 10:51:33 -07002762 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2763 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2764}
2765#else
Yun Parkb4f591d2017-03-29 15:51:01 -07002766static void hdd_ipa_wdi_meter_notifier_cb(void)
2767{
2768}
2769
2770static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002771{
2772}
2773#endif
2774
Rajeev Kumar217f2172016-01-06 18:11:55 -08002775/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002776 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2777 * @hdd_ctx: Global HDD context
2778 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002779 * This function is called to update IPA pipe configuration with resources
2780 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2781 * (cds_enable)
2782 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302783 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002784 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002785QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786{
Yun Parkb4f591d2017-03-29 15:51:01 -07002787 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002788 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002789 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07002790 uint8_t i;
2791 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002792
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002793 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2794 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002795
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002796 ENTER();
2797 /* Do only IPA Pipe specific configuration here. All one time
2798 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2799 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2800 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002801 if (!pdev || !soc) {
2802 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07002803 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002804 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002805 }
Yun Parkb4f591d2017-03-29 15:51:01 -07002806 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002807 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2808 "IPA UC resource alloc fail");
2809 return QDF_STATUS_E_FAILURE;
2810 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811
Yun Parkb4f591d2017-03-29 15:51:01 -07002812 if (true == hdd_ipa->uc_loaded) {
2813 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2814 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2815 hdd_ipa_wdi_meter_notifier_cb,
2816 hdd_ctx->config->IpaDescSize,
2817 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2818 &hdd_ipa->tx_pipe_handle,
2819 &hdd_ipa->rx_pipe_handle);
2820 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08002821 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002822 "Failure to setup IPA pipes (status=%d)",
2823 status);
2824 return QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002825 }
Yun Park637d6482016-10-05 10:51:33 -07002826
Yun Parkb4f591d2017-03-29 15:51:01 -07002827 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
2828 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002829 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830
Yun Parkb4f591d2017-03-29 15:51:01 -07002831 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08002832 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2833
Yun Parkb4f591d2017-03-29 15:51:01 -07002834 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
2835 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
2836 hdd_ipa_uc_fw_op_event_handler);
2837 hdd_ipa->uc_op_work[i].msg = NULL;
2838 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002839
Yun Parkbaa62862017-01-18 13:43:34 -08002840fail_return:
2841 EXIT();
Yun Parkb4f591d2017-03-29 15:51:01 -07002842 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002843}
2844
Leo Change3e49442015-10-26 20:07:13 -07002845/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302846 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
2847 * @hdd_ctx: Global HDD context
2848 *
2849 * Return: 0 on success, negativer errno on error
2850 */
2851int hdd_ipa_uc_ol_deinit(hdd_context_t *hdd_ctx)
2852{
2853 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2854 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07002855 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302856
2857 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2858 return ret;
2859
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05302860 if (!hdd_ipa->ipa_pipes_down)
2861 hdd_ipa_uc_disable_pipes(hdd_ipa);
2862
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302863 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002864 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
2865 hdd_ipa->tx_pipe_handle,
2866 hdd_ipa->rx_pipe_handle);
2867 if (status) {
2868 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2869 "Failure to cleanup IPA pipes (status=%d)",
2870 status);
2871 return -EFAULT;
2872 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302873 }
2874
2875 return ret;
2876}
2877
2878/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002879 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002880 * @hdd_ctx: hdd main context
2881 *
2882 * Force shutdown IPA pipe
2883 * Independent of FW pipe status, IPA pipe shutdonw progress
2884 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2885 * independent from FW pipe status
2886 *
2887 * Return: NONE
2888 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002889static void __hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002890{
2891 struct hdd_ipa_priv *hdd_ipa;
2892
2893 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2894 return;
2895
2896 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2897 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302898 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002899 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07002900 hdd_ipa_uc_disable_pipes(hdd_ipa);
2901 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002902 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07002903 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07002904 }
Leo Change3e49442015-10-26 20:07:13 -07002905}
2906
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002907/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002908 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2909 * __hdd_ipa_uc_force_pipe_shutdown
2910 * @hdd_ctx: hdd main context
2911 *
2912 * Force shutdown IPA pipe
2913 * Independent of FW pipe status, IPA pipe shutdonw progress
2914 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2915 * independent from FW pipe status
2916 *
2917 * Return: NONE
2918 */
2919void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
2920{
2921 cds_ssr_protect(__func__);
2922 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2923 cds_ssr_unprotect(__func__);
2924}
2925
2926/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302927 * hdd_ipa_msg_free_fn() - Free an IPA message
2928 * @buff: pointer to the IPA message
2929 * @len: length of the IPA message
2930 * @type: type of IPA message
2931 *
2932 * Return: None
2933 */
2934static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2935{
Srinivas Girigowda97852372017-03-06 16:52:59 -08002936 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05302937 ghdd_ipa->stats.num_free_msg++;
2938 qdf_mem_free(buff);
2939}
2940
Govind Singh9c58eba2016-09-02 16:23:06 +05302941/**
jge62037862016-12-09 10:44:33 +08002942 * hdd_ipa_uc_send_evt() - send event to ipa
2943 * @hdd_ctx: pointer to hdd context
2944 * @type: event type
2945 * @mac_addr: pointer to mac address
2946 *
2947 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05302948 *
2949 * Return: 0 - Success
2950 */
jge62037862016-12-09 10:44:33 +08002951static int hdd_ipa_uc_send_evt(hdd_adapter_t *adapter,
2952 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05302953{
jge62037862016-12-09 10:44:33 +08002954 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05302955 struct ipa_msg_meta meta;
2956 struct ipa_wlan_msg *msg;
2957 int ret = 0;
jge62037862016-12-09 10:44:33 +08002958
2959 meta.msg_len = sizeof(struct ipa_wlan_msg);
2960 msg = qdf_mem_malloc(meta.msg_len);
2961 if (msg == NULL) {
2962 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2963 "msg allocation failed");
2964 return -ENOMEM;
2965 }
2966
2967 meta.msg_type = type;
2968 strlcpy(msg->name, adapter->dev->name,
2969 IPA_RESOURCE_NAME_MAX);
2970 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Srinivas Girigowda97852372017-03-06 16:52:59 -08002971 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08002972 msg->name, meta.msg_type);
2973 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
2974 if (ret) {
2975 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2976 "%s: Evt: %d fail:%d",
2977 msg->name, meta.msg_type, ret);
2978 qdf_mem_free(msg);
2979 return ret;
2980 }
2981
2982 hdd_ipa->stats.num_send_msg++;
2983
2984 return ret;
2985}
2986
2987/**
2988 * hdd_ipa_uc_disconnect_client() - send client disconnect event
2989 * @hdd_ctx: pointer to hdd adapter
2990 *
2991 * Send disconnect client event to IPA driver during SSR
2992 *
2993 * Return: 0 - Success
2994 */
2995static int hdd_ipa_uc_disconnect_client(hdd_adapter_t *adapter)
2996{
2997 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2998 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05302999 int i;
3000
3001 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3002 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3003 continue;
3004 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003005 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3006 hdd_ipa->sap_num_connected_sta) {
3007 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3008 adapter->aStaInfo[i].macAddrSTA.bytes);
3009 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303010 }
3011 }
3012
3013 return ret;
3014}
3015
3016/**
jge62037862016-12-09 10:44:33 +08003017 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3018 * @hdd_ctx: pointer to hdd adapter
3019 *
3020 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303021 *
3022 * Return: 0 - Success
3023 */
jge62037862016-12-09 10:44:33 +08003024
3025static int hdd_ipa_uc_disconnect_ap(hdd_adapter_t *adapter)
3026{
3027 int ret = 0;
3028
3029 if (adapter->ipa_context)
3030 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3031 adapter->dev->dev_addr);
3032
3033 return ret;
3034}
3035
jge62037862016-12-09 10:44:33 +08003036/**
3037 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3038 * @hdd_ctx: pointer to hdd adapter
3039 *
3040 * Send disconnect sta event to IPA driver during SSR
3041 *
3042 * Return: 0 - Success
3043 */
3044static int hdd_ipa_uc_disconnect_sta(hdd_adapter_t *adapter)
3045{
3046 hdd_station_ctx_t *pHddStaCtx;
3047 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3048 int ret = 0;
3049
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003050 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003051 hdd_ipa->sta_connected) {
3052 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3053 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003054 pHddStaCtx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003055 }
3056
3057 return ret;
3058}
jge62037862016-12-09 10:44:33 +08003059
3060/**
3061 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3062 * @hdd_ctx: pointer to hdd context
3063 *
3064 * Send disconnect event to IPA driver during SSR
3065 *
3066 * Return: 0 - Success
3067 */
3068static int hdd_ipa_uc_disconnect(hdd_context_t *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303069{
3070 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3071 QDF_STATUS status;
3072 hdd_adapter_t *adapter;
3073 int ret = 0;
3074
Govind Singh9c58eba2016-09-02 16:23:06 +05303075 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3076 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3077 adapter = adapter_node->pAdapter;
jge62037862016-12-09 10:44:33 +08003078 if (adapter->device_mode == QDF_SAP_MODE) {
3079 hdd_ipa_uc_disconnect_client(adapter);
3080 hdd_ipa_uc_disconnect_ap(adapter);
3081 } else if (adapter->device_mode == QDF_STA_MODE) {
3082 hdd_ipa_uc_disconnect_sta(adapter);
3083 }
3084
Govind Singh9c58eba2016-09-02 16:23:06 +05303085 status = hdd_get_next_adapter(
3086 hdd_ctx, adapter_node, &next);
3087 adapter_node = next;
3088 }
3089
3090 return ret;
3091}
3092
3093/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003094 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003095 *
3096 * Deinit basic IPA UC host side to be in sync reloaded FW during
3097 * SSR
3098 *
3099 * Return: 0 - Success
3100 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003101static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003102{
3103 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3104 int idx;
3105 struct hdd_ipa_iface_context *iface_context;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303106 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003107
Arun Khandavallicc544b32017-01-30 19:52:16 +05303108 if (!hdd_ipa)
3109 return 0;
3110
3111 hdd_ctx = hdd_ipa->hdd_ctx;
3112 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003113 return 0;
3114
jge62037862016-12-09 10:44:33 +08003115 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303116 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003117
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118 /* Clean up HDD IPA interfaces */
3119 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3120 (idx < HDD_IPA_MAX_IFACE); idx++) {
3121 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003122 if (iface_context->adapter && iface_context->adapter->magic ==
3123 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003124 hdd_ipa_cleanup_iface(iface_context);
3125 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003126 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 /* After SSR, wlan driver reloads FW again. But we need to protect
3128 * IPA submodule during SSR transient state. So deinit basic IPA
3129 * UC host side to be in sync with reloaded FW during SSR
3130 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003131
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303132 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003133 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3134 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3135 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3136 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303137 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003138
Guolei Bianca144d82016-11-10 11:07:42 +08003139 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3140 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3141
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003142 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3143 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3144 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3145 hdd_ipa->uc_op_work[idx].msg = NULL;
3146 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003147 return 0;
3148}
3149
3150/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003151 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3152 *
3153 * Deinit basic IPA UC host side to be in sync reloaded FW during
3154 * SSR
3155 *
3156 * Return: 0 - Success
3157 */
3158int hdd_ipa_uc_ssr_deinit(void)
3159{
3160 int ret;
3161
3162 cds_ssr_protect(__func__);
3163 ret = __hdd_ipa_uc_ssr_deinit();
3164 cds_ssr_unprotect(__func__);
3165
3166 return ret;
3167}
3168
3169/**
3170 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003171 *
3172 * Init basic IPA UC host side to be in sync with reloaded FW after
3173 * SSR to resume IPA UC operations
3174 *
3175 * Return: 0 - Success
3176 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303177static int __hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003178{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003179
Arun Khandavallicc544b32017-01-30 19:52:16 +05303180 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3181 int i;
3182 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303183
3184 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3185 return 0;
3186
Arun Khandavallicc544b32017-01-30 19:52:16 +05303187 /* Create the interface context */
3188 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3189 iface_context = &hdd_ipa->iface_context[i];
3190 iface_context->hdd_ipa = hdd_ipa;
3191 iface_context->cons_client =
3192 hdd_ipa_adapter_2_client[i].cons_client;
3193 iface_context->prod_client =
3194 hdd_ipa_adapter_2_client[i].prod_client;
3195 iface_context->iface_id = i;
3196 iface_context->adapter = NULL;
3197 }
3198 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3199 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3200 hdd_ipa->vdev_offload_enabled[i] = false;
3201 }
3202
3203 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3204 hdd_ipa->resource_loading = false;
3205 hdd_ipa->resource_unloading = false;
3206 hdd_ipa->sta_connected = 0;
3207 hdd_ipa->ipa_pipes_down = true;
3208 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303209 }
3210
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003211 return 0;
3212}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003213
3214/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003215 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3216 *
3217 * Init basic IPA UC host side to be in sync with reloaded FW after
3218 * SSR to resume IPA UC operations
3219 *
3220 * Return: 0 - Success
3221 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303222int hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003223{
3224 int ret;
3225
3226 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303227 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003228 cds_ssr_unprotect(__func__);
3229
3230 return ret;
3231}
3232
3233/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003234 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3235 * @work: scheduled work
3236 *
3237 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3238 * not want to immediately release the wake lock since the system
3239 * would then potentially try to suspend when there is a healthy data
3240 * rate. Deferred work is scheduled and this function handles the
3241 * work. When this function is called, if the IPA resource is still
3242 * released then we release the wake lock.
3243 *
3244 * Return: None
3245 */
3246static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3247{
3248 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3249 struct hdd_ipa_priv,
3250 wake_lock_work);
3251
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303252 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253
3254 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3255 goto end;
3256
3257 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303258 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003259 WIFI_POWER_EVENT_WAKELOCK_IPA);
3260
3261end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303262 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003263}
3264
3265/**
3266 * hdd_ipa_rm_request() - Request resource from IPA
3267 * @hdd_ipa: Global HDD IPA context
3268 *
3269 * Return: 0 on success, negative errno on error
3270 */
3271static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3272{
3273 int ret = 0;
3274
3275 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3276 return 0;
3277
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303278 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003279
3280 switch (hdd_ipa->rm_state) {
3281 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303282 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003283 return 0;
3284 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303285 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003286 return -EINPROGRESS;
3287 case HDD_IPA_RM_RELEASED:
3288 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3289 break;
3290 }
3291
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303292 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003293
3294 ret = ipa_rm_inactivity_timer_request_resource(
3295 IPA_RM_RESOURCE_WLAN_PROD);
3296
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303297 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003298 if (ret == 0) {
3299 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3300 hdd_ipa->stats.num_rm_grant_imm++;
3301 }
3302
3303 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3304 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303305 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003306 WIFI_POWER_EVENT_WAKELOCK_IPA);
3307 hdd_ipa->wake_lock_released = false;
3308 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303309 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003310
3311 return ret;
3312}
3313
3314/**
3315 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3316 * @hdd_ipa: Global HDD IPA context
3317 *
3318 * Return: 0 if resources released, negative errno otherwise
3319 */
3320static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3321{
3322 int ret = 0;
3323
3324 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3325 return 0;
3326
3327 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3328 return -EAGAIN;
3329
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303330 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003331
Nirav Shahcbc6d722016-03-01 16:24:53 +05303332 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303333 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003334 return -EAGAIN;
3335 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303336 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003337
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303338 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003339 switch (hdd_ipa->rm_state) {
3340 case HDD_IPA_RM_GRANTED:
3341 break;
3342 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303343 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003344 return -EINPROGRESS;
3345 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303346 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003347 return 0;
3348 }
3349
3350 /* IPA driver returns immediately so set the state here to avoid any
3351 * race condition.
3352 */
3353 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3354 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303355 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003357 ret = ipa_rm_inactivity_timer_release_resource(
3358 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303360 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003361 if (unlikely(ret != 0)) {
3362 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3363 WARN_ON(1);
3364 }
3365
3366 /*
3367 * If wake_lock is released immediately, kernel would try to suspend
3368 * immediately as well, Just avoid ping-pong between suspend-resume
3369 * while there is healthy amount of data transfer going on by
3370 * releasing the wake_lock after some delay.
3371 */
3372 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3373 msecs_to_jiffies
3374 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3375
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303376 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003377
3378 return ret;
3379}
3380
3381/**
3382 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3383 * @user_data: user data registered with IPA
3384 * @event: the IPA resource manager event that occurred
3385 * @data: the data associated with the event
3386 *
3387 * Return: None
3388 */
3389static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3390 unsigned long data)
3391{
3392 struct hdd_ipa_priv *hdd_ipa = user_data;
3393
3394 if (unlikely(!hdd_ipa))
3395 return;
3396
3397 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3398 return;
3399
Srinivas Girigowda97852372017-03-06 16:52:59 -08003400 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003401
3402 switch (event) {
3403 case IPA_RM_RESOURCE_GRANTED:
3404 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3405 /* RM Notification comes with ISR context
3406 * it should be serialized into work queue to avoid
3407 * ISR sleep problem
3408 */
3409 hdd_ipa->uc_rm_work.event = event;
3410 schedule_work(&hdd_ipa->uc_rm_work.work);
3411 break;
3412 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303413 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003414 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303415 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003416 hdd_ipa->stats.num_rm_grant++;
3417 break;
3418
3419 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003420 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003421 hdd_ipa->resource_unloading = false;
3422 break;
3423
3424 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303425 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003426 break;
3427 }
3428}
3429
3430/**
3431 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3432 *
3433 * Callback function registered with IPA that is called when IPA wants
3434 * to release the WLAN consumer resource
3435 *
3436 * Return: 0 if the request is granted, negative errno otherwise
3437 */
3438static int hdd_ipa_rm_cons_release(void)
3439{
3440 return 0;
3441}
3442
3443/**
3444 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3445 *
3446 * Callback function registered with IPA that is called when IPA wants
3447 * to access the WLAN consumer resource
3448 *
3449 * Return: 0 if the request is granted, negative errno otherwise
3450 */
3451static int hdd_ipa_rm_cons_request(void)
3452{
Yun Park4d8b60a2015-10-22 13:59:32 -07003453 int ret = 0;
3454
3455 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303456 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003457 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003458 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003459 ret = -EINPROGRESS;
3460 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303461 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003462 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003463 ghdd_ipa->pending_cons_req = true;
3464 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003465 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003466
3467 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468}
3469
3470/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003471 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003472 * @hdd_ctx: Global HDD context
3473 * @tx_packets: Number of packets transmitted in the last sample period
3474 * @rx_packets: Number of packets received in the last sample period
3475 *
3476 * Return: 0 on success, negative errno on error
3477 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003478static int __hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 uint64_t rx_packets)
3480{
3481 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003482 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003484 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003485 int ret;
3486
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003487 if (wlan_hdd_validate_context(hdd_ctx))
3488 return 0;
3489
3490 hdd_ipa = hdd_ctx->hdd_ipa;
3491
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003492 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3493 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3494 return 0;
3495
3496 memset(&profile, 0, sizeof(profile));
3497
3498 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3499 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3500 else if (tx_packets >
3501 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3502 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3503 else
3504 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3505
3506 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3507 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3508 else if (rx_packets >
3509 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3510 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3511 else
3512 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3513
Yun Parkec845302016-12-15 09:22:57 -08003514 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003515 "CONS perf curr: %d, next: %d",
3516 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003517 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003518 "PROD perf curr: %d, next: %d",
3519 hdd_ipa->curr_prod_bw, next_prod_bw);
3520
3521 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003522 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003523 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003524 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3525 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003526 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003527 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003528
3529 return ret;
3530 }
3531 hdd_ipa->curr_cons_bw = next_cons_bw;
3532 hdd_ipa->stats.num_cons_perf_req++;
3533 }
3534
3535 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003536 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003537 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003538 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3539 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003540 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003541 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003542 return ret;
3543 }
3544 hdd_ipa->curr_prod_bw = next_prod_bw;
3545 hdd_ipa->stats.num_prod_perf_req++;
3546 }
3547
3548 return 0;
3549}
3550
3551/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003552 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3553 * @hdd_ctx: Global HDD context
3554 * @tx_packets: Number of packets transmitted in the last sample period
3555 * @rx_packets: Number of packets received in the last sample period
3556 *
3557 * Return: 0 on success, negative errno on error
3558 */
3559int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
3560 uint64_t rx_packets)
3561{
3562 int ret;
3563
3564 cds_ssr_protect(__func__);
3565 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3566 cds_ssr_unprotect(__func__);
3567
3568 return ret;
3569}
3570
3571/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003572 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3573 * @work: struct work_struct
3574 * @work_handler: work_handler
3575 *
3576 * Return: none
3577 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003578static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3579 work_func_t work_handler)
3580{
3581 INIT_WORK(work, work_handler);
3582}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003583
3584/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003585 * hdd_ipa_setup_rm() - Setup IPA resource management
3586 * @hdd_ipa: Global HDD IPA context
3587 *
3588 * Return: 0 on success, negative errno on error
3589 */
3590static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3591{
3592 struct ipa_rm_create_params create_params = { 0 };
3593 int ret;
3594
3595 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3596 return 0;
3597
Rajeev Kumar217f2172016-01-06 18:11:55 -08003598 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3599 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003600 memset(&create_params, 0, sizeof(create_params));
3601 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3602 create_params.reg_params.user_data = hdd_ipa;
3603 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3604 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3605
3606 ret = ipa_rm_create_resource(&create_params);
3607 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303608 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609 "Create RM resource failed: %d", ret);
3610 goto setup_rm_fail;
3611 }
3612
3613 memset(&create_params, 0, sizeof(create_params));
3614 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3615 create_params.request_resource = hdd_ipa_rm_cons_request;
3616 create_params.release_resource = hdd_ipa_rm_cons_release;
3617 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3618
3619 ret = ipa_rm_create_resource(&create_params);
3620 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303621 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003622 "Create RM CONS resource failed: %d", ret);
3623 goto delete_prod;
3624 }
3625
3626 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3627 IPA_RM_RESOURCE_APPS_CONS);
3628
3629 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3630 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3631 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303632 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003633 ret);
3634 goto timer_init_failed;
3635 }
3636
3637 /* Set the lowest bandwidth to start with */
3638 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3639
3640 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303641 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003642 "Set perf level failed: %d", ret);
3643 goto set_perf_failed;
3644 }
3645
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303646 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003647 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3648 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303649 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003650 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3651 hdd_ipa->wake_lock_released = true;
3652 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3653
3654 return ret;
3655
3656set_perf_failed:
3657 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3658
3659timer_init_failed:
3660 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3661
3662delete_prod:
3663 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3664
3665setup_rm_fail:
3666 return ret;
3667}
3668
3669/**
3670 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3671 * @hdd_ipa: Global HDD IPA context
3672 *
3673 * Destroys all resources associated with the IPA resource manager
3674 *
3675 * Return: None
3676 */
3677static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3678{
3679 int ret;
3680
3681 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3682 return;
3683
3684 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303685 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003687 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303688 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689
3690 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3691
3692 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3693 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303694 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003695 "RM PROD resource delete failed %d", ret);
3696
3697 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3698 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303699 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003700 "RM CONS resource delete failed %d", ret);
3701}
3702
tfyu0380a972017-07-13 18:19:37 +08003703#ifdef QCA_CONFIG_SMP
3704static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3705{
3706 return netif_rx_ni(skb);
3707}
3708#else
3709static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3710{
3711 struct iphdr *ip_h;
3712 static atomic_t softirq_mitigation_cntr =
3713 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
3714 int result;
3715
3716 ip_h = (struct iphdr *)(skb->data);
3717 if ((skb->protocol == htons(ETH_P_IP)) &&
3718 (ip_h->protocol == IPPROTO_ICMP)) {
3719 result = netif_rx_ni(skb);
3720 } else {
3721 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
3722 * to avoid excessive softirq's.
3723 */
3724 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
3725 result = netif_rx_ni(skb);
3726 atomic_set(&softirq_mitigation_cntr,
3727 IPA_WLAN_RX_SOFTIRQ_THRESH);
3728 } else {
3729 result = netif_rx(skb);
3730 }
3731 }
3732
3733 return result;
3734}
3735#endif
3736
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003737/**
3738 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3739 * @skb: network buffer
3740 * @adapter: network adapter
3741 *
3742 * Called when a network buffer is received which should not be routed
3743 * to the IPA module.
3744 *
3745 * Return: None
3746 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303747static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003748 hdd_adapter_t *adapter)
3749{
tfyu0380a972017-07-13 18:19:37 +08003750 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003751 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3752 unsigned int cpu_index;
3753
3754 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003755 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003756 adapter);
3757 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003758 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 return;
3760 }
3761
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003762 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003763 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003764 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003765 return;
3766 }
3767
3768 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3769 skb->dev = adapter->dev;
3770 skb->protocol = eth_type_trans(skb, skb->dev);
3771 skb->ip_summed = CHECKSUM_NONE;
3772
3773 cpu_index = wlan_hdd_get_cpu();
3774
3775 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08003776 result = hdd_ipa_aggregated_rx_ind(skb);
3777 if (result == NET_RX_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
3779 else
3780 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
3781
3782 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
3783 adapter->dev->last_rx = jiffies;
3784}
3785
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003786/**
Leo Chang69c39692016-10-12 20:11:12 -07003787 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3788 * @hdd_ipa: pointer to hdd ipa context
3789 * @adapter: network adapter
3790 * @skb: data pointer
3791 *
3792 * if exception packet has set forward bit, copied new packet should be
3793 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3794 * put into pm queue and tx procedure will be differed
3795 *
3796 * Return: None
3797 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003798static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
3799 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003800{
Leo Chang69c39692016-10-12 20:11:12 -07003801 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3802
Leo Chang69c39692016-10-12 20:11:12 -07003803 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
3804 /* WLAN subsystem is in suspend, put int queue */
3805 if (hdd_ipa->suspended) {
3806 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3807 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3808 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003809 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3810 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003811 pm_tx_cb->exception = true;
3812 pm_tx_cb->adapter = adapter;
3813 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003814 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003815 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3816 hdd_ipa->stats.num_tx_queued++;
3817 } else {
3818 /* Resume, put packet into WLAN TX */
3819 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003820 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003821 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3822 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003823 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003824 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003825 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003826 hdd_ipa->ipa_tx_forward++;
3827 }
3828 }
3829}
3830
3831/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003832 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3833 * @hdd_ipa: pointer to HDD IPA struct
3834 * @adapter: hdd adapter pointer
3835 * @desc: Firmware descriptor
3836 * @skb: Data buffer
3837 *
3838 * Return:
3839 * HDD_IPA_FORWARD_PKT_NONE
3840 * HDD_IPA_FORWARD_PKT_DISCARD
3841 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3842 *
3843 */
3844
3845static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3846 struct hdd_ipa_priv *hdd_ipa,
3847 hdd_adapter_t *adapter,
3848 uint8_t desc,
3849 qdf_nbuf_t skb)
3850{
3851 int ret = HDD_IPA_FORWARD_PKT_NONE;
3852
3853 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303854 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003855 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
3856 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303857 /* Drop the packet*/
3858 hdd_ipa->stats.num_tx_fwd_err++;
3859 kfree_skb(skb);
3860 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3861 return ret;
3862 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003863 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3864 "Forward packet to Tx (fw_desc=%d)", desc);
3865 hdd_ipa->ipa_tx_forward++;
3866
3867 if ((desc & FW_RX_DESC_DISCARD_M)) {
3868 hdd_ipa_forward(hdd_ipa, adapter, skb);
3869 hdd_ipa->ipa_rx_internel_drop_count++;
3870 hdd_ipa->ipa_rx_discard++;
3871 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3872 } else {
3873 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003874
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003875 if (cloned_skb)
3876 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3877 else
3878 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3879 "%s: tx skb alloc failed",
3880 __func__);
3881 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3882 }
3883 }
3884
3885 return ret;
3886}
3887
3888/**
Yun Park637d6482016-10-05 10:51:33 -07003889 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003890 * @priv: pointer to private data registered with IPA (we register a
3891 * pointer to the global IPA context)
3892 * @evt: the IPA event which triggered the callback
3893 * @data: data associated with the event
3894 *
3895 * Return: None
3896 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003897static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003898 unsigned long data)
3899{
3900 struct hdd_ipa_priv *hdd_ipa = NULL;
3901 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303902 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003903 uint8_t iface_id;
3904 uint8_t session_id;
3905 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003906 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003907 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908
3909 hdd_ipa = (struct hdd_ipa_priv *)priv;
3910
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003911 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3912 return;
3913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003914 switch (evt) {
3915 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303916 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003917
3918 /*
3919 * When SSR is going on or driver is unloading,
3920 * just drop the packets.
3921 */
3922 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
3923 if (0 != status) {
3924 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3925 "Invalid context: drop packet");
3926 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3927 kfree_skb(skb);
3928 return;
3929 }
3930
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3932 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003933 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08003934 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003935 "IPA_RECEIVE: session_id=%u, iface_id=%u",
3936 session_id, iface_id);
3937 } else {
3938 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
3939 }
3940
3941 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303942 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 "IPA_RECEIVE: Invalid iface_id: %u",
3944 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003945 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003946 "w2i -- skb",
3947 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003949 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003950 return;
3951 }
3952
3953 iface_context = &hdd_ipa->iface_context[iface_id];
3954 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08003955 if (!adapter) {
3956 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3957 "IPA_RECEIVE: Adapter is NULL");
3958 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3959 kfree_skb(skb);
3960 return;
3961 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003962
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303963 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003964 "w2i -- skb",
3965 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3967 hdd_ipa->stats.num_rx_excep++;
3968 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
3969 } else {
3970 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
3971 }
3972
3973 iface_context->stats.num_rx_ipa_excep++;
3974
3975 /* Disable to forward Intra-BSS Rx packets when
3976 * ap_isolate=1 in hostapd.conf
3977 */
Yun Park046101c2016-09-02 15:32:14 -07003978 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003979 /*
3980 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
3981 * all Rx packets to IPA uC, which need to be forwarded
3982 * to other interface.
3983 * And, IPA driver will send back to WLAN host driver
3984 * through exception pipe with fw_desc field set by FW.
3985 * Here we are checking fw_desc field for FORWARD bit
3986 * set, and forward to Tx. Then copy to kernel stack
3987 * only when DISCARD bit is not set.
3988 */
3989 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003990 if (HDD_IPA_FORWARD_PKT_DISCARD ==
3991 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
3992 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08003993 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003994 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003995 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 "Intra-BSS FWD is disabled-skip forward to Tx");
3997 }
3998
3999 hdd_ipa_send_skb_to_network(skb, adapter);
4000 break;
4001
4002 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304003 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004004 "w2i cb wrong event: 0x%x", evt);
4005 return;
4006 }
4007}
4008
4009/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004010 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4011 * @priv: pointer to private data registered with IPA (we register a
4012 * pointer to the global IPA context)
4013 * @evt: the IPA event which triggered the callback
4014 * @data: data associated with the event
4015 *
4016 * Return: None
4017 */
4018static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4019 unsigned long data)
4020{
4021 cds_ssr_protect(__func__);
4022 __hdd_ipa_w2i_cb(priv, evt, data);
4023 cds_ssr_unprotect(__func__);
4024}
4025
4026/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4028 * @skb: packet buffer which was transmitted
4029 *
4030 * Return: None
4031 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304032void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004033{
4034 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004035 struct ipa_rx_data *ipa_tx_desc;
4036 struct hdd_ipa_tx_desc *tx_desc;
4037 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038
Yun Park52b2b992016-09-22 15:49:51 -07004039 if (!qdf_nbuf_ipa_owned_get(skb)) {
4040 dev_kfree_skb_any(skb);
4041 return;
4042 }
4043
4044 /* Get Tx desc pointer from SKB CB */
4045 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4046 tx_desc = hdd_ipa->tx_desc_list + id;
4047 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4048
4049 /* Return Tx Desc to IPA */
4050 ipa_free_skb(ipa_tx_desc);
4051
4052 /* Return to free tx desc list */
4053 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4054 tx_desc->ipa_tx_desc_ptr = NULL;
4055 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4056 hdd_ipa->stats.num_tx_desc_q_cnt--;
4057 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058
4059 hdd_ipa->stats.num_tx_comp_cnt++;
4060
4061 atomic_dec(&hdd_ipa->tx_ref_cnt);
4062
4063 hdd_ipa_rm_try_release(hdd_ipa);
4064}
4065
4066/**
4067 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4068 * @iface_context: interface-specific IPA context
4069 * @ipa_tx_desc: packet data descriptor
4070 *
4071 * Return: None
4072 */
4073static void hdd_ipa_send_pkt_to_tl(
4074 struct hdd_ipa_iface_context *iface_context,
4075 struct ipa_rx_data *ipa_tx_desc)
4076{
4077 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304079 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004080 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304082 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 adapter = iface_context->adapter;
4084 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304085 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004086 ipa_free_skb(ipa_tx_desc);
4087 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304088 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004089 hdd_ipa_rm_try_release(hdd_ipa);
4090 return;
4091 }
4092
4093 /*
4094 * During CAC period, data packets shouldn't be sent over the air so
4095 * drop all the packets here
4096 */
4097 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4098 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304099 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004100 iface_context->stats.num_tx_cac_drop++;
4101 hdd_ipa_rm_try_release(hdd_ipa);
4102 return;
4103 }
4104
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004105 ++adapter->stats.tx_packets;
4106
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304107 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004108
4109 skb = ipa_tx_desc->skb;
4110
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304111 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004112
4113 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304114 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004115 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304116 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004117 ipa_tx_desc->dma_addr
4118 + HDD_IPA_WLAN_FRAG_HEADER
4119 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004120 ipa_tx_desc->skb->len -=
4121 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4122 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304123 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004124
Yun Park52b2b992016-09-22 15:49:51 -07004125 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4126 /* get free Tx desc and assign ipa_tx_desc pointer */
4127 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4128 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4129 struct hdd_ipa_tx_desc, link);
4130 list_del(&tx_desc->link);
4131 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4132 hdd_ipa->stats.num_tx_desc_q_cnt++;
4133 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4134 /* Store Tx Desc index into SKB CB */
4135 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4136 } else {
4137 hdd_ipa->stats.num_tx_desc_error++;
4138 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4139 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4140 ipa_free_skb(ipa_tx_desc);
4141 hdd_ipa_rm_try_release(hdd_ipa);
4142 return;
4143 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144
4145 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4146
Leo Changfdb45c32016-10-28 11:09:23 -07004147 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004148 (struct cdp_vdev *)iface_context->tl_context,
4149 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304151 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
jiad05c1e812017-08-01 16:48:52 +08004152 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004153 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004154 return;
4155 }
4156
4157 atomic_inc(&hdd_ipa->tx_ref_cnt);
4158
4159 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004160}
4161
4162/**
Leo Chang11545d62016-10-17 14:53:50 -07004163 * hdd_ipa_is_present() - get IPA hw status
4164 * @hdd_ctx: pointer to hdd context
4165 *
4166 * ipa_uc_reg_rdyCB is not directly designed to check
4167 * ipa hw status. This is an undocumented function which
4168 * has confirmed with IPA team.
4169 *
4170 * Return: true - ipa hw present
4171 * false - ipa hw not present
4172 */
4173bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
4174{
4175 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004176 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004177 return true;
4178 else
4179 return false;
4180}
4181
4182/**
Leo Chang69c39692016-10-12 20:11:12 -07004183 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004184 * @work: pointer to the scheduled work
4185 *
4186 * Called during PM resume to send packets to TL which were queued
4187 * while host was in the process of suspending.
4188 *
4189 * Return: None
4190 */
Leo Chang69c39692016-10-12 20:11:12 -07004191static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004192{
4193 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4194 struct hdd_ipa_priv,
4195 pm_work);
4196 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304197 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004198 uint32_t dequeued = 0;
4199
Leo Chang69c39692016-10-12 20:11:12 -07004200 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4201 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304202 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304203 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4204 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304205 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004206
4207 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004208 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004209 if (pm_tx_cb->exception) {
4210 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4211 "FLUSH EXCEPTION");
4212 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
4213 } else {
4214 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004216 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304217 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304219 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004220 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4221 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004222
4223 hdd_ipa->stats.num_tx_dequeued += dequeued;
4224 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4225 hdd_ipa->stats.num_max_pm_queue = dequeued;
4226}
4227
4228/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004229 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004230 * @priv: pointer to private data registered with IPA (we register a
4231 * pointer to the interface-specific IPA context)
4232 * @evt: the IPA event which triggered the callback
4233 * @data: data associated with the event
4234 *
4235 * Return: None
4236 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004237static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004238 unsigned long data)
4239{
4240 struct hdd_ipa_priv *hdd_ipa = NULL;
4241 struct ipa_rx_data *ipa_tx_desc;
4242 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304243 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304245 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004246
Mukul Sharma81661ae2015-10-30 20:26:02 +05304247 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004248 ipa_tx_desc = (struct ipa_rx_data *)data;
4249 hdd_ipa = iface_context->hdd_ipa;
4250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004251 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004252 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4253 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004254 iface_context->stats.num_tx_drop++;
4255 return;
4256 }
4257
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004258 /*
4259 * When SSR is going on or driver is unloading, just drop the packets.
4260 * During SSR, there is no use in queueing the packets as STA has to
4261 * connect back any way
4262 */
4263 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304264 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004265 ipa_free_skb(ipa_tx_desc);
4266 iface_context->stats.num_tx_drop++;
4267 return;
4268 }
4269
4270 skb = ipa_tx_desc->skb;
4271
Yun Parkb187d542016-11-14 18:10:04 -08004272 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4273 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274
4275 /*
4276 * If PROD resource is not requested here then there may be cases where
4277 * IPA hardware may be clocked down because of not having proper
4278 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4279 * workaround to request PROD resource while data is going over CONS
4280 * pipe to prevent the IPA hardware clockdown.
4281 */
4282 hdd_ipa_rm_request(hdd_ipa);
4283
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304284 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004285 /*
4286 * If host is still suspended then queue the packets and these will be
4287 * drained later when resume completes. When packet is arrived here and
4288 * host is suspended, this means that there is already resume is in
4289 * progress.
4290 */
4291 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304292 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4294 pm_tx_cb->iface_context = iface_context;
4295 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304296 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 hdd_ipa->stats.num_tx_queued++;
4298
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304299 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004300 return;
4301 }
4302
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304303 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304
4305 /*
4306 * If we are here means, host is not suspended, wait for the work queue
4307 * to finish.
4308 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004310
4311 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4312}
4313
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004314/*
4315 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4316 * @priv: pointer to private data registered with IPA (we register a
4317 * pointer to the interface-specific IPA context)
4318 * @evt: the IPA event which triggered the callback
4319 * @data: data associated with the event
4320 *
4321 * Return: None
4322 */
4323static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4324 unsigned long data)
4325{
4326 cds_ssr_protect(__func__);
4327 __hdd_ipa_i2w_cb(priv, evt, data);
4328 cds_ssr_unprotect(__func__);
4329}
4330
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004331/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004332 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333 * @hdd_ctx: Global HDD context
4334 *
4335 * Return: 0 on success, negativer errno on error
4336 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004337static int __hdd_ipa_suspend(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004338{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004339 struct hdd_ipa_priv *hdd_ipa;
4340
4341 if (wlan_hdd_validate_context(hdd_ctx))
4342 return 0;
4343
4344 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004345
4346 if (!hdd_ipa_is_enabled(hdd_ctx))
4347 return 0;
4348
4349 /*
4350 * Check if IPA is ready for suspend, If we are here means, there is
4351 * high chance that suspend would go through but just to avoid any race
4352 * condition after suspend started, these checks are conducted before
4353 * allowing to suspend.
4354 */
4355 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4356 return -EAGAIN;
4357
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304358 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004359
4360 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304361 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362 return -EAGAIN;
4363 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304364 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004365
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304366 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004367 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304368 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004369
4370 return 0;
4371}
4372
4373/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004374 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4375 * @hdd_ctx: Global HDD context
4376 *
4377 * Return: 0 on success, negativer errno on error
4378 */
4379int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
4380{
4381 int ret;
4382
4383 cds_ssr_protect(__func__);
4384 ret = __hdd_ipa_suspend(hdd_ctx);
4385 cds_ssr_unprotect(__func__);
4386
4387 return ret;
4388}
4389
4390/**
4391 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392 * hdd_ctx: Global HDD context
4393 *
4394 * Return: 0 on success, negative errno on error
4395 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004396static int __hdd_ipa_resume(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004398 struct hdd_ipa_priv *hdd_ipa;
4399
4400 if (wlan_hdd_validate_context(hdd_ctx))
4401 return 0;
4402
4403 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004404
4405 if (!hdd_ipa_is_enabled(hdd_ctx))
4406 return 0;
4407
4408 schedule_work(&hdd_ipa->pm_work);
4409
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304410 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004411 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304412 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413
4414 return 0;
4415}
4416
4417/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004418 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4419 * hdd_ctx: Global HDD context
4420 *
4421 * Return: 0 on success, negative errno on error
4422 */
4423int hdd_ipa_resume(hdd_context_t *hdd_ctx)
4424{
4425 int ret;
4426
4427 cds_ssr_protect(__func__);
4428 ret = __hdd_ipa_resume(hdd_ctx);
4429 cds_ssr_unprotect(__func__);
4430
4431 return ret;
4432}
4433
4434/**
Yun Park52b2b992016-09-22 15:49:51 -07004435 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4436 * @hdd_ipa: Global HDD IPA context
4437 *
4438 * Return: 0 on success, negative errno on error
4439 */
4440static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4441{
4442 int i;
4443 uint32_t max_desc_cnt;
4444 struct hdd_ipa_tx_desc *tmp_desc;
4445
4446 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4447
4448 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4449
4450 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc)*max_desc_cnt);
4451
4452 if (!tmp_desc) {
4453 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4454 "Free Tx descriptor allocation failed");
4455 return -ENOMEM;
4456 }
4457
4458 hdd_ipa->tx_desc_list = tmp_desc;
4459
4460 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4461 for (i = 0; i < max_desc_cnt; i++) {
4462 tmp_desc->id = i;
4463 tmp_desc->ipa_tx_desc_ptr = NULL;
4464 list_add_tail(&tmp_desc->link,
4465 &hdd_ipa->free_tx_desc_head);
4466 tmp_desc++;
4467 }
4468
4469 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4470 hdd_ipa->stats.num_tx_desc_error = 0;
4471
4472 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4473
4474 return 0;
4475}
4476
4477/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004478 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4479 * @hdd_ipa: Global HDD IPA context
4480 *
4481 * Return: 0 on success, negative errno on error
4482 */
4483static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4484{
4485 int i, ret = 0;
4486 struct ipa_sys_connect_params *ipa;
4487 uint32_t desc_fifo_sz;
4488
4489 /* The maximum number of descriptors that can be provided to a BAM at
4490 * once is one less than the total number of descriptors that the buffer
4491 * can contain.
4492 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4493 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4494 * be provided at once.
4495 * Because of above requirement, one extra descriptor will be added to
4496 * make sure hardware always has one descriptor.
4497 */
4498 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4499 + sizeof(struct sps_iovec);
4500
4501 /*setup TX pipes */
4502 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4503 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4504
4505 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4506 ipa->desc_fifo_sz = desc_fifo_sz;
4507 ipa->priv = &hdd_ipa->iface_context[i];
4508 ipa->notify = hdd_ipa_i2w_cb;
4509
4510 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4511 ipa->ipa_ep_cfg.hdr.hdr_len =
4512 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4513 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4514 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4515 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4516 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4517 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4518 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4519 } else {
4520 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4521 }
4522 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4523
4524 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4525 ipa->keep_ipa_awake = 1;
4526
4527 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4528 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004529 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4530 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004531 goto setup_sys_pipe_fail;
4532 }
4533 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4534 }
4535
4536 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4537 /*
4538 * Hard code it here, this can be extended if in case
4539 * PROD pipe is also per interface.
4540 * Right now there is no advantage of doing this.
4541 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004542 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4543
Yun Parkb4f591d2017-03-29 15:51:01 -07004544 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545
4546 ipa->desc_fifo_sz = desc_fifo_sz;
4547 ipa->priv = hdd_ipa;
4548 ipa->notify = hdd_ipa_w2i_cb;
4549
4550 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4551 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4552 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4553 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4554
4555 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4556 ipa->keep_ipa_awake = 1;
4557
4558 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4559 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304560 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561 "Failed for RX pipe: %d", ret);
4562 goto setup_sys_pipe_fail;
4563 }
4564 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4565 }
4566
Yun Park52b2b992016-09-22 15:49:51 -07004567 /* Allocate free Tx desc list */
4568 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4569 if (ret)
4570 goto setup_sys_pipe_fail;
4571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004572 return ret;
4573
4574setup_sys_pipe_fail:
4575
4576 while (--i >= 0) {
4577 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304578 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579 sizeof(struct hdd_ipa_sys_pipe));
4580 }
4581
4582 return ret;
4583}
4584
4585/**
4586 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4587 * @hdd_ipa: Global HDD IPA context
4588 *
4589 * Return: None
4590 */
4591static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4592{
4593 int ret = 0, i;
Yun Park52b2b992016-09-22 15:49:51 -07004594 uint32_t max_desc_cnt;
4595 struct hdd_ipa_tx_desc *tmp_desc;
4596 struct ipa_rx_data *ipa_tx_desc;
4597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004598 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4599 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004600 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4601 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004602 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304603 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004604 ret);
4605
4606 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4607 }
4608 }
Yun Park52b2b992016-09-22 15:49:51 -07004609
4610 if (hdd_ipa->tx_desc_list) {
4611 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4612
4613 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4614 for (i = 0; i < max_desc_cnt; i++) {
4615 tmp_desc = hdd_ipa->tx_desc_list + i;
4616 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4617 if (ipa_tx_desc)
4618 ipa_free_skb(ipa_tx_desc);
4619 }
4620 tmp_desc = hdd_ipa->tx_desc_list;
4621 hdd_ipa->tx_desc_list = NULL;
4622 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4623 hdd_ipa->stats.num_tx_desc_error = 0;
4624 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4625 qdf_mem_free(tmp_desc);
4626 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004627}
4628
4629/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004630 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4631 * @iface_context: interface-specific IPA context
4632 *
4633 * Return: None
4634 */
4635static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4636{
4637 if (iface_context == NULL)
4638 return;
4639
Yun Parkb4f591d2017-03-29 15:51:01 -07004640 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4641 iface_context->adapter->dev->name,
4642 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004643
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304644 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004645 iface_context->adapter->ipa_context = NULL;
4646 iface_context->adapter = NULL;
4647 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304648 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004649 iface_context->ifa_address = 0;
4650 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304651 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304653 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004654 }
4655 iface_context->hdd_ipa->num_iface--;
4656}
4657
4658/**
4659 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4660 * @hdd_ipa: HDD IPA global context
4661 * @adapter: Interface upon which IPA is being setup
4662 * @sta_id: Station ID of the API instance
4663 *
4664 * Return: 0 on success, negative errno value on error
4665 */
4666static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
4667 hdd_adapter_t *adapter, uint8_t sta_id)
4668{
4669 struct hdd_ipa_iface_context *iface_context = NULL;
4670 void *tl_context = NULL;
4671 int i, ret = 0;
4672
4673 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4674 * channel change indication. Since these indications are sent by lower
4675 * layer as SAP updates and IPA doesn't have to do anything for these
4676 * updates so ignoring!
4677 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004678 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679 return 0;
4680
4681 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4682 if (hdd_ipa->iface_context[i].adapter == NULL) {
4683 iface_context = &(hdd_ipa->iface_context[i]);
4684 break;
4685 }
4686 }
4687
4688 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304689 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004690 "All the IPA interfaces are in use");
4691 ret = -ENOMEM;
4692 goto end;
4693 }
4694
4695 adapter->ipa_context = iface_context;
4696 iface_context->adapter = adapter;
4697 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004698 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07004699 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004700 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304701 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004702 "Not able to get TL context sta_id: %d", sta_id);
4703 ret = -EINVAL;
4704 goto end;
4705 }
4706
4707 iface_context->tl_context = tl_context;
4708
Yun Parkb4f591d2017-03-29 15:51:01 -07004709 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4710 adapter->dev->name, adapter->dev->dev_addr,
4711 iface_context->prod_client,
4712 iface_context->cons_client,
4713 adapter->sessionId,
4714 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004715 if (ret)
4716 goto end;
4717
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718 hdd_ipa->num_iface++;
4719 return ret;
4720
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004721end:
4722 if (iface_context)
4723 hdd_ipa_cleanup_iface(iface_context);
4724 return ret;
4725}
4726
Yun Parka27049a2016-10-11 12:30:49 -07004727#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004728/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004729 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004730 * @mcc_mode: 0=MCC/1=SCC
4731 *
4732 * Return: 0 on success, negative errno value on error
4733 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004734static int __hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004735{
4736 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304737 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004738 hdd_adapter_t *pAdapter;
4739 struct ipa_msg_meta meta;
4740 struct ipa_wlan_msg *msg;
4741 int ret;
4742
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004743 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004744 return -EINVAL;
4745
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004746 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4747 return -EINVAL;
4748
4749 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004750 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004751 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304752 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004753 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08004754 if (pAdapter->device_mode == QDF_STA_MODE ||
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004755 pAdapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004756 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004757 pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004758 hdd_deinit_tx_rx(pAdapter);
4759 }
4760 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004761 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004762 adapter_node = next;
4763 }
4764 }
4765
4766 /* Send SCC/MCC Switching event to IPA */
4767 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304768 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004769 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004770 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771 return -ENOMEM;
4772 }
4773
4774 meta.msg_type = mcc_mode ?
4775 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08004776 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777
4778 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4779
4780 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004781 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004782 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304783 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004784 }
4785
4786 return ret;
4787}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004788
4789/**
4790 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
4791 * @mcc_mode: 0=MCC/1=SCC
4792 *
4793 * Return: 0 on success, negative errno value on error
4794 */
4795int hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
4796{
4797 int ret;
4798
4799 cds_ssr_protect(__func__);
4800 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
4801 cds_ssr_unprotect(__func__);
4802
4803 return ret;
4804}
Yun Parka27049a2016-10-11 12:30:49 -07004805#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004806
4807/**
4808 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
4809 * @event: IPA WLAN event to be converted to a string
4810 *
4811 * Return: ASCII string representing the IPA WLAN event
4812 */
4813static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
4814{
4815 switch (event) {
4816 case WLAN_CLIENT_CONNECT:
4817 return "WLAN_CLIENT_CONNECT";
4818 case WLAN_CLIENT_DISCONNECT:
4819 return "WLAN_CLIENT_DISCONNECT";
4820 case WLAN_CLIENT_POWER_SAVE_MODE:
4821 return "WLAN_CLIENT_POWER_SAVE_MODE";
4822 case WLAN_CLIENT_NORMAL_MODE:
4823 return "WLAN_CLIENT_NORMAL_MODE";
4824 case SW_ROUTING_ENABLE:
4825 return "SW_ROUTING_ENABLE";
4826 case SW_ROUTING_DISABLE:
4827 return "SW_ROUTING_DISABLE";
4828 case WLAN_AP_CONNECT:
4829 return "WLAN_AP_CONNECT";
4830 case WLAN_AP_DISCONNECT:
4831 return "WLAN_AP_DISCONNECT";
4832 case WLAN_STA_CONNECT:
4833 return "WLAN_STA_CONNECT";
4834 case WLAN_STA_DISCONNECT:
4835 return "WLAN_STA_DISCONNECT";
4836 case WLAN_CLIENT_CONNECT_EX:
4837 return "WLAN_CLIENT_CONNECT_EX";
4838
4839 case IPA_WLAN_EVENT_MAX:
4840 default:
4841 return "UNKNOWN";
4842 }
4843}
4844
4845/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004846 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
4847 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
4848 *
4849 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
4850 */
4851static enum ipa_wlan_event
4852hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
4853{
4854 enum ipa_wlan_event ipa_event;
4855
4856 switch (hdd_ipa_event_type) {
4857 case HDD_IPA_CLIENT_CONNECT:
4858 ipa_event = WLAN_CLIENT_CONNECT;
4859 break;
4860 case HDD_IPA_CLIENT_DISCONNECT:
4861 ipa_event = WLAN_CLIENT_DISCONNECT;
4862 break;
4863 case HDD_IPA_AP_CONNECT:
4864 ipa_event = WLAN_AP_CONNECT;
4865 break;
4866 case HDD_IPA_AP_DISCONNECT:
4867 ipa_event = WLAN_AP_DISCONNECT;
4868 break;
4869 case HDD_IPA_STA_CONNECT:
4870 ipa_event = WLAN_STA_CONNECT;
4871 break;
4872 case HDD_IPA_STA_DISCONNECT:
4873 ipa_event = WLAN_STA_DISCONNECT;
4874 break;
4875 case HDD_IPA_CLIENT_CONNECT_EX:
4876 ipa_event = WLAN_CLIENT_CONNECT_EX;
4877 break;
4878 case HDD_IPA_WLAN_EVENT_MAX:
4879 default:
4880 ipa_event = IPA_WLAN_EVENT_MAX;
4881 break;
4882 }
4883 return ipa_event;
4884
4885}
4886
4887/**
4888 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 * @adapter: adapter upon which the event was received
4890 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07004891 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004892 * @mac_address: MAC address associated with the event
4893 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07004894 * This function is meant to be called from within wlan_hdd_ipa.c
4895 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896 * Return: 0 on success, negative errno value on error
4897 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07004898static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004899 enum ipa_wlan_event type, uint8_t *mac_addr)
4900{
4901 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4902 struct ipa_msg_meta meta;
4903 struct ipa_wlan_msg *msg;
4904 struct ipa_wlan_msg_ex *msg_ex = NULL;
4905 int ret;
4906
Srinivas Girigowda97852372017-03-06 16:52:59 -08004907 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004908 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
4909 mac_addr, sta_id);
4910
4911 if (type >= IPA_WLAN_EVENT_MAX)
4912 return -EINVAL;
4913
4914 if (WARN_ON(is_zero_ether_addr(mac_addr)))
4915 return -EINVAL;
4916
4917 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304918 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004919 return -EINVAL;
4920 }
4921
4922 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
4923 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08004924 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004925 return 0;
4926 }
4927
4928 /*
4929 * During IPA UC resource loading/unloading new events can be issued.
4930 * Store the events separately and handle them later.
4931 */
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004932 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4933 if (hdd_ipa->resource_loading) {
4934 unsigned int pending_event_count;
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004935 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08004936
Yun Park64c405e2017-01-10 22:35:51 -08004937 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4938 "IPA resource load in progress");
Yun Park7c4f31b2016-11-30 10:09:21 -08004939
Yun Park64c405e2017-01-10 22:35:51 -08004940 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004941
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004942 pending_event_count =
4943 qdf_list_size(&hdd_ipa->pending_event);
4944 if (pending_event_count >=
4945 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004946 hdd_debug("Reached max pending event count");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004947 qdf_list_remove_front(&hdd_ipa->pending_event,
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004948 (qdf_list_node_t **)&pending_event);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004949 } else {
4950 pending_event =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004951 qdf_mem_malloc(sizeof(*pending_event));
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004952 }
4953
4954 if (!pending_event) {
Yun Park64c405e2017-01-10 22:35:51 -08004955 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park7c4f31b2016-11-30 10:09:21 -08004956 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4957 "Pending event memory alloc fail");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004958 return -ENOMEM;
4959 }
4960
4961 pending_event->adapter = adapter;
4962 pending_event->sta_id = sta_id;
4963 pending_event->type = type;
4964 qdf_mem_copy(pending_event->mac_addr,
4965 mac_addr,
4966 QDF_MAC_ADDR_SIZE);
4967 qdf_list_insert_back(&hdd_ipa->pending_event,
4968 &pending_event->node);
4969
Yun Park64c405e2017-01-10 22:35:51 -08004970 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004971 return 0;
4972 } else if (hdd_ipa->resource_unloading) {
Yun Park64c405e2017-01-10 22:35:51 -08004973 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4974 "IPA resource unload in progress");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004975 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977 }
4978
4979 hdd_ipa->stats.event[type]++;
4980
Leo Chang3bc8fed2015-11-13 10:59:47 -08004981 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004982 switch (type) {
4983 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07004984 qdf_mutex_acquire(&hdd_ipa->event_lock);
4985
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986 /* STA already connected and without disconnect, connect again
4987 * This is Roaming scenario
4988 */
4989 if (hdd_ipa->sta_connected)
4990 hdd_ipa_cleanup_iface(adapter->ipa_context);
4991
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004992 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
4993 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304994 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07004996 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004997
Yun Park8f289c82016-10-18 16:38:21 -07004998 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4999 (hdd_ipa->sap_num_connected_sta > 0) &&
5000 !hdd_ipa->sta_connected) {
5001 qdf_mutex_release(&hdd_ipa->event_lock);
5002 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005003 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005004 qdf_mutex_acquire(&hdd_ipa->event_lock);
5005 }
5006
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005007 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005008 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005009 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005010
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005011 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005012
5013 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014 break;
5015
5016 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005017 qdf_mutex_acquire(&hdd_ipa->event_lock);
5018
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005019 /* For DFS channel we get two start_bss event (before and after
5020 * CAC). Also when ACS range includes both DFS and non DFS
5021 * channels, we could possibly change channel many times due to
5022 * RADAR detection and chosen channel may not be a DFS channels.
5023 * So dont return error here. Just discard the event.
5024 */
Yun Park8f289c82016-10-18 16:38:21 -07005025 if (adapter->ipa_context) {
5026 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005027 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005028 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005029
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005030 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5031 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005032 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005033 hdd_err("%s: Evt: %d, Interface setup failed",
5034 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005035 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005036 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005037
Yun Park8f289c82016-10-18 16:38:21 -07005038 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5039 qdf_mutex_release(&hdd_ipa->event_lock);
5040 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005041 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005042 qdf_mutex_acquire(&hdd_ipa->event_lock);
5043 }
5044
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005045 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005046 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005047 (adapter->ipa_context))->iface_id;
5048
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305049 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050 break;
5051
5052 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305053 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005054
5055 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005056 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005057 hdd_err("%s: Evt: %d, STA already disconnected",
5058 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005059 return -EINVAL;
5060 }
Yun Parka37592b2016-06-11 17:10:28 -07005061
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005062 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005063
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005064 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005065 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005066 msg_ex->name);
5067 } else {
5068 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005069 if (!hdd_ipa->num_iface &&
5070 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305071 hdd_ipa->activated_fw_pipe) &&
5072 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005074 }
5075
Yun Park74127cf2016-09-18 11:22:41 -07005076 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5077 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005078 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005080 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005081 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005082 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5083 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 }
5085
Yun Park8f289c82016-10-18 16:38:21 -07005086 hdd_ipa_cleanup_iface(adapter->ipa_context);
5087
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305088 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 break;
5090
5091 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005092 qdf_mutex_acquire(&hdd_ipa->event_lock);
5093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005095 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005096 hdd_err("%s: Evt: %d, SAP already disconnected",
5097 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 return -EINVAL;
5099 }
5100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101 if ((!hdd_ipa->num_iface) &&
5102 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305103 hdd_ipa->activated_fw_pipe) &&
5104 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005105 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005106 /*
5107 * We disable WDI pipes directly here since
5108 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5109 * processed when unloading WLAN driver is in
5110 * progress
5111 */
5112 hdd_ipa_uc_disable_pipes(hdd_ipa);
5113 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305114 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005115 "NO INTF left but still pipe clean up");
5116 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5117 }
5118 }
5119
5120 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005121 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005123 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005124 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005125 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5126 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005127 }
Yun Parka37592b2016-06-11 17:10:28 -07005128
Yun Park8f289c82016-10-18 16:38:21 -07005129 hdd_ipa_cleanup_iface(adapter->ipa_context);
5130
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305131 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132 break;
5133
5134 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005136 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005137 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305138 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005139 return 0;
5140 }
5141
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305142 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5144 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005145 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305146 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 "%s: STA ID %d found, not valid",
5148 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005149 return 0;
5150 }
Yun Park312f71a2015-12-08 10:22:42 -08005151
5152 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005153 if (hdd_ipa->sap_num_connected_sta == 0 &&
5154 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005155 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005156 hdd_ipa->sta_connected) {
5157 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005158 hdd_ipa_uc_offload_enable_disable(
5159 hdd_get_adapter(hdd_ipa->hdd_ctx,
5160 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005161 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005162 qdf_mutex_acquire(&hdd_ipa->event_lock);
5163 }
Yun Parka37592b2016-06-11 17:10:28 -07005164
Yun Park312f71a2015-12-08 10:22:42 -08005165 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5166 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305167 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005168 "%s: handle 1st con ret %d",
5169 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005170
5171 if (hdd_ipa_uc_sta_is_enabled(
5172 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005173 hdd_ipa->sta_connected) {
5174 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005175 hdd_ipa_uc_offload_enable_disable(
5176 hdd_get_adapter(
5177 hdd_ipa->hdd_ctx,
5178 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005179 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005180 } else {
5181 qdf_mutex_release(&hdd_ipa->event_lock);
5182 }
Yun Parka37592b2016-06-11 17:10:28 -07005183
Yun Park312f71a2015-12-08 10:22:42 -08005184 return ret;
5185 }
5186 }
5187
5188 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005189
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305190 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191
5192 meta.msg_type = type;
5193 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5194 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305195 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196
5197 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305198 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005199 "msg_ex allocation failed");
5200 return -ENOMEM;
5201 }
5202 strlcpy(msg_ex->name, adapter->dev->name,
5203 IPA_RESOURCE_NAME_MAX);
5204 msg_ex->num_of_attribs = 1;
5205 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5206 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5207 msg_ex->attribs[0].offset =
5208 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5209 } else {
5210 msg_ex->attribs[0].offset =
5211 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5212 }
5213 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5214 IPA_MAC_ADDR_SIZE);
5215
5216 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5217
5218 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005219 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305220 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305221 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005222 return ret;
5223 }
5224 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 return ret;
5226
5227 case WLAN_CLIENT_DISCONNECT:
5228 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005229 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005230 "%s: IPA UC OFFLOAD NOT ENABLED",
5231 msg_ex->name);
5232 return 0;
5233 }
5234
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305235 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005237 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305238 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239 "%s: STA ID %d NOT found, not valid",
5240 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 return 0;
5242 }
5243 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005244
Yun Park9b5030f2016-11-08 12:02:37 -08005245 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005246 if (!hdd_ipa->sap_num_connected_sta &&
5247 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005248 if ((false == hdd_ipa->resource_unloading)
5249 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305250 hdd_ipa->activated_fw_pipe) &&
5251 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005252 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5253 }
5254
Yun Park9b5030f2016-11-08 12:02:37 -08005255 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005256 hdd_ipa->sta_connected) {
5257 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005258 hdd_ipa_uc_offload_enable_disable(
5259 hdd_get_adapter(hdd_ipa->hdd_ctx,
5260 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005261 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005262 } else {
5263 qdf_mutex_release(&hdd_ipa->event_lock);
5264 }
Yun Park8f289c82016-10-18 16:38:21 -07005265 } else {
5266 qdf_mutex_release(&hdd_ipa->event_lock);
5267 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005268 break;
5269
5270 default:
5271 return 0;
5272 }
5273
5274 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305275 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005276 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305277 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005278 return -ENOMEM;
5279 }
5280
5281 meta.msg_type = type;
5282 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5283 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5284
Srinivas Girigowda97852372017-03-06 16:52:59 -08005285 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005286 msg->name, meta.msg_type);
5287
5288 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5289
5290 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005291 hdd_err("%s: Evt: %d fail:%d",
5292 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305293 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005294 return ret;
5295 }
5296
5297 hdd_ipa->stats.num_send_msg++;
5298
5299end:
5300 return ret;
5301}
5302
5303/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005304 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005305 * @adapter: adapter upon which the event was received
5306 * @sta_id: station id for the event
5307 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5308 * @mac_address: MAC address associated with the event
5309 *
5310 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5311 *
5312 * Return: 0 on success, negative errno value on error
5313 */
5314int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
5315 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5316{
5317 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005318 int ret = 0;
5319
5320 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005321
Leo Changa202b522016-10-14 16:13:50 -07005322 /* Data path offload only support for STA and SAP mode */
5323 if ((QDF_STA_MODE == adapter->device_mode) ||
5324 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005325 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005326
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005327 cds_ssr_unprotect(__func__);
5328
5329 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005330}
5331
5332/**
5333 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5334 * @hdd_ipa: Global HDD IPA context
5335 *
5336 * Return: None
5337 */
5338static void
5339hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5340{
5341 unsigned int pending_event_count;
5342 struct ipa_uc_pending_event *pending_event = NULL;
5343
5344 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005345 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005346 "%s, Pending Event Count %d", __func__, pending_event_count);
5347 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005348 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005349 "%s, No Pending Event", __func__);
5350 return;
5351 }
5352
5353 qdf_list_remove_front(&hdd_ipa->pending_event,
5354 (qdf_list_node_t **)&pending_event);
5355 while (pending_event != NULL) {
5356 __hdd_ipa_wlan_evt(pending_event->adapter,
5357 pending_event->type,
5358 pending_event->sta_id,
5359 pending_event->mac_addr);
5360 qdf_mem_free(pending_event);
5361 pending_event = NULL;
5362 qdf_list_remove_front(&hdd_ipa->pending_event,
5363 (qdf_list_node_t **)&pending_event);
5364 }
5365}
5366
5367/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005368 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5369 * @state: IPA RM state value
5370 *
5371 * Return: ASCII string representing the IPA RM state
5372 */
5373static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5374{
5375 switch (state) {
5376 case HDD_IPA_RM_RELEASED:
5377 return "RELEASED";
5378 case HDD_IPA_RM_GRANT_PENDING:
5379 return "GRANT_PENDING";
5380 case HDD_IPA_RM_GRANTED:
5381 return "GRANTED";
5382 }
5383
5384 return "UNKNOWN";
5385}
5386
5387/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005388 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005389 * @hdd_ctx: HDD global context
5390 *
5391 * Allocate hdd_ipa resources, ipa pipe resource and register
5392 * wlan interface with IPA module.
5393 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305394 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005395 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005396static QDF_STATUS __hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005397{
5398 struct hdd_ipa_priv *hdd_ipa = NULL;
5399 int ret, i;
5400 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005401 struct ol_txrx_pdev_t *pdev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005402
5403 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305404 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005405
Yun Parkbaa62862017-01-18 13:43:34 -08005406 ENTER();
5407
5408 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005409 if (!pdev) {
5410 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5411 goto fail_return;
5412 }
5413
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305414 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005415 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305416 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005417 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005418 }
5419
5420 hdd_ctx->hdd_ipa = hdd_ipa;
5421 ghdd_ipa = hdd_ipa;
5422 hdd_ipa->hdd_ctx = hdd_ctx;
5423 hdd_ipa->num_iface = 0;
5424
5425 /* Create the interface context */
5426 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5427 iface_context = &hdd_ipa->iface_context[i];
5428 iface_context->hdd_ipa = hdd_ipa;
5429 iface_context->cons_client =
5430 hdd_ipa_adapter_2_client[i].cons_client;
5431 iface_context->prod_client =
5432 hdd_ipa_adapter_2_client[i].prod_client;
5433 iface_context->iface_id = i;
5434 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305435 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005436 }
5437 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005438 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5439 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005440 }
5441
Leo Chang69c39692016-10-12 20:11:12 -07005442 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305443 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005444 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305445 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005446 qdf_list_create(&hdd_ipa->pending_event, 1000);
5447 qdf_mutex_create(&hdd_ipa->event_lock);
5448 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005449
5450 ret = hdd_ipa_setup_rm(hdd_ipa);
5451 if (ret)
5452 goto fail_setup_rm;
5453
5454 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5455 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305456 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005457 hdd_ipa->sap_num_connected_sta = 0;
5458 hdd_ipa->ipa_tx_packets_diff = 0;
5459 hdd_ipa->ipa_rx_packets_diff = 0;
5460 hdd_ipa->ipa_p_tx_packets = 0;
5461 hdd_ipa->ipa_p_rx_packets = 0;
5462 hdd_ipa->resource_loading = false;
5463 hdd_ipa->resource_unloading = false;
5464 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005465 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005466 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005467 /* Setup IPA sys_pipe for MCC */
5468 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5469 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5470 if (ret)
5471 goto fail_create_sys_pipe;
5472 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005473 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5474 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005475
5476 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5477 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5478 hdd_ipa_uc_fw_op_event_handler);
5479 hdd_ipa->uc_op_work[i].msg = NULL;
5480 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005481 } else {
5482 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5483 if (ret)
5484 goto fail_create_sys_pipe;
5485 }
5486
Yun Parkbaa62862017-01-18 13:43:34 -08005487 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305488 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005489
5490fail_create_sys_pipe:
5491 hdd_ipa_destroy_rm_resource(hdd_ipa);
5492fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305493 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305494 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005495 hdd_ctx->hdd_ipa = NULL;
5496 ghdd_ipa = NULL;
5497fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08005498 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305499 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005500}
5501
5502/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005503 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5504 * @hdd_ctx: HDD global context
5505 *
5506 * Allocate hdd_ipa resources, ipa pipe resource and register
5507 * wlan interface with IPA module.
5508 *
5509 * Return: QDF_STATUS enumeration
5510 */
5511QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
5512{
5513 QDF_STATUS ret;
5514
5515 cds_ssr_protect(__func__);
5516 ret = __hdd_ipa_init(hdd_ctx);
5517 cds_ssr_unprotect(__func__);
5518
5519 return ret;
5520}
5521
Arun Khandavallicc544b32017-01-30 19:52:16 +05305522
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005523/**
Yun Parkf19e07d2015-11-20 11:34:27 -08005524 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
5525 * @hdd_ipa: pointer to HDD IPA struct
5526 *
5527 * Return: none
5528 */
Jeff Johnsond7720632016-10-05 16:04:32 -07005529static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08005530{
5531 struct ipa_uc_pending_event *pending_event = NULL;
5532
Anurag Chouhanffb21542016-02-17 14:33:03 +05305533 while (qdf_list_remove_front(&hdd_ipa->pending_event,
5534 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305535 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005536 }
5537
Anurag Chouhanffb21542016-02-17 14:33:03 +05305538 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005539}
5540
5541/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005542 * __hdd_ipa_cleanup - IPA cleanup function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543 * @hdd_ctx: HDD global context
5544 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305545 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005546 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005547static QDF_STATUS __hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548{
5549 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5550 int i;
5551 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305552 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005553 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5554
5555 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305556 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005557
5558 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5559 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5560 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5561 }
5562
5563 /* Teardown IPA sys_pipe for MCC */
5564 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5565 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5566
5567 hdd_ipa_destroy_rm_resource(hdd_ipa);
5568
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005569 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005570
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305571 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572
Nirav Shahcbc6d722016-03-01 16:24:53 +05305573 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5574 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305575 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005576
5577 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005578 if (pm_tx_cb->ipa_tx_desc)
5579 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005580
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305581 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005582 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305583 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005584
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305585 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005586 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587
5588 /* destory the interface lock */
5589 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5590 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305591 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005592 }
5593
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005594 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005595 if (ipa_uc_dereg_rdyCB())
5596 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5597 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305599 qdf_mutex_destroy(&hdd_ipa->event_lock);
5600 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005601 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005603 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5604 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5605 hdd_ipa->uc_op_work[i].msg = NULL;
5606 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005607 }
5608
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305609 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005610 hdd_ctx->hdd_ipa = NULL;
5611
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305612 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005613}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005614
5615/**
5616 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5617 * @hdd_ctx: HDD global context
5618 *
5619 * Return: QDF_STATUS enumeration
5620 */
5621QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
5622{
5623 QDF_STATUS ret;
5624
5625 cds_ssr_protect(__func__);
5626 ret = __hdd_ipa_cleanup(hdd_ctx);
5627 cds_ssr_unprotect(__func__);
5628
5629 return ret;
5630}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631#endif /* IPA_OFFLOAD */