blob: e34b5d6ccc2b7588b69e6e2c01b7b7467ba97a82 [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 */
Mohit Khannafa99aea2016-05-12 21:43:13 -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"
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080061#include <cdp_txrx_handle.h>
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -080062#include "wlan_policy_mgr_api.h"
63
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064#define HDD_IPA_DESC_BUFFER_RATIO 4
65#define HDD_IPA_IPV4_NAME_EXT "_ipv4"
66#define HDD_IPA_IPV6_NAME_EXT "_ipv6"
67
68#define HDD_IPA_RX_INACTIVITY_MSEC_DELAY 1000
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080069#define HDD_IPA_UC_WLAN_8023_HDR_SIZE 14
70/* WDI TX and RX PIPE */
71#define HDD_IPA_UC_NUM_WDI_PIPE 2
72#define HDD_IPA_UC_MAX_PENDING_EVENT 33
73
74#define HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE 32000
75#define HDD_IPA_UC_RT_DEBUG_PERIOD 300
76#define HDD_IPA_UC_RT_DEBUG_BUF_COUNT 30
77#define HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL 10000
78
79#define HDD_IPA_WLAN_HDR_DES_MAC_OFFSET 0
80#define HDD_IPA_MAX_IFACE 3
81#define HDD_IPA_MAX_SYSBAM_PIPE 4
82#define HDD_IPA_RX_PIPE HDD_IPA_MAX_IFACE
83#define HDD_IPA_ENABLE_MASK BIT(0)
84#define HDD_IPA_PRE_FILTER_ENABLE_MASK BIT(1)
85#define HDD_IPA_IPV6_ENABLE_MASK BIT(2)
86#define HDD_IPA_RM_ENABLE_MASK BIT(3)
87#define HDD_IPA_CLK_SCALING_ENABLE_MASK BIT(4)
88#define HDD_IPA_UC_ENABLE_MASK BIT(5)
89#define HDD_IPA_UC_STA_ENABLE_MASK BIT(6)
90#define HDD_IPA_REAL_TIME_DEBUGGING BIT(8)
91
Yun Parkf19e07d2015-11-20 11:34:27 -080092#define HDD_IPA_MAX_PENDING_EVENT_COUNT 20
93
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -070094enum hdd_ipa_uc_op_code {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080095 HDD_IPA_UC_OPCODE_TX_SUSPEND = 0,
96 HDD_IPA_UC_OPCODE_TX_RESUME = 1,
97 HDD_IPA_UC_OPCODE_RX_SUSPEND = 2,
98 HDD_IPA_UC_OPCODE_RX_RESUME = 3,
99 HDD_IPA_UC_OPCODE_STATS = 4,
Yun Park637d6482016-10-05 10:51:33 -0700100#ifdef FEATURE_METERING
101 HDD_IPA_UC_OPCODE_SHARING_STATS = 5,
102 HDD_IPA_UC_OPCODE_QUOTA_RSP = 6,
103 HDD_IPA_UC_OPCODE_QUOTA_IND = 7,
104#endif
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800105 HDD_IPA_UC_OPCODE_UC_READY = 8,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800106 /* keep this last */
107 HDD_IPA_UC_OPCODE_MAX
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700108};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800109
110/**
111 * enum - Reason codes for stat query
112 *
113 * @HDD_IPA_UC_STAT_REASON_NONE: Initial value
114 * @HDD_IPA_UC_STAT_REASON_DEBUG: For debug/info
115 * @HDD_IPA_UC_STAT_REASON_BW_CAL: For bandwidth calibration
Yun Parkb187d542016-11-14 18:10:04 -0800116 * @HDD_IPA_UC_STAT_REASON_DUMP_INFO: For debug info dump
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800117 */
118enum {
119 HDD_IPA_UC_STAT_REASON_NONE,
120 HDD_IPA_UC_STAT_REASON_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -0800121 HDD_IPA_UC_STAT_REASON_BW_CAL,
122 HDD_IPA_UC_STAT_REASON_DUMP_INFO
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800123};
124
125/**
126 * enum hdd_ipa_rm_state - IPA resource manager state
127 * @HDD_IPA_RM_RELEASED: PROD pipe resource released
128 * @HDD_IPA_RM_GRANT_PENDING: PROD pipe resource requested but not granted yet
129 * @HDD_IPA_RM_GRANTED: PROD pipe resource granted
130 */
131enum hdd_ipa_rm_state {
132 HDD_IPA_RM_RELEASED,
133 HDD_IPA_RM_GRANT_PENDING,
134 HDD_IPA_RM_GRANTED,
135};
136
137struct llc_snap_hdr {
138 uint8_t dsap;
139 uint8_t ssap;
140 uint8_t resv[4];
141 __be16 eth_type;
142} __packed;
143
Leo Chang3bc8fed2015-11-13 10:59:47 -0800144/**
145 * struct hdd_ipa_tx_hdr - header type which IPA should handle to TX packet
146 * @eth: ether II header
147 * @llc_snap: LLC snap header
148 *
149 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800150struct hdd_ipa_tx_hdr {
151 struct ethhdr eth;
152 struct llc_snap_hdr llc_snap;
153} __packed;
154
Leo Chang3bc8fed2015-11-13 10:59:47 -0800155/**
156 * struct frag_header - fragment header type registered to IPA hardware
157 * @length: fragment length
158 * @reserved1: Reserved not used
159 * @reserved2: Reserved not used
160 *
161 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800162struct frag_header {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800163 uint16_t length;
164 uint32_t reserved1;
165 uint32_t reserved2;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800166} __packed;
167
Leo Chang3bc8fed2015-11-13 10:59:47 -0800168/**
169 * struct ipa_header - ipa header type registered to IPA hardware
170 * @vdev_id: vdev id
171 * @reserved: Reserved not used
172 *
173 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800174struct ipa_header {
175 uint32_t
176 vdev_id:8, /* vdev_id field is LSB of IPA DESC */
177 reserved:24;
178} __packed;
179
Leo Chang3bc8fed2015-11-13 10:59:47 -0800180/**
181 * struct hdd_ipa_uc_tx_hdr - full tx header registered to IPA hardware
182 * @frag_hd: fragment header
183 * @ipa_hd: ipa header
184 * @eth: ether II header
185 *
186 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800187struct hdd_ipa_uc_tx_hdr {
188 struct frag_header frag_hd;
189 struct ipa_header ipa_hd;
190 struct ethhdr eth;
191} __packed;
192
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800193/**
194 * struct hdd_ipa_cld_hdr - IPA CLD Header
195 * @reserved: reserved fields
196 * @iface_id: interface ID
197 * @sta_id: Station ID
198 *
199 * Packed 32-bit structure
200 * +----------+----------+--------------+--------+
201 * | Reserved | QCMAP ID | interface id | STA ID |
202 * +----------+----------+--------------+--------+
203 */
204struct hdd_ipa_cld_hdr {
205 uint8_t reserved[2];
206 uint8_t iface_id;
207 uint8_t sta_id;
208} __packed;
209
210struct hdd_ipa_rx_hdr {
211 struct hdd_ipa_cld_hdr cld_hdr;
212 struct ethhdr eth;
213} __packed;
214
215struct hdd_ipa_pm_tx_cb {
Leo Chang69c39692016-10-12 20:11:12 -0700216 bool exception;
217 hdd_adapter_t *adapter;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800218 struct hdd_ipa_iface_context *iface_context;
219 struct ipa_rx_data *ipa_tx_desc;
220};
221
222struct hdd_ipa_uc_rx_hdr {
223 struct ethhdr eth;
224} __packed;
225
226struct hdd_ipa_sys_pipe {
227 uint32_t conn_hdl;
228 uint8_t conn_hdl_valid;
229 struct ipa_sys_connect_params ipa_sys_params;
230};
231
232struct hdd_ipa_iface_stats {
233 uint64_t num_tx;
234 uint64_t num_tx_drop;
235 uint64_t num_tx_err;
236 uint64_t num_tx_cac_drop;
237 uint64_t num_rx_prefilter;
238 uint64_t num_rx_ipa_excep;
239 uint64_t num_rx_recv;
240 uint64_t num_rx_recv_mul;
241 uint64_t num_rx_send_desc_err;
242 uint64_t max_rx_mul;
243};
244
245struct hdd_ipa_priv;
246
247struct hdd_ipa_iface_context {
248 struct hdd_ipa_priv *hdd_ipa;
249 hdd_adapter_t *adapter;
250 void *tl_context;
251
252 enum ipa_client_type cons_client;
253 enum ipa_client_type prod_client;
254
255 uint8_t iface_id; /* This iface ID */
256 uint8_t sta_id; /* This iface station ID */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530257 qdf_spinlock_t interface_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800258 uint32_t ifa_address;
259 struct hdd_ipa_iface_stats stats;
260};
261
262struct hdd_ipa_stats {
263 uint32_t event[IPA_WLAN_EVENT_MAX];
264 uint64_t num_send_msg;
265 uint64_t num_free_msg;
266
267 uint64_t num_rm_grant;
268 uint64_t num_rm_release;
269 uint64_t num_rm_grant_imm;
270 uint64_t num_cons_perf_req;
271 uint64_t num_prod_perf_req;
272
273 uint64_t num_rx_drop;
274 uint64_t num_rx_ipa_tx_dp;
275 uint64_t num_rx_ipa_splice;
276 uint64_t num_rx_ipa_loop;
277 uint64_t num_rx_ipa_tx_dp_err;
278 uint64_t num_rx_ipa_write_done;
279 uint64_t num_max_ipa_tx_mul;
280 uint64_t num_rx_ipa_hw_maxed_out;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800281
Yun Park52b2b992016-09-22 15:49:51 -0700282 uint64_t num_tx_desc_q_cnt;
283 uint64_t num_tx_desc_error;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800284 uint64_t num_tx_comp_cnt;
285 uint64_t num_tx_queued;
286 uint64_t num_tx_dequeued;
287 uint64_t num_max_pm_queue;
288
289 uint64_t num_freeq_empty;
290 uint64_t num_pri_freeq_empty;
291 uint64_t num_rx_excep;
Yun Parkb187d542016-11-14 18:10:04 -0800292 uint64_t num_tx_fwd_ok;
293 uint64_t num_tx_fwd_err;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800294};
295
296struct ipa_uc_stas_map {
297 bool is_reserved;
298 uint8_t sta_id;
299};
300struct op_msg_type {
301 uint8_t msg_t;
302 uint8_t rsvd;
303 uint16_t op_code;
304 uint16_t len;
305 uint16_t rsvd_snd;
306};
307
308struct ipa_uc_fw_stats {
309 uint32_t tx_comp_ring_base;
310 uint32_t tx_comp_ring_size;
311 uint32_t tx_comp_ring_dbell_addr;
312 uint32_t tx_comp_ring_dbell_ind_val;
313 uint32_t tx_comp_ring_dbell_cached_val;
314 uint32_t tx_pkts_enqueued;
315 uint32_t tx_pkts_completed;
316 uint32_t tx_is_suspend;
317 uint32_t tx_reserved;
318 uint32_t rx_ind_ring_base;
319 uint32_t rx_ind_ring_size;
320 uint32_t rx_ind_ring_dbell_addr;
321 uint32_t rx_ind_ring_dbell_ind_val;
322 uint32_t rx_ind_ring_dbell_ind_cached_val;
323 uint32_t rx_ind_ring_rdidx_addr;
324 uint32_t rx_ind_ring_rd_idx_cached_val;
325 uint32_t rx_refill_idx;
326 uint32_t rx_num_pkts_indicated;
327 uint32_t rx_buf_refilled;
328 uint32_t rx_num_ind_drop_no_space;
329 uint32_t rx_num_ind_drop_no_buf;
330 uint32_t rx_is_suspend;
331 uint32_t rx_reserved;
332};
333
334struct ipa_uc_pending_event {
Anurag Chouhanffb21542016-02-17 14:33:03 +0530335 qdf_list_node_t node;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800336 hdd_adapter_t *adapter;
337 enum ipa_wlan_event type;
338 uint8_t sta_id;
Anurag Chouhan6d760662016-02-20 16:05:43 +0530339 uint8_t mac_addr[QDF_MAC_ADDR_SIZE];
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800340};
341
342/**
343 * struct uc_rm_work_struct
344 * @work: uC RM work
345 * @event: IPA RM event
346 */
347struct uc_rm_work_struct {
348 struct work_struct work;
349 enum ipa_rm_event event;
350};
351
352/**
353 * struct uc_op_work_struct
354 * @work: uC OP work
355 * @msg: OP message
356 */
357struct uc_op_work_struct {
358 struct work_struct work;
359 struct op_msg_type *msg;
360};
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800361
362/**
363 * struct uc_rt_debug_info
364 * @time: system time
365 * @ipa_excep_count: IPA exception packet count
366 * @rx_drop_count: IPA Rx drop packet count
367 * @net_sent_count: IPA Rx packet sent to network stack count
368 * @rx_discard_count: IPA Rx discard packet count
Yun Parkb187d542016-11-14 18:10:04 -0800369 * @tx_fwd_ok_count: IPA Tx forward success packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800370 * @tx_fwd_count: IPA Tx forward packet count
371 * @rx_destructor_call: IPA Rx packet destructor count
372 */
373struct uc_rt_debug_info {
Deepthi Gowri6acee342016-10-28 15:00:38 +0530374 uint64_t time;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800375 uint64_t ipa_excep_count;
376 uint64_t rx_drop_count;
377 uint64_t net_sent_count;
378 uint64_t rx_discard_count;
Yun Parkb187d542016-11-14 18:10:04 -0800379 uint64_t tx_fwd_ok_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800380 uint64_t tx_fwd_count;
381 uint64_t rx_destructor_call;
382};
383
Yun Park637d6482016-10-05 10:51:33 -0700384#ifdef FEATURE_METERING
385struct ipa_uc_sharing_stats {
386 uint64_t ipv4_rx_packets;
387 uint64_t ipv4_rx_bytes;
388 uint64_t ipv6_rx_packets;
389 uint64_t ipv6_rx_bytes;
390 uint64_t ipv4_tx_packets;
391 uint64_t ipv4_tx_bytes;
392 uint64_t ipv6_tx_packets;
393 uint64_t ipv6_tx_bytes;
394};
395
396struct ipa_uc_quota_rsp {
397 uint8_t success;
398 uint8_t reserved[3];
399 uint32_t quota_lo; /* quota limit low bytes */
400 uint32_t quota_hi; /* quota limit high bytes */
401};
402
403struct ipa_uc_quota_ind {
404 uint64_t quota_bytes; /* quota limit in bytes */
405};
406#endif
407
Yun Park52b2b992016-09-22 15:49:51 -0700408/**
409 * struct hdd_ipa_tx_desc
410 * @link: link to list head
411 * @priv: pointer to priv list entry
412 * @id: Tx desc idex
413 * @ipa_tx_desc_ptr: pointer to IPA Tx descriptor
414 */
415struct hdd_ipa_tx_desc {
416 struct list_head link;
417 void *priv;
418 uint32_t id;
419 struct ipa_rx_data *ipa_tx_desc_ptr;
420};
421
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800422struct hdd_ipa_priv {
423 struct hdd_ipa_sys_pipe sys_pipe[HDD_IPA_MAX_SYSBAM_PIPE];
424 struct hdd_ipa_iface_context iface_context[HDD_IPA_MAX_IFACE];
425 uint8_t num_iface;
426 enum hdd_ipa_rm_state rm_state;
427 /*
Nirav Shahcbc6d722016-03-01 16:24:53 +0530428 * IPA driver can send RM notifications with IRQ disabled so using qdf
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800429 * APIs as it is taken care gracefully. Without this, kernel would throw
430 * an warning if spin_lock_bh is used while IRQ is disabled
431 */
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530432 qdf_spinlock_t rm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800433 struct uc_rm_work_struct uc_rm_work;
434 struct uc_op_work_struct uc_op_work[HDD_IPA_UC_OPCODE_MAX];
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530435 qdf_wake_lock_t wake_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800436 struct delayed_work wake_lock_work;
437 bool wake_lock_released;
438
439 enum ipa_client_type prod_client;
440
441 atomic_t tx_ref_cnt;
Nirav Shahcbc6d722016-03-01 16:24:53 +0530442 qdf_nbuf_queue_t pm_queue_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800443 struct work_struct pm_work;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530444 qdf_spinlock_t pm_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800445 bool suspended;
446
Yun Park52b2b992016-09-22 15:49:51 -0700447 qdf_spinlock_t q_lock;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800449 struct list_head pend_desc_head;
Yun Park52b2b992016-09-22 15:49:51 -0700450 struct hdd_ipa_tx_desc *tx_desc_list;
451 struct list_head free_tx_desc_head;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800452
453 hdd_context_t *hdd_ctx;
454
455 struct dentry *debugfs_dir;
456 struct hdd_ipa_stats stats;
457
458 struct notifier_block ipv4_notifier;
459 uint32_t curr_prod_bw;
460 uint32_t curr_cons_bw;
461
462 uint8_t activated_fw_pipe;
463 uint8_t sap_num_connected_sta;
464 uint8_t sta_connected;
465 uint32_t tx_pipe_handle;
466 uint32_t rx_pipe_handle;
467 bool resource_loading;
468 bool resource_unloading;
469 bool pending_cons_req;
470 struct ipa_uc_stas_map assoc_stas_map[WLAN_MAX_STA_COUNT];
Anurag Chouhanffb21542016-02-17 14:33:03 +0530471 qdf_list_t pending_event;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530472 qdf_mutex_t event_lock;
Leo Change3e49442015-10-26 20:07:13 -0700473 bool ipa_pipes_down;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800474 uint32_t ipa_tx_packets_diff;
475 uint32_t ipa_rx_packets_diff;
476 uint32_t ipa_p_tx_packets;
477 uint32_t ipa_p_rx_packets;
478 uint32_t stat_req_reason;
479 uint64_t ipa_tx_forward;
480 uint64_t ipa_rx_discard;
481 uint64_t ipa_rx_net_send_count;
482 uint64_t ipa_rx_internel_drop_count;
483 uint64_t ipa_rx_destructor_count;
Anurag Chouhan210db072016-02-22 18:42:15 +0530484 qdf_mc_timer_t rt_debug_timer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800485 struct uc_rt_debug_info rt_bug_buffer[HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
486 unsigned int rt_buf_fill_index;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800487 struct ipa_wdi_in_params cons_pipe_in;
488 struct ipa_wdi_in_params prod_pipe_in;
489 bool uc_loaded;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800490 bool wdi_enabled;
Anurag Chouhan210db072016-02-22 18:42:15 +0530491 qdf_mc_timer_t rt_debug_fill_timer;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530492 qdf_mutex_t rt_debug_lock;
493 qdf_mutex_t ipa_lock;
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800494 struct ol_txrx_ipa_resources ipa_resource;
Leo Chang3bc8fed2015-11-13 10:59:47 -0800495 /* IPA UC doorbell registers paddr */
Anurag Chouhan6d760662016-02-20 16:05:43 +0530496 qdf_dma_addr_t tx_comp_doorbell_paddr;
497 qdf_dma_addr_t rx_ready_doorbell_paddr;
Prakash Dhavali89d406d2016-11-23 11:11:00 -0800498 uint8_t vdev_to_iface[CSR_ROAM_SESSION_MAX];
499 bool vdev_offload_enabled[CSR_ROAM_SESSION_MAX];
Yun Park637d6482016-10-05 10:51:33 -0700500#ifdef FEATURE_METERING
501 struct ipa_uc_sharing_stats ipa_sharing_stats;
502 struct ipa_uc_quota_rsp ipa_quota_rsp;
503 struct ipa_uc_quota_ind ipa_quota_ind;
504 struct completion ipa_uc_sharing_stats_comp;
505 struct completion ipa_uc_set_quota_comp;
506#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800507};
508
Leo Changcc923e22016-06-16 15:29:03 -0700509#define HDD_IPA_WLAN_FRAG_HEADER sizeof(struct frag_header)
510#define HDD_IPA_WLAN_IPA_HEADER sizeof(struct ipa_header)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800511#define HDD_IPA_WLAN_CLD_HDR_LEN sizeof(struct hdd_ipa_cld_hdr)
512#define HDD_IPA_UC_WLAN_CLD_HDR_LEN 0
513#define HDD_IPA_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_tx_hdr)
514#define HDD_IPA_UC_WLAN_TX_HDR_LEN sizeof(struct hdd_ipa_uc_tx_hdr)
515#define HDD_IPA_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_rx_hdr)
516#define HDD_IPA_UC_WLAN_RX_HDR_LEN sizeof(struct hdd_ipa_uc_rx_hdr)
Leo Changcc923e22016-06-16 15:29:03 -0700517#define HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET \
518 (HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800519
520#define HDD_IPA_GET_IFACE_ID(_data) \
521 (((struct hdd_ipa_cld_hdr *) (_data))->iface_id)
522
523#define HDD_IPA_LOG(LVL, fmt, args ...) \
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530524 QDF_TRACE(QDF_MODULE_ID_HDD, LVL, \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800525 "%s:%d: "fmt, __func__, __LINE__, ## args)
526
Govind Singhb6a89772016-08-12 11:23:35 +0530527#define HDD_IPA_DP_LOG(LVL, fmt, args...) \
528 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, LVL, \
529 "%s:%d: "fmt, __func__, __LINE__, ## args)
530
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800531#define HDD_IPA_DBG_DUMP(_lvl, _prefix, _buf, _len) \
532 do { \
Yun Parkec845302016-12-15 09:22:57 -0800533 QDF_TRACE(QDF_MODULE_ID_HDD_DATA, _lvl, "%s:", _prefix); \
534 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD_DATA, _lvl, _buf, _len); \
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800535 } while (0)
536
537#define HDD_IPA_IS_CONFIG_ENABLED(_hdd_ctx, _mask) \
538 (((_hdd_ctx)->config->IpaConfig & (_mask)) == (_mask))
539
540#define HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa) \
541 do { \
542 hdd_ipa->ipa_rx_internel_drop_count++; \
543 } while (0)
544#define HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa) \
545 do { \
546 hdd_ipa->ipa_rx_net_send_count++; \
547 } while (0)
548#define HDD_BW_GET_DIFF(_x, _y) (unsigned long)((ULONG_MAX - (_y)) + (_x) + 1)
549
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700550#if defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)
Dhanashri Atreb08959a2016-03-01 17:28:03 -0800551#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt) \
552do { \
553 pipe_in.u.ul.rdy_ring_rp_va = \
554 ipa_ctxt->ipa_resource.rx_proc_done_idx_vaddr; \
555 pipe_in.u.ul.rdy_comp_ring_base_pa = \
556 ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr;\
557 pipe_in.u.ul.rdy_comp_ring_size = \
558 ipa_ctxt->ipa_resource.rx2_rdy_ring_size; \
559 pipe_in.u.ul.rdy_comp_ring_wp_pa = \
560 ipa_ctxt->ipa_resource.rx2_proc_done_idx_paddr; \
561 pipe_in.u.ul.rdy_comp_ring_wp_va = \
562 ipa_ctxt->ipa_resource.rx2_proc_done_idx_vaddr; \
Leo Chang3bc8fed2015-11-13 10:59:47 -0800563} while (0)
Leo Chang63d73612016-10-18 18:09:43 -0700564
565#define HDD_IPA_CHECK_HW() ipa_uc_reg_rdyCB(NULL)
Leo Chang3bc8fed2015-11-13 10:59:47 -0800566#else
567/* Do nothing */
568#define HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt)
Leo Chang63d73612016-10-18 18:09:43 -0700569#define HDD_IPA_CHECK_HW() 0
Leo Chang07b28f62016-05-11 12:29:22 -0700570#endif /* IPA3 */
Leo Chang3bc8fed2015-11-13 10:59:47 -0800571
Yun Parkb187d542016-11-14 18:10:04 -0800572#define HDD_IPA_DBG_DUMP_RX_LEN 32
573#define HDD_IPA_DBG_DUMP_TX_LEN 48
574
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800575static struct hdd_ipa_adapter_2_client {
576 enum ipa_client_type cons_client;
577 enum ipa_client_type prod_client;
578} hdd_ipa_adapter_2_client[HDD_IPA_MAX_IFACE] = {
579 {
580 IPA_CLIENT_WLAN2_CONS, IPA_CLIENT_WLAN1_PROD
581 }, {
582 IPA_CLIENT_WLAN3_CONS, IPA_CLIENT_WLAN1_PROD
583 }, {
584 IPA_CLIENT_WLAN4_CONS, IPA_CLIENT_WLAN1_PROD
585 },
586};
587
588/* For Tx pipes, use Ethernet-II Header format */
589struct hdd_ipa_uc_tx_hdr ipa_uc_tx_hdr = {
590 {
Leo Chang3bc8fed2015-11-13 10:59:47 -0800591 0x0000,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 0x00000000,
593 0x00000000
594 },
595 {
596 0x00000000
597 },
598 {
599 {0x00, 0x03, 0x7f, 0xaa, 0xbb, 0xcc},
600 {0x00, 0x03, 0x7f, 0xdd, 0xee, 0xff},
601 0x0008
602 }
603};
604
605/* For Tx pipes, use 802.3 Header format */
606static struct hdd_ipa_tx_hdr ipa_tx_hdr = {
607 {
608 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
609 {0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0xFF},
610 0x00 /* length can be zero */
611 },
612 {
613 /* LLC SNAP header 8 bytes */
614 0xaa, 0xaa,
615 {0x03, 0x00, 0x00, 0x00},
616 0x0008 /* type value(2 bytes) ,filled by wlan */
617 /* 0x0800 - IPV4, 0x86dd - IPV6 */
618 }
619};
620
Yun Park637d6482016-10-05 10:51:33 -0700621#ifdef FEATURE_METERING
622#define IPA_UC_SHARING_STATES_WAIT_TIME 500
623#define IPA_UC_SET_QUOTA_WAIT_TIME 500
624#endif
625
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800626static struct hdd_ipa_priv *ghdd_ipa;
627
628/* Local Function Prototypes */
629static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
630 unsigned long data);
631static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
632 unsigned long data);
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800633static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800634
635static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -0700636static void hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800637
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800638#if ((defined(QCA_WIFI_3_0) && defined(CONFIG_IPA3)) || \
639 defined(IPA_CLIENT_IS_MHI_CONS))
640/**
641 * hdd_ipa_uc_get_db_paddr() - Get Doorbell physical address
642 * @db_paddr: Doorbell physical address should be given bu IPA
643 * @client: IPA client type
644 *
645 * Query doorbell physical address from IPA
646 * IPA will give physical address for TX COMP and RX READY
647 *
648 * Return: None
649 */
650static void hdd_ipa_uc_get_db_paddr(qdf_dma_addr_t *db_paddr,
651 enum ipa_client_type client)
652{
653 struct ipa_wdi_db_params dbpa;
654
655 dbpa.client = client;
656 ipa_uc_wdi_get_dbpa(&dbpa);
657 *db_paddr = dbpa.uc_door_bell_pa;
Srinivas Girigowda97852372017-03-06 16:52:59 -0800658 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s PROD DB get dbpa 0x%x",
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800659 __func__, (unsigned int)dbpa.uc_door_bell_pa);
660}
661
662/**
663 * hdd_ipa_uc_loaded_uc_cb() - IPA UC loaded event callback
664 * @priv_ctxt: hdd ipa local context
665 *
666 * Will be called by IPA context.
667 * It's atomic context, then should be scheduled to kworker thread
668 *
669 * Return: None
670 */
671static void hdd_ipa_uc_loaded_uc_cb(void *priv_ctxt)
672{
673 struct hdd_ipa_priv *hdd_ipa;
674 struct op_msg_type *msg;
675 struct uc_op_work_struct *uc_op_work;
676
677 if (priv_ctxt == NULL) {
678 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Invalid IPA context");
679 return;
680 }
681
682 hdd_ipa = (struct hdd_ipa_priv *)priv_ctxt;
683 msg = (struct op_msg_type *)qdf_mem_malloc(sizeof(*msg));
684 if (!msg) {
685 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "op_msg allocation fails");
686 return;
687 }
688
689 msg->op_code = HDD_IPA_UC_OPCODE_UC_READY;
690
691 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
692
693 /* When the same uC OPCODE is already pended, just return */
694 if (uc_op_work->msg)
695 return;
696
697 uc_op_work->msg = msg;
698 schedule_work(&uc_op_work->work);
699}
700
701/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800702 * hdd_ipa_uc_send_wdi_control_msg() - Set WDI control message
703 * @ctrl: WDI control value
704 *
705 * Send WLAN_WDI_ENABLE for ctrl = true and WLAN_WDI_DISABLE otherwise.
706 *
707 * Return: 0 on message send to ipa, -1 on failure
708 */
709static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
710{
711 struct ipa_msg_meta meta;
712 struct ipa_wlan_msg *ipa_msg;
713 int ret = 0;
714
715 /* WDI enable message to IPA */
716 meta.msg_len = sizeof(*ipa_msg);
717 ipa_msg = qdf_mem_malloc(meta.msg_len);
718 if (ipa_msg == NULL) {
719 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
720 "msg allocation failed");
721 return -ENOMEM;
722 }
723
724 if (ctrl == true)
725 meta.msg_type = WLAN_WDI_ENABLE;
726 else
727 meta.msg_type = WLAN_WDI_DISABLE;
728
Srinivas Girigowda97852372017-03-06 16:52:59 -0800729 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800730 "ipa_send_msg(Evt:%d)", meta.msg_type);
731 ret = ipa_send_msg(&meta, ipa_msg, hdd_ipa_msg_free_fn);
732 if (ret) {
733 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
734 "ipa_send_msg(Evt:%d)-fail=%d",
735 meta.msg_type, ret);
736 qdf_mem_free(ipa_msg);
737 }
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800738 return ret;
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800739}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800740
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800741/**
742 * hdd_ipa_uc_register_uc_ready() - Register UC ready callback function to IPA
743 * @hdd_ipa: HDD IPA local context
744 *
745 * Register IPA UC ready callback function to IPA kernel driver
746 * Even IPA UC loaded later than WLAN kernel driver, WLAN kernel driver will
747 * open WDI pipe after WLAN driver loading finished
748 *
749 * Return: 0 Success
750 * -EPERM Registration fail
751 */
752static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
753{
754 struct ipa_wdi_uc_ready_params uc_ready_param;
755 int ret = 0;
756
757 hdd_ipa->uc_loaded = false;
758 uc_ready_param.priv = (void *)hdd_ipa;
759 uc_ready_param.notify = hdd_ipa_uc_loaded_uc_cb;
760 if (ipa_uc_reg_rdyCB(&uc_ready_param)) {
761 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
762 "UC Ready CB register fail");
763 return -EPERM;
764 }
765 if (true == uc_ready_param.is_uC_ready) {
Srinivas Girigowda2b5d47c2017-03-29 00:28:46 -0700766 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "UC Ready");
Manikandan Mohancd64c0b2017-03-08 13:00:24 -0800767 hdd_ipa->uc_loaded = true;
768 } else {
769 ret = hdd_ipa_uc_send_wdi_control_msg(false);
770 }
771
772 return ret;
773}
Manikandan Mohan153a4c32017-02-16 15:04:30 -0800774#else
775static void hdd_ipa_uc_get_db_paddr(qdf_dma_addr_t *db_paddr,
776 enum ipa_client_type client)
777{
778 /* Do nothing */
779}
780
781static int hdd_ipa_uc_register_uc_ready(struct hdd_ipa_priv *hdd_ipa)
782{
783 hdd_ipa->uc_loaded = true;
784 return 0;
785}
786
787static int hdd_ipa_uc_send_wdi_control_msg(bool ctrl)
788{
789 return 0;
790}
791#endif
792
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793/**
794 * hdd_ipa_is_enabled() - Is IPA enabled?
795 * @hdd_ctx: Global HDD context
796 *
797 * Return: true if IPA is enabled, false otherwise
798 */
799bool hdd_ipa_is_enabled(hdd_context_t *hdd_ctx)
800{
801 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_ENABLE_MASK);
802}
803
804/**
805 * hdd_ipa_uc_is_enabled() - Is IPA uC offload enabled?
806 * @hdd_ctx: Global HDD context
807 *
808 * Return: true if IPA uC offload is enabled, false otherwise
809 */
810bool hdd_ipa_uc_is_enabled(hdd_context_t *hdd_ctx)
811{
812 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_ENABLE_MASK);
813}
814
815/**
816 * hdd_ipa_uc_sta_is_enabled() - Is STA mode IPA uC offload enabled?
817 * @hdd_ctx: Global HDD context
818 *
819 * Return: true if STA mode IPA uC offload is enabled, false otherwise
820 */
821static inline bool hdd_ipa_uc_sta_is_enabled(hdd_context_t *hdd_ctx)
822{
823 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_UC_STA_ENABLE_MASK);
824}
825
826/**
Guolei Bianca144d82016-11-10 11:07:42 +0800827 * hdd_ipa_uc_sta_reset_sta_connected() - Reset sta_connected flag
828 * @hdd_ipa: Global HDD IPA context
829 *
830 * Return: None
831 */
Guolei Bianca144d82016-11-10 11:07:42 +0800832static inline void hdd_ipa_uc_sta_reset_sta_connected(
833 struct hdd_ipa_priv *hdd_ipa)
834{
Yun Park637d6482016-10-05 10:51:33 -0700835 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800836 hdd_ipa->sta_connected = 0;
Yun Park637d6482016-10-05 10:51:33 -0700837 qdf_mutex_release(&hdd_ipa->ipa_lock);
Guolei Bianca144d82016-11-10 11:07:42 +0800838}
Guolei Bianca144d82016-11-10 11:07:42 +0800839
840/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800841 * hdd_ipa_is_pre_filter_enabled() - Is IPA pre-filter enabled?
842 * @hdd_ipa: Global HDD IPA context
843 *
844 * Return: true if pre-filter is enabled, otherwise false
845 */
846static inline bool hdd_ipa_is_pre_filter_enabled(hdd_context_t *hdd_ctx)
847{
848 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
849 HDD_IPA_PRE_FILTER_ENABLE_MASK);
850}
851
852/**
853 * hdd_ipa_is_ipv6_enabled() - Is IPA IPv6 enabled?
854 * @hdd_ipa: Global HDD IPA context
855 *
856 * Return: true if IPv6 is enabled, otherwise false
857 */
858static inline bool hdd_ipa_is_ipv6_enabled(hdd_context_t *hdd_ctx)
859{
860 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_IPV6_ENABLE_MASK);
861}
862
863/**
864 * hdd_ipa_is_rm_enabled() - Is IPA resource manager enabled?
865 * @hdd_ipa: Global HDD IPA context
866 *
867 * Return: true if resource manager is enabled, otherwise false
868 */
869static inline bool hdd_ipa_is_rm_enabled(hdd_context_t *hdd_ctx)
870{
871 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_RM_ENABLE_MASK);
872}
873
874/**
875 * hdd_ipa_is_rt_debugging_enabled() - Is IPA real-time debug enabled?
876 * @hdd_ipa: Global HDD IPA context
877 *
878 * Return: true if resource manager is enabled, otherwise false
879 */
880static inline bool hdd_ipa_is_rt_debugging_enabled(hdd_context_t *hdd_ctx)
881{
882 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx, HDD_IPA_REAL_TIME_DEBUGGING);
883}
884
885/**
886 * hdd_ipa_is_clk_scaling_enabled() - Is IPA clock scaling enabled?
887 * @hdd_ipa: Global HDD IPA context
888 *
889 * Return: true if clock scaling is enabled, otherwise false
890 */
891static inline bool hdd_ipa_is_clk_scaling_enabled(hdd_context_t *hdd_ctx)
892{
893 return HDD_IPA_IS_CONFIG_ENABLED(hdd_ctx,
894 HDD_IPA_CLK_SCALING_ENABLE_MASK |
895 HDD_IPA_RM_ENABLE_MASK);
896}
897
898/**
899 * hdd_ipa_uc_rt_debug_host_fill - fill rt debug buffer
900 * @ctext: pointer to hdd context.
901 *
902 * If rt debug enabled, periodically called, and fill debug buffer
903 *
904 * Return: none
905 */
906static void hdd_ipa_uc_rt_debug_host_fill(void *ctext)
907{
908 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
909 struct hdd_ipa_priv *hdd_ipa;
910 struct uc_rt_debug_info *dump_info = NULL;
911
912 if (wlan_hdd_validate_context(hdd_ctx))
913 return;
914
915 if (!hdd_ctx->hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -0800916 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 "%s: IPA UC is not enabled", __func__);
918 return;
919 }
920
921 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
922
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530923 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 dump_info = &hdd_ipa->rt_bug_buffer[
925 hdd_ipa->rt_buf_fill_index % HDD_IPA_UC_RT_DEBUG_BUF_COUNT];
926
Deepthi Gowri6acee342016-10-28 15:00:38 +0530927 dump_info->time = (uint64_t)qdf_mc_timer_get_system_time();
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800928 dump_info->ipa_excep_count = hdd_ipa->stats.num_rx_excep;
929 dump_info->rx_drop_count = hdd_ipa->ipa_rx_internel_drop_count;
930 dump_info->net_sent_count = hdd_ipa->ipa_rx_net_send_count;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800931 dump_info->tx_fwd_count = hdd_ipa->ipa_tx_forward;
Yun Parkb187d542016-11-14 18:10:04 -0800932 dump_info->tx_fwd_ok_count = hdd_ipa->stats.num_tx_fwd_ok;
933 dump_info->rx_discard_count = hdd_ipa->ipa_rx_discard;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800934 dump_info->rx_destructor_call = hdd_ipa->ipa_rx_destructor_count;
935 hdd_ipa->rt_buf_fill_index++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530936 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800937
Anurag Chouhan210db072016-02-22 18:42:15 +0530938 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800939 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
940}
941
942/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700943 * __hdd_ipa_uc_rt_debug_host_dump - dump rt debug buffer
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800944 * @hdd_ctx: pointer to hdd context.
945 *
946 * If rt debug enabled, dump debug buffer contents based on requirement
947 *
948 * Return: none
949 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700950static void __hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800951{
952 struct hdd_ipa_priv *hdd_ipa;
953 unsigned int dump_count;
954 unsigned int dump_index;
955 struct uc_rt_debug_info *dump_info = NULL;
956
957 if (wlan_hdd_validate_context(hdd_ctx))
958 return;
959
960 hdd_ipa = hdd_ctx->hdd_ipa;
961 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -0800962 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800963 "%s: IPA UC is not enabled", __func__);
964 return;
965 }
966
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530967 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800968 "========= WLAN-IPA DEBUG BUF DUMP ==========\n");
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530969 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkb187d542016-11-14 18:10:04 -0800970 " TM : EXEP : DROP : NETS : FWOK : TXFD : DSTR : DSCD\n");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800971
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530972 qdf_mutex_acquire(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800973 for (dump_count = 0;
974 dump_count < HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
975 dump_count++) {
976 dump_index = (hdd_ipa->rt_buf_fill_index + dump_count) %
977 HDD_IPA_UC_RT_DEBUG_BUF_COUNT;
978 dump_info = &hdd_ipa->rt_bug_buffer[dump_index];
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530979 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Deepthi Gowri6acee342016-10-28 15:00:38 +0530980 "%12llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu:%10llu\n",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800981 dump_info->time, dump_info->ipa_excep_count,
982 dump_info->rx_drop_count, dump_info->net_sent_count,
Yun Parkb187d542016-11-14 18:10:04 -0800983 dump_info->tx_fwd_ok_count, dump_info->tx_fwd_count,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 dump_info->rx_destructor_call,
985 dump_info->rx_discard_count);
986 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +0530987 qdf_mutex_release(&hdd_ipa->rt_debug_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +0530988 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800989 "======= WLAN-IPA DEBUG BUF DUMP END ========\n");
990}
991
992/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -0700993 * hdd_ipa_uc_rt_debug_host_dump - SSR wrapper for
994 * __hdd_ipa_uc_rt_debug_host_dump
995 * @hdd_ctx: pointer to hdd context.
996 *
997 * If rt debug enabled, dump debug buffer contents based on requirement
998 *
999 * Return: none
1000 */
1001void hdd_ipa_uc_rt_debug_host_dump(hdd_context_t *hdd_ctx)
1002{
1003 cds_ssr_protect(__func__);
1004 __hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
1005 cds_ssr_unprotect(__func__);
1006}
1007
1008/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 * hdd_ipa_uc_rt_debug_handler - periodic memory health monitor handler
1010 * @ctext: pointer to hdd context.
1011 *
1012 * periodically called by timer expire
1013 * will try to alloc dummy memory and detect out of memory condition
1014 * if out of memory detected, dump wlan-ipa stats
1015 *
1016 * Return: none
1017 */
1018static void hdd_ipa_uc_rt_debug_handler(void *ctext)
1019{
1020 hdd_context_t *hdd_ctx = (hdd_context_t *)ctext;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001021 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 void *dummy_ptr = NULL;
1023
1024 if (wlan_hdd_validate_context(hdd_ctx))
1025 return;
1026
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001027 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1028
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001030 hdd_debug("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001031 return;
1032 }
1033
1034 /* Allocate dummy buffer periodically and free immediately. this will
1035 * proactively detect OOM and if allocation fails dump ipa stats
1036 */
1037 dummy_ptr = kmalloc(HDD_IPA_UC_DEBUG_DUMMY_MEM_SIZE,
1038 GFP_KERNEL | GFP_ATOMIC);
1039 if (!dummy_ptr) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001040 hdd_ipa_uc_rt_debug_host_dump(hdd_ctx);
1041 hdd_ipa_uc_stat_request(
Yun Park637d6482016-10-05 10:51:33 -07001042 hdd_get_adapter(hdd_ctx, QDF_SAP_MODE),
1043 HDD_IPA_UC_STAT_REASON_DEBUG);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 } else {
1045 kfree(dummy_ptr);
1046 }
1047
Anurag Chouhan210db072016-02-22 18:42:15 +05301048 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001049 HDD_IPA_UC_RT_DEBUG_PERIOD);
1050}
1051
1052/**
Yun Parkb187d542016-11-14 18:10:04 -08001053 * hdd_ipa_uc_rt_debug_destructor() - called by data packet free
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 * @skb: packet pinter
1055 *
1056 * when free data packet, will be invoked by wlan client and will increase
1057 * free counter
1058 *
1059 * Return: none
1060 */
Jeff Johnsond7720632016-10-05 16:04:32 -07001061static void hdd_ipa_uc_rt_debug_destructor(struct sk_buff *skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001062{
1063 if (!ghdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301064 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001065 "%s: invalid hdd context", __func__);
1066 return;
1067 }
1068
1069 ghdd_ipa->ipa_rx_destructor_count++;
1070}
1071
1072/**
Yun Parkb187d542016-11-14 18:10:04 -08001073 * hdd_ipa_uc_rt_debug_deinit() - remove resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001074 * @hdd_ctx: hdd main context
1075 *
1076 * free all rt debugging resources
1077 *
1078 * Return: none
1079 */
1080static void hdd_ipa_uc_rt_debug_deinit(hdd_context_t *hdd_ctx)
1081{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001082 struct hdd_ipa_priv *hdd_ipa;
1083
1084 if (wlan_hdd_validate_context(hdd_ctx))
1085 return;
1086
1087 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001088
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301089 qdf_mutex_destroy(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001090
1091 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001092 hdd_debug("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001093 return;
1094 }
1095
Anurag Chouhan210db072016-02-22 18:42:15 +05301096 if (QDF_TIMER_STATE_STOPPED !=
Prakash Dhavali169de302016-11-30 12:52:49 -08001097 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_fill_timer)) {
1098 qdf_mc_timer_stop(&hdd_ipa->rt_debug_fill_timer);
1099 }
1100 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_fill_timer);
1101
1102 if (QDF_TIMER_STATE_STOPPED !=
Anurag Chouhan210db072016-02-22 18:42:15 +05301103 qdf_mc_timer_get_current_state(&hdd_ipa->rt_debug_timer)) {
1104 qdf_mc_timer_stop(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 }
Anurag Chouhan210db072016-02-22 18:42:15 +05301106 qdf_mc_timer_destroy(&hdd_ipa->rt_debug_timer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001107}
1108
1109/**
Yun Parkb187d542016-11-14 18:10:04 -08001110 * hdd_ipa_uc_rt_debug_init() - intialize resources to handle rt debugging
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 * @hdd_ctx: hdd main context
1112 *
1113 * alloc and initialize all rt debugging resources
1114 *
1115 * Return: none
1116 */
1117static void hdd_ipa_uc_rt_debug_init(hdd_context_t *hdd_ctx)
1118{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001119 struct hdd_ipa_priv *hdd_ipa;
1120
1121 if (wlan_hdd_validate_context(hdd_ctx))
1122 return;
1123
1124 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001125
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301126 qdf_mutex_create(&hdd_ipa->rt_debug_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001127 hdd_ipa->rt_buf_fill_index = 0;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301128 qdf_mem_zero(hdd_ipa->rt_bug_buffer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 sizeof(struct uc_rt_debug_info) *
1130 HDD_IPA_UC_RT_DEBUG_BUF_COUNT);
1131 hdd_ipa->ipa_tx_forward = 0;
1132 hdd_ipa->ipa_rx_discard = 0;
1133 hdd_ipa->ipa_rx_net_send_count = 0;
1134 hdd_ipa->ipa_rx_internel_drop_count = 0;
1135 hdd_ipa->ipa_rx_destructor_count = 0;
1136
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001137 /* Reatime debug enable on feature enable */
1138 if (!hdd_ipa_is_rt_debugging_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001139 hdd_debug("IPA RT debug is not enabled");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001140 return;
1141 }
Yun Parkdfc1da52016-11-15 14:50:11 -08001142
1143 qdf_mc_timer_init(&hdd_ipa->rt_debug_fill_timer, QDF_TIMER_TYPE_SW,
1144 hdd_ipa_uc_rt_debug_host_fill, (void *)hdd_ctx);
1145 qdf_mc_timer_start(&hdd_ipa->rt_debug_fill_timer,
1146 HDD_IPA_UC_RT_DEBUG_FILL_INTERVAL);
1147
Anurag Chouhan210db072016-02-22 18:42:15 +05301148 qdf_mc_timer_init(&hdd_ipa->rt_debug_timer, QDF_TIMER_TYPE_SW,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001149 hdd_ipa_uc_rt_debug_handler, (void *)hdd_ctx);
Anurag Chouhan210db072016-02-22 18:42:15 +05301150 qdf_mc_timer_start(&hdd_ipa->rt_debug_timer,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001151 HDD_IPA_UC_RT_DEBUG_PERIOD);
1152
1153}
1154
1155/**
Yun Parkb187d542016-11-14 18:10:04 -08001156 * hdd_ipa_dump_hdd_ipa() - dump entries in HDD IPA struct
1157 * @hdd_ipa: HDD IPA struct
1158 *
1159 * Dump entries in struct hdd_ipa
1160 *
1161 * Return: none
1162 */
1163static void hdd_ipa_dump_hdd_ipa(struct hdd_ipa_priv *hdd_ipa)
1164{
1165 int i;
1166
1167 /* HDD IPA */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001168 hdd_info("==== HDD IPA ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08001169 "num_iface: %d\n"
1170 "rm_state: %d\n"
1171 "rm_lock: %p\n"
1172 "uc_rm_work: %p\n"
1173 "uc_op_work: %p\n"
1174 "wake_lock: %p\n"
1175 "wake_lock_work: %p\n"
1176 "wake_lock_released: %d\n"
1177 "prod_client: %d\n"
1178 "tx_ref_cnt: %d\n"
1179 "pm_queue_head----\n"
1180 "\thead: %p\n"
1181 "\ttail: %p\n"
1182 "\tqlen: %d\n"
1183 "pm_work: %p\n"
1184 "pm_lock: %p\n"
1185 "suspended: %d\n",
1186 hdd_ipa->num_iface,
1187 hdd_ipa->rm_state,
1188 &hdd_ipa->rm_lock,
1189 &hdd_ipa->uc_rm_work,
1190 &hdd_ipa->uc_op_work,
1191 &hdd_ipa->wake_lock,
1192 &hdd_ipa->wake_lock_work,
1193 hdd_ipa->wake_lock_released,
1194 hdd_ipa->prod_client,
1195 hdd_ipa->tx_ref_cnt.counter,
1196 hdd_ipa->pm_queue_head.head,
1197 hdd_ipa->pm_queue_head.tail,
1198 hdd_ipa->pm_queue_head.qlen,
1199 &hdd_ipa->pm_work,
1200 &hdd_ipa->pm_lock,
1201 hdd_ipa->suspended);
Yun Park52b2b992016-09-22 15:49:51 -07001202 hdd_err("\nq_lock: %p\n"
Yun Parkb187d542016-11-14 18:10:04 -08001203 "pend_desc_head----\n"
1204 "\tnext: %p\n"
1205 "\tprev: %p\n"
1206 "hdd_ctx: %p\n"
1207 "debugfs_dir: %p\n"
1208 "stats: %p\n"
1209 "ipv4_notifier: %p\n"
1210 "curr_prod_bw: %d\n"
1211 "curr_cons_bw: %d\n"
1212 "activated_fw_pipe: %d\n"
1213 "sap_num_connected_sta: %d\n"
1214 "sta_connected: %d\n",
Yun Parkb187d542016-11-14 18:10:04 -08001215 &hdd_ipa->q_lock,
Yun Parkb187d542016-11-14 18:10:04 -08001216 hdd_ipa->pend_desc_head.next,
1217 hdd_ipa->pend_desc_head.prev,
1218 hdd_ipa->hdd_ctx,
1219 hdd_ipa->debugfs_dir,
1220 &hdd_ipa->stats,
1221 &hdd_ipa->ipv4_notifier,
1222 hdd_ipa->curr_prod_bw,
1223 hdd_ipa->curr_cons_bw,
1224 hdd_ipa->activated_fw_pipe,
1225 hdd_ipa->sap_num_connected_sta,
1226 (unsigned int)hdd_ipa->sta_connected
1227 );
Srinivas Girigowda97852372017-03-06 16:52:59 -08001228 hdd_info("\ntx_pipe_handle: 0x%x\n"
Yun Parkb187d542016-11-14 18:10:04 -08001229 "rx_pipe_handle: 0x%x\n"
1230 "resource_loading: %d\n"
1231 "resource_unloading: %d\n"
1232 "pending_cons_req: %d\n"
1233 "pending_event----\n"
1234 "\tanchor.next: %p\n"
1235 "\tanchor.prev: %p\n"
1236 "\tcount: %d\n"
1237 "\tmax_size: %d\n"
1238 "event_lock: %p\n"
1239 "ipa_tx_packets_diff: %d\n"
1240 "ipa_rx_packets_diff: %d\n"
1241 "ipa_p_tx_packets: %d\n"
1242 "ipa_p_rx_packets: %d\n"
1243 "stat_req_reason: %d\n",
1244 hdd_ipa->tx_pipe_handle,
1245 hdd_ipa->rx_pipe_handle,
1246 hdd_ipa->resource_loading,
1247 hdd_ipa->resource_unloading,
1248 hdd_ipa->pending_cons_req,
1249 hdd_ipa->pending_event.anchor.next,
1250 hdd_ipa->pending_event.anchor.prev,
1251 hdd_ipa->pending_event.count,
1252 hdd_ipa->pending_event.max_size,
1253 &hdd_ipa->event_lock,
1254 hdd_ipa->ipa_tx_packets_diff,
1255 hdd_ipa->ipa_rx_packets_diff,
1256 hdd_ipa->ipa_p_tx_packets,
1257 hdd_ipa->ipa_p_rx_packets,
1258 hdd_ipa->stat_req_reason);
1259
Srinivas Girigowda97852372017-03-06 16:52:59 -08001260 hdd_info("assoc_stas_map([id]is_reserved/sta_id): ");
Yun Parkb187d542016-11-14 18:10:04 -08001261 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08001262 hdd_info(" [%d]%d/%d", i,
Yun Parkb187d542016-11-14 18:10:04 -08001263 hdd_ipa->assoc_stas_map[i].is_reserved,
1264 hdd_ipa->assoc_stas_map[i].sta_id);
1265 }
1266}
1267
1268/**
1269 * hdd_ipa_dump_sys_pipe() - dump HDD IPA SYS Pipe struct
1270 * @hdd_ipa: HDD IPA struct
1271 *
1272 * Dump entire struct hdd_ipa_sys_pipe
1273 *
1274 * Return: none
1275 */
1276static void hdd_ipa_dump_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
1277{
1278 int i;
1279
1280 /* IPA SYS Pipes */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001281 hdd_info("==== IPA SYS Pipes ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001282
1283 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
1284 struct hdd_ipa_sys_pipe *sys_pipe;
1285 struct ipa_sys_connect_params *ipa_sys_params;
1286
1287 sys_pipe = &hdd_ipa->sys_pipe[i];
1288 ipa_sys_params = &sys_pipe->ipa_sys_params;
1289
Srinivas Girigowda97852372017-03-06 16:52:59 -08001290 hdd_info("sys_pipe[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001291 "\tconn_hdl: 0x%x\n"
1292 "\tconn_hdl_valid: %d\n"
1293 "\tnat_en: %d\n"
1294 "\thdr_len %d\n"
1295 "\thdr_additional_const_len: %d\n"
1296 "\thdr_ofst_pkt_size_valid: %d\n"
1297 "\thdr_ofst_pkt_size: %d\n"
1298 "\thdr_little_endian: %d\n"
1299 "\tmode: %d\n"
1300 "\tclient: %d\n"
1301 "\tdesc_fifo_sz: %d\n"
1302 "\tpriv: %p\n"
1303 "\tnotify: %p\n"
1304 "\tskip_ep_cfg: %d\n"
1305 "\tkeep_ipa_awake: %d\n",
1306 i,
1307 sys_pipe->conn_hdl,
1308 sys_pipe->conn_hdl_valid,
1309 ipa_sys_params->ipa_ep_cfg.nat.nat_en,
1310 ipa_sys_params->ipa_ep_cfg.hdr.hdr_len,
1311 ipa_sys_params->ipa_ep_cfg.hdr.hdr_additional_const_len,
1312 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid,
1313 ipa_sys_params->ipa_ep_cfg.hdr.hdr_ofst_pkt_size,
1314 ipa_sys_params->ipa_ep_cfg.hdr_ext.hdr_little_endian,
1315 ipa_sys_params->ipa_ep_cfg.mode.mode,
1316 ipa_sys_params->client,
1317 ipa_sys_params->desc_fifo_sz,
1318 ipa_sys_params->priv,
1319 ipa_sys_params->notify,
1320 ipa_sys_params->skip_ep_cfg,
1321 ipa_sys_params->keep_ipa_awake);
1322 }
1323}
1324
1325/**
1326 * hdd_ipa_dump_iface_context() - dump HDD IPA Interface Context struct
1327 * @hdd_ipa: HDD IPA struct
1328 *
1329 * Dump entire struct hdd_ipa_iface_context
1330 *
1331 * Return: none
1332 */
1333static void hdd_ipa_dump_iface_context(struct hdd_ipa_priv *hdd_ipa)
1334{
1335 int i;
1336
1337 /* IPA Interface Contexts */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001338 hdd_info("==== IPA Interface Contexts ====\n");
Yun Parkb187d542016-11-14 18:10:04 -08001339
1340 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
1341 struct hdd_ipa_iface_context *iface_context;
1342
1343 iface_context = &hdd_ipa->iface_context[i];
1344
Srinivas Girigowda97852372017-03-06 16:52:59 -08001345 hdd_info("iface_context[%d]----\n"
Yun Parkb187d542016-11-14 18:10:04 -08001346 "\thdd_ipa: %p\n"
1347 "\tadapter: %p\n"
1348 "\ttl_context: %p\n"
1349 "\tcons_client: %d\n"
1350 "\tprod_client: %d\n"
1351 "\tiface_id: %d\n"
1352 "\tsta_id: %d\n"
1353 "\tinterface_lock: %p\n"
1354 "\tifa_address: 0x%x\n",
1355 i,
1356 iface_context->hdd_ipa,
1357 iface_context->adapter,
1358 iface_context->tl_context,
1359 iface_context->cons_client,
1360 iface_context->prod_client,
1361 iface_context->iface_id,
1362 iface_context->sta_id,
1363 &iface_context->interface_lock,
1364 iface_context->ifa_address);
1365 }
1366}
1367
1368/**
1369 * hdd_ipa_dump_info() - dump HDD IPA struct
1370 * @pHddCtx: hdd main context
1371 *
1372 * Dump entire struct hdd_ipa
1373 *
1374 * Return: none
1375 */
1376void hdd_ipa_dump_info(hdd_context_t *hdd_ctx)
1377{
1378 struct hdd_ipa_priv *hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1379
1380 hdd_ipa_dump_hdd_ipa(hdd_ipa);
1381 hdd_ipa_dump_sys_pipe(hdd_ipa);
1382 hdd_ipa_dump_iface_context(hdd_ipa);
1383}
1384
1385/**
Tushnim Bhattacharyya9e81b4c2017-02-15 17:11:14 -08001386 * hdd_ipa_set_tx_flow_info() - To set TX flow info if IPA is
1387 * enabled
1388 *
1389 * This routine is called to set TX flow info if IPA is enabled
1390 *
1391 * Return: None
1392 */
1393void hdd_ipa_set_tx_flow_info(void)
1394{
1395 hdd_adapter_list_node_t *adapterNode = NULL, *pNext = NULL;
1396 QDF_STATUS status;
1397 hdd_adapter_t *adapter;
1398 hdd_station_ctx_t *pHddStaCtx;
1399 hdd_ap_ctx_t *hdd_ap_ctx;
1400 hdd_hostapd_state_t *hostapd_state;
1401 struct qdf_mac_addr staBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1402 struct qdf_mac_addr p2pBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1403 struct qdf_mac_addr apBssid = QDF_MAC_ADDR_ZERO_INITIALIZER;
1404 uint8_t staChannel = 0, p2pChannel = 0, apChannel = 0;
1405 const char *p2pMode = "DEV";
1406 hdd_context_t *hdd_ctx;
1407 cds_context_type *cds_ctx;
1408#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1409 uint8_t targetChannel = 0;
1410 uint8_t preAdapterChannel = 0;
1411 uint8_t channel24;
1412 uint8_t channel5;
1413 hdd_adapter_t *preAdapterContext = NULL;
1414 hdd_adapter_t *adapter2_4 = NULL;
1415 hdd_adapter_t *adapter5 = NULL;
1416 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1417#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1418 struct wlan_objmgr_psoc *psoc;
1419
1420 hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
1421 if (!hdd_ctx) {
1422 cds_err("HDD context is NULL");
1423 return;
1424 }
1425
1426 cds_ctx = cds_get_context(QDF_MODULE_ID_QDF);
1427 if (!cds_ctx) {
1428 cds_err("Invalid CDS Context");
1429 return;
1430 }
1431
1432 psoc = hdd_ctx->hdd_psoc;
1433 status = hdd_get_front_adapter(hdd_ctx, &adapterNode);
1434 while (NULL != adapterNode && QDF_STATUS_SUCCESS == status) {
1435 adapter = adapterNode->pAdapter;
1436 switch (adapter->device_mode) {
1437 case QDF_STA_MODE:
1438 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1439 if (eConnectionState_Associated ==
1440 pHddStaCtx->conn_info.connState) {
1441 staChannel =
1442 pHddStaCtx->conn_info.operationChannel;
1443 qdf_copy_macaddr(&staBssid,
1444 &pHddStaCtx->conn_info.bssId);
1445#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1446 targetChannel = staChannel;
1447#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1448 }
1449 break;
1450 case QDF_P2P_CLIENT_MODE:
1451 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1452 if (eConnectionState_Associated ==
1453 pHddStaCtx->conn_info.connState) {
1454 p2pChannel =
1455 pHddStaCtx->conn_info.operationChannel;
1456 qdf_copy_macaddr(&p2pBssid,
1457 &pHddStaCtx->conn_info.bssId);
1458 p2pMode = "CLI";
1459#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1460 targetChannel = p2pChannel;
1461#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1462 }
1463 break;
1464 case QDF_P2P_GO_MODE:
1465 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1466 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1467 if (hostapd_state->bssState == BSS_START
1468 && hostapd_state->qdf_status ==
1469 QDF_STATUS_SUCCESS) {
1470 p2pChannel = hdd_ap_ctx->operatingChannel;
1471 qdf_copy_macaddr(&p2pBssid,
1472 &adapter->macAddressCurrent);
1473#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1474 targetChannel = p2pChannel;
1475#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1476 }
1477 p2pMode = "GO";
1478 break;
1479 case QDF_SAP_MODE:
1480 hdd_ap_ctx = WLAN_HDD_GET_AP_CTX_PTR(adapter);
1481 hostapd_state = WLAN_HDD_GET_HOSTAP_STATE_PTR(adapter);
1482 if (hostapd_state->bssState == BSS_START
1483 && hostapd_state->qdf_status ==
1484 QDF_STATUS_SUCCESS) {
1485 apChannel = hdd_ap_ctx->operatingChannel;
1486 qdf_copy_macaddr(&apBssid,
1487 &adapter->macAddressCurrent);
1488#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1489 targetChannel = apChannel;
1490#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1491 }
1492 break;
1493 case QDF_IBSS_MODE:
1494 default:
1495 break;
1496 }
1497#ifdef QCA_LL_LEGACY_TX_FLOW_CONTROL
1498 if (targetChannel) {
1499 /*
1500 * This is first adapter detected as active
1501 * set as default for none concurrency case
1502 */
1503 if (!preAdapterChannel) {
1504 /* If IPA UC data path is enabled,
1505 * target should reserve extra tx descriptors
1506 * for IPA data path.
1507 * Then host data path should allow less TX
1508 * packet pumping in case IPA
1509 * data path enabled
1510 */
1511 if (hdd_ipa_uc_is_enabled(hdd_ctx) &&
1512 (QDF_SAP_MODE == adapter->device_mode)) {
1513 adapter->tx_flow_low_watermark =
1514 hdd_ctx->config->TxFlowLowWaterMark +
1515 WLAN_TFC_IPAUC_TX_DESC_RESERVE;
1516 } else {
1517 adapter->tx_flow_low_watermark =
1518 hdd_ctx->config->
1519 TxFlowLowWaterMark;
1520 }
1521 adapter->tx_flow_high_watermark_offset =
1522 hdd_ctx->config->TxFlowHighWaterMarkOffset;
1523 cdp_fc_ll_set_tx_pause_q_depth(soc,
1524 adapter->sessionId,
1525 hdd_ctx->config->TxFlowMaxQueueDepth);
1526 cds_info("MODE %d,CH %d,LWM %d,HWM %d,TXQDEP %d",
1527 adapter->device_mode,
1528 targetChannel,
1529 adapter->tx_flow_low_watermark,
1530 adapter->tx_flow_low_watermark +
1531 adapter->tx_flow_high_watermark_offset,
1532 hdd_ctx->config->TxFlowMaxQueueDepth);
1533 preAdapterChannel = targetChannel;
1534 preAdapterContext = adapter;
1535 } else {
1536 /*
1537 * SCC, disable TX flow control for both
1538 * SCC each adapter cannot reserve dedicated
1539 * channel resource, as a result, if any adapter
1540 * blocked OS Q by flow control,
1541 * blocked adapter will lost chance to recover
1542 */
1543 if (preAdapterChannel == targetChannel) {
1544 /* Current adapter */
1545 adapter->tx_flow_low_watermark = 0;
1546 adapter->
1547 tx_flow_high_watermark_offset = 0;
1548 cdp_fc_ll_set_tx_pause_q_depth(soc,
1549 adapter->sessionId,
1550 hdd_ctx->config->
1551 TxHbwFlowMaxQueueDepth);
1552 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1553 hdd_device_mode_to_string(
1554 adapter->device_mode),
1555 adapter->device_mode,
1556 targetChannel,
1557 adapter->tx_flow_low_watermark,
1558 adapter->tx_flow_low_watermark +
1559 adapter->
1560 tx_flow_high_watermark_offset,
1561 hdd_ctx->config->
1562 TxHbwFlowMaxQueueDepth);
1563
1564 if (!preAdapterContext) {
1565 cds_err("SCC: Previous adapter context NULL");
1566 continue;
1567 }
1568
1569 /* Previous adapter */
1570 preAdapterContext->
1571 tx_flow_low_watermark = 0;
1572 preAdapterContext->
1573 tx_flow_high_watermark_offset = 0;
1574 cdp_fc_ll_set_tx_pause_q_depth(soc,
1575 preAdapterContext->sessionId,
1576 hdd_ctx->config->
1577 TxHbwFlowMaxQueueDepth);
1578 cds_info("SCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1579 hdd_device_mode_to_string(
1580 preAdapterContext->device_mode
1581 ),
1582 preAdapterContext->device_mode,
1583 targetChannel,
1584 preAdapterContext->
1585 tx_flow_low_watermark,
1586 preAdapterContext->
1587 tx_flow_low_watermark +
1588 preAdapterContext->
1589 tx_flow_high_watermark_offset,
1590 hdd_ctx->config->
1591 TxHbwFlowMaxQueueDepth);
1592 }
1593 /*
1594 * MCC, each adapter will have dedicated
1595 * resource
1596 */
1597 else {
1598 /* current channel is 2.4 */
1599 if (targetChannel <=
1600 WLAN_HDD_TX_FLOW_CONTROL_MAX_24BAND_CH) {
1601 channel24 = targetChannel;
1602 channel5 = preAdapterChannel;
1603 adapter2_4 = adapter;
1604 adapter5 = preAdapterContext;
1605 } else {
1606 /* Current channel is 5 */
1607 channel24 = preAdapterChannel;
1608 channel5 = targetChannel;
1609 adapter2_4 = preAdapterContext;
1610 adapter5 = adapter;
1611 }
1612
1613 if (!adapter5) {
1614 cds_err("MCC: 5GHz adapter context NULL");
1615 continue;
1616 }
1617 adapter5->tx_flow_low_watermark =
1618 hdd_ctx->config->
1619 TxHbwFlowLowWaterMark;
1620 adapter5->
1621 tx_flow_high_watermark_offset =
1622 hdd_ctx->config->
1623 TxHbwFlowHighWaterMarkOffset;
1624 cdp_fc_ll_set_tx_pause_q_depth(soc,
1625 adapter5->sessionId,
1626 hdd_ctx->config->
1627 TxHbwFlowMaxQueueDepth);
1628 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1629 hdd_device_mode_to_string(
1630 adapter5->device_mode),
1631 adapter5->device_mode,
1632 channel5,
1633 adapter5->tx_flow_low_watermark,
1634 adapter5->
1635 tx_flow_low_watermark +
1636 adapter5->
1637 tx_flow_high_watermark_offset,
1638 hdd_ctx->config->
1639 TxHbwFlowMaxQueueDepth);
1640
1641 if (!adapter2_4) {
1642 cds_err("MCC: 2.4GHz adapter context NULL");
1643 continue;
1644 }
1645 adapter2_4->tx_flow_low_watermark =
1646 hdd_ctx->config->
1647 TxLbwFlowLowWaterMark;
1648 adapter2_4->
1649 tx_flow_high_watermark_offset =
1650 hdd_ctx->config->
1651 TxLbwFlowHighWaterMarkOffset;
1652 cdp_fc_ll_set_tx_pause_q_depth(soc,
1653 adapter2_4->sessionId,
1654 hdd_ctx->config->
1655 TxLbwFlowMaxQueueDepth);
1656 cds_info("MCC: MODE %s(%d), CH %d, LWM %d, HWM %d, TXQDEP %d",
1657 hdd_device_mode_to_string(
1658 adapter2_4->device_mode),
1659 adapter2_4->device_mode,
1660 channel24,
1661 adapter2_4->
1662 tx_flow_low_watermark,
1663 adapter2_4->
1664 tx_flow_low_watermark +
1665 adapter2_4->
1666 tx_flow_high_watermark_offset,
1667 hdd_ctx->config->
1668 TxLbwFlowMaxQueueDepth);
1669
1670 }
1671 }
1672 }
1673 targetChannel = 0;
1674#endif /* QCA_LL_LEGACY_TX_FLOW_CONTROL */
1675 status = hdd_get_next_adapter(hdd_ctx, adapterNode, &pNext);
1676 adapterNode = pNext;
1677 }
1678 hdd_ctx->mcc_mode = policy_mgr_current_concurrency_is_mcc(psoc);
1679}
1680
1681/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001682 * __hdd_ipa_uc_stat_query() - Query the IPA stats
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001683 * @hdd_ctx: Global HDD context
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001684 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1685 * @ipa_rx_diff: rx packet count diff from previous rx packet count
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001686 *
1687 * Return: true if IPA is enabled, false otherwise
1688 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001689static void __hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001690 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1691{
1692 struct hdd_ipa_priv *hdd_ipa;
1693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 *ipa_tx_diff = 0;
1695 *ipa_rx_diff = 0;
1696
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001697 if (wlan_hdd_validate_context(hdd_ctx))
1698 return;
1699
1700 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1701
1702 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1703 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 return;
1705 }
1706
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301707 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1709 (false == hdd_ipa->resource_loading)) {
1710 *ipa_tx_diff = hdd_ipa->ipa_tx_packets_diff;
1711 *ipa_rx_diff = hdd_ipa->ipa_rx_packets_diff;
Yun Parkb187d542016-11-14 18:10:04 -08001712 hdd_debug("STAT Query TX DIFF %d, RX DIFF %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001713 *ipa_tx_diff, *ipa_rx_diff);
1714 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301715 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001716}
1717
1718/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001719 * hdd_ipa_uc_stat_query() - SSR wrapper for __hdd_ipa_uc_stat_query
1720 * @hdd_ctx: Global HDD context
1721 * @ipa_tx_diff: tx packet count diff from previous tx packet count
1722 * @ipa_rx_diff: rx packet count diff from previous rx packet count
1723 *
1724 * Return: true if IPA is enabled, false otherwise
1725 */
1726void hdd_ipa_uc_stat_query(hdd_context_t *hdd_ctx,
1727 uint32_t *ipa_tx_diff, uint32_t *ipa_rx_diff)
1728{
1729 cds_ssr_protect(__func__);
1730 __hdd_ipa_uc_stat_query(hdd_ctx, ipa_tx_diff, ipa_rx_diff);
1731 cds_ssr_unprotect(__func__);
1732}
1733
1734/**
1735 * __hdd_ipa_uc_stat_request() - Get IPA stats from IPA.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001736 * @adapter: network adapter
1737 * @reason: STAT REQ Reason
1738 *
1739 * Return: None
1740 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001741static void __hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001742{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001743 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001744 struct hdd_ipa_priv *hdd_ipa;
1745
Yun Park637d6482016-10-05 10:51:33 -07001746 if (!adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001747 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001748
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001749 hdd_ctx = (hdd_context_t *)adapter->pHddCtx;
1750
1751 if (wlan_hdd_validate_context(hdd_ctx))
1752 return;
1753
1754 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
1755 if (!hdd_ipa_is_enabled(hdd_ctx) ||
1756 !(hdd_ipa_uc_is_enabled(hdd_ctx))) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001757 return;
1758 }
1759
Yun Parkb187d542016-11-14 18:10:04 -08001760 hdd_debug("STAT REQ Reason %d", reason);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05301761 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001762 if ((HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) &&
1763 (false == hdd_ipa->resource_loading)) {
1764 hdd_ipa->stat_req_reason = reason;
Yun Park637d6482016-10-05 10:51:33 -07001765 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001766 wma_cli_set_command(
1767 (int)adapter->sessionId,
1768 (int)WMA_VDEV_TXRX_GET_IPA_UC_FW_STATS_CMDID,
1769 0, VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001770 } else {
1771 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001772 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773}
1774
1775/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001776 * hdd_ipa_uc_stat_request() - SSR wrapper for __hdd_ipa_uc_stat_request
1777 * @adapter: network adapter
1778 * @reason: STAT REQ Reason
1779 *
1780 * Return: None
1781 */
1782void hdd_ipa_uc_stat_request(hdd_adapter_t *adapter, uint8_t reason)
1783{
1784 cds_ssr_protect(__func__);
1785 __hdd_ipa_uc_stat_request(adapter, reason);
1786 cds_ssr_unprotect(__func__);
1787}
1788
Yun Park637d6482016-10-05 10:51:33 -07001789#ifdef FEATURE_METERING
1790/**
1791 * hdd_ipa_uc_sharing_stats_request() - Get IPA stats from IPA.
1792 * @adapter: network adapter
1793 * @reset_stats: reset stat countis after response
1794 *
1795 * Return: None
1796 */
1797void hdd_ipa_uc_sharing_stats_request(hdd_adapter_t *adapter,
1798 uint8_t reset_stats)
1799{
1800 hdd_context_t *pHddCtx;
1801 struct hdd_ipa_priv *hdd_ipa;
1802
1803 if (!adapter)
1804 return;
1805
1806 pHddCtx = adapter->pHddCtx;
1807 hdd_ipa = pHddCtx->hdd_ipa;
1808 if (!hdd_ipa_is_enabled(pHddCtx) ||
1809 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1810 return;
1811 }
1812
1813 HDD_IPA_LOG(LOG1, "SHARING_STATS: reset_stats=%d", reset_stats);
1814 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001815 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001816 qdf_mutex_release(&hdd_ipa->ipa_lock);
1817 wma_cli_set_command(
1818 (int)adapter->sessionId,
1819 (int)WMA_VDEV_TXRX_GET_IPA_UC_SHARING_STATS_CMDID,
1820 reset_stats, VDEV_CMD);
1821 } else {
1822 qdf_mutex_release(&hdd_ipa->ipa_lock);
1823 }
1824}
1825
1826/**
1827 * hdd_ipa_uc_set_quota() - Set quota limit bytes from IPA.
1828 * @adapter: network adapter
1829 * @set_quota: when 1, FW starts quota monitoring
1830 * @quota_bytes: quota limit in bytes
1831 *
1832 * Return: None
1833 */
1834void hdd_ipa_uc_set_quota(hdd_adapter_t *adapter, uint8_t set_quota,
1835 uint64_t quota_bytes)
1836{
1837 hdd_context_t *pHddCtx;
1838 struct hdd_ipa_priv *hdd_ipa;
1839
1840 if (!adapter)
1841 return;
1842
1843 pHddCtx = adapter->pHddCtx;
1844 hdd_ipa = pHddCtx->hdd_ipa;
1845 if (!hdd_ipa_is_enabled(pHddCtx) ||
1846 !(hdd_ipa_uc_is_enabled(pHddCtx))) {
1847 return;
1848 }
1849
1850 HDD_IPA_LOG(LOG1, "SET_QUOTA: set_quota=%d, quota_bytes=%llu",
1851 set_quota, quota_bytes);
1852
1853 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Park3374a4b2016-12-15 16:52:15 -08001854 if (false == hdd_ipa->resource_loading) {
Yun Park637d6482016-10-05 10:51:33 -07001855 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park327e7812017-02-14 15:18:10 -08001856 wma_cli_set2_command(
Yun Park637d6482016-10-05 10:51:33 -07001857 (int)adapter->sessionId,
1858 (int)WMA_VDEV_TXRX_SET_IPA_UC_QUOTA_CMDID,
Yun Park327e7812017-02-14 15:18:10 -08001859 (set_quota ? quota_bytes&0xffffffff : 0),
1860 (set_quota ? quota_bytes>>32 : 0),
1861 VDEV_CMD);
Yun Park637d6482016-10-05 10:51:33 -07001862 } else {
1863 qdf_mutex_release(&hdd_ipa->ipa_lock);
1864 }
1865}
1866#endif
1867
Prakash Dhavali412cdb02016-10-20 21:19:31 -07001868/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001869 * hdd_ipa_uc_find_add_assoc_sta() - Find associated station
1870 * @hdd_ipa: Global HDD IPA context
1871 * @sta_add: Should station be added
1872 * @sta_id: ID of the station being queried
1873 *
1874 * Return: true if the station was found
1875 */
1876static bool hdd_ipa_uc_find_add_assoc_sta(struct hdd_ipa_priv *hdd_ipa,
1877 bool sta_add, uint8_t sta_id)
1878{
1879 bool sta_found = false;
1880 uint8_t idx;
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07001881
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001882 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1883 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1884 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1885 sta_found = true;
1886 break;
1887 }
1888 }
1889 if (sta_add && sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301890 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001891 "%s: STA ID %d already exist, cannot add",
1892 __func__, sta_id);
1893 return sta_found;
1894 }
1895 if (sta_add) {
1896 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1897 if (!hdd_ipa->assoc_stas_map[idx].is_reserved) {
1898 hdd_ipa->assoc_stas_map[idx].is_reserved = true;
1899 hdd_ipa->assoc_stas_map[idx].sta_id = sta_id;
1900 return sta_found;
1901 }
1902 }
1903 }
1904 if (!sta_add && !sta_found) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301905 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001906 "%s: STA ID %d does not exist, cannot delete",
1907 __func__, sta_id);
1908 return sta_found;
1909 }
1910 if (!sta_add) {
1911 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
1912 if ((hdd_ipa->assoc_stas_map[idx].is_reserved) &&
1913 (hdd_ipa->assoc_stas_map[idx].sta_id == sta_id)) {
1914 hdd_ipa->assoc_stas_map[idx].is_reserved =
1915 false;
1916 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
1917 return sta_found;
1918 }
1919 }
1920 }
1921 return sta_found;
1922}
1923
1924/**
1925 * hdd_ipa_uc_enable_pipes() - Enable IPA uC pipes
1926 * @hdd_ipa: Global HDD IPA context
1927 *
1928 * Return: 0 on success, negative errno if error
1929 */
1930static int hdd_ipa_uc_enable_pipes(struct hdd_ipa_priv *hdd_ipa)
1931{
1932 int result;
1933 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07001934 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001935
1936 /* ACTIVATE TX PIPE */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001937 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park4cab6ee2015-10-27 11:43:40 -07001938 "%s: Enable TX PIPE(tx_pipe_handle=%d)",
1939 __func__, hdd_ipa->tx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001940 result = ipa_enable_wdi_pipe(hdd_ipa->tx_pipe_handle);
1941 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301942 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001943 "%s: Enable TX PIPE fail, code %d",
1944 __func__, result);
1945 return result;
1946 }
1947 result = ipa_resume_wdi_pipe(hdd_ipa->tx_pipe_handle);
1948 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301949 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 "%s: Resume TX PIPE fail, code %d",
1951 __func__, result);
1952 return result;
1953 }
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001954 cdp_ipa_set_active(soc,
1955 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
1956 true, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957
1958 /* ACTIVATE RX PIPE */
Srinivas Girigowda97852372017-03-06 16:52:59 -08001959 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park4cab6ee2015-10-27 11:43:40 -07001960 "%s: Enable RX PIPE(rx_pipe_handle=%d)",
1961 __func__, hdd_ipa->rx_pipe_handle);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001962 result = ipa_enable_wdi_pipe(hdd_ipa->rx_pipe_handle);
1963 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301964 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001965 "%s: Enable RX PIPE fail, code %d",
1966 __func__, result);
1967 return result;
1968 }
1969 result = ipa_resume_wdi_pipe(hdd_ipa->rx_pipe_handle);
1970 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301971 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001972 "%s: Resume RX PIPE fail, code %d",
1973 __func__, result);
1974 return result;
1975 }
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08001976 cdp_ipa_set_active(soc,
1977 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
1978 true, false);
Leo Change3e49442015-10-26 20:07:13 -07001979 hdd_ipa->ipa_pipes_down = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001980 return 0;
1981}
1982
1983/**
1984 * hdd_ipa_uc_disable_pipes() - Disable IPA uC pipes
1985 * @hdd_ipa: Global HDD IPA context
1986 *
1987 * Return: 0 on success, negative errno if error
1988 */
1989static int hdd_ipa_uc_disable_pipes(struct hdd_ipa_priv *hdd_ipa)
1990{
1991 int result;
1992
Leo Change3e49442015-10-26 20:07:13 -07001993 hdd_ipa->ipa_pipes_down = true;
1994
Srinivas Girigowda97852372017-03-06 16:52:59 -08001995 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable RX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001996 result = ipa_suspend_wdi_pipe(hdd_ipa->rx_pipe_handle);
1997 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05301998 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001999 "%s: Suspend RX PIPE fail, code %d",
2000 __func__, result);
2001 return result;
2002 }
2003 result = ipa_disable_wdi_pipe(hdd_ipa->rx_pipe_handle);
2004 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302005 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002006 "%s: Disable RX PIPE fail, code %d",
2007 __func__, result);
2008 return result;
2009 }
2010
Srinivas Girigowda97852372017-03-06 16:52:59 -08002011 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable TX PIPE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002012 result = ipa_suspend_wdi_pipe(hdd_ipa->tx_pipe_handle);
2013 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302014 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002015 "%s: Suspend TX PIPE fail, code %d",
2016 __func__, result);
2017 return result;
2018 }
2019 result = ipa_disable_wdi_pipe(hdd_ipa->tx_pipe_handle);
2020 if (result) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302021 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002022 "%s: Disable TX PIPE fail, code %d",
2023 __func__, result);
2024 return result;
2025 }
2026
2027 return 0;
2028}
2029
2030/**
2031 * hdd_ipa_uc_handle_first_con() - Handle first uC IPA connection
2032 * @hdd_ipa: Global HDD IPA context
2033 *
2034 * Return: 0 on success, negative errno if error
2035 */
2036static int hdd_ipa_uc_handle_first_con(struct hdd_ipa_priv *hdd_ipa)
2037{
2038 hdd_ipa->activated_fw_pipe = 0;
2039 hdd_ipa->resource_loading = true;
Yun Park4cab6ee2015-10-27 11:43:40 -07002040
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002041 /* If RM feature enabled
2042 * Request PROD Resource first
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08002043 * PROD resource may return sync or async manners
2044 */
Yun Park4cab6ee2015-10-27 11:43:40 -07002045 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx)) {
2046 if (!ipa_rm_request_resource(IPA_RM_RESOURCE_WLAN_PROD)) {
2047 /* RM PROD request sync return
2048 * enable pipe immediately
2049 */
2050 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302051 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07002052 "%s: IPA WDI Pipe activation failed",
2053 __func__);
2054 hdd_ipa->resource_loading = false;
2055 return -EBUSY;
2056 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002057 }
2058 } else {
2059 /* RM Disabled
Yun Park4cab6ee2015-10-27 11:43:40 -07002060 * Just enabled all the PIPEs
2061 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002062 if (hdd_ipa_uc_enable_pipes(hdd_ipa)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302063 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park4cab6ee2015-10-27 11:43:40 -07002064 "%s: IPA WDI Pipe activation failed",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002065 __func__);
2066 hdd_ipa->resource_loading = false;
2067 return -EBUSY;
2068 }
2069 hdd_ipa->resource_loading = false;
2070 }
Yun Park4cab6ee2015-10-27 11:43:40 -07002071
Srinivas Girigowda97852372017-03-06 16:52:59 -08002072 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park4cab6ee2015-10-27 11:43:40 -07002073 "%s: IPA WDI Pipes activated successfully", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002074 return 0;
2075}
2076
2077/**
2078 * hdd_ipa_uc_handle_last_discon() - Handle last uC IPA disconnection
2079 * @hdd_ipa: Global HDD IPA context
2080 *
2081 * Return: None
2082 */
2083static void hdd_ipa_uc_handle_last_discon(struct hdd_ipa_priv *hdd_ipa)
2084{
2085 p_cds_contextType cds_ctx = hdd_ipa->hdd_ctx->pcds_context;
Leo Changfdb45c32016-10-28 11:09:23 -07002086 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002087
Yun Park7c4f31b2016-11-30 10:09:21 -08002088 if (!cds_ctx || !cds_ctx->pdev_txrx_ctx) {
2089 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "txrx context is NULL");
2090 QDF_ASSERT(0);
2091 return;
2092 }
2093
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002094 hdd_ipa->resource_unloading = true;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002095 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable FW RX PIPE", __func__);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08002096 cdp_ipa_set_active(soc,
2097 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
2098 false, false);
Srinivas Girigowda97852372017-03-06 16:52:59 -08002099 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Disable FW TX PIPE", __func__);
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08002100 cdp_ipa_set_active(soc,
2101 (struct cdp_pdev *)cds_ctx->pdev_txrx_ctx,
2102 false, true);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002103}
2104
2105/**
2106 * hdd_ipa_uc_rm_notify_handler() - IPA uC resource notification handler
2107 * @context: User context registered with TL (the IPA Global context is
2108 * registered
2109 * @rxpkt: Packet containing the notification
2110 * @staid: ID of the station associated with the packet
2111 *
2112 * Return: None
2113 */
2114static void
2115hdd_ipa_uc_rm_notify_handler(void *context, enum ipa_rm_event event)
2116{
2117 struct hdd_ipa_priv *hdd_ipa = context;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302118 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002119
2120 /*
2121 * When SSR is going on or driver is unloading, just return.
2122 */
2123 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302124 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002125 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002126
2127 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2128 return;
2129
Srinivas Girigowda97852372017-03-06 16:52:59 -08002130 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s, event code %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002131 __func__, event);
2132
2133 switch (event) {
2134 case IPA_RM_RESOURCE_GRANTED:
2135 /* Differed RM Granted */
2136 hdd_ipa_uc_enable_pipes(hdd_ipa);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302137 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002138 if ((false == hdd_ipa->resource_unloading) &&
2139 (!hdd_ipa->activated_fw_pipe)) {
2140 hdd_ipa_uc_enable_pipes(hdd_ipa);
2141 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302142 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002143 break;
2144
2145 case IPA_RM_RESOURCE_RELEASED:
2146 /* Differed RM Released */
2147 hdd_ipa->resource_unloading = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002148 break;
2149
2150 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302151 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002152 "%s, invalid event code %d", __func__, event);
2153 break;
2154 }
2155}
2156
2157/**
2158 * hdd_ipa_uc_rm_notify_defer() - Defer IPA uC notification
2159 * @hdd_ipa: Global HDD IPA context
2160 * @event: IPA resource manager event to be deferred
2161 *
2162 * This function is called when a resource manager event is received
2163 * from firmware in interrupt context. This function will defer the
2164 * handling to the OL RX thread
2165 *
2166 * Return: None
2167 */
2168static void hdd_ipa_uc_rm_notify_defer(struct work_struct *work)
2169{
2170 enum ipa_rm_event event;
2171 struct uc_rm_work_struct *uc_rm_work = container_of(work,
2172 struct uc_rm_work_struct, work);
2173 struct hdd_ipa_priv *hdd_ipa = container_of(uc_rm_work,
2174 struct hdd_ipa_priv, uc_rm_work);
2175
2176 cds_ssr_protect(__func__);
2177 event = uc_rm_work->event;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002178 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002179 "%s, posted event %d", __func__, event);
2180
2181 hdd_ipa_uc_rm_notify_handler(hdd_ipa, event);
2182 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002183}
2184
2185/**
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002186 * hdd_ipa_uc_loaded_handler() - Process IPA uC loaded indication
2187 * @ipa_ctxt: hdd ipa local context
2188 *
2189 * Will handle IPA UC image loaded indication comes from IPA kernel
2190 *
2191 * Return: None
2192 */
2193static void hdd_ipa_uc_loaded_handler(struct hdd_ipa_priv *ipa_ctxt)
2194{
2195 struct ipa_wdi_out_params pipe_out;
2196
2197 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s : UC READY", __func__);
2198 if (true == ipa_ctxt->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002199 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s : UC already loaded",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002200 __func__);
2201 return;
2202 }
2203
2204 ipa_ctxt->uc_loaded = true;
2205 /* Connect pipe */
2206 ipa_connect_wdi_pipe(&ipa_ctxt->cons_pipe_in, &pipe_out);
2207 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
2208 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
2209 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2210 "%s : TX PIPE Handle %d, DBPA 0x%llx",
2211 __func__, ipa_ctxt->tx_pipe_handle,
2212 (unsigned long long) pipe_out.uc_door_bell_pa);
2213
2214 ipa_connect_wdi_pipe(&ipa_ctxt->prod_pipe_in, &pipe_out);
2215 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
2216 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
2217 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2218 "%s : RX PIPE Handle %d, DBPA 0x%llx",
2219 __func__, ipa_ctxt->rx_pipe_handle,
2220 (unsigned long long) pipe_out.uc_door_bell_pa);
2221
2222 /* If already any STA connected, enable IPA/FW PIPEs */
2223 if (ipa_ctxt->sap_num_connected_sta) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002224 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002225 "Client already connected, enable IPA/FW PIPEs");
2226 hdd_ipa_uc_handle_first_con(ipa_ctxt);
2227 }
2228}
2229
2230/**
Yun Park637d6482016-10-05 10:51:33 -07002231 * hdd_ipa_uc_op_metering() - IPA uC operation for stats and quota limit
2232 * @hdd_ctx: Global HDD context
2233 * @op_msg: operation message received from firmware
2234 *
2235 * Return: QDF_STATUS enumeration
2236 */
2237#ifdef FEATURE_METERING
2238static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2239 struct op_msg_type *op_msg)
2240{
2241 struct op_msg_type *msg = op_msg;
2242 struct ipa_uc_sharing_stats *uc_sharing_stats;
2243 struct ipa_uc_quota_rsp *uc_quota_rsp;
2244 struct ipa_uc_quota_ind *uc_quota_ind;
2245 struct hdd_ipa_priv *hdd_ipa;
2246 hdd_adapter_t *adapter;
2247
2248 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2249
2250 if (HDD_IPA_UC_OPCODE_SHARING_STATS == msg->op_code) {
2251 /* fill-up ipa_uc_sharing_stats structure from FW */
2252 uc_sharing_stats = (struct ipa_uc_sharing_stats *)
2253 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2254
2255 memcpy(&(hdd_ipa->ipa_sharing_stats), uc_sharing_stats,
2256 sizeof(struct ipa_uc_sharing_stats));
2257
2258 complete(&hdd_ipa->ipa_uc_sharing_stats_comp);
2259
2260 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2261 "%s: %llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2262 "HDD_IPA_UC_OPCODE_SHARING_STATS",
2263 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets,
2264 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes,
2265 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets,
2266 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes,
2267 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets,
2268 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes,
2269 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets,
2270 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes);
2271 } else if (HDD_IPA_UC_OPCODE_QUOTA_RSP == msg->op_code) {
2272 /* received set quota response */
2273 uc_quota_rsp = (struct ipa_uc_quota_rsp *)
2274 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2275
2276 memcpy(&(hdd_ipa->ipa_quota_rsp), uc_quota_rsp,
2277 sizeof(struct ipa_uc_quota_rsp));
2278
2279 complete(&hdd_ipa->ipa_uc_set_quota_comp);
2280 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2281 "%s: success=%d, quota_bytes=%llu",
2282 "HDD_IPA_UC_OPCODE_QUOTA_RSP",
2283 hdd_ipa->ipa_quota_rsp.success,
2284 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)<<32)|
2285 hdd_ipa->ipa_quota_rsp.quota_lo);
2286 } else if (HDD_IPA_UC_OPCODE_QUOTA_IND == msg->op_code) {
2287 /* hit quota limit */
2288 uc_quota_ind = (struct ipa_uc_quota_ind *)
2289 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
2290
2291 hdd_ipa->ipa_quota_ind.quota_bytes =
2292 uc_quota_ind->quota_bytes;
2293
2294 /* send quota exceeded indication to IPA */
2295 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2296 "OPCODE_QUOTA_IND: quota exceed! (quota_bytes=%llu)",
2297 hdd_ipa->ipa_quota_ind.quota_bytes);
2298
2299 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2300 if (adapter)
2301 ipa_broadcast_wdi_quota_reach_ind(
2302 adapter->dev->ifindex,
2303 uc_quota_ind->quota_bytes);
2304 else
2305 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2306 "Failed quota_reach_ind: NULL adapter");
2307 } else {
2308 return QDF_STATUS_E_INVAL;
2309 }
2310
2311 return QDF_STATUS_SUCCESS;
2312}
2313#else
2314static QDF_STATUS hdd_ipa_uc_op_metering(hdd_context_t *hdd_ctx,
2315 struct op_msg_type *op_msg)
2316{
2317 return QDF_STATUS_E_INVAL;
2318}
2319#endif
2320
2321/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002322 * hdd_ipa_uc_op_cb() - IPA uC operation callback
2323 * @op_msg: operation message received from firmware
2324 * @usr_ctxt: user context registered with TL (we register the HDD Global
2325 * context)
2326 *
2327 * Return: None
2328 */
2329static void hdd_ipa_uc_op_cb(struct op_msg_type *op_msg, void *usr_ctxt)
2330{
2331 struct op_msg_type *msg = op_msg;
2332 struct ipa_uc_fw_stats *uc_fw_stat;
2333 struct IpaHwStatsWDIInfoData_t ipa_stat;
2334 struct hdd_ipa_priv *hdd_ipa;
2335 hdd_context_t *hdd_ctx;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302336 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002337
2338 if (!op_msg || !usr_ctxt) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302339 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s, INVALID ARG", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002340 return;
2341 }
2342
2343 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302344 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002345 "%s, INVALID OPCODE %d", __func__, msg->op_code);
2346 return;
2347 }
2348
2349 hdd_ctx = (hdd_context_t *) usr_ctxt;
2350
2351 /*
2352 * When SSR is going on or driver is unloading, just return.
2353 */
2354 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302355 if (status) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302356 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002357 return;
2358 }
2359
2360 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
2361
Govind Singhb6a89772016-08-12 11:23:35 +05302362 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park5f0fc232017-02-10 10:34:57 -08002363 "OPCODE=%d", msg->op_code);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002364
2365 if ((HDD_IPA_UC_OPCODE_TX_RESUME == msg->op_code) ||
2366 (HDD_IPA_UC_OPCODE_RX_RESUME == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302367 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002368 hdd_ipa->activated_fw_pipe++;
2369 if (HDD_IPA_UC_NUM_WDI_PIPE == hdd_ipa->activated_fw_pipe) {
2370 hdd_ipa->resource_loading = false;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08002371 if (hdd_ipa->wdi_enabled == false) {
2372 hdd_ipa->wdi_enabled = true;
2373 if (hdd_ipa_uc_send_wdi_control_msg(true) == 0)
2374 hdd_ipa_send_mcc_scc_msg(hdd_ctx,
2375 hdd_ctx->mcc_mode);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002376 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002377 hdd_ipa_uc_proc_pending_event(hdd_ipa);
Yun Parkccc6d7a2015-12-02 14:50:13 -08002378 if (hdd_ipa->pending_cons_req)
2379 ipa_rm_notify_completion(
2380 IPA_RM_RESOURCE_GRANTED,
2381 IPA_RM_RESOURCE_WLAN_CONS);
Yun Park5b635012015-12-02 15:05:01 -08002382 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002383 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302384 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002385 } else if ((HDD_IPA_UC_OPCODE_TX_SUSPEND == msg->op_code) ||
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002386 (HDD_IPA_UC_OPCODE_RX_SUSPEND == msg->op_code)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302387 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002388 hdd_ipa->activated_fw_pipe--;
2389 if (!hdd_ipa->activated_fw_pipe) {
2390 hdd_ipa_uc_disable_pipes(hdd_ipa);
Yun Park5b635012015-12-02 15:05:01 -08002391 if (hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
2392 ipa_rm_release_resource(
2393 IPA_RM_RESOURCE_WLAN_PROD);
Jeff Johnsonfaa63b82017-01-12 09:46:43 -08002394 /*
2395 * Sync return success from IPA
2396 * Enable/resume all the PIPEs
2397 */
Yun Park5b635012015-12-02 15:05:01 -08002398 hdd_ipa->resource_unloading = false;
2399 hdd_ipa_uc_proc_pending_event(hdd_ipa);
2400 hdd_ipa->pending_cons_req = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002401 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302402 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park8292dcb2016-10-07 16:46:06 -07002403 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002404 (HDD_IPA_UC_STAT_REASON_DEBUG == hdd_ipa->stat_req_reason)) {
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002405 struct ol_txrx_ipa_resources *res = &hdd_ipa->ipa_resource;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002406 /* STATs from host */
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302407 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002408 "==== IPA_UC WLAN_HOST CE ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002409 "CE RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002410 "CE RING SIZE: %d\n"
2411 "CE REG ADDR : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002412 (unsigned long long)res->ce_sr_base_paddr,
2413 res->ce_sr_ring_size,
2414 (unsigned long long)res->ce_reg_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302415 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002416 "==== IPA_UC WLAN_HOST TX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002417 "COMP RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002418 "COMP RING SIZE: %d\n"
2419 "NUM ALLOC BUF: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002420 "COMP RING DBELL : 0x%llx",
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002421 (unsigned long long)res->tx_comp_ring_base_paddr,
2422 res->tx_comp_ring_size,
2423 res->tx_num_alloc_buffer,
Manikandan Mohan22b83722015-12-15 15:03:23 -08002424 (unsigned long long)hdd_ipa->tx_comp_doorbell_paddr);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302425 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002426 "==== IPA_UC WLAN_HOST RX ====\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002427 "IND RING BASE: 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002428 "IND RING SIZE: %d\n"
Leo Chang3bc8fed2015-11-13 10:59:47 -08002429 "IND RING DBELL : 0x%llx\n"
2430 "PROC DONE IND ADDR : 0x%llx\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002431 "NUM EXCP PKT : %llu\n"
Yun Parkb187d542016-11-14 18:10:04 -08002432 "NUM TX FWD OK : %llu\n"
2433 "NUM TX FWD ERR : %llu",
Yun Park8b2bc4b2016-12-18 16:58:33 -08002434 (unsigned long long)res->rx_rdy_ring_base_paddr,
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002435 res->rx_rdy_ring_size,
Yun Park8b2bc4b2016-12-18 16:58:33 -08002436 (unsigned long long)hdd_ipa->rx_ready_doorbell_paddr,
2437 (unsigned long long)res->rx_proc_done_idx_paddr,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002438 hdd_ipa->stats.num_rx_excep,
Yun Parkb187d542016-11-14 18:10:04 -08002439 hdd_ipa->stats.num_tx_fwd_ok,
2440 hdd_ipa->stats.num_tx_fwd_err);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302441 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002442 "==== IPA_UC WLAN_HOST CONTROL ====\n"
2443 "SAP NUM STAs: %d\n"
2444 "STA CONNECTED: %d\n"
Yun Parkb187d542016-11-14 18:10:04 -08002445 "CONCURRENT MODE: %s\n"
2446 "TX PIPE HDL: 0x%x\n"
2447 "RX PIPE HDL : 0x%x\n"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002448 "RSC LOADING : %d\n"
2449 "RSC UNLOADING : %d\n"
2450 "PNDNG CNS RQT : %d",
2451 hdd_ipa->sap_num_connected_sta,
2452 hdd_ipa->sta_connected,
Yun Parkb187d542016-11-14 18:10:04 -08002453 (hdd_ctx->mcc_mode ? "MCC" : "SCC"),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002454 hdd_ipa->tx_pipe_handle,
2455 hdd_ipa->rx_pipe_handle,
Yun Parkb187d542016-11-14 18:10:04 -08002456 hdd_ipa->resource_loading,
2457 hdd_ipa->resource_unloading,
2458 hdd_ipa->pending_cons_req);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002459
2460 /* STATs from FW */
2461 uc_fw_stat = (struct ipa_uc_fw_stats *)
2462 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302463 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002464 "==== IPA_UC WLAN_FW TX ====\n"
2465 "COMP RING BASE: 0x%x\n"
2466 "COMP RING SIZE: %d\n"
2467 "COMP RING DBELL : 0x%x\n"
2468 "COMP RING DBELL IND VAL : %d\n"
2469 "COMP RING DBELL CACHED VAL : %d\n"
2470 "COMP RING DBELL CACHED VAL : %d\n"
2471 "PKTS ENQ : %d\n"
2472 "PKTS COMP : %d\n"
2473 "IS SUSPEND : %d\n"
2474 "RSVD : 0x%x",
2475 uc_fw_stat->tx_comp_ring_base,
2476 uc_fw_stat->tx_comp_ring_size,
2477 uc_fw_stat->tx_comp_ring_dbell_addr,
2478 uc_fw_stat->tx_comp_ring_dbell_ind_val,
2479 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2480 uc_fw_stat->tx_comp_ring_dbell_cached_val,
2481 uc_fw_stat->tx_pkts_enqueued,
2482 uc_fw_stat->tx_pkts_completed,
Yun Parkb187d542016-11-14 18:10:04 -08002483 uc_fw_stat->tx_is_suspend,
2484 uc_fw_stat->tx_reserved);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302485 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002486 "==== IPA_UC WLAN_FW RX ====\n"
2487 "IND RING BASE: 0x%x\n"
2488 "IND RING SIZE: %d\n"
2489 "IND RING DBELL : 0x%x\n"
2490 "IND RING DBELL IND VAL : %d\n"
2491 "IND RING DBELL CACHED VAL : %d\n"
2492 "RDY IND ADDR : 0x%x\n"
2493 "RDY IND CACHE VAL : %d\n"
2494 "RFIL IND : %d\n"
2495 "NUM PKT INDICAT : %d\n"
2496 "BUF REFIL : %d\n"
2497 "NUM DROP NO SPC : %d\n"
2498 "NUM DROP NO BUF : %d\n"
2499 "IS SUSPND : %d\n"
2500 "RSVD : 0x%x\n",
2501 uc_fw_stat->rx_ind_ring_base,
2502 uc_fw_stat->rx_ind_ring_size,
2503 uc_fw_stat->rx_ind_ring_dbell_addr,
2504 uc_fw_stat->rx_ind_ring_dbell_ind_val,
2505 uc_fw_stat->rx_ind_ring_dbell_ind_cached_val,
2506 uc_fw_stat->rx_ind_ring_rdidx_addr,
2507 uc_fw_stat->rx_ind_ring_rd_idx_cached_val,
2508 uc_fw_stat->rx_refill_idx,
2509 uc_fw_stat->rx_num_pkts_indicated,
2510 uc_fw_stat->rx_buf_refilled,
2511 uc_fw_stat->rx_num_ind_drop_no_space,
2512 uc_fw_stat->rx_num_ind_drop_no_buf,
Yun Parkb187d542016-11-14 18:10:04 -08002513 uc_fw_stat->rx_is_suspend,
2514 uc_fw_stat->rx_reserved);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002515 /* STATs from IPA */
2516 ipa_get_wdi_stats(&ipa_stat);
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302517 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002518 "==== IPA_UC IPA TX ====\n"
2519 "NUM PROCD : %d\n"
2520 "CE DBELL : 0x%x\n"
2521 "NUM DBELL FIRED : %d\n"
2522 "COMP RNG FULL : %d\n"
2523 "COMP RNG EMPT : %d\n"
2524 "COMP RNG USE HGH : %d\n"
2525 "COMP RNG USE LOW : %d\n"
2526 "BAM FIFO FULL : %d\n"
2527 "BAM FIFO EMPT : %d\n"
2528 "BAM FIFO USE HGH : %d\n"
2529 "BAM FIFO USE LOW : %d\n"
2530 "NUM DBELL : %d\n"
2531 "NUM UNEXP DBELL : %d\n"
2532 "NUM BAM INT HDL : 0x%x\n"
2533 "NUM BAM INT NON-RUN : 0x%x\n"
2534 "NUM QMB INT HDL : 0x%x",
2535 ipa_stat.tx_ch_stats.num_pkts_processed,
2536 ipa_stat.tx_ch_stats.copy_engine_doorbell_value,
2537 ipa_stat.tx_ch_stats.num_db_fired,
2538 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringFull,
2539 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringEmpty,
2540 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageHigh,
2541 ipa_stat.tx_ch_stats.tx_comp_ring_stats.ringUsageLow,
2542 ipa_stat.tx_ch_stats.bam_stats.bamFifoFull,
2543 ipa_stat.tx_ch_stats.bam_stats.bamFifoEmpty,
2544 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageHigh,
2545 ipa_stat.tx_ch_stats.bam_stats.bamFifoUsageLow,
2546 ipa_stat.tx_ch_stats.num_db,
2547 ipa_stat.tx_ch_stats.num_unexpected_db,
2548 ipa_stat.tx_ch_stats.num_bam_int_handled,
2549 ipa_stat.tx_ch_stats.
2550 num_bam_int_in_non_runnning_state,
2551 ipa_stat.tx_ch_stats.num_qmb_int_handled);
2552
Anurag Chouhandf2b2682016-02-29 14:15:27 +05302553 QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002554 "==== IPA_UC IPA RX ====\n"
2555 "MAX OST PKT : %d\n"
2556 "NUM PKT PRCSD : %d\n"
2557 "RNG RP : 0x%x\n"
2558 "COMP RNG FULL : %d\n"
2559 "COMP RNG EMPT : %d\n"
2560 "COMP RNG USE HGH : %d\n"
2561 "COMP RNG USE LOW : %d\n"
2562 "BAM FIFO FULL : %d\n"
2563 "BAM FIFO EMPT : %d\n"
2564 "BAM FIFO USE HGH : %d\n"
2565 "BAM FIFO USE LOW : %d\n"
2566 "NUM DB : %d\n"
2567 "NUM UNEXP DB : %d\n"
2568 "NUM BAM INT HNDL : 0x%x\n",
2569 ipa_stat.rx_ch_stats.max_outstanding_pkts,
2570 ipa_stat.rx_ch_stats.num_pkts_processed,
2571 ipa_stat.rx_ch_stats.rx_ring_rp_value,
2572 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringFull,
2573 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringEmpty,
2574 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageHigh,
2575 ipa_stat.rx_ch_stats.rx_ind_ring_stats.ringUsageLow,
2576 ipa_stat.rx_ch_stats.bam_stats.bamFifoFull,
2577 ipa_stat.rx_ch_stats.bam_stats.bamFifoEmpty,
2578 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageHigh,
2579 ipa_stat.rx_ch_stats.bam_stats.bamFifoUsageLow,
2580 ipa_stat.rx_ch_stats.num_db,
2581 ipa_stat.rx_ch_stats.num_unexpected_db,
2582 ipa_stat.rx_ch_stats.num_bam_int_handled);
2583 } else if ((HDD_IPA_UC_OPCODE_STATS == msg->op_code) &&
2584 (HDD_IPA_UC_STAT_REASON_BW_CAL == hdd_ipa->stat_req_reason)) {
2585 /* STATs from FW */
2586 uc_fw_stat = (struct ipa_uc_fw_stats *)
2587 ((uint8_t *)op_msg + sizeof(struct op_msg_type));
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302588 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002589 hdd_ipa->ipa_tx_packets_diff = HDD_BW_GET_DIFF(
2590 uc_fw_stat->tx_pkts_completed,
2591 hdd_ipa->ipa_p_tx_packets);
2592 hdd_ipa->ipa_rx_packets_diff = HDD_BW_GET_DIFF(
2593 (uc_fw_stat->rx_num_ind_drop_no_space +
2594 uc_fw_stat->rx_num_ind_drop_no_buf +
2595 uc_fw_stat->rx_num_pkts_indicated),
2596 hdd_ipa->ipa_p_rx_packets);
2597
2598 hdd_ipa->ipa_p_tx_packets = uc_fw_stat->tx_pkts_completed;
2599 hdd_ipa->ipa_p_rx_packets =
2600 (uc_fw_stat->rx_num_ind_drop_no_space +
2601 uc_fw_stat->rx_num_ind_drop_no_buf +
2602 uc_fw_stat->rx_num_pkts_indicated);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05302603 qdf_mutex_release(&hdd_ipa->ipa_lock);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002604 } else if (msg->op_code == HDD_IPA_UC_OPCODE_UC_READY) {
2605 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
2606 hdd_ipa_uc_loaded_handler(hdd_ipa);
2607 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park637d6482016-10-05 10:51:33 -07002608 } else if (hdd_ipa_uc_op_metering(hdd_ctx, op_msg)) {
2609 HDD_IPA_LOG(LOGE, "Invalid message: op_code=%d, reason=%d",
2610 msg->op_code, hdd_ipa->stat_req_reason);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002611 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302612 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002613}
2614
2615
2616/**
2617 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2618 * @adapter: device adapter instance
2619 * @offload_type: MCC or SCC
2620 * @enable: TX offload enable or disable
2621 *
2622 * Return: none
2623 */
2624static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002625 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002626{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002627 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002628 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002629 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002630 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002631
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002632 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002633 return;
2634
Yun Park8292dcb2016-10-07 16:46:06 -07002635 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002636 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002637
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002638 if (!iface_context) {
2639 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2640 "Interface context is NULL");
2641 return;
2642 }
2643
2644 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002645 /* IPA offload status is already set as desired */
2646 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002647 "%s: (offload_type=%d, vdev_id=%d, enable=%d)",
2648 "IPA offload status is already set",
2649 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002650 return;
2651 }
2652
Yun Park4540e862016-11-10 16:30:06 -08002653 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2654 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2655 "invalid session id: %d, offload_type=%d, enable=%d",
2656 adapter->sessionId, offload_type, enable);
2657 return;
2658 }
2659
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302660 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002661 sizeof(ipa_offload_enable_disable));
2662 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002663 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002664 ipa_offload_enable_disable.enable = enable;
2665
Srinivas Girigowda97852372017-03-06 16:52:59 -08002666 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002667 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002668 ipa_offload_enable_disable.offload_type,
2669 ipa_offload_enable_disable.vdev_id,
2670 ipa_offload_enable_disable.enable);
2671
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302672 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002673 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2674 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302675 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002676 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
2677 __func__,
2678 ipa_offload_enable_disable.offload_type,
2679 ipa_offload_enable_disable.vdev_id,
2680 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002681 } else {
2682 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002683 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002684 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002685 }
2686}
2687
2688/**
2689 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2690 * @work: uC OP work
2691 *
2692 * Return: None
2693 */
2694static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2695{
2696 struct op_msg_type *msg;
2697 struct uc_op_work_struct *uc_op_work = container_of(work,
2698 struct uc_op_work_struct, work);
2699 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2700
2701 cds_ssr_protect(__func__);
2702
2703 msg = uc_op_work->msg;
2704 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002705 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002706 "%s, posted msg %d", __func__, msg->op_code);
2707
2708 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2709
2710 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002711}
2712
2713/**
2714 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2715 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2716 * @op_msg: operation message received from firmware
2717 * @hdd_ctx: Global HDD context
2718 *
2719 * Return: None
2720 */
2721static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2722{
2723 struct hdd_ipa_priv *hdd_ipa;
2724 struct op_msg_type *msg;
2725 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302726 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002727
2728 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302729 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002730 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002731
2732 msg = (struct op_msg_type *)op_msg;
2733 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
2734
2735 if (unlikely(!hdd_ipa))
2736 goto end;
2737
2738 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302739 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002740 __func__, msg->op_code);
2741 goto end;
2742 }
2743
2744 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2745 if (uc_op_work->msg)
2746 /* When the same uC OPCODE is already pended, just return */
2747 goto end;
2748
2749 uc_op_work->msg = msg;
2750 schedule_work(&uc_op_work->work);
2751 return;
2752
2753end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302754 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002755}
2756
2757/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002758 * hdd_ipa_init_uc_op_work - init ipa uc op work
2759 * @work: struct work_struct
2760 * @work_handler: work_handler
2761 *
2762 * Return: none
2763 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002764static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002765 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002766{
2767 INIT_WORK(work, work_handler);
2768}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002769
Yun Park637d6482016-10-05 10:51:33 -07002770#ifdef FEATURE_METERING
2771/**
2772 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2773 * IPA calls to get WLAN stats or set quota limit.
2774 * @priv: pointer to private data registered with IPA (we register a
2775 *» pointer to the global IPA context)
2776 * @evt: the IPA event which triggered the callback
2777 * @data: data associated with the event
2778 *
2779 * Return: None
2780 */
2781static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2782 void *data)
2783{
2784 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2785 hdd_adapter_t *adapter = NULL;
2786 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2787 struct ipa_set_wifi_quota *ipa_set_quota;
2788 int ret = 0;
2789
2790 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2791 return;
2792
2793 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2794
2795 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2796
2797 switch (evt) {
2798 case IPA_GET_WDI_SAP_STATS:
2799 /* fill-up ipa_get_wdi_sap_stats structure after getting
2800 ipa_uc_fw_stats from FW */
2801 wdi_sap_stats = data;
2802
2803 if (!adapter) {
2804 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2805 "IPA uC share stats failed - no adapter");
2806 wdi_sap_stats->stats_valid = 0;
2807 return;
2808 }
2809
2810 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
2811 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
2812 hdd_ipa_uc_sharing_stats_request(adapter,
2813 wdi_sap_stats->reset_stats);
2814 ret = wait_for_completion_timeout(
2815 &hdd_ipa->ipa_uc_sharing_stats_comp,
2816 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2817 if (!ret) {
2818 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2819 "IPA uC share stats request timed out");
2820 wdi_sap_stats->stats_valid = 0;
2821 } else {
2822 wdi_sap_stats->stats_valid = 1;
2823
2824 wdi_sap_stats->ipv4_rx_packets =
2825 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2826 wdi_sap_stats->ipv4_rx_bytes =
2827 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2828 wdi_sap_stats->ipv6_rx_packets =
2829 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2830 wdi_sap_stats->ipv6_rx_bytes =
2831 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2832 wdi_sap_stats->ipv4_tx_packets =
2833 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2834 wdi_sap_stats->ipv4_tx_bytes =
2835 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2836 wdi_sap_stats->ipv6_tx_packets =
2837 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2838 wdi_sap_stats->ipv6_tx_bytes =
2839 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2840 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2841 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2842 "IPA_GET_WDI_SAP_STATS",
2843 wdi_sap_stats->stats_valid,
2844 wdi_sap_stats->ipv4_rx_packets,
2845 wdi_sap_stats->ipv4_rx_bytes,
2846 wdi_sap_stats->ipv6_rx_packets,
2847 wdi_sap_stats->ipv6_rx_bytes,
2848 wdi_sap_stats->ipv4_tx_packets,
2849 wdi_sap_stats->ipv4_tx_bytes,
2850 wdi_sap_stats->ipv6_tx_packets,
2851 wdi_sap_stats->ipv6_tx_bytes);
2852 }
2853 break;
2854 case IPA_SET_WIFI_QUOTA:
2855 /* get ipa_set_wifi_quota structure from IPA and pass to FW
2856 through quota_exceeded field in ipa_uc_fw_stats */
2857 ipa_set_quota = data;
2858
2859 if (!adapter) {
2860 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2861 "IPA uC set quota failed - no adapter");
2862 ipa_set_quota->set_valid = 0;
2863 return;
2864 }
2865
2866 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2867 ipa_set_quota->quota_bytes);
2868
2869 ret = wait_for_completion_timeout(
2870 &hdd_ipa->ipa_uc_set_quota_comp,
2871 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2872 if (!ret) {
2873 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2874 "IPA uC set quota request timed out");
2875 ipa_set_quota->set_valid = 0;
2876 } else {
2877 ipa_set_quota->quota_bytes =
2878 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2879 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2880 ipa_set_quota->set_valid =
2881 hdd_ipa->ipa_quota_rsp.success;
2882 }
2883
2884 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2885 ipa_set_quota->quota_bytes,
2886 ipa_set_quota->set_valid);
2887 break;
2888 }
2889}
2890
2891/**
2892 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2893 * IPA calls to get WLAN stats or set quota limit.
2894 * @priv: pointer to private data registered with IPA (we register a
2895 *» pointer to the global IPA context)
2896 * @evt: the IPA event which triggered the callback
2897 * @data: data associated with the event
2898 *
2899 * Return: None
2900 */
2901static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2902 void *data)
2903{
2904 cds_ssr_protect(__func__);
2905 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2906 cds_ssr_unprotect(__func__);
2907}
2908
2909static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt,
2910 struct ipa_wdi_in_params *pipe_in)
2911{
2912 pipe_in->wdi_notify = hdd_ipa_wdi_meter_notifier_cb;
2913
2914 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2915 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2916}
2917#else
2918static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt,
2919 struct ipa_wdi_in_params *pipe_in)
2920{
2921}
2922#endif
2923
Rajeev Kumar217f2172016-01-06 18:11:55 -08002924/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002925 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2926 * @hdd_ctx: Global HDD context
2927 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002928 * This function is called to update IPA pipe configuration with resources
2929 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2930 * (cds_enable)
2931 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302932 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002933 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002934QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002935{
2936 struct ipa_wdi_in_params pipe_in;
2937 struct ipa_wdi_out_params pipe_out;
2938 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002939 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002940 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
2941 int ret;
2942 QDF_STATUS stat = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002943
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002944 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2945 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002946
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002947 ENTER();
2948 /* Do only IPA Pipe specific configuration here. All one time
2949 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2950 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2951 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002952 if (!pdev || !soc) {
2953 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkbaa62862017-01-18 13:43:34 -08002954 stat = QDF_STATUS_E_FAILURE;
2955 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002956 }
Yun Parkbaa62862017-01-18 13:43:34 -08002957
2958 cdp_ipa_get_resource(soc, (void *)pdev, &ipa_ctxt->ipa_resource);
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002959 if ((ipa_ctxt->ipa_resource.ce_sr_base_paddr == 0) ||
2960 (ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr == 0) ||
2961 (ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr == 0) ||
2962 (ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr == 0)) {
2963 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2964 "IPA UC resource alloc fail");
2965 return QDF_STATUS_E_FAILURE;
2966 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002967 qdf_mem_zero(&ipa_ctxt->cons_pipe_in, sizeof(struct ipa_wdi_in_params));
2968 qdf_mem_zero(&ipa_ctxt->prod_pipe_in, sizeof(struct ipa_wdi_in_params));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302969 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
2970 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002971
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002972 /* TX PIPE */
2973 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2974 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
2975 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2976 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2977 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
2978 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
2979 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
2980 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
2981 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
2982 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
2983 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
2984 pipe_in.sys.notify = hdd_ipa_i2w_cb;
2985 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002986 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
2987 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002988 pipe_in.sys.keep_ipa_awake = true;
2989 }
2990
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002991 pipe_in.u.dl.comp_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002992 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002993 pipe_in.u.dl.comp_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08002994 ipa_ctxt->ipa_resource.tx_comp_ring_size *
2995 sizeof(qdf_dma_addr_t);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002996 pipe_in.u.dl.ce_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002997 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002998 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
2999 pipe_in.u.dl.ce_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08003000 ipa_ctxt->ipa_resource.ce_sr_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003001 pipe_in.u.dl.num_tx_buffers =
Yun Parkbaa62862017-01-18 13:43:34 -08003002 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003003
Yun Parkbaa62862017-01-18 13:43:34 -08003004 qdf_mem_copy(&ipa_ctxt->cons_pipe_in, &pipe_in,
3005 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003006 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->tx_comp_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08003007 IPA_CLIENT_WLAN1_CONS);
3008
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003009 if (true == ipa_ctxt->uc_loaded) {
3010 /* Connect WDI IPA PIPE */
Yun Parkbaa62862017-01-18 13:43:34 -08003011 ret = ipa_connect_wdi_pipe(&ipa_ctxt->cons_pipe_in, &pipe_out);
3012 if (ret) {
3013 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3014 "ipa_connect_wdi_pipe falied for Tx: ret=%d",
3015 ret);
3016 stat = QDF_STATUS_E_FAILURE;
3017 goto fail_return;
3018 }
Yun Park637d6482016-10-05 10:51:33 -07003019
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003020 /* Micro Controller Doorbell register */
Srinivas Girigowda97852372017-03-06 16:52:59 -08003021 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003022 "CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
3023 (unsigned int)pipe_out.uc_door_bell_pa,
3024 ipa_ctxt->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003025 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Yun Parkbaa62862017-01-18 13:43:34 -08003026
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003027 /* WLAN TX PIPE Handle */
3028 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Srinivas Girigowda97852372017-03-06 16:52:59 -08003029 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003030 "TX: %s 0x%x, %s %d, %s 0x%x, %s 0x%x, %s %d, %s %d, %s 0x%x",
3031 "comp_ring_base_pa",
3032 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
3033 "comp_ring_size",
3034 pipe_in.u.dl.comp_ring_size,
3035 "ce_ring_base_pa",
3036 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
3037 "ce_door_bell_pa",
3038 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
3039 "ce_ring_size",
3040 pipe_in.u.dl.ce_ring_size,
3041 "num_tx_buffers",
3042 pipe_in.u.dl.num_tx_buffers,
3043 "tx_comp_doorbell_paddr",
3044 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003045 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003046
3047 /* RX PIPE */
3048 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3049 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
3050 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
3051 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
3052 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
3053 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
3054 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
3055 sizeof(struct sps_iovec);
3056 pipe_in.sys.notify = hdd_ipa_w2i_cb;
3057 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303058 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkbaa62862017-01-18 13:43:34 -08003059 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003060 pipe_in.sys.keep_ipa_awake = true;
3061 }
3062
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003063 pipe_in.u.ul.rdy_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08003064 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003065 pipe_in.u.ul.rdy_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08003066 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003067 pipe_in.u.ul.rdy_ring_rp_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08003068 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08003069 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Yun Parkbaa62862017-01-18 13:43:34 -08003070
Yun Park637d6482016-10-05 10:51:33 -07003071 hdd_ipa_init_metering(ipa_ctxt, &pipe_in);
3072
Yun Parkbaa62862017-01-18 13:43:34 -08003073 qdf_mem_copy(&ipa_ctxt->prod_pipe_in, &pipe_in,
3074 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003075 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->rx_ready_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08003076 IPA_CLIENT_WLAN1_PROD);
3077
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003078 if (true == ipa_ctxt->uc_loaded) {
Yun Parkbaa62862017-01-18 13:43:34 -08003079 ret = ipa_connect_wdi_pipe(&ipa_ctxt->prod_pipe_in, &pipe_out);
3080 if (ret) {
3081 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3082 "ipa_connect_wdi_pipe falied for Rx: ret=%d",
3083 ret);
3084 stat = QDF_STATUS_E_FAILURE;
3085 goto fail_return;
3086
3087 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003088 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
3089 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Srinivas Girigowda97852372017-03-06 16:52:59 -08003090 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkbaa62862017-01-18 13:43:34 -08003091 "PROD DB pipe out 0x%x TX PIPE Handle 0x%x",
3092 (unsigned int)pipe_out.uc_door_bell_pa,
3093 ipa_ctxt->tx_pipe_handle);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003094 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003095 "RX: %s 0x%x, %s %d, %s 0x%x, %s 0x%x",
3096 "rdy_ring_base_pa",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003097 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
Yun Park637d6482016-10-05 10:51:33 -07003098 "rdy_ring_size",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003099 pipe_in.u.ul.rdy_ring_size,
Yun Park637d6482016-10-05 10:51:33 -07003100 "rdy_ring_rp_pa",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003101 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Yun Park637d6482016-10-05 10:51:33 -07003102 "rx_ready_doorbell_paddr",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003103 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
3104 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003105
Yun Parkbaa62862017-01-18 13:43:34 -08003106 cdp_ipa_set_doorbell_paddr(soc, (void *)pdev,
3107 ipa_ctxt->tx_comp_doorbell_paddr,
3108 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003109
Yun Parkbaa62862017-01-18 13:43:34 -08003110 cdp_ipa_register_op_cb(soc, (void *)pdev,
3111 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
3112
3113 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
3114 "ipa_uc_op_cb=0x%p, tx_comp_idx_paddr=0x%x, rx_rdy_idx_paddr=0x%x",
3115 pdev->ipa_uc_op_cb,
3116 (unsigned int)pdev->htt_pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr,
3117 (unsigned int)pdev->htt_pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003118
Yun Parkbaa62862017-01-18 13:43:34 -08003119fail_return:
3120 EXIT();
3121 return stat;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003122}
3123
Leo Change3e49442015-10-26 20:07:13 -07003124/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003125 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07003126 * @hdd_ctx: hdd main context
3127 *
3128 * Force shutdown IPA pipe
3129 * Independent of FW pipe status, IPA pipe shutdonw progress
3130 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3131 * independent from FW pipe status
3132 *
3133 * Return: NONE
3134 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003135static void __hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07003136{
3137 struct hdd_ipa_priv *hdd_ipa;
3138
3139 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
3140 return;
3141
3142 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
3143 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303144 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07003145 "IPA pipes are not down yet, force shutdown");
3146 hdd_ipa_uc_disable_pipes(hdd_ipa);
3147 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003148 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Leo Change3e49442015-10-26 20:07:13 -07003149 "IPA pipes are down, do nothing");
3150 }
Leo Change3e49442015-10-26 20:07:13 -07003151}
3152
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003153/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003154 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
3155 * __hdd_ipa_uc_force_pipe_shutdown
3156 * @hdd_ctx: hdd main context
3157 *
3158 * Force shutdown IPA pipe
3159 * Independent of FW pipe status, IPA pipe shutdonw progress
3160 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3161 * independent from FW pipe status
3162 *
3163 * Return: NONE
3164 */
3165void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
3166{
3167 cds_ssr_protect(__func__);
3168 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
3169 cds_ssr_unprotect(__func__);
3170}
3171
3172/**
Govind Singh9c58eba2016-09-02 16:23:06 +05303173 * hdd_ipa_msg_free_fn() - Free an IPA message
3174 * @buff: pointer to the IPA message
3175 * @len: length of the IPA message
3176 * @type: type of IPA message
3177 *
3178 * Return: None
3179 */
3180static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3181{
Srinivas Girigowda97852372017-03-06 16:52:59 -08003182 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05303183 ghdd_ipa->stats.num_free_msg++;
3184 qdf_mem_free(buff);
3185}
3186
Govind Singh9c58eba2016-09-02 16:23:06 +05303187/**
jge62037862016-12-09 10:44:33 +08003188 * hdd_ipa_uc_send_evt() - send event to ipa
3189 * @hdd_ctx: pointer to hdd context
3190 * @type: event type
3191 * @mac_addr: pointer to mac address
3192 *
3193 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303194 *
3195 * Return: 0 - Success
3196 */
jge62037862016-12-09 10:44:33 +08003197static int hdd_ipa_uc_send_evt(hdd_adapter_t *adapter,
3198 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303199{
jge62037862016-12-09 10:44:33 +08003200 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05303201 struct ipa_msg_meta meta;
3202 struct ipa_wlan_msg *msg;
3203 int ret = 0;
jge62037862016-12-09 10:44:33 +08003204
3205 meta.msg_len = sizeof(struct ipa_wlan_msg);
3206 msg = qdf_mem_malloc(meta.msg_len);
3207 if (msg == NULL) {
3208 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3209 "msg allocation failed");
3210 return -ENOMEM;
3211 }
3212
3213 meta.msg_type = type;
3214 strlcpy(msg->name, adapter->dev->name,
3215 IPA_RESOURCE_NAME_MAX);
3216 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003217 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08003218 msg->name, meta.msg_type);
3219 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3220 if (ret) {
3221 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3222 "%s: Evt: %d fail:%d",
3223 msg->name, meta.msg_type, ret);
3224 qdf_mem_free(msg);
3225 return ret;
3226 }
3227
3228 hdd_ipa->stats.num_send_msg++;
3229
3230 return ret;
3231}
3232
3233/**
3234 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3235 * @hdd_ctx: pointer to hdd adapter
3236 *
3237 * Send disconnect client event to IPA driver during SSR
3238 *
3239 * Return: 0 - Success
3240 */
3241static int hdd_ipa_uc_disconnect_client(hdd_adapter_t *adapter)
3242{
3243 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3244 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303245 int i;
3246
3247 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3248 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3249 continue;
3250 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003251 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3252 hdd_ipa->sap_num_connected_sta) {
3253 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3254 adapter->aStaInfo[i].macAddrSTA.bytes);
3255 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303256 }
3257 }
3258
3259 return ret;
3260}
3261
3262/**
jge62037862016-12-09 10:44:33 +08003263 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3264 * @hdd_ctx: pointer to hdd adapter
3265 *
3266 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303267 *
3268 * Return: 0 - Success
3269 */
jge62037862016-12-09 10:44:33 +08003270
3271static int hdd_ipa_uc_disconnect_ap(hdd_adapter_t *adapter)
3272{
3273 int ret = 0;
3274
3275 if (adapter->ipa_context)
3276 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3277 adapter->dev->dev_addr);
3278
3279 return ret;
3280}
3281
jge62037862016-12-09 10:44:33 +08003282/**
3283 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3284 * @hdd_ctx: pointer to hdd adapter
3285 *
3286 * Send disconnect sta event to IPA driver during SSR
3287 *
3288 * Return: 0 - Success
3289 */
3290static int hdd_ipa_uc_disconnect_sta(hdd_adapter_t *adapter)
3291{
3292 hdd_station_ctx_t *pHddStaCtx;
3293 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3294 int ret = 0;
3295
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003296 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003297 hdd_ipa->sta_connected) {
3298 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3299 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003300 pHddStaCtx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003301 }
3302
3303 return ret;
3304}
jge62037862016-12-09 10:44:33 +08003305
3306/**
3307 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3308 * @hdd_ctx: pointer to hdd context
3309 *
3310 * Send disconnect event to IPA driver during SSR
3311 *
3312 * Return: 0 - Success
3313 */
3314static int hdd_ipa_uc_disconnect(hdd_context_t *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303315{
3316 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3317 QDF_STATUS status;
3318 hdd_adapter_t *adapter;
3319 int ret = 0;
3320
Govind Singh9c58eba2016-09-02 16:23:06 +05303321 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3322 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3323 adapter = adapter_node->pAdapter;
jge62037862016-12-09 10:44:33 +08003324 if (adapter->device_mode == QDF_SAP_MODE) {
3325 hdd_ipa_uc_disconnect_client(adapter);
3326 hdd_ipa_uc_disconnect_ap(adapter);
3327 } else if (adapter->device_mode == QDF_STA_MODE) {
3328 hdd_ipa_uc_disconnect_sta(adapter);
3329 }
3330
Govind Singh9c58eba2016-09-02 16:23:06 +05303331 status = hdd_get_next_adapter(
3332 hdd_ctx, adapter_node, &next);
3333 adapter_node = next;
3334 }
3335
3336 return ret;
3337}
3338
3339/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003340 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003341 *
3342 * Deinit basic IPA UC host side to be in sync reloaded FW during
3343 * SSR
3344 *
3345 * Return: 0 - Success
3346 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003347static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003348{
3349 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3350 int idx;
3351 struct hdd_ipa_iface_context *iface_context;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303352 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003353
Arun Khandavallicc544b32017-01-30 19:52:16 +05303354 if (!hdd_ipa)
3355 return 0;
3356
3357 hdd_ctx = hdd_ipa->hdd_ctx;
3358 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003359 return 0;
3360
jge62037862016-12-09 10:44:33 +08003361 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303362 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003363
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003364 /* Clean up HDD IPA interfaces */
3365 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3366 (idx < HDD_IPA_MAX_IFACE); idx++) {
3367 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003368 if (iface_context->adapter && iface_context->adapter->magic ==
3369 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003370 hdd_ipa_cleanup_iface(iface_context);
3371 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003372 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003373 /* After SSR, wlan driver reloads FW again. But we need to protect
3374 * IPA submodule during SSR transient state. So deinit basic IPA
3375 * UC host side to be in sync with reloaded FW during SSR
3376 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08003377 if (!hdd_ipa->ipa_pipes_down)
3378 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003379
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303380 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003381 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3382 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3383 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3384 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303385 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003386
Srinivas Girigowda97852372017-03-06 16:52:59 -08003387 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Arun Khandavallicc544b32017-01-30 19:52:16 +05303388 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
3389 __func__, hdd_ipa->tx_pipe_handle);
3390 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
3391
Srinivas Girigowda97852372017-03-06 16:52:59 -08003392 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Arun Khandavallicc544b32017-01-30 19:52:16 +05303393 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
3394 __func__, hdd_ipa->rx_pipe_handle);
3395 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
3396
Guolei Bianca144d82016-11-10 11:07:42 +08003397 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3398 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3399
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003400 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3401 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3402 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3403 hdd_ipa->uc_op_work[idx].msg = NULL;
3404 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003405 return 0;
3406}
3407
3408/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003409 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3410 *
3411 * Deinit basic IPA UC host side to be in sync reloaded FW during
3412 * SSR
3413 *
3414 * Return: 0 - Success
3415 */
3416int hdd_ipa_uc_ssr_deinit(void)
3417{
3418 int ret;
3419
3420 cds_ssr_protect(__func__);
3421 ret = __hdd_ipa_uc_ssr_deinit();
3422 cds_ssr_unprotect(__func__);
3423
3424 return ret;
3425}
3426
3427/**
3428 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003429 *
3430 * Init basic IPA UC host side to be in sync with reloaded FW after
3431 * SSR to resume IPA UC operations
3432 *
3433 * Return: 0 - Success
3434 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303435static int __hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003436{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437
Arun Khandavallicc544b32017-01-30 19:52:16 +05303438 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3439 int i;
3440 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303441
3442 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3443 return 0;
3444
Arun Khandavallicc544b32017-01-30 19:52:16 +05303445 /* Create the interface context */
3446 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3447 iface_context = &hdd_ipa->iface_context[i];
3448 iface_context->hdd_ipa = hdd_ipa;
3449 iface_context->cons_client =
3450 hdd_ipa_adapter_2_client[i].cons_client;
3451 iface_context->prod_client =
3452 hdd_ipa_adapter_2_client[i].prod_client;
3453 iface_context->iface_id = i;
3454 iface_context->adapter = NULL;
3455 }
3456 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3457 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3458 hdd_ipa->vdev_offload_enabled[i] = false;
3459 }
3460
3461 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3462 hdd_ipa->resource_loading = false;
3463 hdd_ipa->resource_unloading = false;
3464 hdd_ipa->sta_connected = 0;
3465 hdd_ipa->ipa_pipes_down = true;
3466 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303467 }
3468
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003469 return 0;
3470}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003471
3472/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003473 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3474 *
3475 * Init basic IPA UC host side to be in sync with reloaded FW after
3476 * SSR to resume IPA UC operations
3477 *
3478 * Return: 0 - Success
3479 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303480int hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003481{
3482 int ret;
3483
3484 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303485 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003486 cds_ssr_unprotect(__func__);
3487
3488 return ret;
3489}
3490
3491/**
3492 * __hdd_ipa_tx_packet_ipa() - send packet to IPA
Leo Chang3bc8fed2015-11-13 10:59:47 -08003493 * @hdd_ctx: Global HDD context
3494 * @skb: skb sent to IPA
3495 * @session_id: send packet instance session id
3496 *
3497 * Send TX packet which generated by system to IPA.
3498 * This routine only will be used for function verification
3499 *
3500 * Return: NULL packet sent to IPA properly
3501 * NULL invalid packet drop
3502 * skb packet not sent to IPA. legacy data path should handle
3503 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003504static struct sk_buff *__hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08003505 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07003506{
Leo Chang3bc8fed2015-11-13 10:59:47 -08003507 struct ipa_header *ipa_header;
3508 struct frag_header *frag_header;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003509 struct hdd_ipa_priv *hdd_ipa;
3510
3511 if (wlan_hdd_validate_context(hdd_ctx))
3512 return skb;
3513
3514 hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08003515
3516 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3517 return skb;
3518
Leo Chang07b28f62016-05-11 12:29:22 -07003519 if (!hdd_ipa)
3520 return skb;
3521
3522 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
3523 return skb;
3524
Leo Changcc923e22016-06-16 15:29:03 -07003525 if (skb_headroom(skb) <
3526 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07003527 return skb;
3528
Leo Chang3bc8fed2015-11-13 10:59:47 -08003529 ipa_header = (struct ipa_header *) skb_push(skb,
3530 sizeof(struct ipa_header));
3531 if (!ipa_header) {
3532 /* No headroom, legacy */
3533 return skb;
3534 }
3535 memset(ipa_header, 0, sizeof(*ipa_header));
3536 ipa_header->vdev_id = 0;
3537
3538 frag_header = (struct frag_header *) skb_push(skb,
3539 sizeof(struct frag_header));
3540 if (!frag_header) {
3541 /* No headroom, drop */
3542 kfree_skb(skb);
3543 return NULL;
3544 }
3545 memset(frag_header, 0, sizeof(*frag_header));
3546 frag_header->length = skb->len - sizeof(struct frag_header)
3547 - sizeof(struct ipa_header);
3548
3549 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
3550 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07003551}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003552
3553/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003554 * hdd_ipa_tx_packet_ipa() - SSR wrapper for __hdd_ipa_tx_packet_ipa
3555 * @hdd_ctx: Global HDD context
3556 * @skb: skb sent to IPA
3557 * @session_id: send packet instance session id
3558 *
3559 * Send TX packet which generated by system to IPA.
3560 * This routine only will be used for function verification
3561 *
3562 * Return: NULL packet sent to IPA properly
3563 * NULL invalid packet drop
3564 * skb packet not sent to IPA. legacy data path should handle
3565 */
3566struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
3567 struct sk_buff *skb, uint8_t session_id)
3568{
3569 struct sk_buff *ret;
3570
3571 cds_ssr_protect(__func__);
3572 ret = __hdd_ipa_tx_packet_ipa(hdd_ctx, skb, session_id);
3573 cds_ssr_unprotect(__func__);
3574
3575 return ret;
3576}
3577
3578/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003579 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3580 * @work: scheduled work
3581 *
3582 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3583 * not want to immediately release the wake lock since the system
3584 * would then potentially try to suspend when there is a healthy data
3585 * rate. Deferred work is scheduled and this function handles the
3586 * work. When this function is called, if the IPA resource is still
3587 * released then we release the wake lock.
3588 *
3589 * Return: None
3590 */
3591static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3592{
3593 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3594 struct hdd_ipa_priv,
3595 wake_lock_work);
3596
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303597 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003598
3599 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3600 goto end;
3601
3602 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303603 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003604 WIFI_POWER_EVENT_WAKELOCK_IPA);
3605
3606end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303607 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003608}
3609
3610/**
3611 * hdd_ipa_rm_request() - Request resource from IPA
3612 * @hdd_ipa: Global HDD IPA context
3613 *
3614 * Return: 0 on success, negative errno on error
3615 */
3616static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3617{
3618 int ret = 0;
3619
3620 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3621 return 0;
3622
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303623 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003624
3625 switch (hdd_ipa->rm_state) {
3626 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303627 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003628 return 0;
3629 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303630 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003631 return -EINPROGRESS;
3632 case HDD_IPA_RM_RELEASED:
3633 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3634 break;
3635 }
3636
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303637 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003638
3639 ret = ipa_rm_inactivity_timer_request_resource(
3640 IPA_RM_RESOURCE_WLAN_PROD);
3641
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303642 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003643 if (ret == 0) {
3644 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3645 hdd_ipa->stats.num_rm_grant_imm++;
3646 }
3647
3648 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3649 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303650 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003651 WIFI_POWER_EVENT_WAKELOCK_IPA);
3652 hdd_ipa->wake_lock_released = false;
3653 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303654 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003655
3656 return ret;
3657}
3658
3659/**
3660 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3661 * @hdd_ipa: Global HDD IPA context
3662 *
3663 * Return: 0 if resources released, negative errno otherwise
3664 */
3665static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3666{
3667 int ret = 0;
3668
3669 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3670 return 0;
3671
3672 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3673 return -EAGAIN;
3674
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303675 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003676
Nirav Shahcbc6d722016-03-01 16:24:53 +05303677 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303678 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003679 return -EAGAIN;
3680 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303681 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003682
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303683 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003684 switch (hdd_ipa->rm_state) {
3685 case HDD_IPA_RM_GRANTED:
3686 break;
3687 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303688 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003689 return -EINPROGRESS;
3690 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303691 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003692 return 0;
3693 }
3694
3695 /* IPA driver returns immediately so set the state here to avoid any
3696 * race condition.
3697 */
3698 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3699 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303700 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003701
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003702 ret = ipa_rm_inactivity_timer_release_resource(
3703 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003704
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303705 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003706 if (unlikely(ret != 0)) {
3707 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3708 WARN_ON(1);
3709 }
3710
3711 /*
3712 * If wake_lock is released immediately, kernel would try to suspend
3713 * immediately as well, Just avoid ping-pong between suspend-resume
3714 * while there is healthy amount of data transfer going on by
3715 * releasing the wake_lock after some delay.
3716 */
3717 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3718 msecs_to_jiffies
3719 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3720
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303721 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003722
3723 return ret;
3724}
3725
3726/**
3727 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3728 * @user_data: user data registered with IPA
3729 * @event: the IPA resource manager event that occurred
3730 * @data: the data associated with the event
3731 *
3732 * Return: None
3733 */
3734static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3735 unsigned long data)
3736{
3737 struct hdd_ipa_priv *hdd_ipa = user_data;
3738
3739 if (unlikely(!hdd_ipa))
3740 return;
3741
3742 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3743 return;
3744
Srinivas Girigowda97852372017-03-06 16:52:59 -08003745 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003746
3747 switch (event) {
3748 case IPA_RM_RESOURCE_GRANTED:
3749 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3750 /* RM Notification comes with ISR context
3751 * it should be serialized into work queue to avoid
3752 * ISR sleep problem
3753 */
3754 hdd_ipa->uc_rm_work.event = event;
3755 schedule_work(&hdd_ipa->uc_rm_work.work);
3756 break;
3757 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303758 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003759 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303760 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003761 hdd_ipa->stats.num_rm_grant++;
3762 break;
3763
3764 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003765 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003766 hdd_ipa->resource_unloading = false;
3767 break;
3768
3769 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303770 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003771 break;
3772 }
3773}
3774
3775/**
3776 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3777 *
3778 * Callback function registered with IPA that is called when IPA wants
3779 * to release the WLAN consumer resource
3780 *
3781 * Return: 0 if the request is granted, negative errno otherwise
3782 */
3783static int hdd_ipa_rm_cons_release(void)
3784{
3785 return 0;
3786}
3787
3788/**
3789 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3790 *
3791 * Callback function registered with IPA that is called when IPA wants
3792 * to access the WLAN consumer resource
3793 *
3794 * Return: 0 if the request is granted, negative errno otherwise
3795 */
3796static int hdd_ipa_rm_cons_request(void)
3797{
Yun Park4d8b60a2015-10-22 13:59:32 -07003798 int ret = 0;
3799
3800 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303801 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003802 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003803 __func__);
3804 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003805 ret = -EINPROGRESS;
3806 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303807 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003808 "%s: IPA resource unloading in progress",
3809 __func__);
3810 ghdd_ipa->pending_cons_req = true;
3811 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003812 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003813
3814 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003815}
3816
3817/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003818 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003819 * @hdd_ctx: Global HDD context
3820 * @tx_packets: Number of packets transmitted in the last sample period
3821 * @rx_packets: Number of packets received in the last sample period
3822 *
3823 * Return: 0 on success, negative errno on error
3824 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003825static int __hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003826 uint64_t rx_packets)
3827{
3828 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003829 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003830 struct ipa_rm_perf_profile profile;
3831 int ret;
3832
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003833 if (wlan_hdd_validate_context(hdd_ctx))
3834 return 0;
3835
3836 hdd_ipa = hdd_ctx->hdd_ipa;
3837
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003838 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3839 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3840 return 0;
3841
3842 memset(&profile, 0, sizeof(profile));
3843
3844 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3845 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3846 else if (tx_packets >
3847 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3848 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3849 else
3850 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3851
3852 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3853 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3854 else if (rx_packets >
3855 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3856 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3857 else
3858 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3859
Yun Parkec845302016-12-15 09:22:57 -08003860 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003861 "CONS perf curr: %d, next: %d",
3862 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003863 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003864 "PROD perf curr: %d, next: %d",
3865 hdd_ipa->curr_prod_bw, next_prod_bw);
3866
3867 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003868 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003869 hdd_ipa->curr_cons_bw, next_cons_bw);
3870 profile.max_supported_bandwidth_mbps = next_cons_bw;
3871 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
3872 &profile);
3873 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003874 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003875
3876 return ret;
3877 }
3878 hdd_ipa->curr_cons_bw = next_cons_bw;
3879 hdd_ipa->stats.num_cons_perf_req++;
3880 }
3881
3882 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003883 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003884 hdd_ipa->curr_prod_bw, next_prod_bw);
3885 profile.max_supported_bandwidth_mbps = next_prod_bw;
3886 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
3887 &profile);
3888 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003889 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003890 return ret;
3891 }
3892 hdd_ipa->curr_prod_bw = next_prod_bw;
3893 hdd_ipa->stats.num_prod_perf_req++;
3894 }
3895
3896 return 0;
3897}
3898
3899/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003900 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3901 * @hdd_ctx: Global HDD context
3902 * @tx_packets: Number of packets transmitted in the last sample period
3903 * @rx_packets: Number of packets received in the last sample period
3904 *
3905 * Return: 0 on success, negative errno on error
3906 */
3907int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
3908 uint64_t rx_packets)
3909{
3910 int ret;
3911
3912 cds_ssr_protect(__func__);
3913 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3914 cds_ssr_unprotect(__func__);
3915
3916 return ret;
3917}
3918
3919/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003920 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3921 * @work: struct work_struct
3922 * @work_handler: work_handler
3923 *
3924 * Return: none
3925 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003926static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3927 work_func_t work_handler)
3928{
3929 INIT_WORK(work, work_handler);
3930}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003931
3932/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003933 * hdd_ipa_setup_rm() - Setup IPA resource management
3934 * @hdd_ipa: Global HDD IPA context
3935 *
3936 * Return: 0 on success, negative errno on error
3937 */
3938static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3939{
3940 struct ipa_rm_create_params create_params = { 0 };
3941 int ret;
3942
3943 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3944 return 0;
3945
Rajeev Kumar217f2172016-01-06 18:11:55 -08003946 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3947 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003948 memset(&create_params, 0, sizeof(create_params));
3949 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3950 create_params.reg_params.user_data = hdd_ipa;
3951 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3952 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3953
3954 ret = ipa_rm_create_resource(&create_params);
3955 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303956 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003957 "Create RM resource failed: %d", ret);
3958 goto setup_rm_fail;
3959 }
3960
3961 memset(&create_params, 0, sizeof(create_params));
3962 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3963 create_params.request_resource = hdd_ipa_rm_cons_request;
3964 create_params.release_resource = hdd_ipa_rm_cons_release;
3965 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3966
3967 ret = ipa_rm_create_resource(&create_params);
3968 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303969 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003970 "Create RM CONS resource failed: %d", ret);
3971 goto delete_prod;
3972 }
3973
3974 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3975 IPA_RM_RESOURCE_APPS_CONS);
3976
3977 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3978 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3979 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303980 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003981 ret);
3982 goto timer_init_failed;
3983 }
3984
3985 /* Set the lowest bandwidth to start with */
3986 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3987
3988 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303989 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003990 "Set perf level failed: %d", ret);
3991 goto set_perf_failed;
3992 }
3993
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303994 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003995 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3996 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303997 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003998 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3999 hdd_ipa->wake_lock_released = true;
4000 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
4001
4002 return ret;
4003
4004set_perf_failed:
4005 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4006
4007timer_init_failed:
4008 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4009
4010delete_prod:
4011 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4012
4013setup_rm_fail:
4014 return ret;
4015}
4016
4017/**
4018 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
4019 * @hdd_ipa: Global HDD IPA context
4020 *
4021 * Destroys all resources associated with the IPA resource manager
4022 *
4023 * Return: None
4024 */
4025static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
4026{
4027 int ret;
4028
4029 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4030 return;
4031
4032 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304033 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004034
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304036 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004037
4038 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4039
4040 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4041 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304042 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004043 "RM PROD resource delete failed %d", ret);
4044
4045 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4046 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304047 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004048 "RM CONS resource delete failed %d", ret);
4049}
4050
4051/**
4052 * hdd_ipa_send_skb_to_network() - Send skb to kernel
4053 * @skb: network buffer
4054 * @adapter: network adapter
4055 *
4056 * Called when a network buffer is received which should not be routed
4057 * to the IPA module.
4058 *
4059 * Return: None
4060 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304061static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004062 hdd_adapter_t *adapter)
4063{
4064 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4065 unsigned int cpu_index;
4066
4067 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004068 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004069 adapter);
4070 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004071 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004072 return;
4073 }
4074
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004075 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004076 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004077 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004078 return;
4079 }
4080
4081 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
4082 skb->dev = adapter->dev;
4083 skb->protocol = eth_type_trans(skb, skb->dev);
4084 skb->ip_summed = CHECKSUM_NONE;
4085
4086 cpu_index = wlan_hdd_get_cpu();
4087
4088 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
4089 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
4090 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
4091 else
4092 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
4093
4094 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
4095 adapter->dev->last_rx = jiffies;
4096}
4097
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004098/**
Leo Chang69c39692016-10-12 20:11:12 -07004099 * hdd_ipa_forward() - handle packet forwarding to wlan tx
4100 * @hdd_ipa: pointer to hdd ipa context
4101 * @adapter: network adapter
4102 * @skb: data pointer
4103 *
4104 * if exception packet has set forward bit, copied new packet should be
4105 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
4106 * put into pm queue and tx procedure will be differed
4107 *
4108 * Return: None
4109 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07004110static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
4111 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07004112{
Leo Chang69c39692016-10-12 20:11:12 -07004113 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
4114
Leo Chang69c39692016-10-12 20:11:12 -07004115 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
4116 /* WLAN subsystem is in suspend, put int queue */
4117 if (hdd_ipa->suspended) {
4118 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4119 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4120 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004121 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
4122 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07004123 pm_tx_cb->exception = true;
4124 pm_tx_cb->adapter = adapter;
4125 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004126 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07004127 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4128 hdd_ipa->stats.num_tx_queued++;
4129 } else {
4130 /* Resume, put packet into WLAN TX */
4131 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004132 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07004133 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4134 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08004135 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07004136 } else {
Yun Parkb187d542016-11-14 18:10:04 -08004137 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07004138 hdd_ipa->ipa_tx_forward++;
4139 }
4140 }
4141}
4142
4143/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004144 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
4145 * @hdd_ipa: pointer to HDD IPA struct
4146 * @adapter: hdd adapter pointer
4147 * @desc: Firmware descriptor
4148 * @skb: Data buffer
4149 *
4150 * Return:
4151 * HDD_IPA_FORWARD_PKT_NONE
4152 * HDD_IPA_FORWARD_PKT_DISCARD
4153 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
4154 *
4155 */
4156
4157static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
4158 struct hdd_ipa_priv *hdd_ipa,
4159 hdd_adapter_t *adapter,
4160 uint8_t desc,
4161 qdf_nbuf_t skb)
4162{
4163 int ret = HDD_IPA_FORWARD_PKT_NONE;
4164
4165 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304166 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004167 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
4168 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304169 /* Drop the packet*/
4170 hdd_ipa->stats.num_tx_fwd_err++;
4171 kfree_skb(skb);
4172 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4173 return ret;
4174 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004175 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
4176 "Forward packet to Tx (fw_desc=%d)", desc);
4177 hdd_ipa->ipa_tx_forward++;
4178
4179 if ((desc & FW_RX_DESC_DISCARD_M)) {
4180 hdd_ipa_forward(hdd_ipa, adapter, skb);
4181 hdd_ipa->ipa_rx_internel_drop_count++;
4182 hdd_ipa->ipa_rx_discard++;
4183 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4184 } else {
4185 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004186
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004187 if (cloned_skb)
4188 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
4189 else
4190 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4191 "%s: tx skb alloc failed",
4192 __func__);
4193 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
4194 }
4195 }
4196
4197 return ret;
4198}
4199
4200/**
Yun Park637d6482016-10-05 10:51:33 -07004201 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004202 * @priv: pointer to private data registered with IPA (we register a
4203 * pointer to the global IPA context)
4204 * @evt: the IPA event which triggered the callback
4205 * @data: data associated with the event
4206 *
4207 * Return: None
4208 */
Yun Parkf8d6a122016-10-11 15:49:43 -07004209static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004210 unsigned long data)
4211{
4212 struct hdd_ipa_priv *hdd_ipa = NULL;
4213 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304214 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004215 uint8_t iface_id;
4216 uint8_t session_id;
4217 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004218 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07004219 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004220
4221 hdd_ipa = (struct hdd_ipa_priv *)priv;
4222
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08004223 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
4224 return;
4225
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004226 switch (evt) {
4227 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05304228 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07004229
4230 /*
4231 * When SSR is going on or driver is unloading,
4232 * just drop the packets.
4233 */
4234 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4235 if (0 != status) {
4236 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4237 "Invalid context: drop packet");
4238 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4239 kfree_skb(skb);
4240 return;
4241 }
4242
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004243 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4244 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004245 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004246 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004247 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4248 session_id, iface_id);
4249 } else {
4250 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4251 }
4252
4253 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304254 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004255 "IPA_RECEIVE: Invalid iface_id: %u",
4256 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004257 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004258 "w2i -- skb",
4259 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004260 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004261 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004262 return;
4263 }
4264
4265 iface_context = &hdd_ipa->iface_context[iface_id];
4266 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004267 if (!adapter) {
4268 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4269 "IPA_RECEIVE: Adapter is NULL");
4270 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4271 kfree_skb(skb);
4272 return;
4273 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004274
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304275 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004276 "w2i -- skb",
4277 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004278 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4279 hdd_ipa->stats.num_rx_excep++;
4280 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4281 } else {
4282 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4283 }
4284
4285 iface_context->stats.num_rx_ipa_excep++;
4286
4287 /* Disable to forward Intra-BSS Rx packets when
4288 * ap_isolate=1 in hostapd.conf
4289 */
Yun Park046101c2016-09-02 15:32:14 -07004290 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004291 /*
4292 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4293 * all Rx packets to IPA uC, which need to be forwarded
4294 * to other interface.
4295 * And, IPA driver will send back to WLAN host driver
4296 * through exception pipe with fw_desc field set by FW.
4297 * Here we are checking fw_desc field for FORWARD bit
4298 * set, and forward to Tx. Then copy to kernel stack
4299 * only when DISCARD bit is not set.
4300 */
4301 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004302 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4303 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4304 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004305 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004306 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004307 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004308 "Intra-BSS FWD is disabled-skip forward to Tx");
4309 }
4310
4311 hdd_ipa_send_skb_to_network(skb, adapter);
4312 break;
4313
4314 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304315 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004316 "w2i cb wrong event: 0x%x", evt);
4317 return;
4318 }
4319}
4320
4321/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004322 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4323 * @priv: pointer to private data registered with IPA (we register a
4324 * pointer to the global IPA context)
4325 * @evt: the IPA event which triggered the callback
4326 * @data: data associated with the event
4327 *
4328 * Return: None
4329 */
4330static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4331 unsigned long data)
4332{
4333 cds_ssr_protect(__func__);
4334 __hdd_ipa_w2i_cb(priv, evt, data);
4335 cds_ssr_unprotect(__func__);
4336}
4337
4338/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004339 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4340 * @skb: packet buffer which was transmitted
4341 *
4342 * Return: None
4343 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304344void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004345{
4346 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004347 struct ipa_rx_data *ipa_tx_desc;
4348 struct hdd_ipa_tx_desc *tx_desc;
4349 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004350
Yun Park52b2b992016-09-22 15:49:51 -07004351 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%x", QDF_NBUF_CB_TX_IPA_PRIV(skb));
4352
4353 if (!qdf_nbuf_ipa_owned_get(skb)) {
4354 dev_kfree_skb_any(skb);
4355 return;
4356 }
4357
4358 /* Get Tx desc pointer from SKB CB */
4359 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4360 tx_desc = hdd_ipa->tx_desc_list + id;
4361 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4362
4363 /* Return Tx Desc to IPA */
4364 ipa_free_skb(ipa_tx_desc);
4365
4366 /* Return to free tx desc list */
4367 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4368 tx_desc->ipa_tx_desc_ptr = NULL;
4369 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4370 hdd_ipa->stats.num_tx_desc_q_cnt--;
4371 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004372
4373 hdd_ipa->stats.num_tx_comp_cnt++;
4374
4375 atomic_dec(&hdd_ipa->tx_ref_cnt);
4376
4377 hdd_ipa_rm_try_release(hdd_ipa);
4378}
4379
4380/**
4381 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4382 * @iface_context: interface-specific IPA context
4383 * @ipa_tx_desc: packet data descriptor
4384 *
4385 * Return: None
4386 */
4387static void hdd_ipa_send_pkt_to_tl(
4388 struct hdd_ipa_iface_context *iface_context,
4389 struct ipa_rx_data *ipa_tx_desc)
4390{
4391 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004392 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304393 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004394 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004395
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304396 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004397 adapter = iface_context->adapter;
4398 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304399 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004400 ipa_free_skb(ipa_tx_desc);
4401 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304402 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004403 hdd_ipa_rm_try_release(hdd_ipa);
4404 return;
4405 }
4406
4407 /*
4408 * During CAC period, data packets shouldn't be sent over the air so
4409 * drop all the packets here
4410 */
4411 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4412 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304413 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004414 iface_context->stats.num_tx_cac_drop++;
4415 hdd_ipa_rm_try_release(hdd_ipa);
4416 return;
4417 }
4418
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004419 ++adapter->stats.tx_packets;
4420
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304421 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004422
4423 skb = ipa_tx_desc->skb;
4424
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304425 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004426
4427 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304428 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004429 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304430 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004431 ipa_tx_desc->dma_addr
4432 + HDD_IPA_WLAN_FRAG_HEADER
4433 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004434 ipa_tx_desc->skb->len -=
4435 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4436 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304437 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004438
Yun Park52b2b992016-09-22 15:49:51 -07004439 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4440 /* get free Tx desc and assign ipa_tx_desc pointer */
4441 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4442 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4443 struct hdd_ipa_tx_desc, link);
4444 list_del(&tx_desc->link);
4445 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4446 hdd_ipa->stats.num_tx_desc_q_cnt++;
4447 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4448 /* Store Tx Desc index into SKB CB */
4449 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4450 } else {
4451 hdd_ipa->stats.num_tx_desc_error++;
4452 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4453 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4454 ipa_free_skb(ipa_tx_desc);
4455 hdd_ipa_rm_try_release(hdd_ipa);
4456 return;
4457 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004458
4459 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4460
Leo Changfdb45c32016-10-28 11:09:23 -07004461 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004462 (struct cdp_vdev *)iface_context->tl_context,
4463 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004464 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304465 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004466 ipa_free_skb(ipa_tx_desc);
4467 iface_context->stats.num_tx_err++;
4468 hdd_ipa_rm_try_release(hdd_ipa);
4469 return;
4470 }
4471
4472 atomic_inc(&hdd_ipa->tx_ref_cnt);
4473
4474 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004475}
4476
4477/**
Leo Chang11545d62016-10-17 14:53:50 -07004478 * hdd_ipa_is_present() - get IPA hw status
4479 * @hdd_ctx: pointer to hdd context
4480 *
4481 * ipa_uc_reg_rdyCB is not directly designed to check
4482 * ipa hw status. This is an undocumented function which
4483 * has confirmed with IPA team.
4484 *
4485 * Return: true - ipa hw present
4486 * false - ipa hw not present
4487 */
4488bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
4489{
4490 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004491 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004492 return true;
4493 else
4494 return false;
4495}
4496
4497/**
Leo Chang69c39692016-10-12 20:11:12 -07004498 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004499 * @work: pointer to the scheduled work
4500 *
4501 * Called during PM resume to send packets to TL which were queued
4502 * while host was in the process of suspending.
4503 *
4504 * Return: None
4505 */
Leo Chang69c39692016-10-12 20:11:12 -07004506static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004507{
4508 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4509 struct hdd_ipa_priv,
4510 pm_work);
4511 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304512 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004513 uint32_t dequeued = 0;
4514
Leo Chang69c39692016-10-12 20:11:12 -07004515 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4516 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304517 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304518 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4519 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304520 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004521
4522 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004523 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004524 if (pm_tx_cb->exception) {
4525 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4526 "FLUSH EXCEPTION");
4527 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
4528 } else {
4529 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004530 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004531 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304532 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004533 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304534 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004535 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4536 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004537
4538 hdd_ipa->stats.num_tx_dequeued += dequeued;
4539 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4540 hdd_ipa->stats.num_max_pm_queue = dequeued;
4541}
4542
4543/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004544 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004545 * @priv: pointer to private data registered with IPA (we register a
4546 * pointer to the interface-specific IPA context)
4547 * @evt: the IPA event which triggered the callback
4548 * @data: data associated with the event
4549 *
4550 * Return: None
4551 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004552static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004553 unsigned long data)
4554{
4555 struct hdd_ipa_priv *hdd_ipa = NULL;
4556 struct ipa_rx_data *ipa_tx_desc;
4557 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304558 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004559 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304560 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004561
Mukul Sharma81661ae2015-10-30 20:26:02 +05304562 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004563 ipa_tx_desc = (struct ipa_rx_data *)data;
4564 hdd_ipa = iface_context->hdd_ipa;
4565
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004566 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004567 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4568 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004569 iface_context->stats.num_tx_drop++;
4570 return;
4571 }
4572
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004573 /*
4574 * When SSR is going on or driver is unloading, just drop the packets.
4575 * During SSR, there is no use in queueing the packets as STA has to
4576 * connect back any way
4577 */
4578 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304579 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004580 ipa_free_skb(ipa_tx_desc);
4581 iface_context->stats.num_tx_drop++;
4582 return;
4583 }
4584
4585 skb = ipa_tx_desc->skb;
4586
Yun Parkb187d542016-11-14 18:10:04 -08004587 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4588 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004589
4590 /*
4591 * If PROD resource is not requested here then there may be cases where
4592 * IPA hardware may be clocked down because of not having proper
4593 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4594 * workaround to request PROD resource while data is going over CONS
4595 * pipe to prevent the IPA hardware clockdown.
4596 */
4597 hdd_ipa_rm_request(hdd_ipa);
4598
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304599 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004600 /*
4601 * If host is still suspended then queue the packets and these will be
4602 * drained later when resume completes. When packet is arrived here and
4603 * host is suspended, this means that there is already resume is in
4604 * progress.
4605 */
4606 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304607 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004608 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4609 pm_tx_cb->iface_context = iface_context;
4610 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304611 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004612 hdd_ipa->stats.num_tx_queued++;
4613
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304614 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004615 return;
4616 }
4617
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304618 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004619
4620 /*
4621 * If we are here means, host is not suspended, wait for the work queue
4622 * to finish.
4623 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004625
4626 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4627}
4628
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004629/*
4630 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4631 * @priv: pointer to private data registered with IPA (we register a
4632 * pointer to the interface-specific IPA context)
4633 * @evt: the IPA event which triggered the callback
4634 * @data: data associated with the event
4635 *
4636 * Return: None
4637 */
4638static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4639 unsigned long data)
4640{
4641 cds_ssr_protect(__func__);
4642 __hdd_ipa_i2w_cb(priv, evt, data);
4643 cds_ssr_unprotect(__func__);
4644}
4645
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004646/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004647 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004648 * @hdd_ctx: Global HDD context
4649 *
4650 * Return: 0 on success, negativer errno on error
4651 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004652static int __hdd_ipa_suspend(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004653{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004654 struct hdd_ipa_priv *hdd_ipa;
4655
4656 if (wlan_hdd_validate_context(hdd_ctx))
4657 return 0;
4658
4659 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004660
4661 if (!hdd_ipa_is_enabled(hdd_ctx))
4662 return 0;
4663
4664 /*
4665 * Check if IPA is ready for suspend, If we are here means, there is
4666 * high chance that suspend would go through but just to avoid any race
4667 * condition after suspend started, these checks are conducted before
4668 * allowing to suspend.
4669 */
4670 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4671 return -EAGAIN;
4672
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304673 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004674
4675 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304676 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004677 return -EAGAIN;
4678 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304679 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004680
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304681 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004682 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304683 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004684
4685 return 0;
4686}
4687
4688/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004689 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4690 * @hdd_ctx: Global HDD context
4691 *
4692 * Return: 0 on success, negativer errno on error
4693 */
4694int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
4695{
4696 int ret;
4697
4698 cds_ssr_protect(__func__);
4699 ret = __hdd_ipa_suspend(hdd_ctx);
4700 cds_ssr_unprotect(__func__);
4701
4702 return ret;
4703}
4704
4705/**
4706 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004707 * hdd_ctx: Global HDD context
4708 *
4709 * Return: 0 on success, negative errno on error
4710 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004711static int __hdd_ipa_resume(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004712{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004713 struct hdd_ipa_priv *hdd_ipa;
4714
4715 if (wlan_hdd_validate_context(hdd_ctx))
4716 return 0;
4717
4718 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004719
4720 if (!hdd_ipa_is_enabled(hdd_ctx))
4721 return 0;
4722
4723 schedule_work(&hdd_ipa->pm_work);
4724
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304725 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004726 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304727 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004728
4729 return 0;
4730}
4731
4732/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004733 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4734 * hdd_ctx: Global HDD context
4735 *
4736 * Return: 0 on success, negative errno on error
4737 */
4738int hdd_ipa_resume(hdd_context_t *hdd_ctx)
4739{
4740 int ret;
4741
4742 cds_ssr_protect(__func__);
4743 ret = __hdd_ipa_resume(hdd_ctx);
4744 cds_ssr_unprotect(__func__);
4745
4746 return ret;
4747}
4748
4749/**
Yun Park52b2b992016-09-22 15:49:51 -07004750 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4751 * @hdd_ipa: Global HDD IPA context
4752 *
4753 * Return: 0 on success, negative errno on error
4754 */
4755static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4756{
4757 int i;
4758 uint32_t max_desc_cnt;
4759 struct hdd_ipa_tx_desc *tmp_desc;
4760
4761 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4762
4763 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4764
4765 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc)*max_desc_cnt);
4766
4767 if (!tmp_desc) {
4768 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4769 "Free Tx descriptor allocation failed");
4770 return -ENOMEM;
4771 }
4772
4773 hdd_ipa->tx_desc_list = tmp_desc;
4774
4775 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4776 for (i = 0; i < max_desc_cnt; i++) {
4777 tmp_desc->id = i;
4778 tmp_desc->ipa_tx_desc_ptr = NULL;
4779 list_add_tail(&tmp_desc->link,
4780 &hdd_ipa->free_tx_desc_head);
4781 tmp_desc++;
4782 }
4783
4784 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4785 hdd_ipa->stats.num_tx_desc_error = 0;
4786
4787 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4788
4789 return 0;
4790}
4791
4792/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004793 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4794 * @hdd_ipa: Global HDD IPA context
4795 *
4796 * Return: 0 on success, negative errno on error
4797 */
4798static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4799{
4800 int i, ret = 0;
4801 struct ipa_sys_connect_params *ipa;
4802 uint32_t desc_fifo_sz;
4803
4804 /* The maximum number of descriptors that can be provided to a BAM at
4805 * once is one less than the total number of descriptors that the buffer
4806 * can contain.
4807 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4808 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4809 * be provided at once.
4810 * Because of above requirement, one extra descriptor will be added to
4811 * make sure hardware always has one descriptor.
4812 */
4813 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4814 + sizeof(struct sps_iovec);
4815
4816 /*setup TX pipes */
4817 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4818 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4819
4820 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4821 ipa->desc_fifo_sz = desc_fifo_sz;
4822 ipa->priv = &hdd_ipa->iface_context[i];
4823 ipa->notify = hdd_ipa_i2w_cb;
4824
4825 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4826 ipa->ipa_ep_cfg.hdr.hdr_len =
4827 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4828 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4829 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4830 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4831 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4832 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4833 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4834 } else {
4835 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4836 }
4837 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4838
4839 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4840 ipa->keep_ipa_awake = 1;
4841
4842 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4843 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004844 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4845 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004846 goto setup_sys_pipe_fail;
4847 }
4848 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4849 }
4850
4851 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4852 /*
4853 * Hard code it here, this can be extended if in case
4854 * PROD pipe is also per interface.
4855 * Right now there is no advantage of doing this.
4856 */
4857 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
4858
4859 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4860
4861 ipa->client = hdd_ipa->prod_client;
4862
4863 ipa->desc_fifo_sz = desc_fifo_sz;
4864 ipa->priv = hdd_ipa;
4865 ipa->notify = hdd_ipa_w2i_cb;
4866
4867 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4868 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4869 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4870 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4871
4872 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4873 ipa->keep_ipa_awake = 1;
4874
4875 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4876 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304877 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004878 "Failed for RX pipe: %d", ret);
4879 goto setup_sys_pipe_fail;
4880 }
4881 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4882 }
4883
Yun Park52b2b992016-09-22 15:49:51 -07004884 /* Allocate free Tx desc list */
4885 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4886 if (ret)
4887 goto setup_sys_pipe_fail;
4888
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004889 return ret;
4890
4891setup_sys_pipe_fail:
4892
4893 while (--i >= 0) {
4894 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304895 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004896 sizeof(struct hdd_ipa_sys_pipe));
4897 }
4898
4899 return ret;
4900}
4901
4902/**
4903 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4904 * @hdd_ipa: Global HDD IPA context
4905 *
4906 * Return: None
4907 */
4908static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4909{
4910 int ret = 0, i;
Yun Park52b2b992016-09-22 15:49:51 -07004911 uint32_t max_desc_cnt;
4912 struct hdd_ipa_tx_desc *tmp_desc;
4913 struct ipa_rx_data *ipa_tx_desc;
4914
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004915 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4916 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
4917 ret =
4918 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4919 conn_hdl);
4920 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304921 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004922 ret);
4923
4924 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4925 }
4926 }
Yun Park52b2b992016-09-22 15:49:51 -07004927
4928 if (hdd_ipa->tx_desc_list) {
4929 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4930
4931 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4932 for (i = 0; i < max_desc_cnt; i++) {
4933 tmp_desc = hdd_ipa->tx_desc_list + i;
4934 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4935 if (ipa_tx_desc)
4936 ipa_free_skb(ipa_tx_desc);
4937 }
4938 tmp_desc = hdd_ipa->tx_desc_list;
4939 hdd_ipa->tx_desc_list = NULL;
4940 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4941 hdd_ipa->stats.num_tx_desc_error = 0;
4942 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4943 qdf_mem_free(tmp_desc);
4944 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004945}
4946
4947/**
4948 * hdd_ipa_register_interface() - register IPA interface
4949 * @hdd_ipa: Global IPA context
4950 * @iface_context: Per-interface IPA context
4951 *
4952 * Return: 0 on success, negative errno on error
4953 */
4954static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
4955 struct hdd_ipa_iface_context
4956 *iface_context)
4957{
4958 struct ipa_tx_intf tx_intf;
4959 struct ipa_rx_intf rx_intf;
4960 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
4961 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
4962 char *ifname = iface_context->adapter->dev->name;
4963
4964 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
4965 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
4966
4967 int num_prop = 1;
4968 int ret = 0;
4969
4970 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
4971 num_prop++;
4972
4973 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
4974 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304975 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004976 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304977 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004978 goto register_interface_fail;
4979 }
4980
4981 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
4982 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304983 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004984 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304985 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004986 goto register_interface_fail;
4987 }
4988
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304989 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
4990 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004991
4992 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
4993 ifname, HDD_IPA_IPV4_NAME_EXT);
4994 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
4995 ifname, HDD_IPA_IPV6_NAME_EXT);
4996
4997 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
4998 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
4999 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5000 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
5001
5002 /*
5003 * Interface ID is 3rd byte in the CLD header. Add the meta data and
5004 * mask to identify the interface in IPA hardware
5005 */
5006 rx_prop[IPA_IP_v4].attrib.meta_data =
5007 htonl(iface_context->adapter->sessionId << 16);
5008 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
5009
5010 rx_intf.num_props++;
5011 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5012 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
5013 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
5014 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5015 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
5016 rx_prop[IPA_IP_v4].attrib.meta_data =
5017 htonl(iface_context->adapter->sessionId << 16);
5018 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
5019
5020 rx_intf.num_props++;
5021 }
5022
5023 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
5024 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5025 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
5026 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
5027 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
5028 IPA_RESOURCE_NAME_MAX);
5029 tx_intf.num_props++;
5030
5031 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5032 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
5033 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5034 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
5035 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
5036 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
5037 IPA_RESOURCE_NAME_MAX);
5038 tx_intf.num_props++;
5039 }
5040
5041 tx_intf.prop = tx_prop;
5042 rx_intf.prop = rx_prop;
5043
5044 /* Call the ipa api to register interface */
5045 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
5046
Yun Park52b2b992016-09-22 15:49:51 -07005047 /* Register IPA Tx desc free callback */
5048 qdf_nbuf_reg_free_cb(hdd_ipa_nbuf_cb);
5049
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005050register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305051 qdf_mem_free(tx_prop);
5052 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005053 return ret;
5054}
5055
5056/**
5057 * hdd_remove_ipa_header() - Remove a specific header from IPA
5058 * @name: Name of the header to be removed
5059 *
5060 * Return: None
5061 */
5062static void hdd_ipa_remove_header(char *name)
5063{
5064 struct ipa_ioc_get_hdr hdrlookup;
5065 int ret = 0, len;
5066 struct ipa_ioc_del_hdr *ipa_hdr;
5067
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305068 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005069 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
5070 ret = ipa_get_hdr(&hdrlookup);
5071 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005072 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005073 name, ret);
5074 return;
5075 }
5076
Srinivas Girigowda97852372017-03-06 16:52:59 -08005077 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005078 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305079 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005080 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305081 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005082 return;
5083 }
5084 ipa_hdr->num_hdls = 1;
5085 ipa_hdr->commit = 0;
5086 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
5087 ipa_hdr->hdl[0].status = -1;
5088 ret = ipa_del_hdr(ipa_hdr);
5089 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305090 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005091 ret);
5092
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305093 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005094}
5095
5096/**
Yun Parkb187d542016-11-14 18:10:04 -08005097 * wlan_ipa_add_hdr() - Add IPA Tx header
5098 * @ipa_hdr: pointer to IPA header addition parameters
5099 *
5100 * Call IPA API to add IPA Tx header descriptor
5101 * and dump Tx header struct
5102 *
5103 * Return: 0 for success, non-zero for failure
5104 */
5105static int wlan_ipa_add_hdr(struct ipa_ioc_add_hdr *ipa_hdr)
5106{
5107 int ret;
5108
Srinivas Girigowda97852372017-03-06 16:52:59 -08005109 hdd_debug("==== IPA Tx Header ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08005110 "name: %s\n"
5111 "hdr_len: %d\n"
5112 "type: %d\n"
5113 "is_partial: %d\n"
5114 "hdr_hdl: 0x%x\n"
5115 "status: %d\n"
5116 "is_eth2_ofst_valid: %d\n"
5117 "eth2_ofst: %d\n",
5118 ipa_hdr->hdr[0].name,
5119 ipa_hdr->hdr[0].hdr_len,
5120 ipa_hdr->hdr[0].type,
5121 ipa_hdr->hdr[0].is_partial,
5122 ipa_hdr->hdr[0].hdr_hdl,
5123 ipa_hdr->hdr[0].status,
5124 ipa_hdr->hdr[0].is_eth2_ofst_valid,
5125 ipa_hdr->hdr[0].eth2_ofst);
5126
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08005127 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "hdr:",
Yun Parkb187d542016-11-14 18:10:04 -08005128 ipa_hdr->hdr[0].hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
5129
5130 ret = ipa_add_hdr(ipa_hdr);
5131 return ret;
5132}
5133
5134/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005135 * hdd_ipa_add_header_info() - Add IPA header for a given interface
5136 * @hdd_ipa: Global HDD IPA context
5137 * @iface_context: Interface-specific HDD IPA context
5138 * @mac_addr: Interface MAC address
5139 *
5140 * Return: 0 on success, negativer errno value on error
5141 */
5142static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
5143 struct hdd_ipa_iface_context *iface_context,
5144 uint8_t *mac_addr)
5145{
5146 hdd_adapter_t *adapter = iface_context->adapter;
5147 char *ifname;
5148 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
5149 int ret = -EINVAL;
5150 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
5151 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
5152
5153 ifname = adapter->dev->name;
5154
Srinivas Girigowda97852372017-03-06 16:52:59 -08005155 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005156 ifname, mac_addr);
5157
5158 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305159 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005160 + sizeof(struct ipa_hdr_add));
5161 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305162 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005163 "%s: ipa_hdr allocation failed", ifname);
5164 ret = -ENOMEM;
5165 goto end;
5166 }
5167
5168 ipa_hdr->commit = 0;
5169 ipa_hdr->num_hdrs = 1;
5170
5171 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5172 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
5173 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
5174 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
5175 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305176 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005177 "ifname=%s, vdev_id=%d",
5178 ifname, uc_tx_hdr->ipa_hd.vdev_id);
5179 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5180 ifname, HDD_IPA_IPV4_NAME_EXT);
5181 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
5182 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
5183 ipa_hdr->hdr[0].is_partial = 1;
5184 ipa_hdr->hdr[0].hdr_hdl = 0;
5185 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
5186 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5187
Yun Parkb187d542016-11-14 18:10:04 -08005188 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005189 } else {
5190 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
5191
5192 /* Set the Source MAC */
5193 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
5194 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
5195
5196 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5197 ifname, HDD_IPA_IPV4_NAME_EXT);
5198 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
5199 ipa_hdr->hdr[0].is_partial = 1;
5200 ipa_hdr->hdr[0].hdr_hdl = 0;
5201 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
5202 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5203
5204 /* Set the type to IPV4 in the header */
5205 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
5206
5207 ret = ipa_add_hdr(ipa_hdr);
5208 }
5209 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305210 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005211 ifname, ret);
5212 goto end;
5213 }
5214
Srinivas Girigowda97852372017-03-06 16:52:59 -08005215 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005216 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
5217
5218 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5219 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5220 ifname, HDD_IPA_IPV6_NAME_EXT);
5221
5222 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5223 uc_tx_hdr =
5224 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
5225 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08005226 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005227 } else {
5228 /* Set the type to IPV6 in the header */
5229 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
5230 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08005231 ret = ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005232 }
5233
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005234 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305235 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005236 "%s: IPv6 add hdr failed: %d", ifname, ret);
5237 goto clean_ipv4_hdr;
5238 }
5239
Srinivas Girigowda97852372017-03-06 16:52:59 -08005240 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005241 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
5242 }
5243
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305244 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005245
5246 return ret;
5247
5248clean_ipv4_hdr:
5249 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5250 ifname, HDD_IPA_IPV4_NAME_EXT);
5251 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
5252end:
5253 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305254 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005255
5256 return ret;
5257}
5258
5259/**
5260 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
5261 * @adapter: Adapter upon which IPA was previously configured
5262 *
5263 * Return: None
5264 */
5265static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
5266{
5267 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5268 int ret;
5269 char name_ipa[IPA_RESOURCE_NAME_MAX];
5270
5271 /* Remove the headers */
5272 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
5273 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
5274 hdd_ipa_remove_header(name_ipa);
5275
5276 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5277 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
5278 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
5279 hdd_ipa_remove_header(name_ipa);
5280 }
5281 /* unregister the interface with IPA */
5282 ret = ipa_deregister_intf(adapter->dev->name);
5283 if (ret)
Srinivas Girigowda97852372017-03-06 16:52:59 -08005284 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005285 "%s: ipa_deregister_intf fail: %d",
5286 adapter->dev->name, ret);
5287}
5288
5289/**
5290 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
5291 * @iface_context: interface-specific IPA context
5292 *
5293 * Return: None
5294 */
5295static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
5296{
5297 if (iface_context == NULL)
5298 return;
5299
5300 hdd_ipa_clean_hdr(iface_context->adapter);
5301
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305302 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005303 iface_context->adapter->ipa_context = NULL;
5304 iface_context->adapter = NULL;
5305 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305306 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005307 iface_context->ifa_address = 0;
5308 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305309 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005310 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05305311 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005312 }
5313 iface_context->hdd_ipa->num_iface--;
5314}
5315
5316/**
5317 * hdd_ipa_setup_iface() - Setup IPA on a given interface
5318 * @hdd_ipa: HDD IPA global context
5319 * @adapter: Interface upon which IPA is being setup
5320 * @sta_id: Station ID of the API instance
5321 *
5322 * Return: 0 on success, negative errno value on error
5323 */
5324static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
5325 hdd_adapter_t *adapter, uint8_t sta_id)
5326{
5327 struct hdd_ipa_iface_context *iface_context = NULL;
5328 void *tl_context = NULL;
5329 int i, ret = 0;
5330
5331 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
5332 * channel change indication. Since these indications are sent by lower
5333 * layer as SAP updates and IPA doesn't have to do anything for these
5334 * updates so ignoring!
5335 */
Krunal Sonibe766b02016-03-10 13:00:44 -08005336 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005337 return 0;
5338
5339 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5340 if (hdd_ipa->iface_context[i].adapter == NULL) {
5341 iface_context = &(hdd_ipa->iface_context[i]);
5342 break;
5343 }
5344 }
5345
5346 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305347 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005348 "All the IPA interfaces are in use");
5349 ret = -ENOMEM;
5350 goto end;
5351 }
5352
5353 adapter->ipa_context = iface_context;
5354 iface_context->adapter = adapter;
5355 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005356 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07005357 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005358 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305359 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005360 "Not able to get TL context sta_id: %d", sta_id);
5361 ret = -EINVAL;
5362 goto end;
5363 }
5364
5365 iface_context->tl_context = tl_context;
5366
5367 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
5368 adapter->dev->dev_addr);
5369
5370 if (ret)
5371 goto end;
5372
5373 /* Configure the TX and RX pipes filter rules */
5374 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
5375 if (ret)
5376 goto cleanup_header;
5377
5378 hdd_ipa->num_iface++;
5379 return ret;
5380
5381cleanup_header:
5382
5383 hdd_ipa_clean_hdr(adapter);
5384end:
5385 if (iface_context)
5386 hdd_ipa_cleanup_iface(iface_context);
5387 return ret;
5388}
5389
Yun Parka27049a2016-10-11 12:30:49 -07005390#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005391/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005392 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005393 * @mcc_mode: 0=MCC/1=SCC
5394 *
5395 * Return: 0 on success, negative errno value on error
5396 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005397static int __hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005398{
5399 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305400 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005401 hdd_adapter_t *pAdapter;
5402 struct ipa_msg_meta meta;
5403 struct ipa_wlan_msg *msg;
5404 int ret;
5405
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005406 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005407 return -EINVAL;
5408
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005409 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
5410 return -EINVAL;
5411
5412 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005413 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005414 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305415 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005416 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08005417 if (pAdapter->device_mode == QDF_STA_MODE ||
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005418 pAdapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005419 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005420 pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005421 hdd_deinit_tx_rx(pAdapter);
5422 }
5423 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005424 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005425 adapter_node = next;
5426 }
5427 }
5428
5429 /* Send SCC/MCC Switching event to IPA */
5430 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305431 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005432 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005433 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005434 return -ENOMEM;
5435 }
5436
5437 meta.msg_type = mcc_mode ?
5438 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08005439 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005440
5441 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5442
5443 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005444 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005445 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305446 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005447 }
5448
5449 return ret;
5450}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005451
5452/**
5453 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
5454 * @mcc_mode: 0=MCC/1=SCC
5455 *
5456 * Return: 0 on success, negative errno value on error
5457 */
5458int hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
5459{
5460 int ret;
5461
5462 cds_ssr_protect(__func__);
5463 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
5464 cds_ssr_unprotect(__func__);
5465
5466 return ret;
5467}
Yun Parka27049a2016-10-11 12:30:49 -07005468#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005469
5470/**
5471 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
5472 * @event: IPA WLAN event to be converted to a string
5473 *
5474 * Return: ASCII string representing the IPA WLAN event
5475 */
5476static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
5477{
5478 switch (event) {
5479 case WLAN_CLIENT_CONNECT:
5480 return "WLAN_CLIENT_CONNECT";
5481 case WLAN_CLIENT_DISCONNECT:
5482 return "WLAN_CLIENT_DISCONNECT";
5483 case WLAN_CLIENT_POWER_SAVE_MODE:
5484 return "WLAN_CLIENT_POWER_SAVE_MODE";
5485 case WLAN_CLIENT_NORMAL_MODE:
5486 return "WLAN_CLIENT_NORMAL_MODE";
5487 case SW_ROUTING_ENABLE:
5488 return "SW_ROUTING_ENABLE";
5489 case SW_ROUTING_DISABLE:
5490 return "SW_ROUTING_DISABLE";
5491 case WLAN_AP_CONNECT:
5492 return "WLAN_AP_CONNECT";
5493 case WLAN_AP_DISCONNECT:
5494 return "WLAN_AP_DISCONNECT";
5495 case WLAN_STA_CONNECT:
5496 return "WLAN_STA_CONNECT";
5497 case WLAN_STA_DISCONNECT:
5498 return "WLAN_STA_DISCONNECT";
5499 case WLAN_CLIENT_CONNECT_EX:
5500 return "WLAN_CLIENT_CONNECT_EX";
5501
5502 case IPA_WLAN_EVENT_MAX:
5503 default:
5504 return "UNKNOWN";
5505 }
5506}
5507
5508/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07005509 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
5510 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
5511 *
5512 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
5513 */
5514static enum ipa_wlan_event
5515hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
5516{
5517 enum ipa_wlan_event ipa_event;
5518
5519 switch (hdd_ipa_event_type) {
5520 case HDD_IPA_CLIENT_CONNECT:
5521 ipa_event = WLAN_CLIENT_CONNECT;
5522 break;
5523 case HDD_IPA_CLIENT_DISCONNECT:
5524 ipa_event = WLAN_CLIENT_DISCONNECT;
5525 break;
5526 case HDD_IPA_AP_CONNECT:
5527 ipa_event = WLAN_AP_CONNECT;
5528 break;
5529 case HDD_IPA_AP_DISCONNECT:
5530 ipa_event = WLAN_AP_DISCONNECT;
5531 break;
5532 case HDD_IPA_STA_CONNECT:
5533 ipa_event = WLAN_STA_CONNECT;
5534 break;
5535 case HDD_IPA_STA_DISCONNECT:
5536 ipa_event = WLAN_STA_DISCONNECT;
5537 break;
5538 case HDD_IPA_CLIENT_CONNECT_EX:
5539 ipa_event = WLAN_CLIENT_CONNECT_EX;
5540 break;
5541 case HDD_IPA_WLAN_EVENT_MAX:
5542 default:
5543 ipa_event = IPA_WLAN_EVENT_MAX;
5544 break;
5545 }
5546 return ipa_event;
5547
5548}
5549
5550/**
5551 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005552 * @adapter: adapter upon which the event was received
5553 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07005554 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005555 * @mac_address: MAC address associated with the event
5556 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07005557 * This function is meant to be called from within wlan_hdd_ipa.c
5558 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005559 * Return: 0 on success, negative errno value on error
5560 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07005561static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005562 enum ipa_wlan_event type, uint8_t *mac_addr)
5563{
5564 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5565 struct ipa_msg_meta meta;
5566 struct ipa_wlan_msg *msg;
5567 struct ipa_wlan_msg_ex *msg_ex = NULL;
5568 int ret;
5569
Srinivas Girigowda97852372017-03-06 16:52:59 -08005570 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005571 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5572 mac_addr, sta_id);
5573
5574 if (type >= IPA_WLAN_EVENT_MAX)
5575 return -EINVAL;
5576
5577 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5578 return -EINVAL;
5579
5580 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305581 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005582 return -EINVAL;
5583 }
5584
5585 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5586 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005587 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005588 return 0;
5589 }
5590
5591 /*
5592 * During IPA UC resource loading/unloading new events can be issued.
5593 * Store the events separately and handle them later.
5594 */
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005595 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5596 if (hdd_ipa->resource_loading) {
5597 unsigned int pending_event_count;
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005598 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005599
Yun Park64c405e2017-01-10 22:35:51 -08005600 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5601 "IPA resource load in progress");
Yun Park7c4f31b2016-11-30 10:09:21 -08005602
Yun Park64c405e2017-01-10 22:35:51 -08005603 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005604
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005605 pending_event_count =
5606 qdf_list_size(&hdd_ipa->pending_event);
5607 if (pending_event_count >=
5608 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005609 hdd_debug("Reached max pending event count");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005610 qdf_list_remove_front(&hdd_ipa->pending_event,
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005611 (qdf_list_node_t **)&pending_event);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005612 } else {
5613 pending_event =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005614 qdf_mem_malloc(sizeof(*pending_event));
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005615 }
5616
5617 if (!pending_event) {
Yun Park64c405e2017-01-10 22:35:51 -08005618 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park7c4f31b2016-11-30 10:09:21 -08005619 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5620 "Pending event memory alloc fail");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005621 return -ENOMEM;
5622 }
5623
5624 pending_event->adapter = adapter;
5625 pending_event->sta_id = sta_id;
5626 pending_event->type = type;
5627 qdf_mem_copy(pending_event->mac_addr,
5628 mac_addr,
5629 QDF_MAC_ADDR_SIZE);
5630 qdf_list_insert_back(&hdd_ipa->pending_event,
5631 &pending_event->node);
5632
Yun Park64c405e2017-01-10 22:35:51 -08005633 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005634 return 0;
5635 } else if (hdd_ipa->resource_unloading) {
Yun Park64c405e2017-01-10 22:35:51 -08005636 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5637 "IPA resource unload in progress");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005638 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005640 }
5641
5642 hdd_ipa->stats.event[type]++;
5643
Leo Chang3bc8fed2015-11-13 10:59:47 -08005644 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005645 switch (type) {
5646 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005647 qdf_mutex_acquire(&hdd_ipa->event_lock);
5648
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005649 /* STA already connected and without disconnect, connect again
5650 * This is Roaming scenario
5651 */
5652 if (hdd_ipa->sta_connected)
5653 hdd_ipa_cleanup_iface(adapter->ipa_context);
5654
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005655 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5656 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305657 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005658 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005659 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005660
Yun Park8f289c82016-10-18 16:38:21 -07005661 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5662 (hdd_ipa->sap_num_connected_sta > 0) &&
5663 !hdd_ipa->sta_connected) {
5664 qdf_mutex_release(&hdd_ipa->event_lock);
5665 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005666 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005667 qdf_mutex_acquire(&hdd_ipa->event_lock);
5668 }
5669
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005670 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005671 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005672 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005674 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005675
5676 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005677 break;
5678
5679 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005680 qdf_mutex_acquire(&hdd_ipa->event_lock);
5681
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005682 /* For DFS channel we get two start_bss event (before and after
5683 * CAC). Also when ACS range includes both DFS and non DFS
5684 * channels, we could possibly change channel many times due to
5685 * RADAR detection and chosen channel may not be a DFS channels.
5686 * So dont return error here. Just discard the event.
5687 */
Yun Park8f289c82016-10-18 16:38:21 -07005688 if (adapter->ipa_context) {
5689 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005690 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005691 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005692
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005693 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5694 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005695 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005696 hdd_err("%s: Evt: %d, Interface setup failed",
5697 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005698 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005699 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005700
Yun Park8f289c82016-10-18 16:38:21 -07005701 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5702 qdf_mutex_release(&hdd_ipa->event_lock);
5703 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005704 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005705 qdf_mutex_acquire(&hdd_ipa->event_lock);
5706 }
5707
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005708 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005709 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005710 (adapter->ipa_context))->iface_id;
5711
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305712 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005713 break;
5714
5715 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305716 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005717
5718 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005719 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005720 hdd_err("%s: Evt: %d, STA already disconnected",
5721 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005722 return -EINVAL;
5723 }
Yun Parka37592b2016-06-11 17:10:28 -07005724
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005725 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005726
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005727 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005728 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005729 msg_ex->name);
5730 } else {
5731 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005732 if (!hdd_ipa->num_iface &&
5733 (HDD_IPA_UC_NUM_WDI_PIPE ==
5734 hdd_ipa->activated_fw_pipe))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005735 hdd_ipa_uc_handle_last_discon(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005736 }
5737
Yun Park74127cf2016-09-18 11:22:41 -07005738 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5739 (hdd_ipa->sap_num_connected_sta > 0)) {
Yun Park8f289c82016-10-18 16:38:21 -07005740 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005741 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005742 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005743 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005744 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5745 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005746 }
5747
Yun Park8f289c82016-10-18 16:38:21 -07005748 hdd_ipa_cleanup_iface(adapter->ipa_context);
5749
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305750 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005751 break;
5752
5753 case WLAN_AP_DISCONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005754 qdf_mutex_acquire(&hdd_ipa->event_lock);
5755
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005756 if (!adapter->ipa_context) {
Yun Park64c405e2017-01-10 22:35:51 -08005757 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005758 hdd_err("%s: Evt: %d, SAP already disconnected",
5759 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005760 return -EINVAL;
5761 }
5762
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005763 if ((!hdd_ipa->num_iface) &&
5764 (HDD_IPA_UC_NUM_WDI_PIPE ==
5765 hdd_ipa->activated_fw_pipe)) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005766 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005767 /*
5768 * We disable WDI pipes directly here since
5769 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5770 * processed when unloading WLAN driver is in
5771 * progress
5772 */
5773 hdd_ipa_uc_disable_pipes(hdd_ipa);
5774 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305775 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005776 "NO INTF left but still pipe clean up");
5777 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5778 }
5779 }
5780
5781 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005782 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005783 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005784 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005785 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005786 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5787 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005788 }
Yun Parka37592b2016-06-11 17:10:28 -07005789
Yun Park8f289c82016-10-18 16:38:21 -07005790 hdd_ipa_cleanup_iface(adapter->ipa_context);
5791
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305792 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005793 break;
5794
5795 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005796 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005797 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005798 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305799 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005800 return 0;
5801 }
5802
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305803 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005804 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5805 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005806 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305807 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005808 "%s: STA ID %d found, not valid",
5809 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005810 return 0;
5811 }
Yun Park312f71a2015-12-08 10:22:42 -08005812
5813 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005814 if (hdd_ipa->sap_num_connected_sta == 0 &&
5815 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005816 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005817 hdd_ipa->sta_connected) {
5818 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005819 hdd_ipa_uc_offload_enable_disable(
5820 hdd_get_adapter(hdd_ipa->hdd_ctx,
5821 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005822 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005823 qdf_mutex_acquire(&hdd_ipa->event_lock);
5824 }
Yun Parka37592b2016-06-11 17:10:28 -07005825
Yun Park312f71a2015-12-08 10:22:42 -08005826 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5827 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305828 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005829 "%s: handle 1st con ret %d",
5830 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005831
5832 if (hdd_ipa_uc_sta_is_enabled(
5833 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005834 hdd_ipa->sta_connected) {
5835 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005836 hdd_ipa_uc_offload_enable_disable(
5837 hdd_get_adapter(
5838 hdd_ipa->hdd_ctx,
5839 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005840 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005841 } else {
5842 qdf_mutex_release(&hdd_ipa->event_lock);
5843 }
Yun Parka37592b2016-06-11 17:10:28 -07005844
Yun Park312f71a2015-12-08 10:22:42 -08005845 return ret;
5846 }
5847 }
5848
5849 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005850
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305851 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005852
5853 meta.msg_type = type;
5854 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5855 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305856 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005857
5858 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305859 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005860 "msg_ex allocation failed");
5861 return -ENOMEM;
5862 }
5863 strlcpy(msg_ex->name, adapter->dev->name,
5864 IPA_RESOURCE_NAME_MAX);
5865 msg_ex->num_of_attribs = 1;
5866 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5867 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5868 msg_ex->attribs[0].offset =
5869 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5870 } else {
5871 msg_ex->attribs[0].offset =
5872 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5873 }
5874 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5875 IPA_MAC_ADDR_SIZE);
5876
5877 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5878
5879 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005880 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305881 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305882 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005883 return ret;
5884 }
5885 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005886 return ret;
5887
5888 case WLAN_CLIENT_DISCONNECT:
5889 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005890 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005891 "%s: IPA UC OFFLOAD NOT ENABLED",
5892 msg_ex->name);
5893 return 0;
5894 }
5895
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305896 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005897 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005898 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305899 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005900 "%s: STA ID %d NOT found, not valid",
5901 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005902 return 0;
5903 }
5904 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005905
Yun Park9b5030f2016-11-08 12:02:37 -08005906 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005907 if (!hdd_ipa->sap_num_connected_sta &&
5908 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005909 if ((false == hdd_ipa->resource_unloading)
5910 && (HDD_IPA_UC_NUM_WDI_PIPE ==
5911 hdd_ipa->activated_fw_pipe)) {
5912 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5913 }
5914
Yun Park8f289c82016-10-18 16:38:21 -07005915 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005916
5917 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5918 hdd_ipa->sta_connected)
5919 hdd_ipa_uc_offload_enable_disable(
5920 hdd_get_adapter(hdd_ipa->hdd_ctx,
5921 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005922 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005923 } else {
5924 qdf_mutex_release(&hdd_ipa->event_lock);
5925 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005926 break;
5927
5928 default:
5929 return 0;
5930 }
5931
5932 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305933 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005934 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305935 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005936 return -ENOMEM;
5937 }
5938
5939 meta.msg_type = type;
5940 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5941 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5942
Srinivas Girigowda97852372017-03-06 16:52:59 -08005943 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005944 msg->name, meta.msg_type);
5945
5946 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5947
5948 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005949 hdd_err("%s: Evt: %d fail:%d",
5950 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305951 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005952 return ret;
5953 }
5954
5955 hdd_ipa->stats.num_send_msg++;
5956
5957end:
5958 return ret;
5959}
5960
5961/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005962 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005963 * @adapter: adapter upon which the event was received
5964 * @sta_id: station id for the event
5965 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5966 * @mac_address: MAC address associated with the event
5967 *
5968 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5969 *
5970 * Return: 0 on success, negative errno value on error
5971 */
5972int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
5973 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5974{
5975 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005976 int ret = 0;
5977
5978 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005979
Leo Changa202b522016-10-14 16:13:50 -07005980 /* Data path offload only support for STA and SAP mode */
5981 if ((QDF_STA_MODE == adapter->device_mode) ||
5982 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005983 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005984
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005985 cds_ssr_unprotect(__func__);
5986
5987 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005988}
5989
5990/**
5991 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5992 * @hdd_ipa: Global HDD IPA context
5993 *
5994 * Return: None
5995 */
5996static void
5997hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
5998{
5999 unsigned int pending_event_count;
6000 struct ipa_uc_pending_event *pending_event = NULL;
6001
6002 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08006003 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07006004 "%s, Pending Event Count %d", __func__, pending_event_count);
6005 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08006006 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07006007 "%s, No Pending Event", __func__);
6008 return;
6009 }
6010
6011 qdf_list_remove_front(&hdd_ipa->pending_event,
6012 (qdf_list_node_t **)&pending_event);
6013 while (pending_event != NULL) {
6014 __hdd_ipa_wlan_evt(pending_event->adapter,
6015 pending_event->type,
6016 pending_event->sta_id,
6017 pending_event->mac_addr);
6018 qdf_mem_free(pending_event);
6019 pending_event = NULL;
6020 qdf_list_remove_front(&hdd_ipa->pending_event,
6021 (qdf_list_node_t **)&pending_event);
6022 }
6023}
6024
6025/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006026 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
6027 * @state: IPA RM state value
6028 *
6029 * Return: ASCII string representing the IPA RM state
6030 */
6031static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
6032{
6033 switch (state) {
6034 case HDD_IPA_RM_RELEASED:
6035 return "RELEASED";
6036 case HDD_IPA_RM_GRANT_PENDING:
6037 return "GRANT_PENDING";
6038 case HDD_IPA_RM_GRANTED:
6039 return "GRANTED";
6040 }
6041
6042 return "UNKNOWN";
6043}
6044
6045/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006046 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006047 * @hdd_ctx: HDD global context
6048 *
6049 * Allocate hdd_ipa resources, ipa pipe resource and register
6050 * wlan interface with IPA module.
6051 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306052 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006053 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006054static QDF_STATUS __hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006055{
6056 struct hdd_ipa_priv *hdd_ipa = NULL;
6057 int ret, i;
6058 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08006059 struct ol_txrx_pdev_t *pdev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006060
6061 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306062 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006063
Yun Parkbaa62862017-01-18 13:43:34 -08006064 ENTER();
6065
6066 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07006067 if (!pdev) {
6068 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
6069 goto fail_return;
6070 }
6071
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306072 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006073 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306074 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08006075 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006076 }
6077
6078 hdd_ctx->hdd_ipa = hdd_ipa;
6079 ghdd_ipa = hdd_ipa;
6080 hdd_ipa->hdd_ctx = hdd_ctx;
6081 hdd_ipa->num_iface = 0;
6082
6083 /* Create the interface context */
6084 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6085 iface_context = &hdd_ipa->iface_context[i];
6086 iface_context->hdd_ipa = hdd_ipa;
6087 iface_context->cons_client =
6088 hdd_ipa_adapter_2_client[i].cons_client;
6089 iface_context->prod_client =
6090 hdd_ipa_adapter_2_client[i].prod_client;
6091 iface_context->iface_id = i;
6092 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306093 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08006094 }
6095 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08006096 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
6097 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006098 }
6099
Leo Chang69c39692016-10-12 20:11:12 -07006100 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306101 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006102 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05306103 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08006104 qdf_list_create(&hdd_ipa->pending_event, 1000);
6105 qdf_mutex_create(&hdd_ipa->event_lock);
6106 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006107
6108 ret = hdd_ipa_setup_rm(hdd_ipa);
6109 if (ret)
6110 goto fail_setup_rm;
6111
6112 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
6113 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306114 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006115 hdd_ipa->sap_num_connected_sta = 0;
6116 hdd_ipa->ipa_tx_packets_diff = 0;
6117 hdd_ipa->ipa_rx_packets_diff = 0;
6118 hdd_ipa->ipa_p_tx_packets = 0;
6119 hdd_ipa->ipa_p_rx_packets = 0;
6120 hdd_ipa->resource_loading = false;
6121 hdd_ipa->resource_unloading = false;
6122 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07006123 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08006124 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006125 /* Setup IPA sys_pipe for MCC */
6126 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
6127 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
6128 if (ret)
6129 goto fail_create_sys_pipe;
6130 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006131 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
6132 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08006133
6134 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
6135 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
6136 hdd_ipa_uc_fw_op_event_handler);
6137 hdd_ipa->uc_op_work[i].msg = NULL;
6138 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006139 } else {
6140 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
6141 if (ret)
6142 goto fail_create_sys_pipe;
6143 }
6144
Yun Parkbaa62862017-01-18 13:43:34 -08006145 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306146 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006147
6148fail_create_sys_pipe:
6149 hdd_ipa_destroy_rm_resource(hdd_ipa);
6150fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306151 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306152 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08006153 hdd_ctx->hdd_ipa = NULL;
6154 ghdd_ipa = NULL;
6155fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08006156 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306157 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006158}
6159
6160/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006161 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
6162 * @hdd_ctx: HDD global context
6163 *
6164 * Allocate hdd_ipa resources, ipa pipe resource and register
6165 * wlan interface with IPA module.
6166 *
6167 * Return: QDF_STATUS enumeration
6168 */
6169QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
6170{
6171 QDF_STATUS ret;
6172
6173 cds_ssr_protect(__func__);
6174 ret = __hdd_ipa_init(hdd_ctx);
6175 cds_ssr_unprotect(__func__);
6176
6177 return ret;
6178}
6179
Arun Khandavallicc544b32017-01-30 19:52:16 +05306180
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006181/**
Yun Parkf19e07d2015-11-20 11:34:27 -08006182 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
6183 * @hdd_ipa: pointer to HDD IPA struct
6184 *
6185 * Return: none
6186 */
Jeff Johnsond7720632016-10-05 16:04:32 -07006187static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08006188{
6189 struct ipa_uc_pending_event *pending_event = NULL;
6190
Anurag Chouhanffb21542016-02-17 14:33:03 +05306191 while (qdf_list_remove_front(&hdd_ipa->pending_event,
6192 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306193 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08006194 }
6195
Anurag Chouhanffb21542016-02-17 14:33:03 +05306196 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08006197}
6198
6199/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006200 * __hdd_ipa_cleanup - IPA cleanup function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006201 * @hdd_ctx: HDD global context
6202 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306203 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006204 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006205static QDF_STATUS __hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006206{
6207 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
6208 int i;
6209 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05306210 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006211 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
6212
6213 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306214 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006215
6216 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
6217 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
6218 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6219 }
6220
6221 /* Teardown IPA sys_pipe for MCC */
6222 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
6223 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6224
6225 hdd_ipa_destroy_rm_resource(hdd_ipa);
6226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006227 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006228
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306229 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230
Nirav Shahcbc6d722016-03-01 16:24:53 +05306231 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
6232 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306233 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006234
6235 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
6236 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
6237
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306238 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006239 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306240 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306242 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006243 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006244
6245 /* destory the interface lock */
6246 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6247 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306248 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006249 }
6250
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08006252 if (ipa_uc_dereg_rdyCB())
6253 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
6254 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006255 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006256 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08006257 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Govind Singh0487bf22016-08-24 23:08:57 +05306258 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
6259 __func__, hdd_ipa->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006260 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Srinivas Girigowda97852372017-03-06 16:52:59 -08006261 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Govind Singh0487bf22016-08-24 23:08:57 +05306262 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
6263 __func__, hdd_ipa->rx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006264 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
6265 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306266 qdf_mutex_destroy(&hdd_ipa->event_lock);
6267 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08006268 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006269
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006270 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
6271 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
6272 hdd_ipa->uc_op_work[i].msg = NULL;
6273 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006274 }
6275
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306276 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006277 hdd_ctx->hdd_ipa = NULL;
6278
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306279 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006280}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006281
6282/**
6283 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
6284 * @hdd_ctx: HDD global context
6285 *
6286 * Return: QDF_STATUS enumeration
6287 */
6288QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
6289{
6290 QDF_STATUS ret;
6291
6292 cds_ssr_protect(__func__);
6293 ret = __hdd_ipa_cleanup(hdd_ctx);
6294 cds_ssr_unprotect(__func__);
6295
6296 return ret;
6297}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006298#endif /* IPA_OFFLOAD */