blob: 3da984baa849faae174ec96efbebccce01a9e52e [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
jge62037862016-12-09 10:44:33 +08002 * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ipa.c
30 *
31 * WLAN HDD and ipa interface implementation
32 * Originally written by Qualcomm Atheros, Inc
33 */
34
35#ifdef IPA_OFFLOAD
36
37/* Include Files */
Dustin Brown0bec9a92017-08-17 15:44:34 -070038#include <linux/ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
42#include <linux/etherdevice.h>
43#include <linux/atomic.h>
44#include <linux/netdevice.h>
45#include <linux/skbuff.h>
46#include <linux/list.h>
47#include <linux/debugfs.h>
48#include <linux/inetdevice.h>
49#include <linux/ip.h>
50#include <wlan_hdd_softap_tx_rx.h>
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +053051#include <ol_txrx.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070052#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080053
54#include "cds_sched.h"
55
56#include "wma.h"
57#include "wma_api.h"
Prakash Dhavali87b38e32016-11-14 16:22:53 -080058#include "wal_rx_desc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
Dhanashri Atreb08959a2016-03-01 17:28:03 -080060#include "cdp_txrx_ipa.h"
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080061#include "wlan_policy_mgr_api.h"
62
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
Yun Parkb4f591d2017-03-29 15:51:01 -070065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066#define HDD_IPA_UC_NUM_WDI_PIPE 2
67#define HDD_IPA_UC_MAX_PENDING_EVENT 33
68
69#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
70#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
71#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
72#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
73
74#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
75#define HDD_IPA_MAX_IFACE 3
76#define HDD_IPA_MAX_SYSBAM_PIPE 4
Yun Parkb4f591d2017-03-29 15:51:01 -070077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080078#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
79#define HDD_IPA_ENABLE_MASK BIT(0)
80#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
81#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
82#define HDD_IPA_RM_ENABLE_MASK BIT(3)
83#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
84#define HDD_IPA_UC_ENABLE_MASK BIT(5)
85#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
86#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
87
Yun Parkf19e07d2015-11-20 11:34:27 -080088#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
89
tfyu0380a972017-07-13 18:19:37 +080090#define IPA_WLAN_RX_SOFTIRQ_THRESH 16
91
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -070092enum hdd_ipa_uc_op_code {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
94 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
95 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
96 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
97 HDD_IPA_UC_OPCODE_STATS = 4,
Yun Park637d6482016-10-05 10:51:33 -070098#ifdef FEATURE_METERING
99 HDD_IPA_UC_OPCODE_SHARING_STATS = 5,
100 HDD_IPA_UC_OPCODE_QUOTA_RSP = 6,
101 HDD_IPA_UC_OPCODE_QUOTA_IND = 7,
102#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800103 HDD_IPA_UC_OPCODE_UC_READY = 8,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104 /* keep this last */
105 HDD_IPA_UC_OPCODE_MAX
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700106};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800107
108/**
109 * enum - Reason codes for stat query
110 *
111 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
112 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
113 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
Yun Parkb187d542016-11-14 18:10:04 -0800114 * @HDD_IPA_UC_STAT_REASON_DUMP_INFO: For debug info dump
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800115 */
116enum {
117 HDD_IPA_UC_STAT_REASON_NONE,
118 HDD_IPA_UC_STAT_REASON_DEBUG,
Yun Park46255682017-10-09 15:56:34 -0700119 HDD_IPA_UC_STAT_REASON_BW_CAL
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800120};
121
122/**
123 * enum hdd_ipa_rm_state - IPA resource manager state
124 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
125 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
126 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
127 */
128enum hdd_ipa_rm_state {
129 HDD_IPA_RM_RELEASED,
130 HDD_IPA_RM_GRANT_PENDING,
131 HDD_IPA_RM_GRANTED,
132};
133
134struct llc_snap_hdr {
135 uint8_t dsap;
136 uint8_t ssap;
137 uint8_t resv[4];
138 __be16 eth_type;
139} __packed;
140
Leo Chang3bc8fed2015-11-13 10:59:47 -0800141/**
142 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
143 * @eth: ether II header
144 * @llc_snap: LLC snap header
145 *
146 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800147struct hdd_ipa_tx_hdr {
148 struct ethhdr eth;
149 struct llc_snap_hdr llc_snap;
150} __packed;
151
Leo Chang3bc8fed2015-11-13 10:59:47 -0800152/**
153 * struct frag_header - fragment header type registered to IPA hardware
154 * @length: fragment length
155 * @reserved1: Reserved not used
156 * @reserved2: Reserved not used
157 *
158 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800159struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800160 uint16_t length;
161 uint32_t reserved1;
162 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800163} __packed;
164
Leo Chang3bc8fed2015-11-13 10:59:47 -0800165/**
166 * struct ipa_header - ipa header type registered to IPA hardware
167 * @vdev_id: vdev id
168 * @reserved: Reserved not used
169 *
170 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800171struct ipa_header {
172 uint32_t
173 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
174 reserved:24;
175} __packed;
176
Leo Chang3bc8fed2015-11-13 10:59:47 -0800177/**
178 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
179 * @frag_hd: fragment header
180 * @ipa_hd: ipa header
181 * @eth: ether II header
182 *
183 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800184struct hdd_ipa_uc_tx_hdr {
185 struct frag_header frag_hd;
186 struct ipa_header ipa_hd;
187 struct ethhdr eth;
188} __packed;
189
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800190/**
191 * struct hdd_ipa_cld_hdr - IPA CLD Header
192 * @reserved: reserved fields
193 * @iface_id: interface ID
194 * @sta_id: Station ID
195 *
196 * Packed 32-bit structure
197 * +----------+----------+--------------+--------+
198 * | Reserved | QCMAP ID | interface id | STA ID |
199 * +----------+----------+--------------+--------+
200 */
201struct hdd_ipa_cld_hdr {
202 uint8_t reserved[2];
203 uint8_t iface_id;
204 uint8_t sta_id;
205} __packed;
206
207struct hdd_ipa_rx_hdr {
208 struct hdd_ipa_cld_hdr cld_hdr;
209 struct ethhdr eth;
210} __packed;
211
212struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700213 bool exception;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700214 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800215 struct hdd_ipa_iface_context *iface_context;
216 struct ipa_rx_data *ipa_tx_desc;
217};
218
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800219struct hdd_ipa_sys_pipe {
220 uint32_t conn_hdl;
221 uint8_t conn_hdl_valid;
222 struct ipa_sys_connect_params ipa_sys_params;
223};
224
225struct hdd_ipa_iface_stats {
226 uint64_t num_tx;
227 uint64_t num_tx_drop;
228 uint64_t num_tx_err;
229 uint64_t num_tx_cac_drop;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800230 uint64_t num_rx_ipa_excep;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800231};
232
233struct hdd_ipa_priv;
234
235struct hdd_ipa_iface_context {
236 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700237 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800238 void *tl_context;
239
240 enum ipa_client_type cons_client;
241 enum ipa_client_type prod_client;
242
243 uint8_t iface_id; /* This iface ID */
244 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530245 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800246 uint32_t ifa_address;
247 struct hdd_ipa_iface_stats stats;
248};
249
250struct hdd_ipa_stats {
251 uint32_t event[IPA_WLAN_EVENT_MAX];
252 uint64_t num_send_msg;
253 uint64_t num_free_msg;
254
255 uint64_t num_rm_grant;
256 uint64_t num_rm_release;
257 uint64_t num_rm_grant_imm;
258 uint64_t num_cons_perf_req;
259 uint64_t num_prod_perf_req;
260
261 uint64_t num_rx_drop;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800262
Yun Park52b2b992016-09-22 15:49:51 -0700263 uint64_t num_tx_desc_q_cnt;
264 uint64_t num_tx_desc_error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800265 uint64_t num_tx_comp_cnt;
266 uint64_t num_tx_queued;
267 uint64_t num_tx_dequeued;
268 uint64_t num_max_pm_queue;
269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800270 uint64_t num_rx_excep;
Yun Parkb187d542016-11-14 18:10:04 -0800271 uint64_t num_tx_fwd_ok;
272 uint64_t num_tx_fwd_err;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800273};
274
275struct ipa_uc_stas_map {
276 bool is_reserved;
277 uint8_t sta_id;
278};
279struct op_msg_type {
280 uint8_t msg_t;
281 uint8_t rsvd;
282 uint16_t op_code;
283 uint16_t len;
284 uint16_t rsvd_snd;
285};
286
287struct ipa_uc_fw_stats {
288 uint32_t tx_comp_ring_base;
289 uint32_t tx_comp_ring_size;
290 uint32_t tx_comp_ring_dbell_addr;
291 uint32_t tx_comp_ring_dbell_ind_val;
292 uint32_t tx_comp_ring_dbell_cached_val;
293 uint32_t tx_pkts_enqueued;
294 uint32_t tx_pkts_completed;
295 uint32_t tx_is_suspend;
296 uint32_t tx_reserved;
297 uint32_t rx_ind_ring_base;
298 uint32_t rx_ind_ring_size;
299 uint32_t rx_ind_ring_dbell_addr;
300 uint32_t rx_ind_ring_dbell_ind_val;
301 uint32_t rx_ind_ring_dbell_ind_cached_val;
302 uint32_t rx_ind_ring_rdidx_addr;
303 uint32_t rx_ind_ring_rd_idx_cached_val;
304 uint32_t rx_refill_idx;
305 uint32_t rx_num_pkts_indicated;
306 uint32_t rx_buf_refilled;
307 uint32_t rx_num_ind_drop_no_space;
308 uint32_t rx_num_ind_drop_no_buf;
309 uint32_t rx_is_suspend;
310 uint32_t rx_reserved;
311};
312
313struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530314 qdf_list_node_t node;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700315 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800316 enum ipa_wlan_event type;
317 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530318 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800319};
320
321/**
322 * struct uc_rm_work_struct
323 * @work: uC RM work
324 * @event: IPA RM event
325 */
326struct uc_rm_work_struct {
327 struct work_struct work;
328 enum ipa_rm_event event;
329};
330
331/**
332 * struct uc_op_work_struct
333 * @work: uC OP work
334 * @msg: OP message
335 */
336struct uc_op_work_struct {
337 struct work_struct work;
338 struct op_msg_type *msg;
339};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340
341/**
342 * struct uc_rt_debug_info
343 * @time: system time
344 * @ipa_excep_count: IPA exception packet count
345 * @rx_drop_count: IPA Rx drop packet count
346 * @net_sent_count: IPA Rx packet sent to network stack count
347 * @rx_discard_count: IPA Rx discard packet count
Yun Parkb187d542016-11-14 18:10:04 -0800348 * @tx_fwd_ok_count: IPA Tx forward success packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800349 * @tx_fwd_count: IPA Tx forward packet count
350 * @rx_destructor_call: IPA Rx packet destructor count
351 */
352struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530353 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800354 uint64_t ipa_excep_count;
355 uint64_t rx_drop_count;
356 uint64_t net_sent_count;
357 uint64_t rx_discard_count;
Yun Parkb187d542016-11-14 18:10:04 -0800358 uint64_t tx_fwd_ok_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800359 uint64_t tx_fwd_count;
360 uint64_t rx_destructor_call;
361};
362
Yun Park637d6482016-10-05 10:51:33 -0700363#ifdef FEATURE_METERING
364struct ipa_uc_sharing_stats {
365 uint64_t ipv4_rx_packets;
366 uint64_t ipv4_rx_bytes;
367 uint64_t ipv6_rx_packets;
368 uint64_t ipv6_rx_bytes;
369 uint64_t ipv4_tx_packets;
370 uint64_t ipv4_tx_bytes;
371 uint64_t ipv6_tx_packets;
372 uint64_t ipv6_tx_bytes;
373};
374
375struct ipa_uc_quota_rsp {
376 uint8_t success;
377 uint8_t reserved[3];
378 uint32_t quota_lo; /* quota limit low bytes */
379 uint32_t quota_hi; /* quota limit high bytes */
380};
381
382struct ipa_uc_quota_ind {
383 uint64_t quota_bytes; /* quota limit in bytes */
384};
385#endif
386
Yun Park52b2b992016-09-22 15:49:51 -0700387/**
388 * struct hdd_ipa_tx_desc
389 * @link: link to list head
390 * @priv: pointer to priv list entry
391 * @id: Tx desc idex
392 * @ipa_tx_desc_ptr: pointer to IPA Tx descriptor
393 */
394struct hdd_ipa_tx_desc {
395 struct list_head link;
396 void *priv;
397 uint32_t id;
398 struct ipa_rx_data *ipa_tx_desc_ptr;
399};
400
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800401struct hdd_ipa_priv {
402 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
403 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
404 uint8_t num_iface;
405 enum hdd_ipa_rm_state rm_state;
406 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530407 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800408 * APIs as it is taken care gracefully. Without this, kernel would throw
409 * an warning if spin_lock_bh is used while IRQ is disabled
410 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530411 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800412 struct uc_rm_work_struct uc_rm_work;
413 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530414 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800415 struct delayed_work wake_lock_work;
416 bool wake_lock_released;
417
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800418 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530419 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800420 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530421 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800422 bool suspended;
423
Yun Park52b2b992016-09-22 15:49:51 -0700424 qdf_spinlock_t q_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800425
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800426 struct list_head pend_desc_head;
Yun Park52b2b992016-09-22 15:49:51 -0700427 struct hdd_ipa_tx_desc *tx_desc_list;
428 struct list_head free_tx_desc_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800429
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700430 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800431 struct hdd_ipa_stats stats;
432
433 struct notifier_block ipv4_notifier;
434 uint32_t curr_prod_bw;
435 uint32_t curr_cons_bw;
436
437 uint8_t activated_fw_pipe;
438 uint8_t sap_num_connected_sta;
439 uint8_t sta_connected;
440 uint32_t tx_pipe_handle;
441 uint32_t rx_pipe_handle;
442 bool resource_loading;
443 bool resource_unloading;
444 bool pending_cons_req;
445 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530446 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530447 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700448 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800449 uint32_t ipa_tx_packets_diff;
450 uint32_t ipa_rx_packets_diff;
451 uint32_t ipa_p_tx_packets;
452 uint32_t ipa_p_rx_packets;
453 uint32_t stat_req_reason;
454 uint64_t ipa_tx_forward;
455 uint64_t ipa_rx_discard;
456 uint64_t ipa_rx_net_send_count;
Yun Park46255682017-10-09 15:56:34 -0700457 uint64_t ipa_rx_internal_drop_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800458 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530459 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800460 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
461 unsigned int rt_buf_fill_index;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800462 struct ipa_wdi_in_params cons_pipe_in;
463 struct ipa_wdi_in_params prod_pipe_in;
464 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800465 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530466 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530467 qdf_mutex_t rt_debug_lock;
468 qdf_mutex_t ipa_lock;
Yun Parkb4f591d2017-03-29 15:51:01 -0700469
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800470 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
471 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Yun Park637d6482016-10-05 10:51:33 -0700472#ifdef FEATURE_METERING
473 struct ipa_uc_sharing_stats ipa_sharing_stats;
474 struct ipa_uc_quota_rsp ipa_quota_rsp;
475 struct ipa_uc_quota_ind ipa_quota_ind;
476 struct completion ipa_uc_sharing_stats_comp;
477 struct completion ipa_uc_set_quota_comp;
478#endif
Yun Park777d7242017-03-30 15:38:33 -0700479 struct completion ipa_resource_comp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800480};
481
Leo Changcc923e22016-06-16 15:29:03 -0700482#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
483#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800484#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
485#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
486#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
487#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
488#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700489#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
490 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800491
492#define HDD_IPA_GET_IFACE_ID(_data) \
493 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
494
495#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530496 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800497 "%s:%d: "fmt, __func__, __LINE__, ## args)
498
Govind Singhb6a89772016-08-12 11:23:35 +0530499#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
500 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
501 "%s:%d: "fmt, __func__, __LINE__, ## args)
502
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800503#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
504 do { \
Yun Parkec845302016-12-15 09:22:57 -0800505 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
506 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507 } while (0)
508
509#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
510 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
511
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800512#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
513
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700514#if defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)
Leo Chang63d73612016-10-18 18:09:43 -0700515#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800516#else
517/* Do nothing */
Leo Chang63d73612016-10-18 18:09:43 -0700518#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700519#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800520
Yun Park0dad1002017-07-14 14:57:01 -0700521#define HDD_IPA_DBG_DUMP_RX_LEN 84
Yun Parkb187d542016-11-14 18:10:04 -0800522#define HDD_IPA_DBG_DUMP_TX_LEN 48
523
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800524static struct hdd_ipa_adapter_2_client {
525 enum ipa_client_type cons_client;
526 enum ipa_client_type prod_client;
527} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
528 {
529 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
530 }, {
531 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
532 }, {
533 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
534 },
535};
536
Yun Park637d6482016-10-05 10:51:33 -0700537#ifdef FEATURE_METERING
538#define IPA_UC_SHARING_STATES_WAIT_TIME 500
539#define IPA_UC_SET_QUOTA_WAIT_TIME 500
540#endif
541
Yun Park777d7242017-03-30 15:38:33 -0700542#define IPA_RESOURCE_COMP_WAIT_TIME 100
543
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800544static struct hdd_ipa_priv *ghdd_ipa;
545
546/* Local Function Prototypes */
547static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
548 unsigned long data);
549static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
550 unsigned long data);
Yun Parkb4f591d2017-03-29 15:51:01 -0700551#ifdef FEATURE_METERING
552static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
553 void *data);
554#else
555static void hdd_ipa_wdi_meter_notifier_cb(void);
556#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800557static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800558
559static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700560static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800561
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800562#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
563 defined(IPA_CLIENT_IS_MHI_CONS))
564/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800565 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
566 * @priv_ctxt: hdd ipa local context
567 *
568 * Will be called by IPA context.
569 * It's atomic context, then should be scheduled to kworker thread
570 *
571 * Return: None
572 */
573static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
574{
575 struct hdd_ipa_priv *hdd_ipa;
576 struct op_msg_type *msg;
577 struct uc_op_work_struct *uc_op_work;
578
579 if (priv_ctxt == NULL) {
580 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
581 return;
582 }
583
584 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
585 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
586 if (!msg) {
587 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
588 return;
589 }
590
591 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
592
593 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
594
595 /* When the same uC OPCODE is already pended, just return */
596 if (uc_op_work->msg)
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530597 goto done;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800598
599 uc_op_work->msg = msg;
600 schedule_work(&uc_op_work->work);
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530601
jiadd91a6842017-08-01 14:46:02 +0800602 /* work handler will free the msg buffer */
603 return;
604
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530605done:
606 qdf_mem_free(msg);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800607}
608
609/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800610 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
611 * @ctrl: WDI control value
612 *
613 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
614 *
615 * Return: 0 on message send to ipa, -1 on failure
616 */
617static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
618{
619 struct ipa_msg_meta meta;
620 struct ipa_wlan_msg *ipa_msg;
621 int ret = 0;
622
623 /* WDI enable message to IPA */
624 meta.msg_len = sizeof(*ipa_msg);
625 ipa_msg = qdf_mem_malloc(meta.msg_len);
626 if (ipa_msg == NULL) {
627 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
628 "msg allocation failed");
629 return -ENOMEM;
630 }
631
632 if (ctrl == true)
633 meta.msg_type = WLAN_WDI_ENABLE;
634 else
635 meta.msg_type = WLAN_WDI_DISABLE;
636
Srinivas Girigowda97852372017-03-06 16:52:59 -0800637 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800638 "ipa_send_msg(Evt:%d)", meta.msg_type);
639 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
640 if (ret) {
641 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
642 "ipa_send_msg(Evt:%d)-fail=%d",
643 meta.msg_type, ret);
644 qdf_mem_free(ipa_msg);
645 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800646 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800647}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800648
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800649/**
650 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
651 * @hdd_ipa: HDD IPA local context
652 *
653 * Register IPA UC ready callback function to IPA kernel driver
654 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
655 * open WDI pipe after WLAN driver loading finished
656 *
657 * Return: 0 Success
658 * -EPERM Registration fail
659 */
660static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
661{
662 struct ipa_wdi_uc_ready_params uc_ready_param;
663 int ret = 0;
664
665 hdd_ipa->uc_loaded = false;
666 uc_ready_param.priv = (void *)hdd_ipa;
667 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
668 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
669 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
670 "UC Ready CB register fail");
671 return -EPERM;
672 }
673 if (true == uc_ready_param.is_uC_ready) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700674 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800675 hdd_ipa->uc_loaded = true;
676 } else {
677 ret = hdd_ipa_uc_send_wdi_control_msg(false);
678 }
679
680 return ret;
681}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800682#else
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800683static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
684{
685 hdd_ipa->uc_loaded = true;
686 return 0;
687}
688
689static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
690{
691 return 0;
692}
693#endif
694
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800695/**
696 * hdd_ipa_is_enabled() - Is IPA enabled?
697 * @hdd_ctx: Global HDD context
698 *
699 * Return: true if IPA is enabled, false otherwise
700 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700701bool hdd_ipa_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800702{
703 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
704}
705
706/**
707 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
708 * @hdd_ctx: Global HDD context
709 *
710 * Return: true if IPA uC offload is enabled, false otherwise
711 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700712bool hdd_ipa_uc_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800713{
714 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
715}
716
717/**
718 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
719 * @hdd_ctx: Global HDD context
720 *
721 * Return: true if STA mode IPA uC offload is enabled, false otherwise
722 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700723static inline bool hdd_ipa_uc_sta_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800724{
725 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
726}
727
728/**
Guolei Bianca144d82016-11-10 11:07:42 +0800729 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
730 * @hdd_ipa: Global HDD IPA context
731 *
732 * Return: None
733 */
Guolei Bianca144d82016-11-10 11:07:42 +0800734static inline void hdd_ipa_uc_sta_reset_sta_connected(
735 struct hdd_ipa_priv *hdd_ipa)
736{
Yun Park637d6482016-10-05 10:51:33 -0700737 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800738 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700739 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800740}
Guolei Bianca144d82016-11-10 11:07:42 +0800741
742/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800743 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
744 * @hdd_ipa: Global HDD IPA context
745 *
746 * Return: true if pre-filter is enabled, otherwise false
747 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700748static inline bool hdd_ipa_is_pre_filter_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800749{
750 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
751 HDD_IPA_PRE_FILTER_ENABLE_MASK);
752}
753
754/**
755 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
756 * @hdd_ipa: Global HDD IPA context
757 *
758 * Return: true if IPv6 is enabled, otherwise false
759 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700760static inline bool hdd_ipa_is_ipv6_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800761{
762 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
763}
764
765/**
766 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
767 * @hdd_ipa: Global HDD IPA context
768 *
769 * Return: true if resource manager is enabled, otherwise false
770 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700771static inline bool hdd_ipa_is_rm_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800772{
773 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
774}
775
776/**
777 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
778 * @hdd_ipa: Global HDD IPA context
779 *
780 * Return: true if resource manager is enabled, otherwise false
781 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700782static inline bool hdd_ipa_is_rt_debugging_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800783{
784 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
785}
786
787/**
788 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
789 * @hdd_ipa: Global HDD IPA context
790 *
791 * Return: true if clock scaling is enabled, otherwise false
792 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700793static inline bool hdd_ipa_is_clk_scaling_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794{
795 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
796 HDD_IPA_CLK_SCALING_ENABLE_MASK |
797 HDD_IPA_RM_ENABLE_MASK);
798}
799
800/**
801 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
802 * @ctext: pointer to hdd context.
803 *
804 * If rt debug enabled, periodically called, and fill debug buffer
805 *
806 * Return: none
807 */
808static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
809{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700810 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800811 struct hdd_ipa_priv *hdd_ipa;
812 struct uc_rt_debug_info *dump_info = NULL;
813
814 if (wlan_hdd_validate_context(hdd_ctx))
815 return;
816
817 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700818 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800819 return;
820 }
821
822 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
823
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530824 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800825 dump_info = &hdd_ipa->rt_bug_buffer[
826 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
827
Deepthi Gowri6acee342016-10-28 15:00:38 +0530828 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800829 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
Yun Park46255682017-10-09 15:56:34 -0700830 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internal_drop_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800832 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800833 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
834 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800835 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
836 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530837 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838
Anurag Chouhan210db072016-02-22 18:42:15 +0530839 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800840 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
841}
842
843/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700844 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800845 * @hdd_ctx: pointer to hdd context.
846 *
847 * If rt debug enabled, dump debug buffer contents based on requirement
848 *
849 * Return: none
850 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700851static void __hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800852{
853 struct hdd_ipa_priv *hdd_ipa;
854 unsigned int dump_count;
855 unsigned int dump_index;
856 struct uc_rt_debug_info *dump_info = NULL;
857
858 if (wlan_hdd_validate_context(hdd_ctx))
859 return;
860
861 hdd_ipa = hdd_ctx->hdd_ipa;
862 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700863 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 return;
865 }
866
Chris Guo1751acf2017-07-03 14:09:01 +0800867 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
868 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -0700869 "IPA RT debug is not enabled");
Chris Guo1751acf2017-07-03 14:09:01 +0800870 return;
871 }
872
Yun Park46255682017-10-09 15:56:34 -0700873 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Yun Park46255682017-10-09 15:56:34 -0700875 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Parkb187d542016-11-14 18:10:04 -0800876 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800877
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530878 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800879 for (dump_count = 0;
880 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
881 dump_count++) {
882 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
883 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
884 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Yun Park46255682017-10-09 15:56:34 -0700885 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530886 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800887 dump_info->time, dump_info->ipa_excep_count,
888 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800889 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800890 dump_info->rx_destructor_call,
891 dump_info->rx_discard_count);
892 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530893 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Yun Park46255682017-10-09 15:56:34 -0700894 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800895 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
896}
897
898/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700899 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
900 * __hdd_ipa_uc_rt_debug_host_dump
901 * @hdd_ctx: pointer to hdd context.
902 *
903 * If rt debug enabled, dump debug buffer contents based on requirement
904 *
905 * Return: none
906 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700907void hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700908{
909 cds_ssr_protect(__func__);
910 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
911 cds_ssr_unprotect(__func__);
912}
913
914/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800915 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
916 * @ctext: pointer to hdd context.
917 *
918 * periodically called by timer expire
919 * will try to alloc dummy memory and detect out of memory condition
920 * if out of memory detected, dump wlan-ipa stats
921 *
922 * Return: none
923 */
924static void hdd_ipa_uc_rt_debug_handler(void *ctext)
925{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700926 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700927 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928 void *dummy_ptr = NULL;
929
930 if (wlan_hdd_validate_context(hdd_ctx))
931 return;
932
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700933 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
934
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800935 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700936 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
937 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800938 return;
939 }
940
941 /* Allocate dummy buffer periodically and free immediately. this will
942 * proactively detect OOM and if allocation fails dump ipa stats
943 */
944 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
945 GFP_KERNEL | GFP_ATOMIC);
946 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800947 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
948 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -0700949 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
950 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951 } else {
952 kfree(dummy_ptr);
953 }
954
Anurag Chouhan210db072016-02-22 18:42:15 +0530955 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800956 HDD_IPA_UC_RT_DEBUG_PERIOD);
957}
958
959/**
Yun Parkb187d542016-11-14 18:10:04 -0800960 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800961 * @skb: packet pinter
962 *
963 * when free data packet, will be invoked by wlan client and will increase
964 * free counter
965 *
966 * Return: none
967 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700968static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969{
970 if (!ghdd_ipa) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700971 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "invalid hdd context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800972 return;
973 }
974
975 ghdd_ipa->ipa_rx_destructor_count++;
976}
977
978/**
Yun Parkb187d542016-11-14 18:10:04 -0800979 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800980 * @hdd_ctx: hdd main context
981 *
982 * free all rt debugging resources
983 *
984 * Return: none
985 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700986static void hdd_ipa_uc_rt_debug_deinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800987{
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700988 struct hdd_ipa_priv *hdd_ipa;
989
990 if (wlan_hdd_validate_context(hdd_ctx))
991 return;
992
993 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530995 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800996
997 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700998 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
999 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000 return;
1001 }
1002
Anurag Chouhan210db072016-02-22 18:42:15 +05301003 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001004 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1005 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1006 }
1007 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1008
1009 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301010 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1011 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001012 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301013 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001014}
1015
1016/**
Yun Parkb187d542016-11-14 18:10:04 -08001017 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 * @hdd_ctx: hdd main context
1019 *
1020 * alloc and initialize all rt debugging resources
1021 *
1022 * Return: none
1023 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001024static void hdd_ipa_uc_rt_debug_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001025{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001026 struct hdd_ipa_priv *hdd_ipa;
1027
Chris Guo1751acf2017-07-03 14:09:01 +08001028 if (wlan_hdd_validate_context_in_loading(hdd_ctx))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001029 return;
1030
1031 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001032
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301033 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301035 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036 sizeof(struct uc_rt_debug_info) *
1037 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1038 hdd_ipa->ipa_tx_forward = 0;
1039 hdd_ipa->ipa_rx_discard = 0;
1040 hdd_ipa->ipa_rx_net_send_count = 0;
Yun Park46255682017-10-09 15:56:34 -07001041 hdd_ipa->ipa_rx_internal_drop_count = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001042 hdd_ipa->ipa_rx_destructor_count = 0;
1043
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 /* Reatime debug enable on feature enable */
1045 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001046 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1047 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048 return;
1049 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001050
1051 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1052 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1053 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1054 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1055
Anurag Chouhan210db072016-02-22 18:42:15 +05301056 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001057 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301058 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001059 HDD_IPA_UC_RT_DEBUG_PERIOD);
1060
1061}
1062
1063/**
Yun Parkb187d542016-11-14 18:10:04 -08001064 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1065 * @hdd_ipa: HDD IPA struct
1066 *
1067 * Dump entries in struct hdd_ipa
1068 *
1069 * Return: none
1070 */
1071static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1072{
1073 int i;
1074
1075 /* HDD IPA */
Yun Park46255682017-10-09 15:56:34 -07001076 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1077 "\n==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001078 "num_iface: %d\n"
1079 "rm_state: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001080 "rm_lock: %pK\n"
1081 "uc_rm_work: %pK\n"
1082 "uc_op_work: %pK\n"
1083 "wake_lock: %pK\n"
1084 "wake_lock_work: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001085 "wake_lock_released: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08001086 "tx_ref_cnt: %d\n"
1087 "pm_queue_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001088 "\thead: %pK\n"
1089 "\ttail: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001090 "\tqlen: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001091 "pm_work: %pK\n"
1092 "pm_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001093 "suspended: %d\n",
1094 hdd_ipa->num_iface,
1095 hdd_ipa->rm_state,
1096 &hdd_ipa->rm_lock,
1097 &hdd_ipa->uc_rm_work,
1098 &hdd_ipa->uc_op_work,
1099 &hdd_ipa->wake_lock,
1100 &hdd_ipa->wake_lock_work,
1101 hdd_ipa->wake_lock_released,
Yun Parkb187d542016-11-14 18:10:04 -08001102 hdd_ipa->tx_ref_cnt.counter,
1103 hdd_ipa->pm_queue_head.head,
1104 hdd_ipa->pm_queue_head.tail,
1105 hdd_ipa->pm_queue_head.qlen,
1106 &hdd_ipa->pm_work,
1107 &hdd_ipa->pm_lock,
1108 hdd_ipa->suspended);
Yun Park46255682017-10-09 15:56:34 -07001109
1110 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1111 "\nq_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001112 "pend_desc_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001113 "\tnext: %pK\n"
1114 "\tprev: %pK\n"
1115 "hdd_ctx: %pK\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001116 "stats: %pK\n"
1117 "ipv4_notifier: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001118 "curr_prod_bw: %d\n"
1119 "curr_cons_bw: %d\n"
1120 "activated_fw_pipe: %d\n"
1121 "sap_num_connected_sta: %d\n"
1122 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001123 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001124 hdd_ipa->pend_desc_head.next,
1125 hdd_ipa->pend_desc_head.prev,
1126 hdd_ipa->hdd_ctx,
Yun Parkb187d542016-11-14 18:10:04 -08001127 &hdd_ipa->stats,
1128 &hdd_ipa->ipv4_notifier,
1129 hdd_ipa->curr_prod_bw,
1130 hdd_ipa->curr_cons_bw,
1131 hdd_ipa->activated_fw_pipe,
1132 hdd_ipa->sap_num_connected_sta,
Yun Park46255682017-10-09 15:56:34 -07001133 (unsigned int)hdd_ipa->sta_connected);
1134
1135 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1136 "\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001137 "rx_pipe_handle: 0x%x\n"
1138 "resource_loading: %d\n"
1139 "resource_unloading: %d\n"
1140 "pending_cons_req: %d\n"
1141 "pending_event----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001142 "\tanchor.next: %pK\n"
1143 "\tanchor.prev: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001144 "\tcount: %d\n"
1145 "\tmax_size: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001146 "event_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001147 "ipa_tx_packets_diff: %d\n"
1148 "ipa_rx_packets_diff: %d\n"
1149 "ipa_p_tx_packets: %d\n"
1150 "ipa_p_rx_packets: %d\n"
1151 "stat_req_reason: %d\n",
1152 hdd_ipa->tx_pipe_handle,
1153 hdd_ipa->rx_pipe_handle,
1154 hdd_ipa->resource_loading,
1155 hdd_ipa->resource_unloading,
1156 hdd_ipa->pending_cons_req,
1157 hdd_ipa->pending_event.anchor.next,
1158 hdd_ipa->pending_event.anchor.prev,
1159 hdd_ipa->pending_event.count,
1160 hdd_ipa->pending_event.max_size,
1161 &hdd_ipa->event_lock,
1162 hdd_ipa->ipa_tx_packets_diff,
1163 hdd_ipa->ipa_rx_packets_diff,
1164 hdd_ipa->ipa_p_tx_packets,
1165 hdd_ipa->ipa_p_rx_packets,
1166 hdd_ipa->stat_req_reason);
1167
Yun Park46255682017-10-09 15:56:34 -07001168 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1169 "\ncons_pipe_in----\n"
1170 "\tsys: %pK\n"
1171 "\tdl.comp_ring_base_pa: 0x%x\n"
1172 "\tdl.comp_ring_size: %d\n"
1173 "\tdl.ce_ring_base_pa: 0x%x\n"
1174 "\tdl.ce_door_bell_pa: 0x%x\n"
1175 "\tdl.ce_ring_size: %d\n"
1176 "\tdl.num_tx_buffers: %d\n"
1177 "prod_pipe_in----\n"
1178 "\tsys: %pK\n"
1179 "\tul.rdy_ring_base_pa: 0x%x\n"
1180 "\tul.rdy_ring_size: %d\n"
1181 "\tul.rdy_ring_rp_pa: 0x%x\n"
1182 "uc_loaded: %d\n"
1183 "wdi_enabled: %d\n"
1184 "rt_debug_fill_timer: %pK\n"
1185 "rt_debug_lock: %pK\n"
1186 "ipa_lock: %pK\n",
1187 &hdd_ipa->cons_pipe_in.sys,
1188 (unsigned int)hdd_ipa->cons_pipe_in.u.dl.comp_ring_base_pa,
1189 hdd_ipa->cons_pipe_in.u.dl.comp_ring_size,
1190 (unsigned int)hdd_ipa->cons_pipe_in.u.dl.ce_ring_base_pa,
1191 (unsigned int)hdd_ipa->cons_pipe_in.u.dl.ce_door_bell_pa,
1192 hdd_ipa->cons_pipe_in.u.dl.ce_ring_size,
1193 hdd_ipa->cons_pipe_in.u.dl.num_tx_buffers,
1194 &hdd_ipa->prod_pipe_in.sys,
1195 (unsigned int)hdd_ipa->prod_pipe_in.u.ul.rdy_ring_base_pa,
1196 hdd_ipa->prod_pipe_in.u.ul.rdy_ring_size,
1197 (unsigned int)hdd_ipa->prod_pipe_in.u.ul.rdy_ring_rp_pa,
1198 hdd_ipa->uc_loaded,
1199 hdd_ipa->wdi_enabled,
1200 &hdd_ipa->rt_debug_fill_timer,
1201 &hdd_ipa->rt_debug_lock,
1202 &hdd_ipa->ipa_lock);
1203
1204 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1205 "\nvdev_to_iface----");
1206 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1207 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1208 "\n\t[%d]=%d", i, hdd_ipa->vdev_to_iface[i]);
1209 }
1210 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1211 "\nvdev_offload_enabled----");
1212 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
1213 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1214 "\n\t[%d]=%d", i, hdd_ipa->vdev_offload_enabled[i]);
1215 }
1216 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1217 "\nassoc_stas_map ----");
Yun Parkb187d542016-11-14 18:10:04 -08001218 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Yun Park46255682017-10-09 15:56:34 -07001219 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1220 "\n\t[%d]: is_reserved=%d, sta_id=%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001221 hdd_ipa->assoc_stas_map[i].is_reserved,
1222 hdd_ipa->assoc_stas_map[i].sta_id);
1223 }
1224}
1225
1226/**
1227 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1228 * @hdd_ipa: HDD IPA struct
1229 *
1230 * Dump entire struct hdd_ipa_sys_pipe
1231 *
1232 * Return: none
1233 */
1234static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1235{
1236 int i;
1237
1238 /* IPA SYS Pipes */
Yun Park46255682017-10-09 15:56:34 -07001239 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1240 "\n==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001241
1242 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1243 struct hdd_ipa_sys_pipe *sys_pipe;
1244 struct ipa_sys_connect_params *ipa_sys_params;
1245
1246 sys_pipe = &hdd_ipa->sys_pipe[i];
1247 ipa_sys_params = &sys_pipe->ipa_sys_params;
1248
Yun Park46255682017-10-09 15:56:34 -07001249 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1250 "\nsys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001251 "\tconn_hdl: 0x%x\n"
1252 "\tconn_hdl_valid: %d\n"
1253 "\tnat_en: %d\n"
1254 "\thdr_len %d\n"
1255 "\thdr_additional_const_len: %d\n"
1256 "\thdr_ofst_pkt_size_valid: %d\n"
1257 "\thdr_ofst_pkt_size: %d\n"
1258 "\thdr_little_endian: %d\n"
1259 "\tmode: %d\n"
1260 "\tclient: %d\n"
1261 "\tdesc_fifo_sz: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001262 "\tpriv: %pK\n"
1263 "\tnotify: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001264 "\tskip_ep_cfg: %d\n"
1265 "\tkeep_ipa_awake: %d\n",
1266 i,
1267 sys_pipe->conn_hdl,
1268 sys_pipe->conn_hdl_valid,
1269 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1270 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1271 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1272 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1273 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1274 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1275 ipa_sys_params->ipa_ep_cfg.mode.mode,
1276 ipa_sys_params->client,
1277 ipa_sys_params->desc_fifo_sz,
1278 ipa_sys_params->priv,
1279 ipa_sys_params->notify,
1280 ipa_sys_params->skip_ep_cfg,
1281 ipa_sys_params->keep_ipa_awake);
1282 }
1283}
1284
1285/**
1286 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1287 * @hdd_ipa: HDD IPA struct
1288 *
1289 * Dump entire struct hdd_ipa_iface_context
1290 *
1291 * Return: none
1292 */
1293static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1294{
1295 int i;
1296
1297 /* IPA Interface Contexts */
Yun Park46255682017-10-09 15:56:34 -07001298 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1299 "\n==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001300
1301 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1302 struct hdd_ipa_iface_context *iface_context;
1303
1304 iface_context = &hdd_ipa->iface_context[i];
1305
Yun Park46255682017-10-09 15:56:34 -07001306 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
1307 "\niface_context[%d]----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001308 "\thdd_ipa: %pK\n"
1309 "\tadapter: %pK\n"
1310 "\ttl_context: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001311 "\tcons_client: %d\n"
1312 "\tprod_client: %d\n"
1313 "\tiface_id: %d\n"
1314 "\tsta_id: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001315 "\tinterface_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001316 "\tifa_address: 0x%x\n",
1317 i,
1318 iface_context->hdd_ipa,
1319 iface_context->adapter,
1320 iface_context->tl_context,
1321 iface_context->cons_client,
1322 iface_context->prod_client,
1323 iface_context->iface_id,
1324 iface_context->sta_id,
1325 &iface_context->interface_lock,
1326 iface_context->ifa_address);
1327 }
1328}
1329
1330/**
1331 * hdd_ipa_dump_info() - dump HDD IPA struct
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001332 * @hdd_ctx: hdd main context
Yun Parkb187d542016-11-14 18:10:04 -08001333 *
1334 * Dump entire struct hdd_ipa
1335 *
1336 * Return: none
1337 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001338void hdd_ipa_dump_info(struct hdd_context *hdd_ctx)
Yun Parkb187d542016-11-14 18:10:04 -08001339{
1340 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1341
1342 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1343 hdd_ipa_dump_sys_pipe(hdd_ipa);
1344 hdd_ipa_dump_iface_context(hdd_ipa);
1345}
1346
1347/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001348 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1349 * enabled
1350 *
1351 * This routine is called to set TX flow info if IPA is enabled
1352 *
1353 * Return: None
1354 */
1355void hdd_ipa_set_tx_flow_info(void)
1356{
1357 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1358 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001359 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07001360 struct hdd_station_ctx *sta_ctx;
Jeff Johnson87251032017-08-29 13:31:11 -07001361 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -07001362 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001363 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1364 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1365 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1366 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1367 const char *p2pMode = "DEV";
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001368 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001369 cds_context_type *cds_ctx;
1370#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1371 uint8_t targetChannel = 0;
1372 uint8_t preAdapterChannel = 0;
1373 uint8_t channel24;
1374 uint8_t channel5;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001375 struct hdd_adapter *preAdapterContext = NULL;
1376 struct hdd_adapter *adapter2_4 = NULL;
1377 struct hdd_adapter *adapter5 = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001378 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1379#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1380 struct wlan_objmgr_psoc *psoc;
1381
1382 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1383 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001384 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001385 return;
1386 }
1387
1388 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1389 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001390 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001391 return;
1392 }
1393
1394 psoc = hdd_ctx->hdd_psoc;
1395 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1396 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001397 adapter = adapterNode->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001398 switch (adapter->device_mode) {
1399 case QDF_STA_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001400 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001401 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001402 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001403 staChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001404 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001405 qdf_copy_macaddr(&staBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001406 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001407#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1408 targetChannel = staChannel;
1409#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1410 }
1411 break;
1412 case QDF_P2P_CLIENT_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001413 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001414 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001415 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001416 p2pChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001417 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001418 qdf_copy_macaddr(&p2pBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001419 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001420 p2pMode = "CLI";
1421#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1422 targetChannel = p2pChannel;
1423#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1424 }
1425 break;
1426 case QDF_P2P_GO_MODE:
1427 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1428 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1429 if (hostapd_state->bssState == BSS_START
1430 && hostapd_state->qdf_status ==
1431 QDF_STATUS_SUCCESS) {
1432 p2pChannel = hdd_ap_ctx->operatingChannel;
1433 qdf_copy_macaddr(&p2pBssid,
1434 &adapter->macAddressCurrent);
1435#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1436 targetChannel = p2pChannel;
1437#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1438 }
1439 p2pMode = "GO";
1440 break;
1441 case QDF_SAP_MODE:
1442 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1443 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1444 if (hostapd_state->bssState == BSS_START
1445 && hostapd_state->qdf_status ==
1446 QDF_STATUS_SUCCESS) {
1447 apChannel = hdd_ap_ctx->operatingChannel;
1448 qdf_copy_macaddr(&apBssid,
1449 &adapter->macAddressCurrent);
1450#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1451 targetChannel = apChannel;
1452#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1453 }
1454 break;
1455 case QDF_IBSS_MODE:
1456 default:
1457 break;
1458 }
1459#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1460 if (targetChannel) {
1461 /*
1462 * This is first adapter detected as active
1463 * set as default for none concurrency case
1464 */
1465 if (!preAdapterChannel) {
1466 /* If IPA UC data path is enabled,
1467 * target should reserve extra tx descriptors
1468 * for IPA data path.
1469 * Then host data path should allow less TX
1470 * packet pumping in case IPA
1471 * data path enabled
1472 */
1473 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1474 (QDF_SAP_MODE == adapter->device_mode)) {
1475 adapter->tx_flow_low_watermark =
1476 hdd_ctx->config->TxFlowLowWaterMark +
1477 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1478 } else {
1479 adapter->tx_flow_low_watermark =
1480 hdd_ctx->config->
1481 TxFlowLowWaterMark;
1482 }
1483 adapter->tx_flow_high_watermark_offset =
1484 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1485 cdp_fc_ll_set_tx_pause_q_depth(soc,
1486 adapter->sessionId,
1487 hdd_ctx->config->TxFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001488 hdd_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001489 adapter->device_mode,
1490 targetChannel,
1491 adapter->tx_flow_low_watermark,
1492 adapter->tx_flow_low_watermark +
1493 adapter->tx_flow_high_watermark_offset,
1494 hdd_ctx->config->TxFlowMaxQueueDepth);
1495 preAdapterChannel = targetChannel;
1496 preAdapterContext = adapter;
1497 } else {
1498 /*
1499 * SCC, disable TX flow control for both
1500 * SCC each adapter cannot reserve dedicated
1501 * channel resource, as a result, if any adapter
1502 * blocked OS Q by flow control,
1503 * blocked adapter will lost chance to recover
1504 */
1505 if (preAdapterChannel == targetChannel) {
1506 /* Current adapter */
1507 adapter->tx_flow_low_watermark = 0;
1508 adapter->
1509 tx_flow_high_watermark_offset = 0;
1510 cdp_fc_ll_set_tx_pause_q_depth(soc,
1511 adapter->sessionId,
1512 hdd_ctx->config->
1513 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001514 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001515 hdd_device_mode_to_string(
1516 adapter->device_mode),
1517 adapter->device_mode,
1518 targetChannel,
1519 adapter->tx_flow_low_watermark,
1520 adapter->tx_flow_low_watermark +
1521 adapter->
1522 tx_flow_high_watermark_offset,
1523 hdd_ctx->config->
1524 TxHbwFlowMaxQueueDepth);
1525
1526 if (!preAdapterContext) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001527 hdd_err("SCC: Previous adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001528 continue;
1529 }
1530
1531 /* Previous adapter */
1532 preAdapterContext->
1533 tx_flow_low_watermark = 0;
1534 preAdapterContext->
1535 tx_flow_high_watermark_offset = 0;
1536 cdp_fc_ll_set_tx_pause_q_depth(soc,
1537 preAdapterContext->sessionId,
1538 hdd_ctx->config->
1539 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001540 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001541 hdd_device_mode_to_string(
1542 preAdapterContext->device_mode
1543 ),
1544 preAdapterContext->device_mode,
1545 targetChannel,
1546 preAdapterContext->
1547 tx_flow_low_watermark,
1548 preAdapterContext->
1549 tx_flow_low_watermark +
1550 preAdapterContext->
1551 tx_flow_high_watermark_offset,
1552 hdd_ctx->config->
1553 TxHbwFlowMaxQueueDepth);
1554 }
1555 /*
1556 * MCC, each adapter will have dedicated
1557 * resource
1558 */
1559 else {
1560 /* current channel is 2.4 */
1561 if (targetChannel <=
1562 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1563 channel24 = targetChannel;
1564 channel5 = preAdapterChannel;
1565 adapter2_4 = adapter;
1566 adapter5 = preAdapterContext;
1567 } else {
1568 /* Current channel is 5 */
1569 channel24 = preAdapterChannel;
1570 channel5 = targetChannel;
1571 adapter2_4 = preAdapterContext;
1572 adapter5 = adapter;
1573 }
1574
1575 if (!adapter5) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001576 hdd_err("MCC: 5GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001577 continue;
1578 }
1579 adapter5->tx_flow_low_watermark =
1580 hdd_ctx->config->
1581 TxHbwFlowLowWaterMark;
1582 adapter5->
1583 tx_flow_high_watermark_offset =
1584 hdd_ctx->config->
1585 TxHbwFlowHighWaterMarkOffset;
1586 cdp_fc_ll_set_tx_pause_q_depth(soc,
1587 adapter5->sessionId,
1588 hdd_ctx->config->
1589 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001590 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001591 hdd_device_mode_to_string(
1592 adapter5->device_mode),
1593 adapter5->device_mode,
1594 channel5,
1595 adapter5->tx_flow_low_watermark,
1596 adapter5->
1597 tx_flow_low_watermark +
1598 adapter5->
1599 tx_flow_high_watermark_offset,
1600 hdd_ctx->config->
1601 TxHbwFlowMaxQueueDepth);
1602
1603 if (!adapter2_4) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001604 hdd_err("MCC: 2.4GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001605 continue;
1606 }
1607 adapter2_4->tx_flow_low_watermark =
1608 hdd_ctx->config->
1609 TxLbwFlowLowWaterMark;
1610 adapter2_4->
1611 tx_flow_high_watermark_offset =
1612 hdd_ctx->config->
1613 TxLbwFlowHighWaterMarkOffset;
1614 cdp_fc_ll_set_tx_pause_q_depth(soc,
1615 adapter2_4->sessionId,
1616 hdd_ctx->config->
1617 TxLbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001618 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001619 hdd_device_mode_to_string(
1620 adapter2_4->device_mode),
1621 adapter2_4->device_mode,
1622 channel24,
1623 adapter2_4->
1624 tx_flow_low_watermark,
1625 adapter2_4->
1626 tx_flow_low_watermark +
1627 adapter2_4->
1628 tx_flow_high_watermark_offset,
1629 hdd_ctx->config->
1630 TxLbwFlowMaxQueueDepth);
1631
1632 }
1633 }
1634 }
1635 targetChannel = 0;
1636#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1637 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1638 adapterNode = pNext;
1639 }
1640 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1641}
1642
1643/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001644 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001645 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001646 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1647 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648 *
1649 * Return: true if IPA is enabled, false otherwise
1650 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001651static void __hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001652 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1653{
1654 struct hdd_ipa_priv *hdd_ipa;
1655
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001656 *ipa_tx_diff = 0;
1657 *ipa_rx_diff = 0;
1658
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001659 if (wlan_hdd_validate_context(hdd_ctx))
1660 return;
1661
1662 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1663
1664 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1665 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001666 return;
1667 }
1668
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301669 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001670 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1671 (false == hdd_ipa->resource_loading)) {
1672 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1673 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301675 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676}
1677
1678/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001679 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1680 * @hdd_ctx: Global HDD context
1681 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1682 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1683 *
1684 * Return: true if IPA is enabled, false otherwise
1685 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001686void hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001687 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1688{
1689 cds_ssr_protect(__func__);
1690 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1691 cds_ssr_unprotect(__func__);
1692}
1693
1694/**
1695 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001696 * @adapter: network adapter
1697 * @reason: STAT REQ Reason
1698 *
1699 * Return: None
1700 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07001701static void __hdd_ipa_uc_stat_request(struct hdd_adapter *adapter,
1702 uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001703{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001704 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001705 struct hdd_ipa_priv *hdd_ipa;
1706
Yun Park637d6482016-10-05 10:51:33 -07001707 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001709
Jeff Johnson399c6272017-08-30 10:51:00 -07001710 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001711
1712 if (wlan_hdd_validate_context(hdd_ctx))
1713 return;
1714
1715 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1716 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1717 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001718 return;
1719 }
1720
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301721 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001722 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1723 (false == hdd_ipa->resource_loading)) {
1724 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001725 qdf_mutex_release(&hdd_ipa->ipa_lock);
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001726 sme_ipa_uc_stat_request(WLAN_HDD_GET_HAL_CTX(adapter),
1727 adapter->sessionId,
1728 WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001729 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001730 } else {
1731 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001732 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001733}
1734
1735/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001736 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1737 * @adapter: network adapter
1738 * @reason: STAT REQ Reason
1739 *
1740 * Return: None
1741 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001742void hdd_ipa_uc_stat_request(struct hdd_adapter *adapter, uint8_t reason)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001743{
1744 cds_ssr_protect(__func__);
1745 __hdd_ipa_uc_stat_request(adapter, reason);
1746 cds_ssr_unprotect(__func__);
1747}
1748
Yun Park637d6482016-10-05 10:51:33 -07001749#ifdef FEATURE_METERING
1750/**
1751 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1752 * @adapter: network adapter
1753 * @reset_stats: reset stat countis after response
1754 *
1755 * Return: None
1756 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001757void hdd_ipa_uc_sharing_stats_request(struct hdd_adapter *adapter,
Yun Park637d6482016-10-05 10:51:33 -07001758 uint8_t reset_stats)
1759{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001760 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001761 struct hdd_ipa_priv *hdd_ipa;
1762
1763 if (!adapter)
1764 return;
1765
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001766 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1767 hdd_ipa = hdd_ctx->hdd_ipa;
1768 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1769 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001770 return;
1771 }
1772
1773 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1774 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001775 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001776 qdf_mutex_release(&hdd_ipa->ipa_lock);
1777 wma_cli_set_command(
1778 (int)adapter->sessionId,
1779 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1780 reset_stats, VDEV_CMD);
1781 } else {
1782 qdf_mutex_release(&hdd_ipa->ipa_lock);
1783 }
1784}
1785
1786/**
1787 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1788 * @adapter: network adapter
1789 * @set_quota: when 1, FW starts quota monitoring
1790 * @quota_bytes: quota limit in bytes
1791 *
1792 * Return: None
1793 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001794void hdd_ipa_uc_set_quota(struct hdd_adapter *adapter, uint8_t set_quota,
Yun Park637d6482016-10-05 10:51:33 -07001795 uint64_t quota_bytes)
1796{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001797 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001798 struct hdd_ipa_priv *hdd_ipa;
1799
1800 if (!adapter)
1801 return;
1802
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001803 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1804 hdd_ipa = hdd_ctx->hdd_ipa;
1805 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1806 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001807 return;
1808 }
1809
1810 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1811 set_quota, quota_bytes);
1812
1813 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001814 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001815 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001816 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001817 (int)adapter->sessionId,
1818 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001819 (set_quota ? quota_bytes&0xffffffff : 0),
1820 (set_quota ? quota_bytes>>32 : 0),
1821 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001822 } else {
1823 qdf_mutex_release(&hdd_ipa->ipa_lock);
1824 }
1825}
1826#endif
1827
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001828/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001829 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1830 * @hdd_ipa: Global HDD IPA context
1831 * @sta_add: Should station be added
1832 * @sta_id: ID of the station being queried
1833 *
1834 * Return: true if the station was found
1835 */
1836static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1837 bool sta_add, uint8_t sta_id)
1838{
1839 bool sta_found = false;
1840 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001841
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001842 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1843 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1844 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1845 sta_found = true;
1846 break;
1847 }
1848 }
1849 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301850 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001851 "STA ID %d already exist, cannot add", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001852 return sta_found;
1853 }
1854 if (sta_add) {
1855 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1856 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1857 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1858 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1859 return sta_found;
1860 }
1861 }
1862 }
1863 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301864 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001865 "STA ID %d does not exist, cannot delete", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001866 return sta_found;
1867 }
1868 if (!sta_add) {
1869 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1870 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1871 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1872 hdd_ipa->assoc_stas_map[idx].is_reserved =
1873 false;
1874 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1875 return sta_found;
1876 }
1877 }
1878 }
1879 return sta_found;
1880}
1881
1882/**
1883 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1884 * @hdd_ipa: Global HDD IPA context
1885 *
1886 * Return: 0 on success, negative errno if error
1887 */
1888static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1889{
Yun Parkfec73dc2017-09-06 10:40:07 -07001890 int result = 0;
Leo Changfdb45c32016-10-28 11:09:23 -07001891 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001892 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893
Yun Park199c2ed2017-10-02 11:24:22 -07001894 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
1895
1896 if (!hdd_ipa->ipa_pipes_down) {
1897 /*
1898 * This shouldn't happen :
1899 * IPA WDI Pipes are already activated
1900 */
1901 WARN_ON(1);
1902 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
1903 "IPA WDI Pipes are already activated");
1904 goto end;
1905 }
Yun Parkfec73dc2017-09-06 10:40:07 -07001906
Yun Parkb4f591d2017-03-29 15:51:01 -07001907 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001908 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301909 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001910 "Enable PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001911 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001912 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001913
Yun Park777d7242017-03-30 15:38:33 -07001914 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Leo Change3e49442015-10-26 20:07:13 -07001915 hdd_ipa->ipa_pipes_down = false;
Yun Parkb4f591d2017-03-29 15:51:01 -07001916
1917 cdp_ipa_enable_autonomy(soc, (struct cdp_pdev *)pdev);
1918
Yun Parkfec73dc2017-09-06 10:40:07 -07001919end:
Yun Park199c2ed2017-10-02 11:24:22 -07001920 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: ipa_pipes_down=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07001921 hdd_ipa->ipa_pipes_down);
Yun Park199c2ed2017-10-02 11:24:22 -07001922
Yun Parkfec73dc2017-09-06 10:40:07 -07001923 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001924}
1925
1926/**
1927 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1928 * @hdd_ipa: Global HDD IPA context
1929 *
1930 * Return: 0 on success, negative errno if error
1931 */
1932static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1933{
Yun Parkb4f591d2017-03-29 15:51:01 -07001934 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1935 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkfec73dc2017-09-06 10:40:07 -07001936 int result = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001937
Yun Park199c2ed2017-10-02 11:24:22 -07001938 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
1939
1940 if (hdd_ipa->ipa_pipes_down) {
1941 /*
1942 * This shouldn't happen :
1943 * IPA WDI Pipes are already deactivated
1944 */
1945 WARN_ON(1);
1946 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
1947 "IPA WDI Pipes are already deactivated");
1948 goto end;
1949 }
Leo Change3e49442015-10-26 20:07:13 -07001950
Yun Parkb4f591d2017-03-29 15:51:01 -07001951 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001952
Yun Parkb4f591d2017-03-29 15:51:01 -07001953 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001954 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301955 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001956 "Disable WDI PIPE fail, code %d", result);
Yun Parkfec73dc2017-09-06 10:40:07 -07001957 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001958 }
1959
Yun Parkfec73dc2017-09-06 10:40:07 -07001960 hdd_ipa->ipa_pipes_down = true;
1961
1962end:
Yun Park199c2ed2017-10-02 11:24:22 -07001963 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: ipa_pipes_down=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07001964 hdd_ipa->ipa_pipes_down);
1965 return result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001966}
1967
1968/**
1969 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1970 * @hdd_ipa: Global HDD IPA context
1971 *
1972 * Return: 0 on success, negative errno if error
1973 */
1974static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1975{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001976 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07001977
Yun Park199c2ed2017-10-02 11:24:22 -07001978 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07001979
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001980 hdd_ipa->activated_fw_pipe = 0;
1981 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001982
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001983 /* If RM feature enabled
1984 * Request PROD Resource first
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07001985 * PROD resource may return sync or async manners
1986 */
Yun Parkb4f591d2017-03-29 15:51:01 -07001987 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001988 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1989 /* RM PROD request sync return
1990 * enable pipe immediately
1991 */
1992 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301993 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001994 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001995 hdd_ipa->resource_loading = false;
1996 return -EBUSY;
1997 }
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301998 } else {
1999 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park199c2ed2017-10-02 11:24:22 -07002000 "IPA WDI Pipe activation deferred");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002001 }
2002 } else {
2003 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07002004 * Just enabled all the PIPEs
2005 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302007 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002008 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009 hdd_ipa->resource_loading = false;
2010 return -EBUSY;
2011 }
2012 hdd_ipa->resource_loading = false;
2013 }
Yun Park4cab6ee2015-10-27 11:43:40 -07002014
Yun Park199c2ed2017-10-02 11:24:22 -07002015 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002016 return 0;
2017}
2018
2019/**
2020 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
2021 * @hdd_ipa: Global HDD IPA context
2022 *
2023 * Return: None
2024 */
2025static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
2026{
Leo Changfdb45c32016-10-28 11:09:23 -07002027 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07002028 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002029
Yun Park199c2ed2017-10-02 11:24:22 -07002030 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07002031
Yun Parkb4f591d2017-03-29 15:51:01 -07002032 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08002033 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
2034 QDF_ASSERT(0);
2035 return;
2036 }
2037
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002038 hdd_ipa->resource_unloading = true;
Yun Park777d7242017-03-30 15:38:33 -07002039 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Yun Parkb4f591d2017-03-29 15:51:01 -07002040 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
2041 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
2042 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
2043 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Yun Parkfec73dc2017-09-06 10:40:07 -07002044
Yun Park199c2ed2017-10-02 11:24:22 -07002045 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: IPA WDI Pipes deactivated");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002046}
2047
2048/**
2049 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
2050 * @context: User context registered with TL (the IPA Global context is
2051 * registered
2052 * @rxpkt: Packet containing the notification
2053 * @staid: ID of the station associated with the packet
2054 *
2055 * Return: None
2056 */
2057static void
2058hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
2059{
2060 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302061 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002062 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002063
2064 /*
2065 * When SSR is going on or driver is unloading, just return.
2066 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002067 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302068 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002069 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002070
Yun Parkb4f591d2017-03-29 15:51:01 -07002071 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002072 return;
2073
Yun Park46255682017-10-09 15:56:34 -07002074 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "event code %d",
2075 event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002076
2077 switch (event) {
2078 case IPA_RM_RESOURCE_GRANTED:
2079 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302080 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002081 if ((false == hdd_ipa->resource_unloading) &&
2082 (!hdd_ipa->activated_fw_pipe)) {
2083 hdd_ipa_uc_enable_pipes(hdd_ipa);
2084 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302085 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002086 break;
2087
2088 case IPA_RM_RESOURCE_RELEASED:
2089 /* Differed RM Released */
2090 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002091 break;
2092
2093 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302094 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07002095 "invalid event code %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002096 break;
2097 }
2098}
2099
2100/**
2101 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2102 * @hdd_ipa: Global HDD IPA context
2103 * @event: IPA resource manager event to be deferred
2104 *
2105 * This function is called when a resource manager event is received
2106 * from firmware in interrupt context. This function will defer the
2107 * handling to the OL RX thread
2108 *
2109 * Return: None
2110 */
2111static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2112{
2113 enum ipa_rm_event event;
2114 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2115 struct uc_rm_work_struct, work);
2116 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2117 struct hdd_ipa_priv, uc_rm_work);
2118
2119 cds_ssr_protect(__func__);
2120 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002121 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07002122 "posted event %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002123
2124 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2125 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002126}
2127
2128/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002129 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002130 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002131 *
2132 * Will handle IPA UC image loaded indication comes from IPA kernel
2133 *
2134 * Return: None
2135 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002136static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002137{
Yun Parkb4f591d2017-03-29 15:51:01 -07002138 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2139 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002140 struct hdd_context *hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07002141 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002142
Yun Park46255682017-10-09 15:56:34 -07002143 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC READY");
Yun Parkb4f591d2017-03-29 15:51:01 -07002144 if (true == hdd_ipa->uc_loaded) {
Yun Park46255682017-10-09 15:56:34 -07002145 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "UC already loaded");
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002146 return;
2147 }
2148
Yun Parkb4f591d2017-03-29 15:51:01 -07002149 hdd_ctx = hdd_ipa->hdd_ctx;
2150 hdd_ipa->uc_loaded = true;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002151
Yun Parkb4f591d2017-03-29 15:51:01 -07002152 /* Connect pipe */
2153 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2154 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2155 hdd_ipa_wdi_meter_notifier_cb,
2156 hdd_ctx->config->IpaDescSize,
2157 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2158 &hdd_ipa->tx_pipe_handle,
2159 &hdd_ipa->rx_pipe_handle);
2160 if (status) {
2161 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2162 "Failure to setup IPA pipes (status=%d)",
2163 status);
2164 return;
2165 }
2166
2167 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002168
2169 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002170 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002171 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002172 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002173 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002174 }
2175}
2176
2177/**
Yun Park637d6482016-10-05 10:51:33 -07002178 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2179 * @hdd_ctx: Global HDD context
2180 * @op_msg: operation message received from firmware
2181 *
2182 * Return: QDF_STATUS enumeration
2183 */
2184#ifdef FEATURE_METERING
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002185static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002186 struct op_msg_type *op_msg)
2187{
2188 struct op_msg_type *msg = op_msg;
2189 struct ipa_uc_sharing_stats *uc_sharing_stats;
2190 struct ipa_uc_quota_rsp *uc_quota_rsp;
2191 struct ipa_uc_quota_ind *uc_quota_ind;
2192 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002193 struct hdd_adapter *adapter;
Yun Park637d6482016-10-05 10:51:33 -07002194
2195 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2196
2197 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2198 /* fill-up ipa_uc_sharing_stats structure from FW */
2199 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2200 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2201
2202 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2203 sizeof(struct ipa_uc_sharing_stats));
2204
2205 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2206
2207 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2208 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2209 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2210 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2211 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2212 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2213 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2214 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2215 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2216 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2217 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2218 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2219 /* received set quota response */
2220 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2221 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2222
2223 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2224 sizeof(struct ipa_uc_quota_rsp));
2225
2226 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2227 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2228 "%s: success=%d, quota_bytes=%llu",
2229 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2230 hdd_ipa->ipa_quota_rsp.success,
2231 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2232 hdd_ipa->ipa_quota_rsp.quota_lo);
2233 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2234 /* hit quota limit */
2235 uc_quota_ind = (struct ipa_uc_quota_ind *)
2236 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2237
2238 hdd_ipa->ipa_quota_ind.quota_bytes =
2239 uc_quota_ind->quota_bytes;
2240
2241 /* send quota exceeded indication to IPA */
2242 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2243 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2244 hdd_ipa->ipa_quota_ind.quota_bytes);
2245
2246 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2247 if (adapter)
2248 ipa_broadcast_wdi_quota_reach_ind(
2249 adapter->dev->ifindex,
2250 uc_quota_ind->quota_bytes);
2251 else
2252 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2253 "Failed quota_reach_ind: NULL adapter");
2254 } else {
2255 return QDF_STATUS_E_INVAL;
2256 }
2257
2258 return QDF_STATUS_SUCCESS;
2259}
2260#else
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002261static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002262 struct op_msg_type *op_msg)
2263{
2264 return QDF_STATUS_E_INVAL;
2265}
2266#endif
2267
Yun Park657c7d72017-06-07 15:44:59 -07002268#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0))
2269/* older versions had a typo */
2270#define num_bam_int_in_non_running_state num_bam_int_in_non_runnning_state
2271#endif
2272
Yun Park637d6482016-10-05 10:51:33 -07002273/**
Yun Park46255682017-10-09 15:56:34 -07002274 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
2275 * @event: IPA WLAN event to be converted to a string
2276 *
2277 * Return: ASCII string representing the IPA WLAN event
2278 */
2279static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
2280{
2281 switch (event) {
2282 CASE_RETURN_STRING(WLAN_CLIENT_CONNECT);
2283 CASE_RETURN_STRING(WLAN_CLIENT_DISCONNECT);
2284 CASE_RETURN_STRING(WLAN_CLIENT_POWER_SAVE_MODE);
2285 CASE_RETURN_STRING(WLAN_CLIENT_NORMAL_MODE);
2286 CASE_RETURN_STRING(SW_ROUTING_ENABLE);
2287 CASE_RETURN_STRING(SW_ROUTING_DISABLE);
2288 CASE_RETURN_STRING(WLAN_AP_CONNECT);
2289 CASE_RETURN_STRING(WLAN_AP_DISCONNECT);
2290 CASE_RETURN_STRING(WLAN_STA_CONNECT);
2291 CASE_RETURN_STRING(WLAN_STA_DISCONNECT);
2292 CASE_RETURN_STRING(WLAN_CLIENT_CONNECT_EX);
2293 default:
2294 return "UNKNOWN";
2295 }
2296}
2297
2298/**
2299 * hdd_ipa_print_session_info - Print IPA session info
2300 * @hdd_ipa: HDD IPA local context
2301 *
2302 * Return: None
2303 */
2304static void hdd_ipa_print_session_info(struct hdd_ipa_priv *hdd_ipa)
2305{
2306 uint8_t session_id;
2307 int device_mode;
2308 struct ipa_uc_pending_event *event = NULL, *next = NULL;
2309 struct hdd_ipa_iface_context *iface_context = NULL;
2310 int i;
2311
2312 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2313 "\n==== IPA SESSION INFO ====\n"
2314 "NUM IFACE: %d\n"
2315 "RM STATE: %d\n"
2316 "ACTIVATED FW PIPE: %d\n"
2317 "SAP NUM STAs: %d\n"
2318 "STA CONNECTED: %d\n"
2319 "CONCURRENT MODE: %s\n"
2320 "RSC LOADING: %d\n"
2321 "RSC UNLOADING: %d\n"
2322 "PENDING CONS REQ: %d\n"
2323 "IPA PIPES DOWN: %d\n"
2324 "IPA UC LOADED: %d\n"
2325 "IPA WDI ENABLED: %d\n"
2326 "NUM SEND MSG: %d\n"
2327 "NUM FREE MSG: %d\n",
2328 hdd_ipa->num_iface,
2329 hdd_ipa->rm_state,
2330 hdd_ipa->activated_fw_pipe,
2331 hdd_ipa->sap_num_connected_sta,
2332 hdd_ipa->sta_connected,
2333 (hdd_ipa->hdd_ctx->mcc_mode ? "MCC" : "SCC"),
2334 hdd_ipa->resource_loading,
2335 hdd_ipa->resource_unloading,
2336 hdd_ipa->pending_cons_req,
2337 hdd_ipa->ipa_pipes_down,
2338 hdd_ipa->uc_loaded,
2339 hdd_ipa->wdi_enabled,
2340 (unsigned int)hdd_ipa->stats.num_send_msg,
2341 (unsigned int)hdd_ipa->stats.num_free_msg);
2342
2343 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2344 iface_context = &hdd_ipa->iface_context[i];
2345 if (!iface_context || !iface_context->adapter)
2346 continue;
2347
2348 session_id = iface_context->adapter->sessionId;
2349 if (session_id >= CSR_ROAM_SESSION_MAX)
2350 continue;
2351
2352 device_mode = iface_context->adapter->device_mode;
2353 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2354 "\nIFACE[%d]: session:%d, sta_id:%d, mode:%s, offload:%d",
2355 i, session_id,
2356 iface_context->sta_id,
2357 hdd_device_mode_to_string(device_mode),
2358 hdd_ipa->vdev_offload_enabled[session_id]);
2359 }
2360
2361 for (i = 0; i < IPA_WLAN_EVENT_MAX; i++)
2362 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2363 "\nEVENT[%d]=%d",
2364 i, hdd_ipa->stats.event[i]);
2365
2366 i = 0;
2367 qdf_list_peek_front(&hdd_ipa->pending_event,
2368 (qdf_list_node_t **)&event);
2369 while (event != NULL) {
2370 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2371 "\nPENDING EVENT[%d]: DEV:%s, EVT:%s, sta_id:%d, MAC:%pM",
2372 i, event->adapter->dev->name,
2373 hdd_ipa_wlan_event_to_str(event->type),
2374 event->sta_id, event->mac_addr);
2375
2376 qdf_list_peek_next(&hdd_ipa->pending_event,
2377 (qdf_list_node_t *)event, (qdf_list_node_t **)&next);
2378 event = next;
2379 next = NULL;
2380 i++;
2381 }
2382}
2383
2384/**
2385 * hdd_ipa_print_txrx_stats - Print HDD IPA TX/RX stats
2386 * @hdd_ipa: HDD IPA local context
2387 *
2388 * Return: None
2389 */
2390static void hdd_ipa_print_txrx_stats(struct hdd_ipa_priv *hdd_ipa)
2391{
2392 int i;
2393 struct hdd_ipa_iface_context *iface_context = NULL;
2394
2395 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2396 "\n==== HDD IPA TX/RX STATS ====\n"
2397 "NUM RM GRANT: %llu\n"
2398 "NUM RM RELEASE: %llu\n"
2399 "NUM RM GRANT IMM: %llu\n"
2400 "NUM CONS PERF REQ: %llu\n"
2401 "NUM PROD PERF REQ: %llu\n"
2402 "NUM RX DROP: %llu\n"
2403 "NUM EXCP PKT: %llu\n"
2404 "NUM TX FWD OK: %llu\n"
2405 "NUM TX FWD ERR: %llu\n"
2406 "NUM TX DESC Q CNT: %llu\n"
2407 "NUM TX DESC ERROR: %llu\n"
2408 "NUM TX COMP CNT: %llu\n"
2409 "NUM TX QUEUED: %llu\n"
2410 "NUM TX DEQUEUED: %llu\n"
2411 "NUM MAX PM QUEUE: %llu\n"
2412 "TX REF CNT: %d\n"
2413 "SUSPENDED: %d\n"
2414 "PEND DESC HEAD: %pK\n"
2415 "TX DESC LIST: %pK\n"
2416 "FREE TX DESC HEAD: %pK\n",
2417 hdd_ipa->stats.num_rm_grant,
2418 hdd_ipa->stats.num_rm_release,
2419 hdd_ipa->stats.num_rm_grant_imm,
2420 hdd_ipa->stats.num_cons_perf_req,
2421 hdd_ipa->stats.num_prod_perf_req,
2422 hdd_ipa->stats.num_rx_drop,
2423 hdd_ipa->stats.num_rx_excep,
2424 hdd_ipa->stats.num_tx_fwd_ok,
2425 hdd_ipa->stats.num_tx_fwd_err,
2426 hdd_ipa->stats.num_tx_desc_q_cnt,
2427 hdd_ipa->stats.num_tx_desc_error,
2428 hdd_ipa->stats.num_tx_comp_cnt,
2429 hdd_ipa->stats.num_tx_queued,
2430 hdd_ipa->stats.num_tx_dequeued,
2431 hdd_ipa->stats.num_max_pm_queue,
2432 hdd_ipa->tx_ref_cnt.counter,
2433 hdd_ipa->suspended,
2434 &hdd_ipa->pend_desc_head,
2435 hdd_ipa->tx_desc_list,
2436 &hdd_ipa->free_tx_desc_head);
2437
2438 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
2439 iface_context = &hdd_ipa->iface_context[i];
2440 if (!iface_context || !iface_context->adapter)
2441 continue;
2442
2443 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2444 "IFACE[%d]: TX:%llu, TX DROP:%llu, TX ERR:%llu, TX CAC DROP:%llu, RX IPA EXCEP:%llu",
2445 i,
2446 iface_context->stats.num_tx,
2447 iface_context->stats.num_tx_drop,
2448 iface_context->stats.num_tx_err,
2449 iface_context->stats.num_tx_cac_drop,
2450 iface_context->stats.num_rx_ipa_excep);
2451 }
2452}
2453
2454/**
2455 * hdd_ipa_print_fw_wdi_stats - Print WLAN FW WDI stats
2456 * @hdd_ipa: HDD IPA local context
2457 *
2458 * Return: None
2459 */
2460static void hdd_ipa_print_fw_wdi_stats(struct hdd_ipa_priv *hdd_ipa,
2461 struct ipa_uc_fw_stats *uc_fw_stat)
2462{
2463 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2464 "\n==== WLAN FW WDI TX STATS ====\n"
2465 "COMP RING BASE: 0x%x\n"
2466 "COMP RING SIZE: %d\n"
2467 "COMP RING DBELL : 0x%x\n"
2468 "COMP RING DBELL IND VAL : %d\n"
2469 "COMP RING DBELL CACHED VAL : %d\n"
2470 "PKTS ENQ : %d\n"
2471 "PKTS COMP : %d\n"
2472 "IS SUSPEND : %d\n",
2473 uc_fw_stat->tx_comp_ring_base,
2474 uc_fw_stat->tx_comp_ring_size,
2475 uc_fw_stat->tx_comp_ring_dbell_addr,
2476 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2477 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2478 uc_fw_stat->tx_pkts_enqueued,
2479 uc_fw_stat->tx_pkts_completed,
2480 uc_fw_stat->tx_is_suspend);
2481
2482 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2483 "\n==== WLAN FW WDI RX STATS ====\n"
2484 "IND RING BASE: 0x%x\n"
2485 "IND RING SIZE: %d\n"
2486 "IND RING DBELL : 0x%x\n"
2487 "IND RING DBELL IND VAL : %d\n"
2488 "IND RING DBELL CACHED VAL : %d\n"
2489 "RDY IND ADDR : 0x%x\n"
2490 "RDY IND CACHE VAL : %d\n"
2491 "RFIL IND : %d\n"
2492 "NUM PKT INDICAT : %d\n"
2493 "BUF REFIL : %d\n"
2494 "NUM DROP NO SPC : %d\n"
2495 "NUM DROP NO BUF : %d\n"
2496 "IS SUSPND : %d\n",
2497 uc_fw_stat->rx_ind_ring_base,
2498 uc_fw_stat->rx_ind_ring_size,
2499 uc_fw_stat->rx_ind_ring_dbell_addr,
2500 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2501 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2502 uc_fw_stat->rx_ind_ring_rdidx_addr,
2503 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2504 uc_fw_stat->rx_refill_idx,
2505 uc_fw_stat->rx_num_pkts_indicated,
2506 uc_fw_stat->rx_buf_refilled,
2507 uc_fw_stat->rx_num_ind_drop_no_space,
2508 uc_fw_stat->rx_num_ind_drop_no_buf,
2509 uc_fw_stat->rx_is_suspend);
2510}
2511
2512/**
2513 * hdd_ipa_print_ipa_wdi_stats - Print IPA WDI stats
2514 * @hdd_ipa: HDD IPA local context
2515 *
2516 * Return: None
2517 */
2518static void hdd_ipa_print_ipa_wdi_stats(struct hdd_ipa_priv *hdd_ipa)
2519{
2520 struct IpaHwStatsWDIInfoData_t ipa_stat;
2521
2522 ipa_get_wdi_stats(&ipa_stat);
2523
2524 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2525 "\n==== IPA WDI TX STATS ====\n"
2526 "NUM PROCD : %d\n"
2527 "CE DBELL : 0x%x\n"
2528 "NUM DBELL FIRED : %d\n"
2529 "COMP RNG FULL : %d\n"
2530 "COMP RNG EMPT : %d\n"
2531 "COMP RNG USE HGH : %d\n"
2532 "COMP RNG USE LOW : %d\n"
2533 "BAM FIFO FULL : %d\n"
2534 "BAM FIFO EMPT : %d\n"
2535 "BAM FIFO USE HGH : %d\n"
2536 "BAM FIFO USE LOW : %d\n"
2537 "NUM DBELL : %d\n"
2538 "NUM UNEXP DBELL : %d\n"
2539 "NUM BAM INT HDL : 0x%x\n"
2540 "NUM BAM INT NON-RUN : 0x%x\n"
2541 "NUM QMB INT HDL : 0x%x\n",
2542 ipa_stat.tx_ch_stats.num_pkts_processed,
2543 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2544 ipa_stat.tx_ch_stats.num_db_fired,
2545 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2546 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2547 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2548 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2549 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2550 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2551 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2552 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2553 ipa_stat.tx_ch_stats.num_db,
2554 ipa_stat.tx_ch_stats.num_unexpected_db,
2555 ipa_stat.tx_ch_stats.num_bam_int_handled,
2556 ipa_stat.tx_ch_stats.
2557#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
2558 num_bam_int_in_non_running_state,
2559#else
2560 num_bam_int_in_non_runnning_state,
2561#endif
2562 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2563
2564 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO,
2565 "\n==== IPA WDI RX STATS ====\n"
2566 "MAX OST PKT : %d\n"
2567 "NUM PKT PRCSD : %d\n"
2568 "RNG RP : 0x%x\n"
2569 "IND RNG FULL : %d\n"
2570 "IND RNG EMPT : %d\n"
2571 "IND RNG USE HGH : %d\n"
2572 "IND RNG USE LOW : %d\n"
2573 "BAM FIFO FULL : %d\n"
2574 "BAM FIFO EMPT : %d\n"
2575 "BAM FIFO USE HGH : %d\n"
2576 "BAM FIFO USE LOW : %d\n"
2577 "NUM DB : %d\n"
2578 "NUM UNEXP DB : %d\n"
2579 "NUM BAM INT HNDL : 0x%x\n",
2580 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2581 ipa_stat.rx_ch_stats.num_pkts_processed,
2582 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2583 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2584 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2585 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2586 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2587 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2588 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2589 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2590 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2591 ipa_stat.rx_ch_stats.num_db,
2592 ipa_stat.rx_ch_stats.num_unexpected_db,
2593 ipa_stat.rx_ch_stats.num_bam_int_handled);
2594}
2595
2596/**
2597 * hdd_ipa_uc_info() - Print IPA uC resource and session information
2598 * @adapter: network adapter
2599 *
2600 * Return: None
2601 */
2602void hdd_ipa_uc_info(struct hdd_context *hdd_ctx)
2603{
2604 struct hdd_ipa_priv *hdd_ipa;
2605
2606 hdd_ipa = hdd_ctx->hdd_ipa;
2607
2608 if (!hdd_ipa) {
2609 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2610 "HDD IPA context is NULL");
2611 return;
2612 }
2613
2614 /* IPA session info */
2615 hdd_ipa_print_session_info(hdd_ipa);
2616}
2617
2618/**
2619 * hdd_ipa_uc_stat() - Print IPA uC stats
2620 * @adapter: network adapter
2621 *
2622 * Return: None
2623 */
2624void hdd_ipa_uc_stat(struct hdd_adapter *adapter)
2625{
2626 struct hdd_context *hdd_ctx;
2627 struct hdd_ipa_priv *hdd_ipa;
2628
2629 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2630 hdd_ipa = hdd_ctx->hdd_ipa;
2631
2632 if (!hdd_ipa) {
2633 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2634 "HDD IPA context is NULL");
2635 return;
2636 }
2637
2638 /* HDD IPA TX/RX stats */
2639 hdd_ipa_print_txrx_stats(hdd_ipa);
2640 /* IPA WDI stats */
2641 hdd_ipa_print_ipa_wdi_stats(hdd_ipa);
2642 /* WLAN FW WDI stats */
2643 hdd_ipa_uc_stat_request(adapter, HDD_IPA_UC_STAT_REASON_DEBUG);
2644}
2645
2646/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002647 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2648 * @op_msg: operation message received from firmware
2649 * @usr_ctxt: user context registered with TL (we register the HDD Global
2650 * context)
2651 *
2652 * Return: None
2653 */
2654static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2655{
2656 struct op_msg_type *msg = op_msg;
2657 struct ipa_uc_fw_stats *uc_fw_stat;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002658 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002659 struct hdd_context *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302660 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002661
2662 if (!op_msg || !usr_ctxt) {
Yun Park46255682017-10-09 15:56:34 -07002663 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "INVALID ARG");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002664 return;
2665 }
2666
2667 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302668 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07002669 "INVALID OPCODE %d", msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002670 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002671 return;
2672 }
2673
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002674 hdd_ctx = (struct hdd_context *) usr_ctxt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002675
2676 /*
2677 * When SSR is going on or driver is unloading, just return.
2678 */
2679 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302680 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302681 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002682 return;
2683 }
2684
2685 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2686
Govind Singhb6a89772016-08-12 11:23:35 +05302687 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002688 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002689
2690 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2691 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302692 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002693 hdd_ipa->activated_fw_pipe++;
2694 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2695 hdd_ipa->resource_loading = false;
Yun Park777d7242017-03-30 15:38:33 -07002696 complete(&hdd_ipa->ipa_resource_comp);
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002697 if (hdd_ipa->wdi_enabled == false) {
2698 hdd_ipa->wdi_enabled = true;
2699 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2700 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2701 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002702 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002703 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002704 if (hdd_ipa->pending_cons_req)
2705 ipa_rm_notify_completion(
2706 IPA_RM_RESOURCE_GRANTED,
2707 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002708 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002709 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302710 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002711 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002712 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302713 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002714 hdd_ipa->activated_fw_pipe--;
2715 if (!hdd_ipa->activated_fw_pipe) {
Yun Park777d7242017-03-30 15:38:33 -07002716 /*
2717 * Async return success from FW
2718 * Disable/suspend all the PIPEs
2719 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002720 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002721 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2722 ipa_rm_release_resource(
2723 IPA_RM_RESOURCE_WLAN_PROD);
Yun Park5b635012015-12-02 15:05:01 -08002724 hdd_ipa->resource_unloading = false;
Yun Park777d7242017-03-30 15:38:33 -07002725 complete(&hdd_ipa->ipa_resource_comp);
Yun Park5b635012015-12-02 15:05:01 -08002726 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2727 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002728 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302729 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002730 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002731 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002732 uc_fw_stat = (struct ipa_uc_fw_stats *)
Yun Park46255682017-10-09 15:56:34 -07002733 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002734
Yun Park46255682017-10-09 15:56:34 -07002735 /* WLAN FW WDI stats */
2736 hdd_ipa_print_fw_wdi_stats(hdd_ipa, uc_fw_stat);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002737 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2738 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2739 /* STATs from FW */
2740 uc_fw_stat = (struct ipa_uc_fw_stats *)
2741 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302742 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002743 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2744 uc_fw_stat->tx_pkts_completed,
2745 hdd_ipa->ipa_p_tx_packets);
2746 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2747 (uc_fw_stat->rx_num_ind_drop_no_space +
2748 uc_fw_stat->rx_num_ind_drop_no_buf +
2749 uc_fw_stat->rx_num_pkts_indicated),
2750 hdd_ipa->ipa_p_rx_packets);
2751
2752 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2753 hdd_ipa->ipa_p_rx_packets =
2754 (uc_fw_stat->rx_num_ind_drop_no_space +
2755 uc_fw_stat->rx_num_ind_drop_no_buf +
2756 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302757 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002758 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2759 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2760 hdd_ipa_uc_loaded_handler(hdd_ipa);
2761 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002762 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2763 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2764 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002765 }
Yun Park8957d802017-01-25 12:27:29 -08002766
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302767 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002768}
2769
2770
2771/**
2772 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2773 * @adapter: device adapter instance
2774 * @offload_type: MCC or SCC
2775 * @enable: TX offload enable or disable
2776 *
2777 * Return: none
2778 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002779static void hdd_ipa_uc_offload_enable_disable(struct hdd_adapter *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002780 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002781{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002782 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002783 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002784 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002785 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002786
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002787 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002788 return;
2789
Yun Park8292dcb2016-10-07 16:46:06 -07002790 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002791 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002792
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002793 if (!iface_context) {
2794 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2795 "Interface context is NULL");
2796 return;
2797 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002798 if (session_id >= CSR_ROAM_SESSION_MAX) {
2799 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2800 "invalid session id: %d", session_id);
2801 return;
2802 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002803 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park199c2ed2017-10-02 11:24:22 -07002804 /*
2805 * This shouldn't happen :
2806 * IPA offload status is already set as desired
2807 */
2808 WARN_ON(1);
2809 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
Yun Parkb4f591d2017-03-29 15:51:01 -07002810 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002811 "IPA offload status is already set",
2812 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002813 return;
2814 }
2815
Yun Park4540e862016-11-10 16:30:06 -08002816 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2817 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2818 "invalid session id: %d, offload_type=%d, enable=%d",
2819 adapter->sessionId, offload_type, enable);
2820 return;
2821 }
2822
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302823 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002824 sizeof(ipa_offload_enable_disable));
2825 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002826 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002827 ipa_offload_enable_disable.enable = enable;
2828
Yun Park199c2ed2017-10-02 11:24:22 -07002829 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park8292dcb2016-10-07 16:46:06 -07002830 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002831 ipa_offload_enable_disable.offload_type,
2832 ipa_offload_enable_disable.vdev_id,
2833 ipa_offload_enable_disable.enable);
2834
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302835 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002836 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2837 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302838 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07002839 "Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
2840 ipa_offload_enable_disable.offload_type,
2841 ipa_offload_enable_disable.vdev_id,
2842 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002843 } else {
2844 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002845 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002846 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002847 }
2848}
2849
2850/**
2851 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2852 * @work: uC OP work
2853 *
2854 * Return: None
2855 */
2856static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2857{
2858 struct op_msg_type *msg;
2859 struct uc_op_work_struct *uc_op_work = container_of(work,
2860 struct uc_op_work_struct, work);
2861 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2862
2863 cds_ssr_protect(__func__);
2864
2865 msg = uc_op_work->msg;
2866 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002867 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07002868 "posted msg %d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002869
2870 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2871
2872 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002873}
2874
2875/**
2876 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2877 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2878 * @op_msg: operation message received from firmware
2879 * @hdd_ctx: Global HDD context
2880 *
2881 * Return: None
2882 */
2883static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2884{
2885 struct hdd_ipa_priv *hdd_ipa;
2886 struct op_msg_type *msg;
2887 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302888 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002889
2890 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302891 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002892 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002893
2894 msg = (struct op_msg_type *)op_msg;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002895 hdd_ipa = ((struct hdd_context *)hdd_ctx)->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002896
2897 if (unlikely(!hdd_ipa))
2898 goto end;
2899
2900 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002901 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2902 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002903 goto end;
2904 }
2905
2906 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2907 if (uc_op_work->msg)
2908 /* When the same uC OPCODE is already pended, just return */
2909 goto end;
2910
2911 uc_op_work->msg = msg;
2912 schedule_work(&uc_op_work->work);
2913 return;
2914
2915end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302916 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002917}
2918
2919/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002920 * hdd_ipa_init_uc_op_work - init ipa uc op work
2921 * @work: struct work_struct
2922 * @work_handler: work_handler
2923 *
2924 * Return: none
2925 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002926static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002927 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002928{
2929 INIT_WORK(work, work_handler);
2930}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002931
Yun Park637d6482016-10-05 10:51:33 -07002932#ifdef FEATURE_METERING
2933/**
2934 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2935 * IPA calls to get WLAN stats or set quota limit.
2936 * @priv: pointer to private data registered with IPA (we register a
2937 *» pointer to the global IPA context)
2938 * @evt: the IPA event which triggered the callback
2939 * @data: data associated with the event
2940 *
2941 * Return: None
2942 */
2943static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2944 void *data)
2945{
2946 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002947 struct hdd_adapter *adapter = NULL;
Yun Park637d6482016-10-05 10:51:33 -07002948 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2949 struct ipa_set_wifi_quota *ipa_set_quota;
2950 int ret = 0;
2951
2952 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2953 return;
2954
2955 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2956
2957 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2958
2959 switch (evt) {
2960 case IPA_GET_WDI_SAP_STATS:
2961 /* fill-up ipa_get_wdi_sap_stats structure after getting
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002962 * ipa_uc_fw_stats from FW
2963 */
Yun Park637d6482016-10-05 10:51:33 -07002964 wdi_sap_stats = data;
2965
2966 if (!adapter) {
2967 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2968 "IPA uC share stats failed - no adapter");
2969 wdi_sap_stats->stats_valid = 0;
2970 return;
2971 }
2972
2973 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
Yun Park637d6482016-10-05 10:51:33 -07002974 hdd_ipa_uc_sharing_stats_request(adapter,
2975 wdi_sap_stats->reset_stats);
2976 ret = wait_for_completion_timeout(
2977 &hdd_ipa->ipa_uc_sharing_stats_comp,
2978 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2979 if (!ret) {
2980 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2981 "IPA uC share stats request timed out");
2982 wdi_sap_stats->stats_valid = 0;
2983 } else {
2984 wdi_sap_stats->stats_valid = 1;
2985
2986 wdi_sap_stats->ipv4_rx_packets =
2987 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2988 wdi_sap_stats->ipv4_rx_bytes =
2989 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2990 wdi_sap_stats->ipv6_rx_packets =
2991 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2992 wdi_sap_stats->ipv6_rx_bytes =
2993 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2994 wdi_sap_stats->ipv4_tx_packets =
2995 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2996 wdi_sap_stats->ipv4_tx_bytes =
2997 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2998 wdi_sap_stats->ipv6_tx_packets =
2999 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
3000 wdi_sap_stats->ipv6_tx_bytes =
3001 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
3002 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
3003 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
3004 "IPA_GET_WDI_SAP_STATS",
3005 wdi_sap_stats->stats_valid,
3006 wdi_sap_stats->ipv4_rx_packets,
3007 wdi_sap_stats->ipv4_rx_bytes,
3008 wdi_sap_stats->ipv6_rx_packets,
3009 wdi_sap_stats->ipv6_rx_bytes,
3010 wdi_sap_stats->ipv4_tx_packets,
3011 wdi_sap_stats->ipv4_tx_bytes,
3012 wdi_sap_stats->ipv6_tx_packets,
3013 wdi_sap_stats->ipv6_tx_bytes);
3014 }
3015 break;
3016 case IPA_SET_WIFI_QUOTA:
3017 /* get ipa_set_wifi_quota structure from IPA and pass to FW
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07003018 * through quota_exceeded field in ipa_uc_fw_stats
3019 */
Yun Park637d6482016-10-05 10:51:33 -07003020 ipa_set_quota = data;
3021
3022 if (!adapter) {
3023 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3024 "IPA uC set quota failed - no adapter");
3025 ipa_set_quota->set_valid = 0;
3026 return;
3027 }
3028
Yun Park777d7242017-03-30 15:38:33 -07003029 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
Yun Park637d6482016-10-05 10:51:33 -07003030 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
3031 ipa_set_quota->quota_bytes);
3032
3033 ret = wait_for_completion_timeout(
3034 &hdd_ipa->ipa_uc_set_quota_comp,
3035 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
3036 if (!ret) {
3037 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3038 "IPA uC set quota request timed out");
3039 ipa_set_quota->set_valid = 0;
3040 } else {
3041 ipa_set_quota->quota_bytes =
3042 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
3043 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
3044 ipa_set_quota->set_valid =
3045 hdd_ipa->ipa_quota_rsp.success;
3046 }
3047
3048 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
3049 ipa_set_quota->quota_bytes,
3050 ipa_set_quota->set_valid);
3051 break;
3052 }
3053}
3054
3055/**
3056 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
3057 * IPA calls to get WLAN stats or set quota limit.
3058 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07003059 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07003060 * @evt: the IPA event which triggered the callback
3061 * @data: data associated with the event
3062 *
3063 * Return: None
3064 */
3065static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
3066 void *data)
3067{
3068 cds_ssr_protect(__func__);
3069 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
3070 cds_ssr_unprotect(__func__);
3071}
3072
Yun Parkb4f591d2017-03-29 15:51:01 -07003073static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07003074{
Yun Park637d6482016-10-05 10:51:33 -07003075 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
3076 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
3077}
3078#else
Yun Parkb4f591d2017-03-29 15:51:01 -07003079static void hdd_ipa_wdi_meter_notifier_cb(void)
3080{
3081}
3082
3083static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07003084{
3085}
3086#endif
3087
Rajeev Kumar217f2172016-01-06 18:11:55 -08003088/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003089 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
3090 * @hdd_ctx: Global HDD context
3091 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003092 * This function is called to update IPA pipe configuration with resources
3093 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
3094 * (cds_enable)
3095 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05303096 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003097 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003098QDF_STATUS hdd_ipa_uc_ol_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003099{
Yun Parkb4f591d2017-03-29 15:51:01 -07003100 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07003101 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08003102 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07003103 uint8_t i;
3104 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003106 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3107 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003108
Yun Park199c2ed2017-10-02 11:24:22 -07003109 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003110
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003111 /* Do only IPA Pipe specific configuration here. All one time
3112 * initialization wrt IPA UC shall in hdd_ipa_init and those need
3113 * to be reinit at SSR shall in be SSR deinit / reinit functions.
3114 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003115 if (!pdev || !soc) {
3116 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07003117 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08003118 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003119 }
Yun Parkb4f591d2017-03-29 15:51:01 -07003120 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003121 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
3122 "IPA UC resource alloc fail");
Yun Park199c2ed2017-10-02 11:24:22 -07003123 status = QDF_STATUS_E_FAILURE;
3124 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08003125 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126
Yun Parkb4f591d2017-03-29 15:51:01 -07003127 if (true == hdd_ipa->uc_loaded) {
3128 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
3129 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
3130 hdd_ipa_wdi_meter_notifier_cb,
3131 hdd_ctx->config->IpaDescSize,
3132 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
3133 &hdd_ipa->tx_pipe_handle,
3134 &hdd_ipa->rx_pipe_handle);
3135 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08003136 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07003137 "Failure to setup IPA pipes (status=%d)",
3138 status);
Yun Park199c2ed2017-10-02 11:24:22 -07003139 status = QDF_STATUS_E_FAILURE;
3140 goto fail_return;
Yun Parkbaa62862017-01-18 13:43:34 -08003141 }
Yun Park637d6482016-10-05 10:51:33 -07003142
Yun Parkb4f591d2017-03-29 15:51:01 -07003143 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
3144 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003145 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146
Yun Parkb4f591d2017-03-29 15:51:01 -07003147 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08003148 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
3149
Yun Parkb4f591d2017-03-29 15:51:01 -07003150 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
3151 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
3152 hdd_ipa_uc_fw_op_event_handler);
3153 hdd_ipa->uc_op_work[i].msg = NULL;
3154 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003155
Yun Parkbaa62862017-01-18 13:43:34 -08003156fail_return:
Yun Park199c2ed2017-10-02 11:24:22 -07003157 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: status=%d", status);
Yun Parkb4f591d2017-03-29 15:51:01 -07003158 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003159}
3160
Leo Change3e49442015-10-26 20:07:13 -07003161/**
Yun Parkd8fb1a82017-10-13 16:48:20 -07003162 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
3163 * @hdd_ipa: pointer to HDD IPA struct
3164 *
3165 * Return: none
3166 */
3167static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
3168{
3169 struct ipa_uc_pending_event *pending_event = NULL;
3170
3171 while (qdf_list_remove_front(&hdd_ipa->pending_event,
3172 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS)
3173 qdf_mem_free(pending_event);
3174}
3175
3176/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303177 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
3178 * @hdd_ctx: Global HDD context
3179 *
3180 * Return: 0 on success, negativer errno on error
3181 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003182int hdd_ipa_uc_ol_deinit(struct hdd_context *hdd_ctx)
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303183{
3184 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
3185 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07003186 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303187
Yun Park199c2ed2017-10-02 11:24:22 -07003188 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003189
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303190 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3191 return ret;
3192
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05303193 if (!hdd_ipa->ipa_pipes_down)
3194 hdd_ipa_uc_disable_pipes(hdd_ipa);
3195
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303196 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07003197 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
3198 hdd_ipa->tx_pipe_handle,
3199 hdd_ipa->rx_pipe_handle);
3200 if (status) {
3201 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3202 "Failure to cleanup IPA pipes (status=%d)",
3203 status);
3204 return -EFAULT;
3205 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303206 }
3207
Yun Parkd8fb1a82017-10-13 16:48:20 -07003208 hdd_ipa_cleanup_pending_event(hdd_ipa);
3209
Yun Park199c2ed2017-10-02 11:24:22 -07003210 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: ret=%d", ret);
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05303211 return ret;
3212}
3213
3214/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003215 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07003216 * @hdd_ctx: hdd main context
3217 *
3218 * Force shutdown IPA pipe
3219 * Independent of FW pipe status, IPA pipe shutdonw progress
3220 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3221 * independent from FW pipe status
3222 *
3223 * Return: NONE
3224 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003225static void __hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07003226{
3227 struct hdd_ipa_priv *hdd_ipa;
3228
Yun Park199c2ed2017-10-02 11:24:22 -07003229 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003230
Leo Change3e49442015-10-26 20:07:13 -07003231 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
3232 return;
3233
3234 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
3235 if (false == hdd_ipa->ipa_pipes_down) {
Yun Park46255682017-10-09 15:56:34 -07003236 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Parkb4f591d2017-03-29 15:51:01 -07003237 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07003238 hdd_ipa_uc_disable_pipes(hdd_ipa);
3239 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003240 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07003241 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07003242 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003243
Yun Park199c2ed2017-10-02 11:24:22 -07003244 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit");
Leo Change3e49442015-10-26 20:07:13 -07003245}
3246
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003247/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003248 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
3249 * __hdd_ipa_uc_force_pipe_shutdown
3250 * @hdd_ctx: hdd main context
3251 *
3252 * Force shutdown IPA pipe
3253 * Independent of FW pipe status, IPA pipe shutdonw progress
3254 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3255 * independent from FW pipe status
3256 *
3257 * Return: NONE
3258 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003259void hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003260{
3261 cds_ssr_protect(__func__);
3262 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
3263 cds_ssr_unprotect(__func__);
3264}
3265
3266/**
Govind Singh9c58eba2016-09-02 16:23:06 +05303267 * hdd_ipa_msg_free_fn() - Free an IPA message
3268 * @buff: pointer to the IPA message
3269 * @len: length of the IPA message
3270 * @type: type of IPA message
3271 *
3272 * Return: None
3273 */
3274static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3275{
Srinivas Girigowda97852372017-03-06 16:52:59 -08003276 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05303277 ghdd_ipa->stats.num_free_msg++;
3278 qdf_mem_free(buff);
3279}
3280
Govind Singh9c58eba2016-09-02 16:23:06 +05303281/**
jge62037862016-12-09 10:44:33 +08003282 * hdd_ipa_uc_send_evt() - send event to ipa
3283 * @hdd_ctx: pointer to hdd context
3284 * @type: event type
3285 * @mac_addr: pointer to mac address
3286 *
3287 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303288 *
3289 * Return: 0 - Success
3290 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003291static int hdd_ipa_uc_send_evt(struct hdd_adapter *adapter,
jge62037862016-12-09 10:44:33 +08003292 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303293{
jge62037862016-12-09 10:44:33 +08003294 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05303295 struct ipa_msg_meta meta;
3296 struct ipa_wlan_msg *msg;
3297 int ret = 0;
jge62037862016-12-09 10:44:33 +08003298
3299 meta.msg_len = sizeof(struct ipa_wlan_msg);
3300 msg = qdf_mem_malloc(meta.msg_len);
3301 if (msg == NULL) {
3302 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3303 "msg allocation failed");
3304 return -ENOMEM;
3305 }
3306
3307 meta.msg_type = type;
3308 strlcpy(msg->name, adapter->dev->name,
3309 IPA_RESOURCE_NAME_MAX);
3310 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Yun Park199c2ed2017-10-02 11:24:22 -07003311 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08003312 msg->name, meta.msg_type);
3313 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3314 if (ret) {
3315 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3316 "%s: Evt: %d fail:%d",
3317 msg->name, meta.msg_type, ret);
3318 qdf_mem_free(msg);
3319 return ret;
3320 }
3321
3322 hdd_ipa->stats.num_send_msg++;
3323
3324 return ret;
3325}
3326
3327/**
3328 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3329 * @hdd_ctx: pointer to hdd adapter
3330 *
3331 * Send disconnect client event to IPA driver during SSR
3332 *
3333 * Return: 0 - Success
3334 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003335static int hdd_ipa_uc_disconnect_client(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003336{
3337 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3338 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303339 int i;
3340
Yun Park199c2ed2017-10-02 11:24:22 -07003341 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Govind Singh9c58eba2016-09-02 16:23:06 +05303342 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003343 if (qdf_is_macaddr_broadcast(&adapter->sta_info[i].sta_mac))
Govind Singh9c58eba2016-09-02 16:23:06 +05303344 continue;
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003345 if ((adapter->sta_info[i].in_use) &&
3346 (!adapter->sta_info[i].is_deauth_in_progress) &&
jge62037862016-12-09 10:44:33 +08003347 hdd_ipa->sap_num_connected_sta) {
3348 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
Jeff Johnsonbb8b56a2017-10-23 07:02:36 -07003349 adapter->sta_info[i].sta_mac.bytes);
jge62037862016-12-09 10:44:33 +08003350 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303351 }
3352 }
Yun Park199c2ed2017-10-02 11:24:22 -07003353 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: sap_num_connected_sta=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07003354 hdd_ipa->sap_num_connected_sta);
Govind Singh9c58eba2016-09-02 16:23:06 +05303355
3356 return ret;
3357}
3358
3359/**
jge62037862016-12-09 10:44:33 +08003360 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3361 * @hdd_ctx: pointer to hdd adapter
3362 *
3363 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303364 *
3365 * Return: 0 - Success
3366 */
jge62037862016-12-09 10:44:33 +08003367
Jeff Johnson49d45e62017-08-29 14:30:42 -07003368static int hdd_ipa_uc_disconnect_ap(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003369{
3370 int ret = 0;
3371
Yun Park199c2ed2017-10-02 11:24:22 -07003372 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003373 if (adapter->ipa_context) {
jge62037862016-12-09 10:44:33 +08003374 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3375 adapter->dev->dev_addr);
Yun Parkfec73dc2017-09-06 10:40:07 -07003376 }
Yun Park199c2ed2017-10-02 11:24:22 -07003377 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit");
jge62037862016-12-09 10:44:33 +08003378
3379 return ret;
3380}
3381
jge62037862016-12-09 10:44:33 +08003382/**
3383 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3384 * @hdd_ctx: pointer to hdd adapter
3385 *
3386 * Send disconnect sta event to IPA driver during SSR
3387 *
3388 * Return: 0 - Success
3389 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003390static int hdd_ipa_uc_disconnect_sta(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003391{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003392 struct hdd_station_ctx *sta_ctx;
jge62037862016-12-09 10:44:33 +08003393 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3394 int ret = 0;
3395
Yun Park199c2ed2017-10-02 11:24:22 -07003396 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003397 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003398 hdd_ipa->sta_connected) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07003399 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
jge62037862016-12-09 10:44:33 +08003400 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Jeff Johnsond377dce2017-10-04 10:32:42 -07003401 sta_ctx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003402 }
Yun Park199c2ed2017-10-02 11:24:22 -07003403 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit");
jge62037862016-12-09 10:44:33 +08003404
3405 return ret;
3406}
jge62037862016-12-09 10:44:33 +08003407
3408/**
3409 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3410 * @hdd_ctx: pointer to hdd context
3411 *
3412 * Send disconnect event to IPA driver during SSR
3413 *
3414 * Return: 0 - Success
3415 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003416static int hdd_ipa_uc_disconnect(struct hdd_context *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303417{
3418 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3419 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003420 struct hdd_adapter *adapter;
Govind Singh9c58eba2016-09-02 16:23:06 +05303421 int ret = 0;
3422
Govind Singh9c58eba2016-09-02 16:23:06 +05303423 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3424 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003425 adapter = adapter_node->adapter;
jge62037862016-12-09 10:44:33 +08003426 if (adapter->device_mode == QDF_SAP_MODE) {
3427 hdd_ipa_uc_disconnect_client(adapter);
3428 hdd_ipa_uc_disconnect_ap(adapter);
3429 } else if (adapter->device_mode == QDF_STA_MODE) {
3430 hdd_ipa_uc_disconnect_sta(adapter);
3431 }
3432
Govind Singh9c58eba2016-09-02 16:23:06 +05303433 status = hdd_get_next_adapter(
3434 hdd_ctx, adapter_node, &next);
3435 adapter_node = next;
3436 }
3437
3438 return ret;
3439}
3440
3441/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003442 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003443 *
3444 * Deinit basic IPA UC host side to be in sync reloaded FW during
3445 * SSR
3446 *
3447 * Return: 0 - Success
3448 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003449static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003450{
3451 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3452 int idx;
3453 struct hdd_ipa_iface_context *iface_context;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003454 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003455
Yun Park199c2ed2017-10-02 11:24:22 -07003456 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003457
Arun Khandavallicc544b32017-01-30 19:52:16 +05303458 if (!hdd_ipa)
3459 return 0;
3460
3461 hdd_ctx = hdd_ipa->hdd_ctx;
3462 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003463 return 0;
3464
jge62037862016-12-09 10:44:33 +08003465 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303466 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003467
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003468 /* Clean up HDD IPA interfaces */
3469 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3470 (idx < HDD_IPA_MAX_IFACE); idx++) {
3471 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003472 if (iface_context->adapter && iface_context->adapter->magic ==
3473 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003474 hdd_ipa_cleanup_iface(iface_context);
3475 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003476 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 /* After SSR, wlan driver reloads FW again. But we need to protect
3478 * IPA submodule during SSR transient state. So deinit basic IPA
3479 * UC host side to be in sync with reloaded FW during SSR
3480 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003481
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303482 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003483 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3484 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3485 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3486 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303487 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003488
Guolei Bianca144d82016-11-10 11:07:42 +08003489 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3490 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3491
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003492 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3493 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3494 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3495 hdd_ipa->uc_op_work[idx].msg = NULL;
3496 }
Yun Parkfec73dc2017-09-06 10:40:07 -07003497
Yun Park199c2ed2017-10-02 11:24:22 -07003498 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003499 return 0;
3500}
3501
3502/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003503 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3504 *
3505 * Deinit basic IPA UC host side to be in sync reloaded FW during
3506 * SSR
3507 *
3508 * Return: 0 - Success
3509 */
3510int hdd_ipa_uc_ssr_deinit(void)
3511{
3512 int ret;
3513
3514 cds_ssr_protect(__func__);
3515 ret = __hdd_ipa_uc_ssr_deinit();
3516 cds_ssr_unprotect(__func__);
3517
3518 return ret;
3519}
3520
3521/**
3522 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003523 *
3524 * Init basic IPA UC host side to be in sync with reloaded FW after
3525 * SSR to resume IPA UC operations
3526 *
3527 * Return: 0 - Success
3528 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003529static int __hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003530{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003531
Arun Khandavallicc544b32017-01-30 19:52:16 +05303532 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3533 int i;
3534 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303535
Yun Park199c2ed2017-10-02 11:24:22 -07003536 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07003537
Arun Khandavallicc544b32017-01-30 19:52:16 +05303538 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3539 return 0;
3540
Arun Khandavallicc544b32017-01-30 19:52:16 +05303541 /* Create the interface context */
3542 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3543 iface_context = &hdd_ipa->iface_context[i];
3544 iface_context->hdd_ipa = hdd_ipa;
3545 iface_context->cons_client =
3546 hdd_ipa_adapter_2_client[i].cons_client;
3547 iface_context->prod_client =
3548 hdd_ipa_adapter_2_client[i].prod_client;
3549 iface_context->iface_id = i;
3550 iface_context->adapter = NULL;
3551 }
3552 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3553 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3554 hdd_ipa->vdev_offload_enabled[i] = false;
3555 }
3556
3557 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3558 hdd_ipa->resource_loading = false;
3559 hdd_ipa->resource_unloading = false;
3560 hdd_ipa->sta_connected = 0;
3561 hdd_ipa->ipa_pipes_down = true;
3562 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303563 }
3564
Yun Park199c2ed2017-10-02 11:24:22 -07003565 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003566 return 0;
3567}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003568
3569/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003570 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3571 *
3572 * Init basic IPA UC host side to be in sync with reloaded FW after
3573 * SSR to resume IPA UC operations
3574 *
3575 * Return: 0 - Success
3576 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003577int hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003578{
3579 int ret;
3580
3581 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303582 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003583 cds_ssr_unprotect(__func__);
3584
3585 return ret;
3586}
3587
3588/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003589 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3590 * @work: scheduled work
3591 *
3592 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3593 * not want to immediately release the wake lock since the system
3594 * would then potentially try to suspend when there is a healthy data
3595 * rate. Deferred work is scheduled and this function handles the
3596 * work. When this function is called, if the IPA resource is still
3597 * released then we release the wake lock.
3598 *
3599 * Return: None
3600 */
3601static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3602{
3603 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3604 struct hdd_ipa_priv,
3605 wake_lock_work);
3606
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303607 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608
3609 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3610 goto end;
3611
3612 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303613 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003614 WIFI_POWER_EVENT_WAKELOCK_IPA);
3615
3616end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303617 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003618}
3619
3620/**
3621 * hdd_ipa_rm_request() - Request resource from IPA
3622 * @hdd_ipa: Global HDD IPA context
3623 *
3624 * Return: 0 on success, negative errno on error
3625 */
3626static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3627{
3628 int ret = 0;
3629
3630 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3631 return 0;
3632
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303633 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003634
3635 switch (hdd_ipa->rm_state) {
3636 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303637 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003638 return 0;
3639 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303640 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003641 return -EINPROGRESS;
3642 case HDD_IPA_RM_RELEASED:
3643 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3644 break;
3645 }
3646
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303647 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003648
3649 ret = ipa_rm_inactivity_timer_request_resource(
3650 IPA_RM_RESOURCE_WLAN_PROD);
3651
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303652 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 if (ret == 0) {
3654 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3655 hdd_ipa->stats.num_rm_grant_imm++;
3656 }
3657
3658 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3659 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303660 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003661 WIFI_POWER_EVENT_WAKELOCK_IPA);
3662 hdd_ipa->wake_lock_released = false;
3663 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303664 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003665
3666 return ret;
3667}
3668
3669/**
3670 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3671 * @hdd_ipa: Global HDD IPA context
3672 *
3673 * Return: 0 if resources released, negative errno otherwise
3674 */
3675static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3676{
3677 int ret = 0;
3678
3679 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3680 return 0;
3681
3682 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3683 return -EAGAIN;
3684
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303685 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003686
Nirav Shahcbc6d722016-03-01 16:24:53 +05303687 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303688 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 return -EAGAIN;
3690 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303691 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303693 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003694 switch (hdd_ipa->rm_state) {
3695 case HDD_IPA_RM_GRANTED:
3696 break;
3697 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303698 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003699 return -EINPROGRESS;
3700 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303701 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702 return 0;
3703 }
3704
3705 /* IPA driver returns immediately so set the state here to avoid any
3706 * race condition.
3707 */
3708 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3709 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303710 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003711
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003712 ret = ipa_rm_inactivity_timer_release_resource(
3713 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003714
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303715 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003716 if (unlikely(ret != 0)) {
3717 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3718 WARN_ON(1);
Yun Park199c2ed2017-10-02 11:24:22 -07003719 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
3720 "ipa_rm_inactivity_timer_release_resource returnied fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003721 }
3722
3723 /*
3724 * If wake_lock is released immediately, kernel would try to suspend
3725 * immediately as well, Just avoid ping-pong between suspend-resume
3726 * while there is healthy amount of data transfer going on by
3727 * releasing the wake_lock after some delay.
3728 */
3729 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3730 msecs_to_jiffies
3731 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3732
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303733 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003734
3735 return ret;
3736}
3737
3738/**
3739 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3740 * @user_data: user data registered with IPA
3741 * @event: the IPA resource manager event that occurred
3742 * @data: the data associated with the event
3743 *
3744 * Return: None
3745 */
3746static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3747 unsigned long data)
3748{
3749 struct hdd_ipa_priv *hdd_ipa = user_data;
3750
3751 if (unlikely(!hdd_ipa))
3752 return;
3753
3754 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3755 return;
3756
Srinivas Girigowda97852372017-03-06 16:52:59 -08003757 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003758
3759 switch (event) {
3760 case IPA_RM_RESOURCE_GRANTED:
3761 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3762 /* RM Notification comes with ISR context
3763 * it should be serialized into work queue to avoid
3764 * ISR sleep problem
3765 */
3766 hdd_ipa->uc_rm_work.event = event;
3767 schedule_work(&hdd_ipa->uc_rm_work.work);
3768 break;
3769 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303770 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303772 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003773 hdd_ipa->stats.num_rm_grant++;
3774 break;
3775
3776 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003777 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003778 hdd_ipa->resource_unloading = false;
3779 break;
3780
3781 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303782 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783 break;
3784 }
3785}
3786
3787/**
3788 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3789 *
3790 * Callback function registered with IPA that is called when IPA wants
3791 * to release the WLAN consumer resource
3792 *
3793 * Return: 0 if the request is granted, negative errno otherwise
3794 */
3795static int hdd_ipa_rm_cons_release(void)
3796{
3797 return 0;
3798}
3799
3800/**
3801 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3802 *
3803 * Callback function registered with IPA that is called when IPA wants
3804 * to access the WLAN consumer resource
3805 *
3806 * Return: 0 if the request is granted, negative errno otherwise
3807 */
3808static int hdd_ipa_rm_cons_request(void)
3809{
Yun Park4d8b60a2015-10-22 13:59:32 -07003810 int ret = 0;
3811
3812 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303813 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003814 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003816 ret = -EINPROGRESS;
3817 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303818 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003819 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003820 ghdd_ipa->pending_cons_req = true;
3821 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003822 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003823
3824 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003825}
3826
3827/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003828 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003829 * @hdd_ctx: Global HDD context
3830 * @tx_packets: Number of packets transmitted in the last sample period
3831 * @rx_packets: Number of packets received in the last sample period
3832 *
3833 * Return: 0 on success, negative errno on error
3834 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07003835static int __hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx,
3836 uint64_t tx_packets,
3837 uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003838{
3839 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003840 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003841 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003842 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003843 int ret;
3844
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003845 if (wlan_hdd_validate_context(hdd_ctx))
3846 return 0;
3847
3848 hdd_ipa = hdd_ctx->hdd_ipa;
3849
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003850 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3851 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3852 return 0;
3853
3854 memset(&profile, 0, sizeof(profile));
3855
3856 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3857 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3858 else if (tx_packets >
3859 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3860 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3861 else
3862 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3863
3864 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3865 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3866 else if (rx_packets >
3867 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3868 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3869 else
3870 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3871
Yun Parkec845302016-12-15 09:22:57 -08003872 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003873 "CONS perf curr: %d, next: %d",
3874 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003875 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876 "PROD perf curr: %d, next: %d",
3877 hdd_ipa->curr_prod_bw, next_prod_bw);
3878
3879 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003880 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003881 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003882 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3883 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003885 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003886
3887 return ret;
3888 }
3889 hdd_ipa->curr_cons_bw = next_cons_bw;
3890 hdd_ipa->stats.num_cons_perf_req++;
3891 }
3892
3893 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003894 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003895 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003896 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3897 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003898 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003899 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003900 return ret;
3901 }
3902 hdd_ipa->curr_prod_bw = next_prod_bw;
3903 hdd_ipa->stats.num_prod_perf_req++;
3904 }
3905
3906 return 0;
3907}
3908
3909/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003910 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3911 * @hdd_ctx: Global HDD context
3912 * @tx_packets: Number of packets transmitted in the last sample period
3913 * @rx_packets: Number of packets received in the last sample period
3914 *
3915 * Return: 0 on success, negative errno on error
3916 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003917int hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003918 uint64_t rx_packets)
3919{
3920 int ret;
3921
3922 cds_ssr_protect(__func__);
3923 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3924 cds_ssr_unprotect(__func__);
3925
3926 return ret;
3927}
3928
3929/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003930 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3931 * @work: struct work_struct
3932 * @work_handler: work_handler
3933 *
3934 * Return: none
3935 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003936static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3937 work_func_t work_handler)
3938{
3939 INIT_WORK(work, work_handler);
3940}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003941
3942/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003943 * hdd_ipa_setup_rm() - Setup IPA resource management
3944 * @hdd_ipa: Global HDD IPA context
3945 *
3946 * Return: 0 on success, negative errno on error
3947 */
3948static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3949{
3950 struct ipa_rm_create_params create_params = { 0 };
3951 int ret;
3952
3953 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3954 return 0;
3955
Rajeev Kumar217f2172016-01-06 18:11:55 -08003956 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3957 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 memset(&create_params, 0, sizeof(create_params));
3959 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3960 create_params.reg_params.user_data = hdd_ipa;
3961 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3962 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3963
3964 ret = ipa_rm_create_resource(&create_params);
3965 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303966 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003967 "Create RM resource failed: %d", ret);
3968 goto setup_rm_fail;
3969 }
3970
3971 memset(&create_params, 0, sizeof(create_params));
3972 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3973 create_params.request_resource = hdd_ipa_rm_cons_request;
3974 create_params.release_resource = hdd_ipa_rm_cons_release;
3975 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3976
3977 ret = ipa_rm_create_resource(&create_params);
3978 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303979 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003980 "Create RM CONS resource failed: %d", ret);
3981 goto delete_prod;
3982 }
3983
3984 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3985 IPA_RM_RESOURCE_APPS_CONS);
3986
3987 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3988 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3989 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303990 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 ret);
3992 goto timer_init_failed;
3993 }
3994
3995 /* Set the lowest bandwidth to start with */
3996 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3997
3998 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303999 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004000 "Set perf level failed: %d", ret);
4001 goto set_perf_failed;
4002 }
4003
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304004 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004005 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
4006 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304007 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004008 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
4009 hdd_ipa->wake_lock_released = true;
4010 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
4011
4012 return ret;
4013
4014set_perf_failed:
4015 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4016
4017timer_init_failed:
4018 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4019
4020delete_prod:
4021 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4022
4023setup_rm_fail:
4024 return ret;
4025}
4026
4027/**
4028 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
4029 * @hdd_ipa: Global HDD IPA context
4030 *
4031 * Destroys all resources associated with the IPA resource manager
4032 *
4033 * Return: None
4034 */
4035static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
4036{
4037 int ret;
4038
4039 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4040 return;
4041
4042 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304043 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004045 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304046 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004047
4048 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4049
4050 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4051 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304052 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004053 "RM PROD resource delete failed %d", ret);
4054
4055 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4056 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304057 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004058 "RM CONS resource delete failed %d", ret);
4059}
4060
tfyu0380a972017-07-13 18:19:37 +08004061#ifdef QCA_CONFIG_SMP
4062static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
4063{
4064 return netif_rx_ni(skb);
4065}
4066#else
4067static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
4068{
4069 struct iphdr *ip_h;
4070 static atomic_t softirq_mitigation_cntr =
4071 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
4072 int result;
4073
4074 ip_h = (struct iphdr *)(skb->data);
4075 if ((skb->protocol == htons(ETH_P_IP)) &&
4076 (ip_h->protocol == IPPROTO_ICMP)) {
4077 result = netif_rx_ni(skb);
4078 } else {
4079 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
4080 * to avoid excessive softirq's.
4081 */
4082 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
4083 result = netif_rx_ni(skb);
4084 atomic_set(&softirq_mitigation_cntr,
4085 IPA_WLAN_RX_SOFTIRQ_THRESH);
4086 } else {
4087 result = netif_rx(skb);
4088 }
4089 }
4090
4091 return result;
4092}
4093#endif
4094
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004095/**
4096 * hdd_ipa_send_skb_to_network() - Send skb to kernel
4097 * @skb: network buffer
4098 * @adapter: network adapter
4099 *
4100 * Called when a network buffer is received which should not be routed
4101 * to the IPA module.
4102 *
4103 * Return: None
4104 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304105static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004106 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004107{
tfyu0380a972017-07-13 18:19:37 +08004108 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4110 unsigned int cpu_index;
4111
4112 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07004113 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004114 adapter);
Yun Park46255682017-10-09 15:56:34 -07004115 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004116 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004117 return;
4118 }
4119
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004120 if (cds_is_driver_unloading()) {
Yun Park46255682017-10-09 15:56:34 -07004121 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004122 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004123 return;
4124 }
4125
4126 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
4127 skb->dev = adapter->dev;
4128 skb->protocol = eth_type_trans(skb, skb->dev);
4129 skb->ip_summed = CHECKSUM_NONE;
4130
4131 cpu_index = wlan_hdd_get_cpu();
4132
Jeff Johnson6ced42c2017-10-20 12:48:11 -07004133 ++adapter->hdd_stats.tx_rx_stats.rx_packets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08004134 result = hdd_ipa_aggregated_rx_ind(skb);
4135 if (result == NET_RX_SUCCESS)
Jeff Johnson6ced42c2017-10-20 12:48:11 -07004136 ++adapter->hdd_stats.tx_rx_stats.rx_delivered[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004137 else
Jeff Johnson6ced42c2017-10-20 12:48:11 -07004138 ++adapter->hdd_stats.tx_rx_stats.rx_refused[cpu_index];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004139
Yun Park46255682017-10-09 15:56:34 -07004140 hdd_ipa->ipa_rx_net_send_count++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004141}
4142
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004143/**
Leo Chang69c39692016-10-12 20:11:12 -07004144 * hdd_ipa_forward() - handle packet forwarding to wlan tx
4145 * @hdd_ipa: pointer to hdd ipa context
4146 * @adapter: network adapter
4147 * @skb: data pointer
4148 *
4149 * if exception packet has set forward bit, copied new packet should be
4150 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
4151 * put into pm queue and tx procedure will be differed
4152 *
4153 * Return: None
4154 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07004155static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004156 struct hdd_adapter *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07004157{
Leo Chang69c39692016-10-12 20:11:12 -07004158 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
4159
Leo Chang69c39692016-10-12 20:11:12 -07004160 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Yun Park01deb2c2017-06-14 15:21:44 -07004161
4162 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
4163 qdf_nbuf_ipa_owned_set(skb);
4164
Yun Park46255682017-10-09 15:56:34 -07004165 /* WLAN subsystem is in suspend, put in queue */
Leo Chang69c39692016-10-12 20:11:12 -07004166 if (hdd_ipa->suspended) {
4167 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Yun Park46255682017-10-09 15:56:34 -07004168 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4169 "Tx in suspend, put in queue");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004170 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
4171 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07004172 pm_tx_cb->exception = true;
4173 pm_tx_cb->adapter = adapter;
4174 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004175 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07004176 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4177 hdd_ipa->stats.num_tx_queued++;
4178 } else {
4179 /* Resume, put packet into WLAN TX */
4180 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004181 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07004182 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07004183 "packet Tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08004184 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07004185 } else {
Yun Parkb187d542016-11-14 18:10:04 -08004186 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07004187 }
4188 }
4189}
4190
4191/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004192 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
4193 * @hdd_ipa: pointer to HDD IPA struct
4194 * @adapter: hdd adapter pointer
4195 * @desc: Firmware descriptor
4196 * @skb: Data buffer
4197 *
4198 * Return:
4199 * HDD_IPA_FORWARD_PKT_NONE
4200 * HDD_IPA_FORWARD_PKT_DISCARD
4201 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
4202 *
4203 */
4204
4205static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
4206 struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004207 struct hdd_adapter *adapter,
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004208 uint8_t desc,
4209 qdf_nbuf_t skb)
4210{
4211 int ret = HDD_IPA_FORWARD_PKT_NONE;
Yun Park0dad1002017-07-14 14:57:01 -07004212 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
4213 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004214
4215 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304216 if (!ol_txrx_fwd_desc_thresh_check(
Yun Park0dad1002017-07-14 14:57:01 -07004217 (struct ol_txrx_vdev_t *)cdp_get_vdev_from_vdev_id(soc,
4218 (struct cdp_pdev *)pdev,
4219 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304220 /* Drop the packet*/
4221 hdd_ipa->stats.num_tx_fwd_err++;
4222 kfree_skb(skb);
4223 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4224 return ret;
4225 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004226 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
4227 "Forward packet to Tx (fw_desc=%d)", desc);
4228 hdd_ipa->ipa_tx_forward++;
4229
4230 if ((desc & FW_RX_DESC_DISCARD_M)) {
4231 hdd_ipa_forward(hdd_ipa, adapter, skb);
Yun Park46255682017-10-09 15:56:34 -07004232 hdd_ipa->ipa_rx_internal_drop_count++;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004233 hdd_ipa->ipa_rx_discard++;
4234 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4235 } else {
4236 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004237
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004238 if (cloned_skb)
4239 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
4240 else
4241 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park46255682017-10-09 15:56:34 -07004242 "tx skb alloc failed");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004243 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
4244 }
4245 }
4246
4247 return ret;
4248}
4249
4250/**
Yun Park637d6482016-10-05 10:51:33 -07004251 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004252 * @priv: pointer to private data registered with IPA (we register a
4253 * pointer to the global IPA context)
4254 * @evt: the IPA event which triggered the callback
4255 * @data: data associated with the event
4256 *
4257 * Return: None
4258 */
Yun Parkf8d6a122016-10-11 15:49:43 -07004259static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 unsigned long data)
4261{
4262 struct hdd_ipa_priv *hdd_ipa = NULL;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004263 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304264 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004265 uint8_t iface_id;
4266 uint8_t session_id;
4267 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07004269 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004270
4271 hdd_ipa = (struct hdd_ipa_priv *)priv;
4272
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08004273 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
4274 return;
4275
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276 switch (evt) {
4277 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05304278 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07004279
4280 /*
4281 * When SSR is going on or driver is unloading,
4282 * just drop the packets.
4283 */
4284 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4285 if (0 != status) {
4286 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4287 "Invalid context: drop packet");
Yun Park46255682017-10-09 15:56:34 -07004288 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004289 kfree_skb(skb);
4290 return;
4291 }
4292
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004293 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4294 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004295 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004296 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004297 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4298 session_id, iface_id);
4299 } else {
4300 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4301 }
4302
4303 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304304 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004305 "IPA_RECEIVE: Invalid iface_id: %u",
4306 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004307 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004308 "w2i -- skb",
4309 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Yun Park46255682017-10-09 15:56:34 -07004310 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Parkf8d6a122016-10-11 15:49:43 -07004311 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004312 return;
4313 }
4314
4315 iface_context = &hdd_ipa->iface_context[iface_id];
4316 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004317 if (!adapter) {
4318 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4319 "IPA_RECEIVE: Adapter is NULL");
Yun Park46255682017-10-09 15:56:34 -07004320 hdd_ipa->ipa_rx_internal_drop_count++;
Yun Park16a78262017-02-01 12:15:03 -08004321 kfree_skb(skb);
4322 return;
4323 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004324
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304325 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004326 "w2i -- skb",
4327 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004328 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4329 hdd_ipa->stats.num_rx_excep++;
4330 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4331 } else {
4332 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4333 }
4334
4335 iface_context->stats.num_rx_ipa_excep++;
4336
4337 /* Disable to forward Intra-BSS Rx packets when
4338 * ap_isolate=1 in hostapd.conf
4339 */
Yun Park046101c2016-09-02 15:32:14 -07004340 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004341 /*
4342 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4343 * all Rx packets to IPA uC, which need to be forwarded
4344 * to other interface.
4345 * And, IPA driver will send back to WLAN host driver
4346 * through exception pipe with fw_desc field set by FW.
4347 * Here we are checking fw_desc field for FORWARD bit
4348 * set, and forward to Tx. Then copy to kernel stack
4349 * only when DISCARD bit is not set.
4350 */
4351 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004352 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4353 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4354 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004355 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004356 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004357 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004358 "Intra-BSS FWD is disabled-skip forward to Tx");
4359 }
4360
4361 hdd_ipa_send_skb_to_network(skb, adapter);
4362 break;
4363
4364 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304365 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004366 "w2i cb wrong event: 0x%x", evt);
4367 return;
4368 }
4369}
4370
4371/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004372 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4373 * @priv: pointer to private data registered with IPA (we register a
4374 * pointer to the global IPA context)
4375 * @evt: the IPA event which triggered the callback
4376 * @data: data associated with the event
4377 *
4378 * Return: None
4379 */
4380static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4381 unsigned long data)
4382{
4383 cds_ssr_protect(__func__);
4384 __hdd_ipa_w2i_cb(priv, evt, data);
4385 cds_ssr_unprotect(__func__);
4386}
4387
4388/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4390 * @skb: packet buffer which was transmitted
4391 *
4392 * Return: None
4393 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304394void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395{
4396 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004397 struct ipa_rx_data *ipa_tx_desc;
4398 struct hdd_ipa_tx_desc *tx_desc;
4399 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400
Yun Park52b2b992016-09-22 15:49:51 -07004401 if (!qdf_nbuf_ipa_owned_get(skb)) {
4402 dev_kfree_skb_any(skb);
4403 return;
4404 }
4405
4406 /* Get Tx desc pointer from SKB CB */
4407 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4408 tx_desc = hdd_ipa->tx_desc_list + id;
4409 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4410
4411 /* Return Tx Desc to IPA */
4412 ipa_free_skb(ipa_tx_desc);
4413
4414 /* Return to free tx desc list */
4415 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4416 tx_desc->ipa_tx_desc_ptr = NULL;
4417 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4418 hdd_ipa->stats.num_tx_desc_q_cnt--;
4419 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004420
4421 hdd_ipa->stats.num_tx_comp_cnt++;
4422
4423 atomic_dec(&hdd_ipa->tx_ref_cnt);
4424
4425 hdd_ipa_rm_try_release(hdd_ipa);
4426}
4427
4428/**
4429 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4430 * @iface_context: interface-specific IPA context
4431 * @ipa_tx_desc: packet data descriptor
4432 *
4433 * Return: None
4434 */
4435static void hdd_ipa_send_pkt_to_tl(
4436 struct hdd_ipa_iface_context *iface_context,
4437 struct ipa_rx_data *ipa_tx_desc)
4438{
4439 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004440 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304441 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004442 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304444 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004445 adapter = iface_context->adapter;
4446 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304447 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004448 ipa_free_skb(ipa_tx_desc);
4449 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304450 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004451 hdd_ipa_rm_try_release(hdd_ipa);
4452 return;
4453 }
4454
4455 /*
4456 * During CAC period, data packets shouldn't be sent over the air so
4457 * drop all the packets here
4458 */
hqu70708ab2017-10-10 17:52:01 +08004459 if (QDF_SAP_MODE == adapter->device_mode ||
4460 QDF_P2P_GO_MODE == adapter->device_mode) {
4461 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4462 ipa_free_skb(ipa_tx_desc);
4463 qdf_spin_unlock_bh(&iface_context->interface_lock);
4464 iface_context->stats.num_tx_cac_drop++;
4465 hdd_ipa_rm_try_release(hdd_ipa);
4466 return;
4467 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004468 }
4469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004470 ++adapter->stats.tx_packets;
4471
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304472 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004473
4474 skb = ipa_tx_desc->skb;
4475
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304476 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004477
4478 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304479 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004480 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304481 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004482 ipa_tx_desc->dma_addr
4483 + HDD_IPA_WLAN_FRAG_HEADER
4484 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004485 ipa_tx_desc->skb->len -=
4486 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4487 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304488 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004489
Yun Park52b2b992016-09-22 15:49:51 -07004490 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4491 /* get free Tx desc and assign ipa_tx_desc pointer */
4492 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4493 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4494 struct hdd_ipa_tx_desc, link);
4495 list_del(&tx_desc->link);
4496 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4497 hdd_ipa->stats.num_tx_desc_q_cnt++;
4498 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4499 /* Store Tx Desc index into SKB CB */
4500 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4501 } else {
4502 hdd_ipa->stats.num_tx_desc_error++;
4503 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Yun Park52b2b992016-09-22 15:49:51 -07004504 ipa_free_skb(ipa_tx_desc);
4505 hdd_ipa_rm_try_release(hdd_ipa);
4506 return;
4507 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004508
4509 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4510
Leo Changfdb45c32016-10-28 11:09:23 -07004511 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004512 (struct cdp_vdev *)iface_context->tl_context,
4513 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004514 if (skb) {
jiad05c1e812017-08-01 16:48:52 +08004515 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004516 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004517 return;
4518 }
4519
4520 atomic_inc(&hdd_ipa->tx_ref_cnt);
4521
4522 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523}
4524
4525/**
Leo Chang11545d62016-10-17 14:53:50 -07004526 * hdd_ipa_is_present() - get IPA hw status
4527 * @hdd_ctx: pointer to hdd context
4528 *
4529 * ipa_uc_reg_rdyCB is not directly designed to check
4530 * ipa hw status. This is an undocumented function which
4531 * has confirmed with IPA team.
4532 *
4533 * Return: true - ipa hw present
4534 * false - ipa hw not present
4535 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004536bool hdd_ipa_is_present(struct hdd_context *hdd_ctx)
Leo Chang11545d62016-10-17 14:53:50 -07004537{
4538 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004539 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004540 return true;
4541 else
4542 return false;
4543}
4544
4545/**
Leo Chang69c39692016-10-12 20:11:12 -07004546 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004547 * @work: pointer to the scheduled work
4548 *
4549 * Called during PM resume to send packets to TL which were queued
4550 * while host was in the process of suspending.
4551 *
4552 * Return: None
4553 */
Leo Chang69c39692016-10-12 20:11:12 -07004554static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004555{
4556 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4557 struct hdd_ipa_priv,
4558 pm_work);
4559 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304560 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561 uint32_t dequeued = 0;
4562
Leo Chang69c39692016-10-12 20:11:12 -07004563 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4564 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304565 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304566 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4567 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304568 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004569
4570 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004572 if (pm_tx_cb->exception) {
Yun Park46255682017-10-09 15:56:34 -07004573 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
4574 "Flush Exception");
Govind Singh1dab23b2017-08-12 13:31:00 +05304575 if (pm_tx_cb->adapter->dev)
4576 hdd_softap_hard_start_xmit(skb,
4577 pm_tx_cb->adapter->dev);
Govind Singh02075942017-08-15 11:13:28 +05304578 else
4579 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004580 } else {
4581 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004582 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004583 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304584 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304586 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004587 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4588 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004589
4590 hdd_ipa->stats.num_tx_dequeued += dequeued;
4591 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4592 hdd_ipa->stats.num_max_pm_queue = dequeued;
4593}
4594
4595/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004596 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004597 * @priv: pointer to private data registered with IPA (we register a
4598 * pointer to the interface-specific IPA context)
4599 * @evt: the IPA event which triggered the callback
4600 * @data: data associated with the event
4601 *
4602 * Return: None
4603 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004604static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004605 unsigned long data)
4606{
4607 struct hdd_ipa_priv *hdd_ipa = NULL;
4608 struct ipa_rx_data *ipa_tx_desc;
4609 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304610 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304612 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004613
Mukul Sharma81661ae2015-10-30 20:26:02 +05304614 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004615 ipa_tx_desc = (struct ipa_rx_data *)data;
4616 hdd_ipa = iface_context->hdd_ipa;
4617
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004619 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4620 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004621 iface_context->stats.num_tx_drop++;
4622 return;
4623 }
4624
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625 /*
4626 * When SSR is going on or driver is unloading, just drop the packets.
4627 * During SSR, there is no use in queueing the packets as STA has to
4628 * connect back any way
4629 */
4630 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304631 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004632 ipa_free_skb(ipa_tx_desc);
4633 iface_context->stats.num_tx_drop++;
4634 return;
4635 }
4636
4637 skb = ipa_tx_desc->skb;
4638
Yun Parkb187d542016-11-14 18:10:04 -08004639 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4640 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004641
4642 /*
4643 * If PROD resource is not requested here then there may be cases where
4644 * IPA hardware may be clocked down because of not having proper
4645 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4646 * workaround to request PROD resource while data is going over CONS
4647 * pipe to prevent the IPA hardware clockdown.
4648 */
4649 hdd_ipa_rm_request(hdd_ipa);
4650
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304651 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652 /*
4653 * If host is still suspended then queue the packets and these will be
4654 * drained later when resume completes. When packet is arrived here and
4655 * host is suspended, this means that there is already resume is in
4656 * progress.
4657 */
4658 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304659 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4661 pm_tx_cb->iface_context = iface_context;
4662 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304663 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004664 hdd_ipa->stats.num_tx_queued++;
4665
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304666 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 return;
4668 }
4669
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304670 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004671
4672 /*
4673 * If we are here means, host is not suspended, wait for the work queue
4674 * to finish.
4675 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004676 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004677
4678 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4679}
4680
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004681/*
4682 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4683 * @priv: pointer to private data registered with IPA (we register a
4684 * pointer to the interface-specific IPA context)
4685 * @evt: the IPA event which triggered the callback
4686 * @data: data associated with the event
4687 *
4688 * Return: None
4689 */
4690static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4691 unsigned long data)
4692{
4693 cds_ssr_protect(__func__);
4694 __hdd_ipa_i2w_cb(priv, evt, data);
4695 cds_ssr_unprotect(__func__);
4696}
4697
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004698/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004699 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004700 * @hdd_ctx: Global HDD context
4701 *
4702 * Return: 0 on success, negativer errno on error
4703 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004704static int __hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004705{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004706 struct hdd_ipa_priv *hdd_ipa;
4707
4708 if (wlan_hdd_validate_context(hdd_ctx))
4709 return 0;
4710
4711 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712
4713 if (!hdd_ipa_is_enabled(hdd_ctx))
4714 return 0;
4715
4716 /*
4717 * Check if IPA is ready for suspend, If we are here means, there is
4718 * high chance that suspend would go through but just to avoid any race
4719 * condition after suspend started, these checks are conducted before
4720 * allowing to suspend.
4721 */
4722 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4723 return -EAGAIN;
4724
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304725 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004726
4727 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304728 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004729 return -EAGAIN;
4730 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304731 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004732
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304733 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004734 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304735 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004736
4737 return 0;
4738}
4739
4740/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004741 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4742 * @hdd_ctx: Global HDD context
4743 *
4744 * Return: 0 on success, negativer errno on error
4745 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004746int hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004747{
4748 int ret;
4749
4750 cds_ssr_protect(__func__);
4751 ret = __hdd_ipa_suspend(hdd_ctx);
4752 cds_ssr_unprotect(__func__);
4753
4754 return ret;
4755}
4756
4757/**
4758 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004759 * hdd_ctx: Global HDD context
4760 *
4761 * Return: 0 on success, negative errno on error
4762 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004763static int __hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004764{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004765 struct hdd_ipa_priv *hdd_ipa;
4766
4767 if (wlan_hdd_validate_context(hdd_ctx))
4768 return 0;
4769
4770 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004771
4772 if (!hdd_ipa_is_enabled(hdd_ctx))
4773 return 0;
4774
4775 schedule_work(&hdd_ipa->pm_work);
4776
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304777 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004778 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304779 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004780
4781 return 0;
4782}
4783
4784/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004785 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4786 * hdd_ctx: Global HDD context
4787 *
4788 * Return: 0 on success, negative errno on error
4789 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004790int hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004791{
4792 int ret;
4793
4794 cds_ssr_protect(__func__);
4795 ret = __hdd_ipa_resume(hdd_ctx);
4796 cds_ssr_unprotect(__func__);
4797
4798 return ret;
4799}
4800
4801/**
Yun Park52b2b992016-09-22 15:49:51 -07004802 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4803 * @hdd_ipa: Global HDD IPA context
4804 *
4805 * Return: 0 on success, negative errno on error
4806 */
4807static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4808{
4809 int i;
4810 uint32_t max_desc_cnt;
4811 struct hdd_ipa_tx_desc *tmp_desc;
4812
Yun Parkd9c528e2017-08-30 16:34:57 -07004813 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
Yun Park52b2b992016-09-22 15:49:51 -07004814
4815 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4816
jiad14fe4fb2017-08-08 13:33:14 +08004817 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc) *
Yun Parkd9c528e2017-08-30 16:34:57 -07004818 max_desc_cnt);
Yun Park52b2b992016-09-22 15:49:51 -07004819
4820 if (!tmp_desc) {
4821 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkd9c528e2017-08-30 16:34:57 -07004822 "Free Tx descriptor allocation failed");
Yun Park52b2b992016-09-22 15:49:51 -07004823 return -ENOMEM;
4824 }
4825
4826 hdd_ipa->tx_desc_list = tmp_desc;
4827
4828 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004829 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004830 tmp_desc->id = i;
4831 tmp_desc->ipa_tx_desc_ptr = NULL;
4832 list_add_tail(&tmp_desc->link,
4833 &hdd_ipa->free_tx_desc_head);
4834 tmp_desc++;
4835 }
4836
4837 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4838 hdd_ipa->stats.num_tx_desc_error = 0;
4839
4840 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4841
4842 return 0;
4843}
4844
4845/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4847 * @hdd_ipa: Global HDD IPA context
4848 *
4849 * Return: 0 on success, negative errno on error
4850 */
4851static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4852{
4853 int i, ret = 0;
4854 struct ipa_sys_connect_params *ipa;
4855 uint32_t desc_fifo_sz;
4856
4857 /* The maximum number of descriptors that can be provided to a BAM at
4858 * once is one less than the total number of descriptors that the buffer
4859 * can contain.
4860 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4861 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4862 * be provided at once.
4863 * Because of above requirement, one extra descriptor will be added to
4864 * make sure hardware always has one descriptor.
4865 */
4866 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4867 + sizeof(struct sps_iovec);
4868
4869 /*setup TX pipes */
4870 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4871 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4872
4873 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4874 ipa->desc_fifo_sz = desc_fifo_sz;
4875 ipa->priv = &hdd_ipa->iface_context[i];
4876 ipa->notify = hdd_ipa_i2w_cb;
4877
4878 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4879 ipa->ipa_ep_cfg.hdr.hdr_len =
4880 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4881 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4882 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4883 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4884 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4885 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4886 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4887 } else {
4888 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4889 }
4890 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4891
4892 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4893 ipa->keep_ipa_awake = 1;
4894
4895 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4896 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004897 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4898 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004899 goto setup_sys_pipe_fail;
4900 }
4901 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4902 }
4903
4904 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4905 /*
4906 * Hard code it here, this can be extended if in case
4907 * PROD pipe is also per interface.
4908 * Right now there is no advantage of doing this.
4909 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004910 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4911
Yun Parkb4f591d2017-03-29 15:51:01 -07004912 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004913
4914 ipa->desc_fifo_sz = desc_fifo_sz;
4915 ipa->priv = hdd_ipa;
4916 ipa->notify = hdd_ipa_w2i_cb;
4917
4918 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4919 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4920 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4921 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4922
4923 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4924 ipa->keep_ipa_awake = 1;
4925
4926 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4927 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304928 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004929 "Failed for RX pipe: %d", ret);
4930 goto setup_sys_pipe_fail;
4931 }
4932 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4933 }
4934
Yun Parkd9c528e2017-08-30 16:34:57 -07004935 /* Allocate free Tx desc list */
Yun Park52b2b992016-09-22 15:49:51 -07004936 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4937 if (ret)
4938 goto setup_sys_pipe_fail;
4939
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004940 return ret;
4941
4942setup_sys_pipe_fail:
4943
4944 while (--i >= 0) {
4945 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304946 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004947 sizeof(struct hdd_ipa_sys_pipe));
4948 }
4949
4950 return ret;
4951}
4952
4953/**
4954 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4955 * @hdd_ipa: Global HDD IPA context
4956 *
4957 * Return: None
4958 */
4959static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4960{
4961 int ret = 0, i;
Yun Parkd9c528e2017-08-30 16:34:57 -07004962 uint32_t max_desc_cnt;
Yun Park52b2b992016-09-22 15:49:51 -07004963 struct hdd_ipa_tx_desc *tmp_desc;
4964 struct ipa_rx_data *ipa_tx_desc;
4965
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004966 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4967 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004968 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4969 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004970 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304971 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004972 ret);
4973
4974 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4975 }
4976 }
Yun Park52b2b992016-09-22 15:49:51 -07004977
4978 if (hdd_ipa->tx_desc_list) {
Yun Parkd9c528e2017-08-30 16:34:57 -07004979 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4980
Yun Park52b2b992016-09-22 15:49:51 -07004981 qdf_spin_lock_bh(&hdd_ipa->q_lock);
Yun Parkd9c528e2017-08-30 16:34:57 -07004982 for (i = 0; i < max_desc_cnt; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004983 tmp_desc = hdd_ipa->tx_desc_list + i;
4984 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4985 if (ipa_tx_desc)
4986 ipa_free_skb(ipa_tx_desc);
4987 }
4988 tmp_desc = hdd_ipa->tx_desc_list;
4989 hdd_ipa->tx_desc_list = NULL;
4990 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4991 hdd_ipa->stats.num_tx_desc_error = 0;
4992 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4993 qdf_mem_free(tmp_desc);
4994 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004995}
4996
4997/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004998 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4999 * @iface_context: interface-specific IPA context
5000 *
5001 * Return: None
5002 */
5003static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
5004{
Yun Park199c2ed2017-10-02 11:24:22 -07005005 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07005006
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005007 if (iface_context == NULL)
5008 return;
Orhan K AKYILDIZ3332be32017-05-31 15:36:31 -07005009 if (iface_context->adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
5010 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
5011 "%s: bad adapter(%pK).magic(%d)!",
5012 __func__, iface_context->adapter,
5013 iface_context->adapter->magic);
5014 return;
5015 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005016
Yun Parkb4f591d2017-03-29 15:51:01 -07005017 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
5018 iface_context->adapter->dev->name,
5019 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005020
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305021 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005022 iface_context->adapter->ipa_context = NULL;
5023 iface_context->adapter = NULL;
5024 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305025 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005026 iface_context->ifa_address = 0;
5027 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305028 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005029 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05305030 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031 }
5032 iface_context->hdd_ipa->num_iface--;
Yun Park199c2ed2017-10-02 11:24:22 -07005033 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: num_iface=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005034 iface_context->hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005035}
5036
5037/**
5038 * hdd_ipa_setup_iface() - Setup IPA on a given interface
5039 * @hdd_ipa: HDD IPA global context
5040 * @adapter: Interface upon which IPA is being setup
5041 * @sta_id: Station ID of the API instance
5042 *
5043 * Return: 0 on success, negative errno value on error
5044 */
5045static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07005046 struct hdd_adapter *adapter, uint8_t sta_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005047{
5048 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Park0dad1002017-07-14 14:57:01 -07005049 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
5050 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051 void *tl_context = NULL;
5052 int i, ret = 0;
5053
Yun Park199c2ed2017-10-02 11:24:22 -07005054 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
Yun Parkfec73dc2017-09-06 10:40:07 -07005055
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
5057 * channel change indication. Since these indications are sent by lower
5058 * layer as SAP updates and IPA doesn't have to do anything for these
5059 * updates so ignoring!
5060 */
Krunal Sonibe766b02016-03-10 13:00:44 -08005061 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005062 return 0;
5063
5064 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5065 if (hdd_ipa->iface_context[i].adapter == NULL) {
5066 iface_context = &(hdd_ipa->iface_context[i]);
5067 break;
5068 }
5069 }
5070
5071 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305072 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 "All the IPA interfaces are in use");
5074 ret = -ENOMEM;
5075 goto end;
5076 }
5077
5078 adapter->ipa_context = iface_context;
5079 iface_context->adapter = adapter;
5080 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005081 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Yun Park0dad1002017-07-14 14:57:01 -07005082 soc, (struct cdp_pdev *)pdev, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005083 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305084 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005085 "Not able to get TL context sta_id: %d", sta_id);
5086 ret = -EINVAL;
5087 goto end;
5088 }
5089
5090 iface_context->tl_context = tl_context;
5091
Yun Parkb4f591d2017-03-29 15:51:01 -07005092 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
5093 adapter->dev->name, adapter->dev->dev_addr,
5094 iface_context->prod_client,
5095 iface_context->cons_client,
5096 adapter->sessionId,
5097 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005098 if (ret)
5099 goto end;
5100
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005101 hdd_ipa->num_iface++;
Yun Parkfec73dc2017-09-06 10:40:07 -07005102
Yun Park199c2ed2017-10-02 11:24:22 -07005103 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: num_iface=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005104 hdd_ipa->num_iface);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005105 return ret;
5106
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005107end:
5108 if (iface_context)
5109 hdd_ipa_cleanup_iface(iface_context);
5110 return ret;
5111}
5112
Yun Parka27049a2016-10-11 12:30:49 -07005113#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005114/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005115 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Jeff Johnson4929cd92017-10-06 19:21:57 -07005116 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005117 * @mcc_mode: 0=MCC/1=SCC
5118 *
5119 * Return: 0 on success, negative errno value on error
5120 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07005121static int __hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx,
5122 bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123{
5124 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305125 QDF_STATUS status;
Jeff Johnson089d0432017-10-02 13:27:21 -07005126 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005127 struct ipa_msg_meta meta;
5128 struct ipa_wlan_msg *msg;
5129 int ret;
5130
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005131 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132 return -EINVAL;
5133
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005134 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
5135 return -EINVAL;
5136
5137 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005139 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305140 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson089d0432017-10-02 13:27:21 -07005141 adapter = adapter_node->adapter;
5142 if (adapter->device_mode == QDF_STA_MODE ||
5143 adapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005144 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnson089d0432017-10-02 13:27:21 -07005145 adapter->device_mode);
5146 hdd_deinit_tx_rx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005147 }
5148 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005149 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005150 adapter_node = next;
5151 }
5152 }
5153
5154 /* Send SCC/MCC Switching event to IPA */
5155 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305156 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005158 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 return -ENOMEM;
5160 }
5161
5162 meta.msg_type = mcc_mode ?
5163 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08005164 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165
5166 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5167
5168 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005169 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005170 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305171 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005172 }
5173
5174 return ret;
5175}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005176
5177/**
5178 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
5179 * @mcc_mode: 0=MCC/1=SCC
5180 *
5181 * Return: 0 on success, negative errno value on error
5182 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005183int hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005184{
5185 int ret;
5186
5187 cds_ssr_protect(__func__);
5188 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
5189 cds_ssr_unprotect(__func__);
5190
5191 return ret;
5192}
Yun Parka27049a2016-10-11 12:30:49 -07005193#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194
5195/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07005196 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
5197 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
5198 *
5199 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
5200 */
5201static enum ipa_wlan_event
5202hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
5203{
5204 enum ipa_wlan_event ipa_event;
5205
5206 switch (hdd_ipa_event_type) {
5207 case HDD_IPA_CLIENT_CONNECT:
5208 ipa_event = WLAN_CLIENT_CONNECT;
5209 break;
5210 case HDD_IPA_CLIENT_DISCONNECT:
5211 ipa_event = WLAN_CLIENT_DISCONNECT;
5212 break;
5213 case HDD_IPA_AP_CONNECT:
5214 ipa_event = WLAN_AP_CONNECT;
5215 break;
5216 case HDD_IPA_AP_DISCONNECT:
5217 ipa_event = WLAN_AP_DISCONNECT;
5218 break;
5219 case HDD_IPA_STA_CONNECT:
5220 ipa_event = WLAN_STA_CONNECT;
5221 break;
5222 case HDD_IPA_STA_DISCONNECT:
5223 ipa_event = WLAN_STA_DISCONNECT;
5224 break;
5225 case HDD_IPA_CLIENT_CONNECT_EX:
5226 ipa_event = WLAN_CLIENT_CONNECT_EX;
5227 break;
5228 case HDD_IPA_WLAN_EVENT_MAX:
5229 default:
5230 ipa_event = IPA_WLAN_EVENT_MAX;
5231 break;
5232 }
5233 return ipa_event;
5234
5235}
5236
5237/**
5238 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005239 * @adapter: adapter upon which the event was received
5240 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07005241 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005242 * @mac_address: MAC address associated with the event
5243 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07005244 * This function is meant to be called from within wlan_hdd_ipa.c
5245 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005246 * Return: 0 on success, negative errno value on error
5247 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005248static int __hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005249 enum ipa_wlan_event type, uint8_t *mac_addr)
5250{
5251 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5252 struct ipa_msg_meta meta;
5253 struct ipa_wlan_msg *msg;
5254 struct ipa_wlan_msg_ex *msg_ex = NULL;
5255 int ret;
5256
Yun Park46255682017-10-09 15:56:34 -07005257 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "%s: EVT: %s, MAC: %pM, sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5259 mac_addr, sta_id);
5260
5261 if (type >= IPA_WLAN_EVENT_MAX)
5262 return -EINVAL;
5263
5264 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5265 return -EINVAL;
5266
5267 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305268 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005269 return -EINVAL;
5270 }
5271
5272 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5273 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005274 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005275 return 0;
5276 }
5277
5278 /*
5279 * During IPA UC resource loading/unloading new events can be issued.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005280 */
Yun Park777d7242017-03-30 15:38:33 -07005281 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5282 (hdd_ipa->resource_loading || hdd_ipa->resource_unloading)) {
5283 unsigned int pending_event_count;
5284 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005285
Yun Park46255682017-10-09 15:56:34 -07005286 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park777d7242017-03-30 15:38:33 -07005287 "%s:IPA resource %s inprogress",
5288 hdd_ipa_wlan_event_to_str(type),
5289 hdd_ipa->resource_loading ?
5290 "load" : "unload");
5291
5292 /* Wait until completion of the long/unloading */
5293 ret = wait_for_completion_timeout(&hdd_ipa->ipa_resource_comp,
5294 msecs_to_jiffies(IPA_RESOURCE_COMP_WAIT_TIME));
5295 if (!ret) {
5296 /*
5297 * If timed out, store the events separately and
5298 * handle them later.
5299 */
Yun Park46255682017-10-09 15:56:34 -07005300 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park777d7242017-03-30 15:38:33 -07005301 "IPA resource %s timed out",
5302 hdd_ipa->resource_loading ?
5303 "load" : "unload");
Yun Park7c4f31b2016-11-30 10:09:21 -08005304
Yun Park777d7242017-03-30 15:38:33 -07005305 if (hdd_ipa->resource_loading) {
5306 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005307
Yun Park777d7242017-03-30 15:38:33 -07005308 pending_event_count =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005309 qdf_list_size(&hdd_ipa->pending_event);
Yun Park777d7242017-03-30 15:38:33 -07005310 if (pending_event_count >=
5311 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
5312 hdd_debug(
5313 "Reached max pending event count");
5314 qdf_list_remove_front(
5315 &hdd_ipa->pending_event,
5316 (qdf_list_node_t **)&pending_event);
5317 } else {
5318 pending_event =
5319 (struct ipa_uc_pending_event *)
5320 qdf_mem_malloc(sizeof(
5321 struct ipa_uc_pending_event));
5322 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005323
Yun Park777d7242017-03-30 15:38:33 -07005324 if (!pending_event) {
5325 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5326 "Pending event memory alloc fail");
5327 qdf_mutex_release(&hdd_ipa->ipa_lock);
5328 return -ENOMEM;
5329 }
5330
5331 pending_event->adapter = adapter;
5332 pending_event->sta_id = sta_id;
5333 pending_event->type = type;
5334 qdf_mem_copy(pending_event->mac_addr,
5335 mac_addr, QDF_MAC_ADDR_SIZE);
5336 qdf_list_insert_back(&hdd_ipa->pending_event,
5337 &pending_event->node);
5338
Yun Park64c405e2017-01-10 22:35:51 -08005339 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005340 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005341 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005342 }
Yun Park46255682017-10-09 15:56:34 -07005343 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Jeff Johnson4929cd92017-10-06 19:21:57 -07005344 "IPA resource %s completed",
5345 hdd_ipa->resource_loading ?
5346 "load" : "unload");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005347 }
5348
5349 hdd_ipa->stats.event[type]++;
5350
Leo Chang3bc8fed2015-11-13 10:59:47 -08005351 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005352 switch (type) {
5353 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005354 qdf_mutex_acquire(&hdd_ipa->event_lock);
5355
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005356 /* STA already connected and without disconnect, connect again
5357 * This is Roaming scenario
5358 */
5359 if (hdd_ipa->sta_connected)
5360 hdd_ipa_cleanup_iface(adapter->ipa_context);
5361
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005362 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5363 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305364 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005365 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005366 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005367
Yun Park8f289c82016-10-18 16:38:21 -07005368 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5369 (hdd_ipa->sap_num_connected_sta > 0) &&
5370 !hdd_ipa->sta_connected) {
5371 qdf_mutex_release(&hdd_ipa->event_lock);
5372 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005373 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005374 qdf_mutex_acquire(&hdd_ipa->event_lock);
5375 }
5376
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005377 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005378 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005379 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005380
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005381 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005382
5383 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005384
Yun Park199c2ed2017-10-02 11:24:22 -07005385 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "sta_connected=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005386 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005387 break;
5388
5389 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005390 qdf_mutex_acquire(&hdd_ipa->event_lock);
5391
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392 /* For DFS channel we get two start_bss event (before and after
5393 * CAC). Also when ACS range includes both DFS and non DFS
5394 * channels, we could possibly change channel many times due to
5395 * RADAR detection and chosen channel may not be a DFS channels.
5396 * So dont return error here. Just discard the event.
5397 */
Yun Park8f289c82016-10-18 16:38:21 -07005398 if (adapter->ipa_context) {
5399 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005400 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005401 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005402
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005403 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5404 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005405 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005406 hdd_err("%s: Evt: %d, Interface setup failed",
5407 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005408 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005409 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005410
Yun Park8f289c82016-10-18 16:38:21 -07005411 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5412 qdf_mutex_release(&hdd_ipa->event_lock);
5413 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005414 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005415 qdf_mutex_acquire(&hdd_ipa->event_lock);
5416 }
5417
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005418 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005419 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005420 (adapter->ipa_context))->iface_id;
5421
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305422 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005423 break;
5424
5425 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305426 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005427
5428 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005429 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005430 hdd_err("%s: Evt: %d, STA already disconnected",
5431 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 return -EINVAL;
5433 }
Yun Parka37592b2016-06-11 17:10:28 -07005434
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005435 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005436
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005437 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005438 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005439 msg_ex->name);
5440 } else {
5441 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Park3b7152b2017-08-25 08:33:37 -07005442 if ((1 == hdd_ipa->num_iface) &&
Yun Parka37592b2016-06-11 17:10:28 -07005443 (HDD_IPA_UC_NUM_WDI_PIPE ==
Yun Park3b7152b2017-08-25 08:33:37 -07005444 hdd_ipa->activated_fw_pipe) &&
5445 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005446 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447 }
5448
Yun Park74127cf2016-09-18 11:22:41 -07005449 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5450 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005451 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005452 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005453 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005454 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005455 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5456 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005457 }
5458
Yun Park8f289c82016-10-18 16:38:21 -07005459 hdd_ipa_cleanup_iface(adapter->ipa_context);
5460
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305461 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkfec73dc2017-09-06 10:40:07 -07005462
Yun Park199c2ed2017-10-02 11:24:22 -07005463 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "sta_connected=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005464 hdd_ipa->sta_connected);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005465 break;
5466
5467 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005468 qdf_mutex_acquire(&hdd_ipa->event_lock);
5469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005470 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005471 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005472 hdd_err("%s: Evt: %d, SAP already disconnected",
5473 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005474 return -EINVAL;
5475 }
5476
Yun Park3b7152b2017-08-25 08:33:37 -07005477 if ((1 == hdd_ipa->num_iface) &&
5478 (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
5479 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005480 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005481 /*
5482 * We disable WDI pipes directly here since
5483 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5484 * processed when unloading WLAN driver is in
5485 * progress
5486 */
5487 hdd_ipa_uc_disable_pipes(hdd_ipa);
5488 } else {
Yun Park199c2ed2017-10-02 11:24:22 -07005489 /*
5490 * This shouldn't happen :
5491 * No interface left but WDI pipes are still
5492 * active - force close WDI pipes
5493 */
5494 WARN_ON(1);
5495 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN,
5496 "No interface left but WDI pipes are still active - force close WDI pipes");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005497 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5498 }
5499 }
5500
5501 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005502 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005503 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005504 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005505 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005506 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5507 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005508 }
Yun Parka37592b2016-06-11 17:10:28 -07005509
Yun Park8f289c82016-10-18 16:38:21 -07005510 hdd_ipa_cleanup_iface(adapter->ipa_context);
5511
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305512 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005513 break;
5514
5515 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005516 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005517 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005518 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305519 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005520 return 0;
5521 }
5522
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305523 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005524 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5525 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005526 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305527 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005528 "%s: STA ID %d found, not valid",
5529 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005530 return 0;
5531 }
Yun Park312f71a2015-12-08 10:22:42 -08005532
5533 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005534 if (hdd_ipa->sap_num_connected_sta == 0 &&
5535 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005536 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005537 hdd_ipa->sta_connected) {
5538 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005539 hdd_ipa_uc_offload_enable_disable(
5540 hdd_get_adapter(hdd_ipa->hdd_ctx,
5541 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005542 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005543 qdf_mutex_acquire(&hdd_ipa->event_lock);
5544 }
Yun Parka37592b2016-06-11 17:10:28 -07005545
Yun Park312f71a2015-12-08 10:22:42 -08005546 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5547 if (ret) {
Yun Park46255682017-10-09 15:56:34 -07005548 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
Yun Park312f71a2015-12-08 10:22:42 -08005549 "%s: handle 1st con ret %d",
5550 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005551
5552 if (hdd_ipa_uc_sta_is_enabled(
5553 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005554 hdd_ipa->sta_connected) {
5555 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005556 hdd_ipa_uc_offload_enable_disable(
5557 hdd_get_adapter(
5558 hdd_ipa->hdd_ctx,
5559 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005560 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005561 } else {
5562 qdf_mutex_release(&hdd_ipa->event_lock);
5563 }
Yun Parka37592b2016-06-11 17:10:28 -07005564
Yun Park312f71a2015-12-08 10:22:42 -08005565 return ret;
5566 }
5567 }
5568
5569 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005570
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305571 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572
5573 meta.msg_type = type;
5574 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5575 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305576 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005577
5578 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305579 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005580 "msg_ex allocation failed");
5581 return -ENOMEM;
5582 }
5583 strlcpy(msg_ex->name, adapter->dev->name,
5584 IPA_RESOURCE_NAME_MAX);
5585 msg_ex->num_of_attribs = 1;
5586 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5587 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5588 msg_ex->attribs[0].offset =
5589 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5590 } else {
5591 msg_ex->attribs[0].offset =
5592 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5593 }
5594 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5595 IPA_MAC_ADDR_SIZE);
5596
5597 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5598
5599 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005600 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305601 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305602 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005603 return ret;
5604 }
5605 hdd_ipa->stats.num_send_msg++;
Yun Parkfec73dc2017-09-06 10:40:07 -07005606
Yun Park199c2ed2017-10-02 11:24:22 -07005607 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "sap_num_connected_sta=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005608 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005609 return ret;
5610
5611 case WLAN_CLIENT_DISCONNECT:
5612 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005613 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005614 "%s: IPA UC OFFLOAD NOT ENABLED",
5615 msg_ex->name);
5616 return 0;
5617 }
5618
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305619 qdf_mutex_acquire(&hdd_ipa->event_lock);
Yun Park73ea8bb2017-08-25 07:27:39 -07005620 if (!hdd_ipa->sap_num_connected_sta) {
5621 qdf_mutex_release(&hdd_ipa->event_lock);
5622 hdd_err("%s: Evt: %d, Client already disconnected",
5623 msg_ex->name, meta.msg_type);
5624 return 0;
5625 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005626 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005627 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305628 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629 "%s: STA ID %d NOT found, not valid",
5630 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631 return 0;
5632 }
5633 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005634
Yun Park9b5030f2016-11-08 12:02:37 -08005635 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005636 if (!hdd_ipa->sap_num_connected_sta &&
5637 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005638 if ((false == hdd_ipa->resource_unloading)
5639 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305640 hdd_ipa->activated_fw_pipe) &&
5641 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005642 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5643 }
5644
Yun Park9b5030f2016-11-08 12:02:37 -08005645 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005646 hdd_ipa->sta_connected) {
5647 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005648 hdd_ipa_uc_offload_enable_disable(
5649 hdd_get_adapter(hdd_ipa->hdd_ctx,
5650 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005651 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005652 } else {
5653 qdf_mutex_release(&hdd_ipa->event_lock);
5654 }
Yun Park8f289c82016-10-18 16:38:21 -07005655 } else {
5656 qdf_mutex_release(&hdd_ipa->event_lock);
5657 }
Yun Parkfec73dc2017-09-06 10:40:07 -07005658
Yun Park199c2ed2017-10-02 11:24:22 -07005659 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "sap_num_connected_sta=%d",
Yun Parkfec73dc2017-09-06 10:40:07 -07005660 hdd_ipa->sap_num_connected_sta);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005661 break;
5662
5663 default:
5664 return 0;
5665 }
5666
5667 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305668 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005669 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305670 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671 return -ENOMEM;
5672 }
5673
5674 meta.msg_type = type;
5675 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5676 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5677
Srinivas Girigowda97852372017-03-06 16:52:59 -08005678 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005679 msg->name, meta.msg_type);
5680
5681 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5682
5683 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005684 hdd_err("%s: Evt: %d fail:%d",
5685 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305686 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005687 return ret;
5688 }
5689
5690 hdd_ipa->stats.num_send_msg++;
5691
5692end:
5693 return ret;
5694}
5695
5696/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005697 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005698 * @adapter: adapter upon which the event was received
5699 * @sta_id: station id for the event
5700 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5701 * @mac_address: MAC address associated with the event
5702 *
5703 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5704 *
5705 * Return: 0 on success, negative errno value on error
5706 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005707int hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005708 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5709{
5710 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005711 int ret = 0;
5712
5713 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005714
Leo Changa202b522016-10-14 16:13:50 -07005715 /* Data path offload only support for STA and SAP mode */
5716 if ((QDF_STA_MODE == adapter->device_mode) ||
5717 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005718 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005719
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005720 cds_ssr_unprotect(__func__);
5721
5722 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005723}
5724
5725/**
5726 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5727 * @hdd_ipa: Global HDD IPA context
5728 *
5729 * Return: None
5730 */
5731static void
5732hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5733{
5734 unsigned int pending_event_count;
5735 struct ipa_uc_pending_event *pending_event = NULL;
5736
5737 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005738 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07005739 "Pending Event Count %d", pending_event_count);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005740 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005741 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park46255682017-10-09 15:56:34 -07005742 "No Pending Event");
Mohit Khannafa99aea2016-05-12 21:43:13 -07005743 return;
5744 }
5745
5746 qdf_list_remove_front(&hdd_ipa->pending_event,
5747 (qdf_list_node_t **)&pending_event);
5748 while (pending_event != NULL) {
5749 __hdd_ipa_wlan_evt(pending_event->adapter,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005750 pending_event->sta_id,
Will Huang0ca39e22017-10-24 14:32:57 +08005751 pending_event->type,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005752 pending_event->mac_addr);
5753 qdf_mem_free(pending_event);
5754 pending_event = NULL;
5755 qdf_list_remove_front(&hdd_ipa->pending_event,
5756 (qdf_list_node_t **)&pending_event);
5757 }
5758}
5759
5760/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005761 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5762 * @state: IPA RM state value
5763 *
5764 * Return: ASCII string representing the IPA RM state
5765 */
5766static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5767{
5768 switch (state) {
5769 case HDD_IPA_RM_RELEASED:
5770 return "RELEASED";
5771 case HDD_IPA_RM_GRANT_PENDING:
5772 return "GRANT_PENDING";
5773 case HDD_IPA_RM_GRANTED:
5774 return "GRANTED";
5775 }
5776
5777 return "UNKNOWN";
5778}
5779
5780/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005781 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005782 * @hdd_ctx: HDD global context
5783 *
5784 * Allocate hdd_ipa resources, ipa pipe resource and register
5785 * wlan interface with IPA module.
5786 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305787 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005788 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005789static QDF_STATUS __hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005790{
5791 struct hdd_ipa_priv *hdd_ipa = NULL;
5792 int ret, i;
5793 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005794 struct ol_txrx_pdev_t *pdev = NULL;
Yun Park66f24c42017-03-20 10:39:47 -07005795 struct ipa_rm_perf_profile profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005796
5797 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305798 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005799
Yun Park199c2ed2017-10-02 11:24:22 -07005800 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "enter");
5801
Yun Parkbaa62862017-01-18 13:43:34 -08005802 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005803 if (!pdev) {
5804 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5805 goto fail_return;
5806 }
5807
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305808 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005809 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305810 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005811 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005812 }
5813
5814 hdd_ctx->hdd_ipa = hdd_ipa;
5815 ghdd_ipa = hdd_ipa;
5816 hdd_ipa->hdd_ctx = hdd_ctx;
5817 hdd_ipa->num_iface = 0;
5818
5819 /* Create the interface context */
5820 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5821 iface_context = &hdd_ipa->iface_context[i];
5822 iface_context->hdd_ipa = hdd_ipa;
5823 iface_context->cons_client =
5824 hdd_ipa_adapter_2_client[i].cons_client;
5825 iface_context->prod_client =
5826 hdd_ipa_adapter_2_client[i].prod_client;
5827 iface_context->iface_id = i;
5828 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305829 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005830 }
5831 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005832 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5833 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005834 }
5835
Leo Chang69c39692016-10-12 20:11:12 -07005836 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305837 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005838 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305839 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005840 qdf_list_create(&hdd_ipa->pending_event, 1000);
5841 qdf_mutex_create(&hdd_ipa->event_lock);
5842 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005843
5844 ret = hdd_ipa_setup_rm(hdd_ipa);
5845 if (ret)
5846 goto fail_setup_rm;
5847
5848 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5849 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305850 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005851 hdd_ipa->sap_num_connected_sta = 0;
5852 hdd_ipa->ipa_tx_packets_diff = 0;
5853 hdd_ipa->ipa_rx_packets_diff = 0;
5854 hdd_ipa->ipa_p_tx_packets = 0;
5855 hdd_ipa->ipa_p_rx_packets = 0;
5856 hdd_ipa->resource_loading = false;
5857 hdd_ipa->resource_unloading = false;
5858 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005859 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005860 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005861 /* Setup IPA sys_pipe for MCC */
5862 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5863 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5864 if (ret)
5865 goto fail_create_sys_pipe;
5866 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005867 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5868 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005869
5870 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5871 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5872 hdd_ipa_uc_fw_op_event_handler);
5873 hdd_ipa->uc_op_work[i].msg = NULL;
5874 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005875 } else {
5876 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5877 if (ret)
5878 goto fail_create_sys_pipe;
5879 }
5880
Yun Park66f24c42017-03-20 10:39:47 -07005881 /* When IPA clock scaling is disabled, initialze maximum clock */
5882 if (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)) {
5883 profile.max_supported_bandwidth_mbps = 800;
5884 hdd_debug("IPA clock scaling is disabled.");
5885 hdd_debug("Set initial CONS/PROD perf: %d",
5886 profile.max_supported_bandwidth_mbps);
5887 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
5888 &profile);
5889 if (ret) {
5890 hdd_err("RM CONS set perf profile failed: %d", ret);
5891 goto fail_create_sys_pipe;
5892 }
5893
5894 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
5895 &profile);
5896 if (ret) {
5897 hdd_err("RM PROD set perf profile failed: %d", ret);
5898 goto fail_create_sys_pipe;
5899 }
5900 }
5901
Yun Park777d7242017-03-30 15:38:33 -07005902 init_completion(&hdd_ipa->ipa_resource_comp);
5903
Yun Park199c2ed2017-10-02 11:24:22 -07005904 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: success");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305905 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005906
5907fail_create_sys_pipe:
5908 hdd_ipa_destroy_rm_resource(hdd_ipa);
5909fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305910 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305911 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005912 hdd_ctx->hdd_ipa = NULL;
5913 ghdd_ipa = NULL;
5914fail_return:
Yun Park199c2ed2017-10-02 11:24:22 -07005915 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "exit: fail");
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305916 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005917}
5918
5919/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005920 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5921 * @hdd_ctx: HDD global context
5922 *
5923 * Allocate hdd_ipa resources, ipa pipe resource and register
5924 * wlan interface with IPA module.
5925 *
5926 * Return: QDF_STATUS enumeration
5927 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005928QDF_STATUS hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005929{
5930 QDF_STATUS ret;
5931
5932 cds_ssr_protect(__func__);
5933 ret = __hdd_ipa_init(hdd_ctx);
5934 cds_ssr_unprotect(__func__);
5935
5936 return ret;
5937}
5938
Arun Khandavallicc544b32017-01-30 19:52:16 +05305939
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005940/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305941 * __hdd_ipa_flush - flush IPA exception path SKB's
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005942 * @hdd_ctx: HDD global context
5943 *
Govind Singh1dab23b2017-08-12 13:31:00 +05305944 * Return: none
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005945 */
Govind Singh1dab23b2017-08-12 13:31:00 +05305946static void __hdd_ipa_flush(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005947{
5948 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305949 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005950 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5951
5952 if (!hdd_ipa_is_enabled(hdd_ctx))
Govind Singh1dab23b2017-08-12 13:31:00 +05305953 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005955 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005956
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305957 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005958
Nirav Shahcbc6d722016-03-01 16:24:53 +05305959 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5960 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305961 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005962
5963 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005964 if (pm_tx_cb->ipa_tx_desc)
5965 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005966
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305967 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005968 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305969 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Govind Singh1dab23b2017-08-12 13:31:00 +05305970}
5971
5972/**
5973 * __hdd_ipa_cleanup - IPA cleanup function
5974 * @hdd_ctx: HDD global context
5975 *
5976 * Return: QDF_STATUS enumeration
5977 */
5978static QDF_STATUS __hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
5979{
5980 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5981 int i;
5982 struct hdd_ipa_iface_context *iface_context = NULL;
5983
5984 if (!hdd_ipa_is_enabled(hdd_ctx))
5985 return QDF_STATUS_SUCCESS;
5986
5987 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5988 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5989 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5990 }
5991
5992 /* Teardown IPA sys_pipe for MCC */
5993 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5994 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5995
5996 hdd_ipa_destroy_rm_resource(hdd_ipa);
5997
5998 __hdd_ipa_flush(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005999
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306000 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006001 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006002
6003 /* destory the interface lock */
6004 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6005 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306006 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006007 }
6008
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006009 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08006010 if (ipa_uc_dereg_rdyCB())
6011 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
6012 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006013 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306014 qdf_mutex_destroy(&hdd_ipa->event_lock);
6015 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkd8fb1a82017-10-13 16:48:20 -07006016 qdf_list_destroy(&hdd_ipa->pending_event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006017
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006018 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
6019 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
6020 hdd_ipa->uc_op_work[i].msg = NULL;
6021 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006022 }
6023
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306024 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006025 hdd_ctx->hdd_ipa = NULL;
6026
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306027 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006028}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006029
6030/**
Govind Singh1dab23b2017-08-12 13:31:00 +05306031 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_flush
6032 * @hdd_ctx: HDD global context
6033 *
6034 * Return: None
6035 */
6036void hdd_ipa_flush(struct hdd_context *hdd_ctx)
6037{
6038 cds_ssr_protect(__func__);
6039 __hdd_ipa_flush(hdd_ctx);
6040 cds_ssr_unprotect(__func__);
6041}
6042
6043/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006044 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
6045 * @hdd_ctx: HDD global context
6046 *
6047 * Return: QDF_STATUS enumeration
6048 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07006049QDF_STATUS hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006050{
6051 QDF_STATUS ret;
6052
6053 cds_ssr_protect(__func__);
6054 ret = __hdd_ipa_cleanup(hdd_ctx);
6055 cds_ssr_unprotect(__func__);
6056
6057 return ret;
6058}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006059#endif /* IPA_OFFLOAD */