blob: 0db3a706c507835eb5253cf37ad1a8fc5303393d [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 }
Yun Park8957d802017-01-25 12:27:29 -08002612
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302613 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002614}
2615
2616
2617/**
2618 * hdd_ipa_uc_offload_enable_disable() - wdi enable/disable notify to fw
2619 * @adapter: device adapter instance
2620 * @offload_type: MCC or SCC
2621 * @enable: TX offload enable or disable
2622 *
2623 * Return: none
2624 */
2625static void hdd_ipa_uc_offload_enable_disable(hdd_adapter_t *adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002626 uint32_t offload_type, bool enable)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002627{
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002628 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002629 struct sir_ipa_offload_enable_disable ipa_offload_enable_disable;
Yun Park8292dcb2016-10-07 16:46:06 -07002630 struct hdd_ipa_iface_context *iface_context = NULL;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002631 uint8_t session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002632
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002633 if (!adapter || !hdd_ipa)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002634 return;
2635
Yun Park8292dcb2016-10-07 16:46:06 -07002636 iface_context = adapter->ipa_context;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002637 session_id = adapter->sessionId;
Yun Park8292dcb2016-10-07 16:46:06 -07002638
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002639 if (!iface_context) {
2640 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2641 "Interface context is NULL");
2642 return;
2643 }
2644
2645 if (enable == hdd_ipa->vdev_offload_enabled[session_id]) {
Yun Park8292dcb2016-10-07 16:46:06 -07002646 /* IPA offload status is already set as desired */
2647 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002648 "%s: (offload_type=%d, vdev_id=%d, enable=%d)",
2649 "IPA offload status is already set",
2650 offload_type, session_id, enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002651 return;
2652 }
2653
Yun Park4540e862016-11-10 16:30:06 -08002654 if (wlan_hdd_validate_session_id(adapter->sessionId)) {
2655 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2656 "invalid session id: %d, offload_type=%d, enable=%d",
2657 adapter->sessionId, offload_type, enable);
2658 return;
2659 }
2660
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302661 qdf_mem_zero(&ipa_offload_enable_disable,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002662 sizeof(ipa_offload_enable_disable));
2663 ipa_offload_enable_disable.offload_type = offload_type;
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002664 ipa_offload_enable_disable.vdev_id = session_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002665 ipa_offload_enable_disable.enable = enable;
2666
Srinivas Girigowda97852372017-03-06 16:52:59 -08002667 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park8292dcb2016-10-07 16:46:06 -07002668 "offload_type=%d, vdev_id=%d, enable=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002669 ipa_offload_enable_disable.offload_type,
2670 ipa_offload_enable_disable.vdev_id,
2671 ipa_offload_enable_disable.enable);
2672
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302673 if (QDF_STATUS_SUCCESS !=
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002674 sme_ipa_offload_enable_disable(WLAN_HDD_GET_HAL_CTX(adapter),
2675 adapter->sessionId, &ipa_offload_enable_disable)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302676 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Jeff Johnsona8a4f542016-11-08 10:56:53 -08002677 "%s: Failure to enable IPA offload (offload_type=%d, vdev_id=%d, enable=%d)",
2678 __func__,
2679 ipa_offload_enable_disable.offload_type,
2680 ipa_offload_enable_disable.vdev_id,
2681 ipa_offload_enable_disable.enable);
Yun Park8292dcb2016-10-07 16:46:06 -07002682 } else {
2683 /* Update the IPA offload status */
Prakash Dhavali89d406d2016-11-23 11:11:00 -08002684 hdd_ipa->vdev_offload_enabled[session_id] =
Yun Park8292dcb2016-10-07 16:46:06 -07002685 ipa_offload_enable_disable.enable;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002686 }
2687}
2688
2689/**
2690 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2691 * @work: uC OP work
2692 *
2693 * Return: None
2694 */
2695static void hdd_ipa_uc_fw_op_event_handler(struct work_struct *work)
2696{
2697 struct op_msg_type *msg;
2698 struct uc_op_work_struct *uc_op_work = container_of(work,
2699 struct uc_op_work_struct, work);
2700 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2701
2702 cds_ssr_protect(__func__);
2703
2704 msg = uc_op_work->msg;
2705 uc_op_work->msg = NULL;
Srinivas Girigowda97852372017-03-06 16:52:59 -08002706 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002707 "%s, posted msg %d", __func__, msg->op_code);
2708
2709 hdd_ipa_uc_op_cb(msg, hdd_ipa->hdd_ctx);
2710
2711 cds_ssr_unprotect(__func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002712}
2713
2714/**
2715 * hdd_ipa_uc_op_event_handler() - Adapter lookup
2716 * hdd_ipa_uc_fw_op_event_handler - IPA uC FW OPvent handler
2717 * @op_msg: operation message received from firmware
2718 * @hdd_ctx: Global HDD context
2719 *
2720 * Return: None
2721 */
2722static void hdd_ipa_uc_op_event_handler(uint8_t *op_msg, void *hdd_ctx)
2723{
2724 struct hdd_ipa_priv *hdd_ipa;
2725 struct op_msg_type *msg;
2726 struct uc_op_work_struct *uc_op_work;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302727 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002728
2729 status = wlan_hdd_validate_context(hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05302730 if (status)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002731 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002732
2733 msg = (struct op_msg_type *)op_msg;
2734 hdd_ipa = ((hdd_context_t *)hdd_ctx)->hdd_ipa;
2735
2736 if (unlikely(!hdd_ipa))
2737 goto end;
2738
2739 if (HDD_IPA_UC_OPCODE_MAX <= msg->op_code) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05302740 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s: Invalid OP Code (%d)",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002741 __func__, msg->op_code);
2742 goto end;
2743 }
2744
2745 uc_op_work = &hdd_ipa->uc_op_work[msg->op_code];
2746 if (uc_op_work->msg)
2747 /* When the same uC OPCODE is already pended, just return */
2748 goto end;
2749
2750 uc_op_work->msg = msg;
2751 schedule_work(&uc_op_work->work);
2752 return;
2753
2754end:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302755 qdf_mem_free(op_msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002756}
2757
2758/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08002759 * hdd_ipa_init_uc_op_work - init ipa uc op work
2760 * @work: struct work_struct
2761 * @work_handler: work_handler
2762 *
2763 * Return: none
2764 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08002765static void hdd_ipa_init_uc_op_work(struct work_struct *work,
Yun Park637d6482016-10-05 10:51:33 -07002766 work_func_t work_handler)
Rajeev Kumar217f2172016-01-06 18:11:55 -08002767{
2768 INIT_WORK(work, work_handler);
2769}
Rajeev Kumar217f2172016-01-06 18:11:55 -08002770
Yun Park637d6482016-10-05 10:51:33 -07002771#ifdef FEATURE_METERING
2772/**
2773 * __hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2774 * IPA calls to get WLAN stats or set quota limit.
2775 * @priv: pointer to private data registered with IPA (we register a
2776 *» pointer to the global IPA context)
2777 * @evt: the IPA event which triggered the callback
2778 * @data: data associated with the event
2779 *
2780 * Return: None
2781 */
2782static void __hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2783 void *data)
2784{
2785 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
2786 hdd_adapter_t *adapter = NULL;
2787 struct ipa_get_wdi_sap_stats *wdi_sap_stats;
2788 struct ipa_set_wifi_quota *ipa_set_quota;
2789 int ret = 0;
2790
2791 if (wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
2792 return;
2793
2794 adapter = hdd_get_adapter(hdd_ipa->hdd_ctx, QDF_STA_MODE);
2795
2796 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO, "event=%d", evt);
2797
2798 switch (evt) {
2799 case IPA_GET_WDI_SAP_STATS:
2800 /* fill-up ipa_get_wdi_sap_stats structure after getting
2801 ipa_uc_fw_stats from FW */
2802 wdi_sap_stats = data;
2803
2804 if (!adapter) {
2805 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2806 "IPA uC share stats failed - no adapter");
2807 wdi_sap_stats->stats_valid = 0;
2808 return;
2809 }
2810
2811 INIT_COMPLETION(hdd_ipa->ipa_uc_sharing_stats_comp);
2812 INIT_COMPLETION(hdd_ipa->ipa_uc_set_quota_comp);
2813 hdd_ipa_uc_sharing_stats_request(adapter,
2814 wdi_sap_stats->reset_stats);
2815 ret = wait_for_completion_timeout(
2816 &hdd_ipa->ipa_uc_sharing_stats_comp,
2817 msecs_to_jiffies(IPA_UC_SHARING_STATES_WAIT_TIME));
2818 if (!ret) {
2819 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2820 "IPA uC share stats request timed out");
2821 wdi_sap_stats->stats_valid = 0;
2822 } else {
2823 wdi_sap_stats->stats_valid = 1;
2824
2825 wdi_sap_stats->ipv4_rx_packets =
2826 hdd_ipa->ipa_sharing_stats.ipv4_rx_packets;
2827 wdi_sap_stats->ipv4_rx_bytes =
2828 hdd_ipa->ipa_sharing_stats.ipv4_rx_bytes;
2829 wdi_sap_stats->ipv6_rx_packets =
2830 hdd_ipa->ipa_sharing_stats.ipv6_rx_packets;
2831 wdi_sap_stats->ipv6_rx_bytes =
2832 hdd_ipa->ipa_sharing_stats.ipv6_rx_bytes;
2833 wdi_sap_stats->ipv4_tx_packets =
2834 hdd_ipa->ipa_sharing_stats.ipv4_tx_packets;
2835 wdi_sap_stats->ipv4_tx_bytes =
2836 hdd_ipa->ipa_sharing_stats.ipv4_tx_bytes;
2837 wdi_sap_stats->ipv6_tx_packets =
2838 hdd_ipa->ipa_sharing_stats.ipv6_tx_packets;
2839 wdi_sap_stats->ipv6_tx_bytes =
2840 hdd_ipa->ipa_sharing_stats.ipv6_tx_bytes;
2841 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
2842 "%s:%d,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu",
2843 "IPA_GET_WDI_SAP_STATS",
2844 wdi_sap_stats->stats_valid,
2845 wdi_sap_stats->ipv4_rx_packets,
2846 wdi_sap_stats->ipv4_rx_bytes,
2847 wdi_sap_stats->ipv6_rx_packets,
2848 wdi_sap_stats->ipv6_rx_bytes,
2849 wdi_sap_stats->ipv4_tx_packets,
2850 wdi_sap_stats->ipv4_tx_bytes,
2851 wdi_sap_stats->ipv6_tx_packets,
2852 wdi_sap_stats->ipv6_tx_bytes);
2853 }
2854 break;
2855 case IPA_SET_WIFI_QUOTA:
2856 /* get ipa_set_wifi_quota structure from IPA and pass to FW
2857 through quota_exceeded field in ipa_uc_fw_stats */
2858 ipa_set_quota = data;
2859
2860 if (!adapter) {
2861 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2862 "IPA uC set quota failed - no adapter");
2863 ipa_set_quota->set_valid = 0;
2864 return;
2865 }
2866
2867 hdd_ipa_uc_set_quota(adapter, ipa_set_quota->set_quota,
2868 ipa_set_quota->quota_bytes);
2869
2870 ret = wait_for_completion_timeout(
2871 &hdd_ipa->ipa_uc_set_quota_comp,
2872 msecs_to_jiffies(IPA_UC_SET_QUOTA_WAIT_TIME));
2873 if (!ret) {
2874 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
2875 "IPA uC set quota request timed out");
2876 ipa_set_quota->set_valid = 0;
2877 } else {
2878 ipa_set_quota->quota_bytes =
2879 ((uint64_t)(hdd_ipa->ipa_quota_rsp.quota_hi)
2880 <<32)|hdd_ipa->ipa_quota_rsp.quota_lo;
2881 ipa_set_quota->set_valid =
2882 hdd_ipa->ipa_quota_rsp.success;
2883 }
2884
2885 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG, "SET_QUOTA: %llu, %d",
2886 ipa_set_quota->quota_bytes,
2887 ipa_set_quota->set_valid);
2888 break;
2889 }
2890}
2891
2892/**
2893 * hdd_ipa_wdi_meter_notifier_cb() - WLAN to IPA callback handler.
2894 * IPA calls to get WLAN stats or set quota limit.
2895 * @priv: pointer to private data registered with IPA (we register a
2896 *» pointer to the global IPA context)
2897 * @evt: the IPA event which triggered the callback
2898 * @data: data associated with the event
2899 *
2900 * Return: None
2901 */
2902static void hdd_ipa_wdi_meter_notifier_cb(enum ipa_wdi_meter_evt_type evt,
2903 void *data)
2904{
2905 cds_ssr_protect(__func__);
2906 __hdd_ipa_wdi_meter_notifier_cb(evt, data);
2907 cds_ssr_unprotect(__func__);
2908}
2909
2910static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt,
2911 struct ipa_wdi_in_params *pipe_in)
2912{
2913 pipe_in->wdi_notify = hdd_ipa_wdi_meter_notifier_cb;
2914
2915 init_completion(&ipa_ctxt->ipa_uc_sharing_stats_comp);
2916 init_completion(&ipa_ctxt->ipa_uc_set_quota_comp);
2917}
2918#else
2919static void hdd_ipa_init_metering(struct hdd_ipa_priv *ipa_ctxt,
2920 struct ipa_wdi_in_params *pipe_in)
2921{
2922}
2923#endif
2924
Rajeev Kumar217f2172016-01-06 18:11:55 -08002925/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002926 * hdd_ipa_uc_ol_init() - Initialize IPA uC offload
2927 * @hdd_ctx: Global HDD context
2928 *
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002929 * This function is called to update IPA pipe configuration with resources
2930 * allocated by wlan driver (cds_pre_enable) before enabling it in FW
2931 * (cds_enable)
2932 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302933 * Return: QDF_STATUS
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002934 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002935QDF_STATUS hdd_ipa_uc_ol_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002936{
2937 struct ipa_wdi_in_params pipe_in;
2938 struct ipa_wdi_out_params pipe_out;
2939 struct hdd_ipa_priv *ipa_ctxt = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
Leo Changfdb45c32016-10-28 11:09:23 -07002940 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
Yun Parkbaa62862017-01-18 13:43:34 -08002941 struct ol_txrx_pdev_t *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
2942 int ret;
2943 QDF_STATUS stat = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002944
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002945 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
2946 return QDF_STATUS_SUCCESS;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002947
Manikandan Mohan2e803a02017-02-14 14:57:53 -08002948 ENTER();
2949 /* Do only IPA Pipe specific configuration here. All one time
2950 * initialization wrt IPA UC shall in hdd_ipa_init and those need
2951 * to be reinit at SSR shall in be SSR deinit / reinit functions.
2952 */
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002953 if (!pdev || !soc) {
2954 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "DP context is NULL");
Yun Parkbaa62862017-01-18 13:43:34 -08002955 stat = QDF_STATUS_E_FAILURE;
2956 goto fail_return;
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002957 }
Yun Parkbaa62862017-01-18 13:43:34 -08002958
2959 cdp_ipa_get_resource(soc, (void *)pdev, &ipa_ctxt->ipa_resource);
Manikandan Mohanbb8a7ee2017-02-09 11:26:53 -08002960 if ((ipa_ctxt->ipa_resource.ce_sr_base_paddr == 0) ||
2961 (ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr == 0) ||
2962 (ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr == 0) ||
2963 (ipa_ctxt->ipa_resource.rx2_rdy_ring_base_paddr == 0)) {
2964 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
2965 "IPA UC resource alloc fail");
2966 return QDF_STATUS_E_FAILURE;
2967 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08002968 qdf_mem_zero(&ipa_ctxt->cons_pipe_in, sizeof(struct ipa_wdi_in_params));
2969 qdf_mem_zero(&ipa_ctxt->prod_pipe_in, sizeof(struct ipa_wdi_in_params));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05302970 qdf_mem_zero(&pipe_in, sizeof(struct ipa_wdi_in_params));
2971 qdf_mem_zero(&pipe_out, sizeof(struct ipa_wdi_out_params));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002972
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002973 /* TX PIPE */
2974 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
2975 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
2976 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
2977 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
2978 pipe_in.sys.ipa_ep_cfg.hdr.hdr_additional_const_len =
2979 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
2980 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
2981 pipe_in.sys.client = IPA_CLIENT_WLAN1_CONS;
2982 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize;
2983 pipe_in.sys.priv = hdd_ctx->hdd_ipa;
2984 pipe_in.sys.ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
2985 pipe_in.sys.notify = hdd_ipa_i2w_cb;
2986 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08002987 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
2988 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002989 pipe_in.sys.keep_ipa_awake = true;
2990 }
2991
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002992 pipe_in.u.dl.comp_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002993 ipa_ctxt->ipa_resource.tx_comp_ring_base_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08002994 pipe_in.u.dl.comp_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08002995 ipa_ctxt->ipa_resource.tx_comp_ring_size *
2996 sizeof(qdf_dma_addr_t);
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002997 pipe_in.u.dl.ce_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08002998 ipa_ctxt->ipa_resource.ce_sr_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08002999 pipe_in.u.dl.ce_door_bell_pa = ipa_ctxt->ipa_resource.ce_reg_paddr;
3000 pipe_in.u.dl.ce_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08003001 ipa_ctxt->ipa_resource.ce_sr_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003002 pipe_in.u.dl.num_tx_buffers =
Yun Parkbaa62862017-01-18 13:43:34 -08003003 ipa_ctxt->ipa_resource.tx_num_alloc_buffer;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003004
Yun Parkbaa62862017-01-18 13:43:34 -08003005 qdf_mem_copy(&ipa_ctxt->cons_pipe_in, &pipe_in,
3006 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003007 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->tx_comp_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08003008 IPA_CLIENT_WLAN1_CONS);
3009
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003010 if (true == ipa_ctxt->uc_loaded) {
3011 /* Connect WDI IPA PIPE */
Yun Parkbaa62862017-01-18 13:43:34 -08003012 ret = ipa_connect_wdi_pipe(&ipa_ctxt->cons_pipe_in, &pipe_out);
3013 if (ret) {
3014 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3015 "ipa_connect_wdi_pipe falied for Tx: ret=%d",
3016 ret);
3017 stat = QDF_STATUS_E_FAILURE;
3018 goto fail_return;
3019 }
Yun Park637d6482016-10-05 10:51:33 -07003020
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003021 /* Micro Controller Doorbell register */
Srinivas Girigowda97852372017-03-06 16:52:59 -08003022 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003023 "CONS DB pipe out 0x%x TX PIPE Handle 0x%x",
3024 (unsigned int)pipe_out.uc_door_bell_pa,
3025 ipa_ctxt->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003026 ipa_ctxt->tx_comp_doorbell_paddr = pipe_out.uc_door_bell_pa;
Yun Parkbaa62862017-01-18 13:43:34 -08003027
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003028 /* WLAN TX PIPE Handle */
3029 ipa_ctxt->tx_pipe_handle = pipe_out.clnt_hdl;
Srinivas Girigowda97852372017-03-06 16:52:59 -08003030 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003031 "TX: %s 0x%x, %s %d, %s 0x%x, %s 0x%x, %s %d, %s %d, %s 0x%x",
3032 "comp_ring_base_pa",
3033 (unsigned int)pipe_in.u.dl.comp_ring_base_pa,
3034 "comp_ring_size",
3035 pipe_in.u.dl.comp_ring_size,
3036 "ce_ring_base_pa",
3037 (unsigned int)pipe_in.u.dl.ce_ring_base_pa,
3038 "ce_door_bell_pa",
3039 (unsigned int)pipe_in.u.dl.ce_door_bell_pa,
3040 "ce_ring_size",
3041 pipe_in.u.dl.ce_ring_size,
3042 "num_tx_buffers",
3043 pipe_in.u.dl.num_tx_buffers,
3044 "tx_comp_doorbell_paddr",
3045 (unsigned int)ipa_ctxt->tx_comp_doorbell_paddr);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003046 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003047
3048 /* RX PIPE */
3049 pipe_in.sys.ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
3050 pipe_in.sys.ipa_ep_cfg.hdr.hdr_len = HDD_IPA_UC_WLAN_RX_HDR_LEN;
3051 pipe_in.sys.ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 0;
3052 pipe_in.sys.ipa_ep_cfg.hdr.hdr_metadata_reg_valid = 1;
3053 pipe_in.sys.ipa_ep_cfg.mode.mode = IPA_BASIC;
3054 pipe_in.sys.client = IPA_CLIENT_WLAN1_PROD;
3055 pipe_in.sys.desc_fifo_sz = hdd_ctx->config->IpaDescSize +
3056 sizeof(struct sps_iovec);
3057 pipe_in.sys.notify = hdd_ipa_w2i_cb;
3058 if (!hdd_ipa_is_rm_enabled(hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303059 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Parkbaa62862017-01-18 13:43:34 -08003060 "%s: IPA RM DISABLED, IPA AWAKE", __func__);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003061 pipe_in.sys.keep_ipa_awake = true;
3062 }
3063
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003064 pipe_in.u.ul.rdy_ring_base_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08003065 ipa_ctxt->ipa_resource.rx_rdy_ring_base_paddr;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003066 pipe_in.u.ul.rdy_ring_size =
Yun Parkbaa62862017-01-18 13:43:34 -08003067 ipa_ctxt->ipa_resource.rx_rdy_ring_size;
Dhanashri Atreb08959a2016-03-01 17:28:03 -08003068 pipe_in.u.ul.rdy_ring_rp_pa =
Yun Parkbaa62862017-01-18 13:43:34 -08003069 ipa_ctxt->ipa_resource.rx_proc_done_idx_paddr;
Leo Chang3bc8fed2015-11-13 10:59:47 -08003070 HDD_IPA_WDI2_SET(pipe_in, ipa_ctxt);
Yun Parkbaa62862017-01-18 13:43:34 -08003071
Yun Park637d6482016-10-05 10:51:33 -07003072 hdd_ipa_init_metering(ipa_ctxt, &pipe_in);
3073
Yun Parkbaa62862017-01-18 13:43:34 -08003074 qdf_mem_copy(&ipa_ctxt->prod_pipe_in, &pipe_in,
3075 sizeof(struct ipa_wdi_in_params));
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003076 hdd_ipa_uc_get_db_paddr(&ipa_ctxt->rx_ready_doorbell_paddr,
Yun Parkbaa62862017-01-18 13:43:34 -08003077 IPA_CLIENT_WLAN1_PROD);
3078
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003079 if (true == ipa_ctxt->uc_loaded) {
Yun Parkbaa62862017-01-18 13:43:34 -08003080 ret = ipa_connect_wdi_pipe(&ipa_ctxt->prod_pipe_in, &pipe_out);
3081 if (ret) {
3082 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3083 "ipa_connect_wdi_pipe falied for Rx: ret=%d",
3084 ret);
3085 stat = QDF_STATUS_E_FAILURE;
3086 goto fail_return;
3087
3088 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003089 ipa_ctxt->rx_ready_doorbell_paddr = pipe_out.uc_door_bell_pa;
3090 ipa_ctxt->rx_pipe_handle = pipe_out.clnt_hdl;
Srinivas Girigowda97852372017-03-06 16:52:59 -08003091 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Parkbaa62862017-01-18 13:43:34 -08003092 "PROD DB pipe out 0x%x TX PIPE Handle 0x%x",
3093 (unsigned int)pipe_out.uc_door_bell_pa,
3094 ipa_ctxt->tx_pipe_handle);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003095 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Yun Park637d6482016-10-05 10:51:33 -07003096 "RX: %s 0x%x, %s %d, %s 0x%x, %s 0x%x",
3097 "rdy_ring_base_pa",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003098 (unsigned int)pipe_in.u.ul.rdy_ring_base_pa,
Yun Park637d6482016-10-05 10:51:33 -07003099 "rdy_ring_size",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003100 pipe_in.u.ul.rdy_ring_size,
Yun Park637d6482016-10-05 10:51:33 -07003101 "rdy_ring_rp_pa",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003102 (unsigned int)pipe_in.u.ul.rdy_ring_rp_pa,
Yun Park637d6482016-10-05 10:51:33 -07003103 "rx_ready_doorbell_paddr",
Manikandan Mohan153a4c32017-02-16 15:04:30 -08003104 (unsigned int)ipa_ctxt->rx_ready_doorbell_paddr);
3105 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003106
Yun Parkbaa62862017-01-18 13:43:34 -08003107 cdp_ipa_set_doorbell_paddr(soc, (void *)pdev,
3108 ipa_ctxt->tx_comp_doorbell_paddr,
3109 ipa_ctxt->rx_ready_doorbell_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003110
Yun Parkbaa62862017-01-18 13:43:34 -08003111 cdp_ipa_register_op_cb(soc, (void *)pdev,
3112 hdd_ipa_uc_op_event_handler, (void *)hdd_ctx);
3113
3114 HDD_IPA_LOG(QDF_TRACE_LEVEL_INFO_HIGH,
3115 "ipa_uc_op_cb=0x%p, tx_comp_idx_paddr=0x%x, rx_rdy_idx_paddr=0x%x",
3116 pdev->ipa_uc_op_cb,
3117 (unsigned int)pdev->htt_pdev->ipa_uc_tx_rsc.tx_comp_idx_paddr,
3118 (unsigned int)pdev->htt_pdev->ipa_uc_rx_rsc.rx_rdy_idx_paddr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003119
Yun Parkbaa62862017-01-18 13:43:34 -08003120fail_return:
3121 EXIT();
3122 return stat;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003123}
3124
Leo Change3e49442015-10-26 20:07:13 -07003125/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003126 * __hdd_ipa_uc_force_pipe_shutdown() - Force shutdown IPA pipe
Leo Change3e49442015-10-26 20:07:13 -07003127 * @hdd_ctx: hdd main context
3128 *
3129 * Force shutdown IPA pipe
3130 * Independent of FW pipe status, IPA pipe shutdonw progress
3131 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3132 * independent from FW pipe status
3133 *
3134 * Return: NONE
3135 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003136static void __hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
Leo Change3e49442015-10-26 20:07:13 -07003137{
3138 struct hdd_ipa_priv *hdd_ipa;
3139
3140 if (!hdd_ipa_is_enabled(hdd_ctx) || !hdd_ctx->hdd_ipa)
3141 return;
3142
3143 hdd_ipa = (struct hdd_ipa_priv *)hdd_ctx->hdd_ipa;
3144 if (false == hdd_ipa->ipa_pipes_down) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303145 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Leo Change3e49442015-10-26 20:07:13 -07003146 "IPA pipes are not down yet, force shutdown");
3147 hdd_ipa_uc_disable_pipes(hdd_ipa);
3148 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08003149 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Leo Change3e49442015-10-26 20:07:13 -07003150 "IPA pipes are down, do nothing");
3151 }
Leo Change3e49442015-10-26 20:07:13 -07003152}
3153
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003154/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003155 * hdd_ipa_uc_force_pipe_shutdown() - SSR wrapper for
3156 * __hdd_ipa_uc_force_pipe_shutdown
3157 * @hdd_ctx: hdd main context
3158 *
3159 * Force shutdown IPA pipe
3160 * Independent of FW pipe status, IPA pipe shutdonw progress
3161 * in case, any STA does not leave properly, IPA HW pipe should cleaned up
3162 * independent from FW pipe status
3163 *
3164 * Return: NONE
3165 */
3166void hdd_ipa_uc_force_pipe_shutdown(hdd_context_t *hdd_ctx)
3167{
3168 cds_ssr_protect(__func__);
3169 __hdd_ipa_uc_force_pipe_shutdown(hdd_ctx);
3170 cds_ssr_unprotect(__func__);
3171}
3172
3173/**
Govind Singh9c58eba2016-09-02 16:23:06 +05303174 * hdd_ipa_msg_free_fn() - Free an IPA message
3175 * @buff: pointer to the IPA message
3176 * @len: length of the IPA message
3177 * @type: type of IPA message
3178 *
3179 * Return: None
3180 */
3181static void hdd_ipa_msg_free_fn(void *buff, uint32_t len, uint32_t type)
3182{
Srinivas Girigowda97852372017-03-06 16:52:59 -08003183 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "msg type:%d, len:%d", type, len);
Govind Singh9c58eba2016-09-02 16:23:06 +05303184 ghdd_ipa->stats.num_free_msg++;
3185 qdf_mem_free(buff);
3186}
3187
Govind Singh9c58eba2016-09-02 16:23:06 +05303188/**
jge62037862016-12-09 10:44:33 +08003189 * hdd_ipa_uc_send_evt() - send event to ipa
3190 * @hdd_ctx: pointer to hdd context
3191 * @type: event type
3192 * @mac_addr: pointer to mac address
3193 *
3194 * Send event to IPA driver
Govind Singh9c58eba2016-09-02 16:23:06 +05303195 *
3196 * Return: 0 - Success
3197 */
jge62037862016-12-09 10:44:33 +08003198static int hdd_ipa_uc_send_evt(hdd_adapter_t *adapter,
3199 enum ipa_wlan_event type, uint8_t *mac_addr)
Govind Singh9c58eba2016-09-02 16:23:06 +05303200{
jge62037862016-12-09 10:44:33 +08003201 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Govind Singh9c58eba2016-09-02 16:23:06 +05303202 struct ipa_msg_meta meta;
3203 struct ipa_wlan_msg *msg;
3204 int ret = 0;
jge62037862016-12-09 10:44:33 +08003205
3206 meta.msg_len = sizeof(struct ipa_wlan_msg);
3207 msg = qdf_mem_malloc(meta.msg_len);
3208 if (msg == NULL) {
3209 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3210 "msg allocation failed");
3211 return -ENOMEM;
3212 }
3213
3214 meta.msg_type = type;
3215 strlcpy(msg->name, adapter->dev->name,
3216 IPA_RESOURCE_NAME_MAX);
3217 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
Srinivas Girigowda97852372017-03-06 16:52:59 -08003218 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
jge62037862016-12-09 10:44:33 +08003219 msg->name, meta.msg_type);
3220 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
3221 if (ret) {
3222 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
3223 "%s: Evt: %d fail:%d",
3224 msg->name, meta.msg_type, ret);
3225 qdf_mem_free(msg);
3226 return ret;
3227 }
3228
3229 hdd_ipa->stats.num_send_msg++;
3230
3231 return ret;
3232}
3233
3234/**
3235 * hdd_ipa_uc_disconnect_client() - send client disconnect event
3236 * @hdd_ctx: pointer to hdd adapter
3237 *
3238 * Send disconnect client event to IPA driver during SSR
3239 *
3240 * Return: 0 - Success
3241 */
3242static int hdd_ipa_uc_disconnect_client(hdd_adapter_t *adapter)
3243{
3244 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3245 int ret = 0;
Govind Singh9c58eba2016-09-02 16:23:06 +05303246 int i;
3247
3248 for (i = 0; i < WLAN_MAX_STA_COUNT; i++) {
3249 if (qdf_is_macaddr_broadcast(&adapter->aStaInfo[i].macAddrSTA))
3250 continue;
3251 if ((adapter->aStaInfo[i].isUsed) &&
jge62037862016-12-09 10:44:33 +08003252 (!adapter->aStaInfo[i].isDeauthInProgress) &&
3253 hdd_ipa->sap_num_connected_sta) {
3254 hdd_ipa_uc_send_evt(adapter, WLAN_CLIENT_DISCONNECT,
3255 adapter->aStaInfo[i].macAddrSTA.bytes);
3256 hdd_ipa->sap_num_connected_sta--;
Govind Singh9c58eba2016-09-02 16:23:06 +05303257 }
3258 }
3259
3260 return ret;
3261}
3262
3263/**
jge62037862016-12-09 10:44:33 +08003264 * hdd_ipa_uc_disconnect_ap() - send ap disconnect event
3265 * @hdd_ctx: pointer to hdd adapter
3266 *
3267 * Send disconnect ap event to IPA driver during SSR
Govind Singh9c58eba2016-09-02 16:23:06 +05303268 *
3269 * Return: 0 - Success
3270 */
jge62037862016-12-09 10:44:33 +08003271
3272static int hdd_ipa_uc_disconnect_ap(hdd_adapter_t *adapter)
3273{
3274 int ret = 0;
3275
3276 if (adapter->ipa_context)
3277 hdd_ipa_uc_send_evt(adapter, WLAN_AP_DISCONNECT,
3278 adapter->dev->dev_addr);
3279
3280 return ret;
3281}
3282
jge62037862016-12-09 10:44:33 +08003283/**
3284 * hdd_ipa_uc_disconnect_sta() - send sta disconnect event
3285 * @hdd_ctx: pointer to hdd adapter
3286 *
3287 * Send disconnect sta event to IPA driver during SSR
3288 *
3289 * Return: 0 - Success
3290 */
3291static int hdd_ipa_uc_disconnect_sta(hdd_adapter_t *adapter)
3292{
3293 hdd_station_ctx_t *pHddStaCtx;
3294 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3295 int ret = 0;
3296
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003297 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
jge62037862016-12-09 10:44:33 +08003298 hdd_ipa->sta_connected) {
3299 pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
3300 hdd_ipa_uc_send_evt(adapter, WLAN_STA_DISCONNECT,
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08003301 pHddStaCtx->conn_info.bssId.bytes);
jge62037862016-12-09 10:44:33 +08003302 }
3303
3304 return ret;
3305}
jge62037862016-12-09 10:44:33 +08003306
3307/**
3308 * hdd_ipa_uc_disconnect() - send disconnect ipa event
3309 * @hdd_ctx: pointer to hdd context
3310 *
3311 * Send disconnect event to IPA driver during SSR
3312 *
3313 * Return: 0 - Success
3314 */
3315static int hdd_ipa_uc_disconnect(hdd_context_t *hdd_ctx)
Govind Singh9c58eba2016-09-02 16:23:06 +05303316{
3317 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
3318 QDF_STATUS status;
3319 hdd_adapter_t *adapter;
3320 int ret = 0;
3321
Govind Singh9c58eba2016-09-02 16:23:06 +05303322 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
3323 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
3324 adapter = adapter_node->pAdapter;
jge62037862016-12-09 10:44:33 +08003325 if (adapter->device_mode == QDF_SAP_MODE) {
3326 hdd_ipa_uc_disconnect_client(adapter);
3327 hdd_ipa_uc_disconnect_ap(adapter);
3328 } else if (adapter->device_mode == QDF_STA_MODE) {
3329 hdd_ipa_uc_disconnect_sta(adapter);
3330 }
3331
Govind Singh9c58eba2016-09-02 16:23:06 +05303332 status = hdd_get_next_adapter(
3333 hdd_ctx, adapter_node, &next);
3334 adapter_node = next;
3335 }
3336
3337 return ret;
3338}
3339
3340/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003341 * __hdd_ipa_uc_ssr_deinit() - handle ipa deinit for SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003342 *
3343 * Deinit basic IPA UC host side to be in sync reloaded FW during
3344 * SSR
3345 *
3346 * Return: 0 - Success
3347 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003348static int __hdd_ipa_uc_ssr_deinit(void)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003349{
3350 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3351 int idx;
3352 struct hdd_ipa_iface_context *iface_context;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303353 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003354
Arun Khandavallicc544b32017-01-30 19:52:16 +05303355 if (!hdd_ipa)
3356 return 0;
3357
3358 hdd_ctx = hdd_ipa->hdd_ctx;
3359 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003360 return 0;
3361
jge62037862016-12-09 10:44:33 +08003362 /* send disconnect to ipa driver */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303363 hdd_ipa_uc_disconnect(hdd_ctx);
jge62037862016-12-09 10:44:33 +08003364
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003365 /* Clean up HDD IPA interfaces */
3366 for (idx = 0; (hdd_ipa->num_iface > 0) &&
3367 (idx < HDD_IPA_MAX_IFACE); idx++) {
3368 iface_context = &hdd_ipa->iface_context[idx];
Manikandan Mohaneab58242017-02-17 14:21:53 -08003369 if (iface_context->adapter && iface_context->adapter->magic ==
3370 WLAN_HDD_ADAPTER_MAGIC)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003371 hdd_ipa_cleanup_iface(iface_context);
3372 }
Manikandan Mohaneab58242017-02-17 14:21:53 -08003373 hdd_ipa->num_iface = 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003374 /* After SSR, wlan driver reloads FW again. But we need to protect
3375 * IPA submodule during SSR transient state. So deinit basic IPA
3376 * UC host side to be in sync with reloaded FW during SSR
3377 */
Yun Parkf7dc8cd2015-11-17 15:25:12 -08003378 if (!hdd_ipa->ipa_pipes_down)
3379 hdd_ipa_uc_disable_pipes(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003380
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303381 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003382 for (idx = 0; idx < WLAN_MAX_STA_COUNT; idx++) {
3383 hdd_ipa->assoc_stas_map[idx].is_reserved = false;
3384 hdd_ipa->assoc_stas_map[idx].sta_id = 0xFF;
3385 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303386 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003387
Srinivas Girigowda97852372017-03-06 16:52:59 -08003388 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Arun Khandavallicc544b32017-01-30 19:52:16 +05303389 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
3390 __func__, hdd_ipa->tx_pipe_handle);
3391 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
3392
Srinivas Girigowda97852372017-03-06 16:52:59 -08003393 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Arun Khandavallicc544b32017-01-30 19:52:16 +05303394 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
3395 __func__, hdd_ipa->rx_pipe_handle);
3396 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
3397
Guolei Bianca144d82016-11-10 11:07:42 +08003398 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
3399 hdd_ipa_uc_sta_reset_sta_connected(hdd_ipa);
3400
Manikandan Mohan2e803a02017-02-14 14:57:53 -08003401 for (idx = 0; idx < HDD_IPA_UC_OPCODE_MAX; idx++) {
3402 cancel_work_sync(&hdd_ipa->uc_op_work[idx].work);
3403 qdf_mem_free(hdd_ipa->uc_op_work[idx].msg);
3404 hdd_ipa->uc_op_work[idx].msg = NULL;
3405 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003406 return 0;
3407}
3408
3409/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003410 * hdd_ipa_uc_ssr_deinit() - SSR wrapper for __hdd_ipa_uc_ssr_deinit
3411 *
3412 * Deinit basic IPA UC host side to be in sync reloaded FW during
3413 * SSR
3414 *
3415 * Return: 0 - Success
3416 */
3417int hdd_ipa_uc_ssr_deinit(void)
3418{
3419 int ret;
3420
3421 cds_ssr_protect(__func__);
3422 ret = __hdd_ipa_uc_ssr_deinit();
3423 cds_ssr_unprotect(__func__);
3424
3425 return ret;
3426}
3427
3428/**
3429 * __hdd_ipa_uc_ssr_reinit() - handle ipa reinit after SSR
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003430 *
3431 * Init basic IPA UC host side to be in sync with reloaded FW after
3432 * SSR to resume IPA UC operations
3433 *
3434 * Return: 0 - Success
3435 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303436static int __hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003437{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003438
Arun Khandavallicc544b32017-01-30 19:52:16 +05303439 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
3440 int i;
3441 struct hdd_ipa_iface_context *iface_context = NULL;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303442
3443 if (!hdd_ipa || !hdd_ipa_uc_is_enabled(hdd_ctx))
3444 return 0;
3445
Arun Khandavallicc544b32017-01-30 19:52:16 +05303446 /* Create the interface context */
3447 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
3448 iface_context = &hdd_ipa->iface_context[i];
3449 iface_context->hdd_ipa = hdd_ipa;
3450 iface_context->cons_client =
3451 hdd_ipa_adapter_2_client[i].cons_client;
3452 iface_context->prod_client =
3453 hdd_ipa_adapter_2_client[i].prod_client;
3454 iface_context->iface_id = i;
3455 iface_context->adapter = NULL;
3456 }
3457 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
3458 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
3459 hdd_ipa->vdev_offload_enabled[i] = false;
3460 }
3461
3462 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3463 hdd_ipa->resource_loading = false;
3464 hdd_ipa->resource_unloading = false;
3465 hdd_ipa->sta_connected = 0;
3466 hdd_ipa->ipa_pipes_down = true;
3467 hdd_ipa->uc_loaded = true;
Arun Khandavallicc544b32017-01-30 19:52:16 +05303468 }
3469
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003470 return 0;
3471}
Leo Chang3bc8fed2015-11-13 10:59:47 -08003472
3473/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003474 * hdd_ipa_uc_ssr_reinit() - SSR wrapper for __hdd_ipa_uc_ssr_reinit
3475 *
3476 * Init basic IPA UC host side to be in sync with reloaded FW after
3477 * SSR to resume IPA UC operations
3478 *
3479 * Return: 0 - Success
3480 */
Arun Khandavallicc544b32017-01-30 19:52:16 +05303481int hdd_ipa_uc_ssr_reinit(hdd_context_t *hdd_ctx)
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003482{
3483 int ret;
3484
3485 cds_ssr_protect(__func__);
Arun Khandavallicc544b32017-01-30 19:52:16 +05303486 ret = __hdd_ipa_uc_ssr_reinit(hdd_ctx);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003487 cds_ssr_unprotect(__func__);
3488
3489 return ret;
3490}
3491
3492/**
3493 * __hdd_ipa_tx_packet_ipa() - send packet to IPA
Leo Chang3bc8fed2015-11-13 10:59:47 -08003494 * @hdd_ctx: Global HDD context
3495 * @skb: skb sent to IPA
3496 * @session_id: send packet instance session id
3497 *
3498 * Send TX packet which generated by system to IPA.
3499 * This routine only will be used for function verification
3500 *
3501 * Return: NULL packet sent to IPA properly
3502 * NULL invalid packet drop
3503 * skb packet not sent to IPA. legacy data path should handle
3504 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003505static struct sk_buff *__hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
Leo Chang3bc8fed2015-11-13 10:59:47 -08003506 struct sk_buff *skb, uint8_t session_id)
Leo Change3e49442015-10-26 20:07:13 -07003507{
Leo Chang3bc8fed2015-11-13 10:59:47 -08003508 struct ipa_header *ipa_header;
3509 struct frag_header *frag_header;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003510 struct hdd_ipa_priv *hdd_ipa;
3511
3512 if (wlan_hdd_validate_context(hdd_ctx))
3513 return skb;
3514
3515 hdd_ipa = hdd_ctx->hdd_ipa;
Leo Chang3bc8fed2015-11-13 10:59:47 -08003516
3517 if (!hdd_ipa_uc_is_enabled(hdd_ctx))
3518 return skb;
3519
Leo Chang07b28f62016-05-11 12:29:22 -07003520 if (!hdd_ipa)
3521 return skb;
3522
3523 if (HDD_IPA_UC_NUM_WDI_PIPE != hdd_ipa->activated_fw_pipe)
3524 return skb;
3525
Leo Changcc923e22016-06-16 15:29:03 -07003526 if (skb_headroom(skb) <
3527 (sizeof(struct ipa_header) + sizeof(struct frag_header)))
Leo Chang07b28f62016-05-11 12:29:22 -07003528 return skb;
3529
Leo Chang3bc8fed2015-11-13 10:59:47 -08003530 ipa_header = (struct ipa_header *) skb_push(skb,
3531 sizeof(struct ipa_header));
3532 if (!ipa_header) {
3533 /* No headroom, legacy */
3534 return skb;
3535 }
3536 memset(ipa_header, 0, sizeof(*ipa_header));
3537 ipa_header->vdev_id = 0;
3538
3539 frag_header = (struct frag_header *) skb_push(skb,
3540 sizeof(struct frag_header));
3541 if (!frag_header) {
3542 /* No headroom, drop */
3543 kfree_skb(skb);
3544 return NULL;
3545 }
3546 memset(frag_header, 0, sizeof(*frag_header));
3547 frag_header->length = skb->len - sizeof(struct frag_header)
3548 - sizeof(struct ipa_header);
3549
3550 ipa_tx_dp(IPA_CLIENT_WLAN1_CONS, skb, NULL);
3551 return NULL;
Leo Change3e49442015-10-26 20:07:13 -07003552}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003553
3554/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003555 * hdd_ipa_tx_packet_ipa() - SSR wrapper for __hdd_ipa_tx_packet_ipa
3556 * @hdd_ctx: Global HDD context
3557 * @skb: skb sent to IPA
3558 * @session_id: send packet instance session id
3559 *
3560 * Send TX packet which generated by system to IPA.
3561 * This routine only will be used for function verification
3562 *
3563 * Return: NULL packet sent to IPA properly
3564 * NULL invalid packet drop
3565 * skb packet not sent to IPA. legacy data path should handle
3566 */
3567struct sk_buff *hdd_ipa_tx_packet_ipa(hdd_context_t *hdd_ctx,
3568 struct sk_buff *skb, uint8_t session_id)
3569{
3570 struct sk_buff *ret;
3571
3572 cds_ssr_protect(__func__);
3573 ret = __hdd_ipa_tx_packet_ipa(hdd_ctx, skb, session_id);
3574 cds_ssr_unprotect(__func__);
3575
3576 return ret;
3577}
3578
3579/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003580 * hdd_ipa_wake_lock_timer_func() - Wake lock work handler
3581 * @work: scheduled work
3582 *
3583 * When IPA resources are released in hdd_ipa_rm_try_release() we do
3584 * not want to immediately release the wake lock since the system
3585 * would then potentially try to suspend when there is a healthy data
3586 * rate. Deferred work is scheduled and this function handles the
3587 * work. When this function is called, if the IPA resource is still
3588 * released then we release the wake lock.
3589 *
3590 * Return: None
3591 */
3592static void hdd_ipa_wake_lock_timer_func(struct work_struct *work)
3593{
3594 struct hdd_ipa_priv *hdd_ipa = container_of(to_delayed_work(work),
3595 struct hdd_ipa_priv,
3596 wake_lock_work);
3597
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303598 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003599
3600 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED)
3601 goto end;
3602
3603 hdd_ipa->wake_lock_released = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303604 qdf_wake_lock_release(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003605 WIFI_POWER_EVENT_WAKELOCK_IPA);
3606
3607end:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303608 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003609}
3610
3611/**
3612 * hdd_ipa_rm_request() - Request resource from IPA
3613 * @hdd_ipa: Global HDD IPA context
3614 *
3615 * Return: 0 on success, negative errno on error
3616 */
3617static int hdd_ipa_rm_request(struct hdd_ipa_priv *hdd_ipa)
3618{
3619 int ret = 0;
3620
3621 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3622 return 0;
3623
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303624 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003625
3626 switch (hdd_ipa->rm_state) {
3627 case HDD_IPA_RM_GRANTED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303628 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003629 return 0;
3630 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303631 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003632 return -EINPROGRESS;
3633 case HDD_IPA_RM_RELEASED:
3634 hdd_ipa->rm_state = HDD_IPA_RM_GRANT_PENDING;
3635 break;
3636 }
3637
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303638 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003639
3640 ret = ipa_rm_inactivity_timer_request_resource(
3641 IPA_RM_RESOURCE_WLAN_PROD);
3642
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303643 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003644 if (ret == 0) {
3645 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3646 hdd_ipa->stats.num_rm_grant_imm++;
3647 }
3648
3649 cancel_delayed_work(&hdd_ipa->wake_lock_work);
3650 if (hdd_ipa->wake_lock_released) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303651 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003652 WIFI_POWER_EVENT_WAKELOCK_IPA);
3653 hdd_ipa->wake_lock_released = false;
3654 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303655 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003656
3657 return ret;
3658}
3659
3660/**
3661 * hdd_ipa_rm_try_release() - Attempt to release IPA resource
3662 * @hdd_ipa: Global HDD IPA context
3663 *
3664 * Return: 0 if resources released, negative errno otherwise
3665 */
3666static int hdd_ipa_rm_try_release(struct hdd_ipa_priv *hdd_ipa)
3667{
3668 int ret = 0;
3669
3670 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3671 return 0;
3672
3673 if (atomic_read(&hdd_ipa->tx_ref_cnt))
3674 return -EAGAIN;
3675
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303676 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003677
Nirav Shahcbc6d722016-03-01 16:24:53 +05303678 if (!qdf_nbuf_is_queue_empty(&hdd_ipa->pm_queue_head)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303679 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003680 return -EAGAIN;
3681 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303682 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003683
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303684 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003685 switch (hdd_ipa->rm_state) {
3686 case HDD_IPA_RM_GRANTED:
3687 break;
3688 case HDD_IPA_RM_GRANT_PENDING:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303689 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003690 return -EINPROGRESS;
3691 case HDD_IPA_RM_RELEASED:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303692 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003693 return 0;
3694 }
3695
3696 /* IPA driver returns immediately so set the state here to avoid any
3697 * race condition.
3698 */
3699 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
3700 hdd_ipa->stats.num_rm_release++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303701 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003702
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07003703 ret = ipa_rm_inactivity_timer_release_resource(
3704 IPA_RM_RESOURCE_WLAN_PROD);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003705
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303706 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003707 if (unlikely(ret != 0)) {
3708 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
3709 WARN_ON(1);
3710 }
3711
3712 /*
3713 * If wake_lock is released immediately, kernel would try to suspend
3714 * immediately as well, Just avoid ping-pong between suspend-resume
3715 * while there is healthy amount of data transfer going on by
3716 * releasing the wake_lock after some delay.
3717 */
3718 schedule_delayed_work(&hdd_ipa->wake_lock_work,
3719 msecs_to_jiffies
3720 (HDD_IPA_RX_INACTIVITY_MSEC_DELAY));
3721
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303722 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003723
3724 return ret;
3725}
3726
3727/**
3728 * hdd_ipa_rm_notify() - IPA resource manager notifier callback
3729 * @user_data: user data registered with IPA
3730 * @event: the IPA resource manager event that occurred
3731 * @data: the data associated with the event
3732 *
3733 * Return: None
3734 */
3735static void hdd_ipa_rm_notify(void *user_data, enum ipa_rm_event event,
3736 unsigned long data)
3737{
3738 struct hdd_ipa_priv *hdd_ipa = user_data;
3739
3740 if (unlikely(!hdd_ipa))
3741 return;
3742
3743 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3744 return;
3745
Srinivas Girigowda97852372017-03-06 16:52:59 -08003746 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003747
3748 switch (event) {
3749 case IPA_RM_RESOURCE_GRANTED:
3750 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
3751 /* RM Notification comes with ISR context
3752 * it should be serialized into work queue to avoid
3753 * ISR sleep problem
3754 */
3755 hdd_ipa->uc_rm_work.event = event;
3756 schedule_work(&hdd_ipa->uc_rm_work.work);
3757 break;
3758 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303759 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003760 hdd_ipa->rm_state = HDD_IPA_RM_GRANTED;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303761 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003762 hdd_ipa->stats.num_rm_grant++;
3763 break;
3764
3765 case IPA_RM_RESOURCE_RELEASED:
Srinivas Girigowda97852372017-03-06 16:52:59 -08003766 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "RM Release");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003767 hdd_ipa->resource_unloading = false;
3768 break;
3769
3770 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303771 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Unknown RM Evt: %d", event);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003772 break;
3773 }
3774}
3775
3776/**
3777 * hdd_ipa_rm_cons_release() - WLAN consumer resource release handler
3778 *
3779 * Callback function registered with IPA that is called when IPA wants
3780 * to release the WLAN consumer resource
3781 *
3782 * Return: 0 if the request is granted, negative errno otherwise
3783 */
3784static int hdd_ipa_rm_cons_release(void)
3785{
3786 return 0;
3787}
3788
3789/**
3790 * hdd_ipa_rm_cons_request() - WLAN consumer resource request handler
3791 *
3792 * Callback function registered with IPA that is called when IPA wants
3793 * to access the WLAN consumer resource
3794 *
3795 * Return: 0 if the request is granted, negative errno otherwise
3796 */
3797static int hdd_ipa_rm_cons_request(void)
3798{
Yun Park4d8b60a2015-10-22 13:59:32 -07003799 int ret = 0;
3800
3801 if (ghdd_ipa->resource_loading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303802 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003803 "%s: IPA resource loading in progress",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003804 __func__);
3805 ghdd_ipa->pending_cons_req = true;
Yun Park4d8b60a2015-10-22 13:59:32 -07003806 ret = -EINPROGRESS;
3807 } else if (ghdd_ipa->resource_unloading) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303808 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL,
Yun Park4d8b60a2015-10-22 13:59:32 -07003809 "%s: IPA resource unloading in progress",
3810 __func__);
3811 ghdd_ipa->pending_cons_req = true;
3812 ret = -EPERM;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003813 }
Yun Park4d8b60a2015-10-22 13:59:32 -07003814
3815 return ret;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003816}
3817
3818/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003819 * __hdd_ipa_set_perf_level() - Set IPA performance level
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003820 * @hdd_ctx: Global HDD context
3821 * @tx_packets: Number of packets transmitted in the last sample period
3822 * @rx_packets: Number of packets received in the last sample period
3823 *
3824 * Return: 0 on success, negative errno on error
3825 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003826static int __hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003827 uint64_t rx_packets)
3828{
3829 uint32_t next_cons_bw, next_prod_bw;
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003830 struct hdd_ipa_priv *hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003831 struct ipa_rm_perf_profile profile;
3832 int ret;
3833
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003834 if (wlan_hdd_validate_context(hdd_ctx))
3835 return 0;
3836
3837 hdd_ipa = hdd_ctx->hdd_ipa;
3838
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003839 if ((!hdd_ipa_is_enabled(hdd_ctx)) ||
3840 (!hdd_ipa_is_clk_scaling_enabled(hdd_ctx)))
3841 return 0;
3842
3843 memset(&profile, 0, sizeof(profile));
3844
3845 if (tx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3846 next_cons_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3847 else if (tx_packets >
3848 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3849 next_cons_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3850 else
3851 next_cons_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3852
3853 if (rx_packets > (hdd_ctx->config->busBandwidthHighThreshold / 2))
3854 next_prod_bw = hdd_ctx->config->IpaHighBandwidthMbps;
3855 else if (rx_packets >
3856 (hdd_ctx->config->busBandwidthMediumThreshold / 2))
3857 next_prod_bw = hdd_ctx->config->IpaMediumBandwidthMbps;
3858 else
3859 next_prod_bw = hdd_ctx->config->IpaLowBandwidthMbps;
3860
Yun Parkec845302016-12-15 09:22:57 -08003861 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003862 "CONS perf curr: %d, next: %d",
3863 hdd_ipa->curr_cons_bw, next_cons_bw);
Yun Parkec845302016-12-15 09:22:57 -08003864 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003865 "PROD perf curr: %d, next: %d",
3866 hdd_ipa->curr_prod_bw, next_prod_bw);
3867
3868 if (hdd_ipa->curr_cons_bw != next_cons_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003869 hdd_debug("Requesting CONS perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003870 hdd_ipa->curr_cons_bw, next_cons_bw);
3871 profile.max_supported_bandwidth_mbps = next_cons_bw;
3872 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_CONS,
3873 &profile);
3874 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003875 hdd_err("RM CONS set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003876
3877 return ret;
3878 }
3879 hdd_ipa->curr_cons_bw = next_cons_bw;
3880 hdd_ipa->stats.num_cons_perf_req++;
3881 }
3882
3883 if (hdd_ipa->curr_prod_bw != next_prod_bw) {
Yun Parkb187d542016-11-14 18:10:04 -08003884 hdd_debug("Requesting PROD perf curr: %d, next: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003885 hdd_ipa->curr_prod_bw, next_prod_bw);
3886 profile.max_supported_bandwidth_mbps = next_prod_bw;
3887 ret = ipa_rm_set_perf_profile(IPA_RM_RESOURCE_WLAN_PROD,
3888 &profile);
3889 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08003890 hdd_err("RM PROD set perf profile failed: %d", ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003891 return ret;
3892 }
3893 hdd_ipa->curr_prod_bw = next_prod_bw;
3894 hdd_ipa->stats.num_prod_perf_req++;
3895 }
3896
3897 return 0;
3898}
3899
3900/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07003901 * hdd_ipa_set_perf_level() - SSR wrapper for __hdd_ipa_set_perf_level
3902 * @hdd_ctx: Global HDD context
3903 * @tx_packets: Number of packets transmitted in the last sample period
3904 * @rx_packets: Number of packets received in the last sample period
3905 *
3906 * Return: 0 on success, negative errno on error
3907 */
3908int hdd_ipa_set_perf_level(hdd_context_t *hdd_ctx, uint64_t tx_packets,
3909 uint64_t rx_packets)
3910{
3911 int ret;
3912
3913 cds_ssr_protect(__func__);
3914 ret = __hdd_ipa_set_perf_level(hdd_ctx, tx_packets, rx_packets);
3915 cds_ssr_unprotect(__func__);
3916
3917 return ret;
3918}
3919
3920/**
Rajeev Kumar217f2172016-01-06 18:11:55 -08003921 * hdd_ipa_init_uc_rm_work - init ipa uc resource manager work
3922 * @work: struct work_struct
3923 * @work_handler: work_handler
3924 *
3925 * Return: none
3926 */
Rajeev Kumar217f2172016-01-06 18:11:55 -08003927static void hdd_ipa_init_uc_rm_work(struct work_struct *work,
3928 work_func_t work_handler)
3929{
3930 INIT_WORK(work, work_handler);
3931}
Rajeev Kumar217f2172016-01-06 18:11:55 -08003932
3933/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003934 * hdd_ipa_setup_rm() - Setup IPA resource management
3935 * @hdd_ipa: Global HDD IPA context
3936 *
3937 * Return: 0 on success, negative errno on error
3938 */
3939static int hdd_ipa_setup_rm(struct hdd_ipa_priv *hdd_ipa)
3940{
3941 struct ipa_rm_create_params create_params = { 0 };
3942 int ret;
3943
3944 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
3945 return 0;
3946
Rajeev Kumar217f2172016-01-06 18:11:55 -08003947 hdd_ipa_init_uc_rm_work(&hdd_ipa->uc_rm_work.work,
3948 hdd_ipa_uc_rm_notify_defer);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003949 memset(&create_params, 0, sizeof(create_params));
3950 create_params.name = IPA_RM_RESOURCE_WLAN_PROD;
3951 create_params.reg_params.user_data = hdd_ipa;
3952 create_params.reg_params.notify_cb = hdd_ipa_rm_notify;
3953 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3954
3955 ret = ipa_rm_create_resource(&create_params);
3956 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303957 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003958 "Create RM resource failed: %d", ret);
3959 goto setup_rm_fail;
3960 }
3961
3962 memset(&create_params, 0, sizeof(create_params));
3963 create_params.name = IPA_RM_RESOURCE_WLAN_CONS;
3964 create_params.request_resource = hdd_ipa_rm_cons_request;
3965 create_params.release_resource = hdd_ipa_rm_cons_release;
3966 create_params.floor_voltage = IPA_VOLTAGE_SVS;
3967
3968 ret = ipa_rm_create_resource(&create_params);
3969 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303970 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003971 "Create RM CONS resource failed: %d", ret);
3972 goto delete_prod;
3973 }
3974
3975 ipa_rm_add_dependency(IPA_RM_RESOURCE_WLAN_PROD,
3976 IPA_RM_RESOURCE_APPS_CONS);
3977
3978 ret = ipa_rm_inactivity_timer_init(IPA_RM_RESOURCE_WLAN_PROD,
3979 HDD_IPA_RX_INACTIVITY_MSEC_DELAY);
3980 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303981 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Timer init failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003982 ret);
3983 goto timer_init_failed;
3984 }
3985
3986 /* Set the lowest bandwidth to start with */
3987 ret = hdd_ipa_set_perf_level(hdd_ipa->hdd_ctx, 0, 0);
3988
3989 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05303990 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003991 "Set perf level failed: %d", ret);
3992 goto set_perf_failed;
3993 }
3994
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303995 qdf_wake_lock_create(&hdd_ipa->wake_lock, "wlan_ipa");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003996 INIT_DELAYED_WORK(&hdd_ipa->wake_lock_work,
3997 hdd_ipa_wake_lock_timer_func);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05303998 qdf_spinlock_create(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003999 hdd_ipa->rm_state = HDD_IPA_RM_RELEASED;
4000 hdd_ipa->wake_lock_released = true;
4001 atomic_set(&hdd_ipa->tx_ref_cnt, 0);
4002
4003 return ret;
4004
4005set_perf_failed:
4006 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4007
4008timer_init_failed:
4009 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4010
4011delete_prod:
4012 ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4013
4014setup_rm_fail:
4015 return ret;
4016}
4017
4018/**
4019 * hdd_ipa_destroy_rm_resource() - Destroy IPA resources
4020 * @hdd_ipa: Global HDD IPA context
4021 *
4022 * Destroys all resources associated with the IPA resource manager
4023 *
4024 * Return: None
4025 */
4026static void hdd_ipa_destroy_rm_resource(struct hdd_ipa_priv *hdd_ipa)
4027{
4028 int ret;
4029
4030 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4031 return;
4032
4033 cancel_delayed_work_sync(&hdd_ipa->wake_lock_work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304034 qdf_wake_lock_destroy(&hdd_ipa->wake_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004035
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004036 cancel_work_sync(&hdd_ipa->uc_rm_work.work);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304037 qdf_spinlock_destroy(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004038
4039 ipa_rm_inactivity_timer_destroy(IPA_RM_RESOURCE_WLAN_PROD);
4040
4041 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_PROD);
4042 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304043 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004044 "RM PROD resource delete failed %d", ret);
4045
4046 ret = ipa_rm_delete_resource(IPA_RM_RESOURCE_WLAN_CONS);
4047 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304048 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004049 "RM CONS resource delete failed %d", ret);
4050}
4051
4052/**
4053 * hdd_ipa_send_skb_to_network() - Send skb to kernel
4054 * @skb: network buffer
4055 * @adapter: network adapter
4056 *
4057 * Called when a network buffer is received which should not be routed
4058 * to the IPA module.
4059 *
4060 * Return: None
4061 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304062static void hdd_ipa_send_skb_to_network(qdf_nbuf_t skb,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004063 hdd_adapter_t *adapter)
4064{
4065 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
4066 unsigned int cpu_index;
4067
4068 if (!adapter || adapter->magic != WLAN_HDD_ADAPTER_MAGIC) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004069 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Invalid adapter: 0x%p",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004070 adapter);
4071 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004072 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004073 return;
4074 }
4075
Prashanth Bhatta9e143052015-12-04 11:56:47 -08004076 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004077 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004078 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004079 return;
4080 }
4081
4082 skb->destructor = hdd_ipa_uc_rt_debug_destructor;
4083 skb->dev = adapter->dev;
4084 skb->protocol = eth_type_trans(skb, skb->dev);
4085 skb->ip_summed = CHECKSUM_NONE;
4086
4087 cpu_index = wlan_hdd_get_cpu();
4088
4089 ++adapter->hdd_stats.hddTxRxStats.rxPackets[cpu_index];
4090 if (netif_rx_ni(skb) == NET_RX_SUCCESS)
4091 ++adapter->hdd_stats.hddTxRxStats.rxDelivered[cpu_index];
4092 else
4093 ++adapter->hdd_stats.hddTxRxStats.rxRefused[cpu_index];
4094
4095 HDD_IPA_INCREASE_NET_SEND_COUNT(hdd_ipa);
4096 adapter->dev->last_rx = jiffies;
4097}
4098
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004099/**
Leo Chang69c39692016-10-12 20:11:12 -07004100 * hdd_ipa_forward() - handle packet forwarding to wlan tx
4101 * @hdd_ipa: pointer to hdd ipa context
4102 * @adapter: network adapter
4103 * @skb: data pointer
4104 *
4105 * if exception packet has set forward bit, copied new packet should be
4106 * forwarded to wlan tx. if wlan subsystem is in suspend state, packet should
4107 * put into pm queue and tx procedure will be differed
4108 *
4109 * Return: None
4110 */
Jeff Johnson414f7ea2016-10-19 18:50:02 -07004111static void hdd_ipa_forward(struct hdd_ipa_priv *hdd_ipa,
4112 hdd_adapter_t *adapter, qdf_nbuf_t skb)
Leo Chang69c39692016-10-12 20:11:12 -07004113{
Leo Chang69c39692016-10-12 20:11:12 -07004114 struct hdd_ipa_pm_tx_cb *pm_tx_cb;
4115
Leo Chang69c39692016-10-12 20:11:12 -07004116 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
4117 /* WLAN subsystem is in suspend, put int queue */
4118 if (hdd_ipa->suspended) {
4119 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4120 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4121 "TX in SUSPEND PUT QUEUE");
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004122 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
4123 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Leo Chang69c39692016-10-12 20:11:12 -07004124 pm_tx_cb->exception = true;
4125 pm_tx_cb->adapter = adapter;
4126 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004127 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Leo Chang69c39692016-10-12 20:11:12 -07004128 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
4129 hdd_ipa->stats.num_tx_queued++;
4130 } else {
4131 /* Resume, put packet into WLAN TX */
4132 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004133 if (hdd_softap_hard_start_xmit(skb, adapter->dev)) {
Leo Chang69c39692016-10-12 20:11:12 -07004134 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4135 "packet tx fail");
Yun Parkb187d542016-11-14 18:10:04 -08004136 hdd_ipa->stats.num_tx_fwd_err++;
Leo Chang69c39692016-10-12 20:11:12 -07004137 } else {
Yun Parkb187d542016-11-14 18:10:04 -08004138 hdd_ipa->stats.num_tx_fwd_ok++;
Leo Chang69c39692016-10-12 20:11:12 -07004139 hdd_ipa->ipa_tx_forward++;
4140 }
4141 }
4142}
4143
4144/**
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004145 * hdd_ipa_intrabss_forward() - Forward intra bss packets.
4146 * @hdd_ipa: pointer to HDD IPA struct
4147 * @adapter: hdd adapter pointer
4148 * @desc: Firmware descriptor
4149 * @skb: Data buffer
4150 *
4151 * Return:
4152 * HDD_IPA_FORWARD_PKT_NONE
4153 * HDD_IPA_FORWARD_PKT_DISCARD
4154 * HDD_IPA_FORWARD_PKT_LOCAL_STACK
4155 *
4156 */
4157
4158static enum hdd_ipa_forward_type hdd_ipa_intrabss_forward(
4159 struct hdd_ipa_priv *hdd_ipa,
4160 hdd_adapter_t *adapter,
4161 uint8_t desc,
4162 qdf_nbuf_t skb)
4163{
4164 int ret = HDD_IPA_FORWARD_PKT_NONE;
4165
4166 if ((desc & FW_RX_DESC_FORWARD_M)) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304167 if (!ol_txrx_fwd_desc_thresh_check(
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004168 (struct ol_txrx_vdev_t *)ol_txrx_get_vdev_from_vdev_id(
4169 adapter->sessionId))) {
Poddar, Siddarth8e3ee2d2016-11-29 20:17:01 +05304170 /* Drop the packet*/
4171 hdd_ipa->stats.num_tx_fwd_err++;
4172 kfree_skb(skb);
4173 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4174 return ret;
4175 }
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004176 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
4177 "Forward packet to Tx (fw_desc=%d)", desc);
4178 hdd_ipa->ipa_tx_forward++;
4179
4180 if ((desc & FW_RX_DESC_DISCARD_M)) {
4181 hdd_ipa_forward(hdd_ipa, adapter, skb);
4182 hdd_ipa->ipa_rx_internel_drop_count++;
4183 hdd_ipa->ipa_rx_discard++;
4184 ret = HDD_IPA_FORWARD_PKT_DISCARD;
4185 } else {
4186 struct sk_buff *cloned_skb = skb_clone(skb, GFP_ATOMIC);
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004187
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004188 if (cloned_skb)
4189 hdd_ipa_forward(hdd_ipa, adapter, cloned_skb);
4190 else
4191 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4192 "%s: tx skb alloc failed",
4193 __func__);
4194 ret = HDD_IPA_FORWARD_PKT_LOCAL_STACK;
4195 }
4196 }
4197
4198 return ret;
4199}
4200
4201/**
Yun Park637d6482016-10-05 10:51:33 -07004202 * __hdd_ipa_w2i_cb() - WLAN to IPA callback handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004203 * @priv: pointer to private data registered with IPA (we register a
4204 * pointer to the global IPA context)
4205 * @evt: the IPA event which triggered the callback
4206 * @data: data associated with the event
4207 *
4208 * Return: None
4209 */
Yun Parkf8d6a122016-10-11 15:49:43 -07004210static void __hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004211 unsigned long data)
4212{
4213 struct hdd_ipa_priv *hdd_ipa = NULL;
4214 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304215 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004216 uint8_t iface_id;
4217 uint8_t session_id;
4218 struct hdd_ipa_iface_context *iface_context;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004219 uint8_t fw_desc;
Yun Parkf8d6a122016-10-11 15:49:43 -07004220 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004221
4222 hdd_ipa = (struct hdd_ipa_priv *)priv;
4223
Prakash Dhavali63f8fd62016-11-14 14:40:42 -08004224 if (!hdd_ipa || wlan_hdd_validate_context(hdd_ipa->hdd_ctx))
4225 return;
4226
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004227 switch (evt) {
4228 case IPA_RECEIVE:
Nirav Shahcbc6d722016-03-01 16:24:53 +05304229 skb = (qdf_nbuf_t) data;
Yun Parkf8d6a122016-10-11 15:49:43 -07004230
4231 /*
4232 * When SSR is going on or driver is unloading,
4233 * just drop the packets.
4234 */
4235 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
4236 if (0 != status) {
4237 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4238 "Invalid context: drop packet");
4239 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4240 kfree_skb(skb);
4241 return;
4242 }
4243
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004244 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4245 session_id = (uint8_t)skb->cb[0];
Prakash Dhavali89d406d2016-11-23 11:11:00 -08004246 iface_id = hdd_ipa->vdev_to_iface[session_id];
Srinivas Girigowda97852372017-03-06 16:52:59 -08004247 HDD_IPA_DP_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004248 "IPA_RECEIVE: session_id=%u, iface_id=%u",
4249 session_id, iface_id);
4250 } else {
4251 iface_id = HDD_IPA_GET_IFACE_ID(skb->data);
4252 }
4253
4254 if (iface_id >= HDD_IPA_MAX_IFACE) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304255 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004256 "IPA_RECEIVE: Invalid iface_id: %u",
4257 iface_id);
Srinivas Girigowda97852372017-03-06 16:52:59 -08004258 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004259 "w2i -- skb",
4260 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004261 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
Yun Parkf8d6a122016-10-11 15:49:43 -07004262 kfree_skb(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004263 return;
4264 }
4265
4266 iface_context = &hdd_ipa->iface_context[iface_id];
4267 adapter = iface_context->adapter;
Yun Park16a78262017-02-01 12:15:03 -08004268 if (!adapter) {
4269 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4270 "IPA_RECEIVE: Adapter is NULL");
4271 HDD_IPA_INCREASE_INTERNAL_DROP_COUNT(hdd_ipa);
4272 kfree_skb(skb);
4273 return;
4274 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004275
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304276 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
Yun Parkb187d542016-11-14 18:10:04 -08004277 "w2i -- skb",
4278 skb->data, HDD_IPA_DBG_DUMP_RX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004279 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
4280 hdd_ipa->stats.num_rx_excep++;
4281 skb_pull(skb, HDD_IPA_UC_WLAN_CLD_HDR_LEN);
4282 } else {
4283 skb_pull(skb, HDD_IPA_WLAN_CLD_HDR_LEN);
4284 }
4285
4286 iface_context->stats.num_rx_ipa_excep++;
4287
4288 /* Disable to forward Intra-BSS Rx packets when
4289 * ap_isolate=1 in hostapd.conf
4290 */
Yun Park046101c2016-09-02 15:32:14 -07004291 if (!adapter->sessionCtx.ap.apDisableIntraBssFwd) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004292 /*
4293 * When INTRA_BSS_FWD_OFFLOAD is enabled, FW will send
4294 * all Rx packets to IPA uC, which need to be forwarded
4295 * to other interface.
4296 * And, IPA driver will send back to WLAN host driver
4297 * through exception pipe with fw_desc field set by FW.
4298 * Here we are checking fw_desc field for FORWARD bit
4299 * set, and forward to Tx. Then copy to kernel stack
4300 * only when DISCARD bit is not set.
4301 */
4302 fw_desc = (uint8_t)skb->cb[1];
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004303 if (HDD_IPA_FORWARD_PKT_DISCARD ==
4304 hdd_ipa_intrabss_forward(hdd_ipa, adapter,
4305 fw_desc, skb))
Mahesh Kumar Kalikot Veetil221dc672015-11-06 14:27:28 -08004306 break;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004307 } else {
Srinivas Girigowda97852372017-03-06 16:52:59 -08004308 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004309 "Intra-BSS FWD is disabled-skip forward to Tx");
4310 }
4311
4312 hdd_ipa_send_skb_to_network(skb, adapter);
4313 break;
4314
4315 default:
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304316 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004317 "w2i cb wrong event: 0x%x", evt);
4318 return;
4319 }
4320}
4321
4322/**
Yun Parkf8d6a122016-10-11 15:49:43 -07004323 * hdd_ipa_w2i_cb() - SSR wrapper for __hdd_ipa_w2i_cb
4324 * @priv: pointer to private data registered with IPA (we register a
4325 * pointer to the global IPA context)
4326 * @evt: the IPA event which triggered the callback
4327 * @data: data associated with the event
4328 *
4329 * Return: None
4330 */
4331static void hdd_ipa_w2i_cb(void *priv, enum ipa_dp_evt_type evt,
4332 unsigned long data)
4333{
4334 cds_ssr_protect(__func__);
4335 __hdd_ipa_w2i_cb(priv, evt, data);
4336 cds_ssr_unprotect(__func__);
4337}
4338
4339/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004340 * hdd_ipa_nbuf_cb() - IPA TX complete callback
4341 * @skb: packet buffer which was transmitted
4342 *
4343 * Return: None
4344 */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304345void hdd_ipa_nbuf_cb(qdf_nbuf_t skb)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004346{
4347 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
Yun Park52b2b992016-09-22 15:49:51 -07004348 struct ipa_rx_data *ipa_tx_desc;
4349 struct hdd_ipa_tx_desc *tx_desc;
4350 uint16_t id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004351
Yun Park52b2b992016-09-22 15:49:51 -07004352 if (!qdf_nbuf_ipa_owned_get(skb)) {
4353 dev_kfree_skb_any(skb);
4354 return;
4355 }
4356
4357 /* Get Tx desc pointer from SKB CB */
4358 id = QDF_NBUF_CB_TX_IPA_PRIV(skb);
4359 tx_desc = hdd_ipa->tx_desc_list + id;
4360 ipa_tx_desc = tx_desc->ipa_tx_desc_ptr;
4361
4362 /* Return Tx Desc to IPA */
4363 ipa_free_skb(ipa_tx_desc);
4364
4365 /* Return to free tx desc list */
4366 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4367 tx_desc->ipa_tx_desc_ptr = NULL;
4368 list_add_tail(&tx_desc->link, &hdd_ipa->free_tx_desc_head);
4369 hdd_ipa->stats.num_tx_desc_q_cnt--;
4370 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004371
4372 hdd_ipa->stats.num_tx_comp_cnt++;
4373
4374 atomic_dec(&hdd_ipa->tx_ref_cnt);
4375
4376 hdd_ipa_rm_try_release(hdd_ipa);
4377}
4378
4379/**
4380 * hdd_ipa_send_pkt_to_tl() - Send an IPA packet to TL
4381 * @iface_context: interface-specific IPA context
4382 * @ipa_tx_desc: packet data descriptor
4383 *
4384 * Return: None
4385 */
4386static void hdd_ipa_send_pkt_to_tl(
4387 struct hdd_ipa_iface_context *iface_context,
4388 struct ipa_rx_data *ipa_tx_desc)
4389{
4390 struct hdd_ipa_priv *hdd_ipa = iface_context->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004391 hdd_adapter_t *adapter = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304392 qdf_nbuf_t skb;
Yun Park52b2b992016-09-22 15:49:51 -07004393 struct hdd_ipa_tx_desc *tx_desc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004394
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304395 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004396 adapter = iface_context->adapter;
4397 if (!adapter) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304398 HDD_IPA_LOG(QDF_TRACE_LEVEL_WARN, "Interface Down");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004399 ipa_free_skb(ipa_tx_desc);
4400 iface_context->stats.num_tx_drop++;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304401 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004402 hdd_ipa_rm_try_release(hdd_ipa);
4403 return;
4404 }
4405
4406 /*
4407 * During CAC period, data packets shouldn't be sent over the air so
4408 * drop all the packets here
4409 */
4410 if (WLAN_HDD_GET_AP_CTX_PTR(adapter)->dfs_cac_block_tx) {
4411 ipa_free_skb(ipa_tx_desc);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304412 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004413 iface_context->stats.num_tx_cac_drop++;
4414 hdd_ipa_rm_try_release(hdd_ipa);
4415 return;
4416 }
4417
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004418 ++adapter->stats.tx_packets;
4419
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304420 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004421
4422 skb = ipa_tx_desc->skb;
4423
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304424 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Yun Park52b2b992016-09-22 15:49:51 -07004425
4426 /* Store IPA Tx buffer ownership into SKB CB */
Nirav Shahcbc6d722016-03-01 16:24:53 +05304427 qdf_nbuf_ipa_owned_set(skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004428 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
Nirav Shahcbc6d722016-03-01 16:24:53 +05304429 qdf_nbuf_mapped_paddr_set(skb,
Houston Hoffman43d47fa2016-02-24 16:34:30 -08004430 ipa_tx_desc->dma_addr
4431 + HDD_IPA_WLAN_FRAG_HEADER
4432 + HDD_IPA_WLAN_IPA_HEADER);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004433 ipa_tx_desc->skb->len -=
4434 HDD_IPA_WLAN_FRAG_HEADER + HDD_IPA_WLAN_IPA_HEADER;
4435 } else
Nirav Shahcbc6d722016-03-01 16:24:53 +05304436 qdf_nbuf_mapped_paddr_set(skb, ipa_tx_desc->dma_addr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004437
Yun Park52b2b992016-09-22 15:49:51 -07004438 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4439 /* get free Tx desc and assign ipa_tx_desc pointer */
4440 if (!list_empty(&hdd_ipa->free_tx_desc_head)) {
4441 tx_desc = list_first_entry(&hdd_ipa->free_tx_desc_head,
4442 struct hdd_ipa_tx_desc, link);
4443 list_del(&tx_desc->link);
4444 tx_desc->ipa_tx_desc_ptr = ipa_tx_desc;
4445 hdd_ipa->stats.num_tx_desc_q_cnt++;
4446 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4447 /* Store Tx Desc index into SKB CB */
4448 QDF_NBUF_CB_TX_IPA_PRIV(skb) = tx_desc->id;
4449 } else {
4450 hdd_ipa->stats.num_tx_desc_error++;
4451 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4452 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "No free Tx desc!");
4453 ipa_free_skb(ipa_tx_desc);
4454 hdd_ipa_rm_try_release(hdd_ipa);
4455 return;
4456 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004457
4458 adapter->stats.tx_bytes += ipa_tx_desc->skb->len;
4459
Leo Changfdb45c32016-10-28 11:09:23 -07004460 skb = cdp_ipa_tx_send_data_frame(cds_get_context(QDF_MODULE_ID_SOC),
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08004461 (struct cdp_vdev *)iface_context->tl_context,
4462 ipa_tx_desc->skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004463 if (skb) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304464 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "TLSHIM tx fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004465 ipa_free_skb(ipa_tx_desc);
4466 iface_context->stats.num_tx_err++;
4467 hdd_ipa_rm_try_release(hdd_ipa);
4468 return;
4469 }
4470
4471 atomic_inc(&hdd_ipa->tx_ref_cnt);
4472
4473 iface_context->stats.num_tx++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004474}
4475
4476/**
Leo Chang11545d62016-10-17 14:53:50 -07004477 * hdd_ipa_is_present() - get IPA hw status
4478 * @hdd_ctx: pointer to hdd context
4479 *
4480 * ipa_uc_reg_rdyCB is not directly designed to check
4481 * ipa hw status. This is an undocumented function which
4482 * has confirmed with IPA team.
4483 *
4484 * Return: true - ipa hw present
4485 * false - ipa hw not present
4486 */
4487bool hdd_ipa_is_present(hdd_context_t *hdd_ctx)
4488{
4489 /* Check if ipa hw is enabled */
Leo Chang63d73612016-10-18 18:09:43 -07004490 if (HDD_IPA_CHECK_HW() != -EPERM)
Leo Chang11545d62016-10-17 14:53:50 -07004491 return true;
4492 else
4493 return false;
4494}
4495
4496/**
Leo Chang69c39692016-10-12 20:11:12 -07004497 * hdd_ipa_pm_flush() - flush queued packets
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004498 * @work: pointer to the scheduled work
4499 *
4500 * Called during PM resume to send packets to TL which were queued
4501 * while host was in the process of suspending.
4502 *
4503 * Return: None
4504 */
Leo Chang69c39692016-10-12 20:11:12 -07004505static void hdd_ipa_pm_flush(struct work_struct *work)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004506{
4507 struct hdd_ipa_priv *hdd_ipa = container_of(work,
4508 struct hdd_ipa_priv,
4509 pm_work);
4510 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304511 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004512 uint32_t dequeued = 0;
4513
Leo Chang69c39692016-10-12 20:11:12 -07004514 qdf_wake_lock_acquire(&hdd_ipa->wake_lock,
4515 WIFI_POWER_EVENT_WAKELOCK_IPA);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304516 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05304517 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
4518 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304519 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004520
4521 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004522 dequeued++;
Leo Chang69c39692016-10-12 20:11:12 -07004523 if (pm_tx_cb->exception) {
4524 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4525 "FLUSH EXCEPTION");
4526 hdd_softap_hard_start_xmit(skb, pm_tx_cb->adapter->dev);
4527 } else {
4528 hdd_ipa_send_pkt_to_tl(pm_tx_cb->iface_context,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004529 pm_tx_cb->ipa_tx_desc);
Leo Chang69c39692016-10-12 20:11:12 -07004530 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304531 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004532 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304533 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Leo Chang69c39692016-10-12 20:11:12 -07004534 qdf_wake_lock_release(&hdd_ipa->wake_lock,
4535 WIFI_POWER_EVENT_WAKELOCK_IPA);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004536
4537 hdd_ipa->stats.num_tx_dequeued += dequeued;
4538 if (dequeued > hdd_ipa->stats.num_max_pm_queue)
4539 hdd_ipa->stats.num_max_pm_queue = dequeued;
4540}
4541
4542/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004543 * __hdd_ipa_i2w_cb() - IPA to WLAN callback
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004544 * @priv: pointer to private data registered with IPA (we register a
4545 * pointer to the interface-specific IPA context)
4546 * @evt: the IPA event which triggered the callback
4547 * @data: data associated with the event
4548 *
4549 * Return: None
4550 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004551static void __hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004552 unsigned long data)
4553{
4554 struct hdd_ipa_priv *hdd_ipa = NULL;
4555 struct ipa_rx_data *ipa_tx_desc;
4556 struct hdd_ipa_iface_context *iface_context;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304557 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004558 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05304559 QDF_STATUS status = QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004560
Mukul Sharma81661ae2015-10-30 20:26:02 +05304561 iface_context = (struct hdd_ipa_iface_context *)priv;
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004562 ipa_tx_desc = (struct ipa_rx_data *)data;
4563 hdd_ipa = iface_context->hdd_ipa;
4564
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004565 if (evt != IPA_RECEIVE) {
Prakash Dhavali87b38e32016-11-14 16:22:53 -08004566 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Event is not IPA_RECEIVE");
4567 ipa_free_skb(ipa_tx_desc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004568 iface_context->stats.num_tx_drop++;
4569 return;
4570 }
4571
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004572 /*
4573 * When SSR is going on or driver is unloading, just drop the packets.
4574 * During SSR, there is no use in queueing the packets as STA has to
4575 * connect back any way
4576 */
4577 status = wlan_hdd_validate_context(hdd_ipa->hdd_ctx);
Abhishek Singh23edd1c2016-05-05 11:56:06 +05304578 if (status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004579 ipa_free_skb(ipa_tx_desc);
4580 iface_context->stats.num_tx_drop++;
4581 return;
4582 }
4583
4584 skb = ipa_tx_desc->skb;
4585
Yun Parkb187d542016-11-14 18:10:04 -08004586 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG,
4587 "i2w", skb->data, HDD_IPA_DBG_DUMP_TX_LEN);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004588
4589 /*
4590 * If PROD resource is not requested here then there may be cases where
4591 * IPA hardware may be clocked down because of not having proper
4592 * dependency graph between WLAN CONS and modem PROD pipes. Adding the
4593 * workaround to request PROD resource while data is going over CONS
4594 * pipe to prevent the IPA hardware clockdown.
4595 */
4596 hdd_ipa_rm_request(hdd_ipa);
4597
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304598 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004599 /*
4600 * If host is still suspended then queue the packets and these will be
4601 * drained later when resume completes. When packet is arrived here and
4602 * host is suspended, this means that there is already resume is in
4603 * progress.
4604 */
4605 if (hdd_ipa->suspended) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304606 qdf_mem_set(skb->cb, sizeof(skb->cb), 0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004607 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
4608 pm_tx_cb->iface_context = iface_context;
4609 pm_tx_cb->ipa_tx_desc = ipa_tx_desc;
Nirav Shahcbc6d722016-03-01 16:24:53 +05304610 qdf_nbuf_queue_add(&hdd_ipa->pm_queue_head, skb);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004611 hdd_ipa->stats.num_tx_queued++;
4612
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304613 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004614 return;
4615 }
4616
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304617 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004618
4619 /*
4620 * If we are here means, host is not suspended, wait for the work queue
4621 * to finish.
4622 */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004623 flush_work(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004624
4625 return hdd_ipa_send_pkt_to_tl(iface_context, ipa_tx_desc);
4626}
4627
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004628/*
4629 * hdd_ipa_i2w_cb() - SSR wrapper for __hdd_ipa_i2w_cb
4630 * @priv: pointer to private data registered with IPA (we register a
4631 * pointer to the interface-specific IPA context)
4632 * @evt: the IPA event which triggered the callback
4633 * @data: data associated with the event
4634 *
4635 * Return: None
4636 */
4637static void hdd_ipa_i2w_cb(void *priv, enum ipa_dp_evt_type evt,
4638 unsigned long data)
4639{
4640 cds_ssr_protect(__func__);
4641 __hdd_ipa_i2w_cb(priv, evt, data);
4642 cds_ssr_unprotect(__func__);
4643}
4644
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004645/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004646 * __hdd_ipa_suspend() - Suspend IPA
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004647 * @hdd_ctx: Global HDD context
4648 *
4649 * Return: 0 on success, negativer errno on error
4650 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004651static int __hdd_ipa_suspend(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004652{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004653 struct hdd_ipa_priv *hdd_ipa;
4654
4655 if (wlan_hdd_validate_context(hdd_ctx))
4656 return 0;
4657
4658 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004659
4660 if (!hdd_ipa_is_enabled(hdd_ctx))
4661 return 0;
4662
4663 /*
4664 * Check if IPA is ready for suspend, If we are here means, there is
4665 * high chance that suspend would go through but just to avoid any race
4666 * condition after suspend started, these checks are conducted before
4667 * allowing to suspend.
4668 */
4669 if (atomic_read(&hdd_ipa->tx_ref_cnt))
4670 return -EAGAIN;
4671
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304672 qdf_spin_lock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004673
4674 if (hdd_ipa->rm_state != HDD_IPA_RM_RELEASED) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304675 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004676 return -EAGAIN;
4677 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304678 qdf_spin_unlock_bh(&hdd_ipa->rm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004679
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304680 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004681 hdd_ipa->suspended = true;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304682 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004683
4684 return 0;
4685}
4686
4687/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004688 * hdd_ipa_suspend() - SSR wrapper for __hdd_ipa_suspend
4689 * @hdd_ctx: Global HDD context
4690 *
4691 * Return: 0 on success, negativer errno on error
4692 */
4693int hdd_ipa_suspend(hdd_context_t *hdd_ctx)
4694{
4695 int ret;
4696
4697 cds_ssr_protect(__func__);
4698 ret = __hdd_ipa_suspend(hdd_ctx);
4699 cds_ssr_unprotect(__func__);
4700
4701 return ret;
4702}
4703
4704/**
4705 * __hdd_ipa_resume() - Resume IPA following suspend
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004706 * hdd_ctx: Global HDD context
4707 *
4708 * Return: 0 on success, negative errno on error
4709 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004710static int __hdd_ipa_resume(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004711{
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004712 struct hdd_ipa_priv *hdd_ipa;
4713
4714 if (wlan_hdd_validate_context(hdd_ctx))
4715 return 0;
4716
4717 hdd_ipa = hdd_ctx->hdd_ipa;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004718
4719 if (!hdd_ipa_is_enabled(hdd_ctx))
4720 return 0;
4721
4722 schedule_work(&hdd_ipa->pm_work);
4723
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304724 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004725 hdd_ipa->suspended = false;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05304726 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004727
4728 return 0;
4729}
4730
4731/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07004732 * hdd_ipa_resume() - SSR wrapper for __hdd_ipa_resume
4733 * hdd_ctx: Global HDD context
4734 *
4735 * Return: 0 on success, negative errno on error
4736 */
4737int hdd_ipa_resume(hdd_context_t *hdd_ctx)
4738{
4739 int ret;
4740
4741 cds_ssr_protect(__func__);
4742 ret = __hdd_ipa_resume(hdd_ctx);
4743 cds_ssr_unprotect(__func__);
4744
4745 return ret;
4746}
4747
4748/**
Yun Park52b2b992016-09-22 15:49:51 -07004749 * hdd_ipa_alloc_tx_desc_list() - Allocate IPA Tx desc list
4750 * @hdd_ipa: Global HDD IPA context
4751 *
4752 * Return: 0 on success, negative errno on error
4753 */
4754static int hdd_ipa_alloc_tx_desc_list(struct hdd_ipa_priv *hdd_ipa)
4755{
4756 int i;
4757 uint32_t max_desc_cnt;
4758 struct hdd_ipa_tx_desc *tmp_desc;
4759
4760 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4761
4762 INIT_LIST_HEAD(&hdd_ipa->free_tx_desc_head);
4763
4764 tmp_desc = qdf_mem_malloc(sizeof(struct hdd_ipa_tx_desc)*max_desc_cnt);
4765
4766 if (!tmp_desc) {
4767 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4768 "Free Tx descriptor allocation failed");
4769 return -ENOMEM;
4770 }
4771
4772 hdd_ipa->tx_desc_list = tmp_desc;
4773
4774 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4775 for (i = 0; i < max_desc_cnt; i++) {
4776 tmp_desc->id = i;
4777 tmp_desc->ipa_tx_desc_ptr = NULL;
4778 list_add_tail(&tmp_desc->link,
4779 &hdd_ipa->free_tx_desc_head);
4780 tmp_desc++;
4781 }
4782
4783 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4784 hdd_ipa->stats.num_tx_desc_error = 0;
4785
4786 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4787
4788 return 0;
4789}
4790
4791/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004792 * hdd_ipa_setup_sys_pipe() - Setup all IPA Sys pipes
4793 * @hdd_ipa: Global HDD IPA context
4794 *
4795 * Return: 0 on success, negative errno on error
4796 */
4797static int hdd_ipa_setup_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4798{
4799 int i, ret = 0;
4800 struct ipa_sys_connect_params *ipa;
4801 uint32_t desc_fifo_sz;
4802
4803 /* The maximum number of descriptors that can be provided to a BAM at
4804 * once is one less than the total number of descriptors that the buffer
4805 * can contain.
4806 * If max_num_of_descriptors = (BAM_PIPE_DESCRIPTOR_FIFO_SIZE / sizeof
4807 * (SPS_DESCRIPTOR)), then (max_num_of_descriptors - 1) descriptors can
4808 * be provided at once.
4809 * Because of above requirement, one extra descriptor will be added to
4810 * make sure hardware always has one descriptor.
4811 */
4812 desc_fifo_sz = hdd_ipa->hdd_ctx->config->IpaDescSize
4813 + sizeof(struct sps_iovec);
4814
4815 /*setup TX pipes */
4816 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
4817 ipa = &hdd_ipa->sys_pipe[i].ipa_sys_params;
4818
4819 ipa->client = hdd_ipa_adapter_2_client[i].cons_client;
4820 ipa->desc_fifo_sz = desc_fifo_sz;
4821 ipa->priv = &hdd_ipa->iface_context[i];
4822 ipa->notify = hdd_ipa_i2w_cb;
4823
4824 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4825 ipa->ipa_ep_cfg.hdr.hdr_len =
4826 HDD_IPA_UC_WLAN_TX_HDR_LEN;
4827 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4828 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size_valid = 1;
4829 ipa->ipa_ep_cfg.hdr.hdr_ofst_pkt_size = 0;
4830 ipa->ipa_ep_cfg.hdr.hdr_additional_const_len =
4831 HDD_IPA_UC_WLAN_8023_HDR_SIZE;
4832 ipa->ipa_ep_cfg.hdr_ext.hdr_little_endian = true;
4833 } else {
4834 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
4835 }
4836 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4837
4838 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4839 ipa->keep_ipa_awake = 1;
4840
4841 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4842 if (ret) {
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07004843 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
4844 "Failed for pipe %d ret: %d", i, ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004845 goto setup_sys_pipe_fail;
4846 }
4847 hdd_ipa->sys_pipe[i].conn_hdl_valid = 1;
4848 }
4849
4850 if (!hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
4851 /*
4852 * Hard code it here, this can be extended if in case
4853 * PROD pipe is also per interface.
4854 * Right now there is no advantage of doing this.
4855 */
4856 hdd_ipa->prod_client = IPA_CLIENT_WLAN1_PROD;
4857
4858 ipa = &hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].ipa_sys_params;
4859
4860 ipa->client = hdd_ipa->prod_client;
4861
4862 ipa->desc_fifo_sz = desc_fifo_sz;
4863 ipa->priv = hdd_ipa;
4864 ipa->notify = hdd_ipa_w2i_cb;
4865
4866 ipa->ipa_ep_cfg.nat.nat_en = IPA_BYPASS_NAT;
4867 ipa->ipa_ep_cfg.hdr.hdr_len = HDD_IPA_WLAN_RX_HDR_LEN;
4868 ipa->ipa_ep_cfg.hdr.hdr_ofst_metadata_valid = 1;
4869 ipa->ipa_ep_cfg.mode.mode = IPA_BASIC;
4870
4871 if (!hdd_ipa_is_rm_enabled(hdd_ipa->hdd_ctx))
4872 ipa->keep_ipa_awake = 1;
4873
4874 ret = ipa_setup_sys_pipe(ipa, &(hdd_ipa->sys_pipe[i].conn_hdl));
4875 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304876 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004877 "Failed for RX pipe: %d", ret);
4878 goto setup_sys_pipe_fail;
4879 }
4880 hdd_ipa->sys_pipe[HDD_IPA_RX_PIPE].conn_hdl_valid = 1;
4881 }
4882
Yun Park52b2b992016-09-22 15:49:51 -07004883 /* Allocate free Tx desc list */
4884 ret = hdd_ipa_alloc_tx_desc_list(hdd_ipa);
4885 if (ret)
4886 goto setup_sys_pipe_fail;
4887
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004888 return ret;
4889
4890setup_sys_pipe_fail:
4891
4892 while (--i >= 0) {
4893 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].conn_hdl);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304894 qdf_mem_zero(&hdd_ipa->sys_pipe[i],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004895 sizeof(struct hdd_ipa_sys_pipe));
4896 }
4897
4898 return ret;
4899}
4900
4901/**
4902 * hdd_ipa_teardown_sys_pipe() - Tear down all IPA Sys pipes
4903 * @hdd_ipa: Global HDD IPA context
4904 *
4905 * Return: None
4906 */
4907static void hdd_ipa_teardown_sys_pipe(struct hdd_ipa_priv *hdd_ipa)
4908{
4909 int ret = 0, i;
Yun Park52b2b992016-09-22 15:49:51 -07004910 uint32_t max_desc_cnt;
4911 struct hdd_ipa_tx_desc *tmp_desc;
4912 struct ipa_rx_data *ipa_tx_desc;
4913
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004914 for (i = 0; i < HDD_IPA_MAX_SYSBAM_PIPE; i++) {
4915 if (hdd_ipa->sys_pipe[i].conn_hdl_valid) {
4916 ret =
4917 ipa_teardown_sys_pipe(hdd_ipa->sys_pipe[i].
4918 conn_hdl);
4919 if (ret)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304920 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004921 ret);
4922
4923 hdd_ipa->sys_pipe[i].conn_hdl_valid = 0;
4924 }
4925 }
Yun Park52b2b992016-09-22 15:49:51 -07004926
4927 if (hdd_ipa->tx_desc_list) {
4928 max_desc_cnt = hdd_ipa->hdd_ctx->config->IpaUcTxBufCount;
4929
4930 qdf_spin_lock_bh(&hdd_ipa->q_lock);
4931 for (i = 0; i < max_desc_cnt; i++) {
4932 tmp_desc = hdd_ipa->tx_desc_list + i;
4933 ipa_tx_desc = tmp_desc->ipa_tx_desc_ptr;
4934 if (ipa_tx_desc)
4935 ipa_free_skb(ipa_tx_desc);
4936 }
4937 tmp_desc = hdd_ipa->tx_desc_list;
4938 hdd_ipa->tx_desc_list = NULL;
4939 hdd_ipa->stats.num_tx_desc_q_cnt = 0;
4940 hdd_ipa->stats.num_tx_desc_error = 0;
4941 qdf_spin_unlock_bh(&hdd_ipa->q_lock);
4942 qdf_mem_free(tmp_desc);
4943 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004944}
4945
4946/**
4947 * hdd_ipa_register_interface() - register IPA interface
4948 * @hdd_ipa: Global IPA context
4949 * @iface_context: Per-interface IPA context
4950 *
4951 * Return: 0 on success, negative errno on error
4952 */
4953static int hdd_ipa_register_interface(struct hdd_ipa_priv *hdd_ipa,
4954 struct hdd_ipa_iface_context
4955 *iface_context)
4956{
4957 struct ipa_tx_intf tx_intf;
4958 struct ipa_rx_intf rx_intf;
4959 struct ipa_ioc_tx_intf_prop *tx_prop = NULL;
4960 struct ipa_ioc_rx_intf_prop *rx_prop = NULL;
4961 char *ifname = iface_context->adapter->dev->name;
4962
4963 char ipv4_hdr_name[IPA_RESOURCE_NAME_MAX];
4964 char ipv6_hdr_name[IPA_RESOURCE_NAME_MAX];
4965
4966 int num_prop = 1;
4967 int ret = 0;
4968
4969 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx))
4970 num_prop++;
4971
4972 /* Allocate TX properties for TOS categories, 1 each for IPv4 & IPv6 */
4973 tx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304974 qdf_mem_malloc(sizeof(struct ipa_ioc_tx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004975 if (!tx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304976 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "tx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004977 goto register_interface_fail;
4978 }
4979
4980 /* Allocate RX properties, 1 each for IPv4 & IPv6 */
4981 rx_prop =
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304982 qdf_mem_malloc(sizeof(struct ipa_ioc_rx_intf_prop) * num_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004983 if (!rx_prop) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05304984 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "rx_prop allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004985 goto register_interface_fail;
4986 }
4987
Anurag Chouhan600c3a02016-03-01 10:33:54 +05304988 qdf_mem_zero(&tx_intf, sizeof(tx_intf));
4989 qdf_mem_zero(&rx_intf, sizeof(rx_intf));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08004990
4991 snprintf(ipv4_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
4992 ifname, HDD_IPA_IPV4_NAME_EXT);
4993 snprintf(ipv6_hdr_name, IPA_RESOURCE_NAME_MAX, "%s%s",
4994 ifname, HDD_IPA_IPV6_NAME_EXT);
4995
4996 rx_prop[IPA_IP_v4].ip = IPA_IP_v4;
4997 rx_prop[IPA_IP_v4].src_pipe = iface_context->prod_client;
4998 rx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
4999 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
5000
5001 /*
5002 * Interface ID is 3rd byte in the CLD header. Add the meta data and
5003 * mask to identify the interface in IPA hardware
5004 */
5005 rx_prop[IPA_IP_v4].attrib.meta_data =
5006 htonl(iface_context->adapter->sessionId << 16);
5007 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
5008
5009 rx_intf.num_props++;
5010 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5011 rx_prop[IPA_IP_v6].ip = IPA_IP_v6;
5012 rx_prop[IPA_IP_v6].src_pipe = iface_context->prod_client;
5013 rx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5014 rx_prop[IPA_IP_v4].attrib.attrib_mask = IPA_FLT_META_DATA;
5015 rx_prop[IPA_IP_v4].attrib.meta_data =
5016 htonl(iface_context->adapter->sessionId << 16);
5017 rx_prop[IPA_IP_v4].attrib.meta_data_mask = htonl(0x00FF0000);
5018
5019 rx_intf.num_props++;
5020 }
5021
5022 tx_prop[IPA_IP_v4].ip = IPA_IP_v4;
5023 tx_prop[IPA_IP_v4].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5024 tx_prop[IPA_IP_v4].dst_pipe = IPA_CLIENT_WLAN1_CONS;
5025 tx_prop[IPA_IP_v4].alt_dst_pipe = iface_context->cons_client;
5026 strlcpy(tx_prop[IPA_IP_v4].hdr_name, ipv4_hdr_name,
5027 IPA_RESOURCE_NAME_MAX);
5028 tx_intf.num_props++;
5029
5030 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5031 tx_prop[IPA_IP_v6].ip = IPA_IP_v6;
5032 tx_prop[IPA_IP_v6].hdr_l2_type = IPA_HDR_L2_ETHERNET_II;
5033 tx_prop[IPA_IP_v6].dst_pipe = IPA_CLIENT_WLAN1_CONS;
5034 tx_prop[IPA_IP_v6].alt_dst_pipe = iface_context->cons_client;
5035 strlcpy(tx_prop[IPA_IP_v6].hdr_name, ipv6_hdr_name,
5036 IPA_RESOURCE_NAME_MAX);
5037 tx_intf.num_props++;
5038 }
5039
5040 tx_intf.prop = tx_prop;
5041 rx_intf.prop = rx_prop;
5042
5043 /* Call the ipa api to register interface */
5044 ret = ipa_register_intf(ifname, &tx_intf, &rx_intf);
5045
Yun Park52b2b992016-09-22 15:49:51 -07005046 /* Register IPA Tx desc free callback */
5047 qdf_nbuf_reg_free_cb(hdd_ipa_nbuf_cb);
5048
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005049register_interface_fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305050 qdf_mem_free(tx_prop);
5051 qdf_mem_free(rx_prop);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005052 return ret;
5053}
5054
5055/**
5056 * hdd_remove_ipa_header() - Remove a specific header from IPA
5057 * @name: Name of the header to be removed
5058 *
5059 * Return: None
5060 */
5061static void hdd_ipa_remove_header(char *name)
5062{
5063 struct ipa_ioc_get_hdr hdrlookup;
5064 int ret = 0, len;
5065 struct ipa_ioc_del_hdr *ipa_hdr;
5066
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305067 qdf_mem_zero(&hdrlookup, sizeof(hdrlookup));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005068 strlcpy(hdrlookup.name, name, sizeof(hdrlookup.name));
5069 ret = ipa_get_hdr(&hdrlookup);
5070 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005071 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Hdr deleted already %s, %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005072 name, ret);
5073 return;
5074 }
5075
Srinivas Girigowda97852372017-03-06 16:52:59 -08005076 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "hdl: 0x%x", hdrlookup.hdl);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005077 len = sizeof(struct ipa_ioc_del_hdr) + sizeof(struct ipa_hdr_del) * 1;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305078 ipa_hdr = (struct ipa_ioc_del_hdr *)qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005079 if (ipa_hdr == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305080 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "ipa_hdr allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005081 return;
5082 }
5083 ipa_hdr->num_hdls = 1;
5084 ipa_hdr->commit = 0;
5085 ipa_hdr->hdl[0].hdl = hdrlookup.hdl;
5086 ipa_hdr->hdl[0].status = -1;
5087 ret = ipa_del_hdr(ipa_hdr);
5088 if (ret != 0)
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305089 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "Delete header failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005090 ret);
5091
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305092 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005093}
5094
5095/**
Yun Parkb187d542016-11-14 18:10:04 -08005096 * wlan_ipa_add_hdr() - Add IPA Tx header
5097 * @ipa_hdr: pointer to IPA header addition parameters
5098 *
5099 * Call IPA API to add IPA Tx header descriptor
5100 * and dump Tx header struct
5101 *
5102 * Return: 0 for success, non-zero for failure
5103 */
5104static int wlan_ipa_add_hdr(struct ipa_ioc_add_hdr *ipa_hdr)
5105{
5106 int ret;
5107
Srinivas Girigowda97852372017-03-06 16:52:59 -08005108 hdd_debug("==== IPA Tx Header ====\n"
Yun Parkb187d542016-11-14 18:10:04 -08005109 "name: %s\n"
5110 "hdr_len: %d\n"
5111 "type: %d\n"
5112 "is_partial: %d\n"
5113 "hdr_hdl: 0x%x\n"
5114 "status: %d\n"
5115 "is_eth2_ofst_valid: %d\n"
5116 "eth2_ofst: %d\n",
5117 ipa_hdr->hdr[0].name,
5118 ipa_hdr->hdr[0].hdr_len,
5119 ipa_hdr->hdr[0].type,
5120 ipa_hdr->hdr[0].is_partial,
5121 ipa_hdr->hdr[0].hdr_hdl,
5122 ipa_hdr->hdr[0].status,
5123 ipa_hdr->hdr[0].is_eth2_ofst_valid,
5124 ipa_hdr->hdr[0].eth2_ofst);
5125
Srinivas Girigowdac06543c2017-03-09 15:10:03 -08005126 HDD_IPA_DBG_DUMP(QDF_TRACE_LEVEL_DEBUG, "hdr:",
Yun Parkb187d542016-11-14 18:10:04 -08005127 ipa_hdr->hdr[0].hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
5128
5129 ret = ipa_add_hdr(ipa_hdr);
5130 return ret;
5131}
5132
5133/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005134 * hdd_ipa_add_header_info() - Add IPA header for a given interface
5135 * @hdd_ipa: Global HDD IPA context
5136 * @iface_context: Interface-specific HDD IPA context
5137 * @mac_addr: Interface MAC address
5138 *
5139 * Return: 0 on success, negativer errno value on error
5140 */
5141static int hdd_ipa_add_header_info(struct hdd_ipa_priv *hdd_ipa,
5142 struct hdd_ipa_iface_context *iface_context,
5143 uint8_t *mac_addr)
5144{
5145 hdd_adapter_t *adapter = iface_context->adapter;
5146 char *ifname;
5147 struct ipa_ioc_add_hdr *ipa_hdr = NULL;
5148 int ret = -EINVAL;
5149 struct hdd_ipa_tx_hdr *tx_hdr = NULL;
5150 struct hdd_ipa_uc_tx_hdr *uc_tx_hdr = NULL;
5151
5152 ifname = adapter->dev->name;
5153
Srinivas Girigowda97852372017-03-06 16:52:59 -08005154 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "Add Partial hdr: %s, %pM",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005155 ifname, mac_addr);
5156
5157 /* dynamically allocate the memory to add the hdrs */
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305158 ipa_hdr = qdf_mem_malloc(sizeof(struct ipa_ioc_add_hdr)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005159 + sizeof(struct ipa_hdr_add));
5160 if (!ipa_hdr) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305161 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005162 "%s: ipa_hdr allocation failed", ifname);
5163 ret = -ENOMEM;
5164 goto end;
5165 }
5166
5167 ipa_hdr->commit = 0;
5168 ipa_hdr->num_hdrs = 1;
5169
5170 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5171 uc_tx_hdr = (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
5172 memcpy(uc_tx_hdr, &ipa_uc_tx_hdr, HDD_IPA_UC_WLAN_TX_HDR_LEN);
5173 memcpy(uc_tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
5174 uc_tx_hdr->ipa_hd.vdev_id = iface_context->adapter->sessionId;
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305175 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005176 "ifname=%s, vdev_id=%d",
5177 ifname, uc_tx_hdr->ipa_hd.vdev_id);
5178 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5179 ifname, HDD_IPA_IPV4_NAME_EXT);
5180 ipa_hdr->hdr[0].hdr_len = HDD_IPA_UC_WLAN_TX_HDR_LEN;
5181 ipa_hdr->hdr[0].type = IPA_HDR_L2_ETHERNET_II;
5182 ipa_hdr->hdr[0].is_partial = 1;
5183 ipa_hdr->hdr[0].hdr_hdl = 0;
5184 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
5185 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5186
Yun Parkb187d542016-11-14 18:10:04 -08005187 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005188 } else {
5189 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
5190
5191 /* Set the Source MAC */
5192 memcpy(tx_hdr, &ipa_tx_hdr, HDD_IPA_WLAN_TX_HDR_LEN);
5193 memcpy(tx_hdr->eth.h_source, mac_addr, ETH_ALEN);
5194
5195 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5196 ifname, HDD_IPA_IPV4_NAME_EXT);
5197 ipa_hdr->hdr[0].hdr_len = HDD_IPA_WLAN_TX_HDR_LEN;
5198 ipa_hdr->hdr[0].is_partial = 1;
5199 ipa_hdr->hdr[0].hdr_hdl = 0;
5200 ipa_hdr->hdr[0].is_eth2_ofst_valid = 1;
5201 ipa_hdr->hdr[0].eth2_ofst = HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5202
5203 /* Set the type to IPV4 in the header */
5204 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IP);
5205
5206 ret = ipa_add_hdr(ipa_hdr);
5207 }
5208 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305209 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "%s IPv4 add hdr failed: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005210 ifname, ret);
5211 goto end;
5212 }
5213
Srinivas Girigowda97852372017-03-06 16:52:59 -08005214 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: IPv4 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005215 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
5216
5217 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5218 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5219 ifname, HDD_IPA_IPV6_NAME_EXT);
5220
5221 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5222 uc_tx_hdr =
5223 (struct hdd_ipa_uc_tx_hdr *)ipa_hdr->hdr[0].hdr;
5224 uc_tx_hdr->eth.h_proto = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08005225 ret = wlan_ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005226 } else {
5227 /* Set the type to IPV6 in the header */
5228 tx_hdr = (struct hdd_ipa_tx_hdr *)ipa_hdr->hdr[0].hdr;
5229 tx_hdr->llc_snap.eth_type = cpu_to_be16(ETH_P_IPV6);
Yun Parkb187d542016-11-14 18:10:04 -08005230 ret = ipa_add_hdr(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005231 }
5232
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005233 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305234 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005235 "%s: IPv6 add hdr failed: %d", ifname, ret);
5236 goto clean_ipv4_hdr;
5237 }
5238
Srinivas Girigowda97852372017-03-06 16:52:59 -08005239 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: IPv6 hdr_hdl: 0x%x",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005240 ipa_hdr->hdr[0].name, ipa_hdr->hdr[0].hdr_hdl);
5241 }
5242
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305243 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005244
5245 return ret;
5246
5247clean_ipv4_hdr:
5248 snprintf(ipa_hdr->hdr[0].name, IPA_RESOURCE_NAME_MAX, "%s%s",
5249 ifname, HDD_IPA_IPV4_NAME_EXT);
5250 hdd_ipa_remove_header(ipa_hdr->hdr[0].name);
5251end:
5252 if (ipa_hdr)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305253 qdf_mem_free(ipa_hdr);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005254
5255 return ret;
5256}
5257
5258/**
5259 * hdd_ipa_clean_hdr() - Cleanup IPA on a given adapter
5260 * @adapter: Adapter upon which IPA was previously configured
5261 *
5262 * Return: None
5263 */
5264static void hdd_ipa_clean_hdr(hdd_adapter_t *adapter)
5265{
5266 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5267 int ret;
5268 char name_ipa[IPA_RESOURCE_NAME_MAX];
5269
5270 /* Remove the headers */
5271 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
5272 adapter->dev->name, HDD_IPA_IPV4_NAME_EXT);
5273 hdd_ipa_remove_header(name_ipa);
5274
5275 if (hdd_ipa_is_ipv6_enabled(hdd_ipa->hdd_ctx)) {
5276 snprintf(name_ipa, IPA_RESOURCE_NAME_MAX, "%s%s",
5277 adapter->dev->name, HDD_IPA_IPV6_NAME_EXT);
5278 hdd_ipa_remove_header(name_ipa);
5279 }
5280 /* unregister the interface with IPA */
5281 ret = ipa_deregister_intf(adapter->dev->name);
5282 if (ret)
Srinivas Girigowda97852372017-03-06 16:52:59 -08005283 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005284 "%s: ipa_deregister_intf fail: %d",
5285 adapter->dev->name, ret);
5286}
5287
5288/**
5289 * hdd_ipa_cleanup_iface() - Cleanup IPA on a given interface
5290 * @iface_context: interface-specific IPA context
5291 *
5292 * Return: None
5293 */
5294static void hdd_ipa_cleanup_iface(struct hdd_ipa_iface_context *iface_context)
5295{
5296 if (iface_context == NULL)
5297 return;
5298
5299 hdd_ipa_clean_hdr(iface_context->adapter);
5300
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305301 qdf_spin_lock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005302 iface_context->adapter->ipa_context = NULL;
5303 iface_context->adapter = NULL;
5304 iface_context->tl_context = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305305 qdf_spin_unlock_bh(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005306 iface_context->ifa_address = 0;
5307 if (!iface_context->hdd_ipa->num_iface) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305308 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005309 "NUM INTF 0, Invalid");
Anurag Chouhandf2b2682016-02-29 14:15:27 +05305310 QDF_ASSERT(0);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005311 }
5312 iface_context->hdd_ipa->num_iface--;
5313}
5314
5315/**
5316 * hdd_ipa_setup_iface() - Setup IPA on a given interface
5317 * @hdd_ipa: HDD IPA global context
5318 * @adapter: Interface upon which IPA is being setup
5319 * @sta_id: Station ID of the API instance
5320 *
5321 * Return: 0 on success, negative errno value on error
5322 */
5323static int hdd_ipa_setup_iface(struct hdd_ipa_priv *hdd_ipa,
5324 hdd_adapter_t *adapter, uint8_t sta_id)
5325{
5326 struct hdd_ipa_iface_context *iface_context = NULL;
5327 void *tl_context = NULL;
5328 int i, ret = 0;
5329
5330 /* Lower layer may send multiple START_BSS_EVENT in DFS mode or during
5331 * channel change indication. Since these indications are sent by lower
5332 * layer as SAP updates and IPA doesn't have to do anything for these
5333 * updates so ignoring!
5334 */
Krunal Sonibe766b02016-03-10 13:00:44 -08005335 if (QDF_SAP_MODE == adapter->device_mode && adapter->ipa_context)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005336 return 0;
5337
5338 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
5339 if (hdd_ipa->iface_context[i].adapter == NULL) {
5340 iface_context = &(hdd_ipa->iface_context[i]);
5341 break;
5342 }
5343 }
5344
5345 if (iface_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305346 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005347 "All the IPA interfaces are in use");
5348 ret = -ENOMEM;
5349 goto end;
5350 }
5351
5352 adapter->ipa_context = iface_context;
5353 iface_context->adapter = adapter;
5354 iface_context->sta_id = sta_id;
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -08005355 tl_context = (void *)cdp_peer_get_vdev_by_sta_id(
Leo Changfdb45c32016-10-28 11:09:23 -07005356 cds_get_context(QDF_MODULE_ID_SOC), sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005357 if (tl_context == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305358 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005359 "Not able to get TL context sta_id: %d", sta_id);
5360 ret = -EINVAL;
5361 goto end;
5362 }
5363
5364 iface_context->tl_context = tl_context;
5365
5366 ret = hdd_ipa_add_header_info(hdd_ipa, iface_context,
5367 adapter->dev->dev_addr);
5368
5369 if (ret)
5370 goto end;
5371
5372 /* Configure the TX and RX pipes filter rules */
5373 ret = hdd_ipa_register_interface(hdd_ipa, iface_context);
5374 if (ret)
5375 goto cleanup_header;
5376
5377 hdd_ipa->num_iface++;
5378 return ret;
5379
5380cleanup_header:
5381
5382 hdd_ipa_clean_hdr(adapter);
5383end:
5384 if (iface_context)
5385 hdd_ipa_cleanup_iface(iface_context);
5386 return ret;
5387}
5388
Yun Parka27049a2016-10-11 12:30:49 -07005389#ifndef QCA_LL_TX_FLOW_CONTROL_V2
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005390/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005391 * __hdd_ipa_send_mcc_scc_msg() - send IPA WLAN_SWITCH_TO_MCC/SCC message
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005392 * @mcc_mode: 0=MCC/1=SCC
5393 *
5394 * Return: 0 on success, negative errno value on error
5395 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005396static int __hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005397{
5398 hdd_adapter_list_node_t *adapter_node = NULL, *next = NULL;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305399 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005400 hdd_adapter_t *pAdapter;
5401 struct ipa_msg_meta meta;
5402 struct ipa_wlan_msg *msg;
5403 int ret;
5404
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005405 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005406 return -EINVAL;
5407
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005408 if (!hdd_ipa_uc_sta_is_enabled(hdd_ctx))
5409 return -EINVAL;
5410
5411 if (!hdd_ctx->mcc_mode) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005412 /* Flush TxRx queue for each adapter before switch to SCC */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005413 status = hdd_get_front_adapter(hdd_ctx, &adapter_node);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05305414 while (NULL != adapter_node && QDF_STATUS_SUCCESS == status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005415 pAdapter = adapter_node->pAdapter;
Krunal Sonibe766b02016-03-10 13:00:44 -08005416 if (pAdapter->device_mode == QDF_STA_MODE ||
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005417 pAdapter->device_mode == QDF_SAP_MODE) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005418 hdd_debug("MCC->SCC: Flush TxRx queue(d_mode=%d)",
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005419 pAdapter->device_mode);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005420 hdd_deinit_tx_rx(pAdapter);
5421 }
5422 status = hdd_get_next_adapter(
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005423 hdd_ctx, adapter_node, &next);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005424 adapter_node = next;
5425 }
5426 }
5427
5428 /* Send SCC/MCC Switching event to IPA */
5429 meta.msg_len = sizeof(*msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305430 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005431 if (msg == NULL) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005432 hdd_err("msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005433 return -ENOMEM;
5434 }
5435
5436 meta.msg_type = mcc_mode ?
5437 WLAN_SWITCH_TO_MCC : WLAN_SWITCH_TO_SCC;
Srinivas Girigowda97852372017-03-06 16:52:59 -08005438 hdd_debug("ipa_send_msg(Evt:%d)", meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005439
5440 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5441
5442 if (ret) {
Jeff Johnsonab2cd402016-12-05 13:54:28 -08005443 hdd_err("ipa_send_msg(Evt:%d) - fail=%d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005444 meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305445 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005446 }
5447
5448 return ret;
5449}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005450
5451/**
5452 * hdd_ipa_send_mcc_scc_msg() - SSR wrapper for __hdd_ipa_send_mcc_scc_msg
5453 * @mcc_mode: 0=MCC/1=SCC
5454 *
5455 * Return: 0 on success, negative errno value on error
5456 */
5457int hdd_ipa_send_mcc_scc_msg(hdd_context_t *hdd_ctx, bool mcc_mode)
5458{
5459 int ret;
5460
5461 cds_ssr_protect(__func__);
5462 ret = __hdd_ipa_send_mcc_scc_msg(hdd_ctx, mcc_mode);
5463 cds_ssr_unprotect(__func__);
5464
5465 return ret;
5466}
Yun Parka27049a2016-10-11 12:30:49 -07005467#endif
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005468
5469/**
5470 * hdd_ipa_wlan_event_to_str() - convert IPA WLAN event to string
5471 * @event: IPA WLAN event to be converted to a string
5472 *
5473 * Return: ASCII string representing the IPA WLAN event
5474 */
5475static inline char *hdd_ipa_wlan_event_to_str(enum ipa_wlan_event event)
5476{
5477 switch (event) {
5478 case WLAN_CLIENT_CONNECT:
5479 return "WLAN_CLIENT_CONNECT";
5480 case WLAN_CLIENT_DISCONNECT:
5481 return "WLAN_CLIENT_DISCONNECT";
5482 case WLAN_CLIENT_POWER_SAVE_MODE:
5483 return "WLAN_CLIENT_POWER_SAVE_MODE";
5484 case WLAN_CLIENT_NORMAL_MODE:
5485 return "WLAN_CLIENT_NORMAL_MODE";
5486 case SW_ROUTING_ENABLE:
5487 return "SW_ROUTING_ENABLE";
5488 case SW_ROUTING_DISABLE:
5489 return "SW_ROUTING_DISABLE";
5490 case WLAN_AP_CONNECT:
5491 return "WLAN_AP_CONNECT";
5492 case WLAN_AP_DISCONNECT:
5493 return "WLAN_AP_DISCONNECT";
5494 case WLAN_STA_CONNECT:
5495 return "WLAN_STA_CONNECT";
5496 case WLAN_STA_DISCONNECT:
5497 return "WLAN_STA_DISCONNECT";
5498 case WLAN_CLIENT_CONNECT_EX:
5499 return "WLAN_CLIENT_CONNECT_EX";
5500
5501 case IPA_WLAN_EVENT_MAX:
5502 default:
5503 return "UNKNOWN";
5504 }
5505}
5506
5507/**
Mohit Khannafa99aea2016-05-12 21:43:13 -07005508 * hdd_to_ipa_wlan_event() - convert hdd_ipa_wlan_event to ipa_wlan_event
5509 * @hdd_ipa_event_type: HDD IPA WLAN event to be converted to an ipa_wlan_event
5510 *
5511 * Return: ipa_wlan_event representing the hdd_ipa_wlan_event
5512 */
5513static enum ipa_wlan_event
5514hdd_to_ipa_wlan_event(enum hdd_ipa_wlan_event hdd_ipa_event_type)
5515{
5516 enum ipa_wlan_event ipa_event;
5517
5518 switch (hdd_ipa_event_type) {
5519 case HDD_IPA_CLIENT_CONNECT:
5520 ipa_event = WLAN_CLIENT_CONNECT;
5521 break;
5522 case HDD_IPA_CLIENT_DISCONNECT:
5523 ipa_event = WLAN_CLIENT_DISCONNECT;
5524 break;
5525 case HDD_IPA_AP_CONNECT:
5526 ipa_event = WLAN_AP_CONNECT;
5527 break;
5528 case HDD_IPA_AP_DISCONNECT:
5529 ipa_event = WLAN_AP_DISCONNECT;
5530 break;
5531 case HDD_IPA_STA_CONNECT:
5532 ipa_event = WLAN_STA_CONNECT;
5533 break;
5534 case HDD_IPA_STA_DISCONNECT:
5535 ipa_event = WLAN_STA_DISCONNECT;
5536 break;
5537 case HDD_IPA_CLIENT_CONNECT_EX:
5538 ipa_event = WLAN_CLIENT_CONNECT_EX;
5539 break;
5540 case HDD_IPA_WLAN_EVENT_MAX:
5541 default:
5542 ipa_event = IPA_WLAN_EVENT_MAX;
5543 break;
5544 }
5545 return ipa_event;
5546
5547}
5548
5549/**
5550 * __hdd_ipa_wlan_evt() - IPA event handler
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005551 * @adapter: adapter upon which the event was received
5552 * @sta_id: station id for the event
Mohit Khannafa99aea2016-05-12 21:43:13 -07005553 * @type: event enum of type ipa_wlan_event
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005554 * @mac_address: MAC address associated with the event
5555 *
Mohit Khannafa99aea2016-05-12 21:43:13 -07005556 * This function is meant to be called from within wlan_hdd_ipa.c
5557 *
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005558 * Return: 0 on success, negative errno value on error
5559 */
Mohit Khannafa99aea2016-05-12 21:43:13 -07005560static int __hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005561 enum ipa_wlan_event type, uint8_t *mac_addr)
5562{
5563 struct hdd_ipa_priv *hdd_ipa = ghdd_ipa;
5564 struct ipa_msg_meta meta;
5565 struct ipa_wlan_msg *msg;
5566 struct ipa_wlan_msg_ex *msg_ex = NULL;
5567 int ret;
5568
Srinivas Girigowda97852372017-03-06 16:52:59 -08005569 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: %s evt, MAC: %pM sta_id: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005570 adapter->dev->name, hdd_ipa_wlan_event_to_str(type),
5571 mac_addr, sta_id);
5572
5573 if (type >= IPA_WLAN_EVENT_MAX)
5574 return -EINVAL;
5575
5576 if (WARN_ON(is_zero_ether_addr(mac_addr)))
5577 return -EINVAL;
5578
5579 if (!hdd_ipa || !hdd_ipa_is_enabled(hdd_ipa->hdd_ctx)) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305580 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "IPA OFFLOAD NOT ENABLED");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005581 return -EINVAL;
5582 }
5583
5584 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx) &&
5585 !hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Krunal Sonibe766b02016-03-10 13:00:44 -08005586 (QDF_SAP_MODE != adapter->device_mode)) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005587 return 0;
5588 }
5589
5590 /*
5591 * During IPA UC resource loading/unloading new events can be issued.
5592 * Store the events separately and handle them later.
5593 */
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005594 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5595 if (hdd_ipa->resource_loading) {
5596 unsigned int pending_event_count;
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005597 struct ipa_uc_pending_event *pending_event = NULL;
Yun Parkf19e07d2015-11-20 11:34:27 -08005598
Yun Park64c405e2017-01-10 22:35:51 -08005599 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5600 "IPA resource load in progress");
Yun Park7c4f31b2016-11-30 10:09:21 -08005601
Yun Park64c405e2017-01-10 22:35:51 -08005602 qdf_mutex_acquire(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08005603
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005604 pending_event_count =
5605 qdf_list_size(&hdd_ipa->pending_event);
5606 if (pending_event_count >=
5607 HDD_IPA_MAX_PENDING_EVENT_COUNT) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005608 hdd_debug("Reached max pending event count");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005609 qdf_list_remove_front(&hdd_ipa->pending_event,
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005610 (qdf_list_node_t **)&pending_event);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005611 } else {
5612 pending_event =
Srinivas Girigowdac16ba6d2017-03-25 11:43:26 -07005613 qdf_mem_malloc(sizeof(*pending_event));
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005614 }
5615
5616 if (!pending_event) {
Yun Park64c405e2017-01-10 22:35:51 -08005617 qdf_mutex_release(&hdd_ipa->ipa_lock);
Yun Park7c4f31b2016-11-30 10:09:21 -08005618 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5619 "Pending event memory alloc fail");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005620 return -ENOMEM;
5621 }
5622
5623 pending_event->adapter = adapter;
5624 pending_event->sta_id = sta_id;
5625 pending_event->type = type;
5626 qdf_mem_copy(pending_event->mac_addr,
5627 mac_addr,
5628 QDF_MAC_ADDR_SIZE);
5629 qdf_list_insert_back(&hdd_ipa->pending_event,
5630 &pending_event->node);
5631
Yun Park64c405e2017-01-10 22:35:51 -08005632 qdf_mutex_release(&hdd_ipa->ipa_lock);
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005633 return 0;
5634 } else if (hdd_ipa->resource_unloading) {
Yun Park64c405e2017-01-10 22:35:51 -08005635 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
5636 "IPA resource unload in progress");
Prakash Dhavalibf6d5d22016-08-17 10:17:46 -07005637 return 0;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005638 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005639 }
5640
5641 hdd_ipa->stats.event[type]++;
5642
Leo Chang3bc8fed2015-11-13 10:59:47 -08005643 meta.msg_type = type;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005644 switch (type) {
5645 case WLAN_STA_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005646 qdf_mutex_acquire(&hdd_ipa->event_lock);
5647
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005648 /* STA already connected and without disconnect, connect again
5649 * This is Roaming scenario
5650 */
5651 if (hdd_ipa->sta_connected)
5652 hdd_ipa_cleanup_iface(adapter->ipa_context);
5653
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005654 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5655 if (ret) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305656 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005657 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005658 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005659
Yun Park8f289c82016-10-18 16:38:21 -07005660 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5661 (hdd_ipa->sap_num_connected_sta > 0) &&
5662 !hdd_ipa->sta_connected) {
5663 qdf_mutex_release(&hdd_ipa->event_lock);
5664 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005665 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005666 qdf_mutex_acquire(&hdd_ipa->event_lock);
5667 }
5668
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005669 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005670 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005671 (adapter->ipa_context))->iface_id;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005672
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005673 hdd_ipa->sta_connected = 1;
Yun Park8f289c82016-10-18 16:38:21 -07005674
5675 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005676 break;
5677
5678 case WLAN_AP_CONNECT:
Yun Park8f289c82016-10-18 16:38:21 -07005679 qdf_mutex_acquire(&hdd_ipa->event_lock);
5680
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005681 /* For DFS channel we get two start_bss event (before and after
5682 * CAC). Also when ACS range includes both DFS and non DFS
5683 * channels, we could possibly change channel many times due to
5684 * RADAR detection and chosen channel may not be a DFS channels.
5685 * So dont return error here. Just discard the event.
5686 */
Yun Park8f289c82016-10-18 16:38:21 -07005687 if (adapter->ipa_context) {
5688 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005689 return 0;
Yun Park8f289c82016-10-18 16:38:21 -07005690 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005691
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005692 ret = hdd_ipa_setup_iface(hdd_ipa, adapter, sta_id);
5693 if (ret) {
Yun Park64c405e2017-01-10 22:35:51 -08005694 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005695 hdd_err("%s: Evt: %d, Interface setup failed",
5696 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005697 goto end;
Yun Parka37592b2016-06-11 17:10:28 -07005698 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005699
Yun Park8f289c82016-10-18 16:38:21 -07005700 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5701 qdf_mutex_release(&hdd_ipa->event_lock);
5702 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005703 SIR_AP_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005704 qdf_mutex_acquire(&hdd_ipa->event_lock);
5705 }
5706
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005707 hdd_ipa->vdev_to_iface[adapter->sessionId] =
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005708 ((struct hdd_ipa_iface_context *)
Yun Parka37592b2016-06-11 17:10:28 -07005709 (adapter->ipa_context))->iface_id;
5710
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305711 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005712 break;
5713
5714 case WLAN_STA_DISCONNECT:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305715 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005716
5717 if (!hdd_ipa->sta_connected) {
Yun Park64c405e2017-01-10 22:35:51 -08005718 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parkb187d542016-11-14 18:10:04 -08005719 hdd_err("%s: Evt: %d, STA already disconnected",
5720 msg_ex->name, meta.msg_type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005721 return -EINVAL;
5722 }
Yun Parka37592b2016-06-11 17:10:28 -07005723
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005724 hdd_ipa->sta_connected = 0;
Yun Parka37592b2016-06-11 17:10:28 -07005725
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005726 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005727 hdd_debug("%s: IPA UC OFFLOAD NOT ENABLED",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005728 msg_ex->name);
5729 } else {
5730 /* Disable IPA UC TX PIPE when STA disconnected */
Yun Parka37592b2016-06-11 17:10:28 -07005731 if (!hdd_ipa->num_iface &&
5732 (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305733 hdd_ipa->activated_fw_pipe) &&
5734 !hdd_ipa->ipa_pipes_down)
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 ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305765 hdd_ipa->activated_fw_pipe) &&
5766 !hdd_ipa->ipa_pipes_down) {
Prashanth Bhatta9e143052015-12-04 11:56:47 -08005767 if (cds_is_driver_unloading()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005768 /*
5769 * We disable WDI pipes directly here since
5770 * IPA_OPCODE_TX/RX_SUSPEND message will not be
5771 * processed when unloading WLAN driver is in
5772 * progress
5773 */
5774 hdd_ipa_uc_disable_pipes(hdd_ipa);
5775 } else {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305776 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005777 "NO INTF left but still pipe clean up");
5778 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5779 }
5780 }
5781
5782 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Yun Park8f289c82016-10-18 16:38:21 -07005783 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005784 hdd_ipa_uc_offload_enable_disable(adapter,
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005785 SIR_AP_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005786 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005787 hdd_ipa->vdev_to_iface[adapter->sessionId] =
5788 CSR_ROAM_SESSION_MAX;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005789 }
Yun Parka37592b2016-06-11 17:10:28 -07005790
Yun Park8f289c82016-10-18 16:38:21 -07005791 hdd_ipa_cleanup_iface(adapter->ipa_context);
5792
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305793 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005794 break;
5795
5796 case WLAN_CLIENT_CONNECT_EX:
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005797 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005798 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005799 "%s: Evt: %d, IPA UC OFFLOAD NOT ENABLED",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305800 adapter->dev->name, type);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005801 return 0;
5802 }
5803
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305804 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005805 if (hdd_ipa_uc_find_add_assoc_sta(hdd_ipa,
5806 true, sta_id)) {
Yun Park8f289c82016-10-18 16:38:21 -07005807 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305808 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005809 "%s: STA ID %d found, not valid",
5810 adapter->dev->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005811 return 0;
5812 }
Yun Park312f71a2015-12-08 10:22:42 -08005813
5814 /* Enable IPA UC Data PIPEs when first STA connected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005815 if (hdd_ipa->sap_num_connected_sta == 0 &&
5816 hdd_ipa->uc_loaded == true) {
Yun Parka37592b2016-06-11 17:10:28 -07005817 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005818 hdd_ipa->sta_connected) {
5819 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005820 hdd_ipa_uc_offload_enable_disable(
5821 hdd_get_adapter(hdd_ipa->hdd_ctx,
5822 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005823 SIR_STA_RX_DATA_OFFLOAD, true);
Yun Park8f289c82016-10-18 16:38:21 -07005824 qdf_mutex_acquire(&hdd_ipa->event_lock);
5825 }
Yun Parka37592b2016-06-11 17:10:28 -07005826
Yun Park312f71a2015-12-08 10:22:42 -08005827 ret = hdd_ipa_uc_handle_first_con(hdd_ipa);
5828 if (ret) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305829 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Yun Park312f71a2015-12-08 10:22:42 -08005830 "%s: handle 1st con ret %d",
5831 adapter->dev->name, ret);
Yun Parka37592b2016-06-11 17:10:28 -07005832
5833 if (hdd_ipa_uc_sta_is_enabled(
5834 hdd_ipa->hdd_ctx) &&
Yun Park8f289c82016-10-18 16:38:21 -07005835 hdd_ipa->sta_connected) {
5836 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Parka37592b2016-06-11 17:10:28 -07005837 hdd_ipa_uc_offload_enable_disable(
5838 hdd_get_adapter(
5839 hdd_ipa->hdd_ctx,
5840 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005841 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005842 } else {
5843 qdf_mutex_release(&hdd_ipa->event_lock);
5844 }
Yun Parka37592b2016-06-11 17:10:28 -07005845
Yun Park312f71a2015-12-08 10:22:42 -08005846 return ret;
5847 }
5848 }
5849
5850 hdd_ipa->sap_num_connected_sta++;
Yun Park312f71a2015-12-08 10:22:42 -08005851
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305852 qdf_mutex_release(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005853
5854 meta.msg_type = type;
5855 meta.msg_len = (sizeof(struct ipa_wlan_msg_ex) +
5856 sizeof(struct ipa_wlan_hdr_attrib_val));
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305857 msg_ex = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005858
5859 if (msg_ex == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305860 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005861 "msg_ex allocation failed");
5862 return -ENOMEM;
5863 }
5864 strlcpy(msg_ex->name, adapter->dev->name,
5865 IPA_RESOURCE_NAME_MAX);
5866 msg_ex->num_of_attribs = 1;
5867 msg_ex->attribs[0].attrib_type = WLAN_HDR_ATTRIB_MAC_ADDR;
5868 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
5869 msg_ex->attribs[0].offset =
5870 HDD_IPA_UC_WLAN_HDR_DES_MAC_OFFSET;
5871 } else {
5872 msg_ex->attribs[0].offset =
5873 HDD_IPA_WLAN_HDR_DES_MAC_OFFSET;
5874 }
5875 memcpy(msg_ex->attribs[0].u.mac_addr, mac_addr,
5876 IPA_MAC_ADDR_SIZE);
5877
5878 ret = ipa_send_msg(&meta, msg_ex, hdd_ipa_msg_free_fn);
5879
5880 if (ret) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005881 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d : %d",
Manjeet Singhfd51d8f2016-11-09 15:58:26 +05305882 adapter->dev->name, type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305883 qdf_mem_free(msg_ex);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005884 return ret;
5885 }
5886 hdd_ipa->stats.num_send_msg++;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005887 return ret;
5888
5889 case WLAN_CLIENT_DISCONNECT:
5890 if (!hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08005891 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005892 "%s: IPA UC OFFLOAD NOT ENABLED",
5893 msg_ex->name);
5894 return 0;
5895 }
5896
Anurag Chouhana37b5b72016-02-21 14:53:42 +05305897 qdf_mutex_acquire(&hdd_ipa->event_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005898 if (!hdd_ipa_uc_find_add_assoc_sta(hdd_ipa, false, sta_id)) {
Yun Park64c405e2017-01-10 22:35:51 -08005899 qdf_mutex_release(&hdd_ipa->event_lock);
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305900 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005901 "%s: STA ID %d NOT found, not valid",
5902 msg_ex->name, sta_id);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005903 return 0;
5904 }
5905 hdd_ipa->sap_num_connected_sta--;
Yun Parka37592b2016-06-11 17:10:28 -07005906
Yun Park9b5030f2016-11-08 12:02:37 -08005907 /* Disable IPA UC TX PIPE when last STA disconnected */
Manikandan Mohan153a4c32017-02-16 15:04:30 -08005908 if (!hdd_ipa->sap_num_connected_sta &&
5909 hdd_ipa->uc_loaded == true) {
Yun Park9b5030f2016-11-08 12:02:37 -08005910 if ((false == hdd_ipa->resource_unloading)
5911 && (HDD_IPA_UC_NUM_WDI_PIPE ==
Govind Singhb78a75c2017-02-21 17:37:11 +05305912 hdd_ipa->activated_fw_pipe) &&
5913 !hdd_ipa->ipa_pipes_down) {
Yun Park9b5030f2016-11-08 12:02:37 -08005914 hdd_ipa_uc_handle_last_discon(hdd_ipa);
5915 }
5916
Yun Park8f289c82016-10-18 16:38:21 -07005917 qdf_mutex_release(&hdd_ipa->event_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08005918
5919 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx) &&
5920 hdd_ipa->sta_connected)
5921 hdd_ipa_uc_offload_enable_disable(
5922 hdd_get_adapter(hdd_ipa->hdd_ctx,
5923 QDF_STA_MODE),
Prakash Dhavali89d406d2016-11-23 11:11:00 -08005924 SIR_STA_RX_DATA_OFFLOAD, false);
Yun Park8f289c82016-10-18 16:38:21 -07005925 } else {
5926 qdf_mutex_release(&hdd_ipa->event_lock);
5927 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005928 break;
5929
5930 default:
5931 return 0;
5932 }
5933
5934 meta.msg_len = sizeof(struct ipa_wlan_msg);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305935 msg = qdf_mem_malloc(meta.msg_len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005936 if (msg == NULL) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05305937 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR, "msg allocation failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005938 return -ENOMEM;
5939 }
5940
5941 meta.msg_type = type;
5942 strlcpy(msg->name, adapter->dev->name, IPA_RESOURCE_NAME_MAX);
5943 memcpy(msg->mac_addr, mac_addr, ETH_ALEN);
5944
Srinivas Girigowda97852372017-03-06 16:52:59 -08005945 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG, "%s: Evt: %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005946 msg->name, meta.msg_type);
5947
5948 ret = ipa_send_msg(&meta, msg, hdd_ipa_msg_free_fn);
5949
5950 if (ret) {
Yun Parkb187d542016-11-14 18:10:04 -08005951 hdd_err("%s: Evt: %d fail:%d",
5952 msg->name, meta.msg_type, ret);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05305953 qdf_mem_free(msg);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08005954 return ret;
5955 }
5956
5957 hdd_ipa->stats.num_send_msg++;
5958
5959end:
5960 return ret;
5961}
5962
5963/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005964 * hdd_ipa_wlan_evt() - SSR wrapper for __hdd_ipa_wlan_evt
Mohit Khannafa99aea2016-05-12 21:43:13 -07005965 * @adapter: adapter upon which the event was received
5966 * @sta_id: station id for the event
5967 * @hdd_event_type: event enum of type hdd_ipa_wlan_event
5968 * @mac_address: MAC address associated with the event
5969 *
5970 * This function is meant to be called from outside of wlan_hdd_ipa.c.
5971 *
5972 * Return: 0 on success, negative errno value on error
5973 */
5974int hdd_ipa_wlan_evt(hdd_adapter_t *adapter, uint8_t sta_id,
5975 enum hdd_ipa_wlan_event hdd_event_type, uint8_t *mac_addr)
5976{
5977 enum ipa_wlan_event type = hdd_to_ipa_wlan_event(hdd_event_type);
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005978 int ret = 0;
5979
5980 cds_ssr_protect(__func__);
Mohit Khannafa99aea2016-05-12 21:43:13 -07005981
Leo Changa202b522016-10-14 16:13:50 -07005982 /* Data path offload only support for STA and SAP mode */
5983 if ((QDF_STA_MODE == adapter->device_mode) ||
5984 (QDF_SAP_MODE == adapter->device_mode))
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005985 ret = __hdd_ipa_wlan_evt(adapter, sta_id, type, mac_addr);
Leo Changa202b522016-10-14 16:13:50 -07005986
Prakash Dhavali412cdb02016-10-20 21:19:31 -07005987 cds_ssr_unprotect(__func__);
5988
5989 return ret;
Mohit Khannafa99aea2016-05-12 21:43:13 -07005990}
5991
5992/**
5993 * hdd_ipa_uc_proc_pending_event() - Process IPA uC pending events
5994 * @hdd_ipa: Global HDD IPA context
5995 *
5996 * Return: None
5997 */
5998static void
5999hdd_ipa_uc_proc_pending_event(struct hdd_ipa_priv *hdd_ipa)
6000{
6001 unsigned int pending_event_count;
6002 struct ipa_uc_pending_event *pending_event = NULL;
6003
6004 pending_event_count = qdf_list_size(&hdd_ipa->pending_event);
Srinivas Girigowda97852372017-03-06 16:52:59 -08006005 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07006006 "%s, Pending Event Count %d", __func__, pending_event_count);
6007 if (!pending_event_count) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08006008 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Mohit Khannafa99aea2016-05-12 21:43:13 -07006009 "%s, No Pending Event", __func__);
6010 return;
6011 }
6012
6013 qdf_list_remove_front(&hdd_ipa->pending_event,
6014 (qdf_list_node_t **)&pending_event);
6015 while (pending_event != NULL) {
6016 __hdd_ipa_wlan_evt(pending_event->adapter,
6017 pending_event->type,
6018 pending_event->sta_id,
6019 pending_event->mac_addr);
6020 qdf_mem_free(pending_event);
6021 pending_event = NULL;
6022 qdf_list_remove_front(&hdd_ipa->pending_event,
6023 (qdf_list_node_t **)&pending_event);
6024 }
6025}
6026
6027/**
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006028 * hdd_ipa_rm_state_to_str() - Convert IPA RM state to string
6029 * @state: IPA RM state value
6030 *
6031 * Return: ASCII string representing the IPA RM state
6032 */
6033static inline char *hdd_ipa_rm_state_to_str(enum hdd_ipa_rm_state state)
6034{
6035 switch (state) {
6036 case HDD_IPA_RM_RELEASED:
6037 return "RELEASED";
6038 case HDD_IPA_RM_GRANT_PENDING:
6039 return "GRANT_PENDING";
6040 case HDD_IPA_RM_GRANTED:
6041 return "GRANTED";
6042 }
6043
6044 return "UNKNOWN";
6045}
6046
6047/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006048 * __hdd_ipa_init() - IPA initialization function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006049 * @hdd_ctx: HDD global context
6050 *
6051 * Allocate hdd_ipa resources, ipa pipe resource and register
6052 * wlan interface with IPA module.
6053 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306054 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006055 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006056static QDF_STATUS __hdd_ipa_init(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006057{
6058 struct hdd_ipa_priv *hdd_ipa = NULL;
6059 int ret, i;
6060 struct hdd_ipa_iface_context *iface_context = NULL;
Yun Parkbaa62862017-01-18 13:43:34 -08006061 struct ol_txrx_pdev_t *pdev = NULL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006062
6063 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306064 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006065
Yun Parkbaa62862017-01-18 13:43:34 -08006066 ENTER();
6067
6068 pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Yun Park7f171ab2016-07-29 15:44:22 -07006069 if (!pdev) {
6070 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "pdev is NULL");
6071 goto fail_return;
6072 }
6073
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306074 hdd_ipa = qdf_mem_malloc(sizeof(*hdd_ipa));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006075 if (!hdd_ipa) {
Anurag Chouhanb2dc16f2016-02-25 11:47:37 +05306076 HDD_IPA_LOG(QDF_TRACE_LEVEL_FATAL, "hdd_ipa allocation failed");
Leo Chang3bc8fed2015-11-13 10:59:47 -08006077 goto fail_return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006078 }
6079
6080 hdd_ctx->hdd_ipa = hdd_ipa;
6081 ghdd_ipa = hdd_ipa;
6082 hdd_ipa->hdd_ctx = hdd_ctx;
6083 hdd_ipa->num_iface = 0;
6084
6085 /* Create the interface context */
6086 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6087 iface_context = &hdd_ipa->iface_context[i];
6088 iface_context->hdd_ipa = hdd_ipa;
6089 iface_context->cons_client =
6090 hdd_ipa_adapter_2_client[i].cons_client;
6091 iface_context->prod_client =
6092 hdd_ipa_adapter_2_client[i].prod_client;
6093 iface_context->iface_id = i;
6094 iface_context->adapter = NULL;
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306095 qdf_spinlock_create(&iface_context->interface_lock);
Yun Park9b5030f2016-11-08 12:02:37 -08006096 }
6097 for (i = 0; i < CSR_ROAM_SESSION_MAX; i++) {
Prakash Dhavali89d406d2016-11-23 11:11:00 -08006098 hdd_ipa->vdev_to_iface[i] = CSR_ROAM_SESSION_MAX;
6099 hdd_ipa->vdev_offload_enabled[i] = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006100 }
6101
Leo Chang69c39692016-10-12 20:11:12 -07006102 INIT_WORK(&hdd_ipa->pm_work, hdd_ipa_pm_flush);
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306103 qdf_spinlock_create(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006104 qdf_spinlock_create(&hdd_ipa->q_lock);
Nirav Shahcbc6d722016-03-01 16:24:53 +05306105 qdf_nbuf_queue_init(&hdd_ipa->pm_queue_head);
Manikandan Mohan2e803a02017-02-14 14:57:53 -08006106 qdf_list_create(&hdd_ipa->pending_event, 1000);
6107 qdf_mutex_create(&hdd_ipa->event_lock);
6108 qdf_mutex_create(&hdd_ipa->ipa_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006109
6110 ret = hdd_ipa_setup_rm(hdd_ipa);
6111 if (ret)
6112 goto fail_setup_rm;
6113
6114 if (hdd_ipa_uc_is_enabled(hdd_ipa->hdd_ctx)) {
6115 hdd_ipa_uc_rt_debug_init(hdd_ctx);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306116 qdf_mem_zero(&hdd_ipa->stats, sizeof(hdd_ipa->stats));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006117 hdd_ipa->sap_num_connected_sta = 0;
6118 hdd_ipa->ipa_tx_packets_diff = 0;
6119 hdd_ipa->ipa_rx_packets_diff = 0;
6120 hdd_ipa->ipa_p_tx_packets = 0;
6121 hdd_ipa->ipa_p_rx_packets = 0;
6122 hdd_ipa->resource_loading = false;
6123 hdd_ipa->resource_unloading = false;
6124 hdd_ipa->sta_connected = 0;
Leo Change3e49442015-10-26 20:07:13 -07006125 hdd_ipa->ipa_pipes_down = true;
Manikandan Mohancd64c0b2017-03-08 13:00:24 -08006126 hdd_ipa->wdi_enabled = false;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006127 /* Setup IPA sys_pipe for MCC */
6128 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx)) {
6129 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
6130 if (ret)
6131 goto fail_create_sys_pipe;
6132 }
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006133 if (hdd_ipa_uc_register_uc_ready(hdd_ipa))
6134 goto fail_create_sys_pipe;
Manikandan Mohan2e803a02017-02-14 14:57:53 -08006135
6136 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
6137 hdd_ipa_init_uc_op_work(&hdd_ipa->uc_op_work[i].work,
6138 hdd_ipa_uc_fw_op_event_handler);
6139 hdd_ipa->uc_op_work[i].msg = NULL;
6140 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006141 } else {
6142 ret = hdd_ipa_setup_sys_pipe(hdd_ipa);
6143 if (ret)
6144 goto fail_create_sys_pipe;
6145 }
6146
Yun Parkbaa62862017-01-18 13:43:34 -08006147 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306148 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006149
6150fail_create_sys_pipe:
6151 hdd_ipa_destroy_rm_resource(hdd_ipa);
6152fail_setup_rm:
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306153 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306154 qdf_mem_free(hdd_ipa);
Leo Chang3bc8fed2015-11-13 10:59:47 -08006155 hdd_ctx->hdd_ipa = NULL;
6156 ghdd_ipa = NULL;
6157fail_return:
Yun Parkbaa62862017-01-18 13:43:34 -08006158 EXIT();
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306159 return QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006160}
6161
6162/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006163 * hdd_ipa_init() - SSR wrapper for __hdd_ipa_init
6164 * @hdd_ctx: HDD global context
6165 *
6166 * Allocate hdd_ipa resources, ipa pipe resource and register
6167 * wlan interface with IPA module.
6168 *
6169 * Return: QDF_STATUS enumeration
6170 */
6171QDF_STATUS hdd_ipa_init(hdd_context_t *hdd_ctx)
6172{
6173 QDF_STATUS ret;
6174
6175 cds_ssr_protect(__func__);
6176 ret = __hdd_ipa_init(hdd_ctx);
6177 cds_ssr_unprotect(__func__);
6178
6179 return ret;
6180}
6181
Arun Khandavallicc544b32017-01-30 19:52:16 +05306182
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006183/**
Yun Parkf19e07d2015-11-20 11:34:27 -08006184 * hdd_ipa_cleanup_pending_event() - Cleanup IPA pending event list
6185 * @hdd_ipa: pointer to HDD IPA struct
6186 *
6187 * Return: none
6188 */
Jeff Johnsond7720632016-10-05 16:04:32 -07006189static void hdd_ipa_cleanup_pending_event(struct hdd_ipa_priv *hdd_ipa)
Yun Parkf19e07d2015-11-20 11:34:27 -08006190{
6191 struct ipa_uc_pending_event *pending_event = NULL;
6192
Anurag Chouhanffb21542016-02-17 14:33:03 +05306193 while (qdf_list_remove_front(&hdd_ipa->pending_event,
6194 (qdf_list_node_t **)&pending_event) == QDF_STATUS_SUCCESS) {
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306195 qdf_mem_free(pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08006196 }
6197
Anurag Chouhanffb21542016-02-17 14:33:03 +05306198 qdf_list_destroy(&hdd_ipa->pending_event);
Yun Parkf19e07d2015-11-20 11:34:27 -08006199}
6200
6201/**
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006202 * __hdd_ipa_cleanup - IPA cleanup function
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006203 * @hdd_ctx: HDD global context
6204 *
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306205 * Return: QDF_STATUS enumeration
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006206 */
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006207static QDF_STATUS __hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006208{
6209 struct hdd_ipa_priv *hdd_ipa = hdd_ctx->hdd_ipa;
6210 int i;
6211 struct hdd_ipa_iface_context *iface_context = NULL;
Nirav Shahcbc6d722016-03-01 16:24:53 +05306212 qdf_nbuf_t skb;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006213 struct hdd_ipa_pm_tx_cb *pm_tx_cb = NULL;
6214
6215 if (!hdd_ipa_is_enabled(hdd_ctx))
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306216 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006217
6218 if (!hdd_ipa_uc_is_enabled(hdd_ctx)) {
6219 unregister_inetaddr_notifier(&hdd_ipa->ipv4_notifier);
6220 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6221 }
6222
6223 /* Teardown IPA sys_pipe for MCC */
6224 if (hdd_ipa_uc_sta_is_enabled(hdd_ipa->hdd_ctx))
6225 hdd_ipa_teardown_sys_pipe(hdd_ipa);
6226
6227 hdd_ipa_destroy_rm_resource(hdd_ipa);
6228
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006229 cancel_work_sync(&hdd_ipa->pm_work);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006230
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306231 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006232
Nirav Shahcbc6d722016-03-01 16:24:53 +05306233 while (((skb = qdf_nbuf_queue_remove(&hdd_ipa->pm_queue_head))
6234 != NULL)) {
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306235 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006236
6237 pm_tx_cb = (struct hdd_ipa_pm_tx_cb *)skb->cb;
6238 ipa_free_skb(pm_tx_cb->ipa_tx_desc);
6239
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306240 qdf_spin_lock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006241 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306242 qdf_spin_unlock_bh(&hdd_ipa->pm_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006243
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306244 qdf_spinlock_destroy(&hdd_ipa->pm_lock);
Yun Park52b2b992016-09-22 15:49:51 -07006245 qdf_spinlock_destroy(&hdd_ipa->q_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006246
6247 /* destory the interface lock */
6248 for (i = 0; i < HDD_IPA_MAX_IFACE; i++) {
6249 iface_context = &hdd_ipa->iface_context[i];
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306250 qdf_spinlock_destroy(&iface_context->interface_lock);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006251 }
6252
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006253 if (hdd_ipa_uc_is_enabled(hdd_ctx)) {
Yun Park7e1f7c02017-01-05 08:19:49 -08006254 if (ipa_uc_dereg_rdyCB())
6255 HDD_IPA_LOG(QDF_TRACE_LEVEL_ERROR,
6256 "UC Ready CB deregister fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006257 hdd_ipa_uc_rt_debug_deinit(hdd_ctx);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006258 if (true == hdd_ipa->uc_loaded) {
Srinivas Girigowda97852372017-03-06 16:52:59 -08006259 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Govind Singh0487bf22016-08-24 23:08:57 +05306260 "%s: Disconnect TX PIPE tx_pipe_handle=0x%x",
6261 __func__, hdd_ipa->tx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006262 ipa_disconnect_wdi_pipe(hdd_ipa->tx_pipe_handle);
Srinivas Girigowda97852372017-03-06 16:52:59 -08006263 HDD_IPA_LOG(QDF_TRACE_LEVEL_DEBUG,
Govind Singh0487bf22016-08-24 23:08:57 +05306264 "%s: Disconnect RX PIPE rx_pipe_handle=0x%x",
6265 __func__, hdd_ipa->rx_pipe_handle);
Manikandan Mohan153a4c32017-02-16 15:04:30 -08006266 ipa_disconnect_wdi_pipe(hdd_ipa->rx_pipe_handle);
6267 }
Anurag Chouhana37b5b72016-02-21 14:53:42 +05306268 qdf_mutex_destroy(&hdd_ipa->event_lock);
6269 qdf_mutex_destroy(&hdd_ipa->ipa_lock);
Yun Parkf19e07d2015-11-20 11:34:27 -08006270 hdd_ipa_cleanup_pending_event(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006271
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006272 for (i = 0; i < HDD_IPA_UC_OPCODE_MAX; i++) {
6273 cancel_work_sync(&hdd_ipa->uc_op_work[i].work);
6274 hdd_ipa->uc_op_work[i].msg = NULL;
6275 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006276 }
6277
Anurag Chouhan600c3a02016-03-01 10:33:54 +05306278 qdf_mem_free(hdd_ipa);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006279 hdd_ctx->hdd_ipa = NULL;
6280
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05306281 return QDF_STATUS_SUCCESS;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006282}
Prakash Dhavali412cdb02016-10-20 21:19:31 -07006283
6284/**
6285 * hdd_ipa_cleanup - SSR wrapper for __hdd_ipa_cleanup
6286 * @hdd_ctx: HDD global context
6287 *
6288 * Return: QDF_STATUS enumeration
6289 */
6290QDF_STATUS hdd_ipa_cleanup(hdd_context_t *hdd_ctx)
6291{
6292 QDF_STATUS ret;
6293
6294 cds_ssr_protect(__func__);
6295 ret = __hdd_ipa_cleanup(hdd_ctx);
6296 cds_ssr_unprotect(__func__);
6297
6298 return ret;
6299}
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08006300#endif /* IPA_OFFLOAD */