blob: 248752c211c11892dccb9f58695195b265075ef8 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
jge62037862016-12-09 10:44:33 +08002 * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ipa.c
30 *
31 * WLAN HDD and ipa interface implementation
32 * Originally written by Qualcomm Atheros, Inc
33 */
34
35#ifdef IPA_OFFLOAD
36
37/* Include Files */
Dustin Brown0bec9a92017-08-17 15:44:34 -070038#include <linux/ipa.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080039#include <wlan_hdd_includes.h>
40#include <wlan_hdd_ipa.h>
41
42#include <linux/etherdevice.h>
43#include <linux/atomic.h>
44#include <linux/netdevice.h>
45#include <linux/skbuff.h>
46#include <linux/list.h>
47#include <linux/debugfs.h>
48#include <linux/inetdevice.h>
49#include <linux/ip.h>
50#include <wlan_hdd_softap_tx_rx.h>
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +053051#include <ol_txrx.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070052#include <cdp_txrx_peer_ops.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080053
54#include "cds_sched.h"
55
56#include "wma.h"
57#include "wma_api.h"
Prakash Dhavali87b38e32016-11-14 16:22:53 -080058#include "wal_rx_desc.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080059
Dhanashri Atreb08959a2016-03-01 17:28:03 -080060#include "cdp_txrx_ipa.h"
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080061#include "wlan_policy_mgr_api.h"
62
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080063#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
Yun Parkb4f591d2017-03-29 15:51:01 -070065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080066#define HDD_IPA_UC_NUM_WDI_PIPE 2
67#define HDD_IPA_UC_MAX_PENDING_EVENT 33
68
69#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
70#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
71#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
72#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
73
74#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
75#define HDD_IPA_MAX_IFACE 3
76#define HDD_IPA_MAX_SYSBAM_PIPE 4
Yun Parkb4f591d2017-03-29 15:51:01 -070077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080078#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
79#define HDD_IPA_ENABLE_MASK BIT(0)
80#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
81#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
82#define HDD_IPA_RM_ENABLE_MASK BIT(3)
83#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
84#define HDD_IPA_UC_ENABLE_MASK BIT(5)
85#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
86#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
87
Yun Parkf19e07d2015-11-20 11:34:27 -080088#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
89
tfyu0380a972017-07-13 18:19:37 +080090#define IPA_WLAN_RX_SOFTIRQ_THRESH 16
91
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -070092enum hdd_ipa_uc_op_code {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080093 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
94 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
95 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
96 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
97 HDD_IPA_UC_OPCODE_STATS = 4,
Yun Park637d6482016-10-05 10:51:33 -070098#ifdef FEATURE_METERING
99 HDD_IPA_UC_OPCODE_SHARING_STATS = 5,
100 HDD_IPA_UC_OPCODE_QUOTA_RSP = 6,
101 HDD_IPA_UC_OPCODE_QUOTA_IND = 7,
102#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800103 HDD_IPA_UC_OPCODE_UC_READY = 8,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800104 /* keep this last */
105 HDD_IPA_UC_OPCODE_MAX
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700106};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800107
108/**
109 * enum - Reason codes for stat query
110 *
111 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
112 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
113 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
Yun Parkb187d542016-11-14 18:10:04 -0800114 * @HDD_IPA_UC_STAT_REASON_DUMP_INFO: For debug info dump
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800115 */
116enum {
117 HDD_IPA_UC_STAT_REASON_NONE,
118 HDD_IPA_UC_STAT_REASON_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -0800119 HDD_IPA_UC_STAT_REASON_BW_CAL,
120 HDD_IPA_UC_STAT_REASON_DUMP_INFO
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800121};
122
123/**
124 * enum hdd_ipa_rm_state - IPA resource manager state
125 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
126 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
127 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
128 */
129enum hdd_ipa_rm_state {
130 HDD_IPA_RM_RELEASED,
131 HDD_IPA_RM_GRANT_PENDING,
132 HDD_IPA_RM_GRANTED,
133};
134
135struct llc_snap_hdr {
136 uint8_t dsap;
137 uint8_t ssap;
138 uint8_t resv[4];
139 __be16 eth_type;
140} __packed;
141
Leo Chang3bc8fed2015-11-13 10:59:47 -0800142/**
143 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
144 * @eth: ether II header
145 * @llc_snap: LLC snap header
146 *
147 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800148struct hdd_ipa_tx_hdr {
149 struct ethhdr eth;
150 struct llc_snap_hdr llc_snap;
151} __packed;
152
Leo Chang3bc8fed2015-11-13 10:59:47 -0800153/**
154 * struct frag_header - fragment header type registered to IPA hardware
155 * @length: fragment length
156 * @reserved1: Reserved not used
157 * @reserved2: Reserved not used
158 *
159 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800160struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800161 uint16_t length;
162 uint32_t reserved1;
163 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800164} __packed;
165
Leo Chang3bc8fed2015-11-13 10:59:47 -0800166/**
167 * struct ipa_header - ipa header type registered to IPA hardware
168 * @vdev_id: vdev id
169 * @reserved: Reserved not used
170 *
171 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800172struct ipa_header {
173 uint32_t
174 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
175 reserved:24;
176} __packed;
177
Leo Chang3bc8fed2015-11-13 10:59:47 -0800178/**
179 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
180 * @frag_hd: fragment header
181 * @ipa_hd: ipa header
182 * @eth: ether II header
183 *
184 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800185struct hdd_ipa_uc_tx_hdr {
186 struct frag_header frag_hd;
187 struct ipa_header ipa_hd;
188 struct ethhdr eth;
189} __packed;
190
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800191/**
192 * struct hdd_ipa_cld_hdr - IPA CLD Header
193 * @reserved: reserved fields
194 * @iface_id: interface ID
195 * @sta_id: Station ID
196 *
197 * Packed 32-bit structure
198 * +----------+----------+--------------+--------+
199 * | Reserved | QCMAP ID | interface id | STA ID |
200 * +----------+----------+--------------+--------+
201 */
202struct hdd_ipa_cld_hdr {
203 uint8_t reserved[2];
204 uint8_t iface_id;
205 uint8_t sta_id;
206} __packed;
207
208struct hdd_ipa_rx_hdr {
209 struct hdd_ipa_cld_hdr cld_hdr;
210 struct ethhdr eth;
211} __packed;
212
213struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700214 bool exception;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700215 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800216 struct hdd_ipa_iface_context *iface_context;
217 struct ipa_rx_data *ipa_tx_desc;
218};
219
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800220struct hdd_ipa_sys_pipe {
221 uint32_t conn_hdl;
222 uint8_t conn_hdl_valid;
223 struct ipa_sys_connect_params ipa_sys_params;
224};
225
226struct hdd_ipa_iface_stats {
227 uint64_t num_tx;
228 uint64_t num_tx_drop;
229 uint64_t num_tx_err;
230 uint64_t num_tx_cac_drop;
231 uint64_t num_rx_prefilter;
232 uint64_t num_rx_ipa_excep;
233 uint64_t num_rx_recv;
234 uint64_t num_rx_recv_mul;
235 uint64_t num_rx_send_desc_err;
236 uint64_t max_rx_mul;
237};
238
239struct hdd_ipa_priv;
240
241struct hdd_ipa_iface_context {
242 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700243 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800244 void *tl_context;
245
246 enum ipa_client_type cons_client;
247 enum ipa_client_type prod_client;
248
249 uint8_t iface_id; /* This iface ID */
250 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530251 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800252 uint32_t ifa_address;
253 struct hdd_ipa_iface_stats stats;
254};
255
256struct hdd_ipa_stats {
257 uint32_t event[IPA_WLAN_EVENT_MAX];
258 uint64_t num_send_msg;
259 uint64_t num_free_msg;
260
261 uint64_t num_rm_grant;
262 uint64_t num_rm_release;
263 uint64_t num_rm_grant_imm;
264 uint64_t num_cons_perf_req;
265 uint64_t num_prod_perf_req;
266
267 uint64_t num_rx_drop;
268 uint64_t num_rx_ipa_tx_dp;
269 uint64_t num_rx_ipa_splice;
270 uint64_t num_rx_ipa_loop;
271 uint64_t num_rx_ipa_tx_dp_err;
272 uint64_t num_rx_ipa_write_done;
273 uint64_t num_max_ipa_tx_mul;
274 uint64_t num_rx_ipa_hw_maxed_out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800275
Yun Park52b2b992016-09-22 15:49:51 -0700276 uint64_t num_tx_desc_q_cnt;
277 uint64_t num_tx_desc_error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800278 uint64_t num_tx_comp_cnt;
279 uint64_t num_tx_queued;
280 uint64_t num_tx_dequeued;
281 uint64_t num_max_pm_queue;
282
283 uint64_t num_freeq_empty;
284 uint64_t num_pri_freeq_empty;
285 uint64_t num_rx_excep;
Yun Parkb187d542016-11-14 18:10:04 -0800286 uint64_t num_tx_fwd_ok;
287 uint64_t num_tx_fwd_err;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800288};
289
290struct ipa_uc_stas_map {
291 bool is_reserved;
292 uint8_t sta_id;
293};
294struct op_msg_type {
295 uint8_t msg_t;
296 uint8_t rsvd;
297 uint16_t op_code;
298 uint16_t len;
299 uint16_t rsvd_snd;
300};
301
302struct ipa_uc_fw_stats {
303 uint32_t tx_comp_ring_base;
304 uint32_t tx_comp_ring_size;
305 uint32_t tx_comp_ring_dbell_addr;
306 uint32_t tx_comp_ring_dbell_ind_val;
307 uint32_t tx_comp_ring_dbell_cached_val;
308 uint32_t tx_pkts_enqueued;
309 uint32_t tx_pkts_completed;
310 uint32_t tx_is_suspend;
311 uint32_t tx_reserved;
312 uint32_t rx_ind_ring_base;
313 uint32_t rx_ind_ring_size;
314 uint32_t rx_ind_ring_dbell_addr;
315 uint32_t rx_ind_ring_dbell_ind_val;
316 uint32_t rx_ind_ring_dbell_ind_cached_val;
317 uint32_t rx_ind_ring_rdidx_addr;
318 uint32_t rx_ind_ring_rd_idx_cached_val;
319 uint32_t rx_refill_idx;
320 uint32_t rx_num_pkts_indicated;
321 uint32_t rx_buf_refilled;
322 uint32_t rx_num_ind_drop_no_space;
323 uint32_t rx_num_ind_drop_no_buf;
324 uint32_t rx_is_suspend;
325 uint32_t rx_reserved;
326};
327
328struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530329 qdf_list_node_t node;
Jeff Johnson49d45e62017-08-29 14:30:42 -0700330 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800331 enum ipa_wlan_event type;
332 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530333 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800334};
335
336/**
337 * struct uc_rm_work_struct
338 * @work: uC RM work
339 * @event: IPA RM event
340 */
341struct uc_rm_work_struct {
342 struct work_struct work;
343 enum ipa_rm_event event;
344};
345
346/**
347 * struct uc_op_work_struct
348 * @work: uC OP work
349 * @msg: OP message
350 */
351struct uc_op_work_struct {
352 struct work_struct work;
353 struct op_msg_type *msg;
354};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800355
356/**
357 * struct uc_rt_debug_info
358 * @time: system time
359 * @ipa_excep_count: IPA exception packet count
360 * @rx_drop_count: IPA Rx drop packet count
361 * @net_sent_count: IPA Rx packet sent to network stack count
362 * @rx_discard_count: IPA Rx discard packet count
Yun Parkb187d542016-11-14 18:10:04 -0800363 * @tx_fwd_ok_count: IPA Tx forward success packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364 * @tx_fwd_count: IPA Tx forward packet count
365 * @rx_destructor_call: IPA Rx packet destructor count
366 */
367struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530368 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800369 uint64_t ipa_excep_count;
370 uint64_t rx_drop_count;
371 uint64_t net_sent_count;
372 uint64_t rx_discard_count;
Yun Parkb187d542016-11-14 18:10:04 -0800373 uint64_t tx_fwd_ok_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800374 uint64_t tx_fwd_count;
375 uint64_t rx_destructor_call;
376};
377
Yun Park637d6482016-10-05 10:51:33 -0700378#ifdef FEATURE_METERING
379struct ipa_uc_sharing_stats {
380 uint64_t ipv4_rx_packets;
381 uint64_t ipv4_rx_bytes;
382 uint64_t ipv6_rx_packets;
383 uint64_t ipv6_rx_bytes;
384 uint64_t ipv4_tx_packets;
385 uint64_t ipv4_tx_bytes;
386 uint64_t ipv6_tx_packets;
387 uint64_t ipv6_tx_bytes;
388};
389
390struct ipa_uc_quota_rsp {
391 uint8_t success;
392 uint8_t reserved[3];
393 uint32_t quota_lo; /* quota limit low bytes */
394 uint32_t quota_hi; /* quota limit high bytes */
395};
396
397struct ipa_uc_quota_ind {
398 uint64_t quota_bytes; /* quota limit in bytes */
399};
400#endif
401
Yun Park52b2b992016-09-22 15:49:51 -0700402/**
403 * struct hdd_ipa_tx_desc
404 * @link: link to list head
405 * @priv: pointer to priv list entry
406 * @id: Tx desc idex
407 * @ipa_tx_desc_ptr: pointer to IPA Tx descriptor
408 */
409struct hdd_ipa_tx_desc {
410 struct list_head link;
411 void *priv;
412 uint32_t id;
413 struct ipa_rx_data *ipa_tx_desc_ptr;
414};
415
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800416struct hdd_ipa_priv {
417 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
418 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
419 uint8_t num_iface;
420 enum hdd_ipa_rm_state rm_state;
421 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530422 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800423 * APIs as it is taken care gracefully. Without this, kernel would throw
424 * an warning if spin_lock_bh is used while IRQ is disabled
425 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530426 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800427 struct uc_rm_work_struct uc_rm_work;
428 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530429 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800430 struct delayed_work wake_lock_work;
431 bool wake_lock_released;
432
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530434 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800435 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530436 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800437 bool suspended;
438
Yun Park52b2b992016-09-22 15:49:51 -0700439 qdf_spinlock_t q_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800440
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800441 struct list_head pend_desc_head;
jiad14fe4fb2017-08-08 13:33:14 +0800442 uint16_t tx_desc_size;
Yun Park52b2b992016-09-22 15:49:51 -0700443 struct hdd_ipa_tx_desc *tx_desc_list;
444 struct list_head free_tx_desc_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800445
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700446 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800447
448 struct dentry *debugfs_dir;
449 struct hdd_ipa_stats stats;
450
451 struct notifier_block ipv4_notifier;
452 uint32_t curr_prod_bw;
453 uint32_t curr_cons_bw;
454
455 uint8_t activated_fw_pipe;
456 uint8_t sap_num_connected_sta;
457 uint8_t sta_connected;
458 uint32_t tx_pipe_handle;
459 uint32_t rx_pipe_handle;
460 bool resource_loading;
461 bool resource_unloading;
462 bool pending_cons_req;
463 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530464 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530465 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700466 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800467 uint32_t ipa_tx_packets_diff;
468 uint32_t ipa_rx_packets_diff;
469 uint32_t ipa_p_tx_packets;
470 uint32_t ipa_p_rx_packets;
471 uint32_t stat_req_reason;
472 uint64_t ipa_tx_forward;
473 uint64_t ipa_rx_discard;
474 uint64_t ipa_rx_net_send_count;
475 uint64_t ipa_rx_internel_drop_count;
476 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530477 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800478 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
479 unsigned int rt_buf_fill_index;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800480 struct ipa_wdi_in_params cons_pipe_in;
481 struct ipa_wdi_in_params prod_pipe_in;
482 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800483 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530484 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530485 qdf_mutex_t rt_debug_lock;
486 qdf_mutex_t ipa_lock;
Yun Parkb4f591d2017-03-29 15:51:01 -0700487
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800488 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
489 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Yun Park637d6482016-10-05 10:51:33 -0700490#ifdef FEATURE_METERING
491 struct ipa_uc_sharing_stats ipa_sharing_stats;
492 struct ipa_uc_quota_rsp ipa_quota_rsp;
493 struct ipa_uc_quota_ind ipa_quota_ind;
494 struct completion ipa_uc_sharing_stats_comp;
495 struct completion ipa_uc_set_quota_comp;
496#endif
Yun Park777d7242017-03-30 15:38:33 -0700497 struct completion ipa_resource_comp;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800498};
499
Leo Changcc923e22016-06-16 15:29:03 -0700500#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
501#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800502#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
503#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
504#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
505#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
506#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700507#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
508 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800509
510#define HDD_IPA_GET_IFACE_ID(_data) \
511 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
512
513#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530514 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800515 "%s:%d: "fmt, __func__, __LINE__, ## args)
516
Govind Singhb6a89772016-08-12 11:23:35 +0530517#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
518 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
519 "%s:%d: "fmt, __func__, __LINE__, ## args)
520
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800521#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
522 do { \
Yun Parkec845302016-12-15 09:22:57 -0800523 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
524 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525 } while (0)
526
527#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
528 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
529
530#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
Jeff Johnsond5ba8a62017-09-30 14:30:53 -0700531 (hdd_ipa)->ipa_rx_internel_drop_count++
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800532#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
Jeff Johnsond5ba8a62017-09-30 14:30:53 -0700533 (hdd_ipa)->ipa_rx_net_send_count++
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800534#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
535
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700536#if defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)
Leo Chang63d73612016-10-18 18:09:43 -0700537#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800538#else
539/* Do nothing */
Leo Chang63d73612016-10-18 18:09:43 -0700540#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700541#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800542
Yun Parkb187d542016-11-14 18:10:04 -0800543#define HDD_IPA_DBG_DUMP_RX_LEN 32
544#define HDD_IPA_DBG_DUMP_TX_LEN 48
545
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800546static struct hdd_ipa_adapter_2_client {
547 enum ipa_client_type cons_client;
548 enum ipa_client_type prod_client;
549} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
550 {
551 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
552 }, {
553 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
554 }, {
555 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
556 },
557};
558
Yun Park637d6482016-10-05 10:51:33 -0700559#ifdef FEATURE_METERING
560#define IPA_UC_SHARING_STATES_WAIT_TIME 500
561#define IPA_UC_SET_QUOTA_WAIT_TIME 500
562#endif
563
Yun Park777d7242017-03-30 15:38:33 -0700564#define IPA_RESOURCE_COMP_WAIT_TIME 100
565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800566static struct hdd_ipa_priv *ghdd_ipa;
567
568/* Local Function Prototypes */
569static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
570 unsigned long data);
571static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
572 unsigned long data);
Yun Parkb4f591d2017-03-29 15:51:01 -0700573#ifdef FEATURE_METERING
574static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
575 void *data);
576#else
577static void hdd_ipa_wdi_meter_notifier_cb(void);
578#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800579static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800580
581static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700582static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800583
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800584#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
585 defined(IPA_CLIENT_IS_MHI_CONS))
586/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800587 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
588 * @priv_ctxt: hdd ipa local context
589 *
590 * Will be called by IPA context.
591 * It's atomic context, then should be scheduled to kworker thread
592 *
593 * Return: None
594 */
595static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
596{
597 struct hdd_ipa_priv *hdd_ipa;
598 struct op_msg_type *msg;
599 struct uc_op_work_struct *uc_op_work;
600
601 if (priv_ctxt == NULL) {
602 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
603 return;
604 }
605
606 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
607 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
608 if (!msg) {
609 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
610 return;
611 }
612
613 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
614
615 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
616
617 /* When the same uC OPCODE is already pended, just return */
618 if (uc_op_work->msg)
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530619 goto done;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800620
621 uc_op_work->msg = msg;
622 schedule_work(&uc_op_work->work);
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530623
jiadd91a6842017-08-01 14:46:02 +0800624 /* work handler will free the msg buffer */
625 return;
626
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +0530627done:
628 qdf_mem_free(msg);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800629}
630
631/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800632 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
633 * @ctrl: WDI control value
634 *
635 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
636 *
637 * Return: 0 on message send to ipa, -1 on failure
638 */
639static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
640{
641 struct ipa_msg_meta meta;
642 struct ipa_wlan_msg *ipa_msg;
643 int ret = 0;
644
645 /* WDI enable message to IPA */
646 meta.msg_len = sizeof(*ipa_msg);
647 ipa_msg = qdf_mem_malloc(meta.msg_len);
648 if (ipa_msg == NULL) {
649 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
650 "msg allocation failed");
651 return -ENOMEM;
652 }
653
654 if (ctrl == true)
655 meta.msg_type = WLAN_WDI_ENABLE;
656 else
657 meta.msg_type = WLAN_WDI_DISABLE;
658
Srinivas Girigowda97852372017-03-06 16:52:59 -0800659 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800660 "ipa_send_msg(Evt:%d)", meta.msg_type);
661 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
662 if (ret) {
663 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
664 "ipa_send_msg(Evt:%d)-fail=%d",
665 meta.msg_type, ret);
666 qdf_mem_free(ipa_msg);
667 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800668 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800669}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800670
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800671/**
672 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
673 * @hdd_ipa: HDD IPA local context
674 *
675 * Register IPA UC ready callback function to IPA kernel driver
676 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
677 * open WDI pipe after WLAN driver loading finished
678 *
679 * Return: 0 Success
680 * -EPERM Registration fail
681 */
682static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
683{
684 struct ipa_wdi_uc_ready_params uc_ready_param;
685 int ret = 0;
686
687 hdd_ipa->uc_loaded = false;
688 uc_ready_param.priv = (void *)hdd_ipa;
689 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
690 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
691 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
692 "UC Ready CB register fail");
693 return -EPERM;
694 }
695 if (true == uc_ready_param.is_uC_ready) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700696 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800697 hdd_ipa->uc_loaded = true;
698 } else {
699 ret = hdd_ipa_uc_send_wdi_control_msg(false);
700 }
701
702 return ret;
703}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800704#else
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800705static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
706{
707 hdd_ipa->uc_loaded = true;
708 return 0;
709}
710
711static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
712{
713 return 0;
714}
715#endif
716
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800717/**
718 * hdd_ipa_is_enabled() - Is IPA enabled?
719 * @hdd_ctx: Global HDD context
720 *
721 * Return: true if IPA is enabled, false otherwise
722 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700723bool hdd_ipa_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_ENABLE_MASK);
726}
727
728/**
729 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
730 * @hdd_ctx: Global HDD context
731 *
732 * Return: true if IPA uC offload is enabled, false otherwise
733 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700734bool hdd_ipa_uc_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800735{
736 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
737}
738
739/**
740 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
741 * @hdd_ctx: Global HDD context
742 *
743 * Return: true if STA mode IPA uC offload is enabled, false otherwise
744 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700745static inline bool hdd_ipa_uc_sta_is_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800746{
747 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
748}
749
750/**
Guolei Bianca144d82016-11-10 11:07:42 +0800751 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
752 * @hdd_ipa: Global HDD IPA context
753 *
754 * Return: None
755 */
Guolei Bianca144d82016-11-10 11:07:42 +0800756static inline void hdd_ipa_uc_sta_reset_sta_connected(
757 struct hdd_ipa_priv *hdd_ipa)
758{
Yun Park637d6482016-10-05 10:51:33 -0700759 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800760 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700761 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800762}
Guolei Bianca144d82016-11-10 11:07:42 +0800763
764/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800765 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
766 * @hdd_ipa: Global HDD IPA context
767 *
768 * Return: true if pre-filter is enabled, otherwise false
769 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700770static inline bool hdd_ipa_is_pre_filter_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800771{
772 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
773 HDD_IPA_PRE_FILTER_ENABLE_MASK);
774}
775
776/**
777 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
778 * @hdd_ipa: Global HDD IPA context
779 *
780 * Return: true if IPv6 is enabled, otherwise false
781 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700782static inline bool hdd_ipa_is_ipv6_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_IPV6_ENABLE_MASK);
785}
786
787/**
788 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
789 * @hdd_ipa: Global HDD IPA context
790 *
791 * Return: true if resource manager is enabled, otherwise false
792 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700793static inline bool hdd_ipa_is_rm_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800794{
795 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
796}
797
798/**
799 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
800 * @hdd_ipa: Global HDD IPA context
801 *
802 * Return: true if resource manager is enabled, otherwise false
803 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700804static inline bool hdd_ipa_is_rt_debugging_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800805{
806 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
807}
808
809/**
810 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
811 * @hdd_ipa: Global HDD IPA context
812 *
813 * Return: true if clock scaling is enabled, otherwise false
814 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700815static inline bool hdd_ipa_is_clk_scaling_enabled(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800816{
817 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
818 HDD_IPA_CLK_SCALING_ENABLE_MASK |
819 HDD_IPA_RM_ENABLE_MASK);
820}
821
822/**
823 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
824 * @ctext: pointer to hdd context.
825 *
826 * If rt debug enabled, periodically called, and fill debug buffer
827 *
828 * Return: none
829 */
830static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
831{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700832 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800833 struct hdd_ipa_priv *hdd_ipa;
834 struct uc_rt_debug_info *dump_info = NULL;
835
836 if (wlan_hdd_validate_context(hdd_ctx))
837 return;
838
839 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700840 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 return;
842 }
843
844 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
845
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530846 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800847 dump_info = &hdd_ipa->rt_bug_buffer[
848 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
849
Deepthi Gowri6acee342016-10-28 15:00:38 +0530850 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800851 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
852 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
853 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800855 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
856 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800857 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
858 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530859 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800860
Anurag Chouhan210db072016-02-22 18:42:15 +0530861 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800862 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
863}
864
865/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700866 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800867 * @hdd_ctx: pointer to hdd context.
868 *
869 * If rt debug enabled, dump debug buffer contents based on requirement
870 *
871 * Return: none
872 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700873static void __hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874{
875 struct hdd_ipa_priv *hdd_ipa;
876 unsigned int dump_count;
877 unsigned int dump_index;
878 struct uc_rt_debug_info *dump_info = NULL;
879
880 if (wlan_hdd_validate_context(hdd_ctx))
881 return;
882
883 hdd_ipa = hdd_ctx->hdd_ipa;
884 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700885 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "IPA UC is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 return;
887 }
888
Chris Guo1751acf2017-07-03 14:09:01 +0800889 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
890 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
891 "%s: IPA RT debug is not enabled", __func__);
892 return;
893 }
894
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530895 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530897 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800898 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800899
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530900 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 for (dump_count = 0;
902 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
903 dump_count++) {
904 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
905 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
906 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530907 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530908 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 dump_info->time, dump_info->ipa_excep_count,
910 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800911 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 dump_info->rx_destructor_call,
913 dump_info->rx_discard_count);
914 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530915 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530916 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
918}
919
920/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700921 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
922 * __hdd_ipa_uc_rt_debug_host_dump
923 * @hdd_ctx: pointer to hdd context.
924 *
925 * If rt debug enabled, dump debug buffer contents based on requirement
926 *
927 * Return: none
928 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700929void hdd_ipa_uc_rt_debug_host_dump(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700930{
931 cds_ssr_protect(__func__);
932 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
933 cds_ssr_unprotect(__func__);
934}
935
936/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
938 * @ctext: pointer to hdd context.
939 *
940 * periodically called by timer expire
941 * will try to alloc dummy memory and detect out of memory condition
942 * if out of memory detected, dump wlan-ipa stats
943 *
944 * Return: none
945 */
946static void hdd_ipa_uc_rt_debug_handler(void *ctext)
947{
Jeff Johnsondd595cb2017-08-28 11:58:09 -0700948 struct hdd_context *hdd_ctx = (struct hdd_context *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700949 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800950 void *dummy_ptr = NULL;
951
952 if (wlan_hdd_validate_context(hdd_ctx))
953 return;
954
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700955 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
956
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800957 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700958 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
959 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800960 return;
961 }
962
963 /* Allocate dummy buffer periodically and free immediately. this will
964 * proactively detect OOM and if allocation fails dump ipa stats
965 */
966 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
967 GFP_KERNEL | GFP_ATOMIC);
968 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800969 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
970 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -0700971 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
972 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 } else {
974 kfree(dummy_ptr);
975 }
976
Anurag Chouhan210db072016-02-22 18:42:15 +0530977 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800978 HDD_IPA_UC_RT_DEBUG_PERIOD);
979}
980
981/**
Yun Parkb187d542016-11-14 18:10:04 -0800982 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800983 * @skb: packet pinter
984 *
985 * when free data packet, will be invoked by wlan client and will increase
986 * free counter
987 *
988 * Return: none
989 */
Jeff Johnsond7720632016-10-05 16:04:32 -0700990static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800991{
992 if (!ghdd_ipa) {
Yun Parkb4f591d2017-03-29 15:51:01 -0700993 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "invalid hdd context");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800994 return;
995 }
996
997 ghdd_ipa->ipa_rx_destructor_count++;
998}
999
1000/**
Yun Parkb187d542016-11-14 18:10:04 -08001001 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001002 * @hdd_ctx: hdd main context
1003 *
1004 * free all rt debugging resources
1005 *
1006 * Return: none
1007 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001008static void hdd_ipa_uc_rt_debug_deinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001010 struct hdd_ipa_priv *hdd_ipa;
1011
1012 if (wlan_hdd_validate_context(hdd_ctx))
1013 return;
1014
1015 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001016
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301017 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018
1019 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001020 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1021 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 return;
1023 }
1024
Anurag Chouhan210db072016-02-22 18:42:15 +05301025 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001026 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1027 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1028 }
1029 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1030
1031 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301032 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1033 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001034 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301035 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001036}
1037
1038/**
Yun Parkb187d542016-11-14 18:10:04 -08001039 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 * @hdd_ctx: hdd main context
1041 *
1042 * alloc and initialize all rt debugging resources
1043 *
1044 * Return: none
1045 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001046static void hdd_ipa_uc_rt_debug_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001047{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001048 struct hdd_ipa_priv *hdd_ipa;
1049
Chris Guo1751acf2017-07-03 14:09:01 +08001050 if (wlan_hdd_validate_context_in_loading(hdd_ctx))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001051 return;
1052
1053 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301055 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001056 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301057 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001058 sizeof(struct uc_rt_debug_info) *
1059 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1060 hdd_ipa->ipa_tx_forward = 0;
1061 hdd_ipa->ipa_rx_discard = 0;
1062 hdd_ipa->ipa_rx_net_send_count = 0;
1063 hdd_ipa->ipa_rx_internel_drop_count = 0;
1064 hdd_ipa->ipa_rx_destructor_count = 0;
1065
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001066 /* Reatime debug enable on feature enable */
1067 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Yun Parkb4f591d2017-03-29 15:51:01 -07001068 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1069 "IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001070 return;
1071 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001072
1073 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1074 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1075 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1076 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1077
Anurag Chouhan210db072016-02-22 18:42:15 +05301078 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001079 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301080 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001081 HDD_IPA_UC_RT_DEBUG_PERIOD);
1082
1083}
1084
1085/**
Yun Parkb187d542016-11-14 18:10:04 -08001086 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1087 * @hdd_ipa: HDD IPA struct
1088 *
1089 * Dump entries in struct hdd_ipa
1090 *
1091 * Return: none
1092 */
1093static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1094{
1095 int i;
1096
1097 /* HDD IPA */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001098 hdd_info("==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001099 "num_iface: %d\n"
1100 "rm_state: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001101 "rm_lock: %pK\n"
1102 "uc_rm_work: %pK\n"
1103 "uc_op_work: %pK\n"
1104 "wake_lock: %pK\n"
1105 "wake_lock_work: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001106 "wake_lock_released: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08001107 "tx_ref_cnt: %d\n"
1108 "pm_queue_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001109 "\thead: %pK\n"
1110 "\ttail: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001111 "\tqlen: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001112 "pm_work: %pK\n"
1113 "pm_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001114 "suspended: %d\n",
1115 hdd_ipa->num_iface,
1116 hdd_ipa->rm_state,
1117 &hdd_ipa->rm_lock,
1118 &hdd_ipa->uc_rm_work,
1119 &hdd_ipa->uc_op_work,
1120 &hdd_ipa->wake_lock,
1121 &hdd_ipa->wake_lock_work,
1122 hdd_ipa->wake_lock_released,
Yun Parkb187d542016-11-14 18:10:04 -08001123 hdd_ipa->tx_ref_cnt.counter,
1124 hdd_ipa->pm_queue_head.head,
1125 hdd_ipa->pm_queue_head.tail,
1126 hdd_ipa->pm_queue_head.qlen,
1127 &hdd_ipa->pm_work,
1128 &hdd_ipa->pm_lock,
1129 hdd_ipa->suspended);
Jeff Johnson36e74c42017-09-18 08:15:42 -07001130 hdd_err("\nq_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001131 "pend_desc_head----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001132 "\tnext: %pK\n"
1133 "\tprev: %pK\n"
1134 "hdd_ctx: %pK\n"
1135 "debugfs_dir: %pK\n"
1136 "stats: %pK\n"
1137 "ipv4_notifier: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001138 "curr_prod_bw: %d\n"
1139 "curr_cons_bw: %d\n"
1140 "activated_fw_pipe: %d\n"
1141 "sap_num_connected_sta: %d\n"
1142 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001143 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001144 hdd_ipa->pend_desc_head.next,
1145 hdd_ipa->pend_desc_head.prev,
1146 hdd_ipa->hdd_ctx,
1147 hdd_ipa->debugfs_dir,
1148 &hdd_ipa->stats,
1149 &hdd_ipa->ipv4_notifier,
1150 hdd_ipa->curr_prod_bw,
1151 hdd_ipa->curr_cons_bw,
1152 hdd_ipa->activated_fw_pipe,
1153 hdd_ipa->sap_num_connected_sta,
1154 (unsigned int)hdd_ipa->sta_connected
1155 );
Srinivas Girigowda97852372017-03-06 16:52:59 -08001156 hdd_info("\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001157 "rx_pipe_handle: 0x%x\n"
1158 "resource_loading: %d\n"
1159 "resource_unloading: %d\n"
1160 "pending_cons_req: %d\n"
1161 "pending_event----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001162 "\tanchor.next: %pK\n"
1163 "\tanchor.prev: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001164 "\tcount: %d\n"
1165 "\tmax_size: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001166 "event_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001167 "ipa_tx_packets_diff: %d\n"
1168 "ipa_rx_packets_diff: %d\n"
1169 "ipa_p_tx_packets: %d\n"
1170 "ipa_p_rx_packets: %d\n"
1171 "stat_req_reason: %d\n",
1172 hdd_ipa->tx_pipe_handle,
1173 hdd_ipa->rx_pipe_handle,
1174 hdd_ipa->resource_loading,
1175 hdd_ipa->resource_unloading,
1176 hdd_ipa->pending_cons_req,
1177 hdd_ipa->pending_event.anchor.next,
1178 hdd_ipa->pending_event.anchor.prev,
1179 hdd_ipa->pending_event.count,
1180 hdd_ipa->pending_event.max_size,
1181 &hdd_ipa->event_lock,
1182 hdd_ipa->ipa_tx_packets_diff,
1183 hdd_ipa->ipa_rx_packets_diff,
1184 hdd_ipa->ipa_p_tx_packets,
1185 hdd_ipa->ipa_p_rx_packets,
1186 hdd_ipa->stat_req_reason);
1187
Srinivas Girigowda97852372017-03-06 16:52:59 -08001188 hdd_info("assoc_stas_map([id]is_reserved/sta_id): ");
Yun Parkb187d542016-11-14 18:10:04 -08001189 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001190 hdd_info(" [%d]%d/%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001191 hdd_ipa->assoc_stas_map[i].is_reserved,
1192 hdd_ipa->assoc_stas_map[i].sta_id);
1193 }
1194}
1195
1196/**
1197 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1198 * @hdd_ipa: HDD IPA struct
1199 *
1200 * Dump entire struct hdd_ipa_sys_pipe
1201 *
1202 * Return: none
1203 */
1204static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1205{
1206 int i;
1207
1208 /* IPA SYS Pipes */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001209 hdd_info("==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001210
1211 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1212 struct hdd_ipa_sys_pipe *sys_pipe;
1213 struct ipa_sys_connect_params *ipa_sys_params;
1214
1215 sys_pipe = &hdd_ipa->sys_pipe[i];
1216 ipa_sys_params = &sys_pipe->ipa_sys_params;
1217
Srinivas Girigowda97852372017-03-06 16:52:59 -08001218 hdd_info("sys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001219 "\tconn_hdl: 0x%x\n"
1220 "\tconn_hdl_valid: %d\n"
1221 "\tnat_en: %d\n"
1222 "\thdr_len %d\n"
1223 "\thdr_additional_const_len: %d\n"
1224 "\thdr_ofst_pkt_size_valid: %d\n"
1225 "\thdr_ofst_pkt_size: %d\n"
1226 "\thdr_little_endian: %d\n"
1227 "\tmode: %d\n"
1228 "\tclient: %d\n"
1229 "\tdesc_fifo_sz: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001230 "\tpriv: %pK\n"
1231 "\tnotify: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001232 "\tskip_ep_cfg: %d\n"
1233 "\tkeep_ipa_awake: %d\n",
1234 i,
1235 sys_pipe->conn_hdl,
1236 sys_pipe->conn_hdl_valid,
1237 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1238 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1239 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1240 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1241 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1242 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1243 ipa_sys_params->ipa_ep_cfg.mode.mode,
1244 ipa_sys_params->client,
1245 ipa_sys_params->desc_fifo_sz,
1246 ipa_sys_params->priv,
1247 ipa_sys_params->notify,
1248 ipa_sys_params->skip_ep_cfg,
1249 ipa_sys_params->keep_ipa_awake);
1250 }
1251}
1252
1253/**
1254 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1255 * @hdd_ipa: HDD IPA struct
1256 *
1257 * Dump entire struct hdd_ipa_iface_context
1258 *
1259 * Return: none
1260 */
1261static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1262{
1263 int i;
1264
1265 /* IPA Interface Contexts */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001266 hdd_info("==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001267
1268 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1269 struct hdd_ipa_iface_context *iface_context;
1270
1271 iface_context = &hdd_ipa->iface_context[i];
1272
Srinivas Girigowda97852372017-03-06 16:52:59 -08001273 hdd_info("iface_context[%d]----\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001274 "\thdd_ipa: %pK\n"
1275 "\tadapter: %pK\n"
1276 "\ttl_context: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001277 "\tcons_client: %d\n"
1278 "\tprod_client: %d\n"
1279 "\tiface_id: %d\n"
1280 "\tsta_id: %d\n"
Jeff Johnson36e74c42017-09-18 08:15:42 -07001281 "\tinterface_lock: %pK\n"
Yun Parkb187d542016-11-14 18:10:04 -08001282 "\tifa_address: 0x%x\n",
1283 i,
1284 iface_context->hdd_ipa,
1285 iface_context->adapter,
1286 iface_context->tl_context,
1287 iface_context->cons_client,
1288 iface_context->prod_client,
1289 iface_context->iface_id,
1290 iface_context->sta_id,
1291 &iface_context->interface_lock,
1292 iface_context->ifa_address);
1293 }
1294}
1295
1296/**
1297 * hdd_ipa_dump_info() - dump HDD IPA struct
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001298 * @hdd_ctx: hdd main context
Yun Parkb187d542016-11-14 18:10:04 -08001299 *
1300 * Dump entire struct hdd_ipa
1301 *
1302 * Return: none
1303 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001304void hdd_ipa_dump_info(struct hdd_context *hdd_ctx)
Yun Parkb187d542016-11-14 18:10:04 -08001305{
1306 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1307
1308 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1309 hdd_ipa_dump_sys_pipe(hdd_ipa);
1310 hdd_ipa_dump_iface_context(hdd_ipa);
1311}
1312
1313/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001314 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1315 * enabled
1316 *
1317 * This routine is called to set TX flow info if IPA is enabled
1318 *
1319 * Return: None
1320 */
1321void hdd_ipa_set_tx_flow_info(void)
1322{
1323 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1324 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001325 struct hdd_adapter *adapter;
Jeff Johnsond377dce2017-10-04 10:32:42 -07001326 struct hdd_station_ctx *sta_ctx;
Jeff Johnson87251032017-08-29 13:31:11 -07001327 struct hdd_ap_ctx *hdd_ap_ctx;
Jeff Johnsonca2530c2017-09-30 18:25:40 -07001328 struct hdd_hostapd_state *hostapd_state;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001329 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1330 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1331 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1332 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1333 const char *p2pMode = "DEV";
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001334 struct hdd_context *hdd_ctx;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001335 cds_context_type *cds_ctx;
1336#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1337 uint8_t targetChannel = 0;
1338 uint8_t preAdapterChannel = 0;
1339 uint8_t channel24;
1340 uint8_t channel5;
Jeff Johnson49d45e62017-08-29 14:30:42 -07001341 struct hdd_adapter *preAdapterContext = NULL;
1342 struct hdd_adapter *adapter2_4 = NULL;
1343 struct hdd_adapter *adapter5 = NULL;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001344 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1345#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1346 struct wlan_objmgr_psoc *psoc;
1347
1348 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1349 if (!hdd_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001350 hdd_err("HDD context is NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001351 return;
1352 }
1353
1354 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1355 if (!cds_ctx) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001356 hdd_err("Invalid CDS Context");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001357 return;
1358 }
1359
1360 psoc = hdd_ctx->hdd_psoc;
1361 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1362 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07001363 adapter = adapterNode->adapter;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001364 switch (adapter->device_mode) {
1365 case QDF_STA_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001366 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001367 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001368 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001369 staChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001370 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001371 qdf_copy_macaddr(&staBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001372 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001373#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1374 targetChannel = staChannel;
1375#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1376 }
1377 break;
1378 case QDF_P2P_CLIENT_MODE:
Jeff Johnsond377dce2017-10-04 10:32:42 -07001379 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001380 if (eConnectionState_Associated ==
Jeff Johnsond377dce2017-10-04 10:32:42 -07001381 sta_ctx->conn_info.connState) {
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001382 p2pChannel =
Jeff Johnsond377dce2017-10-04 10:32:42 -07001383 sta_ctx->conn_info.operationChannel;
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001384 qdf_copy_macaddr(&p2pBssid,
Jeff Johnsond377dce2017-10-04 10:32:42 -07001385 &sta_ctx->conn_info.bssId);
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001386 p2pMode = "CLI";
1387#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1388 targetChannel = p2pChannel;
1389#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1390 }
1391 break;
1392 case QDF_P2P_GO_MODE:
1393 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1394 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1395 if (hostapd_state->bssState == BSS_START
1396 && hostapd_state->qdf_status ==
1397 QDF_STATUS_SUCCESS) {
1398 p2pChannel = hdd_ap_ctx->operatingChannel;
1399 qdf_copy_macaddr(&p2pBssid,
1400 &adapter->macAddressCurrent);
1401#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1402 targetChannel = p2pChannel;
1403#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1404 }
1405 p2pMode = "GO";
1406 break;
1407 case QDF_SAP_MODE:
1408 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1409 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1410 if (hostapd_state->bssState == BSS_START
1411 && hostapd_state->qdf_status ==
1412 QDF_STATUS_SUCCESS) {
1413 apChannel = hdd_ap_ctx->operatingChannel;
1414 qdf_copy_macaddr(&apBssid,
1415 &adapter->macAddressCurrent);
1416#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1417 targetChannel = apChannel;
1418#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1419 }
1420 break;
1421 case QDF_IBSS_MODE:
1422 default:
1423 break;
1424 }
1425#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1426 if (targetChannel) {
1427 /*
1428 * This is first adapter detected as active
1429 * set as default for none concurrency case
1430 */
1431 if (!preAdapterChannel) {
1432 /* If IPA UC data path is enabled,
1433 * target should reserve extra tx descriptors
1434 * for IPA data path.
1435 * Then host data path should allow less TX
1436 * packet pumping in case IPA
1437 * data path enabled
1438 */
1439 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1440 (QDF_SAP_MODE == adapter->device_mode)) {
1441 adapter->tx_flow_low_watermark =
1442 hdd_ctx->config->TxFlowLowWaterMark +
1443 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1444 } else {
1445 adapter->tx_flow_low_watermark =
1446 hdd_ctx->config->
1447 TxFlowLowWaterMark;
1448 }
1449 adapter->tx_flow_high_watermark_offset =
1450 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1451 cdp_fc_ll_set_tx_pause_q_depth(soc,
1452 adapter->sessionId,
1453 hdd_ctx->config->TxFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001454 hdd_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001455 adapter->device_mode,
1456 targetChannel,
1457 adapter->tx_flow_low_watermark,
1458 adapter->tx_flow_low_watermark +
1459 adapter->tx_flow_high_watermark_offset,
1460 hdd_ctx->config->TxFlowMaxQueueDepth);
1461 preAdapterChannel = targetChannel;
1462 preAdapterContext = adapter;
1463 } else {
1464 /*
1465 * SCC, disable TX flow control for both
1466 * SCC each adapter cannot reserve dedicated
1467 * channel resource, as a result, if any adapter
1468 * blocked OS Q by flow control,
1469 * blocked adapter will lost chance to recover
1470 */
1471 if (preAdapterChannel == targetChannel) {
1472 /* Current adapter */
1473 adapter->tx_flow_low_watermark = 0;
1474 adapter->
1475 tx_flow_high_watermark_offset = 0;
1476 cdp_fc_ll_set_tx_pause_q_depth(soc,
1477 adapter->sessionId,
1478 hdd_ctx->config->
1479 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001480 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001481 hdd_device_mode_to_string(
1482 adapter->device_mode),
1483 adapter->device_mode,
1484 targetChannel,
1485 adapter->tx_flow_low_watermark,
1486 adapter->tx_flow_low_watermark +
1487 adapter->
1488 tx_flow_high_watermark_offset,
1489 hdd_ctx->config->
1490 TxHbwFlowMaxQueueDepth);
1491
1492 if (!preAdapterContext) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001493 hdd_err("SCC: Previous adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001494 continue;
1495 }
1496
1497 /* Previous adapter */
1498 preAdapterContext->
1499 tx_flow_low_watermark = 0;
1500 preAdapterContext->
1501 tx_flow_high_watermark_offset = 0;
1502 cdp_fc_ll_set_tx_pause_q_depth(soc,
1503 preAdapterContext->sessionId,
1504 hdd_ctx->config->
1505 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001506 hdd_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001507 hdd_device_mode_to_string(
1508 preAdapterContext->device_mode
1509 ),
1510 preAdapterContext->device_mode,
1511 targetChannel,
1512 preAdapterContext->
1513 tx_flow_low_watermark,
1514 preAdapterContext->
1515 tx_flow_low_watermark +
1516 preAdapterContext->
1517 tx_flow_high_watermark_offset,
1518 hdd_ctx->config->
1519 TxHbwFlowMaxQueueDepth);
1520 }
1521 /*
1522 * MCC, each adapter will have dedicated
1523 * resource
1524 */
1525 else {
1526 /* current channel is 2.4 */
1527 if (targetChannel <=
1528 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1529 channel24 = targetChannel;
1530 channel5 = preAdapterChannel;
1531 adapter2_4 = adapter;
1532 adapter5 = preAdapterContext;
1533 } else {
1534 /* Current channel is 5 */
1535 channel24 = preAdapterChannel;
1536 channel5 = targetChannel;
1537 adapter2_4 = preAdapterContext;
1538 adapter5 = adapter;
1539 }
1540
1541 if (!adapter5) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001542 hdd_err("MCC: 5GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001543 continue;
1544 }
1545 adapter5->tx_flow_low_watermark =
1546 hdd_ctx->config->
1547 TxHbwFlowLowWaterMark;
1548 adapter5->
1549 tx_flow_high_watermark_offset =
1550 hdd_ctx->config->
1551 TxHbwFlowHighWaterMarkOffset;
1552 cdp_fc_ll_set_tx_pause_q_depth(soc,
1553 adapter5->sessionId,
1554 hdd_ctx->config->
1555 TxHbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001556 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001557 hdd_device_mode_to_string(
1558 adapter5->device_mode),
1559 adapter5->device_mode,
1560 channel5,
1561 adapter5->tx_flow_low_watermark,
1562 adapter5->
1563 tx_flow_low_watermark +
1564 adapter5->
1565 tx_flow_high_watermark_offset,
1566 hdd_ctx->config->
1567 TxHbwFlowMaxQueueDepth);
1568
1569 if (!adapter2_4) {
Jeff Johnson6867ec32017-09-29 20:30:20 -07001570 hdd_err("MCC: 2.4GHz adapter context NULL");
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001571 continue;
1572 }
1573 adapter2_4->tx_flow_low_watermark =
1574 hdd_ctx->config->
1575 TxLbwFlowLowWaterMark;
1576 adapter2_4->
1577 tx_flow_high_watermark_offset =
1578 hdd_ctx->config->
1579 TxLbwFlowHighWaterMarkOffset;
1580 cdp_fc_ll_set_tx_pause_q_depth(soc,
1581 adapter2_4->sessionId,
1582 hdd_ctx->config->
1583 TxLbwFlowMaxQueueDepth);
Jeff Johnson6867ec32017-09-29 20:30:20 -07001584 hdd_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001585 hdd_device_mode_to_string(
1586 adapter2_4->device_mode),
1587 adapter2_4->device_mode,
1588 channel24,
1589 adapter2_4->
1590 tx_flow_low_watermark,
1591 adapter2_4->
1592 tx_flow_low_watermark +
1593 adapter2_4->
1594 tx_flow_high_watermark_offset,
1595 hdd_ctx->config->
1596 TxLbwFlowMaxQueueDepth);
1597
1598 }
1599 }
1600 }
1601 targetChannel = 0;
1602#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1603 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1604 adapterNode = pNext;
1605 }
1606 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1607}
1608
1609/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001610 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001611 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001612 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1613 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001614 *
1615 * Return: true if IPA is enabled, false otherwise
1616 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001617static void __hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1619{
1620 struct hdd_ipa_priv *hdd_ipa;
1621
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622 *ipa_tx_diff = 0;
1623 *ipa_rx_diff = 0;
1624
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001625 if (wlan_hdd_validate_context(hdd_ctx))
1626 return;
1627
1628 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1629
1630 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1631 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001632 return;
1633 }
1634
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301635 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001636 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1637 (false == hdd_ipa->resource_loading)) {
1638 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1639 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001640 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641 *ipa_tx_diff, *ipa_rx_diff);
1642 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301643 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001644}
1645
1646/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001647 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1648 * @hdd_ctx: Global HDD context
1649 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1650 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1651 *
1652 * Return: true if IPA is enabled, false otherwise
1653 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001654void hdd_ipa_uc_stat_query(struct hdd_context *hdd_ctx,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001655 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1656{
1657 cds_ssr_protect(__func__);
1658 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1659 cds_ssr_unprotect(__func__);
1660}
1661
1662/**
1663 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664 * @adapter: network adapter
1665 * @reason: STAT REQ Reason
1666 *
1667 * Return: None
1668 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07001669static void __hdd_ipa_uc_stat_request(struct hdd_adapter *adapter,
1670 uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001671{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001672 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001673 struct hdd_ipa_priv *hdd_ipa;
1674
Yun Park637d6482016-10-05 10:51:33 -07001675 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001676 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001677
Jeff Johnson399c6272017-08-30 10:51:00 -07001678 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001679
1680 if (wlan_hdd_validate_context(hdd_ctx))
1681 return;
1682
1683 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1684 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1685 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001686 return;
1687 }
1688
Yun Parkb187d542016-11-14 18:10:04 -08001689 hdd_debug("STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301690 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1692 (false == hdd_ipa->resource_loading)) {
1693 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001694 qdf_mutex_release(&hdd_ipa->ipa_lock);
Sandeep Puligillaf587adf2017-04-27 19:53:21 -07001695 sme_ipa_uc_stat_request(WLAN_HDD_GET_HAL_CTX(adapter),
1696 adapter->sessionId,
1697 WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001699 } else {
1700 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001702}
1703
1704/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001705 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1706 * @adapter: network adapter
1707 * @reason: STAT REQ Reason
1708 *
1709 * Return: None
1710 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001711void hdd_ipa_uc_stat_request(struct hdd_adapter *adapter, uint8_t reason)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001712{
1713 cds_ssr_protect(__func__);
1714 __hdd_ipa_uc_stat_request(adapter, reason);
1715 cds_ssr_unprotect(__func__);
1716}
1717
Yun Park637d6482016-10-05 10:51:33 -07001718#ifdef FEATURE_METERING
1719/**
1720 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1721 * @adapter: network adapter
1722 * @reset_stats: reset stat countis after response
1723 *
1724 * Return: None
1725 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001726void hdd_ipa_uc_sharing_stats_request(struct hdd_adapter *adapter,
Yun Park637d6482016-10-05 10:51:33 -07001727 uint8_t reset_stats)
1728{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001729 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001730 struct hdd_ipa_priv *hdd_ipa;
1731
1732 if (!adapter)
1733 return;
1734
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001735 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1736 hdd_ipa = hdd_ctx->hdd_ipa;
1737 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1738 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001739 return;
1740 }
1741
1742 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1743 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001744 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001745 qdf_mutex_release(&hdd_ipa->ipa_lock);
1746 wma_cli_set_command(
1747 (int)adapter->sessionId,
1748 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1749 reset_stats, VDEV_CMD);
1750 } else {
1751 qdf_mutex_release(&hdd_ipa->ipa_lock);
1752 }
1753}
1754
1755/**
1756 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1757 * @adapter: network adapter
1758 * @set_quota: when 1, FW starts quota monitoring
1759 * @quota_bytes: quota limit in bytes
1760 *
1761 * Return: None
1762 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07001763void hdd_ipa_uc_set_quota(struct hdd_adapter *adapter, uint8_t set_quota,
Yun Park637d6482016-10-05 10:51:33 -07001764 uint64_t quota_bytes)
1765{
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001766 struct hdd_context *hdd_ctx;
Yun Park637d6482016-10-05 10:51:33 -07001767 struct hdd_ipa_priv *hdd_ipa;
1768
1769 if (!adapter)
1770 return;
1771
Jeff Johnson2c4a93f2017-09-03 08:51:14 -07001772 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1773 hdd_ipa = hdd_ctx->hdd_ipa;
1774 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1775 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Yun Park637d6482016-10-05 10:51:33 -07001776 return;
1777 }
1778
1779 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1780 set_quota, quota_bytes);
1781
1782 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001783 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001784 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001785 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001786 (int)adapter->sessionId,
1787 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001788 (set_quota ? quota_bytes&0xffffffff : 0),
1789 (set_quota ? quota_bytes>>32 : 0),
1790 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001791 } else {
1792 qdf_mutex_release(&hdd_ipa->ipa_lock);
1793 }
1794}
1795#endif
1796
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001797/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001798 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1799 * @hdd_ipa: Global HDD IPA context
1800 * @sta_add: Should station be added
1801 * @sta_id: ID of the station being queried
1802 *
1803 * Return: true if the station was found
1804 */
1805static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1806 bool sta_add, uint8_t sta_id)
1807{
1808 bool sta_found = false;
1809 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001810
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001811 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1812 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1813 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1814 sta_found = true;
1815 break;
1816 }
1817 }
1818 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301819 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001820 "STA ID %d already exist, cannot add", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001821 return sta_found;
1822 }
1823 if (sta_add) {
1824 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1825 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1826 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1827 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1828 return sta_found;
1829 }
1830 }
1831 }
1832 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301833 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001834 "STA ID %d does not exist, cannot delete", sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001835 return sta_found;
1836 }
1837 if (!sta_add) {
1838 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1839 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1840 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1841 hdd_ipa->assoc_stas_map[idx].is_reserved =
1842 false;
1843 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1844 return sta_found;
1845 }
1846 }
1847 }
1848 return sta_found;
1849}
1850
1851/**
1852 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1853 * @hdd_ipa: Global HDD IPA context
1854 *
1855 * Return: 0 on success, negative errno if error
1856 */
1857static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1858{
1859 int result;
Leo Changfdb45c32016-10-28 11:09:23 -07001860 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001861 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862
Yun Parkb4f591d2017-03-29 15:51:01 -07001863 result = cdp_ipa_enable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001864 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301865 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001866 "Enable PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001867 return result;
1868 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869
Yun Park777d7242017-03-30 15:38:33 -07001870 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Leo Change3e49442015-10-26 20:07:13 -07001871 hdd_ipa->ipa_pipes_down = false;
Yun Parkb4f591d2017-03-29 15:51:01 -07001872
1873 cdp_ipa_enable_autonomy(soc, (struct cdp_pdev *)pdev);
1874
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001875 return 0;
1876}
1877
1878/**
1879 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1880 * @hdd_ipa: Global HDD IPA context
1881 *
1882 * Return: 0 on success, negative errno if error
1883 */
1884static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1885{
Yun Parkb4f591d2017-03-29 15:51:01 -07001886 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1887 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888 int result;
1889
Leo Change3e49442015-10-26 20:07:13 -07001890 hdd_ipa->ipa_pipes_down = true;
1891
Yun Parkb4f591d2017-03-29 15:51:01 -07001892 cdp_ipa_disable_autonomy(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001893
Yun Parkb4f591d2017-03-29 15:51:01 -07001894 result = cdp_ipa_disable_pipes(soc, (struct cdp_pdev *)pdev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001895 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301896 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001897 "Disable WDI PIPE fail, code %d", result);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001898 return result;
1899 }
1900
1901 return 0;
1902}
1903
1904/**
1905 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
1906 * @hdd_ipa: Global HDD IPA context
1907 *
1908 * Return: 0 on success, negative errno if error
1909 */
1910static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
1911{
Jeff Johnsondd595cb2017-08-28 11:58:09 -07001912 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07001913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001914 hdd_ipa->activated_fw_pipe = 0;
1915 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07001916
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001917 /* If RM feature enabled
1918 * Request PROD Resource first
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07001919 * PROD resource may return sync or async manners
1920 */
Yun Parkb4f591d2017-03-29 15:51:01 -07001921 if (hdd_ipa_is_rm_enabled(hdd_ctx)) {
Yun Park4cab6ee2015-10-27 11:43:40 -07001922 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
1923 /* RM PROD request sync return
1924 * enable pipe immediately
1925 */
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301926 if (!hdd_ipa->ipa_pipes_down) {
1927 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
1928 "%s: IPA WDI Pipe already activated",
1929 __func__);
1930 return 0;
1931 }
1932
Yun Park4cab6ee2015-10-27 11:43:40 -07001933 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301934 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001935 "IPA WDI Pipe activation failed");
Yun Park4cab6ee2015-10-27 11:43:40 -07001936 hdd_ipa->resource_loading = false;
1937 return -EBUSY;
1938 }
Sravan Kumar Kairamc76f28a2017-07-25 19:03:40 +05301939 } else {
1940 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO,
1941 "%s: IPA WDI Pipe activation deferred",
1942 __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001943 }
1944 } else {
1945 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07001946 * Just enabled all the PIPEs
1947 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001948 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301949 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07001950 "IPA WDI Pipe activation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001951 hdd_ipa->resource_loading = false;
1952 return -EBUSY;
1953 }
1954 hdd_ipa->resource_loading = false;
1955 }
Yun Park4cab6ee2015-10-27 11:43:40 -07001956
Srinivas Girigowda97852372017-03-06 16:52:59 -08001957 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07001958 "IPA WDI Pipes activated successfully");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001959 return 0;
1960}
1961
1962/**
1963 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
1964 * @hdd_ipa: Global HDD IPA context
1965 *
1966 * Return: None
1967 */
1968static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
1969{
Leo Changfdb45c32016-10-28 11:09:23 -07001970 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkb4f591d2017-03-29 15:51:01 -07001971 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001972
Yun Parkb4f591d2017-03-29 15:51:01 -07001973 if (!pdev) {
Yun Park7c4f31b2016-11-30 10:09:21 -08001974 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
1975 QDF_ASSERT(0);
1976 return;
1977 }
1978
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001979 hdd_ipa->resource_unloading = true;
Yun Park777d7242017-03-30 15:38:33 -07001980 INIT_COMPLETION(hdd_ipa->ipa_resource_comp);
Yun Parkb4f591d2017-03-29 15:51:01 -07001981 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW RX PIPE");
1982 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, false);
1983 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Disable FW TX PIPE");
1984 cdp_ipa_set_active(soc, (struct cdp_pdev *)pdev, false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001985}
1986
1987/**
1988 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
1989 * @context: User context registered with TL (the IPA Global context is
1990 * registered
1991 * @rxpkt: Packet containing the notification
1992 * @staid: ID of the station associated with the packet
1993 *
1994 * Return: None
1995 */
1996static void
1997hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
1998{
1999 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302000 QDF_STATUS status = QDF_STATUS_SUCCESS;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002001 struct hdd_context *hdd_ctx = hdd_ipa->hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002002
2003 /*
2004 * When SSR is going on or driver is unloading, just return.
2005 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002006 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302007 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002008 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002009
Yun Parkb4f591d2017-03-29 15:51:01 -07002010 if (!hdd_ipa_is_rm_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002011 return;
2012
Srinivas Girigowda97852372017-03-06 16:52:59 -08002013 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002014 __func__, event);
2015
2016 switch (event) {
2017 case IPA_RM_RESOURCE_GRANTED:
2018 /* Differed RM Granted */
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302019 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002020 if ((false == hdd_ipa->resource_unloading) &&
2021 (!hdd_ipa->activated_fw_pipe)) {
2022 hdd_ipa_uc_enable_pipes(hdd_ipa);
2023 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302024 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 break;
2026
2027 case IPA_RM_RESOURCE_RELEASED:
2028 /* Differed RM Released */
2029 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002030 break;
2031
2032 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302033 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002034 "%s, invalid event code %d", __func__, event);
2035 break;
2036 }
2037}
2038
2039/**
2040 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2041 * @hdd_ipa: Global HDD IPA context
2042 * @event: IPA resource manager event to be deferred
2043 *
2044 * This function is called when a resource manager event is received
2045 * from firmware in interrupt context. This function will defer the
2046 * handling to the OL RX thread
2047 *
2048 * Return: None
2049 */
2050static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2051{
2052 enum ipa_rm_event event;
2053 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2054 struct uc_rm_work_struct, work);
2055 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2056 struct hdd_ipa_priv, uc_rm_work);
2057
2058 cds_ssr_protect(__func__);
2059 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002060 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002061 "%s, posted event %d", __func__, event);
2062
2063 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2064 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065}
2066
2067/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002068 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
Yun Parkb4f591d2017-03-29 15:51:01 -07002069 * @hdd_ipa: hdd ipa local context
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002070 *
2071 * Will handle IPA UC image loaded indication comes from IPA kernel
2072 *
2073 * Return: None
2074 */
Yun Parkb4f591d2017-03-29 15:51:01 -07002075static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *hdd_ipa)
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002076{
Yun Parkb4f591d2017-03-29 15:51:01 -07002077 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
2078 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002079 struct hdd_context *hdd_ctx;
Yun Parkb4f591d2017-03-29 15:51:01 -07002080 QDF_STATUS status;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002081
2082 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
Yun Parkb4f591d2017-03-29 15:51:01 -07002083 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002084 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002085 __func__);
2086 return;
2087 }
2088
Yun Parkb4f591d2017-03-29 15:51:01 -07002089 hdd_ctx = hdd_ipa->hdd_ctx;
2090 hdd_ipa->uc_loaded = true;
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002091
Yun Parkb4f591d2017-03-29 15:51:01 -07002092 /* Connect pipe */
2093 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2094 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2095 hdd_ipa_wdi_meter_notifier_cb,
2096 hdd_ctx->config->IpaDescSize,
2097 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2098 &hdd_ipa->tx_pipe_handle,
2099 &hdd_ipa->rx_pipe_handle);
2100 if (status) {
2101 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2102 "Failure to setup IPA pipes (status=%d)",
2103 status);
2104 return;
2105 }
2106
2107 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002108
2109 /* If already any STA connected, enable IPA/FW PIPEs */
Yun Parkb4f591d2017-03-29 15:51:01 -07002110 if (hdd_ipa->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002111 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002112 "Client already connected, enable IPA/FW PIPEs");
Yun Parkb4f591d2017-03-29 15:51:01 -07002113 hdd_ipa_uc_handle_first_con(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002114 }
2115}
2116
2117/**
Yun Park637d6482016-10-05 10:51:33 -07002118 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2119 * @hdd_ctx: Global HDD context
2120 * @op_msg: operation message received from firmware
2121 *
2122 * Return: QDF_STATUS enumeration
2123 */
2124#ifdef FEATURE_METERING
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002125static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002126 struct op_msg_type *op_msg)
2127{
2128 struct op_msg_type *msg = op_msg;
2129 struct ipa_uc_sharing_stats *uc_sharing_stats;
2130 struct ipa_uc_quota_rsp *uc_quota_rsp;
2131 struct ipa_uc_quota_ind *uc_quota_ind;
2132 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002133 struct hdd_adapter *adapter;
Yun Park637d6482016-10-05 10:51:33 -07002134
2135 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2136
2137 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2138 /* fill-up ipa_uc_sharing_stats structure from FW */
2139 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2140 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2141
2142 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2143 sizeof(struct ipa_uc_sharing_stats));
2144
2145 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2146
2147 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2148 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2149 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2150 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2151 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2152 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2153 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2154 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2155 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2156 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2157 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2158 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2159 /* received set quota response */
2160 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2161 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2162
2163 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2164 sizeof(struct ipa_uc_quota_rsp));
2165
2166 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2167 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2168 "%s: success=%d, quota_bytes=%llu",
2169 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2170 hdd_ipa->ipa_quota_rsp.success,
2171 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2172 hdd_ipa->ipa_quota_rsp.quota_lo);
2173 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2174 /* hit quota limit */
2175 uc_quota_ind = (struct ipa_uc_quota_ind *)
2176 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2177
2178 hdd_ipa->ipa_quota_ind.quota_bytes =
2179 uc_quota_ind->quota_bytes;
2180
2181 /* send quota exceeded indication to IPA */
2182 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2183 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2184 hdd_ipa->ipa_quota_ind.quota_bytes);
2185
2186 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2187 if (adapter)
2188 ipa_broadcast_wdi_quota_reach_ind(
2189 adapter->dev->ifindex,
2190 uc_quota_ind->quota_bytes);
2191 else
2192 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2193 "Failed quota_reach_ind: NULL adapter");
2194 } else {
2195 return QDF_STATUS_E_INVAL;
2196 }
2197
2198 return QDF_STATUS_SUCCESS;
2199}
2200#else
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002201static QDF_STATUS hdd_ipa_uc_op_metering(struct hdd_context *hdd_ctx,
Yun Park637d6482016-10-05 10:51:33 -07002202 struct op_msg_type *op_msg)
2203{
2204 return QDF_STATUS_E_INVAL;
2205}
2206#endif
2207
2208/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002209 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2210 * @op_msg: operation message received from firmware
2211 * @usr_ctxt: user context registered with TL (we register the HDD Global
2212 * context)
2213 *
2214 * Return: None
2215 */
2216static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2217{
2218 struct op_msg_type *msg = op_msg;
2219 struct ipa_uc_fw_stats *uc_fw_stat;
2220 struct IpaHwStatsWDIInfoData_t ipa_stat;
2221 struct hdd_ipa_priv *hdd_ipa;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002222 struct hdd_context *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302223 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002224
2225 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302226 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002227 return;
2228 }
2229
2230 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302231 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002232 "%s, INVALID OPCODE %d", __func__, msg->op_code);
jiadd91a6842017-08-01 14:46:02 +08002233 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002234 return;
2235 }
2236
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002237 hdd_ctx = (struct hdd_context *) usr_ctxt;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002238
2239 /*
2240 * When SSR is going on or driver is unloading, just return.
2241 */
2242 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302243 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302244 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002245 return;
2246 }
2247
2248 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2249
Govind Singhb6a89772016-08-12 11:23:35 +05302250 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002251 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002252
2253 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2254 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302255 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002256 hdd_ipa->activated_fw_pipe++;
2257 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2258 hdd_ipa->resource_loading = false;
Yun Park777d7242017-03-30 15:38:33 -07002259 complete(&hdd_ipa->ipa_resource_comp);
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002260 if (hdd_ipa->wdi_enabled == false) {
2261 hdd_ipa->wdi_enabled = true;
2262 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2263 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2264 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002265 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002266 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002267 if (hdd_ipa->pending_cons_req)
2268 ipa_rm_notify_completion(
2269 IPA_RM_RESOURCE_GRANTED,
2270 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002271 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002272 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302273 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002274 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002275 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302276 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002277 hdd_ipa->activated_fw_pipe--;
2278 if (!hdd_ipa->activated_fw_pipe) {
Yun Park777d7242017-03-30 15:38:33 -07002279 /*
2280 * Async return success from FW
2281 * Disable/suspend all the PIPEs
2282 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002283 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002284 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2285 ipa_rm_release_resource(
2286 IPA_RM_RESOURCE_WLAN_PROD);
Yun Park5b635012015-12-02 15:05:01 -08002287 hdd_ipa->resource_unloading = false;
Yun Park777d7242017-03-30 15:38:33 -07002288 complete(&hdd_ipa->ipa_resource_comp);
Yun Park5b635012015-12-02 15:05:01 -08002289 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2290 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002291 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302292 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002293 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002294 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002295 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302296 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002297 "==== IPA_UC WLAN_HOST RX ====\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002298 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002299 "NUM TX FWD OK : %llu\n"
2300 "NUM TX FWD ERR : %llu",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002301 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002302 hdd_ipa->stats.num_tx_fwd_ok,
2303 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302304 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002305 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2306 "SAP NUM STAs: %d\n"
2307 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002308 "CONCURRENT MODE: %s\n"
2309 "TX PIPE HDL: 0x%x\n"
2310 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002311 "RSC LOADING : %d\n"
2312 "RSC UNLOADING : %d\n"
2313 "PNDNG CNS RQT : %d",
2314 hdd_ipa->sap_num_connected_sta,
2315 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002316 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002317 hdd_ipa->tx_pipe_handle,
2318 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002319 hdd_ipa->resource_loading,
2320 hdd_ipa->resource_unloading,
2321 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002322
2323 /* STATs from FW */
2324 uc_fw_stat = (struct ipa_uc_fw_stats *)
2325 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302326 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002327 "==== IPA_UC WLAN_FW TX ====\n"
2328 "COMP RING BASE: 0x%x\n"
2329 "COMP RING SIZE: %d\n"
2330 "COMP RING DBELL : 0x%x\n"
2331 "COMP RING DBELL IND VAL : %d\n"
2332 "COMP RING DBELL CACHED VAL : %d\n"
2333 "COMP RING DBELL CACHED VAL : %d\n"
2334 "PKTS ENQ : %d\n"
2335 "PKTS COMP : %d\n"
2336 "IS SUSPEND : %d\n"
2337 "RSVD : 0x%x",
2338 uc_fw_stat->tx_comp_ring_base,
2339 uc_fw_stat->tx_comp_ring_size,
2340 uc_fw_stat->tx_comp_ring_dbell_addr,
2341 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2342 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2343 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2344 uc_fw_stat->tx_pkts_enqueued,
2345 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002346 uc_fw_stat->tx_is_suspend,
2347 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302348 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002349 "==== IPA_UC WLAN_FW RX ====\n"
2350 "IND RING BASE: 0x%x\n"
2351 "IND RING SIZE: %d\n"
2352 "IND RING DBELL : 0x%x\n"
2353 "IND RING DBELL IND VAL : %d\n"
2354 "IND RING DBELL CACHED VAL : %d\n"
2355 "RDY IND ADDR : 0x%x\n"
2356 "RDY IND CACHE VAL : %d\n"
2357 "RFIL IND : %d\n"
2358 "NUM PKT INDICAT : %d\n"
2359 "BUF REFIL : %d\n"
2360 "NUM DROP NO SPC : %d\n"
2361 "NUM DROP NO BUF : %d\n"
2362 "IS SUSPND : %d\n"
2363 "RSVD : 0x%x\n",
2364 uc_fw_stat->rx_ind_ring_base,
2365 uc_fw_stat->rx_ind_ring_size,
2366 uc_fw_stat->rx_ind_ring_dbell_addr,
2367 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2368 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2369 uc_fw_stat->rx_ind_ring_rdidx_addr,
2370 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2371 uc_fw_stat->rx_refill_idx,
2372 uc_fw_stat->rx_num_pkts_indicated,
2373 uc_fw_stat->rx_buf_refilled,
2374 uc_fw_stat->rx_num_ind_drop_no_space,
2375 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002376 uc_fw_stat->rx_is_suspend,
2377 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002378 /* STATs from IPA */
2379 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302380 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002381 "==== IPA_UC IPA TX ====\n"
2382 "NUM PROCD : %d\n"
2383 "CE DBELL : 0x%x\n"
2384 "NUM DBELL FIRED : %d\n"
2385 "COMP RNG FULL : %d\n"
2386 "COMP RNG EMPT : %d\n"
2387 "COMP RNG USE HGH : %d\n"
2388 "COMP RNG USE LOW : %d\n"
2389 "BAM FIFO FULL : %d\n"
2390 "BAM FIFO EMPT : %d\n"
2391 "BAM FIFO USE HGH : %d\n"
2392 "BAM FIFO USE LOW : %d\n"
2393 "NUM DBELL : %d\n"
2394 "NUM UNEXP DBELL : %d\n"
2395 "NUM BAM INT HDL : 0x%x\n"
2396 "NUM BAM INT NON-RUN : 0x%x\n"
2397 "NUM QMB INT HDL : 0x%x",
2398 ipa_stat.tx_ch_stats.num_pkts_processed,
2399 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2400 ipa_stat.tx_ch_stats.num_db_fired,
2401 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2402 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2403 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2404 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2405 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2406 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2407 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2408 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2409 ipa_stat.tx_ch_stats.num_db,
2410 ipa_stat.tx_ch_stats.num_unexpected_db,
2411 ipa_stat.tx_ch_stats.num_bam_int_handled,
2412 ipa_stat.tx_ch_stats.
2413 num_bam_int_in_non_runnning_state,
2414 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2415
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302416 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002417 "==== IPA_UC IPA RX ====\n"
2418 "MAX OST PKT : %d\n"
2419 "NUM PKT PRCSD : %d\n"
2420 "RNG RP : 0x%x\n"
2421 "COMP RNG FULL : %d\n"
2422 "COMP RNG EMPT : %d\n"
2423 "COMP RNG USE HGH : %d\n"
2424 "COMP RNG USE LOW : %d\n"
2425 "BAM FIFO FULL : %d\n"
2426 "BAM FIFO EMPT : %d\n"
2427 "BAM FIFO USE HGH : %d\n"
2428 "BAM FIFO USE LOW : %d\n"
2429 "NUM DB : %d\n"
2430 "NUM UNEXP DB : %d\n"
2431 "NUM BAM INT HNDL : 0x%x\n",
2432 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2433 ipa_stat.rx_ch_stats.num_pkts_processed,
2434 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2435 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2436 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2437 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2438 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2439 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2440 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2441 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2442 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2443 ipa_stat.rx_ch_stats.num_db,
2444 ipa_stat.rx_ch_stats.num_unexpected_db,
2445 ipa_stat.rx_ch_stats.num_bam_int_handled);
2446 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2447 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2448 /* STATs from FW */
2449 uc_fw_stat = (struct ipa_uc_fw_stats *)
2450 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302451 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002452 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2453 uc_fw_stat->tx_pkts_completed,
2454 hdd_ipa->ipa_p_tx_packets);
2455 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2456 (uc_fw_stat->rx_num_ind_drop_no_space +
2457 uc_fw_stat->rx_num_ind_drop_no_buf +
2458 uc_fw_stat->rx_num_pkts_indicated),
2459 hdd_ipa->ipa_p_rx_packets);
2460
2461 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2462 hdd_ipa->ipa_p_rx_packets =
2463 (uc_fw_stat->rx_num_ind_drop_no_space +
2464 uc_fw_stat->rx_num_ind_drop_no_buf +
2465 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302466 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002467 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2468 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2469 hdd_ipa_uc_loaded_handler(hdd_ipa);
2470 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002471 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2472 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2473 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002474 }
Yun Park8957d802017-01-25 12:27:29 -08002475
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302476 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002477}
2478
2479
2480/**
2481 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2482 * @adapter: device adapter instance
2483 * @offload_type: MCC or SCC
2484 * @enable: TX offload enable or disable
2485 *
2486 * Return: none
2487 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002488static void hdd_ipa_uc_offload_enable_disable(struct hdd_adapter *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002489 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002490{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002491 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002492 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002493 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002494 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002495
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002496 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002497 return;
2498
Yun Park8292dcb2016-10-07 16:46:06 -07002499 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002500 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002501
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002502 if (!iface_context) {
2503 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2504 "Interface context is NULL");
2505 return;
2506 }
Zhu Jianminded9d2d2017-06-22 09:39:36 +08002507 if (session_id >= CSR_ROAM_SESSION_MAX) {
2508 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2509 "invalid session id: %d", session_id);
2510 return;
2511 }
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002512 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002513 /* IPA offload status is already set as desired */
2514 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002515 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002516 "IPA offload status is already set",
2517 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002518 return;
2519 }
2520
Yun Park4540e862016-11-10 16:30:06 -08002521 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2522 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2523 "invalid session id: %d, offload_type=%d, enable=%d",
2524 adapter->sessionId, offload_type, enable);
2525 return;
2526 }
2527
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302528 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002529 sizeof(ipa_offload_enable_disable));
2530 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002531 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002532 ipa_offload_enable_disable.enable = enable;
2533
Srinivas Girigowda97852372017-03-06 16:52:59 -08002534 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002535 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002536 ipa_offload_enable_disable.offload_type,
2537 ipa_offload_enable_disable.vdev_id,
2538 ipa_offload_enable_disable.enable);
2539
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302540 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002541 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2542 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302543 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002544 "%s (offload_type=%d, vdev_id=%d, enable=%d)",
2545 "Failure to enable IPA offload",
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002546 ipa_offload_enable_disable.offload_type,
2547 ipa_offload_enable_disable.vdev_id,
2548 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002549 } else {
2550 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002551 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002552 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002553 }
2554}
2555
2556/**
2557 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2558 * @work: uC OP work
2559 *
2560 * Return: None
2561 */
2562static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2563{
2564 struct op_msg_type *msg;
2565 struct uc_op_work_struct *uc_op_work = container_of(work,
2566 struct uc_op_work_struct, work);
2567 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2568
2569 cds_ssr_protect(__func__);
2570
2571 msg = uc_op_work->msg;
2572 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002573 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002574 "%s, posted msg %d", __func__, msg->op_code);
2575
2576 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2577
2578 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002579}
2580
2581/**
2582 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2583 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2584 * @op_msg: operation message received from firmware
2585 * @hdd_ctx: Global HDD context
2586 *
2587 * Return: None
2588 */
2589static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2590{
2591 struct hdd_ipa_priv *hdd_ipa;
2592 struct op_msg_type *msg;
2593 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302594 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002595
2596 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302597 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002598 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002599
2600 msg = (struct op_msg_type *)op_msg;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002601 hdd_ipa = ((struct hdd_context *)hdd_ctx)->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002602
2603 if (unlikely(!hdd_ipa))
2604 goto end;
2605
2606 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002607 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid OP Code (%d)",
2608 msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002609 goto end;
2610 }
2611
2612 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2613 if (uc_op_work->msg)
2614 /* When the same uC OPCODE is already pended, just return */
2615 goto end;
2616
2617 uc_op_work->msg = msg;
2618 schedule_work(&uc_op_work->work);
2619 return;
2620
2621end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302622 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002623}
2624
2625/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002626 * hdd_ipa_init_uc_op_work - init ipa uc op work
2627 * @work: struct work_struct
2628 * @work_handler: work_handler
2629 *
2630 * Return: none
2631 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002632static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002633 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002634{
2635 INIT_WORK(work, work_handler);
2636}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002637
Yun Park637d6482016-10-05 10:51:33 -07002638#ifdef FEATURE_METERING
2639/**
2640 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2641 * IPA calls to get WLAN stats or set quota limit.
2642 * @priv: pointer to private data registered with IPA (we register a
2643 *» pointer to the global IPA context)
2644 * @evt: the IPA event which triggered the callback
2645 * @data: data associated with the event
2646 *
2647 * Return: None
2648 */
2649static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2650 void *data)
2651{
2652 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07002653 struct hdd_adapter *adapter = NULL;
Yun Park637d6482016-10-05 10:51:33 -07002654 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2655 struct ipa_set_wifi_quota *ipa_set_quota;
2656 int ret = 0;
2657
2658 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2659 return;
2660
2661 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2662
2663 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2664
2665 switch (evt) {
2666 case IPA_GET_WDI_SAP_STATS:
2667 /* fill-up ipa_get_wdi_sap_stats structure after getting
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002668 * ipa_uc_fw_stats from FW
2669 */
Yun Park637d6482016-10-05 10:51:33 -07002670 wdi_sap_stats = data;
2671
2672 if (!adapter) {
2673 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2674 "IPA uC share stats failed - no adapter");
2675 wdi_sap_stats->stats_valid = 0;
2676 return;
2677 }
2678
2679 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
Yun Park637d6482016-10-05 10:51:33 -07002680 hdd_ipa_uc_sharing_stats_request(adapter,
2681 wdi_sap_stats->reset_stats);
2682 ret = wait_for_completion_timeout(
2683 &hdd_ipa->ipa_uc_sharing_stats_comp,
2684 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2685 if (!ret) {
2686 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2687 "IPA uC share stats request timed out");
2688 wdi_sap_stats->stats_valid = 0;
2689 } else {
2690 wdi_sap_stats->stats_valid = 1;
2691
2692 wdi_sap_stats->ipv4_rx_packets =
2693 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2694 wdi_sap_stats->ipv4_rx_bytes =
2695 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2696 wdi_sap_stats->ipv6_rx_packets =
2697 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2698 wdi_sap_stats->ipv6_rx_bytes =
2699 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2700 wdi_sap_stats->ipv4_tx_packets =
2701 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2702 wdi_sap_stats->ipv4_tx_bytes =
2703 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2704 wdi_sap_stats->ipv6_tx_packets =
2705 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2706 wdi_sap_stats->ipv6_tx_bytes =
2707 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2708 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2709 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2710 "IPA_GET_WDI_SAP_STATS",
2711 wdi_sap_stats->stats_valid,
2712 wdi_sap_stats->ipv4_rx_packets,
2713 wdi_sap_stats->ipv4_rx_bytes,
2714 wdi_sap_stats->ipv6_rx_packets,
2715 wdi_sap_stats->ipv6_rx_bytes,
2716 wdi_sap_stats->ipv4_tx_packets,
2717 wdi_sap_stats->ipv4_tx_bytes,
2718 wdi_sap_stats->ipv6_tx_packets,
2719 wdi_sap_stats->ipv6_tx_bytes);
2720 }
2721 break;
2722 case IPA_SET_WIFI_QUOTA:
2723 /* get ipa_set_wifi_quota structure from IPA and pass to FW
Jeff Johnsondcf84ce2017-10-05 09:26:24 -07002724 * through quota_exceeded field in ipa_uc_fw_stats
2725 */
Yun Park637d6482016-10-05 10:51:33 -07002726 ipa_set_quota = data;
2727
2728 if (!adapter) {
2729 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2730 "IPA uC set quota failed - no adapter");
2731 ipa_set_quota->set_valid = 0;
2732 return;
2733 }
2734
Yun Park777d7242017-03-30 15:38:33 -07002735 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
Yun Park637d6482016-10-05 10:51:33 -07002736 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2737 ipa_set_quota->quota_bytes);
2738
2739 ret = wait_for_completion_timeout(
2740 &hdd_ipa->ipa_uc_set_quota_comp,
2741 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2742 if (!ret) {
2743 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2744 "IPA uC set quota request timed out");
2745 ipa_set_quota->set_valid = 0;
2746 } else {
2747 ipa_set_quota->quota_bytes =
2748 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2749 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2750 ipa_set_quota->set_valid =
2751 hdd_ipa->ipa_quota_rsp.success;
2752 }
2753
2754 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2755 ipa_set_quota->quota_bytes,
2756 ipa_set_quota->set_valid);
2757 break;
2758 }
2759}
2760
2761/**
2762 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2763 * IPA calls to get WLAN stats or set quota limit.
2764 * @priv: pointer to private data registered with IPA (we register a
Yun Parkb4f591d2017-03-29 15:51:01 -07002765 * pointer to the global IPA context)
Yun Park637d6482016-10-05 10:51:33 -07002766 * @evt: the IPA event which triggered the callback
2767 * @data: data associated with the event
2768 *
2769 * Return: None
2770 */
2771static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2772 void *data)
2773{
2774 cds_ssr_protect(__func__);
2775 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2776 cds_ssr_unprotect(__func__);
2777}
2778
Yun Parkb4f591d2017-03-29 15:51:01 -07002779static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002780{
Yun Park637d6482016-10-05 10:51:33 -07002781 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2782 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2783}
2784#else
Yun Parkb4f591d2017-03-29 15:51:01 -07002785static void hdd_ipa_wdi_meter_notifier_cb(void)
2786{
2787}
2788
2789static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt)
Yun Park637d6482016-10-05 10:51:33 -07002790{
2791}
2792#endif
2793
Rajeev Kumar217f2172016-01-06 18:11:55 -08002794/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002795 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2796 * @hdd_ctx: Global HDD context
2797 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002798 * This function is called to update IPA pipe configuration with resources
2799 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2800 * (cds_enable)
2801 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302802 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002803 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002804QDF_STATUS hdd_ipa_uc_ol_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002805{
Yun Parkb4f591d2017-03-29 15:51:01 -07002806 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002807 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002808 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Parkb4f591d2017-03-29 15:51:01 -07002809 uint8_t i;
2810 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002811
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002812 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2813 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002814
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002815 ENTER();
2816 /* Do only IPA Pipe specific configuration here. All one time
2817 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2818 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2819 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002820 if (!pdev || !soc) {
2821 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkb4f591d2017-03-29 15:51:01 -07002822 status = QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002823 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002824 }
Yun Parkb4f591d2017-03-29 15:51:01 -07002825 if (cdp_ipa_get_resource(soc, (struct cdp_pdev *)pdev)) {
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002826 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2827 "IPA UC resource alloc fail");
2828 return QDF_STATUS_E_FAILURE;
2829 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002830
Yun Parkb4f591d2017-03-29 15:51:01 -07002831 if (true == hdd_ipa->uc_loaded) {
2832 status = cdp_ipa_setup(soc, (struct cdp_pdev *)pdev,
2833 hdd_ipa_i2w_cb, hdd_ipa_w2i_cb,
2834 hdd_ipa_wdi_meter_notifier_cb,
2835 hdd_ctx->config->IpaDescSize,
2836 hdd_ipa, hdd_ipa_is_rm_enabled(hdd_ctx),
2837 &hdd_ipa->tx_pipe_handle,
2838 &hdd_ipa->rx_pipe_handle);
2839 if (status) {
Yun Parkbaa62862017-01-18 13:43:34 -08002840 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002841 "Failure to setup IPA pipes (status=%d)",
2842 status);
2843 return QDF_STATUS_E_FAILURE;
Yun Parkbaa62862017-01-18 13:43:34 -08002844 }
Yun Park637d6482016-10-05 10:51:33 -07002845
Yun Parkb4f591d2017-03-29 15:51:01 -07002846 cdp_ipa_set_doorbell_paddr(soc, (struct cdp_pdev *)pdev);
2847 hdd_ipa_init_metering(hdd_ipa);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002848 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002849
Yun Parkb4f591d2017-03-29 15:51:01 -07002850 cdp_ipa_register_op_cb(soc, (struct cdp_pdev *)pdev,
Yun Parkbaa62862017-01-18 13:43:34 -08002851 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
2852
Yun Parkb4f591d2017-03-29 15:51:01 -07002853 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
2854 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
2855 hdd_ipa_uc_fw_op_event_handler);
2856 hdd_ipa->uc_op_work[i].msg = NULL;
2857 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002858
Yun Parkbaa62862017-01-18 13:43:34 -08002859fail_return:
2860 EXIT();
Yun Parkb4f591d2017-03-29 15:51:01 -07002861 return status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002862}
2863
Leo Change3e49442015-10-26 20:07:13 -07002864/**
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302865 * hdd_ipa_uc_ol_deinit() - Disconnect IPA TX and RX pipes
2866 * @hdd_ctx: Global HDD context
2867 *
2868 * Return: 0 on success, negativer errno on error
2869 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002870int hdd_ipa_uc_ol_deinit(struct hdd_context *hdd_ctx)
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302871{
2872 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
2873 int ret = 0;
Yun Parkb4f591d2017-03-29 15:51:01 -07002874 QDF_STATUS status;
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302875
2876 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2877 return ret;
2878
Sravan Kumar Kairam374a8682017-05-15 13:19:44 +05302879 if (!hdd_ipa->ipa_pipes_down)
2880 hdd_ipa_uc_disable_pipes(hdd_ipa);
2881
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302882 if (true == hdd_ipa->uc_loaded) {
Yun Parkb4f591d2017-03-29 15:51:01 -07002883 status = cdp_ipa_cleanup(cds_get_context(QDF_MODULE_ID_SOC),
2884 hdd_ipa->tx_pipe_handle,
2885 hdd_ipa->rx_pipe_handle);
2886 if (status) {
2887 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2888 "Failure to cleanup IPA pipes (status=%d)",
2889 status);
2890 return -EFAULT;
2891 }
Sravan Kumar Kairam71121712017-04-15 00:34:42 +05302892 }
2893
2894 return ret;
2895}
2896
2897/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002898 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07002899 * @hdd_ctx: hdd main context
2900 *
2901 * Force shutdown IPA pipe
2902 * Independent of FW pipe status, IPA pipe shutdonw progress
2903 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2904 * independent from FW pipe status
2905 *
2906 * Return: NONE
2907 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002908static void __hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07002909{
2910 struct hdd_ipa_priv *hdd_ipa;
2911
2912 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
2913 return;
2914
2915 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2916 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302917 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb4f591d2017-03-29 15:51:01 -07002918 "IPA pipes are not down yet, force shutdown");
Leo Change3e49442015-10-26 20:07:13 -07002919 hdd_ipa_uc_disable_pipes(hdd_ipa);
2920 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002921 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb4f591d2017-03-29 15:51:01 -07002922 "IPA pipes are down, do nothing");
Leo Change3e49442015-10-26 20:07:13 -07002923 }
Leo Change3e49442015-10-26 20:07:13 -07002924}
2925
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002927 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
2928 * __hdd_ipa_uc_force_pipe_shutdown
2929 * @hdd_ctx: hdd main context
2930 *
2931 * Force shutdown IPA pipe
2932 * Independent of FW pipe status, IPA pipe shutdonw progress
2933 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
2934 * independent from FW pipe status
2935 *
2936 * Return: NONE
2937 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07002938void hdd_ipa_uc_force_pipe_shutdown(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07002939{
2940 cds_ssr_protect(__func__);
2941 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
2942 cds_ssr_unprotect(__func__);
2943}
2944
2945/**
Govind Singh9c58eba2016-09-02 16:23:06 +05302946 * hdd_ipa_msg_free_fn() - Free an IPA message
2947 * @buff: pointer to the IPA message
2948 * @len: length of the IPA message
2949 * @type: type of IPA message
2950 *
2951 * Return: None
2952 */
2953static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
2954{
Srinivas Girigowda97852372017-03-06 16:52:59 -08002955 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05302956 ghdd_ipa->stats.num_free_msg++;
2957 qdf_mem_free(buff);
2958}
2959
Govind Singh9c58eba2016-09-02 16:23:06 +05302960/**
jge62037862016-12-09 10:44:33 +08002961 * hdd_ipa_uc_send_evt() - send event to ipa
2962 * @hdd_ctx: pointer to hdd context
2963 * @type: event type
2964 * @mac_addr: pointer to mac address
2965 *
2966 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05302967 *
2968 * Return: 0 - Success
2969 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07002970static int hdd_ipa_uc_send_evt(struct hdd_adapter *adapter,
jge62037862016-12-09 10:44:33 +08002971 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05302972{
jge62037862016-12-09 10:44:33 +08002973 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05302974 struct ipa_msg_meta meta;
2975 struct ipa_wlan_msg *msg;
2976 int ret = 0;
jge62037862016-12-09 10:44:33 +08002977
2978 meta.msg_len = sizeof(struct ipa_wlan_msg);
2979 msg = qdf_mem_malloc(meta.msg_len);
2980 if (msg == NULL) {
2981 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2982 "msg allocation failed");
2983 return -ENOMEM;
2984 }
2985
2986 meta.msg_type = type;
2987 strlcpy(msg->name, adapter->dev->name,
2988 IPA_RESOURCE_NAME_MAX);
2989 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Srinivas Girigowda97852372017-03-06 16:52:59 -08002990 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08002991 msg->name, meta.msg_type);
2992 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
2993 if (ret) {
2994 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2995 "%s: Evt: %d fail:%d",
2996 msg->name, meta.msg_type, ret);
2997 qdf_mem_free(msg);
2998 return ret;
2999 }
3000
3001 hdd_ipa->stats.num_send_msg++;
3002
3003 return ret;
3004}
3005
3006/**
3007 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3008 * @hdd_ctx: pointer to hdd adapter
3009 *
3010 * Send disconnect client event to IPA driver during SSR
3011 *
3012 * Return: 0 - Success
3013 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003014static int hdd_ipa_uc_disconnect_client(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003015{
3016 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3017 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303018 int i;
3019
3020 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3021 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3022 continue;
3023 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003024 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3025 hdd_ipa->sap_num_connected_sta) {
3026 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3027 adapter->aStaInfo[i].macAddrSTA.bytes);
3028 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303029 }
3030 }
3031
3032 return ret;
3033}
3034
3035/**
jge62037862016-12-09 10:44:33 +08003036 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3037 * @hdd_ctx: pointer to hdd adapter
3038 *
3039 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303040 *
3041 * Return: 0 - Success
3042 */
jge62037862016-12-09 10:44:33 +08003043
Jeff Johnson49d45e62017-08-29 14:30:42 -07003044static int hdd_ipa_uc_disconnect_ap(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003045{
3046 int ret = 0;
3047
3048 if (adapter->ipa_context)
3049 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3050 adapter->dev->dev_addr);
3051
3052 return ret;
3053}
3054
jge62037862016-12-09 10:44:33 +08003055/**
3056 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3057 * @hdd_ctx: pointer to hdd adapter
3058 *
3059 * Send disconnect sta event to IPA driver during SSR
3060 *
3061 * Return: 0 - Success
3062 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07003063static int hdd_ipa_uc_disconnect_sta(struct hdd_adapter *adapter)
jge62037862016-12-09 10:44:33 +08003064{
Jeff Johnsond377dce2017-10-04 10:32:42 -07003065 struct hdd_station_ctx *sta_ctx;
jge62037862016-12-09 10:44:33 +08003066 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3067 int ret = 0;
3068
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003069 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003070 hdd_ipa->sta_connected) {
Jeff Johnsond377dce2017-10-04 10:32:42 -07003071 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
jge62037862016-12-09 10:44:33 +08003072 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Jeff Johnsond377dce2017-10-04 10:32:42 -07003073 sta_ctx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003074 }
3075
3076 return ret;
3077}
jge62037862016-12-09 10:44:33 +08003078
3079/**
3080 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3081 * @hdd_ctx: pointer to hdd context
3082 *
3083 * Send disconnect event to IPA driver during SSR
3084 *
3085 * Return: 0 - Success
3086 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003087static int hdd_ipa_uc_disconnect(struct hdd_context *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303088{
3089 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3090 QDF_STATUS status;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003091 struct hdd_adapter *adapter;
Govind Singh9c58eba2016-09-02 16:23:06 +05303092 int ret = 0;
3093
Govind Singh9c58eba2016-09-02 16:23:06 +05303094 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3095 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson57eb2732017-10-02 11:40:20 -07003096 adapter = adapter_node->adapter;
jge62037862016-12-09 10:44:33 +08003097 if (adapter->device_mode == QDF_SAP_MODE) {
3098 hdd_ipa_uc_disconnect_client(adapter);
3099 hdd_ipa_uc_disconnect_ap(adapter);
3100 } else if (adapter->device_mode == QDF_STA_MODE) {
3101 hdd_ipa_uc_disconnect_sta(adapter);
3102 }
3103
Govind Singh9c58eba2016-09-02 16:23:06 +05303104 status = hdd_get_next_adapter(
3105 hdd_ctx, adapter_node, &next);
3106 adapter_node = next;
3107 }
3108
3109 return ret;
3110}
3111
3112/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003113 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003114 *
3115 * Deinit basic IPA UC host side to be in sync reloaded FW during
3116 * SSR
3117 *
3118 * Return: 0 - Success
3119 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003120static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003121{
3122 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3123 int idx;
3124 struct hdd_ipa_iface_context *iface_context;
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003125 struct hdd_context *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003126
Arun Khandavallicc544b32017-01-30 19:52:16 +05303127 if (!hdd_ipa)
3128 return 0;
3129
3130 hdd_ctx = hdd_ipa->hdd_ctx;
3131 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003132 return 0;
3133
jge62037862016-12-09 10:44:33 +08003134 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303135 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003137 /* Clean up HDD IPA interfaces */
3138 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3139 (idx < HDD_IPA_MAX_IFACE); idx++) {
3140 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003141 if (iface_context->adapter && iface_context->adapter->magic ==
3142 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003143 hdd_ipa_cleanup_iface(iface_context);
3144 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003145 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003146 /* After SSR, wlan driver reloads FW again. But we need to protect
3147 * IPA submodule during SSR transient state. So deinit basic IPA
3148 * UC host side to be in sync with reloaded FW during SSR
3149 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003150
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303151 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003152 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3153 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3154 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3155 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303156 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003157
Guolei Bianca144d82016-11-10 11:07:42 +08003158 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3159 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3160
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003161 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3162 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3163 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3164 hdd_ipa->uc_op_work[idx].msg = NULL;
3165 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003166 return 0;
3167}
3168
3169/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003170 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3171 *
3172 * Deinit basic IPA UC host side to be in sync reloaded FW during
3173 * SSR
3174 *
3175 * Return: 0 - Success
3176 */
3177int hdd_ipa_uc_ssr_deinit(void)
3178{
3179 int ret;
3180
3181 cds_ssr_protect(__func__);
3182 ret = __hdd_ipa_uc_ssr_deinit();
3183 cds_ssr_unprotect(__func__);
3184
3185 return ret;
3186}
3187
3188/**
3189 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003190 *
3191 * Init basic IPA UC host side to be in sync with reloaded FW after
3192 * SSR to resume IPA UC operations
3193 *
3194 * Return: 0 - Success
3195 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003196static int __hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003197{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003198
Arun Khandavallicc544b32017-01-30 19:52:16 +05303199 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3200 int i;
3201 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303202
3203 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3204 return 0;
3205
Arun Khandavallicc544b32017-01-30 19:52:16 +05303206 /* Create the interface context */
3207 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3208 iface_context = &hdd_ipa->iface_context[i];
3209 iface_context->hdd_ipa = hdd_ipa;
3210 iface_context->cons_client =
3211 hdd_ipa_adapter_2_client[i].cons_client;
3212 iface_context->prod_client =
3213 hdd_ipa_adapter_2_client[i].prod_client;
3214 iface_context->iface_id = i;
3215 iface_context->adapter = NULL;
3216 }
3217 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3218 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3219 hdd_ipa->vdev_offload_enabled[i] = false;
3220 }
3221
3222 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3223 hdd_ipa->resource_loading = false;
3224 hdd_ipa->resource_unloading = false;
3225 hdd_ipa->sta_connected = 0;
3226 hdd_ipa->ipa_pipes_down = true;
3227 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303228 }
3229
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003230 return 0;
3231}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003232
3233/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003234 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3235 *
3236 * Init basic IPA UC host side to be in sync with reloaded FW after
3237 * SSR to resume IPA UC operations
3238 *
3239 * Return: 0 - Success
3240 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003241int hdd_ipa_uc_ssr_reinit(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003242{
3243 int ret;
3244
3245 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303246 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003247 cds_ssr_unprotect(__func__);
3248
3249 return ret;
3250}
3251
3252/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003253 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3254 * @work: scheduled work
3255 *
3256 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3257 * not want to immediately release the wake lock since the system
3258 * would then potentially try to suspend when there is a healthy data
3259 * rate. Deferred work is scheduled and this function handles the
3260 * work. When this function is called, if the IPA resource is still
3261 * released then we release the wake lock.
3262 *
3263 * Return: None
3264 */
3265static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3266{
3267 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3268 struct hdd_ipa_priv,
3269 wake_lock_work);
3270
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303271 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003272
3273 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3274 goto end;
3275
3276 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303277 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003278 WIFI_POWER_EVENT_WAKELOCK_IPA);
3279
3280end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303281 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003282}
3283
3284/**
3285 * hdd_ipa_rm_request() - Request resource from IPA
3286 * @hdd_ipa: Global HDD IPA context
3287 *
3288 * Return: 0 on success, negative errno on error
3289 */
3290static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3291{
3292 int ret = 0;
3293
3294 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3295 return 0;
3296
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303297 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003298
3299 switch (hdd_ipa->rm_state) {
3300 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303301 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003302 return 0;
3303 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303304 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003305 return -EINPROGRESS;
3306 case HDD_IPA_RM_RELEASED:
3307 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3308 break;
3309 }
3310
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303311 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003312
3313 ret = ipa_rm_inactivity_timer_request_resource(
3314 IPA_RM_RESOURCE_WLAN_PROD);
3315
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303316 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003317 if (ret == 0) {
3318 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3319 hdd_ipa->stats.num_rm_grant_imm++;
3320 }
3321
3322 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3323 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303324 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003325 WIFI_POWER_EVENT_WAKELOCK_IPA);
3326 hdd_ipa->wake_lock_released = false;
3327 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303328 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003329
3330 return ret;
3331}
3332
3333/**
3334 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3335 * @hdd_ipa: Global HDD IPA context
3336 *
3337 * Return: 0 if resources released, negative errno otherwise
3338 */
3339static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3340{
3341 int ret = 0;
3342
3343 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3344 return 0;
3345
3346 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3347 return -EAGAIN;
3348
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303349 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003350
Nirav Shahcbc6d722016-03-01 16:24:53 +05303351 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303352 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353 return -EAGAIN;
3354 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303355 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003356
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303357 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003358 switch (hdd_ipa->rm_state) {
3359 case HDD_IPA_RM_GRANTED:
3360 break;
3361 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303362 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003363 return -EINPROGRESS;
3364 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303365 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003366 return 0;
3367 }
3368
3369 /* IPA driver returns immediately so set the state here to avoid any
3370 * race condition.
3371 */
3372 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3373 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303374 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003375
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003376 ret = ipa_rm_inactivity_timer_release_resource(
3377 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003378
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303379 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380 if (unlikely(ret != 0)) {
3381 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3382 WARN_ON(1);
3383 }
3384
3385 /*
3386 * If wake_lock is released immediately, kernel would try to suspend
3387 * immediately as well, Just avoid ping-pong between suspend-resume
3388 * while there is healthy amount of data transfer going on by
3389 * releasing the wake_lock after some delay.
3390 */
3391 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3392 msecs_to_jiffies
3393 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3394
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303395 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003396
3397 return ret;
3398}
3399
3400/**
3401 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3402 * @user_data: user data registered with IPA
3403 * @event: the IPA resource manager event that occurred
3404 * @data: the data associated with the event
3405 *
3406 * Return: None
3407 */
3408static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3409 unsigned long data)
3410{
3411 struct hdd_ipa_priv *hdd_ipa = user_data;
3412
3413 if (unlikely(!hdd_ipa))
3414 return;
3415
3416 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3417 return;
3418
Srinivas Girigowda97852372017-03-06 16:52:59 -08003419 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003420
3421 switch (event) {
3422 case IPA_RM_RESOURCE_GRANTED:
3423 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3424 /* RM Notification comes with ISR context
3425 * it should be serialized into work queue to avoid
3426 * ISR sleep problem
3427 */
3428 hdd_ipa->uc_rm_work.event = event;
3429 schedule_work(&hdd_ipa->uc_rm_work.work);
3430 break;
3431 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303432 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003433 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303434 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003435 hdd_ipa->stats.num_rm_grant++;
3436 break;
3437
3438 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003439 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003440 hdd_ipa->resource_unloading = false;
3441 break;
3442
3443 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303444 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003445 break;
3446 }
3447}
3448
3449/**
3450 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3451 *
3452 * Callback function registered with IPA that is called when IPA wants
3453 * to release the WLAN consumer resource
3454 *
3455 * Return: 0 if the request is granted, negative errno otherwise
3456 */
3457static int hdd_ipa_rm_cons_release(void)
3458{
3459 return 0;
3460}
3461
3462/**
3463 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3464 *
3465 * Callback function registered with IPA that is called when IPA wants
3466 * to access the WLAN consumer resource
3467 *
3468 * Return: 0 if the request is granted, negative errno otherwise
3469 */
3470static int hdd_ipa_rm_cons_request(void)
3471{
Yun Park4d8b60a2015-10-22 13:59:32 -07003472 int ret = 0;
3473
3474 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303475 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003476 "IPA resource loading in progress");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003477 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003478 ret = -EINPROGRESS;
3479 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303480 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Parkb4f591d2017-03-29 15:51:01 -07003481 "IPA resource unloading in progress");
Yun Park4d8b60a2015-10-22 13:59:32 -07003482 ghdd_ipa->pending_cons_req = true;
3483 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003484 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003485
3486 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003487}
3488
3489/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003490 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003491 * @hdd_ctx: Global HDD context
3492 * @tx_packets: Number of packets transmitted in the last sample period
3493 * @rx_packets: Number of packets received in the last sample period
3494 *
3495 * Return: 0 on success, negative errno on error
3496 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07003497static int __hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx,
3498 uint64_t tx_packets,
3499 uint64_t rx_packets)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003500{
3501 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003502 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003503 struct ipa_rm_perf_profile profile;
Yun Parkb4f591d2017-03-29 15:51:01 -07003504 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003505 int ret;
3506
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003507 if (wlan_hdd_validate_context(hdd_ctx))
3508 return 0;
3509
3510 hdd_ipa = hdd_ctx->hdd_ipa;
3511
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003512 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3513 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3514 return 0;
3515
3516 memset(&profile, 0, sizeof(profile));
3517
3518 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3519 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3520 else if (tx_packets >
3521 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3522 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3523 else
3524 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3525
3526 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3527 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3528 else if (rx_packets >
3529 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3530 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3531 else
3532 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3533
Yun Parkec845302016-12-15 09:22:57 -08003534 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003535 "CONS perf curr: %d, next: %d",
3536 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003537 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003538 "PROD perf curr: %d, next: %d",
3539 hdd_ipa->curr_prod_bw, next_prod_bw);
3540
3541 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003542 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003543 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003544 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_CONS,
3545 next_cons_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003546 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003547 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003548
3549 return ret;
3550 }
3551 hdd_ipa->curr_cons_bw = next_cons_bw;
3552 hdd_ipa->stats.num_cons_perf_req++;
3553 }
3554
3555 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003556 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003557 hdd_ipa->curr_prod_bw, next_prod_bw);
Yun Parkb4f591d2017-03-29 15:51:01 -07003558 ret = cdp_ipa_set_perf_level(soc, IPA_RM_RESOURCE_WLAN_PROD,
3559 next_prod_bw);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003560 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003561 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003562 return ret;
3563 }
3564 hdd_ipa->curr_prod_bw = next_prod_bw;
3565 hdd_ipa->stats.num_prod_perf_req++;
3566 }
3567
3568 return 0;
3569}
3570
3571/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003572 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3573 * @hdd_ctx: Global HDD context
3574 * @tx_packets: Number of packets transmitted in the last sample period
3575 * @rx_packets: Number of packets received in the last sample period
3576 *
3577 * Return: 0 on success, negative errno on error
3578 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07003579int hdd_ipa_set_perf_level(struct hdd_context *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003580 uint64_t rx_packets)
3581{
3582 int ret;
3583
3584 cds_ssr_protect(__func__);
3585 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3586 cds_ssr_unprotect(__func__);
3587
3588 return ret;
3589}
3590
3591/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003592 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3593 * @work: struct work_struct
3594 * @work_handler: work_handler
3595 *
3596 * Return: none
3597 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003598static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3599 work_func_t work_handler)
3600{
3601 INIT_WORK(work, work_handler);
3602}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003603
3604/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 * hdd_ipa_setup_rm() - Setup IPA resource management
3606 * @hdd_ipa: Global HDD IPA context
3607 *
3608 * Return: 0 on success, negative errno on error
3609 */
3610static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3611{
3612 struct ipa_rm_create_params create_params = { 0 };
3613 int ret;
3614
3615 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3616 return 0;
3617
Rajeev Kumar217f2172016-01-06 18:11:55 -08003618 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3619 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003620 memset(&create_params, 0, sizeof(create_params));
3621 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3622 create_params.reg_params.user_data = hdd_ipa;
3623 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3624 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3625
3626 ret = ipa_rm_create_resource(&create_params);
3627 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303628 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 "Create RM resource failed: %d", ret);
3630 goto setup_rm_fail;
3631 }
3632
3633 memset(&create_params, 0, sizeof(create_params));
3634 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3635 create_params.request_resource = hdd_ipa_rm_cons_request;
3636 create_params.release_resource = hdd_ipa_rm_cons_release;
3637 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3638
3639 ret = ipa_rm_create_resource(&create_params);
3640 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303641 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003642 "Create RM CONS resource failed: %d", ret);
3643 goto delete_prod;
3644 }
3645
3646 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3647 IPA_RM_RESOURCE_APPS_CONS);
3648
3649 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3650 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3651 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303652 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003653 ret);
3654 goto timer_init_failed;
3655 }
3656
3657 /* Set the lowest bandwidth to start with */
3658 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3659
3660 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303661 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003662 "Set perf level failed: %d", ret);
3663 goto set_perf_failed;
3664 }
3665
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303666 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003667 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3668 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303669 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003670 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3671 hdd_ipa->wake_lock_released = true;
3672 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
3673
3674 return ret;
3675
3676set_perf_failed:
3677 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3678
3679timer_init_failed:
3680 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3681
3682delete_prod:
3683 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3684
3685setup_rm_fail:
3686 return ret;
3687}
3688
3689/**
3690 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
3691 * @hdd_ipa: Global HDD IPA context
3692 *
3693 * Destroys all resources associated with the IPA resource manager
3694 *
3695 * Return: None
3696 */
3697static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
3698{
3699 int ret;
3700
3701 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3702 return;
3703
3704 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303705 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303708 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003709
3710 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
3711
3712 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
3713 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303714 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003715 "RM PROD resource delete failed %d", ret);
3716
3717 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
3718 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303719 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003720 "RM CONS resource delete failed %d", ret);
3721}
3722
tfyu0380a972017-07-13 18:19:37 +08003723#ifdef QCA_CONFIG_SMP
3724static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3725{
3726 return netif_rx_ni(skb);
3727}
3728#else
3729static int hdd_ipa_aggregated_rx_ind(qdf_nbuf_t skb)
3730{
3731 struct iphdr *ip_h;
3732 static atomic_t softirq_mitigation_cntr =
3733 ATOMIC_INIT(IPA_WLAN_RX_SOFTIRQ_THRESH);
3734 int result;
3735
3736 ip_h = (struct iphdr *)(skb->data);
3737 if ((skb->protocol == htons(ETH_P_IP)) &&
3738 (ip_h->protocol == IPPROTO_ICMP)) {
3739 result = netif_rx_ni(skb);
3740 } else {
3741 /* Call netif_rx_ni for every IPA_WLAN_RX_SOFTIRQ_THRESH packets
3742 * to avoid excessive softirq's.
3743 */
3744 if (atomic_dec_and_test(&softirq_mitigation_cntr)) {
3745 result = netif_rx_ni(skb);
3746 atomic_set(&softirq_mitigation_cntr,
3747 IPA_WLAN_RX_SOFTIRQ_THRESH);
3748 } else {
3749 result = netif_rx(skb);
3750 }
3751 }
3752
3753 return result;
3754}
3755#endif
3756
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003757/**
3758 * hdd_ipa_send_skb_to_network() - Send skb to kernel
3759 * @skb: network buffer
3760 * @adapter: network adapter
3761 *
3762 * Called when a network buffer is received which should not be routed
3763 * to the IPA module.
3764 *
3765 * Return: None
3766 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05303767static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003768 struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003769{
tfyu0380a972017-07-13 18:19:37 +08003770 int result;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3772 unsigned int cpu_index;
3773
3774 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Jeff Johnson36e74c42017-09-18 08:15:42 -07003775 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%pK",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003776 adapter);
3777 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003778 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003779 return;
3780 }
3781
Prashanth Bhatta9e143052015-12-04 11:56:47 -08003782 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003783 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003784 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003785 return;
3786 }
3787
3788 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
3789 skb->dev = adapter->dev;
3790 skb->protocol = eth_type_trans(skb, skb->dev);
3791 skb->ip_summed = CHECKSUM_NONE;
3792
3793 cpu_index = wlan_hdd_get_cpu();
3794
3795 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
tfyu0380a972017-07-13 18:19:37 +08003796 result = hdd_ipa_aggregated_rx_ind(skb);
3797 if (result == NET_RX_SUCCESS)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003798 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
3799 else
3800 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
3801
3802 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803}
3804
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003805/**
Leo Chang69c39692016-10-12 20:11:12 -07003806 * hdd_ipa_forward() - handle packet forwarding to wlan tx
3807 * @hdd_ipa: pointer to hdd ipa context
3808 * @adapter: network adapter
3809 * @skb: data pointer
3810 *
3811 * if exception packet has set forward bit, copied new packet should be
3812 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
3813 * put into pm queue and tx procedure will be differed
3814 *
3815 * Return: None
3816 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07003817static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003818 struct hdd_adapter *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07003819{
Leo Chang69c39692016-10-12 20:11:12 -07003820 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
3821
Leo Chang69c39692016-10-12 20:11:12 -07003822 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Yun Park01deb2c2017-06-14 15:21:44 -07003823
3824 /* Set IPA ownership for intra-BSS Tx packets to avoid skb_orphan */
3825 qdf_nbuf_ipa_owned_set(skb);
3826
Leo Chang69c39692016-10-12 20:11:12 -07003827 /* WLAN subsystem is in suspend, put int queue */
3828 if (hdd_ipa->suspended) {
3829 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3830 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3831 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003832 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
3833 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07003834 pm_tx_cb->exception = true;
3835 pm_tx_cb->adapter = adapter;
3836 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003837 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07003838 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
3839 hdd_ipa->stats.num_tx_queued++;
3840 } else {
3841 /* Resume, put packet into WLAN TX */
3842 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003843 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07003844 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3845 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08003846 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07003847 } else {
Yun Parkb187d542016-11-14 18:10:04 -08003848 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07003849 hdd_ipa->ipa_tx_forward++;
3850 }
3851 }
3852}
3853
3854/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003855 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
3856 * @hdd_ipa: pointer to HDD IPA struct
3857 * @adapter: hdd adapter pointer
3858 * @desc: Firmware descriptor
3859 * @skb: Data buffer
3860 *
3861 * Return:
3862 * HDD_IPA_FORWARD_PKT_NONE
3863 * HDD_IPA_FORWARD_PKT_DISCARD
3864 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
3865 *
3866 */
3867
3868static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
3869 struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07003870 struct hdd_adapter *adapter,
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003871 uint8_t desc,
3872 qdf_nbuf_t skb)
3873{
3874 int ret = HDD_IPA_FORWARD_PKT_NONE;
3875
3876 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303877 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08003878 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
3879 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05303880 /* Drop the packet*/
3881 hdd_ipa->stats.num_tx_fwd_err++;
3882 kfree_skb(skb);
3883 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3884 return ret;
3885 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003886 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
3887 "Forward packet to Tx (fw_desc=%d)", desc);
3888 hdd_ipa->ipa_tx_forward++;
3889
3890 if ((desc & FW_RX_DESC_DISCARD_M)) {
3891 hdd_ipa_forward(hdd_ipa, adapter, skb);
3892 hdd_ipa->ipa_rx_internel_drop_count++;
3893 hdd_ipa->ipa_rx_discard++;
3894 ret = HDD_IPA_FORWARD_PKT_DISCARD;
3895 } else {
3896 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003897
Prakash Dhavali87b38e32016-11-14 16:22:53 -08003898 if (cloned_skb)
3899 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
3900 else
3901 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3902 "%s: tx skb alloc failed",
3903 __func__);
3904 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
3905 }
3906 }
3907
3908 return ret;
3909}
3910
3911/**
Yun Park637d6482016-10-05 10:51:33 -07003912 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003913 * @priv: pointer to private data registered with IPA (we register a
3914 * pointer to the global IPA context)
3915 * @evt: the IPA event which triggered the callback
3916 * @data: data associated with the event
3917 *
3918 * Return: None
3919 */
Yun Parkf8d6a122016-10-11 15:49:43 -07003920static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003921 unsigned long data)
3922{
3923 struct hdd_ipa_priv *hdd_ipa = NULL;
Jeff Johnson49d45e62017-08-29 14:30:42 -07003924 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05303925 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003926 uint8_t iface_id;
3927 uint8_t session_id;
3928 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003929 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07003930 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003931
3932 hdd_ipa = (struct hdd_ipa_priv *)priv;
3933
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08003934 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
3935 return;
3936
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003937 switch (evt) {
3938 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05303939 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07003940
3941 /*
3942 * When SSR is going on or driver is unloading,
3943 * just drop the packets.
3944 */
3945 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
3946 if (0 != status) {
3947 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3948 "Invalid context: drop packet");
3949 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3950 kfree_skb(skb);
3951 return;
3952 }
3953
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003954 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3955 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08003956 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08003957 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 "IPA_RECEIVE: session_id=%u, iface_id=%u",
3959 session_id, iface_id);
3960 } else {
3961 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
3962 }
3963
3964 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303965 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003966 "IPA_RECEIVE: Invalid iface_id: %u",
3967 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003968 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003969 "w2i -- skb",
3970 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07003972 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003973 return;
3974 }
3975
3976 iface_context = &hdd_ipa->iface_context[iface_id];
3977 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08003978 if (!adapter) {
3979 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3980 "IPA_RECEIVE: Adapter is NULL");
3981 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
3982 kfree_skb(skb);
3983 return;
3984 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003985
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303986 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08003987 "w2i -- skb",
3988 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003989 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3990 hdd_ipa->stats.num_rx_excep++;
3991 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
3992 } else {
3993 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
3994 }
3995
3996 iface_context->stats.num_rx_ipa_excep++;
3997
3998 /* Disable to forward Intra-BSS Rx packets when
3999 * ap_isolate=1 in hostapd.conf
4000 */
Yun Park046101c2016-09-02 15:32:14 -07004001 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004002 /*
4003 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4004 * all Rx packets to IPA uC, which need to be forwarded
4005 * to other interface.
4006 * And, IPA driver will send back to WLAN host driver
4007 * through exception pipe with fw_desc field set by FW.
4008 * Here we are checking fw_desc field for FORWARD bit
4009 * set, and forward to Tx. Then copy to kernel stack
4010 * only when DISCARD bit is not set.
4011 */
4012 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004013 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4014 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4015 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004016 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004017 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004018 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004019 "Intra-BSS FWD is disabled-skip forward to Tx");
4020 }
4021
4022 hdd_ipa_send_skb_to_network(skb, adapter);
4023 break;
4024
4025 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304026 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004027 "w2i cb wrong event: 0x%x", evt);
4028 return;
4029 }
4030}
4031
4032/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004033 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4034 * @priv: pointer to private data registered with IPA (we register a
4035 * pointer to the global IPA context)
4036 * @evt: the IPA event which triggered the callback
4037 * @data: data associated with the event
4038 *
4039 * Return: None
4040 */
4041static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4042 unsigned long data)
4043{
4044 cds_ssr_protect(__func__);
4045 __hdd_ipa_w2i_cb(priv, evt, data);
4046 cds_ssr_unprotect(__func__);
4047}
4048
4049/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004050 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4051 * @skb: packet buffer which was transmitted
4052 *
4053 * Return: None
4054 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304055void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004056{
4057 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004058 struct ipa_rx_data *ipa_tx_desc;
4059 struct hdd_ipa_tx_desc *tx_desc;
4060 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004061
Yun Park52b2b992016-09-22 15:49:51 -07004062 if (!qdf_nbuf_ipa_owned_get(skb)) {
4063 dev_kfree_skb_any(skb);
4064 return;
4065 }
4066
4067 /* Get Tx desc pointer from SKB CB */
4068 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4069 tx_desc = hdd_ipa->tx_desc_list + id;
4070 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4071
4072 /* Return Tx Desc to IPA */
4073 ipa_free_skb(ipa_tx_desc);
4074
4075 /* Return to free tx desc list */
4076 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4077 tx_desc->ipa_tx_desc_ptr = NULL;
4078 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4079 hdd_ipa->stats.num_tx_desc_q_cnt--;
4080 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004081
4082 hdd_ipa->stats.num_tx_comp_cnt++;
4083
4084 atomic_dec(&hdd_ipa->tx_ref_cnt);
4085
4086 hdd_ipa_rm_try_release(hdd_ipa);
4087}
4088
4089/**
4090 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4091 * @iface_context: interface-specific IPA context
4092 * @ipa_tx_desc: packet data descriptor
4093 *
4094 * Return: None
4095 */
4096static void hdd_ipa_send_pkt_to_tl(
4097 struct hdd_ipa_iface_context *iface_context,
4098 struct ipa_rx_data *ipa_tx_desc)
4099{
4100 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Jeff Johnson49d45e62017-08-29 14:30:42 -07004101 struct hdd_adapter *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304102 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004103 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004104
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304105 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004106 adapter = iface_context->adapter;
4107 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304108 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004109 ipa_free_skb(ipa_tx_desc);
4110 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304111 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004112 hdd_ipa_rm_try_release(hdd_ipa);
4113 return;
4114 }
4115
4116 /*
4117 * During CAC period, data packets shouldn't be sent over the air so
4118 * drop all the packets here
4119 */
hqu70708ab2017-10-10 17:52:01 +08004120 if (QDF_SAP_MODE == adapter->device_mode ||
4121 QDF_P2P_GO_MODE == adapter->device_mode) {
4122 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4123 ipa_free_skb(ipa_tx_desc);
4124 qdf_spin_unlock_bh(&iface_context->interface_lock);
4125 iface_context->stats.num_tx_cac_drop++;
4126 hdd_ipa_rm_try_release(hdd_ipa);
4127 return;
4128 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004129 }
4130
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004131 ++adapter->stats.tx_packets;
4132
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304133 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004134
4135 skb = ipa_tx_desc->skb;
4136
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304137 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004138
4139 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304140 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004141 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304142 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004143 ipa_tx_desc->dma_addr
4144 + HDD_IPA_WLAN_FRAG_HEADER
4145 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004146 ipa_tx_desc->skb->len -=
4147 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4148 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304149 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004150
Yun Park52b2b992016-09-22 15:49:51 -07004151 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4152 /* get free Tx desc and assign ipa_tx_desc pointer */
4153 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4154 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4155 struct hdd_ipa_tx_desc, link);
4156 list_del(&tx_desc->link);
4157 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4158 hdd_ipa->stats.num_tx_desc_q_cnt++;
4159 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4160 /* Store Tx Desc index into SKB CB */
4161 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4162 } else {
4163 hdd_ipa->stats.num_tx_desc_error++;
4164 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4165 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4166 ipa_free_skb(ipa_tx_desc);
4167 hdd_ipa_rm_try_release(hdd_ipa);
4168 return;
4169 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004170
4171 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4172
Leo Changfdb45c32016-10-28 11:09:23 -07004173 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004174 (struct cdp_vdev *)iface_context->tl_context,
4175 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004176 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304177 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
jiad05c1e812017-08-01 16:48:52 +08004178 qdf_nbuf_free(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004179 iface_context->stats.num_tx_err++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004180 return;
4181 }
4182
4183 atomic_inc(&hdd_ipa->tx_ref_cnt);
4184
4185 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004186}
4187
4188/**
Leo Chang11545d62016-10-17 14:53:50 -07004189 * hdd_ipa_is_present() - get IPA hw status
4190 * @hdd_ctx: pointer to hdd context
4191 *
4192 * ipa_uc_reg_rdyCB is not directly designed to check
4193 * ipa hw status. This is an undocumented function which
4194 * has confirmed with IPA team.
4195 *
4196 * Return: true - ipa hw present
4197 * false - ipa hw not present
4198 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004199bool hdd_ipa_is_present(struct hdd_context *hdd_ctx)
Leo Chang11545d62016-10-17 14:53:50 -07004200{
4201 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004202 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004203 return true;
4204 else
4205 return false;
4206}
4207
4208/**
Leo Chang69c39692016-10-12 20:11:12 -07004209 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 * @work: pointer to the scheduled work
4211 *
4212 * Called during PM resume to send packets to TL which were queued
4213 * while host was in the process of suspending.
4214 *
4215 * Return: None
4216 */
Leo Chang69c39692016-10-12 20:11:12 -07004217static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218{
4219 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4220 struct hdd_ipa_priv,
4221 pm_work);
4222 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304223 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004224 uint32_t dequeued = 0;
4225
Leo Chang69c39692016-10-12 20:11:12 -07004226 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4227 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304228 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304229 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4230 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304231 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004232
4233 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004234 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004235 if (pm_tx_cb->exception) {
4236 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4237 "FLUSH EXCEPTION");
Govind Singh1dab23b2017-08-12 13:31:00 +05304238 if (pm_tx_cb->adapter->dev)
4239 hdd_softap_hard_start_xmit(skb,
4240 pm_tx_cb->adapter->dev);
Govind Singh02075942017-08-15 11:13:28 +05304241 else
4242 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004243 } else {
4244 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004245 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004246 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304247 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304249 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004250 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4251 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004252
4253 hdd_ipa->stats.num_tx_dequeued += dequeued;
4254 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4255 hdd_ipa->stats.num_max_pm_queue = dequeued;
4256}
4257
4258/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004259 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 * @priv: pointer to private data registered with IPA (we register a
4261 * pointer to the interface-specific IPA context)
4262 * @evt: the IPA event which triggered the callback
4263 * @data: data associated with the event
4264 *
4265 * Return: None
4266 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004267static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004268 unsigned long data)
4269{
4270 struct hdd_ipa_priv *hdd_ipa = NULL;
4271 struct ipa_rx_data *ipa_tx_desc;
4272 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304273 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304275 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004276
Mukul Sharma81661ae2015-10-30 20:26:02 +05304277 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004278 ipa_tx_desc = (struct ipa_rx_data *)data;
4279 hdd_ipa = iface_context->hdd_ipa;
4280
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004281 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004282 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4283 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004284 iface_context->stats.num_tx_drop++;
4285 return;
4286 }
4287
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004288 /*
4289 * When SSR is going on or driver is unloading, just drop the packets.
4290 * During SSR, there is no use in queueing the packets as STA has to
4291 * connect back any way
4292 */
4293 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304294 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004295 ipa_free_skb(ipa_tx_desc);
4296 iface_context->stats.num_tx_drop++;
4297 return;
4298 }
4299
4300 skb = ipa_tx_desc->skb;
4301
Yun Parkb187d542016-11-14 18:10:04 -08004302 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4303 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004304
4305 /*
4306 * If PROD resource is not requested here then there may be cases where
4307 * IPA hardware may be clocked down because of not having proper
4308 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4309 * workaround to request PROD resource while data is going over CONS
4310 * pipe to prevent the IPA hardware clockdown.
4311 */
4312 hdd_ipa_rm_request(hdd_ipa);
4313
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304314 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004315 /*
4316 * If host is still suspended then queue the packets and these will be
4317 * drained later when resume completes. When packet is arrived here and
4318 * host is suspended, this means that there is already resume is in
4319 * progress.
4320 */
4321 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304322 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004323 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4324 pm_tx_cb->iface_context = iface_context;
4325 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304326 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004327 hdd_ipa->stats.num_tx_queued++;
4328
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304329 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004330 return;
4331 }
4332
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304333 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004334
4335 /*
4336 * If we are here means, host is not suspended, wait for the work queue
4337 * to finish.
4338 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340
4341 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4342}
4343
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004344/*
4345 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4346 * @priv: pointer to private data registered with IPA (we register a
4347 * pointer to the interface-specific IPA context)
4348 * @evt: the IPA event which triggered the callback
4349 * @data: data associated with the event
4350 *
4351 * Return: None
4352 */
4353static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4354 unsigned long data)
4355{
4356 cds_ssr_protect(__func__);
4357 __hdd_ipa_i2w_cb(priv, evt, data);
4358 cds_ssr_unprotect(__func__);
4359}
4360
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004361/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004362 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004363 * @hdd_ctx: Global HDD context
4364 *
4365 * Return: 0 on success, negativer errno on error
4366 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004367static int __hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004368{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004369 struct hdd_ipa_priv *hdd_ipa;
4370
4371 if (wlan_hdd_validate_context(hdd_ctx))
4372 return 0;
4373
4374 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004375
4376 if (!hdd_ipa_is_enabled(hdd_ctx))
4377 return 0;
4378
4379 /*
4380 * Check if IPA is ready for suspend, If we are here means, there is
4381 * high chance that suspend would go through but just to avoid any race
4382 * condition after suspend started, these checks are conducted before
4383 * allowing to suspend.
4384 */
4385 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4386 return -EAGAIN;
4387
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304388 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004389
4390 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304391 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392 return -EAGAIN;
4393 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304394 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304396 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304398 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399
4400 return 0;
4401}
4402
4403/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004404 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4405 * @hdd_ctx: Global HDD context
4406 *
4407 * Return: 0 on success, negativer errno on error
4408 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004409int hdd_ipa_suspend(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004410{
4411 int ret;
4412
4413 cds_ssr_protect(__func__);
4414 ret = __hdd_ipa_suspend(hdd_ctx);
4415 cds_ssr_unprotect(__func__);
4416
4417 return ret;
4418}
4419
4420/**
4421 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422 * hdd_ctx: Global HDD context
4423 *
4424 * Return: 0 on success, negative errno on error
4425 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004426static int __hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004427{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004428 struct hdd_ipa_priv *hdd_ipa;
4429
4430 if (wlan_hdd_validate_context(hdd_ctx))
4431 return 0;
4432
4433 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434
4435 if (!hdd_ipa_is_enabled(hdd_ctx))
4436 return 0;
4437
4438 schedule_work(&hdd_ipa->pm_work);
4439
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304440 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004441 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304442 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004443
4444 return 0;
4445}
4446
4447/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004448 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4449 * hdd_ctx: Global HDD context
4450 *
4451 * Return: 0 on success, negative errno on error
4452 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004453int hdd_ipa_resume(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004454{
4455 int ret;
4456
4457 cds_ssr_protect(__func__);
4458 ret = __hdd_ipa_resume(hdd_ctx);
4459 cds_ssr_unprotect(__func__);
4460
4461 return ret;
4462}
4463
4464/**
Yun Park52b2b992016-09-22 15:49:51 -07004465 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4466 * @hdd_ipa: Global HDD IPA context
4467 *
4468 * Return: 0 on success, negative errno on error
4469 */
4470static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4471{
4472 int i;
4473 uint32_t max_desc_cnt;
4474 struct hdd_ipa_tx_desc *tmp_desc;
jiad14fe4fb2017-08-08 13:33:14 +08004475 struct ol_txrx_pdev_t *pdev;
Yun Park52b2b992016-09-22 15:49:51 -07004476
jiad14fe4fb2017-08-08 13:33:14 +08004477 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
4478 if (!pdev) {
4479 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "pdev is NULL");
4480 return -ENODEV;
4481 }
4482
4483 hdd_ipa->tx_desc_size = QDF_MIN(
4484 hdd_ipa->hdd_ctx->config->IpaMccTxDescSize,
4485 pdev->tx_desc.pool_size);
Yun Park52b2b992016-09-22 15:49:51 -07004486
4487 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4488
jiad14fe4fb2017-08-08 13:33:14 +08004489 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc) *
4490 hdd_ipa->tx_desc_size);
Yun Park52b2b992016-09-22 15:49:51 -07004491
4492 if (!tmp_desc) {
4493 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4494 "Free Tx descriptor allocation failed");
4495 return -ENOMEM;
4496 }
4497
4498 hdd_ipa->tx_desc_list = tmp_desc;
4499
4500 qdf_spin_lock_bh(&hdd_ipa->q_lock);
jiad14fe4fb2017-08-08 13:33:14 +08004501 for (i = 0; i < hdd_ipa->tx_desc_size; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004502 tmp_desc->id = i;
4503 tmp_desc->ipa_tx_desc_ptr = NULL;
4504 list_add_tail(&tmp_desc->link,
4505 &hdd_ipa->free_tx_desc_head);
4506 tmp_desc++;
4507 }
4508
4509 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4510 hdd_ipa->stats.num_tx_desc_error = 0;
4511
4512 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4513
4514 return 0;
4515}
4516
4517/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004518 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4519 * @hdd_ipa: Global HDD IPA context
4520 *
4521 * Return: 0 on success, negative errno on error
4522 */
4523static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4524{
4525 int i, ret = 0;
4526 struct ipa_sys_connect_params *ipa;
4527 uint32_t desc_fifo_sz;
4528
4529 /* The maximum number of descriptors that can be provided to a BAM at
4530 * once is one less than the total number of descriptors that the buffer
4531 * can contain.
4532 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4533 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4534 * be provided at once.
4535 * Because of above requirement, one extra descriptor will be added to
4536 * make sure hardware always has one descriptor.
4537 */
4538 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4539 + sizeof(struct sps_iovec);
4540
4541 /*setup TX pipes */
4542 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4543 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4544
4545 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4546 ipa->desc_fifo_sz = desc_fifo_sz;
4547 ipa->priv = &hdd_ipa->iface_context[i];
4548 ipa->notify = hdd_ipa_i2w_cb;
4549
4550 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4551 ipa->ipa_ep_cfg.hdr.hdr_len =
4552 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4553 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4554 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4555 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4556 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4557 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4558 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4559 } else {
4560 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4561 }
4562 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4563
4564 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4565 ipa->keep_ipa_awake = 1;
4566
4567 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4568 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004569 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4570 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004571 goto setup_sys_pipe_fail;
4572 }
4573 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4574 }
4575
4576 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4577 /*
4578 * Hard code it here, this can be extended if in case
4579 * PROD pipe is also per interface.
4580 * Right now there is no advantage of doing this.
4581 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004582 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4583
Yun Parkb4f591d2017-03-29 15:51:01 -07004584 ipa->client = IPA_CLIENT_WLAN1_PROD;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004585
4586 ipa->desc_fifo_sz = desc_fifo_sz;
4587 ipa->priv = hdd_ipa;
4588 ipa->notify = hdd_ipa_w2i_cb;
4589
4590 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4591 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4592 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4593 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4594
4595 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4596 ipa->keep_ipa_awake = 1;
4597
4598 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4599 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304600 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004601 "Failed for RX pipe: %d", ret);
4602 goto setup_sys_pipe_fail;
4603 }
4604 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4605 }
4606
jiad14fe4fb2017-08-08 13:33:14 +08004607 /* Allocate free Tx desc list */
Yun Park52b2b992016-09-22 15:49:51 -07004608 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4609 if (ret)
4610 goto setup_sys_pipe_fail;
4611
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004612 return ret;
4613
4614setup_sys_pipe_fail:
4615
4616 while (--i >= 0) {
4617 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304618 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619 sizeof(struct hdd_ipa_sys_pipe));
4620 }
4621
4622 return ret;
4623}
4624
4625/**
4626 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4627 * @hdd_ipa: Global HDD IPA context
4628 *
4629 * Return: None
4630 */
4631static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4632{
4633 int ret = 0, i;
Yun Park52b2b992016-09-22 15:49:51 -07004634 struct hdd_ipa_tx_desc *tmp_desc;
4635 struct ipa_rx_data *ipa_tx_desc;
4636
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004637 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4638 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
Yun Parkb4f591d2017-03-29 15:51:01 -07004639 ret = ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4640 conn_hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004641 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304642 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004643 ret);
4644
4645 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4646 }
4647 }
Yun Park52b2b992016-09-22 15:49:51 -07004648
4649 if (hdd_ipa->tx_desc_list) {
Yun Park52b2b992016-09-22 15:49:51 -07004650 qdf_spin_lock_bh(&hdd_ipa->q_lock);
jiad14fe4fb2017-08-08 13:33:14 +08004651 for (i = 0; i < hdd_ipa->tx_desc_size; i++) {
Yun Park52b2b992016-09-22 15:49:51 -07004652 tmp_desc = hdd_ipa->tx_desc_list + i;
4653 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4654 if (ipa_tx_desc)
4655 ipa_free_skb(ipa_tx_desc);
4656 }
4657 tmp_desc = hdd_ipa->tx_desc_list;
4658 hdd_ipa->tx_desc_list = NULL;
4659 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4660 hdd_ipa->stats.num_tx_desc_error = 0;
4661 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4662 qdf_mem_free(tmp_desc);
4663 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004664}
4665
4666/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004667 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
4668 * @iface_context: interface-specific IPA context
4669 *
4670 * Return: None
4671 */
4672static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
4673{
4674 if (iface_context == NULL)
4675 return;
4676
Yun Parkb4f591d2017-03-29 15:51:01 -07004677 cdp_ipa_cleanup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4678 iface_context->adapter->dev->name,
4679 hdd_ipa_is_ipv6_enabled(iface_context->hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004680
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304681 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682 iface_context->adapter->ipa_context = NULL;
4683 iface_context->adapter = NULL;
4684 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304685 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004686 iface_context->ifa_address = 0;
4687 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304688 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004689 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05304690 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004691 }
4692 iface_context->hdd_ipa->num_iface--;
4693}
4694
4695/**
4696 * hdd_ipa_setup_iface() - Setup IPA on a given interface
4697 * @hdd_ipa: HDD IPA global context
4698 * @adapter: Interface upon which IPA is being setup
4699 * @sta_id: Station ID of the API instance
4700 *
4701 * Return: 0 on success, negative errno value on error
4702 */
4703static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
Jeff Johnson49d45e62017-08-29 14:30:42 -07004704 struct hdd_adapter *adapter, uint8_t sta_id)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004705{
4706 struct hdd_ipa_iface_context *iface_context = NULL;
4707 void *tl_context = NULL;
4708 int i, ret = 0;
4709
4710 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
4711 * channel change indication. Since these indications are sent by lower
4712 * layer as SAP updates and IPA doesn't have to do anything for these
4713 * updates so ignoring!
4714 */
Krunal Sonibe766b02016-03-10 13:00:44 -08004715 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004716 return 0;
4717
4718 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4719 if (hdd_ipa->iface_context[i].adapter == NULL) {
4720 iface_context = &(hdd_ipa->iface_context[i]);
4721 break;
4722 }
4723 }
4724
4725 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304726 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727 "All the IPA interfaces are in use");
4728 ret = -ENOMEM;
4729 goto end;
4730 }
4731
4732 adapter->ipa_context = iface_context;
4733 iface_context->adapter = adapter;
4734 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004735 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07004736 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004737 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304738 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004739 "Not able to get TL context sta_id: %d", sta_id);
4740 ret = -EINVAL;
4741 goto end;
4742 }
4743
4744 iface_context->tl_context = tl_context;
4745
Yun Parkb4f591d2017-03-29 15:51:01 -07004746 ret = cdp_ipa_setup_iface(cds_get_context(QDF_MODULE_ID_SOC),
4747 adapter->dev->name, adapter->dev->dev_addr,
4748 iface_context->prod_client,
4749 iface_context->cons_client,
4750 adapter->sessionId,
4751 hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004752 if (ret)
4753 goto end;
4754
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004755 hdd_ipa->num_iface++;
4756 return ret;
4757
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004758end:
4759 if (iface_context)
4760 hdd_ipa_cleanup_iface(iface_context);
4761 return ret;
4762}
4763
Yun Parka27049a2016-10-11 12:30:49 -07004764#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004765/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004766 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Jeff Johnson4929cd92017-10-06 19:21:57 -07004767 * @hdd_ctx: HDD context
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004768 * @mcc_mode: 0=MCC/1=SCC
4769 *
4770 * Return: 0 on success, negative errno value on error
4771 */
Jeff Johnson4929cd92017-10-06 19:21:57 -07004772static int __hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx,
4773 bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004774{
4775 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304776 QDF_STATUS status;
Jeff Johnson089d0432017-10-02 13:27:21 -07004777 struct hdd_adapter *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004778 struct ipa_msg_meta meta;
4779 struct ipa_wlan_msg *msg;
4780 int ret;
4781
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004782 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004783 return -EINVAL;
4784
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004785 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
4786 return -EINVAL;
4787
4788 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004789 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004790 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304791 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Jeff Johnson089d0432017-10-02 13:27:21 -07004792 adapter = adapter_node->adapter;
4793 if (adapter->device_mode == QDF_STA_MODE ||
4794 adapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004795 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnson089d0432017-10-02 13:27:21 -07004796 adapter->device_mode);
4797 hdd_deinit_tx_rx(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004798 }
4799 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004800 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004801 adapter_node = next;
4802 }
4803 }
4804
4805 /* Send SCC/MCC Switching event to IPA */
4806 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304807 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004808 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004809 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004810 return -ENOMEM;
4811 }
4812
4813 meta.msg_type = mcc_mode ?
4814 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08004815 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004816
4817 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
4818
4819 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08004820 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004821 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304822 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004823 }
4824
4825 return ret;
4826}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004827
4828/**
4829 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
4830 * @mcc_mode: 0=MCC/1=SCC
4831 *
4832 * Return: 0 on success, negative errno value on error
4833 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07004834int hdd_ipa_send_mcc_scc_msg(struct hdd_context *hdd_ctx, bool mcc_mode)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004835{
4836 int ret;
4837
4838 cds_ssr_protect(__func__);
4839 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
4840 cds_ssr_unprotect(__func__);
4841
4842 return ret;
4843}
Yun Parka27049a2016-10-11 12:30:49 -07004844#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004845
4846/**
4847 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
4848 * @event: IPA WLAN event to be converted to a string
4849 *
4850 * Return: ASCII string representing the IPA WLAN event
4851 */
4852static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
4853{
4854 switch (event) {
4855 case WLAN_CLIENT_CONNECT:
4856 return "WLAN_CLIENT_CONNECT";
4857 case WLAN_CLIENT_DISCONNECT:
4858 return "WLAN_CLIENT_DISCONNECT";
4859 case WLAN_CLIENT_POWER_SAVE_MODE:
4860 return "WLAN_CLIENT_POWER_SAVE_MODE";
4861 case WLAN_CLIENT_NORMAL_MODE:
4862 return "WLAN_CLIENT_NORMAL_MODE";
4863 case SW_ROUTING_ENABLE:
4864 return "SW_ROUTING_ENABLE";
4865 case SW_ROUTING_DISABLE:
4866 return "SW_ROUTING_DISABLE";
4867 case WLAN_AP_CONNECT:
4868 return "WLAN_AP_CONNECT";
4869 case WLAN_AP_DISCONNECT:
4870 return "WLAN_AP_DISCONNECT";
4871 case WLAN_STA_CONNECT:
4872 return "WLAN_STA_CONNECT";
4873 case WLAN_STA_DISCONNECT:
4874 return "WLAN_STA_DISCONNECT";
4875 case WLAN_CLIENT_CONNECT_EX:
4876 return "WLAN_CLIENT_CONNECT_EX";
4877
4878 case IPA_WLAN_EVENT_MAX:
4879 default:
4880 return "UNKNOWN";
4881 }
4882}
4883
4884/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07004885 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
4886 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
4887 *
4888 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
4889 */
4890static enum ipa_wlan_event
4891hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
4892{
4893 enum ipa_wlan_event ipa_event;
4894
4895 switch (hdd_ipa_event_type) {
4896 case HDD_IPA_CLIENT_CONNECT:
4897 ipa_event = WLAN_CLIENT_CONNECT;
4898 break;
4899 case HDD_IPA_CLIENT_DISCONNECT:
4900 ipa_event = WLAN_CLIENT_DISCONNECT;
4901 break;
4902 case HDD_IPA_AP_CONNECT:
4903 ipa_event = WLAN_AP_CONNECT;
4904 break;
4905 case HDD_IPA_AP_DISCONNECT:
4906 ipa_event = WLAN_AP_DISCONNECT;
4907 break;
4908 case HDD_IPA_STA_CONNECT:
4909 ipa_event = WLAN_STA_CONNECT;
4910 break;
4911 case HDD_IPA_STA_DISCONNECT:
4912 ipa_event = WLAN_STA_DISCONNECT;
4913 break;
4914 case HDD_IPA_CLIENT_CONNECT_EX:
4915 ipa_event = WLAN_CLIENT_CONNECT_EX;
4916 break;
4917 case HDD_IPA_WLAN_EVENT_MAX:
4918 default:
4919 ipa_event = IPA_WLAN_EVENT_MAX;
4920 break;
4921 }
4922 return ipa_event;
4923
4924}
4925
4926/**
4927 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004928 * @adapter: adapter upon which the event was received
4929 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07004930 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004931 * @mac_address: MAC address associated with the event
4932 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07004933 * This function is meant to be called from within wlan_hdd_ipa.c
4934 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004935 * Return: 0 on success, negative errno value on error
4936 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07004937static int __hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004938 enum ipa_wlan_event type, uint8_t *mac_addr)
4939{
4940 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4941 struct ipa_msg_meta meta;
4942 struct ipa_wlan_msg *msg;
4943 struct ipa_wlan_msg_ex *msg_ex = NULL;
4944 int ret;
4945
Srinivas Girigowda97852372017-03-06 16:52:59 -08004946 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004947 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
4948 mac_addr, sta_id);
4949
4950 if (type >= IPA_WLAN_EVENT_MAX)
4951 return -EINVAL;
4952
4953 if (WARN_ON(is_zero_ether_addr(mac_addr)))
4954 return -EINVAL;
4955
4956 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304957 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004958 return -EINVAL;
4959 }
4960
4961 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
4962 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08004963 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004964 return 0;
4965 }
4966
4967 /*
4968 * During IPA UC resource loading/unloading new events can be issued.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004969 */
Yun Park777d7242017-03-30 15:38:33 -07004970 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
4971 (hdd_ipa->resource_loading || hdd_ipa->resource_unloading)) {
4972 unsigned int pending_event_count;
4973 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08004974
Yun Park777d7242017-03-30 15:38:33 -07004975 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4976 "%s:IPA resource %s inprogress",
4977 hdd_ipa_wlan_event_to_str(type),
4978 hdd_ipa->resource_loading ?
4979 "load" : "unload");
4980
4981 /* Wait until completion of the long/unloading */
4982 ret = wait_for_completion_timeout(&hdd_ipa->ipa_resource_comp,
4983 msecs_to_jiffies(IPA_RESOURCE_COMP_WAIT_TIME));
4984 if (!ret) {
4985 /*
4986 * If timed out, store the events separately and
4987 * handle them later.
4988 */
Yun Park64c405e2017-01-10 22:35:51 -08004989 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park777d7242017-03-30 15:38:33 -07004990 "IPA resource %s timed out",
4991 hdd_ipa->resource_loading ?
4992 "load" : "unload");
Yun Park7c4f31b2016-11-30 10:09:21 -08004993
Yun Park777d7242017-03-30 15:38:33 -07004994 if (hdd_ipa->resource_loading) {
4995 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08004996
Yun Park777d7242017-03-30 15:38:33 -07004997 pending_event_count =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004998 qdf_list_size(&hdd_ipa->pending_event);
Yun Park777d7242017-03-30 15:38:33 -07004999 if (pending_event_count >=
5000 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
5001 hdd_debug(
5002 "Reached max pending event count");
5003 qdf_list_remove_front(
5004 &hdd_ipa->pending_event,
5005 (qdf_list_node_t **)&pending_event);
5006 } else {
5007 pending_event =
5008 (struct ipa_uc_pending_event *)
5009 qdf_mem_malloc(sizeof(
5010 struct ipa_uc_pending_event));
5011 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005012
Yun Park777d7242017-03-30 15:38:33 -07005013 if (!pending_event) {
5014 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5015 "Pending event memory alloc fail");
5016 qdf_mutex_release(&hdd_ipa->ipa_lock);
5017 return -ENOMEM;
5018 }
5019
5020 pending_event->adapter = adapter;
5021 pending_event->sta_id = sta_id;
5022 pending_event->type = type;
5023 qdf_mem_copy(pending_event->mac_addr,
5024 mac_addr, QDF_MAC_ADDR_SIZE);
5025 qdf_list_insert_back(&hdd_ipa->pending_event,
5026 &pending_event->node);
5027
Yun Park64c405e2017-01-10 22:35:51 -08005028 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005029 }
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005030 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005031 }
Jeff Johnson4929cd92017-10-06 19:21:57 -07005032 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5033 "IPA resource %s completed",
5034 hdd_ipa->resource_loading ?
5035 "load" : "unload");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005036 }
5037
5038 hdd_ipa->stats.event[type]++;
5039
Leo Chang3bc8fed2015-11-13 10:59:47 -08005040 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005041 switch (type) {
5042 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005043 qdf_mutex_acquire(&hdd_ipa->event_lock);
5044
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005045 /* STA already connected and without disconnect, connect again
5046 * This is Roaming scenario
5047 */
5048 if (hdd_ipa->sta_connected)
5049 hdd_ipa_cleanup_iface(adapter->ipa_context);
5050
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005051 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5052 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305053 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005054 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005055 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005056
Yun Park8f289c82016-10-18 16:38:21 -07005057 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5058 (hdd_ipa->sap_num_connected_sta > 0) &&
5059 !hdd_ipa->sta_connected) {
5060 qdf_mutex_release(&hdd_ipa->event_lock);
5061 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005062 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005063 qdf_mutex_acquire(&hdd_ipa->event_lock);
5064 }
5065
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005066 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005067 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005068 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005070 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005071
5072 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 break;
5074
5075 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005076 qdf_mutex_acquire(&hdd_ipa->event_lock);
5077
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005078 /* For DFS channel we get two start_bss event (before and after
5079 * CAC). Also when ACS range includes both DFS and non DFS
5080 * channels, we could possibly change channel many times due to
5081 * RADAR detection and chosen channel may not be a DFS channels.
5082 * So dont return error here. Just discard the event.
5083 */
Yun Park8f289c82016-10-18 16:38:21 -07005084 if (adapter->ipa_context) {
5085 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005086 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005087 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005088
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005089 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5090 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005091 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005092 hdd_err("%s: Evt: %d, Interface setup failed",
5093 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005095 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005096
Yun Park8f289c82016-10-18 16:38:21 -07005097 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5098 qdf_mutex_release(&hdd_ipa->event_lock);
5099 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005100 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005101 qdf_mutex_acquire(&hdd_ipa->event_lock);
5102 }
5103
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005104 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005105 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005106 (adapter->ipa_context))->iface_id;
5107
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305108 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005109 break;
5110
5111 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305112 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005113
5114 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005115 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005116 hdd_err("%s: Evt: %d, STA already disconnected",
5117 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005118 return -EINVAL;
5119 }
Yun Parka37592b2016-06-11 17:10:28 -07005120
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005121 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005122
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005123 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005124 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005125 msg_ex->name);
5126 } else {
5127 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005128 if (!hdd_ipa->num_iface &&
5129 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305130 hdd_ipa->activated_fw_pipe) &&
5131 !hdd_ipa->ipa_pipes_down)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005132 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005133 }
5134
Yun Park74127cf2016-09-18 11:22:41 -07005135 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5136 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005137 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005138 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005139 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005140 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005141 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5142 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005143 }
5144
Yun Park8f289c82016-10-18 16:38:21 -07005145 hdd_ipa_cleanup_iface(adapter->ipa_context);
5146
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305147 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005148 break;
5149
5150 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005151 qdf_mutex_acquire(&hdd_ipa->event_lock);
5152
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005153 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005154 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005155 hdd_err("%s: Evt: %d, SAP already disconnected",
5156 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005157 return -EINVAL;
5158 }
5159
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160 if ((!hdd_ipa->num_iface) &&
5161 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305162 hdd_ipa->activated_fw_pipe) &&
5163 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005164 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005165 /*
5166 * We disable WDI pipes directly here since
5167 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5168 * processed when unloading WLAN driver is in
5169 * progress
5170 */
5171 hdd_ipa_uc_disable_pipes(hdd_ipa);
5172 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305173 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005174 "NO INTF left but still pipe clean up");
5175 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5176 }
5177 }
5178
5179 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005180 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005181 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005182 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005183 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005184 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5185 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005186 }
Yun Parka37592b2016-06-11 17:10:28 -07005187
Yun Park8f289c82016-10-18 16:38:21 -07005188 hdd_ipa_cleanup_iface(adapter->ipa_context);
5189
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305190 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005191 break;
5192
5193 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005194 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005195 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005196 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305197 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005198 return 0;
5199 }
5200
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305201 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005202 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5203 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005204 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305205 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005206 "%s: STA ID %d found, not valid",
5207 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005208 return 0;
5209 }
Yun Park312f71a2015-12-08 10:22:42 -08005210
5211 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005212 if (hdd_ipa->sap_num_connected_sta == 0 &&
5213 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005214 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005215 hdd_ipa->sta_connected) {
5216 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005217 hdd_ipa_uc_offload_enable_disable(
5218 hdd_get_adapter(hdd_ipa->hdd_ctx,
5219 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005220 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005221 qdf_mutex_acquire(&hdd_ipa->event_lock);
5222 }
Yun Parka37592b2016-06-11 17:10:28 -07005223
Yun Park312f71a2015-12-08 10:22:42 -08005224 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5225 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305226 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005227 "%s: handle 1st con ret %d",
5228 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005229
5230 if (hdd_ipa_uc_sta_is_enabled(
5231 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005232 hdd_ipa->sta_connected) {
5233 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005234 hdd_ipa_uc_offload_enable_disable(
5235 hdd_get_adapter(
5236 hdd_ipa->hdd_ctx,
5237 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005238 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005239 } else {
5240 qdf_mutex_release(&hdd_ipa->event_lock);
5241 }
Yun Parka37592b2016-06-11 17:10:28 -07005242
Yun Park312f71a2015-12-08 10:22:42 -08005243 return ret;
5244 }
5245 }
5246
5247 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005248
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305249 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005250
5251 meta.msg_type = type;
5252 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5253 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305254 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005255
5256 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305257 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005258 "msg_ex allocation failed");
5259 return -ENOMEM;
5260 }
5261 strlcpy(msg_ex->name, adapter->dev->name,
5262 IPA_RESOURCE_NAME_MAX);
5263 msg_ex->num_of_attribs = 1;
5264 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5265 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5266 msg_ex->attribs[0].offset =
5267 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5268 } else {
5269 msg_ex->attribs[0].offset =
5270 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5271 }
5272 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5273 IPA_MAC_ADDR_SIZE);
5274
5275 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5276
5277 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005278 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305279 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305280 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005281 return ret;
5282 }
5283 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 return ret;
5285
5286 case WLAN_CLIENT_DISCONNECT:
5287 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005288 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005289 "%s: IPA UC OFFLOAD NOT ENABLED",
5290 msg_ex->name);
5291 return 0;
5292 }
5293
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305294 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005295 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005296 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305297 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005298 "%s: STA ID %d NOT found, not valid",
5299 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005300 return 0;
5301 }
5302 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005303
Yun Park9b5030f2016-11-08 12:02:37 -08005304 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005305 if (!hdd_ipa->sap_num_connected_sta &&
5306 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005307 if ((false == hdd_ipa->resource_unloading)
5308 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305309 hdd_ipa->activated_fw_pipe) &&
5310 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005311 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5312 }
5313
Yun Park9b5030f2016-11-08 12:02:37 -08005314 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jiad9d472c92017-07-28 14:05:31 +08005315 hdd_ipa->sta_connected) {
5316 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005317 hdd_ipa_uc_offload_enable_disable(
5318 hdd_get_adapter(hdd_ipa->hdd_ctx,
5319 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005320 SIR_STA_RX_DATA_OFFLOAD, false);
jiad9d472c92017-07-28 14:05:31 +08005321 } else {
5322 qdf_mutex_release(&hdd_ipa->event_lock);
5323 }
Yun Park8f289c82016-10-18 16:38:21 -07005324 } else {
5325 qdf_mutex_release(&hdd_ipa->event_lock);
5326 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005327 break;
5328
5329 default:
5330 return 0;
5331 }
5332
5333 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305334 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005335 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305336 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005337 return -ENOMEM;
5338 }
5339
5340 meta.msg_type = type;
5341 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5342 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5343
Srinivas Girigowda97852372017-03-06 16:52:59 -08005344 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005345 msg->name, meta.msg_type);
5346
5347 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5348
5349 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005350 hdd_err("%s: Evt: %d fail:%d",
5351 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305352 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005353 return ret;
5354 }
5355
5356 hdd_ipa->stats.num_send_msg++;
5357
5358end:
5359 return ret;
5360}
5361
5362/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005363 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005364 * @adapter: adapter upon which the event was received
5365 * @sta_id: station id for the event
5366 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5367 * @mac_address: MAC address associated with the event
5368 *
5369 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5370 *
5371 * Return: 0 on success, negative errno value on error
5372 */
Jeff Johnson49d45e62017-08-29 14:30:42 -07005373int hdd_ipa_wlan_evt(struct hdd_adapter *adapter, uint8_t sta_id,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005374 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5375{
5376 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005377 int ret = 0;
5378
5379 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005380
Leo Changa202b522016-10-14 16:13:50 -07005381 /* Data path offload only support for STA and SAP mode */
5382 if ((QDF_STA_MODE == adapter->device_mode) ||
5383 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005384 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005385
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005386 cds_ssr_unprotect(__func__);
5387
5388 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005389}
5390
5391/**
5392 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5393 * @hdd_ipa: Global HDD IPA context
5394 *
5395 * Return: None
5396 */
5397static void
5398hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5399{
5400 unsigned int pending_event_count;
5401 struct ipa_uc_pending_event *pending_event = NULL;
5402
5403 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08005404 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005405 "%s, Pending Event Count %d", __func__, pending_event_count);
5406 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005407 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07005408 "%s, No Pending Event", __func__);
5409 return;
5410 }
5411
5412 qdf_list_remove_front(&hdd_ipa->pending_event,
5413 (qdf_list_node_t **)&pending_event);
5414 while (pending_event != NULL) {
5415 __hdd_ipa_wlan_evt(pending_event->adapter,
5416 pending_event->type,
5417 pending_event->sta_id,
5418 pending_event->mac_addr);
5419 qdf_mem_free(pending_event);
5420 pending_event = NULL;
5421 qdf_list_remove_front(&hdd_ipa->pending_event,
5422 (qdf_list_node_t **)&pending_event);
5423 }
5424}
5425
5426/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005427 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
5428 * @state: IPA RM state value
5429 *
5430 * Return: ASCII string representing the IPA RM state
5431 */
5432static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
5433{
5434 switch (state) {
5435 case HDD_IPA_RM_RELEASED:
5436 return "RELEASED";
5437 case HDD_IPA_RM_GRANT_PENDING:
5438 return "GRANT_PENDING";
5439 case HDD_IPA_RM_GRANTED:
5440 return "GRANTED";
5441 }
5442
5443 return "UNKNOWN";
5444}
5445
5446/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005447 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005448 * @hdd_ctx: HDD global context
5449 *
5450 * Allocate hdd_ipa resources, ipa pipe resource and register
5451 * wlan interface with IPA module.
5452 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305453 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005454 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005455static QDF_STATUS __hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005456{
5457 struct hdd_ipa_priv *hdd_ipa = NULL;
5458 int ret, i;
5459 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08005460 struct ol_txrx_pdev_t *pdev = NULL;
Yun Park66f24c42017-03-20 10:39:47 -07005461 struct ipa_rm_perf_profile profile;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005462
5463 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305464 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005465
Yun Parkbaa62862017-01-18 13:43:34 -08005466 ENTER();
5467
5468 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07005469 if (!pdev) {
5470 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
5471 goto fail_return;
5472 }
5473
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305474 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005475 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305476 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08005477 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005478 }
5479
5480 hdd_ctx->hdd_ipa = hdd_ipa;
5481 ghdd_ipa = hdd_ipa;
5482 hdd_ipa->hdd_ctx = hdd_ctx;
5483 hdd_ipa->num_iface = 0;
5484
5485 /* Create the interface context */
5486 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5487 iface_context = &hdd_ipa->iface_context[i];
5488 iface_context->hdd_ipa = hdd_ipa;
5489 iface_context->cons_client =
5490 hdd_ipa_adapter_2_client[i].cons_client;
5491 iface_context->prod_client =
5492 hdd_ipa_adapter_2_client[i].prod_client;
5493 iface_context->iface_id = i;
5494 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305495 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005496 }
5497 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005498 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
5499 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005500 }
5501
Leo Chang69c39692016-10-12 20:11:12 -07005502 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305503 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005504 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05305505 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005506 qdf_list_create(&hdd_ipa->pending_event, 1000);
5507 qdf_mutex_create(&hdd_ipa->event_lock);
5508 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005509
5510 ret = hdd_ipa_setup_rm(hdd_ipa);
5511 if (ret)
5512 goto fail_setup_rm;
5513
5514 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5515 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305516 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005517 hdd_ipa->sap_num_connected_sta = 0;
5518 hdd_ipa->ipa_tx_packets_diff = 0;
5519 hdd_ipa->ipa_rx_packets_diff = 0;
5520 hdd_ipa->ipa_p_tx_packets = 0;
5521 hdd_ipa->ipa_p_rx_packets = 0;
5522 hdd_ipa->resource_loading = false;
5523 hdd_ipa->resource_unloading = false;
5524 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07005525 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08005526 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005527 /* Setup IPA sys_pipe for MCC */
5528 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
5529 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5530 if (ret)
5531 goto fail_create_sys_pipe;
5532 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005533 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
5534 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08005535
5536 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5537 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
5538 hdd_ipa_uc_fw_op_event_handler);
5539 hdd_ipa->uc_op_work[i].msg = NULL;
5540 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005541 } else {
5542 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
5543 if (ret)
5544 goto fail_create_sys_pipe;
5545 }
5546
Yun Park66f24c42017-03-20 10:39:47 -07005547 /* When IPA clock scaling is disabled, initialze maximum clock */
5548 if (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)) {
5549 profile.max_supported_bandwidth_mbps = 800;
5550 hdd_debug("IPA clock scaling is disabled.");
5551 hdd_debug("Set initial CONS/PROD perf: %d",
5552 profile.max_supported_bandwidth_mbps);
5553 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
5554 &profile);
5555 if (ret) {
5556 hdd_err("RM CONS set perf profile failed: %d", ret);
5557 goto fail_create_sys_pipe;
5558 }
5559
5560 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
5561 &profile);
5562 if (ret) {
5563 hdd_err("RM PROD set perf profile failed: %d", ret);
5564 goto fail_create_sys_pipe;
5565 }
5566 }
5567
Yun Park777d7242017-03-30 15:38:33 -07005568 init_completion(&hdd_ipa->ipa_resource_comp);
5569
Yun Parkbaa62862017-01-18 13:43:34 -08005570 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305571 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005572
5573fail_create_sys_pipe:
5574 hdd_ipa_destroy_rm_resource(hdd_ipa);
5575fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305576 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305577 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08005578 hdd_ctx->hdd_ipa = NULL;
5579 ghdd_ipa = NULL;
5580fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08005581 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305582 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005583}
5584
5585/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005586 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
5587 * @hdd_ctx: HDD global context
5588 *
5589 * Allocate hdd_ipa resources, ipa pipe resource and register
5590 * wlan interface with IPA module.
5591 *
5592 * Return: QDF_STATUS enumeration
5593 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005594QDF_STATUS hdd_ipa_init(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005595{
5596 QDF_STATUS ret;
5597
5598 cds_ssr_protect(__func__);
5599 ret = __hdd_ipa_init(hdd_ctx);
5600 cds_ssr_unprotect(__func__);
5601
5602 return ret;
5603}
5604
Arun Khandavallicc544b32017-01-30 19:52:16 +05305605
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005606/**
Yun Parkf19e07d2015-11-20 11:34:27 -08005607 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
5608 * @hdd_ipa: pointer to HDD IPA struct
5609 *
5610 * Return: none
5611 */
Jeff Johnsond7720632016-10-05 16:04:32 -07005612static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08005613{
5614 struct ipa_uc_pending_event *pending_event = NULL;
5615
Anurag Chouhanffb21542016-02-17 14:33:03 +05305616 while (qdf_list_remove_front(&hdd_ipa->pending_event,
5617 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305618 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005619 }
5620
Anurag Chouhanffb21542016-02-17 14:33:03 +05305621 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08005622}
5623
5624/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305625 * __hdd_ipa_flush - flush IPA exception path SKB's
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005626 * @hdd_ctx: HDD global context
5627 *
Govind Singh1dab23b2017-08-12 13:31:00 +05305628 * Return: none
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005629 */
Govind Singh1dab23b2017-08-12 13:31:00 +05305630static void __hdd_ipa_flush(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005631{
5632 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
Nirav Shahcbc6d722016-03-01 16:24:53 +05305633 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005634 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
5635
5636 if (!hdd_ipa_is_enabled(hdd_ctx))
Govind Singh1dab23b2017-08-12 13:31:00 +05305637 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005638
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305641 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005642
Nirav Shahcbc6d722016-03-01 16:24:53 +05305643 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
5644 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305645 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005646
5647 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Yun Parked827b42017-05-12 23:59:27 -07005648 if (pm_tx_cb->ipa_tx_desc)
5649 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005650
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305651 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005652 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305653 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Govind Singh1dab23b2017-08-12 13:31:00 +05305654}
5655
5656/**
5657 * __hdd_ipa_cleanup - IPA cleanup function
5658 * @hdd_ctx: HDD global context
5659 *
5660 * Return: QDF_STATUS enumeration
5661 */
5662static QDF_STATUS __hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
5663{
5664 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
5665 int i;
5666 struct hdd_ipa_iface_context *iface_context = NULL;
5667
5668 if (!hdd_ipa_is_enabled(hdd_ctx))
5669 return QDF_STATUS_SUCCESS;
5670
5671 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
5672 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
5673 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5674 }
5675
5676 /* Teardown IPA sys_pipe for MCC */
5677 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
5678 hdd_ipa_teardown_sys_pipe(hdd_ipa);
5679
5680 hdd_ipa_destroy_rm_resource(hdd_ipa);
5681
5682 __hdd_ipa_flush(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005683
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305684 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07005685 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005686
5687 /* destory the interface lock */
5688 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5689 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305690 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691 }
5692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08005694 if (ipa_uc_dereg_rdyCB())
5695 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5696 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305698 qdf_mutex_destroy(&hdd_ipa->event_lock);
5699 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005700 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005701
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005702 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
5703 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
5704 hdd_ipa->uc_op_work[i].msg = NULL;
5705 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005706 }
5707
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305708 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709 hdd_ctx->hdd_ipa = NULL;
5710
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305711 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005712}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005713
5714/**
Govind Singh1dab23b2017-08-12 13:31:00 +05305715 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_flush
5716 * @hdd_ctx: HDD global context
5717 *
5718 * Return: None
5719 */
5720void hdd_ipa_flush(struct hdd_context *hdd_ctx)
5721{
5722 cds_ssr_protect(__func__);
5723 __hdd_ipa_flush(hdd_ctx);
5724 cds_ssr_unprotect(__func__);
5725}
5726
5727/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005728 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
5729 * @hdd_ctx: HDD global context
5730 *
5731 * Return: QDF_STATUS enumeration
5732 */
Jeff Johnsondd595cb2017-08-28 11:58:09 -07005733QDF_STATUS hdd_ipa_cleanup(struct hdd_context *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005734{
5735 QDF_STATUS ret;
5736
5737 cds_ssr_protect(__func__);
5738 ret = __hdd_ipa_cleanup(hdd_ctx);
5739 cds_ssr_unprotect(__func__);
5740
5741 return ret;
5742}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005743#endif /* IPA_OFFLOAD */