blob: 545d2048733c93a366302150028c0ba166e00666 [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
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530889 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530891 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800892 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800893
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530894 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 for (dump_count = 0;
896 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
897 dump_count++) {
898 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
899 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
900 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530901 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530902 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800903 dump_info->time, dump_info->ipa_excep_count,
904 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800905 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800906 dump_info->rx_destructor_call,
907 dump_info->rx_discard_count);
908 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530909 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530910 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800911 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
912}
913
914/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700915 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
916 * __hdd_ipa_uc_rt_debug_host_dump
917 * @hdd_ctx: pointer to hdd context.
918 *
919 * If rt debug enabled, dump debug buffer contents based on requirement
920 *
921 * Return: none
922 */
923void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
924{
925 cds_ssr_protect(__func__);
926 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
927 cds_ssr_unprotect(__func__);
928}
929
930/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
932 * @ctext: pointer to hdd context.
933 *
934 * periodically called by timer expire
935 * will try to alloc dummy memory and detect out of memory condition
936 * if out of memory detected, dump wlan-ipa stats
937 *
938 * Return: none
939 */
940static void hdd_ipa_uc_rt_debug_handler(void *ctext)
941{
942 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700943 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800944 void *dummy_ptr = NULL;
945
946 if (wlan_hdd_validate_context(hdd_ctx))
947 return;
948
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700949 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
950
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700952 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
953 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800954 return;
955 }
956
957 /* Allocate dummy buffer periodically and free immediately. this will
958 * proactively detect OOM and if allocation fails dump ipa stats
959 */
960 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
961 GFP_KERNEL | GFP_ATOMIC);
962 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
964 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -0700965 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
966 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800967 } else {
968 kfree(dummy_ptr);
969 }
970
Anurag Chouhan210db072016-02-22 18:42:15 +0530971 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800972 HDD_IPA_UC_RT_DEBUG_PERIOD);
973}
974
975/**
Yun Parkb187d542016-11-14 18:10:04 -0800976 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800977 * @skb: packet pinter
978 *
979 * when free data packet, will be invoked by wlan client and will increase
980 * free counter
981 *
982 * Return: none
983 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700984static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800985{
986 if (!ghdd_ipa) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700987 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "invalid hdd context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800988 return;
989 }
990
991 ghdd_ipa->ipa_rx_destructor_count++;
992}
993
994/**
Yun Parkb187d542016-11-14 18:10:04 -0800995 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800996 * @hdd_ctx: hdd main context
997 *
998 * free all rt debugging resources
999 *
1000 * Return: none
1001 */
1002static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
1003{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001004 struct hdd_ipa_priv *hdd_ipa;
1005
1006 if (wlan_hdd_validate_context(hdd_ctx))
1007 return;
1008
1009 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001010
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301011 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012
1013 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001014 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1015 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016 return;
1017 }
1018
Anurag Chouhan210db072016-02-22 18:42:15 +05301019 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001020 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1021 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1022 }
1023 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1024
1025 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301026 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1027 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301029 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001030}
1031
1032/**
Yun Parkb187d542016-11-14 18:10:04 -08001033 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 * @hdd_ctx: hdd main context
1035 *
1036 * alloc and initialize all rt debugging resources
1037 *
1038 * Return: none
1039 */
1040static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
1041{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001042 struct hdd_ipa_priv *hdd_ipa;
1043
1044 if (wlan_hdd_validate_context(hdd_ctx))
1045 return;
1046
1047 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301049 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301051 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001052 sizeof(struct uc_rt_debug_info) *
1053 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1054 hdd_ipa->ipa_tx_forward = 0;
1055 hdd_ipa->ipa_rx_discard = 0;
1056 hdd_ipa->ipa_rx_net_send_count = 0;
1057 hdd_ipa->ipa_rx_internel_drop_count = 0;
1058 hdd_ipa->ipa_rx_destructor_count = 0;
1059
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060 /* Reatime debug enable on feature enable */
1061 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001062 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1063 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001064 return;
1065 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001066
1067 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1068 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1069 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1070 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1071
Anurag Chouhan210db072016-02-22 18:42:15 +05301072 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001073 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301074 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001075 HDD_IPA_UC_RT_DEBUG_PERIOD);
1076
1077}
1078
1079/**
Yun Parkb187d542016-11-14 18:10:04 -08001080 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1081 * @hdd_ipa: HDD IPA struct
1082 *
1083 * Dump entries in struct hdd_ipa
1084 *
1085 * Return: none
1086 */
1087static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1088{
1089 int i;
1090
1091 /* HDD IPA */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001092 hdd_info("==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001093 "num_iface: %d\n"
1094 "rm_state: %d\n"
1095 "rm_lock: %p\n"
1096 "uc_rm_work: %p\n"
1097 "uc_op_work: %p\n"
1098 "wake_lock: %p\n"
1099 "wake_lock_work: %p\n"
1100 "wake_lock_released: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08001101 "tx_ref_cnt: %d\n"
1102 "pm_queue_head----\n"
1103 "\thead: %p\n"
1104 "\ttail: %p\n"
1105 "\tqlen: %d\n"
1106 "pm_work: %p\n"
1107 "pm_lock: %p\n"
1108 "suspended: %d\n",
1109 hdd_ipa->num_iface,
1110 hdd_ipa->rm_state,
1111 &hdd_ipa->rm_lock,
1112 &hdd_ipa->uc_rm_work,
1113 &hdd_ipa->uc_op_work,
1114 &hdd_ipa->wake_lock,
1115 &hdd_ipa->wake_lock_work,
1116 hdd_ipa->wake_lock_released,
Yun Parkb187d542016-11-14 18:10:04 -08001117 hdd_ipa->tx_ref_cnt.counter,
1118 hdd_ipa->pm_queue_head.head,
1119 hdd_ipa->pm_queue_head.tail,
1120 hdd_ipa->pm_queue_head.qlen,
1121 &hdd_ipa->pm_work,
1122 &hdd_ipa->pm_lock,
1123 hdd_ipa->suspended);
Yun Park52b2b992016-09-22 15:49:51 -07001124 hdd_err("\nq_lock: %p\n"
Yun Parkb187d542016-11-14 18:10:04 -08001125 "pend_desc_head----\n"
1126 "\tnext: %p\n"
1127 "\tprev: %p\n"
1128 "hdd_ctx: %p\n"
1129 "debugfs_dir: %p\n"
1130 "stats: %p\n"
1131 "ipv4_notifier: %p\n"
1132 "curr_prod_bw: %d\n"
1133 "curr_cons_bw: %d\n"
1134 "activated_fw_pipe: %d\n"
1135 "sap_num_connected_sta: %d\n"
1136 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001137 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001138 hdd_ipa->pend_desc_head.next,
1139 hdd_ipa->pend_desc_head.prev,
1140 hdd_ipa->hdd_ctx,
1141 hdd_ipa->debugfs_dir,
1142 &hdd_ipa->stats,
1143 &hdd_ipa->ipv4_notifier,
1144 hdd_ipa->curr_prod_bw,
1145 hdd_ipa->curr_cons_bw,
1146 hdd_ipa->activated_fw_pipe,
1147 hdd_ipa->sap_num_connected_sta,
1148 (unsigned int)hdd_ipa->sta_connected
1149 );
Srinivas Girigowda97852372017-03-06 16:52:59 -08001150 hdd_info("\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001151 "rx_pipe_handle: 0x%x\n"
1152 "resource_loading: %d\n"
1153 "resource_unloading: %d\n"
1154 "pending_cons_req: %d\n"
1155 "pending_event----\n"
1156 "\tanchor.next: %p\n"
1157 "\tanchor.prev: %p\n"
1158 "\tcount: %d\n"
1159 "\tmax_size: %d\n"
1160 "event_lock: %p\n"
1161 "ipa_tx_packets_diff: %d\n"
1162 "ipa_rx_packets_diff: %d\n"
1163 "ipa_p_tx_packets: %d\n"
1164 "ipa_p_rx_packets: %d\n"
1165 "stat_req_reason: %d\n",
1166 hdd_ipa->tx_pipe_handle,
1167 hdd_ipa->rx_pipe_handle,
1168 hdd_ipa->resource_loading,
1169 hdd_ipa->resource_unloading,
1170 hdd_ipa->pending_cons_req,
1171 hdd_ipa->pending_event.anchor.next,
1172 hdd_ipa->pending_event.anchor.prev,
1173 hdd_ipa->pending_event.count,
1174 hdd_ipa->pending_event.max_size,
1175 &hdd_ipa->event_lock,
1176 hdd_ipa->ipa_tx_packets_diff,
1177 hdd_ipa->ipa_rx_packets_diff,
1178 hdd_ipa->ipa_p_tx_packets,
1179 hdd_ipa->ipa_p_rx_packets,
1180 hdd_ipa->stat_req_reason);
1181
Srinivas Girigowda97852372017-03-06 16:52:59 -08001182 hdd_info("assoc_stas_map([id]is_reserved/sta_id): ");
Yun Parkb187d542016-11-14 18:10:04 -08001183 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001184 hdd_info(" [%d]%d/%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001185 hdd_ipa->assoc_stas_map[i].is_reserved,
1186 hdd_ipa->assoc_stas_map[i].sta_id);
1187 }
1188}
1189
1190/**
1191 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1192 * @hdd_ipa: HDD IPA struct
1193 *
1194 * Dump entire struct hdd_ipa_sys_pipe
1195 *
1196 * Return: none
1197 */
1198static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1199{
1200 int i;
1201
1202 /* IPA SYS Pipes */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001203 hdd_info("==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001204
1205 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1206 struct hdd_ipa_sys_pipe *sys_pipe;
1207 struct ipa_sys_connect_params *ipa_sys_params;
1208
1209 sys_pipe = &hdd_ipa->sys_pipe[i];
1210 ipa_sys_params = &sys_pipe->ipa_sys_params;
1211
Srinivas Girigowda97852372017-03-06 16:52:59 -08001212 hdd_info("sys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001213 "\tconn_hdl: 0x%x\n"
1214 "\tconn_hdl_valid: %d\n"
1215 "\tnat_en: %d\n"
1216 "\thdr_len %d\n"
1217 "\thdr_additional_const_len: %d\n"
1218 "\thdr_ofst_pkt_size_valid: %d\n"
1219 "\thdr_ofst_pkt_size: %d\n"
1220 "\thdr_little_endian: %d\n"
1221 "\tmode: %d\n"
1222 "\tclient: %d\n"
1223 "\tdesc_fifo_sz: %d\n"
1224 "\tpriv: %p\n"
1225 "\tnotify: %p\n"
1226 "\tskip_ep_cfg: %d\n"
1227 "\tkeep_ipa_awake: %d\n",
1228 i,
1229 sys_pipe->conn_hdl,
1230 sys_pipe->conn_hdl_valid,
1231 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1232 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1233 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1234 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1235 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1236 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1237 ipa_sys_params->ipa_ep_cfg.mode.mode,
1238 ipa_sys_params->client,
1239 ipa_sys_params->desc_fifo_sz,
1240 ipa_sys_params->priv,
1241 ipa_sys_params->notify,
1242 ipa_sys_params->skip_ep_cfg,
1243 ipa_sys_params->keep_ipa_awake);
1244 }
1245}
1246
1247/**
1248 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1249 * @hdd_ipa: HDD IPA struct
1250 *
1251 * Dump entire struct hdd_ipa_iface_context
1252 *
1253 * Return: none
1254 */
1255static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1256{
1257 int i;
1258
1259 /* IPA Interface Contexts */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001260 hdd_info("==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001261
1262 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1263 struct hdd_ipa_iface_context *iface_context;
1264
1265 iface_context = &hdd_ipa->iface_context[i];
1266
Srinivas Girigowda97852372017-03-06 16:52:59 -08001267 hdd_info("iface_context[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001268 "\thdd_ipa: %p\n"
1269 "\tadapter: %p\n"
1270 "\ttl_context: %p\n"
1271 "\tcons_client: %d\n"
1272 "\tprod_client: %d\n"
1273 "\tiface_id: %d\n"
1274 "\tsta_id: %d\n"
1275 "\tinterface_lock: %p\n"
1276 "\tifa_address: 0x%x\n",
1277 i,
1278 iface_context->hdd_ipa,
1279 iface_context->adapter,
1280 iface_context->tl_context,
1281 iface_context->cons_client,
1282 iface_context->prod_client,
1283 iface_context->iface_id,
1284 iface_context->sta_id,
1285 &iface_context->interface_lock,
1286 iface_context->ifa_address);
1287 }
1288}
1289
1290/**
1291 * hdd_ipa_dump_info() - dump HDD IPA struct
1292 * @pHddCtx: hdd main context
1293 *
1294 * Dump entire struct hdd_ipa
1295 *
1296 * Return: none
1297 */
1298void hdd_ipa_dump_info(hdd_context_t *hdd_ctx)
1299{
1300 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1301
1302 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1303 hdd_ipa_dump_sys_pipe(hdd_ipa);
1304 hdd_ipa_dump_iface_context(hdd_ipa);
1305}
1306
1307/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001308 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1309 * enabled
1310 *
1311 * This routine is called to set TX flow info if IPA is enabled
1312 *
1313 * Return: None
1314 */
1315void hdd_ipa_set_tx_flow_info(void)
1316{
1317 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1318 QDF_STATUS status;
1319 hdd_adapter_t *adapter;
1320 hdd_station_ctx_t *pHddStaCtx;
1321 hdd_ap_ctx_t *hdd_ap_ctx;
1322 hdd_hostapd_state_t *hostapd_state;
1323 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1324 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1325 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1326 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1327 const char *p2pMode = "DEV";
1328 hdd_context_t *hdd_ctx;
1329 cds_context_type *cds_ctx;
1330#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1331 uint8_t targetChannel = 0;
1332 uint8_t preAdapterChannel = 0;
1333 uint8_t channel24;
1334 uint8_t channel5;
1335 hdd_adapter_t *preAdapterContext = NULL;
1336 hdd_adapter_t *adapter2_4 = NULL;
1337 hdd_adapter_t *adapter5 = NULL;
1338 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1339#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1340 struct wlan_objmgr_psoc *psoc;
1341
1342 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1343 if (!hdd_ctx) {
1344 cds_err("HDD context is NULL");
1345 return;
1346 }
1347
1348 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1349 if (!cds_ctx) {
1350 cds_err("Invalid CDS Context");
1351 return;
1352 }
1353
1354 psoc = hdd_ctx->hdd_psoc;
1355 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1356 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1357 adapter = adapterNode->pAdapter;
1358 switch (adapter->device_mode) {
1359 case QDF_STA_MODE:
1360 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1361 if (eConnectionState_Associated ==
1362 pHddStaCtx->conn_info.connState) {
1363 staChannel =
1364 pHddStaCtx->conn_info.operationChannel;
1365 qdf_copy_macaddr(&staBssid,
1366 &pHddStaCtx->conn_info.bssId);
1367#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1368 targetChannel = staChannel;
1369#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1370 }
1371 break;
1372 case QDF_P2P_CLIENT_MODE:
1373 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1374 if (eConnectionState_Associated ==
1375 pHddStaCtx->conn_info.connState) {
1376 p2pChannel =
1377 pHddStaCtx->conn_info.operationChannel;
1378 qdf_copy_macaddr(&p2pBssid,
1379 &pHddStaCtx->conn_info.bssId);
1380 p2pMode = "CLI";
1381#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1382 targetChannel = p2pChannel;
1383#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1384 }
1385 break;
1386 case QDF_P2P_GO_MODE:
1387 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1388 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1389 if (hostapd_state->bssState == BSS_START
1390 && hostapd_state->qdf_status ==
1391 QDF_STATUS_SUCCESS) {
1392 p2pChannel = hdd_ap_ctx->operatingChannel;
1393 qdf_copy_macaddr(&p2pBssid,
1394 &adapter->macAddressCurrent);
1395#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1396 targetChannel = p2pChannel;
1397#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1398 }
1399 p2pMode = "GO";
1400 break;
1401 case QDF_SAP_MODE:
1402 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1403 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1404 if (hostapd_state->bssState == BSS_START
1405 && hostapd_state->qdf_status ==
1406 QDF_STATUS_SUCCESS) {
1407 apChannel = hdd_ap_ctx->operatingChannel;
1408 qdf_copy_macaddr(&apBssid,
1409 &adapter->macAddressCurrent);
1410#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1411 targetChannel = apChannel;
1412#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1413 }
1414 break;
1415 case QDF_IBSS_MODE:
1416 default:
1417 break;
1418 }
1419#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1420 if (targetChannel) {
1421 /*
1422 * This is first adapter detected as active
1423 * set as default for none concurrency case
1424 */
1425 if (!preAdapterChannel) {
1426 /* If IPA UC data path is enabled,
1427 * target should reserve extra tx descriptors
1428 * for IPA data path.
1429 * Then host data path should allow less TX
1430 * packet pumping in case IPA
1431 * data path enabled
1432 */
1433 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1434 (QDF_SAP_MODE == adapter->device_mode)) {
1435 adapter->tx_flow_low_watermark =
1436 hdd_ctx->config->TxFlowLowWaterMark +
1437 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1438 } else {
1439 adapter->tx_flow_low_watermark =
1440 hdd_ctx->config->
1441 TxFlowLowWaterMark;
1442 }
1443 adapter->tx_flow_high_watermark_offset =
1444 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1445 cdp_fc_ll_set_tx_pause_q_depth(soc,
1446 adapter->sessionId,
1447 hdd_ctx->config->TxFlowMaxQueueDepth);
1448 cds_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
1449 adapter->device_mode,
1450 targetChannel,
1451 adapter->tx_flow_low_watermark,
1452 adapter->tx_flow_low_watermark +
1453 adapter->tx_flow_high_watermark_offset,
1454 hdd_ctx->config->TxFlowMaxQueueDepth);
1455 preAdapterChannel = targetChannel;
1456 preAdapterContext = adapter;
1457 } else {
1458 /*
1459 * SCC, disable TX flow control for both
1460 * SCC each adapter cannot reserve dedicated
1461 * channel resource, as a result, if any adapter
1462 * blocked OS Q by flow control,
1463 * blocked adapter will lost chance to recover
1464 */
1465 if (preAdapterChannel == targetChannel) {
1466 /* Current adapter */
1467 adapter->tx_flow_low_watermark = 0;
1468 adapter->
1469 tx_flow_high_watermark_offset = 0;
1470 cdp_fc_ll_set_tx_pause_q_depth(soc,
1471 adapter->sessionId,
1472 hdd_ctx->config->
1473 TxHbwFlowMaxQueueDepth);
1474 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1475 hdd_device_mode_to_string(
1476 adapter->device_mode),
1477 adapter->device_mode,
1478 targetChannel,
1479 adapter->tx_flow_low_watermark,
1480 adapter->tx_flow_low_watermark +
1481 adapter->
1482 tx_flow_high_watermark_offset,
1483 hdd_ctx->config->
1484 TxHbwFlowMaxQueueDepth);
1485
1486 if (!preAdapterContext) {
1487 cds_err("SCC: Previous adapter context NULL");
1488 continue;
1489 }
1490
1491 /* Previous adapter */
1492 preAdapterContext->
1493 tx_flow_low_watermark = 0;
1494 preAdapterContext->
1495 tx_flow_high_watermark_offset = 0;
1496 cdp_fc_ll_set_tx_pause_q_depth(soc,
1497 preAdapterContext->sessionId,
1498 hdd_ctx->config->
1499 TxHbwFlowMaxQueueDepth);
1500 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1501 hdd_device_mode_to_string(
1502 preAdapterContext->device_mode
1503 ),
1504 preAdapterContext->device_mode,
1505 targetChannel,
1506 preAdapterContext->
1507 tx_flow_low_watermark,
1508 preAdapterContext->
1509 tx_flow_low_watermark +
1510 preAdapterContext->
1511 tx_flow_high_watermark_offset,
1512 hdd_ctx->config->
1513 TxHbwFlowMaxQueueDepth);
1514 }
1515 /*
1516 * MCC, each adapter will have dedicated
1517 * resource
1518 */
1519 else {
1520 /* current channel is 2.4 */
1521 if (targetChannel <=
1522 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1523 channel24 = targetChannel;
1524 channel5 = preAdapterChannel;
1525 adapter2_4 = adapter;
1526 adapter5 = preAdapterContext;
1527 } else {
1528 /* Current channel is 5 */
1529 channel24 = preAdapterChannel;
1530 channel5 = targetChannel;
1531 adapter2_4 = preAdapterContext;
1532 adapter5 = adapter;
1533 }
1534
1535 if (!adapter5) {
1536 cds_err("MCC: 5GHz adapter context NULL");
1537 continue;
1538 }
1539 adapter5->tx_flow_low_watermark =
1540 hdd_ctx->config->
1541 TxHbwFlowLowWaterMark;
1542 adapter5->
1543 tx_flow_high_watermark_offset =
1544 hdd_ctx->config->
1545 TxHbwFlowHighWaterMarkOffset;
1546 cdp_fc_ll_set_tx_pause_q_depth(soc,
1547 adapter5->sessionId,
1548 hdd_ctx->config->
1549 TxHbwFlowMaxQueueDepth);
1550 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1551 hdd_device_mode_to_string(
1552 adapter5->device_mode),
1553 adapter5->device_mode,
1554 channel5,
1555 adapter5->tx_flow_low_watermark,
1556 adapter5->
1557 tx_flow_low_watermark +
1558 adapter5->
1559 tx_flow_high_watermark_offset,
1560 hdd_ctx->config->
1561 TxHbwFlowMaxQueueDepth);
1562
1563 if (!adapter2_4) {
1564 cds_err("MCC: 2.4GHz adapter context NULL");
1565 continue;
1566 }
1567 adapter2_4->tx_flow_low_watermark =
1568 hdd_ctx->config->
1569 TxLbwFlowLowWaterMark;
1570 adapter2_4->
1571 tx_flow_high_watermark_offset =
1572 hdd_ctx->config->
1573 TxLbwFlowHighWaterMarkOffset;
1574 cdp_fc_ll_set_tx_pause_q_depth(soc,
1575 adapter2_4->sessionId,
1576 hdd_ctx->config->
1577 TxLbwFlowMaxQueueDepth);
1578 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1579 hdd_device_mode_to_string(
1580 adapter2_4->device_mode),
1581 adapter2_4->device_mode,
1582 channel24,
1583 adapter2_4->
1584 tx_flow_low_watermark,
1585 adapter2_4->
1586 tx_flow_low_watermark +
1587 adapter2_4->
1588 tx_flow_high_watermark_offset,
1589 hdd_ctx->config->
1590 TxLbwFlowMaxQueueDepth);
1591
1592 }
1593 }
1594 }
1595 targetChannel = 0;
1596#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1597 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1598 adapterNode = pNext;
1599 }
1600 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1601}
1602
1603/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001604 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001605 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001606 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1607 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 *
1609 * Return: true if IPA is enabled, false otherwise
1610 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001611static void __hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001612 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1613{
1614 struct hdd_ipa_priv *hdd_ipa;
1615
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001616 *ipa_tx_diff = 0;
1617 *ipa_rx_diff = 0;
1618
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001619 if (wlan_hdd_validate_context(hdd_ctx))
1620 return;
1621
1622 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1623
1624 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1625 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001626 return;
1627 }
1628
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301629 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1631 (false == hdd_ipa->resource_loading)) {
1632 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1633 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001634 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001635 *ipa_tx_diff, *ipa_rx_diff);
1636 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301637 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001638}
1639
1640/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001641 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1642 * @hdd_ctx: Global HDD context
1643 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1644 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1645 *
1646 * Return: true if IPA is enabled, false otherwise
1647 */
1648void hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
1649 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1650{
1651 cds_ssr_protect(__func__);
1652 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1653 cds_ssr_unprotect(__func__);
1654}
1655
1656/**
1657 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001658 * @adapter: network adapter
1659 * @reason: STAT REQ Reason
1660 *
1661 * Return: None
1662 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001663static void __hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001665 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 struct hdd_ipa_priv *hdd_ipa;
1667
Yun Park637d6482016-10-05 10:51:33 -07001668 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001669 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001671 hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
1672
1673 if (wlan_hdd_validate_context(hdd_ctx))
1674 return;
1675
1676 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1677 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1678 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001679 return;
1680 }
1681
Yun Parkb187d542016-11-14 18:10:04 -08001682 hdd_debug("STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301683 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001684 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1685 (false == hdd_ipa->resource_loading)) {
1686 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001687 qdf_mutex_release(&hdd_ipa->ipa_lock);
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001688 sme_ipa_uc_stat_request(WLAN_HDD_GET_HAL_CTX(adapter),
1689 adapter->sessionId,
1690 WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001692 } else {
1693 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001695}
1696
1697/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001698 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1699 * @adapter: network adapter
1700 * @reason: STAT REQ Reason
1701 *
1702 * Return: None
1703 */
1704void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
1705{
1706 cds_ssr_protect(__func__);
1707 __hdd_ipa_uc_stat_request(adapter, reason);
1708 cds_ssr_unprotect(__func__);
1709}
1710
Yun Park637d6482016-10-05 10:51:33 -07001711#ifdef FEATURE_METERING
1712/**
1713 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1714 * @adapter: network adapter
1715 * @reset_stats: reset stat countis after response
1716 *
1717 * Return: None
1718 */
1719void hdd_ipa_uc_sharing_stats_request(hdd_adapter_t *adapter,
1720 uint8_t reset_stats)
1721{
1722 hdd_context_t *pHddCtx;
1723 struct hdd_ipa_priv *hdd_ipa;
1724
1725 if (!adapter)
1726 return;
1727
1728 pHddCtx = adapter->pHddCtx;
1729 hdd_ipa = pHddCtx->hdd_ipa;
1730 if (!hdd_ipa_is_enabled(pHddCtx) ||
1731 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1732 return;
1733 }
1734
1735 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1736 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001737 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001738 qdf_mutex_release(&hdd_ipa->ipa_lock);
1739 wma_cli_set_command(
1740 (int)adapter->sessionId,
1741 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1742 reset_stats, VDEV_CMD);
1743 } else {
1744 qdf_mutex_release(&hdd_ipa->ipa_lock);
1745 }
1746}
1747
1748/**
1749 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1750 * @adapter: network adapter
1751 * @set_quota: when 1, FW starts quota monitoring
1752 * @quota_bytes: quota limit in bytes
1753 *
1754 * Return: None
1755 */
1756void hdd_ipa_uc_set_quota(hdd_adapter_t *adapter, uint8_t set_quota,
1757 uint64_t quota_bytes)
1758{
1759 hdd_context_t *pHddCtx;
1760 struct hdd_ipa_priv *hdd_ipa;
1761
1762 if (!adapter)
1763 return;
1764
1765 pHddCtx = adapter->pHddCtx;
1766 hdd_ipa = pHddCtx->hdd_ipa;
1767 if (!hdd_ipa_is_enabled(pHddCtx) ||
1768 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1769 return;
1770 }
1771
1772 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1773 set_quota, quota_bytes);
1774
1775 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001776 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001777 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001778 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001779 (int)adapter->sessionId,
1780 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001781 (set_quota ? quota_bytes&0xffffffff : 0),
1782 (set_quota ? quota_bytes>>32 : 0),
1783 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001784 } else {
1785 qdf_mutex_release(&hdd_ipa->ipa_lock);
1786 }
1787}
1788#endif
1789
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001790/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001791 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1792 * @hdd_ipa: Global HDD IPA context
1793 * @sta_add: Should station be added
1794 * @sta_id: ID of the station being queried
1795 *
1796 * Return: true if the station was found
1797 */
1798static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1799 bool sta_add, uint8_t sta_id)
1800{
1801 bool sta_found = false;
1802 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001803
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001804 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1805 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1806 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1807 sta_found = true;
1808 break;
1809 }
1810 }
1811 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301812 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001813 "STA ID %d already exist, cannot add", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001814 return sta_found;
1815 }
1816 if (sta_add) {
1817 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1818 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1819 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1820 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1821 return sta_found;
1822 }
1823 }
1824 }
1825 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301826 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001827 "STA ID %d does not exist, cannot delete", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001828 return sta_found;
1829 }
1830 if (!sta_add) {
1831 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1832 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1833 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1834 hdd_ipa->assoc_stas_map[idx].is_reserved =
1835 false;
1836 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1837 return sta_found;
1838 }
1839 }
1840 }
1841 return sta_found;
1842}
1843
1844/**
1845 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1846 * @hdd_ipa: Global HDD IPA context
1847 *
1848 * Return: 0 on success, negative errno if error
1849 */
1850static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1851{
1852 int result;
Leo Changfdb45c32016-10-28 11:09:23 -07001853 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001854 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855
Yun Parkb4f591d2017-03-29 15:51:01 -07001856 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001857 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301858 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001859 "Enable PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001860 return result;
1861 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862
Leo Change3e49442015-10-26 20:07:13 -07001863 hdd_ipa->ipa_pipes_down = false;
Yun Parkb4f591d2017-03-29 15:51:01 -07001864
1865 cdp_ipa_enable_autonomy(soc, (struct cdp_pdev *)pdev);
1866
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001867 return 0;
1868}
1869
1870/**
1871 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1872 * @hdd_ipa: Global HDD IPA context
1873 *
1874 * Return: 0 on success, negative errno if error
1875 */
1876static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1877{
Yun Parkb4f591d2017-03-29 15:51:01 -07001878 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1879 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880 int result;
1881
Leo Change3e49442015-10-26 20:07:13 -07001882 hdd_ipa->ipa_pipes_down = true;
1883
Yun Parkb4f591d2017-03-29 15:51:01 -07001884 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001885
Yun Parkb4f591d2017-03-29 15:51:01 -07001886 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001887 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301888 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001889 "Disable WDI PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890 return result;
1891 }
1892
1893 return 0;
1894}
1895
1896/**
1897 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1898 * @hdd_ipa: Global HDD IPA context
1899 *
1900 * Return: 0 on success, negative errno if error
1901 */
1902static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1903{
Yun Parkb4f591d2017-03-29 15:51:01 -07001904 hdd_context_t *hdd_ctx = hdd_ipa->hdd_ctx;
1905
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906 hdd_ipa->activated_fw_pipe = 0;
1907 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001908
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001909 /* If RM feature enabled
1910 * Request PROD Resource first
Yun Parkb4f591d2017-03-29 15:51:01 -07001911 * PROD resource may return sync or async manners */
1912 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001913 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1914 /* RM PROD request sync return
1915 * enable pipe immediately
1916 */
1917 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301918 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001919 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001920 hdd_ipa->resource_loading = false;
1921 return -EBUSY;
1922 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001923 }
1924 } else {
1925 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001926 * Just enabled all the PIPEs
1927 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001928 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301929 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001930 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001931 hdd_ipa->resource_loading = false;
1932 return -EBUSY;
1933 }
1934 hdd_ipa->resource_loading = false;
1935 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001936
Srinivas Girigowda97852372017-03-06 16:52:59 -08001937 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07001938 "IPA WDI Pipes activated successfully");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001939 return 0;
1940}
1941
1942/**
1943 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1944 * @hdd_ipa: Global HDD IPA context
1945 *
1946 * Return: None
1947 */
1948static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1949{
Leo Changfdb45c32016-10-28 11:09:23 -07001950 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001951 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001952
Yun Parkb4f591d2017-03-29 15:51:01 -07001953 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08001954 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
1955 QDF_ASSERT(0);
1956 return;
1957 }
1958
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001959 hdd_ipa->resource_unloading = true;
Yun Parkb4f591d2017-03-29 15:51:01 -07001960 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
1961 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
1962 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
1963 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001964}
1965
1966/**
1967 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1968 * @context: User context registered with TL (the IPA Global context is
1969 * registered
1970 * @rxpkt: Packet containing the notification
1971 * @staid: ID of the station associated with the packet
1972 *
1973 * Return: None
1974 */
1975static void
1976hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1977{
1978 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301979 QDF_STATUS status = QDF_STATUS_SUCCESS;
Yun Parkb4f591d2017-03-29 15:51:01 -07001980 hdd_context_t *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001981
1982 /*
1983 * When SSR is going on or driver is unloading, just return.
1984 */
Yun Parkb4f591d2017-03-29 15:51:01 -07001985 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301986 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001987 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001988
Yun Parkb4f591d2017-03-29 15:51:01 -07001989 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001990 return;
1991
Srinivas Girigowda97852372017-03-06 16:52:59 -08001992 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001993 __func__, event);
1994
1995 switch (event) {
1996 case IPA_RM_RESOURCE_GRANTED:
1997 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301998 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999 if ((false == hdd_ipa->resource_unloading) &&
2000 (!hdd_ipa->activated_fw_pipe)) {
2001 hdd_ipa_uc_enable_pipes(hdd_ipa);
2002 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302003 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002004 break;
2005
2006 case IPA_RM_RESOURCE_RELEASED:
2007 /* Differed RM Released */
2008 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009 break;
2010
2011 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302012 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002013 "%s, invalid event code %d", __func__, event);
2014 break;
2015 }
2016}
2017
2018/**
2019 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2020 * @hdd_ipa: Global HDD IPA context
2021 * @event: IPA resource manager event to be deferred
2022 *
2023 * This function is called when a resource manager event is received
2024 * from firmware in interrupt context. This function will defer the
2025 * handling to the OL RX thread
2026 *
2027 * Return: None
2028 */
2029static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2030{
2031 enum ipa_rm_event event;
2032 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2033 struct uc_rm_work_struct, work);
2034 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2035 struct hdd_ipa_priv, uc_rm_work);
2036
2037 cds_ssr_protect(__func__);
2038 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002039 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002040 "%s, posted event %d", __func__, event);
2041
2042 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2043 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044}
2045
2046/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002047 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002048 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002049 *
2050 * Will handle IPA UC image loaded indication comes from IPA kernel
2051 *
2052 * Return: None
2053 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002054static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002055{
Yun Parkb4f591d2017-03-29 15:51:01 -07002056 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2057 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
2058 hdd_context_t *hdd_ctx;
2059 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002060
2061 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
Yun Parkb4f591d2017-03-29 15:51:01 -07002062 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002063 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002064 __func__);
2065 return;
2066 }
2067
Yun Parkb4f591d2017-03-29 15:51:01 -07002068 hdd_ctx = hdd_ipa->hdd_ctx;
2069 hdd_ipa->uc_loaded = true;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002070
Yun Parkb4f591d2017-03-29 15:51:01 -07002071 /* Connect pipe */
2072 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2073 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2074 hdd_ipa_wdi_meter_notifier_cb,
2075 hdd_ctx->config->IpaDescSize,
2076 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2077 &hdd_ipa->tx_pipe_handle,
2078 &hdd_ipa->rx_pipe_handle);
2079 if (status) {
2080 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2081 "Failure to setup IPA pipes (status=%d)",
2082 status);
2083 return;
2084 }
2085
2086 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002087
2088 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002089 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002090 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002091 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002092 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002093 }
2094}
2095
2096/**
Yun Park637d6482016-10-05 10:51:33 -07002097 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2098 * @hdd_ctx: Global HDD context
2099 * @op_msg: operation message received from firmware
2100 *
2101 * Return: QDF_STATUS enumeration
2102 */
2103#ifdef FEATURE_METERING
2104static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2105 struct op_msg_type *op_msg)
2106{
2107 struct op_msg_type *msg = op_msg;
2108 struct ipa_uc_sharing_stats *uc_sharing_stats;
2109 struct ipa_uc_quota_rsp *uc_quota_rsp;
2110 struct ipa_uc_quota_ind *uc_quota_ind;
2111 struct hdd_ipa_priv *hdd_ipa;
2112 hdd_adapter_t *adapter;
2113
2114 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2115
2116 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2117 /* fill-up ipa_uc_sharing_stats structure from FW */
2118 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2119 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2120
2121 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2122 sizeof(struct ipa_uc_sharing_stats));
2123
2124 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2125
2126 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2127 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2128 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2129 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2130 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2131 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2132 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2133 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2134 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2135 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2136 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2137 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2138 /* received set quota response */
2139 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2140 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2141
2142 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2143 sizeof(struct ipa_uc_quota_rsp));
2144
2145 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2146 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2147 "%s: success=%d, quota_bytes=%llu",
2148 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2149 hdd_ipa->ipa_quota_rsp.success,
2150 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2151 hdd_ipa->ipa_quota_rsp.quota_lo);
2152 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2153 /* hit quota limit */
2154 uc_quota_ind = (struct ipa_uc_quota_ind *)
2155 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2156
2157 hdd_ipa->ipa_quota_ind.quota_bytes =
2158 uc_quota_ind->quota_bytes;
2159
2160 /* send quota exceeded indication to IPA */
2161 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2162 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2163 hdd_ipa->ipa_quota_ind.quota_bytes);
2164
2165 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2166 if (adapter)
2167 ipa_broadcast_wdi_quota_reach_ind(
2168 adapter->dev->ifindex,
2169 uc_quota_ind->quota_bytes);
2170 else
2171 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2172 "Failed quota_reach_ind: NULL adapter");
2173 } else {
2174 return QDF_STATUS_E_INVAL;
2175 }
2176
2177 return QDF_STATUS_SUCCESS;
2178}
2179#else
2180static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2181 struct op_msg_type *op_msg)
2182{
2183 return QDF_STATUS_E_INVAL;
2184}
2185#endif
2186
2187/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002188 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2189 * @op_msg: operation message received from firmware
2190 * @usr_ctxt: user context registered with TL (we register the HDD Global
2191 * context)
2192 *
2193 * Return: None
2194 */
2195static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2196{
2197 struct op_msg_type *msg = op_msg;
2198 struct ipa_uc_fw_stats *uc_fw_stat;
2199 struct IpaHwStatsWDIInfoData_t ipa_stat;
2200 struct hdd_ipa_priv *hdd_ipa;
2201 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302202 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002203
2204 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302205 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002206 return;
2207 }
2208
2209 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302210 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002211 "%s, INVALID OPCODE %d", __func__, msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002212 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002213 return;
2214 }
2215
2216 hdd_ctx = (hdd_context_t *) usr_ctxt;
2217
2218 /*
2219 * When SSR is going on or driver is unloading, just return.
2220 */
2221 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302222 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302223 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002224 return;
2225 }
2226
2227 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2228
Govind Singhb6a89772016-08-12 11:23:35 +05302229 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002230 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002231
2232 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2233 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302234 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002235 hdd_ipa->activated_fw_pipe++;
2236 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2237 hdd_ipa->resource_loading = false;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002238 if (hdd_ipa->wdi_enabled == false) {
2239 hdd_ipa->wdi_enabled = true;
2240 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2241 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2242 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002243 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002244 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002245 if (hdd_ipa->pending_cons_req)
2246 ipa_rm_notify_completion(
2247 IPA_RM_RESOURCE_GRANTED,
2248 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002249 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002250 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302251 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002252 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002253 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302254 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002255 hdd_ipa->activated_fw_pipe--;
2256 if (!hdd_ipa->activated_fw_pipe) {
2257 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002258 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2259 ipa_rm_release_resource(
2260 IPA_RM_RESOURCE_WLAN_PROD);
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08002261 /*
2262 * Sync return success from IPA
2263 * Enable/resume all the PIPEs
2264 */
Yun Park5b635012015-12-02 15:05:01 -08002265 hdd_ipa->resource_unloading = false;
2266 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2267 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002268 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302269 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002270 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002271 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002272 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302273 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002274 "==== IPA_UC WLAN_HOST RX ====\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002275 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002276 "NUM TX FWD OK : %llu\n"
2277 "NUM TX FWD ERR : %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002278 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002279 hdd_ipa->stats.num_tx_fwd_ok,
2280 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302281 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002282 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2283 "SAP NUM STAs: %d\n"
2284 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002285 "CONCURRENT MODE: %s\n"
2286 "TX PIPE HDL: 0x%x\n"
2287 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002288 "RSC LOADING : %d\n"
2289 "RSC UNLOADING : %d\n"
2290 "PNDNG CNS RQT : %d",
2291 hdd_ipa->sap_num_connected_sta,
2292 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002293 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002294 hdd_ipa->tx_pipe_handle,
2295 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002296 hdd_ipa->resource_loading,
2297 hdd_ipa->resource_unloading,
2298 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002299
2300 /* STATs from FW */
2301 uc_fw_stat = (struct ipa_uc_fw_stats *)
2302 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302303 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002304 "==== IPA_UC WLAN_FW TX ====\n"
2305 "COMP RING BASE: 0x%x\n"
2306 "COMP RING SIZE: %d\n"
2307 "COMP RING DBELL : 0x%x\n"
2308 "COMP RING DBELL IND VAL : %d\n"
2309 "COMP RING DBELL CACHED VAL : %d\n"
2310 "COMP RING DBELL CACHED VAL : %d\n"
2311 "PKTS ENQ : %d\n"
2312 "PKTS COMP : %d\n"
2313 "IS SUSPEND : %d\n"
2314 "RSVD : 0x%x",
2315 uc_fw_stat->tx_comp_ring_base,
2316 uc_fw_stat->tx_comp_ring_size,
2317 uc_fw_stat->tx_comp_ring_dbell_addr,
2318 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2319 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2320 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2321 uc_fw_stat->tx_pkts_enqueued,
2322 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002323 uc_fw_stat->tx_is_suspend,
2324 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302325 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002326 "==== IPA_UC WLAN_FW RX ====\n"
2327 "IND RING BASE: 0x%x\n"
2328 "IND RING SIZE: %d\n"
2329 "IND RING DBELL : 0x%x\n"
2330 "IND RING DBELL IND VAL : %d\n"
2331 "IND RING DBELL CACHED VAL : %d\n"
2332 "RDY IND ADDR : 0x%x\n"
2333 "RDY IND CACHE VAL : %d\n"
2334 "RFIL IND : %d\n"
2335 "NUM PKT INDICAT : %d\n"
2336 "BUF REFIL : %d\n"
2337 "NUM DROP NO SPC : %d\n"
2338 "NUM DROP NO BUF : %d\n"
2339 "IS SUSPND : %d\n"
2340 "RSVD : 0x%x\n",
2341 uc_fw_stat->rx_ind_ring_base,
2342 uc_fw_stat->rx_ind_ring_size,
2343 uc_fw_stat->rx_ind_ring_dbell_addr,
2344 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2345 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2346 uc_fw_stat->rx_ind_ring_rdidx_addr,
2347 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2348 uc_fw_stat->rx_refill_idx,
2349 uc_fw_stat->rx_num_pkts_indicated,
2350 uc_fw_stat->rx_buf_refilled,
2351 uc_fw_stat->rx_num_ind_drop_no_space,
2352 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002353 uc_fw_stat->rx_is_suspend,
2354 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002355 /* STATs from IPA */
2356 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302357 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002358 "==== IPA_UC IPA TX ====\n"
2359 "NUM PROCD : %d\n"
2360 "CE DBELL : 0x%x\n"
2361 "NUM DBELL FIRED : %d\n"
2362 "COMP RNG FULL : %d\n"
2363 "COMP RNG EMPT : %d\n"
2364 "COMP RNG USE HGH : %d\n"
2365 "COMP RNG USE LOW : %d\n"
2366 "BAM FIFO FULL : %d\n"
2367 "BAM FIFO EMPT : %d\n"
2368 "BAM FIFO USE HGH : %d\n"
2369 "BAM FIFO USE LOW : %d\n"
2370 "NUM DBELL : %d\n"
2371 "NUM UNEXP DBELL : %d\n"
2372 "NUM BAM INT HDL : 0x%x\n"
2373 "NUM BAM INT NON-RUN : 0x%x\n"
2374 "NUM QMB INT HDL : 0x%x",
2375 ipa_stat.tx_ch_stats.num_pkts_processed,
2376 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2377 ipa_stat.tx_ch_stats.num_db_fired,
2378 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2379 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2380 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2381 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2382 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2383 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2384 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2385 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2386 ipa_stat.tx_ch_stats.num_db,
2387 ipa_stat.tx_ch_stats.num_unexpected_db,
2388 ipa_stat.tx_ch_stats.num_bam_int_handled,
2389 ipa_stat.tx_ch_stats.
2390 num_bam_int_in_non_runnning_state,
2391 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2392
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302393 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002394 "==== IPA_UC IPA RX ====\n"
2395 "MAX OST PKT : %d\n"
2396 "NUM PKT PRCSD : %d\n"
2397 "RNG RP : 0x%x\n"
2398 "COMP RNG FULL : %d\n"
2399 "COMP RNG EMPT : %d\n"
2400 "COMP RNG USE HGH : %d\n"
2401 "COMP RNG USE LOW : %d\n"
2402 "BAM FIFO FULL : %d\n"
2403 "BAM FIFO EMPT : %d\n"
2404 "BAM FIFO USE HGH : %d\n"
2405 "BAM FIFO USE LOW : %d\n"
2406 "NUM DB : %d\n"
2407 "NUM UNEXP DB : %d\n"
2408 "NUM BAM INT HNDL : 0x%x\n",
2409 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2410 ipa_stat.rx_ch_stats.num_pkts_processed,
2411 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2412 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2413 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2414 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2415 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2416 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2417 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2418 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2419 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2420 ipa_stat.rx_ch_stats.num_db,
2421 ipa_stat.rx_ch_stats.num_unexpected_db,
2422 ipa_stat.rx_ch_stats.num_bam_int_handled);
2423 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2424 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2425 /* STATs from FW */
2426 uc_fw_stat = (struct ipa_uc_fw_stats *)
2427 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302428 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002429 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2430 uc_fw_stat->tx_pkts_completed,
2431 hdd_ipa->ipa_p_tx_packets);
2432 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2433 (uc_fw_stat->rx_num_ind_drop_no_space +
2434 uc_fw_stat->rx_num_ind_drop_no_buf +
2435 uc_fw_stat->rx_num_pkts_indicated),
2436 hdd_ipa->ipa_p_rx_packets);
2437
2438 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2439 hdd_ipa->ipa_p_rx_packets =
2440 (uc_fw_stat->rx_num_ind_drop_no_space +
2441 uc_fw_stat->rx_num_ind_drop_no_buf +
2442 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302443 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002444 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2445 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2446 hdd_ipa_uc_loaded_handler(hdd_ipa);
2447 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002448 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2449 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2450 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002451 }
Yun Park8957d802017-01-25 12:27:29 -08002452
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302453 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002454}
2455
2456
2457/**
2458 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2459 * @adapter: device adapter instance
2460 * @offload_type: MCC or SCC
2461 * @enable: TX offload enable or disable
2462 *
2463 * Return: none
2464 */
2465static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002466 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002467{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002468 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002469 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002470 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002471 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002472
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002473 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002474 return;
2475
Yun Park8292dcb2016-10-07 16:46:06 -07002476 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002477 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002478
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002479 if (!iface_context) {
2480 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2481 "Interface context is NULL");
2482 return;
2483 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002484 if (session_id >= CSR_ROAM_SESSION_MAX) {
2485 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2486 "invalid session id: %d", session_id);
2487 return;
2488 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002489 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002490 /* IPA offload status is already set as desired */
2491 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002492 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002493 "IPA offload status is already set",
2494 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002495 return;
2496 }
2497
Yun Park4540e862016-11-10 16:30:06 -08002498 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2499 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2500 "invalid session id: %d, offload_type=%d, enable=%d",
2501 adapter->sessionId, offload_type, enable);
2502 return;
2503 }
2504
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302505 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002506 sizeof(ipa_offload_enable_disable));
2507 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002508 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002509 ipa_offload_enable_disable.enable = enable;
2510
Srinivas Girigowda97852372017-03-06 16:52:59 -08002511 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002512 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002513 ipa_offload_enable_disable.offload_type,
2514 ipa_offload_enable_disable.vdev_id,
2515 ipa_offload_enable_disable.enable);
2516
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302517 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002518 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2519 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302520 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002521 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
2522 "Failure to enable IPA offload",
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002523 ipa_offload_enable_disable.offload_type,
2524 ipa_offload_enable_disable.vdev_id,
2525 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002526 } else {
2527 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002528 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002529 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002530 }
2531}
2532
2533/**
2534 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2535 * @work: uC OP work
2536 *
2537 * Return: None
2538 */
2539static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2540{
2541 struct op_msg_type *msg;
2542 struct uc_op_work_struct *uc_op_work = container_of(work,
2543 struct uc_op_work_struct, work);
2544 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2545
2546 cds_ssr_protect(__func__);
2547
2548 msg = uc_op_work->msg;
2549 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002550 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002551 "%s, posted msg %d", __func__, msg->op_code);
2552
2553 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2554
2555 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002556}
2557
2558/**
2559 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2560 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2561 * @op_msg: operation message received from firmware
2562 * @hdd_ctx: Global HDD context
2563 *
2564 * Return: None
2565 */
2566static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2567{
2568 struct hdd_ipa_priv *hdd_ipa;
2569 struct op_msg_type *msg;
2570 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302571 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002572
2573 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302574 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002575 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002576
2577 msg = (struct op_msg_type *)op_msg;
2578 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
2579
2580 if (unlikely(!hdd_ipa))
2581 goto end;
2582
2583 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002584 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2585 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002586 goto end;
2587 }
2588
2589 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2590 if (uc_op_work->msg)
2591 /* When the same uC OPCODE is already pended, just return */
2592 goto end;
2593
2594 uc_op_work->msg = msg;
2595 schedule_work(&uc_op_work->work);
2596 return;
2597
2598end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302599 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002600}
2601
2602/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002603 * hdd_ipa_init_uc_op_work - init ipa uc op work
2604 * @work: struct work_struct
2605 * @work_handler: work_handler
2606 *
2607 * Return: none
2608 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002609static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002610 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002611{
2612 INIT_WORK(work, work_handler);
2613}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002614
Yun Park637d6482016-10-05 10:51:33 -07002615#ifdef FEATURE_METERING
2616/**
2617 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2618 * IPA calls to get WLAN stats or set quota limit.
2619 * @priv: pointer to private data registered with IPA (we register a
2620 *» pointer to the global IPA context)
2621 * @evt: the IPA event which triggered the callback
2622 * @data: data associated with the event
2623 *
2624 * Return: None
2625 */
2626static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2627 void *data)
2628{
2629 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2630 hdd_adapter_t *adapter = NULL;
2631 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2632 struct ipa_set_wifi_quota *ipa_set_quota;
2633 int ret = 0;
2634
2635 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2636 return;
2637
2638 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2639
2640 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2641
2642 switch (evt) {
2643 case IPA_GET_WDI_SAP_STATS:
2644 /* fill-up ipa_get_wdi_sap_stats structure after getting
2645 ipa_uc_fw_stats from FW */
2646 wdi_sap_stats = data;
2647
2648 if (!adapter) {
2649 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2650 "IPA uC share stats failed - no adapter");
2651 wdi_sap_stats->stats_valid = 0;
2652 return;
2653 }
2654
2655 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
2656 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
2657 hdd_ipa_uc_sharing_stats_request(adapter,
2658 wdi_sap_stats->reset_stats);
2659 ret = wait_for_completion_timeout(
2660 &hdd_ipa->ipa_uc_sharing_stats_comp,
2661 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2662 if (!ret) {
2663 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2664 "IPA uC share stats request timed out");
2665 wdi_sap_stats->stats_valid = 0;
2666 } else {
2667 wdi_sap_stats->stats_valid = 1;
2668
2669 wdi_sap_stats->ipv4_rx_packets =
2670 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2671 wdi_sap_stats->ipv4_rx_bytes =
2672 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2673 wdi_sap_stats->ipv6_rx_packets =
2674 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2675 wdi_sap_stats->ipv6_rx_bytes =
2676 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2677 wdi_sap_stats->ipv4_tx_packets =
2678 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2679 wdi_sap_stats->ipv4_tx_bytes =
2680 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2681 wdi_sap_stats->ipv6_tx_packets =
2682 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2683 wdi_sap_stats->ipv6_tx_bytes =
2684 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2685 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2686 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2687 "IPA_GET_WDI_SAP_STATS",
2688 wdi_sap_stats->stats_valid,
2689 wdi_sap_stats->ipv4_rx_packets,
2690 wdi_sap_stats->ipv4_rx_bytes,
2691 wdi_sap_stats->ipv6_rx_packets,
2692 wdi_sap_stats->ipv6_rx_bytes,
2693 wdi_sap_stats->ipv4_tx_packets,
2694 wdi_sap_stats->ipv4_tx_bytes,
2695 wdi_sap_stats->ipv6_tx_packets,
2696 wdi_sap_stats->ipv6_tx_bytes);
2697 }
2698 break;
2699 case IPA_SET_WIFI_QUOTA:
2700 /* get ipa_set_wifi_quota structure from IPA and pass to FW
2701 through quota_exceeded field in ipa_uc_fw_stats */
2702 ipa_set_quota = data;
2703
2704 if (!adapter) {
2705 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2706 "IPA uC set quota failed - no adapter");
2707 ipa_set_quota->set_valid = 0;
2708 return;
2709 }
2710
2711 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2712 ipa_set_quota->quota_bytes);
2713
2714 ret = wait_for_completion_timeout(
2715 &hdd_ipa->ipa_uc_set_quota_comp,
2716 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2717 if (!ret) {
2718 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2719 "IPA uC set quota request timed out");
2720 ipa_set_quota->set_valid = 0;
2721 } else {
2722 ipa_set_quota->quota_bytes =
2723 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2724 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2725 ipa_set_quota->set_valid =
2726 hdd_ipa->ipa_quota_rsp.success;
2727 }
2728
2729 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2730 ipa_set_quota->quota_bytes,
2731 ipa_set_quota->set_valid);
2732 break;
2733 }
2734}
2735
2736/**
2737 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2738 * IPA calls to get WLAN stats or set quota limit.
2739 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07002740 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07002741 * @evt: the IPA event which triggered the callback
2742 * @data: data associated with the event
2743 *
2744 * Return: None
2745 */
2746static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2747 void *data)
2748{
2749 cds_ssr_protect(__func__);
2750 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2751 cds_ssr_unprotect(__func__);
2752}
2753
Yun Parkb4f591d2017-03-29 15:51:01 -07002754static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002755{
Yun Park637d6482016-10-05 10:51:33 -07002756 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2757 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2758}
2759#else
Yun Parkb4f591d2017-03-29 15:51:01 -07002760static void hdd_ipa_wdi_meter_notifier_cb(void)
2761{
2762}
2763
2764static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002765{
2766}
2767#endif
2768
Rajeev Kumar217f2172016-01-06 18:11:55 -08002769/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002770 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2771 * @hdd_ctx: Global HDD context
2772 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002773 * This function is called to update IPA pipe configuration with resources
2774 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2775 * (cds_enable)
2776 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302777 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002778 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002779QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002780{
Yun Parkb4f591d2017-03-29 15:51:01 -07002781 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002782 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002783 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07002784 uint8_t i;
2785 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002787 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2788 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002789
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002790 ENTER();
2791 /* Do only IPA Pipe specific configuration here. All one time
2792 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2793 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2794 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002795 if (!pdev || !soc) {
2796 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07002797 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002798 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002799 }
Yun Parkb4f591d2017-03-29 15:51:01 -07002800 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002801 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2802 "IPA UC resource alloc fail");
2803 return QDF_STATUS_E_FAILURE;
2804 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002805
Yun Parkb4f591d2017-03-29 15:51:01 -07002806 if (true == hdd_ipa->uc_loaded) {
2807 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2808 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2809 hdd_ipa_wdi_meter_notifier_cb,
2810 hdd_ctx->config->IpaDescSize,
2811 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2812 &hdd_ipa->tx_pipe_handle,
2813 &hdd_ipa->rx_pipe_handle);
2814 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08002815 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002816 "Failure to setup IPA pipes (status=%d)",
2817 status);
2818 return QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002819 }
Yun Park637d6482016-10-05 10:51:33 -07002820
Yun Parkb4f591d2017-03-29 15:51:01 -07002821 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
2822 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002823 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824
Yun Parkb4f591d2017-03-29 15:51:01 -07002825 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08002826 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2827
Yun Parkb4f591d2017-03-29 15:51:01 -07002828 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
2829 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
2830 hdd_ipa_uc_fw_op_event_handler);
2831 hdd_ipa->uc_op_work[i].msg = NULL;
2832 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002833
Yun Parkbaa62862017-01-18 13:43:34 -08002834fail_return:
2835 EXIT();
Yun Parkb4f591d2017-03-29 15:51:01 -07002836 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002837}
2838
Leo Change3e49442015-10-26 20:07:13 -07002839/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302840 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
2841 * @hdd_ctx: Global HDD context
2842 *
2843 * Return: 0 on success, negativer errno on error
2844 */
2845int hdd_ipa_uc_ol_deinit(hdd_context_t *hdd_ctx)
2846{
2847 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2848 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07002849 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302850
2851 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2852 return ret;
2853
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05302854 if (!hdd_ipa->ipa_pipes_down)
2855 hdd_ipa_uc_disable_pipes(hdd_ipa);
2856
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302857 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002858 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
2859 hdd_ipa->tx_pipe_handle,
2860 hdd_ipa->rx_pipe_handle);
2861 if (status) {
2862 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2863 "Failure to cleanup IPA pipes (status=%d)",
2864 status);
2865 return -EFAULT;
2866 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302867 }
2868
2869 return ret;
2870}
2871
2872/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002873 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002874 * @hdd_ctx: hdd main context
2875 *
2876 * Force shutdown IPA pipe
2877 * Independent of FW pipe status, IPA pipe shutdonw progress
2878 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2879 * independent from FW pipe status
2880 *
2881 * Return: NONE
2882 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002883static void __hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002884{
2885 struct hdd_ipa_priv *hdd_ipa;
2886
2887 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2888 return;
2889
2890 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2891 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302892 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002893 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07002894 hdd_ipa_uc_disable_pipes(hdd_ipa);
2895 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002896 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07002897 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07002898 }
Leo Change3e49442015-10-26 20:07:13 -07002899}
2900
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002901/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002902 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2903 * __hdd_ipa_uc_force_pipe_shutdown
2904 * @hdd_ctx: hdd main context
2905 *
2906 * Force shutdown IPA pipe
2907 * Independent of FW pipe status, IPA pipe shutdonw progress
2908 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2909 * independent from FW pipe status
2910 *
2911 * Return: NONE
2912 */
2913void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
2914{
2915 cds_ssr_protect(__func__);
2916 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2917 cds_ssr_unprotect(__func__);
2918}
2919
2920/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302921 * hdd_ipa_msg_free_fn() - Free an IPA message
2922 * @buff: pointer to the IPA message
2923 * @len: length of the IPA message
2924 * @type: type of IPA message
2925 *
2926 * Return: None
2927 */
2928static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2929{
Srinivas Girigowda97852372017-03-06 16:52:59 -08002930 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05302931 ghdd_ipa->stats.num_free_msg++;
2932 qdf_mem_free(buff);
2933}
2934
Govind Singh9c58eba2016-09-02 16:23:06 +05302935/**
jge62037862016-12-09 10:44:33 +08002936 * hdd_ipa_uc_send_evt() - send event to ipa
2937 * @hdd_ctx: pointer to hdd context
2938 * @type: event type
2939 * @mac_addr: pointer to mac address
2940 *
2941 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05302942 *
2943 * Return: 0 - Success
2944 */
jge62037862016-12-09 10:44:33 +08002945static int hdd_ipa_uc_send_evt(hdd_adapter_t *adapter,
2946 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05302947{
jge62037862016-12-09 10:44:33 +08002948 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05302949 struct ipa_msg_meta meta;
2950 struct ipa_wlan_msg *msg;
2951 int ret = 0;
jge62037862016-12-09 10:44:33 +08002952
2953 meta.msg_len = sizeof(struct ipa_wlan_msg);
2954 msg = qdf_mem_malloc(meta.msg_len);
2955 if (msg == NULL) {
2956 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2957 "msg allocation failed");
2958 return -ENOMEM;
2959 }
2960
2961 meta.msg_type = type;
2962 strlcpy(msg->name, adapter->dev->name,
2963 IPA_RESOURCE_NAME_MAX);
2964 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Srinivas Girigowda97852372017-03-06 16:52:59 -08002965 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08002966 msg->name, meta.msg_type);
2967 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
2968 if (ret) {
2969 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2970 "%s: Evt: %d fail:%d",
2971 msg->name, meta.msg_type, ret);
2972 qdf_mem_free(msg);
2973 return ret;
2974 }
2975
2976 hdd_ipa->stats.num_send_msg++;
2977
2978 return ret;
2979}
2980
2981/**
2982 * hdd_ipa_uc_disconnect_client() - send client disconnect event
2983 * @hdd_ctx: pointer to hdd adapter
2984 *
2985 * Send disconnect client event to IPA driver during SSR
2986 *
2987 * Return: 0 - Success
2988 */
2989static int hdd_ipa_uc_disconnect_client(hdd_adapter_t *adapter)
2990{
2991 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2992 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05302993 int i;
2994
2995 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
2996 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
2997 continue;
2998 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08002999 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3000 hdd_ipa->sap_num_connected_sta) {
3001 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3002 adapter->aStaInfo[i].macAddrSTA.bytes);
3003 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303004 }
3005 }
3006
3007 return ret;
3008}
3009
3010/**
jge62037862016-12-09 10:44:33 +08003011 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3012 * @hdd_ctx: pointer to hdd adapter
3013 *
3014 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303015 *
3016 * Return: 0 - Success
3017 */
jge62037862016-12-09 10:44:33 +08003018
3019static int hdd_ipa_uc_disconnect_ap(hdd_adapter_t *adapter)
3020{
3021 int ret = 0;
3022
3023 if (adapter->ipa_context)
3024 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3025 adapter->dev->dev_addr);
3026
3027 return ret;
3028}
3029
jge62037862016-12-09 10:44:33 +08003030/**
3031 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3032 * @hdd_ctx: pointer to hdd adapter
3033 *
3034 * Send disconnect sta event to IPA driver during SSR
3035 *
3036 * Return: 0 - Success
3037 */
3038static int hdd_ipa_uc_disconnect_sta(hdd_adapter_t *adapter)
3039{
3040 hdd_station_ctx_t *pHddStaCtx;
3041 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3042 int ret = 0;
3043
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003044 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003045 hdd_ipa->sta_connected) {
3046 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3047 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003048 pHddStaCtx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003049 }
3050
3051 return ret;
3052}
jge62037862016-12-09 10:44:33 +08003053
3054/**
3055 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3056 * @hdd_ctx: pointer to hdd context
3057 *
3058 * Send disconnect event to IPA driver during SSR
3059 *
3060 * Return: 0 - Success
3061 */
3062static int hdd_ipa_uc_disconnect(hdd_context_t *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303063{
3064 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3065 QDF_STATUS status;
3066 hdd_adapter_t *adapter;
3067 int ret = 0;
3068
Govind Singh9c58eba2016-09-02 16:23:06 +05303069 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3070 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3071 adapter = adapter_node->pAdapter;
jge62037862016-12-09 10:44:33 +08003072 if (adapter->device_mode == QDF_SAP_MODE) {
3073 hdd_ipa_uc_disconnect_client(adapter);
3074 hdd_ipa_uc_disconnect_ap(adapter);
3075 } else if (adapter->device_mode == QDF_STA_MODE) {
3076 hdd_ipa_uc_disconnect_sta(adapter);
3077 }
3078
Govind Singh9c58eba2016-09-02 16:23:06 +05303079 status = hdd_get_next_adapter(
3080 hdd_ctx, adapter_node, &next);
3081 adapter_node = next;
3082 }
3083
3084 return ret;
3085}
3086
3087/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003088 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089 *
3090 * Deinit basic IPA UC host side to be in sync reloaded FW during
3091 * SSR
3092 *
3093 * Return: 0 - Success
3094 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003095static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003096{
3097 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3098 int idx;
3099 struct hdd_ipa_iface_context *iface_context;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303100 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003101
Arun Khandavallicc544b32017-01-30 19:52:16 +05303102 if (!hdd_ipa)
3103 return 0;
3104
3105 hdd_ctx = hdd_ipa->hdd_ctx;
3106 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003107 return 0;
3108
jge62037862016-12-09 10:44:33 +08003109 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303110 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003111
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003112 /* Clean up HDD IPA interfaces */
3113 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3114 (idx < HDD_IPA_MAX_IFACE); idx++) {
3115 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003116 if (iface_context->adapter && iface_context->adapter->magic ==
3117 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118 hdd_ipa_cleanup_iface(iface_context);
3119 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003120 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121 /* After SSR, wlan driver reloads FW again. But we need to protect
3122 * IPA submodule during SSR transient state. So deinit basic IPA
3123 * UC host side to be in sync with reloaded FW during SSR
3124 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003125
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303126 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003127 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3128 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3129 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3130 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303131 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132
Guolei Bianca144d82016-11-10 11:07:42 +08003133 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3134 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3135
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003136 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3137 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3138 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3139 hdd_ipa->uc_op_work[idx].msg = NULL;
3140 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003141 return 0;
3142}
3143
3144/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003145 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3146 *
3147 * Deinit basic IPA UC host side to be in sync reloaded FW during
3148 * SSR
3149 *
3150 * Return: 0 - Success
3151 */
3152int hdd_ipa_uc_ssr_deinit(void)
3153{
3154 int ret;
3155
3156 cds_ssr_protect(__func__);
3157 ret = __hdd_ipa_uc_ssr_deinit();
3158 cds_ssr_unprotect(__func__);
3159
3160 return ret;
3161}
3162
3163/**
3164 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003165 *
3166 * Init basic IPA UC host side to be in sync with reloaded FW after
3167 * SSR to resume IPA UC operations
3168 *
3169 * Return: 0 - Success
3170 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303171static int __hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003172{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003173
Arun Khandavallicc544b32017-01-30 19:52:16 +05303174 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3175 int i;
3176 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303177
3178 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3179 return 0;
3180
Arun Khandavallicc544b32017-01-30 19:52:16 +05303181 /* Create the interface context */
3182 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3183 iface_context = &hdd_ipa->iface_context[i];
3184 iface_context->hdd_ipa = hdd_ipa;
3185 iface_context->cons_client =
3186 hdd_ipa_adapter_2_client[i].cons_client;
3187 iface_context->prod_client =
3188 hdd_ipa_adapter_2_client[i].prod_client;
3189 iface_context->iface_id = i;
3190 iface_context->adapter = NULL;
3191 }
3192 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3193 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3194 hdd_ipa->vdev_offload_enabled[i] = false;
3195 }
3196
3197 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3198 hdd_ipa->resource_loading = false;
3199 hdd_ipa->resource_unloading = false;
3200 hdd_ipa->sta_connected = 0;
3201 hdd_ipa->ipa_pipes_down = true;
3202 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303203 }
3204
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003205 return 0;
3206}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003207
3208/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003209 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3210 *
3211 * Init basic IPA UC host side to be in sync with reloaded FW after
3212 * SSR to resume IPA UC operations
3213 *
3214 * Return: 0 - Success
3215 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303216int hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003217{
3218 int ret;
3219
3220 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303221 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003222 cds_ssr_unprotect(__func__);
3223
3224 return ret;
3225}
3226
3227/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003228 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3229 * @work: scheduled work
3230 *
3231 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3232 * not want to immediately release the wake lock since the system
3233 * would then potentially try to suspend when there is a healthy data
3234 * rate. Deferred work is scheduled and this function handles the
3235 * work. When this function is called, if the IPA resource is still
3236 * released then we release the wake lock.
3237 *
3238 * Return: None
3239 */
3240static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3241{
3242 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3243 struct hdd_ipa_priv,
3244 wake_lock_work);
3245
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303246 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247
3248 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3249 goto end;
3250
3251 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303252 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253 WIFI_POWER_EVENT_WAKELOCK_IPA);
3254
3255end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303256 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003257}
3258
3259/**
3260 * hdd_ipa_rm_request() - Request resource from IPA
3261 * @hdd_ipa: Global HDD IPA context
3262 *
3263 * Return: 0 on success, negative errno on error
3264 */
3265static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3266{
3267 int ret = 0;
3268
3269 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3270 return 0;
3271
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303272 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003273
3274 switch (hdd_ipa->rm_state) {
3275 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303276 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003277 return 0;
3278 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303279 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003280 return -EINPROGRESS;
3281 case HDD_IPA_RM_RELEASED:
3282 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3283 break;
3284 }
3285
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303286 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003287
3288 ret = ipa_rm_inactivity_timer_request_resource(
3289 IPA_RM_RESOURCE_WLAN_PROD);
3290
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303291 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003292 if (ret == 0) {
3293 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3294 hdd_ipa->stats.num_rm_grant_imm++;
3295 }
3296
3297 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3298 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303299 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003300 WIFI_POWER_EVENT_WAKELOCK_IPA);
3301 hdd_ipa->wake_lock_released = false;
3302 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303303 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003304
3305 return ret;
3306}
3307
3308/**
3309 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3310 * @hdd_ipa: Global HDD IPA context
3311 *
3312 * Return: 0 if resources released, negative errno otherwise
3313 */
3314static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3315{
3316 int ret = 0;
3317
3318 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3319 return 0;
3320
3321 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3322 return -EAGAIN;
3323
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303324 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003325
Nirav Shahcbc6d722016-03-01 16:24:53 +05303326 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303327 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003328 return -EAGAIN;
3329 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303330 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003331
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303332 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003333 switch (hdd_ipa->rm_state) {
3334 case HDD_IPA_RM_GRANTED:
3335 break;
3336 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303337 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003338 return -EINPROGRESS;
3339 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303340 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 return 0;
3342 }
3343
3344 /* IPA driver returns immediately so set the state here to avoid any
3345 * race condition.
3346 */
3347 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3348 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303349 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003350
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003351 ret = ipa_rm_inactivity_timer_release_resource(
3352 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303354 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003355 if (unlikely(ret != 0)) {
3356 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3357 WARN_ON(1);
3358 }
3359
3360 /*
3361 * If wake_lock is released immediately, kernel would try to suspend
3362 * immediately as well, Just avoid ping-pong between suspend-resume
3363 * while there is healthy amount of data transfer going on by
3364 * releasing the wake_lock after some delay.
3365 */
3366 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3367 msecs_to_jiffies
3368 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3369
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303370 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371
3372 return ret;
3373}
3374
3375/**
3376 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3377 * @user_data: user data registered with IPA
3378 * @event: the IPA resource manager event that occurred
3379 * @data: the data associated with the event
3380 *
3381 * Return: None
3382 */
3383static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3384 unsigned long data)
3385{
3386 struct hdd_ipa_priv *hdd_ipa = user_data;
3387
3388 if (unlikely(!hdd_ipa))
3389 return;
3390
3391 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3392 return;
3393
Srinivas Girigowda97852372017-03-06 16:52:59 -08003394 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003395
3396 switch (event) {
3397 case IPA_RM_RESOURCE_GRANTED:
3398 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3399 /* RM Notification comes with ISR context
3400 * it should be serialized into work queue to avoid
3401 * ISR sleep problem
3402 */
3403 hdd_ipa->uc_rm_work.event = event;
3404 schedule_work(&hdd_ipa->uc_rm_work.work);
3405 break;
3406 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303407 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003408 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303409 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003410 hdd_ipa->stats.num_rm_grant++;
3411 break;
3412
3413 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003414 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003415 hdd_ipa->resource_unloading = false;
3416 break;
3417
3418 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303419 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420 break;
3421 }
3422}
3423
3424/**
3425 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3426 *
3427 * Callback function registered with IPA that is called when IPA wants
3428 * to release the WLAN consumer resource
3429 *
3430 * Return: 0 if the request is granted, negative errno otherwise
3431 */
3432static int hdd_ipa_rm_cons_release(void)
3433{
3434 return 0;
3435}
3436
3437/**
3438 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3439 *
3440 * Callback function registered with IPA that is called when IPA wants
3441 * to access the WLAN consumer resource
3442 *
3443 * Return: 0 if the request is granted, negative errno otherwise
3444 */
3445static int hdd_ipa_rm_cons_request(void)
3446{
Yun Park4d8b60a2015-10-22 13:59:32 -07003447 int ret = 0;
3448
3449 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303450 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003451 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003452 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003453 ret = -EINPROGRESS;
3454 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303455 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003456 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003457 ghdd_ipa->pending_cons_req = true;
3458 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003459 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003460
3461 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003462}
3463
3464/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003465 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003466 * @hdd_ctx: Global HDD context
3467 * @tx_packets: Number of packets transmitted in the last sample period
3468 * @rx_packets: Number of packets received in the last sample period
3469 *
3470 * Return: 0 on success, negative errno on error
3471 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003472static int __hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003473 uint64_t rx_packets)
3474{
3475 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003476 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003478 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003479 int ret;
3480
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003481 if (wlan_hdd_validate_context(hdd_ctx))
3482 return 0;
3483
3484 hdd_ipa = hdd_ctx->hdd_ipa;
3485
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003486 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3487 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3488 return 0;
3489
3490 memset(&profile, 0, sizeof(profile));
3491
3492 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3493 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3494 else if (tx_packets >
3495 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3496 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3497 else
3498 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3499
3500 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3501 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3502 else if (rx_packets >
3503 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3504 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3505 else
3506 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3507
Yun Parkec845302016-12-15 09:22:57 -08003508 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003509 "CONS perf curr: %d, next: %d",
3510 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003511 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003512 "PROD perf curr: %d, next: %d",
3513 hdd_ipa->curr_prod_bw, next_prod_bw);
3514
3515 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003516 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003517 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003518 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3519 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003520 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003521 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003522
3523 return ret;
3524 }
3525 hdd_ipa->curr_cons_bw = next_cons_bw;
3526 hdd_ipa->stats.num_cons_perf_req++;
3527 }
3528
3529 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003530 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003532 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3533 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003534 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003535 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003536 return ret;
3537 }
3538 hdd_ipa->curr_prod_bw = next_prod_bw;
3539 hdd_ipa->stats.num_prod_perf_req++;
3540 }
3541
3542 return 0;
3543}
3544
3545/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003546 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3547 * @hdd_ctx: Global HDD context
3548 * @tx_packets: Number of packets transmitted in the last sample period
3549 * @rx_packets: Number of packets received in the last sample period
3550 *
3551 * Return: 0 on success, negative errno on error
3552 */
3553int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
3554 uint64_t rx_packets)
3555{
3556 int ret;
3557
3558 cds_ssr_protect(__func__);
3559 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3560 cds_ssr_unprotect(__func__);
3561
3562 return ret;
3563}
3564
3565/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003566 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3567 * @work: struct work_struct
3568 * @work_handler: work_handler
3569 *
3570 * Return: none
3571 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003572static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3573 work_func_t work_handler)
3574{
3575 INIT_WORK(work, work_handler);
3576}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003577
3578/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003579 * hdd_ipa_setup_rm() - Setup IPA resource management
3580 * @hdd_ipa: Global HDD IPA context
3581 *
3582 * Return: 0 on success, negative errno on error
3583 */
3584static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3585{
3586 struct ipa_rm_create_params create_params = { 0 };
3587 int ret;
3588
3589 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3590 return 0;
3591
Rajeev Kumar217f2172016-01-06 18:11:55 -08003592 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3593 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003594 memset(&create_params, 0, sizeof(create_params));
3595 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3596 create_params.reg_params.user_data = hdd_ipa;
3597 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3598 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3599
3600 ret = ipa_rm_create_resource(&create_params);
3601 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303602 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003603 "Create RM resource failed: %d", ret);
3604 goto setup_rm_fail;
3605 }
3606
3607 memset(&create_params, 0, sizeof(create_params));
3608 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3609 create_params.request_resource = hdd_ipa_rm_cons_request;
3610 create_params.release_resource = hdd_ipa_rm_cons_release;
3611 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3612
3613 ret = ipa_rm_create_resource(&create_params);
3614 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303615 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003616 "Create RM CONS resource failed: %d", ret);
3617 goto delete_prod;
3618 }
3619
3620 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3621 IPA_RM_RESOURCE_APPS_CONS);
3622
3623 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3624 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3625 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303626 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003627 ret);
3628 goto timer_init_failed;
3629 }
3630
3631 /* Set the lowest bandwidth to start with */
3632 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3633
3634 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303635 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003636 "Set perf level failed: %d", ret);
3637 goto set_perf_failed;
3638 }
3639
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303640 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3642 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303643 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3645 hdd_ipa->wake_lock_released = true;
3646 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3647
3648 return ret;
3649
3650set_perf_failed:
3651 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3652
3653timer_init_failed:
3654 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3655
3656delete_prod:
3657 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3658
3659setup_rm_fail:
3660 return ret;
3661}
3662
3663/**
3664 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3665 * @hdd_ipa: Global HDD IPA context
3666 *
3667 * Destroys all resources associated with the IPA resource manager
3668 *
3669 * Return: None
3670 */
3671static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3672{
3673 int ret;
3674
3675 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3676 return;
3677
3678 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303679 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003681 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303682 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683
3684 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3685
3686 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3687 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303688 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 "RM PROD resource delete failed %d", ret);
3690
3691 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3692 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303693 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694 "RM CONS resource delete failed %d", ret);
3695}
3696
tfyu0380a972017-07-13 18:19:37 +08003697#ifdef QCA_CONFIG_SMP
3698static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3699{
3700 return netif_rx_ni(skb);
3701}
3702#else
3703static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3704{
3705 struct iphdr *ip_h;
3706 static atomic_t softirq_mitigation_cntr =
3707 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
3708 int result;
3709
3710 ip_h = (struct iphdr *)(skb->data);
3711 if ((skb->protocol == htons(ETH_P_IP)) &&
3712 (ip_h->protocol == IPPROTO_ICMP)) {
3713 result = netif_rx_ni(skb);
3714 } else {
3715 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
3716 * to avoid excessive softirq's.
3717 */
3718 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
3719 result = netif_rx_ni(skb);
3720 atomic_set(&softirq_mitigation_cntr,
3721 IPA_WLAN_RX_SOFTIRQ_THRESH);
3722 } else {
3723 result = netif_rx(skb);
3724 }
3725 }
3726
3727 return result;
3728}
3729#endif
3730
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003731/**
3732 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3733 * @skb: network buffer
3734 * @adapter: network adapter
3735 *
3736 * Called when a network buffer is received which should not be routed
3737 * to the IPA module.
3738 *
3739 * Return: None
3740 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303741static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003742 hdd_adapter_t *adapter)
3743{
tfyu0380a972017-07-13 18:19:37 +08003744 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003745 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3746 unsigned int cpu_index;
3747
3748 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003749 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003750 adapter);
3751 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003752 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003753 return;
3754 }
3755
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003756 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003757 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
3762 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3763 skb->dev = adapter->dev;
3764 skb->protocol = eth_type_trans(skb, skb->dev);
3765 skb->ip_summed = CHECKSUM_NONE;
3766
3767 cpu_index = wlan_hdd_get_cpu();
3768
3769 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08003770 result = hdd_ipa_aggregated_rx_ind(skb);
3771 if (result == NET_RX_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
3773 else
3774 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
3775
3776 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
3777 adapter->dev->last_rx = jiffies;
3778}
3779
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003780/**
Leo Chang69c39692016-10-12 20:11:12 -07003781 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3782 * @hdd_ipa: pointer to hdd ipa context
3783 * @adapter: network adapter
3784 * @skb: data pointer
3785 *
3786 * if exception packet has set forward bit, copied new packet should be
3787 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3788 * put into pm queue and tx procedure will be differed
3789 *
3790 * Return: None
3791 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003792static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
3793 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003794{
Leo Chang69c39692016-10-12 20:11:12 -07003795 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3796
Leo Chang69c39692016-10-12 20:11:12 -07003797 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
3798 /* WLAN subsystem is in suspend, put int queue */
3799 if (hdd_ipa->suspended) {
3800 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3801 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3802 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003803 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3804 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003805 pm_tx_cb->exception = true;
3806 pm_tx_cb->adapter = adapter;
3807 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003808 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003809 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3810 hdd_ipa->stats.num_tx_queued++;
3811 } else {
3812 /* Resume, put packet into WLAN TX */
3813 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003814 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003815 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3816 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003817 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003818 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003819 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003820 hdd_ipa->ipa_tx_forward++;
3821 }
3822 }
3823}
3824
3825/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003826 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3827 * @hdd_ipa: pointer to HDD IPA struct
3828 * @adapter: hdd adapter pointer
3829 * @desc: Firmware descriptor
3830 * @skb: Data buffer
3831 *
3832 * Return:
3833 * HDD_IPA_FORWARD_PKT_NONE
3834 * HDD_IPA_FORWARD_PKT_DISCARD
3835 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3836 *
3837 */
3838
3839static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3840 struct hdd_ipa_priv *hdd_ipa,
3841 hdd_adapter_t *adapter,
3842 uint8_t desc,
3843 qdf_nbuf_t skb)
3844{
3845 int ret = HDD_IPA_FORWARD_PKT_NONE;
3846
3847 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303848 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003849 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
3850 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303851 /* Drop the packet*/
3852 hdd_ipa->stats.num_tx_fwd_err++;
3853 kfree_skb(skb);
3854 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3855 return ret;
3856 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003857 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3858 "Forward packet to Tx (fw_desc=%d)", desc);
3859 hdd_ipa->ipa_tx_forward++;
3860
3861 if ((desc & FW_RX_DESC_DISCARD_M)) {
3862 hdd_ipa_forward(hdd_ipa, adapter, skb);
3863 hdd_ipa->ipa_rx_internel_drop_count++;
3864 hdd_ipa->ipa_rx_discard++;
3865 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3866 } else {
3867 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003868
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003869 if (cloned_skb)
3870 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3871 else
3872 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3873 "%s: tx skb alloc failed",
3874 __func__);
3875 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3876 }
3877 }
3878
3879 return ret;
3880}
3881
3882/**
Yun Park637d6482016-10-05 10:51:33 -07003883 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884 * @priv: pointer to private data registered with IPA (we register a
3885 * pointer to the global IPA context)
3886 * @evt: the IPA event which triggered the callback
3887 * @data: data associated with the event
3888 *
3889 * Return: None
3890 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003891static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003892 unsigned long data)
3893{
3894 struct hdd_ipa_priv *hdd_ipa = NULL;
3895 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303896 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003897 uint8_t iface_id;
3898 uint8_t session_id;
3899 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003901 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003902
3903 hdd_ipa = (struct hdd_ipa_priv *)priv;
3904
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003905 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3906 return;
3907
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003908 switch (evt) {
3909 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303910 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003911
3912 /*
3913 * When SSR is going on or driver is unloading,
3914 * just drop the packets.
3915 */
3916 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
3917 if (0 != status) {
3918 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3919 "Invalid context: drop packet");
3920 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3921 kfree_skb(skb);
3922 return;
3923 }
3924
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003925 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3926 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003927 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08003928 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 "IPA_RECEIVE: session_id=%u, iface_id=%u",
3930 session_id, iface_id);
3931 } else {
3932 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
3933 }
3934
3935 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303936 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 "IPA_RECEIVE: Invalid iface_id: %u",
3938 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003939 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003940 "w2i -- skb",
3941 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003942 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003943 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003944 return;
3945 }
3946
3947 iface_context = &hdd_ipa->iface_context[iface_id];
3948 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08003949 if (!adapter) {
3950 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3951 "IPA_RECEIVE: Adapter is NULL");
3952 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3953 kfree_skb(skb);
3954 return;
3955 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003956
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303957 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003958 "w2i -- skb",
3959 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003960 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3961 hdd_ipa->stats.num_rx_excep++;
3962 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
3963 } else {
3964 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
3965 }
3966
3967 iface_context->stats.num_rx_ipa_excep++;
3968
3969 /* Disable to forward Intra-BSS Rx packets when
3970 * ap_isolate=1 in hostapd.conf
3971 */
Yun Park046101c2016-09-02 15:32:14 -07003972 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 /*
3974 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
3975 * all Rx packets to IPA uC, which need to be forwarded
3976 * to other interface.
3977 * And, IPA driver will send back to WLAN host driver
3978 * through exception pipe with fw_desc field set by FW.
3979 * Here we are checking fw_desc field for FORWARD bit
3980 * set, and forward to Tx. Then copy to kernel stack
3981 * only when DISCARD bit is not set.
3982 */
3983 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003984 if (HDD_IPA_FORWARD_PKT_DISCARD ==
3985 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
3986 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08003987 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003988 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003989 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 "Intra-BSS FWD is disabled-skip forward to Tx");
3991 }
3992
3993 hdd_ipa_send_skb_to_network(skb, adapter);
3994 break;
3995
3996 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303997 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 "w2i cb wrong event: 0x%x", evt);
3999 return;
4000 }
4001}
4002
4003/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004004 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4005 * @priv: pointer to private data registered with IPA (we register a
4006 * pointer to the global IPA context)
4007 * @evt: the IPA event which triggered the callback
4008 * @data: data associated with the event
4009 *
4010 * Return: None
4011 */
4012static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4013 unsigned long data)
4014{
4015 cds_ssr_protect(__func__);
4016 __hdd_ipa_w2i_cb(priv, evt, data);
4017 cds_ssr_unprotect(__func__);
4018}
4019
4020/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004021 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4022 * @skb: packet buffer which was transmitted
4023 *
4024 * Return: None
4025 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304026void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027{
4028 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004029 struct ipa_rx_data *ipa_tx_desc;
4030 struct hdd_ipa_tx_desc *tx_desc;
4031 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004032
Yun Park52b2b992016-09-22 15:49:51 -07004033 if (!qdf_nbuf_ipa_owned_get(skb)) {
4034 dev_kfree_skb_any(skb);
4035 return;
4036 }
4037
4038 /* Get Tx desc pointer from SKB CB */
4039 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4040 tx_desc = hdd_ipa->tx_desc_list + id;
4041 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4042
4043 /* Return Tx Desc to IPA */
4044 ipa_free_skb(ipa_tx_desc);
4045
4046 /* Return to free tx desc list */
4047 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4048 tx_desc->ipa_tx_desc_ptr = NULL;
4049 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4050 hdd_ipa->stats.num_tx_desc_q_cnt--;
4051 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004052
4053 hdd_ipa->stats.num_tx_comp_cnt++;
4054
4055 atomic_dec(&hdd_ipa->tx_ref_cnt);
4056
4057 hdd_ipa_rm_try_release(hdd_ipa);
4058}
4059
4060/**
4061 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4062 * @iface_context: interface-specific IPA context
4063 * @ipa_tx_desc: packet data descriptor
4064 *
4065 * Return: None
4066 */
4067static void hdd_ipa_send_pkt_to_tl(
4068 struct hdd_ipa_iface_context *iface_context,
4069 struct ipa_rx_data *ipa_tx_desc)
4070{
4071 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304073 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004074 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004075
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304076 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 adapter = iface_context->adapter;
4078 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304079 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004080 ipa_free_skb(ipa_tx_desc);
4081 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304082 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004083 hdd_ipa_rm_try_release(hdd_ipa);
4084 return;
4085 }
4086
4087 /*
4088 * During CAC period, data packets shouldn't be sent over the air so
4089 * drop all the packets here
4090 */
4091 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4092 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304093 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004094 iface_context->stats.num_tx_cac_drop++;
4095 hdd_ipa_rm_try_release(hdd_ipa);
4096 return;
4097 }
4098
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004099 ++adapter->stats.tx_packets;
4100
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304101 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004102
4103 skb = ipa_tx_desc->skb;
4104
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304105 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004106
4107 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304108 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304110 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004111 ipa_tx_desc->dma_addr
4112 + HDD_IPA_WLAN_FRAG_HEADER
4113 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 ipa_tx_desc->skb->len -=
4115 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4116 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304117 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004118
Yun Park52b2b992016-09-22 15:49:51 -07004119 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4120 /* get free Tx desc and assign ipa_tx_desc pointer */
4121 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4122 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4123 struct hdd_ipa_tx_desc, link);
4124 list_del(&tx_desc->link);
4125 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4126 hdd_ipa->stats.num_tx_desc_q_cnt++;
4127 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4128 /* Store Tx Desc index into SKB CB */
4129 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4130 } else {
4131 hdd_ipa->stats.num_tx_desc_error++;
4132 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4133 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4134 ipa_free_skb(ipa_tx_desc);
4135 hdd_ipa_rm_try_release(hdd_ipa);
4136 return;
4137 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004138
4139 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4140
Leo Changfdb45c32016-10-28 11:09:23 -07004141 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004142 (struct cdp_vdev *)iface_context->tl_context,
4143 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004144 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304145 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146 ipa_free_skb(ipa_tx_desc);
4147 iface_context->stats.num_tx_err++;
4148 hdd_ipa_rm_try_release(hdd_ipa);
4149 return;
4150 }
4151
4152 atomic_inc(&hdd_ipa->tx_ref_cnt);
4153
4154 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004155}
4156
4157/**
Leo Chang11545d62016-10-17 14:53:50 -07004158 * hdd_ipa_is_present() - get IPA hw status
4159 * @hdd_ctx: pointer to hdd context
4160 *
4161 * ipa_uc_reg_rdyCB is not directly designed to check
4162 * ipa hw status. This is an undocumented function which
4163 * has confirmed with IPA team.
4164 *
4165 * Return: true - ipa hw present
4166 * false - ipa hw not present
4167 */
4168bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
4169{
4170 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004171 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004172 return true;
4173 else
4174 return false;
4175}
4176
4177/**
Leo Chang69c39692016-10-12 20:11:12 -07004178 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 * @work: pointer to the scheduled work
4180 *
4181 * Called during PM resume to send packets to TL which were queued
4182 * while host was in the process of suspending.
4183 *
4184 * Return: None
4185 */
Leo Chang69c39692016-10-12 20:11:12 -07004186static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004187{
4188 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4189 struct hdd_ipa_priv,
4190 pm_work);
4191 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304192 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004193 uint32_t dequeued = 0;
4194
Leo Chang69c39692016-10-12 20:11:12 -07004195 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4196 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304197 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304198 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4199 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304200 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004201
4202 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004204 if (pm_tx_cb->exception) {
4205 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4206 "FLUSH EXCEPTION");
4207 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
4208 } else {
4209 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004211 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304212 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004213 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304214 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004215 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4216 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004217
4218 hdd_ipa->stats.num_tx_dequeued += dequeued;
4219 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4220 hdd_ipa->stats.num_max_pm_queue = dequeued;
4221}
4222
4223/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004224 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004225 * @priv: pointer to private data registered with IPA (we register a
4226 * pointer to the interface-specific IPA context)
4227 * @evt: the IPA event which triggered the callback
4228 * @data: data associated with the event
4229 *
4230 * Return: None
4231 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004232static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004233 unsigned long data)
4234{
4235 struct hdd_ipa_priv *hdd_ipa = NULL;
4236 struct ipa_rx_data *ipa_tx_desc;
4237 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304238 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004239 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304240 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004241
Mukul Sharma81661ae2015-10-30 20:26:02 +05304242 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004243 ipa_tx_desc = (struct ipa_rx_data *)data;
4244 hdd_ipa = iface_context->hdd_ipa;
4245
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004246 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004247 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4248 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004249 iface_context->stats.num_tx_drop++;
4250 return;
4251 }
4252
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004253 /*
4254 * When SSR is going on or driver is unloading, just drop the packets.
4255 * During SSR, there is no use in queueing the packets as STA has to
4256 * connect back any way
4257 */
4258 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304259 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 ipa_free_skb(ipa_tx_desc);
4261 iface_context->stats.num_tx_drop++;
4262 return;
4263 }
4264
4265 skb = ipa_tx_desc->skb;
4266
Yun Parkb187d542016-11-14 18:10:04 -08004267 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4268 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004269
4270 /*
4271 * If PROD resource is not requested here then there may be cases where
4272 * IPA hardware may be clocked down because of not having proper
4273 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4274 * workaround to request PROD resource while data is going over CONS
4275 * pipe to prevent the IPA hardware clockdown.
4276 */
4277 hdd_ipa_rm_request(hdd_ipa);
4278
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304279 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004280 /*
4281 * If host is still suspended then queue the packets and these will be
4282 * drained later when resume completes. When packet is arrived here and
4283 * host is suspended, this means that there is already resume is in
4284 * progress.
4285 */
4286 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304287 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4289 pm_tx_cb->iface_context = iface_context;
4290 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304291 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292 hdd_ipa->stats.num_tx_queued++;
4293
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304294 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295 return;
4296 }
4297
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304298 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004299
4300 /*
4301 * If we are here means, host is not suspended, wait for the work queue
4302 * to finish.
4303 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305
4306 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4307}
4308
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004309/*
4310 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4311 * @priv: pointer to private data registered with IPA (we register a
4312 * pointer to the interface-specific IPA context)
4313 * @evt: the IPA event which triggered the callback
4314 * @data: data associated with the event
4315 *
4316 * Return: None
4317 */
4318static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4319 unsigned long data)
4320{
4321 cds_ssr_protect(__func__);
4322 __hdd_ipa_i2w_cb(priv, evt, data);
4323 cds_ssr_unprotect(__func__);
4324}
4325
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004326/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004327 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 * @hdd_ctx: Global HDD context
4329 *
4330 * Return: 0 on success, negativer errno on error
4331 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004332static int __hdd_ipa_suspend(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004333{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004334 struct hdd_ipa_priv *hdd_ipa;
4335
4336 if (wlan_hdd_validate_context(hdd_ctx))
4337 return 0;
4338
4339 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340
4341 if (!hdd_ipa_is_enabled(hdd_ctx))
4342 return 0;
4343
4344 /*
4345 * Check if IPA is ready for suspend, If we are here means, there is
4346 * high chance that suspend would go through but just to avoid any race
4347 * condition after suspend started, these checks are conducted before
4348 * allowing to suspend.
4349 */
4350 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4351 return -EAGAIN;
4352
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304353 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004354
4355 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304356 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004357 return -EAGAIN;
4358 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304359 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004360
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304361 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004362 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304363 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004364
4365 return 0;
4366}
4367
4368/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004369 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4370 * @hdd_ctx: Global HDD context
4371 *
4372 * Return: 0 on success, negativer errno on error
4373 */
4374int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
4375{
4376 int ret;
4377
4378 cds_ssr_protect(__func__);
4379 ret = __hdd_ipa_suspend(hdd_ctx);
4380 cds_ssr_unprotect(__func__);
4381
4382 return ret;
4383}
4384
4385/**
4386 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004387 * hdd_ctx: Global HDD context
4388 *
4389 * Return: 0 on success, negative errno on error
4390 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004391static int __hdd_ipa_resume(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004393 struct hdd_ipa_priv *hdd_ipa;
4394
4395 if (wlan_hdd_validate_context(hdd_ctx))
4396 return 0;
4397
4398 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399
4400 if (!hdd_ipa_is_enabled(hdd_ctx))
4401 return 0;
4402
4403 schedule_work(&hdd_ipa->pm_work);
4404
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304405 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004406 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304407 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004408
4409 return 0;
4410}
4411
4412/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004413 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4414 * hdd_ctx: Global HDD context
4415 *
4416 * Return: 0 on success, negative errno on error
4417 */
4418int hdd_ipa_resume(hdd_context_t *hdd_ctx)
4419{
4420 int ret;
4421
4422 cds_ssr_protect(__func__);
4423 ret = __hdd_ipa_resume(hdd_ctx);
4424 cds_ssr_unprotect(__func__);
4425
4426 return ret;
4427}
4428
4429/**
Yun Park52b2b992016-09-22 15:49:51 -07004430 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4431 * @hdd_ipa: Global HDD IPA context
4432 *
4433 * Return: 0 on success, negative errno on error
4434 */
4435static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4436{
4437 int i;
4438 uint32_t max_desc_cnt;
4439 struct hdd_ipa_tx_desc *tmp_desc;
4440
4441 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4442
4443 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4444
4445 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc)*max_desc_cnt);
4446
4447 if (!tmp_desc) {
4448 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4449 "Free Tx descriptor allocation failed");
4450 return -ENOMEM;
4451 }
4452
4453 hdd_ipa->tx_desc_list = tmp_desc;
4454
4455 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4456 for (i = 0; i < max_desc_cnt; i++) {
4457 tmp_desc->id = i;
4458 tmp_desc->ipa_tx_desc_ptr = NULL;
4459 list_add_tail(&tmp_desc->link,
4460 &hdd_ipa->free_tx_desc_head);
4461 tmp_desc++;
4462 }
4463
4464 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4465 hdd_ipa->stats.num_tx_desc_error = 0;
4466
4467 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4468
4469 return 0;
4470}
4471
4472/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4474 * @hdd_ipa: Global HDD IPA context
4475 *
4476 * Return: 0 on success, negative errno on error
4477 */
4478static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4479{
4480 int i, ret = 0;
4481 struct ipa_sys_connect_params *ipa;
4482 uint32_t desc_fifo_sz;
4483
4484 /* The maximum number of descriptors that can be provided to a BAM at
4485 * once is one less than the total number of descriptors that the buffer
4486 * can contain.
4487 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4488 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4489 * be provided at once.
4490 * Because of above requirement, one extra descriptor will be added to
4491 * make sure hardware always has one descriptor.
4492 */
4493 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4494 + sizeof(struct sps_iovec);
4495
4496 /*setup TX pipes */
4497 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4498 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4499
4500 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4501 ipa->desc_fifo_sz = desc_fifo_sz;
4502 ipa->priv = &hdd_ipa->iface_context[i];
4503 ipa->notify = hdd_ipa_i2w_cb;
4504
4505 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4506 ipa->ipa_ep_cfg.hdr.hdr_len =
4507 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4508 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4509 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4510 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4511 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4512 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4513 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4514 } else {
4515 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4516 }
4517 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4518
4519 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4520 ipa->keep_ipa_awake = 1;
4521
4522 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4523 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004524 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4525 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004526 goto setup_sys_pipe_fail;
4527 }
4528 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4529 }
4530
4531 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4532 /*
4533 * Hard code it here, this can be extended if in case
4534 * PROD pipe is also per interface.
4535 * Right now there is no advantage of doing this.
4536 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4538
Yun Parkb4f591d2017-03-29 15:51:01 -07004539 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004540
4541 ipa->desc_fifo_sz = desc_fifo_sz;
4542 ipa->priv = hdd_ipa;
4543 ipa->notify = hdd_ipa_w2i_cb;
4544
4545 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4546 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4547 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4548 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4549
4550 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4551 ipa->keep_ipa_awake = 1;
4552
4553 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4554 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304555 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004556 "Failed for RX pipe: %d", ret);
4557 goto setup_sys_pipe_fail;
4558 }
4559 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4560 }
4561
Yun Park52b2b992016-09-22 15:49:51 -07004562 /* Allocate free Tx desc list */
4563 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4564 if (ret)
4565 goto setup_sys_pipe_fail;
4566
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004567 return ret;
4568
4569setup_sys_pipe_fail:
4570
4571 while (--i >= 0) {
4572 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304573 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004574 sizeof(struct hdd_ipa_sys_pipe));
4575 }
4576
4577 return ret;
4578}
4579
4580/**
4581 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4582 * @hdd_ipa: Global HDD IPA context
4583 *
4584 * Return: None
4585 */
4586static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4587{
4588 int ret = 0, i;
Yun Park52b2b992016-09-22 15:49:51 -07004589 uint32_t max_desc_cnt;
4590 struct hdd_ipa_tx_desc *tmp_desc;
4591 struct ipa_rx_data *ipa_tx_desc;
4592
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004593 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4594 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004595 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4596 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004597 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304598 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599 ret);
4600
4601 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4602 }
4603 }
Yun Park52b2b992016-09-22 15:49:51 -07004604
4605 if (hdd_ipa->tx_desc_list) {
4606 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4607
4608 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4609 for (i = 0; i < max_desc_cnt; i++) {
4610 tmp_desc = hdd_ipa->tx_desc_list + i;
4611 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4612 if (ipa_tx_desc)
4613 ipa_free_skb(ipa_tx_desc);
4614 }
4615 tmp_desc = hdd_ipa->tx_desc_list;
4616 hdd_ipa->tx_desc_list = NULL;
4617 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4618 hdd_ipa->stats.num_tx_desc_error = 0;
4619 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4620 qdf_mem_free(tmp_desc);
4621 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004622}
4623
4624/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4626 * @iface_context: interface-specific IPA context
4627 *
4628 * Return: None
4629 */
4630static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4631{
4632 if (iface_context == NULL)
4633 return;
4634
Yun Parkb4f591d2017-03-29 15:51:01 -07004635 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4636 iface_context->adapter->dev->name,
4637 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004638
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304639 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004640 iface_context->adapter->ipa_context = NULL;
4641 iface_context->adapter = NULL;
4642 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304643 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004644 iface_context->ifa_address = 0;
4645 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304646 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304648 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004649 }
4650 iface_context->hdd_ipa->num_iface--;
4651}
4652
4653/**
4654 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4655 * @hdd_ipa: HDD IPA global context
4656 * @adapter: Interface upon which IPA is being setup
4657 * @sta_id: Station ID of the API instance
4658 *
4659 * Return: 0 on success, negative errno value on error
4660 */
4661static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
4662 hdd_adapter_t *adapter, uint8_t sta_id)
4663{
4664 struct hdd_ipa_iface_context *iface_context = NULL;
4665 void *tl_context = NULL;
4666 int i, ret = 0;
4667
4668 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4669 * channel change indication. Since these indications are sent by lower
4670 * layer as SAP updates and IPA doesn't have to do anything for these
4671 * updates so ignoring!
4672 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004673 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674 return 0;
4675
4676 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4677 if (hdd_ipa->iface_context[i].adapter == NULL) {
4678 iface_context = &(hdd_ipa->iface_context[i]);
4679 break;
4680 }
4681 }
4682
4683 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304684 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004685 "All the IPA interfaces are in use");
4686 ret = -ENOMEM;
4687 goto end;
4688 }
4689
4690 adapter->ipa_context = iface_context;
4691 iface_context->adapter = adapter;
4692 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004693 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07004694 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004695 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304696 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004697 "Not able to get TL context sta_id: %d", sta_id);
4698 ret = -EINVAL;
4699 goto end;
4700 }
4701
4702 iface_context->tl_context = tl_context;
4703
Yun Parkb4f591d2017-03-29 15:51:01 -07004704 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4705 adapter->dev->name, adapter->dev->dev_addr,
4706 iface_context->prod_client,
4707 iface_context->cons_client,
4708 adapter->sessionId,
4709 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004710 if (ret)
4711 goto end;
4712
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004713 hdd_ipa->num_iface++;
4714 return ret;
4715
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004716end:
4717 if (iface_context)
4718 hdd_ipa_cleanup_iface(iface_context);
4719 return ret;
4720}
4721
Yun Parka27049a2016-10-11 12:30:49 -07004722#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004723/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004724 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004725 * @mcc_mode: 0=MCC/1=SCC
4726 *
4727 * Return: 0 on success, negative errno value on error
4728 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004729static int __hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004730{
4731 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304732 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004733 hdd_adapter_t *pAdapter;
4734 struct ipa_msg_meta meta;
4735 struct ipa_wlan_msg *msg;
4736 int ret;
4737
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004738 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004739 return -EINVAL;
4740
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004741 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4742 return -EINVAL;
4743
4744 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004745 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004746 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304747 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004748 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08004749 if (pAdapter->device_mode == QDF_STA_MODE ||
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004750 pAdapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004751 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004752 pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004753 hdd_deinit_tx_rx(pAdapter);
4754 }
4755 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004756 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004757 adapter_node = next;
4758 }
4759 }
4760
4761 /* Send SCC/MCC Switching event to IPA */
4762 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304763 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004765 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004766 return -ENOMEM;
4767 }
4768
4769 meta.msg_type = mcc_mode ?
4770 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08004771 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004772
4773 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4774
4775 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004776 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004777 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304778 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004779 }
4780
4781 return ret;
4782}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004783
4784/**
4785 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
4786 * @mcc_mode: 0=MCC/1=SCC
4787 *
4788 * Return: 0 on success, negative errno value on error
4789 */
4790int hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
4791{
4792 int ret;
4793
4794 cds_ssr_protect(__func__);
4795 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
4796 cds_ssr_unprotect(__func__);
4797
4798 return ret;
4799}
Yun Parka27049a2016-10-11 12:30:49 -07004800#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004801
4802/**
4803 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
4804 * @event: IPA WLAN event to be converted to a string
4805 *
4806 * Return: ASCII string representing the IPA WLAN event
4807 */
4808static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
4809{
4810 switch (event) {
4811 case WLAN_CLIENT_CONNECT:
4812 return "WLAN_CLIENT_CONNECT";
4813 case WLAN_CLIENT_DISCONNECT:
4814 return "WLAN_CLIENT_DISCONNECT";
4815 case WLAN_CLIENT_POWER_SAVE_MODE:
4816 return "WLAN_CLIENT_POWER_SAVE_MODE";
4817 case WLAN_CLIENT_NORMAL_MODE:
4818 return "WLAN_CLIENT_NORMAL_MODE";
4819 case SW_ROUTING_ENABLE:
4820 return "SW_ROUTING_ENABLE";
4821 case SW_ROUTING_DISABLE:
4822 return "SW_ROUTING_DISABLE";
4823 case WLAN_AP_CONNECT:
4824 return "WLAN_AP_CONNECT";
4825 case WLAN_AP_DISCONNECT:
4826 return "WLAN_AP_DISCONNECT";
4827 case WLAN_STA_CONNECT:
4828 return "WLAN_STA_CONNECT";
4829 case WLAN_STA_DISCONNECT:
4830 return "WLAN_STA_DISCONNECT";
4831 case WLAN_CLIENT_CONNECT_EX:
4832 return "WLAN_CLIENT_CONNECT_EX";
4833
4834 case IPA_WLAN_EVENT_MAX:
4835 default:
4836 return "UNKNOWN";
4837 }
4838}
4839
4840/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004841 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
4842 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
4843 *
4844 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
4845 */
4846static enum ipa_wlan_event
4847hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
4848{
4849 enum ipa_wlan_event ipa_event;
4850
4851 switch (hdd_ipa_event_type) {
4852 case HDD_IPA_CLIENT_CONNECT:
4853 ipa_event = WLAN_CLIENT_CONNECT;
4854 break;
4855 case HDD_IPA_CLIENT_DISCONNECT:
4856 ipa_event = WLAN_CLIENT_DISCONNECT;
4857 break;
4858 case HDD_IPA_AP_CONNECT:
4859 ipa_event = WLAN_AP_CONNECT;
4860 break;
4861 case HDD_IPA_AP_DISCONNECT:
4862 ipa_event = WLAN_AP_DISCONNECT;
4863 break;
4864 case HDD_IPA_STA_CONNECT:
4865 ipa_event = WLAN_STA_CONNECT;
4866 break;
4867 case HDD_IPA_STA_DISCONNECT:
4868 ipa_event = WLAN_STA_DISCONNECT;
4869 break;
4870 case HDD_IPA_CLIENT_CONNECT_EX:
4871 ipa_event = WLAN_CLIENT_CONNECT_EX;
4872 break;
4873 case HDD_IPA_WLAN_EVENT_MAX:
4874 default:
4875 ipa_event = IPA_WLAN_EVENT_MAX;
4876 break;
4877 }
4878 return ipa_event;
4879
4880}
4881
4882/**
4883 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004884 * @adapter: adapter upon which the event was received
4885 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07004886 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004887 * @mac_address: MAC address associated with the event
4888 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07004889 * This function is meant to be called from within wlan_hdd_ipa.c
4890 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004891 * Return: 0 on success, negative errno value on error
4892 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07004893static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004894 enum ipa_wlan_event type, uint8_t *mac_addr)
4895{
4896 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4897 struct ipa_msg_meta meta;
4898 struct ipa_wlan_msg *msg;
4899 struct ipa_wlan_msg_ex *msg_ex = NULL;
4900 int ret;
4901
Srinivas Girigowda97852372017-03-06 16:52:59 -08004902 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004903 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
4904 mac_addr, sta_id);
4905
4906 if (type >= IPA_WLAN_EVENT_MAX)
4907 return -EINVAL;
4908
4909 if (WARN_ON(is_zero_ether_addr(mac_addr)))
4910 return -EINVAL;
4911
4912 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304913 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 return -EINVAL;
4915 }
4916
4917 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
4918 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08004919 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004920 return 0;
4921 }
4922
4923 /*
4924 * During IPA UC resource loading/unloading new events can be issued.
4925 * Store the events separately and handle them later.
4926 */
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004927 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4928 if (hdd_ipa->resource_loading) {
4929 unsigned int pending_event_count;
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004930 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08004931
Yun Park64c405e2017-01-10 22:35:51 -08004932 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4933 "IPA resource load in progress");
Yun Park7c4f31b2016-11-30 10:09:21 -08004934
Yun Park64c405e2017-01-10 22:35:51 -08004935 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004936
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004937 pending_event_count =
4938 qdf_list_size(&hdd_ipa->pending_event);
4939 if (pending_event_count >=
4940 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004941 hdd_debug("Reached max pending event count");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004942 qdf_list_remove_front(&hdd_ipa->pending_event,
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004943 (qdf_list_node_t **)&pending_event);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004944 } else {
4945 pending_event =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004946 qdf_mem_malloc(sizeof(*pending_event));
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004947 }
4948
4949 if (!pending_event) {
Yun Park64c405e2017-01-10 22:35:51 -08004950 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park7c4f31b2016-11-30 10:09:21 -08004951 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4952 "Pending event memory alloc fail");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004953 return -ENOMEM;
4954 }
4955
4956 pending_event->adapter = adapter;
4957 pending_event->sta_id = sta_id;
4958 pending_event->type = type;
4959 qdf_mem_copy(pending_event->mac_addr,
4960 mac_addr,
4961 QDF_MAC_ADDR_SIZE);
4962 qdf_list_insert_back(&hdd_ipa->pending_event,
4963 &pending_event->node);
4964
Yun Park64c405e2017-01-10 22:35:51 -08004965 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004966 return 0;
4967 } else if (hdd_ipa->resource_unloading) {
Yun Park64c405e2017-01-10 22:35:51 -08004968 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4969 "IPA resource unload in progress");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07004970 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004971 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004972 }
4973
4974 hdd_ipa->stats.event[type]++;
4975
Leo Chang3bc8fed2015-11-13 10:59:47 -08004976 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977 switch (type) {
4978 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07004979 qdf_mutex_acquire(&hdd_ipa->event_lock);
4980
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004981 /* STA already connected and without disconnect, connect again
4982 * This is Roaming scenario
4983 */
4984 if (hdd_ipa->sta_connected)
4985 hdd_ipa_cleanup_iface(adapter->ipa_context);
4986
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004987 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
4988 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304989 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07004991 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004992
Yun Park8f289c82016-10-18 16:38:21 -07004993 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
4994 (hdd_ipa->sap_num_connected_sta > 0) &&
4995 !hdd_ipa->sta_connected) {
4996 qdf_mutex_release(&hdd_ipa->event_lock);
4997 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004998 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07004999 qdf_mutex_acquire(&hdd_ipa->event_lock);
5000 }
5001
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005002 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005003 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005004 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005005
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005006 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005007
5008 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005009 break;
5010
5011 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005012 qdf_mutex_acquire(&hdd_ipa->event_lock);
5013
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005014 /* For DFS channel we get two start_bss event (before and after
5015 * CAC). Also when ACS range includes both DFS and non DFS
5016 * channels, we could possibly change channel many times due to
5017 * RADAR detection and chosen channel may not be a DFS channels.
5018 * So dont return error here. Just discard the event.
5019 */
Yun Park8f289c82016-10-18 16:38:21 -07005020 if (adapter->ipa_context) {
5021 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005023 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005024
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005025 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5026 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005027 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005028 hdd_err("%s: Evt: %d, Interface setup failed",
5029 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005030 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005031 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005032
Yun Park8f289c82016-10-18 16:38:21 -07005033 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5034 qdf_mutex_release(&hdd_ipa->event_lock);
5035 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005036 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005037 qdf_mutex_acquire(&hdd_ipa->event_lock);
5038 }
5039
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005040 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005041 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005042 (adapter->ipa_context))->iface_id;
5043
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305044 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045 break;
5046
5047 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305048 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049
5050 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005051 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005052 hdd_err("%s: Evt: %d, STA already disconnected",
5053 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005054 return -EINVAL;
5055 }
Yun Parka37592b2016-06-11 17:10:28 -07005056
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005057 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005058
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005059 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005060 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005061 msg_ex->name);
5062 } else {
5063 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005064 if (!hdd_ipa->num_iface &&
5065 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305066 hdd_ipa->activated_fw_pipe) &&
5067 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069 }
5070
Yun Park74127cf2016-09-18 11:22:41 -07005071 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5072 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005073 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005074 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005075 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005076 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005077 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5078 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 }
5080
Yun Park8f289c82016-10-18 16:38:21 -07005081 hdd_ipa_cleanup_iface(adapter->ipa_context);
5082
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305083 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005084 break;
5085
5086 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005087 qdf_mutex_acquire(&hdd_ipa->event_lock);
5088
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005090 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005091 hdd_err("%s: Evt: %d, SAP already disconnected",
5092 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093 return -EINVAL;
5094 }
5095
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096 if ((!hdd_ipa->num_iface) &&
5097 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305098 hdd_ipa->activated_fw_pipe) &&
5099 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005100 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101 /*
5102 * We disable WDI pipes directly here since
5103 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5104 * processed when unloading WLAN driver is in
5105 * progress
5106 */
5107 hdd_ipa_uc_disable_pipes(hdd_ipa);
5108 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305109 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005110 "NO INTF left but still pipe clean up");
5111 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5112 }
5113 }
5114
5115 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005116 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005118 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005119 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005120 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5121 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005122 }
Yun Parka37592b2016-06-11 17:10:28 -07005123
Yun Park8f289c82016-10-18 16:38:21 -07005124 hdd_ipa_cleanup_iface(adapter->ipa_context);
5125
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305126 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005127 break;
5128
5129 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005130 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005131 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305133 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134 return 0;
5135 }
5136
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305137 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5139 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005140 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305141 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005142 "%s: STA ID %d found, not valid",
5143 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005144 return 0;
5145 }
Yun Park312f71a2015-12-08 10:22:42 -08005146
5147 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005148 if (hdd_ipa->sap_num_connected_sta == 0 &&
5149 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005150 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005151 hdd_ipa->sta_connected) {
5152 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005153 hdd_ipa_uc_offload_enable_disable(
5154 hdd_get_adapter(hdd_ipa->hdd_ctx,
5155 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005156 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005157 qdf_mutex_acquire(&hdd_ipa->event_lock);
5158 }
Yun Parka37592b2016-06-11 17:10:28 -07005159
Yun Park312f71a2015-12-08 10:22:42 -08005160 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5161 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305162 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005163 "%s: handle 1st con ret %d",
5164 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005165
5166 if (hdd_ipa_uc_sta_is_enabled(
5167 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005168 hdd_ipa->sta_connected) {
5169 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005170 hdd_ipa_uc_offload_enable_disable(
5171 hdd_get_adapter(
5172 hdd_ipa->hdd_ctx,
5173 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005174 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005175 } else {
5176 qdf_mutex_release(&hdd_ipa->event_lock);
5177 }
Yun Parka37592b2016-06-11 17:10:28 -07005178
Yun Park312f71a2015-12-08 10:22:42 -08005179 return ret;
5180 }
5181 }
5182
5183 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005184
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305185 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005186
5187 meta.msg_type = type;
5188 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5189 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305190 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191
5192 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305193 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194 "msg_ex allocation failed");
5195 return -ENOMEM;
5196 }
5197 strlcpy(msg_ex->name, adapter->dev->name,
5198 IPA_RESOURCE_NAME_MAX);
5199 msg_ex->num_of_attribs = 1;
5200 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5201 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5202 msg_ex->attribs[0].offset =
5203 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5204 } else {
5205 msg_ex->attribs[0].offset =
5206 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5207 }
5208 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5209 IPA_MAC_ADDR_SIZE);
5210
5211 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5212
5213 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005214 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305215 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305216 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005217 return ret;
5218 }
5219 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005220 return ret;
5221
5222 case WLAN_CLIENT_DISCONNECT:
5223 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005224 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005225 "%s: IPA UC OFFLOAD NOT ENABLED",
5226 msg_ex->name);
5227 return 0;
5228 }
5229
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305230 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005232 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305233 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 "%s: STA ID %d NOT found, not valid",
5235 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 return 0;
5237 }
5238 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005239
Yun Park9b5030f2016-11-08 12:02:37 -08005240 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005241 if (!hdd_ipa->sap_num_connected_sta &&
5242 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005243 if ((false == hdd_ipa->resource_unloading)
5244 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305245 hdd_ipa->activated_fw_pipe) &&
5246 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005247 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5248 }
5249
Yun Park9b5030f2016-11-08 12:02:37 -08005250 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005251 hdd_ipa->sta_connected) {
5252 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005253 hdd_ipa_uc_offload_enable_disable(
5254 hdd_get_adapter(hdd_ipa->hdd_ctx,
5255 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005256 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005257 } else {
5258 qdf_mutex_release(&hdd_ipa->event_lock);
5259 }
Yun Park8f289c82016-10-18 16:38:21 -07005260 } else {
5261 qdf_mutex_release(&hdd_ipa->event_lock);
5262 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005263 break;
5264
5265 default:
5266 return 0;
5267 }
5268
5269 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305270 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005271 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305272 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005273 return -ENOMEM;
5274 }
5275
5276 meta.msg_type = type;
5277 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5278 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5279
Srinivas Girigowda97852372017-03-06 16:52:59 -08005280 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281 msg->name, meta.msg_type);
5282
5283 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5284
5285 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005286 hdd_err("%s: Evt: %d fail:%d",
5287 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305288 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289 return ret;
5290 }
5291
5292 hdd_ipa->stats.num_send_msg++;
5293
5294end:
5295 return ret;
5296}
5297
5298/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005299 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005300 * @adapter: adapter upon which the event was received
5301 * @sta_id: station id for the event
5302 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5303 * @mac_address: MAC address associated with the event
5304 *
5305 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5306 *
5307 * Return: 0 on success, negative errno value on error
5308 */
5309int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
5310 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5311{
5312 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005313 int ret = 0;
5314
5315 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005316
Leo Changa202b522016-10-14 16:13:50 -07005317 /* Data path offload only support for STA and SAP mode */
5318 if ((QDF_STA_MODE == adapter->device_mode) ||
5319 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005320 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005321
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005322 cds_ssr_unprotect(__func__);
5323
5324 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005325}
5326
5327/**
5328 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5329 * @hdd_ipa: Global HDD IPA context
5330 *
5331 * Return: None
5332 */
5333static void
5334hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5335{
5336 unsigned int pending_event_count;
5337 struct ipa_uc_pending_event *pending_event = NULL;
5338
5339 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005340 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005341 "%s, Pending Event Count %d", __func__, pending_event_count);
5342 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005343 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005344 "%s, No Pending Event", __func__);
5345 return;
5346 }
5347
5348 qdf_list_remove_front(&hdd_ipa->pending_event,
5349 (qdf_list_node_t **)&pending_event);
5350 while (pending_event != NULL) {
5351 __hdd_ipa_wlan_evt(pending_event->adapter,
5352 pending_event->type,
5353 pending_event->sta_id,
5354 pending_event->mac_addr);
5355 qdf_mem_free(pending_event);
5356 pending_event = NULL;
5357 qdf_list_remove_front(&hdd_ipa->pending_event,
5358 (qdf_list_node_t **)&pending_event);
5359 }
5360}
5361
5362/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005363 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5364 * @state: IPA RM state value
5365 *
5366 * Return: ASCII string representing the IPA RM state
5367 */
5368static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5369{
5370 switch (state) {
5371 case HDD_IPA_RM_RELEASED:
5372 return "RELEASED";
5373 case HDD_IPA_RM_GRANT_PENDING:
5374 return "GRANT_PENDING";
5375 case HDD_IPA_RM_GRANTED:
5376 return "GRANTED";
5377 }
5378
5379 return "UNKNOWN";
5380}
5381
5382/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005383 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005384 * @hdd_ctx: HDD global context
5385 *
5386 * Allocate hdd_ipa resources, ipa pipe resource and register
5387 * wlan interface with IPA module.
5388 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305389 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005390 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005391static QDF_STATUS __hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392{
5393 struct hdd_ipa_priv *hdd_ipa = NULL;
5394 int ret, i;
5395 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005396 struct ol_txrx_pdev_t *pdev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005397
5398 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305399 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005400
Yun Parkbaa62862017-01-18 13:43:34 -08005401 ENTER();
5402
5403 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005404 if (!pdev) {
5405 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5406 goto fail_return;
5407 }
5408
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305409 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305411 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005412 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005413 }
5414
5415 hdd_ctx->hdd_ipa = hdd_ipa;
5416 ghdd_ipa = hdd_ipa;
5417 hdd_ipa->hdd_ctx = hdd_ctx;
5418 hdd_ipa->num_iface = 0;
5419
5420 /* Create the interface context */
5421 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5422 iface_context = &hdd_ipa->iface_context[i];
5423 iface_context->hdd_ipa = hdd_ipa;
5424 iface_context->cons_client =
5425 hdd_ipa_adapter_2_client[i].cons_client;
5426 iface_context->prod_client =
5427 hdd_ipa_adapter_2_client[i].prod_client;
5428 iface_context->iface_id = i;
5429 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305430 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005431 }
5432 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005433 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5434 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435 }
5436
Leo Chang69c39692016-10-12 20:11:12 -07005437 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305438 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005439 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305440 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005441 qdf_list_create(&hdd_ipa->pending_event, 1000);
5442 qdf_mutex_create(&hdd_ipa->event_lock);
5443 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005444
5445 ret = hdd_ipa_setup_rm(hdd_ipa);
5446 if (ret)
5447 goto fail_setup_rm;
5448
5449 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5450 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305451 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005452 hdd_ipa->sap_num_connected_sta = 0;
5453 hdd_ipa->ipa_tx_packets_diff = 0;
5454 hdd_ipa->ipa_rx_packets_diff = 0;
5455 hdd_ipa->ipa_p_tx_packets = 0;
5456 hdd_ipa->ipa_p_rx_packets = 0;
5457 hdd_ipa->resource_loading = false;
5458 hdd_ipa->resource_unloading = false;
5459 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005460 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005461 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462 /* Setup IPA sys_pipe for MCC */
5463 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5464 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5465 if (ret)
5466 goto fail_create_sys_pipe;
5467 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005468 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5469 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005470
5471 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5472 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5473 hdd_ipa_uc_fw_op_event_handler);
5474 hdd_ipa->uc_op_work[i].msg = NULL;
5475 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005476 } else {
5477 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5478 if (ret)
5479 goto fail_create_sys_pipe;
5480 }
5481
Yun Parkbaa62862017-01-18 13:43:34 -08005482 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305483 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005484
5485fail_create_sys_pipe:
5486 hdd_ipa_destroy_rm_resource(hdd_ipa);
5487fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305488 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305489 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005490 hdd_ctx->hdd_ipa = NULL;
5491 ghdd_ipa = NULL;
5492fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08005493 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305494 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005495}
5496
5497/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005498 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5499 * @hdd_ctx: HDD global context
5500 *
5501 * Allocate hdd_ipa resources, ipa pipe resource and register
5502 * wlan interface with IPA module.
5503 *
5504 * Return: QDF_STATUS enumeration
5505 */
5506QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
5507{
5508 QDF_STATUS ret;
5509
5510 cds_ssr_protect(__func__);
5511 ret = __hdd_ipa_init(hdd_ctx);
5512 cds_ssr_unprotect(__func__);
5513
5514 return ret;
5515}
5516
Arun Khandavallicc544b32017-01-30 19:52:16 +05305517
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005518/**
Yun Parkf19e07d2015-11-20 11:34:27 -08005519 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
5520 * @hdd_ipa: pointer to HDD IPA struct
5521 *
5522 * Return: none
5523 */
Jeff Johnsond7720632016-10-05 16:04:32 -07005524static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08005525{
5526 struct ipa_uc_pending_event *pending_event = NULL;
5527
Anurag Chouhanffb21542016-02-17 14:33:03 +05305528 while (qdf_list_remove_front(&hdd_ipa->pending_event,
5529 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305530 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005531 }
5532
Anurag Chouhanffb21542016-02-17 14:33:03 +05305533 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005534}
5535
5536/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005537 * __hdd_ipa_cleanup - IPA cleanup function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005538 * @hdd_ctx: HDD global context
5539 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305540 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005541 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005542static QDF_STATUS __hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005543{
5544 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5545 int i;
5546 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305547 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005548 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5549
5550 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305551 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005552
5553 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5554 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5555 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5556 }
5557
5558 /* Teardown IPA sys_pipe for MCC */
5559 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5560 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5561
5562 hdd_ipa_destroy_rm_resource(hdd_ipa);
5563
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005564 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005565
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305566 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005567
Nirav Shahcbc6d722016-03-01 16:24:53 +05305568 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5569 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305570 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005571
5572 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005573 if (pm_tx_cb->ipa_tx_desc)
5574 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005575
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305576 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005577 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305578 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005579
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305580 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005581 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005582
5583 /* destory the interface lock */
5584 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5585 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305586 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587 }
5588
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005589 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005590 if (ipa_uc_dereg_rdyCB())
5591 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5592 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005593 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305594 qdf_mutex_destroy(&hdd_ipa->event_lock);
5595 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005596 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005597
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005598 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5599 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5600 hdd_ipa->uc_op_work[i].msg = NULL;
5601 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005602 }
5603
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305604 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005605 hdd_ctx->hdd_ipa = NULL;
5606
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305607 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005608}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005609
5610/**
5611 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5612 * @hdd_ctx: HDD global context
5613 *
5614 * Return: QDF_STATUS enumeration
5615 */
5616QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
5617{
5618 QDF_STATUS ret;
5619
5620 cds_ssr_protect(__func__);
5621 ret = __hdd_ipa_cleanup(hdd_ctx);
5622 cds_ssr_unprotect(__func__);
5623
5624 return ret;
5625}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005626#endif /* IPA_OFFLOAD */